Fossil SCM
Added /json/g, which dumps the "g" object to JSON (debuggering tool).
Commit
65e0c94c8a8309ec33321b3f6b8f33ba50778e11
Parent
fb55f2534d09761…
1 file changed
+134
+134
| --- src/json.c | ||
| +++ src/json.c | ||
| @@ -803,10 +803,18 @@ | ||
| 803 | 803 | them in. |
| 804 | 804 | */ |
| 805 | 805 | v = cson_value_new_array(); |
| 806 | 806 | g.json.gc.v = v; |
| 807 | 807 | g.json.gc.a = cson_value_get_array(v); |
| 808 | + cson_value_add_reference(v) | |
| 809 | + /* Needed to allow us to include this value in other JSON | |
| 810 | + containers without transfering ownership to those containers. | |
| 811 | + All other persistent g.json.XXX.v values get appended to | |
| 812 | + g.json.gc.a, and therefore already have a live reference | |
| 813 | + for this purpose. | |
| 814 | + */ | |
| 815 | + ; | |
| 808 | 816 | |
| 809 | 817 | /* |
| 810 | 818 | g.json.param holds the JSONized counterpart of fossil's |
| 811 | 819 | cgi_parameter_xxx() family of data. We store them as JSON, as |
| 812 | 820 | opposed to using fossil's data directly, because we can retain |
| @@ -1788,10 +1796,30 @@ | ||
| 1788 | 1796 | cson_object_set( jobj, "resultCodeParanoiaLevel", |
| 1789 | 1797 | cson_value_new_integer(g.json.errorDetailParanoia) ); |
| 1790 | 1798 | return jval; |
| 1791 | 1799 | } |
| 1792 | 1800 | |
| 1801 | + | |
| 1802 | +/* | |
| 1803 | +** Returns the current user's capabilities string as a String value. | |
| 1804 | +** Returned value is owned by the caller, and will only be NULL if | |
| 1805 | +** g.userUid is invalid or an out of memory error. Or, it turns out, | |
| 1806 | +** in CLI mode (where there is no logged-in user). | |
| 1807 | +*/ | |
| 1808 | +cson_value * json_cap_value(){ | |
| 1809 | + Stmt q; | |
| 1810 | + cson_value * val = NULL; | |
| 1811 | + db_prepare(&q, "SELECT cap FROM user WHERE uid=%d", g.userUid); | |
| 1812 | + if( db_step(&q)==SQLITE_ROW ){ | |
| 1813 | + char const * str = (char const *)sqlite3_column_text(q.pStmt,0); | |
| 1814 | + if( str ){ | |
| 1815 | + val = json_new_string(str); | |
| 1816 | + } | |
| 1817 | + } | |
| 1818 | + db_finalize(&q); | |
| 1819 | + return val; | |
| 1820 | +} | |
| 1793 | 1821 | |
| 1794 | 1822 | /* |
| 1795 | 1823 | ** Implementation for /json/cap |
| 1796 | 1824 | ** |
| 1797 | 1825 | ** Returned object contains details about the "capabilities" of the |
| @@ -2125,10 +2153,115 @@ | ||
| 2125 | 2153 | } |
| 2126 | 2154 | db_finalize(&q); |
| 2127 | 2155 | return payV; |
| 2128 | 2156 | } |
| 2129 | 2157 | |
| 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 | + | |
| 2130 | 2263 | /* Impl in json_login.c. */ |
| 2131 | 2264 | cson_value * json_page_anon_password(); |
| 2132 | 2265 | /* Impl in json_artifact.c. */ |
| 2133 | 2266 | cson_value * json_page_artifact(); |
| 2134 | 2267 | /* Impl in json_branch.c. */ |
| @@ -2156,10 +2289,11 @@ | ||
| 2156 | 2289 | {"artifact", json_page_artifact, 0}, |
| 2157 | 2290 | {"branch", json_page_branch,0}, |
| 2158 | 2291 | {"cap", json_page_cap, 0}, |
| 2159 | 2292 | {"diff", json_page_diff, 0}, |
| 2160 | 2293 | {"dir", json_page_nyi, 0}, |
| 2294 | +{"g", json_page_g, 0}, | |
| 2161 | 2295 | {"HAI",json_page_version,0}, |
| 2162 | 2296 | {"login",json_page_login,1}, |
| 2163 | 2297 | {"logout",json_page_logout,1}, |
| 2164 | 2298 | {"query",json_page_query,0}, |
| 2165 | 2299 | {"rebuild",json_page_rebuild,0}, |
| 2166 | 2300 |
| --- src/json.c | |
| +++ src/json.c | |
| @@ -803,10 +803,18 @@ | |
| 803 | them in. |
| 804 | */ |
| 805 | v = cson_value_new_array(); |
| 806 | g.json.gc.v = v; |
| 807 | g.json.gc.a = cson_value_get_array(v); |
| 808 | |
| 809 | /* |
| 810 | g.json.param holds the JSONized counterpart of fossil's |
| 811 | cgi_parameter_xxx() family of data. We store them as JSON, as |
| 812 | opposed to using fossil's data directly, because we can retain |
| @@ -1788,10 +1796,30 @@ | |
| 1788 | cson_object_set( jobj, "resultCodeParanoiaLevel", |
| 1789 | cson_value_new_integer(g.json.errorDetailParanoia) ); |
| 1790 | return jval; |
| 1791 | } |
| 1792 | |
| 1793 | |
| 1794 | /* |
| 1795 | ** Implementation for /json/cap |
| 1796 | ** |
| 1797 | ** Returned object contains details about the "capabilities" of the |
| @@ -2125,10 +2153,115 @@ | |
| 2125 | } |
| 2126 | db_finalize(&q); |
| 2127 | return payV; |
| 2128 | } |
| 2129 | |
| 2130 | /* Impl in json_login.c. */ |
| 2131 | cson_value * json_page_anon_password(); |
| 2132 | /* Impl in json_artifact.c. */ |
| 2133 | cson_value * json_page_artifact(); |
| 2134 | /* Impl in json_branch.c. */ |
| @@ -2156,10 +2289,11 @@ | |
| 2156 | {"artifact", json_page_artifact, 0}, |
| 2157 | {"branch", json_page_branch,0}, |
| 2158 | {"cap", json_page_cap, 0}, |
| 2159 | {"diff", json_page_diff, 0}, |
| 2160 | {"dir", json_page_nyi, 0}, |
| 2161 | {"HAI",json_page_version,0}, |
| 2162 | {"login",json_page_login,1}, |
| 2163 | {"logout",json_page_logout,1}, |
| 2164 | {"query",json_page_query,0}, |
| 2165 | {"rebuild",json_page_rebuild,0}, |
| 2166 |
| --- src/json.c | |
| +++ src/json.c | |
| @@ -803,10 +803,18 @@ | |
| 803 | them in. |
| 804 | */ |
| 805 | v = cson_value_new_array(); |
| 806 | g.json.gc.v = v; |
| 807 | g.json.gc.a = cson_value_get_array(v); |
| 808 | cson_value_add_reference(v) |
| 809 | /* Needed to allow us to include this value in other JSON |
| 810 | containers without transfering ownership to those containers. |
| 811 | All other persistent g.json.XXX.v values get appended to |
| 812 | g.json.gc.a, and therefore already have a live reference |
| 813 | for this purpose. |
| 814 | */ |
| 815 | ; |
| 816 | |
| 817 | /* |
| 818 | g.json.param holds the JSONized counterpart of fossil's |
| 819 | cgi_parameter_xxx() family of data. We store them as JSON, as |
| 820 | opposed to using fossil's data directly, because we can retain |
| @@ -1788,10 +1796,30 @@ | |
| 1796 | cson_object_set( jobj, "resultCodeParanoiaLevel", |
| 1797 | cson_value_new_integer(g.json.errorDetailParanoia) ); |
| 1798 | return jval; |
| 1799 | } |
| 1800 | |
| 1801 | |
| 1802 | /* |
| 1803 | ** Returns the current user's capabilities string as a String value. |
| 1804 | ** Returned value is owned by the caller, and will only be NULL if |
| 1805 | ** g.userUid is invalid or an out of memory error. Or, it turns out, |
| 1806 | ** in CLI mode (where there is no logged-in user). |
| 1807 | */ |
| 1808 | cson_value * json_cap_value(){ |
| 1809 | Stmt q; |
| 1810 | cson_value * val = NULL; |
| 1811 | db_prepare(&q, "SELECT cap FROM user WHERE uid=%d", g.userUid); |
| 1812 | if( db_step(&q)==SQLITE_ROW ){ |
| 1813 | char const * str = (char const *)sqlite3_column_text(q.pStmt,0); |
| 1814 | if( str ){ |
| 1815 | val = json_new_string(str); |
| 1816 | } |
| 1817 | } |
| 1818 | db_finalize(&q); |
| 1819 | return val; |
| 1820 | } |
| 1821 | |
| 1822 | /* |
| 1823 | ** Implementation for /json/cap |
| 1824 | ** |
| 1825 | ** Returned object contains details about the "capabilities" of the |
| @@ -2125,10 +2153,115 @@ | |
| 2153 | } |
| 2154 | db_finalize(&q); |
| 2155 | return payV; |
| 2156 | } |
| 2157 | |
| 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 | cson_value * json_page_artifact(); |
| 2267 | /* Impl in json_branch.c. */ |
| @@ -2156,10 +2289,11 @@ | |
| 2289 | {"artifact", json_page_artifact, 0}, |
| 2290 | {"branch", json_page_branch,0}, |
| 2291 | {"cap", json_page_cap, 0}, |
| 2292 | {"diff", json_page_diff, 0}, |
| 2293 | {"dir", json_page_nyi, 0}, |
| 2294 | {"g", json_page_g, 0}, |
| 2295 | {"HAI",json_page_version,0}, |
| 2296 | {"login",json_page_login,1}, |
| 2297 | {"logout",json_page_logout,1}, |
| 2298 | {"query",json_page_query,0}, |
| 2299 | {"rebuild",json_page_rebuild,0}, |
| 2300 |