couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fdman...@apache.org
Subject svn commit: r1088941 [3/3] - in /couchdb/trunk: ./ src/ src/couchdb/ src/ejson/ src/ejson/yajl/ test/etap/ utils/
Date Tue, 05 Apr 2011 09:42:42 GMT
Added: couchdb/trunk/src/ejson/yajl/yajl_parser.c
URL: http://svn.apache.org/viewvc/couchdb/trunk/src/ejson/yajl/yajl_parser.c?rev=1088941&view=auto
==============================================================================
--- couchdb/trunk/src/ejson/yajl/yajl_parser.c (added)
+++ couchdb/trunk/src/ejson/yajl/yajl_parser.c Tue Apr  5 09:42:41 2011
@@ -0,0 +1,470 @@
+/*
+ * Copyright 2010, Lloyd Hilaiel.
+ * 
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ * 
+ *  1. Redistributions of source code must retain the above copyright
+ *     notice, this list of conditions and the following disclaimer.
+ * 
+ *  2. Redistributions in binary form must reproduce the above copyright
+ *     notice, this list of conditions and the following disclaimer in
+ *     the documentation and/or other materials provided with the
+ *     distribution.
+ * 
+ *  3. Neither the name of Lloyd Hilaiel nor the names of its
+ *     contributors may be used to endorse or promote products derived
+ *     from this software without specific prior written permission.
+ * 
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
+ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */ 
+
+#include "yajl_lex.h"
+#include "yajl_parser.h"
+#include "yajl_encode.h"
+#include "yajl_bytestack.h"
+
+#include <stdlib.h>
+#include <limits.h>
+#include <errno.h>
+#include <stdio.h>
+#include <string.h>
+#include <ctype.h>
+#include <assert.h>
+#include <math.h>
+
+const char *
+yajl_parser_error_to_string(yajl_parser_error error)
+{
+    switch (error) {
+        case yajl_parser_e_ok:
+            return "ok, no error";
+        case yajl_parser_client_cancelled:
+            return "client cancelled parse via callback return value";
+        case yajl_parser_integer_overflow:
+            return "integer overflow";
+        case yajl_parser_numeric_overflow:
+            return "numeric (floating point) overflow";
+        case yajl_parser_invalid_token:
+            return "unallowed token at this point in JSON text";
+        case yajl_parser_internal_invalid_token:
+            return "invalid token, internal error";
+        case yajl_parser_key_must_be_string:
+            return "invalid object key (must be a string)";
+        case yajl_parser_pair_missing_colon:
+            return "object key and value must be separated by a colon (':')";
+        case yajl_parser_bad_token_after_map_value:
+            return "after key and value, inside map, I expect ',' or '}'";
+        case yajl_parser_bad_token_after_array_value:
+            return "after array element, I expect ',' or ']'";
+    }
+    return "unknown error code";
+}
+
+
+unsigned char *
+yajl_render_error_string(yajl_handle hand, const unsigned char * jsonText,
+                         unsigned int jsonTextLen, int verbose)
+{
+    unsigned int offset = hand->bytesConsumed;
+    unsigned char * str;
+    const char * errorType = NULL;
+    const char * errorText = NULL;
+    char text[72];
+    const char * arrow = "                     (right here) ------^\n";    
+
+    if (yajl_bs_current(hand->stateStack) == yajl_state_parse_error) {
+        errorType = "parse";
+        errorText = yajl_parser_error_to_string(hand->parserError);
+    } else if (yajl_bs_current(hand->stateStack) == yajl_state_lexical_error) {
+        errorType = "lexical";
+        errorText = yajl_lex_error_to_string(yajl_lex_get_error(hand->lexer));
+    } else {
+        errorType = "unknown";
+    }
+
+    {
+        unsigned int memneeded = 0;
+        memneeded += strlen(errorType);
+        memneeded += strlen(" error");
+        if (errorText != NULL) {
+            memneeded += strlen(": ");            
+            memneeded += strlen(errorText);            
+        }
+        str = (unsigned char *) YA_MALLOC(&(hand->alloc), memneeded + 2);
+        str[0] = 0;
+        strcat((char *) str, errorType);
+        strcat((char *) str, " error");    
+        if (errorText != NULL) {
+            strcat((char *) str, ": ");            
+            strcat((char *) str, errorText);            
+        }
+        strcat((char *) str, "\n");    
+    }
+
+    /* now we append as many spaces as needed to make sure the error
+     * falls at char 41, if verbose was specified */
+    if (verbose) {
+        unsigned int start, end, i;
+        unsigned int spacesNeeded;
+
+        spacesNeeded = (offset < 30 ? 40 - offset : 10);
+        start = (offset >= 30 ? offset - 30 : 0);
+        end = (offset + 30 > jsonTextLen ? jsonTextLen : offset + 30);
+    
+        for (i=0;i<spacesNeeded;i++) text[i] = ' ';
+
+        for (;start < end;start++, i++) {
+            if (jsonText[start] != '\n' && jsonText[start] != '\r')
+            {
+                text[i] = jsonText[start];
+            }
+            else
+            {
+                text[i] = ' ';
+            }
+        }
+        assert(i <= 71);
+        text[i++] = '\n';
+        text[i] = 0;
+        {
+            char * newStr = (char *)
+                YA_MALLOC(&(hand->alloc), (strlen((char *) str) +
+                                           strlen((char *) text) +
+                                           strlen(arrow) + 1));
+            newStr[0] = 0;
+            strcat((char *) newStr, (char *) str);
+            strcat((char *) newStr, text);
+            strcat((char *) newStr, arrow);    
+            YA_FREE(&(hand->alloc), str);
+            str = (unsigned char *) newStr;
+        }
+    }
+    return str;
+}
+
+/* check for client cancelation */
+#define _CC_CHK(x)                                                \
+    if (!(x)) {                                                   \
+        yajl_bs_set(hand->stateStack, yajl_state_parse_error);    \
+        hand->parserError = yajl_parser_client_cancelled;          \
+        return yajl_status_client_canceled;                       \
+    }
+
+
+yajl_status
+yajl_do_parse(yajl_handle hand, const unsigned char * jsonText,
+              unsigned int jsonTextLen)
+{
+    yajl_tok tok;
+    const unsigned char * buf;
+    unsigned int bufLen;
+    unsigned int * offset = &(hand->bytesConsumed);
+
+    *offset = 0;
+    
+
+  around_again:
+    switch (yajl_bs_current(hand->stateStack)) {
+        case yajl_state_parse_complete:
+            return yajl_status_ok;
+        case yajl_state_lexical_error:
+        case yajl_state_parse_error:            
+            return yajl_status_error;
+        case yajl_state_start:
+        case yajl_state_map_need_val:
+        case yajl_state_array_need_val:
+        case yajl_state_array_start: {
+            /* for arrays and maps, we advance the state for this
+             * depth, then push the state of the next depth.
+             * If an error occurs during the parsing of the nesting
+             * enitity, the state at this level will not matter.
+             * a state that needs pushing will be anything other
+             * than state_start */
+            yajl_state stateToPush = yajl_state_start;
+
+            tok = yajl_lex_lex(hand->lexer, jsonText, jsonTextLen,
+                               offset, &buf, &bufLen);
+
+            switch (tok) {
+                case yajl_tok_eof:
+                    return yajl_status_insufficient_data;
+                case yajl_tok_error:
+                    yajl_bs_set(hand->stateStack, yajl_state_lexical_error);
+                    goto around_again;
+                case yajl_tok_string:
+                    if (hand->callbacks && hand->callbacks->yajl_string)
{
+                        _CC_CHK(hand->callbacks->yajl_string(hand->ctx,
+                                                             buf, bufLen));
+                    }
+                    break;
+                case yajl_tok_string_with_escapes:
+                    if (hand->callbacks && hand->callbacks->yajl_string)
{
+                        yajl_buf_clear(hand->decodeBuf);
+                        yajl_string_decode(hand->decodeBuf, buf, bufLen);
+                        _CC_CHK(hand->callbacks->yajl_string(
+                                    hand->ctx, yajl_buf_data(hand->decodeBuf),
+                                    yajl_buf_len(hand->decodeBuf)));
+                    }
+                    break;
+                case yajl_tok_bool: 
+                    if (hand->callbacks && hand->callbacks->yajl_boolean)
{
+                        _CC_CHK(hand->callbacks->yajl_boolean(hand->ctx,
+                                                              *buf == 't'));
+                    }
+                    break;
+                case yajl_tok_null: 
+                    if (hand->callbacks && hand->callbacks->yajl_null) {
+                        _CC_CHK(hand->callbacks->yajl_null(hand->ctx));
+                    }
+                    break;
+                case yajl_tok_left_bracket:
+                    if (hand->callbacks && hand->callbacks->yajl_start_map)
{
+                        _CC_CHK(hand->callbacks->yajl_start_map(hand->ctx));
+                    }
+                    stateToPush = yajl_state_map_start;
+                    break;
+                case yajl_tok_left_brace:
+                    if (hand->callbacks && hand->callbacks->yajl_start_array)
{
+                        _CC_CHK(hand->callbacks->yajl_start_array(hand->ctx));
+                    }
+                    stateToPush = yajl_state_array_start;
+                    break;
+                case yajl_tok_integer:
+                    /*
+                     * note.  strtol does not respect the length of
+                     * the lexical token.  in a corner case where the
+                     * lexed number is a integer with a trailing zero,
+                     * immediately followed by the end of buffer,
+                     * sscanf could run off into oblivion and cause a
+                     * crash.  for this reason we copy the integer
+                     * (and doubles), into our parse buffer (the same
+                     * one used for unescaping strings), before
+                     * calling strtol.  yajl_buf ensures null padding,
+                     * so we're safe.
+                     */
+                    if (hand->callbacks) {
+                        if (hand->callbacks->yajl_number) {
+                            _CC_CHK(hand->callbacks->yajl_number(
+                                        hand->ctx,(const char *) buf, bufLen));
+                        } else if (hand->callbacks->yajl_integer) {
+                            long int i = 0;
+                            yajl_buf_clear(hand->decodeBuf);
+                            yajl_buf_append(hand->decodeBuf, buf, bufLen);
+                            buf = yajl_buf_data(hand->decodeBuf);
+                            i = strtol((const char *) buf, NULL, 10);
+                            if ((i == LONG_MIN || i == LONG_MAX) &&
+                                errno == ERANGE)
+                            {
+                                yajl_bs_set(hand->stateStack,
+                                            yajl_state_parse_error);
+                                hand->parserError = yajl_parser_integer_overflow;
+                                /* try to restore error offset */
+                                if (*offset >= bufLen) *offset -= bufLen;
+                                else *offset = 0;
+                                goto around_again;
+                            }
+                            _CC_CHK(hand->callbacks->yajl_integer(hand->ctx,
+                                                                  i));
+                        }
+                    }
+                    break;
+                case yajl_tok_double:
+                    if (hand->callbacks) {
+                        if (hand->callbacks->yajl_number) {
+                            _CC_CHK(hand->callbacks->yajl_number(
+                                        hand->ctx, (const char *) buf, bufLen));
+                        } else if (hand->callbacks->yajl_double) {
+                            double d = 0.0;
+                            yajl_buf_clear(hand->decodeBuf);
+                            yajl_buf_append(hand->decodeBuf, buf, bufLen);
+                            buf = yajl_buf_data(hand->decodeBuf);
+                            d = strtod((char *) buf, NULL);
+                            if ((d == HUGE_VAL || d == -HUGE_VAL) &&
+                                errno == ERANGE)
+                            {
+                                yajl_bs_set(hand->stateStack,
+                                            yajl_state_parse_error);
+                                hand->parserError = yajl_parser_numeric_overflow;
+                                /* try to restore error offset */
+                                if (*offset >= bufLen) *offset -= bufLen;
+                                else *offset = 0;
+                                goto around_again;
+                            }
+                            _CC_CHK(hand->callbacks->yajl_double(hand->ctx,
+                                                                 d));
+                        }
+                    }
+                    break;
+                case yajl_tok_right_brace: {
+                    if (yajl_bs_current(hand->stateStack) ==
+                        yajl_state_array_start)
+                    {
+                        if (hand->callbacks &&
+                            hand->callbacks->yajl_end_array)
+                        {
+                            _CC_CHK(hand->callbacks->yajl_end_array(hand->ctx));
+                        }
+                        yajl_bs_pop(hand->stateStack);
+                        goto around_again;                        
+                    }
+                    /* intentional fall-through */
+                }
+                case yajl_tok_colon: 
+                case yajl_tok_comma: 
+                case yajl_tok_right_bracket:                
+                    yajl_bs_set(hand->stateStack, yajl_state_parse_error);
+                    hand->parserError = yajl_parser_invalid_token;
+                    goto around_again;
+                default:
+                    yajl_bs_set(hand->stateStack, yajl_state_parse_error);
+                    hand->parserError = yajl_parser_invalid_token;
+                    goto around_again;
+            }
+            /* got a value.  transition depends on the state we're in. */
+            {
+                yajl_state s = yajl_bs_current(hand->stateStack);
+                if (s == yajl_state_start) {
+                    yajl_bs_set(hand->stateStack, yajl_state_parse_complete);
+                } else if (s == yajl_state_map_need_val) {
+                    yajl_bs_set(hand->stateStack, yajl_state_map_got_val);
+                } else { 
+                    yajl_bs_set(hand->stateStack, yajl_state_array_got_val);
+                }
+            }
+            if (stateToPush != yajl_state_start) {
+                yajl_bs_push(hand->stateStack, stateToPush);
+            }
+
+            goto around_again;
+        }
+        case yajl_state_map_start: 
+        case yajl_state_map_need_key: {
+            /* only difference between these two states is that in
+             * start '}' is valid, whereas in need_key, we've parsed
+             * a comma, and a string key _must_ follow */
+            tok = yajl_lex_lex(hand->lexer, jsonText, jsonTextLen,
+                               offset, &buf, &bufLen);
+            switch (tok) {
+                case yajl_tok_eof:
+                    return yajl_status_insufficient_data;
+                case yajl_tok_error:
+                    yajl_bs_set(hand->stateStack, yajl_state_lexical_error);
+                    goto around_again;
+                case yajl_tok_string_with_escapes:
+                    if (hand->callbacks && hand->callbacks->yajl_map_key)
{
+                        yajl_buf_clear(hand->decodeBuf);
+                        yajl_string_decode(hand->decodeBuf, buf, bufLen);
+                        buf = yajl_buf_data(hand->decodeBuf);
+                        bufLen = yajl_buf_len(hand->decodeBuf);
+                    }
+                    /* intentional fall-through */
+                case yajl_tok_string:
+                    if (hand->callbacks && hand->callbacks->yajl_map_key)
{
+                        _CC_CHK(hand->callbacks->yajl_map_key(hand->ctx, buf,
+                                                              bufLen));
+                    }
+                    yajl_bs_set(hand->stateStack, yajl_state_map_sep);
+                    goto around_again;
+                case yajl_tok_right_bracket:
+                    if (yajl_bs_current(hand->stateStack) ==
+                        yajl_state_map_start)
+                    {
+                        if (hand->callbacks && hand->callbacks->yajl_end_map)
{
+                            _CC_CHK(hand->callbacks->yajl_end_map(hand->ctx));
+                        }
+                        yajl_bs_pop(hand->stateStack);
+                        goto around_again;                        
+                    }
+                default:
+                    yajl_bs_set(hand->stateStack, yajl_state_parse_error);
+                    hand->parserError = yajl_parser_key_must_be_string;
+                    goto around_again;
+            }
+        }
+        case yajl_state_map_sep: {
+            tok = yajl_lex_lex(hand->lexer, jsonText, jsonTextLen,
+                               offset, &buf, &bufLen);
+            switch (tok) {
+                case yajl_tok_colon:
+                    yajl_bs_set(hand->stateStack, yajl_state_map_need_val);
+                    goto around_again;                    
+                case yajl_tok_eof:
+                    return yajl_status_insufficient_data;
+                case yajl_tok_error:
+                    yajl_bs_set(hand->stateStack, yajl_state_lexical_error);
+                    goto around_again;
+                default:
+                    yajl_bs_set(hand->stateStack, yajl_state_parse_error);
+                    hand->parserError = yajl_parser_pair_missing_colon;
+                    goto around_again;
+            }
+        }
+        case yajl_state_map_got_val: {
+            tok = yajl_lex_lex(hand->lexer, jsonText, jsonTextLen,
+                               offset, &buf, &bufLen);
+            switch (tok) {
+                case yajl_tok_right_bracket:
+                    if (hand->callbacks && hand->callbacks->yajl_end_map)
{
+                        _CC_CHK(hand->callbacks->yajl_end_map(hand->ctx));
+                    }
+                    yajl_bs_pop(hand->stateStack);
+                    goto around_again;                        
+                case yajl_tok_comma:
+                    yajl_bs_set(hand->stateStack, yajl_state_map_need_key);
+                    goto around_again;                    
+                case yajl_tok_eof:
+                    return yajl_status_insufficient_data;
+                case yajl_tok_error:
+                    yajl_bs_set(hand->stateStack, yajl_state_lexical_error);
+                    goto around_again;
+                default:
+                    yajl_bs_set(hand->stateStack, yajl_state_parse_error);
+                    hand->parserError = yajl_parser_bad_token_after_map_value; 
+                    /* try to restore error offset */
+                    if (*offset >= bufLen) *offset -= bufLen;
+                    else *offset = 0;
+                    goto around_again;
+            }
+        }
+        case yajl_state_array_got_val: {
+            tok = yajl_lex_lex(hand->lexer, jsonText, jsonTextLen,
+                               offset, &buf, &bufLen);
+            switch (tok) {
+                case yajl_tok_right_brace:
+                    if (hand->callbacks && hand->callbacks->yajl_end_array)
{
+                        _CC_CHK(hand->callbacks->yajl_end_array(hand->ctx));
+                    }
+                    yajl_bs_pop(hand->stateStack);
+                    goto around_again;                        
+                case yajl_tok_comma:
+                    yajl_bs_set(hand->stateStack, yajl_state_array_need_val);
+                    goto around_again;                    
+                case yajl_tok_eof:
+                    return yajl_status_insufficient_data;
+                case yajl_tok_error:
+                    yajl_bs_set(hand->stateStack, yajl_state_lexical_error);
+                    goto around_again;
+                default:
+                    yajl_bs_set(hand->stateStack, yajl_state_parse_error);
+                    hand->parserError = yajl_parser_bad_token_after_array_value;
+                    goto around_again;
+            }
+        }
+    }
+    
+    abort();
+    return yajl_status_error;
+}
+

