Fossil

Diff
Login

Diff

Differences From Artifact [bff6200306]:

To Artifact [ca3e4958a3]:


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
  const char *azAuxVal[MX_AUX];  /* Value of each aux() or option() value */
  const char **azAuxOpt[MX_AUX]; /* Options of each option() value */
  int anAuxCols[MX_AUX];         /* Number of columns for option() values */
  
  int allowSymlinks;             /* Cached "allow-symlinks" option */

  struct FossilJsonBits {
    int isJsonMode;            /* True if running in JSON mode, else false. This changes

                                  how errors are reported. In JSON mode we try to always
                                  output JSON-form error responses.


                               */











    int cmdOffset;             /* Tells us which PATH_INFO/CLI args
                                  part holds the "json" command, so
                                  that we can account for sub-repos
                                  and path prefixes.  This is handled
                                  differently for CLI and CGI modes.
                               */
    int resultCode;            /* used for passing back specific codes from /json callbacks. */
    int errorDetailParanoia;   /* 0=full error codes, 1=%10, 2=%100, 3=%1000 */
    cson_cgi_cx cgiCx;         /* cson_cgi context */

    cson_output_opt outOpt;    /* formatting options for JSON mode. */


    cson_value * authToken;    /* authentication token */


    struct {
      cson_value * v;
      cson_object * o;
    } reqPayload;              /* request payload object (if any) */
  } json;
};








|
>
|
|
>
>

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





|
<
|
>
|
>
>
|
>
>







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
  const char *azAuxVal[MX_AUX];  /* Value of each aux() or option() value */
  const char **azAuxOpt[MX_AUX]; /* Options of each option() value */
  int anAuxCols[MX_AUX];         /* Number of columns for option() values */
  
  int allowSymlinks;             /* Cached "allow-symlinks" option */

  struct FossilJsonBits {
    int isJsonMode;            /* True if running in JSON mode, else
                                  false. This changes how errors are
                                  reported. In JSON mode we try to
                                  always output JSON-form error
                                  responses and always exit() with
                                  code 0 to avoid an HTTP 500 error.
                               */
    int resultCode;            /* used for passing back specific codes from /json callbacks. */
    int errorDetailParanoia;   /* 0=full error codes, 1=%10, 2=%100, 3=%1000 */
    cson_output_opt outOpt;    /* formatting options for JSON mode. */
    cson_value * authToken;    /* authentication token */
    struct {                   /* "garbage collector" */
      cson_value * v;
      cson_object * o;
    } gc;
    struct {                   /* JSON POST data. */
      cson_value * v;
      cson_array * a;
      int offset;              /* Tells us which PATH_INFO/CLI args
                                  part holds the "json" command, so
                                  that we can account for sub-repos
                                  and path prefixes.  This is handled
                                  differently for CLI and CGI modes.
                               */
    } cmd;

    struct {                   /* JSON POST data. */
      cson_value * v;
      cson_object * o;
    } post;
    struct {                   /* GET/COOKIE params in JSON form. */
      cson_value * v;
      cson_object * o;
    } param;
    struct {
      cson_value * v;
      cson_object * o;
    } reqPayload;              /* request payload object (if any) */
  } json;
};

257
258
259
260
261
262
263
264


265
266
267
268
269
270
271
}

/*
** atexit() handler which frees up "some" of the resources
** used by fossil.
*/
void fossil_atexit() {
  cson_cgi_cx_clean(&g.json.cgiCx);


  if(g.db){
    db_close(0);
  }
}

/*
** This procedure runs first.







|
>
>







275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
}

/*
** atexit() handler which frees up "some" of the resources
** used by fossil.
*/
void fossil_atexit() {

  cson_value_free(g.json.gc.v);
  memset(&g.json, 0, sizeof(g.json));
  if(g.db){
    db_close(0);
  }
}

/*
** This procedure runs first.
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
  g.json.errorDetailParanoia = 2 /* FIXME: make configurable
                                    One problem we have here is that this
                                    code is needed before the db is opened,
                                    so we can't sql for it.*/;
