Navigation



Ignore:
Timestamp:
Apr 15, 2013, 4:17:07 PM (11 years ago)
Author:
Sebastien Decugis <sdecugis@freediameter.net>
Branch:
default
Phase:
public
Message:

Fix a number of errors and warnings introduced/highlighted by recent commits

File:
1 edited

Legend:

Unmodified
Added
Removed
  • extensions/app_diameap/diameap_eappacket.c

    r974 r1027  
    3939#include "libdiameap.h"
    4040
    41 int diameap_eap_get_code(struct eap_packet eappacket, eap_code * eapcode)
     41int diameap_eap_get_code(struct eap_packet *eappacket, eap_code * eapcode)
    4242{
    4343        TRACE_ENTRY("%p %p",eappacket,eapcode);
    4444
    45         if (eappacket.data == NULL)
     45        if (eappacket->data == NULL)
    4646        {
    4747                *eapcode = ERROR;
     
    4949                return EINVAL;
    5050        }
    51         if (eappacket.length < 1)
     51        if (eappacket->length < 1)
    5252        {
    5353                *eapcode = ERROR;
    54                 TRACE_DEBUG(INFO,"%sEAP packet length %d : no EAP Code to return.",DIAMEAP_EXTENSION, eappacket.length);
    55                 return EINVAL;
    56         }
    57         *eapcode = G8(eappacket.data);
    58         return 0;
    59 }
    60 
    61 int diameap_eap_get_identifier(struct eap_packet eappacket, u8 * identifier)
     54                TRACE_DEBUG(INFO,"%sEAP packet length %d : no EAP Code to return.",DIAMEAP_EXTENSION, eappacket->length);
     55                return EINVAL;
     56        }
     57        *eapcode = G8(eappacket->data);
     58        return 0;
     59}
     60
     61int diameap_eap_get_identifier(struct eap_packet *eappacket, u8 * identifier)
    6262{
    6363        TRACE_ENTRY("%p %p",eappacket,identifier);
    6464        *identifier = 0;
    65         if (eappacket.data == NULL)
     65        if (eappacket->data == NULL)
    6666        {
    6767                TRACE_DEBUG(INFO,"%sEmpty data in EAP packet: no Identifier field to return.",DIAMEAP_EXTENSION);
    6868                return EINVAL;
    6969        }
    70         if (eappacket.length < 2)
    71         {
    72                 TRACE_DEBUG(INFO,"%sEAP packet length %d : no Identifier field to return.",DIAMEAP_EXTENSION, eappacket.length);
    73                 return EINVAL;
    74         }
    75         *identifier = G8(eappacket.data + 1);
    76         return 0;
    77 }
    78 
    79 int diameap_eap_get_length(struct eap_packet eappacket, u16 *length)
     70        if (eappacket->length < 2)
     71        {
     72                TRACE_DEBUG(INFO,"%sEAP packet length %d : no Identifier field to return.",DIAMEAP_EXTENSION, eappacket->length);
     73                return EINVAL;
     74        }
     75        *identifier = G8(eappacket->data + 1);
     76        return 0;
     77}
     78
     79int diameap_eap_get_length(struct eap_packet *eappacket, u16 *length)
    8080{
    8181        TRACE_ENTRY("%p %p",eappacket,length);
    8282        *length = 0;
    8383
    84         if (eappacket.data == NULL)
     84        if (eappacket->data == NULL)
    8585        {
    8686                TRACE_DEBUG(INFO,"%sEmpty data in EAP packet: no Length field to return.",DIAMEAP_EXTENSION);
    8787                return EINVAL;
    8888        }
    89         if (eappacket.ulength < 4)
    90         {
    91                 TRACE_DEBUG(INFO,"%sEAP packet length %d : no Length field to return.",DIAMEAP_EXTENSION, eappacket.length);
    92                 return EINVAL;
    93         }
    94         *length = (u16) G16BIGE((eappacket.data + 2));
    95         return 0;
    96 }
    97 
    98 int diameap_eap_get_packetlength(struct eap_packet eappacket, u16 *length)
     89        if (eappacket->ulength < 4)
     90        {
     91                TRACE_DEBUG(INFO,"%sEAP packet length %d : no Length field to return.",DIAMEAP_EXTENSION, eappacket->length);
     92                return EINVAL;
     93        }
     94        *length = (u16) G16BIGE((eappacket->data + 2));
     95        return 0;
     96}
     97
     98int diameap_eap_get_packetlength(struct eap_packet *eappacket, u16 *length)
    9999{
    100100        TRACE_ENTRY("%p %p",eappacket,length);
    101         if (eappacket.data == NULL)
     101        if (eappacket->data == NULL)
    102102        {
    103103                TRACE_DEBUG(INFO,"%sEmpty data in EAP packet: no Length field to return.",DIAMEAP_EXTENSION);
    104104                return EINVAL;
    105105        }
    106         *length = eappacket.ulength;
    107         return 0;
    108 }
    109 
    110 int diameap_eap_get_type(struct eap_packet eappacket, eap_type * eaptype)
     106        *length = eappacket->ulength;
     107        return 0;
     108}
     109
     110int diameap_eap_get_type(struct eap_packet *eappacket, eap_type * eaptype)
    111111{
    112112        TRACE_ENTRY("%p %p",eappacket,eaptype);
    113113        *eaptype = 0;
    114114
    115         if (eappacket.data == NULL)
     115        if (eappacket->data == NULL)
    116116        {
    117117                TRACE_DEBUG(INFO,"%sEmpty data in EAP packet: no EAP Type field to return.",DIAMEAP_EXTENSION);
    118118                return EINVAL;
    119119        }
    120         if (eappacket.length < 5)
    121         {
    122                 TRACE_DEBUG(INFO,"%sEAP packet length %d : no EAP Type field to return.",DIAMEAP_EXTENSION, eappacket.length);
    123                 return EINVAL;
    124         }
    125         *eaptype = (u32) G8(eappacket.data + 4);
     120        if (eappacket->length < 5)
     121        {
     122                TRACE_DEBUG(INFO,"%sEAP packet length %d : no EAP Type field to return.",DIAMEAP_EXTENSION, eappacket->length);
     123                return EINVAL;
     124        }
     125        *eaptype = (u32) G8(eappacket->data + 4);
    126126        return 0;
    127127}
     
    129129boolean diameap_eap_check_code(eap_code code)
    130130{
    131         TRACE_ENTRY("%p",code);
     131        TRACE_ENTRY("%d",code);
    132132        if (code != EAP_REQUEST && code != EAP_RESPONSE && code != EAP_SUCCESS
    133133                        && code != EAP_FAILURE)
     
    139139}
    140140
    141 int diameap_eap_get_packetdata(struct eap_packet eappacket, u8 ** data,
     141int diameap_eap_get_packetdata(struct eap_packet *eappacket, u8 ** data,
    142142                int *len)
    143143{
    144144        TRACE_ENTRY("%p %p",eappacket,data);
    145         if (eappacket.length > 0)
    146         {
    147                 *data = malloc(sizeof(u8) * eappacket.length);
    148                 U8COPY(*data,0,eappacket.length,eappacket.data);
    149                 *len = eappacket.length;
     145        if (eappacket->length > 0)
     146        {
     147                *data = malloc(sizeof(u8) * eappacket->length);
     148                U8COPY(*data,0,eappacket->length,eappacket->data);
     149                *len = eappacket->length;
    150150                return 0;
    151151        }
    152         TRACE_DEBUG(INFO,"%sEAP packet length=%d: empty or wrong EAP Packet.",DIAMEAP_EXTENSION, eappacket.length);
     152        TRACE_DEBUG(INFO,"%sEAP packet length=%d: empty or wrong EAP Packet.",DIAMEAP_EXTENSION, eappacket->length);
    153153        *data = NULL;
    154154        *len = 0;
     
    156156}
    157157
    158 int diameap_eap_get_data(struct eap_packet eappacket, u8 ** data, int * len)
     158int diameap_eap_get_data(struct eap_packet *eappacket, u8 ** data, int * len)
    159159{
    160160        TRACE_ENTRY("%p %p",eappacket,data);
    161         if (eappacket.length > 5)
    162         {
    163                 *data = malloc(sizeof(u8) * (eappacket.length - 5));
    164                 U8COPY(*data,0,(eappacket.length-5),(eappacket.data+5));
    165                 *len = eappacket.length - 5;
     161        if (eappacket->length > 5)
     162        {
     163                CHECK_MALLOC( *data = malloc(sizeof(u8) * (eappacket->length - 5)) );
     164                U8COPY(*data,0,(eappacket->length-5),(eappacket->data+5));
     165                *len = eappacket->length - 5;
    166166                return 0;
    167167        }
    168         TRACE_DEBUG(INFO,"%sEAP packet length=%d: empty or wrong EAP Packet.",DIAMEAP_EXTENSION, eappacket.length);
     168        TRACE_DEBUG(INFO,"%sEAP packet length=%d: empty or wrong EAP Packet.",DIAMEAP_EXTENSION, eappacket->length);
    169169        *data = NULL;
    170170        *len = 0;
     
    173173}
    174174
    175 void diameap_eap_dump(int level, struct eap_packet eappacket)
    176 {
    177         TRACE_ENTRY("%p %p",level,eappacket);
     175void diameap_eap_dump(int level, struct eap_packet *eappacket)
     176{
     177        TRACE_ENTRY("%d %p",level,eappacket);
    178178        if (!TRACE_BOOL(level))
    179179                return;
    180180
    181         if (eappacket.data == NULL)
     181        if (eappacket->data == NULL)
    182182                return;
    183         if (eappacket.length < 5)
     183        if (eappacket->length < 5)
    184184                return;
    185         if (eappacket.ulength < 5)
     185        if (eappacket->ulength < 5)
    186186                return;
    187187
     
    215215        CHECK_FCT_DO(diameap_eap_get_length(eappacket,&length),return);
    216216        fd_log_debug("\t -Length     : %d ", (unsigned int)length);
    217         if (eappacket.length > 4)
     217        if (eappacket->length > 4)
    218218        {
    219219                eap_type type;
     
    221221                fd_log_debug("\t -Type       : %d ", type);
    222222        }
    223         if (eappacket.length > 5)
     223        if (eappacket->length > 5)
    224224        {
    225225                char buf[1024];
    226226                snprintf(buf, sizeof(buf), "\t -Data       : ");
    227                 for (i = 5; i < eappacket.length && i < 30; i++)
     227                for (i = 5; i < eappacket->length && i < 30; i++)
    228228                {
    229                         snprintf(buf+strlen(buf), sizeof(buf)-strlen(buf), "%02x ", G8(eappacket.data + i));
     229                        snprintf(buf+strlen(buf), sizeof(buf)-strlen(buf), "%02x ", G8(eappacket->data + i));
    230230                }
    231                 if(i+1<eappacket.length)
     231                if(i+1<eappacket->length)
    232232                        snprintf(buf+strlen(buf), sizeof(buf)-strlen(buf), "[...] (len=%d)",(unsigned int) length);
    233233                fd_log_debug("%s", buf);
     
    240240{
    241241
    242         TRACE_ENTRY("%p %p %p %p %p %p", code, id, type, data, dataLength,eappacket);
     242        TRACE_ENTRY("%d %hhu %d %p %hu %p", code, id, type, data, dataLength,eappacket);
    243243
    244244        int length = 0;
Note: See TracChangeset for help on using the changeset viewer.