Definition in file auth_api.h.
#include "../../parser/msg_parser.h"
#include "../../parser/hf.h"
#include "../../str.h"
Go to the source code of this file.
Functions | |
| int | find_credentials (struct sip_msg *_m, str *_realm, hdr_types_t _hftype, struct hdr_field **_h) |
| Find credentials with given realm in a SIP message header. | |
| int find_credentials | ( | struct sip_msg * | _m, | |
| str * | _realm, | |||
| hdr_types_t | _hftype, | |||
| struct hdr_field ** | _h | |||
| ) | [inline] |
Find credentials with given realm in a SIP message header.
| _m | - the SIP message to look into | |
| _realm | - the realm to match in the authorization header | |
| _hftype | - the header type (HDR_AUTHORIZATION_T,HDR_PROXYAUTH_T) | |
| _h | - header pointer to fill with the match |
Definition at line 59 of file auth_api.c.
00061 { 00062 struct hdr_field** hook, *ptr, *prev; 00063 hdr_flags_t hdr_flags; 00064 int res; 00065 str* r; 00066 00067 /* 00068 * Determine if we should use WWW-Authorization or 00069 * Proxy-Authorization header fields, this parameter 00070 * is set in www_authorize and proxy_authorize 00071 */ 00072 switch(_hftype) { 00073 case HDR_AUTHORIZATION_T: 00074 hook = &(_m->authorization); 00075 hdr_flags=HDR_AUTHORIZATION_F; 00076 break; 00077 case HDR_PROXYAUTH_T: 00078 hook = &(_m->proxy_auth); 00079 hdr_flags=HDR_PROXYAUTH_F; 00080 break; 00081 default: 00082 hook = &(_m->authorization); 00083 hdr_flags=HDR_T2F(_hftype); 00084 break; 00085 } 00086 00087 /* 00088 * If the credentials haven't been parsed yet, do it now 00089 */ 00090 if (*hook == 0) { 00091 /* No credentials parsed yet */ 00092 if (parse_headers(_m, hdr_flags, 0) == -1) { 00093 LOG(L_ERR, "find_credentials(): Error while parsing headers\n"); 00094 return -1; 00095 } 00096 } 00097 00098 ptr = *hook; 00099 00100 /* 00101 * Iterate through the credentials in the message and 00102 * find credentials with given realm 00103 */ 00104 while(ptr) { 00105 res = parse_credentials(ptr); 00106 00107 if (res < 0) { 00108 LOG(L_ERR, "find_credentials(): Error while parsing credentials [%d]\n",res); 00109 return (res == -1) ? -2 : -3; 00110 } else if (res == 0) { 00111 if (_realm->len) { 00112 r = &(((auth_body_t*)(ptr->parsed))->digest.realm); 00113 00114 if (r->len == _realm->len) { 00115 if (!strncasecmp(_realm->s, r->s, r->len)) { 00116 *_h = ptr; 00117 return 0; 00118 } 00119 } 00120 } 00121 else { 00122 *_h = ptr; 00123 return 0; 00124 } 00125 00126 } 00127 00128 prev = ptr; 00129 if (parse_headers(_m, hdr_flags, 1) == -1) { 00130 LOG(L_ERR, "find_credentials(): Error while parsing headers\n"); 00131 return -4; 00132 } else { 00133 if (prev != _m->last_header) { 00134 if (_m->last_header->type == _hftype) ptr = _m->last_header; 00135 else break; 00136 } else break; 00137 } 00138 } 00139 00140 /* 00141 * Credentials with given realm not found 00142 */ 00143 return 1; 00144 }
1.5.2