-HashList *GetFloorListHash(StrBuf *Target, WCTemplputParams *TP) {
- /* 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 (GetServerStatus(Buf, NULL) == 1)
- while(StrBufTCP_read_line(Buf, &WC->serv_sock, 0, &Err), strcmp(ChrPtr(Buf), "000")) {
- int a;
- const StrBuf *floorNum = NULL;
- floor = NewHash(1, NULL);
- for(a=0; a<FLOOR_PARAM_LEN; a++) {
- Buf2 = NewStrBuf();
- StrBufExtract_token(Buf2, Buf, a, '|');
- if (a==0) {
- floorNum = Buf2; /* hmm, should we copy Buf2 first? */
-
- }
- Put(floor, CKEY(FLOOR_PARAM_NAMES[a]), Buf2, HFreeStrBuf);
- }
- Put(floors, SKEY(floorNum), floor, HDeleteHash);
- }
- 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 (GetServerStatus(buf, NULL) == 1)
- while(StrBufTCP_read_line(buf, &WC->serv_sock, 0, &Err), strcmp(ChrPtr(buf), "000")) {
- int i;
- StrBuf *rmName = NULL;
- room = NewHash(1, NULL);
- for(i=0; i<ROOM_PARAM_LEN; i++) {
- buf2 = NewStrBuf();
- StrBufExtract_token(buf2, buf, i, '|');
- if (i==0) {
- rmName = buf2;
- }
- Put(room, CKEY(ROOM_PARAM_NAMES[i]), buf2, HFreeStrBuf);
- }
- Put(rooms, SKEY(rmName), room, HDeleteHash);
- }
- SortByHashKey(rooms, 1);
- /*SortByPayload(rooms, SortRoomsByListOrder); */
- FreeStrBuf(&buf);
- return rooms;
-}
-/** Unused function that orders rooms by the listorder flag */
-int SortRoomsByListOrder(const void *room1, const void *room2)
-{
- int l1;
- int l2;
- HashList *r1 = (HashList *)GetSearchPayload(room1);
- HashList *r2 = (HashList *)GetSearchPayload(room2);
- StrBuf *listOrderBuf1;
- StrBuf *listOrderBuf2;
-
- GetHash(r1, CKEY(ROOM_PARAM_NAMES[3]), (void *)&listOrderBuf1);
- GetHash(r2, CKEY(ROOM_PARAM_NAMES[3]), (void *)&listOrderBuf2);
- l1 = atoi(ChrPtr(listOrderBuf1));
- l2 = atoi(ChrPtr(listOrderBuf2));
- if (l1 < l2) return -1;
- else if (l1 > l2) return +1;
- else return 0;
-}
-void tmplput_ROOM_Value(StrBuf *TemplBuffer, WCTemplputParams *TP)
-{
- void *value;
- StrBuf *val;
- HashList *room = (HashList *)(TP->Context);
-
- GetHash(room, TKEY(0), &value);
- val = (StrBuf *)value;
- StrECMAEscAppend(TemplBuffer, val, 0);
-}
-void jsonRoomFlr(void)
-{
- /* Send as our own (application/json) content type */
- hprintf("HTTP/1.1 200 OK\r\n");
- hprintf("Content-type: application/json; charset=utf-8\r\n");
- hprintf("Server: %s / %s\r\n", PACKAGE_STRING, ChrPtr(WC->serv_info->serv_software));
- hprintf("Connection: close\r\n");
- hprintf("Pragma: no-cache\r\nCache-Control: no-store\r\nExpires:-1\r\n");
- begin_burst();
- DoTemplate(HKEY("json_roomflr"),NULL,&NoCtx);
- end_burst();
-}
-