~ubuntu-branches/ubuntu/trusty/hyperestraier/trusty-proposed

« back to all changes in this revision

Viewing changes to estnode.c

  • Committer: Bazaar Package Importer
  • Author(s): Steve Langasek
  • Date: 2006-11-14 05:28:32 UTC
  • mfrom: (2.1.4 feisty)
  • Revision ID: james.westby@ubuntu.com-20061114052832-0lzqzcefn8mt4yqe
Tags: 1.4.9-1.1
* Non-maintainer upload.
* High-urgency upload for RC bugfix.
* Set HOME=$(CURDIR)/junkhome when building, otherwise the package build
  will incorrectly look for headers there -- and fail when the directory
  exists and is unreadable, as happens sometimes on sudo-using
  autobuilders!

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*************************************************************************************************
2
2
 * Implementation of the node API
3
 
 *                                                      Copyright (C) 2004-2005 Mikio Hirabayashi
 
3
 *                                                      Copyright (C) 2004-2006 Mikio Hirabayashi
4
4
 * This file is part of Hyper Estraier.
5
5
 * Hyper Estraier is free software; you can redistribute it and/or modify it under the terms of
6
6
 * the GNU Lesser General Public License as published by the Free Software Foundation; either
34
34
#define ESTVAXVECNUM   256               /* maximum number of vector dimensions */
35
35
#define ESTECLPMAX     64                /* maximum number of documents to be eclipsed */
36
36
#define ESTITERUNIT    256               /* retrieval unit number of iterator */
 
37
#define ESTRESLIMSIZE  (1048576*128)     /* limitation of the entity body of response */
37
38
#define ESTWWIDTHDEF   480               /* default of whole width of a snippet */
38
39
#define ESTHWIDTHDEF   96                /* default of head width of a snippet */
39
40
#define ESTAWIDTHDEF   96                /* default of around width of a snippet */
46
47
  const char *url;                       /* URL */
47
48
  const char *pxhost;                    /* host name of proxy */
48
49
  int pxport;                            /* port number of proxy */
 
50
  int limsize;                           /* limitation of the response body */
49
51
  const char *auth;                      /* authority */
50
52
  const CBLIST *reqheads;                /* request headers */
51
53
  const char *reqbody;                   /* request body */
57
59
 
58
60
 
59
61
/* private function prototypes */
 
62
static char *est_gethostaddrbyname(const char *name);
60
63
static int est_sock_close(int sock);
61
64
static int est_inet_aton(const char *cp, struct in_addr *inp);
62
65
static void *est_url_shuttle_impl(void *targ);
74
77
 *************************************************************************************************/
75
78
 
76
79
 
77
 
/* Cache of host addresses */
 
80
/* Cache of host addresses. */
78
81
CBMAP *est_host_addrs = NULL;
79
82
int est_host_attrs_cnt = 0;
80
83
pthread_mutex_t est_host_addrs_mutex = PTHREAD_MUTEX_INITIALIZER;
289
292
}
290
293
 
291
294
 
292
 
/* Get the keyword vector of a result document object. */
293
 
const char *est_resdoc_vector(ESTRESDOC *rdoc){
 
295
/* Get keywords of a result document object. */
 
296
const char *est_resdoc_keywords(ESTRESDOC *rdoc){
294
297
  const char *vbuf;
295
298
  assert(rdoc);
296
299
  vbuf = cbmapget(rdoc->attrs, ESTDCNTLVECTOR, -1, NULL);
337
340
  node->dnum = -1;
338
341
  node->wnum = -1;
339
342
  node->size = -1.0;
 
343
  node->admins = NULL;
 
344
  node->users = NULL;
 
345
  node->links = NULL;
340
346
  node->wwidth = ESTWWIDTHDEF;
341
347
  node->hwidth = ESTHWIDTHDEF;
342
348
  node->awidth = ESTAWIDTHDEF;
353
359
  assert(node);
354
360
  cbmapclose(node->heads);
355
361
  est_node_iter_delete(node);
 
362
  if(node->links) cblistclose(node->links);
 
363
  if(node->users) cblistclose(node->users);
 
364
  if(node->admins) cblistclose(node->admins);
356
365
  free(node->label);
357
366
  free(node->name);
358
367
  free(node->auth);
393
402
}
394
403
 
395
404
 
 
405
/* Synchronize updating contents of the database of a node. */
 
406
int est_node_sync(ESTNODE *node){
 
407
  CBLIST *reqheads;
 
408
  CBDATUM *reqbody;
 
409
  const char *kbuf;
 
410
  char url[ESTPATHBUFSIZ], *vbuf;
 
411
  int rescode, err;
 
412
  assert(node);
 
413
  err = FALSE;
 
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);
 
421
      free(vbuf);
 
422
    }
 
