Fossil

Check-in [a893fff3]
Login

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

Overview
Comment:Started adding artifact-type-dependent result data to /json/artifact output.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | json-multitag-test | json
Files: files | file ages | folders
SHA1:a893fff3ca2fb9f0cbc3bd80674939d3e41ad5a1
User & Date: stephan 2011-10-01 05:58:53
Context
2011-10-01
06:45
Started refactoring some of the timeline/artifact components into reusable parts. Comment edited only to test json responses which differentiate between pristine and edited commits. check-in: b1f92572 user: stephan tags: json-multitag-test, json
05:58
Started adding artifact-type-dependent result data to /json/artifact output. check-in: a893fff3 user: stephan tags: json-multitag-test, json
05:58
minor cleanups. check-in: 6ee6486e user: stephan tags: json
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/json_artifact.c.

2
3
4
5
6
7
8




























































































































9
10
11
12
13
14
15
..
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
..
76
77
78
79
80
81
82








83







84
85
86
87
88
#include "config.h"
#include "json_artifact.h"

#if INTERFACE
#include "json_detail.h"
#endif





























































































































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;
  Blob uuid = empty_blob;
................................................................................
  if(1==rc){
    g.json.resultCode = FSL_JSON_E_RESOURCE_NOT_FOUND;
    goto error;
  }else if(2==rc){
    g.json.resultCode = FSL_JSON_E_AMBIGUOUS_UUID;
    goto error;
  }
  zName = blob_str(&uuid);
  rid = db_int(0, "SELECT rid FROM blob WHERE uuid='%s'", zName);
  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)
................................................................................
  end_ok:
  payV = cson_value_new_object();
  pay = cson_value_get_object(payV);
  assert( NULL != zType );
  cson_object_set( pay, "type", json_new_string(zType) );
  cson_object_set( pay, "id", json_new_string(zName) );
  cson_object_set( pay, "rid", cson_value_new_integer(rid) );
















  veryend:
  blob_reset(&uuid);
  return payV;
}








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







 







|







 







>
>
>
>
>
>
>
>
|
>
>
>
>
>
>
>





2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
...
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
...
200
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
#include "config.h"
#include "json_artifact.h"

#if INTERFACE
#include "json_detail.h"
#endif

/*
** Internal callback for /json/artifact handlers. rid and uid refer to
** the rid/uid of a given type of artifact, and each callback is
** specialized to return a JSON form of one type of artifact.
*/
typedef cson_value * (*artifact_f)( int rid, char const * uid );

typedef struct ArtifactDispatchEntry {
  /**
     Artifact type name, e.g. "checkin".
   */
  char const * name;
  /**
     JSON construction callback.
   */
  artifact_f func;
  /**
     Must return true if g.perm has the proper permissions to fetch
     this info, else false. If it returns false, func() is skipped
     (producing no extra payload output).
   */
  char (*permCheck)();
} ArtifactDispatchEntry;


/*
** Generates an artifact Object for the given rid/zUuid. rid
** must refer to a Checkin.
**
**
** TODO: consolidate the result structure (and its generation) with
** /json/timeline/ci.
*/
static cson_value * json_artifact_ci( int rid, char const * zUuid ){
  cson_value * v = cson_value_new_object();
  cson_object * o = cson_value_get_object(v);
  char const * zParent = NULL;
  Stmt q;
  assert( NULL != zUuid );
  cson_object_set(o,"isLeaf", cson_value_new_bool(is_a_leaf(rid)));
  zParent = db_text(0,
    "SELECT uuid FROM plink, blob"
    " WHERE plink.cid=%d AND blob.rid=plink.pid AND plink.isprim",
    rid
  );

  db_prepare(&q, 
             "SELECT uuid, mtime, user, comment,"
             "       omtime"
             "  FROM blob, event"
             " WHERE blob.rid=%d"
             "   AND event.objid=%d",
             rid, rid
             );
  if( db_step(&q)==SQLITE_ROW ){
    /*const char *zUuid = db_column_text(&q, 0);*/
    char * zTmp;
    const char *zUser;
    const char *zComment;
    char * zEUser, * zEComment;
    int mtime, omtime;
    cson_value * fileList = NULL;
#define SET(K,V) cson_object_set(o,(K), (V))
    SET("uuid",json_new_string(zUuid));
    zUser = db_column_text(&q,2);
    SET("user",json_new_string(zUser));
    zEUser = db_text(0,
                   "SELECT value FROM tagxref WHERE tagid=%d AND rid=%d",
                   TAG_USER, rid);
    if(zEUser){
      SET("editedBy", json_new_string(zEUser));
      free(zEUser);
    }

    zComment = db_column_text(&q,3);
    SET("comment",json_new_string(zComment));
    zEComment = db_text(0, 
                   "SELECT value FROM tagxref WHERE tagid=%d AND rid=%d",
                   TAG_COMMENT, rid);
    if(zEComment){
      SET("editedComment", json_new_string(zEComment));
      free(zEComment);
    }

    mtime = db_column_int(&q,1);
    SET("mtime",json_new_int(mtime));
    omtime = db_column_int(&q,4);
    if(omtime && (omtime!=mtime)){
      SET("omtime",json_new_int(omtime));
    }

    if(zParent){
      SET("parentUuid", json_new_string(zParent));
    }

    fileList = json_timeline_get_changed_files(rid);
    if(fileList){
      SET("files",fileList);
    }

#undef SET
  }else{
    cson_value_free(v);
    v = NULL;
  }
  db_finalize(&q);
  return v;
}

static char perms_can_read(){
  return g.perm.Read ? 1 : 0;
}

static ArtifactDispatchEntry ArtifactDispatchList[] = {
{"checkin", json_artifact_ci, perms_can_read},
{"tag", NULL, perms_can_read},
{"ticket", NULL, perms_can_read},
{"wiki", NULL, perms_can_read},
{NULL,NULL,NULL}
};

/*
** Impl of /json/artifact
*/
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;
  Blob uuid = empty_blob;
................................................................................
  if(1==rc){
    g.json.resultCode = FSL_JSON_E_RESOURCE_NOT_FOUND;
    goto error;
  }else if(2==rc){
    g.json.resultCode = FSL_JSON_E_AMBIGUOUS_UUID;
    goto error;
  }
  zUuid = zName = blob_str(&uuid);
  rid = db_int(0, "SELECT rid FROM blob WHERE uuid='%s'", zName);
  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)
................................................................................
  end_ok:
  payV = cson_value_new_object();
  pay = cson_value_get_object(payV);
  assert( NULL != zType );
  cson_object_set( pay, "type", json_new_string(zType) );
  cson_object_set( pay, "id", json_new_string(zName) );
  cson_object_set( pay, "rid", cson_value_new_integer(rid) );
  ArtifactDispatchEntry const * disp = &ArtifactDispatchList[0];
  for( ; disp->name; ++disp ){
    if(0!=strcmp(disp->name, zType)){
      continue;
    }else{
      cson_value * entry;
      if( ! (*disp->permCheck)() ){
        break;
      }
      entry = (*disp->func)(rid, zUuid);
      if(entry){
        cson_object_set(pay, "artifact", entry);
      }
      break;
    }
  }
  veryend:
  blob_reset(&uuid);
  return payV;
}