Skip to content

Commit

Permalink
* Fix bug in escaping of control characters
Browse files Browse the repository at this point in the history
    Johan Bj�rklund, johbjo09 at kth dot se
  * Remove include "config.h" from headers (should only
    be included from .c files)
    Michael Clark <michael@metaparadigm.com>


git-svn-id: http://svn.metaparadigm.com/svn/json-c/trunk@12 327403b1-1117-474d-bef2-5cb71233fd97
  • Loading branch information
michaeljclark committed Mar 13, 2007
1 parent f6a6e48 commit 837240f
Show file tree
Hide file tree
Showing 11 changed files with 39 additions and 60 deletions.
7 changes: 7 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
0.6
* Fix bug in escaping of control characters
Johan Bj�rklund, johbjo09 at kth dot se
* Remove include "config.h" from headers (should only
be included from .c files)
Michael Clark <michael@metaparadigm.com>

0.5
* Make headers C++ compatible by change *this to *obj
* Add ifdef C++ extern "C" to headers
Expand Down
2 changes: 1 addition & 1 deletion README.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
</head>
<body>
<h2>JSON-C - A JSON implementation in C</h2>
<p>Latest release: <a href="json-c-0.5.tar.gz">json-c-0.5.tar.gz</a></p>
<p>Latest release: <a href="json-c-0.6.tar.gz">json-c-0.6.tar.gz</a></p>
<p>JSON-C implements a reference counting object model that allows you to easily
construct JSON objects in C, output them as JSON formatted strings and parse
JSON formatted strings back into the C representation of JSON objects.</p>
Expand Down
13 changes: 1 addition & 12 deletions bits.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* $Id: bits.h,v 1.9 2006/01/26 02:16:28 mclark Exp $
* $Id: bits.h,v 1.10 2006/01/30 23:07:57 mclark Exp $
*
* Copyright (c) 2004, 2005 Metaparadigm Pte. Ltd.
* Michael Clark <michael@metaparadigm.com>
Expand All @@ -12,17 +12,6 @@
#ifndef _bits_h_
#define _bits_h_

#include "config.h"

#if STDC_HEADERS
# include <stddef.h>
#endif /* STDC_HEADERS */

/* CAW: wrapped in ifndef's to make win32 compliant
** this fails to take over GCC specifics, but this
** seems to be unimportant.
*/

#ifndef min
#define min(a,b) ((a) < (b) ? (a) : (b))
#endif
Expand Down
10 changes: 1 addition & 9 deletions debug.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* $Id: debug.h,v 1.4 2006/01/26 02:16:28 mclark Exp $
* $Id: debug.h,v 1.5 2006/01/30 23:07:57 mclark Exp $
*
* Copyright (c) 2004, 2005 Metaparadigm Pte. Ltd.
* Michael Clark <michael@metaparadigm.com>
Expand All @@ -12,14 +12,6 @@
#ifndef _DEBUG_H_
#define _DEBUG_H_

#include "config.h"

#if HAVE_STRERROR
#define errstr strerror(errno)
#else /* !HAVE_STRERROR */
#define errstr
#endif /* HAVE_STRERROR */

extern void mc_set_debug(int debug);
extern int mc_get_debug();

Expand Down
14 changes: 10 additions & 4 deletions json_object.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* $Id: json_object.c,v 1.14 2006/01/26 02:16:28 mclark Exp $
* $Id: json_object.c,v 1.15 2006/01/30 23:07:57 mclark Exp $
*
* Copyright (c) 2004, 2005 Metaparadigm Pte. Ltd.
* Michael Clark <michael@metaparadigm.com>
Expand All @@ -23,6 +23,10 @@
#include "json_object_private.h"
#include "json_tokener.h"

#if !HAVE_STRNDUP
char* strndup(const char* str, size_t n);
#endif /* !HAVE_STRNDUP */

/* #define REFCOUNT_DEBUG 1 */