Added: couchdb/trunk/src/ejson/yajl/yajl_parser.h
URL: http://svn.apache.org/viewvc/couchdb/trunk/src/ejson/yajl/yajl_parser.h?rev=1088941&view=auto
==============================================================================
--- couchdb/trunk/src/ejson/yajl/yajl_parser.h (added)
+++ couchdb/trunk/src/ejson/yajl/yajl_parser.h Tue Apr  5 09:42:41 2011
@@ -0,0 +1,95 @@
+/*
+ * Copyright 2010, Lloyd Hilaiel.
+ * 
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ * 
+ *  1. Redistributions of source code must retain the above copyright
+ *     notice, this list of conditions and the following disclaimer.
+ * 
+ *  2. Redistributions in binary form must reproduce the above copyright
+ *     notice, this list of conditions and the following disclaimer in
+ *     the documentation and/or other materials provided with the
+ *     distribution.
+ * 
+ *  3. Neither the name of Lloyd Hilaiel nor the names of its
+ *     contributors may be used to endorse or promote products derived
+ *     from this software without specific prior written permission.
+ * 
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
+ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */ 
+
+#ifndef __YAJL_PARSER_H__
+#define __YAJL_PARSER_H__
+
+#include "yajl_parse.h"
+#include "yajl_bytestack.h"
+#include "yajl_buf.h"
+#include "yajl_lex.h"
+
+typedef enum {
+    yajl_state_start = 0,
+    yajl_state_parse_complete,
+    yajl_state_parse_error,
+    yajl_state_lexical_error,
+    yajl_state_map_start,
+    yajl_state_map_sep,    
+    yajl_state_map_need_val,
+    yajl_state_map_got_val,
+    yajl_state_map_need_key,
+    yajl_state_array_start,
+    yajl_state_array_got_val,
+    yajl_state_array_need_val
+} yajl_state;
+
+typedef enum {
+    yajl_parser_e_ok = 0,
+    yajl_parser_client_cancelled,
+    yajl_parser_integer_overflow,
+    yajl_parser_numeric_overflow,
+    yajl_parser_invalid_token,
+    yajl_parser_internal_invalid_token,
+    yajl_parser_key_must_be_string,
+    yajl_parser_pair_missing_colon,
+    yajl_parser_bad_token_after_map_value,
+    yajl_parser_bad_token_after_array_value
+} yajl_parser_error;
+
+struct yajl_handle_t {
+    const yajl_callbacks * callbacks;
+    void * ctx;
+    yajl_lexer lexer;
+    yajl_parser_error parserError;
+    /* the number of bytes consumed from the last client buffer,
+     * in the case of an error this will be an error offset, in the
+     * case of an error this can be used as the error offset */
+    unsigned int bytesConsumed;
+    /* temporary storage for decoded strings */
+    yajl_buf decodeBuf;
+    /* a stack of states.  access with yajl_state_XXX routines */
+    yajl_bytestack stateStack;
+    /* memory allocation routines */
+    yajl_alloc_funcs alloc;
+};
+
+yajl_status
+yajl_do_parse(yajl_handle handle, const unsigned char * jsonText,
+              unsigned int jsonTextLen);
+
+unsigned char *
+yajl_render_error_string(yajl_handle hand, const unsigned char * jsonText,
+                         unsigned int jsonTextLen, int verbose);
+
+
+#endif

