Browse code

grand acc cleanup: all (core, tm, acc, serweb) but radius intergrated

Jiri Kuthan authored on 04/04/2003 03:21:58
Showing 11 changed files
... ...
@@ -43,13 +43,19 @@ New features
43 43
 Changes to use of ser scripts
44 44
 =============================
45 45
 
46
+
46 47
 core
47 48
 ----
48 49
 XXX TCP
49 50
 
50 51
 acc module:
51 52
 -----------
52
-XXX
53
+- radius and sql support integrated in this module; you need to
54
+  recompile to enable it
55
+- acc_flag is now called log_flag to better reflect it relates
56
+  to the syslog mode (as opposed to sql/radius); for the same
57
+  reasons, the accounting action is now called "acc_log_request"
58
+- log_fmt allows now to specify what will be printed to syslog
53 59
 
54 60
 auth module:
55 61
 ------------
... ...
@@ -24,6 +24,10 @@
24 24
  * You should have received a copy of the GNU General Public License 
25 25
  * along with this program; if not, write to the Free Software 
26 26
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
27
+ *
28
+ * History:
29
+ * --------
30
+ * 2003-04-04 phrase length corrected not to include trailer 0 (jiri)
27 31
  */
28 32
 
29 33
 
... ...
@@ -185,8 +189,8 @@ void get_reply_status( str *status, struct sip_msg *reply, int code )
185 189
 	} else {
186 190
 		phrase=reply->first_line.u.reply.reason;
187 191
 	}
188
-	status->len=phrase.len+3/*code*/+1/*space*/+1/*ZT*/;
189
-	status->s=pkg_malloc(status->len);
192
+	status->len=phrase.len+3/*code*/+1/*space*/; 
193
+	status->s=pkg_malloc(status->len+1/*ZT */);
190 194
 	if (!status->s) {
191 195
 		LOG(L_ERR, "ERROR: get_reply_status: no mem\n");
192 196
 		return;
... ...
@@ -196,5 +200,5 @@ void get_reply_status( str *status, struct sip_msg *reply, int code )
196 200
 	status->s[1]='0'+code% 10; code=code/10;
197 201
 	status->s[0]='0'+code % 10;
198 202
 	memcpy(&status->s[4], phrase.s, phrase.len);
199
-	status->s[status->len-1]=0;
203
+	status->s[status->len]=0;
200 204
 }
... ...
@@ -26,11 +26,13 @@
26 26
  *
27 27
  * History
28 28
  * -------
29
- * 2003-03-30  set_kr for requests only (jiri)
30
- * 2003-03-16  removed _TOTAG (jiri)
31 29
  * 2003-03-06  200/INV to-tag list deallocation added;
32 30
  *             setting "kill_reason" moved in here -- it is moved
33 31
  *             from transaction state to a static var(jiri)
32
+ * 2003-03-16  removed _TOTAG (jiri)
33
+ * 2003-03-30  set_kr for requests only (jiri)
34
+ * 2003-04-04  bug_fix: REQ_IN callback not called for local 
35
+ *             UAC transactions (jiri)
34 36
  */
35 37
 
36 38
 #include "defs.h"
... ...
@@ -182,8 +184,11 @@ struct cell*  build_cell( struct sip_msg* p_msg )
182 184
 	/*fprintf(stderr,"before clone VIA |%.*s|\n",via_len(p_msg->via1),
183 185
 		via_s(p_msg->via1,p_msg));*/
184 186
 
185
-	callback_event(TMCB_REQUEST_IN, new_cell, p_msg, 
186
-			p_msg ? p_msg->REQ_METHOD : METHOD_UNDEF );
187
+	/* enter callback, which may potentially want to parse some stuff,
188
+	   before the request is shmem-ized
189
+	*/ 
190
+    if (p_msg) callback_event(TMCB_REQUEST_IN, new_cell, p_msg,
191
+            p_msg->REQ_METHOD );
187 192
 
