Mercurial > hg > freeDiameter
annotate libfdproto/ostr.c @ 1056:e330166422ba
Use the pragma outside the function
author | Sebastien Decugis <sdecugis@freediameter.net> |
---|---|
date | Mon, 29 Apr 2013 12:30:07 +0800 |
parents | b95e2b9b78d8 |
children | 54f06e95c2ee |
rev | line source |
---|---|
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
1 /********************************************************************************************************* |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
2 * Software License Agreement (BSD License) * |
740
4a9f08d6b6ba
Updated my mail address
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
738
diff
changeset
|
3 * Author: Sebastien Decugis <sdecugis@freediameter.net> * |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
4 * * |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
5 * Copyright (c) 2011, WIDE Project and NICT * |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
6 * All rights reserved. * |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
7 * * |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
8 * Redistribution and use of this software in source and binary forms, with or without modification, are * |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
9 * permitted provided that the following conditions are met: * |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
10 * * |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
11 * * Redistributions of source code must retain the above * |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
12 * copyright notice, this list of conditions and the * |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
13 * following disclaimer. * |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
14 * * |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
15 * * Redistributions in binary form must reproduce the above * |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
16 * copyright notice, this list of conditions and the * |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
17 * following disclaimer in the documentation and/or other * |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
18 * materials provided with the distribution. * |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
19 * * |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
20 * * Neither the name of the WIDE Project or NICT nor the * |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
21 * names of its contributors may be used to endorse or * |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
22 * promote products derived from this software without * |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
23 * specific prior written permission of WIDE Project and * |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
24 * NICT. * |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
25 * * |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
26 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED * |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
27 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
28 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR * |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
29 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
30 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
31 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR * |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
32 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
33 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
34 *********************************************************************************************************/ |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
35 |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
36 #include "fdproto-internal.h" |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
37 |
707
e387d5c6b6f5
Added support for Internationalized Domain Names (IDNA) using GNU libidn
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
706
diff
changeset
|
38 #if (!defined(DIAMID_IDNA_IGNORE) && !defined(DIAMID_IDNA_REJECT)) |
e387d5c6b6f5
Added support for Internationalized Domain Names (IDNA) using GNU libidn
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
706
diff
changeset
|
39 /* Process IDNA with stringprep -- See RFC5890 -- and libidn documentation... */ |
e387d5c6b6f5
Added support for Internationalized Domain Names (IDNA) using GNU libidn
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
706
diff
changeset
|
40 #include <idna.h> /* idna_to_ascii_8z() */ |
e387d5c6b6f5
Added support for Internationalized Domain Names (IDNA) using GNU libidn
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
706
diff
changeset
|
41 #endif /* !defined(DIAMID_IDNA_IGNORE) && !defined(DIAMID_IDNA_REJECT) */ |
e387d5c6b6f5
Added support for Internationalized Domain Names (IDNA) using GNU libidn
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
706
diff
changeset
|
42 |
730 | 43 /* Similar to strdup with (must have been verified) os0_t */ |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
44 os0_t os0dup_int(os0_t s, size_t l) { |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
45 os0_t r; |
730 | 46 CHECK_MALLOC_DO( r = malloc(l+1), return NULL ); |
752
9e9840ccf059
Attempt to handle more gracefully (invalid) AVPs that contain an empty octetstring
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
743
diff
changeset
|
47 if (l) |
9e9840ccf059
Attempt to handle more gracefully (invalid) AVPs that contain an empty octetstring
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
743
diff
changeset
|
48 memcpy(r, s, l); /* this might be faster than a strcpy or strdup because it can work with 32 or 64b blocks */ |
730 | 49 r[l] = '\0'; |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
50 return r; |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
51 } |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
52 |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
53 /* case sensitive comparison, fast */ |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
54 int fd_os_cmp_int(uint8_t * os1, size_t os1sz, uint8_t * os2, size_t os2sz) |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
55 { |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
56 ASSERT( os1 && os2); |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
57 if (os1sz < os2sz) |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
58 return -1; |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
59 if (os1sz > os2sz) |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
60 return 1; |
752
9e9840ccf059
Attempt to handle more gracefully (invalid) AVPs that contain an empty octetstring
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
743
diff
changeset
|
61 return os1sz ? memcmp(os1, os2, os1sz) : 0; |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
62 } |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
63 |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
64 /* a local version of tolower() that does not depend on LC_CTYPE locale */ |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
65 static inline uint8_t asciitolower(uint8_t a) |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
66 { |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
67 if ((a >= 'A') && (a <= 'Z')) |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
68 return a + 32 /* == 'a' - 'A' */; |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
69 return a; |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
70 } |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
71 |
738
d666051658bd
Fix broken 'almostcasecmp' logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
730
diff
changeset
|
72 /* less sensitive to case, slower. */ |
743
5d529eb0ad33
Fix bug in peers order
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
73 /* the semantics of "maybefurther" assume you are searching for os1 in a list of elements ordered, each element passed as os2 */ |
738
d666051658bd
Fix broken 'almostcasecmp' logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
730
diff
changeset
|
74 int fd_os_almostcasesrch_int(uint8_t * os1, size_t os1sz, uint8_t * os2, size_t os2sz, int *maybefurther) |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
75 { |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
76 int i; |
738
d666051658bd
Fix broken 'almostcasecmp' logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
730
diff
changeset
|
77 int res = 0; |
d666051658bd
Fix broken 'almostcasecmp' logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
730
diff
changeset
|
78 |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
79 ASSERT( os1 && os2); |
738
d666051658bd
Fix broken 'almostcasecmp' logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
730
diff
changeset
|
80 if (maybefurther) |
d666051658bd
Fix broken 'almostcasecmp' logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
730
diff
changeset
|
81 *maybefurther = 0; |
d666051658bd
Fix broken 'almostcasecmp' logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
730
diff
changeset
|
82 |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
83 if (os1sz < os2sz) |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
84 return -1; |
738
d666051658bd
Fix broken 'almostcasecmp' logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
730
diff
changeset
|
85 |
d666051658bd
Fix broken 'almostcasecmp' logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
730
diff
changeset
|
86 if (maybefurther) |
d666051658bd
Fix broken 'almostcasecmp' logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
730
diff
changeset
|
87 *maybefurther = 1; |
d666051658bd
Fix broken 'almostcasecmp' logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
730
diff
changeset
|
88 |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
89 if (os1sz > os2sz) |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
90 return 1; |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
91 |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
92 for (i = 0; i < os1sz; i++) { |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
93 if (os1[i] == os2[i]) |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
94 continue; |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
95 |
738
d666051658bd
Fix broken 'almostcasecmp' logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
730
diff
changeset
|
96 if (!res) |
d666051658bd
Fix broken 'almostcasecmp' logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
730
diff
changeset
|
97 res = os1[i] < os2[i] ? -1 : 1; |
d666051658bd
Fix broken 'almostcasecmp' logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
730
diff
changeset
|
98 |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
99 if (asciitolower(os1[i]) == asciitolower(os2[i])) |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
100 continue; |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
101 |
738
d666051658bd
Fix broken 'almostcasecmp' logic
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
730
diff
changeset
|
102 return res; |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
103 } |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
104 |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
105 return 0; |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
106 } |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
107 |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
108 /* Check if the string contains only ASCII */ |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
109 int fd_os_is_valid_DiameterIdentity(uint8_t * os, size_t ossz) |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
110 { |
707
e387d5c6b6f5
Added support for Internationalized Domain Names (IDNA) using GNU libidn
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
706
diff
changeset
|
111 #ifdef DIAMID_IDNA_IGNORE |
e387d5c6b6f5
Added support for Internationalized Domain Names (IDNA) using GNU libidn
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
706
diff
changeset
|
112 |
e387d5c6b6f5
Added support for Internationalized Domain Names (IDNA) using GNU libidn
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
706
diff
changeset
|
113 /* Allow anything */ |
e387d5c6b6f5
Added support for Internationalized Domain Names (IDNA) using GNU libidn
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
706
diff
changeset
|
114 |
e387d5c6b6f5
Added support for Internationalized Domain Names (IDNA) using GNU libidn
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
706
diff
changeset
|
115 #else /* DIAMID_IDNA_IGNORE */ |
e387d5c6b6f5
Added support for Internationalized Domain Names (IDNA) using GNU libidn
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
706
diff
changeset
|
116 |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
117 int i; |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
118 |
707
e387d5c6b6f5
Added support for Internationalized Domain Names (IDNA) using GNU libidn
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
706
diff
changeset
|
119 /* Allow only letters, digits, hyphen, dot */ |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
120 for (i=0; i < ossz; i++) { |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
121 if (os[i] > 'z') |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
122 break; |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
123 if (os[i] >= 'a') |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
124 continue; |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
125 if ((os[i] >= 'A') && (os[i] <= 'Z')) |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
126 continue; |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
127 if ((os[i] == '-') || (os[i] == '.')) |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
128 continue; |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
129 if ((os[i] >= '0') && (os[i] <= '9')) |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
130 continue; |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
131 break; |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
132 } |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
133 if (i < ossz) { |
707
e387d5c6b6f5
Added support for Internationalized Domain Names (IDNA) using GNU libidn
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
706
diff
changeset
|
134 int nb = 1; |
e387d5c6b6f5
Added support for Internationalized Domain Names (IDNA) using GNU libidn
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
706
diff
changeset
|
135 /* To get a better display, check if the invalid char is UTF-8 */ |
e387d5c6b6f5
Added support for Internationalized Domain Names (IDNA) using GNU libidn
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
706
diff
changeset
|
136 if ((os[i] & 0xE0) == 0xC0 /* 110xxxxx */) { |
e387d5c6b6f5
Added support for Internationalized Domain Names (IDNA) using GNU libidn
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
706
diff
changeset
|
137 if ((i < ossz - 1) && ((os[i + 1] & 0xC0) == 0x80 /* 10xxxxxx */)) |
e387d5c6b6f5
Added support for Internationalized Domain Names (IDNA) using GNU libidn
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
706
diff
changeset
|
138 nb = 2; |
e387d5c6b6f5
Added support for Internationalized Domain Names (IDNA) using GNU libidn
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
706
diff
changeset
|
139 goto disp; |
e387d5c6b6f5
Added support for Internationalized Domain Names (IDNA) using GNU libidn
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
706
diff
changeset
|
140 } |
e387d5c6b6f5
Added support for Internationalized Domain Names (IDNA) using GNU libidn
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
706
diff
changeset
|
141 if ((os[i] & 0xF0) == 0xE0 /* 1110xxxx */) { |
e387d5c6b6f5
Added support for Internationalized Domain Names (IDNA) using GNU libidn
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
706
diff
changeset
|
142 if ((i < ossz - 2) && ((os[i + 1] & 0xC0) == 0x80 /* 10xxxxxx */) |
e387d5c6b6f5
Added support for Internationalized Domain Names (IDNA) using GNU libidn
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
706
diff
changeset
|
143 && ((os[i + 2] & 0xC0) == 0x80 /* 10xxxxxx */)) |
e387d5c6b6f5
Added support for Internationalized Domain Names (IDNA) using GNU libidn
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
706
diff
changeset
|
144 nb = 3; |
e387d5c6b6f5
Added support for Internationalized Domain Names (IDNA) using GNU libidn
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
706
diff
changeset
|
145 goto disp; |
e387d5c6b6f5
Added support for Internationalized Domain Names (IDNA) using GNU libidn
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
706
diff
changeset
|
146 } |
e387d5c6b6f5
Added support for Internationalized Domain Names (IDNA) using GNU libidn
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
706
diff
changeset
|
147 if ((os[i] & 0xF8) == 0xF0 /* 11110xxx */) { |
e387d5c6b6f5
Added support for Internationalized Domain Names (IDNA) using GNU libidn
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
706
diff
changeset
|
148 if ((i < ossz - 3) && ((os[i + 1] & 0xC0) == 0x80 /* 10xxxxxx */) |
e387d5c6b6f5
Added support for Internationalized Domain Names (IDNA) using GNU libidn
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
706
diff
changeset
|
149 && ((os[i + 2] & 0xC0) == 0x80 /* 10xxxxxx */) |
e387d5c6b6f5
Added support for Internationalized Domain Names (IDNA) using GNU libidn
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
706
diff
changeset
|
150 && ((os[i + 3] & 0xC0) == 0x80 /* 10xxxxxx */)) |
e387d5c6b6f5
Added support for Internationalized Domain Names (IDNA) using GNU libidn
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
706
diff
changeset
|
151 nb = 4; |
e387d5c6b6f5
Added support for Internationalized Domain Names (IDNA) using GNU libidn
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
706
diff
changeset
|
152 goto disp; |
e387d5c6b6f5
Added support for Internationalized Domain Names (IDNA) using GNU libidn
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
706
diff
changeset
|
153 } |
e387d5c6b6f5
Added support for Internationalized Domain Names (IDNA) using GNU libidn
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
706
diff
changeset
|
154 if ((os[i] & 0xFC) == 0xF8 /* 111110xx */) { |
e387d5c6b6f5
Added support for Internationalized Domain Names (IDNA) using GNU libidn
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
706
diff
changeset
|
155 if ((i < ossz - 4) && ((os[i + 1] & 0xC0) == 0x80 /* 10xxxxxx */) |
e387d5c6b6f5
Added support for Internationalized Domain Names (IDNA) using GNU libidn
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
706
diff
changeset
|
156 && ((os[i + 2] & 0xC0) == 0x80 /* 10xxxxxx */) |
e387d5c6b6f5
Added support for Internationalized Domain Names (IDNA) using GNU libidn
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
706
diff
changeset
|
157 && ((os[i + 3] & 0xC0) == 0x80 /* 10xxxxxx */) |
e387d5c6b6f5
Added support for Internationalized Domain Names (IDNA) using GNU libidn
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
706
diff
changeset
|
158 && ((os[i + 4] & 0xC0) == 0x80 /* 10xxxxxx */)) |
e387d5c6b6f5
Added support for Internationalized Domain Names (IDNA) using GNU libidn
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
706
diff
changeset
|
159 nb = 5; |
e387d5c6b6f5
Added support for Internationalized Domain Names (IDNA) using GNU libidn
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
706
diff
changeset
|
160 goto disp; |
e387d5c6b6f5
Added support for Internationalized Domain Names (IDNA) using GNU libidn
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
706
diff
changeset
|
161 } |
e387d5c6b6f5
Added support for Internationalized Domain Names (IDNA) using GNU libidn
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
706
diff
changeset
|
162 if ((os[i] & 0xFE) == 0xFC /* 1111110x */) { |
e387d5c6b6f5
Added support for Internationalized Domain Names (IDNA) using GNU libidn
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
706
diff
changeset
|
163 if ((i < ossz - 5) && ((os[i + 1] & 0xC0) == 0x80 /* 10xxxxxx */) |
e387d5c6b6f5
Added support for Internationalized Domain Names (IDNA) using GNU libidn
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
706
diff
changeset
|
164 && ((os[i + 2] & 0xC0) == 0x80 /* 10xxxxxx */) |
e387d5c6b6f5
Added support for Internationalized Domain Names (IDNA) using GNU libidn
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
706
diff
changeset
|
165 && ((os[i + 3] & 0xC0) == 0x80 /* 10xxxxxx */) |
e387d5c6b6f5
Added support for Internationalized Domain Names (IDNA) using GNU libidn
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
706
diff
changeset
|
166 && ((os[i + 4] & 0xC0) == 0x80 /* 10xxxxxx */) |
e387d5c6b6f5
Added support for Internationalized Domain Names (IDNA) using GNU libidn
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
706
diff
changeset
|
167 && ((os[i + 5] & 0xC0) == 0x80 /* 10xxxxxx */)) |
e387d5c6b6f5
Added support for Internationalized Domain Names (IDNA) using GNU libidn
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
706
diff
changeset
|
168 nb = 6; |
e387d5c6b6f5
Added support for Internationalized Domain Names (IDNA) using GNU libidn
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
706
diff
changeset
|
169 goto disp; |
e387d5c6b6f5
Added support for Internationalized Domain Names (IDNA) using GNU libidn
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
706
diff
changeset
|
170 } |
e387d5c6b6f5
Added support for Internationalized Domain Names (IDNA) using GNU libidn
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
706
diff
changeset
|
171 /* otherwise, we just display the hex code */ |
1027
0117a7746b21
Fix a number of errors and warnings introduced/highlighted by recent commits
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1022
diff
changeset
|
172 TRACE_DEBUG(INFO, "Invalid character (0x%hhX) at offset %d in DiameterIdentity '%.*s'", os[i], i+1, (int)ossz, os); |
707
e387d5c6b6f5
Added support for Internationalized Domain Names (IDNA) using GNU libidn
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
706
diff
changeset
|
173 return 0; |
e387d5c6b6f5
Added support for Internationalized Domain Names (IDNA) using GNU libidn
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
706
diff
changeset
|
174 disp: |
1027
0117a7746b21
Fix a number of errors and warnings introduced/highlighted by recent commits
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1022
diff
changeset
|
175 TRACE_DEBUG(INFO, "Invalid character '%.*s' at offset %d in DiameterIdentity '%.*s'", nb, os + i, i+1, (int)ossz, os); |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
176 return 0; |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
177 } |
707
e387d5c6b6f5
Added support for Internationalized Domain Names (IDNA) using GNU libidn
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
706
diff
changeset
|
178 |
e387d5c6b6f5
Added support for Internationalized Domain Names (IDNA) using GNU libidn
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
706
diff
changeset
|
179 #endif /* DIAMID_IDNA_IGNORE */ |
e387d5c6b6f5
Added support for Internationalized Domain Names (IDNA) using GNU libidn
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
706
diff
changeset
|
180 |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
181 return 1; |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
182 } |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
183 |
717
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
184 /* The following function validates a string as a Diameter Identity or applies the IDNA transformation on it |
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
185 if *inoutsz is != 0 on entry, *id may not be \0-terminated. |
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
186 memory has the following meaning: 0: *id can be realloc'd. 1: *id must be malloc'd on output (was static) |
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
187 */ |
1056
e330166422ba
Use the pragma outside the function
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1054
diff
changeset
|
188 #if defined(DIAMID_IDNA_IGNORE) || defined(DIAMID_IDNA_REJECT) |
e330166422ba
Use the pragma outside the function
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1054
diff
changeset
|
189 GCC_DIAG_OFF("-Wunused-but-set-variable") |
e330166422ba
Use the pragma outside the function
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1054
diff
changeset
|
190 #endif |
717
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
191 int fd_os_validate_DiameterIdentity(char ** id, size_t * inoutsz, int memory) |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
192 { |
717
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
193 int gotsize = 0; |
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
194 |
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
195 TRACE_ENTRY("%p %p", id, inoutsz); |
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
196 CHECK_PARAMS( id && *id && inoutsz ); |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
197 |
717
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
198 if (!*inoutsz) |
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
199 *inoutsz = strlen(*id); |
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
200 else |
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
201 gotsize = 1; |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
202 |
707
e387d5c6b6f5
Added support for Internationalized Domain Names (IDNA) using GNU libidn
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
706
diff
changeset
|
203 #ifndef DIAMID_IDNA_IGNORE |
e387d5c6b6f5
Added support for Internationalized Domain Names (IDNA) using GNU libidn
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
706
diff
changeset
|
204 |
717
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
205 if (!fd_os_is_valid_DiameterIdentity((os0_t)*id, *inoutsz)) { |
707
e387d5c6b6f5
Added support for Internationalized Domain Names (IDNA) using GNU libidn
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
706
diff
changeset
|
206 |
e387d5c6b6f5
Added support for Internationalized Domain Names (IDNA) using GNU libidn
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
706
diff
changeset
|
207 #ifdef DIAMID_IDNA_REJECT |
e387d5c6b6f5
Added support for Internationalized Domain Names (IDNA) using GNU libidn
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
706
diff
changeset
|
208 |
e387d5c6b6f5
Added support for Internationalized Domain Names (IDNA) using GNU libidn
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
706
diff
changeset
|
209 TRACE_DEBUG(INFO, "The string '%s' is not a valid DiameterIdentity!", *id); |
e387d5c6b6f5
Added support for Internationalized Domain Names (IDNA) using GNU libidn
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
706
diff
changeset
|
210 TRACE_DEBUG(INFO, "Returning EINVAL since fD is compiled with option DIAMID_IDNA_REJECT."); |
e387d5c6b6f5
Added support for Internationalized Domain Names (IDNA) using GNU libidn
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
706
diff
changeset
|
211 return EINVAL; |
e387d5c6b6f5
Added support for Internationalized Domain Names (IDNA) using GNU libidn
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
706
diff
changeset
|
212 |
e387d5c6b6f5
Added support for Internationalized Domain Names (IDNA) using GNU libidn
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
706
diff
changeset
|
213 #else /* DIAMID_IDNA_REJECT */ |
e387d5c6b6f5
Added support for Internationalized Domain Names (IDNA) using GNU libidn
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
706
diff
changeset
|
214 |
e387d5c6b6f5
Added support for Internationalized Domain Names (IDNA) using GNU libidn
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
706
diff
changeset
|
215 char *processed; |
e387d5c6b6f5
Added support for Internationalized Domain Names (IDNA) using GNU libidn
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
706
diff
changeset
|
216 int ret; |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
217 |
717
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
218 if (gotsize) { /* make it \0-terminated */ |
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
219 if (memory) { |
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
220 CHECK_MALLOC( *id = os0dup(*id, *inoutsz) ); |
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
221 memory = 0; |
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
222 } else { |
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
223 CHECK_MALLOC( *id = realloc(*id, *inoutsz + 1) ); |
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
224 (*id)[*inoutsz] = '0'; |
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
225 } |
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
226 } |
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
227 |
707
e387d5c6b6f5
Added support for Internationalized Domain Names (IDNA) using GNU libidn
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
706
diff
changeset
|
228 ret = idna_to_ascii_8z ( *id, &processed, IDNA_USE_STD3_ASCII_RULES ); |
e387d5c6b6f5
Added support for Internationalized Domain Names (IDNA) using GNU libidn
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
706
diff
changeset
|
229 if (ret == IDNA_SUCCESS) { |
e387d5c6b6f5
Added support for Internationalized Domain Names (IDNA) using GNU libidn
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
706
diff
changeset
|
230 TRACE_DEBUG(INFO, "The string '%s' is not a valid DiameterIdentity, it was changed to '%s'", *id, processed); |
e387d5c6b6f5
Added support for Internationalized Domain Names (IDNA) using GNU libidn
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
706
diff
changeset
|
231 if (memory == 0) |
e387d5c6b6f5
Added support for Internationalized Domain Names (IDNA) using GNU libidn
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
706
diff
changeset
|
232 free(*id); |
e387d5c6b6f5
Added support for Internationalized Domain Names (IDNA) using GNU libidn
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
706
diff
changeset
|
233 *id = processed; |
717
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
234 *inoutsz = strlen(processed); |
707
e387d5c6b6f5
Added support for Internationalized Domain Names (IDNA) using GNU libidn
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
706
diff
changeset
|
235 /* Done! */ |
e387d5c6b6f5
Added support for Internationalized Domain Names (IDNA) using GNU libidn
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
706
diff
changeset
|
236 } else { |
e387d5c6b6f5
Added support for Internationalized Domain Names (IDNA) using GNU libidn
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
706
diff
changeset
|
237 TRACE_DEBUG(INFO, "The string '%s' is not a valid DiameterIdentity and cannot be sanitanized: %s", *id, idna_strerror (ret)); |
e387d5c6b6f5
Added support for Internationalized Domain Names (IDNA) using GNU libidn
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
706
diff
changeset
|
238 return EINVAL; |
e387d5c6b6f5
Added support for Internationalized Domain Names (IDNA) using GNU libidn
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
706
diff
changeset
|
239 } |
e387d5c6b6f5
Added support for Internationalized Domain Names (IDNA) using GNU libidn
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
706
diff
changeset
|
240 |
e387d5c6b6f5
Added support for Internationalized Domain Names (IDNA) using GNU libidn
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
706
diff
changeset
|
241 #endif /* DIAMID_IDNA_REJECT */ |
e387d5c6b6f5
Added support for Internationalized Domain Names (IDNA) using GNU libidn
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
706
diff
changeset
|
242 } else |
e387d5c6b6f5
Added support for Internationalized Domain Names (IDNA) using GNU libidn
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
706
diff
changeset
|
243 #endif /* ! DIAMID_IDNA_IGNORE */ |
e387d5c6b6f5
Added support for Internationalized Domain Names (IDNA) using GNU libidn
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
706
diff
changeset
|
244 { |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
245 if (memory == 1) { |
717
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
246 CHECK_MALLOC( *id = os0dup(*id, *inoutsz) ); |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
247 } |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
248 } |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
249 return 0; |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
250 } |
1056
e330166422ba
Use the pragma outside the function
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1054
diff
changeset
|
251 #if defined(DIAMID_IDNA_IGNORE) || defined(DIAMID_IDNA_REJECT) |
e330166422ba
Use the pragma outside the function
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1054
diff
changeset
|
252 GCC_DIAG_ON("-Wunused-but-set-variable") |
e330166422ba
Use the pragma outside the function
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1054
diff
changeset
|
253 #endif |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
254 |
717
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
255 /* Analyze a DiameterURI and return its components. |
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
256 Return EINVAL if the URI is not valid. |
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
257 *diamid is malloc'd on function return and must be freed (it is processed by fd_os_validate_DiameterIdentity). |
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
258 *secure is 0 (no security) or 1 (security enabled) on return. |
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
259 *port is 0 (default) or a value in host byte order on return. |
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
260 *transport is 0 (default) or IPPROTO_* on return. |
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
261 *proto is 0 (default) or 'd' (diameter), 'r' (radius), or 't' (tacacs+) on return. |
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
262 */ |
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
263 int fd_os_parse_DiameterURI(uint8_t * uri, size_t urisz, DiamId_t * diamid, size_t * diamidlen, int * secure, uint16_t * port, int * transport, char *proto) |
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
264 { |
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
265 size_t offset = 0; |
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
266 DiamId_t fqdn = NULL; |
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
267 size_t fqdnlen; |
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
268 TRACE_ENTRY("%p %zd %p %p %p %p %p %p", uri, urisz, diamid, diamidlen, secure, port, transport, proto); |
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
269 CHECK_PARAMS( uri && urisz ); |
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
270 |
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
271 CHECK_PARAMS( urisz > 7 ); /* "aaa" + "://" + something else at least */ |
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
272 |
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
273 /* Initialize values */ |
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
274 if (secure) |
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
275 *secure = 0; |
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
276 if (port) |
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
277 *port = 0; |
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
278 if (transport) |
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
279 *transport = 0; |
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
280 if (proto) |
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
281 *proto = 0; |
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
282 |
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
283 /* Check the beginning */ |
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
284 if (memcmp( uri, "aaa", 3)) { |
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
285 TRACE_DEBUG(INFO, "Invalid DiameterURI prefix: got '%.*s', expected 'aaa'", 3, uri); |
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
286 return EINVAL; |
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
287 } |
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
288 offset += 3; |
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
289 |
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
290 /* Secure? */ |
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
291 if (uri[offset] == (uint8_t)'s') { |
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
292 if (secure) |
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
293 *secure = 1; |
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
294 offset += 1; |
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
295 } |
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
296 |
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
297 /* Remaining of URI marker */ |
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
298 if (memcmp( uri + offset, "://", 3)) { |
1027
0117a7746b21
Fix a number of errors and warnings introduced/highlighted by recent commits
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1022
diff
changeset
|
299 TRACE_DEBUG(INFO, "Invalid DiameterURI prefix: got '%.*s', expected 'aaa://' or 'aaas://'", (int)offset + 3, uri); |
717
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
300 return EINVAL; |
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
301 } |
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
302 offset += 3; |
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
303 |
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
304 /* This is the start of the FQDN */ |
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
305 fqdn = (DiamId_t)uri + offset; |
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
306 for ( ; offset < urisz ; offset++ ) { |
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
307 /* Stop only when we find ':' or ';' */ |
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
308 if ((uri[offset] == (uint8_t)':') || (uri[offset] == (uint8_t)';')) |
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
309 break; |
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
310 } |
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
311 fqdnlen = offset - (fqdn - (DiamId_t)uri); |
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
312 CHECK_FCT(fd_os_validate_DiameterIdentity(&fqdn, &fqdnlen, 1)); |
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
313 if (diamid) |
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
314 *diamid = fqdn; |
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
315 else |
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
316 free(fqdn); |
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
317 if (diamidlen) |
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
318 *diamidlen = fqdnlen; |
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
319 |
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
320 if (offset == urisz) |
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
321 return 0; /* Finished */ |
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
322 |
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
323 /* Is there a port ? */ |
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
324 if (uri[offset] == ':') { |
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
325 uint16_t p = 0; |
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
326 do { |
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
327 offset++; |
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
328 |
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
329 if (offset == urisz) |
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
330 break; |
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
331 |
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
332 uint32_t t = (uint32_t)((char)uri[offset] - '0'); |
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
333 if (t > 9) |
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
334 break; /* we did not get a digit */ |
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
335 |
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
336 t += p * 10; /* the port is specified in decimal base */ |
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
337 |
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
338 if (t >= (1<<16)) { |
719
dc71992e3378
Be less tolerant on DiameterURI format
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
717
diff
changeset
|
339 TRACE_DEBUG(INFO, "Invalid DiameterURI: port value is too big."); |
dc71992e3378
Be less tolerant on DiameterURI format
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
717
diff
changeset
|
340 return EINVAL; |
717
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
341 } |
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
342 |
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
343 p = t; |
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
344 } while (1); |
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
345 |
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
346 if (port) |
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
347 *port = p; |
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
348 } |
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
349 |
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
350 if (offset == urisz) |
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
351 return 0; /* Finished */ |
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
352 |
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
353 /* Is there a transport? */ |
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
354 if ( (urisz - offset > CONSTSTRLEN(";transport=")) |
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
355 && !strncasecmp((char *)uri + offset, ";transport=", CONSTSTRLEN(";transport=")) ) { |
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
356 |
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
357 offset += CONSTSTRLEN(";transport="); |
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
358 |
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
359 if (urisz - offset < 3) { |
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
360 TRACE_DEBUG(INFO, "Invalid DiameterURI: transport string is too short, ignored."); |
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
361 return 0; |
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
362 } |
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
363 if (!strncasecmp((char *)uri + offset, "tcp", CONSTSTRLEN("tcp"))) { |
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
364 if (transport) |
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
365 *transport = IPPROTO_TCP; |
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
366 offset += CONSTSTRLEN("tcp"); |
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
367 goto after_transport; |
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
368 } |
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
369 if (!strncasecmp((char *)uri + offset, "udp", CONSTSTRLEN("udp"))) { |
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
370 if (transport) |
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
371 *transport = IPPROTO_UDP; |
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
372 offset += CONSTSTRLEN("udp"); |
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
373 goto after_transport; |
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
374 } |
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
375 if ((urisz - offset > 3) && !strncasecmp((char *)uri + offset, "sctp", CONSTSTRLEN("sctp"))) { |
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
376 if (transport) { |
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
377 #ifndef DISABLE_SCTP |
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
378 *transport = IPPROTO_SCTP; |
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
379 #else /* DISABLE_SCTP */ |
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
380 TRACE_DEBUG(INFO, "Received DiameterURI with 'transport=sctp' but DISABLE_SCTP was selected"); |
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
381 *transport = 0; |
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
382 #endif /* DISABLE_SCTP */ |
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
383 } |
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
384 offset += CONSTSTRLEN("sctp"); |
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
385 goto after_transport; |
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
386 } |
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
387 |
1027
0117a7746b21
Fix a number of errors and warnings introduced/highlighted by recent commits
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1022
diff
changeset
|
388 TRACE_DEBUG(INFO, "Invalid DiameterURI: transport string is not recognized ('%.*s').", (int)(urisz - offset), uri + offset); |
719
dc71992e3378
Be less tolerant on DiameterURI format
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
717
diff
changeset
|
389 return EINVAL; |
717
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
390 } |
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
391 after_transport: |
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
392 if (offset == urisz) |
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
393 return 0; /* Finished */ |
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
394 |
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
395 /* Is there a protocol? */ |
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
396 if ( ((urisz - offset) > CONSTSTRLEN(";protocol=")) |
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
397 && (!strncasecmp((char *)uri + offset, ";protocol=", CONSTSTRLEN(";protocol="))) ) { |
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
398 |
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
399 offset += CONSTSTRLEN(";protocol="); |
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
400 |
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
401 if ( ((urisz - offset) >= CONSTSTRLEN("diameter")) |
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
402 && (!strncasecmp((char *)uri + offset, "diameter", CONSTSTRLEN("diameter"))) ) { |
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
403 if (proto) |
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
404 *proto = 'd'; |
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
405 offset += CONSTSTRLEN("diameter"); |
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
406 goto after_proto; |
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
407 } |
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
408 |
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
409 if ( ((urisz - offset) >= CONSTSTRLEN("radius")) |
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
410 && (!strncasecmp((char *)uri + offset, "radius", CONSTSTRLEN("radius"))) ) { |
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
411 if (proto) |
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
412 *proto = 'r'; |
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
413 offset += CONSTSTRLEN("radius"); |
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
414 goto after_proto; |
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
415 } |
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
416 |
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
417 if ( ((urisz - offset) >= CONSTSTRLEN("tacacs+")) |
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
418 && (!strncasecmp((char *)uri + offset, "tacacs+", CONSTSTRLEN("tacacs+"))) ) { |
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
419 if (proto) |
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
420 *proto = 't'; |
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
421 offset += CONSTSTRLEN("tacacs+"); |
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
422 goto after_proto; |
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
423 } |
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
424 |
1027
0117a7746b21
Fix a number of errors and warnings introduced/highlighted by recent commits
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1022
diff
changeset
|
425 TRACE_DEBUG(INFO, "Invalid DiameterURI: protocol string is not recognized ('%.*s').", (int)(urisz - offset), uri + offset); |
719
dc71992e3378
Be less tolerant on DiameterURI format
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
717
diff
changeset
|
426 return EINVAL; |
717
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
427 |
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
428 } |
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
429 after_proto: |
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
430 if (offset == urisz) |
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
431 return 0; /* Finished */ |
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
432 |
1027
0117a7746b21
Fix a number of errors and warnings introduced/highlighted by recent commits
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1022
diff
changeset
|
433 TRACE_DEBUG(INFO, "Invalid DiameterURI: final part of string is not recognized ('%.*s').", (int)(urisz - offset), uri + offset); |
719
dc71992e3378
Be less tolerant on DiameterURI format
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
717
diff
changeset
|
434 return EINVAL; |
717
571b3abaa5df
Support for Diameter Redirects through rt_redirect.fdx extension (EXPERIMENTAL)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
707
diff
changeset
|
435 } |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
436 |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
437 |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
438 /********************************************************************************************************/ |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
439 /* Hash function -- credits to Austin Appleby, thank you ^^ */ |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
440 /* See http://murmurhash.googlepages.com for more information on this function */ |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
441 |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
442 /* the strings are NOT always aligned properly (ex: received in RADIUS message), so we use the aligned MurmurHash2 function as needed */ |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
443 #define _HASH_MIX(h,k,m) { k *= m; k ^= k >> r; k *= m; h *= m; h ^= k; } |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
444 uint32_t fd_os_hash ( uint8_t * string, size_t len ) |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
445 { |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
446 uint32_t hash = len; |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
447 uint8_t * data = string; |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
448 |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
449 const unsigned int m = 0x5bd1e995; |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
450 const int r = 24; |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
451 int align = (long)string & 3; |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
452 |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
453 if (!align || (len < 4)) { |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
454 /* In case data is aligned, MurmurHash2 function */ |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
455 while(len >= 4) |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
456 { |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
457 /* Mix 4 bytes at a time into the hash */ |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
458 uint32_t k = *(uint32_t *)data; /* We don't care about the byte order */ |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
459 |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
460 _HASH_MIX(hash, k, m); |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
461 |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
462 data += 4; |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
463 len -= 4; |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
464 } |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
465 |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
466 /* Handle the last few bytes of the input */ |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
467 switch(len) { |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
468 case 3: hash ^= data[2] << 16; |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
469 case 2: hash ^= data[1] << 8; |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
470 case 1: hash ^= data[0]; |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
471 hash *= m; |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
472 } |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
473 |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
474 } else { |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
475 /* Unaligned data, use alignment-safe slower version */ |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
476 |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
477 /* Pre-load the temp registers */ |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
478 uint32_t t = 0, d = 0; |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
479 switch(align) |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
480 { |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
481 case 1: t |= data[2] << 16; |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
482 case 2: t |= data[1] << 8; |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
483 case 3: t |= data[0]; |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
484 } |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
485 t <<= (8 * align); |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
486 |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
487 data += 4-align; |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
488 len -= 4-align; |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
489 |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
490 /* From this point, "data" can be read by chunks of 4 bytes */ |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
491 |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
492 int sl = 8 * (4-align); |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
493 int sr = 8 * align; |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
494 |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
495 /* Mix */ |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
496 while(len >= 4) |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
497 { |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
498 uint32_t k; |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
499 |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
500 d = *(unsigned int *)data; |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
501 k = (t >> sr) | (d << sl); |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
502 |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
503 _HASH_MIX(hash, k, m); |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
504 |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
505 t = d; |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
506 |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
507 data += 4; |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
508 len -= 4; |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
509 } |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
510 |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
511 /* Handle leftover data in temp registers */ |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
512 d = 0; |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
513 if(len >= align) |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
514 { |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
515 uint32_t k; |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
516 |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
517 switch(align) |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
518 { |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
519 case 3: d |= data[2] << 16; |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
520 case 2: d |= data[1] << 8; |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
521 case 1: d |= data[0]; |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
522 } |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
523 |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
524 k = (t >> sr) | (d << sl); |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
525 _HASH_MIX(hash, k, m); |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
526 |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
527 data += align; |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
528 len -= align; |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
529 |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
530 /* Handle tail bytes */ |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
531 |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
532 switch(len) |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
533 { |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
534 case 3: hash ^= data[2] << 16; |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
535 case 2: hash ^= data[1] << 8; |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
536 case 1: hash ^= data[0]; |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
537 hash *= m; |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
538 }; |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
539 } |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
540 else |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
541 { |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
542 switch(len) |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
543 { |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
544 case 3: d |= data[2] << 16; |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
545 case 2: d |= data[1] << 8; |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
546 case 1: d |= data[0]; |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
547 case 0: hash ^= (t >> sr) | (d << sl); |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
548 hash *= m; |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
549 } |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
550 } |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
551 |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
552 |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
553 } |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
554 |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
555 /* Do a few final mixes of the hash to ensure the last few |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
556 bytes are well-incorporated. */ |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
557 hash ^= hash >> 13; |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
558 hash *= m; |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
559 hash ^= hash >> 15; |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
560 |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
561 return hash; |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
562 } |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
563 |