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