added libjson-c. added driver, webinterface and userspace daemon for the
[openwrt.git] / package / fonera-mp3 / src / lib / mp3_socket_parser.c
1 /*
2 * FOXMP3
3 * Copyright (c) 2006 acmesystems.it - john@acmesystems.it
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA02111-1307USA
18 *
19 * Feedback, Bugs... info@acmesystems.it
20 *
21 */
22
23 #include <stdio.h>
24 #include <string.h>
25 #include <stdlib.h>
26
27 #include "mp3.h"
28
29 #define TOKEN_MAX 16
30 #define TOKEN_SIZE 256
31
32 static unsigned char mp3_parser_tokens[TOKEN_MAX][TOKEN_SIZE];
33
34 int mp3_parser_tokenize(unsigned char *in){
35 int i = 0;
36 char *token = in;
37 char *tmp;
38 do {
39 tmp = strstr(token, " ");
40 if(tmp){
41 *tmp = '\0';
42 strcpy(mp3_parser_tokens[i], token);
43 tmp++;
44 token = tmp;
45 } else {
46 strcpy(mp3_parser_tokens[i], token);
47 };
48 i++;
49 }while((i < TOKEN_MAX) && (tmp));
50 return i;
51 };
52
53 extern int state_current;
54 void mp3_parser_incoming(unsigned char *in, unsigned char *out){
55 int c = mp3_parser_tokenize(in);
56 int ret = 0;
57 int t1;
58 if(c){
59 printf("Parsing command from frontend app -> %s --- %d tokens\n", in, c);
60 if((!strcmp(mp3_parser_tokens[0], "PLAY")) && (c == 2)){
61 state_event(MP3_EVENT_FILE, state_new_event(mp3_parser_tokens[1], 0));
62 ret = 1;
63 } else if((!strcmp(mp3_parser_tokens[0], "STREAM"))
64 && (c == 3)){
65 if(!strcmp(mp3_parser_tokens[1], "pls")){
66 state_event(MP3_EVENT_STREAM, state_new_event(mp3_parser_tokens[2], STREAM_PLS));
67 ret = 1;
68 } else if(!strcmp(mp3_parser_tokens[1], "url")){
69 state_event(MP3_EVENT_STREAM, state_new_event(mp3_parser_tokens[2], STREAM_URL));
70 ret = 1;
71 }
72 } else if((!strcmp(mp3_parser_tokens[0], "VOLUME"))
73 && (c == 2)){
74 t1 = atoi(mp3_parser_tokens[1]);
75 state_generic_event(MP3_EVENT_GENERIC_VOLUME, t1, NULL);
76 ret = 1;
77 } else if((!strcmp(mp3_parser_tokens[0], "STOP"))
78 && (c == 1)){
79 state_event(MP3_EVENT_STOP, NULL);
80 ret = 1;
81 } else if((!strcmp(mp3_parser_tokens[0], "STATE"))
82 && (c == 1)){
83 state_generic_event(MP3_EVENT_GENERIC_STATE, 0, out);
84 return;
85 } else if((!strcmp(mp3_parser_tokens[0], "BASS"))
86 && (c == 2)){
87 t1 = atoi(mp3_parser_tokens[1]);
88 state_generic_event(MP3_EVENT_GENERIC_BASS, t1, NULL);
89 ret = 1;
90 }
91 if(ret){
92 sprintf(out, "OK\n");
93 printf("Command parsed ok.\n");
94 } else {
95
96 sprintf(out, "ERROR\n");
97 printf("Command parsed with error.\n");
98 };
99 } else {
100 printf("Got command from frontend with 0 tokens.\n");
101 };
102 };
103
104
This page took 0.052393 seconds and 5 git commands to generate.