[0] | 1 | //req.c: |
---|
| 2 | |
---|
| 3 | #include "roard.h" |
---|
| 4 | |
---|
| 5 | int req_on_noop (int client, struct roar_message * mes, char * data) { |
---|
| 6 | mes->cmd = ROAR_CMD_OK; |
---|
| 7 | mes->datalen = 0; |
---|
| 8 | return 0; |
---|
| 9 | } |
---|
| 10 | |
---|
| 11 | int req_on_identify (int client, struct roar_message * mes, char * data) { |
---|
| 12 | struct roar_client * c; |
---|
| 13 | int max_len; |
---|
| 14 | |
---|
| 15 | if ( mes->datalen < 1 ) |
---|
| 16 | return -1; |
---|
| 17 | |
---|
| 18 | clients_get(client, &c); |
---|
| 19 | |
---|
| 20 | if ( mes->data[0] == 1 ) { |
---|
| 21 | c->pid = ROAR_NET2HOST32(*(uint32_t*)((mes->data)+1)); |
---|
| 22 | |
---|
| 23 | max_len = (mes->datalen - 5) < (ROAR_BUFFER_NAME-1) ? (mes->datalen - 5) : (ROAR_BUFFER_NAME-1); |
---|
| 24 | |
---|
| 25 | strncpy(c->name, mes->data + 5, max_len); |
---|
| 26 | c->name[max_len] = 0; |
---|
| 27 | |
---|
| 28 | mes->cmd = ROAR_CMD_OK; |
---|
| 29 | mes->datalen = 0; |
---|
| 30 | |
---|
| 31 | ROAR_DBG("req_on_identify(*): client=%i, pid=%i", client, c->pid); |
---|
| 32 | ROAR_DBG("req_on_identify(*) = 0"); |
---|
| 33 | return 0; |
---|
| 34 | } |
---|
| 35 | |
---|
| 36 | return -1; |
---|
| 37 | } |
---|
| 38 | |
---|
| 39 | int req_on_auth (int client, struct roar_message * mes, char * data) { |
---|
| 40 | // TODO: add code to support some auth. |
---|
| 41 | mes->cmd = ROAR_CMD_OK; |
---|
| 42 | mes->datalen = 0; |
---|
| 43 | return 0; |
---|
| 44 | } |
---|
| 45 | |
---|
| 46 | |
---|
| 47 | int req_on_new_stream (int client, struct roar_message * mes, char * data) { |
---|
| 48 | int stream; |
---|
| 49 | struct roar_stream * s; |
---|
| 50 | |
---|
| 51 | if ((stream = streams_new()) == -1 ) |
---|
| 52 | return -1; |
---|
| 53 | |
---|
| 54 | if ( streams_get(stream, (struct roar_stream_server **)&s) == -1 ) { |
---|
| 55 | streams_delete(stream); |
---|
| 56 | return -1; |
---|
| 57 | } |
---|
| 58 | |
---|
| 59 | if ( client_stream_add(client, stream) == -1 ) { |
---|
| 60 | streams_delete(stream); |
---|
| 61 | return -1; |
---|
| 62 | } |
---|
| 63 | |
---|
| 64 | if ( roar_stream_m2s(s, mes) == -1 ) { |
---|
| 65 | streams_delete(stream); |
---|
| 66 | return -1; |
---|
| 67 | } |
---|
| 68 | |
---|
| 69 | mes->cmd = ROAR_CMD_OK; |
---|
| 70 | mes->stream = stream; |
---|
| 71 | mes->datalen = 0; |
---|
| 72 | |
---|
| 73 | return 0; |
---|
| 74 | } |
---|
| 75 | |
---|
| 76 | int req_on_exec_stream (int client, struct roar_message * mes, char * data) { |
---|
| 77 | int r; |
---|
| 78 | |
---|
| 79 | if ( (r = client_stream_exec(client, mes->stream)) == -1 ) |
---|
| 80 | return -1; |
---|
| 81 | |
---|
| 82 | mes->cmd = ROAR_CMD_OK; |
---|
| 83 | mes->datalen = 0; |
---|
| 84 | |
---|
| 85 | return 0; |
---|
| 86 | } |
---|
| 87 | |
---|
| 88 | |
---|
| 89 | int req_on_set_meta (int client, struct roar_message * mes, char * data) { |
---|
| 90 | return -1; |
---|
| 91 | } |
---|
| 92 | |
---|
| 93 | |
---|
| 94 | int req_on_server_oinfo (int client, struct roar_message * mes, char * data) { |
---|
| 95 | struct roar_stream s; |
---|
| 96 | //ROAR_DIR_OUTPUT |
---|
| 97 | |
---|
| 98 | s.dir = ROAR_DIR_OUTPUT; |
---|
| 99 | s.pos_rel_id = -1; |
---|
| 100 | s.info.rate = g_sa->rate; |
---|
| 101 | s.info.bits = g_sa->bits; |
---|
| 102 | s.info.channels = g_sa->channels; |
---|
| 103 | s.info.codec = g_sa->codec; |
---|
| 104 | |
---|
| 105 | if ( roar_stream_s2m(&s, mes) == -1 ) |
---|
| 106 | return -1; |
---|
| 107 | |
---|
| 108 | mes->cmd = ROAR_CMD_OK; |
---|
| 109 | |
---|
| 110 | return 0; |
---|
| 111 | } |
---|
| 112 | |
---|
| 113 | |
---|
| 114 | int req_on_get_standby (int client, struct roar_message * mes, char * data) { |
---|
| 115 | mes->cmd = ROAR_CMD_OK; |
---|
| 116 | mes->datalen = 2; |
---|
| 117 | |
---|
| 118 | *((uint16_t*)mes->data) = ROAR_HOST2NET16((unsigned) g_standby); |
---|
| 119 | |
---|
| 120 | return 0; |
---|
| 121 | } |
---|
| 122 | |
---|
| 123 | int req_on_set_standby (int client, struct roar_message * mes, char * data) { |
---|
| 124 | if ( mes->datalen != 2 ) |
---|
| 125 | return -1; |
---|
| 126 | |
---|
| 127 | g_standby = ROAR_NET2HOST16(*((uint16_t*)mes->data)); |
---|
| 128 | |
---|
| 129 | mes->cmd = ROAR_CMD_OK; |
---|
| 130 | mes->datalen = 0; |
---|
| 131 | |
---|
| 132 | return 0; |
---|
| 133 | } |
---|
| 134 | |
---|
| 135 | int req_on_exit (int client, struct roar_message * mes, char * data) { |
---|
| 136 | mes->cmd = ROAR_CMD_OK; |
---|
| 137 | mes->datalen = 0; |
---|
| 138 | |
---|
| 139 | alive = 0; |
---|
| 140 | |
---|
| 141 | return 0; |
---|
| 142 | } |
---|
| 143 | |
---|
| 144 | int req_on_list_clients(int client, struct roar_message * mes, char * data) { |
---|
| 145 | unsigned char filter, cmp; |
---|
| 146 | uint32_t id; |
---|
| 147 | int clients[ROAR_CLIENTS_MAX]; |
---|
| 148 | int i, c = 0; |
---|
| 149 | |
---|
| 150 | if ( roar_ctl_m2f(mes, &filter, &cmp, &id) == -1 ) |
---|
| 151 | return -1; |
---|
| 152 | |
---|
| 153 | // TODO: add code to support filter |
---|
| 154 | if ( filter != ROAR_CTL_FILTER_ANY ) |
---|
| 155 | return -1; |
---|
| 156 | |
---|
| 157 | for (i = 0; i < ROAR_CLIENTS_MAX; i++) { |
---|
| 158 | if ( g_clients[i] != NULL ) { |
---|
| 159 | clients[c++] = i; |
---|
| 160 | } |
---|
| 161 | } |
---|
| 162 | |
---|
| 163 | roar_ctl_ia2m(mes, clients, c); |
---|
| 164 | |
---|
| 165 | mes->cmd = ROAR_CMD_OK; |
---|
| 166 | |
---|
| 167 | return 0; |
---|
| 168 | } |
---|
| 169 | int req_on_list_streams(int client, struct roar_message * mes, char * data) { |
---|
| 170 | unsigned char filter, cmp; |
---|
| 171 | uint32_t id; |
---|
| 172 | int streams[ROAR_STREAMS_MAX]; |
---|
| 173 | int i, c = 0; |
---|
| 174 | |
---|
| 175 | if ( roar_ctl_m2f(mes, &filter, &cmp, &id) == -1 ) |
---|
| 176 | return -1; |
---|
| 177 | |
---|
| 178 | // TODO: add code to support filter |
---|
| 179 | if ( filter != ROAR_CTL_FILTER_ANY ) |
---|
| 180 | return -1; |
---|
| 181 | |
---|
| 182 | for (i = 0; i < ROAR_STREAMS_MAX; i++) { |
---|
| 183 | if ( g_streams[i] != NULL ) { |
---|
| 184 | streams[c++] = i; |
---|
| 185 | } |
---|
| 186 | } |
---|
| 187 | |
---|
| 188 | roar_ctl_ia2m(mes, streams, c); |
---|
| 189 | |
---|
| 190 | mes->cmd = ROAR_CMD_OK; |
---|
| 191 | |
---|
| 192 | return 0; |
---|
| 193 | } |
---|
| 194 | |
---|
| 195 | int req_on_get_client (int client, struct roar_message * mes, char * data) { |
---|
| 196 | struct roar_client * c; |
---|
| 197 | |
---|
| 198 | if ( mes->datalen != 1 ) |
---|
| 199 | return -1; |
---|
| 200 | |
---|
| 201 | if ( clients_get(mes->data[0], &c) == -1 ) |
---|
| 202 | return -1; |
---|
| 203 | |
---|
| 204 | mes->cmd = ROAR_CMD_OK; |
---|
| 205 | |
---|
| 206 | return roar_ctl_c2m(mes, c); |
---|
| 207 | } |
---|
| 208 | |
---|
| 209 | int req_on_get_stream (int client, struct roar_message * mes, char * data) { |
---|
| 210 | struct roar_stream_server * s; |
---|
| 211 | |
---|
| 212 | if ( mes->datalen != 1 ) |
---|
| 213 | return -1; |
---|
| 214 | |
---|
| 215 | if ( streams_get(mes->data[0], &s) == -1 ) |
---|
| 216 | return -1; |
---|
| 217 | |
---|
| 218 | mes->cmd = ROAR_CMD_OK; |
---|
| 219 | |
---|
| 220 | return roar_stream_s2m(ROAR_STREAM(s), mes); |
---|
| 221 | } |
---|
| 222 | |
---|
| 223 | int req_on_kick (int client, struct roar_message * mes, char * data) { |
---|
[17] | 224 | uint16_t * info = (uint16_t *) mes->data; |
---|
[0] | 225 | |
---|
| 226 | if ( mes->datalen != 4 ) |
---|
| 227 | return -1; |
---|
| 228 | |
---|
| 229 | if ( info[0] == ROAR_OT_CLIENT ) { |
---|
| 230 | clients_delete(info[1]); |
---|
| 231 | } else if ( info[0] == ROAR_OT_STREAM ) { |
---|
| 232 | streams_delete(info[1]); |
---|
| 233 | } else { |
---|
| 234 | return -1; |
---|
| 235 | } |
---|
| 236 | |
---|
| 237 | mes->cmd = ROAR_CMD_OK; |
---|
| 238 | mes->datalen = 0; |
---|
| 239 | |
---|
| 240 | return 0; |
---|
| 241 | } |
---|
| 242 | |
---|
[17] | 243 | int req_on_set_vol (int client, struct roar_message * mes, char * data) { |
---|
| 244 | uint16_t * info = (uint16_t *) mes->data; |
---|
| 245 | int stream; |
---|
| 246 | struct roar_stream_server * s; |
---|
| 247 | int i; |
---|
| 248 | int chans; |
---|
| 249 | |
---|
| 250 | ROAR_DBG("req_on_set_vol(*) = ?"); |
---|
| 251 | ROAR_DBG("req_on_set_vol(*): mes->datalen=%i", mes->datalen); |
---|
| 252 | |
---|
| 253 | if ( mes->datalen < (4*2) ) |
---|
| 254 | return -1; |
---|
| 255 | |
---|
| 256 | if ( info[0] != 0 ) // version |
---|
| 257 | return -1; |
---|
| 258 | |
---|
| 259 | stream = info[1]; |
---|
| 260 | ROAR_DBG("req_on_set_vol(*): stream=%i", stream); |
---|
| 261 | |
---|
| 262 | // TODO: change this code. |
---|
| 263 | // we should not directly change the stream object but use some stream_*()-func |
---|
| 264 | // for that job. |
---|
| 265 | |
---|
| 266 | if ( stream < 0 || stream >= ROAR_STREAMS_MAX ) |
---|
| 267 | return -1; |
---|
| 268 | |
---|
| 269 | s = g_streams[stream]; |
---|
| 270 | |
---|
| 271 | if ( s == NULL ) |
---|
| 272 | return -1; |
---|
| 273 | |
---|
| 274 | ROAR_DBG("req_on_set_vol(*): s=%p", s); |
---|
| 275 | |
---|
| 276 | if ( info[2] == ROAR_SET_VOL_ALL ) { |
---|
| 277 | chans = (mes->datalen/2) - 3; |
---|
| 278 | ROAR_DBG("req_on_set_vol(*): mode is ROAR_SET_VOL_ALL, channes=%i", chans); |
---|
| 279 | |
---|
| 280 | if ( chans >= ROAR_MAX_CHANNELS ) |
---|
| 281 | return -1; |
---|
| 282 | |
---|
[18] | 283 | ROAR_DBG("req_on_set_vol(*): mixer at %p", s->mixer.mixer); |
---|
| 284 | |
---|
[17] | 285 | for (i = 0; i < chans; i++) { |
---|
| 286 | s->mixer.mixer[i] = info[i+3]; |
---|
| 287 | ROAR_DBG("req_on_set_vol(*): channel %i: %i", i, info[i+3]); |
---|
| 288 | } |
---|
| 289 | |
---|
| 290 | ROAR_DBG("req_on_set_vol(*): mixer changed!"); |
---|
| 291 | |
---|
| 292 | } else if ( info[2] == ROAR_SET_VOL_ONE ) { |
---|
| 293 | ROAR_DBG("req_on_set_vol(*): mode is ROAR_SET_VOL_ONE"); |
---|
| 294 | if ( info[3] >= ROAR_MAX_CHANNELS ) |
---|
| 295 | return -1; |
---|
| 296 | |
---|
| 297 | s->mixer.mixer[info[3]] = info[4]; |
---|
| 298 | } else { |
---|
| 299 | return -1; |
---|
| 300 | } |
---|
| 301 | |
---|
| 302 | mes->cmd = ROAR_CMD_OK; |
---|
| 303 | mes->datalen = 0; |
---|
| 304 | |
---|
| 305 | return 0; |
---|
| 306 | } |
---|
[0] | 307 | |
---|
| 308 | int req_on_add_data (int client, struct roar_message * mes, char * data) { |
---|
| 309 | struct roar_buffer * b; |
---|
| 310 | char * buf; |
---|
| 311 | |
---|
| 312 | if ( roar_buffer_new(&b, mes->datalen) == -1 ) { |
---|
| 313 | ROAR_ERR("req_on_add_data(*): Can not alloc buffer space!"); |
---|
| 314 | ROAR_DBG("req_on_add_data(*) = -1"); |
---|
| 315 | return -1; |
---|
| 316 | } |
---|
| 317 | |
---|
| 318 | roar_buffer_get_data(b, (void **)&buf); |
---|
| 319 | |
---|
| 320 | if ( data == NULL ) { |
---|
| 321 | memcpy(buf, mes->data, mes->datalen); |
---|
| 322 | } else { |
---|
| 323 | memcpy(buf, data, mes->datalen); |
---|
| 324 | } |
---|
| 325 | |
---|
| 326 | if ( stream_add_buffer(mes->stream, b) == -1 ) { |
---|
| 327 | roar_buffer_free(b); |
---|
| 328 | return -1; |
---|
| 329 | } |
---|
| 330 | |
---|
| 331 | mes->cmd = ROAR_CMD_OK; |
---|
| 332 | mes->datalen = 0; |
---|
| 333 | |
---|
| 334 | return 0; |
---|
| 335 | } |
---|
| 336 | |
---|
| 337 | //ll |
---|