423
  }
 
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)){
 
429
    node->status = -1;
 
430
    err = TRUE;
 
431
  }
 
432
  if(!err){
 
433
    node->status = rescode;
 
434
    if(rescode != 200) err = TRUE;
 
435
  }
 
436
  cbdatumclose(reqbody);
 
437
  cblistclose(reqheads);
 
438
  return err ? FALSE : TRUE;
 
439
}
 
440
 
 
441
 
 
442
/* Optimize the database of a node. */
 
443
int est_node_optimize(ESTNODE *node){
 
444
  CBLIST *reqheads;
 
445
  CBDATUM *reqbody;
 
446
  const char *kbuf;
 
447
  char url[ESTPATHBUFSIZ], *vbuf;
 
448
  int rescode, err;
 
449
  assert(node);
 
450
  err = FALSE;
 
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);
 
458
      free(vbuf);
 
459
    }
 
460
  }
 
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)){
 
466
    node->status = -1;
 
467
    err = TRUE;
 
468
  }
 
469
  if(!err){
 
470
    node->status = rescode;
 
471
    if(rescode != 200) err = TRUE;
 
472
  }
 
473
  cbdatumclose(reqbody);
 
474
  cblistclose(reqheads);
 
475
  return err ? FALSE : TRUE;
 
476
}
 
477
 
 
478
 
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;
 
484
  int rescode, err;
402
485
  assert(node && doc);
403
486
  err = FALSE;
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);
411
494
      free(vbuf);
412
495
    }
413
496
  }
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;
419
502
    err = TRUE;
420
503
  }
434
517
  CBDATUM *reqbody;
435
518
  const char *kbuf;
436
519
  char url[ESTPATHBUFSIZ], *vbuf;
437
 
  int rescode, err, ksiz;
 
520
  int rescode, err;
438
521
  assert(node && id > 0);
439
522
  err = FALSE;
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);
447
530
      free(vbuf);
448
531
    }
449
532
  }
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;
456
540
    err = TRUE;
457
541
  }
471
555
  CBDATUM *reqbody;
472
556
  const char *kbuf;
473
557
  char url[ESTPATHBUFSIZ], *vbuf;
474
 
  int rescode, err, ksiz;
 
558
  int rescode, err;
475
559
  assert(node && uri);
476
560
  err = FALSE;
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);
484
568
      free(vbuf);
485
569
    }
486
570
  }
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;
493
578
    err = TRUE;
494
579
  }
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);
521
606
      free(vbuf);
522
607
    }
523
608
  }
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);
533
618
  }
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;
538
624
    err = TRUE;
539
625
  }
555
641
  CBDATUM *reqbody, *resbody;
556
642
  const char *kbuf;
557
643
  char url[ESTPATHBUFSIZ], *vbuf;
558
 
  int rescode, err, ksiz;
 
644
  int rescode, err;
559
645
  assert(node && id > 0);
560
646
  err = FALSE;
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);
568
654
      free(vbuf);
569
655
    }
570
656
  }
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;
578
665
    err = TRUE;
579
666
  }
596
683
  CBDATUM *reqbody, *resbody;
597
684
  const char *kbuf;
598
685
  char url[ESTPATHBUFSIZ], *vbuf;
599
 
  int rescode, err, ksiz;
 
686
  int rescode, err;
600
687
  assert(node && uri);
601
688
  err = FALSE;
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);
609
696
      free(vbuf);
610
697
    }
611
698
  }
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;
619
707
    err = TRUE;
620
708
  }
636
724
  CBDATUM *reqbody, *resbody;
637
725
  const char *kbuf;
638
726
  char url[ESTPATHBUFSIZ], *vbuf;
639
 
  int rescode, err, ksiz;
 
727
  int rescode, err;
640
728
  assert(node && id > 0 && name);
641
729
  err = FALSE;
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);
649
737
      free(vbuf);
650
738
    }
651
739
  }
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;
659
748
    err = TRUE;
660
749
  }
681
770
  CBDATUM *reqbody, *resbody;
