Changeset 4715:7fce204ba6a8 in roaraudio


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

added some basic client infos

File:
1 edited

Legend:

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

    r4714 r4715  
    4040static int scb_clients    (int client, struct roar_vio_calls * vio, char * selector, char ** text, struct item * sitem); 
    4141static int scb_streams    (int client, struct roar_vio_calls * vio, char * selector, char ** text, struct item * sitem); 
     42static int scb_client_info(int client, struct roar_vio_calls * vio, char * selector, char ** text, struct item * sitem); 
    4243 
    4344static struct roar_gopher_menu_item g_gopher_root_menu[] = { 
     
    7172 {.selector = "/test/*",     .type = _FILE, .cb = scb_test}, 
    7273 {.selector = "/clients/",   .type = _DIR,  .cb = scb_clients}, 
    73  {.selector = "/streams/",   .type = _DIR,  .cb = scb_streams} 
     74 {.selector = "/streams/",   .type = _DIR,  .cb = scb_streams}, 
     75 {.selector = "/clients/*/", .type = _DIR,  .cb = scb_client_info} 
    7476}; 
    7577 
    7678static int strselcmp(const char *s1, const char *s2); 
    7779static ssize_t strseltok(const char *s1, char *s2, char ** tok, size_t toks); 
     80 
     81static char * _aprintf(size_t sizehint, const char * format, ...); 
    7882 
    7983static int send_menu (int client, struct roar_gopher_menu * menu, struct roar_vio_calls * vio); 
     
    246250 } 
    247251 
     252 return ret; 
     253} 
     254 
     255static int scb_client_info(int client, struct roar_vio_calls * vio, char * selector, char ** text, struct item * sitem) { 
     256#define _MAX_ITEMS 8 
     257 struct roar_gopher_menu_item items[_MAX_ITEMS]; 
     258 struct roar_gopher_menu menu = {.flags = 0, .items = items, .items_len = 0}; 
     259 struct roar_gopher_menu_item * item; 
     260 struct roar_client_server * cs; 
     261 struct roar_client        * c; 
     262 size_t i; 
     263 int ret; 
     264 ssize_t toks; 
     265 char * tok; 
     266 int id; 
     267 char tmp[80]; 
     268 
     269 memset(items, 0, sizeof(items)); 
     270 
     271 toks = strseltok(sitem->selector, selector, &tok, 1); 
     272 if ( toks == -1 ) 
     273  return -1; 
     274 
     275 id = atoi(tok); 
     276 
     277 if ( clients_get_server(id, &cs) == -1 ) 
     278  return -1; 
     279 
     280 c = ROAR_CLIENT(cs); 
     281 
     282 item = &(items[menu.items_len++]); 
     283 item->type = _INFO; 
     284 if ( c->name != NULL && c->name[0] != 0 ) { 
     285  item->name = _aprintf(64, "Client %i: %s", id, c->name); 
     286 } else { 
     287  item->name = _aprintf(64, "Client %i", id); 
     288 } 
     289 
     290 if ( roar_nnode_get_socktype(&(c->nnode)) != ROAR_SOCKET_TYPE_UNKNOWN ) { 
     291  if ( roar_nnode_to_str(&(c->nnode), tmp, sizeof(tmp)) == 0 ) { 
     292   item = &(items[menu.items_len++]); 
     293   item->type = _INFO; 
     294   item->name = _aprintf(64, "Network node: %s", tmp); 
     295  } 
     296 } 
     297 
     298 item = &(items[menu.items_len++]); 
     299 item->type = _INFO; 
     300 item->name = _aprintf(64, "Protocol: %s", roar_proto2str(c->proto)); 
     301 
     302 if ( c->execed != -1 ) { 
     303  item = &(items[menu.items_len++]); 
     304  item->type = _DIR; 
     305  item->name = _aprintf(64, "Exected Stream: %i", c->execed); 
     306  item->selector = _aprintf(64, "/streams/%i/", c->execed); 
     307 } 
     308 
     309 for (i = 0; i < ROAR_CLIENTS_MAX_STREAMS_PER_CLIENT; i++) { 
     310  if ( c->streams[i] != -1 ) { 
     311   item = &(items[menu.items_len++]); 
     312   item->type = _DIR; 
     313   item->name = _aprintf(64, "Stream: %i", c->streams[i]); 
     314   item->selector = _aprintf(64, "/streams/%i/", c->streams[i]); 
     315  } 
     316 } 
     317 
     318 ret = send_menu(client, &menu, vio); 
     319 
     320 for (i = 0; i < menu.items_len; i++) { 
     321  if ( items[i].name != NULL ) 
     322   roar_mm_free((void*)items[i].name); 
     323  if ( items[i].selector != NULL ) 
     324   roar_mm_free((void*)items[i].selector); 
     325 } 
     326 
     327#undef _MAX_ITEMS 
    248328 return ret; 
    249329} 
     
    345425} 
    346426 
     427static char * _aprintf(size_t sizehint, const char * format, ...) { 
     428 va_list ap; 
     429 char * buf; 
     430 int ret; 
     431 
     432 sizehint += 128; 
     433 
     434 if ( (buf = roar_mm_malloc(sizehint)) == NULL ) 
     435  return NULL; 
     436 
     437 va_start(ap, format); 
     438 ret = vsnprintf(buf, sizehint, format, ap); 
     439 va_end(ap); 
     440 
     441 buf[sizehint-1] = 0; 
     442 
     443 return buf; 
     444} 
     445 
    347446static int send_menu (int client, struct roar_gopher_menu * menu, struct roar_vio_calls * vio) { 
    348447 struct roar_buffer * buf; 
Note: See TracChangeset for help on using the changeset viewer.