Don't use lvalue, use the correct struct name
authorAlan T. DeKok <aland@freeradius.org>
Tue, 22 Nov 2011 17:29:06 +0000 (18:29 +0100)
committerAlan T. DeKok <aland@freeradius.org>
Tue, 22 Nov 2011 17:29:06 +0000 (18:29 +0100)
In preparation for removing lvalue.

src/lib/dhcp.c
src/lib/valuepair.c
src/lib/vqp.c
src/main/xlat.c
src/modules/rlm_acct_unique/rlm_acct_unique.c
src/modules/rlm_preprocess/rlm_preprocess.c

index a7f8417..5b62055 100644 (file)
@@ -746,7 +746,7 @@ int fr_dhcp_decode(RADIUS_PACKET *packet)
                 *      DHCP Opcode is request
                 */
                vp = pairfind(head, 256, DHCP_MAGIC_VENDOR);
-               if (vp && vp->lvalue == 3) {
+               if (vp && vp->vp_integer == 3) {
                        /*
                         *      Vendor is "MSFT 98"
                         */
@@ -757,7 +757,7 @@ int fr_dhcp_decode(RADIUS_PACKET *packet)
                                /*
                                 *      Reply should be broadcast.
                                 */
-                               if (vp) vp->lvalue |= 0x8000;
+                               if (vp) vp->vp_integer |= 0x8000;
                                packet->data[10] |= 0x80;                       
                        }
                }
