Changeset 4714:c8403b42e127 in roaraudio for plugins/roard


Ignore:
Timestamp:
01/09/11 15:09:11 (13 years ago)
Author:
phi
Branch:
default
Phase:
public
Message:

added support for paramterized selectors

File:
1 edited

Legend:

Unmodified
Added
Removed
  • plugins/roard/protocol-gopher.c

    r4712 r4714  
    3434#define _SOUND ROAR_GOPHER_TYPE_SOUND 
    3535 
    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); 
     36struct item; 
     37 
     38static int scb_status_txt (int client, struct roar_vio_calls * vio, char * selector, char ** text, struct item * sitem); 
     39static int scb_test       (int client, struct roar_vio_calls * vio, char * selector, char ** text, struct item * sitem); 
     40static int scb_clients    (int client, struct roar_vio_calls * vio, char * selector, char ** text, struct item * sitem); 
     41static int scb_streams    (int client, struct roar_vio_calls * vio, char * selector, char ** text, struct item * sitem); 
    4142 
    4243static struct roar_gopher_menu_item g_gopher_root_menu[] = { 
     
    5556 int dir; 
    5657 const char * text; 
    57  int (*cb)(int client, struct roar_vio_calls * vio, const char * selector, char ** text, struct item * sitem); 
     58 int (*cb)(int client, struct roar_vio_calls * vio, char * selector, char ** text, struct item * sitem); 
    5859} g_gopher_items[] = { 
    5960 {.selector = "", .type = _DIR, 
     
    6869 {.selector = "/info.txt",   .type = _FILE, .text = "Some\nText.", .cb = NULL}, 
    6970 {.selector = "/status.txt", .type = _FILE, .cb = scb_status_txt}, 
     71 {.selector = "/test/*",     .type = _FILE, .cb = scb_test}, 
    7072 {.selector = "/clients/",   .type = _DIR,  .cb = scb_clients}, 
    7173 {.selector = "/streams/",   .type = _DIR,  .cb = scb_streams} 
     
    8082 
    8183// SCBs: 
    82 static int scb_status_txt (int client, struct roar_vio_calls * vio, const char * selector, char ** text, struct item * sitem) { 
     84static int scb_status_txt (int client, struct roar_vio_calls * vio, char * selector, char ** text, struct item * sitem) { 
    8385 const size_t len = 1024; 
    8486 const char * server_version = NULL; 
     
    9092 } 
    9193 
    92  *text = roar_mm_malloc(1024); 
     94 *text = roar_mm_malloc(len); 
    9395 if ( *text == NULL ) 
    9496  return -1; 
     
    113115} 
    114116 
    115 static int scb_clients    (int client, struct roar_vio_calls * vio, const char * selector, char ** text, struct item * sitem) { 
     117static 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 
     143static int scb_clients    (int client, struct roar_vio_calls * vio, char * selector, char ** text, struct item * sitem) { 
    116144 struct roar_gopher_menu_item items[ROAR_CLIENTS_MAX]; 
    117145 struct roar_gopher_menu menu = {.flags = 0, .items = items, .items_len = 0}; 
     
    167195} 
    168196 
    169 static int scb_streams    (int client, struct roar_vio_calls * vio, const char * selector, char ** text, struct item * sitem) { 
     197static int scb_streams    (int client, struct roar_vio_calls * vio, char * selector, char ** text, struct item * sitem) { 
    170198 struct roar_gopher_menu_item items[ROAR_STREAMS_MAX]; 
    171199 struct roar_gopher_menu menu = {.flags = 0, .items = items, .items_len = 0}; 
     
    394422 char * text; 
    395423 
     424 ROAR_DBG("emul_gopher_check_client(client=%i, vio=%p) = ?", client, vio); 
     425 
    396426 if ( clients_get_server(client, &cs) == -1 ) { 
    397427  clients_delete(client); 
    398428  return -1; 
    399429 } 
     430 
     431 ROAR_DBG("emul_gopher_check_client(client=%i, vio=%p) = ?", client, vio); 
    400432 
    401433 if ( vio == NULL ) { 
     
    403435  roar_vio_open_fh_socket(vio, clients_get_fh(client)); 
    404436 } 
     437 
     438 ROAR_DBG("emul_gopher_check_client(client=%i, vio=%p) = ?", client, vio); 
    405439 
    406440 if ( cs->inbuf != NULL ) { 
     
    424458 } 
    425459 
     460 ROAR_DBG("emul_gopher_check_client(client=%i, vio=%p) = ?", client, vio); 
     461 
    426462 ret = roar_vio_read(vio, inbuf+len, sizeof(inbuf)-len-1); 
    427463 if ( ret < 1 ) { 
    428464  clients_delete(client); 
     465  ROAR_DBG("emul_gopher_check_client(client=%i, vio=%p) = -1", client, vio); 
    429466  return -1; 
    430467 } 
     
    433470 
    434471 inbuf[ret] = 0; 
     472 
     473 ROAR_DBG("emul_gopher_check_client(client=%i, vio=%p) = ?", client, vio); 
    435474 
    436475 if ( !strip_nl(inbuf) ) { 
    437476  if ( roar_buffer_new_data(&(cs->inbuf), ret, &data) == -1 ) { 
    438477   clients_delete(client); 
     478   ROAR_DBG("emul_gopher_check_client(client=%i, vio=%p) = -1", client, vio); 
    439479   return -1; 
    440480  } 
    441481 
    442482  memcpy(data, inbuf, ret); 
     483 
     484  ROAR_DBG("emul_gopher_check_client(client=%i, vio=%p) = 0", client, vio); 
     485 
    443486  return 0; 
    444487 } 
    445488 
     489 ROAR_DBG("emul_gopher_check_client(client=%i, vio=%p) = ?", client, vio); 
     490 
    446491 for (i = 0; i < sizeof(g_gopher_items)/sizeof(*g_gopher_items); i++) { 
     492//  if ( !strselcmp(g_gopher_items[i].selector, inbuf) ) { 
    447493  if ( !strselcmp(g_gopher_items[i].selector, inbuf) ) { 
    448494   c = &(g_gopher_items[i]); 
     
    453499 if ( c == NULL ) { 
    454500  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); 
    457506 
    458507 if ( c->cb != NULL ) { 
     
    479528 } 
    480529 
     530 ROAR_DBG("emul_gopher_check_client(client=%i, vio=%p) = ?", client, vio); 
     531 
    481532 if ( funcret == -1 ) { 
    482533  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); 
    485539 
    486540 return 0; 
     
    488542 
    489543int 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 
    490546 return clients_delete(client); 
    491547} 
Note: See TracChangeset for help on using the changeset viewer.