Fossil

Check-in [3d1d139a]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:add support for fetching text file content and checkin history via /artifact json request
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | json-multitag-test | json
Files: files | file ages | folders
SHA1:3d1d139a7a0f9519d4e67086c9cc8daf7b46e32d
User & Date: zach 2011-10-18 13:06:32
Context
2011-10-19
14:56
removed a superfluous call to json_set_err() which "overwrote" the previously set error. check-in: 16155447 user: stephan tags: json-multitag-test, json
2011-10-18
13:06
add support for fetching text file content and checkin history via /artifact json request check-in: 3d1d139a user: zach tags: json-multitag-test, json
2011-10-17
18:03
Removed some dead code. Experimentally enabled jQuery ajax back-end to test a problem on my 3DS. check-in: ebb0c047 user: stephan tags: json-multitag-test, json
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/json_artifact.c.

201
202
203
204
205
206
207

208
209
210
211
212
213




























































































214
215
216
217
218
219
220
...
258
259
260
261
262
263
264

265
266
267
268
269
270
271
272
273
274
275
276



277
278
279
280
281
282
283
}

/*
** Internal mapping of /json/artifact/FOO commands/callbacks.
*/
static ArtifactDispatchEntry ArtifactDispatchList[] = {
{"checkin", json_artifact_ci},

{"tag", NULL},
{"ticket", json_artifact_ticket},
{"wiki", NULL},
/* Final entry MUST have a NULL name. */
{NULL,NULL}
};





























































































/*
** 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;
................................................................................
  }
  zUuid = blob_str(&uuid);
  rid = db_int(0, "SELECT rid FROM blob WHERE uuid='%s'", zUuid);
  if(0==rid){
    g.json.resultCode = FSL_JSON_E_RESOURCE_NOT_FOUND;
    goto error;
  }

  if( db_exists("SELECT 1 FROM mlink WHERE mid=%d", rid)
      || db_exists("SELECT 1 FROM plink WHERE cid=%d", rid)
      || db_exists("SELECT 1 FROM plink WHERE pid=%d", rid)){
    zType = "checkin";
    goto handle_entry;
  }else if( db_exists("SELECT 1 FROM tagxref JOIN tag USING(tagid)"
                      " WHERE rid=%d AND tagname LIKE 'wiki-%%'", rid) ){
    zType = "wiki";
    goto handle_entry;
  }else if( db_exists("SELECT 1 FROM tagxref JOIN tag USING(tagid)"
                      " WHERE rid=%d AND tagname LIKE 'tkt-%%'", rid) ){
    zType = "ticket";



    goto handle_entry;
  }else{
    g.json.resultCode = FSL_JSON_E_RESOURCE_NOT_FOUND;
    goto error;
  }

  error:







>


|



>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







>












>
>
>







201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
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
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
...
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
}

/*
** Internal mapping of /json/artifact/FOO commands/callbacks.
*/
static ArtifactDispatchEntry ArtifactDispatchList[] = {
{"checkin", json_artifact_ci},
{"file", json_artifact_file},
{"tag", NULL},
{"ticket", json_artifact_ticket},
{"wiki", json_artifact_wiki},
/* Final entry MUST have a NULL name. */
{NULL,NULL}
};

cson_value * json_artifact_wiki(int rid){
  Manifest *pWiki = 0;
  char *zBody = NULL;
  char const *zPageName = NULL;
  cson_value * payV = NULL;
  cson_object * pay = NULL;

  payV = cson_value_new_object();
  pay = cson_value_get_object(payV);

  zPageName = db_text(0, "SELECT tagname FROM tag"
                         " WHERE tagid=(SELECT tagid FROM tagxref WHERE rid=%d)", rid);

  pWiki = manifest_get(rid, CFTYPE_WIKI);
  if( pWiki ){
    zBody = pWiki->zWiki;
  }

  cson_object_set(pay, "name", json_new_string(zPageName));
  cson_object_set(pay, "body", json_new_string(zBody));
  return payV;
}

