Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Initial v1.0 commit

  • Loading branch information...
commit 919d586037092636bd8ced36cc3d6465037f3c42 1 parent 5e89870
@paraboul paraboul authored
Showing with 465 additions and 212 deletions.
  1. 0  AUTHORS
  2. 0  COPYING
  3. 0  Makefile
  4. 0  README
  5. 0  bin/ape.conf
  6. 0  bin/controller.conf
  7. 0  bin/helloworld.conf
  8. 0  bin/mod_mysql.conf
  9. 0  modules/Makefile
  10. 0  modules/global_plugins.h
  11. 0  modules/lib/README
  12. 0  modules/libape-chat.c
  13. 0  modules/libape-controller.c
  14. 0  modules/libape-helloworld.c
  15. 0  modules/libape-mouse.c
  16. 0  modules/libape-mysql.c
  17. 0  modules/libape-mysql.h
  18. 0  modules/libape-setcord.c
  19. 0  modules/libape-spidermonkey.c
  20. 0  modules/plugins.h
  21. 0  src/base64.c
  22. 0  src/base64.h
  23. +4 −4 src/channel.c
  24. 0  src/channel.h
  25. +170 −155 src/cmd.c
  26. +7 −6 src/cmd.h
  27. 0  src/config.c
  28. 0  src/config.h
  29. +1 −1  src/entry.c
  30. +10 −0 src/extend.c
  31. 0  src/extend.h
  32. +2 −0  src/handle_http.c
  33. 0  src/handle_http.h
  34. 0  src/hash.c
  35. 0  src/hash.h
  36. 0  src/http.c
  37. 0  src/http.h
  38. +167 −32 src/json.c
  39. +32 −5 src/json.h
  40. 0  src/json_parser.c
  41. 0  src/json_parser.h
  42. 0  src/main.h
  43. 0  src/pipe.c
  44. 0  src/pipe.h
  45. 0  src/plugins.c
  46. 0  src/plugins.h
  47. 0  src/proxy.c
  48. 0  src/proxy.h
  49. +10 −7 src/raw.c
  50. 0  src/raw.h
  51. +4 −0 src/sock.c
  52. +0 −2  src/sock.h
  53. 0  src/ticks.c
  54. 0  src/ticks.h
  55. 0  src/users.c
  56. 0  src/users.h
  57. +56 −0 src/utils.c
  58. +2 −0  src/utils.h
