2 ** libCxClient - Citadel/UX Extensible Client API
3 ** Copyright (c) 2000, Flaming Sword Productions
4 ** Copyright (c) 2001, The Citadel/UX Consortium
9 ** Last Revision: 2000-10-15
10 ** Description: Functions which manipulate user lists. (who's online, Directory, etc.)
21 ** CxUsOnline(fmt): List online users.
22 ** [fmt]: Format of list you are expecting to receive:
23 ** 0: (Default) Session ID|User|Room
25 CXLIST CxUsOnline(int fmt) {
30 DPF((DFA,"Retrieving online user list"));
35 ** The session protocol specs say that
36 ** this process will never return anything
37 ** but LISTING_FOLLOWS. I don't belive it. ;)
39 if( CHECKRC(rc, RC_LISTING) ) {
43 DPF((DFA,"[%d] %s",rc,buf));
46 toret = (CXLIST)CxLlInsert(toret,buf);
54 ** In the event that the moon IS made of
55 ** green cheese.......
58 DPF((DFA,"Session spec violation!! IG!!! AUGH!!!"));
66 ** CxUsList(): Fetch the Global Address Book.
73 DPF((DFA,"Requesting user list..."));
76 if( CHECKRC(rc, RC_LISTING) ) {
80 toret = CxLlInsert(toret,buf);
89 ** CxUsAuth(): Authenticate a username/password combination. If we're
90 ** already logged in, then we need to abort this. [How can we tell if
94 ** (char *) uname: Username we wish to verify
95 ** (char *) passwd: Password of this user.
98 ** On Success: USERINFO: User Information structure. [*]
101 USERINFO *CxUsAuth(const char *uname, const char *passwd) {
103 char *xmit, buf[512], *g_Ser[20];
106 DPF((DFA,"Authenticating '%s'",uname));
107 xmit = (char *)CxMalloc(strlen(uname)+6);
108 sprintf(xmit,"USER %s",uname);
112 DPF((DFA,"Validating username"));
115 if( CHECKRC(rc, RC_MOREDATA) ) {
116 xmit = (char *)CxMalloc(strlen(passwd)+6);
117 sprintf(xmit,"PASS %s",passwd);
121 DPF((DFA,"Validating password"));
125 ** RETURN: Authentication information O.K.
127 if( CHECKRC(rc, RC_OK) ) {
128 user_info = (USERINFO *)CxMalloc(sizeof(USERINFO));
130 CxSerialize(buf, &g_Ser);
131 strcpy(user_info->username, g_Ser[0]);
132 user_info->system.access_level = atoi(g_Ser[1]);
133 user_info->system.times_called = atol(g_Ser[2]);
134 user_info->system.messages_posted = atol(g_Ser[3]);
135 user_info->system.user_flags = atol(g_Ser[4]);
136 user_info->system.user_number = atol(g_Ser[5]);
137 DPF((DFA,"MEM/MDA:\t-1\t@0x%08x (Needs manual deallocation)", user_info));
142 ** RETURN: Invalid password.
149 ** RETURN: Invalid username
156 ** SHOULD be unreachable...
162 ** CxUsCreate(): Create a user account.
165 ** USERINFO user: Populated USERINFO structure.
169 ** On Failure: 1 - Not enough information
170 ** 2 - USER ALREADY EXISTS
172 int CxUsCreate(USERINFO user) {
177 ** RETURN: Not enough information.
179 if(!user.username[0] || !user.password[0]) return(1);
182 ** Phase 1: Create new account.
184 DPF((DFA,"Creating user account '%s'", user.username));
186 sprintf(buf, "NEWU %s", user.username);
191 ** RETURN: User already exists.
193 if( CHECKRC(rc, RC_OK)) {
197 sprintf(buf, "SETP %s", user.password);
201 if( CHECKRC(rc, RC_OK)) {
202 return(0); /** Non-fatal error. User just has a blank "" password. **/
206 ** Phase 2: Populate registration structures on server.
210 if( CHECKRC(rc, RC_SENDLIST)) {
211 sprintf(buf, "%s", user.fullname);
213 sprintf(buf, "%s", user.addr.street);
215 sprintf(buf, "%s", user.addr.city);
217 sprintf(buf, "%s", user.addr.st);
219 sprintf(buf, "%s", user.addr.zip);
221 sprintf(buf, "%s", user.contact.telephone);
223 sprintf(buf, "%s", user.contact.emailaddr);
229 ** Phase 3: Create personal rooms expected by CxClient. [Please note that this will only work if
230 ** the server's default permissions allow new users to create rooms. bbs.shadowcom.net will.]
234 if( CHECKRC(rc, RC_OK)) {
235 CxClSend("CRE8 1|My Schedule|4||");
237 printf("My Schedule: rc = %d", rc);
238 CxClSend("CRE8 1|My Notes|4||");
240 printf("My Notes: rc = %d", rc);
241 CxClSend("CRE8 1|My Tasks|4||");
243 printf("My Tasks: rc = %d", rc);
244 CxClSend("CRE8 1|My Journal|4||");
246 printf("My Journal: rc = %d", rc);
247 CxClSend("CRE8 1|My Contacts|4||");
249 printf("My Contacts: rc = %d", rc);