diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/http.cc | 2 | ||||
-rw-r--r-- | src/msgparser.cc | 5 | ||||
-rw-r--r-- | src/task_proto.cc | 28 |
3 files changed, 32 insertions, 3 deletions
diff --git a/src/http.cc b/src/http.cc index c755442..fe37d76 100644 --- a/src/http.cc +++ b/src/http.cc @@ -41,7 +41,7 @@ int callback_http(struct libwebsocket_context * context, switch(reason) { case LWS_CALLBACK_HTTP: fprintf(stderr, "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, diff --git a/src/msgparser.cc b/src/msgparser.cc index f3bafe1..675e305 100644 --- a/src/msgparser.cc +++ b/src/msgparser.cc @@ -203,6 +203,9 @@ MsgVector parse_msg(std::string data) { printf("Wrong number of parameters\n"); continue; } + m.update.id = atoi(t[1].c_str()); + sprintf(m.update.title, "%s", t[2].c_str()); + sprintf(m.update.desc, "%s", t[3].c_str()); break; } default: @@ -247,6 +250,7 @@ msg_t create_msg(cmd::cmd_t type, task_t t) { // m.update.desc = t.desc; snprintf(m.update.title, sizeof(m.update.title), "%s", t.title.c_str()); snprintf(m.update.desc, sizeof(m.update.desc), "%s", t.desc.c_str()); +// printf("msg: %d, %s, %s\n", m.update.id, m.update.title, m.update.desc); break; }; default: @@ -286,6 +290,7 @@ std::string msg_tostring(msg_t m) { } case cmd::update: { //todo + asprintf(&buf, "update %d \"%s\" \"%s\";", m.update.id, m.update.title, m.update.desc); break; }; default: diff --git a/src/task_proto.cc b/src/task_proto.cc index 717ca3e..2312c9e 100644 --- a/src/task_proto.cc +++ b/src/task_proto.cc @@ -260,9 +260,33 @@ int callback_lws_task(struct libwebsocket_context * context, printf("Moving task: %s\n", buf_str.c_str()); break; } - case cmd::update: - printf("Update\n"); + case cmd::update: { + printf("Updating %d\n", m.update.id); + + bool id_found = false; + TaskList::iterator it; + + task_t updated_task; + for(it = tasklist.begin(); it != tasklist.end(); it++) { + task_t &t = *it; + if(t.id == m.update.id) { + id_found = true; + t.title = m.update.title; + t.desc = m.update.desc; + updated_task = t; + break; + } + } + + if(!id_found) { + printf("\t!!!Could not locate task with id %d\n", m.update.id); + } + + buf_str = msg_tostring(create_msg(cmd::update, updated_task)); + printf("Updating task: %s\n", buf_str.c_str()); + break; + } default: printf("Wrong command :(\n"); break; |