188 193
 	if (p_msg) {
189 194
 		new_cell->uas.request = sip_msg_cloner(p_msg);
... ...
@@ -37,11 +37,12 @@
37 37
  *
38 38
  * History:
39 39
  * --------
40
- *  2003-02-28  scratchpad compatibility abandoned (jiri)
41
- *  2003-02-25 - auth_body cloner added (janakj)
42
- *  2003-01-29 - scratchpad removed (jiri)
43 40
  *  2003-01-23 - msg_cloner clones msg->from->parsed too (janakj)
41
+ *  2003-01-29 - scratchpad removed (jiri)
42
+ *  2003-02-25 - auth_body cloner added (janakj)
43
+ *  2003-02-28  scratchpad compatibility abandoned (jiri)
44 44
  *  2003-03-31  removed msg->repl_add_rm (andrei)
45
+ *  2003-04-04  parsed uris are recalculated on cloning (jiri)
45 46
  */
46 47
 
47 48
 #include "defs.h"
... ...
@@ -157,6 +158,16 @@ inline struct via_body* via_body_cloner( char* new_buf,
157 158
 	return first_via;
158 159
 }
159 160
 
161
+static void uri_trans(char *new_buf, char *org_buf, struct sip_uri *uri)
162
+{
163
+	uri->user.s=translate_pointer(new_buf,org_buf,uri->user.s);
164
+	uri->passwd.s=translate_pointer(new_buf,org_buf,uri->passwd.s);
165
+	uri->host.s=translate_pointer(new_buf,org_buf,uri->host.s);
166
+	uri->port.s=translate_pointer(new_buf,org_buf,uri->port.s);
167
+	uri->params.s=translate_pointer(new_buf,org_buf,uri->params.s);
168
+	uri->headers.s=translate_pointer(new_buf,org_buf,uri->headers.s);
169
+}
170
+
160 171
 
161 172
 static inline struct auth_body* auth_body_cloner(char* new_buf, char *org_buf, struct auth_body *auth, char **p)
162 173
 {
... ...
@@ -365,6 +376,8 @@ struct sip_msg*  sip_msg_cloner( struct sip_msg *org_msg )
365 376
 		new_msg->first_line.u.request.version.s =
366 377
 			translate_pointer( new_msg->buf , org_msg->buf ,
367 378
 			org_msg->first_line.u.request.version.s );
379
+		uri_trans(new_msg->buf, org_msg->buf, &new_msg->parsed_orig_ruri);
380
+		uri_trans(new_msg->buf, org_msg->buf, &new_msg->parsed_uri);
368 381
 	}
369 382
 	else if ( org_msg->first_line.type==SIP_REPLY )
370 383
 	{
... ...
@@ -73,7 +73,10 @@ typedef enum {
73 73
  * lives in pkg mem -- your last chance to mangle it before
74 74
  * it gets shmem-ized (then, it's read-only); it's called from
75 75
  * HASH_LOCK, so be careful. It is guaranteed not to be
76
- * a retransmission.
76
+ * a retransmission. The transactional context is mostly
77
+ * incomplete -- this callback is called in very early stage
78
+ * before the message is shmem-ized (so that you can work
79
+ * with it).
77 80
  *
78 81
  * TMCB_RESPONSE_IN -- a brand-new reply was received which matches
79 82
  * an existing transaction. It may or may not be a retranmisssion.
... ...
@@ -51,20 +51,22 @@
51 51
  *
52 52
  * History:
53 53
  * ----------
54
- * 2003-03-30  set_kr for requests only (jiri)
55
- * 2003-03-29  optimization: e2e ACK matching only if callback installed
56
- *             (jiri)
57
- * 2003-03-06  dialog matching introduced for ACKs -- that's important for 
58
- *             INVITE UAS (like INVITE) and 200/ACK proxy matching (jiri)
59
- * 2003-03-01  kr set through a function now (jiri)
60
- * 2003-02-28 scratchpad compatibility abandoned (jiri)
61
- * 2003-02-27  3261 ACK/200 consumption bug removed (jiri)
62
- * 2003-02-24  s/T_NULL/T_NULL_CELL/ to avoid redefinition conflict w/
63
- * 2003-02-13  init_rb() is proto indep. & it uses struct dest_info (andrei)
64
- * 2003-01-28  scratchpad removed (jiri)
65
- * 2003-01-27  next baby-step to removing ZT - PRESERVE_ZT (jiri)
66 54
  * 2003-01-23  options for disabling r-uri matching introduced (jiri)
67 55
  *              nameser_compat.h (andrei)
56
+ * 2003-01-27  next baby-step to removing ZT - PRESERVE_ZT (jiri)
57
+ * 2003-01-28  scratchpad removed (jiri)
58
+ * 2003-02-13  init_rb() is proto indep. & it uses struct dest_info (andrei)
59
+ * 2003-02-24  s/T_NULL/T_NULL_CELL/ to avoid redefinition conflict w/
60
+ * 2003-02-27  3261 ACK/200 consumption bug removed (jiri)
61
+ * 2003-02-28 scratchpad compatibility abandoned (jiri)
62
+ * 2003-03-01  kr set through a function now (jiri)
63
+ * 2003-03-06  dialog matching introduced for ACKs -- that's important for 
64
+ *             INVITE UAS (like INVITE) and 200/ACK proxy matching (jiri)
65
+ * 2003-03-29  optimization: e2e ACK matching only if callback installed
66
+ *             (jiri)
67
+ * 2003-03-30  set_kr for requests only (jiri)
68
+ * 2003-04-04  bug_fix: RESPONSE_IN callback not called for local
69
+ *             UAC transactions (jiri)
68 70
  */
69 71
 
70 72
 
... ...
@@ -781,7 +783,8 @@ int t_reply_matching( struct sip_msg *p_msg , int *p_branch )
781 783
 				LOG(L_ERR, "ERROR: t_reply_matching: to parsing failed\n");
782 784
 			}
783 785
 		}
784
-		callback_event(TMCB_RESPONSE_IN, T, p_msg, p_msg->REPLY_STATUS);
786
+		if (!p_cell->local) 
787
+			callback_event(TMCB_RESPONSE_IN, T, p_msg, p_msg->REPLY_STATUS);
785 788
 		return 1;
786 789
 	} /* for cycle */
787 790
 
... ...
@@ -471,7 +471,7 @@ static void fifo_callback( struct cell *t, struct sip_msg *reply,
471 471
 			fifo_reply(filename, "500 fifo_callback: get_reply_status failed\n");
472 472
 			return;
473 473
 		}
474
-		fifo_reply(filename, "%.*s", text.len, text.s );
474
+		fifo_reply(filename, "%.*s\n", text.len, text.s );
475 475
 		pkg_free(text.s);
476 476
 	} else {
477 477
 		text.s=reply->first_line.u.reply.status.s;
... ...
@@ -32,6 +32,7 @@
32 32
  *  2003-01-28  removed scratchpad (jiri)
33 33
  *  2003-03-31  removed sip_msg->repl_add_rm (andrei)
34 34
  *  2003-04-01  2 macros added: GET_NEXT_HOP and GET_RURI (janakj)
35
+ *  2003-04-04  structure for parsed inbound uri added (jiri)
35 36
  */
36 37
 
37 38
 
... ...
@@ -161,8 +162,12 @@ struct sip_msg {
161 162
 
162 163
 	str dst_uri; /* Destination URI, must be forwarded to this URI if len != 0 */
163 164
 
165
+	/* current uri */
164 166
 	int parsed_uri_ok; /* 1 if parsed_uri is valid, 0 if not */
165 167
 	struct sip_uri parsed_uri; /* speed-up > keep here the parsed uri*/
168
+	/* the same for original uri */
169
+	int parsed_orig_ruri_ok;
170
+	struct sip_uri parsed_orig_ruri;
166 171
 	
167 172
 	struct lump* add_rm;       /* used for all the forwarded requests/replies */
168 173
 	struct lump_rpl *reply_lump; /* only for localy generated replies !!!*/
... ...
@@ -23,6 +23,11 @@
23 23
  * You should have received a copy of the GNU General Public License 
24 24
  * along with this program; if not, write to the Free Software 
25 25
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
26
+ *
27
+ * History:
28
+ * --------
29
+ * 2003-04-04  convenience inbound-uri parser parse_orig_ruri
30
+ *             introduced (jiri)
26 31
  */
27 32
 
28 33
 
... ...
@@ -173,28 +178,50 @@ int parse_uri(char *buf, int len, struct sip_uri* uri)
173 178
 }
174 179
 
175 180
 
181
+static inline int _parse_ruri(str *uri,
182
+	int *status, struct sip_uri *parsed_uri)
183
+{
184
+	if (*status) return 1;
185
+
186
+	if (parse_uri(uri->s, uri->len, parsed_uri)<0) {
187
+		LOG(L_ERR, "ERROR: _parse_ruri: bad uri <%.*s>\n", 
188
+				uri->len, uri->s);
189
+		*status=0;
190
+		return -1;
191
+	}
192
+	*status=1;
193
+	return 1;
194
+}
176 195
 
177 196
 int parse_sip_msg_uri(struct sip_msg* msg)
178 197
 {
179 198
 	char* tmp;
180 199
 	int tmp_len;
181 200
 	if (msg->parsed_uri_ok) return 1;
182
-	else{
183
-		if (msg->new_uri.s){
184
-			tmp=msg->new_uri.s;
185
-			tmp_len=msg->new_uri.len;
186
-		}else{
187
-			tmp=msg->first_line.u.request.uri.s;
188
-			tmp_len=msg->first_line.u.request.uri.len;
189
-		}
190
-		if (parse_uri(tmp, tmp_len, &msg->parsed_uri)<0){
191
-			LOG(L_ERR, "ERROR: parse_sip_msg_uri: bad uri <%.*s>\n",
192
-						tmp_len, tmp);
193
-			msg->parsed_uri_ok=0;
194
-			return -1;
195
-		}
196
-		msg->parsed_uri_ok=1;
197
-		return 1;
201
+
202
+	if (msg->new_uri.s){
203
+		tmp=msg->new_uri.s;
204
+		tmp_len=msg->new_uri.len;
205
+	}else{
206
+		tmp=msg->first_line.u.request.uri.s;
207
+		tmp_len=msg->first_line.u.request.uri.len;
198 208
 	}
209
+	if (parse_uri(tmp, tmp_len, &msg->parsed_uri)<0){
210
+		LOG(L_ERR, "ERROR: parse_sip_msg_uri: bad uri <%.*s>\n",
211
+					tmp_len, tmp);
212
+		msg->parsed_uri_ok=0;
213
+		return -1;
214
+	}
215
+	msg->parsed_uri_ok=1;
216
+	return 1;
199 217
 }
200 218
 
219
+int parse_orig_ruri(struct sip_msg* msg)
220
+{
221
+	int ret;
222
+
223
+	ret=_parse_ruri(&REQ_LINE(msg).uri,
224
+		&msg->parsed_orig_ruri_ok, &msg->parsed_orig_ruri);
225
+	if (ret<0) LOG(L_ERR, "ERROR: parse_orig_ruri failed\n");
226
+	return ret;
227
+}
... ...
@@ -45,5 +45,6 @@
45 45
  */
46 46
 int parse_uri(char *buf, int len, struct sip_uri* uri);
47 47
 int parse_sip_msg_uri(struct sip_msg* msg);
48
+int parse_orig_ruri(struct sip_msg* msg);
48 49
 
49 50
 #endif /* PARSE_URI_H */
... ...
@@ -126,13 +126,13 @@ INSERT INTO version VALUES ( 'subscriber', '2');
126 126
 INSERT INTO version VALUES ( 'reserved', '1');
127 127
 INSERT INTO version VALUES ( 'phonebook', '1');
128 128
 INSERT INTO version VALUES ( 'pending', '2');
129
-INSERT INTO version VALUES ( 'missed_calls', '1');
129
+INSERT INTO version VALUES ( 'missed_calls', '2');
130 130
 INSERT INTO version VALUES ( 'location', '3');
131 131
 INSERT INTO version VALUES ( 'grp', '2');
132 132
 INSERT INTO version VALUES ( 'event', '1');
133
-INSERT INTO version VALUES ( 'aliases', '2');
133
+INSERT INTO version VALUES ( 'aliases', '3');
134 134
 INSERT INTO version VALUES ( 'active_sessions', '1');
135
-INSERT INTO version VALUES ( 'acc', '1');
135
+INSERT INTO version VALUES ( 'acc', '2');
136 136
 INSERT INTO version VALUES ( 'config', '1');
137 137
 INSERT INTO version VALUES ( 'silo', '2');
138 138
 INSERT INTO version VALUES ( 'realm', '1');
... ...
@@ -154,6 +154,8 @@ CREATE TABLE acc (
154 154
   sip_method varchar(16) NOT NULL default '',
155 155
   i_uri varchar(128) NOT NULL default '',
156 156
   o_uri varchar(128) NOT NULL default '',
157
+  from_uri varchar(128) NOT NULL default '',
158
+  to_uri varchar(128) NOT NULL default '',
157 159
   sip_callid varchar(128) NOT NULL default '',
158 160
   username varchar(64) NOT NULL default '',
159 161
   time datetime NOT NULL default '0000-00-00 00:00:00',
... ...
@@ -184,7 +186,6 @@ CREATE TABLE active_sessions (
184 186
 # Table structure for table 'aliases' -- location-like table
185 187
 #
186 188
 
187
-
188 189
 CREATE TABLE aliases (
189 190
   username varchar(50) NOT NULL default '',
190 191
   domain varchar(100) NOT NULL default '',
... ...
@@ -194,12 +195,12 @@ CREATE TABLE aliases (
194 195
   callid varchar(255) default NULL,
195 196
   cseq int(11) default NULL,
196 197
   last_modified timestamp(14) NOT NULL,
197
-  PRIMARY KEY usr (username, domain, contact)
198
+  replicate int(10) unsigned default NULL,
199
+  state tinyint(1) unsigned default NULL,
200
+  PRIMARY KEY(username, domain, contact)
198 201
 ) $TABLE_TYPE;
199 202
 
200 203
 
201
-
202
-
203 204
 #
204 205
 # Table structure for table 'event' -- track of predefined
205 206
 # events to which a user subscribed
... ...
@@ -269,6 +270,8 @@ CREATE TABLE missed_calls (
269 270
   sip_method varchar(16) NOT NULL default '',
270 271
   i_uri varchar(128) NOT NULL default '',
271 272
   o_uri varchar(128) NOT NULL default '',
273
+  from_uri varchar(128) NOT NULL default '',
274
+  to_uri varchar(128) NOT NULL default '',
272 275
   sip_callid varchar(128) NOT NULL default '',
273 276
   username varchar(64) NOT NULL default '',
274 277
   time datetime NOT NULL default '0000-00-00 00:00:00',
... ...
@@ -495,7 +498,32 @@ EOF
495 498
 
496 499
 
497 500
 case $1 in
501
+	renew)
502
+		# backup, drop, restore (experimental)
503
+		tmp_file=/tmp/ser_mysql.$$
504
+		ser_backup $DBNAME $SQL_USER > $tmp_file
505
+		ret=$?
506
+		if [ "$ret" -ne 0 ]; then
507
+			rm $tmp_file
508
+			exit $ret
509
+		fi
510
+		ser_drop $DBNAME $SQL_USER
511
+		ret=$?
512
+		if [ "$ret" -ne 0 ]; then
513
+			exit $ret
514
+		fi
515
+		ser_create $DBNAME $SQL_USER
516
+		ret=$?
517
+		if [ "$ret" -ne 0 ]; then
518
+			exit $ret
519
+		fi
520
+		ser_restore $DBNAME $SQL_USER $tmp_file
521
+		ret=$?
522
+		rm $tmp_file
523
+		exit $ret
524
+		;;
498 525
 	copy)
526
+		# copy database to some other name
499 527
 		shift
500 528
 		if [ $# -ne 1 ]; then
501 529
 			usage
... ...
@@ -520,10 +548,12 @@ case $1 in
520 548
 		exit $ret
521 549
 		;;
522 550
 	backup)
551
+		# backup current database
523 552
 		ser_backup $DBNAME $SQL_USER
524 553
 		exit $?
525 554
 		;;
526 555
 	restore)
556
+		# restore database from a backup
527 557
 		shift
528 558
 		if [ $# -ne 1 ]; then
529 559
 			usage
... ...
@@ -533,6 +563,7 @@ case $1 in
533 563
 		exit $?
534 564
 		;;
535 565
 	create)
566
+		# create new database structures
536 567
 		shift
537 568
 		if [ $# -eq 1 ] ; then
538 569
 			DBNAME="$1"
... ...
@@ -541,10 +572,12 @@ case $1 in
541 572
 		exit $?
542 573
 		;;
543 574
 	drop)
575
+		# delete ser database
544 576
 		ser_drop $DBNAME $SQL_USER
545 577
 		exit $?
546 578
 		;;
547 579
 	reinit)
580
+		# delete database and create a new one
548 581
 		ser_drop $DBNAME $SQL_USER
549 582
 		ret=$?
550 583
 		if [ "$ret" -ne 0 ]; then