* move the marchlist into its own file
authorWilfried Göesgens <willi@citadel.org>
Mon, 24 Aug 2009 19:26:13 +0000 (19:26 +0000)
committerWilfried Göesgens <willi@citadel.org>
Mon, 24 Aug 2009 19:26:13 +0000 (19:26 +0000)
webcit/Makefile.in
webcit/marchlist.c [new file with mode: 0644]
webcit/roomops.c
webcit/webcit.h

index 4940c49aa9e28875e225f21750828f84e1c08614..5ce2c24594c6c0df1592bb495be665fdff98195e 100644 (file)
@@ -42,7 +42,7 @@ setup: setup.o gettext.o
 
 webcit: webserver.o context_loop.o ical_dezonify.o \
        cookie_conversion.o locate_host.o floors.o summary.o \
-       webcit.o auth.o tcp_sockets.o mainmenu.o serv_func.o who.o \
+       webcit.o auth.o tcp_sockets.o mainmenu.o serv_func.o who.o marchlist.o \
        roomops.o messages.o msg_renderers.o userlist.o paging.o sysmsgs.o \
        useredit.o vcard_edit.o preferences.o html2html.o listsub.o \
        graphics.o netconf.o siteconfig.o subst.o \
@@ -56,7 +56,7 @@ webcit: webserver.o context_loop.o ical_dezonify.o \
        ical_maps.o ical_subst.o static.o \
        $(LIBOBJS)
        $(CC) $(LDFLAGS) $(LIBOBJS) $(LIBS) \
-       webserver.o context_loop.o cookie_conversion.o \
+       webserver.o context_loop.o cookie_conversion.o marchlist.o \
        webcit.o auth.o tcp_sockets.o mainmenu.o serv_func.o who.o listsub.o \
        roomops.o messages.o msg_renderers.o userlist.o paging.o sysmsgs.o \
        useredit.o locate_host.o siteconfig.o subst.o vcard_edit.o floors.o \