View
0  AUTHORS 100644 → 100755
File mode changed
View
0  COPYING 100644 → 100755
File mode changed
View
0  Makefile 100644 → 100755
File mode changed
View
0  README 100644 → 100755
File mode changed
View
0  bin/ape.conf 100644 → 100755
File mode changed
View
0  bin/controller.conf 100644 → 100755
File mode changed
View
0  bin/helloworld.conf 100644 → 100755
File mode changed
View
0  bin/mod_mysql.conf 100644 → 100755
File mode changed
View
0  modules/Makefile 100644 → 100755
File mode changed
View
0  modules/global_plugins.h 100644 → 100755
File mode changed
View
0  modules/lib/README 100644 → 100755
File mode changed
View
0  modules/libape-chat.c 100644 → 100755
File mode changed
View
0  modules/libape-controller.c 100644 → 100755
File mode changed
View
0  modules/libape-helloworld.c 100644 → 100755
File mode changed
View
0  modules/libape-mouse.c 100644 → 100755
File mode changed
View
0  modules/libape-mysql.c 100644 → 100755
File mode changed
View
0  modules/libape-mysql.h 100644 → 100755
File mode changed
View
0  modules/libape-setcord.c 100644 → 100755
File mode changed
View
0  modules/libape-spidermonkey.c 100644 → 100755
File mode changed
View
0  modules/plugins.h 100644 → 100755
File mode changed
View
0  src/base64.c 100644 → 100755
File mode changed
View
0  src/base64.h 100644 → 100755
File mode changed
View
8 src/channel.c 100644 → 100755
@@ -338,7 +338,7 @@ unsigned int setlevel(USERS *user_actif, USERS *user_passif, CHANNEL *chan, unsi
json_attach(jlist, get_json_object_user(user_actif), JSON_OBJECT);
set_json("level", itos(lvl, level), &jlist);
- set_json("channel", NULL, &jlist);
+ set_json("pipe", NULL, &jlist);
json_attach(jlist, get_json_object_channel(chan), JSON_OBJECT);
newraw = forge_raw(RAW_SETLEVEL, jlist);
@@ -358,7 +358,7 @@ unsigned int setlevel(USERS *user_actif, USERS *user_passif, CHANNEL *chan, unsi
json_attach(jlist, get_json_object_user(NULL), JSON_OBJECT);
set_json("level", itos(lvl, level), &jlist);
- set_json("channel", NULL, &jlist);
+ set_json("pipe", NULL, &jlist);
json_attach(jlist, get_json_object_channel(chan), JSON_OBJECT);
newraw = forge_raw(RAW_SETLEVEL, jlist);
@@ -390,7 +390,7 @@ unsigned int settopic(USERS *user, CHANNEL *chan, const char *topic, acetables *
set_json("user", NULL, &jlist);
json_attach(jlist, get_json_object_user(user), JSON_OBJECT);
- set_json("channel", NULL, &jlist);
+ set_json("pipe", NULL, &jlist);
json_attach(jlist, get_json_object_channel(chan), JSON_OBJECT);
newraw = forge_raw(RAW_SETTOPIC, jlist);
@@ -432,7 +432,7 @@ void ban(CHANNEL *chan, USERS *banner, const char *ip, char *reason, unsigned in
set_json("banner", NULL, &jlist);
json_attach(jlist, get_json_object_user(NULL), JSON_OBJECT);
}
- set_json("channel", NULL, &jlist);
+ set_json("pipe", NULL, &jlist);
json_attach(jlist, get_json_object_channel(chan), JSON_OBJECT);
newraw = forge_raw(RAW_BAN, jlist);
View
0  src/channel.h 100644 → 100755
File mode changed
View
325 src/cmd.c 100644 → 100755
@@ -30,35 +30,34 @@
void do_register(acetables *g_ape) // register_raw("CMD", Nparam (without IP and time, with sessid), callback_func, NEEDSOMETHING?, g_ape);
{
- register_cmd("CONNECT", 1, cmd_connect, NEED_NOTHING, g_ape);
- register_cmd("PCONNECT", 1, cmd_pconnect, NEED_NOTHING, g_ape);
- register_cmd("SCRIPT", -1, cmd_script, NEED_NOTHING, g_ape);
-
- register_cmd("CHECK", 1, cmd_check, NEED_SESSID, g_ape);
- register_cmd("SEND", 3, cmd_send, NEED_SESSID, g_ape);
-
- register_cmd("QUIT", 1, cmd_quit, NEED_SESSID, g_ape);
- register_cmd("SETLEVEL", 4, cmd_setlevel, NEED_SESSID, g_ape); // Module
- register_cmd("SETTOPIC", 3, cmd_settopic, NEED_SESSID, g_ape); // Module
- register_cmd("JOIN", 2, cmd_join, NEED_SESSID, g_ape);
- register_cmd("LEFT", 2, cmd_left, NEED_SESSID, g_ape);
- register_cmd("KICK", 3, cmd_kick, NEED_SESSID, g_ape); // Module
- register_cmd("BAN", 5, cmd_ban, NEED_SESSID, g_ape); // Module
- register_cmd("SESSION", -3, cmd_session, NEED_SESSID, g_ape);
-
- register_cmd("KONG", 2, cmd_pong, NEED_SESSID, g_ape);
-
- register_cmd("PROXY_CONNECT", 3, cmd_proxy_connect, NEED_SESSID, g_ape);
- register_cmd("PROXY_WRITE", 3, cmd_proxy_write, NEED_SESSID, g_ape);
+ register_cmd("CONNECT", cmd_connect, NEED_NOTHING, g_ape);
+ register_cmd("PCONNECT", cmd_pconnect, NEED_NOTHING, g_ape);
+ register_cmd("SCRIPT", cmd_script, NEED_NOTHING, g_ape);
+
+ register_cmd("CHECK", cmd_check, NEED_SESSID, g_ape);
+ register_cmd("SEND", cmd_send, NEED_SESSID, g_ape);
+
+ register_cmd("QUIT", cmd_quit, NEED_SESSID, g_ape);
+ //register_cmd("SETLEVEL", cmd_setlevel, NEED_SESSID, g_ape); // Module
+ //register_cmd("SETTOPIC", cmd_settopic, NEED_SESSID, g_ape); // Module
+ register_cmd("JOIN", cmd_join, NEED_SESSID, g_ape);
+ register_cmd("LEFT", cmd_left, NEED_SESSID, g_ape);
+ //register_cmd("KICK", cmd_kick, NEED_SESSID, g_ape); // Module
+ //register_cmd("BAN", cmd_ban, NEED_SESSID, g_ape); // Module
+ //register_cmd("SESSION", cmd_session, NEED_SESSID, g_ape);
+
+ //register_cmd("KONG", cmd_pong, NEED_SESSID, g_ape);
+
+ //register_cmd("PROXY_CONNECT", cmd_proxy_connect, NEED_SESSID, g_ape);
+ //register_cmd("PROXY_WRITE", cmd_proxy_write, NEED_SESSID, g_ape);
}
-void register_cmd(const char *cmd, int nParam, unsigned int (*func)(callbackp *), unsigned int need, acetables *g_ape)
+void register_cmd(const char *cmd, unsigned int (*func)(callbackp *), unsigned int need, acetables *g_ape)
{
callback *new_cmd, *old_cmd;
new_cmd = (callback *) xmalloc(sizeof(*new_cmd));
-
- new_cmd->nParam = nParam;
+
new_cmd->func = func;
new_cmd->need = need;
@@ -78,11 +77,9 @@ void unregister_cmd(const char *cmd, acetables *g_ape)
unsigned int checkcmd(clientget *cget, subuser **iuser, acetables *g_ape)
{
- char *param[64+1], *cmd;
+
callback *cmdback;
- json_item *ijson;
-
- size_t nTok;
+ json_item *ijson, *rjson;
unsigned int flag;
@@ -90,111 +87,115 @@ unsigned int checkcmd(clientget *cget, subuser **iuser, acetables *g_ape)
subuser *sub = NULL;
ijson = init_json_parser(cget->get);
-
- nTok = explode('&', cget->get, param, 64);
+
+ /*nTok = explode('&', cget->get, param, 64);
if (nTok < 1) {
cmd = NULL;
} else {
cmd = param[0];
- }
-
- /* TODO: Making a simple chainlist can be more efficient since we do not have many cmds */
- cmdback = (callback *)hashtbl_seek(g_ape->hCallback, cmd);
- if (cmdback != NULL) {
- if ((nTok-1) == cmdback->nParam || (cmdback->nParam < 0 && (nTok-1) >= (cmdback->nParam*-1) && (cmdback->nParam*-1) <= 16)) {
- int tmpfd = 0;
- callbackp cp;
- switch(cmdback->need) {
- case NEED_SESSID:
- guser = seek_user_id(param[1], g_ape);
- break;
- case NEED_NOTHING:
- guser = NULL;
- break;
- }
-
- if (cmdback->need != NEED_NOTHING) {
- if (guser == NULL) {
- SENDH(cget->fdclient, ERR_BAD_SESSID, g_ape);
-
- return (CONNECT_SHUTDOWN);
- } else {
- sub = getsubuser(guser, cget->host);
- if (sub != NULL && sub->fd != cget->fdclient && sub->state == ALIVE) {
- if (guser->transport == TRANSPORT_IFRAME) {
- /* iframe is already open on "sub" */
- tmpfd = sub->fd; /* Forward data directly to iframe */
- CLOSE(cget->fdclient, g_ape);
- shutdown(cget->fdclient, 2); /* Immediatly close controller */
- } else {
- /* Only one connection is allowed per user/host */
- CLOSE(sub->fd, g_ape);
- shutdown(sub->fd, 2);
- sub->state = ADIED;
- sub->fd = cget->fdclient;
- }
- } else if (sub == NULL) {
- sub = addsubuser(cget->fdclient, cget->host, guser, g_ape);
- if (sub != NULL) {
- subuser_restor(sub, g_ape);
- }
- } else if (sub != NULL) {
- sub->fd = cget->fdclient;
- }
- guser->idle = (long int)time(NULL); // update user idle
+ }*/
- sub->idle = guser->idle; // Update subuser idle
- }
- }
- cp.param = param;
- cp.fdclient = (tmpfd ? tmpfd : cget->fdclient);
- cp.call_user = guser,
- cp.g_ape = g_ape;
- cp.nParam = nTok-1;
- cp.host = cget->host;
-
- flag = cmdback->func(&cp);
-
- if (flag & FOR_NULL) {
- guser = NULL;
- } else if (flag & FOR_LOGIN) {
- guser = cp.call_user;
- }
-
- if (guser != NULL) {
+ if (ijson == NULL || ijson->child == NULL) {
+ SENDH(cget->fdclient, ERR_BAD_JSON, g_ape);
+ } else if ((rjson = json_lookup(ijson->child, "cmd")) != NULL &&
+ rjson->jval.vu.str.value != NULL &&
+ (cmdback = (callback *)hashtbl_seek(g_ape->hCallback, rjson->jval.vu.str.value)) != NULL) {
- if (sub == NULL && (sub = getsubuser(guser, cget->host)) == NULL) {
-
- if ((sub = addsubuser(cget->fdclient, cget->host, guser, g_ape)) == NULL) {
- return (CONNECT_SHUTDOWN);
+ int tmpfd = 0;
+ callbackp cp;
+ switch(cmdback->need) {
+ case NEED_SESSID:
+ {
+ json_item *jsid;
+
+ if ((jsid = json_lookup(ijson->child, "sessid")) != NULL && jsid->jval.vu.str.value != NULL) {
+ guser = seek_user_id(jsid->jval.vu.str.value, g_ape);
}
- subuser_restor(sub, g_ape);
-
- if (guser->transport == TRANSPORT_IFRAME) {
- sendbin(sub->fd, HEADER, strlen(HEADER), g_ape);
- }
}
-
- *iuser = (tmpfd ? NULL : sub);
+ break;
+ case NEED_NOTHING:
+ guser = NULL;
+ break;
+ }
+
+ if (cmdback->need != NEED_NOTHING) {
+ if (guser == NULL) {
+ SENDH(cget->fdclient, ERR_BAD_SESSID, g_ape);
- if (flag & FOR_UPDATE_IP) {
- strncpy(guser->ip, cget->ip_get, 16);
+ return (CONNECT_SHUTDOWN);
+ } else {
+ sub = getsubuser(guser, cget->host);
+ if (sub != NULL && sub->fd != cget->fdclient && sub->state == ALIVE) {
+ if (guser->transport == TRANSPORT_IFRAME) {
+ /* iframe is already open on "sub" */
+ tmpfd = sub->fd; /* Forward data directly to iframe */
+ CLOSE(cget->fdclient, g_ape);
+ shutdown(cget->fdclient, 2); /* Immediatly close controller */
+ } else {
+ /* Only one connection is allowed per user/host */
+ CLOSE(sub->fd, g_ape);
+ shutdown(sub->fd, 2);
+ sub->state = ADIED;
+ sub->fd = cget->fdclient;
+ }
+ } else if (sub == NULL) {
+ sub = addsubuser(cget->fdclient, cget->host, guser, g_ape);
+ if (sub != NULL) {
+ subuser_restor(sub, g_ape);
+ }
+ } else if (sub != NULL) {
+ sub->fd = cget->fdclient;
}
+ guser->idle = (long int)time(NULL); // update user idle
+
+ sub->idle = guser->idle; // Update subuser idle
+ }
+ }
+ cp.param = json_lookup(ijson->child, "params");
+ cp.fdclient = (tmpfd ? tmpfd : cget->fdclient);
+ cp.call_user = guser,
+ cp.g_ape = g_ape;
+ cp.host = cget->host;
+
+ flag = cmdback->func(&cp);
+
+ if (flag & FOR_NULL) {
+ guser = NULL;
+ } else if (flag & FOR_LOGIN) {
+ guser = cp.call_user;
+ }
+
+ if (guser != NULL) {
+
+ if (sub == NULL && (sub = getsubuser(guser, cget->host)) == NULL) {
- /* If tmpfd is set, we do not have reasons to change this state */
- if (!tmpfd) {
- sub->state = ALIVE;
+ if ((sub = addsubuser(cget->fdclient, cget->host, guser, g_ape)) == NULL) {
+ return (CONNECT_SHUTDOWN);
}
- return (CONNECT_KEEPALIVE);
+ subuser_restor(sub, g_ape);
+ if (guser->transport == TRANSPORT_IFRAME) {
+ sendbin(sub->fd, HEADER, strlen(HEADER), g_ape);
+ }
}
- return (CONNECT_SHUTDOWN);
- } else {
- SENDH(cget->fdclient, ERR_BAD_PARAM, g_ape);
+ *iuser = (tmpfd ? NULL : sub);
+
+ if (flag & FOR_UPDATE_IP) {
+ strncpy(guser->ip, cget->ip_get, 16);
+ }
+
+ /* If tmpfd is set, we do not have reasons to change this state */
+ if (!tmpfd) {
+ sub->state = ALIVE;
+ }
+ return (CONNECT_KEEPALIVE);
+
}
+ return (CONNECT_SHUTDOWN);
+
} else { // unregistered CMD
SENDH(cget->fdclient, ERR_BAD_CMD, g_ape);
}
@@ -217,7 +218,7 @@ unsigned int cmd_connect(callbackp *callbacki)
return (FOR_NOTHING);
}
- if (strcmp(callbacki->param[1], "2") == 0) {
+ if (JINT(transport) == 2) {
nuser->transport = TRANSPORT_IFRAME;
nuser->flags |= FLG_PCONNECT;
} else {
@@ -234,7 +235,6 @@ unsigned int cmd_connect(callbackp *callbacki)
post_raw(newraw, nuser, callbacki->g_ape);
-
return (FOR_LOGIN | FOR_UPDATE_IP);
}
@@ -257,7 +257,7 @@ unsigned int cmd_pconnect(callbackp *callbacki)
unsigned int cmd_script(callbackp *callbacki)
{
- char *domain = CONFIG_VAL(Server, domain, callbacki->g_ape->srv);
+ /*char *domain = CONFIG_VAL(Server, domain, callbacki->g_ape->srv);
if (domain == NULL) {
send_error(callbacki->call_user, "NO_DOMAIN", "201", callbacki->g_ape);
} else {
@@ -267,7 +267,7 @@ unsigned int cmd_script(callbackp *callbacki)
sendf(callbacki->fdclient, callbacki->g_ape, "\t<script type=\"text/javascript\" src=\"%s\"></script>\n", callbacki->param[i]);
}
sendbin(callbacki->fdclient, "</head>\n<body>\n</body>\n</html>", 30, callbacki->g_ape);
- }
+ }*/
return (FOR_NOTHING);
}
@@ -277,38 +277,42 @@ unsigned int cmd_join(callbackp *callbacki)
RAW *newraw;
json *jlist;
BANNED *blist;
+ char *chan_name = JSTR(channel);
+
+ if (chan_name != NULL) {
- if ((jchan = getchan(callbacki->param[2], callbacki->g_ape)) == NULL) {
- jchan = mkchan(callbacki->param[2], "Default%20Topic", callbacki->g_ape);
+ if ((jchan = getchan(chan_name, callbacki->g_ape)) == NULL) {
+ jchan = mkchan(chan_name, "Default%20Topic", callbacki->g_ape);
- if (jchan == NULL) {
+ if (jchan == NULL) {
- send_error(callbacki->call_user, "CANT_JOIN_CHANNEL", "202", callbacki->g_ape);
+ send_error(callbacki->call_user, "CANT_JOIN_CHANNEL", "202", callbacki->g_ape);
- } else {
+ } else {
- join(callbacki->call_user, jchan, callbacki->g_ape);
- }
+ join(callbacki->call_user, jchan, callbacki->g_ape);
+ }
- } else if (isonchannel(callbacki->call_user, jchan)) {
+ } else if (isonchannel(callbacki->call_user, jchan)) {
- send_error(callbacki->call_user, "ALREADY_ON_CHANNEL", "100", callbacki->g_ape);
+ send_error(callbacki->call_user, "ALREADY_ON_CHANNEL", "100", callbacki->g_ape);
- } else {
- blist = getban(jchan, callbacki->call_user->ip);
- if (blist != NULL) {
- jlist = NULL;
+ } else {
+ blist = getban(jchan, callbacki->call_user->ip);
+ if (blist != NULL) {
+ jlist = NULL;
- set_json("reason", blist->reason, &jlist);
- set_json("error", "YOU_ARE_BANNED", &jlist);
- /*
- TODO: Add Until
- */
- newraw = forge_raw(RAW_ERR, jlist);
+ set_json("reason", blist->reason, &jlist);
+ set_json("error", "YOU_ARE_BANNED", &jlist);
+ /*
+ TODO: Add Until
+ */
+ newraw = forge_raw(RAW_ERR, jlist);
- post_raw(newraw, callbacki->call_user, callbacki->g_ape);
- } else {
- join(callbacki->call_user, jchan, callbacki->g_ape);
+ post_raw(newraw, callbacki->call_user, callbacki->g_ape);
+ } else {
+ join(callbacki->call_user, jchan, callbacki->g_ape);
+ }
}
}
return (FOR_NOTHING);
@@ -322,10 +326,15 @@ unsigned int cmd_check(callbackp *callbacki)
unsigned int cmd_send(callbackp *callbacki)
{
json *jlist = NULL;
+ char *msg, *pipe;
+
+ if ((msg = JSTR(msg)) != NULL && (pipe = JSTR(pipe)) != NULL) {
+
+ set_json("msg", msg, &jlist);
- set_json("msg", callbacki->param[3], &jlist);
-
- post_to_pipe(jlist, RAW_DATA, callbacki->param[2], getsubuser(callbacki->call_user, callbacki->host), NULL, callbacki->g_ape);
+ post_to_pipe(jlist, RAW_DATA, pipe, getsubuser(callbacki->call_user, callbacki->host), NULL, callbacki->g_ape);
+
+ }
return (FOR_NOTHING);
}
@@ -337,6 +346,7 @@ unsigned int cmd_quit(callbackp *callbacki)
return (FOR_NULL);
}
+#if 0
unsigned int cmd_setlevel(callbackp *callbacki)
{
USERS *recver;
@@ -348,27 +358,30 @@ unsigned int cmd_setlevel(callbackp *callbacki)
}
return (FOR_NOTHING);
}
-
+#endif
unsigned int cmd_left(callbackp *callbacki)
{
CHANNEL *chan;
-
-
- if ((chan = getchan(callbacki->param[2], callbacki->g_ape)) == NULL) {
- send_error(callbacki->call_user, "UNKNOWN_CHANNEL", "103", callbacki->g_ape);
+ char *chan_name;
+
+ if ((chan_name = JSTR(channel)) != NULL) {
+
+ if ((chan = getchan(chan_name, callbacki->g_ape)) == NULL) {
+ send_error(callbacki->call_user, "UNKNOWN_CHANNEL", "103", callbacki->g_ape);
- } else if (!isonchannel(callbacki->call_user, chan)) {
- send_error(callbacki->call_user, "NOT_IN_CHANNEL", "104", callbacki->g_ape);
+ } else if (!isonchannel(callbacki->call_user, chan)) {
+ send_error(callbacki->call_user, "NOT_IN_CHANNEL", "104", callbacki->g_ape);
- } else {
+ } else {
- left(callbacki->call_user, chan, callbacki->g_ape);
+ left(callbacki->call_user, chan, callbacki->g_ape);
+ }
}
-
return (FOR_NOTHING);
}
+#if 0
unsigned int cmd_settopic(callbackp *callbacki)
{
settopic(callbacki->call_user, getchan(callbacki->param[2], callbacki->g_ape), callbacki->param[3], callbacki->g_ape);
@@ -394,7 +407,7 @@ unsigned int cmd_kick(callbackp *callbacki)
send_error(callbacki->call_user, "CANT_KICK", "105", callbacki->g_ape);
} else {
- victim = seek_user(callbacki->param[3], chan->name, callbacki->g_ape);
+ victim = seek_user(callbacki->param[3], chan->pipe->pubid, callbacki->g_ape);
if (victim == NULL) {
@@ -493,6 +506,8 @@ unsigned int cmd_ban(callbackp *callbacki)
return (FOR_NOTHING);
}
+
+
unsigned int cmd_session(callbackp *callbacki)
{
if (strcmp(callbacki->param[2], "set") == 0 && (callbacki->nParam == 4 || callbacki->nParam == 5)) {
@@ -591,4 +606,4 @@ unsigned int cmd_proxy_write(callbackp *callbacki)
return (FOR_NOTHING);
}
-
+#endif
View
13 src/cmd.h 100644 → 100755
@@ -35,6 +35,7 @@
#define ERR_BAD_PARAM "[\n{\"raw\":\"ERR\",\"time\":null,\"datas\":{\"code\":\"001\",\"value\":\"BAD_PARAM\"}}\n]\n"
#define ERR_BAD_CMD "[\n{\"raw\":\"ERR\",\"time\":null,\"datas\":{\"code\":\"002\",\"value\":\"BAD_CMD\"}}\n]\n"
#define ERR_BAD_SESSID "[\n{\"raw\":\"ERR\",\"time\":null,\"datas\":{\"code\":\"004\",\"value\":\"BAD_SESSID\"}}\n]\n"
+#define ERR_BAD_JSON "[\n{\"raw\":\"ERR\",\"time\":null,\"datas\":{\"code\":\"005\",\"value\":\"BAD_JSON\"}}\n]\n"
#define ERR_CONNECT "[\n{\"raw\":\"ERR\",\"time\":null,\"datas\":{\"code\":\"200\",\"value\":\"UNKNOWN_CONNECTION_ERROR\"}}\n]\n"
@@ -61,8 +62,9 @@ typedef struct _callbackp callbackp;
struct _callbackp
{
- int nParam;
- char **param;
+
+ json_item *param;
+
unsigned int fdclient;
struct USERS *call_user;
char *host;
@@ -73,9 +75,8 @@ struct _callbackp
typedef struct callback
{
- int nParam;
- unsigned int need;
- unsigned int (*func)(struct _callbackp *);
+ unsigned int need; /* Need SESSID ? */
+ unsigned int (*func)(struct _callbackp *); /* Callback func */
} callback;
@@ -105,7 +106,7 @@ unsigned int cmd_pong(struct _callbackp *);
unsigned int cmd_proxy_connect(struct _callbackp *);
unsigned int cmd_proxy_write(struct _callbackp *);
///////////////////////////////////////////////////////////////////////////////////////////////
-void register_cmd(const char *cmd, int nParam, unsigned int (*func)(callbackp *), unsigned int need, acetables *g_ape);
+void register_cmd(const char *cmd, unsigned int (*func)(callbackp *), unsigned int need, acetables *g_ape);
void unregister_cmd(const char *cmd, acetables *g_ape);
#endif
View
0  src/config.c 100644 → 100755
File mode changed
View
0  src/config.h 100644 → 100755
File mode changed
View
2  src/entry.c 100644 → 100755
@@ -38,7 +38,7 @@
#include <grp.h>
#include <pwd.h>
-#define _VERSION "0.9.0"
+#define _VERSION "1.0-PRE1"
static void signal_handler(int sign)
View
10 src/extend.c 100644 → 100755
@@ -94,6 +94,16 @@ extend *get_property(extend *entry, const char *key)
}
+void *get_property_val(extend *entry, const char *key)
+{
+ extend *find;
+
+ if ((find = get_property(entry, key)) != NULL) {
+ return find->val;
+ }
+ return NULL;
+
+}
void del_property(extend **entry, const char *key)
{
View
0  src/extend.h 100644 → 100755
File mode changed
View
2  src/handle_http.c 100644 → 100755
@@ -158,6 +158,8 @@ subuser *checkrecv(char *pSock, int fdclient, acetables *g_ape, char *ip_client)
shutdown(fdclient, 2);
return NULL;
+ } else {
+ urldecode(cget->get);
}
} else if (strncasecmp(pSock, "POST", 4) == 0) {
if ((cget->get = getpost(pSock)) == NULL) {
View
0  src/handle_http.h 100644 → 100755
File mode changed
View
0  src/hash.c 100644 → 100755
File mode changed
View
0  src/hash.h 100644 → 100755
File mode changed
View
0  src/http.c 100644 → 100755
File mode changed
View
0  src/http.h 100644 → 100755
File mode changed
View
199 src/json.c 100644 → 100755
@@ -1,5 +1,5 @@
/*
- Copyright (C) 2006, 2007, 2008 Anthony Catel <a.catel@weelya.com>
+ Copyright (C) 2006, 2007, 2008, 2009 Anthony Catel <a.catel@weelya.com>
This file is part of APE Server.
APE is free software; you can redistribute it and/or modify
@@ -31,10 +31,22 @@ void set_json(const char *name, const char *value, struct json **jprev)
{
struct json *new_json, *old_json = *jprev;
+
new_json = xmalloc(sizeof(struct json));
- new_json->name = xstrdup(name);
- new_json->value = (value != NULL ? xstrdup(value) : NULL);
+ new_json->name.len = strlen(name);
+ new_json->name.buf = xmalloc(sizeof(char) * (new_json->name.len + 1));
+ memcpy(new_json->name.buf, name, new_json->name.len + 1);
+
+
+ new_json->value.len = (value != NULL ? strlen(value) : 0);
+
+ if (new_json->value.len) {
+ new_json->value.buf = xmalloc(sizeof(char) * (new_json->value.len + 1));
+ memcpy(new_json->value.buf, value, new_json->value.len + 1);
+ } else {
+ new_json->value.buf = NULL;
+ }
new_json->jfather = NULL;
new_json->jchilds = NULL;
@@ -54,9 +66,21 @@ struct json *json_copy(struct json *jbase)
struct json *new_json = xmalloc(sizeof(struct json));
struct json_childs *jchilds = jbase->jchilds;
- new_json->name = xstrdup(jbase->name);
- new_json->value = (jbase->value != NULL ? xstrdup(jbase->value) : NULL);
+ new_json->name.len = jbase->name.len;
+ new_json->name.buf = xmalloc(sizeof(char) * (new_json->name.len + 1));
+
+ memcpy(new_json->name.buf, jbase->name.buf, new_json->name.len + 1);
+
+ new_json->value.len = jbase->value.len;
+ if (jbase->value.len) {
+
+ new_json->value.buf = xmalloc(sizeof(char) * (new_json->value.len + 1));
+ memcpy(new_json->value.buf, jbase->value.buf, new_json->value.len + 1);
+
+ } else {
+ new_json->value.buf = NULL;
+ }
new_json->prev = NULL;
new_json->next = NULL;
new_json->jfather = NULL;
@@ -91,10 +115,10 @@ void json_free(struct json *jbase)
struct json_childs *jchilds = jbase->jchilds;
- free(jbase->name);
+ free(jbase->name.buf);
- if (jbase->value != NULL) {
- free(jbase->value);
+ if (jbase->value.buf != NULL) {
+ free(jbase->value.buf);
}
@@ -163,17 +187,18 @@ struct jsontring *jsontr(struct json *jlist, struct jsontring *string)
if (string == NULL) { // initial size
string = xmalloc(sizeof(struct jsontring));
- string->jsize = strlen(jlist->name)+3 +
- (jlist->jchilds == NULL ? (jlist->value != NULL ? strlen(jlist->value)+2 : 4) : 0) +
+ string->jsize = jlist->name.len+3 +
+ (jlist->jchilds == NULL ? (jlist->value.buf != NULL ? jlist->value.len+2 : 4) : 0) +
(jlist->prev == NULL ? 2 : 1) + (jlist->next == NULL && jlist->jchilds == NULL ? 1 : 0) + 2; /* Estimate init size ~ 2 bytes */
string->jstring = xmalloc(sizeof(char) * string->jsize);
+ string->len = 0;
} else {
string_osize = string->jsize;
- string->jsize += strlen(jlist->name)+3 +
- (jlist->jchilds == NULL ? (jlist->value != NULL ? strlen(jlist->value)+2 : 4) : 0) +
+ string->jsize += jlist->name.len+3 +
+ (jlist->jchilds == NULL ? (jlist->value.buf != NULL ? jlist->value.len+2 : 4) : 0) +
(jlist->prev == NULL ? 2 : 1) + (jlist->next == NULL && jlist->jchilds == NULL ? 1 : 0) + 2; /* Estimate new size ~ 2 bytes */
string->jstring = xrealloc(string->jstring, sizeof(char) * string->jsize);
@@ -184,19 +209,38 @@ struct jsontring *jsontr(struct json *jlist, struct jsontring *string)
pjson = jlist->next;
if (jlist->prev == NULL) {
- sprintf(string->jstring, "%s{", string->jstring);
+ string->jstring[string->len++] = '{';
+ //sprintf(string->jstring, "%s{", string->jstring);
}
- sprintf(string->jstring, "%s\"%s\":", string->jstring, jlist->name);
- free(jlist->name);
+
+ string->jstring[string->len++] = '"';
+
+ memcpy(&string->jstring[string->len], jlist->name.buf, jlist->name.len);
+
+ string->len += jlist->name.len;
+
+ string->jstring[string->len++] = '"';
+ string->jstring[string->len++] = ':';
+
+ //sprintf(string->jstring, "%s\"%s\":", string->jstring, jlist->name);
+
+
+ free(jlist->name.buf);
if (pchild == NULL) {
- if (jlist->value != NULL) {
- sprintf(string->jstring, "%s\"%s\"", string->jstring, jlist->value);
- free(jlist->value);
+ if (jlist->value.buf != NULL) {
+ string->jstring[string->len++] = '"';
+ memcpy(&string->jstring[string->len], jlist->value.buf, jlist->value.len);
+ string->len += jlist->value.len;
+ string->jstring[string->len++] = '"';
+
+ free(jlist->value.buf);
} else {
- sprintf(string->jstring, "%snull", string->jstring);
+ strncpy(&string->jstring[string->len], "null", 4);
+ string->len += 4;
+
}
} else if (pchild->type == JSON_ARRAY) {
- sprintf(string->jstring, "%s[", string->jstring);
+ string->jstring[string->len++] = '[';
}
while (pchild != NULL) {
struct json_childs *pPchild = pchild;
@@ -206,16 +250,17 @@ struct jsontring *jsontr(struct json *jlist, struct jsontring *string)
pchild = pchild->next;
if (pchild == NULL && pPchild->type == JSON_ARRAY) {
- sprintf(string->jstring, "%s]", string->jstring);
+ string->jstring[string->len++] = ']';
+
} else if (pchild != NULL) {
- sprintf(string->jstring, "%s,", string->jstring);
+ string->jstring[string->len++] = ',';
}
free(pPchild);
}
if (jlist->next == NULL) {
- sprintf(string->jstring, "%s}", string->jstring);
+ string->jstring[string->len++] = '}';
} else {
- sprintf(string->jstring, "%s,", string->jstring);
+ string->jstring[string->len++] = ',';
}
if (pjson != NULL) {
@@ -240,7 +285,14 @@ static json_item *init_json_item()
jval->child = NULL;
jval->next = NULL;
- jval->key = NULL;
+ jval->key.val = NULL;
+ jval->key.len = 0;
+
+ jval->jval.vu.str.value = NULL;
+ jval->jval.vu.integer_value = 0;
+ jval->jval.vu.float_value = 0.;
+
+ jval->type = -1;
return jval;
}
@@ -297,7 +349,8 @@ static int json_callback(void *ctx, int type, const JSON_value* value)
cx->current_cx = jval;
cx->key_under = 1;
- cx->current_cx->key = strdup(value->vu.str.value);
+ cx->current_cx->key.val = xstrdup(value->vu.str.value);
+ cx->current_cx->key.len = value->vu.str.length;
break;
@@ -340,10 +393,12 @@ static int json_callback(void *ctx, int type, const JSON_value* value)
cx->current_cx->jval.vu.integer_value = 1;
break;
case JSON_T_STRING:
- cx->current_cx->jval.vu.str.value = strdup(value->vu.str.value);
+ cx->current_cx->jval.vu.str.value = xmalloc(sizeof(char) * (value->vu.str.length+1));
+ cx->current_cx->jval.vu.str.value = xstrdup(value->vu.str.value);
+ cx->current_cx->jval.vu.str.length = value->vu.str.length;
break;
}
-
+ cx->current_cx->type = type;
break;
default:
@@ -368,11 +423,11 @@ json_item *init_json_parser(const char *json_string)
init_JSON_config(&config);
- config.depth = 15;
- config.callback = &json_callback;
- config.callback_ctx = &jcx;
+ config.depth = 15;
+ config.callback = &json_callback;
+ config.callback_ctx = &jcx;
- config.allow_comments = 0;
+ config.allow_comments = 0;
config.handle_floats_manually = 0;
jc = new_JSON_parser(&config);
@@ -389,6 +444,86 @@ json_item *init_json_parser(const char *json_string)
return NULL;
}
+ delete_JSON_parser(jc);
+
return jcx.head;
}
+static void aff(json_item *cx, int depth)
+{
+
+ while (cx != NULL) {
+ if (cx->key.val != NULL) {
+ printf("Key %s\n", cx->key.val);
+ }
+ if (cx->jval.vu.str.value != NULL) {
+ printf("Value : %s\n", cx->jval.vu.str.value);
+ }
+ if (depth && cx->child != NULL) {
+ aff(cx->child, depth - 1);
+ }
+ cx = cx->next;
+ }
+}
+
+/* "val[32]" return 32, "val" return -1 */
+static int key_is_array(char *key, int i)
+{
+ int ret = 0, f = 1;
+
+ if (i < 4 || key[i--] != ']' || *key == '[') {
+ return -1;
+ }
+
+ while (i != 0 && key[i] != '[') {
+ if (f == 10000) {
+ return -1;
+ }
+ if (key[i] < 48 || key[i] > 57) {
+ return -1;
+ }
+
+ ret += (key[i] - 48) * f;
+ f *= 10;
+ i--;
+ }
+
+ return ret;
+}
+
+json_item *json_lookup(json_item *head, char *path)
+{
+ char *split[16];
+ char *base;
+ size_t nTok;
+ int i = 0;
+
+ if (head == NULL || path == NULL) {
+ return NULL;
+ }
+
+ base = xstrdup(path);
+
+ nTok = explode('.', base, split, 15);
+
+ while (head != NULL && i <= nTok) {
+ if (head->key.val != NULL && strcasecmp(split[i], head->key.val) == 0) {
+ /*
+ printf("Array %s : %i\n", split[i], key_is_array(split[i], strlen(split[i])-1));
+ printf("Comparing : %s with %s\n", head->key.val, split[i]);
+ printf("Find !\n");
+ */
+ if (i == nTok) {
+ return (head->child != NULL ? head->child : head);
+ }
+ i++;
+ head = head->child;
+ continue;
+ }
+
+ head = head->next;
+ }
+ free(base);
+ return NULL;
+}
+
View
37 src/json.h 100644 → 100755
@@ -25,14 +25,24 @@
#include "json_parser.h"
+
+typedef char* jpath;
+
enum {
JSON_ARRAY = 0,
JSON_OBJECT
};
typedef struct json {
- char *name;
- char *value;
+ struct {
+ char *buf;
+ size_t len;
+ } name;
+
+ struct {
+ char *buf;
+ size_t len;
+ } value;
struct json_childs *jchilds;
@@ -50,12 +60,16 @@ struct json_childs {
struct jsontring {
char *jstring;
- int jsize;
+ size_t jsize;
+ size_t len;
};
typedef struct _json_item {
- char *key;
-
+
+ struct {
+ char *val;
+ size_t len;
+ } key;
int type;
struct JSON_value_struct jval;
@@ -92,6 +106,19 @@ void json_concat(struct json *json_father, struct json *json_child);
void json_free(struct json *jbase);
struct jsontring *jsontr(struct json *jlist, struct jsontring *string);
json_item *init_json_parser(const char *json_string);
+json_item *json_lookup(json_item *head, char *path);
+
+#define JSTR(key) \
+ (char *)(callbacki->param != NULL ? json_lookup(callbacki->param->child, #key)->jval.vu.str.value : NULL)
+
+#define JINT(key) \
+ (int)(callbacki->param != NULL ? json_lookup(callbacki->param->child, #key)->jval.vu.integer_value : 0)
+
+#define JFLOAT(key) \
+ (callbacki->param != NULL ? json_lookup(callbacki->param->child, #key)->jval.vu.float_value : 0.)
+
+#define JGET_STR(head, key) \
+ json_lookup(head, #key)->jval.vu.str.value
#endif
View
0  src/json_parser.c 100644 → 100755
File mode changed
View
0  src/json_parser.h 100644 → 100755
File mode changed
View
0  src/main.h 100644 → 100755
File mode changed
View
0  src/pipe.c 100644 → 100755
File mode changed
View
0  src/pipe.h 100644 → 100755
File mode changed
View
0  src/plugins.c 100644 → 100755
File mode changed
View
0  src/plugins.h 100644 → 100755
File mode changed
View
0  src/proxy.c 100644 → 100755
File mode changed
View
0  src/proxy.h 100644 → 100755
File mode changed
View
17 src/raw.c 100644 → 100755
@@ -48,8 +48,10 @@ RAW *forge_raw(const char *raw, struct json *jlist)
new_raw = xmalloc(sizeof(*new_raw));
- new_raw->len = strlen(string->jstring);
- new_raw->data = xstrdup(string->jstring);
+ new_raw->len = string->len;
+
+ new_raw->data = xmalloc(sizeof(char) * (new_raw->len + 1));
+ memcpy(new_raw->data, string->jstring, new_raw->len + 1);
new_raw->next = NULL;
new_raw->priority = 0;
@@ -64,9 +66,12 @@ RAW *forge_raw(const char *raw, struct json *jlist)
RAW *copy_raw(RAW *input)
{
RAW *new_raw;
-
+
new_raw = xmalloc(sizeof(*new_raw));
- new_raw->data = xstrdup(input->data);
+
+ new_raw->data = xmalloc(sizeof(char) * (input->len + 1));
+ memcpy(new_raw->data, input->data, input->len + 1);
+
new_raw->len = input->len;
new_raw->next = input->next;
@@ -78,8 +83,6 @@ RAW *copy_raw(RAW *input)
/************* Users related functions ****************/
-
-
/* Post raw to a subuser */
void post_raw_sub(RAW *raw, subuser *sub, acetables *g_ape)
{
@@ -285,7 +288,7 @@ int send_raws(subuser *user, acetables *g_ape)
if (raw->next != NULL) {
finish &= sendbin(user->fd, ",\n", 2, g_ape);
} else {
- finish &= sendbin(user->fd, "\n]\n", 3, g_ape);
+ finish &= sendbin(user->fd, "\n]\n\n", 3, g_ape);
}
older = raw;
raw = raw->next;
View
0  src/raw.h 100644 → 100755
File mode changed
View
4 src/sock.c 100644 → 100755
@@ -124,6 +124,7 @@ static void clear_buffer(connection *co, int *tfd)
(*tfd)--;
}
+#if 0
static void check_idle(struct _socks_list *sl)
{
int i = 0, x = 0;
@@ -139,6 +140,7 @@ static void check_idle(struct _socks_list *sl)
}
}
+#endif
unsigned int sockroutine(int s_listen, acetables *g_ape)
{
@@ -180,7 +182,9 @@ unsigned int sockroutine(int s_listen, acetables *g_ape)
ev.data.fd = s_listen;
epoll_ctl(epoll_fd, EPOLL_CTL_ADD, s_listen, &ev);
+ #if 0
add_periodical(5, 0, check_idle, &sl, g_ape);
+ #endif
while (1) {
View
2  src/sock.h 100644 → 100755
@@ -43,8 +43,6 @@
#define QUIT(x, g_ape) \
sendbin(x, HEADER, HEADER_LEN, g_ape);\
sendbin(x, "QUIT", 4, g_ape)
-
-#define IDLE_SHUTDOWN 15
int newSockListen(unsigned int port, char *listen_ip);
void setnonblocking(int fd);
View
0  src/ticks.c 100644 → 100755
File mode changed
View
0  src/ticks.h 100644 → 100755
File mode changed
View
0  src/users.c 100644 → 100755
File mode changed
View
0  src/users.h 100644 → 100755
File mode changed
View
56 src/utils.c 100644 → 100755
@@ -143,3 +143,59 @@ char *xstrdup(const char *s)
return x;
}
+char hex2int(unsigned char hex)
+{
+ hex = hex - '0';
+ if (hex > 9) {
+ hex = (hex + '0' - 1) | 0x20;
+ hex = hex - 'a' + 11;
+ }
+ if (hex > 15) {
+ hex = 0xFF;
+ }
+
+ return hex;
+}
+
+/* taken from lighttp */
+int urldecode(char *string)
+{
+ unsigned char high, low;
+ const char *src;
+ char *dst;
+
+ if (string == NULL || !string) return -1;
+
+ src = (const char *) string;
+ dst = (char *) string;
+
+ while ((*src) != '\0') {
+ if (*src == '%') {
+ *dst = '%';
+
+ high = hex2int(*(src + 1));
+ if (high != 0xFF) {
+ low = hex2int(*(src + 2));
+ if (low != 0xFF) {
+ high = (high << 4) | low;
+
+ if (high < 32 || high == 127) high = '_';
+
+ *dst = high;
+ src += 2;
+ }
+ }
+ } else {
+ *dst = *src;
+ }
+
+ dst++;
+ src++;
+ }
+
+ *dst = '\0';
+
+ return 1;
+}
+
+
View
2  src/utils.h 100644 → 100755
@@ -34,5 +34,7 @@ char *itos(int input, char *output);
char *trim(char *s);
char *removelast(char *input, unsigned int n);
size_t explode(const char split, char *input, char **tP, unsigned int limit);
+char hex2int(unsigned char hex);
+int urldecode(char *string);
#endif
Please sign in to comment.
Something went wrong with that request. Please try again.