| | @@ -887,30 +887,30 @@ |
| 887 | 887 | if( once ){ |
| 888 | 888 | return; |
| 889 | 889 | }else{ |
| 890 | 890 | once = 1; |
| 891 | 891 | } |
| 892 | | - g.json.jsonp = PD("jsonp",NULL); |
| 892 | + g.json.jsonp = PD("jsonp",NULL) |
| 893 | + /* FIXME: do some sanity checking on g.json.jsonp and ignore it |
| 894 | + if it is not halfway reasonable. |
| 895 | + */ |
| 896 | + ; |
| 893 | 897 | g.json.isJsonMode = 1; |
| 894 | 898 | g.json.resultCode = 0; |
| 895 | 899 | g.json.cmd.offset = -1; |
| 896 | 900 | if( !g.isHTTP && g.fullHttpReply ){ |
| 897 | 901 | /* workaround for server mode, so we see it as CGI mode. */ |
| 898 | 902 | g.isHTTP = 1; |
| 899 | 903 | } |
| 900 | 904 | |
| 901 | | - /* FIXME: do some sanity checking on g.json.jsonp and ignore it |
| 902 | | - if it is not halfway reasonable. |
| 903 | | - */ |
| 904 | | - cgi_set_content_type(json_guess_content_type()) |
| 905 | | - /* reminder: must be done after g.json.jsonp is initialized */ |
| 906 | | - ; |
| 907 | | - |
| 908 | | -#if defined(NDEBUG) |
| 909 | | - /* avoids debug messages on stderr in JSON mode */ |
| 910 | | - sqlite3_config(SQLITE_CONFIG_LOG, NULL, 0); |
| 911 | | -#endif |
| 905 | + if(g.isHTTP){ |
| 906 | + cgi_set_content_type(json_guess_content_type()) |
| 907 | + /* reminder: must be done after g.json.jsonp is initialized */ |
| 908 | + ; |
| 909 | + /* avoids debug messages on stderr in JSON mode */ |
| 910 | + sqlite3_config(SQLITE_CONFIG_LOG, NULL, 0); |
| 911 | + } |
| 912 | 912 | |
| 913 | 913 | g.json.cmd.v = cson_value_new_array(); |
| 914 | 914 | g.json.cmd.a = cson_value_get_array(g.json.cmd.v); |
| 915 | 915 | json_gc_add( FossilJsonKeys.commandPath, g.json.cmd.v, 1 ); |
| 916 | 916 | /* |
| | @@ -931,15 +931,43 @@ |
| 931 | 931 | cson_value * part; |
| 932 | 932 | for(i = 1/*skip argv[0]*/; i < g.argc; ++i ){ |
| 933 | 933 | arg = g.argv[i]; |
| 934 | 934 | if( !arg || !*arg ){ |
| 935 | 935 | continue; |
| 936 | + } |
| 937 | + if('-' == *arg){ |
| 938 | + /* workaround to skip CLI args so that |
| 939 | + json_command_arg() does not see them. |
| 940 | + This assumes that all arguments come LAST |
| 941 | + on the command line. |
| 942 | + */ |
| 943 | + break; |
| 936 | 944 | } |
| 937 | 945 | part = cson_value_new_string(arg,strlen(arg)); |
| 938 | 946 | cson_array_append(g.json.cmd.a, part); |
| 939 | 947 | } |
| 940 | 948 | } |
| 949 | + |
| 950 | + while(!g.isHTTP){ /* simulate JSON POST data via input file. */ |
| 951 | + FILE * inFile = NULL; |
| 952 | + char const * jfile = find_option("json-input",NULL,1); |
| 953 | + if(!jfile || !*jfile){ |
| 954 | + break; |
| 955 | + } |
| 956 | + inFile = (0==strcmp("-",jfile)) |
| 957 | + ? stdin |
| 958 | + : fopen(jfile,"rb"); |
| 959 | + if(!inFile){ |
| 960 | + json_err(FSL_JSON_E_UNKNOWN,"Could not open JSON file.",1); |
| 961 | + fossil_exit(1); |
| 962 | + } |
| 963 | + cgi_parse_POST_JSON(inFile, 0); |
| 964 | + if( stdin != inFile ){ |
| 965 | + fclose(inFile); |
| 966 | + } |
| 967 | + break; |
| 968 | + } |
| 941 | 969 | |
| 942 | 970 | /* g.json.reqPayload exists only to simplify some of our access to |
| 943 | 971 | the request payload. We currently only use this in the context of |
| 944 | 972 | Object payloads, not Arrays, strings, etc. |
| 945 | 973 | */ |
| | @@ -969,13 +997,19 @@ |
| 969 | 997 | } |
| 970 | 998 | |
| 971 | 999 | {/* set up JSON output formatting options. */ |
| 972 | 1000 | unsigned char indent = g.isHTTP ? 0 : 1; |
| 973 | 1001 | char const * indentStr = NULL; |
| 974 | | - if( g.isHTTP ){ |
| 975 | | - indent = (unsigned char)json_getenv_int("indent",(int)indent); |
| 976 | | - }else{/*CLI mode*/ |
| 1002 | + char checkAgain = 1; |
| 1003 | + if( g.json.post.v ){ |
| 1004 | + cson_value const * check = json_getenv("indent"); |
| 1005 | + if(check){ |
| 1006 | + checkAgain = 0; |
| 1007 | + indent = (unsigned char)json_getenv_int("indent",(int)indent); |
| 1008 | + } |
| 1009 | + } |
| 1010 | + if(!g.isHTTP && checkAgain){/*CLI mode*/ |
| 977 | 1011 | indentStr = find_option("indent","I",1); |
| 978 | 1012 | if(indentStr){ |
| 979 | 1013 | int const n = atoi(indentStr); |
| 980 | 1014 | indent = (n>0) |
| 981 | 1015 | ? (unsigned char)n |
| 982 | 1016 | |