/* * PSYC Manager Daemon, src/classes.h * Copyright (C) 2001 Mark Ralf Thomson * Supervisor: Peter Zehetmayer * Concept: Mark Ralf Thomson */ #include "queue.cc" #define PT_TRANS_TELNET parse_telnet #define PT_TRANS_PSYC parse_psyc class varTable : public HashTable { public: varTable(int sz=101) // sz should be a prime { table = new list[size=sz]; if(!table) throw MemoryException(); } void add(const char *ks,const char *ts) { char * tn; char **pn; if((pn = find(ks)) != NULL) free(*pn); tn = (char*)malloc(strlen(ts)+1); assert(tn); strcpy(tn,ts); insert(ks,tn); } bool del(const char* str) { int i=hash(str); list::iterator b = table[i].begin(); while( b != table[i].end() ) { if( (*b).str == str ) { free((*b).attr); table[i].erase(b); return true; } ++b; } return false; } char * get(const char *ks) { char **tmps; tmps = find(ks); if(tmps != NULL) return *tmps; return (char*)NULL; } ~varTable() { list::iterator b; int i=0; while (i <= size) { b = table[i].begin(); while( b != table[i].end() ) { free((*b).attr); ++b; } i++; } delete[] table; } }; class person; typedef int (*parafunc) (person*,char*, char*); struct params { bool sub; parafunc exec; char* para; char* token; }; class connection { public: int type; /* Connection type (UDP/TCP) */ int fd; char ip[IPLEN+1]; char id[IDLEN+1]; // Id in der form "ip-port", wird im User Hash verwendet char host[HOSTLEN+1]; unsigned short int port; int ptime; /* last time it answers a ping */ }; class personal { public: char nickname[NICKLEN+1]; char realname[NAMELEN+1]; char ident[IDENTLEN+1]; char email[EMAILLEN+1]; char password[PASSLEN+1]; time_t regtime; int wrongpass; // wie oft mit falsches pass versucht wurde }; typedef int (*typfunc) (char *,person*,bool); class person { public: bool ok; // ob objekt gültig ist bool reg; // ob nick in DB registriert ist time_t regtime; typfunc pt_trans; char sessid[IDLEN]; char target[UNLLEN]; char lang[3]; connection conn; personal pers; Equeue recvQ; Equeue sendQ; int rnicks; int client_proto; short int events; varTable *v; // flag flags; person(char *ip,unsigned short int port,int typ,int fd); // Konstruktor void exit(); void send(char *, char *, ...); int rsend(void); ~person() { } }; typedef int (*comfunc) (person*,char(*)[21],char(*)[1024]); struct message { char* cmd; comfunc func; // int (*func) (person*,char(*)[21],char(*)[1024]); unsigned int parameters; char* token; unsigned int flags; }; class nickdb { public: char nick[NICKLEN+1]; //0 char ip[IPLEN+1];// 1 char host[HOSTLEN+1]; // 2 char vhost[HOSTLEN+1]; //3 char realname[NAMELEN+1]; //4 char ident[IDENTLEN+1]; // 5 char email[EMAILLEN+1]; //6 char password[PASSLEN+1]; //7 char stamp_reg[14+1]; //8 char stamp_last[14+1]; //9 char quit_msg[QUITMSGLEN+1]; //10 char port[6+1]; //11 int erase(char*); // angabe des grundes }; class self { public: char name[UNLLEN]; };