Fossil

Diff
Login

Differences From Artifact [4f1d62a6df]:

To Artifact [a30a936e98]:


156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
  return v;
}

/*
** Very incomplete/incorrect impl of /json/artifact/TICKET_ID.
*/
cson_value * json_artifact_ticket( int rid ){
  cson_value * payV = NULL;
  cson_object * pay = NULL;
  Manifest *pTktChng = NULL;
  static cson_value * eventTypeLabel = NULL;
  if(! g.perm.RdTkt ){
    g.json.resultCode = FSL_JSON_E_DENIED;
    return NULL;
  }
  if(!eventTypeLabel){
    eventTypeLabel = json_new_string("ticket");
    json_gc_add("$EVENT_TYPE_LABEL(ticket)", eventTypeLabel);
  }

  pTktChng = manifest_get(rid, CFTYPE_TICKET);
  if( pTktChng==0 ){
    g.json.resultCode = FSL_JSON_E_MANIFEST_READ_FAILED;
    return NULL;
  }
  payV = cson_value_new_object();
  pay = cson_value_get_object(payV);
  cson_object_set(pay, "eventType", eventTypeLabel );
  cson_object_set(pay, "uuid", json_new_string(pTktChng->zTicketUuid));
  cson_object_set(pay, "user", json_new_string(pTktChng->zUser));
  cson_object_set(pay, "timestamp", json_julian_to_timestamp(pTktChng->rDate));
  manifest_destroy(pTktChng);
  return payV;
}

/*
** Sub-impl of /json/artifact for checkins.
*/
static cson_value * json_artifact_ci( int rid ){
  if(! g.perm.Read ){







<

















|
<





|







156
157
158
159
160
161
162

163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180

181
182
183
184
185
186
187
188
189
190
191
192
193
  return v;
}

/*
** Very incomplete/incorrect impl of /json/artifact/TICKET_ID.
*/
cson_value * json_artifact_ticket( int rid ){

  cson_object * pay = NULL;
  Manifest *pTktChng = NULL;
  static cson_value * eventTypeLabel = NULL;
  if(! g.perm.RdTkt ){
    g.json.resultCode = FSL_JSON_E_DENIED;
    return NULL;
  }
  if(!eventTypeLabel){
    eventTypeLabel = json_new_string("ticket");
    json_gc_add("$EVENT_TYPE_LABEL(ticket)", eventTypeLabel);
  }

  pTktChng = manifest_get(rid, CFTYPE_TICKET);
  if( pTktChng==0 ){
    g.json.resultCode = FSL_JSON_E_MANIFEST_READ_FAILED;
    return NULL;
  }
  pay = cson_new_object();

  cson_object_set(pay, "eventType", eventTypeLabel );
  cson_object_set(pay, "uuid", json_new_string(pTktChng->zTicketUuid));
  cson_object_set(pay, "user", json_new_string(pTktChng->zUser));
  cson_object_set(pay, "timestamp", json_julian_to_timestamp(pTktChng->rDate));
  manifest_destroy(pTktChng);
  return cson_object_value(pay);
}

/*
** Sub-impl of /json/artifact for checkins.
*/
static cson_value * json_artifact_ci( int rid ){
  if(! g.perm.Read ){
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
    return NULL;
  }else{
    return json_get_wiki_page_by_rid(rid, 0);
  }
}

cson_value * json_artifact_file(int rid){
  cson_value * payV = NULL;
  cson_object * pay = NULL;
  const char *zMime;
  Blob content = empty_blob;
  Stmt q = empty_Stmt;
  cson_array * checkin_arr = NULL;
#if 0
    /*see next #if block below*/
      cson_string * tagKey = NULL;
      cson_value * checkinV = NULL;
      cson_object * checkin = NULL;
#endif

  if( ! g.perm.Read ){
    json_set_err(FSL_JSON_E_DENIED,
                 "Requires 'o' privileges.");
    return NULL;
  }
  
  payV = cson_value_new_object();
  pay = cson_value_get_object(payV);

  content_get(rid, &content);
  cson_object_set(pay, "contentLength",
                  json_new_int( blob_size(&content) )
                  /* achtung: overflow potential on 32-bit builds! */);
  zMime = mimetype_from_content(&content);








<


















|
<







226
227
228
229
230
231
232

233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251

252
253
254
255
256
257
258
    return NULL;
  }else{
    return json_get_wiki_page_by_rid(rid, 0);
  }
}