diff --git a/webcit/marchlist.c b/webcit/marchlist.c
new file mode 100644 (file)
index 0000000..8838cd3
--- /dev/null
@@ -0,0 +1,241 @@
+#include "webcit.h"
+#include "webserver.h"
+
+
+/*
+ * Free a session's march list
+ */
+void free_march_list(wcsession *wcf)
+{
+       struct march *mptr;
+
+       while (wcf->march != NULL) {
+               mptr = wcf->march->next;
+               free(wcf->march);
+               wcf->march = mptr;
+       }
+
+}
+
+
+
+/*
+ * remove a room from the march list
+ */
+void remove_march(const StrBuf *aaa)
+{
+       struct march *mptr, *mptr2;
+
+       if (WC->march == NULL)
+               return;
+
+       if (!strcasecmp(WC->march->march_name, ChrPtr(aaa))) {
+               mptr = WC->march->next;
+               free(WC->march);
+               WC->march = mptr;
+               return;
+       }
+       mptr2 = WC->march;
+       for (mptr = WC->march; mptr != NULL; mptr = mptr->next) {
+               if (!strcasecmp(mptr->march_name, ChrPtr(aaa))) {
+                       mptr2->next = mptr->next;
+                       free(mptr);
+                       mptr = mptr2;
+               } else {
+                       mptr2 = mptr;
+               }
+       }
+}
+
+
+
+/**
+ * \brief Locate the room on the march list which we most want to go to.  
+ * Each room
+ * is measured given a "weight" of preference based on various factors.
+ * \param desired_floor the room number on the citadel server
+ * \return the roomname
+ */
+char *pop_march(int desired_floor)
+{
+       static char TheRoom[128];
+       int TheFloor = 0;
+       int TheOrder = 32767;
+       int TheWeight = 0;
+       int weight;
+       struct march *mptr = NULL;
+
+       strcpy(TheRoom, "_BASEROOM_");
+       if (WC->march == NULL)
+               return (TheRoom);
+
+       for (mptr = WC->march; mptr != NULL; mptr = mptr->next) {
+               weight = 0;
+               if ((strcasecmp(mptr->march_name, "_BASEROOM_")))
+                       weight = weight + 10000;
+               if (mptr->march_floor == desired_floor)
+                       weight = weight + 5000;
+
+               weight = weight + ((128 - (mptr->march_floor)) * 128);
+               weight = weight + (128 - (mptr->march_order));
+
+               if (weight > TheWeight) {
+                       TheWeight = weight;
+                       strcpy(TheRoom, mptr->march_name);
+                       TheFloor = mptr->march_floor;
+                       TheOrder = mptr->march_order;
+               }
+       }
+       return (TheRoom);
+}
+
+
+
+/*
+ * Goto next room having unread messages.
+ *
+ * We want to skip over rooms that the user has already been to, and take the
+ * user back to the lobby when done.  The room we end up in is placed in
+ * newroom - which is set to 0 (the lobby) initially.
+ * We start the search in the current room rather than the beginning to prevent
+ * two or more concurrent users from dragging each other back to the same room.
+ */
+void gotonext(void)
+{
+       char buf[256];
+       struct march *mptr = NULL;
+       struct march *mptr2 = NULL;
+       char room_name[128];
+       StrBuf *next_room;
+       int ELoop = 0;
+
+       /*
+        * First check to see if the march-mode list is already allocated.
+        * If it is, pop the first room off the list and go there.
+        */
+       if (havebstr("startmsg")) {
+                readloop(readnew);
+                return;
+       }
+
+       if (WC->march == NULL) {
+               serv_puts("LKRN");
+               serv_getln(buf, sizeof buf);
+               if (buf[0] == '1')
+                       while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
+                               if (IsEmptyStr(buf)) {
+                                       if (ELoop > 10000)
+                                               return;
+                                       if (ELoop % 100 == 0)
+                                               sleeeeeeeeeep(1);
+                                       ELoop ++;
+                                       continue;                                       
+                               }
+                               extract_token(room_name, buf, 0, '|', sizeof room_name);
+                               if (strcasecmp(room_name, ChrPtr(WC->wc_roomname))) {
+                                       mptr = (struct march *) malloc(sizeof(struct march));
+                                       mptr->next = NULL;
+                                       safestrncpy(mptr->march_name, room_name, sizeof mptr->march_name);
+                                       mptr->march_floor = extract_int(buf, 2);
+                                       mptr->march_order = extract_int(buf, 3);
+                                       if (WC->march == NULL) 
+                                               WC->march = mptr;
+                                       else 
+                                               mptr2->next = mptr;
+                                       mptr2 = mptr;
+                               }
+                               buf[0] = '\0';
+                       }
+               /*
+                * add _BASEROOM_ to the end of the march list, so the user will end up
+                * in the system base room (usually the Lobby>) at the end of the loop
+                */
+               mptr = (struct march *) malloc(sizeof(struct march));
+               mptr->next = NULL;
+               mptr->march_order = 0;
+               mptr->march_floor = 0;
+               strcpy(mptr->march_name, "_BASEROOM_");
+               if (WC->march == NULL) {
+                       WC->march = mptr;
+               } else {
+                       mptr2 = WC->march;
+                       while (mptr2->next != NULL)
+                               mptr2 = mptr2->next;
+                       mptr2->next = mptr;
+               }
+               /*
+                * ...and remove the room we're currently in, so a <G>oto doesn't make us
+                * walk around in circles
+                */
+               remove_march(WC->wc_roomname);
+       }
+       if (WC->march != NULL) {
+               next_room = NewStrBufPlain(pop_march(-1), -1);/*TODO: migrate march to strbuf */
+       } else {
+               next_room = NewStrBufPlain(HKEY("_BASEROOM_"));
+       }
+
+
+       smart_goto(next_room);
+       FreeStrBuf(&next_room);
+}
+
+/*
+ * un-goto the previous room
+ */
+void ungoto(void)
+{
+       StrBuf *Buf;
+
+       if (havebstr("startmsg")) {
+               readloop(readnew);
+               return;
+       }
+
+       if (!strcmp(WC->ugname, "")) {
+               smart_goto(WC->wc_roomname);
+               return;
+       }
+       serv_printf("GOTO %s", WC->ugname);
+       Buf = NewStrBuf();
+       StrBuf_ServGetln(Buf);
+       if (GetServerStatus(Buf, NULL) != 2) {
+               smart_goto(WC->wc_roomname);
+               FreeStrBuf(&Buf);
+               return;
+       }
+       if (WC->uglsn >= 0L) {
+               serv_printf("SLRP %ld", WC->uglsn);
+               StrBuf_ServGetln(Buf);
+       }
+       FlushStrBuf(Buf);
+       StrBufAppendBufPlain(Buf, WC->ugname, -1, 0);
+       strcpy(WC->ugname, "");
+       smart_goto(Buf);
+       FreeStrBuf(&Buf);
+}
+
+
+
+void _gotonext(void) {
+       slrp_highest();
+       gotonext();
+}
+
+
+void dotskip(void) {
+       smart_goto(sbstr("room"));
+}
+
+
+
+
+void 
+InitModule_MARCHLIST
+(void)
+{
+
+       WebcitAddUrlHandler(HKEY("gotonext"), _gotonext, NEED_URL);
+       WebcitAddUrlHandler(HKEY("skip"), gotonext, NEED_URL);
+       WebcitAddUrlHandler(HKEY("ungoto"), ungoto, NEED_URL);
+}
index 48497c9f6885f87bdfaa568380a284837b2425f4..6b668f6f74f42b6b6ca2ca5fed6c67643fe9058d 100644 (file)
@@ -102,52 +102,6 @@ void load_floorlist(StrBuf *Buf)
 }
 
 
