Changeset 4714:c8403b42e127 in roaraudio
- Timestamp:
- 01/09/11 15:09:11 (13 years ago)
- Branch:
- default
- Phase:
- public
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
plugins/roard/protocol-gopher.c
r4712 r4714 34 34 #define _SOUND ROAR_GOPHER_TYPE_SOUND 35 35 36 static struct item; 37 38 static int scb_status_txt (int client, struct roar_vio_calls * vio, const char * selector, char ** text, struct item * sitem); 39 static int scb_clients (int client, struct roar_vio_calls * vio, const char * selector, char ** text, struct item * sitem); 40 static int scb_streams (int client, struct roar_vio_calls * vio, const char * selector, char ** text, struct item * sitem); 36 struct item; 37 38 static int scb_status_txt (int client, struct roar_vio_calls * vio, char * selector, char ** text, struct item * sitem); 39 static int scb_test (int client, struct roar_vio_calls * vio, char * selector, char ** text, struct item * sitem); 40 static int scb_clients (int client, struct roar_vio_calls * vio, char * selector, char ** text, struct item * sitem); 41 static int scb_streams (int client, struct roar_vio_calls * vio, char * selector, char ** text, struct item * sitem); 41 42 42 43 static struct roar_gopher_menu_item g_gopher_root_menu[] = { … … 55 56 int dir; 56 57 const char * text; 57 int (*cb)(int client, struct roar_vio_calls * vio, c onst char * selector, char ** text, struct item * sitem);58 int (*cb)(int client, struct roar_vio_calls * vio, char * selector, char ** text, struct item * sitem); 58 59 } g_gopher_items[] = { 59 60 {.selector = "", .type = _DIR, … … 68 69 {.selector = "/info.txt", .type = _FILE, .text = "Some\nText.", .cb = NULL}, 69 70 {.selector = "/status.txt", .type = _FILE, .cb = scb_status_txt}, 71 {.selector = "/test/*", .type = _FILE, .cb = scb_test}, 70 72 {.selector = "/clients/", .type = _DIR, .cb = scb_clients}, 71 73 {.selector = "/streams/", .type = _DIR, .cb = scb_streams} … … 80 82 81 83 // SCBs: 82 static int scb_status_txt (int client, struct roar_vio_calls * vio, c onst char * selector, char ** text, struct item * sitem) {84 static int scb_status_txt (int client, struct roar_vio_calls * vio, char * selector, char ** text, struct item * sitem) { 83 85 const size_t len = 1024; 84 86 const char * server_version = NULL; … … 90 92 } 91 93 92 *text = roar_mm_malloc( 1024);94 *text = roar_mm_malloc(len); 93 95 if ( *text == NULL ) 94 96 return -1; … … 113 115 } 114 116 115 static int scb_clients (int client, struct roar_vio_calls * vio, const char * selector, char ** text, struct item * sitem) { 117 static int scb_test(int client, struct roar_vio_calls * vio, char * selector, char ** text, struct item * sitem) { 118 ssize_t toks; 119 char * tok; 120 size_t len; 121 122 toks = strseltok(sitem->selector, selector, &tok, 1); 123 124 if ( toks == -1 ) 125 return -1; 126 127 len = strlen(tok); 128 len += 64; 129 130 *text = roar_mm_malloc(1024); 131 if ( *text == NULL ) 132 return -1; 133 134 **text = 0; 135 136 snprintf(*text, len, "Your text was: %s", tok); 137 138 (*text)[len-1] = 0; 139 140 return 0; 141 } 142 143 static int scb_clients (int client, struct roar_vio_calls * vio, char * selector, char ** text, struct item * sitem) { 116 144 struct roar_gopher_menu_item items[ROAR_CLIENTS_MAX]; 117 145 struct roar_gopher_menu menu = {.flags = 0, .items = items, .items_len = 0}; … … 167 195 } 168 196 169 static int scb_streams (int client, struct roar_vio_calls * vio, c onst char * selector, char ** text, struct item * sitem) {197 static int scb_streams (int client, struct roar_vio_calls * vio, char * selector, char ** text, struct item * sitem) { 170 198 struct roar_gopher_menu_item items[ROAR_STREAMS_MAX]; 171 199 struct roar_gopher_menu menu = {.flags = 0, .items = items, .items_len = 0}; … … 394 422 char * text; 395 423 424 ROAR_DBG("emul_gopher_check_client(client=%i, vio=%p) = ?", client, vio); 425 396 426 if ( clients_get_server(client, &cs) == -1 ) { 397 427 clients_delete(client); 398 428 return -1; 399 429 } 430 431 ROAR_DBG("emul_gopher_check_client(client=%i, vio=%p) = ?", client, vio); 400 432 401 433 if ( vio == NULL ) { … … 403 435 roar_vio_open_fh_socket(vio, clients_get_fh(client)); 404 436 } 437 438 ROAR_DBG("emul_gopher_check_client(client=%i, vio=%p) = ?", client, vio); 405 439 406 440 if ( cs->inbuf != NULL ) { … … 424 458 } 425 459 460 ROAR_DBG("emul_gopher_check_client(client=%i, vio=%p) = ?", client, vio); 461 426 462 ret = roar_vio_read(vio, inbuf+len, sizeof(inbuf)-len-1); 427 463 if ( ret < 1 ) { 428 464 clients_delete(client); 465 ROAR_DBG("emul_gopher_check_client(client=%i, vio=%p) = -1", client, vio); 429 466 return -1; 430 467 } … … 433 470 434 471 inbuf[ret] = 0; 472 473 ROAR_DBG("emul_gopher_check_client(client=%i, vio=%p) = ?", client, vio); 435 474 436 475 if ( !strip_nl(inbuf) ) { 437 476 if ( roar_buffer_new_data(&(cs->inbuf), ret, &data) == -1 ) { 438 477 clients_delete(client); 478 ROAR_DBG("emul_gopher_check_client(client=%i, vio=%p) = -1", client, vio); 439 479 return -1; 440 480 } 441 481 442 482 memcpy(data, inbuf, ret); 483 484 ROAR_DBG("emul_gopher_check_client(client=%i, vio=%p) = 0", client, vio); 485 443 486 return 0; 444 487 } 445 488 489 ROAR_DBG("emul_gopher_check_client(client=%i, vio=%p) = ?", client, vio); 490 446 491 for (i = 0; i < sizeof(g_gopher_items)/sizeof(*g_gopher_items); i++) { 492 // if ( !strselcmp(g_gopher_items[i].selector, inbuf) ) { 447 493 if ( !strselcmp(g_gopher_items[i].selector, inbuf) ) { 448 494 c = &(g_gopher_items[i]); … … 453 499 if ( c == NULL ) { 454 500 clients_delete(client); 455 return -1; 456 } 501 ROAR_DBG("emul_gopher_check_client(client=%i, vio=%p) = -1", client, vio); 502 return -1; 503 } 504 505 ROAR_DBG("emul_gopher_check_client(client=%i, vio=%p) = ?", client, vio); 457 506 458 507 if ( c->cb != NULL ) { … … 479 528 } 480 529 530 ROAR_DBG("emul_gopher_check_client(client=%i, vio=%p) = ?", client, vio); 531 481 532 if ( funcret == -1 ) { 482 533 clients_delete(client); 483 return -1; 484 } 534 ROAR_DBG("emul_gopher_check_client(client=%i, vio=%p) = -1", client, vio); 535 return -1; 536 } 537 538 ROAR_DBG("emul_gopher_check_client(client=%i, vio=%p) = 0", client, vio); 485 539 486 540 return 0; … … 488 542 489 543 int emul_gopher_flushed_client(int client, struct roar_vio_calls * vio) { 544 ROAR_DBG("emul_gopher_flushed_client(client=%i, vio=%p) = ?", client, vio); 545 490 546 return clients_delete(client); 491 547 }
Note: See TracChangeset
for help on using the changeset viewer.