Fossil SCM
Added global debugFossilG/--json-debug-g boolean to add the "g" output to any response (including (especially) error responses) to simplify debuggering. Requires a|s privileges.
Commit
f047bbddb484880b19cb9618c585fb9ecfc25d91
Parent
65e0c94c8a8309e…
2 files changed
+1
+109
-97
+1
| --- ajax/index.html | ||
| +++ ajax/index.html | ||
| @@ -224,10 +224,11 @@ | ||
| 224 | 224 | <input type='button' value='version' onclick='TheApp.cgi.sendCommand("/json/version")' /> |
| 225 | 225 | <input type='button' value='stat' onclick='TheApp.cgi.sendCommand("/json/stat?full=0")' /> |
| 226 | 226 | <input type='button' value='whoami' onclick='TheApp.cgi.whoami()' /> |
| 227 | 227 | <input type='button' value='cap' onclick='TheApp.cgi.sendCommand("/json/cap")' /> |
| 228 | 228 | <input type='button' value='resultCodes' onclick='TheApp.cgi.sendCommand("/json/resultCodes")' /> |
| 229 | +<input type='button' value='g' onclick='TheApp.cgi.sendCommand("/json/g")' /> | |
| 229 | 230 | |
| 230 | 231 | <br/> |
| 231 | 232 | |
| 232 | 233 | <input type='button' value='branch/list' onclick='TheApp.cgi.sendCommand("/json/branch/list")' /> |
| 233 | 234 | <input type='button' value='timeline/ci' onclick='TheApp.cgi.sendCommand("/json/timeline/ci?files=true")' /> |
| 234 | 235 |
| --- ajax/index.html | |
| +++ ajax/index.html | |
| @@ -224,10 +224,11 @@ | |
| 224 | <input type='button' value='version' onclick='TheApp.cgi.sendCommand("/json/version")' /> |
| 225 | <input type='button' value='stat' onclick='TheApp.cgi.sendCommand("/json/stat?full=0")' /> |
| 226 | <input type='button' value='whoami' onclick='TheApp.cgi.whoami()' /> |
| 227 | <input type='button' value='cap' onclick='TheApp.cgi.sendCommand("/json/cap")' /> |
| 228 | <input type='button' value='resultCodes' onclick='TheApp.cgi.sendCommand("/json/resultCodes")' /> |
| 229 | |
| 230 | <br/> |
| 231 | |
| 232 | <input type='button' value='branch/list' onclick='TheApp.cgi.sendCommand("/json/branch/list")' /> |
| 233 | <input type='button' value='timeline/ci' onclick='TheApp.cgi.sendCommand("/json/timeline/ci?files=true")' /> |
| 234 |
| --- ajax/index.html | |
| +++ ajax/index.html | |
| @@ -224,10 +224,11 @@ | |
| 224 | <input type='button' value='version' onclick='TheApp.cgi.sendCommand("/json/version")' /> |
| 225 | <input type='button' value='stat' onclick='TheApp.cgi.sendCommand("/json/stat?full=0")' /> |
| 226 | <input type='button' value='whoami' onclick='TheApp.cgi.whoami()' /> |
| 227 | <input type='button' value='cap' onclick='TheApp.cgi.sendCommand("/json/cap")' /> |
| 228 | <input type='button' value='resultCodes' onclick='TheApp.cgi.sendCommand("/json/resultCodes")' /> |
| 229 | <input type='button' value='g' onclick='TheApp.cgi.sendCommand("/json/g")' /> |
| 230 | |
| 231 | <br/> |
| 232 | |
| 233 | <input type='button' value='branch/list' onclick='TheApp.cgi.sendCommand("/json/branch/list")' /> |
| 234 | <input type='button' value='timeline/ci' onclick='TheApp.cgi.sendCommand("/json/timeline/ci?files=true")' /> |
| 235 |
+109
-97
| --- src/json.c | ||
| +++ src/json.c | ||
| @@ -1346,10 +1346,110 @@ | ||
| 1346 | 1346 | ; |
| 1347 | 1347 | blob_reset(&path); |
| 1348 | 1348 | return rc; |
| 1349 | 1349 | } |
| 1350 | 1350 | } |
| 1351 | + | |
| 1352 | +/* | |
| 1353 | +** Returns a JSON Object representation of the global g object. | |
| 1354 | +** Returned value is owned by the caller. | |
| 1355 | +*/ | |
| 1356 | +cson_value * json_g_to_json(){ | |
| 1357 | + cson_object * o = NULL; | |
| 1358 | + cson_object * pay = NULL; | |
| 1359 | + pay = o = cson_new_object(); | |
| 1360 | + | |
| 1361 | +#define INT(OBJ,K) cson_object_set(o, #K, json_new_int(OBJ.K)) | |
| 1362 | +#define CSTR(OBJ,K) cson_object_set(o, #K, OBJ.K ? json_new_string(OBJ.K) : cson_value_null()) | |
| 1363 | +#define VAL(K,V) cson_object_set(o, #K, (V) ? (V) : cson_value_null()) | |
| 1364 | + VAL(capabilities, json_cap_value()); | |
| 1365 | + INT(g, argc); | |
| 1366 | + INT(g, isConst); | |
| 1367 | + INT(g, useAttach); | |
| 1368 | + INT(g, configOpen); | |
| 1369 | + INT(g, repositoryOpen); | |
| 1370 | + INT(g, localOpen); | |
| 1371 | + INT(g, minPrefix); | |
| 1372 | + INT(g, fSqlTrace); | |
| 1373 | + INT(g, fSqlStats); | |
| 1374 | + INT(g, fSqlPrint); | |
| 1375 | + INT(g, fQuiet); | |
| 1376 | + INT(g, fHttpTrace); | |
| 1377 | + INT(g, fSystemTrace); | |
| 1378 | + INT(g, fNoSync); | |
| 1379 | + INT(g, iErrPriority); | |
| 1380 | + INT(g, sslNotAvailable); | |
| 1381 | + INT(g, cgiOutput); | |
| 1382 | + INT(g, xferPanic); | |
| 1383 | + INT(g, fullHttpReply); | |
| 1384 | + INT(g, xlinkClusterOnly); | |
| 1385 | + INT(g, fTimeFormat); | |
| 1386 | + INT(g, markPrivate); | |
| 1387 | + INT(g, clockSkewSeen); | |
| 1388 | + INT(g, isHTTP); | |
| 1389 | + INT(g, urlIsFile); | |
| 1390 | + INT(g, urlIsHttps); | |
| 1391 | + INT(g, urlIsSsh); | |
| 1392 | + INT(g, urlPort); | |
| 1393 | + INT(g, urlDfltPort); | |
| 1394 | + INT(g, dontKeepUrl); | |
| 1395 | + INT(g, useLocalauth); | |
| 1396 | + INT(g, noPswd); | |
| 1397 | + INT(g, userUid); | |
| 1398 | + INT(g, rcvid); | |
| 1399 | + INT(g, okCsrf); | |
| 1400 | + INT(g, thTrace); | |
| 1401 | + INT(g, isHome); | |
| 1402 | + INT(g, nAux); | |
| 1403 | + INT(g, allowSymlinks); | |
| 1404 | + | |
| 1405 | + CSTR(g, zMainDbType); | |
| 1406 | + CSTR(g, zHome); | |
| 1407 | + CSTR(g, zLocalRoot); | |
| 1408 | + CSTR(g, zPath); | |
| 1409 | + CSTR(g, zExtra); | |
| 1410 | + CSTR(g, zBaseURL); | |
| 1411 | + CSTR(g, zTop); | |
| 1412 | + CSTR(g, zContentType); | |
| 1413 | + CSTR(g, zErrMsg); | |
| 1414 | + CSTR(g, urlName); | |
| 1415 | + CSTR(g, urlHostname); | |
| 1416 | + CSTR(g, urlProtocol); | |
| 1417 | + CSTR(g, urlPath); | |
| 1418 | + CSTR(g, urlUser); | |
| 1419 | + CSTR(g, urlPasswd); | |
| 1420 | + CSTR(g, urlCanonical); | |
| 1421 | + CSTR(g, urlProxyAuth); | |
| 1422 | + CSTR(g, urlFossil); | |
| 1423 | + CSTR(g, zLogin); | |
| 1424 | + CSTR(g, zSSLIdentity); | |
| 1425 | + CSTR(g, zIpAddr); | |
| 1426 | + CSTR(g, zNonce); | |
| 1427 | + CSTR(g, zCsrfToken); | |
| 1428 | + | |
| 1429 | + o = cson_new_object(); | |
| 1430 | + cson_object_set(pay, "json", cson_object_value(o) ); | |
| 1431 | + INT(g.json, isJsonMode); | |
| 1432 | + INT(g.json, resultCode); | |
| 1433 | + INT(g.json, errorDetailParanoia); | |
| 1434 | + INT(g.json, dispatchDepth); | |
| 1435 | + VAL(authToken, g.json.authToken); | |
| 1436 | + CSTR(g.json, jsonp); | |
| 1437 | + VAL(gc, g.json.gc.v); | |
| 1438 | + VAL(cmd, g.json.cmd.v); | |
| 1439 | + VAL(param, g.json.param.v); | |
| 1440 | + VAL(POST, g.json.post.v); | |
| 1441 | + VAL(warnings, g.json.warnings.v); | |
| 1442 | + /*cson_output_opt outOpt;*/ | |
| 1443 | + | |
| 1444 | + | |
| 1445 | +#undef INT | |
| 1446 | +#undef CSTR | |
| 1447 | +#undef VAL | |
| 1448 | + return cson_object_value(pay); | |
| 1449 | +} | |
| 1450 | + | |
| 1351 | 1451 | |
| 1352 | 1452 | /* |
| 1353 | 1453 | ** Creates a new Fossil/JSON response envelope skeleton. It is owned |
| 1354 | 1454 | ** by the caller, who must eventually free it using cson_value_free(), |
| 1355 | 1455 | ** or add it to a cson container to transfer ownership. Returns NULL |
| @@ -1389,14 +1489,12 @@ | ||
| 1389 | 1489 | }while(0) |
| 1390 | 1490 | |
| 1391 | 1491 | tmp = cson_value_new_string(MANIFEST_UUID,strlen(MANIFEST_UUID)); |
| 1392 | 1492 | SET("fossil"); |
| 1393 | 1493 | |
| 1394 | - { | |
| 1395 | - tmp = json_new_timestamp(-1); | |
| 1396 | - SET(FossilJsonKeys.timestamp); | |
| 1397 | - } | |
| 1494 | + tmp = json_new_timestamp(-1); | |
| 1495 | + SET(FossilJsonKeys.timestamp); | |
| 1398 | 1496 | |
| 1399 | 1497 | if( 0 != resultCode ){ |
| 1400 | 1498 | if( ! pMsg ){ |
| 1401 | 1499 | pMsg = g.zErrMsg; |
| 1402 | 1500 | if(!pMsg){ |
| @@ -1465,10 +1563,16 @@ | ||
| 1465 | 1563 | tmp = payload; |
| 1466 | 1564 | SET(FossilJsonKeys.payload); |
| 1467 | 1565 | } |
| 1468 | 1566 | } |
| 1469 | 1567 | |
| 1568 | + if(json_find_option_bool("debugFossilG","json-debug-g",NULL,0) | |
| 1569 | + &&(g.perm.Admin||g.perm.Setup)){ | |
| 1570 | + tmp = json_g_to_json(); | |
| 1571 | + SET("g"); | |
| 1572 | + } | |
| 1573 | + | |
| 1470 | 1574 | #undef SET |
| 1471 | 1575 | goto ok; |
| 1472 | 1576 | cleanup: |
| 1473 | 1577 | cson_value_free(v); |
| 1474 | 1578 | v = NULL; |
| @@ -2158,108 +2262,16 @@ | ||
| 2158 | 2262 | |
| 2159 | 2263 | /* |
| 2160 | 2264 | ** Impl of /json/g. Requires admin/setup rights. |
| 2161 | 2265 | */ |
| 2162 | 2266 | static cson_value * json_page_g(){ |
| 2163 | - cson_object * o = NULL; | |
| 2164 | - cson_object * pay = NULL; | |
| 2165 | 2267 | if(!g.perm.Admin || !g.perm.Setup){ |
| 2166 | 2268 | json_set_err(FSL_JSON_E_DENIED, |
| 2167 | 2269 | "Requires 'a' or 's' privileges."); |
| 2168 | 2270 | return NULL; |
| 2169 | 2271 | } |
| 2170 | - pay = o = cson_new_object(); | |
| 2171 | - | |
| 2172 | -#define INT(F,K) cson_object_set(o, #K, json_new_int(F.K)) | |
| 2173 | -#define CSTR(F,K) cson_object_set(o, #K, F.K ? json_new_string(F.K) : cson_value_null()) | |
| 2174 | -#define VAL(K,V) cson_object_set(o, #K, (V) ? (V) : cson_value_null()) | |
| 2175 | - VAL(capabilities, json_cap_value()); | |
| 2176 | - INT(g, argc); | |
| 2177 | - INT(g, isConst); | |
| 2178 | - INT(g, useAttach); | |
| 2179 | - INT(g, configOpen); | |
| 2180 | - INT(g, repositoryOpen); | |
| 2181 | - INT(g, localOpen); | |
| 2182 | - INT(g, minPrefix); | |
| 2183 | - INT(g, fSqlTrace); | |
| 2184 | - INT(g, fSqlStats); | |
| 2185 | - INT(g, fSqlPrint); | |
| 2186 | - INT(g, fQuiet); | |
| 2187 | - INT(g, fHttpTrace); | |
| 2188 | - INT(g, fSystemTrace); | |
| 2189 | - INT(g, fNoSync); | |
| 2190 | - INT(g, iErrPriority); | |
| 2191 | - INT(g, sslNotAvailable); | |
| 2192 | - INT(g, cgiOutput); | |
| 2193 | - INT(g, xferPanic); | |
| 2194 | - INT(g, fullHttpReply); | |
| 2195 | - INT(g, xlinkClusterOnly); | |
| 2196 | - INT(g, fTimeFormat); | |
| 2197 | - INT(g, markPrivate); | |
| 2198 | - INT(g, clockSkewSeen); | |
| 2199 | - INT(g, isHTTP); | |
| 2200 | - | |
| 2201 | - INT(g, urlIsFile); | |
| 2202 | - INT(g, urlIsHttps); | |
| 2203 | - INT(g, urlIsSsh); | |
| 2204 | - INT(g, urlPort); | |
| 2205 | - INT(g, urlDfltPort); | |
| 2206 | - INT(g, dontKeepUrl); | |
| 2207 | - INT(g, useLocalauth); | |
| 2208 | - INT(g, noPswd); | |
| 2209 | - INT(g, userUid); | |
| 2210 | - INT(g, rcvid); | |
| 2211 | - INT(g, okCsrf); | |
| 2212 | - INT(g, thTrace); | |
| 2213 | - INT(g, isHome); | |
| 2214 | - INT(g, nAux); | |
| 2215 | - INT(g, allowSymlinks); | |
| 2216 | - | |
| 2217 | - CSTR(g, zMainDbType); | |
| 2218 | - CSTR(g, zHome); | |
| 2219 | - CSTR(g, zLocalRoot); | |
| 2220 | - CSTR(g, zPath); | |
| 2221 | - CSTR(g, zExtra); | |
| 2222 | - CSTR(g, zBaseURL); | |
| 2223 | - CSTR(g, zTop); | |
| 2224 | - CSTR(g, zContentType); | |
| 2225 | - CSTR(g, zErrMsg); | |
| 2226 | - CSTR(g, urlName); | |
| 2227 | - CSTR(g, urlHostname); | |
| 2228 | - CSTR(g, urlProtocol); | |
| 2229 | - CSTR(g, urlPath); | |
| 2230 | - CSTR(g, urlUser); | |
| 2231 | - CSTR(g, urlPasswd); | |
| 2232 | - CSTR(g, urlCanonical); | |
| 2233 | - CSTR(g, urlProxyAuth); | |
| 2234 | - CSTR(g, urlFossil); | |
| 2235 | - CSTR(g, zLogin); | |
| 2236 | - CSTR(g, zSSLIdentity); | |
| 2237 | - CSTR(g, zIpAddr); | |
| 2238 | - CSTR(g, zNonce); | |
| 2239 | - CSTR(g, zCsrfToken); | |
| 2240 | - | |
| 2241 | - o = cson_new_object(); | |
| 2242 | - cson_object_set(pay, "json", cson_object_value(o) ); | |
| 2243 | - INT(g.json, isJsonMode); | |
| 2244 | - INT(g.json, resultCode); | |
| 2245 | - INT(g.json, errorDetailParanoia); | |
| 2246 | - INT(g.json, dispatchDepth); | |
| 2247 | - VAL(authToken, g.json.authToken); | |
| 2248 | - CSTR(g.json, jsonp); | |
| 2249 | - VAL(gc, g.json.gc.v); | |
| 2250 | - VAL(cmd, g.json.cmd.v); | |
| 2251 | - VAL(param, g.json.param.v); | |
| 2252 | - VAL(requestPayload, g.json.reqPayload.v); | |
| 2253 | - VAL(warnings, g.json.warnings.v); | |
| 2254 | - /*cson_output_opt outOpt;*/ | |
| 2255 | - | |
| 2256 | - | |
| 2257 | -#undef INT | |
| 2258 | -#undef CSTR | |
| 2259 | -#undef VAL | |
| 2260 | - return cson_object_value(pay); | |
| 2272 | + return json_g_to_json(); | |
| 2261 | 2273 | } |
| 2262 | 2274 | |
| 2263 | 2275 | /* Impl in json_login.c. */ |
| 2264 | 2276 | cson_value * json_page_anon_password(); |
| 2265 | 2277 | /* Impl in json_artifact.c. */ |
| 2266 | 2278 |
| --- src/json.c | |
| +++ src/json.c | |
| @@ -1346,10 +1346,110 @@ | |
| 1346 | ; |
| 1347 | blob_reset(&path); |
| 1348 | return rc; |
| 1349 | } |
| 1350 | } |
| 1351 | |
| 1352 | /* |
| 1353 | ** Creates a new Fossil/JSON response envelope skeleton. It is owned |
| 1354 | ** by the caller, who must eventually free it using cson_value_free(), |
| 1355 | ** or add it to a cson container to transfer ownership. Returns NULL |
| @@ -1389,14 +1489,12 @@ | |
| 1389 | }while(0) |
| 1390 | |
| 1391 | tmp = cson_value_new_string(MANIFEST_UUID,strlen(MANIFEST_UUID)); |
| 1392 | SET("fossil"); |
| 1393 | |
| 1394 | { |
| 1395 | tmp = json_new_timestamp(-1); |
| 1396 | SET(FossilJsonKeys.timestamp); |
| 1397 | } |
| 1398 | |
| 1399 | if( 0 != resultCode ){ |
| 1400 | if( ! pMsg ){ |
| 1401 | pMsg = g.zErrMsg; |
| 1402 | if(!pMsg){ |
| @@ -1465,10 +1563,16 @@ | |
| 1465 | tmp = payload; |
| 1466 | SET(FossilJsonKeys.payload); |
| 1467 | } |
| 1468 | } |
| 1469 | |
| 1470 | #undef SET |
| 1471 | goto ok; |
| 1472 | cleanup: |
| 1473 | cson_value_free(v); |
| 1474 | v = NULL; |
| @@ -2158,108 +2262,16 @@ | |
| 2158 | |
| 2159 | /* |
| 2160 | ** Impl of /json/g. Requires admin/setup rights. |
| 2161 | */ |
| 2162 | static cson_value * json_page_g(){ |
| 2163 | cson_object * o = NULL; |
| 2164 | cson_object * pay = NULL; |
| 2165 | if(!g.perm.Admin || !g.perm.Setup){ |
| 2166 | json_set_err(FSL_JSON_E_DENIED, |
| 2167 | "Requires 'a' or 's' privileges."); |
| 2168 | return NULL; |
| 2169 | } |
| 2170 | pay = o = cson_new_object(); |
| 2171 | |
| 2172 | #define INT(F,K) cson_object_set(o, #K, json_new_int(F.K)) |
| 2173 | #define CSTR(F,K) cson_object_set(o, #K, F.K ? json_new_string(F.K) : cson_value_null()) |
| 2174 | #define VAL(K,V) cson_object_set(o, #K, (V) ? (V) : cson_value_null()) |
| 2175 | VAL(capabilities, json_cap_value()); |
| 2176 | INT(g, argc); |
| 2177 | INT(g, isConst); |
| 2178 | INT(g, useAttach); |
| 2179 | INT(g, configOpen); |
| 2180 | INT(g, repositoryOpen); |
| 2181 | INT(g, localOpen); |
| 2182 | INT(g, minPrefix); |
| 2183 | INT(g, fSqlTrace); |
| 2184 | INT(g, fSqlStats); |
| 2185 | INT(g, fSqlPrint); |
| 2186 | INT(g, fQuiet); |
| 2187 | INT(g, fHttpTrace); |
| 2188 | INT(g, fSystemTrace); |
| 2189 | INT(g, fNoSync); |
| 2190 | INT(g, iErrPriority); |
| 2191 | INT(g, sslNotAvailable); |
| 2192 | INT(g, cgiOutput); |
| 2193 | INT(g, xferPanic); |
| 2194 | INT(g, fullHttpReply); |
| 2195 | INT(g, xlinkClusterOnly); |
| 2196 | INT(g, fTimeFormat); |
| 2197 | INT(g, markPrivate); |
| 2198 | INT(g, clockSkewSeen); |
| 2199 | INT(g, isHTTP); |
| 2200 | |
| 2201 | INT(g, urlIsFile); |
| 2202 | INT(g, urlIsHttps); |
| 2203 | INT(g, urlIsSsh); |
| 2204 | INT(g, urlPort); |
| 2205 | INT(g, urlDfltPort); |
| 2206 | INT(g, dontKeepUrl); |
| 2207 | INT(g, useLocalauth); |
| 2208 | INT(g, noPswd); |
| 2209 | INT(g, userUid); |
| 2210 | INT(g, rcvid); |
| 2211 | INT(g, okCsrf); |
| 2212 | INT(g, thTrace); |
| 2213 | INT(g, isHome); |
| 2214 | INT(g, nAux); |
| 2215 | INT(g, allowSymlinks); |
| 2216 | |
| 2217 | CSTR(g, zMainDbType); |
| 2218 | CSTR(g, zHome); |
| 2219 | CSTR(g, zLocalRoot); |
| 2220 | CSTR(g, zPath); |
| 2221 | CSTR(g, zExtra); |
| 2222 | CSTR(g, zBaseURL); |
| 2223 | CSTR(g, zTop); |
| 2224 | CSTR(g, zContentType); |
| 2225 | CSTR(g, zErrMsg); |
| 2226 | CSTR(g, urlName); |
| 2227 | CSTR(g, urlHostname); |
| 2228 | CSTR(g, urlProtocol); |
| 2229 | CSTR(g, urlPath); |
| 2230 | CSTR(g, urlUser); |
| 2231 | CSTR(g, urlPasswd); |
| 2232 | CSTR(g, urlCanonical); |
| 2233 | CSTR(g, urlProxyAuth); |
| 2234 | CSTR(g, urlFossil); |
| 2235 | CSTR(g, zLogin); |
| 2236 | CSTR(g, zSSLIdentity); |
| 2237 | CSTR(g, zIpAddr); |
| 2238 | CSTR(g, zNonce); |
| 2239 | CSTR(g, zCsrfToken); |
| 2240 | |
| 2241 | o = cson_new_object(); |
| 2242 | cson_object_set(pay, "json", cson_object_value(o) ); |
| 2243 | INT(g.json, isJsonMode); |
| 2244 | INT(g.json, resultCode); |
| 2245 | INT(g.json, errorDetailParanoia); |
| 2246 | INT(g.json, dispatchDepth); |
| 2247 | VAL(authToken, g.json.authToken); |
| 2248 | CSTR(g.json, jsonp); |
| 2249 | VAL(gc, g.json.gc.v); |
| 2250 | VAL(cmd, g.json.cmd.v); |
| 2251 | VAL(param, g.json.param.v); |
| 2252 | VAL(requestPayload, g.json.reqPayload.v); |
| 2253 | VAL(warnings, g.json.warnings.v); |
| 2254 | /*cson_output_opt outOpt;*/ |
| 2255 | |
| 2256 | |
| 2257 | #undef INT |
| 2258 | #undef CSTR |
| 2259 | #undef VAL |
| 2260 | return cson_object_value(pay); |
| 2261 | } |
| 2262 | |
| 2263 | /* Impl in json_login.c. */ |
| 2264 | cson_value * json_page_anon_password(); |
| 2265 | /* Impl in json_artifact.c. */ |
| 2266 |
| --- src/json.c | |
| +++ src/json.c | |
| @@ -1346,10 +1346,110 @@ | |
| 1346 | ; |
| 1347 | blob_reset(&path); |
| 1348 | return rc; |
| 1349 | } |
| 1350 | } |
| 1351 | |
| 1352 | /* |
| 1353 | ** Returns a JSON Object representation of the global g object. |
| 1354 | ** Returned value is owned by the caller. |
| 1355 | */ |
| 1356 | cson_value * json_g_to_json(){ |
| 1357 | cson_object * o = NULL; |
| 1358 | cson_object * pay = NULL; |
| 1359 | pay = o = cson_new_object(); |
| 1360 | |
| 1361 | #define INT(OBJ,K) cson_object_set(o, #K, json_new_int(OBJ.K)) |
| 1362 | #define CSTR(OBJ,K) cson_object_set(o, #K, OBJ.K ? json_new_string(OBJ.K) : cson_value_null()) |
| 1363 | #define VAL(K,V) cson_object_set(o, #K, (V) ? (V) : cson_value_null()) |
| 1364 | VAL(capabilities, json_cap_value()); |
| 1365 | INT(g, argc); |
| 1366 | INT(g, isConst); |
| 1367 | INT(g, useAttach); |
| 1368 | INT(g, configOpen); |
| 1369 | INT(g, repositoryOpen); |
| 1370 | INT(g, localOpen); |
| 1371 | INT(g, minPrefix); |
| 1372 | INT(g, fSqlTrace); |
| 1373 | INT(g, fSqlStats); |
| 1374 | INT(g, fSqlPrint); |
| 1375 | INT(g, fQuiet); |
| 1376 | INT(g, fHttpTrace); |
| 1377 | INT(g, fSystemTrace); |
| 1378 | INT(g, fNoSync); |
| 1379 | INT(g, iErrPriority); |
| 1380 | INT(g, sslNotAvailable); |
| 1381 | INT(g, cgiOutput); |
| 1382 | INT(g, xferPanic); |
| 1383 | INT(g, fullHttpReply); |
| 1384 | INT(g, xlinkClusterOnly); |
| 1385 | INT(g, fTimeFormat); |
| 1386 | INT(g, markPrivate); |
| 1387 | INT(g, clockSkewSeen); |
| 1388 | INT(g, isHTTP); |
| 1389 | INT(g, urlIsFile); |
| 1390 | INT(g, urlIsHttps); |
| 1391 | INT(g, urlIsSsh); |
| 1392 | INT(g, urlPort); |
| 1393 | INT(g, urlDfltPort); |
| 1394 | INT(g, dontKeepUrl); |
| 1395 | INT(g, useLocalauth); |
| 1396 | INT(g, noPswd); |
| 1397 | INT(g, userUid); |
| 1398 | INT(g, rcvid); |
| 1399 | INT(g, okCsrf); |
| 1400 | INT(g, thTrace); |
| 1401 | INT(g, isHome); |
| 1402 | INT(g, nAux); |
| 1403 | INT(g, allowSymlinks); |
| 1404 | |
| 1405 | CSTR(g, zMainDbType); |
| 1406 | CSTR(g, zHome); |
| 1407 | CSTR(g, zLocalRoot); |
| 1408 | CSTR(g, zPath); |
| 1409 | CSTR(g, zExtra); |
| 1410 | CSTR(g, zBaseURL); |
| 1411 | CSTR(g, zTop); |
| 1412 | CSTR(g, zContentType); |
| 1413 | CSTR(g, zErrMsg); |
| 1414 | CSTR(g, urlName); |
| 1415 | CSTR(g, urlHostname); |
| 1416 | CSTR(g, urlProtocol); |
| 1417 | CSTR(g, urlPath); |
| 1418 | CSTR(g, urlUser); |
| 1419 | CSTR(g, urlPasswd); |
| 1420 | CSTR(g, urlCanonical); |
| 1421 | CSTR(g, urlProxyAuth); |
| 1422 | CSTR(g, urlFossil); |
| 1423 | CSTR(g, zLogin); |
| 1424 | CSTR(g, zSSLIdentity); |
| 1425 | CSTR(g, zIpAddr); |
| 1426 | CSTR(g, zNonce); |
| 1427 | CSTR(g, zCsrfToken); |
| 1428 | |
| 1429 | o = cson_new_object(); |
| 1430 | cson_object_set(pay, "json", cson_object_value(o) ); |
| 1431 | INT(g.json, isJsonMode); |
| 1432 | INT(g.json, resultCode); |
| 1433 | INT(g.json, errorDetailParanoia); |
| 1434 | INT(g.json, dispatchDepth); |
| 1435 | VAL(authToken, g.json.authToken); |
| 1436 | CSTR(g.json, jsonp); |
| 1437 | VAL(gc, g.json.gc.v); |
| 1438 | VAL(cmd, g.json.cmd.v); |
| 1439 | VAL(param, g.json.param.v); |
| 1440 | VAL(POST, g.json.post.v); |
| 1441 | VAL(warnings, g.json.warnings.v); |
| 1442 | /*cson_output_opt outOpt;*/ |
| 1443 | |
| 1444 | |
| 1445 | #undef INT |
| 1446 | #undef CSTR |
| 1447 | #undef VAL |
| 1448 | return cson_object_value(pay); |
| 1449 | } |
| 1450 | |
| 1451 | |
| 1452 | /* |
| 1453 | ** Creates a new Fossil/JSON response envelope skeleton. It is owned |
| 1454 | ** by the caller, who must eventually free it using cson_value_free(), |
| 1455 | ** or add it to a cson container to transfer ownership. Returns NULL |
| @@ -1389,14 +1489,12 @@ | |
| 1489 | }while(0) |
| 1490 | |
| 1491 | tmp = cson_value_new_string(MANIFEST_UUID,strlen(MANIFEST_UUID)); |
| 1492 | SET("fossil"); |
| 1493 | |
| 1494 | tmp = json_new_timestamp(-1); |
| 1495 | SET(FossilJsonKeys.timestamp); |
| 1496 | |
| 1497 | if( 0 != resultCode ){ |
| 1498 | if( ! pMsg ){ |
| 1499 | pMsg = g.zErrMsg; |
| 1500 | if(!pMsg){ |
| @@ -1465,10 +1563,16 @@ | |
| 1563 | tmp = payload; |
| 1564 | SET(FossilJsonKeys.payload); |
| 1565 | } |
| 1566 | } |
| 1567 | |
| 1568 | if(json_find_option_bool("debugFossilG","json-debug-g",NULL,0) |
| 1569 | &&(g.perm.Admin||g.perm.Setup)){ |
| 1570 | tmp = json_g_to_json(); |
| 1571 | SET("g"); |
| 1572 | } |
| 1573 | |
| 1574 | #undef SET |
| 1575 | goto ok; |
| 1576 | cleanup: |
| 1577 | cson_value_free(v); |
| 1578 | v = NULL; |
| @@ -2158,108 +2262,16 @@ | |
| 2262 | |
| 2263 | /* |
| 2264 | ** Impl of /json/g. Requires admin/setup rights. |
| 2265 | */ |
| 2266 | static cson_value * json_page_g(){ |
| 2267 | if(!g.perm.Admin || !g.perm.Setup){ |
| 2268 | json_set_err(FSL_JSON_E_DENIED, |
| 2269 | "Requires 'a' or 's' privileges."); |
| 2270 | return NULL; |
| 2271 | } |
| 2272 | return json_g_to_json(); |
| 2273 | } |
| 2274 | |
| 2275 | /* Impl in json_login.c. */ |
| 2276 | cson_value * json_page_anon_password(); |
| 2277 | /* Impl in json_artifact.c. */ |
| 2278 |