cson_value * json_artifact_file(int rid){
  cson_value * payV = NULL;
  cson_object * pay = NULL;
  const char *zMime;
  const char *zRaw;
  Blob content;
  Stmt q;

  payV = cson_value_new_object();
  pay = cson_value_get_object(payV);

  content_get(rid, &content);
  zMime = mimetype_from_content(&content);

  if (!zMime){
    cson_array * checkin_arr = NULL;
    cson_value * checkin_list = NULL;

    cson_value * checkinV = NULL;
    cson_object * checkin = NULL;

    zRaw = blob_str(&content);
    checkin_list = cson_value_new_array(); 

    cson_object_set(pay, "content", json_new_string(zRaw));
    cson_object_set(pay, "checkins", checkin_list);

    checkin_arr = cson_value_get_array(checkin_list);

    db_prepare(&q,
      "SELECT filename.name, datetime(event.mtime),"
      "       coalesce(event.ecomment,event.comment),"
      "       coalesce(event.euser,event.user),"
      "       b.uuid, mlink.mperm,"
      "       coalesce((SELECT value FROM tagxref"
                      "  WHERE tagid=%d AND tagtype>0 AND rid=mlink.mid),'trunk')"
      "  FROM mlink, filename, event, blob a, blob b"
      " WHERE filename.fnid=mlink.fnid"
      "   AND event.objid=mlink.mid"
      "   AND a.rid=mlink.fid"
      "   AND b.rid=mlink.mid"
      "   AND mlink.fid=%d"
      "   ORDER BY filename.name, event.mtime",
      TAG_BRANCH, rid
    );

    while( db_step(&q)==SQLITE_ROW ){
      const char *zName = db_column_text(&q, 0);
      const char *zDate = db_column_text(&q, 1);
      const char *zCom = db_column_text(&q, 2);
      const char *zUser = db_column_text(&q, 3);
      const char *zVers = db_column_text(&q, 4);

      checkinV = cson_value_new_object();
      checkin = cson_value_get_object(checkinV);

      cson_object_set(checkin, "name", json_new_string(zName));
      cson_object_set(checkin, "date", json_new_string(zDate));
      cson_object_set(checkin, "comment", json_new_string(zCom));
      cson_object_set(checkin, "user", json_new_string(zUser));
      cson_object_set(checkin, "version", json_new_string(zVers));

      cson_array_append(checkin_arr, checkinV);
    }
    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;
................................................................................
  }
  zUuid = blob_str(&uuid);
  rid = db_int(0, "SELECT rid FROM blob WHERE uuid='%s'", zUuid);
  if(0==rid){
    g.json.resultCode = FSL_JSON_E_RESOURCE_NOT_FOUND;
    goto error;
  }

  if( db_exists("SELECT 1 FROM mlink WHERE mid=%d", rid)
      || db_exists("SELECT 1 FROM plink WHERE cid=%d", rid)
      || db_exists("SELECT 1 FROM plink WHERE pid=%d", rid)){
    zType = "checkin";
    goto handle_entry;
  }else if( db_exists("SELECT 1 FROM tagxref JOIN tag USING(tagid)"
                      " WHERE rid=%d AND tagname LIKE 'wiki-%%'", rid) ){
    zType = "wiki";
    goto handle_entry;
  }else if( db_exists("SELECT 1 FROM tagxref JOIN tag USING(tagid)"
                      " WHERE rid=%d AND tagname LIKE 'tkt-%%'", rid) ){
    zType = "ticket";
    goto handle_entry;
  }else if ( db_exists("SELECT 1 FROM mlink WHERE fid = %d", rid) ){
    zType = "file";
    goto handle_entry;
  }else{
    g.json.resultCode = FSL_JSON_E_RESOURCE_NOT_FOUND;
    goto error;
  }

  error: