11 struct CtdlInternalList {
12 struct CtdlInternalList *next;
17 struct CtdlServerHandle CtdlAppHandle;
18 struct CtdlServInfo CtdlAppServInfo;
23 void logoff(exitcode) {
30 * CtdlInternalNumParms() - discover number of parameters...
32 int CtdlInternalNumParms(char *source)
37 for (a=0; a<strlen(source); ++a)
38 if (source[a]=='|') ++count;
43 * CtdlInternalExtract() - extract a parameter from a series of "|" separated
45 void CtdlInternalExtract(char *dest, char *source, int parmnum)
51 if (strlen(source)==0) {
56 n = CtdlInternalNumParms(source);
63 if ( (parmnum == 0) && (n == 1) ) {
65 for (n=0; n<strlen(dest); ++n)
66 if (dest[n]=='|') dest[n] = 0;
70 while (count++ < parmnum) do {
72 } while( (strlen(buf)>0) && (buf[0]!='|') );
73 if (buf[0]=='|') strcpy(buf,&buf[1]);
74 for (count = 0; count<strlen(buf); ++count)
75 if (buf[count] == '|') buf[count] = 0;
80 * CtdlInternalExtractInt() - CtdlInternalExtract an int parm w/o supplying a buffer
82 int CtdlInternalExtractInt(char *source, int parmnum)
86 CtdlInternalExtract(buf,source,parmnum);
91 * CtdlInternalExtractLong() - CtdlInternalExtract an long parm w/o supplying a buffer
93 long CtdlInternalExtractLong(char *source, long int parmnum)
97 CtdlInternalExtract(buf,source,parmnum);
113 * Programs linked against the Citadel server extension library need to
114 * be called with the following arguments:
115 * 0 - program name (as always)
116 * 1 - server address (usually 127.0.0.1)
117 * 2 - server port number
118 * 3 - internal program secret
122 * 7 - associated client session
132 /* We're really not interested in stdio */
137 /* Bail out if someone tries to run this thing manually */
138 if (argc < 3) exit(1);
140 /* Zeroing out the server handle neatly sets the values of
141 * CtdlAppHandle to sane default values
143 bzero(&CtdlAppHandle, sizeof(struct CtdlServerHandle));
145 /* Now parse the command-line arguments fed to us by the server */
146 for (a=0; a<argc; ++a) switch(a) {
147 case 1: strcpy(CtdlAppHandle.ServerAddress, argv[a]);
149 case 2: CtdlAppHandle.ServerPort = atoi(argv[a]);
151 case 3: strcpy(CtdlAppHandle.ipgmSecret, argv[a]);
153 case 4: strcpy(CtdlAppHandle.UserName, argv[a]);
155 case 5: strcpy(CtdlAppHandle.Password, argv[a]);
157 case 6: strcpy(CtdlAppHandle.InitialRoom, argv[a]);
159 case 7: CtdlAppHandle.AssocClientSession = atoi(argv[a]);
163 /* Connect to the server */
165 attach_to_server(argc, argv);
167 if (buf[0] != '2') exit(1);
169 /* Set up the server environment to our liking */
171 CtdlInternalGetServInfo(&CtdlAppServInfo, 0);
173 sprintf(buf, "IDEN 0|5|006|CitadelAPI Client");
177 if (strlen(CtdlAppHandle.ipgmSecret) > 0) {
178 sprintf(buf, "IPGM %s", CtdlAppHandle.ipgmSecret);
183 if (strlen(CtdlAppHandle.UserName) > 0) {
184 sprintf(buf, "USER %s", CtdlAppHandle.UserName);
187 sprintf(buf, "PASS %s", CtdlAppHandle.Password);
192 sprintf(buf, "GOTO %s", CtdlAppHandle.InitialRoom);
196 serv_puts("GOTO _BASEROOM_");
200 /* Now do the loop. */
203 /* Clean up gracefully and exit. */
209 int CtdlGetLastError() {
214 int CtdlSendExpressMessage(char *ToUser, char *MsgText) {
217 if (strlen(ToUser) + strlen(MsgText) > 248) {
218 CtdlErrno = ERROR + TOO_BIG;
222 sprintf(buf, "SEXP %s|%s", ToUser, MsgText);
226 CtdlErrno = atoi(buf);
227 if (CtdlErrno == OK) CtdlErrno = 0;
233 int CtdlInternalGetUserParam(char *ParamBuf, int ParamNum, char *WhichUser) {
236 sprintf(buf, "AGUP %s", WhichUser);
239 if (buf[0] != '2') return(atoi(buf));
240 CtdlInternalExtract(ParamBuf, &buf[4], ParamNum);
245 int CtdlInternalSetUserParam(char *ParamBuf, int ParamNum, char *WhichUser) {
250 sprintf(buf, "AGUP %s", WhichUser);
253 if (buf[0] != '2') return(atoi(buf));
254 for (a=0; a<8; ++a) {
255 CtdlInternalExtract(¶ms[a][0], &buf[4], a);
257 strcpy(¶ms[ParamNum][0], ParamBuf);
258 strcpy(buf, "ASUP ");
259 for (a=0; a<8; ++a) {
260 strcat(buf, ¶ms[a][0]);
265 if (buf[0] != '2') return(atoi(buf));
272 2 - Flags (see citadel.h)
277 7 - Timestamp of last call
280 int CtdlGetUserPassword(char *buf, char *WhichUser) {
281 CtdlErrno = CtdlInternalGetUserParam(buf, 1, WhichUser);
285 int CtdlSetUserPassword(char *buf, char *WhichUser) {
286 CtdlErrno = CtdlInternalSetUserParam(buf, 1, WhichUser);
290 unsigned int CtdlGetUserFlags(char *WhichUser) {
292 CtdlErrno = CtdlInternalGetUserParam(buf, 2, WhichUser);
293 return((CtdlErrno == 0) ? atoi(buf) : (-1));
296 int CtdlSetUserFlags(unsigned int NewFlags, char *WhichUser) {
298 sprintf(buf, "%u", NewFlags);
299 CtdlErrno = CtdlInternalGetUserParam(buf, 2, WhichUser);
303 int CtdlGetUserTimesCalled(char *WhichUser) {
305 CtdlErrno = CtdlInternalGetUserParam(buf, 3, WhichUser);
306 return((CtdlErrno == 0) ? atoi(buf) : (-1));
309 int CtdlSetUserTimesCalled(int NewValue, char *WhichUser) {
311 sprintf(buf, "%d", NewValue);
312 CtdlErrno = CtdlInternalGetUserParam(buf, 3, WhichUser);
316 int CtdlGetUserMessagesPosted(char *WhichUser) {
318 CtdlErrno = CtdlInternalGetUserParam(buf, 4, WhichUser);
319 return((CtdlErrno == 0) ? atoi(buf) : (-1));
322 int CtdlSetUserMessagesPosted(int NewValue, char *WhichUser) {
324 sprintf(buf, "%d", NewValue);
325 CtdlErrno = CtdlInternalGetUserParam(buf, 4, WhichUser);
329 int CtdlGetUserAccessLevel(char *WhichUser) {
331 CtdlErrno = CtdlInternalGetUserParam(buf, 5, WhichUser);
332 return((CtdlErrno == 0) ? atoi(buf) : (-1));
335 int CtdlSetUserAccessLevel(int NewValue, char *WhichUser) {
338 if ( (NewValue < 1) || (NewValue > 6) ) {
339 return(ERROR + ILLEGAL_VALUE);
342 sprintf(buf, "%d", NewValue);
343 CtdlErrno = CtdlInternalGetUserParam(buf, 5, WhichUser);
347 long CtdlGetUserNumber(char *WhichUser) {
349 CtdlErrno = CtdlInternalGetUserParam(buf, 6, WhichUser);
350 return((CtdlErrno == 0) ? atol(buf) : (-1L));
353 int CtdlSetUserNumber(long NewValue, char *WhichUser) {
355 sprintf(buf, "%ld", NewValue);
356 CtdlErrno = CtdlInternalGetUserParam(buf, 6, WhichUser);
360 time_t CtdlGetUserLastCall(char *WhichUser) {
362 CtdlErrno = CtdlInternalGetUserParam(buf, 7, WhichUser);
363 return((CtdlErrno == 0) ? atol(buf) : (time_t)(-1L));
366 int CtdlSetUserLastCall(time_t NewValue, char *WhichUser) {
368 sprintf(buf, "%ld", NewValue);
369 CtdlErrno = CtdlInternalGetUserParam(buf, 7, WhichUser);
373 int CtdlForEachUser(int (*CallBack)(char *EachUser)) {
374 struct CtdlInternalList *TheList = NULL;
375 struct CtdlInternalList *ptr;
380 if (buf[0] != '1') return(-1);
382 while (serv_gets(buf), strcmp(buf, "000")) {
383 ptr = (struct CtdlInternalList *)
384 malloc(sizeof (struct CtdlInternalList));
386 CtdlInternalExtract(ptr->data, buf, 0);
392 while (TheList != NULL) {
393 (*CallBack)(TheList->data);