Modified: couchdb/trunk/test/etap/130-attachments-md5.t
URL: http://svn.apache.org/viewvc/couchdb/trunk/test/etap/130-attachments-md5.t?rev=1088941&r1=1088940&r2=1088941&view=diff
==============================================================================
--- couchdb/trunk/test/etap/130-attachments-md5.t (original)
+++ couchdb/trunk/test/etap/130-attachments-md5.t Tue Apr  5 09:42:41 2011
@@ -229,7 +229,7 @@ do_request(Request) ->
     [Header, Body] = re:split(R, "\r\n\r\n", [{return, binary}]),
     {ok, {http_response, _, Code, _}, _} =
         erlang:decode_packet(http, Header, []),
-    Json = couch_util:json_decode(Body),
+    Json = ejson:decode(Body),
     {Code, Json}.
 
 get_json(Json, Path) ->

Modified: couchdb/trunk/test/etap/140-attachment-comp.t
URL: http://svn.apache.org/viewvc/couchdb/trunk/test/etap/140-attachment-comp.t?rev=1088941&r1=1088940&r2=1088941&view=diff
==============================================================================
--- couchdb/trunk/test/etap/140-attachment-comp.t (original)
+++ couchdb/trunk/test/etap/140-attachment-comp.t Tue Apr  5 09:42:41 2011
@@ -116,7 +116,7 @@ create_2nd_text_att() ->
     {ok, {{_, Code, _}, _Headers, _Body}} = http:request(
         put,
         {db_url() ++ "/testdoc3", [],
-        "application/json", list_to_binary(couch_util:json_encode(DocJson))},
+        "application/json", ejson:encode(DocJson)},
         [],
         [{sync, true}]),
     etap:is(Code, 201, "Created text attachment using the non-standalone api"),
