summaryrefslogtreecommitdiff
path: root/src/muniacli.cc
diff options
context:
space:
mode:
authorBent Bisballe Nyeng <deva@aasimon.org>2019-02-08 20:26:14 +0100
committerBent Bisballe Nyeng <deva@aasimon.org>2019-02-09 15:40:28 +0100
commit1ae51ff94d0f1f27a4e4cc657371578db13c3ca1 (patch)
treef383cb73afa171ac10ab91eafea9f11804042744 /src/muniacli.cc
parentfb958041310617c7aeef36a8dc9041e2a51fae6d (diff)
Make code compile again (fix bitrot dating back from 2013).
Diffstat (limited to 'src/muniacli.cc')
-rw-r--r--src/muniacli.cc799
1 files changed, 419 insertions, 380 deletions
diff --git a/src/muniacli.cc b/src/muniacli.cc
index 9583957..f28c810 100644
--- a/src/muniacli.cc
+++ b/src/muniacli.cc
@@ -42,53 +42,53 @@
static bool run;
static std::string msgs;
-struct per_session_data__lws_task {
- struct libwebsocket *wsi;
+struct per_session_data__lws_task
+{
+ struct lws *wsi;
};
-static int callback_lws_task(struct libwebsocket_context *me,
- struct libwebsocket *wsi,
- enum libwebsocket_callback_reasons reason,
- void *user, void *in, size_t len)
+static int callback_lws_task(struct lws *wsi,
+ enum lws_callback_reasons reason,
+ void *user, void *in, size_t len)
{
unsigned char buf[LWS_SEND_BUFFER_PRE_PADDING + 4096 +
- LWS_SEND_BUFFER_POST_PADDING];
+ LWS_SEND_BUFFER_POST_PADDING];
int l;
- std::string r;
+ std::string r;
- switch (reason) {
+ switch (reason)
+ {
case LWS_CALLBACK_CLOSED:
-// fprintf(stderr, "mirror: LWS_CALLBACK_CLOSED\n");
+ //fprintf(stderr, "mirror: LWS_CALLBACK_CLOSED\n");
break;
case LWS_CALLBACK_CLIENT_ESTABLISHED:
- libwebsocket_callback_on_writable(me, wsi);
+ lws_callback_on_writable(wsi);
break;
case LWS_CALLBACK_CLIENT_RECEIVE:
-// pretty_print((char*)in);
- printf("%s\n", (char*)in);
- libwebsocket_callback_on_writable(me, wsi);
+ //pretty_print((char*)in);
+ printf("%s\n", (char*)in);
+ lws_callback_on_writable(wsi);
-// if(!interactive) run = false;
+ //if(!interactive) run = false;
run = false;
- break;
+ break;
case LWS_CALLBACK_CLIENT_WRITEABLE:
-
-// if(interactive) {
-// fgets(msg, sizeof(msg), stdin);
-// msgs += msg;
-// printf("send...\n");
-// }
-
- l = sprintf((char *)&buf[LWS_SEND_BUFFER_PRE_PADDING], "%s", msgs.c_str());
-
- libwebsocket_write(wsi, &buf[LWS_SEND_BUFFER_PRE_PADDING],
- l, LWS_WRITE_TEXT);
+ //if(interactive)
+ //{
+ // fgets(msg, sizeof(msg), stdin);
+ // msgs += msg;
+ // printf("send...\n");
+ //}
+
+ l = sprintf((char *)&buf[LWS_SEND_BUFFER_PRE_PADDING], "%s", msgs.c_str());
+
+ lws_write(wsi, &buf[LWS_SEND_BUFFER_PRE_PADDING], l, LWS_WRITE_TEXT);
break;
-
+
default:
break;
}
@@ -96,124 +96,138 @@ static int callback_lws_task(struct libwebsocket_context *me,
return 0;
}
-static struct libwebsocket_protocols protocols[] = {
- { "lws-task-protocol", callback_lws_task,
- sizeof(struct per_session_data__lws_task)
- },
- { NULL, NULL, 0 } // End of list
+static struct lws_protocols protocols[] =
+{
+ { "lws-task-protocol", callback_lws_task,
+ sizeof(struct per_session_data__lws_task)
+ },
+ { nullptr, nullptr, 0 } // End of list
};
int client(const char *address, int port)
{
// printf("Connection to %s on port %d\n", address, port);
- struct libwebsocket_context *context;
- struct libwebsocket *wsi_task = NULL;
+ struct lws_context *context;
+ struct lws *wsi_task = nullptr;
int ietf_version = -1; // latest
- lws_set_log_level(0, NULL);
- struct lws_context_creation_info info;
- memset(&info, 0, sizeof info);
- info.port = CONTEXT_PORT_NO_LISTEN;
- info.iface = NULL; // What is this?
- info.protocols = protocols;
- info.extensions = libwebsocket_get_internal_extensions();
+ lws_set_log_level(0, nullptr);
+ struct lws_context_creation_info info{};
+ info.port = CONTEXT_PORT_NO_LISTEN;
+ info.iface = nullptr; // What is this?
+ info.protocols = protocols;
+ //info.extensions = lws_get_internal_extensions();
- context = libwebsocket_create_context(&info);
+ context = lws_create_context(&info);
- if (context == NULL) {
- fprintf(stderr, "Creating libwebsocket context failed\n");
+ if(context == nullptr)
+ {
+ fprintf(stderr, "Creating lws context failed\n");
return 1;
}
-
- /*
- * sit there servicing the websocket context to handle incoming
- * packets, and drawing random circles on the mirror protocol websocket
- */
- int n = 1;
- while(n >= 0) {
- n = libwebsocket_service(context, 10);
-
- if (wsi_task == NULL) {
- wsi_task = libwebsocket_client_connect(context, address, port,
- 0, "/", address, address,
- "lws-task-protocol",
- ietf_version);
-
- if (wsi_task == NULL) {
- fprintf(stderr, "libwebsocket task connect failed\n");
+ // sit there servicing the websocket context to handle incoming
+ // packets, and drawing random circles on the mirror protocol websocket
+ int n = 1;
+ while(n >= 0)
+ {
+ n = lws_service(context, 10);
+
+ if(wsi_task == nullptr)
+ {
+ wsi_task = lws_client_connect(context, address, port,
+ 0, "/", address, address,
+ "lws-task-protocol",
+ ietf_version);
+
+ if(wsi_task == nullptr)
+ {
+ fprintf(stderr, "lws task connect failed\n");
return -1;
}
- else {
- }
+ else
+ {
+ //...
+ }
- } else {
-// fprintf(stderr, "closing mirror session\n");
-// libwebsocket_close_and_free_session(context,
-// wsi_mirror, LWS_CLOSE_STATUS_GOINGAWAY);
+ }
+ else
+ {
+ //fprintf(stderr, "closing mirror session\n");
+ //lws_close_and_free_session(context,
+ // wsi_mirror, LWS_CLOSE_STATUS_GOINGAWAY);
}
- if(!run) break;
+ if(!run)
+ {
+ break;
+ }
}
- libwebsocket_context_destroy(context);
+ lws_context_destroy(context);
return 0;
}
static struct option options[] = {
- { "command", required_argument, NULL, 'c'},
- { "help", no_argument, NULL, 'h' },
- { "host", required_argument, NULL, 'H'},
- { "port", required_argument, NULL, 'p' },
- { "raw", no_argument, NULL, 'r'},
- { NULL, 0, 0, 0 }
+ { "command", required_argument, nullptr, 'c'},
+ { "help", no_argument, nullptr, 'h' },
+ { "host", required_argument, nullptr, 'H'},
+ { "port", required_argument, nullptr, 'p' },
+ { "raw", no_argument, nullptr, 'r'},
+ { nullptr, 0, 0, 0 }
};
-static const char* USAGE=
- "Usage: muniacli [OPTION]... TASK COMMAND\n"
- "Commandline client to munia."
- "Options:\n"
- " -p, --port Port on host\n"
- " -H, --host Host\n"
- " -c, --command Command\n";
+static const char* USAGE =
+ "Usage: muniacli [OPTION]... TASK COMMAND\n"
+ "Commandline client to munia."
+ "Options:\n"
+ " -p, --port Port on host\n"
+ " -H, --host Host\n"
+ " -c, --command Command\n";
int main(int argc, char** argv)
{
- int port = 7681;
- std::string host = "localhost";
- std::string cmd;
+ int port = 7681;
+ std::string host = "localhost";
+ std::string cmd;
// bool raw = true;
- run = true;
-
- int n = 0;
- while(n >= 0) {
- n = getopt_long(argc, argv, "c:H:p:r", options, NULL);
- if(n < 0) continue;
- switch(n) {
- case 'c':
- cmd = optarg;
- break;
- case 'p':
- port = atoi(optarg);
- break;
- case 'H':
- host = optarg;
- break;
- case 'r':
-// raw = true;
- break;
- case 'h':
- fprintf(stderr, "%s\n", USAGE);
- exit(1);
- break;
- }
- }
- msgs = cmd;
-
- client(host.c_str(), port);
- return 0;
+ run = true;
+
+ int n = 0;
+ while(n >= 0)
+ {
+ n = getopt_long(argc, argv, "c:H:p:r", options, nullptr);
+ if(n < 0)
+ {
+ continue;
+ }
+
+ switch(n)
+ {
+ case 'c':
+ cmd = optarg;
+ break;
+ case 'p':
+ port = atoi(optarg);
+ break;
+ case 'H':
+ host = optarg;
+ break;
+ case 'r':
+ //raw = true;
+ break;
+ case 'h':
+ fprintf(stderr, "%s\n", USAGE);
+ exit(1);
+ break;
+ }
+ }
+ msgs = cmd;
+
+ client(host.c_str(), port);
+ return 0;
}
#if 0
@@ -221,12 +235,13 @@ enum demo_protocols {
PROTOCOL_TASK
};
-enum cmd_t {
- DEFAULT,
- CREATE,
- LIST,
- REMOVE,
- UPDATE
+enum cmd_t
+{
+ DEFAULT,
+ CREATE,
+ LIST,
+ REMOVE,
+ UPDATE
};
static bool run;
@@ -240,114 +255,124 @@ static std::map<int, std::string> titlemap;
static std::string indent;
-static void rec_pretty_print(int node) {
- // printf("pretty printing %d\n", node);
- // for(std::map<int, std::list<int>>::iterator it = structuremap.begin();
- // it != structuremap.end(); it++) {
- // std::list<int> childlist = *it;
-
- printf("%s%d - %s\n", indent.c_str(), node, titlemap[node].c_str());
- std::list<int> childlist = structuremap[node];
- childlist.unique();
- if(!childlist.empty()) {
- for(std::list<int>::iterator it = childlist.begin();
- it != childlist.end(); it++) {
- int child = *it;
- indent += " ";
- rec_pretty_print(child);
- }
- }
-
- indent = indent.substr(0, indent.length()-2);
+static void rec_pretty_print(int node)
+{
+ // printf("pretty printing %d\n", node);
+ // for(std::map<int, std::list<int>>::iterator it = structuremap.begin();
+ // it != structuremap.end(); it++) {
+ // std::list<int> childlist = *it;
+
+ printf("%s%d - %s\n", indent.c_str(), node, titlemap[node].c_str());
+ std::list<int> childlist = structuremap[node];
+ childlist.unique();
+ if(!childlist.empty())
+ {
+ for(std::list<int>::iterator it = childlist.begin();
+ it != childlist.end(); it++)
+ {
+ int child = *it;
+ indent += " ";
+ rec_pretty_print(child);
+ }
+ }
+
+ indent = indent.substr(0, indent.length()-2);
}
-
-static void pretty_print(std::string msgs) {
- // printf("%s\n", msgs.c_str());
- MessageList list = parse_msg_client(msgs);
-
- std::string indent;
-
- std::list<int> childlist;
-
- for(MessageList::iterator it = list.begin();
- it != list.end(); it++) {
- message_t msg = *it;
-
- switch(msg.cmd) {
- case cmd::create:
- // printf("Parent %d, id %d\n", msg.create.parentid, msg.create.id);
- childlist = structuremap[msg.create.parentid];
-// if(childlist.find(msg.create.id) == childlist.end()) {
- childlist.push_back(msg.create.id);
-// }
- structuremap[msg.create.parentid] = childlist;
- // printf("Childlist size of %d = %d\n", msg.create.parentid, childlist.size());
- break;
- case cmd::update:
- // char buf[256];
- // sprintf(buf, "%s", msg.update.title);
- titlemap[msg.update.id] = msg.update.title;
- // printf("%s\n", buf);
- break;
- default:
- break;
- }
- }
-
- rec_pretty_print(taskid);
+
+static void pretty_print(std::string msgs)
+{
+ // printf("%s\n", msgs.c_str());
+ MessageList list = parse_msg_client(msgs);
+
+ std::string indent;
+
+ std::list<int> childlist;
+
+ for(MessageList::iterator it = list.begin();
+ it != list.end(); it++)
+ {
+ message_t msg = *it;
+
+ switch(msg.cmd)
+ {
+ case cmd::create:
+ // printf("Parent %d, id %d\n", msg.create.parentid, msg.create.id);
+ childlist = structuremap[msg.create.parentid];
+ //if(childlist.find(msg.create.id) == childlist.end())
+ //{
+ childlist.push_back(msg.create.id);
+ //}
+ structuremap[msg.create.parentid] = childlist;
+ //printf("Childlist size of %d = %d\n", msg.create.parentid, childlist.size());
+ break;
+ case cmd::update:
+ //char buf[256];
+ //sprintf(buf, "%s", msg.update.title);
+ titlemap[msg.update.id] = msg.update.title;
+ //printf("%s\n", buf);
+ break;
+ default:
+ break;
+ }
+ }
+
+ rec_pretty_print(taskid);
}
-static int callback_task(struct libwebsocket_context *me,
- struct libwebsocket *wsi,
- enum libwebsocket_callback_reasons reason,
+static int callback_task(struct lws_context *me,
+ struct lws *wsi,
+ enum lws_callback_reasons reason,
void *user, void *in, size_t len)
{
unsigned char buf[LWS_SEND_BUFFER_PRE_PADDING + 4096 +
LWS_SEND_BUFFER_POST_PADDING];
int l;
- char msg[4096];
- std::string r;
-
- switch (reason) {
+ char msg[4096];
+ std::string r;
+ switch (reason)
+ {
case LWS_CALLBACK_CLOSED:
- fprintf(stderr, "mirror: LWS_CALLBACK_CLOSED\n");
- // wsi_mirror = NULL;
+ fprintf(stderr, "mirror: LWS_CALLBACK_CLOSED\n");
+ // wsi_mirror = nullptr;
break;
case LWS_CALLBACK_CLIENT_ESTABLISHED:
- libwebsocket_callback_on_writable(me, wsi);
+ lws_callback_on_writable(me, wsi);
break;
case LWS_CALLBACK_CLIENT_RECEIVE:
- // fprintf(stderr, "rx %d '", (int)len);
- // fwrite(in, len, 1, stderr);
- // fprintf(stderr, "\n");
- pretty_print((char*)in);
- libwebsocket_callback_on_writable(me, wsi);
-
- if(!interactive) run = false;
+ //fprintf(stderr, "rx %d '", (int)len);
+ //fwrite(in, len, 1, stderr);
+ //fprintf(stderr, "\n");
+ pretty_print((char*)in);
+ lws_callback_on_writable(me, wsi);
+
+ if(!interactive)
+ {
+ run = false;
+ }
break;
case LWS_CALLBACK_CLIENT_WRITEABLE:
-
- if(interactive) {
- fgets(msg, sizeof(msg), stdin);
- msgs += msg;
- printf("send...\n");
- }
-
- if(!msgs.empty()) {
- // printf("Sending %s\n", msgs.c_str());
- l = sprintf((char *)&buf[LWS_SEND_BUFFER_PRE_PADDING], "%s", msgs.c_str());
-
- libwebsocket_write(wsi, &buf[LWS_SEND_BUFFER_PRE_PADDING],
- l, LWS_WRITE_TEXT);
-
- msgs.clear();
- }
+ if(interactive)
+ {
+ fgets(msg, sizeof(msg), stdin);
+ msgs += msg;
+ printf("send...\n");
+ }
+
+ if(!msgs.empty())
+ {
+ // printf("Sending %s\n", msgs.c_str());
+ l = sprintf((char *)&buf[LWS_SEND_BUFFER_PRE_PADDING], "%s", msgs.c_str());
+ lws_write(wsi, &buf[LWS_SEND_BUFFER_PRE_PADDING],
+ l, LWS_WRITE_TEXT);
+
+ msgs.clear();
+ }
break;
-
+
default:
break;
}
@@ -355,207 +380,221 @@ static int callback_task(struct libwebsocket_context *me,
return 0;
}
-static struct libwebsocket_protocols protocols[] = {
+static struct lws_protocols protocols[] =
+{
{ "lws-task-protocol", callback_task, 0, },
- { NULL, NULL, 0 }
+ { nullptr, nullptr, 0 }
};
int client(const char *address, int port)
{
- struct libwebsocket_context *context;
- struct libwebsocket *wsi_task = NULL;
+ struct lws_context *context;
+ struct lws *wsi_task = nullptr;
int ietf_version = -1; // latest
-
- context = libwebsocket_create_context(CONTEXT_PORT_NO_LISTEN, NULL,
- protocols,
- libwebsocket_internal_extensions,
- NULL, NULL, -1, -1, 0);
- if (context == NULL) {
- fprintf(stderr, "Creating libwebsocket context failed\n");
+ context = lws_create_context(CONTEXT_PORT_NO_LISTEN, nullptr,
+ protocols,
+ lws_internal_extensions,
+ nullptr, nullptr, -1, -1, 0);
+ if (context == nullptr)
+ {
+ fprintf(stderr, "Creating lws context failed\n");
return 1;
}
-
- /*
- * sit there servicing the websocket context to handle incoming
- * packets, and drawing random circles on the mirror protocol websocket
- */
- int n = 1;
- while(n >= 0) {
-
- n = libwebsocket_service(context, 10);
-
- if (wsi_task == NULL) {
- wsi_task = libwebsocket_client_connect(context, address, port,
- 0, "/", address, address,
- protocols[lws-task-protocol].name,
- ietf_version);
-
- if (wsi_task == NULL) {
- fprintf(stderr, "libwebsocket task connect failed\n");
+ // sit there servicing the websocket context to handle incoming
+ // packets, and drawing random circles on the mirror protocol websocket
+ int n = 1;
+ while(n >= 0)
+ {
+ n = lws_service(context, 10);
+
+ if (wsi_task == nullptr)
+ {
+ wsi_task = lws_client_connect(context, address, port,
+ 0, "/", address, address,
+ protocols[lws-task-protocol].name,
+ ietf_version);
+
+ if(wsi_task == nullptr)
+ {
+ fprintf(stderr, "lws task connect failed\n");
return -1;
}
- } else {
-
- /*
- fprintf(stderr, "closing mirror session\n");
- libwebsocket_close_and_free_session(context,
- wsi_mirror, LWS_CLOSE_STATUS_GOINGAWAY);
- */
+ }
+ else
+ {
+ //fprintf(stderr, "closing mirror session\n");
+ //lws_close_and_free_session(context,
+ // wsi_mirror, LWS_CLOSE_STATUS_GOINGAWAY);
}
- if(!run) break;
+ if(!run)
+ {
+ break;
+ }
}
- // fprintf(stderr, "Exiting\n");
+ //fprintf(stderr, "Exiting\n");
- libwebsocket_context_destroy(context);
+ lws_context_destroy(context);
return 0;
}
-static struct option options[] = {
- { "create", no_argument, NULL, 'C'},
- { "help", no_argument, NULL, 'h' },
- { "host", required_argument, NULL, 'H'},
- { "interactive", no_argument, NULL, 'i'},
- { "id", required_argument, NULL, 'I'},
- { "list", no_argument, NULL, 'L'},
- { "name", required_argument, NULL, 'n'},
- { "port", required_argument, NULL, 'p' },
- { "remove", no_argument, NULL, 'R'},
- { "update", required_argument, NULL, 'U'},
- { NULL, 0, 0, 0 }
+static struct option options[] =
+{
+ { "create", no_argument, nullptr, 'C'},
+ { "help", no_argument, nullptr, 'h' },
+ { "host", required_argument, nullptr, 'H'},
+ { "interactive", no_argument, nullptr, 'i'},
+ { "id", required_argument, nullptr, 'I'},
+ { "list", no_argument, nullptr, 'L'},
+ { "name", required_argument, nullptr, 'n'},
+ { "port", required_argument, nullptr, 'p' },
+ { "remove", no_argument, nullptr, 'R'},
+ { "update", required_argument, nullptr, 'U'},
+ { nullptr, 0, 0, 0 }
};
-static const char* USAGE=
- "Usage: muniacli [OPTION]... TASK COMMAND\n"
- "Commandline client to munia."
- "Options:\n"
- " -p, --port Port on host\n"
- " -H, --host Host\n"
- " -i, --interactive Run in interactive/shell mode\n"
- "Task:\n"
- " -N, --name Select task by name\n"
- " -I, --id Select task by id\n"
- "Commands:\n"
- " -C, --create Create new subtask in TASK\n"
- " -L, --list List subtasks in TASK\n"
- " -R, --remove Remove subtask from TASK\n"
- " -U, --update Update data in TASK";
+static const char* USAGE =
+ "Usage: muniacli [OPTION]... TASK COMMAND\n"
+ "Commandline client to munia."
+ "Options:\n"
+ " -p, --port Port on host\n"
+ " -H, --host Host\n"
+ " -i, --interactive Run in interactive/shell mode\n"
+ "Task:\n"
+ " -N, --name Select task by name\n"
+ " -I, --id Select task by id\n"
+ "Commands:\n"
+ " -C, --create Create new subtask in TASK\n"
+ " -L, --list List subtasks in TASK\n"
+ " -R, --remove Remove subtask from TASK\n"
+ " -U, --update Update data in TASK";
int main(int argc, char** argv)
{
- int port = 7681;
- std::string host = "localhost";
- std::string taskbyid;
- std::string taskbyname;
- cmd_t cmd = DEFAULT;
- std::string cmd_opts;
-
- interactive = false;
- run = true;
-
- int n = 0;
- while(n >= 0) {
- n = getopt_long(argc, argv, "p:iN:I:CLRU:hH:", options, NULL);
- if(n < 0) continue;
- switch(n) {
- case 'i':
- interactive = true;
- break;
- case 'p':
- port = atoi(optarg);
- break;
- case 'H':
- host = optarg;
- break;
- case 'h':
- fprintf(stderr, "%s\n", USAGE);
- exit(1);
- case 'N':
- taskbyname = optarg;
- break;
- case 'I':
- taskbyid = optarg;
- break;
- case 'C':
- cmd = CREATE;
- break;
- case 'L':
- cmd = LIST;
- break;
- case 'R':
- cmd = REMOVE;
- break;
- case 'U':
- cmd = UPDATE;
- cmd_opts = optarg;
- break;
- }
- }
-
- if(!interactive && cmd == DEFAULT) {
- fprintf(stderr, "%s\n", USAGE);
- exit(1);
- }
-
- if(!interactive && !taskbyname.empty()) {
- taskbyid = -1;
- fprintf(stderr, "Option '-N, --name' is not yet supported\n");
- fprintf(stderr, "%s\n", USAGE);
- exit(1);
- }
-
- if(!interactive && taskbyid.empty()) {
- fprintf(stderr, "%s\n", USAGE);
- exit(1);
- }
-
- taskid = atoi(taskbyid.c_str());
-
- switch(cmd) {
- case CREATE:
- msgs = "observe " + taskbyid + ";";
- msgs += "create " + taskbyid + ";";
- break;
- case LIST:
- msgs = "observe " + taskbyid + ";"; //+
- // "; unobserve " + task + ";";
- break;
- case REMOVE:
- msgs = "remove " + taskbyid + ";";
- break;
- case UPDATE:
- msgs = "observe " + taskbyid + ";";
- msgs += "update " + taskbyid + " \"" + cmd_opts + "\"; ";
- break;
- case DEFAULT:
- break;
- }
+ int port = 7681;
+ std::string host = "localhost";
+ std::string taskbyid;
+ std::string taskbyname;
+ cmd_t cmd = DEFAULT;
+ std::string cmd_opts;
+
+ interactive = false;
+ run = true;
+
+ int n = 0;
+ while(n >= 0)
+ {
+ n = getopt_long(argc, argv, "p:iN:I:CLRU:hH:", options, nullptr);
+ if(n < 0)
+ {
+ continue;
+ }
+ switch(n)
+ {
+ case 'i':
+ interactive = true;
+ break;
+ case 'p':
+ port = atoi(optarg);
+ break;
+ case 'H':
+ host = optarg;
+ break;
+ case 'h':
+ fprintf(stderr, "%s\n", USAGE);
+ exit(1);
+ case 'N':
+ taskbyname = optarg;
+ break;
+ case 'I':
+ taskbyid = optarg;
+ break;
+ case 'C':
+ cmd = CREATE;
+ break;
+ case 'L':
+ cmd = LIST;
+ break;
+ case 'R':
+ cmd = REMOVE;
+ break;
+ case 'U':
+ cmd = UPDATE;
+ cmd_opts = optarg;
+ break;
+ }
+ }
+
+ if(!interactive && cmd == DEFAULT)
+ {
+ fprintf(stderr, "%s\n", USAGE);
+ exit(1);
+ }
+
+ if(!interactive && !taskbyname.empty())
+ {
+ taskbyid = -1;
+ fprintf(stderr, "Option '-N, --name' is not yet supported\n");
+ fprintf(stderr, "%s\n", USAGE);
+ exit(1);
+ }
+
+ if(!interactive && taskbyid.empty())
+ {
+ fprintf(stderr, "%s\n", USAGE);
+ exit(1);
+ }
+
+ taskid = atoi(taskbyid.c_str());
+
+ switch(cmd)
+ {
+ case CREATE:
+ msgs = "observe " + taskbyid + ";";
+ msgs += "create " + taskbyid + ";";
+ break;
+ case LIST:
+ msgs = "observe " + taskbyid + ";"; //+
+ // "; unobserve " + task + ";";
+ break;
+ case REMOVE:
+ msgs = "remove " + taskbyid + ";";
+ break;
+ case UPDATE:
+ msgs = "observe " + taskbyid + ";";
+ msgs += "update " + taskbyid + " \"" + cmd_opts + "\"; ";
+ break;
+ case DEFAULT:
+ break;
+ }
// printf("msgs: %s\n", msgs.c_str());
- /*
- if(!interactive && argc - optionscount < 3) {
- fprintf(stderr, "%s", USAGE);
- exit(1);
- }
- else if (interactive && argc - optionscount < 2){
- fprintf(stderr, "%s", USAGE);
- exit(1);
- }
-
- if(!interactive) {
- // printf("cmd: %s\n", argv[3]);
- msgs = argv[3];
- }
- */
-
- client(host.c_str(), port);
- return 0;
+// if(!interactive && argc - optionscount < 3)
+// {
+// fprintf(stderr, "%s", USAGE);
+// exit(1);
+// }
+// else if (interactive && argc - optionscount < 2)
+// {
+// fprintf(stderr, "%s", USAGE);
+// exit(1);
+// }
+//
+// if(!interactive)
+// {
+// //printf("cmd: %s\n", argv[3]);
+// msgs = argv[3];
+// }
+
+ client(host.c_str(), port);
+ return 0;
}
+
#endif/*0*/