annotate libfdproto/dictionary_functions.c @ 1033:000e1904074c

Fix a number of additional warnings
author Sebastien Decugis <sdecugis@freediameter.net>
date Tue, 16 Apr 2013 11:45:52 +0800
parents e63de8d76916
children 2f989d1a21e9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
922
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
1 /*********************************************************************************************************
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
2 * Software License Agreement (BSD License) *
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
3 * Author: Sebastien Decugis <sdecugis@freediameter.net> *
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
4 * *
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
5 * Copyright (c) 2013, WIDE Project and NICT *
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
6 * All rights reserved. *
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
7 * *
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
8 * Redistribution and use of this software in source and binary forms, with or without modification, are *
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
9 * permitted provided that the following conditions are met: *
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
10 * *
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
11 * * Redistributions of source code must retain the above *
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
12 * copyright notice, this list of conditions and the *
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
13 * following disclaimer. *
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
14 * *
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
15 * * Redistributions in binary form must reproduce the above *
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
16 * copyright notice, this list of conditions and the *
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
17 * following disclaimer in the documentation and/or other *
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
18 * materials provided with the distribution. *
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
19 * *
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
20 * * Neither the name of the WIDE Project or NICT nor the *
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
21 * names of its contributors may be used to endorse or *
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
22 * promote products derived from this software without *
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
23 * specific prior written permission of WIDE Project and *
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
24 * NICT. *
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
25 * *
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
26 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED *
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
27 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
28 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR *
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
29 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT *
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
30 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS *
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
31 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR *
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
32 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF *
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
33 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
34 *********************************************************************************************************/
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
35
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
36 #include "fdproto-internal.h"
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
37
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
38 /* This file contains helpers functions to be reused as callbacks in the struct dict_type_data structure.
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
39 There are three callbacks there:
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
40
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
41 - type_encode :
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
42 - type_interpret :
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
43 Those two callbacks allow to manipulate more natural structures of data in the code, and to
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
44 map transparently these natural structures with the AVP-encoded format by calling the functions
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
45 msg_avp_value_encode or msg_avp_value_interpret.
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
46 - type_dump :
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
47 This callback if provided gives a more human-readable debug information.
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
48
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
49 */
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
50
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
51 /****************************/
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
52 /* Address AVP type */
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
53 /****************************/
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
54
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
55 /* The interpret and encode functions work with a "struct sockaddr_storage" pointer for mapping
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
56 the contents of the AVP */
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
57
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
58 int fd_dictfct_Address_encode(void * data, union avp_value * avp_value)
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
59 {
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
60 sSS * ss = (sSS *) data;
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
61 uint16_t AddressType = 0;
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
62 size_t size = 0;
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
63 unsigned char * buf = NULL;
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
64
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
65 TRACE_ENTRY("%p %p", data, avp_value);
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
66 CHECK_PARAMS( data && avp_value );
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
67
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
68 switch (ss->ss_family) {
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
69 case AF_INET:
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
70 {
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
71 /* We are encoding an IP address */
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
72 sSA4 * sin = (sSA4 *)ss;
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
73
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
74 AddressType = 1;/* see http://www.iana.org/assignments/address-family-numbers/ */
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
75 size = 6; /* 2 for AddressType + 4 for data */
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
76
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
77 CHECK_MALLOC( buf = malloc(size) );
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
78
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
79 /* may not work because of alignment: *(uint32_t *)(buf+2) = htonl(sin->sin_addr.s_addr); */
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
80 memcpy(buf + 2, &sin->sin_addr.s_addr, 4);
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
81 }
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
82 break;
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
83
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
84 case AF_INET6:
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
85 {
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
86 /* We are encoding an IPv6 address */
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
87 sSA6 * sin6 = (sSA6 *)ss;
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
88
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
89 AddressType = 2;/* see http://www.iana.org/assignments/address-family-numbers/ */
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
90 size = 18; /* 2 for AddressType + 16 for data */
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
91
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
92 CHECK_MALLOC( buf = malloc(size) );
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
93
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
94 /* The order is already good here */
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
95 memcpy(buf + 2, &sin6->sin6_addr.s6_addr, 16);
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
96 }
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
97 break;
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
98
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
99 default:
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
100 CHECK_PARAMS( AddressType = 0 );
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
101 }
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
102
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
103 *(uint16_t *)buf = htons(AddressType);
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
104
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
105 avp_value->os.len = size;
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
106 avp_value->os.data = buf;
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
107
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
108 return 0;
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
109 }
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
110
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
111 int fd_dictfct_Address_interpret(union avp_value * avp_value, void * interpreted)
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
112 {
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
113 uint16_t AddressType = 0;
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
114 unsigned char * buf;
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
115
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
116 TRACE_ENTRY("%p %p", avp_value, interpreted);
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
117
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
118 CHECK_PARAMS( avp_value && interpreted && (avp_value->os.len >= 2) );
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
119
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
120 AddressType = ntohs(*(uint16_t *)avp_value->os.data);
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
121 buf = &avp_value->os.data[2];
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
122
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
123 switch (AddressType) {
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
124 case 1 /* IP */:
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
125 {
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
126 sSA4 * sin = (sSA4 *)interpreted;
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
127
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
128 CHECK_PARAMS( avp_value->os.len == 6 );
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
129
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
130 sin->sin_family = AF_INET;
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
131 /* sin->sin_addr.s_addr = ntohl( * (uint32_t *) buf); -- may not work because of bad alignment */
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
132 memcpy(&sin->sin_addr.s_addr, buf, 4);
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
133 }
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
134 break;
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
135
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
136 case 2 /* IP6 */:
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
137 {
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
138 sSA6 * sin6 = (sSA6 *)interpreted;
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
139
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
140 CHECK_PARAMS( avp_value->os.len == 18 );
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
141
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
142 sin6->sin6_family = AF_INET6;
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
143 memcpy(&sin6->sin6_addr.s6_addr, buf, 16);
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
144 }
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
145 break;
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
146
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
147 default:
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
148 CHECK_PARAMS( AddressType = 0 );
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
149 }
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
150
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
151 return 0;
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
152 }
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
153
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
154 /* Dump the content of an Address AVP */
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
155 char * fd_dictfct_Address_dump(union avp_value * avp_value)
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
156 {
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
157 char * ret;
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
158 #define STR_LEN 1024
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
159 union {
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
160 sSA sa;
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
161 sSS ss;
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
162 sSA4 sin;
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
163 sSA6 sin6;
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
164 } s;
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
165 uint16_t fam;
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
166
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
167 memset(&s, 0, sizeof(s));
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
168
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
169 CHECK_MALLOC_DO( ret = malloc(STR_LEN), return NULL );
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
170
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
171 /* The first two octets represent the address family, http://www.iana.org/assignments/address-family-numbers/ */
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
172 if (avp_value->os.len < 2) {
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
173 snprintf(ret, STR_LEN, "[invalid length: %zd]", avp_value->os.len);
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
174 return ret;
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
175 }
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
176
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
177 /* Following octets are the address in network byte order already */
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
178 fam = avp_value->os.data[0] << 8 | avp_value->os.data[1];
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
179 switch (fam) {
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
180 case 1:
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
181 /* IP */
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
182 s.sa.sa_family = AF_INET;
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
183 if (avp_value->os.len != 6) {
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
184 snprintf(ret, STR_LEN, "[invalid IP length: %zd]", avp_value->os.len);
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
185 return ret;
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
186 }
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
187 memcpy(&s.sin.sin_addr.s_addr, avp_value->os.data + 2, 4);
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
188 break;
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
189 case 2:
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
190 /* IP6 */
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
191 s.sa.sa_family = AF_INET6;
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
192 if (avp_value->os.len != 18) {
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
193 snprintf(ret, STR_LEN, "[invalid IP6 length: %zd]", avp_value->os.len);
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
194 return ret;
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
195 }
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
196 memcpy(&s.sin6.sin6_addr.s6_addr, avp_value->os.data + 2, 16);
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
197 break;
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
198 default:
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
199 snprintf(ret, STR_LEN, "[unsupported family: 0x%hx]", fam);
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
200 return ret;
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
201 }
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
202
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
203 {
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
204 int rc = getnameinfo(&s.sa, sSAlen(&s.sa), ret, STR_LEN, NULL, 0, NI_NUMERICHOST);
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
205 if (rc)
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
206 snprintf(ret, STR_LEN, "%s", (char *)gai_strerror(rc));
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
207 }
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
208
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
209 return ret;
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
210 }
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
211
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
212
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
213
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
214 /*******************************/
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
215 /* UTF8String AVP type */
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
216 /*******************************/
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
217
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
218 /* Dump the AVP in a natural human-readable format */
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
219 char * fd_dictfct_UTF8String_dump(union avp_value * avp_value)
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
220 {
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
221 #define TRUNC_LEN 42 /* avoid very long strings */
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
222 char * ret = strndup((char *)avp_value->os.data, TRUNC_LEN);
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
223 if (ret && (*ret != '\0')) {
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
224 /* We sanitize the returned string to avoid UTF8 boundary problem.
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
225 We do this whether the string is trucated at TRUNC_LEN or not, to avoid potential problem
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
226 with malformed AVP */
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
227
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
228 char * end = strchr(ret, '\0');
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
229
923
6a4d08e239bd Fix UTF8Dump function for the case of truncating UTF8 multibyte sequence,
Sebastien Decugis <sdecugis@freediameter.net>
parents: 922
diff changeset
230 while (end > ret) {
6a4d08e239bd Fix UTF8Dump function for the case of truncating UTF8 multibyte sequence,
Sebastien Decugis <sdecugis@freediameter.net>
parents: 922
diff changeset
231 end--;
6a4d08e239bd Fix UTF8Dump function for the case of truncating UTF8 multibyte sequence,
Sebastien Decugis <sdecugis@freediameter.net>
parents: 922
diff changeset
232 char b = *end;
6a4d08e239bd Fix UTF8Dump function for the case of truncating UTF8 multibyte sequence,
Sebastien Decugis <sdecugis@freediameter.net>
parents: 922
diff changeset
233 /* after the position pointed by end, we have only \0s */
6a4d08e239bd Fix UTF8Dump function for the case of truncating UTF8 multibyte sequence,
Sebastien Decugis <sdecugis@freediameter.net>
parents: 922
diff changeset
234 if ((b & 0x80) == 0) {
6a4d08e239bd Fix UTF8Dump function for the case of truncating UTF8 multibyte sequence,
Sebastien Decugis <sdecugis@freediameter.net>
parents: 922
diff changeset
235 break; /* this is a single byte char, no problem */
6a4d08e239bd Fix UTF8Dump function for the case of truncating UTF8 multibyte sequence,
Sebastien Decugis <sdecugis@freediameter.net>
parents: 922
diff changeset
236 } else {
6a4d08e239bd Fix UTF8Dump function for the case of truncating UTF8 multibyte sequence,
Sebastien Decugis <sdecugis@freediameter.net>
parents: 922
diff changeset
237 /* this byte is start or cont. of multibyte sequence, as we do not know the next byte we need to delete it. */
6a4d08e239bd Fix UTF8Dump function for the case of truncating UTF8 multibyte sequence,
Sebastien Decugis <sdecugis@freediameter.net>
parents: 922
diff changeset
238 *end = '\0';
6a4d08e239bd Fix UTF8Dump function for the case of truncating UTF8 multibyte sequence,
Sebastien Decugis <sdecugis@freediameter.net>
parents: 922
diff changeset
239 if (b & 0x40)
6a4d08e239bd Fix UTF8Dump function for the case of truncating UTF8 multibyte sequence,
Sebastien Decugis <sdecugis@freediameter.net>
parents: 922
diff changeset
240 break; /* This was a start byte, we can stop the loop */
6a4d08e239bd Fix UTF8Dump function for the case of truncating UTF8 multibyte sequence,
Sebastien Decugis <sdecugis@freediameter.net>
parents: 922
diff changeset
241 }
6a4d08e239bd Fix UTF8Dump function for the case of truncating UTF8 multibyte sequence,
Sebastien Decugis <sdecugis@freediameter.net>
parents: 922
diff changeset
242 }
922
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
243 }
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
244 return ret;
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
245 }
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
246
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
247
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
248 /*******************************/
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
249 /* Time AVP type */
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
250 /*******************************/
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
251
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
252 /* The interpret and encode functions work with a "time_t" pointer for mapping
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
253 the contents of the AVP */
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
254
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
255 /* Unix Epoch starts 1970-01-01, NTP 0 is at 1900-01-01 */
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
256 #define DIFF_EPOCH_TO_NTP ((365*(1970-1900) + 17ul) * 24 * 60 * 60)
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
257
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
258 static int diameter_string_to_time_t(const char *str, size_t len, time_t *result) {
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
259 time_t time_stamp;
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
260 CHECK_PARAMS(len == 4);
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
261
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
262 time_stamp = (((unsigned long)(str[0]&0xff))<<24) + ((str[1]&0xff)<<16) + ((str[2]&0xff)<<8) + ((str[3]&0xff));
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
263 time_stamp -= DIFF_EPOCH_TO_NTP;
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
264 #ifdef FIX__NEEDED_FOR_YEAR_2036_AND_LATER
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
265 /* NTP overflows in 2036; after that, values start at zero again */
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
266 #define NTP_OVERFLOW_CORRECTION (0x100000000ull)
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
267 /* XXX: debug and find correct conversion */
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
268 if (str[0] & 0x80 == 0x00) {
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
269 time_stamp += NTP_OVERFLOW_CORRECTION;
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
270 }
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
271 #endif
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
272 *result = time_stamp;
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
273 return 0;
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
274 }
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
275
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
276 static int time_t_to_diameter_string(time_t time_stamp, char **result) {
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
277 uint64_t out = time_stamp;
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
278 char *conv;
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
279 /* XXX: 2036 fix */
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
280 out += DIFF_EPOCH_TO_NTP;
1033
000e1904074c Fix a number of additional warnings
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1029
diff changeset
281 CHECK_PARAMS( (out >> 32) == 0);
922
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
282
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
283 CHECK_MALLOC(conv=(char *)malloc(5));
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
284
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
285 conv[0] = (out>>24) & 0xff;
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
286 conv[1] = (out>>16) & 0xff;
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
287 conv[2] = (out>> 8) & 0xff;
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
288 conv[3] = out & 0xff;
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
289 conv[4] = '\0';
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
290 *result = conv;
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
291 return 0;
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
292 }
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
293
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
294 int fd_dictfct_Time_encode(void * data, union avp_value * avp_value)
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
295 {
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
296 char * buf;
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
297 size_t len;
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
298
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
299 TRACE_ENTRY("%p %p", data, avp_value);
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
300 CHECK_PARAMS( data && avp_value );
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
301
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
302 CHECK_FCT( time_t_to_diameter_string( *((time_t *)data), &buf) );
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
303 /* FIXME: return len from the function above? */ len = 4;
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
304
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
305 avp_value->os.len = len;
1029
e63de8d76916 Remove a few remaining warnings
Sebastien Decugis <sdecugis@freediameter.net>
parents: 923
diff changeset
306 avp_value->os.data = (uint8_t *)buf;
922
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
307 return 0;
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
308 }
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
309
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
310 int fd_dictfct_Time_interpret(union avp_value * avp_value, void * interpreted)
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
311 {
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
312 TRACE_ENTRY("%p %p", avp_value, interpreted);
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
313
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
314 CHECK_PARAMS( avp_value && interpreted );
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
315
1033
000e1904074c Fix a number of additional warnings
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1029
diff changeset
316 return diameter_string_to_time_t((const char *)avp_value->os.data, avp_value->os.len, interpreted);
922
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
317 }
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
318
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
319 char * fd_dictfct_Time_dump(union avp_value * avp_value)
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
320 {
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
321 char * ret;
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
322 CHECK_MALLOC_DO( ret = malloc(STR_LEN), return NULL );
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
323 if (avp_value->os.len != 4) {
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
324 snprintf(ret, STR_LEN, "[invalid length: %zd]", avp_value->os.len);
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
325 return ret;
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
326 }
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
327 /* TODO: display the time as human-readable */
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
328 snprintf(ret, STR_LEN, "[TODO Time dump: 0x%02hhx%02hhx%02hhx%02hhx]", avp_value->os.data[0], avp_value->os.data[1], avp_value->os.data[2], avp_value->os.data[3]);
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
329 return ret;
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
330 }
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
331
"Welcome to our mercurial repository"