@@ -135,7 +135,7 @@ create_2nd_png_att() ->
     {ok, {{_, Code, _}, _Headers, _Body}} = http:request(
         put,
         {db_url() ++ "/testdoc4", [],
-        "application/json", list_to_binary(couch_util:json_encode(DocJson))},
+        "application/json", ejson:encode(DocJson)},
         [],
         [{sync, true}]),
     etap:is(Code, 201, "Created png attachment using the non-standalone api"),
@@ -305,7 +305,7 @@ test_get_doc_with_1st_text_att() ->
         [],
         [{sync, true}]),
     etap:is(Code, 200, "HTTP response code is 200"),
-    Json = couch_util:json_decode(Body),
+    Json = ejson:decode(Body),
     TextAttJson = couch_util:get_nested_json_value(
         Json,
         [<<"_attachments">>, <<"readme.txt">>]
@@ -339,7 +339,7 @@ test_1st_text_att_stub() ->
         [],
         [{sync, true}]),
     etap:is(Code, 200, "HTTP response code is 200"),
-    Json = couch_util:json_decode(Body),
+    Json = ejson:decode(Body),
     {TextAttJson} = couch_util:get_nested_json_value(
         Json,
         [<<"_attachments">>, <<"readme.txt">>]
@@ -372,7 +372,7 @@ test_get_doc_with_1st_png_att() ->
         [],
         [{sync, true}]),
     etap:is(Code, 200, "HTTP response code is 200"),
