1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- /**
- * saop: smtp authentication over pop3
- * Copyright (C) 2007 Juan José Gutiérrez de Quevedo <juanjo@iteisa.com>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; version 2 of the License
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * @author Juan José Gutiérrez de Quevedo <juanjo@iteisa.com>
- */
- #ifndef UTILS_H
- #define UTILS_H
- #include <assert.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <unistd.h>
- #include <string.h>
- #ifdef WIN32
- #include <winsock2.h>
- #include <ws2tcpip.h>
- #else
- #include <sys/socket.h>
- #include <netdb.h>
- #include <arpa/inet.h>
- #include <netinet/in.h>
- #include <sys/select.h>
- #endif /* WIN32 */
- #define BUFLEN 512 /* max length of strings */
- #ifndef MSG_NOSIGNAL
- #define MSG_NOSIGNAL 0
- #endif /* MSG_NOSIGNAL */
- /* utility macros */
- #define cmp(x,y) (NULL==x||NULL==y||strncasecmp(x,y,strlen(y)))
- #define write_string(x,y) do { debug(y); debug("Writing string " #y " to socket " #x); send(x,y,strlen(y),MSG_NOSIGNAL); send(x,"\r\n",2,MSG_NOSIGNAL); } while(0)
- #define condfree(x) do { debug("Freeing memory block " #x); if(NULL!=x) free(x); x=NULL; } while(0)
- #ifndef WIN32
- #define safestrdup(x,y) do { assert(NULL!=y); if(NULL==(x=strndup(y,strlen(y)))) { perror("Error duplicating string"); exit(-1); } } while(0)
- #define closeskt(x); do { if(-1!=x) { debug("Closing socket " #x); close(x); x=-1; } } while(0)
- #else
- #define safestrdup(x,y) do { assert(NULL!=y); if(NULL==(x=strdup(y))) { perror("Error duplicating string"); exit(-1); } } while(0)
- #define closeskt(x); do { if(-1!=x) { debug("Closing socket " #x); closesocket(x); x=-1; } } while(0)
- #endif /* WIN32 */
- #define _(x) x
- #define MAX(x,y) (((x)>(y))?(x):(y))
- #define free_and_read_string(x,y) do { condfree(x); x=read_string(y); } while(0)
- #ifdef DEBUG
- #define debug(x) do { if(NULL==fsaopdebug) { fsaopdebug=fopen("c:\\saop.log","a"); } if(NULL!=fsaopdebug) { fprintf(fsaopdebug,"%s\n",x); fflush(fsaopdebug); } fprintf(stderr,"%s\n",x); fflush(stderr); } while(0)
- #else
- #define debug(x) do {} while(0)
- #endif /* DEBUG */
- char *read_string(int);
- int create_listening_socket(unsigned int);
- int create_connected_socket(char *,unsigned int);
- unsigned long resolve(char *);
- unsigned char can_read(int,float);
- #endif /* UTILS_H */
|