1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
|
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <libwzd.h>
char *msg = NULL;
void siteconfig_parse_args(int argc, const char **argv)
{
int optindex;
/* We have to be carefull here not to use the same values
* as libwzd (see libwzd/libwzd.c /wzd_parse_args
*/
for (optindex=1; optindex<argc; optindex++)
{
if (strcmp(argv[optindex],"-m")==0)
{
optindex++;
if (optindex < argc)
{
if (strlen(argv[optindex])>0)
msg = strdup(argv[optindex]);
}
}
}
}
int main(int argc, const char **argv)
{
int ret;
wzd_reply_t * reply;
int i;
siteconfig_parse_args(argc,argv);
/* if no message was given with -m, then read it from stdin */
if (!msg) {
msg = malloc(1025);
if(!fgets(msg,1024,stdin) || strlen(msg)<=1) {
exit(1);
}
msg[strlen(msg)-1] = '\0';
}
if (!msg || strncasecmp(msg,"site vars",strlen("site vars"))) {
fprintf(stderr,"Incorrect command.\n");
fprintf(stderr,"supported commands are:\n");
fprintf(stderr," site vars\n");
fprintf(stderr," site vars_user\n");
fprintf(stderr," site vars_group\n");
exit (1);
}
wzd_parse_args(argc,argv);
ret = wzd_init();
ret = wzd_connect();
if (ret < 0) {
fprintf(stderr,"Could not connect to server\n");
wzd_fini();
exit(-1);
}
if (ret >= 0) {
reply = wzd_send_message(msg,strlen(msg));
if (reply) {
if (reply->data) {
for (i=0; reply->data[i]!=NULL; i++) {
printf("%s\n",reply->data[i]);
}
}
wzd_free_reply(reply);
} else {
fprintf(stderr,"No reply from server\n");
}
}
wzd_fini();
return 0;
}
|