Changeset 4706:b24a7aa8f563 in roaraudio


Ignore:
Timestamp:
01/06/11 09:58:08 (11 years ago)
Author:
phi
Branch:
default
Phase:
public
Message:

added cb based selector generation and added a small status page

File:
1 edited

Legend:

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

    r4705 r4706  
    3434#define _SOUND ROAR_GOPHER_TYPE_SOUND 
    3535 
     36static int scb_status_txt (int client, struct roar_vio_calls * vio, const char * selector, char ** text); 
     37 
    3638static struct roar_gopher_menu_item g_gopher_root_menu[] = { 
    3739 {.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} 
    3942}; 
    4043 
     
    4649 int dir; 
    4750 const char * text; 
     51 int (*cb)(int client, struct roar_vio_calls * vio, const char * selector, char ** text); 
    4852} g_gopher_items[] = { 
    4953 {.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 
    5156 }, 
    5257 // and again as selector '/' as some clients seems to require it: 
    5358 {.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 
    5561 }, 
    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} 
    5764}; 
    5865 
    5966 
     67// SCBs: 
     68static 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: 
    60103static int strip_nl (char * str) { 
    61104 register char c; 
     
    129172 
    130173 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); 
    132176 clients_add_output(client, buf); 
    133177 
     
    145189 size_t len = 0; 
    146190 void * data; 
     191 char * text; 
    147192 
    148193 if ( clients_get_server(client, &cs) == -1 ) { 
     
    208253 } 
    209254 
    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  } 
    220276 } 
    221277 
Note: See TracChangeset for help on using the changeset viewer.