Bläddra i källkod

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

Jiri Kuthan 22 år sedan
förälder
incheckning
b2fcef3cb0
11 ändrade filer med 149 tillägg och 49 borttagningar
  1. 7 1
      NEWS
  2. 7 3
      error.c
  3. 9 4
      modules/tm/h_table.c
  4. 16 3
      modules/tm/sip_msg.c
  5. 4 1
      modules/tm/t_hooks.h
  6. 16 13
      modules/tm/t_lookup.c
  7. 1 1
      modules/tm/uac.c
  8. 5 0
      parser/msg_parser.h
  9. 43 16
      parser/parse_uri.c
  10. 1 0
      parser/parse_uri.h
  11. 40 7
      scripts/ser_mysql.sh

+ 7 - 1
NEWS

@@ -43,13 +43,19 @@ New features
 Changes to use of ser scripts
 =============================
 
+
 core
 ----
 XXX TCP
 
 acc module:
 -----------
-XXX
+- radius and sql support integrated in this module; you need to
+  recompile to enable it
+- acc_flag is now called log_flag to better reflect it relates
+  to the syslog mode (as opposed to sql/radius); for the same
+  reasons, the accounting action is now called "acc_log_request"
+- log_fmt allows now to specify what will be printed to syslog
 
 auth module:
 ------------

+ 7 - 3
error.c

@@ -24,6 +24,10 @@
  * You should have received a copy of the GNU General Public License 
  * along with this program; if not, write to the Free Software 
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ * History:
+ * --------
+ * 2003-04-04 phrase length corrected not to include trailer 0 (jiri)
  */
 
 
@@ -185,8 +189,8 @@ void get_reply_status( str *status, struct sip_msg *reply, int code )
 	} else {
 		phrase=reply->first_line.u.reply.reason;
 	}
-	status->len=phrase.len+3/*code*/+1/*space*/+1/*ZT*/;
-	status->s=pkg_malloc(status->len);
+	status->len=phrase.len+3/*code*/+1/*space*/; 
+	status->s=pkg_malloc(status->len+1/*ZT */);
 	if (!status->s) {
 		LOG(L_ERR, "ERROR: get_reply_status: no mem\n");
 		return;
@@ -196,5 +200,5 @@ void get_reply_status( str *status, struct sip_msg *reply, int code )
 	status->s[1]='0'+code% 10; code=code/10;
 	status->s[0]='0'+code % 10;
 	memcpy(&status->s[4], phrase.s, phrase.len);
-	status->s[status->len-1]=0;
+	status->s[status->len]=0;
 }

+ 9 - 4
modules/tm/h_table.c

@@ -26,11 +26,13 @@
  *
  * History
  * -------
- * 2003-03-30  set_kr for requests only (jiri)
- * 2003-03-16  removed _TOTAG (jiri)
  * 2003-03-06  200/INV to-tag list deallocation added;
  *             setting "kill_reason" moved in here -- it is moved
  *             from transaction state to a static var(jiri)
+ * 2003-03-16  removed _TOTAG (jiri)
+ * 2003-03-30  set_kr for requests only (jiri)
+ * 2003-04-04  bug_fix: REQ_IN callback not called for local 
+ *             UAC transactions (jiri)
  */
 
 #include "defs.h"
@@ -182,8 +184,11 @@ struct cell*  build_cell( struct sip_msg* p_msg )
 	/*fprintf(stderr,"before clone VIA |%.*s|\n",via_len(p_msg->via1),
 		via_s(p_msg->via1,p_msg));*/
 
