Browse code

- New module interface - Warning fixed

Jan Janak authored on 11/03/2003 15:22:48
Showing 2 changed files
... ...
@@ -45,7 +45,7 @@
45 45
 
46 46
 
47 47
 /*
48
- * Extract username from Request-URI
48
+ * Get Request-URI
49 49
  */
50 50
 static inline int get_request_uri(struct sip_msg* _m, str* _u)
51 51
 {
... ...
@@ -62,7 +62,7 @@ static inline int get_request_uri(struct sip_msg* _m, str* _u)
62 62
 
63 63
 
64 64
 /*
65
- * Extract username from To header field
65
+ * Get To header field URI
66 66
  */
67 67
 static inline int get_to_uri(struct sip_msg* _m, str* _u)
68 68
 {
... ...
@@ -79,7 +79,7 @@ static inline int get_to_uri(struct sip_msg* _m, str* _u)
79 79
 
80 80
 
81 81
 /*
82
- * Extract username from From header field
82
+ * Get From header field URI
83 83
  */
84 84
 static inline int get_from_uri(struct sip_msg* _m, str* _u)
85 85
 {
... ...
@@ -95,32 +95,6 @@ static inline int get_from_uri(struct sip_msg* _m, str* _u)
95 95
 }
96 96
 
97 97
 
98
-/*
99
- * Extract username from digest credentials
100
- */
101
-static inline int get_cred_user(struct sip_msg* _m, str* _u)
102
-{
103
-	struct hdr_field* h;
104
-	auth_body_t* c;
105
-	
106
-	get_authorized_cred(_m->authorization, &h);
107
-	if (!h) {
108
-		get_authorized_cred(_m->proxy_auth, &h);
109
-		if (!h) {
110
-			LOG(L_ERR, "get_cred_user(): No authorized credentials found (error in scripts)\n");
111
-			return -1;
112
-		}
113
-	}
114
-	
115
-	c = (auth_body_t*)(h->parsed);
116
-
117
-	_u->s = c->digest.username.whole.s;
118
-	_u->len = c->digest.username.whole.len;
119
-
120
-	return 0;
121
-}
122
-
123
-
124 98
 /*
125 99
  * Check if username in specified header field is in a table
126 100
  */
... ...
@@ -130,9 +104,11 @@ int is_user_in(struct sip_msg* _msg, char* _hf, char* _grp)
130 104
 	db_val_t vals[3];
131 105
 	db_key_t col[1] = {group_column};
132 106
 	db_res_t* res;
133
-	str uri, user;
107
+	str uri;
134 108
 	int hf_type;
135 109
 	struct sip_uri puri;
110
+	struct hdr_field* h;
111
+	struct auth_body* c = 0; /* Makes gcc happy */
136 112
 	
137 113
 	hf_type = (int)_hf;
138 114
 
... ...
@@ -159,10 +135,16 @@ int is_user_in(struct sip_msg* _msg, char* _hf, char* _grp)
159 135
 		break;
160 136
 
161 137
 	case 4: /* Credentials */
162
-		if (get_cred_user(_msg, &user) < 0) {
163
-			LOG(L_ERR, "is_user_in(): Error while extracting digest username\n");
164
-			return -4;
138
+		get_authorized_cred(_msg->authorization, &h);
139
+		if (!h) {
140
+			get_authorized_cred(_msg->proxy_auth, &h);
141
+			if (!h) {
142
+				LOG(L_ERR, "is_user_in(): No authorized credentials found (error in scripts)\n");
143
+				return -1;
144
+			}
165 145
 		}
146
+	
147
+		c = (auth_body_t*)(h->parsed);
166 148
 		break;
167 149
 	}
168 150
 
... ...
@@ -172,24 +154,20 @@ int is_user_in(struct sip_msg* _msg, char* _hf, char* _grp)
172 154
 			return -5;
173 155
 		}
174 156
 
175
-		if (use_domain) {
176
-			VAL_TYPE(vals + 2) = DB_STR;
177
-			VAL_NULL(vals + 2) = 0;
178
-			VAL_STR(vals + 2) = puri.host;
179
-		}
180
-
181 157
 		VAL_STR(vals) = puri.user;
158
+		VAL_STR(vals + 2) = puri.host;
182 159
 	} else {
183
-		VAL_STR(vals) = user;
160
+		VAL_STR(vals) = c->digest.username.user;
161
+		VAL_STR(vals + 2) = (c->digest.username.domain.len) ? (c->digest.username.domain) : (c->digest.realm);
184 162
 	}
