- Timestamp:
- Feb 21, 2007 12:40:05 AM (18 years ago)
- Location:
- pjproject/trunk
- Files:
-
- 3 deleted
- 10 edited
- 16 copied
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjlib-util/build/Makefile
r805 r992 28 28 export PJLIB_UTIL_OBJS += $(OS_OBJS) $(M_OBJS) $(CC_OBJS) $(HOST_OBJS) \ 29 29 errno.o dns.o dns_dump.o getopt.o md5.o resolver.o \ 30 scanner.o st un.o string.o stun_client.o xml.o30 scanner.o string.o stun_simple.o stun_simple_client.o xml.o 31 31 export PJLIB_UTIL_CFLAGS += $(_CFLAGS) 32 32 -
pjproject/trunk/pjlib-util/build/pjlib_util.dsp
r754 r992 130 130 # Begin Source File 131 131 132 SOURCE="..\src\pjlib-util\stun.c" 133 # End Source File 134 # Begin Source File 135 136 SOURCE="..\src\pjlib-util\stun_client.c" 132 SOURCE="..\src\pjlib-util\stun_endpoint.c" 133 # End Source File 134 # Begin Source File 135 136 SOURCE="..\src\pjlib-util\stun_msg.c" 137 # End Source File 138 # Begin Source File 139 140 SOURCE="..\src\pjlib-util\stun_server.c" 141 # End Source File 142 # Begin Source File 143 144 SOURCE="..\src\pjlib-util\stun_simple.c" 145 # End Source File 146 # Begin Source File 147 148 SOURCE="..\src\pjlib-util\stun_simple_client.c" 149 # End Source File 150 # Begin Source File 151 152 SOURCE="..\src\pjlib-util\stun_transaction.c" 137 153 # End Source File 138 154 # Begin Source File … … 194 210 # Begin Source File 195 211 196 SOURCE="..\include\pjlib-util\stun.h" 212 SOURCE="..\include\pjlib-util\stun_doc.h" 213 # End Source File 214 # Begin Source File 215 216 SOURCE="..\include\pjlib-util\stun_endpoint.h" 217 # End Source File 218 # Begin Source File 219 220 SOURCE="..\include\pjlib-util\stun_msg.h" 221 # End Source File 222 # Begin Source File 223 224 SOURCE="..\include\pjlib-util\stun_server.h" 225 # End Source File 226 # Begin Source File 227 228 SOURCE="..\include\pjlib-util\stun_simple.h" 229 # End Source File 230 # Begin Source File 231 232 SOURCE="..\include\pjlib-util\stun_transaction.h" 197 233 # End Source File 198 234 # Begin Source File -
pjproject/trunk/pjlib-util/build/pjlib_util.dsw
r65 r992 20 20 Package=<5> 21 21 {{{ 22 begin source code control23 "$/pjproject/pjlib/build", UIAAAAAA24 ..\..\pjlib\build25 end source code control26 22 }}} 27 23 … … 62 58 ############################################################################### 63 59 60 Project: "pjstun_srv"=".\pjstun_srv.dsp" - Package Owner=<4> 61 62 Package=<5> 63 {{{ 64 }}} 65 66 Package=<4> 67 {{{ 68 Begin Project Dependency 69 Project_Dep_Name pjlib 70 End Project Dependency 71 Begin Project Dependency 72 Project_Dep_Name pjlib_util 73 End Project Dependency 74 }}} 75 76 ############################################################################### 77 64 78 Global: 65 79 -
pjproject/trunk/pjlib-util/build/pjlib_util.vcproj
r898 r992 400 400 </File> 401 401 <File 402 RelativePath="..\src\pjlib-util\stun.c" 403 > 404 <FileConfiguration 405 Name="Release|Win32" 406 > 407 <Tool 408 Name="VCCLCompilerTool" 409 AdditionalIncludeDirectories="" 410 PreprocessorDefinitions="" 411 /> 412 </FileConfiguration> 413 <FileConfiguration 414 Name="Debug|Win32" 415 > 416 <Tool 417 Name="VCCLCompilerTool" 418 AdditionalIncludeDirectories="" 419 PreprocessorDefinitions="" 420 /> 421 </FileConfiguration> 422 </File> 423 <File 424 RelativePath="..\src\pjlib-util\stun_client.c" 425 > 426 <FileConfiguration 427 Name="Release|Win32" 428 > 429 <Tool 430 Name="VCCLCompilerTool" 431 AdditionalIncludeDirectories="" 432 PreprocessorDefinitions="" 433 /> 434 </FileConfiguration> 435 <FileConfiguration 436 Name="Debug|Win32" 437 > 438 <Tool 439 Name="VCCLCompilerTool" 440 AdditionalIncludeDirectories="" 441 PreprocessorDefinitions="" 442 /> 443 </FileConfiguration> 402 RelativePath="..\src\pjlib-util\stun_simple.c" 403 > 404 </File> 405 <File 406 RelativePath="..\src\pjlib-util\stun_simple_client.c" 407 > 444 408 </File> 445 409 <File … … 537 501 </File> 538 502 <File 539 RelativePath="..\include\pjlib-util\stun .h"503 RelativePath="..\include\pjlib-util\stun_simple.h" 540 504 > 541 505 </File> -
pjproject/trunk/pjlib-util/include/pjlib-util.h
r974 r992 31 31 #include <pjlib-util/resolver.h> 32 32 #include <pjlib-util/scanner.h> 33 #include <pjlib-util/stun.h>34 33 #include <pjlib-util/xml.h> 35 34 35 /* New STUN */ 36 #include <pjlib-util/stun_endpoint.h> 37 #include <pjlib-util/stun_msg.h> 38 #include <pjlib-util/stun_server.h> 39 #include <pjlib-util/stun_transaction.h> 40 41 /* Old STUN */ 42 #include <pjlib-util/stun_simple.h> 36 43 37 44 /** -
pjproject/trunk/pjlib-util/include/pjlib-util/config.h
r974 r992 192 192 193 193 /** 194 * Maximum number of attributes in the STUN packet. 194 * Maximum number of attributes in the STUN packet (for the old STUN 195 * library). 196 * 197 * Default: 16 198 */ 199 #ifndef PJSTUN_MAX_ATTR 200 # define PJSTUN_MAX_ATTR 16 201 #endif 202 203 204 /** 205 * Maximum number of attributes in the STUN packet (for the new STUN 206 * library). 195 207 * 196 208 * Default: 16 … … 200 212 #endif 201 213 202 203 214 /** 204 215 * @} -
pjproject/trunk/pjlib-util/include/pjlib-util/errno.h
r974 r992 51 51 /** 52 52 * @hideinitializer 53 * Invalid STUN message length .53 * Invalid STUN message length 54 54 */ 55 55 #define PJLIB_UTIL_ESTUNINMSGLEN (PJLIB_UTIL_ERRNO_START+3) /* 320003 */ 56 56 /** 57 57 * @hideinitializer 58 * STUN attribute length error.58 * Invalid STUN attribute length 59 59 */ 60 60 #define PJLIB_UTIL_ESTUNINATTRLEN (PJLIB_UTIL_ERRNO_START+4) /* 320004 */ … … 246 246 247 247 248 /************************************************************ 249 * NEW STUN ERROR 250 ***********************************************************/ 251 /* Messaging errors */ 252 /** 253 * @hideinitializer 254 * Invalid STUN attribute 255 */ 256 #define PJLIB_UTIL_ESTUNINATTR (PJLIB_UTIL_ERRNO_START+110)/* 320110 */ 257 /** 258 * @hideinitializer 259 * Too many STUN attributes. 260 */ 261 #define PJLIB_UTIL_ESTUNTOOMANYATTR (PJLIB_UTIL_ERRNO_START+111)/* 320111 */ 262 /** 263 * @hideinitializer 264 * Unknown STUN attribute. 265 */ 266 #define PJLIB_UTIL_ESTUNUNKNOWNATTR (PJLIB_UTIL_ERRNO_START+112)/* 320112 */ 267 /** 268 * @hideinitializer 269 * Invalid socket address length. 270 */ 271 #define PJLIB_UTIL_ESTUNINADDRLEN (PJLIB_UTIL_ERRNO_START+113)/* 320113 */ 272 /** 273 * @hideinitializer 274 * IPv6 attribute not supported 275 */ 276 #define PJLIB_UTIL_ESTUNIPV6NOTSUPP (PJLIB_UTIL_ERRNO_START+113)/* 320113 */ 277 /** 278 * @hideinitializer 279 * Expecting STUN response message. 280 */ 281 #define PJLIB_UTIL_ESTUNNOTRESPONSE (PJLIB_UTIL_ERRNO_START+114)/* 320114 */ 282 /** 283 * @hideinitializer 284 * Transaction ID mismatch. 285 */ 286 #define PJLIB_UTIL_ESTUNINVALIDID (PJLIB_UTIL_ERRNO_START+115)/* 320115 */ 287 /** 288 * @hideinitializer 289 * Unable to find handler for the request. 290 */ 291 #define PJLIB_UTIL_ESTUNNOHANDLER (PJLIB_UTIL_ERRNO_START+116)/* 320116 */ 292 293 294 #define PJ_STATUS_FROM_STUN_CODE(code) -1 295 296 297 298 248 299 /** 249 300 * @} -
pjproject/trunk/pjlib-util/include/pjlib-util/stun_msg.h
r991 r992 146 146 * message. 147 147 */ 148 #define PJ_STUN_GET_METHOD(msg_type) ((msg_type) & 0x 000F)148 #define PJ_STUN_GET_METHOD(msg_type) ((msg_type) & 0xFEEF) 149 149 150 150 … … 1047 1047 1048 1048 1049 /** 1050 * Get STUN message method name. 1051 * 1052 * @param msg_type The STUN message type (in host byte order) 1053 * 1054 * @return The STUN message method name string. 1055 */ 1056 PJ_DECL(const char*) pj_stun_get_method_name(unsigned msg_type); 1057 1058 1059 /** 1060 * Get STUN message class name. 1061 * 1062 * @param msg_type The STUN message type (in host byte order) 1063 * 1064 * @return The STUN message class name string. 1065 */ 1066 PJ_DECL(const char*) pj_stun_get_class_name(unsigned msg_type); 1067 1068 1069 /** 1070 * Get STUN attribute name. 1071 * 1072 * @return attr_type The STUN attribute type (in host byte order). 1073 * 1074 * @return The STUN attribute type name string. 1075 */ 1076 PJ_DECL(const char*) pj_stun_get_attr_name(unsigned attr_type); 1077 1049 1078 1050 1079 /** -
pjproject/trunk/pjlib-util/include/pjlib-util/stun_simple.h
r991 r992 17 17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 18 */ 19 #ifndef __PJ _STUN_H__20 #define __PJ _STUN_H__19 #ifndef __PJSTUN_H__ 20 #define __PJSTUN_H__ 21 21 22 22 /** … … 34 34 * This enumeration describes STUN message types. 35 35 */ 36 typedef enum pj _stun_msg_type37 { 38 PJ _STUN_BINDING_REQUEST = 0x0001,39 PJ _STUN_BINDING_RESPONSE = 0x0101,40 PJ _STUN_BINDING_ERROR_RESPONSE = 0x0111,41 PJ _STUN_SHARED_SECRET_REQUEST = 0x0002,42 PJ _STUN_SHARED_SECRET_RESPONSE = 0x0102,43 PJ _STUN_SHARED_SECRET_ERROR_RESPONSE = 0x011244 } pj _stun_msg_type;36 typedef enum pjstun_msg_type 37 { 38 PJSTUN_BINDING_REQUEST = 0x0001, 39 PJSTUN_BINDING_RESPONSE = 0x0101, 40 PJSTUN_BINDING_ERROR_RESPONSE = 0x0111, 41 PJSTUN_SHARED_SECRET_REQUEST = 0x0002, 42 PJSTUN_SHARED_SECRET_RESPONSE = 0x0102, 43 PJSTUN_SHARED_SECRET_ERROR_RESPONSE = 0x0112 44 } pjstun_msg_type; 45 45 46 46 … … 48 48 * This enumeration describes STUN attribute types. 49 49 */ 50 typedef enum pj _stun_attr_type51 { 52 PJ _STUN_ATTR_MAPPED_ADDR = 1,53 PJ _STUN_ATTR_RESPONSE_ADDR,54 PJ _STUN_ATTR_CHANGE_REQUEST,55 PJ _STUN_ATTR_SOURCE_ADDR,56 PJ _STUN_ATTR_CHANGED_ADDR,57 PJ _STUN_ATTR_USERNAME,58 PJ _STUN_ATTR_PASSWORD,59 PJ _STUN_ATTR_MESSAGE_INTEGRITY,60 PJ _STUN_ATTR_ERROR_CODE,61 PJ _STUN_ATTR_UNKNOWN_ATTRIBUTES,62 PJ _STUN_ATTR_REFLECTED_FORM63 } pj _stun_attr_type;50 typedef enum pjstun_attr_type 51 { 52 PJSTUN_ATTR_MAPPED_ADDR = 1, 53 PJSTUN_ATTR_RESPONSE_ADDR, 54 PJSTUN_ATTR_CHANGE_REQUEST, 55 PJSTUN_ATTR_SOURCE_ADDR, 56 PJSTUN_ATTR_CHANGED_ADDR, 57 PJSTUN_ATTR_USERNAME, 58 PJSTUN_ATTR_PASSWORD, 59 PJSTUN_ATTR_MESSAGE_INTEGRITY, 60 PJSTUN_ATTR_ERROR_CODE, 61 PJSTUN_ATTR_UNKNOWN_ATTRIBUTES, 62 PJSTUN_ATTR_REFLECTED_FORM 63 } pjstun_attr_type; 64 64 65 65 … … 67 67 * This structre describes STUN message header. 68 68 */ 69 typedef struct pj _stun_msg_hdr69 typedef struct pjstun_msg_hdr 70 70 { 71 71 pj_uint16_t type; 72 72 pj_uint16_t length; 73 73 pj_uint32_t tsx[4]; 74 } pj _stun_msg_hdr;74 } pjstun_msg_hdr; 75 75 76 76 … … 78 78 * This structre describes STUN attribute header. 79 79 */ 80 typedef struct pj _stun_attr_hdr80 typedef struct pjstun_attr_hdr 81 81 { 82 82 pj_uint16_t type; 83 83 pj_uint16_t length; 84 } pj _stun_attr_hdr;84 } pjstun_attr_hdr; 85 85 86 86 … … 88 88 * This structre describes STUN MAPPED-ADDR attribute. 89 89 */ 90 typedef struct pj _stun_mapped_addr_attr91 { 92 pj _stun_attr_hdr hdr;90 typedef struct pjstun_mapped_addr_attr 91 { 92 pjstun_attr_hdr hdr; 93 93 pj_uint8_t ignored; 94 94 pj_uint8_t family; 95 95 pj_uint16_t port; 96 96 pj_uint32_t addr; 97 } pj _stun_mapped_addr_attr;98 99 typedef pj _stun_mapped_addr_attr pj_stun_response_addr_attr;100 typedef pj _stun_mapped_addr_attr pj_stun_changed_addr_attr;101 typedef pj _stun_mapped_addr_attr pj_stun_src_addr_attr;102 typedef pj _stun_mapped_addr_attr pj_stun_reflected_form_attr;103 104 typedef struct pj _stun_change_request_attr105 { 106 pj _stun_attr_hdr hdr;97 } pjstun_mapped_addr_attr; 98 99 typedef pjstun_mapped_addr_attr pjstun_response_addr_attr; 100 typedef pjstun_mapped_addr_attr pjstun_changed_addr_attr; 101 typedef pjstun_mapped_addr_attr pjstun_src_addr_attr; 102 typedef pjstun_mapped_addr_attr pjstun_reflected_form_attr; 103 104 typedef struct pjstun_change_request_attr 105 { 106 pjstun_attr_hdr hdr; 107 107 pj_uint32_t value; 108 } pj _stun_change_request_attr;109 110 typedef struct pj _stun_username_attr111 { 112 pj _stun_attr_hdr hdr;108 } pjstun_change_request_attr; 109 110 typedef struct pjstun_username_attr 111 { 112 pjstun_attr_hdr hdr; 113 113 pj_uint32_t value[1]; 114 } pj _stun_username_attr;115 116 typedef pj _stun_username_attr pj_stun_password_attr;117 118 typedef struct pj _stun_error_code_attr119 { 120 pj _stun_attr_hdr hdr;114 } pjstun_username_attr; 115 116 typedef pjstun_username_attr pjstun_password_attr; 117 118 typedef struct pjstun_error_code_attr 119 { 120 pjstun_attr_hdr hdr; 121 121 pj_uint16_t ignored; 122 122 pj_uint8_t err_class; 123 123 pj_uint8_t number; 124 124 char reason[4]; 125 } pj _stun_error_code_attr;126 127 typedef struct pj _stun_msg128 { 129 pj _stun_msg_hdr *hdr;125 } pjstun_error_code_attr; 126 127 typedef struct pjstun_msg 128 { 129 pjstun_msg_hdr *hdr; 130 130 int attr_count; 131 pj _stun_attr_hdr *attr[PJ_STUN_MAX_ATTR];132 } pj _stun_msg;131 pjstun_attr_hdr *attr[PJSTUN_MAX_ATTR]; 132 } pjstun_msg; 133 133 134 134 /* STUN message API (stun.c). */ 135 135 136 PJ_DECL(pj_status_t) pj _stun_create_bind_req( pj_pool_t *pool,136 PJ_DECL(pj_status_t) pjstun_create_bind_req( pj_pool_t *pool, 137 137 void **msg, pj_size_t *len, 138 138 pj_uint32_t id_hi, 139 139 pj_uint32_t id_lo); 140 PJ_DECL(pj_status_t) pj _stun_parse_msg( void *buf, pj_size_t len,141 pj _stun_msg *msg);142 PJ_DECL(void*) pj _stun_msg_find_attr( pj_stun_msg *msg, pj_stun_attr_type t);140 PJ_DECL(pj_status_t) pjstun_parse_msg( void *buf, pj_size_t len, 141 pjstun_msg *msg); 142 PJ_DECL(void*) pjstun_msg_find_attr( pjstun_msg *msg, pjstun_attr_type t); 143 143 144 144 … … 150 150 * 151 151 * This is the older implementation of STUN client, with only one function 152 * provided (pj _stun_get_mapped_addr()) to retrieve the public IP address152 * provided (pjstun_get_mapped_addr()) to retrieve the public IP address 153 153 * of multiple sockets. 154 154 */ … … 192 192 * 193 193 */ 194 PJ_DECL(pj_status_t) pj _stun_get_mapped_addr( pj_pool_factory *pf,194 PJ_DECL(pj_status_t) pjstun_get_mapped_addr( pj_pool_factory *pf, 195 195 int sock_cnt, pj_sock_t sock[], 196 196 const pj_str_t *srv1, int port1, … … 204 204 */ 205 205 206 #endif /* __PJ _STUN_H__ */207 206 #endif /* __PJSTUN_H__ */ 207 -
pjproject/trunk/pjlib-util/src/pjlib-util/stun_msg.c
r991 r992 27 27 28 28 #define THIS_FILE "stun_msg.c" 29 30 31 static const char *stun_method_names[] = 32 { 33 "Unknown", /* 0 */ 34 "Binding", /* 1 */ 35 "Shared Secret", /* 2 */ 36 "Allocate", /* 3 */ 37 "Send", /* 4 */ 38 "Data", /* 5 */ 39 "Set Active Destination", /* 6 */ 40 "Connect", /* 7 */ 41 "Connect Status" /* 8 */ 42 }; 29 43 30 44 static struct … … 60 74 61 75 76 77 struct attr_desc 78 { 79 const char *name; 80 pj_status_t (*decode_attr)(pj_pool_t *pool, const pj_uint8_t *buf, 81 void **p_attr); 82 pj_status_t (*encode_attr)(const void *a, pj_uint8_t *buf, 83 unsigned len, unsigned *printed); 84 85 }; 86 87 static pj_status_t decode_generic_ip_addr_attr(pj_pool_t *pool, 88 const pj_uint8_t *buf, 89 void **p_attr); 90 static pj_status_t encode_generic_ip_addr_attr(const void *a, pj_uint8_t *buf, 91 unsigned len, 92 unsigned *printed); 93 static pj_status_t decode_generic_string_attr(pj_pool_t *pool, 94 const pj_uint8_t *buf, 95 void **p_attr); 96 static pj_status_t encode_generic_string_attr(const void *a, pj_uint8_t *buf, 97 unsigned len, unsigned *printed); 98 static pj_status_t decode_msg_integrity_attr(pj_pool_t *pool, 99 const pj_uint8_t *buf, 100 void **p_attr); 101 static pj_status_t encode_msg_integrity_attr(const void *a, pj_uint8_t *buf, 102 unsigned len, unsigned *printed); 103 static pj_status_t decode_error_code_attr(pj_pool_t *pool, 104 const pj_uint8_t *buf, 105 void **p_attr); 106 static pj_status_t encode_error_code_attr(const void *a, pj_uint8_t *buf, 107 unsigned len, unsigned *printed); 108 static pj_status_t decode_unknown_attr(pj_pool_t *pool, 109 const pj_uint8_t *buf, 110 void **p_attr); 111 static pj_status_t encode_unknown_attr(const void *a, pj_uint8_t *buf, 112 unsigned len, unsigned *printed); 113 static pj_status_t decode_generic_uint_attr(pj_pool_t *pool, 114 const pj_uint8_t *buf, 115 void **p_attr); 116 static pj_status_t encode_generic_uint_attr(const void *a, pj_uint8_t *buf, 117 unsigned len, unsigned *printed); 118 static pj_status_t decode_binary_attr(pj_pool_t *pool, 119 const pj_uint8_t *buf, 120 void **p_attr); 121 static pj_status_t encode_binary_attr(const void *a, pj_uint8_t *buf, 122 unsigned len, unsigned *printed); 123 static pj_status_t decode_empty_attr(pj_pool_t *pool, 124 const pj_uint8_t *buf, 125 void **p_attr); 126 static pj_status_t encode_empty_attr(const void *a, pj_uint8_t *buf, 127 unsigned len, unsigned *printed); 128 129 130 struct attr_desc mandatory_attr_desc[] = 131 { 132 { 133 /* type zero */ 134 NULL, 135 NULL, 136 NULL 137 }, 138 { 139 /* PJ_STUN_ATTR_MAPPED_ADDR, */ 140 "MAPPED-ADDRESS", 141 &decode_generic_ip_addr_attr, 142 &encode_generic_ip_addr_attr 143 }, 144 { 145 /* PJ_STUN_ATTR_RESPONSE_ADDR, */ 146 "RESPONSE-ADDRESS", 147 &decode_generic_ip_addr_attr, 148 &encode_generic_ip_addr_attr 149 }, 150 { 151 /* PJ_STUN_ATTR_CHANGE_REQUEST, */ 152 "CHANGE-REQUEST", 153 &decode_generic_uint_attr, 154 &encode_generic_uint_attr 155 }, 156 { 157 /* PJ_STUN_ATTR_SOURCE_ADDR, */ 158 "SOURCE-ADDRESS", 159 &decode_generic_ip_addr_attr, 160 &encode_generic_ip_addr_attr 161 }, 162 { 163 /* PJ_STUN_ATTR_CHANGED_ADDR, */ 164 "CHANGED-ADDRESS", 165 &decode_generic_ip_addr_attr, 166 &encode_generic_ip_addr_attr 167 }, 168 { 169 /* PJ_STUN_ATTR_USERNAME, */ 170 "USERNAME", 171 &decode_generic_string_attr, 172 &encode_generic_string_attr 173 }, 174 { 175 /* PJ_STUN_ATTR_PASSWORD, */ 176 "PASSWORD", 177 &decode_generic_string_attr, 178 &encode_generic_string_attr 179 }, 180 { 181 /* PJ_STUN_ATTR_MESSAGE_INTEGRITY, */ 182 "MESSAGE-INTEGRITY", 183 &decode_msg_integrity_attr, 184 &encode_msg_integrity_attr 185 }, 186 { 187 /* PJ_STUN_ATTR_ERROR_CODE, */ 188 "ERROR-CODE", 189 &decode_error_code_attr, 190 &encode_error_code_attr 191 }, 192 { 193 /* PJ_STUN_ATTR_UNKNOWN_ATTRIBUTES, */ 194 "UNKNOWN-ATTRIBUTES", 195 &decode_unknown_attr, 196 &encode_unknown_attr 197 }, 198 { 199 /* PJ_STUN_ATTR_REFLECTED_FROM, */ 200 "REFLECTED-FROM", 201 &decode_generic_ip_addr_attr, 202 &encode_generic_ip_addr_attr 203 }, 204 { 205 /* ID 0x000C is not assigned */ 206 NULL, 207 NULL, 208 NULL 209 }, 210 { 211 /* PJ_STUN_ATTR_LIFETIME, */ 212 "LIFETIME", 213 &decode_generic_uint_attr, 214 &encode_generic_uint_attr 215 }, 216 { 217 /* ID 0x000E is not assigned */ 218 NULL, 219 NULL, 220 NULL 221 }, 222 { 223 /* ID 0x000F is not assigned */ 224 NULL, 225 NULL, 226 NULL 227 }, 228 { 229 /* PJ_STUN_ATTR_BANDWIDTH, */ 230 "BANDWIDTH", 231 &decode_generic_uint_attr, 232 &encode_generic_uint_attr 233 }, 234 { 235 /* ID 0x0011 is not assigned */ 236 NULL, 237 NULL, 238 NULL 239 }, 240 { 241 /* PJ_STUN_ATTR_REMOTE_ADDRESS, */ 242 "REMOTE-ADDRESS", 243 &decode_generic_ip_addr_attr, 244 &encode_generic_ip_addr_attr 245 }, 246 { 247 /* PJ_STUN_ATTR_DATA, */ 248 "DATA", 249 &decode_binary_attr, 250 &encode_binary_attr 251 }, 252 { 253 /* PJ_STUN_ATTR_REALM, */ 254 "REALM", 255 &decode_generic_string_attr, 256 &encode_generic_string_attr 257 }, 258 { 259 /* PJ_STUN_ATTR_NONCE, */ 260 "NONCE", 261 &decode_generic_string_attr, 262 &encode_generic_string_attr 263 }, 264 { 265 /* PJ_STUN_ATTR_RELAY_ADDRESS, */ 266 "RELAY-ADDRESS", 267 &decode_generic_ip_addr_attr, 268 &encode_generic_ip_addr_attr 269 }, 270 { 271 /* PJ_STUN_ATTR_REQUESTED_ADDR_TYPE, */ 272 "REQUESTED-ADDRESS-TYPE", 273 &decode_generic_uint_attr, 274 &encode_generic_uint_attr 275 }, 276 { 277 /* PJ_STUN_ATTR_REQUESTED_PORT_PROPS, */ 278 "REQUESTED-PORT-PROPS", 279 &decode_generic_uint_attr, 280 &encode_generic_uint_attr 281 }, 282 { 283 /* PJ_STUN_ATTR_REQUESTED_TRANSPORT, */ 284 "REQUESTED-TRANSPORT", 285 &decode_generic_uint_attr, 286 &encode_generic_uint_attr 287 }, 288 { 289 /* ID 0x001A is not assigned */ 290 NULL, 291 NULL, 292 NULL 293 }, 294 { 295 /* ID 0x001B is not assigned */ 296 NULL, 297 NULL, 298 NULL 299 }, 300 { 301 /* ID 0x001C is not assigned */ 302 NULL, 303 NULL, 304 NULL 305 }, 306 { 307 /* ID 0x001D is not assigned */ 308 NULL, 309 NULL, 310 NULL 311 }, 312 { 313 /* ID 0x001E is not assigned */ 314 NULL, 315 NULL, 316 NULL 317 }, 318 { 319 /* ID 0x001F is not assigned */ 320 NULL, 321 NULL, 322 NULL 323 }, 324 { 325 /* PJ_STUN_ATTR_XOR_MAPPED_ADDRESS, */ 326 "XOR-MAPPED-ADDRESS", 327 &decode_generic_ip_addr_attr, 328 &encode_generic_ip_addr_attr 329 }, 330 { 331 /* PJ_STUN_ATTR_TIMER_VAL, */ 332 "TIMER-VAL", 333 &decode_generic_uint_attr, 334 &encode_generic_uint_attr 335 }, 336 { 337 /* PJ_STUN_ATTR_REQUESTED_IP, */ 338 "REQUESTED-IP", 339 &decode_generic_ip_addr_attr, 340 &encode_generic_ip_addr_attr 341 }, 342 { 343 /* PJ_STUN_ATTR_XOR_REFLECTED_FROM, */ 344 "XOR-REFLECTED-FROM", 345 &decode_generic_ip_addr_attr, 346 &encode_generic_ip_addr_attr 347 }, 348 { 349 /* PJ_STUN_ATTR_PRIORITY, */ 350 "PRIORITY", 351 &decode_generic_uint_attr, 352 &encode_generic_uint_attr 353 }, 354 { 355 /* PJ_STUN_ATTR_USE_CANDIDATE, */ 356 "USE-CANDIDATE", 357 &decode_empty_attr, 358 &encode_empty_attr 359 }, 360 { 361 /* PJ_STUN_ATTR_XOR_INTERNAL_ADDR, */ 362 "XOR-INTERNAL-ADDRESS", 363 &decode_generic_ip_addr_attr, 364 &encode_generic_ip_addr_attr 365 }, 366 367 /* Sentinel */ 368 { 369 /* PJ_STUN_ATTR_END_MANDATORY_ATTR */ 370 NULL, 371 NULL, 372 NULL 373 } 374 }; 375 376 static struct attr_desc extended_attr_desc[] = 377 { 378 { 379 /* PJ_STUN_ATTR_FINGERPRINT, */ 380 "FINGERPRINT", 381 &decode_generic_uint_attr, 382 &encode_generic_uint_attr 383 }, 384 { 385 /* PJ_STUN_ATTR_SERVER, */ 386 "SERVER", 387 &decode_generic_string_attr, 388 &encode_generic_string_attr 389 }, 390 { 391 /* PJ_STUN_ATTR_ALTERNATE_SERVER, */ 392 "ALTERNATE-SERVER", 393 &decode_generic_ip_addr_attr, 394 &encode_generic_ip_addr_attr 395 }, 396 { 397 /* PJ_STUN_ATTR_REFRESH_INTERVAL, */ 398 "REFRESH-INTERVAL", 399 &decode_generic_uint_attr, 400 &encode_generic_uint_attr 401 }, 402 }; 403 404 405 406 /* 407 * Get STUN message type name. 408 */ 409 PJ_DEF(const char*) pj_stun_get_method_name(unsigned msg_type) 410 { 411 unsigned method = PJ_STUN_GET_METHOD(msg_type); 412 413 if (method >= PJ_ARRAY_SIZE(stun_method_names)) 414 return "???"; 415 416 return stun_method_names[method]; 417 } 418 419 420 /* 421 * Get STUN message class name. 422 */ 423 PJ_DEF(const char*) pj_stun_get_class_name(unsigned msg_type) 424 { 425 if (PJ_STUN_IS_REQUEST(msg_type)) 426 return "request"; 427 else if (PJ_STUN_IS_RESPONSE(msg_type)) 428 return "success response"; 429 else if (PJ_STUN_IS_ERROR_RESPONSE(msg_type)) 430 return "error response"; 431 else if (PJ_STUN_IS_INDICATION(msg_type)) 432 return "indication"; 433 else 434 return "???"; 435 } 436 437 438 static const struct attr_desc *find_attr_desc(unsigned attr_type) 439 { 440 struct attr_desc *desc; 441 442 /* Check that attr_desc array is valid */ 443 pj_assert(PJ_ARRAY_SIZE(mandatory_attr_desc)== 444 PJ_STUN_ATTR_END_MANDATORY_ATTR+1); 445 pj_assert(mandatory_attr_desc[PJ_STUN_ATTR_END_MANDATORY_ATTR].decode_attr 446 == NULL); 447 pj_assert(mandatory_attr_desc[PJ_STUN_ATTR_USE_CANDIDATE].decode_attr 448 == &decode_empty_attr); 449 pj_assert(PJ_ARRAY_SIZE(extended_attr_desc) == 450 PJ_STUN_ATTR_END_EXTENDED_ATTR-PJ_STUN_ATTR_START_EXTENDED_ATTR); 451 452 if (attr_type < PJ_STUN_ATTR_START_EXTENDED_ATTR) 453 desc = &mandatory_attr_desc[attr_type]; 454 else if (attr_type >= PJ_STUN_ATTR_START_EXTENDED_ATTR && 455 attr_type < PJ_STUN_ATTR_END_EXTENDED_ATTR) 456 desc = &extended_attr_desc[attr_type-PJ_STUN_ATTR_START_EXTENDED_ATTR]; 457 else 458 return NULL; 459 460 return desc->decode_attr == NULL ? NULL : desc; 461 } 462 463 464 /* 465 * Get STUN attribute name. 466 */ 467 PJ_DEF(const char*) pj_stun_get_attr_name(unsigned attr_type) 468 { 469 const struct attr_desc *attr_desc; 470 471 attr_desc = find_attr_desc(attr_type); 472 if (!attr_desc || attr_desc->name==NULL) 473 return "???"; 474 475 return attr_desc->name; 476 } 477 478 62 479 /** 63 480 * Get STUN standard reason phrase for the specified error code. … … 119 536 attr->addr.ipv4.sin_addr.s_addr = (addr4->sin_addr.s_addr ^ 120 537 pj_htonl(0x2112A442)); 538 } else if (addr_len == sizeof(pj_sockaddr_in6)) { 539 return PJLIB_UTIL_ESTUNIPV6NOTSUPP; 121 540 } else { 122 return PJ _ENOTSUP;541 return PJLIB_UTIL_ESTUNINADDRLEN; 123 542 } 124 543 … … 153 572 /* Check address family is valid (only supports ipv4 for now) */ 154 573 if (val != 1) 155 return PJLIB_UTIL_ESTUNI NATTR;574 return PJLIB_UTIL_ESTUNIPV6NOTSUPP; 156 575 157 576 /* Get port and address */ … … 185 604 attr = (pj_stun_generic_ip_addr_attr*) buf; 186 605 attr->hdr.type = pj_htons(attr->hdr.type); 187 attr->hdr.length = pj_htons((pj_uint16_t) ATTR_LEN);606 attr->hdr.length = pj_htons((pj_uint16_t)STUN_GENERIC_IP_ADDR_LEN); 188 607 buf += ATTR_HDR_LEN; 189 608 … … 371 790 attr = (pj_stun_empty_attr*) buf; 372 791 attr->hdr.type = pj_htons(attr->hdr.type); 373 attr->hdr.length = pj_htons(attr->hdr.length); 792 pj_assert(attr->hdr.length == ATTR_HDR_LEN); 793 attr->hdr.length = pj_htons(ATTR_HDR_LEN); 374 794 375 795 /* Done */ … … 458 878 attr = (pj_stun_generic_uint_attr*) buf; 459 879 attr->hdr.type = pj_htons(attr->hdr.type); 460 attr->hdr.length = pj_htons(attr->hdr.length); 880 pj_assert(attr->hdr.length == STUN_UINT_LEN); 881 attr->hdr.length = pj_htons(STUN_UINT_LEN); 461 882 attr->value = pj_htonl(attr->value); 462 883 … … 539 960 attr = (pj_stun_msg_integrity_attr*) buf; 540 961 attr->hdr.type = pj_htons(attr->hdr.type); 541 attr->hdr.length = pj_htons(attr->hdr.length); 962 pj_assert(attr->hdr.length == STUN_MSG_INTEGRITY_LEN); 963 attr->hdr.length = pj_htons(STUN_MSG_INTEGRITY_LEN); 542 964 543 965 /* Done */ … … 847 1269 848 1270 ////////////////////////////////////////////////////////////////////////////// 849 850 851 struct attr_desc852 {853 pj_status_t (*decode_attr)(pj_pool_t *pool, const pj_uint8_t *buf,854 void **p_attr);855 pj_status_t (*encode_attr)(const void *a, pj_uint8_t *buf,856 unsigned len, unsigned *printed);857 858 };859 860 struct attr_desc mandatory_attr_desc[] =861 {862 {863 /* type zero */864 NULL,865 NULL866 },867 {868 /* PJ_STUN_ATTR_MAPPED_ADDR, */869 &decode_generic_ip_addr_attr,870 &encode_generic_ip_addr_attr871 },872 {873 /* PJ_STUN_ATTR_RESPONSE_ADDR, */874 &decode_generic_ip_addr_attr,875 &encode_generic_ip_addr_attr876 },877 {878 /* PJ_STUN_ATTR_CHANGE_REQUEST, */879 &decode_generic_uint_attr,880 &encode_generic_uint_attr881 },882 {883 /* PJ_STUN_ATTR_SOURCE_ADDR, */884 &decode_generic_ip_addr_attr,885 &encode_generic_ip_addr_attr886 },887 {888 /* PJ_STUN_ATTR_CHANGED_ADDR, */889 &decode_generic_ip_addr_attr,890 &encode_generic_ip_addr_attr891 },892 {893 /* PJ_STUN_ATTR_USERNAME, */894 &decode_generic_string_attr,895 &encode_generic_string_attr896 },897 {898 /* PJ_STUN_ATTR_PASSWORD, */899 &decode_generic_string_attr,900 &encode_generic_string_attr901 },902 {903 /* PJ_STUN_ATTR_MESSAGE_INTEGRITY, */904 &decode_msg_integrity_attr,905 &encode_msg_integrity_attr906 },907 {908 /* PJ_STUN_ATTR_ERROR_CODE, */909 &decode_error_code_attr,910 &encode_error_code_attr911 },912 {913 /* PJ_STUN_ATTR_UNKNOWN_ATTRIBUTES, */914 &decode_unknown_attr,915 &encode_unknown_attr916 },917 {918 /* PJ_STUN_ATTR_REFLECTED_FROM, */919 &decode_generic_ip_addr_attr,920 &encode_generic_ip_addr_attr921 },922 {923 /* ID 0x000C is not assigned */924 NULL,925 NULL926 },927 {928 /* PJ_STUN_ATTR_LIFETIME, */929 &decode_generic_uint_attr,930 &encode_generic_uint_attr931 },932 {933 /* ID 0x000E is not assigned */934 NULL,935 NULL936 },937 {938 /* ID 0x000F is not assigned */939 NULL,940 NULL941 },942 {943 /* PJ_STUN_ATTR_BANDWIDTH, */944 &decode_generic_uint_attr,945 &encode_generic_uint_attr946 },947 {948 /* ID 0x0011 is not assigned */949 NULL,950 NULL951 },952 {953 /* PJ_STUN_ATTR_REMOTE_ADDRESS, */954 &decode_generic_ip_addr_attr,955 &encode_generic_ip_addr_attr956 },957 {958 /* PJ_STUN_ATTR_DATA, */959 &decode_binary_attr,960 &encode_binary_attr961 },962 {963 /* PJ_STUN_ATTR_REALM, */964 &decode_generic_string_attr,965 &encode_generic_string_attr966 },967 {968 /* PJ_STUN_ATTR_NONCE, */969 &decode_generic_string_attr,970 &encode_generic_string_attr971 },972 {973 /* PJ_STUN_ATTR_RELAY_ADDRESS, */974 &decode_generic_ip_addr_attr,975 &encode_generic_ip_addr_attr976 },977 {978 /* PJ_STUN_ATTR_REQUESTED_ADDR_TYPE, */979 &decode_generic_uint_attr,980 &encode_generic_uint_attr981 },982 {983 /* PJ_STUN_ATTR_REQUESTED_PORT_PROPS, */984 &decode_generic_uint_attr,985 &encode_generic_uint_attr986 },987 {988 /* PJ_STUN_ATTR_REQUESTED_TRANSPORT, */989 &decode_generic_uint_attr,990 &encode_generic_uint_attr991 },992 {993 /* ID 0x001A is not assigned */994 NULL,995 NULL996 },997 {998 /* ID 0x001B is not assigned */999 NULL,1000 NULL1001 },1002 {1003 /* ID 0x001C is not assigned */1004 NULL,1005 NULL1006 },1007 {1008 /* ID 0x001D is not assigned */1009 NULL,1010 NULL1011 },1012 {1013 /* ID 0x001E is not assigned */1014 NULL,1015 NULL1016 },1017 {1018 /* ID 0x001F is not assigned */1019 NULL,1020 NULL1021 },1022 {1023 /* PJ_STUN_ATTR_XOR_MAPPED_ADDRESS, */1024 &decode_generic_ip_addr_attr,1025 &encode_generic_ip_addr_attr1026 },1027 {1028 /* PJ_STUN_ATTR_TIMER_VAL, */1029 &decode_generic_uint_attr,1030 &encode_generic_uint_attr1031 },1032 {1033 /* PJ_STUN_ATTR_REQUESTED_IP, */1034 &decode_generic_ip_addr_attr,1035 &encode_generic_ip_addr_attr1036 },1037 {1038 /* PJ_STUN_ATTR_XOR_REFLECTED_FROM, */1039 &decode_generic_ip_addr_attr,1040 &encode_generic_ip_addr_attr1041 },1042 {1043 /* PJ_STUN_ATTR_PRIORITY, */1044 &decode_generic_uint_attr,1045 &encode_generic_uint_attr1046 },1047 {1048 /* PJ_STUN_ATTR_USE_CANDIDATE, */1049 &decode_empty_attr,1050 &encode_empty_attr1051 },1052 {1053 /* PJ_STUN_ATTR_XOR_INTERNAL_ADDR, */1054 &decode_generic_ip_addr_attr,1055 &encode_generic_ip_addr_attr1056 },1057 1058 /* Sentinel */1059 {1060 /* PJ_STUN_ATTR_END_MANDATORY_ATTR */1061 NULL,1062 NULL1063 }1064 };1065 1066 static struct attr_desc extended_attr_desc[] =1067 {1068 {1069 /* PJ_STUN_ATTR_FINGERPRINT, */1070 &decode_generic_uint_attr,1071 &encode_generic_uint_attr1072 },1073 {1074 /* PJ_STUN_ATTR_SERVER, */1075 &decode_generic_string_attr,1076 &encode_generic_string_attr1077 },1078 {1079 /* PJ_STUN_ATTR_ALTERNATE_SERVER, */1080 &decode_generic_ip_addr_attr,1081 &encode_generic_ip_addr_attr1082 },1083 {1084 /* PJ_STUN_ATTR_REFRESH_INTERVAL, */1085 &decode_generic_uint_attr,1086 &encode_generic_uint_attr1087 },1088 };1089 1090 1091 static const struct attr_desc *find_attr_desc(unsigned attr_type)1092 {1093 struct attr_desc *desc;1094 1095 /* Check that attr_desc array is valid */1096 pj_assert(PJ_ARRAY_SIZE(mandatory_attr_desc)==1097 PJ_STUN_ATTR_END_MANDATORY_ATTR+1);1098 pj_assert(mandatory_attr_desc[PJ_STUN_ATTR_END_MANDATORY_ATTR].decode_attr1099 == NULL);1100 pj_assert(mandatory_attr_desc[PJ_STUN_ATTR_USE_CANDIDATE].decode_attr1101 == &decode_empty_attr);1102 pj_assert(PJ_ARRAY_SIZE(extended_attr_desc) ==1103 PJ_STUN_ATTR_END_EXTENDED_ATTR-PJ_STUN_ATTR_START_EXTENDED_ATTR);1104 1105 if (attr_type < PJ_STUN_ATTR_START_EXTENDED_ATTR)1106 desc = &mandatory_attr_desc[attr_type];1107 else if (attr_type >= PJ_STUN_ATTR_START_EXTENDED_ATTR &&1108 attr_type < PJ_STUN_ATTR_END_EXTENDED_ATTR)1109 desc = &extended_attr_desc[attr_type-PJ_STUN_ATTR_START_EXTENDED_ATTR];1110 else1111 return NULL;1112 1113 return desc->decode_attr == NULL ? NULL : desc;1114 }1115 1116 1271 1117 1272 /* … … 1377 1532 * Note that length is not including the 20 bytes header. 1378 1533 */ 1379 hdr->length = pj_htons((pj_uint16_t)(buf - start)); 1534 hdr->length = (pj_uint16_t)((buf - start) - 20); 1535 hdr->length = pj_htons(hdr->length); 1380 1536 1381 1537 /* Done */ -
pjproject/trunk/pjlib-util/src/pjlib-util/stun_simple.c
r991 r992 26 26 #define THIS_FILE "stun.c" 27 27 28 PJ_DEF(pj_status_t) pj _stun_create_bind_req( pj_pool_t *pool,28 PJ_DEF(pj_status_t) pjstun_create_bind_req( pj_pool_t *pool, 29 29 void **msg, pj_size_t *len, 30 30 pj_uint32_t id_hi, 31 31 pj_uint32_t id_lo) 32 32 { 33 pj _stun_msg_hdr *hdr;33 pjstun_msg_hdr *hdr; 34 34 35 35 PJ_CHECK_STACK(); 36 36 37 37 38 hdr = pj_pool_calloc(pool, 1, sizeof(pj _stun_msg_hdr));38 hdr = pj_pool_calloc(pool, 1, sizeof(pjstun_msg_hdr)); 39 39 if (!hdr) 40 40 return PJ_ENOMEM; 41 41 42 hdr->type = pj_htons(PJ _STUN_BINDING_REQUEST);42 hdr->type = pj_htons(PJSTUN_BINDING_REQUEST); 43 43 hdr->tsx[2] = pj_htonl(id_hi); 44 44 hdr->tsx[3] = pj_htonl(id_lo); 45 45 *msg = hdr; 46 *len = sizeof(pj _stun_msg_hdr);46 *len = sizeof(pjstun_msg_hdr); 47 47 48 48 return PJ_SUCCESS; 49 49 } 50 50 51 PJ_DEF(pj_status_t) pj _stun_parse_msg( void *buf, pj_size_t len,52 pj _stun_msg *msg)51 PJ_DEF(pj_status_t) pjstun_parse_msg( void *buf, pj_size_t len, 52 pjstun_msg *msg) 53 53 { 54 54 pj_uint16_t msg_type, msg_len; … … 57 57 PJ_CHECK_STACK(); 58 58 59 msg->hdr = (pj _stun_msg_hdr*)buf;59 msg->hdr = (pjstun_msg_hdr*)buf; 60 60 msg_type = pj_ntohs(msg->hdr->type); 61 61 62 62 switch (msg_type) { 63 case PJ _STUN_BINDING_REQUEST:64 case PJ _STUN_BINDING_RESPONSE:65 case PJ _STUN_BINDING_ERROR_RESPONSE:66 case PJ _STUN_SHARED_SECRET_REQUEST:67 case PJ _STUN_SHARED_SECRET_RESPONSE:68 case PJ _STUN_SHARED_SECRET_ERROR_RESPONSE:63 case PJSTUN_BINDING_REQUEST: 64 case PJSTUN_BINDING_RESPONSE: 65 case PJSTUN_BINDING_ERROR_RESPONSE: 66 case PJSTUN_SHARED_SECRET_REQUEST: 67 case PJSTUN_SHARED_SECRET_RESPONSE: 68 case PJSTUN_SHARED_SECRET_ERROR_RESPONSE: 69 69 break; 70 70 default: … … 74 74 75 75 msg_len = pj_ntohs(msg->hdr->length); 76 if (msg_len != len - sizeof(pj _stun_msg_hdr)) {76 if (msg_len != len - sizeof(pjstun_msg_hdr)) { 77 77 PJ_LOG(4,(THIS_FILE, "Error: invalid msg_len %d (expecting %d)", 78 msg_len, len - sizeof(pj _stun_msg_hdr)));78 msg_len, len - sizeof(pjstun_msg_hdr))); 79 79 return PJLIB_UTIL_ESTUNINMSGLEN; 80 80 } 81 81 82 82 msg->attr_count = 0; 83 p_attr = (char*)buf + sizeof(pj _stun_msg_hdr);83 p_attr = (char*)buf + sizeof(pjstun_msg_hdr); 84 84 85 85 while (msg_len > 0) { 86 pj _stun_attr_hdr **attr = &msg->attr[msg->attr_count];86 pjstun_attr_hdr **attr = &msg->attr[msg->attr_count]; 87 87 pj_uint32_t len; 88 88 89 *attr = (pj _stun_attr_hdr*)p_attr;90 len = pj_ntohs((pj_uint16_t) ((*attr)->length)) + sizeof(pj _stun_attr_hdr);89 *attr = (pjstun_attr_hdr*)p_attr; 90 len = pj_ntohs((pj_uint16_t) ((*attr)->length)) + sizeof(pjstun_attr_hdr); 91 91 92 92 if (msg_len < len) { … … 96 96 } 97 97 98 if (pj_ntohs((*attr)->type) > PJ _STUN_ATTR_REFLECTED_FORM) {98 if (pj_ntohs((*attr)->type) > PJSTUN_ATTR_REFLECTED_FORM) { 99 99 PJ_LOG(5,(THIS_FILE, "Warning: unknown attr type %x in attr %d. " 100 100 "Attribute was ignored.", … … 110 110 } 111 111 112 PJ_DEF(void*) pj _stun_msg_find_attr( pj_stun_msg *msg, pj_stun_attr_type t)112 PJ_DEF(void*) pjstun_msg_find_attr( pjstun_msg *msg, pjstun_attr_type t) 113 113 { 114 114 int i; … … 117 117 118 118 for (i=0; i<msg->attr_count; ++i) { 119 pj _stun_attr_hdr *attr = msg->attr[i];119 pjstun_attr_hdr *attr = msg->attr[i]; 120 120 if (pj_ntohs(attr->type) == t) 121 121 return attr; -
pjproject/trunk/pjlib-util/src/pjlib-util/stun_simple_client.c
r991 r992 33 33 34 34 35 PJ_DECL(pj_status_t) pj _stun_get_mapped_addr( pj_pool_factory *pf,35 PJ_DECL(pj_status_t) pjstun_get_mapped_addr( pj_pool_factory *pf, 36 36 int sock_cnt, pj_sock_t sock[], 37 37 const pj_str_t *srv1, int port1, … … 70 70 71 71 /* Create the outgoing BIND REQUEST message template */ 72 status = pj _stun_create_bind_req( pool, &out_msg, &out_msg_len,72 status = pjstun_create_bind_req( pool, &out_msg, &out_msg_len, 73 73 pj_rand(), pj_rand()); 74 74 if (status != PJ_SUCCESS) … … 98 98 for (i=0; i<sock_cnt && status==PJ_SUCCESS; ++i) { 99 99 for (j=0; j<2 && status==PJ_SUCCESS; ++j) { 100 pj _stun_msg_hdr *msg_hdr = out_msg;100 pjstun_msg_hdr *msg_hdr = out_msg; 101 101 pj_ssize_t sent_len; 102 102 … … 151 151 int sock_idx, srv_idx; 152 152 pj_ssize_t len; 153 pj _stun_msg msg;153 pjstun_msg msg; 154 154 pj_sockaddr_in addr; 155 155 int addrlen = sizeof(addr); 156 pj _stun_mapped_addr_attr *attr;156 pjstun_mapped_addr_attr *attr; 157 157 char recv_buf[128]; 158 158 … … 171 171 continue; 172 172 173 status = pj _stun_parse_msg(recv_buf, len, &msg);173 status = pjstun_parse_msg(recv_buf, len, &msg); 174 174 if (status != PJ_SUCCESS) { 175 175 continue; … … 185 185 } 186 186 187 if (pj_ntohs(msg.hdr->type) != PJ _STUN_BINDING_RESPONSE) {187 if (pj_ntohs(msg.hdr->type) != PJSTUN_BINDING_RESPONSE) { 188 188 status = PJLIB_UTIL_ESTUNNOBINDRES; 189 189 continue; 190 190 } 191 191 192 if (pj _stun_msg_find_attr(&msg, PJ_STUN_ATTR_ERROR_CODE) != NULL) {192 if (pjstun_msg_find_attr(&msg, PJSTUN_ATTR_ERROR_CODE) != NULL) { 193 193 status = PJLIB_UTIL_ESTUNRECVERRATTR; 194 194 continue; 195 195 } 196 196 197 attr = (void*)pj _stun_msg_find_attr(&msg, PJ_STUN_ATTR_MAPPED_ADDR);197 attr = (void*)pjstun_msg_find_attr(&msg, PJSTUN_ATTR_MAPPED_ADDR); 198 198 if (!attr) { 199 199 status = PJLIB_UTIL_ESTUNNOMAP; -
pjproject/trunk/pjlib-util/src/pjstun-srv/server_main.c
r991 r992 120 120 } 121 121 122 PJ_LOG(4,(THIS_FILE, "Sending STUN %s %s", 123 pj_stun_get_method_name(msg->hdr.type), 124 pj_stun_get_class_name(msg->hdr.type))); 125 122 126 return (status == PJ_SUCCESS || status == PJ_EPENDING) ? 123 127 PJ_SUCCESS : status; … … 230 234 NULL, &err_code, &uattr_cnt, uattr_types); 231 235 if (status != PJ_SUCCESS) { 236 server_perror(THIS_FILE, "STUN msg_decode() error", status); 232 237 if (err_code != 0 && rx_msg && PJ_STUN_IS_REQUEST(rx_msg->hdr.type)) { 233 238 err_respond(svc, pool, rx_msg, err_code, … … 236 241 goto next_read; 237 242 } 243 244 PJ_LOG(4,(THIS_FILE, "RX STUN %s %s message", 245 pj_stun_get_method_name(rx_msg->hdr.type), 246 pj_stun_get_class_name(rx_msg->hdr.type))); 238 247 239 248 if (PJ_STUN_IS_REQUEST(rx_msg->hdr.type)) { -
pjproject/trunk/pjlib/include/pj/pool.h
r974 r992 442 442 * 443 443 * @return pointer to the allocated memory. 444 * 445 * @see PJ_POOL_ALLOC_TYPE 444 446 */ 445 447 PJ_IDECL(void*) pj_pool_alloc( pj_pool_t *pool, pj_size_t size); … … 461 463 462 464 /** 463 * @def pj_pool_zalloc(pj_pool_t *pool, pj_size_t size)464 465 * Allocate storage from the pool and initialize it to zero. 465 466 * … … 468 469 * 469 470 * @return Pointer to the allocated memory. 470 */ 471 #define pj_pool_zalloc(pool, size) pj_pool_calloc(pool, 1, size) 471 * 472 * @see PJ_POOL_ZALLOC_TYPE 473 */ 474 PJ_INLINE(void*) pj_pool_zalloc(pj_pool_t *pool, pj_size_t size) 475 { 476 return pj_pool_calloc(pool, 1, size); 477 } 478 479 480 /** 481 * This macro allocates memory from the pool and returns the instance of 482 * the specified type. It provides a stricker type safety than pj_pool_alloc() 483 * since the return value of this macro will be type-casted to the specified 484 * type. 485 * 486 * @param pool The pool 487 * @param type The type of object to be allocated 488 * 489 * @return Memory buffer of the specified type. 490 */ 491 #define PJ_POOL_ALLOC_TYPE(pool,type) \ 492 ((type*)pj_pool_alloc(pool, sizeof(type))) 493 494 /** 495 * This macro allocates memory from the pool, zeroes the buffer, and 496 * returns the instance of the specified type. It provides a stricker type 497 * safety than pj_pool_zalloc() since the return value of this macro will be 498 * type-casted to the specified type. 499 * 500 * @param pool The pool 501 * @param type The type of object to be allocated 502 * 503 * @return Memory buffer of the specified type. 504 */ 505 #define PJ_POOL_ZALLOC_TYPE(pool,type) \ 506 ((type*)pj_pool_zalloc(pool, sizeof(type))) 507 472 508 473 509 -
pjproject/trunk/pjsip/src/pjsua-lib/pjsua_core.c
r974 r992 871 871 * STUN is specified, resolve the address with STUN. 872 872 */ 873 status = pj _stun_get_mapped_addr(&pjsua_var.cp.factory, 1, &sock,873 status = pjstun_get_mapped_addr(&pjsua_var.cp.factory, 1, &sock, 874 874 &stun.stun_srv1, 875 875 stun.stun_port1, -
pjproject/trunk/pjsip/src/pjsua-lib/pjsua_media.c
r974 r992 273 273 */ 274 274 if (cfg->stun_config.stun_srv1.slen) { 275 status=pj _stun_get_mapped_addr(&pjsua_var.cp.factory, 2, sock,275 status=pjstun_get_mapped_addr(&pjsua_var.cp.factory, 2, sock, 276 276 &cfg->stun_config.stun_srv1, 277 277 cfg->stun_config.stun_port1,
Note: See TracChangeset
for help on using the changeset viewer.