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 185
 	} else {
186 186
 		phrase=reply->first_line.u.reply.reason;
187 187
 	}
188
-	status->len=phrase.len+3/*code*/+1/*space*/+1/*ZT*/;
189
-	status->s=pkg_malloc(status->len);
188
+	status->len=phrase.len+3/*code*/+1/*space*/; 
189
+	status->s=pkg_malloc(status->len+1/*ZT */);
190 190
 	if (!status->s) {
191 191
 		LOG(L_ERR, "ERROR: get_reply_status: no mem\n");
192 192
 		return;
... ...
@@ -196,5 +200,5 @@ void get_reply_status( str *status, struct sip_msg *reply, int code )
196 196
 	status->s[1]='0'+code% 10; code=code/10;
197 197
 	status->s[0]='0'+code % 10;
198 198
 	memcpy(&status->s[4], phrase.s, phrase.len);
199
-	status->s[status->len-1]=0;
199
+	status->s[status->len]=0;
200 200
 }
... ...
@@ -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 182
 	/*fprintf(stderr,"before clone VIA |%.*s|\n",via_len(p_msg->via1),
183 183
 		via_s(p_msg->via1,p_msg));*/
184 184
 
185
-	callback_event(TMCB_REQUEST_IN, new_cell, p_msg, 
186
-			p_msg ? p_msg->REQ_METHOD : METHOD_UNDEF );
185
+	/* enter callback, which may potentially want to parse some stuff,
186
+	   before the request is shmem-ized
187
+	*/ 
188
+    if (p_msg) callback_event(TMCB_REQUEST_IN, new_cell, p_msg,
189
+            p_msg->REQ_METHOD );
187 190
 
188 191
 	if (p_msg) {
189 192
 		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 157
 	return first_via;
158 158
 }
159 159
 
160
+static void uri_trans(char *new_buf, char *org_buf, struct sip_uri *uri)
161
+{
162
+	uri->user.s=translate_pointer(new_buf,org_buf,uri->user.s);
163
+	uri->passwd.s=translate_pointer(new_buf,org_buf,uri->passwd.s);
164
+	uri->host.s=translate_pointer(new_buf,org_buf,uri->host.s);
165
+	uri->port.s=translate_pointer(new_buf,org_buf,uri->port.s);
166
+	uri->params.s=translate_pointer(new_buf,org_buf,uri->params.s);
167
+	uri->headers.s=translate_pointer(new_buf,org_buf,uri->headers.s);
168
+}
169
+
160 170
 
161 171
 static inline struct auth_body* auth_body_cloner(char* new_buf, char *org_buf, struct auth_body *auth, char **p)
162 172
 {
... ...
@@ -365,6 +376,8 @@ struct sip_msg*  sip_msg_cloner( struct sip_msg *org_msg )
365 365
 		new_msg->first_line.u.request.version.s =
366 366
 			translate_pointer( new_msg->buf , org_msg->buf ,
367 367
 			org_msg->first_line.u.request.version.s );
368
+		uri_trans(new_msg->buf, org_msg->buf, &new_msg->parsed_orig_ruri);
369
+		uri_trans(new_msg->buf, org_msg->buf, &new_msg->parsed_uri);
368 370
 	}
369 371
 	else if ( org_msg->first_line.type==SIP_REPLY )
370 372
 	{
... ...
@@ -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 781
 				LOG(L_ERR, "ERROR: t_reply_matching: to parsing failed\n");
782 782
 			}
783 783
 		}
784
-		callback_event(TMCB_RESPONSE_IN, T, p_msg, p_msg->REPLY_STATUS);
784
+		if (!p_cell->local) 
785
+			callback_event(TMCB_RESPONSE_IN, T, p_msg, p_msg->REPLY_STATUS);
785 786
 		return 1;
786 787
 	} /* for cycle */
787 788
 
... ...
@@ -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 161
 
162 162
 	str dst_uri; /* Destination URI, must be forwarded to this URI if len != 0 */
163 163
 
164
+	/* current uri */
164 165
 	int parsed_uri_ok; /* 1 if parsed_uri is valid, 0 if not */
165 166
 	struct sip_uri parsed_uri; /* speed-up > keep here the parsed uri*/
167
+	/* the same for original uri */
168
+	int parsed_orig_ruri_ok;
169
+	struct sip_uri parsed_orig_ruri;
166 170
 	
167 171
 	struct lump* add_rm;       /* used for all the forwarded requests/replies */
168 172
 	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 173
 }
174 174
 
175 175
 
176
+static inline int _parse_ruri(str *uri,
177
+	int *status, struct sip_uri *parsed_uri)
178
+{
179
+	if (*status) return 1;
180
+
181
+	if (parse_uri(uri->s, uri->len, parsed_uri)<0) {
182
+		LOG(L_ERR, "ERROR: _parse_ruri: bad uri <%.*s>\n", 
183
+				uri->len, uri->s);
184
+		*status=0;
185
+		return -1;
186
+	}
187
+	*status=1;
188
+	return 1;
189
+}
176 190
 
177 191
 int parse_sip_msg_uri(struct sip_msg* msg)
