Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00037 #include <string.h>
00038 #include "../../dprint.h"
00039 #include "rerrno.h"
00040 #include "reg_mod.h"
00041 #include "common.h"
00042 #include "config.h"
00043
00044 #define MAX_AOR_LEN 256
00045
00049 int extract_aor(str* _uri, str* _a, sip_uri_t *_pu)
00050 {
00051 static char aor_buf[MAX_AOR_LEN];
00052 str tmp;
00053 sip_uri_t turi;
00054 sip_uri_t *puri;
00055 int user_len;
00056 str *uri;
00057 str realm_prefix;
00058
00059 memset(aor_buf, 0, MAX_AOR_LEN);
00060 uri=_uri;
00061
00062 if(_pu!=NULL)
00063 puri = _pu;
00064 else
00065 puri = &turi;
00066
00067 if (parse_uri(uri->s, uri->len, puri) < 0) {
00068 rerrno = R_AOR_PARSE;
00069 LM_ERR("failed to parse Address of Record\n");
00070 return -1;
00071 }
00072
00073 if ( (puri->user.len + puri->host.len + 1) > MAX_AOR_LEN
00074 || puri->user.len > USERNAME_MAX_SIZE
00075 || puri->host.len > DOMAIN_MAX_SIZE ) {
00076 rerrno = R_AOR_LEN;
00077 LM_ERR("Address Of Record too long\n");
00078 return -2;
00079 }
00080
00081 _a->s = aor_buf;
00082 _a->len = puri->user.len;
00083
00084 if (un_escape(&puri->user, _a) < 0) {
00085 rerrno = R_UNESCAPE;
00086 LM_ERR("failed to unescape username\n");
00087 return -3;
00088 }
00089
00090 user_len = _a->len;
00091
00092 if (reg_use_domain) {
00093 if (user_len)
00094 aor_buf[_a->len++] = '@';
00095
00096 realm_prefix.s = cfg_get(registrar, registrar_cfg, realm_pref).s;
00097 realm_prefix.len = cfg_get(registrar, registrar_cfg, realm_pref).len;
00098 if (realm_prefix.len && realm_prefix.len<puri->host.len &&
00099 (memcmp(realm_prefix.s, puri->host.s, realm_prefix.len)==0) ) {
00100 memcpy(aor_buf + _a->len, puri->host.s + realm_prefix.len,
00101 puri->host.len - realm_prefix.len);
00102 _a->len += puri->host.len - realm_prefix.len;
00103 } else {
00104 memcpy(aor_buf + _a->len, puri->host.s, puri->host.len);
00105 _a->len += puri->host.len;
00106 }
00107 }
00108
00109 if (cfg_get(registrar, registrar_cfg, case_sensitive) && user_len) {
00110 tmp.s = _a->s + user_len + 1;
00111 tmp.len = _a->s + _a->len - tmp.s;
00112 strlower(&tmp);
00113 } else {
00114 strlower(_a);
00115 }
00116
00117 return 0;
00118 }