char *json_number_chars = "0123456789.+-e";
Expand Down Expand Up @@ -78,10 +82,12 @@ static void json_object_fini() {
static int json_escape_str(struct printbuf *pb, char *str)
{
int pos = 0, start_offset = 0;
char c;
unsigned char c;
do {
c = str[pos];
switch(c) {
case '\0':
break;
case '\b':
case '\n':
case '\r':
Expand All @@ -97,14 +103,14 @@ static int json_escape_str(struct printbuf *pb, char *str)
start_offset = ++pos;
break;
default:
if(c && c < ' ') {
if(c < ' ') {
if(pos - start_offset > 0)
printbuf_memappend(pb, str + start_offset, pos - start_offset);
sprintbuf(pb, "\\u00%c%c",
json_hex_chars[c >> 4],
json_hex_chars[c & 0xf]);
start_offset = ++pos;
} else if(c) pos++;
} else pos++;
}
} while(c);
if(pos - start_offset > 0)
Expand Down
4 changes: 1 addition & 3 deletions json_object.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* $Id: json_object.h,v 1.11 2006/01/26 02:16:28 mclark Exp $
* $Id: json_object.h,v 1.12 2006/01/30 23:07:57 mclark Exp $
*
* Copyright (c) 2004, 2005 Metaparadigm Pte. Ltd.
* Michael Clark <michael@metaparadigm.com>
Expand All @@ -12,8 +12,6 @@
#ifndef _json_object_h_
#define _json_object_h_

#include "config.h"

#define JSON_OBJECT_DEF_HASH_ENTIRES 16

#undef FALSE
Expand Down
10 changes: 9 additions & 1 deletion json_tokener.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* $Id: json_tokener.c,v 1.18 2006/01/26 02:16:28 mclark Exp $
* $Id: json_tokener.c,v 1.19 2006/01/30 23:07:57 mclark Exp $
*
* Copyright (c) 2004, 2005 Metaparadigm Pte. Ltd.
* Michael Clark <michael@metaparadigm.com>
Expand All @@ -23,6 +23,14 @@
#include "json_object.h"
#include "json_tokener.h"

#if !HAVE_STRNCASECMP && defined(_MSC_VER)
/* MSC has the version as _strnicmp */
# define strncasecmp _strnicmp
#elif !HAVE_STRNCASECMP
# error You do not have strncasecmp on your system.
#endif /* HAVE_STRNCASECMP */


static struct json_object* json_tokener_do_parse(struct json_tokener *this);

struct json_object* json_tokener_parse(char * s)
Expand Down
14 changes: 1 addition & 13 deletions json_tokener.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* $Id: json_tokener.h,v 1.8 2006/01/26 02:16:28 mclark Exp $
* $Id: json_tokener.h,v 1.9 2006/01/30 23:07:57 mclark Exp $
*
* Copyright (c) 2004, 2005 Metaparadigm Pte. Ltd.
* Michael Clark <michael@metaparadigm.com>
Expand All @@ -12,7 +12,6 @@
#ifndef _json_tokener_h_
#define _json_tokener_h_

#include "config.h"
#include "json_object.h"

enum json_tokener_error {
Expand Down Expand Up @@ -59,17 +58,6 @@ struct json_tokener
struct printbuf *pb;
};

#if !HAVE_STRNCASECMP && defined(_MSC_VER)
/* MSC has the version as _strnicmp */
# define strncasecmp _strnicmp
#elif !HAVE_STRNCASECMP
# error You do not have strncasecmp on your system.
#endif /* HAVE_STRNCASECMP */

#if !HAVE_STRNDUP
char* strndup(const char* str, size_t n);
#endif /* !HAVE_STRNDUP */

extern struct json_object* json_tokener_parse(char *s);

#endif
7 changes: 6 additions & 1 deletion json_util.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* $Id: json_util.c,v 1.3 2006/01/26 02:16:28 mclark Exp $
* $Id: json_util.c,v 1.4 2006/01/30 23:07:57 mclark Exp $
*
* Copyright (c) 2004, 2005 Metaparadigm Pte. Ltd.
* Michael Clark <michael@metaparadigm.com>
Expand Down Expand Up @@ -39,6 +39,11 @@
# include <io.h>
#endif /* defined(WIN32) */

#if !HAVE_OPEN && defined(WIN32)
# define open _open
#endif


#include "bits.h"
#include "debug.h"
#include "printbuf.h"
Expand Down
14 changes: 1 addition & 13 deletions json_util.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* $Id: json_util.h,v 1.3 2006/01/26 02:16:28 mclark Exp $
* $Id: json_util.h,v 1.4 2006/01/30 23:07:57 mclark Exp $
*
* Copyright (c) 2004, 2005 Metaparadigm Pte. Ltd.
* Michael Clark <michael@metaparadigm.com>
Expand All @@ -12,20 +12,8 @@
#ifndef _json_util_h_
#define _json_util_h_

#include "config.h"

#ifdef WIN32
# define WIN32_LEAN_AND_MEAN
# include <windows.h>
# include <io.h>
#endif

#include "json_object.h"

#if !HAVE_OPEN && defined(WIN32)
# define open _open
#endif

#define JSON_FILE_BUF_SIZE 4096

/* utlitiy functions */
Expand Down
4 changes: 1 addition & 3 deletions linkhash.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* $Id: linkhash.h,v 1.5 2006/01/26 02:16:28 mclark Exp $
* $Id: linkhash.h,v 1.6 2006/01/30 23:07:57 mclark Exp $
*
* Copyright (c) 2004, 2005 Metaparadigm Pte. Ltd.
* Michael Clark <michael@metaparadigm.com>
Expand All @@ -12,8 +12,6 @@
#ifndef _linkhash_h_
#define _linkhash_h_

#include "config.h"

/**
* golden prime used in hash functions
*/
Expand Down

0 comments on commit 837240f

Please sign in to comment.