682
771
  const char *kbuf;
683
772
  char url[ESTPATHBUFSIZ], *vbuf;
684
 
  int rescode, err, ksiz;
 
773
  int rescode, err;
685
774
  assert(node && uri && name);
686
775
  err = FALSE;
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);
694
783
      free(vbuf);
695
784
    }
696
785
  }
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;
704
794
    err = TRUE;
705
795
  }
728
818
  CBLIST *lines;
729
819
  const char *kbuf, *pv;
730
820
  char url[ESTPATHBUFSIZ], *vbuf;
731
 
  int i, rescode, err, ksiz;
 
821
  int i, rescode, err;
732
822
  assert(node && id > 0);
733
823
  err = FALSE;
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);
741
831
      free(vbuf);
742
832
    }
743
833
  }
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;
751
842
    err = TRUE;
752
843
  }
781
872
  CBLIST *lines;
782
873
  const char *kbuf, *pv;
783
874
  char url[ESTPATHBUFSIZ], *vbuf;
784
 
  int i, rescode, err, ksiz;
 
875
  int i, rescode, err;
785
876
  assert(node && uri);
786
877
  err = FALSE;
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);
794
885
      free(vbuf);
795
886
    }
796
887
  }
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;
804
896
    err = TRUE;
805
897
  }
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);
838
930
  err = FALSE;
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);
846
938
      free(vbuf);
847
939
    }
848
940
  }
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;
856
949
    err = TRUE;
857
950
  }
912
1005
}
913
1006
 
914
1007
 
 
1008
/* Get the usage ratio of the cache of a node. */
 
1009
double est_node_cache_usage(ESTNODE *node){
 
1010
  CBLIST *reqheads;
 
1011
  CBDATUM *resbody;
 
1012
  const char *kbuf;
 
1013
  char url[ESTPATHBUFSIZ], *vbuf;
 
1014
  int rescode, err;
 
1015
  double ratio;
 
1016
  assert(node);
 
1017
  err = FALSE;
 
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);
 
1025
      free(vbuf);
 
1026
    }
 
1027
  }
 
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)){
 
1031
    node->status = -1;
 
1032
    err = TRUE;
 
1033
  }
 
1034
  if(!err){
 
1035
    node->status = rescode;
 
1036
    if(rescode != 200) err = TRUE;
 
1037
  }
 
1038
  ratio = err ? -1.0 : strtod(cbdatumptr(resbody), NULL);
 
1039
  cbdatumclose(resbody);
 
1040
  cblistclose(reqheads);
 
1041
  return ratio;
 
1042
}
 
1043
 
 
1044
 
 
1045
/* Get a list of names of administrators of a node. */
 
1046
const CBLIST *est_node_admins(ESTNODE *node){
 
1047
  assert(node);
 
1048
  if(node->admins) return node->admins;
 
1049
  est_node_set_info(node);
 
1050
  return node->admins;
 
1051
}
 
1052
 
 
1053
 
 
1054
/* Get a list of names of users of a node. */
 
1055
const CBLIST *est_node_users(ESTNODE *node){
 
1056
  assert(node);
 
1057
  if(node->users) return node->users;
 
1058
  est_node_set_info(node);
 
1059
  return node->users;
 
1060
}
 
1061
 
 
1062
 
 
1063
/* Get a list of expressions of links of a node. */
 
1064
const CBLIST *est_node_links(ESTNODE *node){
 
1065
  assert(node);
 
1066
  if(node->links) return node->links;
 
1067
  est_node_set_info(node);
 
1068
  return node->links;
 
1069
}
 
1070
 
 
1071
 
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;
 
1076
  CBMAP *resheads;
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);
925
1083
  err = FALSE;
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);
933
1091
      free(vbuf);
934
1092
    }
935
1093
  }
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++){
955
1113
  }
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;
966
1131
    err = TRUE;
967
1132
  }
971
1136
  }
972
1137
  if(err){
973
1138
    cbdatumclose(resbody);
 
1139
    cbmapclose(resheads);
974
1140
    cbdatumclose(reqbody);
975
1141
    cblistclose(reqheads);
976
1142
    return NULL;
1013
1179
    }
1014
1180
  }
1015
1181
  free(ptr);
 
1182
  if((cbuf = cbmapget(resheads, "last-modified", -1, NULL)) != NULL){
 
1183
    nres->mdate = cbstrmktime(cbuf);
 
1184
  } else {
 
1185
    nres->mdate = time(NULL);
 
1186
  }
 