-    Json = couch_util:json_decode(Body),
+    Json = ejson:decode(Body),
     PngAttJson = couch_util:get_nested_json_value(
         Json,
         [<<"_attachments">>, <<"icon.png">>]
@@ -400,7 +400,7 @@ test_1st_png_att_stub() ->
         [],
         [{sync, true}]),
     etap:is(Code, 200, "HTTP response code is 200"),
-    Json = couch_util:json_decode(Body),
+    Json = ejson:decode(Body),
     {PngAttJson} = couch_util:get_nested_json_value(
         Json,
         [<<"_attachments">>, <<"icon.png">>]
@@ -498,7 +498,7 @@ test_get_doc_with_2nd_text_att() ->
         [],
         [{sync, true}]),
     etap:is(Code, 200, "HTTP response code is 200"),
-    Json = couch_util:json_decode(Body),
+    Json = ejson:decode(Body),
     TextAttJson = couch_util:get_nested_json_value(
         Json,
         [<<"_attachments">>, <<"readme.txt">>]
@@ -528,7 +528,7 @@ test_2nd_text_att_stub() ->
         [],
         [{sync, true}]),
     etap:is(Code, 200, "HTTP response code is 200"),
-    Json = couch_util:json_decode(Body),
+    Json = ejson:decode(Body),
     {TextAttJson} = couch_util:get_nested_json_value(
         Json,
         [<<"_attachments">>, <<"readme.txt">>]
@@ -561,7 +561,7 @@ test_get_doc_with_2nd_png_att() ->
         [],
         [{sync, true}]),
     etap:is(Code, 200, "HTTP response code is 200"),
