133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
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
|
** defined in the page_index.h header file which is automatically
** generated by mkindex.c program.
*/
static int name_search(
const char *zName, /* The name we are looking for */
const NameMap *aMap, /* Search in this array */
int nMap, /* Number of slots in aMap[] */
void (**pxFunc)(void) /* Write pointer to handler function here */
){
int upr, lwr, cnt, m, i;
int n = strlen(zName);
lwr = 0;
upr = nMap-1;
while( lwr<=upr ){
int mid, c;
mid = (upr+lwr)/2;
c = strcmp(zName, aMap[mid].zName);
if( c==0 ){
*pxFunc = aMap[mid].xFunc;
return 0;
}else if( c<0 ){
upr = mid - 1;
}else{
lwr = mid + 1;
}
}
for(m=cnt=0, i=upr-2; i<=upr+3 && i<nMap; i++){
if( i<0 ) continue;
if( strncmp(zName, aMap[i].zName, n)==0 ){
m = i;
cnt++;
}
}
if( cnt==1 ){
*pxFunc = aMap[m].xFunc;
return 0;
}
return 1+(cnt>1);
}
/*
** This procedure runs first.
*/
int main(int argc, char **argv){
const char *zCmdName;
void (*xFunc)(void);
int rc;
g.now = time(0);
g.argc = argc;
g.argv = argv;
if( getenv("GATEWAY_INTERFACE")!=0 ){
zCmdName = "cgi";
}else if( argc<2 ){
fprintf(stderr, "Usage: %s COMMAND ...\n", argv[0]);
exit(1);
}else{
g.fSqlTrace = find_option("sqltrace", 0, 0)!=0;
g.fSqlPrint = find_option("sqlprint", 0, 0)!=0;
g.fHttpTrace = find_option("httptrace", 0, 0)!=0;
g.zLogin = find_option("user", "U", 1);
zCmdName = argv[1];
}
rc = name_search(zCmdName, aCommand, count(aCommand), &xFunc);
if( rc==1 ){
fprintf(stderr,"%s: unknown command: %s\n"
"%s: use \"commands\" or \"test-commands\" for help\n",
argv[0], zCmdName, argv[0]);
return 1;
}else if( rc==2 ){
fprintf(stderr,"%s: ambiguous command prefix: %s\n"
"%s: use \"commands\" or \"test-commands\" for help\n",
argv[0], zCmdName, argv[0]);
return 1;
}
xFunc();
return 0;
}
/*
** Print an error message, rollback all databases, and quit.
*/
void fossil_panic(const char *zFormat, ...){
|
|
|
|
|
|
|
|
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
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
|
** defined in the page_index.h header file which is automatically
** generated by mkindex.c program.
*/
static int name_search(
const char *zName, /* The name we are looking for */
const NameMap *aMap, /* Search in this array */
int nMap, /* Number of slots in aMap[] */
int *pIndex /* OUT: The index in aMap[] of the match */
){
int upr, lwr, cnt, m, i;
int n = strlen(zName);
lwr = 0;
upr = nMap-1;
while( lwr<=upr ){
int mid, c;
mid = (upr+lwr)/2;
c = strcmp(zName, aMap[mid].zName);
if( c==0 ){
*pIndex = mid;
return 0;
}else if( c<0 ){
upr = mid - 1;
}else{
lwr = mid + 1;
}
}
for(m=cnt=0, i=upr-2; i<=upr+3 && i<nMap; i++){
if( i<0 ) continue;
if( strncmp(zName, aMap[i].zName, n)==0 ){
m = i;
cnt++;
}
}
if( cnt==1 ){
*pIndex = m;
return 0;
}
return 1+(cnt>1);
}
/*
** This procedure runs first.
*/
int main(int argc, char **argv){
const char *zCmdName;
int idx;
int rc;
g.now = time(0);
g.argc = argc;
g.argv = argv;
if( getenv("GATEWAY_INTERFACE")!=0 ){
zCmdName = "cgi";
}else if( argc<2 ){
fprintf(stderr, "Usage: %s COMMAND ...\n", argv[0]);
exit(1);
}else{
g.fSqlTrace = find_option("sqltrace", 0, 0)!=0;
g.fSqlPrint = find_option("sqlprint", 0, 0)!=0;
g.fHttpTrace = find_option("httptrace", 0, 0)!=0;
g.zLogin = find_option("user", "U", 1);
zCmdName = argv[1];
}
rc = name_search(zCmdName, aCommand, count(aCommand), &idx);
if( rc==1 ){
fprintf(stderr,"%s: unknown command: %s\n"
"%s: use \"commands\" or \"test-commands\" for help\n",
argv[0], zCmdName, argv[0]);
return 1;
}else if( rc==2 ){
fprintf(stderr,"%s: ambiguous command prefix: %s\n"
"%s: use \"commands\" or \"test-commands\" for help\n",
argv[0], zCmdName, argv[0]);
return 1;
}
aCommand[idx].xFunc();
return 0;
}
/*
** Print an error message, rollback all databases, and quit.
*/
void fossil_panic(const char *zFormat, ...){
|
338
339
340
341
342
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
|
printf("\n");
}
}
/*
** COMMAND: commands
**
** List all commands whose name does not start with "test-"
*/
void cmd_cmd_list(void){
int i, nCmd;
const char *aCmd[count(aCommand)];
for(i=nCmd=0; i<count(aCommand); i++){
if( strncmp(aCommand[i].zName,"test",4)==0 ) continue;
if( strcmp(aCommand[i].zName, g.argv[1])==0 ) continue;
aCmd[nCmd++] = aCommand[i].zName;
}
multi_column_list(aCmd, nCmd);
}
/*
** COMMAND: test-commands
**
** List all commands whose name begins with "test"
*/
void cmd_test_cmd_list(void){
int i, nCmd;
const char *aCmd[count(aCommand)];
for(i=nCmd=0; i<count(aCommand); i++){
if( strncmp(aCommand[i].zName,"test",4)!=0 ) continue;
if( strcmp(aCommand[i].zName, g.argv[1])==0 ) continue;
aCmd[nCmd++] = aCommand[i].zName;
}
multi_column_list(aCmd, nCmd);
}
/*
** RSS feeds need to reference absolute URLs so we need to calculate
** the base URL onto which we add components. This is basically
** cgi_redirect() stripped down and always returning an absolute URL.
*/
static char *get_base_url(void){
|
>
|
|
>
|
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
338
339
340
341
342
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
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
|
printf("\n");
}
}
/*
** COMMAND: commands
**
** Usage: %fossil commands
** List all supported commands.
*/
void cmd_cmd_list(void){
int i, nCmd;
const char *aCmd[count(aCommand)];
for(i=nCmd=0; i<count(aCommand); i++){
if( strncmp(aCommand[i].zName,"test",4)==0 ) continue;
/* if( strcmp(aCommand[i].zName, g.argv[1])==0 ) continue; */
aCmd[nCmd++] = aCommand[i].zName;
}
multi_column_list(aCmd, nCmd);
}
/*
** COMMAND: test-commands
**
** Usage: %fossil test-commands
** List all commands used for testing and debugging.
*/
void cmd_test_cmd_list(void){
int i, nCmd;
const char *aCmd[count(aCommand)];
for(i=nCmd=0; i<count(aCommand); i++){
if( strncmp(aCommand[i].zName,"test",4)!=0 ) continue;
/* if( strcmp(aCommand[i].zName, g.argv[1])==0 ) continue; */
aCmd[nCmd++] = aCommand[i].zName;
}
multi_column_list(aCmd, nCmd);
}
/*
** COMMAND: help
**
** Usage: %fossil help COMMAND
** Display information on how to use COMMAND
*/
void help_cmd(void){
int rc, idx;
const char *z;
if( g.argc!=3 ){
printf("Usage: %s help <command>.\nAvailable commands:\n", g.argv[0]);
cmd_cmd_list();
return;
}
rc = name_search(g.argv[2], aCommand, count(aCommand), &idx);
if( rc==1 ){
fossil_fatal("unknown command: %s", g.argv[2]);
}else if( rc==2 ){
fossil_fatal("ambiguous command prefix: %s", g.argv[2]);
}
z = aCmdHelp[idx];
if( z==0 ){
fossil_fatal("no help available for the %s command",
aCommand[idx].zName);
}
while( *z ){
if( *z=='%' && strncmp(z, "%fossil", 7)==0 ){
printf("%s", g.argv[0]);
z += 7;
}else{
putchar(*z);
z++;
}
}
putchar('\n');
}
/*
** RSS feeds need to reference absolute URLs so we need to calculate
** the base URL onto which we add components. This is basically
** cgi_redirect() stripped down and always returning an absolute URL.
*/
static char *get_base_url(void){
|
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
|
**
** Process the webpage specified by the PATH_INFO or REQUEST_URI
** environment variable.
*/
static void process_one_web_page(void){
const char *zPathInfo;
char *zPath;
void (*xFunc)(void);
int i, j;
/* Find the page that the user has requested, construct and deliver that
** page.
*/
zPathInfo = P("PATH_INFO");
if( zPathInfo==0 || zPathInfo[0]==0 ){
|
|
|
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
|
**
** Process the webpage specified by the PATH_INFO or REQUEST_URI
** environment variable.
*/
static void process_one_web_page(void){
const char *zPathInfo;
char *zPath;
int idx;
int i, j;
/* Find the page that the user has requested, construct and deliver that
** page.
*/
zPathInfo = P("PATH_INFO");
if( zPathInfo==0 || zPathInfo[0]==0 ){
|
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
|
cgi_reply();
exit(0);
}
/* Locate the method specified by the path and execute the function
** that implements that method.
*/
if( name_search(g.zPath, aWebpage, count(aWebpage), &xFunc) &&
name_search("not_found", aWebpage, count(aWebpage), &xFunc) ){
cgi_set_status(404,"Not Found");
@ <h1>Not Found</h1>
@ <p>Page not found: %h(g.zPath)</p>
}else{
xFunc();
}
/* Return the result.
*/
cgi_reply();
}
|
|
|
|
|
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
|
cgi_reply();
exit(0);
}
/* Locate the method specified by the path and execute the function
** that implements that method.
*/
if( name_search(g.zPath, aWebpage, count(aWebpage), &idx) &&
name_search("not_found", aWebpage, count(aWebpage), &idx) ){
cgi_set_status(404,"Not Found");
@ <h1>Not Found</h1>
@ <p>Page not found: %h(g.zPath)</p>
}else{
aWebpage[idx].xFunc();
}
/* Return the result.
*/
cgi_reply();
}
|