libspopc.h | libspopc.h | |||
---|---|---|---|---|
skipping to change at line 24 | skipping to change at line 24 | |||
#endif | #endif | |||
#include <sys/types.h> | #include <sys/types.h> | |||
#ifdef WIN32 | #ifdef WIN32 | |||
#include <winsock.h> | #include <winsock.h> | |||
#else | #else | |||
#include <sys/socket.h> | #include <sys/socket.h> | |||
#include <netinet/in.h> | #include <netinet/in.h> | |||
#include <netdb.h> | #include <netdb.h> | |||
#endif | #endif | |||
#ifdef USE_SSL | ||||
#include <openssl/ssl.h> | ||||
/************************************************************************** | ||||
**** | ||||
* If compiled with SSL support, the low-level functions will act on a | ||||
* "pop3sock" structure, which contains the socket, SSL instance and contex | ||||
t | ||||
* for the connection. This structure is dynamically allocated and initiali | ||||
zed | ||||
* when you do pop3_prepare() or popbegin(), and is cleaned-up and destroye | ||||
d in | ||||
* pop3_disconnect() or popend(). | ||||
************************************************************************** | ||||
****/ | ||||
typedef struct { | ||||
int sock; | ||||
SSL *ssl; | ||||
SSL_CTX *ctx; | ||||
} pop3sock; | ||||
typedef pop3sock* pop3sock_t; | ||||
#define BAD_SOCK NULL | ||||
/************************************************************************** | ||||
**** | ||||
* Use pop3_cert_setup() to specify the location of your SSL certificate | ||||
* bundle. If it is not set (or set to NULL), SSL connections can be still | ||||
be | ||||
* made, but certificates will not be verified! | ||||
* This function sets a global variable, and should be called before | ||||
* pop3_prepare() or popbegin() if you want to verify certs. | ||||
* | ||||
* Hint: If you have a recent version of curl/libcurl installed, you can tr | ||||
y | ||||
* setting this to the output of: "curl-config --ca" | ||||
************************************************************************** | ||||
****/ | ||||
void pop3_cert_setup(char *certfile); | ||||
#else /* Non-SSL */ | ||||
/************************************************************************** | ||||
**** | ||||
* If the library is compiled without SSL, the "pop3sock_t" type is a simp | ||||
le | ||||
* integer (i.e. socket) and all the functions should work just as they di | ||||
d | ||||
* in previous libspopc versions. | ||||
************************************************************************** | ||||
****/ | ||||
typedef int pop3sock_t; | ||||
#define BAD_SOCK -1 | ||||
#endif /* SSL */ | ||||
/*************************************** | /*************************************** | |||
* low-level methods for a pop3 client * | * low-level methods for a pop3 client * | |||
***************************************/ | ***************************************/ | |||
#define SOCKET_TIMEOUT 15 | #define SOCKET_TIMEOUT 15 /* miliseconds socket connection timeout */ | |||
#define TCPBUFLEN 512 | #define TCPBUFLEN 512 /* length of the socket buffer */ | |||
#define POPBUF 512 /* lenght of the pop response: 512 bytes as say RFC 1939 | ||||
*/ | ||||
/************************************************************************** **** | /************************************************************************** **** | |||
* Be careful, using the low-level API is uncompliant with using the high | * Be careful, using the low-level API is uncompliant with using the high | |||
* | * level API. Here, you make your choice. If you don't know the pop3 protoc | |||
* level API. Here, you make your choice. If you don't know the pop3 protoc | ol | |||
ol * | * or what a socket is, it is then warmly recommended to use the *high-leve | |||
* or what a socket is, it is then warmly recommended to use the *high-leve | l* | |||
l* * | * API if which is shown far below on this file. | |||
* API if which is shown far below on this file. | ||||
* | ||||
************************************************************************** ****/ | ************************************************************************** ****/ | |||
/************** | /************** | |||
* connecting * | * connecting * | |||
**************/ | **************/ | |||
int pop3_prepare(const char* servername, const int port, struct sockaddr_in | pop3sock_t pop3_prepare(const char* servername, const int port, struct sock | |||
* connection, struct hostent* server); | addr_in* connection, struct hostent* server); | |||
/* prepares the pop session and returns a socket descriptor */ | /* prepares the pop session and returns a socket descriptor, or BAD_SOCK on | |||
error */ | ||||
char* pop3_connect(int sock, struct sockaddr_in* connection); | char* pop3_connect(pop3sock_t sock, struct sockaddr_in* connection); | |||
/* connects to the server through the sock and returns server's welcome */ | /* connects to the server through the sock and returns server's welcome */ | |||
void pop3_disconnect(int sock); | void pop3_disconnect(pop3sock_t sock); | |||
/* close socket */ | /* close socket */ | |||
/**************** | /**************** | |||
* pop3 queries * | * pop3 queries * | |||
****************/ | ****************/ | |||
char* pop3_user(int sock, const char* name); | char* pop3_user(pop3sock_t sock, const char* name); | |||
/* performs "USER" pop query and returns server's <512 bytes response */ | /* performs "USER" pop query and returns server's <512 bytes response */ | |||
char* pop3_pass(int sock, const char* pw); | char* pop3_pass(pop3sock_t sock, const char* pw); | |||
/* performs "PASS" pop query and return server's <512 bytes response */ | /* performs "PASS" pop query and return server's <512 bytes response */ | |||
char* pop3_quit(int sock); | char* pop3_quit(pop3sock_t sock); | |||
/* performs "QUIT" pop query and returns server's <512 bytes response */ | /* performs "QUIT" pop query and returns server's <512 bytes response */ | |||
char* pop3_stat(int sock); | char* pop3_stat(pop3sock_t sock); | |||
/* performs "STAT" pop query and returns server's <512 bytes response */ | /* performs "STAT" pop query and returns server's <512 bytes response */ | |||
char* pop3_list(int sock, int id); | char* pop3_list(pop3sock_t sock, int id); | |||
/* performs a "LIST" pop query and returns server's (long) response */ | /* performs a "LIST" pop query and returns server's (long) response */ | |||
char* pop3_retr(int sock, int id); | char* pop3_retr(pop3sock_t sock, int id); | |||
/* performs a "RETR" pop query and returns server's (long) response */ | /* performs a "RETR" pop query and returns server's (long) response */ | |||
char* pop3_dele(int sock, int id); | char* pop3_dele(pop3sock_t sock, int id); | |||
/* performs a "DELE" pop query and returns server's <512 bytes response */ | /* performs a "DELE" pop query and returns server's <512 bytes response */ | |||
char* pop3_noop(int sock); | char* pop3_noop(pop3sock_t sock); | |||
/* performs a "NOOP" pop query and returns server's <512 bytes response */ | /* performs a "NOOP" pop query and returns server's <512 bytes response */ | |||
char* pop3_rset(int sock); | char* pop3_rset(pop3sock_t sock); | |||
/* performs a "RSET" pop query and returns server's <512 bytes response */ | /* performs a "RSET" pop query and returns server's <512 bytes response */ | |||
char* pop3_top(int sock, int id, int lines); | char* pop3_top(pop3sock_t sock, int id, int lines); | |||
/* performs a "TOP" pop query and returns server's (long) response */ | /* performs a "TOP" pop query and returns server's (long) response */ | |||
char* pop3_uidl(int sock, int id); | char* pop3_uidl(pop3sock_t sock, int id); | |||
/* performs a "UIDL" pop query and returns server's (long) response */ | /* performs a "UIDL" pop query and returns server's (long) response */ | |||
char* pop3_apop(int sock, const char* name, const char* digest); | char* pop3_apop(pop3sock_t sock, const char* name, const char* digest); | |||
/* performs a "APOP" secure pop query and returns server's <512 bytes respo nse */ | /* performs a "APOP" secure pop query and returns server's <512 bytes respo nse */ | |||
/* this one is not in the API, just for libspopc internal use: */ | ||||
char* recv_rest(int sock, char* buf, int cs, int bs); | ||||
/* recv rest of data through sock, given a cs bytes filled buffer of total | ||||
size bs */ | ||||
/* end of data is assumed when data has a "\n.\n" or "\n.\0" string */ | ||||
/********************* | /********************* | |||
* parsing utilities * | * parsing utilities * | |||
*********************/ | *********************/ | |||
#define DOTBEGIN(s) ((s)[0]=='\n'&&(s)[1]=='.') | #define DOTBEGIN(s) ((s)[0]=='\n'&&(s)[1]=='.') | |||
int dotline(char* buf); | int dotline(char* buf); | |||
/* returns 1 if buf contains a "\n.\n" or "\n.\0" or \r.(etc) substring */ | /* returns 1 if buf contains a "\n.\n" or "\n.\0" or \r.(etc) substring */ | |||
/* buf must be erminated by '\0' */ | /* buf must be terminated by '\0' */ | |||
int pop3_error(char* string); | int pop3_error(char* string); | |||
/* returns 1 if pop server error reply (i.e : -ERR ...) */ | /* returns 1 if pop server error reply (i.e : -ERR ...) */ | |||
/************************************ | /************************************ | |||
* reply re-formatting, after query * | * reply re-formatting, after query * | |||
************************************/ | ************************************/ | |||
char* nextline(char* string); | char* nextline(char* string); | |||
/* returns a pointer to the next line of given string */ | /* returns a pointer to the next line of given string */ | |||
skipping to change at line 158 | skipping to change at line 202 | |||
char* uidli2sig(char* resp); | char* uidli2sig(char* resp); | |||
/* grep the pop signature of *one* message signature reply*/ | /* grep the pop signature of *one* message signature reply*/ | |||
/* should only be called on data received by a pop3_uidl(sock,ID) request * / | /* should only be called on data received by a pop3_uidl(sock,ID) request * / | |||
/* do not use it after a pop3_uidl(sock,0) ! */ | /* do not use it after a pop3_uidl(sock,0) ! */ | |||
/*************************************************** | /*************************************************** | |||
* high-level API for a SIMPLE MDA/MUA * | * high-level API for a SIMPLE MDA/MUA * | |||
***************************************************/ | ***************************************************/ | |||
/************************************************************************** **** | /************************************************************************** **** | |||
* This is the high-level API of libspopc and it is recommended to use it | * This is the high-level API of libspopc and it is recommended to use it | |||
* | * instead of the low-level one. This high-level API, in spite of its very | |||
* instead of the low-level one. This high-level API, in spite of its very | * 'teasing' name, just provides a *very simple* way to access and query a | |||
* | * pop3 server with your e-mail client. This API handles pop3 in a very | |||
* 'teasing' name, just provides a *very simple* way to access and query a | * convenient manner for the non 'socket-aware' C developper. | |||
* | ||||
* pop3 server with your e-mail client. This API handles pop3 in a very | ||||
* | ||||
* convenient manner for the non 'socket-aware' C developper. | ||||
* | ||||
************************************************************************** ****/ | ************************************************************************** ****/ | |||
typedef enum{AUTHORIZATION,TRANSACTION,UPDATE}popstate; | typedef enum{AUTHORIZATION,TRANSACTION,UPDATE}popstate; | |||
/* pop server states definition from RFC 1725*/ | /* pop server states definition from RFC 1725, not used here actually */ | |||
typedef struct{ | typedef struct{ | |||
int sock;/* socket descriptor */ | pop3sock_t sock;/* socket descriptor */ | |||
struct sockaddr_in* connection; | struct sockaddr_in* connection; | |||
struct hostent* server; | struct hostent* server; | |||
popstate state;/* pop server state */ | popstate state;/* pop server state */ | |||
int* list;/* pop messages size list */ | int* list;/* pop messages size list */ | |||
char** uidl;/* pop messages signature list */ | char** uidl;/* pop messages signature list */ | |||
int bytes;/* total stored (in bytes) on pop server */ | int bytes;/* total stored (in bytes) on pop server */ | |||
int last;/* last message id */ | int last;/* last message id */ | |||
int del;/* 0|1 flag to ask deletion of retrieved messages */ | int del;/* 0|1 flag to ask deletion of retrieved messages */ | |||
}popsession; | }popsession; | |||
End of changes. 23 change blocks. | ||||
46 lines changed or deleted | 97 lines changed or added | |||