aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/libraries
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/libraries/SledjHamr.c169
1 files changed, 105 insertions, 64 deletions
diff --git a/src/libraries/SledjHamr.c b/src/libraries/SledjHamr.c
index 7092c10..1fae167 100644
--- a/src/libraries/SledjHamr.c
+++ b/src/libraries/SledjHamr.c
@@ -91,81 +91,122 @@ static boolean checkConnection(Connection *conn, char *func, connType wanted, bo
91 91
92typedef boolean (* notFoundCb)(Connection *conn, char *command, int len); 92typedef boolean (* notFoundCb)(Connection *conn, char *command, int len);
93 93
94/* TODO -
95 It should loop through all lines, looking for the closing ) before dealing with it.
96 If we get to the end, and there's left over open ( or something, then return the length.
97 Bitch and move on if it's not well formed.
98*/
99static int _checkForCommand(Connection *conn, char *commands, notFoundCb notFound, boolean in) 94static int _checkForCommand(Connection *conn, char *commands, notFoundCb notFound, boolean in)
100{ 95{
101 int result = 0; 96 int result = 0;
102 boolean handled = FALSE; 97 boolean handled = FALSE;
103 char *ext, *ext2; 98 char *ext = NULL, *ext1 = NULL, *ext2 = NULL, *ext3 = NULL;
104 99
105 while ((ext = index(commands, '\n')))
106 {
107 char SID[PATH_MAX * 3];
108 int length = ext - commands;
109 100
110 strncpy(SID, commands, length + 1); 101 char *p = commands, name[64], command[32], arguments[PATH_MAX * 3];
111 102
112 SID[length] = '\0'; 103 name[0] = 0;
104 command[0] = 0;
105 arguments[0] = 0;
106 ext = p;
113 107
114 ext = index(SID, '.'); 108 while (*p)
115 if (ext) 109 {
110 switch (*p)
116 { 111 {
117 char *command = ext + 1; 112 case '.' :
113 if (NULL == ext1)
114 {
115 *p = 0;
116 strncpy(name, ext, sizeof(name));
117 name[sizeof(name) - 1] = 0;
118 *p = '.';
119 ext1 = p + 1;
120 }
121 break;
118 122
119 ext[0] = '\0'; 123 case '(' :
120 ext2 = index(command, '('); 124 if ((NULL != ext1) && (NULL == ext2))
121 if (NULL == ext2) 125 {
122 ext2 = index(command, ' '); 126 *p = 0;
123 if (ext2) 127 strncpy(command, ext1, sizeof(command));
124 { 128 command[sizeof(command) - 1] = 0;
125 ext2[0] = '\0'; 129 *p = '(';
126 // TODO - Currently SID.command(arguments), should change that to nameSpace.command(arguments) 130 ext2 = p + 1;
127 // Not sure what to do with SID, but there maybe some common parameters we can shift around differently. 131 }
128 // - First check if the connection has a hashtable of conn->commands. 132 break;
129 //* Next check if "nameSpace.command(arguments)" runs as Lua.
130 // or even the return values from returnWanted calls like -
131 // SID, "return 1"
132 // SID, "result + 5"
133 // SID, "script.SID.return(1)"
134 // Finally pass it to conn->unknownCommand()
135 // * The Lua check can live in unknownCommand().
136 // else bitch.
137
138 // Check if it's in the connections hash table.
139 streamParser func = eina_hash_find(conn->commands, command);
140
141 if (NULL == func)
142 {
143 // Check if the connection has a function for handling it.
144 if (in)
145 func = conn->unknownInCommand;
146 else
147 func = conn->unknownOutCommand;
148 }
149 133
150 // Try it out if we have a function. 134 case ')' :
151 if (func) 135 if (NULL != ext2) // Keep scanning until we get the last one.
152 { 136 {
153 handled = func(conn->pointer, conn, SID, command, ext2 + 1); 137 *p = 0;
154 if (handled) 138 strncpy(arguments, ext2, sizeof(arguments));
155 notFound = NULL; 139 arguments[sizeof(arguments) - 1] = 0;
156 } 140 *p = ')';
141 ext3 = p + 1;
142 }
143 break;
157 144
158 // Last resort, let the caller deal with it. 145 case '\n' :
159 if (notFound) 146 if ((NULL != ext3) && (0 != name[0]) && (0 != command[0]))
160 handled = notFound(conn, commands, length + 1); 147 {
161 if (!handled) 148 int length = p - ext + 1;
162 PE("No function found for command %s(%s!", command, ext2 + 1); 149//PD("name: %s command: %s arguments %s|", name, command, arguments);
150 // TODO - Currently SID.command(arguments), should change that to nameSpace.command(arguments)
151 // Not sure what to do with SID, but there maybe some common parameters we can shift around differently.
152 // - First check if the connection has a hashtable of conn->commands.
153 //* Next check if "nameSpace.command(arguments)" runs as Lua.
154 // or even the return values from returnWanted calls like -
155 // SID, "return(1)"
156 // SID, "result + 5"
157 // SID, "script.SID.return(1)"
158 // Finally pass it to conn->unknownCommand()
159 // * The Lua check can live in unknownCommand().
160 // else bitch.
161
162 // Check if it's in the connections hash table.
163 streamParser func = eina_hash_find(conn->commands, command);
164
165 if (NULL == func)
166 {
167 // Check if the connection has a function for handling it.
168 if (in)
169 func = conn->unknownInCommand;
170 else
171 func = conn->unknownOutCommand;
172 }
173
174 // Try it out if we have a function.
175 if (func)
176 {
177 handled = func(conn->pointer, conn, name, command, arguments);
178 if (handled)
179 notFound = NULL;
180 }
181
182 // Last resort, let the caller deal with it.
183 if (notFound)
184 handled = notFound(conn, commands, length);
185 if (!handled)
186 PE("No function found for command %s.%s(%s)!", name, command, arguments);
187
188 result += length;
189
190 name[0] = 0;
191 command[0] = 0;
192 arguments[0] = 0;
193 ext = p + 1;
194 ext1 = NULL;
195 ext2 = NULL;
196 ext3 = NULL;
197 }
198 else if ((p != ext))
199 {
200 *p = 0;
201 PE("ERROR scanning |%s|", ext);
202 *p = '\n';
203 }
204 break;
163 205
164 result += length; 206 default :
165 } 207 break;
166 } 208 }
167 209 p++;
168 commands = &commands[length + 1];
169 } 210 }
170 211
171 return result; 212 return result;
@@ -178,13 +219,13 @@ static boolean _actuallySendIt(Connection *conn, char *command, int len)
178 switch (conn->type) 219 switch (conn->type)
179 { 220 {
180 case CT_CLIENT : 221 case CT_CLIENT :
181// PD("vvv send2(%*s", len, command); 222//PD("vvv send2(%*s", len, command);
182 ecore_con_client_send(conn->conn.client.client, strndup(command, len), len); 223 ecore_con_client_send(conn->conn.client.client, strndup(command, len), len);
183 ecore_con_client_flush(conn->conn.client.client); 224 ecore_con_client_flush(conn->conn.client.client);
184 return TRUE; 225 return TRUE;
185 226
186 case CT_SERVER : 227 case CT_SERVER :
187// PD("^^^ send2(%*s", len, command); 228//PD("^^^ send2(%*s", len, command);
188 ecore_con_server_send(conn->conn.server.server, strndup(command, len), len); 229 ecore_con_server_send(conn->conn.server.server, strndup(command, len), len);
189 ecore_con_server_flush(conn->conn.server.server); 230 ecore_con_server_flush(conn->conn.server.server);
190 return TRUE; 231 return TRUE;
@@ -227,7 +268,7 @@ static Eina_Bool parseStream(void *data, int type, void *evData, int evSize, voi
227 conn->stream = eina_strbuf_new(); 268 conn->stream = eina_strbuf_new();
228 269
229 eina_strbuf_append_length(conn->stream, evData, evSize); 270 eina_strbuf_append_length(conn->stream, evData, evSize);
230//PD("%s", (char *) eina_strbuf_string_get(conn->stream)); 271//PD("****** %s", (char *) eina_strbuf_string_get(conn->stream));
231 eina_strbuf_remove(conn->stream, 0, _checkForCommand(conn, (char *) eina_strbuf_string_get(conn->stream), NULL, TRUE)); 272 eina_strbuf_remove(conn->stream, 0, _checkForCommand(conn, (char *) eina_strbuf_string_get(conn->stream), NULL, TRUE));
232 273
233 if (conn->_data) 274 if (conn->_data)