-/*
- * Free a session's march list
- */
-void free_march_list(wcsession *wcf)
-{
-       struct march *mptr;
-
-       while (wcf->march != NULL) {
-               mptr = wcf->march->next;
-               free(wcf->march);
-               wcf->march = mptr;
-       }
-
-}
-
-
-
-/*
- * remove a room from the march list
- */
-void remove_march(const StrBuf *aaa)
-{
-       struct march *mptr, *mptr2;
-
-       if (WC->march == NULL)
-               return;
-
-       if (!strcasecmp(WC->march->march_name, ChrPtr(aaa))) {
-               mptr = WC->march->next;
-               free(WC->march);
-               WC->march = mptr;
-               return;
-       }
-       mptr2 = WC->march;
-       for (mptr = WC->march; mptr != NULL; mptr = mptr->next) {
-               if (!strcasecmp(mptr->march_name, ChrPtr(aaa))) {
-                       mptr2->next = mptr->next;
-                       free(mptr);
-                       mptr = mptr2;
-               } else {
-                       mptr2 = mptr;
-               }
-       }
-}
-
-
 
 
 /*
@@ -856,138 +810,6 @@ long gotoroom(const StrBuf *gname)
 }
 
 
-/**
- * \brief Locate the room on the march list which we most want to go to.  
- * Each room
- * is measured given a "weight" of preference based on various factors.
- * \param desired_floor the room number on the citadel server
- * \return the roomname
- */
-char *pop_march(int desired_floor)
-{
-       static char TheRoom[128];
-       int TheFloor = 0;
-       int TheOrder = 32767;
-       int TheWeight = 0;
-       int weight;
-       struct march *mptr = NULL;
-
-       strcpy(TheRoom, "_BASEROOM_");
-       if (WC->march == NULL)
-               return (TheRoom);
-
-       for (mptr = WC->march; mptr != NULL; mptr = mptr->next) {
-               weight = 0;
-               if ((strcasecmp(mptr->march_name, "_BASEROOM_")))
-                       weight = weight + 10000;
-               if (mptr->march_floor == desired_floor)
-                       weight = weight + 5000;
-
-               weight = weight + ((128 - (mptr->march_floor)) * 128);
-               weight = weight + (128 - (mptr->march_order));
-
-               if (weight > TheWeight) {
-                       TheWeight = weight;
-                       strcpy(TheRoom, mptr->march_name);
-                       TheFloor = mptr->march_floor;
-                       TheOrder = mptr->march_order;
-               }
-       }
-       return (TheRoom);
-}
-
-
-
-/*
- * Goto next room having unread messages.
- *
- * We want to skip over rooms that the user has already been to, and take the
- * user back to the lobby when done.  The room we end up in is placed in
- * newroom - which is set to 0 (the lobby) initially.
- * We start the search in the current room rather than the beginning to prevent
- * two or more concurrent users from dragging each other back to the same room.
- */
-void gotonext(void)
-{
-       char buf[256];
-       struct march *mptr = NULL;
-       struct march *mptr2 = NULL;
-       char room_name[128];
-       StrBuf *next_room;
-       int ELoop = 0;
-
-       /*
-        * First check to see if the march-mode list is already allocated.
-        * If it is, pop the first room off the list and go there.
-        */
-       if (havebstr("startmsg")) {
-                readloop(readnew);
-                return;
-       }
-
-       if (WC->march == NULL) {
-               serv_puts("LKRN");
-               serv_getln(buf, sizeof buf);
-               if (buf[0] == '1')
-                       while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
-                               if (IsEmptyStr(buf)) {
-                                       if (ELoop > 10000)
-                                               return;
-                                       if (ELoop % 100 == 0)
-                                               sleeeeeeeeeep(1);
-                                       ELoop ++;
-                                       continue;                                       
-                               }
-                               extract_token(room_name, buf, 0, '|', sizeof room_name);
-                               if (strcasecmp(room_name, ChrPtr(WC->wc_roomname))) {
-                                       mptr = (struct march *) malloc(sizeof(struct march));
-                                       mptr->next = NULL;
-                                       safestrncpy(mptr->march_name, room_name, sizeof mptr->march_name);
-                                       mptr->march_floor = extract_int(buf, 2);
-                                       mptr->march_order = extract_int(buf, 3);
-                                       if (WC->march == NULL) 
-                                               WC->march = mptr;
-                                       else 
-                                               mptr2->next = mptr;
-                                       mptr2 = mptr;
-                               }
-                               buf[0] = '\0';
-                       }
-               /*
-                * add _BASEROOM_ to the end of the march list, so the user will end up
-                * in the system base room (usually the Lobby>) at the end of the loop
-                */
-               mptr = (struct march *) malloc(sizeof(struct march));
-               mptr->next = NULL;
-               mptr->march_order = 0;
-               mptr->march_floor = 0;
-               strcpy(mptr->march_name, "_BASEROOM_");
-               if (WC->march == NULL) {
-                       WC->march = mptr;
-               } else {
-                       mptr2 = WC->march;
-                       while (mptr2->next != NULL)
-                               mptr2 = mptr2->next;
-                       mptr2->next = mptr;
-               }
-               /*
-                * ...and remove the room we're currently in, so a <G>oto doesn't make us
-                * walk around in circles
-                */
-               remove_march(WC->wc_roomname);
-       }
-       if (WC->march != NULL) {
-               next_room = NewStrBufPlain(pop_march(-1), -1);/*TODO: migrate march to strbuf */
-       } else {
-               next_room = NewStrBufPlain(HKEY("_BASEROOM_"));
-       }
-
-
-       smart_goto(next_room);
-       FreeStrBuf(&next_room);
-}
-
-
 /*
  * goto next room
  */