-    Json = couch_util:json_decode(Body),
+    Json = ejson:decode(Body),
     PngAttJson = couch_util:get_nested_json_value(
         Json,
         [<<"_attachments">>, <<"icon.png">>]
@@ -589,7 +589,7 @@ test_2nd_png_att_stub() ->
         [],
         [{sync, true}]),
     etap:is(Code, 200, "HTTP response code is 200"),
-    Json = couch_util:json_decode(Body),
+    Json = ejson:decode(Body),
     {PngAttJson} = couch_util:get_nested_json_value(
         Json,
         [<<"_attachments">>, <<"icon.png">>]
@@ -658,7 +658,7 @@ test_get_already_compressed_att_stub(Doc
         [],
         [{sync, true}]),
     etap:is(Code, 200, "HTTP response code is 200"),
-    Json = couch_util:json_decode(Body),
+    Json = ejson:decode(Body),
     {AttJson} = couch_util:get_nested_json_value(
         Json,
         [<<"_attachments">>, iolist_to_binary(AttName)]
@@ -726,7 +726,7 @@ test_compressible_type_with_parameters()
         [],
         [{sync, true}]),
     etap:is(Code3, 200, "HTTP response code is 200"),
-    Json = couch_util:json_decode(Body3),
+    Json = ejson:decode(Body3),
     {TextAttJson} = couch_util:get_nested_json_value(
         Json,
         [<<"_attachments">>, <<"readme.txt">>]

Modified: couchdb/trunk/test/etap/150-invalid-view-seq.t
URL: http://svn.apache.org/viewvc/couchdb/trunk/test/etap/150-invalid-view-seq.t?rev=1088941&r1=1088940&r2=1088941&view=diff
==============================================================================
--- couchdb/trunk/test/etap/150-invalid-view-seq.t (original)
+++ couchdb/trunk/test/etap/150-invalid-view-seq.t Tue Apr  5 09:42:41 2011
@@ -139,7 +139,7 @@ query_view_before_restore_backup() ->
         [],
         [{sync, true}]),
     etap:is(Code, 200, "Got view response before restoring backup."),
-    ViewJson = couch_util:json_decode(Body),
+    ViewJson = ejson:decode(Body),
     Rows = couch_util:get_nested_json_value(ViewJson, [<<"rows">>]),
     HasDoc1 = has_doc("doc1", Rows),
     HasDoc2 = has_doc("doc2", Rows),
@@ -177,7 +177,7 @@ query_view_after_restore_backup() ->
         [],
         [{sync, true}]),
     etap:is(Code, 200, "Got view response after restoring backup."),
-    ViewJson = couch_util:json_decode(Body),
+    ViewJson = ejson:decode(Body),
     Rows = couch_util:get_nested_json_value(ViewJson, [<<"rows">>]),
     HasDoc1 = has_doc("doc1", Rows),
     HasDoc2 = has_doc("doc2", Rows),

Modified: couchdb/trunk/test/etap/160-vhosts.t
URL: http://svn.apache.org/viewvc/couchdb/trunk/test/etap/160-vhosts.t?rev=1088941&r1=1088940&r2=1088941&view=diff
==============================================================================
--- couchdb/trunk/test/etap/160-vhosts.t (original)
+++ couchdb/trunk/test/etap/160-vhosts.t Tue Apr  5 09:42:41 2011
@@ -146,7 +146,7 @@ test_regular_request() ->
         {ok, _, _, Body} ->
             {[{<<"couchdb">>, <<"Welcome">>},
               {<<"version">>,_}
-            ]} = couch_util:json_decode(Body),
+            ]} = ejson:decode(Body),
             etap:is(true, true, "should return server info");
         _Else -> 
             etap:is(false, true, <<"ibrowse fail">>)
