summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBent Bisballe Nyeng <deva@aasimon.org>2013-01-11 15:52:08 +0100
committerBent Bisballe Nyeng <deva@aasimon.org>2013-01-11 15:52:08 +0100
commitadab7fc5a061624ad931fee4f95de09f78ace91d (patch)
treee6830f57e51334b11dd9ad78bced68eaa38fec07 /src
parent6e2943c8f3befb0a560826e2d764dac1193bfdc1 (diff)
Fix unobserve bug. Change more printf's into hugin syntax.
Diffstat (limited to 'src')
-rw-r--r--src/http.cc14
-rw-r--r--src/messagehandler.cc8
-rw-r--r--src/messageparser.cc56
-rw-r--r--src/munia_proto.cc17
4 files changed, 62 insertions, 33 deletions
diff --git a/src/http.cc b/src/http.cc
index fe37d76..8aa83c3 100644
--- a/src/http.cc
+++ b/src/http.cc
@@ -30,6 +30,8 @@
#include <stdio.h>
#include <string.h>
+#include "hugin.hpp"
+
int callback_http(struct libwebsocket_context * context,
struct libwebsocket *wsi,
enum libwebsocket_callback_reasons reason, void *user,
@@ -40,14 +42,14 @@ int callback_http(struct libwebsocket_context * context,
switch(reason) {
case LWS_CALLBACK_HTTP:
- fprintf(stderr, "serving HTTP URI %s\n", (char *)in);
+ DEBUG(httpd,"serving HTTP URI %s\n", (char *)in);
//
// add favicon later
if(in && strcmp((const char *)in, "/favicon.ico") == 0) {
if(libwebsockets_serve_http_file(wsi,
LOCAL_RESOURCE_PATH"/favicon.ico",
"image/x-icon"))
- fprintf(stderr, "Failed to send favicon\n");
+ DEBUG(httpd,"Failed to send favicon\n");
break;
}
@@ -56,7 +58,7 @@ int callback_http(struct libwebsocket_context * context,
if(libwebsockets_serve_http_file(wsi,
LOCAL_RESOURCE_PATH"/proto.js",
"text/javascript"))
- fprintf(stderr, "Failed to send javascript\n");
+ DEBUG(httpd,"Failed to send javascript\n");
break;
}
@@ -65,7 +67,7 @@ int callback_http(struct libwebsocket_context * context,
if(libwebsockets_serve_http_file(wsi,
LOCAL_RESOURCE_PATH"/munia.html",
"text/html"))
- fprintf(stderr, "Failed to send HTTP file\n");
+ DEBUG(httpd,"Failed to send HTTP file\n");
break;
/*
@@ -82,8 +84,8 @@ int callback_http(struct libwebsocket_context * context,
sizeof(client_name),
client_ip,
sizeof(client_ip));
- fprintf(stderr, "Received network connect from %s (%s)\n",
- client_name, client_ip);
+ DEBUG(httpd,"Received network connect from %s (%s)\n",
+ client_name, client_ip);
/* if we returned non-zero from here, we kill the connection */
break;
diff --git a/src/messagehandler.cc b/src/messagehandler.cc
index 0178d76..d3c3420 100644
--- a/src/messagehandler.cc
+++ b/src/messagehandler.cc
@@ -149,6 +149,7 @@ MessageList handle_msg(MessageList msgList, clientid_t wsi) {
case cmd::unobserve:
//connection_handler.unobserve(wsi, m.observe.id);
outmsgs.push_back(m);
+ DEBUG(handler, "unobserve: %d\n", m.unobserve.id);
break;
case cmd::update:
@@ -164,8 +165,13 @@ MessageList handle_msg(MessageList msgList, clientid_t wsi) {
}
}
break;
+
+ case cmd::error:
+ ERR(messagehandler, "An error occurred.\n");
+ break;
+
default:
- WARN(messagehandler, "!!! Unknown command\n");
+ WARN(messagehandler, "!!! Unknown command %d\n", m.cmd);
break;
}
task_manager.tree.toStdOut();
diff --git a/src/messageparser.cc b/src/messageparser.cc
index 9e5e7ab..4f047d9 100644
--- a/src/messageparser.cc
+++ b/src/messageparser.cc
@@ -50,34 +50,32 @@ inline static void parse_into_msg_tokens(std::string& data,
switch(ch) {
case '\"':
- if(prev_ch != '\\')
+ if(prev_ch != '\\') {
inside_quote = !inside_quote;
- else {
+ } else {
token += ch;
}
break;
case ' ':
if(inside_quote) {
- //DEBUG(msgparser, "Appending %c\n", ch);
+ DEBUG(msgparser, "Appending %c\n", ch);
token += ch;
- }
- else {
+ } else {
if(token.empty()) continue; // skip multiple white spaces and pre white space
-// DEBUG(msgparser, "Adding token %s\n", token.c_str());
+ DEBUG(msgparser, "Adding token %s\n", token.c_str());
tokenVector.push_back(token);
token.clear();
- }
+ }
break;
case ';':
if(inside_quote) {
token += ch;
- }
- else {
+ } else {
tokenVector.push_back(token);
msgTokensList.push_back(tokenVector);
tokenVector.clear();
token.clear();
- }
+ }
break;
default:
token += ch;
@@ -86,15 +84,31 @@ inline static void parse_into_msg_tokens(std::string& data,
prev_ch = ch;
}
-// if(!token.empty()) {
+ if(token != "") {
tokenVector.push_back(token);
token.clear();
-// }
+ }
if(!tokenVector.empty()) {
msgTokensList.push_back(tokenVector);
tokenVector.clear();
}
+
+
+ // Debug: print tokens
+ DEBUG(parser, "tokenlists: %d\n", msgTokensList.size());
+ MsgTokensList::iterator j = msgTokensList.begin();
+ while(j != msgTokensList.end()) {
+ DEBUG(parser, " tokens: %d\n", j->size());
+ int idx = 0;
+ TokenVector::iterator i = j->begin();
+ while(i != j->end()) {
+ DEBUG(parser, " token[%d]: '%s'\n", idx++, i->c_str());
+ i++;
+ }
+ j++;
+ }
+
}
static taskid_t getId(std::map<std::string, taskid_t> &sym, std::string token)
@@ -104,7 +118,13 @@ static taskid_t getId(std::map<std::string, taskid_t> &sym, std::string token)
isnumeric &= (token[i] >= '0' && token[i] <= '9');
}
- if(isnumeric) return atoi(token.c_str());
+ DEBUG(getid, "======= %d %s\n", isnumeric, token.c_str());
+
+ if(isnumeric) {
+ taskid_t id = atoi(token.c_str());
+ DEBUG(getid, "======= id: %d\n", id);
+ return id;
+ }
if(sym.find(token) == sym.end()) sym[token] = task_manager.createId();
return sym[token];
@@ -129,7 +149,8 @@ inline static void create_msg_list(MsgTokensList& msgTokensList,
message_t m;
- DEBUG(msgparser, "t[%d] : %s, running in clientmode: %d\n", origin, t[origin].c_str(), clientmode);
+ DEBUG(msgparser, "t[%d] : %s, running in clientmode: %d\n",
+ origin, t[origin].c_str(), clientmode);
// DEBUG(msgparser, "%d\n", t.size());
@@ -141,8 +162,6 @@ inline static void create_msg_list(MsgTokensList& msgTokensList,
else if(t[origin] == "update") m.cmd = cmd::update;
else m.cmd = cmd::error;
-// DEBUG(msgparser, "Number of tokens %d\n", t.size());
-
switch(m.cmd) {
case cmd::observe: {
if(t.size() != origin+1+1) {
@@ -158,6 +177,7 @@ inline static void create_msg_list(MsgTokensList& msgTokensList,
continue;
}
m.unobserve.id = getId(sym, t[origin+1]);//atoi(t[origin+1].c_str());
+ DEBUG(msgparser, "unobserve @ %d\n", m.unobserve.id);
break;
}
case cmd::create: {
@@ -214,7 +234,7 @@ inline static void create_msg_list(MsgTokensList& msgTokensList,
}
MessageList parse_msg(std::string data) {
- DEBUG(msgparser, "Parsing: %s\n", data.c_str());
+ DEBUG(msgparser, "Parsing: '%s'\n", data.c_str());
MsgTokensList msgTokensList;
parse_into_msg_tokens(data, msgTokensList);
@@ -226,7 +246,7 @@ MessageList parse_msg(std::string data) {
}
MessageList parse_msg_client(std::string data) {
- DEBUG(msgparser, "Parsing: \n%s\n", data.c_str());
+ DEBUG(msgparser, "Parsing: '%s'\n", data.c_str());
MsgTokensList msgTokensList;
parse_into_msg_tokens(data, msgTokensList);
diff --git a/src/munia_proto.cc b/src/munia_proto.cc
index 2a42884..8311f90 100644
--- a/src/munia_proto.cc
+++ b/src/munia_proto.cc
@@ -76,9 +76,9 @@ static void dump_handshake_info(struct lws_tokens *lwst)
for (n = 0; n < WSI_TOKEN_COUNT; n++) {
if (lwst[n].token == NULL || lwst[n].token_len == 0) continue;
- fprintf(stderr, " %s = ", token_names[n]);
+ DEBUG(proto," %s = ", token_names[n]);
if(fwrite(lwst[n].token, 1, lwst[n].token_len, stderr)) {}
- fprintf(stderr, "\n");
+ DEBUG(proto,"\n");
}
}
#endif
@@ -166,7 +166,7 @@ int callback_lws_task(struct libwebsocket_context * context,
LWS_SEND_BUFFER_PRE_PADDING,
LWS_WRITE_TEXT);
if(n < 0) {
- fprintf(stderr, "ERROR writing to socket");
+ DEBUG(proto,"ERROR writing to socket");
exit(1);
}
}
@@ -177,7 +177,7 @@ int callback_lws_task(struct libwebsocket_context * context,
case LWS_CALLBACK_BROADCAST:
printf("LWS_CALLBACK_BROADCAST\n");
n = libwebsocket_write(wsi, (unsigned char*)in, len, LWS_WRITE_TEXT);
- if (n < 0) fprintf(stderr, "task write failed\n");
+ if (n < 0) DEBUG(proto, "task write failed\n");
break;
*/
@@ -231,12 +231,12 @@ int callback_lws_task(struct libwebsocket_context * context,
}
} else if(omi->cmd == cmd::unobserve) {
- connection_handler.unobserve(wsi, omi->observe.id);
+ connection_handler.unobserve(wsi, omi->unobserve.id);
TaskIdList ids;
try {
- ids = task_manager.subTasks(omi->observe.id);
+ ids = task_manager.subTasks(omi->unobserve.id);
} catch(...) {
- DEBUG(proto, "No such node %d\n", omi->observe.id);
+ DEBUG(proto, "No such node %d\n", omi->unobserve.id);
omi++;
continue;
}
@@ -245,8 +245,9 @@ int callback_lws_task(struct libwebsocket_context * context,
task_t task = task_manager.task(*id);
message_t removemsg = create_msg_remove(task);
- removemsg.tid = omi->observe.id;
+ removemsg.tid = omi->unobserve.id;
msgqueue[wsi].push_back(removemsg);
+ DEBUG(unobserve, "remove id: %d\n", *id);
id++;
}