Navigation


Changeset 1001:d03f7e3805ad in freeDiameter for libfdproto


Ignore:
Timestamp:
Mar 21, 2013, 11:05:54 PM (11 years ago)
Author:
Sebastien Decugis <sdecugis@freediameter.net>
Branch:
default
Phase:
public
Message:

Fix generation of the Proxy-Info AVP in fd_msg_new_answer_from_req

Location:
libfdproto
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • libfdproto/lists.c

    r740 r1001  
    7575void fd_list_move_end(struct fd_list * ref, struct fd_list * senti)
    7676{
     77        struct fd_list * li;
    7778        ASSERT(ref->head == ref);
    7879        ASSERT(senti->head == senti);
     
    8081        if (senti->next == senti)
    8182                return;
     83       
     84        for (li = senti->next; li != senti; li = li->next)
     85                li->head = ref;
    8286       
    8387        senti->next->prev = ref->prev;
  • libfdproto/messages.c

    r995 r1001  
    303303static int bufferize_avp(unsigned char * buffer, size_t buflen, size_t * offset,  struct avp * avp);
    304304static int parsebuf_list(unsigned char * buf, size_t buflen, struct fd_list * head);
     305static int parsedict_do_chain(struct dictionary * dict, struct fd_list * head, int mandatory, struct fd_pei *error_info);
     306
    305307
    306308/* Create answer from a request */
     
    366368        if (! (flags & MSGFL_ANSW_NOPROXYINFO)) {
    367369                struct avp * avp;
     370                struct fd_pei pei;
     371                struct fd_list avpcpylist = FD_LIST_INITIALIZER(avpcpylist);
     372               
    368373                CHECK_FCT(  fd_msg_browse(qry, MSG_BRW_FIRST_CHILD, &avp, NULL)  );
    369374                while (avp) {
     
    376381                                size_t offset = 0;
    377382
     383                                /* Create a buffer with the content of the AVP. This is easier than going through the list */
    378384                                CHECK_FCT(  fd_msg_update_length(avp)  );
    379385                                CHECK_MALLOC(  buf = malloc(avp->avp_public.avp_len)  );
    380386                                CHECK_FCT( bufferize_avp(buf, avp->avp_public.avp_len, &offset, avp)  );
    381387
    382                                 /* Now we directly parse this buffer into the new message list */
    383                                 CHECK_FCT( parsebuf_list(buf, avp->avp_public.avp_len, &ans->msg_chain.children) );
     388                                /* Now we parse this buffer to create a copy AVP */
     389                                CHECK_FCT( parsebuf_list(buf, avp->avp_public.avp_len, &avpcpylist) );
     390                               
     391                                /* Parse dictionary objects now to remove the dependency on the buffer */
     392                                CHECK_FCT( parsedict_do_chain(dict, &avpcpylist, 0, &pei) );
    384393
    385394                                /* Done for this AVP */
    386395                                free(buf);
     396
     397                                /* We move this AVP now so that we do not parse again in next loop */
     398                                fd_list_move_end(&ans->msg_chain.children, &avpcpylist);
    387399                        }
    388400                        /* move to next AVP in the message, we can have several Proxy-Info instances */
    389401                        CHECK_FCT( fd_msg_browse(avp, MSG_BRW_NEXT, &avp, NULL) );
    390402                }
    391                 CHECK_FCT( fd_msg_parse_dict( ans, dict, NULL ) );
    392403        }
    393404
     
    15581569                CHECK_PARAMS( avp->avp_source || avp->avp_rawdata );
    15591570               
    1560                 if ( avp->avp_source != NULL ) {
     1571                if ( avp->avp_rawdata != NULL ) {
     1572                        /* the content was stored in rawdata */
     1573                        memcpy(&buffer[*offset], avp->avp_rawdata, avp->avp_rawlen);
     1574                        *offset += PAD4(avp->avp_rawlen);
     1575                } else {
    15611576                        /* the message was not parsed completely */
    15621577                        size_t datalen = avp->avp_public.avp_len - GETAVPHDRSZ(avp->avp_public.avp_flags);
    15631578                        memcpy(&buffer[*offset], avp->avp_source, datalen);
    15641579                        *offset += PAD4(datalen);
    1565                 } else {
    1566                         /* the content was stored in rawdata */
    1567                         memcpy(&buffer[*offset], avp->avp_rawdata, avp->avp_rawlen);
    1568                         *offset += PAD4(avp->avp_rawlen);
    15691580                }
    15701581               
     
    18131824 */
    18141825
    1815 static int parsedict_do_chain(struct dictionary * dict, struct fd_list * head, int mandatory, struct fd_pei *error_info);
    1816 
    18171826static char error_message[256];
    18181827
     
    18211830{
    18221831        struct dict_avp_data dictdata;
     1832        uint8_t * source;
    18231833       
    18241834        TRACE_ENTRY("%p %p %d %p", dict, avp, mandatory, error_info);
     
    19131923        }
    19141924       
     1925        source = avp->avp_source;
     1926        avp->avp_source = NULL;
     1927
    19151928        /* Now get the value inside */
    19161929        switch (dictdata.avp_basetype) {
     
    19191932                       
    19201933                        /* This is a grouped AVP, so let's parse the list of AVPs inside */
    1921                         CHECK_FCT_DO(  ret = parsebuf_list(avp->avp_source, avp->avp_public.avp_len - GETAVPHDRSZ( avp->avp_public.avp_flags ), &avp->avp_chain.children),
     1934                        CHECK_FCT_DO(  ret = parsebuf_list(source, avp->avp_public.avp_len - GETAVPHDRSZ( avp->avp_public.avp_flags ), &avp->avp_chain.children),
    19221935                                {
    19231936                                        if ((ret == EBADMSG) && (error_info)) {
     
    19271940                                                error_info->pei_message = error_message;
    19281941                                        }
     1942                                        avp->avp_source = source;
    19291943                                        return ret;
    19301944                                }  );
     
    19411955                                                error_info->pei_avp = avp;
    19421956                                        }
     1957                                        avp->avp_source = source;
    19431958                                        return EBADMSG;
    19441959                                } );
    19451960                        avp->avp_storage.os.len = avp->avp_public.avp_len - GETAVPHDRSZ( avp->avp_public.avp_flags );
    1946                         CHECK_MALLOC(  avp->avp_storage.os.data = os0dup(avp->avp_source, avp->avp_storage.os.len)  );
     1961                        CHECK_MALLOC(  avp->avp_storage.os.data = os0dup(source, avp->avp_storage.os.len)  );
    19471962                        avp->avp_mustfreeos = 1;
    19481963                        break;
    19491964               
    19501965                case AVP_TYPE_INTEGER32:
    1951                         avp->avp_storage.i32 = (int32_t)ntohl(*(uint32_t *)avp->avp_source);
     1966                        avp->avp_storage.i32 = (int32_t)ntohl(*(uint32_t *)source);
    19521967                        break;
    19531968       
     
    19561971                        {
    19571972                                uint64_t __stor;
    1958                                 memcpy(&__stor, avp->avp_source, sizeof(__stor));
     1973                                memcpy(&__stor, source, sizeof(__stor));
    19591974                                avp->avp_storage.i64 = (int64_t)ntohll(__stor);
    19601975                        }
     
    19631978                case AVP_TYPE_UNSIGNED32:
    19641979                case AVP_TYPE_FLOAT32: /* For float, we must not cast, or the value is changed. Instead we use implicit cast by changing the member of the union */
    1965                         avp->avp_storage.u32 = (uint32_t)ntohl(*(uint32_t *)avp->avp_source);
     1980                        avp->avp_storage.u32 = (uint32_t)ntohl(*(uint32_t *)source);
    19661981                        break;
    19671982       
     
    19701985                        {
    19711986                                uint64_t __stor;
    1972                                 memcpy(&__stor, avp->avp_source, sizeof(__stor));
     1987                                memcpy(&__stor, source, sizeof(__stor));
    19731988                                avp->avp_storage.u64 = (uint64_t)ntohll(__stor);
    19741989                        }
Note: See TracChangeset for help on using the changeset viewer.