@@ -156,7 +156,7 @@ test_vhost_request() ->
     case ibrowse:send_req(server(), [], get, [], [{host_header, "example.com"}]) of
         {ok, _, _, Body} ->
             {[{<<"db_name">>, <<"etap-test-db">>},_,_,_,_,_,_,_,_,_]}
-                = couch_util:json_decode(Body),
+                = ejson:decode(Body),
             etap:is(true, true, "should return database info");
         _Else -> 
            etap:is(false, true, <<"ibrowse fail">>)
@@ -166,7 +166,7 @@ test_vhost_request_with_qs() ->
     Url = server() ++ "doc1?revs_info=true",
     case ibrowse:send_req(Url, [], get, [], [{host_header, "example.com"}]) of
         {ok, _, _, Body} ->
-            {JsonProps} = couch_util:json_decode(Body),
+            {JsonProps} = ejson:decode(Body),
             HasRevsInfo = proplists:is_defined(<<"_revs_info">>, JsonProps),
             etap:is(HasRevsInfo, true, "should return _revs_info");
         _Else -> 
@@ -186,7 +186,7 @@ test_vhost_request_with_global() ->
 test_vhost_requested_path() ->
     case ibrowse:send_req(server(), [], get, [], [{host_header, "example1.com"}]) of
         {ok, _, _, Body} ->
