[open-ils-commits] r8953 - trunk/Open-ILS/src/apachemods
svn at svn.open-ils.org
svn at svn.open-ils.org
Mon Mar 10 01:03:59 EDT 2008
Author: miker
Date: 2008-03-10 00:30:59 -0400 (Mon, 10 Mar 2008)
New Revision: 8953
Modified:
trunk/Open-ILS/src/apachemods/json_xml.c
Log:
Patch from Scott McKellar:
1. The functions _rest_xml_output and _escape_xml are now static, and
a couple of their parameters are now const.
2. In json_string_to_xml() we were leaking res_xml in the case of an
early return. I moved the early return out of the way.
3. In _rest_xml_output() we were leaking tag in the case of an early
return. I plugged that leak.
4. In a couple of spots I replaced buffer_data() with buffer_release(),
and eliminated two intermediate variables that are no longer needed.
Modified: trunk/Open-ILS/src/apachemods/json_xml.c
===================================================================
--- trunk/Open-ILS/src/apachemods/json_xml.c 2008-03-10 04:25:35 UTC (rev 8952)
+++ trunk/Open-ILS/src/apachemods/json_xml.c 2008-03-10 04:30:59 UTC (rev 8953)
@@ -1,21 +1,20 @@
#include "json_xml.h"
#include "fieldmapper_lookup.h"
-void _rest_xml_output(growing_buffer*, jsonObject*, char*, int, int);
-char* _escape_xml (char*);
+static void _rest_xml_output(growing_buffer*, const jsonObject*, char*, int, int);
+static char* _escape_xml (const char*);
char* json_string_to_xml(char* content) {
jsonObject * obj;
growing_buffer * res_xml;
- char * output;
int i;
obj = json_parse_string( content );
- res_xml = buffer_init(1024);
if (!obj)
return NULL;
+ res_xml = buffer_init(1024);
buffer_add(res_xml, "<response>");
if(obj->type == JSON_ARRAY ) {
@@ -28,15 +27,11 @@
buffer_add(res_xml, "</response>");
- output = buffer_data(res_xml);
- buffer_free(res_xml);
jsonObjectFree(obj);
-
- return output;
+ return buffer_release(res_xml);
}
-char* _escape_xml (char* text) {
- char* out;
+char* _escape_xml (const char* text) {
growing_buffer* b = buffer_init(256);
int len = strlen(text);
int i;
@@ -50,12 +45,11 @@
else
buffer_add_char(b,text[i]);
}
- out = buffer_data(b);
- buffer_free(b);
- return out;
+ return buffer_release(b);
}
-void _rest_xml_output(growing_buffer* buf, jsonObject* obj, char * obj_class, int arr_index, int notag) {
+static void _rest_xml_output(growing_buffer* buf, const jsonObject* obj,
+ char * obj_class, int arr_index, int notag) {
char * tag;
int i;
@@ -77,6 +71,7 @@
if(obj->classname) {
if(obj->type == JSON_NULL) {
buffer_fadd(buf,"<%s><Object class_hint=\"%s\"/></%s>", tag, obj->classname, tag);
+ free(tag);
return;
} else {
buffer_fadd(buf,"<%s><Object class_hint=\"%s\">", tag, obj->classname);
More information about the open-ils-commits
mailing list