annotate libfdproto/dictionary_functions.c @ 1122:d4371b7aa0ff

New CMake option: ADDRESS_AVP_INCLUDE_PORT. Turn off for standard Host-IP-Address AVPs
author Sebastien Decugis <sdecugis@freediameter.net>
date Tue, 14 May 2013 18:01:31 +0800
parents 44f3e48dfe27
children 140450615773
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 */
1122
d4371b7aa0ff New CMake option: ADDRESS_AVP_INCLUDE_PORT. Turn off for standard Host-IP-Address AVPs
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
76 #ifdef ADDRESS_AVP_INCLUDE_PORT
d4371b7aa0ff New CMake option: ADDRESS_AVP_INCLUDE_PORT. Turn off for standard Host-IP-Address AVPs
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
77 if (sin->sin_port != 0)
d4371b7aa0ff New CMake option: ADDRESS_AVP_INCLUDE_PORT. Turn off for standard Host-IP-Address AVPs
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
78 size += 2;
d4371b7aa0ff New CMake option: ADDRESS_AVP_INCLUDE_PORT. Turn off for standard Host-IP-Address AVPs
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
79 #endif /* ADDRESS_AVP_INCLUDE_PORT */
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
80
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different 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 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
82
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different 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 /* 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
84 memcpy(buf + 2, &sin->sin_addr.s_addr, 4);
1122
d4371b7aa0ff New CMake option: ADDRESS_AVP_INCLUDE_PORT. Turn off for standard Host-IP-Address AVPs
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
85
d4371b7aa0ff New CMake option: ADDRESS_AVP_INCLUDE_PORT. Turn off for standard Host-IP-Address AVPs
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
86 #ifdef ADDRESS_AVP_INCLUDE_PORT
d4371b7aa0ff New CMake option: ADDRESS_AVP_INCLUDE_PORT. Turn off for standard Host-IP-Address AVPs
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
87 if (sin->sin_port != 0)
d4371b7aa0ff New CMake option: ADDRESS_AVP_INCLUDE_PORT. Turn off for standard Host-IP-Address AVPs
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
88 memcpy(buf + 6, &sin->sin_port, 2);
d4371b7aa0ff New CMake option: ADDRESS_AVP_INCLUDE_PORT. Turn off for standard Host-IP-Address AVPs
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
89 #endif /* ADDRESS_AVP_INCLUDE_PORT */
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
90 }
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different 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 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
92
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different 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 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
94 {
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different 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 /* 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
96 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
97
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different 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 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
99 size = 18; /* 2 for AddressType + 16 for data */
1122
d4371b7aa0ff New CMake option: ADDRESS_AVP_INCLUDE_PORT. Turn off for standard Host-IP-Address AVPs
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
100 #ifdef ADDRESS_AVP_INCLUDE_PORT
d4371b7aa0ff New CMake option: ADDRESS_AVP_INCLUDE_PORT. Turn off for standard Host-IP-Address AVPs
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
101 if (sin6->sin6_port != 0)
d4371b7aa0ff New CMake option: ADDRESS_AVP_INCLUDE_PORT. Turn off for standard Host-IP-Address AVPs
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
102 size += 2;
d4371b7aa0ff New CMake option: ADDRESS_AVP_INCLUDE_PORT. Turn off for standard Host-IP-Address AVPs
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
103 #endif /* ADDRESS_AVP_INCLUDE_PORT */
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
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 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
106
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different 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 /* 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
108 memcpy(buf + 2, &sin6->sin6_addr.s6_addr, 16);
1122
d4371b7aa0ff New CMake option: ADDRESS_AVP_INCLUDE_PORT. Turn off for standard Host-IP-Address AVPs
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
109
d4371b7aa0ff New CMake option: ADDRESS_AVP_INCLUDE_PORT. Turn off for standard Host-IP-Address AVPs
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
110 #ifdef ADDRESS_AVP_INCLUDE_PORT
d4371b7aa0ff New CMake option: ADDRESS_AVP_INCLUDE_PORT. Turn off for standard Host-IP-Address AVPs
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
111 if (sin6->sin6_port != 0)
d4371b7aa0ff New CMake option: ADDRESS_AVP_INCLUDE_PORT. Turn off for standard Host-IP-Address AVPs
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
112 memcpy(buf + 18, &sin6->sin6_port, 2);
d4371b7aa0ff New CMake option: ADDRESS_AVP_INCLUDE_PORT. Turn off for standard Host-IP-Address AVPs
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
113 #endif /* ADDRESS_AVP_INCLUDE_PORT */
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
114 }
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different 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 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
116
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different 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 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
118 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
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
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different 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 *(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
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 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
124 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
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 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
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
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different 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 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
130 {
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different 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 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
132 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
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 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
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 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
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 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
139 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
140
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different 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 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
142 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
143 {
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different 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 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
145
1122
d4371b7aa0ff New CMake option: ADDRESS_AVP_INCLUDE_PORT. Turn off for standard Host-IP-Address AVPs
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
146 CHECK_PARAMS( avp_value->os.len >= 6 );
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
147
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different 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 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
149 /* 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
150 memcpy(&sin->sin_addr.s_addr, buf, 4);
1122
d4371b7aa0ff New CMake option: ADDRESS_AVP_INCLUDE_PORT. Turn off for standard Host-IP-Address AVPs
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
151
d4371b7aa0ff New CMake option: ADDRESS_AVP_INCLUDE_PORT. Turn off for standard Host-IP-Address AVPs
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
152 if (avp_value->os.len == 8)
d4371b7aa0ff New CMake option: ADDRESS_AVP_INCLUDE_PORT. Turn off for standard Host-IP-Address AVPs
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
153 memcpy(&sin->sin_port, buf + 4, 2);
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
154 }
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different 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 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
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 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
158 {
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different 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 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
160
1122
d4371b7aa0ff New CMake option: ADDRESS_AVP_INCLUDE_PORT. Turn off for standard Host-IP-Address AVPs
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
161 CHECK_PARAMS( avp_value->os.len >= 18 );
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
162
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different 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 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
164 memcpy(&sin6->sin6_addr.s6_addr, buf, 16);
1122
d4371b7aa0ff New CMake option: ADDRESS_AVP_INCLUDE_PORT. Turn off for standard Host-IP-Address AVPs
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
165
d4371b7aa0ff New CMake option: ADDRESS_AVP_INCLUDE_PORT. Turn off for standard Host-IP-Address AVPs
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
166 if (avp_value->os.len == 20)
d4371b7aa0ff New CMake option: ADDRESS_AVP_INCLUDE_PORT. Turn off for standard Host-IP-Address AVPs
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
167 memcpy(&sin6->sin6_port, buf + 16, 2);
d4371b7aa0ff New CMake option: ADDRESS_AVP_INCLUDE_PORT. Turn off for standard Host-IP-Address AVPs
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
168
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
169 }
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different 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 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
171
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different 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 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
173 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
174 }
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different 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 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
177 }
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different 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
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different 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 /* Dump the content of an Address AVP */
1085
7d7266115a34 Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1052
diff changeset
180 DECLARE_FD_DUMP_PROTOTYPE(fd_dictfct_Address_dump, union avp_value * avp_value)
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
181 {
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different 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 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
183 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
184 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
185 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
186 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
187 } 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
188 uint16_t fam;
1085
7d7266115a34 Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1052
diff changeset
189
1093
44f3e48dfe27 Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1085
diff changeset
190 FD_DUMP_HANDLE_OFFSET();
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
191
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different 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 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
193
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different 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 /* 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
195 if (avp_value->os.len < 2) {
1085
7d7266115a34 Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1052
diff changeset
196 CHECK_MALLOC_DO( fd_dump_extend(FD_DUMP_STD_PARAMS, "[invalid length: %zd]", avp_value->os.len), return NULL);
7d7266115a34 Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1052
diff changeset
197 return *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
198 }
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different 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
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different 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 /* 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
201 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
202 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
203 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
204 /* 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
205 s.sa.sa_family = AF_INET;
1122
d4371b7aa0ff New CMake option: ADDRESS_AVP_INCLUDE_PORT. Turn off for standard Host-IP-Address AVPs
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
206 if ((avp_value->os.len != 6) && (avp_value->os.len != 8)) {
1085
7d7266115a34 Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1052
diff changeset
207 CHECK_MALLOC_DO( fd_dump_extend(FD_DUMP_STD_PARAMS, "[invalid IP length: %zd]", avp_value->os.len), return NULL);
7d7266115a34 Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1052
diff changeset
208 return *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
209 }
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different 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 memcpy(&s.sin.sin_addr.s_addr, avp_value->os.data + 2, 4);
1122
d4371b7aa0ff New CMake option: ADDRESS_AVP_INCLUDE_PORT. Turn off for standard Host-IP-Address AVPs
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
211 if (avp_value->os.len == 8)
d4371b7aa0ff New CMake option: ADDRESS_AVP_INCLUDE_PORT. Turn off for standard Host-IP-Address AVPs
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
212 memcpy(&s.sin.sin_port, avp_value->os.data + 6, 2);
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
213 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
214 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
215 /* 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
216 s.sa.sa_family = AF_INET6;
1122
d4371b7aa0ff New CMake option: ADDRESS_AVP_INCLUDE_PORT. Turn off for standard Host-IP-Address AVPs
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
217 if ((avp_value->os.len != 18) && (avp_value->os.len != 20)) {
1085
7d7266115a34 Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1052
diff changeset
218 CHECK_MALLOC_DO( fd_dump_extend(FD_DUMP_STD_PARAMS, "[invalid IP6 length: %zd]", avp_value->os.len), return NULL);
7d7266115a34 Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1052
diff changeset
219 return *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
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 memcpy(&s.sin6.sin6_addr.s6_addr, avp_value->os.data + 2, 16);
1122
d4371b7aa0ff New CMake option: ADDRESS_AVP_INCLUDE_PORT. Turn off for standard Host-IP-Address AVPs
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
222 if (avp_value->os.len == 20)
d4371b7aa0ff New CMake option: ADDRESS_AVP_INCLUDE_PORT. Turn off for standard Host-IP-Address AVPs
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
223 memcpy(&s.sin6.sin6_port, avp_value->os.data + 18, 2);
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
224 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
225 default:
1085
7d7266115a34 Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1052
diff changeset
226 CHECK_MALLOC_DO( fd_dump_extend(FD_DUMP_STD_PARAMS, "[unsupported family: 0x%hx]", fam), return NULL);
7d7266115a34 Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1052
diff changeset
227 return *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
228 }
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different 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
1122
d4371b7aa0ff New CMake option: ADDRESS_AVP_INCLUDE_PORT. Turn off for standard Host-IP-Address AVPs
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
230 return fd_sa_dump(FD_DUMP_STD_PARAMS, &s.sa, NI_NUMERICHOST);
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
231 }
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
232
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
233
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
234
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
235 /*******************************/
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
236 /* 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
237 /*******************************/
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
238
1085
7d7266115a34 Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1052
diff changeset
239 /* Dump the AVP in a natural human-readable format. This dumps the complete length of the AVP, it is up to the caller to truncate if needed */
7d7266115a34 Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1052
diff changeset
240 DECLARE_FD_DUMP_PROTOTYPE(fd_dictfct_UTF8String_dump, union avp_value * avp_value)
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
241 {
1093
44f3e48dfe27 Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1085
diff changeset
242 size_t l;
44f3e48dfe27 Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1085
diff changeset
243 FD_DUMP_HANDLE_OFFSET();
1085
7d7266115a34 Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1052
diff changeset
244
7d7266115a34 Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1052
diff changeset
245 l = avp_value->os.len;
7d7266115a34 Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1052
diff changeset
246 /* Just in case the string ends in invalid UTF-8 chars, we shorten it */
7d7266115a34 Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1052
diff changeset
247 while ((l > 0) && (avp_value->os.data[l - 1] & 0x80)) {
7d7266115a34 Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1052
diff changeset
248 /* this byte is start or cont. of multibyte sequence, as we do not know the next byte we need to delete it. */
7d7266115a34 Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1052
diff changeset
249 l--;
7d7266115a34 Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1052
diff changeset
250 if (avp_value->os.data[l] & 0x40)
7d7266115a34 Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1052
diff changeset
251 break; /* This was a start byte, we can stop the loop */
1035
2f989d1a21e9 Improve dumper for time, and print longer UTF8 strings.
Thomas Klausner <tk@giga.or.at>
parents: 1033
diff changeset
252 }
1085
7d7266115a34 Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1052
diff changeset
253
7d7266115a34 Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1052
diff changeset
254 CHECK_MALLOC_DO( fd_dump_extend(FD_DUMP_STD_PARAMS, "\"%.*s\"", (int)l, (char *)avp_value->os.data), return NULL);
7d7266115a34 Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1052
diff changeset
255
7d7266115a34 Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1052
diff changeset
256 return *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
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
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different 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
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different 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 /*******************************/
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different 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 /* 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
262 /*******************************/
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different 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
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different 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 /* 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
265 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
266
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different 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 /* 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
268 #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
269
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different 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 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
271 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
272 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
273
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different 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 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
275 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
276 #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
277 /* 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
278 #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
279 /* 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
280 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
281 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
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 #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
284 *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
285 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
286 }
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different 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
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different 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 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
289 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
290 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
291 /* 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
292 out += DIFF_EPOCH_TO_NTP;
1033
000e1904074c Fix a number of additional warnings
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1029
diff changeset
293 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
294
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different 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 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
296
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different 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 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
298 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
299 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
300 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
301 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
302 *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
303 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
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
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
306 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
307 {
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different 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 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
309 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
310
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different 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 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
312 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
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_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
315 /* 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
316
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different 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 avp_value->os.len = len;
1029
e63de8d76916 Remove a few remaining warnings
Sebastien Decugis <sdecugis@freediameter.net>
parents: 923
diff changeset
318 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
319 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
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
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different 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 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
323 {
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different 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 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
325
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different 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 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
327
1033
000e1904074c Fix a number of additional warnings
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1029
diff changeset
328 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
329 }
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different 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
1085
7d7266115a34 Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1052
diff changeset
331 DECLARE_FD_DUMP_PROTOTYPE(fd_dictfct_Time_dump, union avp_value * avp_value)
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
332 {
1035
2f989d1a21e9 Improve dumper for time, and print longer UTF8 strings.
Thomas Klausner <tk@giga.or.at>
parents: 1033
diff changeset
333 time_t val;
2f989d1a21e9 Improve dumper for time, and print longer UTF8 strings.
Thomas Klausner <tk@giga.or.at>
parents: 1033
diff changeset
334 struct tm conv;
1085
7d7266115a34 Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1052
diff changeset
335
1093
44f3e48dfe27 Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1085
diff changeset
336 FD_DUMP_HANDLE_OFFSET();
1085
7d7266115a34 Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1052
diff changeset
337
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
338 if (avp_value->os.len != 4) {
1085
7d7266115a34 Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1052
diff changeset
339 CHECK_MALLOC_DO( fd_dump_extend(FD_DUMP_STD_PARAMS, "[invalid length: %zd]", avp_value->os.len), return NULL);
7d7266115a34 Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1052
diff changeset
340 return *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
341 }
1085
7d7266115a34 Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1052
diff changeset
342
1052
b3d623f04b6d Fix a number of remaining compilation warnings
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1035
diff changeset
343 if (diameter_string_to_time_t((char *)avp_value->os.data, avp_value->os.len, &val) != 0) {
1085
7d7266115a34 Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1052
diff changeset
344 CHECK_MALLOC_DO( fd_dump_extend(FD_DUMP_STD_PARAMS, "[time conversion error]"), return NULL);
7d7266115a34 Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1052
diff changeset
345 return *buf;
1035
2f989d1a21e9 Improve dumper for time, and print longer UTF8 strings.
Thomas Klausner <tk@giga.or.at>
parents: 1033
diff changeset
346 }
1085
7d7266115a34 Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1052
diff changeset
347
7d7266115a34 Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1052
diff changeset
348 CHECK_MALLOC_DO( fd_dump_extend(FD_DUMP_STD_PARAMS, "%d%02d%02dT%02d%02d%02d+00", conv.tm_year+1900, conv.tm_mon+1, conv.tm_mday, conv.tm_hour, conv.tm_min, conv.tm_sec), return NULL);
7d7266115a34 Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1052
diff changeset
349 return *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
350 }
c7bf1a7a4e90 Split the encoders/interpreters for the dictionary types into a different file for better reusability, add decoder/interpreter for Time type based on code from Thomas Klausner
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
351
"Welcome to our mercurial repository"