Fossil SCM

minor code simplifications.

stephan 2011-10-20 18:48 json-multitag-test
Commit 400fe340c25f191b8f24c54ec9d92ec8f9a4b149
1 file changed +11 -22
--- src/json_artifact.c
+++ src/json_artifact.c
@@ -158,11 +158,10 @@
158158
159159
/*
160160
** Very incomplete/incorrect impl of /json/artifact/TICKET_ID.
161161
*/
162162
cson_value * json_artifact_ticket( int rid ){
163
- cson_value * payV = NULL;
164163
cson_object * pay = NULL;
165164
Manifest *pTktChng = NULL;
166165
static cson_value * eventTypeLabel = NULL;
167166
if(! g.perm.RdTkt ){
168167
g.json.resultCode = FSL_JSON_E_DENIED;
@@ -176,18 +175,17 @@
176175
pTktChng = manifest_get(rid, CFTYPE_TICKET);
177176
if( pTktChng==0 ){
178177
g.json.resultCode = FSL_JSON_E_MANIFEST_READ_FAILED;
179178
return NULL;
180179
}
181
- payV = cson_value_new_object();
182
- pay = cson_value_get_object(payV);
180
+ pay = cson_new_object();
183181
cson_object_set(pay, "eventType", eventTypeLabel );
184182
cson_object_set(pay, "uuid", json_new_string(pTktChng->zTicketUuid));
185183
cson_object_set(pay, "user", json_new_string(pTktChng->zUser));
186184
cson_object_set(pay, "timestamp", json_julian_to_timestamp(pTktChng->rDate));
187185
manifest_destroy(pTktChng);
188
- return payV;
186
+ return cson_object_value(pay);
189187
}
190188
191189
/*
192190
** Sub-impl of /json/artifact for checkins.
193191
*/
@@ -230,11 +228,10 @@
230228
return json_get_wiki_page_by_rid(rid, 0);
231229
}
232230
}
233231
234232
cson_value * json_artifact_file(int rid){
235
- cson_value * payV = NULL;
236233
cson_object * pay = NULL;
237234
const char *zMime;
238235
Blob content = empty_blob;
239236
Stmt q = empty_Stmt;
240237
cson_array * checkin_arr = NULL;
@@ -249,12 +246,11 @@
249246
json_set_err(FSL_JSON_E_DENIED,
250247
"Requires 'o' privileges.");
251248
return NULL;
252249
}
253250
254
- payV = cson_value_new_object();
255
- pay = cson_value_get_object(payV);
251
+ pay = cson_new_object();
256252
257253
content_get(rid, &content);
258254
cson_object_set(pay, "contentLength",
259255
json_new_int( blob_size(&content) )
260256
/* achtung: overflow potential on 32-bit builds! */);
@@ -311,36 +307,32 @@
311307
}
312308
#else
313309
json_stmt_to_array_of_obj( &q, checkin_arr );
314310
#endif
315311
db_finalize(&q);
316
- return payV;
312
+ return cson_object_value(pay);
317313
}
318314
319315
/*
320316
** Impl of /json/artifact. This basically just determines the type of
321317
** an artifact and forwards the real work to another function.
322318
*/
323319
cson_value * json_page_artifact(){
324
- cson_value * payV = NULL;
325320
cson_object * pay = NULL;
326321
char const * zName = NULL;
327322
char const * zType = NULL;
328323
char const * zUuid = NULL;
329324
cson_value * entry = NULL;
330325
Blob uuid = empty_blob;
331326
int rc;
332327
int rid = 0;
333328
ArtifactDispatchEntry const * dispatcher = &ArtifactDispatchList[0];
334
- zName = json_find_option_cstr("uuid",NULL,"u");
335
- if(!zName||!*zName){
336
- zName = json_command_arg(g.json.dispatchDepth+1);
337
- if(!zName || !*zName) {
338
- json_set_err(FSL_JSON_E_MISSING_ARGS,
339
- "Missing 'uuid' argument.");
340
- return NULL;
341
- }
329
+ zName = json_find_option_cstr2("uuid", NULL, NULL, 2);
330
+ if(!zName || !*zName) {
331
+ json_set_err(FSL_JSON_E_MISSING_ARGS,
332
+ "Missing 'uuid' argument.");
333
+ return NULL;
342334
}
343335
344336
if( validate16(zName, strlen(zName)) ){
345337
if( db_exists("SELECT 1 FROM ticket WHERE tkt_uuid GLOB '%q*'", zName) ){
346338
zType = "ticket";
@@ -403,22 +395,19 @@
403395
}
404396
}
405397
if(!g.json.resultCode){
406398
assert( NULL != entry );
407399
assert( NULL != zType );
408
- payV = cson_value_new_object();
409
- pay = cson_value_get_object(payV);
400
+ pay = cson_new_object();
410401
cson_object_set( pay, "type", json_new_string(zType) );
411402
/*cson_object_set( pay, "uuid", json_new_string(zUuid) );*/
412403
cson_object_set( pay, "name", json_new_string(zName ? zName : zUuid) );
413404
cson_object_set( pay, "rid", cson_value_new_integer(rid) );
414405
if(entry){
415406
cson_object_set(pay, "artifact", entry);
416407
}
417
- }else{
418
- assert((NULL == entry) && "Internal misuse - callback must return NULL on error.");
419408
}
420409
veryend:
421410
blob_reset(&uuid);
422
- return payV;
411
+ return cson_object_value(pay);
423412
}
424413
425414
--- src/json_artifact.c
+++ src/json_artifact.c
@@ -158,11 +158,10 @@
158
159 /*
160 ** Very incomplete/incorrect impl of /json/artifact/TICKET_ID.
161 */
162 cson_value * json_artifact_ticket( int rid ){
163 cson_value * payV = NULL;
164 cson_object * pay = NULL;
165 Manifest *pTktChng = NULL;
166 static cson_value * eventTypeLabel = NULL;
167 if(! g.perm.RdTkt ){
168 g.json.resultCode = FSL_JSON_E_DENIED;
@@ -176,18 +175,17 @@
176 pTktChng = manifest_get(rid, CFTYPE_TICKET);
177 if( pTktChng==0 ){
178 g.json.resultCode = FSL_JSON_E_MANIFEST_READ_FAILED;
179 return NULL;
180 }
181 payV = cson_value_new_object();
182 pay = cson_value_get_object(payV);
183 cson_object_set(pay, "eventType", eventTypeLabel );
184 cson_object_set(pay, "uuid", json_new_string(pTktChng->zTicketUuid));
185 cson_object_set(pay, "user", json_new_string(pTktChng->zUser));
186 cson_object_set(pay, "timestamp", json_julian_to_timestamp(pTktChng->rDate));
187 manifest_destroy(pTktChng);
188 return payV;
189 }
190
191 /*
192 ** Sub-impl of /json/artifact for checkins.
193 */
@@ -230,11 +228,10 @@
230 return json_get_wiki_page_by_rid(rid, 0);
231 }
232 }
233
234 cson_value * json_artifact_file(int rid){
235 cson_value * payV = NULL;
236 cson_object * pay = NULL;
237 const char *zMime;
238 Blob content = empty_blob;
239 Stmt q = empty_Stmt;
240 cson_array * checkin_arr = NULL;
@@ -249,12 +246,11 @@
249 json_set_err(FSL_JSON_E_DENIED,
250 "Requires 'o' privileges.");
251 return NULL;
252 }
253
254 payV = cson_value_new_object();
255 pay = cson_value_get_object(payV);
256
257 content_get(rid, &content);
258 cson_object_set(pay, "contentLength",
259 json_new_int( blob_size(&content) )
260 /* achtung: overflow potential on 32-bit builds! */);
@@ -311,36 +307,32 @@
311 }
312 #else
313 json_stmt_to_array_of_obj( &q, checkin_arr );
314 #endif
315 db_finalize(&q);
316 return payV;
317 }
318
319 /*
320 ** Impl of /json/artifact. This basically just determines the type of
321 ** an artifact and forwards the real work to another function.
322 */
323 cson_value * json_page_artifact(){
324 cson_value * payV = NULL;
325 cson_object * pay = NULL;
326 char const * zName = NULL;
327 char const * zType = NULL;
328 char const * zUuid = NULL;
329 cson_value * entry = NULL;
330 Blob uuid = empty_blob;
331 int rc;
332 int rid = 0;
333 ArtifactDispatchEntry const * dispatcher = &ArtifactDispatchList[0];
334 zName = json_find_option_cstr("uuid",NULL,"u");
335 if(!zName||!*zName){
336 zName = json_command_arg(g.json.dispatchDepth+1);
337 if(!zName || !*zName) {
338 json_set_err(FSL_JSON_E_MISSING_ARGS,
339 "Missing 'uuid' argument.");
340 return NULL;
341 }
342 }
343
344 if( validate16(zName, strlen(zName)) ){
345 if( db_exists("SELECT 1 FROM ticket WHERE tkt_uuid GLOB '%q*'", zName) ){
346 zType = "ticket";
@@ -403,22 +395,19 @@
403 }
404 }
405 if(!g.json.resultCode){
406 assert( NULL != entry );
407 assert( NULL != zType );
408 payV = cson_value_new_object();
409 pay = cson_value_get_object(payV);
410 cson_object_set( pay, "type", json_new_string(zType) );
411 /*cson_object_set( pay, "uuid", json_new_string(zUuid) );*/
412 cson_object_set( pay, "name", json_new_string(zName ? zName : zUuid) );
413 cson_object_set( pay, "rid", cson_value_new_integer(rid) );
414 if(entry){
415 cson_object_set(pay, "artifact", entry);
416 }
417 }else{
418 assert((NULL == entry) && "Internal misuse - callback must return NULL on error.");
419 }
420 veryend:
421 blob_reset(&uuid);
422 return payV;
423 }
424
425
--- src/json_artifact.c
+++ src/json_artifact.c
@@ -158,11 +158,10 @@
158
159 /*
160 ** Very incomplete/incorrect impl of /json/artifact/TICKET_ID.
161 */
162 cson_value * json_artifact_ticket( int rid ){
 
163 cson_object * pay = NULL;
164 Manifest *pTktChng = NULL;
165 static cson_value * eventTypeLabel = NULL;
166 if(! g.perm.RdTkt ){
167 g.json.resultCode = FSL_JSON_E_DENIED;
@@ -176,18 +175,17 @@
175 pTktChng = manifest_get(rid, CFTYPE_TICKET);
176 if( pTktChng==0 ){
177 g.json.resultCode = FSL_JSON_E_MANIFEST_READ_FAILED;
178 return NULL;
179 }
180 pay = cson_new_object();
 
181 cson_object_set(pay, "eventType", eventTypeLabel );
182 cson_object_set(pay, "uuid", json_new_string(pTktChng->zTicketUuid));
183 cson_object_set(pay, "user", json_new_string(pTktChng->zUser));
184 cson_object_set(pay, "timestamp", json_julian_to_timestamp(pTktChng->rDate));
185 manifest_destroy(pTktChng);
186 return cson_object_value(pay);
187 }
188
189 /*
190 ** Sub-impl of /json/artifact for checkins.
191 */
@@ -230,11 +228,10 @@
228 return json_get_wiki_page_by_rid(rid, 0);
229 }
230 }
231
232 cson_value * json_artifact_file(int rid){
 
233 cson_object * pay = NULL;
234 const char *zMime;
235 Blob content = empty_blob;
236 Stmt q = empty_Stmt;
237 cson_array * checkin_arr = NULL;
@@ -249,12 +246,11 @@
246 json_set_err(FSL_JSON_E_DENIED,
247 "Requires 'o' privileges.");
248 return NULL;
249 }
250
251 pay = cson_new_object();
 
