Fossil

Check-in [9be377fe]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:minor cleanups made possible by newer cson APIs.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 9be377fef1ba390d64100c1ad5ebf1bb8b328317
User & Date: stephan 2012-07-03 21:30:17
Context
2012-07-05
19:03
Pulled in latest cson amalgamation for the cson_type_id addition and started refactoring some O(N) lookups to O(1) based on that addition. check-in: cde55bd7 user: stephan tags: trunk
2012-07-03
21:30
minor cleanups made possible by newer cson APIs. check-in: 9be377fe user: stephan tags: trunk
21:28
Minor improvement to the "are we in JSON mode so we can disable the name parameter hack?" pre-check. check-in: 5ea759f9 user: stephan tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/json.c.

987
988
989
990
991
992
993
994
995
996
997
998

999
1000
1001
1002
1003
1004

1005
1006
1007
1008
1009
1010
1011
....
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
....
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
**
** The returned value is owned by the caller. If not NULL then it
** _will_ have a JSON type of Array.
*/
cson_value * json_string_split2( char const * zStr,
                                 char separator,
                                 char doDeHttp ){
  cson_value * v = cson_value_new_array();
  cson_array * a = cson_value_get_array(v);
  int rc = json_string_split( zStr, separator, doDeHttp, a );
  if( 0 == rc ){
    cson_value_free(v);

    v = NULL;
  }else if(rc<0){
    cson_value_free(v);
    v = NULL;
  }
  return v;

}


/*
** Performs some common initialization of JSON-related state.  Must be
** called by the json_page_top() and json_cmd_top() dispatching
** functions to set up the JSON stat used by the dispatched functions.
................................................................................
}

/*
** Impl of /json/resultCodes
**
*/
cson_value * json_page_resultCodes(){
    cson_value * listV = cson_value_new_array();
    cson_array * list = cson_value_get_array(listV);
    cson_value * objV = NULL;
    cson_object * obj = NULL;
    cson_string * kRC;
    cson_string * kSymbol;
    cson_string * kNumber;
    cson_string * kDesc;
    cson_array_reserve( list, 35 );
    kRC = cson_new_string("resultCode",10);
    kSymbol = cson_new_string("cSymbol",7);
    kNumber = cson_new_string("number",6);
    kDesc = cson_new_string("description",11);
#define C(K) objV = cson_value_new_object(); obj = cson_value_get_object(objV); \
    cson_object_set_s(obj, kRC, json_new_string(json_rc_cstr(FSL_JSON_E_##K)) ); \
    cson_object_set_s(obj, kSymbol, json_new_string("FSL_JSON_E_"#K) );             \
    cson_object_set_s(obj, kNumber, cson_value_new_integer(FSL_JSON_E_##K) );        \
    cson_object_set_s(obj, kDesc, json_new_string(json_err_cstr(FSL_JSON_E_##K))); \
    cson_array_append( list, objV ); obj = NULL; objV = NULL

    C(GENERIC);
    C(INVALID_REQUEST);
    C(UNKNOWN_COMMAND);
    C(UNKNOWN);
    C(TIMEOUT);
    C(ASSERT);
................................................................................
    C(STMT_BIND);
    C(STMT_EXEC);
    C(DB_LOCKED);
    C(DB_NEEDS_REBUILD);
    C(DB_NOT_FOUND);
    C(DB_NOT_VALID);
#undef C
    return listV;
}


/*
** /json/version implementation.
**
** Returns the payload object (owned by the caller).







<
|

|
<
>
|
<
<
<

<
>







 







<
|
<










|




|







 







|







987
988
989
990
991
992
993

994
995
996

997
998



999

1000
1001
1002
1003
1004
1005
1006
1007
....
1823
1824
1825
1826
1827
1828
1829

1830

1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
....
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
**
** The returned value is owned by the caller. If not NULL then it
** _will_ have a JSON type of Array.
*/
cson_value * json_string_split2( char const * zStr,
                                 char separator,
                                 char doDeHttp ){

  cson_array * a = cson_new_array();
  int rc = json_string_split( zStr, separator, doDeHttp, a );
  if( 0>=rc ){

    cson_free_array(a);
    a = NULL;



  }

  return a ? cson_array_value(a) : NULL;
}


/*
** Performs some common initialization of JSON-related state.  Must be
** called by the json_page_top() and json_cmd_top() dispatching
** functions to set up the JSON stat used by the dispatched functions.
................................................................................
}

/*
** Impl of /json/resultCodes
**
*/
cson_value * json_page_resultCodes(){

    cson_array * list = cson_new_array();

    cson_object * obj = NULL;
    cson_string * kRC;
    cson_string * kSymbol;
    cson_string * kNumber;
    cson_string * kDesc;
    cson_array_reserve( list, 35 );
    kRC = cson_new_string("resultCode",10);
    kSymbol = cson_new_string("cSymbol",7);
    kNumber = cson_new_string("number",6);
    kDesc = cson_new_string("description",11);
#define C(K) obj = cson_new_object(); \
    cson_object_set_s(obj, kRC, json_new_string(json_rc_cstr(FSL_JSON_E_##K)) ); \
    cson_object_set_s(obj, kSymbol, json_new_string("FSL_JSON_E_"#K) );             \
    cson_object_set_s(obj, kNumber, cson_value_new_integer(FSL_JSON_E_##K) );        \
    cson_object_set_s(obj, kDesc, json_new_string(json_err_cstr(FSL_JSON_E_##K))); \
    cson_array_append( list, cson_object_value(obj) ); obj = NULL;

    C(GENERIC);
    C(INVALID_REQUEST);
    C(UNKNOWN_COMMAND);
    C(UNKNOWN);
    C(TIMEOUT);
    C(ASSERT);
................................................................................
    C(STMT_BIND);
    C(STMT_EXEC);
    C(DB_LOCKED);
    C(DB_NEEDS_REBUILD);
    C(DB_NOT_FOUND);
    C(DB_NOT_VALID);
#undef C
    return cson_array_value(list);
}


/*
** /json/version implementation.
**
** Returns the payload object (owned by the caller).