185 163
 	
186
-	VAL_TYPE(vals) = VAL_TYPE(vals + 1) = DB_STR;
187
-	VAL_NULL(vals) = VAL_NULL(vals + 1) = 0;
164
+	VAL_TYPE(vals) = VAL_TYPE(vals + 1) = VAL_TYPE(vals + 2) = DB_STR;
165
+	VAL_NULL(vals) = VAL_NULL(vals + 1) = VAL_NULL(vals + 2) = 0;
188 166
 
189 167
 	VAL_STR(vals + 1) = *((str*)_grp);
190 168
 	
191 169
 	db_use_table(db_handle, table);
192
-	if (db_query(db_handle, keys, 0, vals, col, (use_domain && (hf_type != 4)) ? (3): (2), 1, 0, &res) < 0) {
170
+	if (db_query(db_handle, keys, 0, vals, col, (use_domain) ? (3): (2), 1, 0, &res) < 0) {
193 171
 		LOG(L_ERR, "is_user_in(): Error while querying database\n");
194 172
 		return -5;
195 173
 	}
... ...
@@ -29,6 +29,7 @@
29 29
  * History:
30 30
  * --------
31 31
  * 2003-02-25 - created by janakj
32
+ * 2003-03-11 - New module interface (janakj)
32 33
  */
33 34
 
34 35
 
... ...
@@ -80,52 +81,40 @@ int   use_domain   = 0;
80 81
 db_con_t* db_handle = 0;   /* Database connection handle */
81 82
 
82 83
 
84
+/*
85
+ * Exported functions
86
+ */
87
+static cmd_export_t cmds[] = {
88
+	{"is_user_in", is_user_in, 2, hf_fixup},
89
+	{0, 0, 0, 0}
90
+};
91
+
92
+
93
+/*
94
+ * Exported parameters
95
+ */
96
+static param_export_t params[] = {
97
+	{"db_url",        STR_PARAM, &db_url       },
98
+	{"table",         STR_PARAM, &table        },
99
+	{"user_column",   STR_PARAM, &user_column  },
100
+	{"domain_column", STR_PARAM, &domain_column},
101
+	{"group_column",  STR_PARAM, &group_column },
102
+	{"use_domain",    INT_PARAM, &use_domain   },
103
+	{0, 0, 0}
104
+};
105
+
106
+
83 107
 /*
84 108
  * Module interface
85 109
  */
86 110
 struct module_exports exports = {
87 111
 	"group", 
88
-	(char*[]) { 
89
-		"is_user_in"
90
-	},
91
-	(cmd_function[]) {
92
-		is_user_in
93
-	},
94
-	(int[]) {2},
95
-	(fixup_function[]) {
96
-		hf_fixup
97
-	},
98
-	1,
99
-	
100
-	(char*[]) {
101
-		"db_url",              /* Database URL */
102
-		"table",               /* Group table name */
103
-		"user_column",         /* Group table user column name */
104
-		"domain_column",       /* Group table domain column name */
105
-		"group_column",        /* Group table group column name */
106
-		"use_domain"   
107
-	},   /* Module parameter names */
108
-	(modparam_t[]) {
109
-		STR_PARAM,
110
-		STR_PARAM,
111
-		STR_PARAM,
112
-		STR_PARAM,
113
-		STR_PARAM,
114
-	        INT_PARAM
115
-	},   /* Module parameter types */
116
-	(void*[]) {
117
-		&db_url,
118
-		&table,
119
-		&user_column,
120
-		&domain_column,
121
-		&group_column,
122
-		&use_domain
123
-	},   /* Module parameter variable pointers */
124
-	6,
112
+	cmds,       /* Exported functions */
113
+	params,     /* Exported parameters */
125 114
 	mod_init,   /* module initialization function */
126
-	NULL,       /* response function */
115
+	0,          /* response function */
127 116
 	destroy,    /* destroy function */
128
-	0,       /* oncancel function */
117
+	0,          /* oncancel function */
129 118
 	child_init  /* child initialization function */
130 119
 };
131 120