19 |
#include "estnode.h" |
#include "estnode.h" |
20 |
#include "myconf.h" |
#include "myconf.h" |
21 |
|
|
|
#define AGENTNAME "EstCall" /* name of the agent */ |
|
22 |
#define NUMBUFSIZ 32 /* size of a buffer for a number */ |
#define NUMBUFSIZ 32 /* size of a buffer for a number */ |
23 |
#define IOBUFSIZ 8192 /* size of a buffer for I/O */ |
#define IOBUFSIZ 8192 /* size of a buffer for I/O */ |
24 |
#define MINIBNUM 31 /* bucket number of a small map */ |
#define MINIBNUM 31 /* bucket number of a small map */ |
37 |
const char *g_authname = NULL; /* name of authority */ |
const char *g_authname = NULL; /* name of authority */ |
38 |
const char *g_authpass = NULL; /* password of authority */ |
const char *g_authpass = NULL; /* password of authority */ |
39 |
int g_viewmode = VM_PROT; /* viewing mode */ |
int g_viewmode = VM_PROT; /* viewing mode */ |
40 |
|
int g_condopts = 0; /* options of the search condtion */ |
41 |
int g_nonparse = FALSE; /* whether to output response headers */ |
int g_nonparse = FALSE; /* whether to output response headers */ |
42 |
CBLIST *g_exheaders = NULL; /* extension headers */ |
CBLIST *g_exheaders = NULL; /* extension headers */ |
43 |
|
|
46 |
int main(int argc, char **argv); |
int main(int argc, char **argv); |
47 |
static void usage(void); |
static void usage(void); |
48 |
static void printferror(const char *format, ...); |
static void printferror(const char *format, ...); |
|
static void setproxy(const char *pxstr); |
|
49 |
static int runput(int argc, char **argv); |
static int runput(int argc, char **argv); |
50 |
static int runout(int argc, char **argv); |
static int runout(int argc, char **argv); |
51 |
static int runget(int argc, char **argv); |
static int runget(int argc, char **argv); |
110 |
fprintf(stderr, "%s: command line utility for the node API of Hyper Estraier\n", g_progname); |
fprintf(stderr, "%s: command line utility for the node API of Hyper Estraier\n", g_progname); |
111 |
fprintf(stderr, "\n"); |
fprintf(stderr, "\n"); |
112 |
fprintf(stderr, "usage:\n"); |
fprintf(stderr, "usage:\n"); |
113 |
fprintf(stderr, " %s put [-proxy host:port] [-tout num] [-auth user pass]" |
fprintf(stderr, " %s put [-proxy host port] [-tout num] [-auth user pass]" |
114 |
" nurl [file]\n", g_progname); |
" nurl [file]\n", g_progname); |
115 |
fprintf(stderr, " %s out [-proxy host:port] [-tout num] [-auth user pass]" |
fprintf(stderr, " %s out [-proxy host port] [-tout num] [-auth user pass]" |
116 |
" nurl expr\n", g_progname); |
" nurl expr\n", g_progname); |
117 |
fprintf(stderr, " %s get [-proxy host:port] [-tout num] [-auth user pass]" |
fprintf(stderr, " %s get [-proxy host port] [-tout num] [-auth user pass]" |
118 |
" nurl expr [attr]\n", g_progname); |
" nurl expr [attr]\n", g_progname); |
119 |
fprintf(stderr, " %s uriid [-proxy host:port] [-tout num] [-auth user pass]" |
fprintf(stderr, " %s uriid [-proxy host port] [-tout num] [-auth user pass]" |
120 |
" nurl uri\n",g_progname); |
" nurl uri\n", g_progname); |
121 |
fprintf(stderr, " %s inform [-proxy host:port] [-tout num] [-auth user pass]" |
fprintf(stderr, " %s inform [-proxy host port] [-tout num] [-auth user pass]" |
122 |
" nurl\n", g_progname); |
" nurl\n", g_progname); |
123 |
fprintf(stderr, " %s search [-proxy host:port] [-tout num] [-auth user pass]" |
fprintf(stderr, " %s search [-proxy host port] [-tout num] [-auth user pass]" |
124 |
" [-attr expr] [-ord expr] [-max num] [-dpt num] nurl [phrase]\n", g_progname); |
" [-vx] [-sf] [-attr expr] [-ord expr] [-max num] [-dpt num] nurl [phrase]\n", |
125 |
fprintf(stderr, " %s setuser [-proxy host:port] [-tout num] [-auth user pass]" |
g_progname); |
126 |
|
fprintf(stderr, " %s setuser [-proxy host port] [-tout num] [-auth user pass]" |
127 |
" nurl name mode\n", g_progname); |
" nurl name mode\n", g_progname); |
128 |
fprintf(stderr, " %s setlink [-proxy host:port] [-tout num] [-auth user pass]" |
fprintf(stderr, " %s setlink [-proxy host port] [-tout num] [-auth user pass]" |
129 |
" nurl url label credit\n", g_progname); |
" nurl url label credit\n", g_progname); |
130 |
fprintf(stderr, " %s raw [-proxy host:port] [-tout num] [-auth user pass] [-np] [-eh expr]" |
fprintf(stderr, " %s raw [-proxy host port] [-tout num] [-auth user pass] [-np] [-eh expr]" |
131 |
" url [file]\n", g_progname); |
" url [file]\n", g_progname); |
132 |
fprintf(stderr, "\n"); |
fprintf(stderr, "\n"); |
133 |
exit(1); |
exit(1); |
146 |
} |
} |
147 |
|
|
148 |
|
|
|
/* set proxy information */ |
|
|
static void setproxy(const char *pxstr){ |
|
|
char *rp, *tmp; |
|
|
if((rp = strchr(pxstr, ':')) != NULL){ |
|
|
tmp = cbmemdup(pxstr, rp - pxstr); |
|
|
if((g_pxport = atoi(rp + 1)) < 1) g_pxport = 80; |
|
|
} else { |
|
|
tmp = cbmemdup(pxstr, -1); |
|
|
g_pxport = 80; |
|
|
} |
|
|
cbglobalgc(tmp, free); |
|
|
g_pxhost = tmp; |
|
|
} |
|
|
|
|
|
|
|
149 |
/* parse arguments of the put command */ |
/* parse arguments of the put command */ |
150 |
static int runput(int argc, char **argv){ |
static int runput(int argc, char **argv){ |
151 |
char *nurl, *file; |
char *nurl, *file; |
156 |
if(!nurl && argv[i][0] == '-'){ |
if(!nurl && argv[i][0] == '-'){ |
157 |
if(!strcmp(argv[i], "-proxy")){ |
if(!strcmp(argv[i], "-proxy")){ |
158 |
if(++i >= argc) usage(); |
if(++i >= argc) usage(); |
159 |
setproxy(argv[i]); |
g_pxhost = argv[i]; |
160 |
|
if(++i >= argc) usage(); |
161 |
|
g_pxport = atoi(argv[i]); |
162 |
} else if(!strcmp(argv[i], "-tout")){ |
} else if(!strcmp(argv[i], "-tout")){ |
163 |
if(++i >= argc) usage(); |
if(++i >= argc) usage(); |
164 |
g_timeout = atoi(argv[i]); |
g_timeout = atoi(argv[i]); |
195 |
if(!nurl && argv[i][0] == '-'){ |
if(!nurl && argv[i][0] == '-'){ |
196 |
if(!strcmp(argv[i], "-proxy")){ |
if(!strcmp(argv[i], "-proxy")){ |
197 |
if(++i >= argc) usage(); |
if(++i >= argc) usage(); |
198 |
setproxy(argv[i]); |
g_pxhost = argv[i]; |
199 |
|
if(++i >= argc) usage(); |
200 |
|
g_pxport = atoi(argv[i]); |
201 |
} else if(!strcmp(argv[i], "-tout")){ |
} else if(!strcmp(argv[i], "-tout")){ |
202 |
if(++i >= argc) usage(); |
if(++i >= argc) usage(); |
203 |
g_timeout = atoi(argv[i]); |
g_timeout = atoi(argv[i]); |
235 |
if(!nurl && argv[i][0] == '-'){ |
if(!nurl && argv[i][0] == '-'){ |
236 |
if(!strcmp(argv[i], "-proxy")){ |
if(!strcmp(argv[i], "-proxy")){ |
237 |
if(++i >= argc) usage(); |
if(++i >= argc) usage(); |
238 |
setproxy(argv[i]); |
g_pxhost = argv[i]; |
239 |
|
if(++i >= argc) usage(); |
240 |
|
g_pxport = atoi(argv[i]); |
241 |
} else if(!strcmp(argv[i], "-tout")){ |
} else if(!strcmp(argv[i], "-tout")){ |
242 |
if(++i >= argc) usage(); |
if(++i >= argc) usage(); |
243 |
g_timeout = atoi(argv[i]); |
g_timeout = atoi(argv[i]); |
276 |
if(!nurl && argv[i][0] == '-'){ |
if(!nurl && argv[i][0] == '-'){ |
277 |
if(!strcmp(argv[i], "-proxy")){ |
if(!strcmp(argv[i], "-proxy")){ |
278 |
if(++i >= argc) usage(); |
if(++i >= argc) usage(); |
279 |
setproxy(argv[i]); |
g_pxhost = argv[i]; |
280 |
|
if(++i >= argc) usage(); |
281 |
|
g_pxport = atoi(argv[i]); |
282 |
} else if(!strcmp(argv[i], "-tout")){ |
} else if(!strcmp(argv[i], "-tout")){ |
283 |
if(++i >= argc) usage(); |
if(++i >= argc) usage(); |
284 |
g_timeout = atoi(argv[i]); |
g_timeout = atoi(argv[i]); |
313 |
if(!nurl && argv[i][0] == '-'){ |
if(!nurl && argv[i][0] == '-'){ |
314 |
if(!strcmp(argv[i], "-proxy")){ |
if(!strcmp(argv[i], "-proxy")){ |
315 |
if(++i >= argc) usage(); |
if(++i >= argc) usage(); |
316 |
setproxy(argv[i]); |
g_pxhost = argv[i]; |
317 |
|
if(++i >= argc) usage(); |
318 |
|
g_pxport = atoi(argv[i]); |
319 |
} else if(!strcmp(argv[i], "-tout")){ |
} else if(!strcmp(argv[i], "-tout")){ |
320 |
if(++i >= argc) usage(); |
if(++i >= argc) usage(); |
321 |
g_timeout = atoi(argv[i]); |
g_timeout = atoi(argv[i]); |
357 |
if(!nurl && argv[i][0] == '-'){ |
if(!nurl && argv[i][0] == '-'){ |
358 |
if(!strcmp(argv[i], "-proxy")){ |
if(!strcmp(argv[i], "-proxy")){ |
359 |
if(++i >= argc) usage(); |
if(++i >= argc) usage(); |
360 |
setproxy(argv[i]); |
g_pxhost = argv[i]; |
361 |
|
if(++i >= argc) usage(); |
362 |
|
g_pxport = atoi(argv[i]); |
363 |
} else if(!strcmp(argv[i], "-tout")){ |
} else if(!strcmp(argv[i], "-tout")){ |
364 |
if(++i >= argc) usage(); |
if(++i >= argc) usage(); |
365 |
g_timeout = atoi(argv[i]); |
g_timeout = atoi(argv[i]); |
370 |
g_authpass = argv[i]; |
g_authpass = argv[i]; |
371 |
} else if(!strcmp(argv[i], "-vx")){ |
} else if(!strcmp(argv[i], "-vx")){ |
372 |
g_viewmode = VM_XML; |
g_viewmode = VM_XML; |
373 |
|
} else if(!strcmp(argv[i], "-sf")){ |
374 |
|
g_condopts |= ESTCONDSIMPLE; |
375 |
} else if(!strcmp(argv[i], "-attr")){ |
} else if(!strcmp(argv[i], "-attr")){ |
376 |
if(++i >= argc) usage(); |
if(++i >= argc) usage(); |
377 |
cblistpush(attrs, argv[i], -1); |
cblistpush(attrs, argv[i], -1); |
412 |
if(!nurl && argv[i][0] == '-'){ |
if(!nurl && argv[i][0] == '-'){ |
413 |
if(!strcmp(argv[i], "-proxy")){ |
if(!strcmp(argv[i], "-proxy")){ |
414 |
if(++i >= argc) usage(); |
if(++i >= argc) usage(); |
415 |
setproxy(argv[i]); |
g_pxhost = argv[i]; |
416 |
|
if(++i >= argc) usage(); |
417 |
|
g_pxport = atoi(argv[i]); |
418 |
} else if(!strcmp(argv[i], "-tout")){ |
} else if(!strcmp(argv[i], "-tout")){ |
419 |
if(++i >= argc) usage(); |
if(++i >= argc) usage(); |
420 |
g_timeout = atoi(argv[i]); |
g_timeout = atoi(argv[i]); |
454 |
if(!nurl && argv[i][0] == '-'){ |
if(!nurl && argv[i][0] == '-'){ |
455 |
if(!strcmp(argv[i], "-proxy")){ |
if(!strcmp(argv[i], "-proxy")){ |
456 |
if(++i >= argc) usage(); |
if(++i >= argc) usage(); |
457 |
setproxy(argv[i]); |
g_pxhost = argv[i]; |
458 |
|
if(++i >= argc) usage(); |
459 |
|
g_pxport = atoi(argv[i]); |
460 |
} else if(!strcmp(argv[i], "-tout")){ |
} else if(!strcmp(argv[i], "-tout")){ |
461 |
if(++i >= argc) usage(); |
if(++i >= argc) usage(); |
462 |
g_timeout = atoi(argv[i]); |
g_timeout = atoi(argv[i]); |
499 |
if(!url && argv[i][0] == '-'){ |
if(!url && argv[i][0] == '-'){ |
500 |
if(!strcmp(argv[i], "-proxy")){ |
if(!strcmp(argv[i], "-proxy")){ |
501 |
if(++i >= argc) usage(); |
if(++i >= argc) usage(); |
502 |
setproxy(argv[i]); |
g_pxhost = argv[i]; |
503 |
|
if(++i >= argc) usage(); |
504 |
|
g_pxport = atoi(argv[i]); |
505 |
} else if(!strcmp(argv[i], "-tout")){ |
} else if(!strcmp(argv[i], "-tout")){ |
506 |
if(++i >= argc) usage(); |
if(++i >= argc) usage(); |
507 |
g_timeout = atoi(argv[i]); |
g_timeout = atoi(argv[i]); |
620 |
} |
} |
621 |
err = FALSE; |
err = FALSE; |
622 |
node = est_node_new(nurl); |
node = est_node_new(nurl); |
623 |
if(g_pxhost) est_node_set_proxy(node, g_pxhost, g_pxport); |
if(g_pxhost && g_pxport > 0) est_node_set_proxy(node, g_pxhost, g_pxport); |
624 |
if(g_timeout >= 0) est_node_set_timeout(node, g_timeout); |
if(g_timeout >= 0) est_node_set_timeout(node, g_timeout); |
625 |
if(g_authname && g_authpass) est_node_set_auth(node, g_authname, g_authpass); |
if(g_authname && g_authpass) est_node_set_auth(node, g_authname, g_authpass); |
626 |
doc = est_doc_new_from_draft(draft); |
doc = est_doc_new_from_draft(draft); |
641 |
int err; |
int err; |
642 |
err = FALSE; |
err = FALSE; |
643 |
node = est_node_new(nurl); |
node = est_node_new(nurl); |
644 |
if(g_pxhost) est_node_set_proxy(node, g_pxhost, g_pxport); |
if(g_pxhost && g_pxport > 0) est_node_set_proxy(node, g_pxhost, g_pxport); |
645 |
if(g_timeout >= 0) est_node_set_timeout(node, g_timeout); |
if(g_timeout >= 0) est_node_set_timeout(node, g_timeout); |
646 |
if(g_authname && g_authpass) est_node_set_auth(node, g_authname, g_authpass); |
if(g_authname && g_authpass) est_node_set_auth(node, g_authname, g_authpass); |
647 |
if(uri ? !est_node_out_doc_by_uri(node, uri) : !est_node_out_doc(node, id)){ |
if(uri ? !est_node_out_doc_by_uri(node, uri) : !est_node_out_doc(node, id)){ |
661 |
int err; |
int err; |
662 |
err = FALSE; |
err = FALSE; |
663 |
node = est_node_new(nurl); |
node = est_node_new(nurl); |
664 |
if(g_pxhost) est_node_set_proxy(node, g_pxhost, g_pxport); |
if(g_pxhost && g_pxport > 0) est_node_set_proxy(node, g_pxhost, g_pxport); |
665 |
if(g_timeout >= 0) est_node_set_timeout(node, g_timeout); |
if(g_timeout >= 0) est_node_set_timeout(node, g_timeout); |
666 |
if(g_authname && g_authpass) est_node_set_auth(node, g_authname, g_authpass); |
if(g_authname && g_authpass) est_node_set_auth(node, g_authname, g_authpass); |
667 |
err = FALSE; |
err = FALSE; |
696 |
int err, id; |
int err, id; |
697 |
err = FALSE; |
err = FALSE; |
698 |
node = est_node_new(nurl); |
node = est_node_new(nurl); |
699 |
if(g_pxhost) est_node_set_proxy(node, g_pxhost, g_pxport); |
if(g_pxhost && g_pxport > 0) est_node_set_proxy(node, g_pxhost, g_pxport); |
700 |
if(g_timeout >= 0) est_node_set_timeout(node, g_timeout); |
if(g_timeout >= 0) est_node_set_timeout(node, g_timeout); |
701 |
if(g_authname && g_authpass) est_node_set_auth(node, g_authname, g_authpass); |
if(g_authname && g_authpass) est_node_set_auth(node, g_authname, g_authpass); |
702 |
err = FALSE; |
err = FALSE; |
719 |
double size; |
double size; |
720 |
err = FALSE; |
err = FALSE; |
721 |
node = est_node_new(nurl); |
node = est_node_new(nurl); |
722 |
if(g_pxhost) est_node_set_proxy(node, g_pxhost, g_pxport); |
if(g_pxhost && g_pxport > 0) est_node_set_proxy(node, g_pxhost, g_pxport); |
723 |
if(g_timeout >= 0) est_node_set_timeout(node, g_timeout); |
if(g_timeout >= 0) est_node_set_timeout(node, g_timeout); |
724 |
if(g_authname && g_authpass) est_node_set_auth(node, g_authname, g_authpass); |
if(g_authname && g_authpass) est_node_set_auth(node, g_authname, g_authpass); |
725 |
err = FALSE; |
err = FALSE; |
753 |
int i, j, err, ksiz, vsiz, dnum, wnum, id, ld; |
int i, j, err, ksiz, vsiz, dnum, wnum, id, ld; |
754 |
err = FALSE; |
err = FALSE; |
755 |
node = est_node_new(nurl); |
node = est_node_new(nurl); |
756 |
if(g_pxhost) est_node_set_proxy(node, g_pxhost, g_pxport); |
if(g_pxhost && g_pxport > 0) est_node_set_proxy(node, g_pxhost, g_pxport); |
757 |
if(g_timeout >= 0) est_node_set_timeout(node, g_timeout); |
if(g_timeout >= 0) est_node_set_timeout(node, g_timeout); |
758 |
if(g_authname && g_authpass) est_node_set_auth(node, g_authname, g_authpass); |
if(g_authname && g_authpass) est_node_set_auth(node, g_authname, g_authpass); |
759 |
err = FALSE; |
err = FALSE; |
767 |
} |
} |
768 |
if(ord) est_cond_set_order(cond, ord); |
if(ord) est_cond_set_order(cond, ord); |
769 |
if(max >= 0) est_cond_set_max(cond, max); |
if(max >= 0) est_cond_set_max(cond, max); |
770 |
|
est_cond_set_options(cond, g_condopts); |
771 |
if((nres = est_node_search(node, cond, depth)) != NULL){ |
if((nres = est_node_search(node, cond, depth)) != NULL){ |
772 |
hints = est_noderes_hints(nres); |
hints = est_noderes_hints(nres); |
773 |
switch(g_viewmode){ |
switch(g_viewmode){ |
888 |
int err; |
int err; |
889 |
err = FALSE; |
err = FALSE; |
890 |
node = est_node_new(nurl); |
node = est_node_new(nurl); |
891 |
if(g_pxhost) est_node_set_proxy(node, g_pxhost, g_pxport); |
if(g_pxhost && g_pxport > 0) est_node_set_proxy(node, g_pxhost, g_pxport); |
892 |
if(g_timeout >= 0) est_node_set_timeout(node, g_timeout); |
if(g_timeout >= 0) est_node_set_timeout(node, g_timeout); |
893 |
if(g_authname && g_authpass) est_node_set_auth(node, g_authname, g_authpass); |
if(g_authname && g_authpass) est_node_set_auth(node, g_authname, g_authpass); |
894 |
err = FALSE; |
err = FALSE; |
907 |
int err; |
int err; |
908 |
err = FALSE; |
err = FALSE; |
909 |
node = est_node_new(nurl); |
node = est_node_new(nurl); |
910 |
if(g_pxhost) est_node_set_proxy(node, g_pxhost, g_pxport); |
if(g_pxhost && g_pxport > 0) est_node_set_proxy(node, g_pxhost, g_pxport); |
911 |
if(g_timeout >= 0) est_node_set_timeout(node, g_timeout); |
if(g_timeout >= 0) est_node_set_timeout(node, g_timeout); |
912 |
if(g_authname && g_authpass) est_node_set_auth(node, g_authname, g_authpass); |
if(g_authname && g_authpass) est_node_set_auth(node, g_authname, g_authpass); |
913 |
err = FALSE; |
err = FALSE; |
937 |
rbsiz = 0; |
rbsiz = 0; |
938 |
} |
} |
939 |
err = FALSE; |
err = FALSE; |
940 |
|
if(g_pxport < 1) g_pxport = 80; |
941 |
resheads = cbmapopenex(MINIBNUM); |
resheads = cbmapopenex(MINIBNUM); |
942 |
resbody = cbdatumopen("", 0); |
resbody = cbdatumopen("", 0); |
943 |
auth = (g_authname && g_authpass) ? cbsprintf("%s:%s", g_authname, g_authpass) : NULL; |
auth = (g_authname && g_authpass) ? cbsprintf("%s:%s", g_authname, g_authpass) : NULL; |