RPM Package Manager, CVS Repository
  http://rpm5.org/cvs/
  ____________________________________________________________________________

  Server: rpm5.org                         Name:   Jeff Johnson
  Root:   /v/rpm/cvs                       Email:  j...@rpm5.org
  Module: rpm                              Date:   06-Jul-2016 15:26:37
  Branch: rpm-5_4                          Handle: 2016070613263600

  Modified files:           (Branch: rpm-5_4)
    rpm                     CHANGES
    rpm/rpmio               librpmio.vers microjson.c rpmmacro.h rpmmqtt.c
                            rpmmqtt.h tmqtt.c

  Log:
    - mqtt: prepare for MacroContext sub-classing.

  Summary:
    Revision    Changes     Path
    1.3501.2.513+1  -0      rpm/CHANGES
    2.199.2.61  +8  -1      rpm/rpmio/librpmio.vers
    1.1.2.5     +2  -2      rpm/rpmio/microjson.c
    2.56.4.10   +9  -6      rpm/rpmio/rpmmacro.h
    1.1.2.18    +201 -140   rpm/rpmio/rpmmqtt.c
    1.1.2.16    +15 -8      rpm/rpmio/rpmmqtt.h
    1.1.2.12    +19 -19     rpm/rpmio/tmqtt.c
  ____________________________________________________________________________

  patch -p0 <<'@@ .'
  Index: rpm/CHANGES
  ============================================================================
  $ cvs diff -u -r1.3501.2.512 -r1.3501.2.513 CHANGES
  --- rpm/CHANGES       6 Jul 2016 13:24:17 -0000       1.3501.2.512
  +++ rpm/CHANGES       6 Jul 2016 13:26:36 -0000       1.3501.2.513
  @@ -1,4 +1,5 @@
   5.4.17 -> 5.4.18:
  +    - jbj: mqtt: prepare for MacroContext sub-classing.
       - jbj: macros: add/use vrpmMCExpand.
       - jbj: psm: add RPMIOPOOL_INTERP_RUN.
       - jbj: mqtt: stub-in a %{mqtt:...} mcro embedding.
  @@ .
  patch -p0 <<'@@ .'
  Index: rpm/rpmio/librpmio.vers
  ============================================================================
  $ cvs diff -u -r2.199.2.60 -r2.199.2.61 librpmio.vers
  --- rpm/rpmio/librpmio.vers   6 Jul 2016 09:06:25 -0000       2.199.2.60
  +++ rpm/rpmio/librpmio.vers   6 Jul 2016 13:26:36 -0000       2.199.2.61
  @@ -423,8 +423,10 @@
       rpmDigestUpdate;
       rpmDumpMacroTable;
       rpmExpand;
  -    rpmMCExpand;
       rpmExpandNumeric;
  +    vrpmMCExpand;
  +    rpmMCExpand;
  +    rpmMCExpandNumeric;
       _rpmficl_debug;
       rpmficlNew;
       rpmficlRun;
  @@ -637,6 +639,11 @@
       _rpmmqtt_debug;
       _rpmmqttI;
       _rpmmqttPool;
  +    rpmmqttMacroContext;
  +    rpmmqttDefineMacro;
  +    rpmmqttExpand;
  +    rpmmqttExpandNumeric;
  +    rpmmqttFreeMacros;
       rpmmqttConnect;
       rpmmqttDisconnect;
       rpmmqttNew;
  @@ .
  patch -p0 <<'@@ .'
  Index: rpm/rpmio/microjson.c
  ============================================================================
  $ cvs diff -u -r1.1.2.4 -r1.1.2.5 microjson.c
  --- rpm/rpmio/microjson.c     25 Jun 2016 07:31:08 -0000      1.1.2.4
  +++ rpm/rpmio/microjson.c     6 Jul 2016 13:26:36 -0000       1.1.2.5
  @@ -369,9 +369,9 @@
       enum
       { init, await_attr, in_attr, await_value, in_val_string,
        in_escape, in_val_token, post_val, post_array
  -    } state = 0;
  +    } state = init;
   #ifdef MICROJSON_DEBUG_ENABLE
  -    char *statenames[] = {
  +    const char *const statenames[] = {
        "init", "await_attr", "in_attr", "await_value", "in_val_string",
        "in_escape", "in_val_token", "post_val", "post_array",
       };
  @@ .
  patch -p0 <<'@@ .'
  Index: rpm/rpmio/rpmmacro.h
  ============================================================================
  $ cvs diff -u -r2.56.4.9 -r2.56.4.10 rpmmacro.h
  --- rpm/rpmio/rpmmacro.h      25 Jun 2016 07:31:08 -0000      2.56.4.9
  +++ rpm/rpmio/rpmmacro.h      6 Jul 2016 13:26:36 -0000       2.56.4.10
  @@ -186,7 +186,7 @@
       COMPRESSED_XZ            = 6,    /*!< xz can handle */
       COMPRESSED_LRZIP         = 7,    /*!< lrzip can handle */
       COMPRESSED_LZIP          = 8,    /*!< lzip can handle */
  -    COMPRESSED_7ZIP          = 9     /*!< 7zip can handle */
  +    COMPRESSED_7ZIP          = 9,    /*!< 7zip can handle */
   } rpmCompressedMagic;
   
   /**
  @@ -198,20 +198,21 @@
   int isCompressed(const char * file, rpmCompressedMagic * compressed);
   
   /**
  - * Return (malloc'ed) concatenated macro expansion(s).
  + * Return (malloc'ed) concatenated macro expansion(s) in a context.
  + * @param mc         macro context
    * @param arg                macro(s) to expand (NULL terminates list)
    * @return           macro expansion (malloc'ed)
    */
  -char * rpmExpand(const char * arg, ...)
  +char * vrpmMCExpand(MacroContext mc, const char * arg, va_list ap);
  +char * rpmMCExpand(MacroContext mc, const char * arg, ...)
        RPM_GNUC_NULL_TERMINATED;
   
   /**
  - * Return (malloc'ed) concatenated macro expansion(s) in a context.
  - * @param mc         macro context
  + * Return (malloc'ed) concatenated macro expansion(s).
    * @param arg                macro(s) to expand (NULL terminates list)
    * @return           macro expansion (malloc'ed)
    */
  -char * rpmMCExpand(MacroContext mc, const char * arg, ...)
  +char * rpmExpand(const char * arg, ...)
        RPM_GNUC_NULL_TERMINATED;
   
   /**
  @@ -254,6 +255,8 @@
    */
   int rpmExpandNumeric (const char * arg);
   
  +int rpmMCExpandNumeric(MacroContext mc, const char *arg);
  +
   #ifdef __cplusplus
   }
   #endif
  @@ .
  patch -p0 <<'@@ .'
  Index: rpm/rpmio/rpmmqtt.c
  ============================================================================
  $ cvs diff -u -r1.1.2.17 -r1.1.2.18 rpmmqtt.c
  --- rpm/rpmio/rpmmqtt.c       6 Jul 2016 09:06:25 -0000       1.1.2.17
  +++ rpm/rpmio/rpmmqtt.c       6 Jul 2016 13:26:36 -0000       1.1.2.18
  @@ -13,6 +13,7 @@
   #include <rpmlog.h>
   #include <rpmcb.h>
   #include <rpmdir.h>
  +#define      _MACRO_INTERNAL         /* for struct MacroContext_s */
   #include <rpmmacro.h>
   #include <rpmurl.h>
   #include <poptIO.h>
  @@ -188,7 +189,7 @@
       return n;
   }
   
  -static int Xcheck(rpmmqtt mqtt, const char * msg, int rc,
  +static rpmRC Xcheck(rpmmqtt mqtt, const char * msg, int rc,
                int printit, const char * func, const char * fn, unsigned ln)
   {
   
  @@ -197,11 +198,50 @@
        rpmlog(_lvl, "%s:%s:%u: MQTTAsync_%s: %s(%d)\n",
                func, fn, ln, msg, rpmmqttStrerror(rc), rc);
       }
  -    return rc;
  +    return (rpmRC) rc;
   }
   #define check(_o, _m, _rc)  \
       Xcheck(_o, _m, _rc, _rpmmqtt_debug, __FUNCTION__, __FILE__, __LINE__)
   
  +/*==============================================================*/
  +static struct MacroContext_s _rpmmqttMacroContext;
  +MacroContext rpmmqttMacroContext = &_rpmmqttMacroContext;
  +
  +void rpmmqttFreeMacros(rpmmqtt mqtt)
  +{
  +    if (mqtt)
  +     rpmFreeMacros(mqtt->mc);
  +}
  +
  +int rpmmqttDefineMacro(rpmmqtt mqtt, const char * macro, int level)
  +{
  +    return rpmDefineMacro((mqtt ? mqtt->mc : NULL), macro, level);
  +}
  +
  +char * rpmmqttExpand(rpmmqtt mqtt, char **lhs, const char *arg, ...)
  +{
  +    char *t = NULL;
  +    va_list ap;
  +
  +    if (lhs && *lhs)
  +     *lhs = _free(*lhs);
  +
  +    va_start(ap, arg);
  +    t = vrpmMCExpand((mqtt ? mqtt->mc : NULL), arg, ap);
  +    va_end(ap);
  +
  +    if (lhs)
  +     *lhs = t;
  +    return t;
  +}
  +
  +int rpmmqttExpandNumeric(rpmmqtt mqtt, const char *arg)
  +{
  +    return rpmMCExpandNumeric((mqtt ? mqtt->mc : NULL), arg);
  +}
  +
  +/*==============================================================*/
  +
   static void dumpMQTT(const char * msg, rpmmqtt mqtt)
   {
       FILE * fp = stderr;
  @@ -359,7 +399,7 @@
   
       mqtt->msg_count++;
   
  -    const char * s = message->payload;
  +    const char * s = (const char *) message->payload;
       size_t ns = message->payloadlen;
       if (_rpmmqtt_debug < 0)
        rpmlog(RPMLOG_DEBUG, "MQTT rcvd topic(%s) \"%.*s\"\n", topic, (int)ns, 
s);
  @@ -367,7 +407,7 @@
       if (mqtt->iob) {
        mqtt->iob = rpmiobAppend(mqtt->iob, topic, 0);
        mqtt->iob = rpmiobAppend(mqtt->iob, ":\t", 0);
  -     {   char * t = memcpy(alloca(ns+1), s, ns);
  +     {   char * t = (char *) memcpy(alloca(ns+1), s, ns);
            t[ns] = '\0';
            mqtt->iob = rpmiobAppend(mqtt->iob, t, 1);
        }
  @@ -568,7 +608,7 @@
       rpmmqtt mqtt = (rpmmqtt) _mqtt;
   
       if (mqtt->debug || _rpmmqtt_debug) {
  -     const char * s = response->alt.pub.message.payload;
  +     const char * s = (const char *) response->alt.pub.message.payload;
        size_t ns = response->alt.pub.message.payloadlen;
        int token = response->token;
        rpmlog(RPMLOG_DEBUG, "MQTT sent(%d) topic(%s) \"%.*s\"\n",
  @@ -703,7 +743,7 @@
       if (Fstat(fd, &sb) != 0)
        goto exit;
       nb = sb.st_size;
  -    b = xmalloc(nb);
  +    b = (char *) xmalloc(nb);
       nr = Fread(b, sizeof(*b), nb, fd);
       (void) Fclose(fd);
       fd = NULL;
  @@ -910,7 +950,7 @@
       urlinfo u;
   
       if (mqtt->state == NULL)
  -     mqtt->state = xcalloc(1, sizeof(*p));
  +     mqtt->state = (mqttState) xcalloc(1, sizeof(*p));
       p = (mqttState) mqtt->state;
   
       switch (otype) {
  @@ -922,7 +962,7 @@
        C->cleansession = (MF_ISSET(CLEAN) ? 1 : 0);
        C->maxInflight = mqtt->max_inflight;
   
  -     W = AOBJ(mqtt, 'W');            /* XXX LWT */
  +     W = (MQTTAsync_willOptions *) AOBJ(mqtt, 'W');          /* XXX LWT */
        C->will = (W && W->topicName ? W : NULL);
   
        C->username = (u && u->user ? u->user : mqtt->user);;
  @@ -931,7 +971,7 @@
        C->connectTimeout = 30; /* XXX secs. configure?*/
        C->retryInterval = 0;   /* XXX secs. configure? */
   
  -     S = AOBJ(mqtt, 'S');            /* XXX SSL */
  +     S = (MQTTAsync_SSLOptions *) AOBJ(mqtt, 'S');           /* XXX SSL */
        C->ssl = (S && S->keyStore) ? S : NULL; /* XXX */
   
        C->onSuccess = onConnect;
  @@ -968,7 +1008,7 @@
        M = &p->M;
        memcpy(M, &q->M, sizeof(*M));
        M->payloadlen = 0;
  -     M->payload = "";
  +     M->payload = (void *) "";
        M->qos = mqtt->qos;
        M->retained = (MF_ISSET(RETAIN) ? 1 : 0);
        M->dup = 0;
  @@ -1027,7 +1067,8 @@
       if (!MQTTAsync_isConnected(mqtt->I)) {
        mqtt->finished = 0;
        rc = check(mqtt, "connect",
  -             MQTTAsync_connect(mqtt->I, AOBJ(mqtt, 'C')));
  +             MQTTAsync_connect(mqtt->I,
  +                     (const MQTTAsync_connectOptions*)AOBJ(mqtt, 'C')));
        while (!mqtt->finished)
            usleep(1000);
        if (rc)
  @@ -1047,7 +1088,8 @@
       if (MQTTAsync_isConnected(mqtt->I)) {
        mqtt->finished = 0;
        rc = check(mqtt, "disconnect",
  -             MQTTAsync_disconnect(mqtt->I, AOBJ(mqtt, 'D')));
  +             MQTTAsync_disconnect(mqtt->I,
  +                     (const MQTTAsync_disconnectOptions*)AOBJ(mqtt, 'D')));
        while (!mqtt->finished)
            usleep(100);
        if (rc)
  @@ -1073,24 +1115,26 @@
        ns = strlen(s);
   
   #ifdef       WITH_MQTT
  -    if (rpmmqttConnect(mqtt))
  -     goto exit;
  -    MQTTAsync_message *M = AOBJ(mqtt, 'M');
  -    M->payloadlen = ns;
  -    M->payload = (char *) s;
  -
  -    MQTTAsync_responseOptions *R = AOBJ(mqtt, 'R');
  -    R->onSuccess = onSend;
  -    R->onFailure = onSendFailure;
  +    if (!rpmmqttConnect(mqtt)) {
  +     MQTTAsync_message *M =
  +         (MQTTAsync_message *) AOBJ(mqtt, 'M');
  +     M->payloadlen = ns;
  +     M->payload = (char *) s;
  +
  +     MQTTAsync_responseOptions *R =
  +         (MQTTAsync_responseOptions *) AOBJ(mqtt, 'R');
  +     R->onSuccess = onSend;
  +     R->onFailure = onSendFailure;
   
  -    mqtt->finished = 0;
  -    rc = check(mqtt, "sendMessage",
  +     mqtt->finished = 0;
  +     rc = check(mqtt, "sendMessage",
                MQTTAsync_sendMessage(mqtt->I, topic, M, R));
  -    while (!mqtt->finished)
  -     usleep(100);
  -    if (rc)
  -     goto exit;
  -    rc = RPMRC_OK;
  +     while (!mqtt->finished)
  +         usleep(100);
  +     if (rc)
  +         goto exit;
  +     rc = RPMRC_OK;
  +    }
   exit:
   #endif       /* WITH_MQTT */
   
  @@ -1106,39 +1150,41 @@
       if (ac <= 0)
        goto exit;
   #ifdef       WITH_MQTT
  -    if (rpmmqttConnect(mqtt))
  -     goto exit;
  -    int _lvl = RPMLOG_DEBUG;
  -    int *subqos = xcalloc(ac, sizeof(*subqos));
  -    for (int i = 0; i < ac; i++) {
  -     char * t = av[i];
  +    if (!rpmmqttConnect(mqtt)) {
  +     int _lvl = RPMLOG_DEBUG;
  +     int *subqos = (int *) xcalloc(ac, sizeof(*subqos));
  +     for (int i = 0; i < ac; i++) {
  +         char * t = av[i];
   #ifdef       NOTYET
  -     char * te = strchr(t, '?');
  -     if (te) {
  -         *te++ = '\0';
  -         if ((te = strchr(te, '='))) {
  -             if (!strncmp(t, "qos", (te - t)))
  -                 subqos[i] = strtoul(te+1, NULL, 0);
  -         }
  -     } else
  +         char * te = strchr(t, '?');
  +         if (te) {
  +             *te++ = '\0';
  +             if ((te = strchr(te, '='))) {
  +                 if (!strncmp(t, "qos", (te - t)))
  +                     subqos[i] = strtoul(te+1, NULL, 0);
  +             }
  +         } else
   #endif
  -         subqos[i] = mqtt->qos;      /* XXX */
  -     rpmlog(_lvl, "%19s: %s qos(%u)\n", "subscribe", t, subqos[i]);
  -    }
  +             subqos[i] = mqtt->qos;  /* XXX */
  +         rpmlog(_lvl, "%19s: %s qos(%u)\n", "subscribe", t, subqos[i]);
  +     }
   
  -    MQTTAsync_responseOptions *R = AOBJ(mqtt, 'R');
  -    R->onSuccess = onSubscribeMany;
  -    R->onFailure = onSubscribeManyFailure;
  +     MQTTAsync_responseOptions *R =
  +             (MQTTAsync_responseOptions *) AOBJ(mqtt, 'R');
  +     R->onSuccess = onSubscribeMany;
  +     R->onFailure = onSubscribeManyFailure;
   
  -    mqtt->finished = 0;
  -    rc = check(mqtt, "subscribeMany",
  +     mqtt->finished = 0;
  +     rc = check(mqtt, "subscribeMany",
                MQTTAsync_subscribeMany(mqtt->I, ac, av, subqos, R));
  -    while (!mqtt->finished)
  -     usleep(100);
  -    subqos = _free(subqos);
  -    if (rc)
  -     goto exit;
  -    rc = RPMRC_OK;
  +     while (!mqtt->finished)
  +         usleep(100);
  +     if (subqos)
  +         free(subqos);
  +     if (rc)
  +         goto exit;
  +     rc = RPMRC_OK;
  +    }
   #endif       /* WITH_MQTT */
   
   exit:
  @@ -1152,24 +1198,25 @@
   
   SPEW((stderr, "--> %s(%p,%p,%d)\n", __FUNCTION__, mqtt, topic, qos));
   #ifdef       WITH_MQTT
  -    if (rpmmqttConnect(mqtt))
  -     goto exit;
  -    int _lvl = RPMLOG_DEBUG;
  +    if (!rpmmqttConnect(mqtt)) {
  +     int _lvl = RPMLOG_DEBUG;
   
  -    rpmlog(_lvl, "%19s: %s qos(%d)\n", "subscribe", topic, qos);
  +     rpmlog(_lvl, "%19s: %s qos(%d)\n", "subscribe", topic, qos);
   
  -    MQTTAsync_responseOptions *R = AOBJ(mqtt, 'R');
  -    R->onSuccess = onSubscribe;
  -    R->onFailure = onSubscribeFailure;
  +     MQTTAsync_responseOptions *R =
  +             (MQTTAsync_responseOptions *) AOBJ(mqtt, 'R');
  +     R->onSuccess = onSubscribe;
  +     R->onFailure = onSubscribeFailure;
   
  -    mqtt->finished = 0;
  -    rc = check(mqtt, "subscribe",
  +     mqtt->finished = 0;
  +     rc = check(mqtt, "subscribe",
                MQTTAsync_subscribe(mqtt->I, topic, qos, R));
  -    while (!mqtt->finished)
  -     usleep(100);
  -    if (rc)
  -     goto exit;
  -    rc = RPMRC_OK;
  +     while (!mqtt->finished)
  +         usleep(100);
  +     if (rc)
  +         goto exit;
  +     rc = RPMRC_OK;
  +    }
   #endif       /* WITH_MQTT */
   
   exit:
  @@ -1183,24 +1230,25 @@
   
   SPEW((stderr, "--> %s(%p,\"%s\")\n", __FUNCTION__, mqtt, topic));
   #ifdef       WITH_MQTT
  -    if (rpmmqttConnect(mqtt))
  -     goto exit;
  -    int _lvl = RPMLOG_DEBUG;
  +    if (!rpmmqttConnect(mqtt)) {
  +     int _lvl = RPMLOG_DEBUG;
   
  -    rpmlog(_lvl, "%19s: %s\n", "unsubscribe", topic);
  +     rpmlog(_lvl, "%19s: %s\n", "unsubscribe", topic);
   
  -    MQTTAsync_responseOptions *R = AOBJ(mqtt, 'R');
  -    R->onSuccess = onUnsubscribeMany;
  -    R->onFailure = onUnsubscribeManyFailure;
  +     MQTTAsync_responseOptions *R =
  +             (MQTTAsync_responseOptions *) AOBJ(mqtt, 'R');
  +     R->onSuccess = onUnsubscribeMany;
  +     R->onFailure = onUnsubscribeManyFailure;
   
  -    mqtt->finished = 0;
  -    rc = check(mqtt, "unsubscribe",
  +     mqtt->finished = 0;
  +     rc = check(mqtt, "unsubscribe",
                MQTTAsync_unsubscribe(mqtt->I, topic, R));
  -    while (!mqtt->finished)
  -     usleep(100);
  -    if (rc)
  -     goto exit;
  -    rc = RPMRC_OK;
  +     while (!mqtt->finished)
  +         usleep(100);
  +     if (rc)
  +         goto exit;
  +     rc = RPMRC_OK;
  +    }
   #endif       /* WITH_MQTT */
   
   exit:
  @@ -1216,26 +1264,27 @@
       if (ac <= 0)
        goto exit;
   #ifdef       WITH_MQTT
  -    if (rpmmqttConnect(mqtt))
  -     goto exit;
  -    int _lvl = RPMLOG_DEBUG;
  -    for (int i = 0; i < ac; i++) {
  -     char * t = av[i];
  -     rpmlog(_lvl, "%19s: %s\n", "unsubscribe", t);
  -    }
  +    if (!rpmmqttConnect(mqtt)) {
  +     int _lvl = RPMLOG_DEBUG;
  +     for (int i = 0; i < ac; i++) {
  +         char * t = av[i];
  +         rpmlog(_lvl, "%19s: %s\n", "unsubscribe", t);
  +     }
   
  -    MQTTAsync_responseOptions *R = AOBJ(mqtt, 'R');
  -    R->onSuccess = onUnsubscribeMany;
  -    R->onFailure = onUnsubscribeManyFailure;
  +     MQTTAsync_responseOptions *R =
  +             (MQTTAsync_responseOptions *) AOBJ(mqtt, 'R');
  +     R->onSuccess = onUnsubscribeMany;
  +     R->onFailure = onUnsubscribeManyFailure;
   
  -    mqtt->finished = 0;
  -    rc = check(mqtt, "unsubscribeMany",
  +     mqtt->finished = 0;
  +     rc = check(mqtt, "unsubscribeMany",
                MQTTAsync_unsubscribeMany(mqtt->I, ac, av, R));
  -    while (!mqtt->finished)
  -     usleep(100);
  -    if (rc)
  -     goto exit;
  -    rc = RPMRC_OK;
  +     while (!mqtt->finished)
  +         usleep(100);
  +     if (rc)
  +         goto exit;
  +     rc = RPMRC_OK;
  +    }
   #endif       /* WITH_MQTT */
   
   exit:
  @@ -1260,7 +1309,8 @@
        goto exit;
       {        static char _mqtt_prefix[] = "%{?_mqtt_prefix}";
        /* XXX extra space: prepend in *sendMessage or *send  */
  -     char * t = rpmExpand(_mqtt_prefix, " ", s, NULL);
  +     char * t = rpmmqttExpand(mqtt, NULL,
  +                     _mqtt_prefix, " ", s, NULL);
        size_t nt = strlen(t);
   
        rc = rpmmqttSendMessage(mqtt, topic, t, nt);
  @@ -1287,7 +1337,8 @@
       if (rpmmqttConnect(mqtt))
        goto exit;
   
  -    {        char * subtopic = rpmExpand((s ? s : mqtt->topic), NULL);
  +    {        char * subtopic = rpmmqttExpand(mqtt, NULL,
  +             (s ? s : mqtt->topic), NULL);
        unsigned subqos = mqtt->qos;
        char *t, *te;
        int _lvl = RPMLOG_DEBUG;
  @@ -1314,7 +1365,8 @@
   
        rpmlog(_lvl, "%19s: %s qos(%u)\n", "subtopic", subtopic, subqos);
   
  -     MQTTAsync_responseOptions *R = AOBJ(mqtt, 'R');
  +     MQTTAsync_responseOptions *R =
  +             (MQTTAsync_responseOptions *) AOBJ(mqtt, 'R');
        R->onSuccess = onSubscribe;
        R->onFailure = onSubscribeFailure;
   
  @@ -1499,25 +1551,25 @@
        /* XXX MQTT_FLAGS_RETAIN */
        /* XXX MQTT_FLAGS_WILL_RETAIN */
   static const char _mqtt_qos[] = "%{?_mqtt_qos}%{!?_mqtt_qos:2}";
  -    mqtt->qos = (rpmExpandNumeric(_mqtt_qos) % 3);
  +    mqtt->qos = (rpmmqttExpandNumeric(mqtt, _mqtt_qos) % 3);
   static const char _mqtt_timeout[] = 
"%{?_mqtt_timeout}%{!?_mqtt_timeout:10000}";
  -    mqtt->timeout = rpmExpandNumeric(_mqtt_timeout);
  +    mqtt->timeout = rpmmqttExpandNumeric(mqtt, _mqtt_timeout);
   static const char _mqtt_max_inflight[] = 
"%{?_mqtt_max_inflight}%{!?_mqtt_max_inflight:20}";
  -    mqtt->max_inflight = rpmExpandNumeric(_mqtt_max_inflight);
  +    mqtt->max_inflight = rpmmqttExpandNumeric(mqtt, _mqtt_max_inflight);
   static const char _mqtt_keepalive[] = 
"%{?_mqtt_keepalive}%{!?_mqtt_keepalive:60}";
  -    mqtt->keepalive = rpmExpandNumeric(_mqtt_keepalive);
  +    mqtt->keepalive = rpmmqttExpandNumeric(mqtt, _mqtt_keepalive);
   static const char _mqtt_trace[] = "%{?_mqtt_trace}%{!?_mqtt_trace:0}";
  -    mqtt->trace = rpmExpandNumeric(_mqtt_trace);
  +    mqtt->trace = rpmmqttExpandNumeric(mqtt, _mqtt_trace);
   
   #ifdef       DYING
   static const char _mqtt_topic[] =
        "%{?_mqtt_topic}%{!?_mqtt_topic:rpm/%{pid}/mqtt}";
  -mqtt->topic = _free(mqtt->topic);
  -    mqtt->topic = rpmExpand(_mqtt_topic, NULL);
  +    (void) rpmmqttExpand(mqtt, &mqtt->topic,
  +                     _mqtt_topic, NULL);
   static const char _mqtt_clientid[] =
        "%{?_mqtt_clientid}%{!?_mqtt_clientid:rpm}";
  -mqtt->clientid = _free(mqtt->clientid);
  -    mqtt->clientid = rpmExpand(_mqtt_clientid, NULL);
  +    (void) rpmmqttExpand(mqtt, &mqtt->clientid,
  +             _mqtt_clientid, NULL);
   #endif
   
       return rc;
  @@ -1545,7 +1597,7 @@
        if ((te = strchr(t, '=')) == NULL)
            te += strlen(t);
        if (!strncmp(t, "clean", (te - t))) {
  -         mqtt->flags |= MQTT_FLAGS_CLEAN;
  +         *((int *)&mqtt->flags) |= MQTT_FLAGS_CLEAN;
            continue;
        }
        /* XXX MQTT_FLAGS_EOL */
  @@ -1555,7 +1607,7 @@
        /* XXX MQTT_FLAGS_DNSSRV */
        /* XXX MQTT_FLAGS_INSECURE */
        if (!strncmp(t, "retain", (te - t))) {
  -         mqtt->flags |= MQTT_FLAGS_RETAIN;
  +         *((int *)&mqtt->flags) |= MQTT_FLAGS_RETAIN;
            continue;
        }
        /* XXX MQTT_FLAGS_WILL_RETAIN */
  @@ -1636,7 +1688,7 @@
       rpmRC rc = RPMRC_OK;
        
       /* -- Set unspecified MQTT options from the URI parameters. */
  -    mqtt->ut = urlSplit(url, &u);
  +    mqtt->ut = (urltype) urlSplit(url, &u);
       mqtt->u = u;
   #ifdef       DYING
   dumpU(__FUNCTION__, u);
  @@ -1669,16 +1721,16 @@
        mqtt->port = strtoul(u->portstr, NULL, 0);
        }
   
  -mqtt->uri = _free(mqtt->uri);
  -    mqtt->uri = rpmExpand("tcp://", u->host, ":", u->portstr, NULL);
  +    (void) rpmmqttExpand(mqtt, &mqtt->uri,
  +             "tcp://", u->host, ":", u->portstr, NULL);
   
       {        const char * topic;
        (void) urlPath(u->url, &topic);
        if (topic && *topic == '/')
            topic++;
        if (topic && *topic) {
  -mqtt->topic = _free(mqtt->topic);
  -         mqtt->topic = rpmExpand(topic, NULL);
  +         (void) rpmmqttExpand(mqtt, &mqtt->topic,
  +             topic, NULL);
        }
       }
   
  @@ -1704,17 +1756,17 @@
   
       /* -- Initialize oddball values. */
        /* XXX FIXME: needed for --help POT_ARGFLAG_DEFAULT spewage only */
  -mqtt->protocol_version = _free(mqtt->protocol_version);
  -    mqtt->protocol_version = rpmExpand("auto", NULL);
  -mqtt->will_message = _free(mqtt->will_message);
  -    mqtt->will_message = rpmExpand("", NULL);
  -mqtt->_tls_version = _free(mqtt->_tls_version);
  -    mqtt->_tls_version = rpmExpand("1.2", NULL);
  +    (void) rpmmqttExpand(mqtt, &mqtt->protocol_version,
  +             "auto", NULL);
  +    (void) rpmmqttExpand(mqtt, &mqtt->will_message,
  +             "", NULL);
  +    (void) rpmmqttExpand(mqtt, &mqtt->_tls_version,
  +             "1.2", NULL);
        /* XXX FIXME:  __progname? */
  -mqtt->idprefix = _free(mqtt->idprefix);
  -    mqtt->idprefix = rpmExpand("rpm", NULL);
  -mqtt->_clientid = _free(mqtt->_clientid);
  -    mqtt->_clientid = rpmExpand(mqtt->idprefix, "-%%{pid}", NULL);
  +    (void) rpmmqttExpand(mqtt, &mqtt->idprefix,
  +             "rpm", NULL);
  +    (void) rpmmqttExpand(mqtt, &mqtt->_clientid,
  +             mqtt->idprefix, "-%%{pid}", NULL);
   
       /* -- Initialize values frpm default URI. */
       static const char _mqtt_uri[] =
  @@ -1723,7 +1775,8 @@
                "timeout=10000;"
                "max_inflight=20;";
                "keepalive=60;";
  -    uri = rpmExpand("%{?_mqtt_uri}%{!?_mqtt_uri:", _mqtt_uri, "}", NULL);
  +    uri = rpmmqttExpand(mqtt, NULL,
  +             "%{?_mqtt_uri}%{!?_mqtt_uri:", _mqtt_uri, "}", NULL);
   
       rc = rpmmqttInitURI(mqtt, uri);
       if (rc)
  @@ -1759,11 +1812,13 @@
       /* -- XXX Ensure topic/clientid are set. */
   assert(mqtt->_clientid);
       if (mqtt->clientid == NULL) {
  -     mqtt->clientid = rpmExpand(mqtt->_clientid, NULL);
  +     mqtt->clientid = rpmmqttExpand(mqtt, NULL,
  +             mqtt->_clientid, NULL);
       }
       if (mqtt->topic == NULL) {
   assert(mqtt->idprefix);
  -     mqtt->topic = rpmExpand(mqtt->idprefix, "/mqtt", NULL);
  +     mqtt->topic = rpmmqttExpand(mqtt, NULL,
  +             mqtt->idprefix, "/mqtt", NULL);
       }
        
       rc = RPMRC_OK;
  @@ -1936,8 +1991,11 @@
   
       mqtt->serverURI = _free(mqtt->serverURI);
   
  +    if (mqtt->mc)
  +     rpmmqttFreeMacros(mqtt);
  +
       mqtt->av = (char **) argvFree((ARGV_t)mqtt->av);
  -    mqtt->flags = 0;
  +    mqtt->flags = MQTT_FLAGS_NONE;
   }
   
   RPMIOPOOL_INTERP_MODULE(mqtt)
  @@ -1958,7 +2016,7 @@
   #endif
       int ac = argvCount((ARGV_t)av);
       flags &= ~0x80000000;
  -    rpmRC rc = rpmmqttInit(mqtt, ac, (const char **)av, flags);
  +    rpmRC rc = rpmmqttInit(mqtt, ac, (const char **)av, (mqttFlags)flags);
       (void)rc;
   
   #ifdef       WITH_MQTT
  @@ -1971,7 +2029,7 @@
            xx = check(mqtt, "setTraceCallback",
                (MQTTAsync_setTraceCallback(onTrace), 0));
            xx = check(mqtt, "setTraceLevel",
  -             (MQTTAsync_setTraceLevel(mqtt->trace), 0));
  +             (MQTTAsync_setTraceLevel((enum 
MQTTASYNC_TRACE_LEVELS)mqtt->trace), 0));
        }
   
        rpmlog(_lvl, "==================== MQTT\n");
  @@ -1990,7 +2048,7 @@
        /* XXX improve integration */
   static const char _mqtt_persist[] =
        "%{?_mqtt_persist}%{!?_mqtt_persist:2}";
  -     mqtt->persist_type = (rpmExpandNumeric(_mqtt_persist) % 3);
  +     mqtt->persist_type = (rpmmqttExpandNumeric(mqtt, _mqtt_persist) % 3);
   static const char _mqtt_cachedir[] =
        "%{?_mqtt_cachedir}%{!?_mqtt_cachedir:/var/cache/mqtt}";
   char *persist_path = rpmGetPath(_mqtt_cachedir, NULL);
  @@ -2022,7 +2080,8 @@
        case MQTTCLIENT_PERSISTENCE_USER:
          {
            mqtt->persist_path = xstrdup(persist_path);
  -         MQTTClient_persistence * ctx = xmalloc(sizeof(*ctx));
  +         MQTTClient_persistence * ctx =
  +             (MQTTClient_persistence *) xmalloc(sizeof(*ctx));
            *ctx = _rpmmqtt_persistence;        /* structure assignment */
            ctx->context = mqtt;
            mqtt->persist_ctx = ctx;
  @@ -2059,7 +2118,8 @@
            xx = check(mqtt, "createWithOptions",
                MQTTAsync_createWithOptions(&mqtt->I,
                        mqtt->uri, mqtt->clientid,
  -                     mqtt->persist_type, mqtt->persist_ctx, AOBJ(mqtt, 
'O')));
  +                     mqtt->persist_type, mqtt->persist_ctx,
  +                     (MQTTAsync_createOptions *)AOBJ(mqtt, 'O')));
   
            xx = check(mqtt, "setCallbacks",
                MQTTAsync_setCallbacks(mqtt->I, mqtt,
  @@ -2130,7 +2190,8 @@
   
       if (mqtt == NULL) mqtt = rpmmqttI();
   
  -    msg = rpmExpand("%now", " ", str, NULL);
  +    msg = rpmmqttExpand(mqtt, NULL,
  +             "%now", " ", str, NULL);
   #if defined(WITH_MQTT)
       if (rpmmqttConnect(mqtt))
        goto exit;
  @@ .
  patch -p0 <<'@@ .'
  Index: rpm/rpmio/rpmmqtt.h
  ============================================================================
  $ cvs diff -u -r1.1.2.15 -r1.1.2.16 rpmmqtt.h
  --- rpm/rpmio/rpmmqtt.h       6 Jul 2016 09:06:25 -0000       1.1.2.15
  +++ rpm/rpmio/rpmmqtt.h       6 Jul 2016 13:26:36 -0000       1.1.2.16
  @@ -29,7 +29,7 @@
       MQTT_FLAGS_BUFFER                = _MFB(10),     /*!< -b */
   
   } mqttFlags;
  -#define      MQTT_FLAGS_DEFAULT      (MQTT_FLAGS_CLEAN|MQTT_FLAGS_EOL)
  +#define      MQTT_FLAGS_DEFAULT      
((mqttFlags)(MQTT_FLAGS_CLEAN|MQTT_FLAGS_EOL))
   #undef       _MFB
   #undef       _KFB
   
  @@ -50,6 +50,7 @@
   #if defined(_RPMMQTT_INTERNAL)
   struct rpmmqtt_s {
       struct rpmioItem_s _item;        /*!< usage mutex and pool identifier. */
  +    MacroContext mc;
       char ** av;
       int ac;
   
  @@ -62,7 +63,7 @@
   
       const char *_address;                    /*!< -A */
       const char * host;                               /*!< -h */
  -    const char * idprefix;                   /*!< -I */
  +          char * idprefix;                   /*!< -I */
       int keepalive;                           /*!< -k */
       const char **msgs;                               /*!< -m */
       int max_inflight;                                /*!< -M */
  @@ -72,9 +73,9 @@
       const char **subtopics;                  /*!< -t */
       const char **_filter_out;                        /*!< -T */
       const char * user;                               /*!< -u */
  -    const char * protocol_version;           /*!< -V */
  +          char * protocol_version;           /*!< -V */
   
  -    const char * will_message;                       /*!< --will-payload */
  +          char * will_message;                       /*!< --will-payload */
       int will_qos;                            /*!< --will-qos */
       const char * will_topic;                 /*!< --will-topic */
   
  @@ -84,7 +85,7 @@
       const char * privkey;                    /*!< --key */
       const char * ciphers;                    /*!< --ciphers */
   
  -    const char *_tls_version;                        /*!< --tls-version */
  +          char *_tls_version;                        /*!< --tls-version */
       const char *_psk_key;                    /*!< --psk */
       const char *_psk_identity;                       /*!< --psk-identity */
       const char *_proxy;                              /*!< --proxy */
  @@ -96,9 +97,9 @@
   
       void * I;                        /* MQTTClient */
   
  -    const char * uri;
  -    const char * topic;
  -    const char *_clientid;                   /*!< -i */
  +          char * uri;
  +          char * topic;
  +          char *_clientid;                   /*!< -i */
       const char * clientid;
   
       unsigned persist_type;
  @@ -172,6 +173,12 @@
    */
   rpmmqtt rpmmqttNew(char ** av, uint32_t flags);
   
  +void rpmmqttFreeMacros(rpmmqtt mqtt);
  +int rpmmqttDefineMacro(rpmmqtt mqtt, const char * macro, int level);
  +char * rpmmqttExpand(rpmmqtt mqtt, char **lhs, const char *arg, ...)
  +     RPM_GNUC_NULL_TERMINATED;
  +int rpmmqttExpandNumeric(rpmmqtt mqtt, const char *arg);
  +
   rpmRC rpmmqttConnect(rpmmqtt mqtt);
   
   rpmRC rpmmqttDisconnect(rpmmqtt mqtt);
  @@ .
  patch -p0 <<'@@ .'
  Index: rpm/rpmio/tmqtt.c
  ============================================================================
  $ cvs diff -u -r1.1.2.11 -r1.1.2.12 tmqtt.c
  --- rpm/rpmio/tmqtt.c 6 Jul 2016 09:06:25 -0000       1.1.2.11
  +++ rpm/rpmio/tmqtt.c 6 Jul 2016 13:26:36 -0000       1.1.2.12
  @@ -27,15 +27,15 @@
   {
       rpmRC xx;
       int rc = 0;
  -static char *av[] = { "foo", "bar", "baz", NULL };
  +static const char *const av[] = { "foo", "bar", "baz", NULL };
   int ac = 3;
   int qos = 2;
   
       xx = rpmmqttConnect(mqtt);
       xx = rpmmqttSubscribe(mqtt, av[0], qos);
       xx = rpmmqttUnsubscribe(mqtt, av[0]);
  -    xx = rpmmqttSubscribeMany(mqtt, ac, av);
  -    xx = rpmmqttUnsubscribeMany(mqtt, ac, av);
  +    xx = rpmmqttSubscribeMany(mqtt, ac, (char **)av);
  +    xx = rpmmqttUnsubscribeMany(mqtt, ac, (char **)av);
       xx = rpmmqttDisconnect(mqtt);
    
   #ifdef       DYING
  @@ -76,7 +76,7 @@
       int ac = argvCount(av);
       static char *_av[] = { _mqtt_argv, NULL, };
   #endif
  -    rpmmqtt mqtt;
  +    rpmmqtt mqtt = NULL;
       int rc = -1;
   
       /* Initialize the _mqtt_ macro context */
  @@ -87,24 +87,24 @@
        "timeout=10000;"
        "trace=4;"
        "#rpm/#";
  -(void) rpmDefineMacro(NULL, _mqtt_uri, 0);
  -(void) rpmDefineMacro(NULL, "_mqtt_persist 2", 0);
  -(void) rpmDefineMacro(NULL, "_mqtt_cachedir /var/cache/mqtt", 0);
  +(void) rpmmqttDefineMacro(mqtt, _mqtt_uri, 0);
  +(void) rpmmqttDefineMacro(mqtt, "_mqtt_persist 2", 0);
  +(void) rpmmqttDefineMacro(mqtt, "_mqtt_cachedir /var/cache/mqtt", 0);
   
  -(void) rpmDefineMacro(NULL, "nil %{!?nil}", 0);
  -(void) rpmDefineMacro(NULL, "_mqtt_prefix %{now}", 0);
  +(void) rpmmqttDefineMacro(mqtt, "nil %{!?nil}", 0);
  +(void) rpmmqttDefineMacro(mqtt, "_mqtt_prefix %{now}", 0);
   
   #ifdef       DYING
  -(void) rpmDefineMacro(NULL, "_mqtt_trace 4", 0);
  -(void) rpmDefineMacro(NULL, "_mqtt_user luser", 0);
  -(void) rpmDefineMacro(NULL, "_mqtt_pass jasnl", 0);
  -(void) rpmDefineMacro(NULL, "_mqtt_host localhost", 0);
  -(void) rpmDefineMacro(NULL, "_mqtt_port 1883", 0);
  -(void) rpmDefineMacro(NULL, "_mqtt_clientid rpm-%{pid}", 0);
  -(void) rpmDefineMacro(NULL, "_mqtt_topic rpm/#", 0);
  -(void) rpmDefineMacro(NULL, "_mqtt_qos 1", 0);
  -(void) rpmDefineMacro(NULL, "_mqtt_timeout 10000", 0);
  -(void) rpmDefineMacro(NULL, "_mqtt_prefix %{now} rpm pid %{pid} on cpu%{cpu} 
%{user}:%{group} ", 0);
  +(void) rpmmqttDefineMacro(mqtt, "_mqtt_trace 4", 0);
  +(void) rpmmqttDefineMacro(mqtt, "_mqtt_user luser", 0);
  +(void) rpmmqttDefineMacro(mqtt, "_mqtt_pass jasnl", 0);
  +(void) rpmmqttDefineMacro(mqtt, "_mqtt_host localhost", 0);
  +(void) rpmmqttDefineMacro(mqtt, "_mqtt_port 1883", 0);
  +(void) rpmmqttDefineMacro(mqtt, "_mqtt_clientid rpm-%{pid}", 0);
  +(void) rpmmqttDefineMacro(mqtt, "_mqtt_topic rpm/#", 0);
  +(void) rpmmqttDefineMacro(mqtt, "_mqtt_qos 1", 0);
  +(void) rpmmqttDefineMacro(mqtt, "_mqtt_timeout 10000", 0);
  +(void) rpmmqttDefineMacro(mqtt, "_mqtt_prefix %{now} rpm pid %{pid} on 
cpu%{cpu} %{user}:%{group} ", 0);
   #endif
   
       mqtt = rpmmqttNew(argv, 0);
  @@ .
______________________________________________________________________
RPM Package Manager                                    http://rpm5.org
CVS Sources Repository                                rpm-cvs@rpm5.org

Reply via email to