-            {Json} = couch_util:json_decode(Body), 
+            {Json} = ejson:decode(Body),
             etap:is(case proplists:get_value(<<"requested_path">>, Json) of
                 <<"/">> -> true;
                 _ -> false
@@ -198,7 +198,7 @@ test_vhost_requested_path() ->
 test_vhost_requested_path_path() ->
     case ibrowse:send_req(server(), [], get, [], [{host_header, "example1.com"}]) of
         {ok, _, _, Body} ->
-            {Json} = couch_util:json_decode(Body),
+            {Json} = ejson:decode(Body),
             etap:is(case proplists:get_value(<<"path">>, Json) of
                 <<"/etap-test-db/_design/doc1/_show/test">> -> true;
                 _ -> false
@@ -210,7 +210,7 @@ test_vhost_requested_path_path() ->
 test_vhost_request_wildcard()->
     case ibrowse:send_req(server(), [], get, [], [{host_header, "test.example.com"}]) of
         {ok, _, _, Body} ->
-            {Json} = couch_util:json_decode(Body),
+            {Json} = ejson:decode(Body),
             etap:is(case proplists:get_value(<<"path">>, Json) of
                 <<"/etap-test-db/_design/doc1/_show/test">> -> true;
                 _ -> false
@@ -223,7 +223,7 @@ test_vhost_request_replace_var() ->
     case ibrowse:send_req(server(), [], get, [], [{host_header,"etap-test-db.example1.com"}])
of
         {ok, _, _, Body} ->
             {[{<<"db_name">>, <<"etap-test-db">>},_,_,_,_,_,_,_,_,_]}
-                = couch_util:json_decode(Body),
+                = ejson:decode(Body),
             etap:is(true, true, "should return database info");
         _Else -> etap:is(false, true, <<"ibrowse fail">>)
     end.
@@ -231,7 +231,7 @@ test_vhost_request_replace_var() ->
 test_vhost_request_replace_var1() ->
     case ibrowse:send_req(server(), [], get, [], [{host_header, "doc1.etap-test-db.example1.com"}])
of
         {ok, _, _, Body} ->
-            {Json} = couch_util:json_decode(Body),
+            {Json} = ejson:decode(Body),
             etap:is(case proplists:get_value(<<"path">>, Json) of
                 <<"/etap-test-db/_design/doc1/_show/test">> -> true;
                 _ -> false
@@ -243,7 +243,7 @@ test_vhost_request_replace_wildcard() ->
     case ibrowse:send_req(server(), [], get, [], [{host_header,"etap-test-db.example2.com"}])
of
         {ok, _, _, Body} ->
             {[{<<"db_name">>, <<"etap-test-db">>},_,_,_,_,_,_,_,_,_]}
-                = couch_util:json_decode(Body),
+                = ejson:decode(Body),
             etap:is(true, true, "should return database info");
         _Else -> etap:is(false, true, <<"ibrowse fail">>)
     end.
@@ -253,7 +253,7 @@ test_vhost_request_path() ->
     case ibrowse:send_req(Uri, [], get, [], [{host_header, "example.com"}]) of
         {ok, _, _, Body} ->
             {[{<<"db_name">>, <<"etap-test-db">>},_,_,_,_,_,_,_,_,_]}
-                = couch_util:json_decode(Body),
+                = ejson:decode(Body),
             etap:is(true, true, "should return database info");
         _Else -> etap:is(false, true, <<"ibrowse fail">>)
     end.
@@ -262,7 +262,7 @@ test_vhost_request_path1() ->
     Url = server() ++ "test/doc1?revs_info=true",
     case ibrowse:send_req(Url, [], get, [], []) of
         {ok, _, _, Body} ->
-            {JsonProps} = couch_util:json_decode(Body),
+            {JsonProps} = ejson:decode(Body),
             HasRevsInfo = proplists:is_defined(<<"_revs_info">>, JsonProps),
             etap:is(HasRevsInfo, true, "should return _revs_info");
         _Else -> etap:is(false, true, <<"ibrowse fail">>)
@@ -273,7 +273,7 @@ test_vhost_request_path2() ->
     case ibrowse:send_req(Uri, [], get, [], [{host_header,"etap-test-db.example2.com"}])
of
         {ok, _, _, Body} ->
             {[{<<"db_name">>, <<"etap-test-db">>},_,_,_,_,_,_,_,_,_]}
-                = couch_util:json_decode(Body),
+                = ejson:decode(Body),
             etap:is(true, true, "should return database info");
         _Else -> etap:is(false, true, <<"ibrowse fail">>)
     end.
@@ -282,7 +282,7 @@ test_vhost_request_path3() ->
     Uri = server() ++ "test1",
     case ibrowse:send_req(Uri, [], get, [], []) of
         {ok, _, _, Body} ->
-            {Json} = couch_util:json_decode(Body),
+            {Json} = ejson:decode(Body),
             etap:is(case proplists:get_value(<<"path">>, Json) of
                 <<"/etap-test-db/_design/doc1/_show/test">> -> true;
                 _ -> false

Modified: couchdb/trunk/test/etap/171-os-daemons-config.es
URL: http://svn.apache.org/viewvc/couchdb/trunk/test/etap/171-os-daemons-config.es?rev=1088941&r1=1088940&r2=1088941&view=diff
==============================================================================
--- couchdb/trunk/test/etap/171-os-daemons-config.es (original)
+++ couchdb/trunk/test/etap/171-os-daemons-config.es Tue Apr  5 09:42:41 2011
@@ -20,11 +20,11 @@ read() ->
         eof ->
             stop;
         Data ->
-            couch_util:json_decode(Data)
+            ejson:decode(Data)
     end.
 
 write(Mesg) ->
-    Data = iolist_to_binary(couch_util:json_encode(Mesg)),
+    Data = iolist_to_binary(ejson:encode(Mesg)),
     io:format(binary_to_list(Data) ++ "\n", []).
 
 get_cfg(Section) ->
@@ -80,4 +80,6 @@ loop({error, _Reason}) ->
 
 main([]) ->
     test_util:init_code_path(),
+    couch_config:start_link(test_util:config_files()),
+    couch_drv:start_link(),
     do_tests().

Modified: couchdb/trunk/test/etap/173-os-daemon-cfg-register.es
URL: http://svn.apache.org/viewvc/couchdb/trunk/test/etap/173-os-daemon-cfg-register.es?rev=1088941&r1=1088940&r2=1088941&view=diff
==============================================================================
--- couchdb/trunk/test/etap/173-os-daemon-cfg-register.es (original)
+++ couchdb/trunk/test/etap/173-os-daemon-cfg-register.es Tue Apr  5 09:42:41 2011
@@ -13,8 +13,7 @@
 % the License.
 
 write(Mesg) ->
-    Data = iolist_to_binary(couch_util:json_encode(Mesg)),
-    io:format(binary_to_list(Data) ++ "\n", []).
+    io:format(binary_to_list(ejson:encode(Mesg)) ++ "\n", []).
 
 cfg_register(Section) ->
     write([<<"register">>, Section]).

Modified: couchdb/trunk/test/etap/test_util.erl.in
URL: http://svn.apache.org/viewvc/couchdb/trunk/test/etap/test_util.erl.in?rev=1088941&r1=1088940&r2=1088941&view=diff
==============================================================================
--- couchdb/trunk/test/etap/test_util.erl.in (original)
+++ couchdb/trunk/test/etap/test_util.erl.in Tue Apr  5 09:42:41 2011
@@ -22,7 +22,7 @@ builddir() ->
     "@abs_top_builddir@".
 
 init_code_path() ->
-    Paths = ["etap", "couchdb", "erlang-oauth", "ibrowse", "mochiweb"],
+    Paths = ["etap", "couchdb", "ejson", "erlang-oauth", "ibrowse", "mochiweb"],
     lists:foreach(fun(Name) ->
         code:add_patha(filename:join([builddir(), "src", Name]))
     end, Paths).

Modified: couchdb/trunk/utils/Makefile.am
URL: http://svn.apache.org/viewvc/couchdb/trunk/utils/Makefile.am?rev=1088941&r1=1088940&r2=1088941&view=diff
==============================================================================
--- couchdb/trunk/utils/Makefile.am (original)
+++ couchdb/trunk/utils/Makefile.am Tue Apr  5 09:42:41 2011
@@ -25,6 +25,7 @@ run: ../bin/couchdb.tpl
 	    -e "s|%localini%|local_dev.ini|g" \
 	    -e "s|%localerlanglibdir%|foo \
 			-pa $(abs_top_builddir)\/src\/couchdb \
+			-pa $(abs_top_builddir)\/src\/ejson \
 			-pa $(abs_top_builddir)\/src\/erlang-oauth \
 			-pa $(abs_top_builddir)\/src\/ibrowse \
 			-pa $(abs_top_builddir)\/src\/mochiweb|g" \



Mime
View raw message