~n-muench/ubuntu/oneiric/open-vm-tools/open-vm-tools.fix-836277

« back to all changes in this revision

Viewing changes to lib/rpcIn/rpcin.c

  • Committer: Bazaar Package Importer
  • Author(s): Devid Antonio Filoni
  • Date: 2008-08-15 21:21:40 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20080815212140-05fhxj8wroosysmj
Tags: 2008.08.08-109361-1ubuntu1
* Merge from Debian unstable (LP: #258393), remaining Ubuntu change:
  - add ubuntu_toolchain_FTBFS.dpatch patch, fix FTBFS
* Update ubuntu_toolchain_FTBFS.dpatch patch for the new version.

Show diffs side-by-side

added added

removed removed

Lines of Context:
59
59
 * The RpcIn object
60
60
 */
61
61
 
 
62
typedef enum {
 
63
    RPCIN_CB_OLD,
 
64
    RPCIN_CB_NEW
 
65
} RpcInCallbackType;
 
66
 
 
67
 
62
68
/* The list of TCLO command callbacks we support */
63
69
typedef struct RpcInCallbackList {
64
70
   const char *name;
65
71
   size_t length; /* Length of name so we don't have to strlen a lot */
66
 
   RpcIn_Callback function;
 
72
   RpcInCallbackType type;
 
73
   union {
 
74
      RpcIn_CallbackOld oldCb;
 
75
      RpcIn_Callback newCb;
 
76
   } callback;
67
77
   struct RpcInCallbackList *next;
68
78
   void *clientData;
69
79
} RpcInCallbackList;
110
120
 */
111
121
 
112
122
static Bool
113
 
RpcInPingCallback(char const **result, // OUT
114
 
                  size_t *resultLen,   // OUT
115
 
                  const char *name,    // IN
116
 
                  const char *args,    // IN
117
 
                  size_t argsSize,     // IN
118
 
                  void *clientData)    // IN
 
123
RpcInPingCallback(RpcInData *data)  // IN
119
124
{
120
 
   return RpcIn_SetRetVals(result, resultLen, "", TRUE);
 
125
   return RPCIN_SETRETVALS(data, "", TRUE);
121
126
}
122
127
 
123
128
 
374
379
      unsigned int status;
375
380
      char const *statusStr;
376
381
      unsigned int statusLen;
377
 
      char const *result;
 
382
      char *result;
378
383
      size_t resultLen;
379
384
      char *cmd;
380
385
      unsigned int index = 0;
 
386
      Bool freeResult = FALSE;
381
387
      RpcInCallbackList *cb = NULL;
382
388
 
383
389
      /*
390
396
         free(cmd);
391
397
         if (cb) {
392
398
            result = NULL;
393
 
            status = cb->function(&result, &resultLen, cb->name,
394
 
                                  reply + cb->length, repLen - cb->length,
395
 
                                  cb->clientData);
 
399
            if (cb->type == RPCIN_CB_OLD) {
 
400
               status = cb->callback.oldCb((char const **) &result, &resultLen, cb->name,
 
401
                                           reply + cb->length, repLen - cb->length,
 
402
                                           cb->clientData);
 
403
            } else {
 
404
               RpcInData data = { cb->name,
 
405
                                  reply + cb->length,
 
406
                                  repLen - cb->length,
 
407
                                  NULL,
 
408
                                  0,
 
409
                                  FALSE,
 
410
                                  cb->clientData };
 
411
               status = cb->callback.newCb(&data);
 
412
               result = data.result;
 
413
               resultLen = data.resultLen;
 
414
               freeResult = data.freeResult;
 
415
            }
396
416
 
397
417
            ASSERT(result);
398
418
         } else {
422
442
      memcpy(in->last_result, statusStr, statusLen);
423
443
      memcpy(in->last_result + statusLen, result, resultLen);
424
444
      in->last_resultLen = statusLen + resultLen;
 
445
      
 
446
      if (freeResult) {
 
447
         free(result);
 
448
      }
425
449
 
426
450
#if 0 /* Costly in non-debug cases --hpreg */
427
451
      if (strlen(reply) <= 128) {
539
563
 
540
564
   /* Register the 'reset' handler */
541
565
   if (resetCallback) {
542
 
      RpcIn_RegisterCallback(in, "reset", resetCallback, resetClientData);
 
566
      RpcIn_RegisterCallbackEx(in, "reset", resetCallback, resetClientData);
543
567
   }
544
568
 
545
 
   RpcIn_RegisterCallback(in, "ping", RpcInPingCallback, NULL);
 
569
   RpcIn_RegisterCallbackEx(in, "ping", RpcInPingCallback, NULL);
546
570
 
547
571
   return TRUE;
548
572
 
612
636
 *
613
637
 * RpcIn_RegisterCallback --
614
638
 *
615
 
 *      Register a callback to happen when a TCLO message is
 
639
 *      Register an old-style callback to happen when a TCLO message is
616
640
 *      received. When a TCLO message beginning with 'name' is
617
641
 *      sent, the callback will be called with: the cmd name, the args
618
642
 *      (starting with the char directly after the cmd name; that's why
631
655
void
632
656
RpcIn_RegisterCallback(RpcIn *in,               // IN
633
657
                       const char *name,        // IN
634
 
                       RpcIn_Callback callback, // IN
 
658
                       RpcIn_CallbackOld cb,    // IN
635
659
                       void *clientData)        // IN
636
660
{
637
661
   RpcInCallbackList *p;
640
664
 
641
665
   ASSERT(in);
642
666
   ASSERT(name);
643
 
   ASSERT(callback);
644
 
   ASSERT(RpcInLookupCallback(in, name) == NULL); // not there yet
645
 
 
646
 
   p = (RpcInCallbackList *) malloc(sizeof(RpcInCallbackList));
647
 
   ASSERT_NOT_IMPLEMENTED(p);
648
 
 
649
 
   p->length = strlen(name);
650
 
   p->name = strdup(name);
651
 
   p->function = callback;
 
667
   ASSERT(cb);
 
668
   ASSERT(RpcInLookupCallback(in, name) == NULL); // not there yet
 
669
 
 
670
   p = (RpcInCallbackList *) malloc(sizeof(RpcInCallbackList));
 
671
   ASSERT_NOT_IMPLEMENTED(p);
 
672
 
 
673
   p->length = strlen(name);
 
674
   p->name = strdup(name);
 
675
   p->type = RPCIN_CB_OLD;
 
676
   p->callback.oldCb = cb;
 
677
   p->clientData = clientData;
 
678
 
 
679
   p->next = in->callbacks;
 
680
 
 
681
   in->callbacks = p;
 
682
}
 
683
 
 
684
 
 
685
/*
 
686
 *-----------------------------------------------------------------------------
 
687
 *
 
688
 * RpcIn_RegisterCallbackEx --
 
689
 *
 
690
 *      Register a callback to happen when a TCLO message is
 
691
 *      received. When a TCLO message beginning with 'name' is
 
692
 *      sent, the callback will be called with an instance of
 
693
 *      "RpcInData" with the information from the request.
 
694
 *
 
695
 * Results:
 
696
 *      None
 
697
 *
 
698
 * Side effects:
 
699
 *      None
 
700
 *
 
701
 *-----------------------------------------------------------------------------
 
702
 */
 
703
void
 
704
RpcIn_RegisterCallbackEx(RpcIn *in,          // IN
 
705
                         const char *name,   // IN
 
706
                         RpcIn_Callback cb,  // IN
 
707
                         void *clientData)   // IN
 
708
{
 
709
   RpcInCallbackList *p;
 
710
 
 
711
   Debug("Registering callback '%s'\n", name);
 
712
 
 
713
   ASSERT(in);
 
714
   ASSERT(name);
 
715
   ASSERT(cb);
 
716
   ASSERT(RpcInLookupCallback(in, name) == NULL); // not there yet
 
717
 
 
718
   p = (RpcInCallbackList *) malloc(sizeof(RpcInCallbackList));
 
719
   ASSERT_NOT_IMPLEMENTED(p);
 
720
 
 
721
   p->length = strlen(name);
 
722
   p->name = strdup(name);
 
723
   p->type = RPCIN_CB_NEW;
 
724
   p->callback.newCb = cb;
652
725
   p->clientData = clientData;
653
726
 
654
727
   p->next = in->callbacks;
675
748
 
676
749
void
677
750
RpcIn_UnregisterCallback(RpcIn *in,               // IN
678
 
                         const char *name)        // IN                       
 
751
                         const char *name)        // IN
679
752
{
680
753
   RpcInCallbackList *cur, *prev;
681
754
 
687
760
   for (cur = in->callbacks, prev = NULL; cur && strcmp(cur->name, name);
688
761
        prev = cur, cur = cur->next);
689
762
 
690
 
   /* 
 
763
   /*
691
764
    * If we called UnregisterCallback on a name that doesn't exist, we
692
765
    * have a problem.
693
766
    */
738
811
   return retVal;
739
812
}
740
813
 
741