Fossil SCM
minor code simplifications.
Commit
400fe340c25f191b8f24c54ec9d92ec8f9a4b149
Parent
f56681147746312…
1 file changed
+11
-22
+11
-22
| --- src/json_artifact.c | ||
| +++ src/json_artifact.c | ||
| @@ -158,11 +158,10 @@ | ||
| 158 | 158 | |
| 159 | 159 | /* |
| 160 | 160 | ** Very incomplete/incorrect impl of /json/artifact/TICKET_ID. |
| 161 | 161 | */ |
| 162 | 162 | cson_value * json_artifact_ticket( int rid ){ |
| 163 | - cson_value * payV = NULL; | |
| 164 | 163 | cson_object * pay = NULL; |
| 165 | 164 | Manifest *pTktChng = NULL; |
| 166 | 165 | static cson_value * eventTypeLabel = NULL; |
| 167 | 166 | if(! g.perm.RdTkt ){ |
| 168 | 167 | g.json.resultCode = FSL_JSON_E_DENIED; |
| @@ -176,18 +175,17 @@ | ||
| 176 | 175 | pTktChng = manifest_get(rid, CFTYPE_TICKET); |
| 177 | 176 | if( pTktChng==0 ){ |
| 178 | 177 | g.json.resultCode = FSL_JSON_E_MANIFEST_READ_FAILED; |
| 179 | 178 | return NULL; |
| 180 | 179 | } |
| 181 | - payV = cson_value_new_object(); | |
| 182 | - pay = cson_value_get_object(payV); | |
| 180 | + pay = cson_new_object(); | |
| 183 | 181 | cson_object_set(pay, "eventType", eventTypeLabel ); |
| 184 | 182 | cson_object_set(pay, "uuid", json_new_string(pTktChng->zTicketUuid)); |
| 185 | 183 | cson_object_set(pay, "user", json_new_string(pTktChng->zUser)); |
| 186 | 184 | cson_object_set(pay, "timestamp", json_julian_to_timestamp(pTktChng->rDate)); |
| 187 | 185 | manifest_destroy(pTktChng); |
| 188 | - return payV; | |
| 186 | + return cson_object_value(pay); | |
| 189 | 187 | } |
| 190 | 188 | |
| 191 | 189 | /* |
| 192 | 190 | ** Sub-impl of /json/artifact for checkins. |
| 193 | 191 | */ |
| @@ -230,11 +228,10 @@ | ||
| 230 | 228 | return json_get_wiki_page_by_rid(rid, 0); |
| 231 | 229 | } |
| 232 | 230 | } |
| 233 | 231 | |
| 234 | 232 | cson_value * json_artifact_file(int rid){ |
| 235 | - cson_value * payV = NULL; | |
| 236 | 233 | cson_object * pay = NULL; |
| 237 | 234 | const char *zMime; |
| 238 | 235 | Blob content = empty_blob; |
| 239 | 236 | Stmt q = empty_Stmt; |
| 240 | 237 | cson_array * checkin_arr = NULL; |
| @@ -249,12 +246,11 @@ | ||
| 249 | 246 | json_set_err(FSL_JSON_E_DENIED, |
| 250 | 247 | "Requires 'o' privileges."); |
| 251 | 248 | return NULL; |
| 252 | 249 | } |
| 253 | 250 | |
| 254 | - payV = cson_value_new_object(); | |
| 255 | - pay = cson_value_get_object(payV); | |
| 251 | + pay = cson_new_object(); | |
| 256 | 252 | |
| 257 | 253 | content_get(rid, &content); |
| 258 | 254 | cson_object_set(pay, "contentLength", |
| 259 | 255 | json_new_int( blob_size(&content) ) |
| 260 | 256 | /* achtung: overflow potential on 32-bit builds! */); |
| @@ -311,36 +307,32 @@ | ||
| 311 | 307 | } |
| 312 | 308 | #else |
| 313 | 309 | json_stmt_to_array_of_obj( &q, checkin_arr ); |
| 314 | 310 | #endif |
| 315 | 311 | db_finalize(&q); |
| 316 | - return payV; | |
| 312 | + return cson_object_value(pay); | |
| 317 | 313 | } |
| 318 | 314 | |
| 319 | 315 | /* |
| 320 | 316 | ** Impl of /json/artifact. This basically just determines the type of |
| 321 | 317 | ** an artifact and forwards the real work to another function. |
| 322 | 318 | */ |
| 323 | 319 | cson_value * json_page_artifact(){ |
| 324 | - cson_value * payV = NULL; | |
| 325 | 320 | cson_object * pay = NULL; |
| 326 | 321 | char const * zName = NULL; |
| 327 | 322 | char const * zType = NULL; |
| 328 | 323 | char const * zUuid = NULL; |
| 329 | 324 | cson_value * entry = NULL; |
| 330 | 325 | Blob uuid = empty_blob; |
| 331 | 326 | int rc; |
| 332 | 327 | int rid = 0; |
| 333 | 328 | 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; | |
| 342 | 334 | } |
| 343 | 335 | |
| 344 | 336 | if( validate16(zName, strlen(zName)) ){ |
| 345 | 337 | if( db_exists("SELECT 1 FROM ticket WHERE tkt_uuid GLOB '%q*'", zName) ){ |
| 346 | 338 | zType = "ticket"; |
| @@ -403,22 +395,19 @@ | ||
| 403 | 395 | } |
| 404 | 396 | } |
| 405 | 397 | if(!g.json.resultCode){ |
| 406 | 398 | assert( NULL != entry ); |
| 407 | 399 | assert( NULL != zType ); |
| 408 | - payV = cson_value_new_object(); | |
| 409 | - pay = cson_value_get_object(payV); | |
| 400 | + pay = cson_new_object(); | |
| 410 | 401 | cson_object_set( pay, "type", json_new_string(zType) ); |
| 411 | 402 | /*cson_object_set( pay, "uuid", json_new_string(zUuid) );*/ |
| 412 | 403 | cson_object_set( pay, "name", json_new_string(zName ? zName : zUuid) ); |
| 413 | 404 | cson_object_set( pay, "rid", cson_value_new_integer(rid) ); |
| 414 | 405 | if(entry){ |
| 415 | 406 | cson_object_set(pay, "artifact", entry); |
| 416 | 407 | } |
| 417 | - }else{ | |
| 418 | - assert((NULL == entry) && "Internal misuse - callback must return NULL on error."); | |
| 419 | 408 | } |
| 420 | 409 | veryend: |
| 421 | 410 | blob_reset(&uuid); |
| 422 | - return payV; | |
| 411 | + return cson_object_value(pay); | |
| 423 | 412 | } |
| 424 | 413 | |
| 425 | 414 |
| --- 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 |