#include "webserver.h"
-/**
+/*
* show a list of available users to edit them
* message the header message???
- * preselect which user should be selected in the browser
+ * preselect = which user should be selected in the browser
*/
-void select_user_to_edit(const char *message, const char *preselect)
+void select_user_to_edit(const char *preselect)
{
output_headers(1, 0, 0, 0, 1, 0);
do_template("edituser_select", NULL);
} UserListEntry;
-UserListEntry* NewUserListOneEntry(StrBuf *SerializedUser)
+UserListEntry* NewUserListOneEntry(StrBuf *SerializedUser, const char *Pos)
{
UserListEntry *ul;
ul->UserName = NewStrBuf();
ul->Passvoid = NewStrBuf();
- StrBufExtract_token(ul->UserName, SerializedUser, 0, '|');
- StrBufExtract_token(ul->Passvoid, SerializedUser, 1, '|');
- ul->Flags = (unsigned int)StrBufExtract_long(SerializedUser, 2, '|');
- ul->nLogons = StrBufExtract_int(SerializedUser, 3, '|');
- ul->nPosts = StrBufExtract_int(SerializedUser, 4, '|');
- ul->AccessLevel = StrBufExtract_int(SerializedUser, 5, '|');
- ul->UID = StrBufExtract_int(SerializedUser, 6, '|');
- ul->LastLogonT = StrBufExtract_long(SerializedUser, 7, '|');
- ul->DaysTillPurge = StrBufExtract_int(SerializedUser, 8, '|');
+ StrBufExtract_NextToken(ul->UserName, SerializedUser, &Pos, '|');
+ StrBufExtract_NextToken(ul->Passvoid, SerializedUser, &Pos, '|');
+ ul->Flags = StrBufExtractNext_unsigned_long(SerializedUser, &Pos, '|');
+ ul->nLogons = StrBufExtractNext_int( SerializedUser, &Pos, '|');
+ ul->nPosts = StrBufExtractNext_int( SerializedUser, &Pos, '|');
+ ul->AccessLevel = StrBufExtractNext_int( SerializedUser, &Pos, '|');
+ ul->UID = StrBufExtractNext_int( SerializedUser, &Pos, '|');
+ ul->LastLogonT = StrBufExtractNext_long( SerializedUser, &Pos, '|');
+ ul->DaysTillPurge = StrBufExtractNext_int( SerializedUser, &Pos, '|');
return ul;
}
UserListEntry* NewUserListEntry(StrBuf *SerializedUserList)
{
+ const char *Pos = NULL;
UserListEntry *ul;
if (StrLength(SerializedUserList) < 8)
ul->UserName = NewStrBuf();
ul->Passvoid = NewStrBuf();
- StrBufExtract_token(ul->UserName, SerializedUserList, 0, '|');
- ul->AccessLevel = StrBufExtract_int(SerializedUserList, 1, '|');
- ul->UID = StrBufExtract_int(SerializedUserList, 2, '|');
- ul->LastLogonT = StrBufExtract_long(SerializedUserList, 3, '|');
- ul->nLogons = StrBufExtract_int(SerializedUserList, 4, '|');
- ul->nPosts = StrBufExtract_int(SerializedUserList, 5, '|');
- StrBufExtract_token(ul->Passvoid, SerializedUserList, 6, '|');
+ StrBufExtract_NextToken(ul->UserName, SerializedUserList, &Pos, '|');
+ ul->AccessLevel = StrBufExtractNext_int( SerializedUserList, &Pos, '|');
+ ul->UID = StrBufExtractNext_int( SerializedUserList, &Pos, '|');
+ ul->LastLogonT = StrBufExtractNext_long(SerializedUserList, &Pos, '|');
+ ul->nLogons = StrBufExtractNext_int( SerializedUserList, &Pos, '|');
+ ul->nPosts = StrBufExtractNext_int( SerializedUserList, &Pos, '|');
+ StrBufExtract_NextToken(ul->Passvoid, SerializedUserList, &Pos, '|');
ul->Flags = 0;
ul->DaysTillPurge = -1;
return ul;
return strcmp(ChrPtr(u1->UserName), ChrPtr(u2->UserName));
}
+
int CompareUserListNameRev(const void *vUser1, const void *vUser2)
{
UserListEntry *u1 = (UserListEntry*) GetSearchPayload(vUser1);
UserListEntry *u2 = (UserListEntry*) GetSearchPayload(vUser2);
return strcmp(ChrPtr(u2->UserName), ChrPtr(u1->UserName));
}
+
int GroupchangeUserListName(const void *vUser1, const void *vUser2)
{
UserListEntry *u1 = (UserListEntry*) vUser1;
}
/*
- * Sort by AccessLevel
+ * Sort by access level
*/
int CompareAccessLevel(const void *vUser1, const void *vUser2)
{
return (u1->AccessLevel > u2->AccessLevel);
}
+
int CompareAccessLevelRev(const void *vUser1, const void *vUser2)
{
UserListEntry *u1 = (UserListEntry*) GetSearchPayload(vUser1);
return (u2->AccessLevel > u1->AccessLevel);
}
+
int GroupchangeAccessLevel(const void *vUser1, const void *vUser2)
{
UserListEntry *u1 = (UserListEntry*) vUser1;
return u2->AccessLevel != u1->AccessLevel;
}
-
/*
* Sort by UID
*/
return (u1->UID > u2->UID);
}
+
int CompareUIDRev(const void *vUser1, const void *vUser2)
{
UserListEntry *u1 = (UserListEntry*) GetSearchPayload(vUser1);
return (u2->UID > u1->UID);
}
+
int GroupchangeUID(const void *vUser1, const void *vUser2)
{
UserListEntry *u1 = (UserListEntry*) vUser1;
return (u1->LastLogonT > u2->LastLogonT);
}
+
int CompareLastLogonRev(const void *vUser1, const void *vUser2)
{
UserListEntry *u1 = (UserListEntry*) GetSearchPayload(vUser1);
return (u2->LastLogonT > u1->LastLogonT);
}
+
int GroupchangeLastLogon(const void *vUser1, const void *vUser2)
{
UserListEntry *u1 = (UserListEntry*) vUser1;
return (u1->nLogons > u2->nLogons);
}
+
int ComparenLogonsRev(const void *vUser1, const void *vUser2)
{
UserListEntry *u1 = (UserListEntry*) GetSearchPayload(vUser1);
return (u2->nLogons > u1->nLogons);
}
+
int GroupchangenLogons(const void *vUser1, const void *vUser2)
{
UserListEntry *u1 = (UserListEntry*) vUser1;
return (u1->nPosts > u2->nPosts);
}
+
int ComparenPostsRev(const void *vUser1, const void *vUser2)
{
UserListEntry *u1 = (UserListEntry*) GetSearchPayload(vUser1);
return (u2->nPosts > u1->nPosts);
}
+
int GroupchangenPosts(const void *vUser1, const void *vUser2)
{
UserListEntry *u1 = (UserListEntry*) vUser1;
memset(&SubTP, 0, sizeof(WCTemplputParams));
serv_puts("LIST");
Buf = NewStrBuf();
- StrBuf_ServGetlnBuffered(Buf);
+ StrBuf_ServGetln(Buf);
if (GetServerStatus(Buf, NULL) == 1) {
Hash = NewHash(1, NULL);
while (!Done) {
- len = StrBuf_ServGetlnBuffered(Buf);
+ len = StrBuf_ServGetln(Buf);
if ((len == 3) &&
(strcmp(ChrPtr(Buf), "000")==0)) {
Done = 1;
* Locate the message number of a user's vCard in the current room
* Returns the message id of his vcard
*/
-long locate_user_vcard_in_this_room(message_summary **VCMsg,
- wc_mime_attachment **VCAtt)
+long locate_user_vcard_in_this_room(message_summary **VCMsg, wc_mime_attachment **VCAtt)
{
wcsession *WCC = WC;
HashPos *at;
void *vMsg;
message_summary *Msg;
wc_mime_attachment *Att;
-
-
int Done;
StrBuf *Buf;
long vcard_msgnum = (-1L);
StrBuf *FoundCharset = NewStrBuf();
StrBuf *Error = NULL;
-
Buf = NewStrBuf();
TRYAGAIN:
Done = 0;
- /** Search for the user's vCard */
- if (load_msg_ptrs("MSGS ALL||||1", 1) > 0) {
+ /* Search for the user's vCard */
+ if (load_msg_ptrs("MSGS ALL||||1", 1, NULL, NULL) > 0) {
at = GetNewHashPos(WCC->summ, 0);
while (GetNextHashPos(WCC->summ, at, &HKLen, &HashKey, &vMsg)) {
Msg = (message_summary*) vMsg;
memset(Msg->MsgBody, 0, sizeof(wc_mime_attachment));
Msg->MsgBody->msgnum = Msg->msgnum;
- load_message(Msg,
- FoundCharset,
- &Error);
+ load_message(Msg, FoundCharset, &Error);
if (Msg->AllAttach != NULL) {
att = GetNewHashPos(Msg->AllAttach, 0);
while (GetNextHashPos(Msg->AllAttach, att, &HKLen, &HashKey, &vMsg)) {
Att = (wc_mime_attachment*) vMsg;
- if ( (strcasecmp(ChrPtr(Att->ContentType), "text/x-vcard") == 0) ||
- (strcasecmp(ChrPtr(Att->ContentType), "text/vcard") == 0) ) {
+ if (
+ (strcasecmp(ChrPtr(Att->ContentType), "text/x-vcard") == 0)
+ || (strcasecmp(ChrPtr(Att->ContentType), "text/vcard") == 0)
+ ) {
*VCAtt = Att;
*VCMsg = Msg;
- if (Att->Data == NULL)
+ if (Att->Data == NULL) {
MimeLoadData(Att);
+ vcard_msgnum = Msg->msgnum;
+ }
}
}
+ DeleteHashPos(&att);
}
- FreeStrBuf(&Error); /*< don't care... */
+ FreeStrBuf(&Error); /* don't care... */
}
DeleteHashPos(&at);
}
- /** If there's no vcard, create one */
+
+ /* If there's no vcard, create one */
if ((*VCMsg == NULL) && (already_tried_creating_one == 0)) {
already_tried_creating_one = 1;
serv_puts("ENT0 1|||4");
- StrBuf_ServGetlnBuffered(Buf);
+ StrBuf_ServGetln(Buf);
if (GetServerStatus(Buf, NULL) != 4) {
serv_puts("Content-type: text/x-vcard");
serv_puts("");
goto TRYAGAIN;
}
FreeStrBuf(&Buf);
+ FreeStrBuf(&FoundCharset);
+
return(vcard_msgnum);
}
-/**
+/*
* Display the form for editing a user's address book entry
* username the name of the user
* usernum the citadel-uid of the user
*/
void display_edit_address_book_entry(const char *username, long usernum) {
+ wcsession *WCC = WC;
message_summary *VCMsg = NULL;
wc_mime_attachment *VCAtt = NULL;
StrBuf *roomname;
StrBuf *Buf;
- char error_message[SIZ];
long vcard_msgnum = (-1L);
- /** Locate the user's config room, creating it if necessary */
+ /* Locate the user's config room, creating it if necessary */
Buf = NewStrBuf();
roomname = NewStrBuf();
StrBufPrintf(roomname, "%010ld.%s", usernum, USERCONFIGROOM);
serv_printf("GOTO %s||1", ChrPtr(roomname));
- StrBuf_ServGetlnBuffered(Buf);
+ StrBuf_ServGetln(Buf);
if (GetServerStatus(Buf, NULL) != 2) {
serv_printf("CRE8 1|%s|5|||1|", ChrPtr(roomname));
- StrBuf_ServGetlnBuffered(Buf);
+ StrBuf_ServGetln(Buf);
GetServerStatus(Buf, NULL);
serv_printf("GOTO %s||1", ChrPtr(roomname));
- StrBuf_ServGetlnBuffered(Buf);
+ StrBuf_ServGetln(Buf);
if (GetServerStatus(Buf, NULL) != 2) {
- StrBufCutLeft(Buf, 4);
- sprintf(error_message,
- "<img src=\"static/error.gif\" align=center>"
- "%s<br /><br />\n", ChrPtr(Buf));
- select_user_to_edit(error_message, username);
+ FlushStrBuf(WCC->ImportantMsg);
+ StrBufAppendBuf(WCC->ImportantMsg, Buf, 4);
+ select_user_to_edit(username);
FreeStrBuf(&Buf);
FreeStrBuf(&roomname);
return;
locate_user_vcard_in_this_room(&VCMsg, &VCAtt);
if (VCMsg == NULL) {
- sprintf(error_message,
- "<img src=\"static/error.gif\" align=center>%s<br /><br />\n",
- _("An error occurred while trying to create or edit this address book entry.")
- );
- select_user_to_edit(error_message, username);
+ StrBufPlain(WCC->ImportantMsg,
+ _("An error occurred while trying to create or edit this address book entry."),
+ 0);
+ select_user_to_edit(username);
FreeStrBuf(&roomname);
return;
}
void display_edituser(const char *supplied_username, int is_new) {
+ const char *Pos;
+ wcsession *WCC = WC;
UserListEntry* UL;
StrBuf *Buf;
- char error_message[1024];
char username[256];
if (supplied_username != NULL) {
Buf = NewStrBuf();
serv_printf("AGUP %s", username);
- StrBuf_ServGetlnBuffered(Buf);
+ StrBuf_ServGetln(Buf);
if (GetServerStatus(Buf, NULL) != 2) {
- StrBufCutLeft(Buf, 4);
- /*TODO ImportantMessage */
- sprintf(error_message,
- "<img src=\"static/error.gif\" align=center>"
- "%s<br /><br />\n", ChrPtr(Buf));
- select_user_to_edit(error_message, username);
+ FlushStrBuf(WCC->ImportantMsg);
+ StrBufAppendBuf(WCC->ImportantMsg, Buf, 4);
+ select_user_to_edit(username);
FreeStrBuf(&Buf);
return;
}
else {
- StrBufCutLeft(Buf, 4);
- UL = NewUserListOneEntry(Buf);
+ Pos = ChrPtr(Buf) + 4;
+ UL = NewUserListOneEntry(Buf, Pos);
if ((UL != NULL) && havebstr("edit_abe_button")) {
display_edit_address_book_entry(username, UL->UID);
}
FreeStrBuf(&Buf);
}
-/**
+/*
* do the backend operation of the user edit on the server
*/
void edituser(void) {
- char message[SIZ];
+ wcsession *WCC = WC;
int is_new = 0;
unsigned int flags = 0;
const char *username;
is_new = ibstr("is_new");
- safestrncpy(message, "", sizeof message);
username = bstr("username");
if (!havebstr("ok_button")) {
- safestrncpy(message, _("Changes were not saved."), sizeof message);
+ StrBufPlain(WCC->ImportantMsg, _("Changes were not saved."), -1);
}
else {
StrBuf *Buf = NewStrBuf();
if ((havebstr("newname")) && (strcasecmp(bstr("username"), bstr("newname")))) {
serv_printf("RENU %s|%s", bstr("username"), bstr("newname"));
- StrBuf_ServGetlnBuffered(Buf);
+ StrBuf_ServGetln(Buf);
if (GetServerStatus(Buf, NULL) == 2) {
- StrBufCutLeft(Buf, 4);
- sprintf(&message[strlen(message)],
- "<img src=\"static/error.gif\" align=center>"
- "%s<br /><br />\n", ChrPtr(Buf));
+ FlushStrBuf(WCC->ImportantMsg);
+ StrBufAppendBuf(WCC->ImportantMsg, Buf, 4);
}
else {
username = bstr("newname");
bstr("lastcall"),
bstr("purgedays")
);
- StrBuf_ServGetlnBuffered(Buf);
+ StrBuf_ServGetln(Buf);
if (GetServerStatus(Buf, NULL) == 2) {
- StrBufCutLeft(Buf, 4);
- sprintf(&message[strlen(message)],
- "<img src=\"static/error.gif\" align=center>"
- "%s<br /><br />\n", ChrPtr(Buf));
+ StrBufAppendBuf(WCC->ImportantMsg, Buf, 4);
}
FreeStrBuf(&Buf);
}
- /**
+ /*
* If we are in the middle of creating a new user, move on to
* the vCard edit screen.
*/
display_edit_address_book_entry(username, lbstr("usernum") );
}
else {
- select_user_to_edit(message, username);
+ select_user_to_edit(username);
}
}
* username the name of the user to remove
*/
void delete_user(char *username) {
+ wcsession *WCC = WC;
StrBuf *Buf;
- char message[SIZ];
-
+
Buf = NewStrBuf();
serv_printf("ASUP %s|0|0|0|0|0|", username);
- StrBuf_ServGetlnBuffered(Buf);
- if (GetServerStatus(Buf, NULL) == 2) {
- StrBufCutLeft(Buf, 4);
- sprintf(message,
- "<img src=\"static/error.gif\" align=center>"
- "%s<br /><br />\n", ChrPtr(Buf));
- }
- else {
- safestrncpy(message, "", sizeof message);
- }
- select_user_to_edit(message, bstr("username"));
+ StrBuf_ServGetln(Buf);
+ if (GetServerStatus(Buf, NULL) != 2)
+ StrBufAppendBuf(WCC->ImportantMsg, Buf, 4);
+
+ select_user_to_edit( bstr("username"));
FreeStrBuf(&Buf);
}
-/**
+/*
* create a new user
* take the web environment username and create it on the citadel server
*/
void create_user(void) {
+ wcsession *WCC = WC;
long FullState;
StrBuf *Buf;
- char error_message[SIZ];
const char *username;
Buf = NewStrBuf();
username = bstr("username");
serv_printf("CREU %s", username);
- StrBuf_ServGetlnBuffered(Buf);
+ StrBuf_ServGetln(Buf);
if (GetServerStatus(Buf, &FullState) == 2) {
sprintf(WC->ImportantMessage, _("A new user has been created."));
display_edituser(username, 1);
}
else if (FullState == 570) {
- sprintf(error_message,
- "<img src=\"static/error.gif\" align=center>"
- "%s<br /><br />\n",
- _("You are attempting to create a new user from within Citadel "
- "while running in host based authentication mode. In this mode, "
- "you must create new users on the host system, not within Citadel.")
- );
- select_user_to_edit(error_message, NULL);
+ StrBufPlain(WCC->ImportantMsg,
+ _("You are attempting to create a new user from within Citadel "
+ "while running in host based authentication mode. In this mode, "
+ "you must create new users on the host system, not within Citadel."),
+ 0);
+ select_user_to_edit(NULL);
}
else {
- StrBufCutLeft(Buf, 4);
- sprintf(error_message,
- "<img src=\"static/error.gif\" align=center>"
- "%s<br /><br />\n", ChrPtr(Buf));
- select_user_to_edit(error_message, NULL);
+ StrBufAppendBuf(WCC->ImportantMsg, Buf, 4);
+ select_user_to_edit(NULL);
}
FreeStrBuf(&Buf);
}
-void _select_user_to_edit(void){select_user_to_edit(NULL, NULL);}
-void _display_edituser(void) {display_edituser(NULL, 0);}
+void _select_user_to_edit(void) {
+ select_user_to_edit(NULL);
+}
+
+
+void _display_edituser(void) {
+ display_edituser(NULL, 0);
+}
+
void
InitModule_USEREDIT