minor documentation changes
[citadel.git] / citadel / techdoc / citadelapi.txt
1  Citadel/UX Server Extension API Documentation
2  ---------------------------------------------
3  
4   This is a (very) incomplete documentation of the API for extending the
5 Citadel server using dynamically loaded modules.  It really isn't an API at
6 all, but rather a list of some of the functions available in the server which
7 are likely to be of use to module writers.  
8   
9   Expect this document to become more complete over time, as both the API and
10 the person documenting it have a chance to mature a bit.  :)
11   
12   
13    
14   USER RELATED FUNCTIONS
15   ----------------------
16  
17  The fundamental user data is stored in "struct usersupp" which is defined
18 in citadel.h.  The following functions are available:
19   
20  
21  int getuser(struct usersupp *usbuf, char name[])
22  
23  Given the name of a requested user and a buffer to store the usersupp
24 record in, getuser() will search the userlog for the named user and load its
25 data into the buffer.  getuser() returns 0 upon success or a nonzero error
26 code if the requested operation could not be performed.
27  
28  
29  void putuser(struct usersupp *usbuf, char *name)
30  
31  After reading in a user record with getuser() and perhaps modifying the data
32 in some way, a program may use putuser() to write it back to disk.
33  
34  
35  int lgetuser(struct usersupp *usbuf, char *name)
36  void lputuser(struct usersupp *usbuf, char *name)
37  
38  If critical-section operation is required, this pair of calls may be used.
39 They function the same as getuser() and putuser(), except that lgetuser()
40 locks the user file immediately after retrieving the record and lputuser()
41 unlocks it.  This will guarantee that no other threads manipulate the same
42 user record at the same time.
43  
44  NOTE: do NOT attempt to combine the locking lgetuser/lputuser calls with any
45 other locking calls in this API.  Attempting to obtain concurrent locks on
46 multiple files may result in a deadlock condition which would freeze the
47 entire server.
48  
49    
50  void ForEachUser(void (*CallBack)(struct usersupp *EachUser))
51  
52  This allows a user-supplied function to be called once for each user on
53 the system.  The user-supplied function will be called with a pointer to a
54 usersupp structure as its only argument.
55   
56  
57  int getuserbynumber(struct usersupp *usbuf, long int number)
58  
59  getuserbynumber() functions similarly to getuser(), except that it is
60 supplied with a user number rather than a name.  Calling this function
61 results in a sequential search of the user file, so use it sparingly if at
62 all.
63  
64  
65  int purge_user(char *pname)
66  
67  This function deletes the named user off the system and erases all related
68 objects: bio, photo, etc.  It returns 0 upon success or a nonzero error code
69 if the requested operation could not be performed.
70  
71
72
73  HOW TO REGISTER FUNCTION HOOKS
74  ------------------------------
75  
76  The truly powerful part of the Citadel API is the ability for extensions to
77 register "hooks" -- user-supplied functions will be called while the server
78 is performing various tasks.  Here are the API calls to register hooks:
79  
80    
81  void CtdlRegisterProtoHook(void (*handler)(char *), char *cmd, char *desc)
82   
83  Adds a new server command to the system.  The handler function should accept
84 a single string parameter, which will be set to a string containing any
85 parameters the client software sent along with the server command.  "cmd" 
86 should be the four-character mnemonic the server command is known by, and
87 "desc" is a description of the new command.
88  
89
90  void CtdlRegisterCleanupHook(void *fcn_ptr) 
91  
92  Registers a new function to be called whenever the server is shutting down.
93 Cleanup functions accept no parameters.
94
95  
96 void CtdlRegisterSessionHook(void *fcn_ptr, int EventType) 
97   
98  Registers a session hook.  Session hooks accept no parameters.  There are
99 multiple types of session hooks; the server extension registers which one it
100 is interested in by setting the value of EventType.  The available session
101 hook types are:
102
103 #define EVT_STOP        0       /* Session is terminating */
104 #define EVT_START       1       /* Session is starting */
105 #define EVT_LOGIN       2       /* A user is logging in */
106 #define EVT_NEWROOM     3       /* Changing rooms */
107 #define EVT_LOGOUT      4       /* A user is logging out */
108 #define EVT_SETPASS     5       /* Setting or changing password */
109
110  
111 void CtdlRegisterUserHook(void *fcn_ptr, int EventType) 
112  
113  Registers a user hook.  User hooks accept two parameters: a string pointer
114 containing the user name, and a long which *may* contain a user number (only
115 applicable for certain types of hooks).  The available user hook types are:
116
117 #define EVT_PURGEUSER   100     /* Deleting a user */
118 #define EVT_OUTPUTMSG   101     /* Outputting a message */
119
120
121    
122   FUNCTIONS WHICH MANIPULATE USER/ROOM RELATIONSHIPS
123
124  void CtdlGetRelationship(struct visit *vbuf,
125                         struct usersupp *rel_user,
126                         struct quickroom *rel_room);
127  void CtdlSetRelationship(struct visit *newvisit,
128                         struct usersupp *rel_user,
129                         struct quickroom *rel_room);
130  
131  These functions get/set a "struct visit" structure which may contain
132 information about the relationship between a user and a room.  Specifically:
133
134 struct visit {
135         char v_roomname[20];
136         long v_generation;
137         long v_lastseen;
138         unsigned int v_flags;
139         };
140
141 #define V_FORGET        1               /* User has zapped this room        */
142 #define V_LOCKOUT       2               /* User is locked out of this room  */
143 #define V_ACCESS        4               /* Access is granted to this room   */
144  
145  Don't change v_roomname or v_generation; they're used to identify the room
146 being referred to.  A room is unique to the system by its combination of room
147 name and generation number.  If a new room is created with the same name as
148 a recently deleted room, it will have a new generation number, and therefore
149 stale "visit" records will not be applied (and will eventually be purged).
150  
151  v_lastseen contains the number of the newest message the user has read in
152 this room.  Any existing messages higher than this number can be considered
153 as "new messages."
154  
155  v_flags contains information regarding access to the room.
156  
157   
158  
159  int CtdlRoomAccess(struct quickroom *roombuf, struct usersupp *userbuf)
160  
161  This is a convenience function which uses CtdlGetRelationship() to determine
162 whether a user has access to a room.  It returns a bucket of bits which may
163 contain:
164  
165 #define UA_INUSE                1       /* Room exists */
166 #define UA_KNOWN                2       /* Room is in user's Known list */
167 #define UA_GOTOALLOWED          4       /* User may <.G>oto this room */
168 #define UA_HASNEWMSGS           8       /* Room contains new messages */
169 #define UA_ZAPPED               16      /* User has forgotten this room */