📄 wap_push_pap_compiler.c
字号:
pos = drop_character(address, pos); } else return -2; } return pos;}static long drop_character(Octstr **address, long pos){ if (pos >= 0) { octstr_delete(*address, pos, 1); if (pos > 0) --pos; } return pos;}static long parse_type(Octstr **address, Octstr **type_value, long pos){ unsigned char c; while ((c = octstr_get_char(*address, pos)) != '=' && pos >= 0) { *type_value = prepend_char(*type_value, c); pos = drop_character(address, pos); } if (pos < 0) return -2; return pos;}static long parse_ext_qualifiers(Octstr **address, long pos, Octstr *type){ int ret; while ((ret = qualifiers(*address, pos, type)) == 1) { if ((pos = parse_qualifier_value(address, pos)) < 0) return pos; if ((pos = parse_qualifier_keyword(address, pos)) < 0) return pos; } if (ret == 1) { debug("wap.push.pap.compiler", 0, "PAP COMPILER: erroneous qualifiers" " in the client address"); return -2; } return pos;}/* * According to ppg, chapter 7.1, global phone number starts with +. Phone * number is here an unique identifier, so if it does not conform the inter- * national format, we return an error. (Is up to bearerbox to transform it * to an usable phone number) */static long parse_global_phone_number(Octstr **address, long pos){ unsigned char c; while ((c = octstr_get_char(*address, pos)) != '+' && pos >= 0) { if (!isdigit(c) && c != '-' && c != '.') { debug("wap.push.pap.compiler", 0, "PAP COMPILER: wrong separator" " in a phone number (- and . allowed)"); return -2; } else { --pos; } } if (pos == 0) { debug("wap.push.pap.compiler", 0, "PAP COMPILER:a phone number must" " start with +"); return -2; } if (pos > 0) --pos; pos = drop_character(address, pos); return pos;}static long parse_ipv4(Octstr **address, long pos){ long i; if ((pos = parse_ipv4_fragment(address, pos)) < 0) { debug("wap.push.pap.compiler", 0, "PAP COMPILER: wrong separator in a" " ipv4 address"); return -2; } i = 1; while (i <= 3 && octstr_get_char(*address, pos) != '=' && pos >= 0) { pos = parse_ipv4_fragment(address, pos); ++i; } if (pos == 0) { debug("wap.push.pap.compiler", 0, "PAP COMPILER: missing separator at" " beginning of a client address (=)"); return -2; } return pos;}static long parse_ipv6(Octstr **address, long pos){ long i; if ((pos = parse_ipv6_fragment(address, pos)) < 0) { debug("wap.push.pap.compiler", 0, "PAP COMPILER: wrong separator in a" " ipv6 address"); return -2; } i = 1; while (i <= 7 && octstr_get_char(*address, pos) != '=' && pos >= 0) { pos = parse_ipv6_fragment(address, pos); ++i; } if (pos == 0) { debug("wap.push.pap.compiler", 0, "PAP COMPILER: missing separator at" " beginning of a client address (=)"); return -2; } return pos;}/* * WINA web page does not include address type identifiers. Following ones are * from wdp, Appendix C. */static char *bearer_address[] = { "GSM_MSISDN", "ANSI_136_MSISDN", "IS_637_MSISDN", "iDEN_MSISDN", "FLEX_MSISDN", "PHS_MSISDN", "GSM_Service_Code", "TETRA_ITSI", "TETRA_MSISDN", "ReFLEX_MSIDDN", "MAN",};static size_t bearer_address_size = sizeof(bearer_address) / sizeof(bearer_address[0]);static int wina_bearer_identifier(Octstr *type_value){ size_t i; i = 0; while (i < bearer_address_size) { if (octstr_case_compare(type_value, octstr_imm(bearer_address[i])) == 0) return 1; ++i; } debug("wap.push.pap.compiler", 0, "PAP COMPILER: a bearer not registered" " by wina"); return 0;}/* * Note that we parse backwards. First we create a window of three characters * (representing a possible escaped character). If the first character of the * window is not escape, we handle the last character and move the window one * character backwards; if it is, we handle escaped sequence and create a new * window. If we cannot create a window, rest of characters are unescaped. */static long parse_escaped_value(Octstr **address, long pos){ int ret; if (create_peek_window(address, &pos) == 0) if ((pos = rest_unescaped(address, pos)) == -2) return -2; while (octstr_get_char(*address, pos) != '=' && pos >= 0) { if ((ret = issafe(address, pos)) == 1) { pos = accept_safe(address, pos); } else if (ret == 0) { if ((pos = accept_escaped(address, pos)) < 0) return -2; if (create_peek_window(address, &pos) == 0) if ((pos = rest_unescaped(address, pos)) == -2) return -2; } } pos = drop_character(address, pos); return pos;}static Octstr *prepend_char(Octstr *os, unsigned char c){ Octstr *tmp; tmp = octstr_format("%c", c); octstr_insert(os, tmp, 0); octstr_destroy(tmp); return os;}/* * Ext qualifiers contain /, ipv4 address contains . , ipv6 address contains :. * phone number contains + and escaped-value contain no specific tokens. Lastly * mentioned are for future extensions, but we must parse them. * Return 1, when qualifiers found * 0, when not * -1, when an error was found during the process */static int qualifiers(Octstr *address, long pos, Octstr *type){ unsigned char term, c; long i; i = pos; c = 'E'; if (octstr_case_compare(type, octstr_imm("PLMN")) == 0) term = '+'; else if (octstr_case_compare(type, octstr_imm("IPv4")) == 0) term = '.'; else if (octstr_case_compare(type, octstr_imm("IPv6")) == 0) term = ':'; else term = 'N'; if (term != 'N') { while ((c = octstr_get_char(address, i)) != term && i != 0) { if (c == '/') return 1; --i; } if (i == 0) return 0; } if (term == 'N') { while (i != 0) { if (c == '/') return 1; --i; } } return 0;}static long parse_qualifier_value(Octstr **address, long pos){ unsigned char c; while ((c = octstr_get_char(*address, pos)) != '=' && pos >= 0) { if (c < 0x20 || (c > 0x2e && c < 0x30) || (c > 0x3c && c < 0x3e) || c > 0x7e) return -2; pos = drop_character(address, pos); } pos = drop_character(address, pos); return pos;}static long parse_qualifier_keyword(Octstr **address, long pos){ unsigned char c; while ((c = octstr_get_char(*address, pos)) != '/') { if (isalnum(c) || c == '-') { pos = drop_character(address, pos); } else return -2; } pos = drop_character(address, pos); return pos;}static long parse_ipv4_fragment(Octstr **address, long pos){ long i; unsigned char c; i = 0; c = '='; if (isdigit(c = octstr_get_char(*address, pos)) && pos >= 0) { --pos; ++i; } else { debug("wap.push.pap.compiler", 0, "non-digit found in ip address," " address unacceptable"); return -2; } while (i <= 3 && ((c = octstr_get_char(*address, pos)) != '.' && c != '=') && pos >= 0) { if (isdigit(c)) { --pos; ++i; } else { debug("wap.push.pap.compiler", 0, "parse_ipv4_fragment: non-digit" " in ipv4 address, address unacceptable"); return -2; } } pos = handle_two_terminators(address, pos, '.', '=', c, i, 3); return pos;}static long parse_ipv6_fragment(Octstr **address, long pos){ long i; unsigned char c; i = 0; if (isxdigit(octstr_get_char(*address, pos)) && pos >= 0) { --pos; ++i; } else { return -2; } c = '='; while (i <= 4 && ((c = octstr_get_char(*address, pos)) != ':' && c != '=') && pos >= 0) { if (isxdigit(c)) { --pos; ++i; } else { return -2; } } pos = handle_two_terminators(address, pos, ':', '=', c, i, 4); return pos;}/* * Return -1, it was impossible to create the window because of there is no * more enough characters left and 0 if OK. */static int create_peek_window(Octstr **address, long *pos){ long i; unsigned char c; i = 0; c = '='; while (i < 2 && (c = octstr_get_char(*address, *pos)) != '=') { if (*pos > 0) --*pos; ++i; } if (c == '=') return 0; return 1; }static long rest_unescaped(Octstr **address, long pos){ long i, ret; for (i = 2; i > 0; i--) { if ((ret = accept_safe(address, pos)) == -2) return -2; else if (ret == -1) return pos; } return pos;}static int issafe(Octstr **address, long pos){ if (octstr_get_char(*address, pos) == '%') return 0; else return 1;}static long accept_safe(Octstr **address, long pos){ unsigned char c; c = octstr_get_char(*address, pos); if ((isalnum(c) || c == '+' || c == '-' || c == '.' || c == '_') && pos >= 0) --pos; else if (c == '=') return -1; else retu
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -