Changeset 1037 for pjproject/trunk/pjlib-util/include/pjlib-util/stun_msg.h
- Timestamp:
- Mar 3, 2007 2:16:36 AM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjlib-util/include/pjlib-util/stun_msg.h
r1021 r1037 511 511 \endverbatim 512 512 */ 513 typedef struct pj_stun_ generic_ip_addr_attr513 typedef struct pj_stun_ip_addr_attr 514 514 { 515 515 /** … … 527 527 } addr; 528 528 529 } pj_stun_ generic_ip_addr_attr;529 } pj_stun_ip_addr_attr; 530 530 531 531 … … 549 549 * NONCE attributes, the text MUST be quoted with. 550 550 */ 551 typedef struct pj_stun_ generic_string_attr551 typedef struct pj_stun_string_attr 552 552 { 553 553 /** … … 561 561 pj_str_t value; 562 562 563 } pj_stun_ generic_string_attr;563 } pj_stun_string_attr; 564 564 565 565 … … 568 568 * integer value, such as STUN FINGERPRINT and REFRESH-INTERVAL attributes. 569 569 */ 570 typedef struct pj_stun_ generic_uint_attr570 typedef struct pj_stun_uint_attr 571 571 { 572 572 /** … … 580 580 pj_uint32_t value; 581 581 582 } pj_stun_ generic_uint_attr;582 } pj_stun_uint_attr; 583 583 584 584 … … 614 614 * bytes. 615 615 */ 616 typedef struct pj_stun_msg _integrity_attr616 typedef struct pj_stun_msgint_attr 617 617 { 618 618 /** … … 626 626 pj_uint8_t hmac[20]; 627 627 628 } pj_stun_msg _integrity_attr;628 } pj_stun_msgint_attr; 629 629 630 630 … … 635 635 * attribute itself, xor-d with the 32 bit value 0x5354554e 636 636 */ 637 typedef struct pj_stun_ generic_uint_attr pj_stun_fingerprint_attr;637 typedef struct pj_stun_uint_attr pj_stun_fingerprint_attr; 638 638 639 639 … … 656 656 \endverbatim 657 657 */ 658 typedef struct pj_stun_err or_code_attr658 typedef struct pj_stun_errcode_attr 659 659 { 660 660 /** … … 683 683 pj_str_t reason; 684 684 685 } pj_stun_err or_code_attr;685 } pj_stun_errcode_attr; 686 686 687 687 … … 693 693 * quotes). 694 694 */ 695 typedef struct pj_stun_ generic_string_attr pj_stun_realm_attr;695 typedef struct pj_stun_string_attr pj_stun_realm_attr; 696 696 697 697 … … 703 703 * values in a server. 704 704 */ 705 typedef struct pj_stun_ generic_string_attr pj_stun_nonce_attr;705 typedef struct pj_stun_string_attr pj_stun_nonce_attr; 706 706 707 707 … … 740 740 * The MAPPED-ADDRESS attribute indicates the mapped transport address. 741 741 */ 742 typedef struct pj_stun_ generic_ip_addr_attr pj_stun_mapped_addr_attr;742 typedef struct pj_stun_ip_addr_attr pj_stun_mapped_addr_attr; 743 743 744 744 … … 752 752 * through NATs which would otherwise interfere with STUN. 753 753 */ 754 typedef struct pj_stun_ generic_ip_addr_attr pj_stun_xor_mapped_addr_attr;754 typedef struct pj_stun_ip_addr_attr pj_stun_xor_mapped_addr_attr; 755 755 756 756 … … 763 763 * SERVER is variable length. 764 764 */ 765 typedef struct pj_stun_ generic_string_attr pj_stun_server_attr;765 typedef struct pj_stun_string_attr pj_stun_server_attr; 766 766 767 767 … … 772 772 * MAPPED-ADDRESS. 773 773 */ 774 typedef struct pj_stun_ generic_ip_addr_attr pj_stun_alt_server_attr;774 typedef struct pj_stun_ip_addr_attr pj_stun_alt_server_attr; 775 775 776 776 … … 781 781 * bindings between the client and server. 782 782 */ 783 typedef struct pj_stun_ generic_uint_attr pj_stun_refresh_interval_attr;783 typedef struct pj_stun_uint_attr pj_stun_refresh_interval_attr; 784 784 785 785 … … 793 793 * RFC 3489-bis standard. 794 794 */ 795 typedef struct pj_stun_ generic_ip_addr_attr pj_stun_response_addr_attr;795 typedef struct pj_stun_ip_addr_attr pj_stun_response_addr_attr; 796 796 797 797 … … 808 808 * RFC 3489-bis standard. 809 809 */ 810 typedef struct pj_stun_ generic_ip_addr_attr pj_stun_changed_addr_attr;810 typedef struct pj_stun_ip_addr_attr pj_stun_changed_addr_attr; 811 811 812 812 … … 828 828 * RFC 3489-bis standard. 829 829 */ 830 typedef struct pj_stun_ generic_uint_attr pj_stun_change_request_attr;830 typedef struct pj_stun_uint_attr pj_stun_change_request_attr; 831 831 832 832 /** … … 840 840 * RFC 3489-bis standard. 841 841 */ 842 typedef struct pj_stun_ generic_ip_addr_attr pj_stun_src_addr_attr;842 typedef struct pj_stun_ip_addr_attr pj_stun_src_addr_attr; 843 843 844 844 … … 852 852 * denial-of-service attacks. 853 853 */ 854 typedef struct pj_stun_ generic_ip_addr_attr pj_stun_reflected_from_attr;854 typedef struct pj_stun_ip_addr_attr pj_stun_reflected_from_attr; 855 855 856 856 … … 862 862 * MESSAGE-INTEGRITY attribute. 863 863 */ 864 typedef struct pj_stun_ generic_string_attr pj_stun_username_attr;864 typedef struct pj_stun_string_attr pj_stun_username_attr; 865 865 866 866 … … 870 870 * PASSWORD attribute. 871 871 */ 872 typedef struct pj_stun_ generic_string_attr pj_stun_password_attr;872 typedef struct pj_stun_string_attr pj_stun_password_attr; 873 873 874 874 … … 880 880 * of seconds remaining until expiration. 881 881 */ 882 typedef struct pj_stun_ generic_uint_attr pj_stun_lifetime_attr;882 typedef struct pj_stun_uint_attr pj_stun_lifetime_attr; 883 883 884 884 … … 889 889 * value represents the sum in the receive and send directions. 890 890 */ 891 typedef struct pj_stun_ generic_uint_attr pj_stun_bandwidth_attr;891 typedef struct pj_stun_uint_attr pj_stun_bandwidth_attr; 892 892 893 893 … … 897 897 * from the STUN relay server. 898 898 */ 899 typedef struct pj_stun_ generic_ip_addr_attr pj_stun_remote_addr_attr;899 typedef struct pj_stun_ip_addr_attr pj_stun_remote_addr_attr; 900 900 901 901 … … 915 915 * address and port that the server allocated to the client. 916 916 */ 917 typedef struct pj_stun_ generic_ip_addr_attr pj_stun_relay_addr_attr;917 typedef struct pj_stun_ip_addr_attr pj_stun_relay_addr_attr; 918 918 919 919 … … 934 934 \endverbatim 935 935 */ 936 typedef struct pj_stun_ generic_uint_attr pj_stun_requested_addr_type;936 typedef struct pj_stun_uint_attr pj_stun_requested_addr_type; 937 937 938 938 /** … … 954 954 \endverbatim 955 955 */ 956 typedef struct pj_stun_ generic_uint_attr pj_stun_requested_port_props_attr;956 typedef struct pj_stun_uint_attr pj_stun_requested_port_props_attr; 957 957 958 958 … … 963 963 * unsigned integer. Its values are: 0x0000 for UDP and 0x0000 for TCP. 964 964 */ 965 typedef struct pj_stun_ generic_uint_attr pj_stun_requested_transport_attr;965 typedef struct pj_stun_uint_attr pj_stun_requested_transport_attr; 966 966 967 967 … … 971 971 * specific IP address be allocated to it. 972 972 */ 973 typedef struct pj_stun_ generic_ip_addr_attr pj_stun_requested_ip_attr;973 typedef struct pj_stun_ip_addr_attr pj_stun_requested_ip_attr; 974 974 975 975 /** … … 983 983 * to XOR-MAPPED-ADDRESS. 984 984 */ 985 typedef struct pj_stun_ generic_ip_addr_attr pj_stun_xor_reflected_from_attr;985 typedef struct pj_stun_ip_addr_attr pj_stun_xor_reflected_from_attr; 986 986 987 987 /** … … 992 992 * type of 0x0024. 993 993 */ 994 typedef struct pj_stun_ generic_uint_attr pj_stun_priority_attr;994 typedef struct pj_stun_uint_attr pj_stun_priority_attr; 995 995 996 996 /** … … 1011 1011 * the STUN-aware NATs along the path. 1012 1012 */ 1013 typedef pj_stun_ generic_ip_addr_attr pj_stun_xor_internal_addr_attr;1013 typedef pj_stun_ip_addr_attr pj_stun_xor_internal_addr_attr; 1014 1014 1015 1015 /** … … 1019 1019 * client, the value of the timer used in the server state machine. 1020 1020 */ 1021 typedef struct pj_stun_ generic_uint_attr pj_stun_timer_val_attr;1021 typedef struct pj_stun_uint_attr pj_stun_timer_val_attr; 1022 1022 1023 1023 … … 1048 1048 1049 1049 /** STUN decoding options */ 1050 enum pj_stun_ options1050 enum pj_stun_decode_options 1051 1051 { 1052 1052 /** … … 1063 1063 PJ_STUN_CHECK_PACKET = 2 1064 1064 }; 1065 1065 1066 1066 1067 /** … … 1208 1209 * @param pdu_len The length of the packet buffer. 1209 1210 * @param options Additional options to be applied in the checking, 1210 * which can be taken from pj_stun_ options. One of the1211 * useful option is PJ_STUN_IS_DATAGRAM which means that1212 * the pdu represents a whole STUN packet.1211 * which can be taken from pj_stun_decode_options. One 1212 * of the useful option is PJ_STUN_IS_DATAGRAM which 1213 * means that the pdu represents a whole STUN packet. 1213 1214 * 1214 1215 * @return PJ_SUCCESS if the PDU is a potentially valid STUN 1215 1216 * message. 1216 1217 */ 1217 PJ_DECL(pj_status_t) pj_stun_msg_check(const pj_uint8_t *pdu, unsigned pdu_len,1218 unsigned options);1218 PJ_DECL(pj_status_t) pj_stun_msg_check(const pj_uint8_t *pdu, 1219 unsigned pdu_len, unsigned options); 1219 1220 1220 1221 … … 1225 1226 * @param pdu The incoming packet to be parsed. 1226 1227 * @param pdu_len The length of the incoming packet. 1227 * @param options Parsing flags, according to pj_stun_ options.1228 * @param options Parsing flags, according to pj_stun_decode_options. 1228 1229 * @param p_msg Pointer to receive the parsed message. 1229 1230 * @param p_parsed_len Optional pointer to receive how many bytes have … … 1248 1249 pj_stun_msg **p_response); 1249 1250 1250 typedef enum pj_stun_auth_policy_type1251 {1252 PJ_STUN_POLICY_NONE,1253 PJ_STUN_POLICY_STATIC_SHORT_TERM,1254 PJ_STUN_POLICY_STATIC_LONG_TERM,1255 PJ_STUN_POLICY_DYNAMIC1256 } pj_stun_auth_policy_type;1257 1258 typedef struct pj_stun_auth_policy1259 {1260 pj_stun_auth_policy_type type;1261 void *user_data;1262 1263 union1264 {1265 struct1266 {1267 pj_str_t username;1268 pj_str_t password;1269 pj_str_t nonce;1270 } static_short_term;1271 1272 struct1273 {1274 pj_str_t realm;1275 pj_str_t username;1276 pj_str_t password;1277 pj_str_t nonce;1278 } static_long_term;1279 1280 struct1281 {1282 /**1283 * This callback is called by pj_stun_verify_credential() when1284 * server needs to challenge the request with 401 response.1285 *1286 * @param user_data The user data as specified in the policy.1287 * @param pool Pool to allocate memory.1288 * @param realm On return, the function should fill in with1289 * realm if application wants to use long term1290 * credential. Otherwise application should set1291 * empty string for the realm.1292 * @param nonce On return, if application wants to use long1293 * term credential, it MUST fill in the nonce1294 * with some value. Otherwise if short term1295 * credential is wanted, it MAY set this value.1296 * If short term credential is wanted and the1297 * application doesn't want to include NONCE,1298 * then it must set this to empty string.1299 *1300 * @return The callback should return PJ_SUCCESS, or1301 * otherwise response message will not be1302 * created.1303 */1304 pj_status_t (*get_auth)(void *user_data,1305 pj_pool_t *pool,1306 pj_str_t *realm,1307 pj_str_t *nonce);1308 1309 /**1310 * Get the password for the specified username. This function1311 * is also used to check whether the username is valid.1312 *1313 * @param user_data The user data as specified in the policy.1314 * @param realm The realm as specified in the message.1315 * @param username The username as specified in the message.1316 * @param pool Pool to allocate memory when necessary.1317 * @param password On return, application should fill up this1318 * argument with the password.1319 *1320 * @return The callback should return PJ_SUCCESS if1321 * username has been successfully verified1322 * and password was obtained. If non-PJ_SUCCESS1323 * is returned, it is assumed that the1324 * username is not valid.1325 */1326 pj_status_t (*get_password)(void *user_data,1327 const pj_str_t *realm,1328 const pj_str_t *username,1329 pj_pool_t *pool,1330 pj_str_t *password);1331 pj_bool_t (*require_nonce)(void *user_data,1332 const pj_str_t *realm,1333 const pj_str_t *username);1334 pj_bool_t (*verify_nonce)(void *data,1335 const pj_str_t *realm,1336 const pj_str_t *username,1337 const pj_str_t *nonce);1338 pj_status_t (*make_nonce)(void *user_data,1339 const pj_str_t *realm,1340 const pj_str_t *username,1341 pj_pool_t *pool,1342 pj_str_t *nonce);1343 } dynamic;1344 1345 } data;1346 1347 } pj_stun_auth_policy;1348 1349 1350 /**1351 * Verify credential in the STUN message. Note that before calling this1352 * function, application must have checked that the message contains1353 * PJ_STUN_ATTR_MESSAGE_INTEGRITY attribute by calling pj_stun_msg_find_attr()1354 * function, because this function will reject the message with 401 error1355 * if it doesn't contain PJ_STUN_ATTR_MESSAGE_INTEGRITY attribute.1356 *1357 * @param pkt The original packet which has been parsed into1358 * the message. This packet MUST NOT have been modified1359 * after the parsing.1360 * @param pkt_len The length of the packet.1361 * @param msg The parsed message to be verified.1362 * @param policy Pointer to authentication policy.1363 * @param pool If response is to be created, then memory will1364 * be allocated from this pool.1365 * @param p_response Optional pointer to receive the response message1366 * then the credential in the request fails to1367 * authenticate.1368 *1369 * @return PJ_SUCCESS if credential is verified successfully.1370 * If the verification fails and \a p_response is not1371 * NULL, an appropriate response will be returned in1372 * \a p_response.1373 */1374 PJ_DECL(pj_status_t) pj_stun_verify_credential(const pj_uint8_t *pkt,1375 unsigned pkt_len,1376 const pj_stun_msg *msg,1377 pj_stun_auth_policy *policy,1378 pj_pool_t *pool,1379 pj_stun_msg **p_response);1380 1381 1382 1251 /** 1383 1252 * Dump STUN message to a printable string output. … … 1431 1300 * @return PJ_SUCCESS on success or the appropriate error code. 1432 1301 */ 1433 PJ_DECL(pj_status_t) 1434 pj_stun_generic_ip_addr_attr_create(pj_pool_t *pool, 1435 int attr_type, 1436 pj_bool_t xor_ed, 1437 const pj_sockaddr_t *addr, 1438 unsigned addr_len, 1439 pj_stun_generic_ip_addr_attr **p_attr); 1302 PJ_DECL(pj_status_t) pj_stun_ip_addr_attr_create(pj_pool_t *pool, 1303 int attr_type, 1304 pj_bool_t xor_ed, 1305 const pj_sockaddr_t *addr, 1306 unsigned addr_len, 1307 pj_stun_ip_addr_attr **p_attr); 1440 1308 1441 1309 … … 1455 1323 * @return PJ_SUCCESS on success or the appropriate error code. 1456 1324 */ 1457 PJ_DECL(pj_status_t) 1458 pj_stun_msg_add_generic_ip_addr_attr(pj_pool_t *pool, 1459 pj_stun_msg *msg, 1460 int attr_type, 1461 pj_bool_t xor_ed, 1462 const pj_sockaddr_t *addr, 1463 unsigned addr_len); 1325 PJ_DECL(pj_status_t) pj_stun_msg_add_ip_addr_attr(pj_pool_t *pool, 1326 pj_stun_msg *msg, 1327 int attr_type, 1328 pj_bool_t xor_ed, 1329 const pj_sockaddr_t *addr, 1330 unsigned addr_len); 1464 1331 1465 1332 /** … … 1473 1340 * @return PJ_SUCCESS on success or the appropriate error code. 1474 1341 */ 1475 PJ_DECL(pj_status_t) 1476 pj_stun_generic_string_attr_create(pj_pool_t *pool, 1477 int attr_type, 1478 const pj_str_t *value, 1479 pj_stun_generic_string_attr **p_attr); 1342 PJ_DECL(pj_status_t) pj_stun_string_attr_create(pj_pool_t *pool, 1343 int attr_type, 1344 const pj_str_t *value, 1345 pj_stun_string_attr **p_attr); 1480 1346 1481 1347 /** … … 1489 1355 * @return PJ_SUCCESS on success or the appropriate error code. 1490 1356 */ 1491 PJ_DECL(pj_status_t) 1492 pj_stun_msg_add_generic_string_attr(pj_pool_t *pool, 1493 pj_stun_msg *msg, 1494 int attr_type, 1495 const pj_str_t *value); 1357 PJ_DECL(pj_status_t) pj_stun_msg_add_string_attr(pj_pool_t *pool, 1358 pj_stun_msg *msg, 1359 int attr_type, 1360 const pj_str_t *value); 1496 1361 1497 1362 /** … … 1505 1370 * @return PJ_SUCCESS on success or the appropriate error code. 1506 1371 */ 1507 PJ_DECL(pj_status_t) 1508 pj_stun_generic_uint_attr_create(pj_pool_t *pool, 1509 int attr_type, 1510 pj_uint32_t value, 1511 pj_stun_generic_uint_attr **p_attr); 1372 PJ_DECL(pj_status_t) pj_stun_uint_attr_create(pj_pool_t *pool, 1373 int attr_type, 1374 pj_uint32_t value, 1375 pj_stun_uint_attr **p_attr); 1512 1376 1513 1377 /** … … 1521 1385 * @return PJ_SUCCESS on success or the appropriate error code. 1522 1386 */ 1523 PJ_DECL(pj_status_t) 1524 pj_stun_msg_add_generic_uint_attr(pj_pool_t *pool, 1525 pj_stun_msg *msg, 1526 int attr_type, 1527 pj_uint32_t value); 1387 PJ_DECL(pj_status_t) pj_stun_msg_add_uint_attr(pj_pool_t *pool, 1388 pj_stun_msg *msg, 1389 int attr_type, 1390 pj_uint32_t value); 1528 1391 1529 1392 … … 1536 1399 * @return PJ_SUCCESS on success or the appropriate error code. 1537 1400 */ 1538 PJ_DECL(pj_status_t) 1539 pj_stun_msg_integrity_attr_create(pj_pool_t *pool, 1540 pj_stun_msg_integrity_attr **p_attr); 1401 PJ_DECL(pj_status_t) pj_stun_msgint_attr_create(pj_pool_t *pool, 1402 pj_stun_msgint_attr **p_attr); 1403 1404 /** 1405 * Create and add STUN MESSAGE-INTEGRITY attribute. 1406 * 1407 * @param pool The pool to allocate memory from. 1408 * @param msg The STUN message 1409 * 1410 * @return PJ_SUCCESS on success or the appropriate error code. 1411 */ 1412 PJ_DECL(pj_status_t) pj_stun_msg_add_msgint_attr(pj_pool_t *pool, 1413 pj_stun_msg *msg); 1541 1414 1542 1415 /** … … 1551 1424 * @return PJ_SUCCESS on success or the appropriate error code. 1552 1425 */ 1553 PJ_DECL(pj_status_t) 1554 pj_stun_error_code_attr_create(pj_pool_t *pool, 1555 int err_code, 1556 const pj_str_t *err_reason, 1557 pj_stun_error_code_attr **p_attr); 1558 1426 PJ_DECL(pj_status_t) pj_stun_errcode_attr_create(pj_pool_t *pool, 1427 int err_code, 1428 const pj_str_t *err_reason, 1429 pj_stun_errcode_attr **p_attr); 1430 1431 1432 /** 1433 * Create and add STUN ERROR-CODE attribute to the message. 1434 * 1435 * @param pool The pool to allocate memory from. 1436 * @param msg The STUN mesage. 1437 * @param err_code STUN error code. 1438 * @param err_reason Optional STUN error reason. If NULL is given, the 1439 * standard error reason will be given. 1440 * 1441 * @return PJ_SUCCESS on success or the appropriate error code. 1442 */ 1443 PJ_DECL(pj_status_t) pj_stun_msg_add_errcode_attr(pj_pool_t *pool, 1444 pj_stun_msg *msg, 1445 int err_code, 1446 const pj_str_t *err_reason); 1559 1447 1560 1448 /** … … 1569 1457 * @return PJ_SUCCESS on success or the appropriate error code. 1570 1458 */ 1571 PJ_DECL(pj_status_t) 1572 pj_stun_unknown_attr_create(pj_pool_t *pool, 1573 unsigned attr_cnt, 1574 const pj_uint16_t attr[], 1575 pj_stun_unknown_attr **p_attr); 1459 PJ_DECL(pj_status_t) pj_stun_unknown_attr_create(pj_pool_t *pool, 1460 unsigned attr_cnt, 1461 const pj_uint16_t attr[], 1462 pj_stun_unknown_attr **p_attr); 1576 1463 1577 1464 /** … … 1585 1472 * @return PJ_SUCCESS on success or the appropriate error code. 1586 1473 */ 1587 PJ_DECL(pj_status_t) 1588 pj_stun_msg_add_unknown_attr(pj_pool_t *pool, 1589 pj_stun_msg *msg, 1590 unsigned attr_cnt, 1591 const pj_uint16_t attr[]); 1474 PJ_DECL(pj_status_t) pj_stun_msg_add_unknown_attr(pj_pool_t *pool, 1475 pj_stun_msg *msg, 1476 unsigned attr_cnt, 1477 const pj_uint16_t attr[]); 1592 1478 1593 1479 /** … … 1604 1490 * @return PJ_SUCCESS on success or the appropriate error code. 1605 1491 */ 1606 PJ_DECL(pj_status_t) 1607 pj_stun_binary_attr_create(pj_pool_t *pool, 1608 int attr_type, 1609 const pj_uint8_t *data, 1610 unsigned length, 1611 pj_stun_binary_attr **p_attr); 1492 PJ_DECL(pj_status_t) pj_stun_binary_attr_create(pj_pool_t *pool, 1493 int attr_type, 1494 const pj_uint8_t *data, 1495 unsigned length, 1496 pj_stun_binary_attr **p_attr); 1612 1497 1613 1498 /** … … 1625 1510 * @return PJ_SUCCESS on success or the appropriate error code. 1626 1511 */ 1627 PJ_DECL(pj_status_t) 1628 pj_stun_msg_add_binary_attr(pj_pool_t *pool, 1629 pj_stun_msg *msg, 1630 int attr_type, 1631 const pj_uint8_t *data, 1632 unsigned length); 1512 PJ_DECL(pj_status_t) pj_stun_msg_add_binary_attr(pj_pool_t *pool, 1513 pj_stun_msg *msg, 1514 int attr_type, 1515 const pj_uint8_t *data, 1516 unsigned length); 1633 1517 1634 1518
Note: See TracChangeset
for help on using the changeset viewer.