Changeset 43 for pjproject/main/pjsip/src/pjsip/sip_auth_parser.c
- Timestamp:
- Nov 11, 2005 7:01:31 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/main/pjsip/src/pjsip/sip_auth_parser.c
- Property svn:keywords set to Id
r3 r43 1 1 /* $Id$ 2 *3 2 */ 4 3 #include <pjsip/sip_auth_parser.h> 5 4 #include <pjsip/sip_auth_msg.h> 6 5 #include <pjsip/sip_parser.h> 6 #include <pj/assert.h> 7 7 #include <pj/string.h> 8 8 #include <pj/except.h> 9 9 10 static pjsip_authorization_hdr* parse_hdr_authorization( pj_scanner *scanner, pj_pool_t *pool); 11 static pjsip_proxy_authorization_hdr* parse_hdr_proxy_authorization( pj_scanner *scanner, pj_pool_t *pool); 12 static pjsip_www_authenticate_hdr* parse_hdr_www_authenticate( pj_scanner *scanner, pj_pool_t *pool); 13 static pjsip_proxy_authenticate_hdr* parse_hdr_proxy_authenticate( pj_scanner *scanner, pj_pool_t *pool); 14 15 static void parse_digest_credential( pj_scanner *scanner, pj_pool_t *pool, pjsip_digest_credential *cred); 16 static void parse_pgp_credential( pj_scanner *scanner, pj_pool_t *pool, pjsip_pgp_credential *cred); 17 static void parse_digest_challenge( pj_scanner *scanner, pj_pool_t *pool, pjsip_digest_challenge *chal); 18 static void parse_pgp_challenge( pj_scanner *scanner, pj_pool_t *pool, pjsip_pgp_challenge *chal); 10 static pjsip_hdr* parse_hdr_authorization ( pjsip_parse_ctx *ctx ); 11 static pjsip_hdr* parse_hdr_proxy_authorization ( pjsip_parse_ctx *ctx ); 12 static pjsip_hdr* parse_hdr_www_authenticate ( pjsip_parse_ctx *ctx ); 13 static pjsip_hdr* parse_hdr_proxy_authenticate ( pjsip_parse_ctx *ctx ); 14 15 static void parse_digest_credential ( pj_scanner *scanner, pj_pool_t *pool, 16 pjsip_digest_credential *cred); 17 static void parse_pgp_credential ( pj_scanner *scanner, pj_pool_t *pool, 18 pjsip_pgp_credential *cred); 19 static void parse_digest_challenge ( pj_scanner *scanner, pj_pool_t *pool, 20 pjsip_digest_challenge *chal); 21 static void parse_pgp_challenge ( pj_scanner *scanner, pj_pool_t *pool, 22 pjsip_pgp_challenge *chal); 19 23 20 24 const pj_str_t pjsip_USERNAME_STR = { "username", 8 }, … … 44 48 45 49 46 static void parse_digest_credential( pj_scanner *scanner, pj_pool_t *pool, pjsip_digest_credential *cred) 50 static void parse_digest_credential( pj_scanner *scanner, pj_pool_t *pool, 51 pjsip_digest_credential *cred) 47 52 { 48 53 for (;;) { 49 54 pj_str_t name, value; 50 55 51 pjsip_parse_param_imp(scanner, &name, &value, 56 pjsip_parse_param_imp(scanner, &name, &value,PJSIP_PARSE_REMOVE_QUOTE); 52 57 53 58 if (!pj_stricmp(&name, &pjsip_USERNAME_STR)) { … … 82 87 83 88 } else { 84 pjsip_concat_param_imp(&cred->other_param, pool, &name,&value, ',');89 pjsip_concat_param_imp(&cred->other_param,pool,&name,&value, ','); 85 90 } 86 91 87 92 /* Eat comma */ 88 if (!pj_scan_is_eof(scanner) && *scanner->cur rent== ',')93 if (!pj_scan_is_eof(scanner) && *scanner->curptr == ',') 89 94 pj_scan_get_char(scanner); 90 95 else … … 93 98 } 94 99 95 static void parse_pgp_credential( pj_scanner *scanner, pj_pool_t *pool, pjsip_pgp_credential *cred) 96 { 97 PJ_UNUSED_ARG(scanner) 98 PJ_UNUSED_ARG(pool) 99 PJ_UNUSED_ARG(cred) 100 static void parse_pgp_credential( pj_scanner *scanner, pj_pool_t *pool, 101 pjsip_pgp_credential *cred) 102 { 103 PJ_UNUSED_ARG(scanner); 104 PJ_UNUSED_ARG(pool); 105 PJ_UNUSED_ARG(cred); 100 106 101 107 PJ_THROW(PJSIP_SYN_ERR_EXCEPTION); 102 108 } 103 109 104 static void parse_digest_challenge( pj_scanner *scanner, pj_pool_t *pool, pjsip_digest_challenge *chal) 110 static void parse_digest_challenge( pj_scanner *scanner, pj_pool_t *pool, 111 pjsip_digest_challenge *chal) 105 112 { 106 113 for (;;) { 107 114 pj_str_t name, value; 108 115 109 pjsip_parse_param_imp(scanner, &name, &value, 116 pjsip_parse_param_imp(scanner, &name, &value,PJSIP_PARSE_REMOVE_QUOTE); 110 117 111 118 if (!pj_stricmp(&name, &pjsip_REALM_STR)) { … … 122 129 123 130 } else if (!pj_stricmp(&name, &pjsip_STALE_STR)) { 124 if (!pj_stricmp(&value, &pjsip_TRUE_STR) || !pj_stricmp(&value, &pjsip_QUOTED_TRUE_STR)) 131 if (!pj_stricmp(&value, &pjsip_TRUE_STR) || 132 !pj_stricmp(&value, &pjsip_QUOTED_TRUE_STR)) 133 { 125 134 chal->stale = 1; 135 } 126 136 127 137 } else if (!pj_stricmp(&name, &pjsip_ALGORITHM_STR)) { … … 133 143 134 144 } else { 135 pjsip_concat_param_imp(&chal->other_param, pool, &name, &value, ','); 145 pjsip_concat_param_imp(&chal->other_param, pool, 146 &name, &value, ','); 136 147 } 137 148 138 149 /* Eat comma */ 139 if (!pj_scan_is_eof(scanner) && *scanner->cur rent== ',')150 if (!pj_scan_is_eof(scanner) && *scanner->curptr == ',') 140 151 pj_scan_get_char(scanner); 141 152 else … … 144 155 } 145 156 146 static void parse_pgp_challenge( pj_scanner *scanner, pj_pool_t *pool, pjsip_pgp_challenge *chal) 147 { 148 PJ_UNUSED_ARG(scanner) 149 PJ_UNUSED_ARG(pool) 150 PJ_UNUSED_ARG(chal) 157 static void parse_pgp_challenge( pj_scanner *scanner, pj_pool_t *pool, 158 pjsip_pgp_challenge *chal) 159 { 160 PJ_UNUSED_ARG(scanner); 161 PJ_UNUSED_ARG(pool); 162 PJ_UNUSED_ARG(chal); 151 163 152 164 PJ_THROW(PJSIP_SYN_ERR_EXCEPTION); 153 165 } 154 166 155 static void int_parse_hdr_authorization( pj_scanner *scanner, pj_pool_t *pool, 167 static void int_parse_hdr_authorization( pj_scanner *scanner, pj_pool_t *pool, 156 168 pjsip_authorization_hdr *hdr) 157 169 { 158 if (*scanner->cur rent== '"') {170 if (*scanner->curptr == '"') { 159 171 pj_scan_get_quote(scanner, '"', '"', &hdr->scheme); 160 172 hdr->scheme.ptr++; 161 173 hdr->scheme.slen -= 2; 162 174 } else { 163 pj_scan_get(scanner, pjsip_TOKEN_SPEC, &hdr->scheme);175 pj_scan_get(scanner, &pjsip_TOKEN_SPEC, &hdr->scheme); 164 176 } 165 177 … … 182 194 pjsip_www_authenticate_hdr *hdr) 183 195 { 184 if (*scanner->cur rent== '"') {196 if (*scanner->curptr == '"') { 185 197 pj_scan_get_quote(scanner, '"', '"', &hdr->scheme); 186 198 hdr->scheme.ptr++; 187 199 hdr->scheme.slen -= 2; 188 200 } else { 189 pj_scan_get(scanner, pjsip_TOKEN_SPEC, &hdr->scheme);201 pj_scan_get(scanner, &pjsip_TOKEN_SPEC, &hdr->scheme); 190 202 } 191 203 … … 206 218 207 219 208 static pjsip_authorization_hdr *parse_hdr_authorization( pj_scanner *scanner, pj_pool_t *pool) 209 { 210 pjsip_authorization_hdr *hdr = pjsip_authorization_hdr_create(pool); 211 int_parse_hdr_authorization(scanner, pool, hdr); 212 return hdr; 213 } 214 215 static pjsip_proxy_authorization_hdr *parse_hdr_proxy_authorization( pj_scanner *scanner, pj_pool_t *pool) 216 { 217 pjsip_proxy_authorization_hdr *hdr = pjsip_proxy_authorization_hdr_create(pool); 218 int_parse_hdr_authorization(scanner, pool, hdr); 219 return hdr; 220 } 221 222 static pjsip_www_authenticate_hdr *parse_hdr_www_authenticate( pj_scanner *scanner, pj_pool_t *pool) 223 { 224 pjsip_www_authenticate_hdr *hdr = pjsip_www_authenticate_hdr_create(pool); 225 int_parse_hdr_authenticate(scanner, pool, hdr); 226 return hdr; 227 } 228 229 static pjsip_proxy_authenticate_hdr *parse_hdr_proxy_authenticate( pj_scanner *scanner, pj_pool_t *pool) 230 { 231 pjsip_proxy_authenticate_hdr *hdr = pjsip_proxy_authenticate_hdr_create(pool); 232 int_parse_hdr_authenticate(scanner, pool, hdr); 233 return hdr; 234 } 235 236 237 PJ_DEF(void) pjsip_auth_init_parser() 238 { 239 pjsip_register_hdr_parser( "Authorization", NULL, (pjsip_parse_hdr_func*) &parse_hdr_authorization); 240 pjsip_register_hdr_parser( "Proxy-Authorization", NULL, (pjsip_parse_hdr_func*) &parse_hdr_proxy_authorization); 241 pjsip_register_hdr_parser( "WWW-Authenticate", NULL, (pjsip_parse_hdr_func*) &parse_hdr_www_authenticate); 242 pjsip_register_hdr_parser( "Proxy-Authenticate", NULL, (pjsip_parse_hdr_func*) &parse_hdr_proxy_authenticate); 220 static pjsip_hdr* parse_hdr_authorization( pjsip_parse_ctx *ctx ) 221 { 222 pjsip_authorization_hdr *hdr = pjsip_authorization_hdr_create(ctx->pool); 223 int_parse_hdr_authorization(ctx->scanner, ctx->pool, hdr); 224 return (pjsip_hdr*)hdr; 225 } 226 227 static pjsip_hdr* parse_hdr_proxy_authorization( pjsip_parse_ctx *ctx ) 228 { 229 pjsip_proxy_authorization_hdr *hdr = 230 pjsip_proxy_authorization_hdr_create(ctx->pool); 231 int_parse_hdr_authorization(ctx->scanner, ctx->pool, hdr); 232 return (pjsip_hdr*)hdr; 233 } 234 235 static pjsip_hdr* parse_hdr_www_authenticate( pjsip_parse_ctx *ctx ) 236 { 237 pjsip_www_authenticate_hdr *hdr = 238 pjsip_www_authenticate_hdr_create(ctx->pool); 239 int_parse_hdr_authenticate(ctx->scanner, ctx->pool, hdr); 240 return (pjsip_hdr*)hdr; 241 } 242 243 static pjsip_hdr* parse_hdr_proxy_authenticate( pjsip_parse_ctx *ctx ) 244 { 245 pjsip_proxy_authenticate_hdr *hdr = 246 pjsip_proxy_authenticate_hdr_create(ctx->pool); 247 int_parse_hdr_authenticate(ctx->scanner, ctx->pool, hdr); 248 return (pjsip_hdr*)hdr; 249 } 250 251 252 PJ_DEF(pj_status_t) pjsip_auth_init_parser() 253 { 254 pj_status_t status; 255 256 status = pjsip_register_hdr_parser( "Authorization", NULL, 257 &parse_hdr_authorization); 258 PJ_ASSERT_RETURN(status==PJ_SUCCESS, status); 259 status = pjsip_register_hdr_parser( "Proxy-Authorization", NULL, 260 &parse_hdr_proxy_authorization); 261 PJ_ASSERT_RETURN(status==PJ_SUCCESS, status); 262 status = pjsip_register_hdr_parser( "WWW-Authenticate", NULL, 263 &parse_hdr_www_authenticate); 264 PJ_ASSERT_RETURN(status==PJ_SUCCESS, status); 265 status = pjsip_register_hdr_parser( "Proxy-Authenticate", NULL, 266 &parse_hdr_proxy_authenticate); 267 PJ_ASSERT_RETURN(status==PJ_SUCCESS, status); 268 269 return PJ_SUCCESS; 243 270 } 244 271
Note: See TracChangeset
for help on using the changeset viewer.