Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
Comment: | started adding infrastructure to report non-fatal warnings. |
---|---|
Downloads: | Tarball | ZIP archive |
Timelines: | family | ancestors | descendants | both | json |
Files: | files | file ages | folders |
SHA1: |
ad50fe9584dc909503ee88993ac3f234 |
User & Date: | stephan 2011-09-21 16:31:07.416 |
Context
2011-09-21
| ||
17:38 | More work on the warnings infrastructure. json_warn() now (experimentally) disallows (elides) duplicate warning codes to simplify downstream loops. Still undecided on that behaviour, though. ... (check-in: 576425e8 user: stephan tags: json) | |
16:31 | started adding infrastructure to report non-fatal warnings. ... (check-in: ad50fe95 user: stephan tags: json) | |
15:22 | timeline json refactoring, fixed ordering, split tags into an Array. ... (check-in: d6cbe37b user: stephan tags: json) | |
Changes
Changes to src/json.c.
︙ | ︙ | |||
460 461 462 463 464 465 466 467 468 469 470 471 472 473 | */ v = cson_value_new_object(); g.json.param.v = v; g.json.param.o = cson_value_get_object(v); json_gc_add("$PARAMS", v, 1); } /* ** Splits zStr (which must not be NULL) into tokens separated by the ** given separator character. If doDeHttp is true then each element ** will be passed through dehttpize(), otherwise they are used ** as-is. Each new element is appended to the given target array ** object, which must not be NULL and ownership of it is not changed | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 | */ v = cson_value_new_object(); g.json.param.v = v; g.json.param.o = cson_value_get_object(v); json_gc_add("$PARAMS", v, 1); } /* ** Appends a warning object to the response. ** ** TODO: specify what the code must be. ** ** A Warning object has this JSON structure: ** ** { "code":integer, "text":"string" } ** ** But the text part is optional. ** ** If msg is non-NULL and not empty then it is used ** as the "text" property's value. */ void json_add_warning( int code, char const * msg ){ cson_value * objV = NULL; cson_object * obj = NULL; if(!g.json.warnings.v){ g.json.warnings.v = cson_value_new_array(); assert((NULL != g.json.warnings.v) && "Alloc error."); g.json.warnings.a = cson_value_get_array(g.json.warnings.v); json_gc_add("$WARNINGS",g.json.warnings.v,0); } objV = cson_value_new_object(); assert((NULL != objV) && "Alloc error."); cson_array_append(g.json.warnings.a, objV); obj = cson_value_get_object(objV); cson_object_set(obj,"code",cson_value_new_integer(code)); if(msg && *msg){ /* FIXME: treat NULL msg as standard warning message for the code, but we don't have those yet. */ cson_object_set(obj,"text",cson_value_new_string(msg,strlen(msg))); } } /* ** Splits zStr (which must not be NULL) into tokens separated by the ** given separator character. If doDeHttp is true then each element ** will be passed through dehttpize(), otherwise they are used ** as-is. Each new element is appended to the given target array ** object, which must not be NULL and ownership of it is not changed |
︙ | ︙ | |||
880 881 882 883 884 885 886 887 888 889 890 891 892 893 | if(0){/*Only for debuggering, add some info to the response.*/ tmp = cson_value_new_integer( g.json.cmd.offset ); cson_object_set( o, "cmd.offset", tmp ); cson_object_set( o, "isCGI", cson_value_new_bool( g.isHTTP ) ); } } /* Only add the payload to SUCCESS responses. Else delete it. */ if( NULL != payload ){ if( resultCode ){ cson_value_free(payload); payload = NULL; }else{ tmp = payload; | > > > > > | 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 | if(0){/*Only for debuggering, add some info to the response.*/ tmp = cson_value_new_integer( g.json.cmd.offset ); cson_object_set( o, "cmd.offset", tmp ); cson_object_set( o, "isCGI", cson_value_new_bool( g.isHTTP ) ); } } if(g.json.warnings.v){ tmp = g.json.warnings.v; SET("warnings"); } /* Only add the payload to SUCCESS responses. Else delete it. */ if( NULL != payload ){ if( resultCode ){ cson_value_free(payload); payload = NULL; }else{ tmp = payload; |
︙ | ︙ | |||
1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 | ; json_main_bootstrap(); json_mode_bootstrap(); if( g.argc<3 ){ goto usage; } db_find_and_open_repository(0, 0); cmd = json_command_arg(1); if( !cmd || !*cmd ){ goto usage; } pageDef = json_handler_for_name(cmd,&JsonPageDefs[0]); if( ! pageDef ){ json_err( FSL_JSON_E_UNKNOWN_COMMAND, NULL, 1 ); | > > > | 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 | ; json_main_bootstrap(); json_mode_bootstrap(); if( g.argc<3 ){ goto usage; } db_find_and_open_repository(0, 0); #if 0 json_add_warning(-1, "Just testing."); #endif cmd = json_command_arg(1); if( !cmd || !*cmd ){ goto usage; } pageDef = json_handler_for_name(cmd,&JsonPageDefs[0]); if( ! pageDef ){ json_err( FSL_JSON_E_UNKNOWN_COMMAND, NULL, 1 ); |
︙ | ︙ |
Changes to src/main.c.
︙ | ︙ | |||
205 206 207 208 209 210 211 212 213 214 215 216 217 218 | cson_value * v; cson_object * o; } param; struct { cson_value * v; cson_object * o; } reqPayload; /* request payload object (if any) */ } json; }; /* ** Macro for debugging: */ #define CGIDEBUG(X) if( g.fDebug ) cgi_debug X | > > > > | 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 | cson_value * v; cson_object * o; } param; struct { cson_value * v; cson_object * o; } reqPayload; /* request payload object (if any) */ struct { /* response warnings */ cson_value * v; cson_array * a; } warnings; } json; }; /* ** Macro for debugging: */ #define CGIDEBUG(X) if( g.fDebug ) cgi_debug X |
︙ | ︙ |