cson_value * json_artifact_file(int rid){

  cson_object * pay = NULL;
  const char *zMime;
  Blob content = empty_blob;
  Stmt q = empty_Stmt;
  cson_array * checkin_arr = NULL;
#if 0
    /*see next #if block below*/
      cson_string * tagKey = NULL;
      cson_value * checkinV = NULL;
      cson_object * checkin = NULL;
#endif

  if( ! g.perm.Read ){
    json_set_err(FSL_JSON_E_DENIED,
                 "Requires 'o' privileges.");
    return NULL;
  }
  
  pay = cson_new_object();


  content_get(rid, &content);
  cson_object_set(pay, "contentLength",
                  json_new_int( blob_size(&content) )
                  /* achtung: overflow potential on 32-bit builds! */);
  zMime = mimetype_from_content(&content);

309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
    cson_object_set_s(checkin, tagKey, json_tags_for_rid(rid,0));
    cson_array_append( checkin_arr, checkinV );
  }   
#else
  json_stmt_to_array_of_obj( &q, checkin_arr );
#endif
  db_finalize(&q);
  return payV;
}

/*
** Impl of /json/artifact. This basically just determines the type of
** an artifact and forwards the real work to another function.
*/
cson_value * json_page_artifact(){
  cson_value * payV = NULL;
  cson_object * pay = NULL;
  char const * zName = NULL;
  char const * zType = NULL;
  char const * zUuid = NULL;
  cson_value * entry = NULL;
  Blob uuid = empty_blob;
  int rc;
  int rid = 0;
  ArtifactDispatchEntry const * dispatcher = &ArtifactDispatchList[0];
  zName = json_find_option_cstr("uuid",NULL,"u");
  if(!zName||!*zName){
    zName = json_command_arg(g.json.dispatchDepth+1);
    if(!zName || !*zName) {
      json_set_err(FSL_JSON_E_MISSING_ARGS,
                   "Missing 'uuid' argument.");
      return NULL;
    }
  }

  if( validate16(zName, strlen(zName)) ){
    if( db_exists("SELECT 1 FROM ticket WHERE tkt_uuid GLOB '%q*'", zName) ){
      zType = "ticket";
      goto handle_entry;
    }







|







<









|
<
<
|
|
|
|
<







305
306
307
308
309
310
311
312
313
314
315
316
317
318
319

320
321
322
323
324
325
326
327
328
329


330
331
332
333

334
335
336
337
338
339
340
    cson_object_set_s(checkin, tagKey, json_tags_for_rid(rid,0));
    cson_array_append( checkin_arr, checkinV );
  }   
#else
  json_stmt_to_array_of_obj( &q, checkin_arr );
#endif
  db_finalize(&q);
  return cson_object_value(pay);
}

/*
** Impl of /json/artifact. This basically just determines the type of
** an artifact and forwards the real work to another function.
*/
cson_value * json_page_artifact(){

  cson_object * pay = NULL;
  char const * zName = NULL;
  char const * zType = NULL;
  char const * zUuid = NULL;
  cson_value * entry = NULL;
  Blob uuid = empty_blob;
  int rc;
  int rid = 0;
  ArtifactDispatchEntry const * dispatcher = &ArtifactDispatchList[0];
  zName = json_find_option_cstr2("uuid", NULL, NULL, 2);


  if(!zName || !*zName) {
    json_set_err(FSL_JSON_E_MISSING_ARGS,
                 "Missing 'uuid' argument.");
    return NULL;

  }

  if( validate16(zName, strlen(zName)) ){
    if( db_exists("SELECT 1 FROM ticket WHERE tkt_uuid GLOB '%q*'", zName) ){
      zType = "ticket";
      goto handle_entry;
    }
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
      entry = (*dispatcher->func)(rid);
      break;
    }
  }
  if(!g.json.resultCode){
    assert( NULL != entry );
    assert( NULL != zType );
    payV = cson_value_new_object();
    pay = cson_value_get_object(payV);
    cson_object_set( pay, "type", json_new_string(zType) );
    /*cson_object_set( pay, "uuid", json_new_string(zUuid) );*/
    cson_object_set( pay, "name", json_new_string(zName ? zName : zUuid) );
    cson_object_set( pay, "rid", cson_value_new_integer(rid) );
    if(entry){
      cson_object_set(pay, "artifact", entry);
    }
  }else{
    assert((NULL == entry) && "Internal misuse - callback must return NULL on error.");
  }
  veryend:
  blob_reset(&uuid);
  return payV;
}








|
<







<
<



|


393
394
395
396
397
398
399
400

401
402
403
404
405
406
407


408
409
410
411
412
413
      entry = (*dispatcher->func)(rid);
      break;
    }
  }
  if(!g.json.resultCode){
    assert( NULL != entry );
    assert( NULL != zType );
    pay = cson_new_object();

    cson_object_set( pay, "type", json_new_string(zType) );
    /*cson_object_set( pay, "uuid", json_new_string(zUuid) );*/
    cson_object_set( pay, "name", json_new_string(zName ? zName : zUuid) );
    cson_object_set( pay, "rid", cson_value_new_integer(rid) );
    if(entry){
      cson_object_set(pay, "artifact", entry);
    }


  }
  veryend:
  blob_reset(&uuid);
  return cson_object_value(pay);
}