// iChatServerD // this is server daemon program for iChat client. it companions to Windows chat server. // Copyright 2001 by Vlad // Slightly modified by StaX #ifndef ICHATSERV_H #define ICHATSERV_H //#define _XOPEN_SOURCE #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include // used in the list of active users... (i.e. connections) struct tagCLIENTMSG { struct tagCLIENTMSG* next; // int data_size; char data_ptr[0]; // we use smart allocateion, i.e. message data integrated with message header }; enum { CLIENT_USER = 0, CLIENT_INSERVER = 1, CLIENT_OUTSERVER = 2, }; struct tagCLIENT { struct tagCLIENT* next; // int type; // int clientsocket; // socket of client connection struct sockaddr_in clientaddr; // client info // message data... unsigned char* dataptr; // pointer to currently allocated buffer int data_allocsize; // size of allocated buffer int data_msgsize; // size of message being received int data_size; // size of already received data int waitheader; // mode. waitheader or receive message rest char* reason; // break reason text // NULL until connection is identified char* identifier; // connection identifier // send queue // new messages will fall into the end of queue... pthread_mutex_t sq_mutex; struct tagCLIENTMSG* sq; }; typedef struct tagCLIENT CLIENT, USER, SERVER; // struct tagSERVERTIME { struct tagSERVERTIME* next; // char* identifier; // identity of server // last message time pthread_mutex_t time_mutex; char time[20]; }; typedef struct tagSERVERTIME SERVERTIME; // /*#define PT_SERVER 1 #define PT_CLIENT 0 #define PT_UNDEF -1*/ /*struct PROCTYPE { // signed int type; USER* cur_user; // i think that we need other logic, PROCTYPE is actually client record... or USER int clientsocket; // primary storage for socket... };*/ // /*struct CPACKET { char param1[255]; char param2[255]; char param3[255]; };*/ // options, read from config file // listener.c extern int OPT_MINHEADERLENGTH; // data we need to receive prior trying to find message length extern int OPT_INITIALMSGBUFSIZE; // size of memory allocated for each client extern int OPT_ENABLENULLUSER; // enable not identified users to receive broadcast messages extern int OPT_LOGMESSAGES; // enable message logging extern char OPT_SERVERPASSWORD[]; extern char OPT_SERVERNAME[]; extern int OPT_MAXMSGSIZE; // maximum size of allowed message // main.c extern int OPT_REUSEADDR; // force port reusing even if busy by lost connections extern int OPT_USERPORT; // port for listening for users extern int OPT_SERVERPORT; // port for server-linking extern char OPT_LOGFILE[]; // file for logging data extern char OPT_PIDFILE[]; // file where to store program pid // global signal handler events extern int need2restart; extern int need2exit; extern int restarted; // #ifndef DEF_CONFFILE #define OPT_FILE "/etc/ichatsrv.conf" #else #define OPT_FILE DEF_CONFFILE #endif #define DEF_LOGFILE "/var/log/ichatsrvd.log" #define DEF_PIDFILE "/var/run/ichatsrvd.pid" #define DEF_SERVERPASSWORD "password1" // clist.c // function to use with user's list struct tagCLISTITEM { struct tagCLISTITEM* next; }; typedef struct tagCLISTITEM CLISTITEM; struct tagCLIST { pthread_mutex_t mutex; pthread_cond_t empty_cond; struct tagCLISTITEM* head; }; typedef struct tagCLIST CLIST; void clist_init( CLIST* clist ); void clist_clean( CLIST* clist ); void clist_waitempty( CLIST* clist ); void clist_add( CLIST* clist, void* item ); // does not allocate memory void clist_remove( CLIST* clist, void* item ); // no free call here anymore... // still here, but i wish to devise another way to send... without locking // should return 1 to continue traversing, 0 - to break... be sure, this function will be called fromin the global list lock typedef int (*CLIST_ITERATOR)( void* item, void* cookie ); int clist_firstthat( CLIST* clist, CLIST_ITERATOR function, void* cookie ); // 1 - was breaked, 0 - all calls succeded // main.c extern CLIST* userlist; extern CLIST* serverlist; extern CLIST* timelist; // log.c int open_log( void ); // returns FALSE on error, and TRUE upon valid log void close_log( void ); void print2log( const char *msg, ... ); // getword.c #define MAXWORDLEN 128 int getword( FILE* file, char* word, int* newlinep, char* filename ); // options.c int get_options( void ); // parser.c //void analyze_buf( char *buf, struct CPACKET *pack ); // listener.c CLIENT* client_create( int clientsocket, struct sockaddr_in* clientaddr, int type ); void client_clean( CLIENT* ); int client_process( CLIENT* ); // returns TRUE on success, or FALSE on error void time_clean( SERVERTIME* ); // devastator.c #ifdef DEVASTATOR void log_message( unsigned char* msg_data, int msg_size, char* from, char* to ); #endif // #endif // end of file