-	callback_event(TMCB_REQUEST_IN, new_cell, p_msg, 
-			p_msg ? p_msg->REQ_METHOD : METHOD_UNDEF );
+	/* enter callback, which may potentially want to parse some stuff,
+	   before the request is shmem-ized
+	*/ 
+    if (p_msg) callback_event(TMCB_REQUEST_IN, new_cell, p_msg,
+            p_msg->REQ_METHOD );
 
 	if (p_msg) {
 		new_cell->uas.request = sip_msg_cloner(p_msg);

+ 16 - 3
modules/tm/sip_msg.c

@@ -37,11 +37,12 @@
  *
  * History:
  * --------
- *  2003-02-28  scratchpad compatibility abandoned (jiri)
- *  2003-02-25 - auth_body cloner added (janakj)
- *  2003-01-29 - scratchpad removed (jiri)
  *  2003-01-23 - msg_cloner clones msg->from->parsed too (janakj)
+ *  2003-01-29 - scratchpad removed (jiri)
+ *  2003-02-25 - auth_body cloner added (janakj)
+ *  2003-02-28  scratchpad compatibility abandoned (jiri)
  *  2003-03-31  removed msg->repl_add_rm (andrei)
+ *  2003-04-04  parsed uris are recalculated on cloning (jiri)
  */
 
 #include "defs.h"
@@ -157,6 +158,16 @@ inline struct via_body* via_body_cloner( char* new_buf,
 	return first_via;
 }
 
+static void uri_trans(char *new_buf, char *org_buf, struct sip_uri *uri)
+{
+	uri->user.s=translate_pointer(new_buf,org_buf,uri->user.s);
+	uri->passwd.s=translate_pointer(new_buf,org_buf,uri->passwd.s);
+	uri->host.s=translate_pointer(new_buf,org_buf,uri->host.s);
+	uri->port.s=translate_pointer(new_buf,org_buf,uri->port.s);
+	uri->params.s=translate_pointer(new_buf,org_buf,uri->params.s);
+	uri->headers.s=translate_pointer(new_buf,org_buf,uri->headers.s);
+}
+
 
 static inline struct auth_body* auth_body_cloner(char* new_buf, char *org_buf, struct auth_body *auth, char **p)
 {
@@ -365,6 +376,8 @@ struct sip_msg*  sip_msg_cloner( struct sip_msg *org_msg )
 		new_msg->first_line.u.request.version.s =
 			translate_pointer( new_msg->buf , org_msg->buf ,
 			org_msg->first_line.u.request.version.s );
+		uri_trans(new_msg->buf, org_msg->buf, &new_msg->parsed_orig_ruri);
+		uri_trans(new_msg->buf, org_msg->buf, &new_msg->parsed_uri);
 	}
 	else if ( org_msg->first_line.type==SIP_REPLY )
 	{

+ 4 - 1
modules/tm/t_hooks.h

@@ -73,7 +73,10 @@ typedef enum {
  * lives in pkg mem -- your last chance to mangle it before
  * it gets shmem-ized (then, it's read-only); it's called from
  * HASH_LOCK, so be careful. It is guaranteed not to be
- * a retransmission.
+ * a retransmission. The transactional context is mostly
+ * incomplete -- this callback is called in very early stage
+ * before the message is shmem-ized (so that you can work
+ * with it).
  *
  * TMCB_RESPONSE_IN -- a brand-new reply was received which matches
  * an existing transaction. It may or may not be a retranmisssion.

+ 16 - 13
modules/tm/t_lookup.c

@@ -51,20 +51,22 @@
  *
  * History:
  * ----------
- * 2003-03-30  set_kr for requests only (jiri)
- * 2003-03-29  optimization: e2e ACK matching only if callback installed
- *             (jiri)
- * 2003-03-06  dialog matching introduced for ACKs -- that's important for 
- *             INVITE UAS (like INVITE) and 200/ACK proxy matching (jiri)
- * 2003-03-01  kr set through a function now (jiri)
- * 2003-02-28 scratchpad compatibility abandoned (jiri)
- * 2003-02-27  3261 ACK/200 consumption bug removed (jiri)
- * 2003-02-24  s/T_NULL/T_NULL_CELL/ to avoid redefinition conflict w/
- * 2003-02-13  init_rb() is proto indep. & it uses struct dest_info (andrei)
- * 2003-01-28  scratchpad removed (jiri)
- * 2003-01-27  next baby-step to removing ZT - PRESERVE_ZT (jiri)
  * 2003-01-23  options for disabling r-uri matching introduced (jiri)
  *              nameser_compat.h (andrei)
+ * 2003-01-27  next baby-step to removing ZT - PRESERVE_ZT (jiri)
+ * 2003-01-28  scratchpad removed (jiri)
+ * 2003-02-13  init_rb() is proto indep. & it uses struct dest_info (andrei)
+ * 2003-02-24  s/T_NULL/T_NULL_CELL/ to avoid redefinition conflict w/
+ * 2003-02-27  3261 ACK/200 consumption bug removed (jiri)
+ * 2003-02-28 scratchpad compatibility abandoned (jiri)
+ * 2003-03-01  kr set through a function now (jiri)
+ * 2003-03-06  dialog matching introduced for ACKs -- that's important for 
+ *             INVITE UAS (like INVITE) and 200/ACK proxy matching (jiri)
+ * 2003-03-29  optimization: e2e ACK matching only if callback installed
+ *             (jiri)
+ * 2003-03-30  set_kr for requests only (jiri)
+ * 2003-04-04  bug_fix: RESPONSE_IN callback not called for local
+ *             UAC transactions (jiri)
  */
 
 
@@ -781,7 +783,8 @@ int t_reply_matching( struct sip_msg *p_msg , int *p_branch )
 				LOG(L_ERR, "ERROR: t_reply_matching: to parsing failed\n");
 			}
 		}
-		callback_event(TMCB_RESPONSE_IN, T, p_msg, p_msg->REPLY_STATUS);
+		if (!p_cell->local) 
+			callback_event(TMCB_RESPONSE_IN, T, p_msg, p_msg->REPLY_STATUS);
 		return 1;
 	} /* for cycle */
 

+ 1 - 1
modules/tm/uac.c

@@ -471,7 +471,7 @@ static void fifo_callback( struct cell *t, struct sip_msg *reply,
 			fifo_reply(filename, "500 fifo_callback: get_reply_status failed\n");
 			return;
 		}
-		fifo_reply(filename, "%.*s", text.len, text.s );
+		fifo_reply(filename, "%.*s\n", text.len, text.s );
 		pkg_free(text.s);
 	} else {
 		text.s=reply->first_line.u.reply.status.s;

+ 5 - 0
parser/msg_parser.h

@@ -32,6 +32,7 @@
  *  2003-01-28  removed scratchpad (jiri)
  *  2003-03-31  removed sip_msg->repl_add_rm (andrei)
  *  2003-04-01  2 macros added: GET_NEXT_HOP and GET_RURI (janakj)
+ *  2003-04-04  structure for parsed inbound uri added (jiri)
  */
 
 
@@ -161,8 +162,12 @@ struct sip_msg {
 
 	str dst_uri; /* Destination URI, must be forwarded to this URI if len != 0 */
 
+	/* current uri */
 	int parsed_uri_ok; /* 1 if parsed_uri is valid, 0 if not */
 	struct sip_uri parsed_uri; /* speed-up > keep here the parsed uri*/
+	/* the same for original uri */
+	int parsed_orig_ruri_ok;
+	struct sip_uri parsed_orig_ruri;
 	
 	struct lump* add_rm;       /* used for all the forwarded requests/replies */
 	struct lump_rpl *reply_lump; /* only for localy generated replies !!!*/

+ 43 - 16
parser/parse_uri.c

@@ -23,6 +23,11 @@
  * You should have received a copy of the GNU General Public License 
  * along with this program; if not, write to the Free Software 
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ * History:
+ * --------
+ * 2003-04-04  convenience inbound-uri parser parse_orig_ruri
+ *             introduced (jiri)
  */
 
 
@@ -173,28 +178,50 @@ int parse_uri(char *buf, int len, struct sip_uri* uri)
 }
 
 
+static inline int _parse_ruri(str *uri,
+	int *status, struct sip_uri *parsed_uri)
+{
+	if (*status) return 1;
+
+	if (parse_uri(uri->s, uri->len, parsed_uri)<0) {
+		LOG(L_ERR, "ERROR: _parse_ruri: bad uri <%.*s>\n", 
+				uri->len, uri->s);
+		*status=0;
+		return -1;
+	}
+	*status=1;
+	return 1;
+}
 
 int parse_sip_msg_uri(struct sip_msg* msg)
 {
 	char* tmp;
 	int tmp_len;
 	if (msg->parsed_uri_ok) return 1;
-	else{
-		if (msg->new_uri.s){
-			tmp=msg->new_uri.s;
-			tmp_len=msg->new_uri.len;
-		}else{
-			tmp=msg->first_line.u.request.uri.s;
-			tmp_len=msg->first_line.u.request.uri.len;
-		}
-		if (parse_uri(tmp, tmp_len, &msg->parsed_uri)<0){
-			LOG(L_ERR, "ERROR: parse_sip_msg_uri: bad uri <%.*s>\n",
-						tmp_len, tmp);
-			msg->parsed_uri_ok=0;
-			return -1;
-		}
-		msg->parsed_uri_ok=1;
-		return 1;
+
+	if (msg->new_uri.s){
+		tmp=msg->new_uri.s;
+		tmp_len=msg->new_uri.len;
+	}else{
+		tmp=msg->first_line.u.request.uri.s;
+		tmp_len=msg->first_line.u.request.uri.len;
 	}
+	if (parse_uri(tmp, tmp_len, &msg->parsed_uri)<0){
+		LOG(L_ERR, "ERROR: parse_sip_msg_uri: bad uri <%.*s>\n",
+					tmp_len, tmp);
+		msg->parsed_uri_ok=0;
+		return -1;
+	}
+	msg->parsed_uri_ok=1;
+	return 1;
 }
 
+int parse_orig_ruri(struct sip_msg* msg)
+{
+	int ret;
+
+	ret=_parse_ruri(&REQ_LINE(msg).uri,
+		&msg->parsed_orig_ruri_ok, &msg->parsed_orig_ruri);
+	if (ret<0) LOG(L_ERR, "ERROR: parse_orig_ruri failed\n");
+	return ret;
+}

+ 1 - 0
parser/parse_uri.h

@@ -45,5 +45,6 @@
  */
 int parse_uri(char *buf, int len, struct sip_uri* uri);
 int parse_sip_msg_uri(struct sip_msg* msg);
+int parse_orig_ruri(struct sip_msg* msg);
 
 #endif /* PARSE_URI_H */

+ 40 - 7
scripts/ser_mysql.sh

@@ -126,13 +126,13 @@ INSERT INTO version VALUES ( 'subscriber', '2');
 INSERT INTO version VALUES ( 'reserved', '1');
 INSERT INTO version VALUES ( 'phonebook', '1');
 INSERT INTO version VALUES ( 'pending', '2');
-INSERT INTO version VALUES ( 'missed_calls', '1');
+INSERT INTO version VALUES ( 'missed_calls', '2');
 INSERT INTO version VALUES ( 'location', '3');
 INSERT INTO version VALUES ( 'grp', '2');
 INSERT INTO version VALUES ( 'event', '1');
-INSERT INTO version VALUES ( 'aliases', '2');
+INSERT INTO version VALUES ( 'aliases', '3');
 INSERT INTO version VALUES ( 'active_sessions', '1');
-INSERT INTO version VALUES ( 'acc', '1');
+INSERT INTO version VALUES ( 'acc', '2');
 INSERT INTO version VALUES ( 'config', '1');
 INSERT INTO version VALUES ( 'silo', '2');
 INSERT INTO version VALUES ( 'realm', '1');
@@ -154,6 +154,8 @@ CREATE TABLE acc (
   sip_method varchar(16) NOT NULL default '',
   i_uri varchar(128) NOT NULL default '',
   o_uri varchar(128) NOT NULL default '',
+  from_uri varchar(128) NOT NULL default '',
+  to_uri varchar(128) NOT NULL default '',
   sip_callid varchar(128) NOT NULL default '',
   username varchar(64) NOT NULL default '',
   time datetime NOT NULL default '0000-00-00 00:00:00',
@@ -184,7 +186,6 @@ CREATE TABLE active_sessions (
 # Table structure for table 'aliases' -- location-like table
 #
 
-
 CREATE TABLE aliases (
   username varchar(50) NOT NULL default '',
   domain varchar(100) NOT NULL default '',
@@ -194,12 +195,12 @@ CREATE TABLE aliases (
   callid varchar(255) default NULL,
   cseq int(11) default NULL,
   last_modified timestamp(14) NOT NULL,
-  PRIMARY KEY usr (username, domain, contact)
+  replicate int(10) unsigned default NULL,
+  state tinyint(1) unsigned default NULL,
+  PRIMARY KEY(username, domain, contact)
 ) $TABLE_TYPE;
 
 
-
-
 #
 # Table structure for table 'event' -- track of predefined
 # events to which a user subscribed
@@ -269,6 +270,8 @@ CREATE TABLE missed_calls (
   sip_method varchar(16) NOT NULL default '',
   i_uri varchar(128) NOT NULL default '',
   o_uri varchar(128) NOT NULL default '',
+  from_uri varchar(128) NOT NULL default '',
+  to_uri varchar(128) NOT NULL default '',
   sip_callid varchar(128) NOT NULL default '',
   username varchar(64) NOT NULL default '',
   time datetime NOT NULL default '0000-00-00 00:00:00',
@@ -495,7 +498,32 @@ EOF
 
 
 case $1 in
+	renew)
+		# backup, drop, restore (experimental)
+		tmp_file=/tmp/ser_mysql.$$
+		ser_backup $DBNAME $SQL_USER > $tmp_file
+		ret=$?
+		if [ "$ret" -ne 0 ]; then
+			rm $tmp_file
+			exit $ret
+		fi
+		ser_drop $DBNAME $SQL_USER
+		ret=$?
+		if [ "$ret" -ne 0 ]; then
+			exit $ret
+		fi
+		ser_create $DBNAME $SQL_USER
+		ret=$?
+		if [ "$ret" -ne 0 ]; then
+			exit $ret
+		fi
+		ser_restore $DBNAME $SQL_USER $tmp_file
+		ret=$?
+		rm $tmp_file
+		exit $ret
+		;;
 	copy)
+		# copy database to some other name
 		shift
 		if [ $# -ne 1 ]; then
 			usage
@@ -520,10 +548,12 @@ case $1 in
 		exit $ret
 		;;
 	backup)
+		# backup current database
 		ser_backup $DBNAME $SQL_USER
 		exit $?
 		;;
 	restore)
+		# restore database from a backup
 		shift
 		if [ $# -ne 1 ]; then
 			usage
@@ -533,6 +563,7 @@ case $1 in
 		exit $?
 		;;
 	create)
+		# create new database structures
 		shift
 		if [ $# -eq 1 ] ; then
 			DBNAME="$1"
@@ -541,10 +572,12 @@ case $1 in
 		exit $?
 		;;
 	drop)
+		# delete ser database
 		ser_drop $DBNAME $SQL_USER
 		exit $?
 		;;
 	reinit)
+		# delete database and create a new one
 		ser_drop $DBNAME $SQL_USER
 		ret=$?
 		if [ "$ret" -ne 0 ]; then