- // todo: check context
- const char *Err;
- StrBuf *Buf;
- StrBuf *Buf2;
- HashList *floors;
- HashList *floor;
- floors = NewHash(1, NULL);
- Buf = NewStrBuf();
- serv_puts("LFLR"); // get floors
- StrBufTCP_read_line(Buf, &WC->serv_sock, 0, &Err); // '100', we hope
- if (ChrPtr(Buf)[0] == '1') while(StrBufTCP_read_line(Buf, &WC->serv_sock, 0, &Err), strcmp(ChrPtr(Buf), "000")) {
- floor = NewHash(1, NULL);
- int a;
- const char *floorNum;
- for(a=0; a<FLOOR_PARAM_LEN; a++) {
- Buf2 = NewStrBuf();
- StrBufExtract_token(Buf2, Buf, a, '|');
- if (a==0) {
- floorNum = ChrPtr(Buf2); // hmm, should we copy Buf2 first?
- }
- Put(floor, FPKEY(a), Buf2, NULL);
- }
- Put(floors, HKEY(floorNum), floor, NULL);
- }
- FreeStrBuf(&Buf);
- return floors;
-}
-
-void tmplput_FLOOR_Value(StrBuf *TemplBuffer, WCTemplputParams *TP) {
- HashList *floor = (HashList *)(TP->Context);
- void *value;
- GetHash(floor, TKEY(0), &value);
- StrBuf *val = (StrBuf *)value;
- StrECMAEscAppend(TemplBuffer, val, 0);
-}
-HashList *GetRoomListHashLKRA(StrBuf *Target, WCTemplputParams *TP) {
- serv_puts("LKRA");
- return GetRoomListHash(Target, TP);
-}
-HashList *GetRoomListHash(StrBuf *Target, WCTemplputParams *TP) {
- // TODO: Check context
- HashList *rooms;
- HashList *room;
- StrBuf *buf;
- StrBuf *buf2;
- const char *Err;
- buf = NewStrBuf();
- rooms = NewHash(1, NULL);
- StrBufTCP_read_line(buf, &WC->serv_sock, 0, &Err);
- if (ChrPtr(buf)[0] == '1') while(StrBufTCP_read_line(buf, &WC->serv_sock, 0, &Err), strcmp(ChrPtr(buf), "000")) {
- room = NewHash(1, NULL);
- int i;
- const char *rmName;
- for(i=0; i<ROOM_PARAM_LEN; i++) {
- buf2 = NewStrBuf();
- StrBufExtract_token(buf2, buf, i, '|');
- if (i==0) {
- rmName = ChrPtr(buf2);
- }
- Put(room, RPKEY(i), buf2, NULL);
- }
- Put(rooms, rmName, strlen(rmName), room, NULL);
- }
- SortByHashKey(rooms, 1);
- //SortByPayload(rooms, SortRoomsByListOrder);
- FreeStrBuf(&buf);
- return rooms;
+ /* todo: check context */
+ const char *Err;
+ StrBuf *Buf;
+ StrBuf *Buf2;
+ HashList *floors;
+ HashList *floor;
+ floors = NewHash(1, NULL);
+ Buf = NewStrBuf();
+ serv_puts("LFLR"); /* get floors */
+ StrBufTCP_read_line(Buf, &WC->serv_sock, 0, &Err); /* '100', we hope */
+ if (ChrPtr(Buf)[0] == '1') while(StrBufTCP_read_line(Buf, &WC->serv_sock, 0, &Err), strcmp(ChrPtr(Buf), "000")) {
+ int a;
+ const char *floorNum;
+ floor = NewHash(1, NULL);
+ for(a=0; a<FLOOR_PARAM_LEN; a++) {
+ Buf2 = NewStrBuf();
+ StrBufExtract_token(Buf2, Buf, a, '|');
+ if (a==0) {
+ floorNum = ChrPtr(Buf2); /* hmm, should we copy Buf2 first? */
+ }
+ Put(floor, FPKEY(a), Buf2, NULL);
+ }
+ Put(floors, HKEY(floorNum), floor, NULL);
+ }
+ FreeStrBuf(&Buf);
+ return floors;
+}
+
+void tmplput_FLOOR_Value(StrBuf *TemplBuffer, WCTemplputParams *TP)
+{
+ StrBuf *val;
+ HashList *floor = (HashList *)(TP->Context);
+ void *value;
+ GetHash(floor, TKEY(0), &value);
+ val = (StrBuf *)value;
+ StrECMAEscAppend(TemplBuffer, val, 0);
+}
+HashList *GetRoomListHashLKRA(StrBuf *Target, WCTemplputParams *TP)
+{
+ serv_puts("LKRA");
+ return GetRoomListHash(Target, TP);
+}
+HashList *GetRoomListHash(StrBuf *Target, WCTemplputParams *TP)
+{
+ /* TODO: Check context */
+ HashList *rooms;
+ HashList *room;
+ StrBuf *buf;
+ StrBuf *buf2;
+ const char *Err;
+ buf = NewStrBuf();
+ rooms = NewHash(1, NULL);
+ StrBufTCP_read_line(buf, &WC->serv_sock, 0, &Err);
+ if (ChrPtr(buf)[0] == '1') while(StrBufTCP_read_line(buf, &WC->serv_sock, 0, &Err), strcmp(ChrPtr(buf), "000")) {
+ int i;
+ const char *rmName;
+ room = NewHash(1, NULL);
+ for(i=0; i<ROOM_PARAM_LEN; i++) {
+ buf2 = NewStrBuf();
+ StrBufExtract_token(buf2, buf, i, '|');
+ if (i==0) {
+ rmName = ChrPtr(buf2);
+ }
+ Put(room, RPKEY(i), buf2, NULL);
+ }
+ Put(rooms, rmName, strlen(rmName), room, NULL);
+ }
+ SortByHashKey(rooms, 1);
+ /*SortByPayload(rooms, SortRoomsByListOrder); */
+ FreeStrBuf(&buf);
+ return rooms;