1 //
2 // anyRemote
3 // a wi-fi or bluetooth remote for your PC.
4 //
5 // Copyright (C) 2006-2016 Mikhail Fedotov <anyremote@mail.ru>
6 //
7 // This program is free software; you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License as published by
9 // the Free Software Foundation; either version 3 of the License, or
10 // (at your option) any later version.
11 //
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 // GNU General Public License for more details.
16 //
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
20 //
21 
22 #ifndef _PARSE_H_
23 #define _PARSE_H_ 1
24 
25 #include "common.h"
26 #include "list.h"
27 #include <sys/types.h>
28 #include <unistd.h>
29 
30 #define CFGFILE 	"/.anyremote.cfg"
31 
32 /* Constants */
33 #define MAXARGLEN   	256
34 #define MAXNAMELEN   	512
35 #define MAXCMDLEN   	1024
36 
37 #define KEYS_SECTION_STR     "[Keys]"
38 #define PROTOCOL_SECTION_STR "[Protocol]"
39 #define MODE_END_STR         "[ModeEnd]"
40 #define MODE_STR    	     "[Mode]"
41 #define SECTION_END_STR      "[End]"
42 
43 // Some AT stuff
44 // \r will be added before send
45 #define DEF_AT_CMER_ON_DEFAULT   "AT+CMER=3,2,0,0,0" 	// Default, valid for SE and Siemens S55 phones
46 #define DEF_AT_CMER_OFF_DEFAULT  "AT+CMER=0,0,0,0,0"
47 #define DEF_AT_CMER_ON_SE        "AT+CMER=3,2,0,0,0" 	// SE, same as default
48 #define DEF_AT_CMER_OFF_SE       "AT+CMER=0,0,0,0,0"
49 #define DEF_AT_CMER_ON_MOTOROLA  "AT+CMER=3,1,0,0,0" 	// Motorola phones
50 #define DEF_AT_CMER_OFF_MOTOROLA "AT+CMER=0,0,0,0,0"
51 #define DEF_AT_CMER_ON_SAGEM     "AT+CMER=2,1,0,0,0" 	// Sagem phones
52 #define DEF_AT_CMER_OFF_SAGEM    "AT+CMER=0,0,0,0,0"
53 #define DEF_AT_CMER_ON_SIEMENS   "AT+CMER=3,2,0,0,0" 	// Siemens phones, same as default
54 #define DEF_AT_CMER_OFF_SIEMENS  "AT+CMER=0,0,0,0,0"
55 
56 #define DEF_AT_CGMI     "AT+CGMI"
57 #define DEF_AT_CLCC     "AT+CLCC"		// ? will be added later (will try both variants)
58 #define DEF_AT_CSCS     "AT+CSCS="
59 #define DEF_AT_CKPD 	"AT+CKPD="
60 #define DEF_AT_CLIP 	"AT+CLIP=1"
61 #define DEF_AT_CMEC 	"AT+CMEC=2"		// used by Siemens to made AT+CKPD works
62 #define DEF_CKEV 	"+CKEV:"
63 #define DEF_CLCC 	"+CLCC:"
64 #define DEF_RING 	"RING"			// It could be RING or +CRING (depends on AT+CRC)
65 #define DEF_MSG 	"Msg:"			// Used by Java Client
66 #define DEF_CLDEBUG "Msg:_DEBUG_("	// Used by Java Client
67 #define DEF_CLPING  "Msg:Ping"	    // Used by Java Client
68 
69 #define CMER_ON  	1
70 #define CMER_OFF  	2
71 
72 #define SAME 	    	99
73 #define PAUSE_STR   	"PAUSE"
74 
75 enum EventID {
76     ID_EVT_INIT = 0,
77     ID_EVT_EXIT,
78     ID_EVT_CONNECT,
79     ID_EVT_DISCONNECT,
80     ID_EVT_MAX
81 };
82 
83 #define EVT_INIT     	"(Init)"
84 #define EVT_EXIT        "(Exit)"
85 #define EVT_CONNECT     "(Connect)"
86 #define EVT_DISCONNECT  "(Disconnect)"
87 #define EVT_ENTRMODE	"(EnterMode)"
88 #define EVT_EXITMODE    "(ExitMode)"
89 
90 #define ID_UNKNOWN    	-1
91 
92 enum CommandID {
93     ID_EXIT = 0,
94     ID_EXEC,
95     ID_SENDCKPD,
96     ID_SET,
97     ID_EXECSET,
98     ID_TIMER,
99     ID_SEND,
100     ID_EXECSEND,
101     ID_MACRO,
102     ID_LOAD,
103     ID_INCLUDE,
104     ID_GET,
105     ID_MAKE,
106     ID_EMU,
107     ID_DBUS,
108     ID_CMD_MAX
109 };
110 
111 #define CMD_EXIT    	"Exit"
112 #define CMD_EXEC        "Exec"
113 #define CMD_SENDCKPD    "SendCKPD"		// AT mode only
114 #define CMD_SET         "Set"			// Server mode only
115 #define CMD_EXECSET     "ExecAndSet"		// Server mode only
116 #define CMD_TIMER       "Timer"
117 #define CMD_SEND        "Send"  		// Server mode only, used for Bemused-server emulation
118 #define CMD_EXECSEND    "ExecAndSend"		// Server mode only, used for Bemused-server emulation
119 #define CMD_MACRO       "Macro"
120 #define CMD_LOAD        "Load"
121 #define CMD_INCLUDE     "Include"
122 #define CMD_GET         "Get"			// Server mode only
123 #define CMD_MAKE        "Make"
124 #define CMD_EMU         "Emulate"
125 #define CMD_DBUS        "Dbus"
126 
127 #define SET_BG          "bg"
128 #define SET_CAPTION     "caption"
129 #define SET_PARAM       "parameter"
130 #define SET_EFIELD      "editfield"
131 #define SET_FG          "fg"
132 #define SET_FMGR        "filemanager"
133 #define SET_FONT        "font"
134 #define SET_FSCREEN     "fullscreen"
135 #define SET_ICONS       "icons"
136 #define SET_HINTS       "hints"
137 #define SET_LIST        "list"
138 #define SET_ILIST       "iconlist"
139 #define SET_MENU        "menu"
140 #define SET_REPAINT     "repaint"
141 #define SET_SKIN        "skin"	// obsolete
142 #define SET_LAYOUT      "layout"
143 #define SET_STATUS      "status"
144 #define SET_TEXT        "text"
145 #define SET_TITLE       "title"
146 #define SET_VIBRATE     "vibrate"
147 #define SET_VOLUME      "volume"
148 #define SET_IMAGE       "image"
149 #define SET_COVER       "cover"
150 #define SET_POPUP       "popup"
151 #define SET_DISCONN     "disconnect"
152 
153 enum CommandSetID {
154     ID_SET_BG = 0,
155     ID_SET_CAPTION,
156     ID_SET_PARAM,
157     ID_SET_EFIELD,
158     ID_SET_FG,
159     ID_SET_FMGR,
160     ID_SET_FONT,
161     ID_SET_FSCREEN,
162     ID_SET_ICONS,
163     ID_SET_HINTS,
164     ID_SET_LIST,
165     ID_SET_ILIST,
166     ID_SET_MENU,
167     ID_SET_REPAINT,
168     ID_SET_LAYOUT,
169     ID_SET_STATUS,
170     ID_SET_TEXT,
171     ID_SET_TITLE,
172     ID_SET_VIBRATE,
173     ID_SET_VOLUME,
174     ID_SET_IMAGE,
175     ID_SET_COVER,
176     ID_SET_POPUP,
177     ID_SET_DISCONN,
178     ID_SET_MAX
179 };
180 
181 #define MAKE_DISCONN    "disconnect"
182 #define MAKE_MODE       "mode"
183 #define MAKE_ALARM      "alarm"
184 #define MAKE_FLUSH      "flush"
185 #define MAKE_STOP       "stop"
186 #define MAKE_REMOTE     "remote"
187 #define MAKE_VAR        "var"
188 #define MAKE_EXIT       "exit"
189 #define MAKE_NONE       "none"
190 
191 enum CommandMakeID {
192     ID_MAKE_DISCONN = 0,
193     ID_MAKE_MODE,
194     ID_MAKE_ALARM,
195     ID_MAKE_FLUSH,
196     ID_MAKE_STOP,
197     ID_MAKE_REMOTE,
198     ID_MAKE_VAR,
199     ID_MAKE_EXIT,
200     ID_MAKE_NONE,
201     ID_MAKE_MAX
202 };
203 
204 #define GET_SCREENSIZE  "screen_size"
205 #define GET_COVERSIZE   "cover_size"
206 #define GET_ICONSIZE    "icon_size"
207 #define GET_ICONPADDING "icon_padding"
208 #define GET_MODEL       "model"
209 #define GET_VERSION     "version"
210 #define GET_CURSOR      "cursor"
211 #define GET_PING        "ping"
212 #define GET_PASSWORD    "password"
213 #define GET_ISEXISTS    "is_exists"
214 
215 enum CommandGetID {
216     ID_GET_SCREENSIZE = 0,
217     ID_GET_COVERSIZE,
218     ID_GET_ICONSIZE,
219     ID_GET_ICONPADDING,
220     ID_GET_MODEL,
221     ID_GET_VERSION,
222     ID_GET_CURSOR,
223     ID_GET_PING,
224     ID_GET_PASSWORD,
225     ID_GET_ISEXISTS,
226     ID_GET_MAX
227 };
228 
229 enum CommandEventID {
230     ID_EVENT_FRONTEND,
231     ID_EVENT_INIT,
232     ID_EVENT_DISCONNECT,
233     ID_EVENT_EXIT,
234 };
235 
236 #define TIMER_CANCEL   "cancel"
237 #define TIMER_PAUSE    "pause"
238 #define TIMER_RESET    "reset"
239 #define TIMER_RESTART  "restart"
240 #define TIMER_CONTINUE "continue"
241 
242 enum CommandTimerID {
243     ID_TIMER_CREATE = 0,
244     ID_TIMER_CANCEL,
245     ID_TIMER_PAUSE,
246     ID_TIMER_RESET,
247     ID_TIMER_RESTART,
248     ID_TIMER_CONTINUE,
249     ID_TIMER_MAX
250 };
251 
252 #define UPLOAD_ICON    "image,icon"
253 #define UPLOAD_PIX     "image,window"
254 #define UPLOAD_COVER   "image,cover"
255 #define UPLOAD_COVER_DATA "cover,noname"
256 
257 #define STR_MOTOROLA	"Motorola"
258 #define STR_SE   	    "Sony Ericsson"
259 #define STR_SAGEM	    "SAGEM"
260 #define STR_SIEMENS   	"SIEMENS"
261 
262 #define MODEL_DEFAULT	0
263 #define MODEL_SE	    1
264 #define MODEL_MOTOROLA	2
265 #define MODEL_SAGEM	    3
266 #define MODEL_SIEMENS	4
267 
268 #define FLAG_EXACT	-1 // All non-negative values could be indexes in the list
269 #define FLAG_MULTIKEY	-2
270 #define FLAG_PARAMETR	 1
271 #define FLAG_UNDEF	-3
272 
273 typedef struct Ci {
274     int        type;
275     int        subtype;
276     char       *descr;
277     char       *exec;
278 } cmdItem;
279 
280 typedef struct Tk {
281     char        *key;
282     SingleList  *commands;  // list of cmdItem*
283     struct Tk   *next;
284 } type_key;
285 
286 typedef struct Cp {
287     char       index[6];
288     char       value[MAXARGLEN+1];
289 } cmdParams;
290 
291 typedef struct {
292     int   model;
293     int   frontEnd;
294     uid_t   uid;
295     gid_t   gid;
296 } CONF;
297 
298 // Exported functions definitions
299 
300 const char* id2Cmd      (int cmdId);
301 void  init_cfg_dir      (char *path);
302 int   init_cfg          (char *path);
303 void  freeRegexps       (void);
304 int   parse_opts        (int argc, char *argv[]);
305 int   storeCmds         (SingleList** commands, const char *value);
306 int   load_cfg		(const char *mfile, int isInit);
307 int   cmdSet2id         (const char *what_to_set);
308 
309 #endif
310