1187
  cbmapclose(resheads);
1016
1188
  cbdatumclose(reqbody);
1017
1189
  cblistclose(reqheads);
1018
1190
  if(!end){
1038
1210
  CBDATUM *reqbody, *resbody;
1039
1211
  const char *kbuf;
1040
1212
  char url[ESTPATHBUFSIZ], *vbuf;
1041
 
  int rescode, err, ksiz;
 
1213
  int rescode, err;
1042
1214
  assert(node && name);
1043
1215
  err = FALSE;
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);
1051
1223
      free(vbuf);
1052
1224
    }
1053
1225
  }
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;
1061
1234
    err = TRUE;
1062
1235
  }
1077
1250
  CBDATUM *reqbody, *resbody;
1078
1251
  const char *kbuf;
1079
1252
  char myurl[ESTPATHBUFSIZ], *vbuf;
1080
 
  int rescode, err, ksiz;
 
1253
  int rescode, err;
1081
1254
  assert(node && url && label);
1082
1255
  err = FALSE;
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);
1090
1263
      free(vbuf);
1091
1264
    }
1092
1265
  }
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);
1097
1270
  } else {
1098
1271
    est_datum_printf(reqbody, "url=%?&label=%?", url, label);
1099
1272
  }
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;
1104
1278
    err = TRUE;
1105
1279
  }
1136
1310
 
1137
1311
/* Get the address of a host. */
1138
1312
char *est_get_host_addr(const char *name){
1139
 
  struct hostent *info;
1140
1313
  const char *addr;
1141
1314
  char *buf, *pv, vbuf[64];
1142
1315
  int i, ost, nsiz, asiz, vsiz;
1171
1344
    free(buf);
1172
1345
    return NULL;
1173
1346
  }
1174
 
  if((info = gethostbyname(name)) != NULL && info->h_addr_list[0]){
1175
 
    addr = inet_ntoa(*(struct in_addr *)info->h_addr_list[0]);
1176
 
  } else {
1177
 
    addr = NULL;
1178
 
  }
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);
1466
1634
 
1467
1635
 
1468
1636
/* Perform an interaction of a URL. */
1469
 
int est_url_shuttle(const char *url, const char *pxhost, int pxport, int outsec,
 
1637
int est_url_shuttle(const char *url, const char *pxhost, int pxport, int outsec, int limsize,
1470
1638
                    const char *auth, const CBLIST *reqheads, const char *reqbody, int rbsiz,
1471
1639
                    int *rescodep, CBMAP *resheads, CBDATUM *resbody){
1472
1640
  pthread_t th;
1483
1651
  targ.url = url;
1484
1652
  targ.pxhost = pxhost;
1485
1653
  targ.pxport = pxport;
 
1654
  targ.limsize = limsize;
1486
1655
  targ.auth = auth;
1487
1656
  targ.reqheads = reqheads;
1488
1657
  targ.reqbody = reqbody;
1577
1746
  nres->survivors = NULL;
1578
1747
  nres->snum = 0;
1579
1748
  nres->hints = cbmapopenex(ESTMINIBNUM);
 
1749
  nres->mdate = 0;
1580
1750
  return nres;
1581
1751
}
1582
1752
 
1621
1791
}
1622
1792
 
1623
1793
 
 
1794
/* Get the modification date of a node result object. */
 
1795
time_t est_noderes_mdate(ESTNODERES *nres){
 
1796
  assert(nres);
 
1797
  return nres->mdate;
 
1798
}
 
1799
 
 
1800
 
1624
1801
 
1625
1802
/*************************************************************************************************
1626
1803
 * private objects
1627
1804
 *************************************************************************************************/
1628
1805
 
1629
1806
 
 
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;
 
1816
  int ecode;
 
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);
 
1819
  } else {
 
1820
    addr = NULL;
 
1821
  }
 
1822
  return addr;
 
1823
#else
 
1824
  static pthread_mutex_t mymutex = PTHREAD_MUTEX_INITIALIZER;
 
1825
  struct hostent *info;
 
1826
  char *addr;
 
1827
  int ost;
 
1828
  assert(name);
 
1829
  if(pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &ost) != 0) return NULL;
 
1830
  if(pthread_mutex_lock(&mymutex) != 0){
 
1831
    pthread_setcancelstate(ost, NULL);
 
1832
    return NULL;
 
1833
  }
 
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);
 
