[mw-devel] MW3 r1285 - in trunk/src: . server webclient
arthur at sucs.org
arthur at sucs.org
Fri Nov 9 16:49:19 GMT 2012
Author: arthur
Date: 2012-11-09 16:49:18 +0000 (Fri, 09 Nov 2012)
New Revision: 1285
Modified:
trunk/src/Makefile
trunk/src/server/Makefile
trunk/src/socket.c
trunk/src/webclient/Makefile
Log:
Add json handling library
Modified: trunk/src/Makefile
===================================================================
--- trunk/src/Makefile 2012-11-08 15:19:10 UTC (rev 1284)
+++ trunk/src/Makefile 2012-11-09 16:49:18 UTC (rev 1285)
@@ -13,7 +13,7 @@
# cflags for standard 'cc' compiler
CFLAGS+= -Wall -pedantic -fpie -std=gnu99 -D_GNU_SOURCE
LDFLAGS+= -pie
-LDLIBS+= -lreadline -ltermcap -lcrypt -l$(JSLIB) -lsqlite3 -lcurl -lpthread -lgnutls-openssl
+LDLIBS+= -lreadline -ltermcap -lcrypt -l$(JSLIB) -lsqlite3 -lcurl -lpthread -lgnutls-openssl -ljansson
# info strings, do not edit.
DEFS:= -DBUILD_DATE=\"$(shell date +%Y%m%d)\"
Modified: trunk/src/server/Makefile
===================================================================
--- trunk/src/server/Makefile 2012-11-08 15:19:10 UTC (rev 1284)
+++ trunk/src/server/Makefile 2012-11-09 16:49:18 UTC (rev 1285)
@@ -23,7 +23,7 @@
DEFS+= -DMSGDIR=\"$(MSGDIR)\"
### uncomment for gdb debugging
-LDFLAGS+= -ggdb -g -lcrypt -lpq
+LDFLAGS+= -ggdb -g -lcrypt -lpq -ljansson
CFLAGS+= -ggdb -g -D__NO_STRING_INLINE -fstack-protector-all -std=c99
### Optimisation - uncomment for release & extra testing
Modified: trunk/src/socket.c
===================================================================
--- trunk/src/socket.c 2012-11-08 15:19:10 UTC (rev 1284)
+++ trunk/src/socket.c 2012-11-09 16:49:18 UTC (rev 1285)
@@ -7,6 +7,8 @@
#include <sys/socket.h>
#include <netdb.h>
#include <errno.h>
+#include <jansson.h>
+
#include "socket.h"
/* generate FOURCC code from a string */
@@ -213,3 +215,40 @@
return NULL;
}
+
+
+/**** JSON handling functions ***/
+/* use http://www.digip.org/jansson/doc/2.3/ aka libjansson */
+
+json_t * ipcmsg_json_decode(ipc_message_t *msg)
+{
+ if (msg == NULL || msg->bodylen == 0) return NULL;
+ json_error_t err;
+ json_t * js = json_loads(msg->body, 0, &err);
+
+ if (js == NULL) {
+ fprintf(stderr, "JSON error at byte %d: %s\n", err.position, err.text);
+ return NULL;
+ }
+
+ return js;
+}
+
+int ipcmsg_json_encode(ipc_message_t *msg, json_t *js)
+{
+ if (msg == NULL) return -1;
+ if (msg->bodylen != 0) return -1;
+ if (js == NULL) return -1;
+
+ char * newtext = json_dumps(js, 0);
+ if (newtext == NULL) {
+ fprintf(stderr, "JSON error on encode\n");
+ return -1;
+ }
+ if (msg->body != NULL) {
+ free(msg->body);
+ }
+ msg->body = newtext;
+ msg->bodylen = strlen(newtext);
+ return 0;
+}
Modified: trunk/src/webclient/Makefile
===================================================================
--- trunk/src/webclient/Makefile 2012-11-08 15:19:10 UTC (rev 1284)
+++ trunk/src/webclient/Makefile 2012-11-09 16:49:18 UTC (rev 1285)
@@ -23,7 +23,7 @@
DEFS+= -DMSGDIR=\"$(MSGDIR)\"
### uncomment for gdb debugging
-LDFLAGS+= -ggdb -g -lcrypt -lpq
+LDFLAGS+= -ggdb -g -lcrypt -lpq -ljansson
CFLAGS+= -ggdb -g -D__NO_STRING_INLINE -fstack-protector-all -std=c99
### Optimisation - uncomment for release & extra testing
More information about the mw-devel
mailing list