Changeset 4706:b24a7aa8f563 in roaraudio
- Timestamp:
- 01/06/11 09:58:08 (13 years ago)
- Branch:
- default
- Phase:
- public
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
plugins/roard/protocol-gopher.c
r4705 r4706 34 34 #define _SOUND ROAR_GOPHER_TYPE_SOUND 35 35 36 static int scb_status_txt (int client, struct roar_vio_calls * vio, const char * selector, char ** text); 37 36 38 static struct roar_gopher_menu_item g_gopher_root_menu[] = { 37 39 {.type = _INFO, .name = "roard Root Menu"}, 38 {.type = _FILE, .name = "Server Info", .selector = "/info.txt", .host = NULL, .port = 0} 40 {.type = _FILE, .name = "Server Info", .selector = "/info.txt", .host = NULL, .port = 0}, 41 {.type = _FILE, .name = "Server Status", .selector = "/status.txt", .host = NULL, .port = 0} 39 42 }; 40 43 … … 46 49 int dir; 47 50 const char * text; 51 int (*cb)(int client, struct roar_vio_calls * vio, const char * selector, char ** text); 48 52 } g_gopher_items[] = { 49 53 {.selector = "", .type = _DIR, 50 .menu = {.items = g_gopher_root_menu, .items_len = sizeof(g_gopher_root_menu)/sizeof(*g_gopher_root_menu)} 54 .menu = {.items = g_gopher_root_menu, .items_len = sizeof(g_gopher_root_menu)/sizeof(*g_gopher_root_menu)}, 55 .cb = NULL 51 56 }, 52 57 // and again as selector '/' as some clients seems to require it: 53 58 {.selector = "/", .type = _DIR, 54 .menu = {.items = g_gopher_root_menu, .items_len = sizeof(g_gopher_root_menu)/sizeof(*g_gopher_root_menu)} 59 .menu = {.items = g_gopher_root_menu, .items_len = sizeof(g_gopher_root_menu)/sizeof(*g_gopher_root_menu)}, 60 .cb = NULL 55 61 }, 56 {.selector = "/info.txt", .type = _FILE, .text = "Some\nText."} 62 {.selector = "/info.txt", .type = _FILE, .text = "Some\nText.", .cb = NULL}, 63 {.selector = "/status.txt", .type = _FILE, .cb = scb_status_txt} 57 64 }; 58 65 59 66 67 // SCBs: 68 static int scb_status_txt (int client, struct roar_vio_calls * vio, const char * selector, char ** text) { 69 const size_t len = 1024; 70 const char * server_version = NULL; 71 72 if ( DISTRIBUTION_VERSION_STRING[0] == 0 ) { 73 server_version = "roard/" PACKAGE_VERSION " <" DEVICE_VENDOR_STRING ">"; 74 } else { 75 server_version = "roard/" PACKAGE_VERSION " <" DEVICE_VENDOR_STRING "> (" DISTRIBUTION_VERSION_STRING ")"; 76 } 77 78 *text = roar_mm_malloc(1024); 79 if ( *text == NULL ) 80 return -1; 81 82 **text = 0; 83 84 snprintf(*text, len, 85 "Server version: %s\r\n" 86 "Server location: %s\r\n" 87 "Server description: %s\r\n" 88 "\r\n" 89 "Counters current: %llu clients, %llu streams\r\n", 90 server_version, 91 g_config->location, 92 g_config->description, 93 (long long unsigned int)g_counters.cur.clients, 94 (long long unsigned int)g_counters.cur.streams 95 ); 96 97 (*text)[len-1] = 0; 98 return 0; 99 } 100 101 102 // other code: 60 103 static int strip_nl (char * str) { 61 104 register char c; … … 129 172 130 173 memcpy(data, text, len); 131 memcpy(data+len, "\r\n.\r\n\0", 6); 174 //memcpy(data+len, "\r\n.\r\n\0", 6); 175 memcpy(data+len, "\0", 1); 132 176 clients_add_output(client, buf); 133 177 … … 145 189 size_t len = 0; 146 190 void * data; 191 char * text; 147 192 148 193 if ( clients_get_server(client, &cs) == -1 ) { … … 208 253 } 209 254 210 switch (c->type) { 211 case _DIR: 212 funcret = send_menu(client, &(c->menu), vio); 213 break; 214 case _FILE: 215 funcret = send_text(client, c->text, vio); 216 break; 217 default: 218 funcret = -1; 219 break; 255 if ( c->cb != NULL ) { 256 text = NULL; 257 funcret = c->cb(client, vio, inbuf, &text); 258 259 if ( funcret == 0 && text != NULL ) 260 funcret = send_text(client, text, vio); 261 262 if ( text != NULL ) 263 roar_mm_free(text); 264 } else { 265 switch (c->type) { 266 case _DIR: 267 funcret = send_menu(client, &(c->menu), vio); 268 break; 269 case _FILE: 270 funcret = send_text(client, c->text, vio); 271 break; 272 default: 273 funcret = -1; 274 break; 275 } 220 276 } 221 277
Note: See TracChangeset
for help on using the changeset viewer.