#else
  g.json.errorDetailParanoia = 0;
#endif
  g.json.cgiCx = cson_cgi_cx_empty;
  g.json.outOpt = cson_output_opt_empty;
  g.json.outOpt.addNewline = 1;
  g.json.outOpt.indentation = 1 /* FIXME: make configurable */;
  for(i=0; i<argc; i++) g.argv[i] = fossil_mbcs_to_utf8(argv[i]);
  if( getenv("GATEWAY_INTERFACE")!=0 && !find_option("nocgi", 0, 0)){
    zCmdName = "cgi";
    g.isCGI = 1;







<







305
306
307
308
309
310
311

312
313
314
315
316
317
318
  g.json.errorDetailParanoia = 2 /* FIXME: make configurable
                                    One problem we have here is that this
                                    code is needed before the db is opened,
                                    so we can't sql for it.*/;
#else
  g.json.errorDetailParanoia = 0;
#endif

  g.json.outOpt = cson_output_opt_empty;
  g.json.outOpt.addNewline = 1;
  g.json.outOpt.indentation = 1 /* FIXME: make configurable */;
  for(i=0; i<argc; i++) g.argv[i] = fossil_mbcs_to_utf8(argv[i]);
  if( getenv("GATEWAY_INTERFACE")!=0 && !find_option("nocgi", 0, 0)){
    zCmdName = "cgi";
    g.isCGI = 1;
343
344
345
346
347
348
349
350
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
381
382
383
384
385
386
387
388
      }
    }
    fossil_fatal("%s: ambiguous command prefix: %s\n"
                 "%s: could be any of:%s\n"
                 "%s: use \"help\" for more information\n",
                 argv[0], zCmdName, argv[0], blob_str(&couldbe), argv[0]);
  }
  rc = cson_cgi_init(&g.json.cgiCx, g.argc, (char const * const *)g.argv, NULL)
    /* Reminder: cson_cgi_init() may process the POST data before
       fossil gets to, but it is configured to only read
       application/[json/javascript] and text/plain. form-urlencoded
       and x-fossil-* data will be consumed by fossil's cgi_init().

       Note that we set up the CGI bits even when not running in CGI
       mode because some of cson_cgi's facilities are useful in
       non-CGI contexts and we use those in the CLI variants of the
       JSON commands.

       FIXME: do some analysis of the request path (HTTP mode) or
       CLI args (CLI mode) and only call this if the command is
       a JSON-mode command. We can only do that easily from here
       if we use e.g. /json/foo instead of /foo.json, since we
       have a common prefix.
     */
    ;
  if(rc){
    fossil_fatal("%s: unrecoverable error while initializing JSON CGI bits: "
                 "cson error code #%d (%s)\n",
                 argv[0], rc, cson_rc_string(rc));
  }else{
    if( NULL != cson_cgi_env_get_obj( &g.json.cgiCx, 'p', 0 ) ){
      /* if cson_cgi read the POST data then we're certainly in JSON
         mode. If it didn't then we have to delay this decision until
         the JSON family of callbacks is called.
      */
      g.json.isJsonMode = 1;
    }
    atexit( fossil_atexit );
  }
  aCommand[idx].xFunc();
  fossil_exit(0);
  /*NOT_REACHED*/
  return 0;
}

/*







<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<




<
<
<
<
<
<
<
|
|
<







362
363
364
365
366
367
368


















369
370
371
372







373
374

375
376
377
378
379
380
381
      }
    }
    fossil_fatal("%s: ambiguous command prefix: %s\n"
                 "%s: could be any of:%s\n"
                 "%s: use \"help\" for more information\n",
                 argv[0], zCmdName, argv[0], blob_str(&couldbe), argv[0]);
  }


















  if(rc){
    fossil_fatal("%s: unrecoverable error while initializing JSON CGI bits: "
                 "cson error code #%d (%s)\n",
                 argv[0], rc, cson_rc_string(rc));







  }
  atexit( fossil_atexit );

  aCommand[idx].xFunc();
  fossil_exit(0);
  /*NOT_REACHED*/
  return 0;
}

/*