7be7182c0d6beef40a6f20c61e859932e9da1b10
[citadel.git] / citadel / server.h
1 typedef pthread_t THREAD;
2
3
4 struct ExpressMessage {
5         struct ExpressMessage *next;
6         char em_text[300];
7         };
8
9 /*
10  * Here's the big one... the Citadel context structure.
11  *
12  * This structure keeps track of all information relating to a running 
13  * session on the server.  We keep one of these for each session thread.
14  *
15  * Note that the first element is "*next" so that it may be used without
16  * modification in a linked list.
17  */
18 struct CitContext {
19         struct CitContext *next;        /* Link to next session in the list */
20
21         struct usersupp usersupp;       /* Database record buffers */
22         struct quickroom quickroom;
23         
24         long *msglist;
25         int num_msgs;
26
27         char curr_user[32];             /* name of current user */
28         int logged_in;                  /* logged in */
29         int internal_pgm;               /* authenticated as internal program */
30         char temp[32];                  /* temp file name */
31         int nologin;                    /* not allowed to log in */
32
33         char net_node[32];
34         THREAD mythread;
35         int client_socket;
36         struct ExpressMessage *FirstExpressMessage;
37         int cs_pid;                     /* session ID */
38         char cs_room[20];               /* current room */
39         time_t cs_lastupdt;             /* time of last update */
40         time_t lastcmd;                 /* time of last command executed */
41         time_t lastidle;                /* For computing idle time */
42         char lastcmdname[5];            /* name of last command executed */
43         unsigned cs_flags;              /* miscellaneous flags */
44
45                                         /* feeping creaturisms... */
46         int cs_clientdev;               /* client developer ID */
47         int cs_clienttyp;               /* client type code */
48         int cs_clientver;               /* client version number */
49         char cs_clientname[32];         /* name of client software */
50         char cs_host[25];               /* host logged in from */
51
52         FILE *download_fp;              /* Fields relating to file transfer */
53         FILE *upload_fp;
54         char upl_file[256];
55         char upl_path[256];
56         char upl_comment[256];
57         char upl_filedir[256];
58         char chat_room[20];             /* The chat room */
59         char dl_is_net;
60         char upload_type;
61
62         char ucache_name[32];           /* For a performance boost, we cache */
63         long ucache_pos;                /* the position of the last user rec */
64         char fake_username[32];         /* Fake username <bc>                */
65         char fake_postname[32];         /* Fake postname <bc>                */
66         char fake_hostname[25];         /* Name of the fake hostname <bc>    */
67         char fake_roomname[20];         /* Name of the fake room <bc>        */
68         char last_pager[32];            /* The username of the last pager    */
69
70         int FloorBeingSearched;         /* This is used by cmd_lrms() etc.   */
71
72         int CtdlErrno;                  /* Error return for CitadelAPI calls */
73         };
74
75 typedef struct CitContext t_context;
76
77 #define CS_STEALTH      1               /* stealth mode */
78 #define CS_CHAT         2               /* chat mode */
79 #define CS_POSTING      4               /* Posting */
80
81 struct CitContext *MyContext(void);
82 #define CC ((struct CitContext *)MyContext())
83
84 extern struct CitContext *ContextList;
85 extern int ScheduledShutdown;
86 extern struct CitControl CitControl;
87
88 struct ChatLine {
89         struct ChatLine *next;
90         int chat_seq;
91         time_t chat_time;
92         char chat_text[256];
93         char chat_room[20];
94         char chat_username[32];
95         };
96
97 /*
98  * Various things we need to lock and unlock
99  */
100 #define S_USERSUPP      0
101 #define S_USER_TRANS    1
102 #define S_QUICKROOM     2
103 #define S_MSGMAIN       3
104 #define S_CALLLOG       4
105 #define S_SESSION_TABLE 5
106 #define S_FLOORTAB      6
107 #define S_CHATQUEUE     7
108 #define S_CONTROL       8
109 #define S_HOUSEKEEPING  9
110 #define MAX_SEMAPHORES  10
111
112
113 /*
114  * Upload types
115  */
116 #define UPL_FILE        0
117 #define UPL_NET         1
118 #define UPL_IMAGE       2
119
120
121
122 /*
123  * Citadel DataBases (define one for each cdb we need to open)
124  */
125 #define CDB_MSGMAIN     0       /* message base                  */
126 #define CDB_USERSUPP    1       /* user file                     */
127 #define CDB_QUICKROOM   2       /* room index                    */
128 #define CDB_FLOORTAB    3       /* floor index                   */
129 #define CDB_MSGLISTS    4       /* room message lists            */
130 #define CDB_VISIT       5       /* user/room relationships       */
131 #define MAXCDB          6       /* total number of CDB's defined */
132
133 struct cdbdata {
134         size_t len;
135         char *ptr;
136         };
137
138
139 /* Structures and declarations for function hooks of various types */
140
141 struct CleanupFunctionHook {
142         struct CleanupFunctionHook *next;
143         void (*h_function_pointer) (void);
144         };
145 extern struct CleanupFunctionHook *CleanupHookTable;
146
147
148 /*
149  * SessionFunctionHook extensions are used for any type of hook for which
150  * the context in which it's being called (which is determined by the event
151  * type) will make it obvious for the hook function to know where to look for
152  * pertinent data.
153  */
154 struct SessionFunctionHook {
155         struct SessionFunctionHook *next;
156         void (*h_function_pointer) (void);
157         int eventtype;
158         };
159 extern struct SessionFunctionHook *SessionHookTable;
160
161 #define EVT_STOP        0       /* Session is terminating */
162 #define EVT_START       1       /* Session is starting */
163 #define EVT_LOGIN       2       /* A user is logging in */
164 #define EVT_NEWROOM     3       /* Changing rooms */
165 #define EVT_LOGOUT      4       /* A user is logging out */
166 #define EVT_SETPASS     5       /* Setting or changing password */
167
168
169 /*
170  * UserFunctionHook extensions are used for any type of hook which implements
171  * an operation on a user or username (potentially) other than the one
172  * operating the current session.
173  */
174 struct UserFunctionHook {
175         struct UserFunctionHook *next;
176         void (*h_function_pointer) (char *username, long usernum);
177         int eventtype;
178         };
179 extern struct UserFunctionHook *UserHookTable;
180
181 #define EVT_PURGEUSER   100     /* Deleting a user */
182 #define EVT_OUTPUTMSG   101     /* Outputting a message */
183
184
185 /* Defines the relationship of a user to a particular room */
186 struct visit {
187         char v_roomname[ROOMNAMELEN];
188         long v_generation;
189         long v_lastseen;
190         unsigned int v_flags;
191         };
192
193 #define V_FORGET        1               /* User has zapped this room        */
194 #define V_LOCKOUT       2               /* User is locked out of this room  */
195 #define V_ACCESS        4               /* Access is granted to this room   */
196
197 #define UA_KNOWN                2
198 #define UA_GOTOALLOWED          4
199 #define UA_HASNEWMSGS           8
200 #define UA_ZAPPED               16