registrar/common.c
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
00031
00032
00033
00034
00035
00036
00037 #include <string.h>
00038 #include "../../dprint.h"
00039 #include "../../parser/parse_uri.h"
00040 #include "rerrno.h"
00041 #include "reg_mod.h"
00042 #include "common.h"
00043
00044
00045 #define MAX_AOR_LEN 256
00046
00047
00048
00049
00050 int extract_aor(str* _uri, str* _a)
00051 {
00052 static char aor_buf[MAX_AOR_LEN];
00053 memset(aor_buf, 0, MAX_AOR_LEN);
00054
00055 str tmp;
00056 struct sip_uri puri;
00057 int user_len;
00058 int_str avp_val;
00059 struct usr_avp *avp;
00060 str *uri;
00061
00062 if (aor_avp_name.n!=0) {
00063 avp = search_first_avp( aor_avp_type, aor_avp_name, &avp_val, 0);
00064 if (avp && is_avp_str_val(avp)) {
00065 uri = &avp_val.s;
00066 } else {
00067 uri = _uri;
00068 }
00069 } else {
00070 uri=_uri;
00071 }
00072
00073 if (parse_uri(uri->s, uri->len, &puri) < 0) {
00074 rerrno = R_AOR_PARSE;
00075 LM_ERR("failed to parse Address of Record\n");
00076 return -1;
00077 }
00078
00079 if ( (puri.user.len + puri.host.len + 1) > MAX_AOR_LEN
00080 || puri.user.len > USERNAME_MAX_SIZE
00081 || puri.host.len > DOMAIN_MAX_SIZE ) {
00082 rerrno = R_AOR_LEN;
00083 LM_ERR("Address Of Record too long\n");
00084 return -2;
00085 }
00086
00087 _a->s = aor_buf;
00088 _a->len = puri.user.len;
00089
00090 if (un_escape(&puri.user, _a) < 0) {
00091 rerrno = R_UNESCAPE;
00092 LM_ERR("failed to unescape username\n");
00093 return -3;
00094 }
00095
00096 user_len = _a->len;
00097
00098 if (reg_use_domain) {
00099 if (user_len)
00100 aor_buf[_a->len++] = '@';
00101
00102 if (realm_prefix.len && realm_prefix.len<puri.host.len &&
00103 (memcmp(realm_prefix.s, puri.host.s, realm_prefix.len)==0) ) {
00104 memcpy(aor_buf + _a->len, puri.host.s + realm_prefix.len,
00105 puri.host.len - realm_prefix.len);
00106 _a->len += puri.host.len - realm_prefix.len;
00107 } else {
00108 memcpy(aor_buf + _a->len, puri.host.s, puri.host.len);
00109 _a->len += puri.host.len;
00110 }
00111 }
00112
00113 if (case_sensitive && user_len) {
00114 tmp.s = _a->s + user_len + 1;
00115 tmp.len = _a->s + _a->len - tmp.s;
00116 strlower(&tmp);
00117 } else {
00118 strlower(_a);
00119 }
00120
00121 return 0;
00122 }