178 192
 {
179 193
 	char* tmp;
180 194
 	int tmp_len;
181 195
 	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;
196
+
197
+	if (msg->new_uri.s){
198
+		tmp=msg->new_uri.s;
199
+		tmp_len=msg->new_uri.len;
200
+	}else{
201
+		tmp=msg->first_line.u.request.uri.s;
202
+		tmp_len=msg->first_line.u.request.uri.len;
198 203
 	}
204
+	if (parse_uri(tmp, tmp_len, &msg->parsed_uri)<0){
205
+		LOG(L_ERR, "ERROR: parse_sip_msg_uri: bad uri <%.*s>\n",
206
+					tmp_len, tmp);
207
+		msg->parsed_uri_ok=0;
208
+		return -1;
209
+	}
210
+	msg->parsed_uri_ok=1;
211
+	return 1;
199 212
 }
200 213
 
214
+int parse_orig_ruri(struct sip_msg* msg)
215
+{
216
+	int ret;
217
+
218
+	ret=_parse_ruri(&REQ_LINE(msg).uri,
219
+		&msg->parsed_orig_ruri_ok, &msg->parsed_orig_ruri);
220
+	if (ret<0) LOG(L_ERR, "ERROR: parse_orig_ruri failed\n");
221
+	return ret;
222
+}
... ...
@@ -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 184
 # Table structure for table 'aliases' -- location-like table
185 185
 #
186 186
 
187
-
188 187
 CREATE TABLE aliases (
189 188
   username varchar(50) NOT NULL default '',
190 189
   domain varchar(100) NOT NULL default '',
... ...
@@ -194,12 +195,12 @@ CREATE TABLE aliases (
194 194
   callid varchar(255) default NULL,
195 195
   cseq int(11) default NULL,
196 196
   last_modified timestamp(14) NOT NULL,
197
-  PRIMARY KEY usr (username, domain, contact)
197
+  replicate int(10) unsigned default NULL,
198
+  state tinyint(1) unsigned default NULL,
199
+  PRIMARY KEY(username, domain, contact)
198 200
 ) $TABLE_TYPE;
199 201
 
200 202
 
201
-
202
-
203 203
 #
204 204
 # Table structure for table 'event' -- track of predefined
205 205
 # events to which a user subscribed
... ...
@@ -269,6 +270,8 @@ CREATE TABLE missed_calls (
269 269
   sip_method varchar(16) NOT NULL default '',
270 270
   i_uri varchar(128) NOT NULL default '',
271 271
   o_uri varchar(128) NOT NULL default '',
272
+  from_uri varchar(128) NOT NULL default '',
273
+  to_uri varchar(128) NOT NULL default '',
272 274
   sip_callid varchar(128) NOT NULL default '',
273 275
   username varchar(64) NOT NULL default '',
274 276
   time datetime NOT NULL default '0000-00-00 00:00:00',
... ...
@@ -495,7 +498,32 @@ EOF
495 495
 
496 496
 
497 497
 case $1 in
498
+	renew)
499
+		# backup, drop, restore (experimental)
500
+		tmp_file=/tmp/ser_mysql.$$
501
+		ser_backup $DBNAME $SQL_USER > $tmp_file
502
+		ret=$?
503
+		if [ "$ret" -ne 0 ]; then
504
+			rm $tmp_file
505
+			exit $ret
506
+		fi
507
+		ser_drop $DBNAME $SQL_USER
508
+		ret=$?
509
+		if [ "$ret" -ne 0 ]; then
510
+			exit $ret
511
+		fi
512
+		ser_create $DBNAME $SQL_USER
513
+		ret=$?
514
+		if [ "$ret" -ne 0 ]; then
515
+			exit $ret
516
+		fi
517
+		ser_restore $DBNAME $SQL_USER $tmp_file
518
+		ret=$?
519
+		rm $tmp_file
520
+		exit $ret
521
+		;;
498 522
 	copy)
523
+		# copy database to some other name
499 524
 		shift
500 525
 		if [ $# -ne 1 ]; then
501 526
 			usage
... ...
@@ -520,10 +548,12 @@ case $1 in
520 520
 		exit $ret
521 521
 		;;
522 522
 	backup)
523
+		# backup current database
523 524
 		ser_backup $DBNAME $SQL_USER
524 525
 		exit $?
525 526
 		;;
526 527
 	restore)
528
+		# restore database from a backup
527 529
 		shift
528 530
 		if [ $# -ne 1 ]; then
529 531
 			usage
... ...
@@ -533,6 +563,7 @@ case $1 in
533 533
 		exit $?
534 534
 		;;
535 535
 	create)
536
+		# create new database structures
536 537
 		shift
537 538
 		if [ $# -eq 1 ] ; then
538 539
 			DBNAME="$1"
... ...
@@ -541,10 +572,12 @@ case $1 in
541 541
 		exit $?
542 542
 		;;
543 543
 	drop)
544
+		# delete ser database
544 545
 		ser_drop $DBNAME $SQL_USER
545 546
 		exit $?
546 547
 		;;
547 548
 	reinit)
549
+		# delete database and create a new one
548 550
 		ser_drop $DBNAME $SQL_USER
549 551
 		ret=$?
550 552
 		if [ "$ret" -ne 0 ]; then