Fossil

Diff
Login

Differences From Artifact [1caf876ec1]:

To Artifact [a5d36a69b8]:


43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
  char const * name;

  /**
     JSON construction callback. Creates the contents for the
     payload.artifact property of /json/artifact responses.
  */
  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) and an access error is
     generated.
  */
  char (*permCheck)();
} ArtifactDispatchEntry;


/*
** Generates an artifact Object for the given rid/zUuid. rid
** must refer to a Checkin.
**







<
<
<
<
<
<
<
<







43
44
45
46
47
48
49








50
51
52
53
54
55
56
  char const * name;

  /**
     JSON construction callback. Creates the contents for the
     payload.artifact property of /json/artifact responses.
  */
  artifact_f func;








} ArtifactDispatchEntry;


/*
** Generates an artifact Object for the given rid/zUuid. rid
** must refer to a Checkin.
**
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
196
197

198
199
200
201
202
203
204
205
206
207


#undef SET
  }
  db_finalize(&q);
  return v;
}






























/*
** Sub-impl of /json/artifact for checkins.
*/
static cson_value * json_artifact_ci( int rid ){




  return json_artifact_for_ci(rid, 1);

}

/*
** Permissions callback func for ArtifactDispatchEntry.
*/
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. 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;

  Blob uuid = empty_blob;
  int rc;
  int rid;
  ArtifactDispatchEntry const * dispatcher = &ArtifactDispatchList[0];
  zName = g.isHTTP
    ? json_getenv_cstr("uuid")
    : find_option("uuid","u",1);
  if(!zName||!*zName){
    zName = json_command_arg(g.json.dispatchDepth+1);
    if(!zName || !*zName) {







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





>
>
>
>
|
>










|
|
|
|
>
|












>


|







150
151
152
153
154
155
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
196
197
198
199
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
228
229
230
231
232
233
234
235


#undef SET
  }
  db_finalize(&q);
  return v;
}

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, 1);
  }

  pTktChng = manifest_get(rid, CFTYPE_TICKET);
  if( pTktChng==0 ){
    g.json.resultCode = FSL_JSON_E_UNKNOWN;
    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 ){
    g.json.resultCode = FSL_JSON_E_DENIED;
    return NULL;
  }else{
    return json_artifact_for_ci(rid, 1);
  }
}

/*
** Permissions callback func for ArtifactDispatchEntry.
*/
static char perms_can_read(){
  return g.perm.Read ? 1 : 0;
}

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;
  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 = g.isHTTP
    ? json_getenv_cstr("uuid")
    : find_option("uuid","u",1);
  if(!zName||!*zName){
    zName = json_command_arg(g.json.dispatchDepth+1);
    if(!zName || !*zName) {
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

  handle_entry:
  assert( (NULL != zType) && "Internal dispatching error." );
  for( ; dispatcher->name; ++dispatcher ){
    if(0!=strcmp(dispatcher->name, zType)){
      continue;
    }else{
      if( ! (*dispatcher->permCheck)() ){
        g.json.resultCode = FSL_JSON_E_DENIED;
      }
      break;
    }
  }
  if(!g.json.resultCode){


    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, "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( !dispatcher->name ){
      cson_object_set(pay,"artifact",
                      json_new_string("TODO: handle this artifact type!"));
    }else {
      cson_value * entry = (*dispatcher->func)(rid);
      if(entry){
        cson_object_set(pay, "artifact", entry);
      }
    }

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








|
<
<




>
>


<




<
<
<
<
<
|
|
|
|
>






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
314
315
316
317

  handle_entry:
  assert( (NULL != zType) && "Internal dispatching error." );
  for( ; dispatcher->name; ++dispatcher ){
    if(0!=strcmp(dispatcher->name, zType)){
      continue;
    }else{
      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;
}