[0] | 1 | //ctl.c: |
---|
| 2 | |
---|
[690] | 3 | /* |
---|
[3683] | 4 | * Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2008-2010 |
---|
[690] | 5 | * |
---|
| 6 | * This file is part of libroar a part of RoarAudio, |
---|
| 7 | * a cross-platform sound system for both, home and professional use. |
---|
| 8 | * See README for details. |
---|
| 9 | * |
---|
| 10 | * This file is free software; you can redistribute it and/or modify |
---|
| 11 | * it under the terms of the GNU General Public License version 3 |
---|
| 12 | * as published by the Free Software Foundation. |
---|
| 13 | * |
---|
| 14 | * libroar is distributed in the hope that it will be useful, |
---|
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 17 | * GNU General Public License for more details. |
---|
| 18 | * |
---|
| 19 | * You should have received a copy of the GNU General Public License |
---|
| 20 | * along with this software; see the file COPYING. If not, write to |
---|
[3517] | 21 | * the Free Software Foundation, 51 Franklin Street, Fifth Floor, |
---|
| 22 | * Boston, MA 02110-1301, USA. |
---|
[690] | 23 | * |
---|
| 24 | * NOTE for everyone want's to change something and send patches: |
---|
| 25 | * read README and HACKING! There a addition information on |
---|
| 26 | * the license of this document you need to read before you send |
---|
| 27 | * any patches. |
---|
| 28 | * |
---|
| 29 | * NOTE for uses of non-GPL (LGPL,...) software using libesd, libartsc |
---|
| 30 | * or libpulse*: |
---|
| 31 | * The libs libroaresd, libroararts and libroarpulse link this lib |
---|
| 32 | * and are therefore GPL. Because of this it may be illigal to use |
---|
| 33 | * them with any software that uses libesd, libartsc or libpulse*. |
---|
| 34 | */ |
---|
| 35 | |
---|
[0] | 36 | #include "libroar.h" |
---|
| 37 | |
---|
[1162] | 38 | int roar_get_clientid (struct roar_connection * con) { |
---|
| 39 | struct roar_message mes; |
---|
| 40 | |
---|
| 41 | memset(&mes, 0, sizeof(struct roar_message)); // make valgrind happy! |
---|
| 42 | |
---|
| 43 | mes.cmd = ROAR_CMD_WHOAMI; |
---|
| 44 | mes.datalen = 0; |
---|
| 45 | |
---|
| 46 | if ( roar_req(con, &mes, NULL) == -1 ) |
---|
| 47 | return -1; |
---|
| 48 | |
---|
| 49 | if ( mes.cmd != ROAR_CMD_OK ) |
---|
| 50 | return -1; |
---|
| 51 | |
---|
| 52 | if ( mes.datalen != 1 ) |
---|
| 53 | return -1; |
---|
| 54 | |
---|
| 55 | return mes.data[0]; |
---|
| 56 | } |
---|
| 57 | |
---|
[0] | 58 | int roar_server_oinfo (struct roar_connection * con, struct roar_stream * sa) { |
---|
| 59 | struct roar_message mes; |
---|
| 60 | |
---|
[133] | 61 | memset(&mes, 0, sizeof(struct roar_message)); // make valgrind happy! |
---|
| 62 | |
---|
[0] | 63 | mes.cmd = ROAR_CMD_SERVER_OINFO; |
---|
| 64 | mes.datalen = 0; |
---|
| 65 | |
---|
| 66 | if ( roar_req(con, &mes, NULL) == -1 ) |
---|
| 67 | return -1; |
---|
| 68 | |
---|
| 69 | if ( mes.cmd != ROAR_CMD_OK ) |
---|
| 70 | return -1; |
---|
| 71 | |
---|
| 72 | if ( roar_stream_m2s(sa, &mes) == -1 ) |
---|
| 73 | return -1; |
---|
| 74 | |
---|
| 75 | return 0; |
---|
| 76 | } |
---|
| 77 | |
---|
| 78 | int roar_get_standby (struct roar_connection * con) { |
---|
| 79 | struct roar_message mes; |
---|
| 80 | |
---|
[133] | 81 | memset(&mes, 0, sizeof(struct roar_message)); // make valgrind happy! |
---|
| 82 | |
---|
[0] | 83 | mes.cmd = ROAR_CMD_GET_STANDBY; |
---|
| 84 | mes.datalen = 0; |
---|
| 85 | |
---|
| 86 | if ( roar_req(con, &mes, NULL) == -1 ) |
---|
| 87 | return -1; |
---|
| 88 | |
---|
| 89 | if ( mes.cmd != ROAR_CMD_OK ) |
---|
| 90 | return -1; |
---|
| 91 | |
---|
| 92 | return ROAR_NET2HOST16(*((uint16_t*)mes.data)); |
---|
| 93 | } |
---|
| 94 | |
---|
| 95 | int roar_set_standby (struct roar_connection * con, int state) { |
---|
| 96 | struct roar_message mes; |
---|
| 97 | |
---|
[133] | 98 | memset(&mes, 0, sizeof(struct roar_message)); // make valgrind happy! |
---|
| 99 | |
---|
[0] | 100 | mes.cmd = ROAR_CMD_SET_STANDBY; |
---|
| 101 | mes.datalen = 2; |
---|
| 102 | |
---|
| 103 | *((uint16_t*)mes.data) = ROAR_HOST2NET16((unsigned) state); |
---|
| 104 | |
---|
| 105 | if ( roar_req(con, &mes, NULL) == -1 ) |
---|
| 106 | return -1; |
---|
| 107 | |
---|
| 108 | if ( mes.cmd != ROAR_CMD_OK ) |
---|
| 109 | return -1; |
---|
| 110 | |
---|
| 111 | return 0; |
---|
| 112 | } |
---|
| 113 | |
---|
| 114 | int roar_exit (struct roar_connection * con) { |
---|
[578] | 115 | return roar_terminate(con, 0); |
---|
| 116 | } |
---|
| 117 | |
---|
| 118 | int roar_terminate (struct roar_connection * con, int terminate) { |
---|
[0] | 119 | struct roar_message mes; |
---|
| 120 | |
---|
[133] | 121 | memset(&mes, 0, sizeof(struct roar_message)); // make valgrind happy! |
---|
| 122 | |
---|
[578] | 123 | mes.cmd = ROAR_CMD_EXIT; |
---|
| 124 | mes.datalen = 1; |
---|
| 125 | mes.data[0] = terminate; |
---|
| 126 | |
---|
[0] | 127 | if ( roar_req(con, &mes, NULL) == -1 ) |
---|
| 128 | return -1; |
---|
| 129 | |
---|
| 130 | if ( mes.cmd != ROAR_CMD_OK ) |
---|
| 131 | return -1; |
---|
| 132 | |
---|
| 133 | return 0; |
---|
| 134 | } |
---|
| 135 | |
---|
| 136 | int roar_list (struct roar_connection * con, int * items, int max, int cmd) { |
---|
| 137 | struct roar_message m; |
---|
| 138 | |
---|
[133] | 139 | memset(&m, 0, sizeof(struct roar_message)); // make valgrind happy! |
---|
| 140 | |
---|
[0] | 141 | roar_ctl_f2m_any(&m); |
---|
| 142 | m.cmd = cmd; |
---|
| 143 | |
---|
| 144 | if ( roar_req(con, &m, NULL) == -1 ) |
---|
| 145 | return -1; |
---|
| 146 | |
---|
| 147 | return roar_ctl_m2ia(&m, items, max); |
---|
| 148 | } |
---|
| 149 | |
---|
| 150 | int roar_get_client (struct roar_connection * con, struct roar_client * client, int id) { |
---|
| 151 | struct roar_message m; |
---|
| 152 | |
---|
[133] | 153 | memset(&m, 0, sizeof(struct roar_message)); // make valgrind happy! |
---|
| 154 | |
---|
[0] | 155 | m.cmd = ROAR_CMD_GET_CLIENT; |
---|
| 156 | m.datalen = 1; |
---|
| 157 | m.data[0] = id; |
---|
| 158 | |
---|
| 159 | ROAR_DBG("roar_get_client(*): id = %i", id); |
---|
| 160 | |
---|
| 161 | if ( roar_req(con, &m, NULL) == -1 ) |
---|
| 162 | return -1; |
---|
| 163 | |
---|
| 164 | if ( m.cmd != ROAR_CMD_OK ) |
---|
| 165 | return -1; |
---|
| 166 | |
---|
| 167 | ROAR_DBG("roar_get_client(*): got ok"); |
---|
| 168 | |
---|
| 169 | return roar_ctl_m2c(&m, client); |
---|
| 170 | } |
---|
| 171 | |
---|
| 172 | int roar_get_stream (struct roar_connection * con, struct roar_stream * stream, int id) { |
---|
| 173 | struct roar_message m; |
---|
| 174 | |
---|
[133] | 175 | memset(&m, 0, sizeof(struct roar_message)); // make valgrind happy! |
---|
| 176 | |
---|
[0] | 177 | m.cmd = ROAR_CMD_GET_STREAM; |
---|
| 178 | m.datalen = 1; |
---|
| 179 | m.data[0] = id; |
---|
| 180 | |
---|
[798] | 181 | roar_errno = ROAR_ERROR_UNKNOWN; |
---|
| 182 | |
---|
| 183 | if ( roar_req(con, &m, NULL) == -1 ) { |
---|
| 184 | roar_errno = ROAR_ERROR_PROTO; |
---|
[0] | 185 | return -1; |
---|
[798] | 186 | } |
---|
[0] | 187 | |
---|
| 188 | if ( m.cmd != ROAR_CMD_OK ) |
---|
| 189 | return -1; |
---|
| 190 | |
---|
| 191 | return roar_stream_m2s(stream, &m); |
---|
| 192 | } |
---|
| 193 | |
---|
| 194 | int roar_kick (struct roar_connection * con, int type, int id) { |
---|
| 195 | struct roar_message m; |
---|
[17] | 196 | uint16_t * info = (uint16_t *) m.data; |
---|
[0] | 197 | |
---|
[133] | 198 | memset(&m, 0, sizeof(struct roar_message)); // make valgrind happy! |
---|
| 199 | |
---|
[0] | 200 | m.cmd = ROAR_CMD_KICK; |
---|
| 201 | m.datalen = 4; |
---|
[299] | 202 | info[0] = ROAR_HOST2NET16(type); |
---|
| 203 | info[1] = ROAR_HOST2NET16(id); |
---|
[0] | 204 | |
---|
| 205 | if ( roar_req(con, &m, NULL) == -1 ) |
---|
| 206 | return -1; |
---|
| 207 | |
---|
| 208 | if ( m.cmd != ROAR_CMD_OK ) |
---|
| 209 | return -1; |
---|
| 210 | |
---|
| 211 | return 0; |
---|
| 212 | } |
---|
| 213 | |
---|
[17] | 214 | int roar_set_vol (struct roar_connection * con, int id, struct roar_mixer_settings * mixer, int channels) { |
---|
| 215 | struct roar_message m; |
---|
| 216 | uint16_t * info = (uint16_t *) m.data; |
---|
| 217 | int i; |
---|
| 218 | |
---|
[133] | 219 | memset(&m, 0, sizeof(struct roar_message)); // make valgrind happy! |
---|
| 220 | |
---|
[17] | 221 | m.cmd = ROAR_CMD_SET_VOL; |
---|
| 222 | m.datalen = (3 + channels) * 2; |
---|
[3530] | 223 | m.stream = id; |
---|
| 224 | info[0] = ROAR_HOST2NET16(1); |
---|
| 225 | info[1] = ROAR_HOST2NET16(mixer->scale); |
---|
[300] | 226 | info[2] = ROAR_HOST2NET16(ROAR_SET_VOL_ALL); |
---|
[17] | 227 | |
---|
| 228 | for (i = 0; i < channels; i++) |
---|
[300] | 229 | info[i+3] = ROAR_HOST2NET16(mixer->mixer[i]); |
---|
[17] | 230 | |
---|
| 231 | if ( roar_req(con, &m, NULL) == -1 ) |
---|
| 232 | return -1; |
---|
| 233 | |
---|
| 234 | if ( m.cmd != ROAR_CMD_OK ) |
---|
| 235 | return -1; |
---|
| 236 | |
---|
| 237 | return 0; |
---|
| 238 | } |
---|
| 239 | |
---|
[24] | 240 | int roar_get_vol (struct roar_connection * con, int id, struct roar_mixer_settings * mixer, int * channels) { |
---|
| 241 | struct roar_message m; |
---|
| 242 | uint16_t * info = (uint16_t *) m.data; |
---|
| 243 | int i; |
---|
| 244 | |
---|
[133] | 245 | memset(&m, 0, sizeof(struct roar_message)); // make valgrind happy! |
---|
| 246 | |
---|
[24] | 247 | m.cmd = ROAR_CMD_GET_VOL; |
---|
| 248 | m.datalen = 2*2; |
---|
[3529] | 249 | m.stream = id; |
---|
| 250 | |
---|
| 251 | info[0] = ROAR_HOST2NET16(1); |
---|
[24] | 252 | |
---|
| 253 | if ( roar_req(con, &m, NULL) == -1 ) |
---|
| 254 | return -1; |
---|
| 255 | |
---|
| 256 | if ( m.cmd != ROAR_CMD_OK ) |
---|
| 257 | return -1; |
---|
| 258 | |
---|
[3529] | 259 | if ( ROAR_NET2HOST16(info[0]) != 1 ) |
---|
[24] | 260 | return -1; |
---|
| 261 | |
---|
[300] | 262 | info[1] = ROAR_NET2HOST16(info[1]); |
---|
| 263 | |
---|
[24] | 264 | if ( channels != NULL ) |
---|
| 265 | *channels = info[1]; |
---|
| 266 | |
---|
| 267 | if ( info[1] > ROAR_MAX_CHANNELS ) |
---|
| 268 | return -1; |
---|
| 269 | |
---|
[3529] | 270 | mixer->scale = ROAR_NET2HOST16(info[2]); |
---|
| 271 | mixer->rpg_mul = ROAR_NET2HOST16(info[3]); |
---|
| 272 | mixer->rpg_div = ROAR_NET2HOST16(info[4]); |
---|
[2374] | 273 | |
---|
[24] | 274 | for (i = 0; i < info[1]; i++) |
---|
[3529] | 275 | mixer->mixer[i] = ROAR_NET2HOST16(info[i+5]); |
---|
[24] | 276 | |
---|
| 277 | return 0; |
---|
| 278 | } |
---|
[0] | 279 | |
---|
| 280 | // converts: *_m2*, *_*2m |
---|
| 281 | |
---|
| 282 | int roar_ctl_f2m (struct roar_message * m, unsigned char filter, unsigned char cmp, uint32_t id) { |
---|
| 283 | |
---|
| 284 | m->datalen = 7; |
---|
| 285 | |
---|
| 286 | m->data[0] = 0; |
---|
| 287 | m->data[1] = filter; |
---|
| 288 | m->data[2] = cmp; |
---|
| 289 | *((uint32_t*)&(m->data[3])) = ROAR_HOST2NET32(id); |
---|
| 290 | |
---|
| 291 | return 0; |
---|
| 292 | } |
---|
| 293 | int roar_ctl_m2f (struct roar_message * m, unsigned char * filter, unsigned char * cmp, uint32_t * id) { |
---|
| 294 | |
---|
| 295 | if ( m->datalen != 7 ) |
---|
| 296 | return -1; |
---|
| 297 | |
---|
| 298 | if ( m->data[0] != 0 ) { |
---|
| 299 | ROAR_ERR("roar_ctl_m2f(*): version %i not supported!", m->data[0]); |
---|
| 300 | return -1; |
---|
| 301 | } |
---|
| 302 | |
---|
| 303 | *filter = m->data[1]; |
---|
| 304 | *cmp = m->data[2]; |
---|
| 305 | |
---|
| 306 | *id = ROAR_NET2HOST32(*((uint32_t*)&(m->data[3]))); |
---|
| 307 | |
---|
| 308 | return 0; |
---|
| 309 | } |
---|
| 310 | |
---|
| 311 | int roar_ctl_ia2m (struct roar_message * m, int * data, int len) { |
---|
| 312 | int i; |
---|
| 313 | |
---|
| 314 | if ( len > LIBROAR_BUFFER_MSGDATA ) |
---|
| 315 | return -1; |
---|
| 316 | |
---|
| 317 | m->datalen = len; |
---|
| 318 | |
---|
| 319 | for (i = 0; i < len; i++) |
---|
| 320 | m->data[i] = data[i]; |
---|
| 321 | |
---|
| 322 | return 0; |
---|
| 323 | } |
---|
| 324 | int roar_ctl_m2ia (struct roar_message * m, int * data, int len) { |
---|
| 325 | int i; |
---|
| 326 | |
---|
| 327 | if ( m->datalen > len ) |
---|
| 328 | return -1; |
---|
| 329 | |
---|
| 330 | for (i = 0; i < m->datalen; i++) |
---|
| 331 | data[i] = m->data[i]; |
---|
| 332 | |
---|
| 333 | return m->datalen; |
---|
| 334 | } |
---|
| 335 | |
---|
| 336 | int roar_ctl_c2m (struct roar_message * m, struct roar_client * c) { |
---|
| 337 | int cur = 0; |
---|
| 338 | int h; |
---|
| 339 | int i; |
---|
| 340 | int max_len; |
---|
[434] | 341 | uint32_t pid; |
---|
[2811] | 342 | size_t len_rest; |
---|
[0] | 343 | |
---|
| 344 | if ( c == NULL ) |
---|
| 345 | return -1; |
---|
| 346 | |
---|
| 347 | m->data[cur++] = 0; // 0: Version |
---|
| 348 | m->data[cur++] = c->execed; // 1: execed |
---|
| 349 | |
---|
| 350 | h = 0; |
---|
| 351 | for (i = 0; i < ROAR_CLIENTS_MAX_STREAMS_PER_CLIENT; i++) { |
---|
| 352 | if ( c->streams[i] != -1 ) |
---|
| 353 | m->data[cur+1+h++] = c->streams[i]; |
---|
| 354 | } |
---|
| 355 | |
---|
| 356 | m->data[cur++] = h; // 2: num of streams |
---|
| 357 | cur += h; |
---|
| 358 | |
---|
| 359 | max_len = strlen(c->name); |
---|
| 360 | |
---|
| 361 | // TODO: add some code to check if this fits in the pkg |
---|
| 362 | // NOTE: add this code after we are sure how long this pkg will be |
---|
| 363 | // and fully decieded about this function. |
---|
| 364 | |
---|
| 365 | m->data[cur++] = max_len; |
---|
| 366 | |
---|
| 367 | strncpy((m->data)+cur, c->name, max_len); |
---|
| 368 | |
---|
| 369 | cur += max_len; |
---|
| 370 | |
---|
[434] | 371 | pid = ROAR_HOST2NET32(c->pid); |
---|
[438] | 372 | memcpy(&(m->data[cur]), &pid, 4); |
---|
| 373 | cur += 4; |
---|
[434] | 374 | |
---|
[438] | 375 | pid = ROAR_HOST2NET32(c->uid); |
---|
| 376 | memcpy(&(m->data[cur]), &pid, 4); |
---|
| 377 | cur += 4; |
---|
| 378 | |
---|
| 379 | pid = ROAR_HOST2NET32(c->gid); |
---|
[434] | 380 | memcpy(&(m->data[cur]), &pid, 4); |
---|
| 381 | cur += 4; |
---|
| 382 | |
---|
[2544] | 383 | pid = ROAR_HOST2NET32(c->proto); |
---|
| 384 | memcpy(&(m->data[cur]), &pid, 4); |
---|
| 385 | cur += 4; |
---|
| 386 | |
---|
[2616] | 387 | pid = ROAR_HOST2NET32(c->byteorder); |
---|
| 388 | memcpy(&(m->data[cur]), &pid, 4); |
---|
| 389 | cur += 4; |
---|
| 390 | |
---|
[2811] | 391 | len_rest = sizeof(m->data) - cur; |
---|
| 392 | if ( roar_nnode_to_blob(&(c->nnode), &(m->data[cur]), &len_rest) == 0 ) { |
---|
| 393 | cur += len_rest; |
---|
| 394 | } |
---|
| 395 | |
---|
[0] | 396 | m->datalen = cur; |
---|
| 397 | |
---|
| 398 | return 0; |
---|
| 399 | } |
---|
| 400 | |
---|
| 401 | int roar_ctl_m2c (struct roar_message * m, struct roar_client * c) { |
---|
| 402 | int i; |
---|
| 403 | int cur; |
---|
[434] | 404 | uint32_t pid; |
---|
[2811] | 405 | size_t len; |
---|
[0] | 406 | |
---|
| 407 | if ( m == NULL || c == NULL ) |
---|
| 408 | return -1; |
---|
| 409 | |
---|
| 410 | if ( m->datalen == 0 ) |
---|
| 411 | return -1; |
---|
| 412 | |
---|
| 413 | ROAR_DBG("roar_ctl_m2c(*): got data!, len = %i", m->datalen); |
---|
| 414 | |
---|
| 415 | if ( m->data[0] != 0 ) { |
---|
| 416 | ROAR_DBG("roar_ctl_m2c(*): wrong version!"); |
---|
| 417 | return -1; |
---|
| 418 | } |
---|
| 419 | |
---|
| 420 | if ( m->datalen < 3 ) |
---|
| 421 | return -1; |
---|
| 422 | |
---|
| 423 | ROAR_DBG("roar_ctl_m2c(*): have usable data!"); |
---|
| 424 | |
---|
| 425 | c->execed = m->data[1]; |
---|
| 426 | |
---|
| 427 | for (i = 0; i < ROAR_CLIENTS_MAX_STREAMS_PER_CLIENT; i++) |
---|
| 428 | c->streams[i] = -1; |
---|
| 429 | |
---|
| 430 | for (i = 0; i < m->data[2]; i++) |
---|
| 431 | c->streams[i] = m->data[3+i]; |
---|
| 432 | |
---|
| 433 | cur = 3 + m->data[2]; |
---|
| 434 | |
---|
| 435 | strncpy(c->name, (m->data)+cur+1, m->data[cur]); |
---|
[17] | 436 | c->name[(int)m->data[cur]] = 0; |
---|
[0] | 437 | |
---|
[434] | 438 | cur += m->data[cur] + 1; |
---|
| 439 | |
---|
| 440 | memcpy(&pid, &(m->data[cur]), 4); |
---|
| 441 | c->pid = ROAR_NET2HOST32(pid); |
---|
| 442 | cur += 4; |
---|
| 443 | |
---|
[438] | 444 | memcpy(&pid, &(m->data[cur]), 4); |
---|
| 445 | c->uid = ROAR_NET2HOST32(pid); |
---|
| 446 | cur += 4; |
---|
| 447 | |
---|
| 448 | memcpy(&pid, &(m->data[cur]), 4); |
---|
| 449 | c->gid = ROAR_NET2HOST32(pid); |
---|
| 450 | cur += 4; |
---|
| 451 | |
---|
[2544] | 452 | if ( m->datalen >= cur+4 ) { |
---|
| 453 | memcpy(&pid, &(m->data[cur]), 4); |
---|
| 454 | c->proto = ROAR_NET2HOST32(pid); |
---|
| 455 | cur += 4; |
---|
| 456 | } else { |
---|
| 457 | c->proto = ROAR_PROTO_NONE; |
---|
| 458 | } |
---|
| 459 | |
---|
[2616] | 460 | if ( m->datalen >= cur+4 ) { |
---|
| 461 | memcpy(&pid, &(m->data[cur]), 4); |
---|
| 462 | c->byteorder = ROAR_NET2HOST32(pid); |
---|
| 463 | cur += 4; |
---|
| 464 | } else { |
---|
| 465 | c->byteorder = ROAR_BYTEORDER_UNKNOWN; |
---|
| 466 | } |
---|
| 467 | |
---|
[2811] | 468 | if ( m->datalen > cur ) { |
---|
| 469 | len = m->datalen - cur; |
---|
| 470 | if ( roar_nnode_from_blob(&(c->nnode), &(m->data[cur]), &len) == 0 ) { |
---|
| 471 | cur += len; |
---|
| 472 | } else { |
---|
| 473 | if ( roar_nnode_new(&(c->nnode), ROAR_SOCKET_TYPE_UNKNOWN) == -1 ) |
---|
| 474 | return -1; |
---|
| 475 | } |
---|
| 476 | } else { |
---|
| 477 | if ( roar_nnode_new(&(c->nnode), ROAR_SOCKET_TYPE_UNKNOWN) == -1 ) |
---|
| 478 | return -1; |
---|
| 479 | } |
---|
| 480 | |
---|
[0] | 481 | return 0; |
---|
| 482 | } |
---|
| 483 | |
---|
[2548] | 484 | int roar_str2proto (char * proto) { |
---|
| 485 | if ( !strcasecmp(proto, "roar") ) { |
---|
| 486 | return ROAR_PROTO_ROARAUDIO; |
---|
| 487 | } else if ( !strcasecmp(proto, "roaraudio") ) { |
---|
| 488 | return ROAR_PROTO_ROARAUDIO; |
---|
| 489 | } else if ( !strcasecmp(proto, "esd") ) { |
---|
| 490 | return ROAR_PROTO_ESOUND; |
---|
| 491 | } else if ( !strcasecmp(proto, "esound") ) { |
---|
| 492 | return ROAR_PROTO_ESOUND; |
---|
[2857] | 493 | } else if ( !strcasecmp(proto, "auto") ) { |
---|
| 494 | return ROAR_PROTO_AUTO; |
---|
| 495 | } else if ( !strcasecmp(proto, "(auto)") ) { |
---|
| 496 | return ROAR_PROTO_AUTO; |
---|
| 497 | } else if ( !strcasecmp(proto, "http") ) { |
---|
| 498 | return ROAR_PROTO_HTTP; |
---|
| 499 | } else if ( !strcasecmp(proto, "gopher") ) { |
---|
| 500 | return ROAR_PROTO_GOPHER; |
---|
| 501 | } else if ( !strcasecmp(proto, "icy") ) { |
---|
| 502 | return ROAR_PROTO_ICY; |
---|
[3251] | 503 | } else if ( !strcasecmp(proto, "simple") ) { |
---|
| 504 | return ROAR_PROTO_SIMPLE; |
---|
[3683] | 505 | } else if ( !strcasecmp(proto, "rsound") ) { |
---|
| 506 | return ROAR_PROTO_RSOUND; |
---|
[2548] | 507 | } |
---|
| 508 | |
---|
| 509 | return -1; |
---|
| 510 | } |
---|
| 511 | |
---|
| 512 | char * roar_proto2str (int proto) { |
---|
| 513 | switch (proto) { |
---|
| 514 | case ROAR_PROTO_ROARAUDIO: return "RoarAudio"; break; |
---|
| 515 | case ROAR_PROTO_ESOUND: return "EsounD"; break; |
---|
[2857] | 516 | case ROAR_PROTO_AUTO: return "(auto)"; break; |
---|
| 517 | case ROAR_PROTO_HTTP: return "http"; break; |
---|
| 518 | case ROAR_PROTO_GOPHER: return "gopher"; break; |
---|
| 519 | case ROAR_PROTO_ICY: return "ICY"; break; |
---|
[3258] | 520 | case ROAR_PROTO_SIMPLE: return "Simple"; break; |
---|
[3683] | 521 | case ROAR_PROTO_RSOUND: return "RSound"; break; |
---|
[2548] | 522 | default: |
---|
| 523 | return "(unknown)"; |
---|
| 524 | } |
---|
| 525 | } |
---|
| 526 | |
---|
[2615] | 527 | int roar_str2byteorder (char * byteorder) { |
---|
| 528 | if ( !strcasecmp(byteorder, "le") || !strcasecmp(byteorder, "little") || |
---|
| 529 | !strcasecmp(byteorder, "little endian") || !strcasecmp(byteorder, "1234") ) { |
---|
| 530 | return ROAR_BYTEORDER_LE; |
---|
| 531 | } else if ( !strcasecmp(byteorder, "be") || !strcasecmp(byteorder, "big") || |
---|
| 532 | !strcasecmp(byteorder, "big endian") || !strcasecmp(byteorder, "4321") ) { |
---|
| 533 | return ROAR_BYTEORDER_BE; |
---|
| 534 | } else if ( !strcasecmp(byteorder, "pdp") || |
---|
| 535 | !strcasecmp(byteorder, "pdp endian") ) { |
---|
| 536 | return ROAR_BYTEORDER_PDP; |
---|
| 537 | } else if ( !strcasecmp(byteorder, "network") || |
---|
| 538 | !strcasecmp(byteorder, "network byteorder") ) { |
---|
| 539 | return ROAR_BYTEORDER_NETWORK; |
---|
| 540 | } |
---|
| 541 | |
---|
| 542 | return -1; |
---|
| 543 | } |
---|
| 544 | |
---|
| 545 | char * roar_byteorder2str (int byteorder) { |
---|
| 546 | switch (byteorder) { |
---|
| 547 | case ROAR_BYTEORDER_LE: return "little endian"; break; |
---|
| 548 | case ROAR_BYTEORDER_BE: return "big endian"; break; |
---|
| 549 | case ROAR_BYTEORDER_PDP: return "pdp endian"; break; |
---|
| 550 | // case ROAR_BYTEORDER_NETWORK: return "network"; break; |
---|
| 551 | default: |
---|
| 552 | return "(unknown)"; |
---|
| 553 | } |
---|
| 554 | } |
---|
| 555 | |
---|
[0] | 556 | //ll |
---|