252
253 content_get(rid, &content);
254 cson_object_set(pay, "contentLength",
255 json_new_int( blob_size(&content) )
256 /* achtung: overflow potential on 32-bit builds! */);
@@ -311,36 +307,32 @@
307 }
308 #else
309 json_stmt_to_array_of_obj( &q, checkin_arr );
310 #endif
311 db_finalize(&q);
312 return cson_object_value(pay);
313 }
314
315 /*
316 ** Impl of /json/artifact. This basically just determines the type of
317 ** an artifact and forwards the real work to another function.
318 */
319 cson_value * json_page_artifact(){
 
320 cson_object * pay = NULL;
321 char const * zName = NULL;
322 char const * zType = NULL;
323 char const * zUuid = NULL;
324 cson_value * entry = NULL;
325 Blob uuid = empty_blob;
326 int rc;
327 int rid = 0;
328 ArtifactDispatchEntry const * dispatcher = &ArtifactDispatchList[0];
329 zName = json_find_option_cstr2("uuid", NULL, NULL, 2);
330 if(!zName || !*zName) {
331 json_set_err(FSL_JSON_E_MISSING_ARGS,
332 "Missing 'uuid' argument.");
333 return NULL;
 
 
 
334 }
335
336 if( validate16(zName, strlen(zName)) ){
337 if( db_exists("SELECT 1 FROM ticket WHERE tkt_uuid GLOB '%q*'", zName) ){
338 zType = "ticket";
@@ -403,22 +395,19 @@
395 }
396 }
397 if(!g.json.resultCode){
398 assert( NULL != entry );
399 assert( NULL != zType );
400 pay = cson_new_object();
 
401 cson_object_set( pay, "type", json_new_string(zType) );
402 /*cson_object_set( pay, "uuid", json_new_string(zUuid) );*/
403 cson_object_set( pay, "name", json_new_string(zName ? zName : zUuid) );
404 cson_object_set( pay, "rid", cson_value_new_integer(rid) );
405 if(entry){
406 cson_object_set(pay, "artifact", entry);
407 }
 
 
408 }
409 veryend:
410 blob_reset(&uuid);
411 return cson_object_value(pay);
412 }
413
414

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button