@@ -1010,41 +832,6 @@ void slrp_highest(void)
 }
 
 
-/*
- * un-goto the previous room
- */
-void ungoto(void)
-{
-       StrBuf *Buf;
-
-       if (havebstr("startmsg")) {
-               readloop(readnew);
-               return;
-       }
-
-       if (!strcmp(WC->ugname, "")) {
-               smart_goto(WC->wc_roomname);
-               return;
-       }
-       serv_printf("GOTO %s", WC->ugname);
-       Buf = NewStrBuf();
-       StrBuf_ServGetln(Buf);
-       if (GetServerStatus(Buf, NULL) != 2) {
-               smart_goto(WC->wc_roomname);
-               FreeStrBuf(&Buf);
-               return;
-       }
-       if (WC->uglsn >= 0L) {
-               serv_printf("SLRP %ld", WC->uglsn);
-               StrBuf_ServGetln(Buf);
-       }
-       FlushStrBuf(Buf);
-       StrBufAppendBufPlain(Buf, WC->ugname, -1, 0);
-       strcpy(WC->ugname, "");
-       smart_goto(Buf);
-       FreeStrBuf(&Buf);
-}
-
 typedef struct __room_states {
        char password[SIZ];
        char dirname[SIZ];
@@ -3888,14 +3675,6 @@ void tmplput_RoomName(StrBuf *Target, WCTemplputParams *TP)
        StrBufAppendTemplate(Target, TP, WC->wc_roomname, 0);
 }
 
-void _gotonext(void) {
-       slrp_highest();
-       gotonext();
-}
-
-void dotskip(void) {
-       smart_goto(sbstr("room"));
-}
 
 void _display_private(void) {
        display_private("", 0);
@@ -4117,9 +3896,6 @@ InitModule_ROOMOPS
        RegisterNamespace("ROOMNAME", 0, 1, tmplput_RoomName, 0);
 
        WebcitAddUrlHandler(HKEY("knrooms"), knrooms, 0);
-       WebcitAddUrlHandler(HKEY("gotonext"), _gotonext, NEED_URL);
-       WebcitAddUrlHandler(HKEY("skip"), gotonext, NEED_URL);
-       WebcitAddUrlHandler(HKEY("ungoto"), ungoto, NEED_URL);
        WebcitAddUrlHandler(HKEY("dotgoto"), dotgoto, NEED_URL);
        WebcitAddUrlHandler(HKEY("dotskip"), dotskip, NEED_URL);
        WebcitAddUrlHandler(HKEY("display_private"), _display_private, 0);
index da0e0c717b24f11bb70370e68d15b78cbdf8a741..ad0ce0284bcf3ba423055897493287c5d28b7ce3 100644 (file)
@@ -709,6 +709,8 @@ void save_edit(char *description, char *enter_cmd, int regoto);
 void display_edit(char *description, char *check_cmd,
                  char *read_cmd, char *save_cmd, int with_room_banner);
 long gotoroom(const StrBuf *gname);
+void remove_march(const StrBuf *aaa);
+void dotskip(void);
 void confirm_delete_room(void);
 void validate(void);
 void display_graphics_upload(char *, char *, char *);