ne_socket.h | ne_socket.h | |||
---|---|---|---|---|
skipping to change at line 25 | skipping to change at line 25 | |||
You should have received a copy of the GNU Library General Public | You should have received a copy of the GNU Library General Public | |||
License along with this library; if not, write to the Free | License along with this library; if not, write to the Free | |||
Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, | Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, | |||
MA 02111-1307, USA | MA 02111-1307, USA | |||
*/ | */ | |||
#ifndef NE_SOCKET_H | #ifndef NE_SOCKET_H | |||
#define NE_SOCKET_H | #define NE_SOCKET_H | |||
#ifdef WIN32 | ||||
#include <winsock2.h> | ||||
#include <stddef.h> | ||||
#include <sys/types.h> | ||||
#else | ||||
#include <sys/types.h> | #include <sys/types.h> | |||
#include <sys/socket.h> | ||||
#include <netinet/in.h> | ||||
#include <netdb.h> | ||||
#endif | ||||
#ifdef NEON_SSL | #ifdef NEON_SSL | |||
#include <openssl/ssl.h> | #include <openssl/ssl.h> | |||
#endif | #endif | |||
#include "ne_defs.h" | #include "ne_defs.h" | |||
BEGIN_NEON_DECLS | BEGIN_NEON_DECLS | |||
/* define ssize_t for Win32 */ | /* define ssize_t for Win32 */ | |||
skipping to change at line 56 | skipping to change at line 47 | |||
#define ssize_t int | #define ssize_t int | |||
#endif | #endif | |||
#define NE_SOCK_ERROR (-1) | #define NE_SOCK_ERROR (-1) | |||
/* Read/Write timed out */ | /* Read/Write timed out */ | |||
#define NE_SOCK_TIMEOUT (-2) | #define NE_SOCK_TIMEOUT (-2) | |||
/* Socket was closed */ | /* Socket was closed */ | |||
#define NE_SOCK_CLOSED (-3) | #define NE_SOCK_CLOSED (-3) | |||
/* Connection was reset (e.g. server crashed) */ | /* Connection was reset (e.g. server crashed) */ | |||
#define NE_SOCK_RESET (-4) | #define NE_SOCK_RESET (-4) | |||
/* Secure connection was subject to possible truncation attack. */ | ||||
#define NE_SOCK_TRUNC (-5) | ||||
/* ne_socket represents a TCP socket. */ | ||||
typedef struct ne_socket_s ne_socket; | typedef struct ne_socket_s ne_socket; | |||
/* ne_sock_addr represents an address object. */ | ||||
typedef struct ne_sock_addr_s ne_sock_addr; | ||||
#ifndef NE_INET_ADDR_DEFINED | ||||
typedef struct ne_inet_addr_s ne_inet_addr; | ||||
#endif | ||||
typedef void (*ne_block_reader) ( | typedef void (*ne_block_reader) ( | |||
void *userdata, const char *buf, size_t len); | void *userdata, const char *buf, size_t len); | |||
typedef void (*ne_progress)(void *userdata, off_t progress, off_t total); | typedef void (*ne_progress)(void *userdata, off_t progress, off_t total); | |||
void ne_register_progress(ne_socket *sock, ne_progress cb, void *userdata); | void ne_register_progress(ne_socket *sock, ne_progress cb, void *userdata); | |||
/* While neon itself doesn't require per-process global | /* While neon itself doesn't require per-process global | |||
* initialization, some platforms do, and so does the OpenSSL | * initialization, some platforms do, and so does the OpenSSL | |||
* library. */ | * library. */ | |||
int ne_sock_init(void); | int ne_sock_init(void); | |||
/* Shutdown any underlying libraries. */ | /* Shutdown any underlying libraries. */ | |||
void ne_sock_exit(void); | void ne_sock_exit(void); | |||
/* Resolve the given hostname. 'flags' are currently ignored. Hex | ||||
* string IPv6 addresses (e.g. `::1') may be enclosed in brackets | ||||
* (e.g. `[::1]'). */ | ||||
ne_sock_addr *ne_addr_resolve(const char *hostname, int flags); | ||||
/* Returns zero if name resolution was successful, non-zero on | ||||
* error. */ | ||||
int ne_addr_result(const ne_sock_addr *addr); | ||||
/* Returns the first network address associated with the 'addr' | ||||
* object. Undefined behaviour if ne_addr_result returns non-zero for | ||||
* 'addr'; otherwise, never returns NULL. */ | ||||
ne_inet_addr *ne_addr_first(ne_sock_addr *addr); | ||||
/* Returns the next network address associated with the 'addr' object, | ||||
* or NULL if there are no more. */ | ||||
ne_inet_addr *ne_addr_next(ne_sock_addr *addr); | ||||
/* Prints the string representation of network address 'ia' into the | ||||
* 'buffer', which is of size 'bufsiz'. */ | ||||
char *ne_addr_print(const ne_inet_addr *ia, char *buffer, size_t bufsiz); | ||||
/* If name resolution fails, copies the error string into 'buffer', | ||||
* which is of size 'bufsiz'. 'buffer' is returned. */ | ||||
char *ne_addr_error(const ne_sock_addr *addr, char *buffer, size_t bufsiz); | ||||
/* Destroys an address object created by ne_addr_resolve. */ | ||||
void ne_addr_destroy(ne_sock_addr *addr); | ||||
/* ne_sock_read reads up to 'count' bytes into 'buffer'. | /* ne_sock_read reads up to 'count' bytes into 'buffer'. | |||
* Returns: | * Returns: | |||
* NE_SOCK_* on error, | * NE_SOCK_* on error, | |||
* >0 length of data read into buffer. | * >0 length of data read into buffer. | |||
*/ | */ | |||
ssize_t ne_sock_read(ne_socket *sock, char *buffer, size_t count); | ssize_t ne_sock_read(ne_socket *sock, char *buffer, size_t count); | |||
/* ne_sock_peek reads up to 'count' bytes into 'buffer', but the data | /* ne_sock_peek reads up to 'count' bytes into 'buffer', but the data | |||
* will still be returned on a subsequent call to ne_sock_read or | * will still be returned on a subsequent call to ne_sock_read or | |||
* ne_sock_peek. | * ne_sock_peek. | |||
skipping to change at line 114 | skipping to change at line 144 | |||
* Returns: | * Returns: | |||
* NE_SOCK_* on error, | * NE_SOCK_* on error, | |||
* >0 number of bytes read (including NUL terminator) | * >0 number of bytes read (including NUL terminator) | |||
*/ | */ | |||
ssize_t ne_sock_readline(ne_socket *sock, char *buffer, size_t len); | ssize_t ne_sock_readline(ne_socket *sock, char *buffer, size_t len); | |||
/* Read exactly 'len' bytes into buffer; returns 0 on success, SOCK_* | /* Read exactly 'len' bytes into buffer; returns 0 on success, SOCK_* | |||
* on error. */ | * on error. */ | |||
ssize_t ne_sock_fullread(ne_socket *sock, char *buffer, size_t len); | ssize_t ne_sock_fullread(ne_socket *sock, char *buffer, size_t len); | |||
/* Create a socket connected to server at address 'host' on port | /* Create a TCP socket connected to server at address 'addr' on port | |||
* 'port'. Returns NULL if a connection could not be established. */ | * 'port'. Returns NULL if a connection could not be established. | |||
ne_socket *ne_sock_connect(const struct in_addr host, unsigned int port); | * (error details in errno). */ | |||
ne_socket *ne_sock_connect(ne_inet_addr *addr, unsigned int port); | ||||
/* Accept a connection on listening socket 'fd'. */ | /* Accept a connection on listening socket 'fd'. */ | |||
ne_socket *ne_sock_accept(int fd); | ne_socket *ne_sock_accept(int fd); | |||
/* Returns the file descriptor used for socket 'sock'. */ | /* Returns the file descriptor used for socket 'sock'. */ | |||
int ne_sock_fd(const ne_socket *sock); | int ne_sock_fd(const ne_socket *sock); | |||
/* Close the socket, and destroy the socket object. Returns non-zero | /* Close the socket, and destroy the socket object. Returns non-zero | |||
* on error. */ | * on error. */ | |||
int ne_sock_close(ne_socket *sock); | int ne_sock_close(ne_socket *sock); | |||
/* Return current error string for socket. */ | /* Return current error string for socket. */ | |||
const char *ne_sock_error(const ne_socket *sock); | const char *ne_sock_error(const ne_socket *sock); | |||
/* Set read timeout for socket. */ | /* Set read timeout for socket. */ | |||
void ne_sock_read_timeout(ne_socket *sock, int timeout); | void ne_sock_read_timeout(ne_socket *sock, int timeout); | |||
/* Do a name lookup on given hostname, writes the address into | ||||
* given address buffer. Return -1 on failure. */ | ||||
int ne_name_lookup(const char *hostname, struct in_addr *addr); | ||||
/* Returns the standard TCP port for the given service */ | /* Returns the standard TCP port for the given service */ | |||
int ne_service_lookup(const char *name); | int ne_service_lookup(const char *name); | |||
/* Enable SSL/TLS on the socket. Returns non-zero if the SSL | /* Enable SSL/TLS on the socket. Returns non-zero if the SSL | |||
* negotiation fails. */ | * negotiation fails. */ | |||
int ne_sock_use_ssl(ne_socket *sock); | int ne_sock_use_ssl(ne_socket *sock); | |||
#ifdef NEON_SSL | #ifdef NEON_SSL | |||
/* FIXME: this is a terribly disgusting API. */ | /* FIXME: this is a terribly disgusting API. */ | |||
End of changes. 8 change blocks. | ||||
16 lines changed or deleted | 43 lines changed or added | |||
ne_string.h | ne_string.h | |||
---|---|---|---|---|
skipping to change at line 110 | skipping to change at line 110 | |||
/* Grows the ne_buffer to a minimum size. */ | /* Grows the ne_buffer to a minimum size. */ | |||
void ne_buffer_grow(ne_buffer *buf, size_t size); | void ne_buffer_grow(ne_buffer *buf, size_t size); | |||
void ne_buffer_altered(ne_buffer *buf); | void ne_buffer_altered(ne_buffer *buf); | |||
/* Destroys a buffer, WITHOUT freeing the data, and returns the | /* Destroys a buffer, WITHOUT freeing the data, and returns the | |||
* data. */ | * data. */ | |||
char *ne_buffer_finish(ne_buffer *buf); | char *ne_buffer_finish(ne_buffer *buf); | |||
/* Thread-safe strerror() wrapper; place system error for errno value | /* Thread-safe strerror() wrapper; place system error for errno value | |||
* 'errnum' in 'buffer', which is of length 'buflen'. */ | * 'errnum' in 'buffer', which is of length 'buflen'. Returns | |||
void ne_strerror(int errnum, char *buffer, size_t buflen); | * 'buffer'. */ | |||
char *ne_strerror(int errnum, char *buffer, size_t buflen); | ||||
/* ne_strnzcpy copies at most 'n'-1 bytes of 'src' to 'dest', and | ||||
* ensures that 'dest' is subsequently NUL-terminated. */ | ||||
#define ne_strnzcpy(dest, src, n) do { \ | ||||
strncpy(dest, src, n-1); dest[n-1] = '\0'; } while (0) | ||||
/* Return malloc-allocated concatenation of all NUL-terminated string | /* Return malloc-allocated concatenation of all NUL-terminated string | |||
* arguments, up to a terminating NULL. */ | * arguments, up to a terminating NULL. */ | |||
char *ne_concat(const char *str, ...); | char *ne_concat(const char *str, ...); | |||
#define NE_ASC2HEX(x) (((x) <= '9') ? ((x) - '0') : (tolower((x)) + 10 - 'a ')) | #define NE_ASC2HEX(x) (((x) <= '9') ? ((x) - '0') : (tolower((x)) + 10 - 'a ')) | |||
#define NE_HEX2ASC(x) ((x) > 9 ? ((x) - 10 + 'a') : ((x) + '0')) | #define NE_HEX2ASC(x) ((x) > 9 ? ((x) - 10 + 'a') : ((x) + '0')) | |||
END_NEON_DECLS | END_NEON_DECLS | |||
End of changes. 1 change blocks. | ||||
2 lines changed or deleted | 8 lines changed or added | |||
ne_utils.h | ne_utils.h | |||
---|---|---|---|---|
skipping to change at line 83 | skipping to change at line 83 | |||
#endif /* DEBUGGING */ | #endif /* DEBUGGING */ | |||
#define NE_DBG_SOCKET (1<<0) | #define NE_DBG_SOCKET (1<<0) | |||
#define NE_DBG_HTTP (1<<1) | #define NE_DBG_HTTP (1<<1) | |||
#define NE_DBG_XML (1<<2) | #define NE_DBG_XML (1<<2) | |||
#define NE_DBG_HTTPAUTH (1<<3) | #define NE_DBG_HTTPAUTH (1<<3) | |||
#define NE_DBG_HTTPPLAIN (1<<4) | #define NE_DBG_HTTPPLAIN (1<<4) | |||
#define NE_DBG_LOCKS (1<<5) | #define NE_DBG_LOCKS (1<<5) | |||
#define NE_DBG_XMLPARSE (1<<6) | #define NE_DBG_XMLPARSE (1<<6) | |||
#define NE_DBG_HTTPBODY (1<<7) | #define NE_DBG_HTTPBODY (1<<7) | |||
#define NE_DBG_SSL (1<<8) | ||||
#define NE_DBG_FLUSH (1<<30) | #define NE_DBG_FLUSH (1<<30) | |||
void ne_debug_init(FILE *stream, int mask); | void ne_debug_init(FILE *stream, int mask); | |||
extern int ne_debug_mask; | extern int ne_debug_mask; | |||
extern FILE *ne_debug_stream; | extern FILE *ne_debug_stream; | |||
void ne_debug(int ch, const char *, ...) | void ne_debug(int ch, const char *, ...) | |||
#ifdef __GNUC__ | #ifdef __GNUC__ | |||
__attribute__ ((format (printf, 2, 3))) | __attribute__ ((format (printf, 2, 3))) | |||
#endif /* __GNUC__ */ | #endif /* __GNUC__ */ | |||
End of changes. 1 change blocks. | ||||
0 lines changed or deleted | 1 lines changed or added | |||