Changeset 3976:09f5b430ba74 in roaraudio for plugins/roard
- Timestamp:
- 06/27/10 19:32:02 (14 years ago)
- Branch:
- default
- Phase:
- public
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
plugins/roard/protocol-rplay.c
r3968 r3976 26 26 #include "roard.h" 27 27 28 struct emul_rplay_command emul_rplay_commands[] = { 29 {"access", NULL, -1, -1, NULL}, 30 {"application", NULL, 1, -1, NULL}, 31 {"continue", NULL, 1, -1, NULL}, 32 {"die", NULL, 1, -1, NULL}, 33 {"done", NULL, 1, -1, NULL}, // #ifdef DEBUG 34 {"find", NULL, 1, 1, NULL}, 35 {"get", NULL, 1, 1, NULL}, 36 {"help", NULL, -1, -1, NULL}, 37 {"info", NULL, 1, 1, NULL}, 38 {"list", NULL, 0, 1, NULL}, 39 {"modify", NULL, 2, -1, NULL}, 40 {"monitor", NULL, 1, -1, NULL}, 41 {"pause", NULL, 1, -1, NULL}, 42 {"play", NULL, 1, -1, NULL}, 43 {"put", NULL, 2, -1, NULL}, 44 {"quit", NULL, 0, 0, NULL}, 45 {"reset", NULL, 0, 0, NULL}, 46 {"set", NULL, 1, -1, NULL}, 47 {"skip", NULL, 1, 1, NULL}, 48 {"status", NULL, 0, 0, NULL}, 49 {"stop", NULL, 1, -1, NULL}, 50 {"version", NULL, 0, 0, NULL}, 51 {"volume", NULL, 0, 1, NULL}, 52 {"wait", NULL, -1, -1, NULL}, 53 {NULL, NULL, -1, -1, NULL} 54 }; 55 56 static inline int is_true(const char * str) { 57 const char * ts[] = {"true", "t", "1", "yes", "y", "on"}; 58 int i; 59 60 for (i = 0; i < sizeof(ts)/sizeof(*ts); i++) 61 if ( !strcasecmp(str, ts[i]) ) 62 return 1; 63 64 return 0; 65 } 66 67 static inline int is_false(const char * str) { 68 return !is_true(str); 69 } 70 71 72 int emul_rplay_check_client (int client, struct roar_vio_calls * vio); 73 74 int emul_rplay_exec_command (int client, struct roar_vio_calls * vio, char * command) { 75 struct emul_rplay_command * cmd; 76 struct roar_keyval * kv; 77 ssize_t kvlen; 78 char * para = NULL; 79 char * c; 80 int last_was_space = 0; 81 82 for (c = command; *c != 0; c++) { 83 if ( *c == ' ' || *c == '\t' ) { 84 last_was_space = 1; 85 *c = 0; 86 } else { 87 if ( last_was_space ) { 88 para = c; 89 break; 90 } 91 } 92 } 93 94 if ( para == NULL ) { 95 kv = NULL; 96 kvlen = 0; 97 } else { 98 kvlen = roar_keyval_split(&kv, para, " \t", "=", 0); 99 if ( kvlen == -1 ) 100 return emul_rplay_send_error(client, NULL, vio, NULL, 0, "Can not parse parameter list"); 101 } 102 103 for (cmd = emul_rplay_commands; cmd->name != NULL; cmd++) { 104 if ( !strcasecmp(cmd->name, command) ) 105 break; 106 } 107 108 if ( cmd->name == NULL ) 109 return emul_rplay_send_error(client, NULL, vio, kv, kvlen, "unknown command"); 110 111 if ( cmd->handler == NULL ) 112 return emul_rplay_send_error(client, cmd, vio, kv, kvlen, "unsupported command"); 113 114 return cmd->handler(client, cmd, vio, kv, kvlen); 115 } 116 117 int emul_rplay_send_error (int client, struct emul_rplay_command * cmd, struct roar_vio_calls * vio, struct roar_keyval * kv, size_t kvlen, const char * msg) { 118 struct roar_keyval * kvr; 119 const char * command; 120 const char * cd = NULL; 121 122 if ( cmd != NULL ) { 123 command = cmd->name; 124 } else { 125 command = "(unknown)"; 126 } 127 128 if ( kv != NULL ) { 129 kvr = roar_keyval_lookup(kv, "client-data", kvlen, 0); 130 if ( kvr != NULL ) 131 cd = kvr->value; 132 } 133 134 if ( cd == NULL ) 135 cd = ""; 136 137 return roar_vio_printf("-error=\"%s\" command=\"%s\" client-data=\"%s\"\n", msg, command, cd) <= 0 ? -1 : 0; 138 } 139 28 140 //ll
Note: See TracChangeset
for help on using the changeset viewer.