index d32d055..96bf02d 100644 (file)
@@ -1358,6 +1358,7 @@ static VALUE_PAIR *pairmake_any(const char *attribute, const char *value,
        char            *q;
        VALUE_PAIR      *vp;
        DICT_VENDOR     *dv;
+       const DICT_ATTR *da;
 
        /*
         *      Unknown attributes MUST be of type 'octets'
@@ -1533,6 +1534,23 @@ static VALUE_PAIR *pairmake_any(const char *attribute, const char *value,
                        return NULL;
                }
        }
+
+       /*
+        *      Maybe we're reading an old detail/config file, where
+        *      it didn't know about a particular attribute and dumped
+        *      it as hex.  Now the dictionaries have been updated,
+        *      and we know about it.  So... convert it to the
+        *      appropriate type.
+        *
+        *      FIXME: call data2vp_any.
+        */
+       da = dict_attrbyvalue(attr, vendor);
+       if (da) {
+               /*
+                *      FIXME: convert hex to the data type.
+                */
+               return NULL;
+       }
        
        /*
         *      We've now parsed the attribute properly, Let's create
@@ -1550,46 +1568,16 @@ static VALUE_PAIR *pairmake_any(const char *attribute, const char *value,
        size = strlen(value + 2);
        data = vp->vp_octets;
 
-       /*
-        *      We may be reading something like Attr-5.  i.e.
-        *      who-ever wrote the text didn't understand it, but we
-        *      do.
-        */
-       switch (vp->type) {
-       default:
-               if (size == (vp->length * 2)) break;
-               vp->type = PW_TYPE_OCTETS;
-               /* FALL-THROUGH */
-               
-       case PW_TYPE_OCTETS:
-       case PW_TYPE_ABINARY:
-               vp->length = size >> 1;
-               if (vp->length > sizeof(vp->vp_octets)) {
-                       vp->vp_tlv = malloc(vp->length);
-                       if (!vp->vp_tlv) {
-                               fr_strerror_printf("Out of memory");
-                               free(vp);
-                               return NULL;
-                       }
-                       data = vp->vp_tlv;
-                       vp->type |= PW_FLAG_LONG;
-               }
-               break;
-
-       case PW_TYPE_STRING:
-               vp->length = size >> 1;
-               memset(&vp->vp_strvalue, 0, sizeof(vp->vp_strvalue));
-               if (vp->length >= sizeof(vp->vp_strvalue)) {
-                       vp->vp_tlv = malloc(vp->length);
-                       if (!vp->vp_tlv) {
-                               fr_strerror_printf("Out of memory");
-                               free(vp);
-                               return NULL;
-                       }
-                       data = vp->vp_tlv;
-                       vp->type |= PW_FLAG_LONG;
+       vp->length = size >> 1;
+       if (vp->length > sizeof(vp->vp_octets)) {
+               vp->vp_tlv = malloc(vp->length);
+               if (!vp->vp_tlv) {
+                       fr_strerror_printf("Out of memory");
+                       free(vp);
+                       return NULL;
                }
-               break;
+               data = vp->vp_tlv;
+               vp->type |= PW_FLAG_LONG;
        }
 
        if (fr_hex2bin(value + 2, data, size) != vp->length) {
@@ -1598,22 +1586,6 @@ static VALUE_PAIR *pairmake_any(const char *attribute, const char *value,
                return NULL;
        }
 
-       /*
-        *      Move contents around based on type.  This is
-        *      to work around the historical use of "lvalue".
-        */
-       switch (vp->type) {
-       case PW_TYPE_DATE:
-       case PW_TYPE_IPADDR:
-       case PW_TYPE_INTEGER:
-               memcpy(&vp->lvalue, vp->vp_octets, sizeof(vp->lvalue));
-               vp->vp_strvalue[0] = '\0';
-               break;
-               
-       default:
-               break;
-       }
-       
        return vp;
 }
 
index bb1d21f..b60c84d 100644 (file)
@@ -435,34 +435,34 @@ int vqp_decode(RADIUS_PACKET *packet)
 
        tail = &packet->vps;
 
-       vp = paircreate(PW_VQP_PACKET_TYPE, 0, PW_TYPE_OCTETS);
+       vp = paircreate(PW_VQP_PACKET_TYPE, 0, PW_TYPE_INTEGER);
        if (!vp) {
                fr_strerror_printf("No memory");
                return -1;
        }
-       vp->lvalue = packet->data[1];
+       vp->vp_integer = packet->data[1];
        debug_pair(vp);
 
        *tail = vp;
        tail = &(vp->next);
 
-       vp = paircreate(PW_VQP_ERROR_CODE, 0, PW_TYPE_OCTETS);
+       vp = paircreate(PW_VQP_ERROR_CODE, 0, PW_TYPE_INTEGER);
        if (!vp) {
                fr_strerror_printf("No memory");
                return -1;
        }
-       vp->lvalue = packet->data[2];
+       vp->vp_integer = packet->data[2];
        debug_pair(vp);
 
        *tail = vp;
        tail = &(vp->next);
 
-       vp = paircreate(PW_VQP_SEQUENCE_NUMBER, 0, PW_TYPE_OCTETS);
+       vp = paircreate(PW_VQP_SEQUENCE_NUMBER, 0, PW_TYPE_INTEGER);
        if (!vp) {
                fr_strerror_printf("No memory");
                return -1;
        }
-       vp->lvalue = packet->id; /* already set by vqp_recv */
+       vp->vp_integer = packet->id; /* already set by vqp_recv */
        debug_pair(vp);
 
        *tail = vp;
@@ -562,7 +562,7 @@ int vqp_encode(RADIUS_PACKET *packet, RADIUS_PACKET *original)
                return -1;
        }
 
-       code = vp->lvalue;
+       code = vp->vp_integer;
        if ((code < 1) || (code > 4)) {
                fr_strerror_printf("Invalid value %d for VQP-Packet-Type", code);
                return -1;
@@ -616,7 +616,7 @@ int vqp_encode(RADIUS_PACKET *packet, RADIUS_PACKET *original)
        if (!vp) {
                ptr[2] = 0;
        } else {
-               ptr[2] = vp->lvalue & 0xff;
+               ptr[2] = vp->vp_integer & 0xff;
                return 0;
        }
 
index f302a76..3263148 100644 (file)
@@ -212,7 +212,7 @@ static size_t xlat_packet(void *instance, REQUEST *request,
                        case PW_TYPE_DATE:
                        case PW_TYPE_SHORT:
                        case PW_TYPE_BYTE:
-                               snprintf(out, outlen, "%u", vp->lvalue);
+                               snprintf(out, outlen, "%u", vp->vp_integer);
                                return strlen(out);
 
                        case PW_TYPE_SIGNED:
index 1b0d1a7..88a064d 100644 (file)
@@ -215,7 +215,7 @@ static int add_unique_id(void *instance, REQUEST *request)
                                hack.type = cur->dattr->type;
                                hack.operator = T_OP_EQ;
                                hack.length = 4;
-                               hack.lvalue = request->packet->src_ipaddr.ipaddr.ip4addr.s_addr;
+                               hack.vp_ipaddr = request->packet->src_ipaddr.ipaddr.ip4addr.s_addr;
                                vp = &hack;
                        } else {
                                RDEBUG2("WARNING: Attribute %s was not found in request, unique ID MAY be inconsistent", cur->dattr->name);
index 9fcbce5..41e200e 100644 (file)
@@ -78,7 +78,7 @@ static int fallthrough(VALUE_PAIR *vp)
        VALUE_PAIR *tmp;
        tmp = pairfind(vp, PW_FALL_THROUGH, 0);
 
-       return tmp ? tmp->lvalue : 0;
+       return tmp ? tmp->vp_integer : 0;
 }
 
 /*