405
/* Synchronize updating contents of the database of a node. */
406
int est_node_sync(ESTNODE *node){
410
char url[ESTPATHBUFSIZ], *vbuf;
414
sprintf(url, "%s/sync", node->url);
415
reqheads = cblistopen();
416
if(cbmaprnum(node->heads) > 0){
417
cbmapiterinit(node->heads);
418
while((kbuf = cbmapiternext(node->heads, NULL)) != NULL){
419
vbuf = cbsprintf("%s: %s", kbuf, cbmapiterval(kbuf, NULL));
420
cblistpush(reqheads, vbuf, -1);
424
cblistpush(reqheads, "Content-Type: " ESTFORMTYPE, -1);
425
reqbody = cbdatumopen(NULL, -1);
426
if(!est_url_shuttle(url, node->pxhost, node->pxport, node->timeout, ESTRESLIMSIZE, node->auth,
427
reqheads, cbdatumptr(reqbody), cbdatumsize(reqbody),
428
&rescode, NULL, NULL)){
433
node->status = rescode;
434
if(rescode != 200) err = TRUE;
436
cbdatumclose(reqbody);
437
cblistclose(reqheads);
438
return err ? FALSE : TRUE;
442
/* Optimize the database of a node. */
443
int est_node_optimize(ESTNODE *node){
447
char url[ESTPATHBUFSIZ], *vbuf;
451
sprintf(url, "%s/optimize", node->url);
452
reqheads = cblistopen();
453
if(cbmaprnum(node->heads) > 0){
454
cbmapiterinit(node->heads);
455
while((kbuf = cbmapiternext(node->heads, NULL)) != NULL){
456
vbuf = cbsprintf("%s: %s", kbuf, cbmapiterval(kbuf, NULL));
457
cblistpush(reqheads, vbuf, -1);
461
cblistpush(reqheads, "Content-Type: " ESTFORMTYPE, -1);
462
reqbody = cbdatumopen(NULL, -1);
463
if(!est_url_shuttle(url, node->pxhost, node->pxport, node->timeout, ESTRESLIMSIZE, node->auth,
464
reqheads, cbdatumptr(reqbody), cbdatumsize(reqbody),
465
&rescode, NULL, NULL)){
470
node->status = rescode;
471
if(rescode != 200) err = TRUE;
473
cbdatumclose(reqbody);
474
cblistclose(reqheads);
475
return err ? FALSE : TRUE;
396
479
/* Add a document to a node. */
397
480
int est_node_put_doc(ESTNODE *node, ESTDOC *doc){
398
481
CBLIST *reqheads;
399
482
const char *kbuf;
400
483
char url[ESTPATHBUFSIZ], *vbuf, *reqbody;
401
int rescode, err, ksiz;
402
485
assert(node && doc);
404
487
sprintf(url, "%s/put_doc", node->url);
405
488
reqheads = cblistopen();
406
489
if(cbmaprnum(node->heads) > 0){
407
490
cbmapiterinit(node->heads);
408
while((kbuf = cbmapiternext(node->heads, &ksiz)) != NULL){
409
vbuf = cbsprintf("%s: %s", kbuf, cbmapget(node->heads, kbuf, ksiz, NULL));
491
while((kbuf = cbmapiternext(node->heads, NULL)) != NULL){
492
vbuf = cbsprintf("%s: %s", kbuf, cbmapiterval(kbuf, NULL));
410
493
cblistpush(reqheads, vbuf, -1);
414
497
cblistpush(reqheads, "Content-Type: " ESTDRAFTTYPE, -1);
415
498
reqbody = est_doc_dump_draft(doc);
416
if(!est_url_shuttle(url, node->pxhost, node->pxport, node->timeout, node->auth, reqheads,
417
reqbody, strlen(reqbody), &rescode, NULL, NULL)){
499
if(!est_url_shuttle(url, node->pxhost, node->pxport, node->timeout, ESTRESLIMSIZE, node->auth,
500
reqheads, reqbody, strlen(reqbody), &rescode, NULL, NULL)){
418
501
node->status = -1;
434
517
CBDATUM *reqbody;
435
518
const char *kbuf;
436
519
char url[ESTPATHBUFSIZ], *vbuf;
437
int rescode, err, ksiz;
438
521
assert(node && id > 0);
440
523
sprintf(url, "%s/out_doc", node->url);
441
524
reqheads = cblistopen();
442
525
if(cbmaprnum(node->heads) > 0){
443
526
cbmapiterinit(node->heads);
444
while((kbuf = cbmapiternext(node->heads, &ksiz)) != NULL){
445
vbuf = cbsprintf("%s: %s", kbuf, cbmapget(node->heads, kbuf, ksiz, NULL));
527
while((kbuf = cbmapiternext(node->heads, NULL)) != NULL){
528
vbuf = cbsprintf("%s: %s", kbuf, cbmapiterval(kbuf, NULL));
446
529
cblistpush(reqheads, vbuf, -1);
450
533
cblistpush(reqheads, "Content-Type: " ESTFORMTYPE, -1);
451
reqbody = cbdatumopen("", 0);
534
reqbody = cbdatumopen(NULL, -1);
452
535
est_datum_printf(reqbody, "id=%d", id);
453
if(!est_url_shuttle(url, node->pxhost, node->pxport, node->timeout, node->auth, reqheads,
454
cbdatumptr(reqbody), cbdatumsize(reqbody), &rescode, NULL, NULL)){
536
if(!est_url_shuttle(url, node->pxhost, node->pxport, node->timeout, ESTRESLIMSIZE, node->auth,
537
reqheads, cbdatumptr(reqbody), cbdatumsize(reqbody),
538
&rescode, NULL, NULL)){
455
539
node->status = -1;
471
555
CBDATUM *reqbody;
472
556
const char *kbuf;
473
557
char url[ESTPATHBUFSIZ], *vbuf;
474
int rescode, err, ksiz;
475
559
assert(node && uri);
477
561
sprintf(url, "%s/out_doc", node->url);
478
562
reqheads = cblistopen();
479
563
if(cbmaprnum(node->heads) > 0){
480
564
cbmapiterinit(node->heads);
481
while((kbuf = cbmapiternext(node->heads, &ksiz)) != NULL){
482
vbuf = cbsprintf("%s: %s", kbuf, cbmapget(node->heads, kbuf, ksiz, NULL));
565
while((kbuf = cbmapiternext(node->heads, NULL)) != NULL){
566
vbuf = cbsprintf("%s: %s", kbuf, cbmapiterval(kbuf, NULL));
483
567
cblistpush(reqheads, vbuf, -1);
487
571
cblistpush(reqheads, "Content-Type: " ESTFORMTYPE, -1);
488
reqbody = cbdatumopen("", 0);
572
reqbody = cbdatumopen(NULL, -1);
489
573
est_datum_printf(reqbody, "uri=%?", uri);
490
if(!est_url_shuttle(url, node->pxhost, node->pxport, node->timeout, node->auth, reqheads,
491
cbdatumptr(reqbody), cbdatumsize(reqbody), &rescode, NULL, NULL)){
574
if(!est_url_shuttle(url, node->pxhost, node->pxport, node->timeout, ESTRESLIMSIZE, node->auth,
575
reqheads, cbdatumptr(reqbody), cbdatumsize(reqbody),
576
&rescode, NULL, NULL)){
492
577
node->status = -1;
515
600
reqheads = cblistopen();
516
601
if(cbmaprnum(node->heads) > 0){
517
602
cbmapiterinit(node->heads);
518
while((kbuf = cbmapiternext(node->heads, &ksiz)) != NULL){
519
vbuf = cbsprintf("%s: %s", kbuf, cbmapget(node->heads, kbuf, ksiz, NULL));
603
while((kbuf = cbmapiternext(node->heads, NULL)) != NULL){
604
vbuf = cbsprintf("%s: %s", kbuf, cbmapiterval(kbuf, NULL));
520
605
cblistpush(reqheads, vbuf, -1);
524
609
cblistpush(reqheads, "Content-Type: " ESTDRAFTTYPE, -1);
525
reqbody = cbdatumopen("", 0);
610
reqbody = cbdatumopen(NULL, -1);
526
611
names = est_doc_attr_names(doc);
527
612
for(i = 0; i < cblistnum(names); i++){
528
613
kbuf = cblistval(names, i, &ksiz);
532
617
cbdatumcat(reqbody, "\n", 1);
534
619
cbdatumcat(reqbody, "\n", 1);
535
if(!est_url_shuttle(url, node->pxhost, node->pxport, node->timeout, node->auth, reqheads,
536
cbdatumptr(reqbody), cbdatumsize(reqbody), &rescode, NULL, NULL)){
620
if(!est_url_shuttle(url, node->pxhost, node->pxport, node->timeout, ESTRESLIMSIZE, node->auth,
621
reqheads, cbdatumptr(reqbody), cbdatumsize(reqbody),
622
&rescode, NULL, NULL)){
537
623
node->status = -1;
555
641
CBDATUM *reqbody, *resbody;
556
642
const char *kbuf;
557
643
char url[ESTPATHBUFSIZ], *vbuf;
558
int rescode, err, ksiz;
559
645
assert(node && id > 0);
561
647
sprintf(url, "%s/get_doc", node->url);
562
648
reqheads = cblistopen();
563
649
if(cbmaprnum(node->heads) > 0){
564
650
cbmapiterinit(node->heads);
565
while((kbuf = cbmapiternext(node->heads, &ksiz)) != NULL){
566
vbuf = cbsprintf("%s: %s", kbuf, cbmapget(node->heads, kbuf, ksiz, NULL));
651
while((kbuf = cbmapiternext(node->heads, NULL)) != NULL){
652
vbuf = cbsprintf("%s: %s", kbuf, cbmapiterval(kbuf, NULL));
567
653
cblistpush(reqheads, vbuf, -1);
571
657
cblistpush(reqheads, "Content-Type: " ESTFORMTYPE, -1);
572
reqbody = cbdatumopen("", 0);
658
reqbody = cbdatumopen(NULL, -1);
573
659
est_datum_printf(reqbody, "id=%d", id);
574
resbody = cbdatumopen("", 0);
575
if(!est_url_shuttle(url, node->pxhost, node->pxport, node->timeout, node->auth, reqheads,
576
cbdatumptr(reqbody), cbdatumsize(reqbody), &rescode, NULL, resbody)){
660
resbody = cbdatumopen(NULL, -1);
661
if(!est_url_shuttle(url, node->pxhost, node->pxport, node->timeout, ESTRESLIMSIZE, node->auth,
662
reqheads, cbdatumptr(reqbody), cbdatumsize(reqbody),
663
&rescode, NULL, resbody)){
577
664
node->status = -1;
596
683
CBDATUM *reqbody, *resbody;
597
684
const char *kbuf;
598
685
char url[ESTPATHBUFSIZ], *vbuf;
599
int rescode, err, ksiz;
600
687
assert(node && uri);
602
689
sprintf(url, "%s/get_doc", node->url);
603
690
reqheads = cblistopen();
604
691
if(cbmaprnum(node->heads) > 0){
605
692
cbmapiterinit(node->heads);
606
while((kbuf = cbmapiternext(node->heads, &ksiz)) != NULL){
607
vbuf = cbsprintf("%s: %s", kbuf, cbmapget(node->heads, kbuf, ksiz, NULL));
693
while((kbuf = cbmapiternext(node->heads, NULL)) != NULL){
694
vbuf = cbsprintf("%s: %s", kbuf, cbmapiterval(kbuf, NULL));
608
695
cblistpush(reqheads, vbuf, -1);
612
699
cblistpush(reqheads, "Content-Type: " ESTFORMTYPE, -1);
613
reqbody = cbdatumopen("", 0);
700
reqbody = cbdatumopen(NULL, -1);
614
701
est_datum_printf(reqbody, "uri=%?", uri);
615
resbody = cbdatumopen("", 0);
616
if(!est_url_shuttle(url, node->pxhost, node->pxport, node->timeout, node->auth, reqheads,
617
cbdatumptr(reqbody), cbdatumsize(reqbody), &rescode, NULL, resbody)){
702
resbody = cbdatumopen(NULL, -1);
703
if(!est_url_shuttle(url, node->pxhost, node->pxport, node->timeout, ESTRESLIMSIZE, node->auth,
704
reqheads, cbdatumptr(reqbody), cbdatumsize(reqbody),
705
&rescode, NULL, resbody)){
618
706
node->status = -1;
636
724
CBDATUM *reqbody, *resbody;
637
725
const char *kbuf;
638
726
char url[ESTPATHBUFSIZ], *vbuf;
639
int rescode, err, ksiz;
640
728
assert(node && id > 0 && name);
642
730
sprintf(url, "%s/get_doc_attr", node->url);
643
731
reqheads = cblistopen();
644
732
if(cbmaprnum(node->heads) > 0){
645
733
cbmapiterinit(node->heads);
646
while((kbuf = cbmapiternext(node->heads, &ksiz)) != NULL){
647
vbuf = cbsprintf("%s: %s", kbuf, cbmapget(node->heads, kbuf, ksiz, NULL));
734
while((kbuf = cbmapiternext(node->heads, NULL)) != NULL){
735
vbuf = cbsprintf("%s: %s", kbuf, cbmapiterval(kbuf, NULL));
648
736
cblistpush(reqheads, vbuf, -1);
652
740
cblistpush(reqheads, "Content-Type: " ESTFORMTYPE, -1);
653
reqbody = cbdatumopen("", 0);
741
reqbody = cbdatumopen(NULL, -1);
654
742
est_datum_printf(reqbody, "id=%d&attr=%?", id, name);
655
resbody = cbdatumopen("", 0);
656
if(!est_url_shuttle(url, node->pxhost, node->pxport, node->timeout, node->auth, reqheads,
657
cbdatumptr(reqbody), cbdatumsize(reqbody), &rescode, NULL, resbody)){
743
resbody = cbdatumopen(NULL, -1);
744
if(!est_url_shuttle(url, node->pxhost, node->pxport, node->timeout, ESTRESLIMSIZE, node->auth,
745
reqheads, cbdatumptr(reqbody), cbdatumsize(reqbody),
746
&rescode, NULL, resbody)){
658
747
node->status = -1;
681
770
CBDATUM *reqbody, *resbody;
682
771
const char *kbuf;
683
772
char url[ESTPATHBUFSIZ], *vbuf;
684
int rescode, err, ksiz;
685
774
assert(node && uri && name);
687
776
sprintf(url, "%s/get_doc_attr", node->url);
688
777
reqheads = cblistopen();
689
778
if(cbmaprnum(node->heads) > 0){
690
779
cbmapiterinit(node->heads);
691
while((kbuf = cbmapiternext(node->heads, &ksiz)) != NULL){
692
vbuf = cbsprintf("%s: %s", kbuf, cbmapget(node->heads, kbuf, ksiz, NULL));
780
while((kbuf = cbmapiternext(node->heads, NULL)) != NULL){
781
vbuf = cbsprintf("%s: %s", kbuf, cbmapiterval(kbuf, NULL));
693
782
cblistpush(reqheads, vbuf, -1);
697
786
cblistpush(reqheads, "Content-Type: " ESTFORMTYPE, -1);
698
reqbody = cbdatumopen("", 0);
787
reqbody = cbdatumopen(NULL, -1);
699
788
est_datum_printf(reqbody, "uri=%?&attr=%?", uri, name);
700
resbody = cbdatumopen("", 0);
701
if(!est_url_shuttle(url, node->pxhost, node->pxport, node->timeout, node->auth, reqheads,
702
cbdatumptr(reqbody), cbdatumsize(reqbody), &rescode, NULL, resbody)){
789
resbody = cbdatumopen(NULL, -1);
790
if(!est_url_shuttle(url, node->pxhost, node->pxport, node->timeout, ESTRESLIMSIZE, node->auth,
791
reqheads, cbdatumptr(reqbody), cbdatumsize(reqbody),
792
&rescode, NULL, resbody)){
703
793
node->status = -1;
729
819
const char *kbuf, *pv;
730
820
char url[ESTPATHBUFSIZ], *vbuf;
731
int i, rescode, err, ksiz;
732
822
assert(node && id > 0);
734
824
sprintf(url, "%s/etch_doc", node->url);
735
825
reqheads = cblistopen();
736
826
if(cbmaprnum(node->heads) > 0){
737
827
cbmapiterinit(node->heads);
738
while((kbuf = cbmapiternext(node->heads, &ksiz)) != NULL){
739
vbuf = cbsprintf("%s: %s", kbuf, cbmapget(node->heads, kbuf, ksiz, NULL));
828
while((kbuf = cbmapiternext(node->heads, NULL)) != NULL){
829
vbuf = cbsprintf("%s: %s", kbuf, cbmapiterval(kbuf, NULL));
740
830
cblistpush(reqheads, vbuf, -1);
744
834
cblistpush(reqheads, "Content-Type: " ESTFORMTYPE, -1);
745
reqbody = cbdatumopen("", 0);
835
reqbody = cbdatumopen(NULL, -1);
746
836
est_datum_printf(reqbody, "id=%d", id);
747
resbody = cbdatumopen("", 0);
748
if(!est_url_shuttle(url, node->pxhost, node->pxport, node->timeout, node->auth, reqheads,
749
cbdatumptr(reqbody), cbdatumsize(reqbody), &rescode, NULL, resbody)){
837
resbody = cbdatumopen(NULL, -1);
838
if(!est_url_shuttle(url, node->pxhost, node->pxport, node->timeout, ESTRESLIMSIZE, node->auth,
839
reqheads, cbdatumptr(reqbody), cbdatumsize(reqbody),
840
&rescode, NULL, resbody)){
750
841
node->status = -1;
782
873
const char *kbuf, *pv;
783
874
char url[ESTPATHBUFSIZ], *vbuf;
784
int i, rescode, err, ksiz;
785
876
assert(node && uri);
787
878
sprintf(url, "%s/etch_doc", node->url);
788
879
reqheads = cblistopen();
789
880
if(cbmaprnum(node->heads) > 0){
790
881
cbmapiterinit(node->heads);
791
while((kbuf = cbmapiternext(node->heads, &ksiz)) != NULL){
792
vbuf = cbsprintf("%s: %s", kbuf, cbmapget(node->heads, kbuf, ksiz, NULL));
882
while((kbuf = cbmapiternext(node->heads, NULL)) != NULL){
883
vbuf = cbsprintf("%s: %s", kbuf, cbmapiterval(kbuf, NULL));
793
884
cblistpush(reqheads, vbuf, -1);
797
888
cblistpush(reqheads, "Content-Type: " ESTFORMTYPE, -1);
798
reqbody = cbdatumopen("", 0);
889
reqbody = cbdatumopen(NULL, -1);
799
890
est_datum_printf(reqbody, "uri=%?", uri);
800
resbody = cbdatumopen("", 0);
801
if(!est_url_shuttle(url, node->pxhost, node->pxport, node->timeout, node->auth, reqheads,
802
cbdatumptr(reqbody), cbdatumsize(reqbody), &rescode, NULL, resbody)){
891
resbody = cbdatumopen(NULL, -1);
892
if(!est_url_shuttle(url, node->pxhost, node->pxport, node->timeout, ESTRESLIMSIZE, node->auth,
893
reqheads, cbdatumptr(reqbody), cbdatumsize(reqbody),
894
&rescode, NULL, resbody)){
803
895
node->status = -1;
833
925
CBDATUM *reqbody, *resbody;
834
926
const char *kbuf;
835
927
char url[ESTPATHBUFSIZ], *vbuf;
836
int rescode, err, ksiz, id;
928
int rescode, err, id;
837
929
assert(node && uri);
839
931
sprintf(url, "%s/uri_to_id", node->url);
840
932
reqheads = cblistopen();
841
933
if(cbmaprnum(node->heads) > 0){
842
934
cbmapiterinit(node->heads);
843
while((kbuf = cbmapiternext(node->heads, &ksiz)) != NULL){
844
vbuf = cbsprintf("%s: %s", kbuf, cbmapget(node->heads, kbuf, ksiz, NULL));
935
while((kbuf = cbmapiternext(node->heads, NULL)) != NULL){
936
vbuf = cbsprintf("%s: %s", kbuf, cbmapiterval(kbuf, NULL));
845
937
cblistpush(reqheads, vbuf, -1);
849
941
cblistpush(reqheads, "Content-Type: " ESTFORMTYPE, -1);
850
reqbody = cbdatumopen("", 0);
942
reqbody = cbdatumopen(NULL, -1);
851
943
est_datum_printf(reqbody, "uri=%?", uri);
852
resbody = cbdatumopen("", 0);
853
if(!est_url_shuttle(url, node->pxhost, node->pxport, node->timeout, node->auth, reqheads,
854
cbdatumptr(reqbody), cbdatumsize(reqbody), &rescode, NULL, resbody)){
944
resbody = cbdatumopen(NULL, -1);
945
if(!est_url_shuttle(url, node->pxhost, node->pxport, node->timeout, ESTRESLIMSIZE, node->auth,
946
reqheads, cbdatumptr(reqbody), cbdatumsize(reqbody),
947
&rescode, NULL, resbody)){
855
948
node->status = -1;
1008
/* Get the usage ratio of the cache of a node. */
1009
double est_node_cache_usage(ESTNODE *node){
1013
char url[ESTPATHBUFSIZ], *vbuf;
1018
sprintf(url, "%s/cacheusage", node->url);
1019
reqheads = cblistopen();
1020
if(cbmaprnum(node->heads) > 0){
1021
cbmapiterinit(node->heads);
1022
while((kbuf = cbmapiternext(node->heads, NULL)) != NULL){
1023
vbuf = cbsprintf("%s: %s", kbuf, cbmapiterval(kbuf, NULL));
1024
cblistpush(reqheads, vbuf, -1);
1028
resbody = cbdatumopen(NULL, -1);
1029
if(!est_url_shuttle(url, node->pxhost, node->pxport, node->timeout, ESTRESLIMSIZE, node->auth,
1030
reqheads, NULL, -1, &rescode, NULL, resbody)){
1035
node->status = rescode;
1036
if(rescode != 200) err = TRUE;
1038
ratio = err ? -1.0 : strtod(cbdatumptr(resbody), NULL);
1039
cbdatumclose(resbody);
1040
cblistclose(reqheads);
1045
/* Get a list of names of administrators of a node. */
1046
const CBLIST *est_node_admins(ESTNODE *node){
1048
if(node->admins) return node->admins;
1049
est_node_set_info(node);
1050
return node->admins;
1054
/* Get a list of names of users of a node. */
1055
const CBLIST *est_node_users(ESTNODE *node){
1057
if(node->users) return node->users;
1058
est_node_set_info(node);
1063
/* Get a list of expressions of links of a node. */
1064
const CBLIST *est_node_links(ESTNODE *node){
1066
if(node->links) return node->links;
1067
est_node_set_info(node);
915
1072
/* Search documents corresponding a condition for a node. */
916
1073
ESTNODERES *est_node_search(ESTNODE *node, ESTCOND *cond, int depth){
917
1074
ESTNODERES *nres;
918
1075
const CBLIST *attrs;
919
1077
CBLIST *reqheads;
920
1078
CBDATUM *reqbody, *resbody;
921
const char *kbuf, *phrase, *order;
1079
const char *kbuf, *phrase, *order, *distinct, *cbuf;
922
1080
char buf[ESTPATHBUFSIZ], *vbuf, *ptr, *pv, *ep;
923
int i, rescode, err, ksiz, max, plen, part, end;
1081
int i, rescode, err, max, plen, part, end;
924
1082
assert(node && cond && depth >= 0);
926
1084
sprintf(buf, "%s/search", node->url);
927
1085
reqheads = cblistopen();
928
1086
if(cbmaprnum(node->heads) > 0){
929
1087
cbmapiterinit(node->heads);
930
while((kbuf = cbmapiternext(node->heads, &ksiz)) != NULL){
931
vbuf = cbsprintf("%s: %s", kbuf, cbmapget(node->heads, kbuf, ksiz, NULL));
1088
while((kbuf = cbmapiternext(node->heads, NULL)) != NULL){
1089
vbuf = cbsprintf("%s: %s", kbuf, cbmapiterval(kbuf, NULL));
932
1090
cblistpush(reqheads, vbuf, -1);
936
1094
cblistpush(reqheads, "Content-Type: " ESTFORMTYPE, -1);
937
reqbody = cbdatumopen("", 0);
1095
reqbody = cbdatumopen(NULL, -1);
938
1096
if((phrase = est_cond_phrase(cond)) != NULL) est_datum_printf(reqbody, "phrase=%?", phrase);
939
1097
if((attrs = est_cond_attrs(cond)) != NULL){
940
1098
for(i = 0; i < cblistnum(attrs); i++){
956
1114
if(cbdatumsize(reqbody) > 0) cbdatumcat(reqbody, "&", 1);
957
1115
est_datum_printf(reqbody, "options=%d", est_cond_options(cond));
1116
est_datum_printf(reqbody, "&auxiliary=%d", est_cond_auxiliary(cond));
1117
if((distinct = est_cond_distinct(cond)) != NULL)
1118
est_datum_printf(reqbody, "&distinct=%?", distinct);
958
1119
est_datum_printf(reqbody, "&depth=%d", depth);
959
1120
est_datum_printf(reqbody, "&wwidth=%d", node->wwidth);
960
1121
est_datum_printf(reqbody, "&hwidth=%d", node->hwidth);
961
1122
est_datum_printf(reqbody, "&awidth=%d", node->awidth);
962
resbody = cbdatumopen("", 0);
963
if(!est_url_shuttle(buf, node->pxhost, node->pxport, node->timeout, node->auth, reqheads,
964
cbdatumptr(reqbody), cbdatumsize(reqbody), &rescode, NULL, resbody)){
1123
est_datum_printf(reqbody, "&skip=%d", est_cond_skip(cond));
1124
est_datum_printf(reqbody, "&mask=%d", est_cond_mask(cond));
1125
resheads = cbmapopenex(ESTMINIBNUM);
1126
resbody = cbdatumopen(NULL, -1);
1127
if(!est_url_shuttle(buf, node->pxhost, node->pxport, node->timeout, ESTRESLIMSIZE, node->auth,
1128
reqheads, cbdatumptr(reqbody), cbdatumsize(reqbody),
1129
&rescode, resheads, resbody)){
965
1130
node->status = -1;
1038
1210
CBDATUM *reqbody, *resbody;
1039
1211
const char *kbuf;
1040
1212
char url[ESTPATHBUFSIZ], *vbuf;
1041
int rescode, err, ksiz;
1042
1214
assert(node && name);
1044
1216
sprintf(url, "%s/_set_user", node->url);
1045
1217
reqheads = cblistopen();
1046
1218
if(cbmaprnum(node->heads) > 0){
1047
1219
cbmapiterinit(node->heads);
1048
while((kbuf = cbmapiternext(node->heads, &ksiz)) != NULL){
1049
vbuf = cbsprintf("%s: %s", kbuf, cbmapget(node->heads, kbuf, ksiz, NULL));
1220
while((kbuf = cbmapiternext(node->heads, NULL)) != NULL){
1221
vbuf = cbsprintf("%s: %s", kbuf, cbmapiterval(kbuf, NULL));
1050
1222
cblistpush(reqheads, vbuf, -1);
1054
1226
cblistpush(reqheads, "Content-Type: " ESTFORMTYPE, -1);
1055
reqbody = cbdatumopen("", 0);
1227
reqbody = cbdatumopen(NULL, -1);
1056
1228
est_datum_printf(reqbody, "name=%?&mode=%d", name, mode);
1057
resbody = cbdatumopen("", 0);
1058
if(!est_url_shuttle(url, node->pxhost, node->pxport, node->timeout, node->auth, reqheads,
1059
cbdatumptr(reqbody), cbdatumsize(reqbody), &rescode, NULL, resbody)){
1229
resbody = cbdatumopen(NULL, -1);
1230
if(!est_url_shuttle(url, node->pxhost, node->pxport, node->timeout, ESTRESLIMSIZE, node->auth,
1231
reqheads, cbdatumptr(reqbody), cbdatumsize(reqbody),
1232
&rescode, NULL, resbody)){
1060
1233
node->status = -1;
1077
1250
CBDATUM *reqbody, *resbody;
1078
1251
const char *kbuf;
1079
1252
char myurl[ESTPATHBUFSIZ], *vbuf;
1080
int rescode, err, ksiz;
1081
1254
assert(node && url && label);
1083
1256
sprintf(myurl, "%s/_set_link", node->url);
1084
1257
reqheads = cblistopen();
1085
1258
if(cbmaprnum(node->heads) > 0){
1086
1259
cbmapiterinit(node->heads);
1087
while((kbuf = cbmapiternext(node->heads, &ksiz)) != NULL){
1088
vbuf = cbsprintf("%s: %s", kbuf, cbmapget(node->heads, kbuf, ksiz, NULL));
1260
while((kbuf = cbmapiternext(node->heads, NULL)) != NULL){
1261
vbuf = cbsprintf("%s: %s", kbuf, cbmapiterval(kbuf, NULL));
1089
1262
cblistpush(reqheads, vbuf, -1);
1093
1266
cblistpush(reqheads, "Content-Type: " ESTFORMTYPE, -1);
1094
reqbody = cbdatumopen("", 0);
1267
reqbody = cbdatumopen(NULL, -1);
1095
1268
if(credit >= 0){
1096
1269
est_datum_printf(reqbody, "url=%?&label=%?&credit=%d", url, label, credit);
1098
1271
est_datum_printf(reqbody, "url=%?&label=%?", url, label);
1100
resbody = cbdatumopen("", 0);
1101
if(!est_url_shuttle(myurl, node->pxhost, node->pxport, node->timeout, node->auth, reqheads,
1102
cbdatumptr(reqbody), cbdatumsize(reqbody), &rescode, NULL, resbody)){
1273
resbody = cbdatumopen(NULL, -1);
1274
if(!est_url_shuttle(myurl, node->pxhost, node->pxport, node->timeout, ESTRESLIMSIZE, node->auth,
1275
reqheads, cbdatumptr(reqbody), cbdatumsize(reqbody),
1276
&rescode, NULL, resbody)){
1103
1277
node->status = -1;
1174
if((info = gethostbyname(name)) != NULL && info->h_addr_list[0]){
1175
addr = inet_ntoa(*(struct in_addr *)info->h_addr_list[0]);
1179
buf = addr ? cbmemdup(addr, -1) : NULL;
1347
buf = est_gethostaddrbyname(name);
1180
1348
if(pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &ost) == 0){
1181
1349
if(pthread_mutex_lock(&est_host_addrs_mutex) == 0){
1182
vsiz = sprintf(vbuf, "%s\t%d", addr ? addr : "", (int)time(NULL));
1350
vsiz = sprintf(vbuf, "%s\t%d", buf ? buf : "", (int)time(NULL));
1183
1351
cbmapput(est_host_addrs, name, nsiz, vbuf, vsiz, TRUE);
1184
1352
if(cbmaprnum(est_host_addrs) > ESTDNHOLDNUM){
1185
1353
cbmapiterinit(est_host_addrs);
1794
/* Get the modification date of a node result object. */
1795
time_t est_noderes_mdate(ESTNODERES *nres){
1625
1802
/*************************************************************************************************
1626
1803
* private objects
1627
1804
*************************************************************************************************/
1807
/* Get the primary address of a host name.
1808
`name' specifies the name of a host.
1809
The return value is the address of a host or `NULL' if failure. Because the region of the
1810
return value is allocated with the `malloc' call, it should be released with the `free' call
1811
if it is no longer in use. */
1812
static char *est_gethostaddrbyname(const char *name){
1813
#if defined(_SYS_LINUX_)
1814
struct hostent infobuf, *info;
1815
char buf[ESTIOBUFSIZ], *addr;
1817
if(gethostbyname_r(name, &infobuf, buf, ESTIOBUFSIZ, &info, &ecode) == 0 && info){
1818
addr = cbmemdup(inet_ntoa(*(struct in_addr *)info->h_addr_list[0]), -1);
1824
static pthread_mutex_t mymutex = PTHREAD_MUTEX_INITIALIZER;
1825
struct hostent *info;
1829
if(pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &ost) != 0) return NULL;
1830
if(pthread_mutex_lock(&mymutex) != 0){
1831
pthread_setcancelstate(ost, NULL);
1834
if((info = gethostbyname(name)) != NULL && info->h_addr_list[0]){
1835
addr = cbmemdup(inet_ntoa(*(struct in_addr *)info->h_addr_list[0]), -1);
1839
pthread_mutex_unlock(&mymutex);
1840
pthread_setcancelstate(ost, NULL);
1630
1846
/* Close a socket.
1631
1847
`sock' specifies a socket.
1632
1848
The return value is 0 if success, else it is -1. */
1674
1890
CBDATUM *resbody, *datum;
1675
1891
const char *url, *pxhost, *auth, *reqbody, *tmp, *scheme, *host, *path, *query, *rp;
1676
1892
char *addr, *enc, iobuf[ESTIOBUFSIZ], name[ESTIOBUFSIZ], *pv, *zbuf;
1677
int i, pxport, rbsiz, *rescodep, port, sock, *sp, size, nsiz, defl, zsiz;
1893
int i, pxport, limsize, rbsiz, *rescodep, port, sock, *sp, size, nsiz, defl, zsiz;
1679
1895
url = ((TARGSHUTTLE *)targ)->url;
1680
1896
pxhost = ((TARGSHUTTLE *)targ)->pxhost;
1681
1897
pxport = ((TARGSHUTTLE *)targ)->pxport;
1898
limsize = ((TARGSHUTTLE *)targ)->limsize;
1682
1899
auth = ((TARGSHUTTLE *)targ)->auth;
1683
1900
reqheads = ((TARGSHUTTLE *)targ)->reqheads;
1684
1901
reqbody = ((TARGSHUTTLE *)targ)->reqbody;
1786
2003
if(cbstrfwimatch(iobuf, "content-encoding:") && strstr(iobuf + 17, "deflate")) defl = TRUE;
2005
if(limsize < 0) limsize = INT_MAX;
1788
2006
while((size = recv(sock, iobuf, ESTIOBUFSIZ, 0)) > 0){
1789
if(resbody) cbdatumcat(resbody, iobuf, size);
2007
if(resbody && cbdatumsize(resbody) <= limsize) cbdatumcat(resbody, iobuf, size);
1791
if(defl && (zbuf = est_inflate(cbdatumptr(resbody), cbdatumsize(resbody), &zsiz)) != NULL){
1792
cbdatumsetsize(resbody, 0);
1793
cbdatumcat(resbody, zbuf, zsiz);
2009
if(defl && (zbuf = est_inflate(cbdatumptr(resbody), cbdatumsize(resbody), &zsiz, 0)) != NULL){
2010
cbdatumsetbuf(resbody, zbuf, zsiz);
1796
2012
pthread_cleanup_pop(1);
1797
2013
pthread_cleanup_pop(1);
1817
2033
static int est_node_set_info(ESTNODE *node){
1818
2034
CBLIST *reqheads, *elems;
1819
2035
CBDATUM *resbody;
1820
const char *kbuf, *ptr;
1821
char url[ESTPATHBUFSIZ], *vbuf, *pv;
1822
int rescode, err, ksiz;
2036
const char *kbuf, *ptr, *pv, *tv;
2037
char url[ESTPATHBUFSIZ], *vbuf;
2038
int rescode, err, tc;
1825
2041
sprintf(url, "%s/inform", node->url);
1826
2042
reqheads = cblistopen();
1827
2043
if(cbmaprnum(node->heads) > 0){
1828
2044
cbmapiterinit(node->heads);
1829
while((kbuf = cbmapiternext(node->heads, &ksiz)) != NULL){
1830
vbuf = cbsprintf("%s: %s", kbuf, cbmapget(node->heads, kbuf, ksiz, NULL));
2045
while((kbuf = cbmapiternext(node->heads, NULL)) != NULL){
2046
vbuf = cbsprintf("%s: %s", kbuf, cbmapiterval(kbuf, NULL));
1831
2047
cblistpush(reqheads, vbuf, -1);
1835
2051
node->dnum = -1;
1836
2052
node->wnum = -1;
1837
2053
node->size = -1.0;
1838
resbody = cbdatumopen("", 0);
1839
if(!est_url_shuttle(url, node->pxhost, node->pxport, node->timeout, node->auth, reqheads,
1840
NULL, -1, &rescode, NULL, resbody)){
2055
cblistclose(node->admins);
2056
node->admins = NULL;
2059
cblistclose(node->users);
2063
cblistclose(node->links);
2066
resbody = cbdatumopen(NULL, -1);
2067
if(!est_url_shuttle(url, node->pxhost, node->pxport, node->timeout, ESTRESLIMSIZE, node->auth,
2068
reqheads, NULL, -1, &rescode, NULL, resbody)){
1841
2069
node->status = -1;
1914
2180
reqheads = cblistopen();
1915
2181
if(cbmaprnum(node->heads) > 0){
1916
2182
cbmapiterinit(node->heads);
1917
while((kbuf = cbmapiternext(node->heads, &ksiz)) != NULL){
1918
vbuf = cbsprintf("%s: %s", kbuf, cbmapget(node->heads, kbuf, ksiz, NULL));
2183
while((kbuf = cbmapiternext(node->heads, NULL)) != NULL){
2184
vbuf = cbsprintf("%s: %s", kbuf, cbmapiterval(kbuf, NULL));
1919
2185
cblistpush(reqheads, vbuf, -1);
1923
2189
cblistpush(reqheads, "Content-Type: " ESTFORMTYPE, -1);
1924
reqbody = cbdatumopen("", 0);
2190
reqbody = cbdatumopen(NULL, -1);
1925
2191
est_datum_printf(reqbody, "max=%d", ESTITERUNIT);
1926
2192
if(node->iprev) est_datum_printf(reqbody, "&prev=%?", node->iprev);
1927
resbody = cbdatumopen("", 0);
1928
if(!est_url_shuttle(url, node->pxhost, node->pxport, node->timeout, node->auth, reqheads,
1929
cbdatumptr(reqbody), cbdatumsize(reqbody), &rescode, NULL, resbody)){
2193
resbody = cbdatumopen(NULL, -1);
2194
if(!est_url_shuttle(url, node->pxhost, node->pxport, node->timeout, ESTRESLIMSIZE, node->auth,
2195
reqheads, cbdatumptr(reqbody), cbdatumsize(reqbody),
2196
&rescode, NULL, resbody)){
1930
2197
node->status = -1;