Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
Comment: | Implemented /json/timeline/ticket, cleaned up timeline/ci|wiki. |
---|---|
Downloads: | Tarball | ZIP archive |
Timelines: | family | ancestors | descendants | both | json |
Files: | files | file ages | folders |
SHA1: |
42900f3029d129d97f9e8c73f68a37ea |
User & Date: | stephan 2011-09-23 12:29:36.454 |
Context
2011-09-23
| ||
12:46 | Added comment to timeline/ticket. Minor additions to AJAX test pages. ... (check-in: de0b860f user: stephan tags: json) | |
12:29 | Implemented /json/timeline/ticket, cleaned up timeline/ci|wiki. ... (check-in: 42900f30 user: stephan tags: json) | |
10:52 | Changed fossil_json_f() callback interface. Refactored json command dispatching a bit. Fixed an ordering problem in the json timelines. Pulled in latest cson_amalgamation. ... (check-in: c24b4450 user: stephan tags: json) | |
Changes
Changes to src/json.c.
︙ | ︙ | |||
1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 | } } return payV; } static cson_value * json_timeline_ci(); static cson_value * json_timeline_wiki(); /* ** Mapping of /json/timeline/XXX commands/paths to callbacks. */ static const JsonPageDef JsonPageDefs_Timeline[] = { {"ci", json_timeline_ci, 0}, {"wiki", json_timeline_wiki, 0}, /* Last entry MUST have a NULL name. */ {NULL,NULL,0} }; /* ** Implements the /json/timeline family of pages/commands. Far from | > > > > > > > > > | 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 | } } return payV; } static cson_value * json_timeline_ci(); static cson_value * json_timeline_wiki(); static cson_value * json_timeline_ticket(); /* ** Mapping of /json/timeline/XXX commands/paths to callbacks. */ static const JsonPageDef JsonPageDefs_Timeline[] = { {"c", json_timeline_ci, 0}, {"ci", json_timeline_ci, 0}, {"com", json_timeline_ci, 0}, {"commit", json_timeline_ci, 0}, {"t", json_timeline_ticket, 0}, {"ticket", json_timeline_ticket, 0}, {"w", json_timeline_wiki, 0}, {"wi", json_timeline_wiki, 0}, {"wik", json_timeline_wiki, 0}, {"wiki", json_timeline_wiki, 0}, /* Last entry MUST have a NULL name. */ {NULL,NULL,0} }; /* ** Implements the /json/timeline family of pages/commands. Far from |
︙ | ︙ | |||
2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 | }else{/* CLI mode */ char const * arg = find_option("limit","n",1); if(arg && *arg){ limit = atoi(arg); } } return (limit<0) ? defaultLimit : limit; } /* ** Implementation of /json/timeline/ci. ** ** Still a few TODOs (like figuring out how to structure ** inheritance info). */ static cson_value * json_timeline_ci(){ cson_value * payV = NULL; cson_object * pay = NULL; cson_value * tmp = NULL; cson_value * listV = NULL; cson_array * list = NULL; | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > < < | < < < < < < < < < | | < | 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 | }else{/* CLI mode */ char const * arg = find_option("limit","n",1); if(arg && *arg){ limit = atoi(arg); } } return (limit<0) ? defaultLimit : limit; } /* ** Internal helper for the json_timeline_EVENTTYPE() family of ** functions. zEventType must be one of (ci, w, t). pSql must be a ** cleanly-initialized, empty Blob to store the sql in. If pPayload is ** not NULL it is assumed to be the pending response payload. If ** json_timeline_limit() returns non-0, this function adds a LIMIT ** clause to the generated SQL and (if pPayload is not NULL) adds the ** limit value as the "limit" property of pPayload. */ static void json_timeline_setup_sql( char const * zEventType, Blob * pSql, cson_object * pPayload ){ int limit; assert( zEventType && *zEventType && pSql ); json_timeline_temp_table(); blob_append(pSql, "INSERT OR IGNORE INTO json_timeline ", -1); blob_append(pSql, json_timeline_query(), -1 ); blob_appendf(pSql, " AND event.type IN(%Q) ", zEventType); json_timeline_add_time_clause(pSql); limit = json_timeline_limit(); if(limit){ blob_appendf(pSql,"LIMIT %d ",limit); } if(pPayload){ cson_object_set(pPayload, "limit",cson_value_new_integer(limit)); } } /* ** Implementation of /json/timeline/ci. ** ** Still a few TODOs (like figuring out how to structure ** inheritance info). */ static cson_value * json_timeline_ci(){ cson_value * payV = NULL; cson_object * pay = NULL; cson_value * tmp = NULL; cson_value * listV = NULL; cson_array * list = NULL; int check = 0; Stmt q; Blob sql = empty_blob; if( !g.perm.Read/* && !g.perm.RdTkt && !g.perm.RdWiki*/ ){ g.json.resultCode = FSL_JSON_E_DENIED; return NULL; } payV = cson_value_new_object(); pay = cson_value_get_object(payV); json_timeline_setup_sql( "ci", &sql, pay ); #define SET(K) if(0!=(check=cson_object_set(pay,K,tmp))){ \ g.json.resultCode = (cson_rc.AllocError==check) \ ? FSL_JSON_E_ALLOC : FSL_JSON_E_UNKNOWN; \ goto error;\ } db_multi_exec(blob_buffer(&sql)); #if 0 /* only for testing! */ tmp = cson_value_new_string(blob_buffer(&sql),strlen(blob_buffer(&sql))); SET("timelineSql"); #endif blob_reset(&sql); blob_append(&sql, "SELECT " " rid AS rid," " uuid AS uuid," " mtime AS timestamp," " timestampString AS timestampString," " comment AS comment, " " user AS user," " isLeaf AS isLeaf," /*FIXME: convert to JSON bool */ " bgColor AS bgColor," /* why always null? */ " eventType AS eventType," " tags AS tags," /*FIXME: split this into a JSON array*/ " tagId AS tagId" " FROM json_timeline" " ORDER BY sortId", -1); db_prepare(&q,blob_buffer(&sql)); listV = cson_value_new_array(); list = cson_value_get_array(listV); tmp = listV; |
︙ | ︙ | |||
2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 | tmp = NULL; } } db_finalize(&q); #undef SET goto ok; error: cson_value_free(payV); payV = NULL; ok: return payV; } /* ** Implementation of /json/timeline/wiki. ** */ static cson_value * json_timeline_wiki(){ /* This code is 95% the same as json_timeline_ci(), by the way. */ cson_value * payV = NULL; cson_object * pay = NULL; cson_value * tmp = NULL; cson_value * listV = NULL; cson_array * list = NULL; | > < < | < < < < < < < < < | 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 | tmp = NULL; } } db_finalize(&q); #undef SET goto ok; error: assert( 0 != g.json.resultCode ); cson_value_free(payV); payV = NULL; ok: return payV; } /* ** Implementation of /json/timeline/wiki. ** */ static cson_value * json_timeline_wiki(){ /* This code is 95% the same as json_timeline_ci(), by the way. */ cson_value * payV = NULL; cson_object * pay = NULL; cson_value * tmp = NULL; cson_value * listV = NULL; cson_array * list = NULL; int check = 0; Stmt q; Blob sql = empty_blob; if( !g.perm.Read || !g.perm.RdWiki ){ g.json.resultCode = FSL_JSON_E_DENIED; return NULL; } payV = cson_value_new_object(); pay = cson_value_get_object(payV); json_timeline_setup_sql( "w", &sql, pay ); #define SET(K) if(0!=(check=cson_object_set(pay,K,tmp))){ \ g.json.resultCode = (cson_rc.AllocError==check) \ ? FSL_JSON_E_ALLOC : FSL_JSON_E_UNKNOWN; \ goto error;\ } db_multi_exec(blob_buffer(&sql)); #if 0 /* only for testing! */ tmp = cson_value_new_string(blob_buffer(&sql),strlen(blob_buffer(&sql))); SET("timelineSql"); #endif |
︙ | ︙ | |||
2257 2258 2259 2260 2261 2262 2263 | list = cson_value_get_array(listV); tmp = listV; SET("timeline"); while( (SQLITE_ROW == db_step(&q) )){ /* convert each row into a JSON object...*/ cson_value * rowV = cson_sqlite3_row_to_object(q.pStmt); cson_object * row = cson_value_get_object(rowV); | > > > > > > > > > > > > > > > > > > > > > | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > < | < < < < < | < | < < > | < < | | | < < > | 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 | list = cson_value_get_array(listV); tmp = listV; SET("timeline"); while( (SQLITE_ROW == db_step(&q) )){ /* convert each row into a JSON object...*/ cson_value * rowV = cson_sqlite3_row_to_object(q.pStmt); cson_object * row = cson_value_get_object(rowV); int rc; if(!row){ json_warn( FSL_JSON_W_ROW_TO_JSON_FAILED, "Could not convert at least one timeline result row to JSON." ); continue; } rc = cson_array_append( list, rowV ); if( 0 != rc ){ cson_value_free(rowV); g.json.resultCode = (cson_rc.AllocError==rc) ? FSL_JSON_E_ALLOC : FSL_JSON_E_UNKNOWN; goto error; } } db_finalize(&q); #undef SET goto ok; error: assert( 0 != g.json.resultCode ); cson_value_free(payV); payV = NULL; ok: return payV; } /* ** Implementation of /json/timeline/ticket. ** */ static cson_value * json_timeline_ticket(){ /* This code is 95% the same as json_timeline_ci(), by the way. */ cson_value * payV = NULL; cson_object * pay = NULL; cson_value * tmp = NULL; cson_value * listV = NULL; cson_array * list = NULL; int check = 0; Stmt q; Blob sql = empty_blob; if( !g.perm.Read || !g.perm.RdTkt ){ g.json.resultCode = FSL_JSON_E_DENIED; return NULL; } payV = cson_value_new_object(); pay = cson_value_get_object(payV); json_timeline_setup_sql( "t", &sql, pay ); db_multi_exec(blob_buffer(&sql)); #define SET(K) if(0!=(check=cson_object_set(pay,K,tmp))){ \ g.json.resultCode = (cson_rc.AllocError==check) \ ? FSL_JSON_E_ALLOC : FSL_JSON_E_UNKNOWN; \ goto error;\ } #if 0 /* only for testing! */ tmp = cson_value_new_string(blob_buffer(&sql),strlen(blob_buffer(&sql))); SET("timelineSql"); #endif blob_reset(&sql); blob_append(&sql, "SELECT rid AS rid," " uuid AS uuid," " mtime AS timestamp," " timestampString AS timestampString," " user AS user," " eventType AS eventType," " brief AS briefText" " FROM json_timeline" " ORDER BY sortId", -1); db_prepare(&q,blob_buffer(&sql)); listV = cson_value_new_array(); list = cson_value_get_array(listV); tmp = listV; SET("timeline"); while( (SQLITE_ROW == db_step(&q) )){ /* convert each row into a JSON object...*/ int rc; cson_value * rowV = cson_sqlite3_row_to_object(q.pStmt); cson_object * row = cson_value_get_object(rowV); if(!row){ json_warn( FSL_JSON_W_ROW_TO_JSON_FAILED, "Could not convert at least one timeline result row to JSON." ); continue; } rc = cson_array_append( list, rowV ); if( 0 != rc ){ cson_value_free(rowV); g.json.resultCode = (cson_rc.AllocError==rc) ? FSL_JSON_E_ALLOC : FSL_JSON_E_UNKNOWN; goto error; } } db_finalize(&q); #undef SET goto ok; error: assert( 0 != g.json.resultCode ); cson_value_free(payV); payV = NULL; ok: return payV; } |
︙ | ︙ |