1836
  } else {
 
1837
    addr = NULL;
 
1838
  }
 
1839
  pthread_mutex_unlock(&mymutex);
 
1840
  pthread_setcancelstate(ost, NULL);
 
1841
  return addr;
 
1842
#endif
 
1843
}
 
1844
 
 
1845
 
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;
1678
1894
  assert(targ);
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;
1712
1929
  sp = cbmalloc(sizeof(int));
1713
1930
  *sp = sock;
1714
1931
  pthread_cleanup_push((void (*)(void *))est_sockpt_down, sp);
1715
 
  datum = cbdatumopen("", 0);
 
1932
  datum = cbdatumopen(NULL, -1);
1716
1933
  pthread_cleanup_push((void (*)(void *))cbdatumclose, datum);
1717
1934
  if(pxhost){
1718
1935
    est_datum_printf(datum, "%s %s HTTP/1.0\r\n", reqbody ? "POST" : "GET", url);
1785
2002
    }
1786
2003
    if(cbstrfwimatch(iobuf, "content-encoding:") && strstr(iobuf + 17, "deflate")) defl = TRUE;
1787
2004
  }
 
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);
1790
2008
  }
1791
 
  if(defl && (zbuf = est_inflate(cbdatumptr(resbody), cbdatumsize(resbody), &zsiz)) != NULL){
1792
 
    cbdatumsetsize(resbody, 0);
1793
 
    cbdatumcat(resbody, zbuf, zsiz);
1794
 
    free(zbuf);
 
2009
  if(defl && (zbuf = est_inflate(cbdatumptr(resbody), cbdatumsize(resbody), &zsiz, 0)) != NULL){
 
2010
    cbdatumsetbuf(resbody, zbuf, zsiz);
1795
2011
  }
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;
1823
2039
  assert(node);
1824
2040
  err = FALSE;
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);
1832
2048
      free(vbuf);
1833
2049
    }
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)){
 
2054
  if(node->admins){
 
2055
    cblistclose(node->admins);
 
2056
    node->admins = NULL;
 
2057
  }
 
2058
  if(node->users){
 
2059
    cblistclose(node->users);
 
2060
    node->users = NULL;
 
2061
  }
 
2062
  if(node->links){
 
2063
    cblistclose(node->links);
 
2064
    node->links = NULL;
 
2065
  }
 
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;
1842
2070
    err = TRUE;
1843
2071
  }
1867
2095
          node->size = -1.0;
1868
2096
          err = TRUE;
1869
2097
        }
 
2098
        ptr = pv;
 
2099
        ptr++;
 
2100
        if(*ptr == '\n') ptr++;
 
2101
        node->admins = cblistopen();
 
2102
        while((pv = strchr(ptr, '\n')) != NULL){
 
2103
          if(ptr == pv){
 
2104
            ptr = pv + 1;
 
2105
            break;
 
2106
          }
 
2107
          cblistpush(node->admins, ptr, pv - ptr);
 
2108
          ptr = pv + 1;
 
2109
        }
 
2110
        if(*pv == '\n') pv++;
 
2111
        node->users = cblistopen();
 
2112
        while((pv = strchr(ptr, '\n')) != NULL){
 
2113
          if(ptr == pv){
 
2114
            ptr = pv + 1;
 
2115
            break;
 
2116
          }
 
2117
          cblistpush(node->users, ptr, pv - ptr);
 
2118
          ptr = pv + 1;
 
2119
        }
 
2120
        if(*pv == '\n') pv++;
 
2121
        node->links = cblistopen();
 
2122
        while((pv = strchr(ptr, '\n')) != NULL){
 
2123
          if(ptr == pv){
 
2124
            ptr = pv + 1;
 
2125
            break;
 
2126
          }
 
2127
          tc = 0;
 
2128
          tv = ptr;
 
2129
          while(tv < pv){
 
2130
            if(*tv == '\t') tc++;
 
2131
            tv++;
 
2132
          }
 
2133
          if(tc == 2) cblistpush(node->links, ptr, pv - ptr);
 
2134
          ptr = pv + 1;
 
2135
        }
1870
2136
      } else {
1871
2137
        err = TRUE;
1872
2138
      }
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);
1920
2186
      free(vbuf);
1921
2187
    }
1922
2188
  }
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;
1931
2198
    err = TRUE;
1932
2199
  }