Browse Source

- sun cc compile fixes (all the files not mentioned explicitly)
- fixed a bug in build_res_buf_with_body_from_sip_req (bad len computations
when via was not crlf terminated, e.g only lf)
- Makefile.def: sun cc modules compilations options updated (it seems tm uses too many symbols for the default small memory model)
- lock_ops.h: lock set support added also for PTHREAD_MUTEX & POSIX_SEM
- route.c: updated to the new module exports format
- sr_module.[hc]: changed module exports interface: added struct cmd_export
and param_export, updated find_export, find_export_param,
find_module

Andrei Pelinescu-Onciul 22 years ago
parent
commit
6419a43f9f
16 changed files with 197 additions and 126 deletions
  1. 11 5
      Makefile.defs
  2. 2 2
      ip_addr.h
  3. 41 28
      lock_ops.h
  4. 9 0
      mem/mem.h
  5. 5 0
      mem/shm_mem.h
  6. 26 18
      msg_translator.c
  7. 6 6
      parser/hf.h
  8. 3 3
      parser/parse_content.c
  9. 5 3
      parser/parse_via.c
  10. 4 4
      resolve.h
  11. 11 12
      route.c
  12. 24 16
      sr_module.c
  13. 44 24
      sr_module.h
  14. 0 1
      tcp_main.c
  15. 2 2
      test/th-uri-fast.cfg
  16. 4 2
      ut.h

+ 11 - 5
Makefile.defs

@@ -2,6 +2,7 @@
 #
 #
 # makefile defs (CC, LD,a.s.o)
 # makefile defs (CC, LD,a.s.o)
 #
 #
+#
 # History:
 # History:
 # --------
 # --------
 #              created by andrei
 #              created by andrei
@@ -9,13 +10,15 @@
 #               by Maxim Sobolev <[email protected]>
 #               by Maxim Sobolev <[email protected]>
 #  2003-02-25  added -DDISABLE_NAGLE
 #  2003-02-25  added -DDISABLE_NAGLE
 #  2003-03-02  added -DDIGEST_DOMAIN (janakj)
 #  2003-03-02  added -DDIGEST_DOMAIN (janakj)
+#  2003-03-10  added -xcode=pic32 for module compilation w/ sun cc
+#              (too many symbols for pic13)  (andrei)
 
 
 
 
 #version number
 #version number
 VERSION = 0
 VERSION = 0
 PATCHLEVEL = 8
 PATCHLEVEL = 8
 SUBLEVEL =   11
 SUBLEVEL =   11
-EXTRAVERSION = pre6-tcp10-lck
+EXTRAVERSION = pre7
 
 
 RELEASE=$(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION)
 RELEASE=$(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION)
 OS = $(shell uname -s | sed -e s/SunOS/solaris/ | tr "[A-Z]" "[a-z]")
 OS = $(shell uname -s | sed -e s/SunOS/solaris/ | tr "[A-Z]" "[a-z]")
@@ -195,7 +198,10 @@ DEFS+= -DNAME='"$(NAME)"' -DVERSION='"$(RELEASE)"' -DARCH='"$(ARCH)"' \
 	 #-DNO_LOG
 	 #-DNO_LOG
 
 
 #PROFILE=  -pg #set this if you want profiling
 #PROFILE=  -pg #set this if you want profiling
-mode = debug
+
+# WARNING: do not add mode=debug or mode=release anymore in the Makefile,
+# use make mode=debug all instead. Anyway no by default ser is  compiled w/ 
+# debugging symbols in all cases (-g). --andrei
 ifeq ($(mode),)
 ifeq ($(mode),)
 	mode = release
 	mode = release
 endif
 endif
@@ -366,7 +372,7 @@ endif			# CC_SHORTVER, 3.0
 
 
 else		# CC_NAME, gcc
 else		# CC_NAME, gcc
 ifeq		($(CC_NAME), icc)
 ifeq		($(CC_NAME), icc)
-			CFLAGS=-O3  -ipo -ipo_obj -unroll  $(PROFILE) \
+			CFLAGS=-g -O3  -ipo -ipo_obj -unroll  $(PROFILE) \
 					 -tpp6 -xK  #-openmp  #optimize for PIII 
 					 -tpp6 -xK  #-openmp  #optimize for PIII 
 				# -prefetch doesn't seem to work
 				# -prefetch doesn't seem to work
 				#( ty to inline acroos files, unroll loops,prefetch,
 				#( ty to inline acroos files, unroll loops,prefetch,
@@ -424,7 +430,7 @@ endif			#CC_SHORTVER, 3.0
 
 
 else		#CC_NAME, gcc
 else		#CC_NAME, gcc
 ifeq		($(CC_NAME), suncc)
 ifeq		($(CC_NAME), suncc)
-			CFLAGS+=-xO5 -fast -native -xarch=v8plusa -xCC \
+			CFLAGS+=-g -xO5 -fast -native -xarch=v8plusa -xCC \
 					-xc99 # C99 support
 					-xc99 # C99 support
 			# -Dinline="" # add this if cc < 5.3 (define inline as null)
 			# -Dinline="" # add this if cc < 5.3 (define inline as null)
 else
 else
@@ -537,7 +543,7 @@ ifeq	($(CC_NAME), icc)
 MOD_CFLAGS=-Kpic $(CFLAGS)
 MOD_CFLAGS=-Kpic $(CFLAGS)
 endif
 endif
 ifeq	($(CC_NAME), suncc)
 ifeq	($(CC_NAME), suncc)
-MOD_CFLAGS=-Kpic  $(CFLAGS)
+MOD_CFLAGS=-xcode=pic32  $(CFLAGS)
 endif
 endif
 
 
 ifeq ($(LEX),)
 ifeq ($(LEX),)

+ 2 - 2
ip_addr.h

@@ -93,8 +93,8 @@ struct socket_info{
 struct receive_info{
 struct receive_info{
 	struct ip_addr src_ip;
 	struct ip_addr src_ip;
 	struct ip_addr dst_ip;
 	struct ip_addr dst_ip;
-	short src_port;
-	short dst_port;
+	unsigned short src_port;
+	unsigned short dst_port;
 	int proto;
 	int proto;
 	int proto_reserved1; /* tcp stores the connection id here */
 	int proto_reserved1; /* tcp stores the connection id here */
 	int proto_reserved2;
 	int proto_reserved2;

+ 41 - 28
lock_ops.h

@@ -37,6 +37,8 @@
  *  2003-03-06  removed *_alloc,*_dealloc & moved them to lock_alloc.h
  *  2003-03-06  removed *_alloc,*_dealloc & moved them to lock_alloc.h
  *              renamed locking.h to lock_ops.h (all this to solve
  *              renamed locking.h to lock_ops.h (all this to solve
  *              the locking.h<->shm_mem.h interdependency) (andrei)
  *              the locking.h<->shm_mem.h interdependency) (andrei)
+ *  2003-03-10  lock set support added also for PTHREAD_MUTEX & POSIX_SEM
+ *               (andrei)
  *
  *
 Implements:
 Implements:
 
 
@@ -66,11 +68,6 @@ WARNING: signals are not treated! (some locks are "awakened" by the signals)
 
 
 typedef fl_lock_t gen_lock_t;
 typedef fl_lock_t gen_lock_t;
 
 
-struct lock_set_t_ {
-	long size;
-	gen_lock_t* locks;
-}; /* must be  aligned (32 bits or 64 depending on the arch)*/
-typedef struct lock_set_t_ lock_set_t;
 
 
 #define lock_destroy(lock) /* do nothing */ 
 #define lock_destroy(lock) /* do nothing */ 
 
 
@@ -83,21 +80,6 @@ inline static gen_lock_t* lock_init(gen_lock_t* lock)
 #define lock_get(lock) get_lock(lock)
 #define lock_get(lock) get_lock(lock)
 #define lock_release(lock) release_lock(lock)
 #define lock_release(lock) release_lock(lock)
 
 
-/* lock sets */
-
-#define lock_set_destroy(lock_set) /* do nothing */
-
-inline static lock_set_t* lock_set_init(lock_set_t* s)
-{
-	int r;
-	for (r=0; r<s->size; r++) lock_init(&s->locks[r]);
-	return s;
-}
-
-/* WARNING: no boundary checks!*/
-#define lock_set_get(set, i) lock_get(&set->locks[i])
-#define lock_set_release(set, i) lock_release(&set->locks[i])
-
 #elif defined USE_PTHREAD_MUTEX
 #elif defined USE_PTHREAD_MUTEX
 #include <pthread.h>
 #include <pthread.h>
 
 
@@ -152,11 +134,6 @@ inline static gen_lock_t* lock_init(gen_lock_t* lock)
 
 
 typedef int gen_lock_t;
 typedef int gen_lock_t;
 
 
-struct lock_set_t_ {
-	int size;
-	int semid;
-};
-typedef struct lock_set_t_ lock_set_t;
 
 
 
 
 
 
@@ -200,8 +177,45 @@ inline static void lock_release(gen_lock_t* lock)
 	semop(*lock, &sop, 1);
 	semop(*lock, &sop, 1);
 }
 }
 
 
+
+#else
+#error "no locking method selected"
+#endif
+
+
 /* lock sets */
 /* lock sets */
 
 
+#if defined(FAST_LOCK) || defined(USE_PTHREAD_MUTEX) || defined(USE_POSIX_SEM)
+
+struct lock_set_t_ {
+	long size;
+	gen_lock_t* locks;
+}; /* must be  aligned (32 bits or 64 depending on the arch)*/
+typedef struct lock_set_t_ lock_set_t;
+
+
+#define lock_set_destroy(lock_set) /* do nothing */
+
+inline static lock_set_t* lock_set_init(lock_set_t* s)
+{
+	int r;
+	for (r=0; r<s->size; r++) if (lock_init(&s->locks[r])==0) return 0;
+	return s;
+}
+
+/* WARNING: no boundary checks!*/
+#define lock_set_get(set, i) lock_get(&set->locks[i])
+#define lock_set_release(set, i) lock_release(&set->locks[i])
+
+#elif defined(USE_SYSV_SEM)
+
+struct lock_set_t_ {
+	int size;
+	int semid;
+};
+
+
+typedef struct lock_set_t_ lock_set_t;
 inline static lock_set_t* lock_set_init(lock_set_t* s)
 inline static lock_set_t* lock_set_init(lock_set_t* s)
 {
 {
 	union semun su;
 	union semun su;
@@ -247,9 +261,8 @@ inline static void lock_set_release(lock_set_t* s, int n)
 	sop.sem_flg=0;
 	sop.sem_flg=0;
 	semop(s->semid, &sop, 1);
 	semop(s->semid, &sop, 1);
 }
 }
-
-#else
-#error "no locking method selected"
+#else 
+#error "no lock set method selected"
 #endif
 #endif
 
 
 
 

+ 9 - 0
mem/mem.h

@@ -26,6 +26,12 @@
  * along with this program; if not, write to the Free Software 
  * along with this program; if not, write to the Free Software 
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
  */
+/*
+ * History:
+ * --------
+ *  2003-03-10  __FUNCTION__ is a gcc-ism, defined it to "" for sun cc
+ *               (andrei)
+ */
 
 
 
 
 
 
@@ -50,6 +56,9 @@
 
 
 
 
 #	ifdef DBG_QM_MALLOC
 #	ifdef DBG_QM_MALLOC
+#ifdef __SUNPRO_C
+		#define __FUNCTION__ ""  /* gcc specific */
+#endif
 #		ifdef VQ_MALLOC
 #		ifdef VQ_MALLOC
 #			define pkg_malloc(s) vqm_malloc(mem_block, (s),__FILE__, \
 #			define pkg_malloc(s) vqm_malloc(mem_block, (s),__FILE__, \
 				__FUNCTION__, __LINE__)
 				__FUNCTION__, __LINE__)

+ 5 - 0
mem/shm_mem.h

@@ -88,6 +88,11 @@ void shm_mem_destroy();
 
 
 #ifdef DBG_QM_MALLOC
 #ifdef DBG_QM_MALLOC
 
 
+#ifdef __SUNPRO_C
+		#define __FUNCTION__ ""  /* gcc specific */
+#endif
+
+
 #define shm_malloc_unsafe(_size ) \
 #define shm_malloc_unsafe(_size ) \
 	MY_MALLOC(shm_block, (_size), __FILE__, __FUNCTION__, __LINE__ )
 	MY_MALLOC(shm_block, (_size), __FILE__, __FUNCTION__, __LINE__ )
 
 

+ 26 - 18
msg_translator.c

@@ -38,7 +38,7 @@
  *             modified via_builder params (andrei)
  *             modified via_builder params (andrei)
  * 2003-01-27 more rport fixes (make use of new via_param->start)  (andrei)
  * 2003-01-27 more rport fixes (make use of new via_param->start)  (andrei)
  * 2003-01-27 next baby-step to removing ZT - PRESERVE_ZT (jiri)
  * 2003-01-27 next baby-step to removing ZT - PRESERVE_ZT (jiri)
- * 2003-01-29 scrathcpad removed (jiri)
+ * 2003-01-29 scratchpad removed (jiri)
  *
  *
  */
  */
 
 
@@ -220,7 +220,7 @@ char* received_builder(struct sip_msg *msg, unsigned int *received_len)
 	}
 	}
 	
 	
 	memcpy(buf+RECEIVED_LEN+extra_len, tmp, tmp_len);
 	memcpy(buf+RECEIVED_LEN+extra_len, tmp, tmp_len);
-	buf[len+1]=0; /*null terminate it */
+	buf[len]=0; /*null terminate it */
 
 
 	*received_len = len;
 	*received_len = len;
 	return buf;
 	return buf;
@@ -237,8 +237,8 @@ char* rport_builder(struct sip_msg *msg, unsigned int *rport_len)
 	
 	
 	tmp_len=0;
 	tmp_len=0;
 	tmp=int2str(ntohs(msg->rcv.src_port), &tmp_len);
 	tmp=int2str(ntohs(msg->rcv.src_port), &tmp_len);
-	len=RPORT_LEN+tmp_len; /* space for null term */
-	buf=pkg_malloc(sizeof(char)*(len+1));
+	len=RPORT_LEN+tmp_len;
+	buf=pkg_malloc(sizeof(char)*(len+1));/* space for null term */
 	if (buf==0){
 	if (buf==0){
 		ser_error=E_OUT_OF_MEM;
 		ser_error=E_OUT_OF_MEM;
 		LOG(L_ERR, "ERROR: rport_builder: out of memory\n");
 		LOG(L_ERR, "ERROR: rport_builder: out of memory\n");
@@ -246,7 +246,7 @@ char* rport_builder(struct sip_msg *msg, unsigned int *rport_len)
 	}
 	}
 	memcpy(buf, RPORT, RPORT_LEN);
 	memcpy(buf, RPORT, RPORT_LEN);
 	memcpy(buf+RPORT_LEN, tmp, tmp_len);
 	memcpy(buf+RPORT_LEN, tmp, tmp_len);
-	buf[len+1]=0; /*null terminate it*/
+	buf[len]=0; /*null terminate it*/
 	
 	
 	*rport_len=len;
 	*rport_len=len;
 	return buf;
 	return buf;
@@ -269,8 +269,8 @@ char* id_builder(struct sip_msg* msg, unsigned int *id_len)
 		return 0;
 		return 0;
 	}
 	}
 	value_len=p-&revhex[0];
 	value_len=p-&revhex[0];
-	len=ID_PARAM_LEN+value_len; /* place for ending \0 */
-	buf=pkg_malloc(sizeof(char)*(len+1));
+	len=ID_PARAM_LEN+value_len; 
+	buf=pkg_malloc(sizeof(char)*(len+1));/* place for ending \0 */
 	if (buf==0){
 	if (buf==0){
 		ser_error=E_OUT_OF_MEM;
 		ser_error=E_OUT_OF_MEM;
 		LOG(L_ERR, "ERROR: rport_builder: out of memory\n");
 		LOG(L_ERR, "ERROR: rport_builder: out of memory\n");
@@ -278,7 +278,7 @@ char* id_builder(struct sip_msg* msg, unsigned int *id_len)
 	}
 	}
 	memcpy(buf, ID_PARAM, ID_PARAM_LEN);
 	memcpy(buf, ID_PARAM, ID_PARAM_LEN);
 	memcpy(buf+ID_PARAM_LEN, revhex, value_len);
 	memcpy(buf+ID_PARAM_LEN, revhex, value_len);
-	buf[len+1]=0; /* null terminate it */
+	buf[len]=0; /* null terminate it */
 	*id_len=len;
 	*id_len=len;
 	return buf;
 	return buf;
 }
 }
@@ -316,7 +316,7 @@ char* clen_builder(struct sip_msg* msg, unsigned int *clen_len)
 	memcpy(buf, CONTENT_LENGTH, CONTENT_LENGTH_LEN);
 	memcpy(buf, CONTENT_LENGTH, CONTENT_LENGTH_LEN);
 	memcpy(buf+CONTENT_LENGTH_LEN, value_s, value_len);
 	memcpy(buf+CONTENT_LENGTH_LEN, value_s, value_len);
 	memcpy(buf+CONTENT_LENGTH_LEN+value_len, CRLF, CRLF_LEN);
 	memcpy(buf+CONTENT_LENGTH_LEN+value_len, CRLF, CRLF_LEN);
-	buf[len+1]=0; /* null terminate it */
+	buf[len]=0; /* null terminate it */
 	*clen_len=len;
 	*clen_len=len;
 	return buf;
 	return buf;
 }
 }
@@ -522,9 +522,9 @@ char * build_req_buf_from_sip_req( struct sip_msg* msg,
 	
 	
 #ifdef USE_TCP
 #ifdef USE_TCP
 	char* id_buf;
 	char* id_buf;
-	int id_len;
+	unsigned int id_len;
 	char* clen_buf;
 	char* clen_buf;
-	int clen_len;
+	unsigned int clen_len;
 	
 	
 	
 	
 	id_buf=0;
 	id_buf=0;
@@ -727,7 +727,7 @@ char * build_res_buf_from_sip_res( struct sip_msg* msg,
 #ifdef USE_TCP
 #ifdef USE_TCP
 	struct lump* anchor;
 	struct lump* anchor;
 	char* clen_buf;
 	char* clen_buf;
-	int clen_len;
+	unsigned int clen_len;
 	
 	
 	clen_buf=0;
 	clen_buf=0;
 	clen_len=0;
 	clen_len=0;
@@ -932,7 +932,10 @@ char * build_res_buf_with_body_from_sip_req( unsigned int code, char *text ,
 				continue;
 				continue;
 			}
 			}
 		} else if (hdr->type==HDR_VIA) {
 		} else if (hdr->type==HDR_VIA) {
+				/* we always add CRLF to via*/
+				len+=(hdr->body.s+hdr->body.len)-hdr->name.s+CRLF_LEN;
 				if (hdr==msg->h_via1) len += received_len+rport_len;
 				if (hdr==msg->h_via1) len += received_len+rport_len;
+				continue;
 		} else if (hdr->type==HDR_RECORDROUTE) {
 		} else if (hdr->type==HDR_RECORDROUTE) {
 				/* RR only for 1xx and 2xx replies */
 				/* RR only for 1xx and 2xx replies */
 				if (code<180 || code>=300) continue;
 				if (code<180 || code>=300) continue;
@@ -941,7 +944,8 @@ char * build_res_buf_with_body_from_sip_req( unsigned int code, char *text ,
 					|| hdr->type==HDR_CSEQ)) {
 					|| hdr->type==HDR_CSEQ)) {
 			continue;
 			continue;
 		}
 		}
-		len += hdr->len;
+		len += hdr->len; /* we keep the original termination for these 
+							headers*/
 	}
 	}
 	len-=delete_len;
 	len-=delete_len;
 	/*lumps length*/
 	/*lumps length*/
@@ -1015,21 +1019,23 @@ char * build_res_buf_with_body_from_sip_req( unsigned int code, char *text ,
 											msg->via1->rport->size, msg);
 											msg->via1->rport->size, msg);
 					}else{
 					}else{
 						/* normal whole via copy */
 						/* normal whole via copy */
-						append_str_trans( p, hdr->name.s ,
-							((hdr->body.s+hdr->body.len )-hdr->name.s ), msg);
+						append_str_trans( p, hdr->name.s , 
+								(hdr->body.s+hdr->body.len)-hdr->name.s, msg);
 					}
 					}
 					if (received_buf)
 					if (received_buf)
 						append_str( p, received_buf, received_len);
 						append_str( p, received_buf, received_len);
 				}else{
 				}else{
 					/* normal whole via copy */
 					/* normal whole via copy */
-					append_str_trans( p, hdr->name.s ,
-						((hdr->body.s+hdr->body.len )-hdr->name.s ),msg);
+					append_str_trans( p, hdr->name.s,
+							(hdr->body.s+hdr->body.len)-hdr->name.s, msg);
 				}
 				}
 				append_str( p, CRLF,CRLF_LEN);
 				append_str( p, CRLF,CRLF_LEN);
 				break;
 				break;
 			case HDR_RECORDROUTE:
 			case HDR_RECORDROUTE:
 				/* RR only for 1xx and 2xx replies */
 				/* RR only for 1xx and 2xx replies */
 				if (code<180 || code>=300) break;
 				if (code<180 || code>=300) break;
+				append_str(p, hdr->name.s, hdr->len);
+				break;
 			case HDR_TO:
 			case HDR_TO:
 				if (new_tag){
 				if (new_tag){
 					if (to_tag.s ) { /* replacement */
 					if (to_tag.s ) { /* replacement */
@@ -1078,7 +1084,6 @@ char * build_res_buf_with_body_from_sip_req( unsigned int code, char *text ,
 		memcpy( p, CRLF, CRLF_LEN );
 		memcpy( p, CRLF, CRLF_LEN );
 		p+=CRLF_LEN;
 		p+=CRLF_LEN;
 	}
 	}
-
 	
 	
 	if (body_len) {
 	if (body_len) {
 		memcpy(p, CONTENT_LENGTH, CONTENT_LENGTH_LEN );
 		memcpy(p, CONTENT_LENGTH, CONTENT_LENGTH_LEN );
@@ -1113,6 +1118,9 @@ char * build_res_buf_with_body_from_sip_req( unsigned int code, char *text ,
 	}
 	}
 	*(p) = 0;
 	*(p) = 0;
 	*returned_len = len;
 	*returned_len = len;
+	DBG("build_*: len=%d, diff=%d\n", len, p-buf);
+	DBG("build_*: rport_len=%d, delete_len=%d\n", rport_len, delete_len);
+	DBG("build_*: message=\n%.*s\n", len, buf);
 	/* in req2reply, received_buf is not introduced to lumps and
 	/* in req2reply, received_buf is not introduced to lumps and
 	   needs to be deleted here
 	   needs to be deleted here
 	*/
 	*/

+ 6 - 6
parser/hf.h

@@ -71,12 +71,12 @@
  * Format: name':' body 
  * Format: name':' body 
  */
  */
 struct hdr_field {   
 struct hdr_field {   
-	int type;                /* Header field type */
-	str name;                /* Header field name */
-	str body;                /* Header field body */
-	int len;				 /* length from body until EoHF (incl. CRLF) */
-	void* parsed;            /* Parsed data structures */
-	struct hdr_field* next;  /* Next header field in the list */
+	int type;               /* Header field type */
+	str name;               /* Header field name */
+	str body;               /* Header field body (may not include CRLF) */
+	int len;				/* length from hdr start until EoHF (incl.CRLF) */
+	void* parsed;           /* Parsed data structures */
+	struct hdr_field* next; /* Next header field in the list */
 };
 };
 
 
 
 

+ 3 - 3
parser/parse_content.c

@@ -41,11 +41,11 @@
  */
  */
 typedef struct type_node_s {
 typedef struct type_node_s {
 	char c;                      /* char contained by this node */
 	char c;                      /* char contained by this node */
-	unsigned char final;         /* says what to be done if the mached string
+	char final;                 /* says what to be done if the matched string
 	                              * ends at this node: -1-> dead end (unknown
 	                              * ends at this node: -1-> dead end (unknown
 	                              * type) or the index of the sub-type that
 	                              * type) or the index of the sub-type that
-	                              * follows (for types) or the  final type (for
-	                              * sub-types)*/
+	                              * follows (for types) or the  final type 
+	                              * (for sub-types)*/
 	unsigned char nr_sons;       /* the number of sub-nodes */
 	unsigned char nr_sons;       /* the number of sub-nodes */
 	int next;                    /* the next sibling node */
 	int next;                    /* the next sibling node */
 }type_node_t;
 }type_node_t;

+ 5 - 3
parser/parse_via.c

@@ -906,7 +906,9 @@ normal_exit:
 	*pstate=state;
 	*pstate=state;
 	*psaved_state=saved_state;
 	*psaved_state=saved_state;
 	DBG("Found param type %d, <%.*s> = <%.*s>; state=%d\n", param->type,
 	DBG("Found param type %d, <%.*s> = <%.*s>; state=%d\n", param->type,
-			param->name.len, param->name.s, param->value.len, param->value.s, state);
+			param->name.len, param->name.s, 
+			(param->value.len?param->value.len:3),
+			(param->value.len?param->value.s:"n/a"), state);
 	return tmp;
 	return tmp;
 	
 	
  end_via:
  end_via:
@@ -1863,7 +1865,7 @@ endofpacket:
 	vb->error=PARSE_OK;
 	vb->error=PARSE_OK;
 	vb->bsize=tmp-buffer;
 	vb->bsize=tmp-buffer;
 	if (vb->port_str.s){
 	if (vb->port_str.s){
-		vb->port=str2s((unsigned char*)vb->port_str.s, vb->port_str.len, &err);
+		vb->port=str2s(vb->port_str.s, vb->port_str.len, &err);
 		if (err){
 		if (err){
 					LOG(L_ERR, "ERROR: parse_via: invalid port number <%.*s>\n",
 					LOG(L_ERR, "ERROR: parse_via: invalid port number <%.*s>\n",
 						vb->port_str.len, vb->port_str.s);
 						vb->port_str.len, vb->port_str.s);
@@ -1876,7 +1878,7 @@ nextvia:
 	vb->error=PARSE_OK;
 	vb->error=PARSE_OK;
 	vb->bsize=tmp-buffer;
 	vb->bsize=tmp-buffer;
 	if (vb->port_str.s){
 	if (vb->port_str.s){
-		vb->port=str2s((unsigned char*)vb->port_str.s, vb->port_str.len, &err);
+		vb->port=str2s(vb->port_str.s, vb->port_str.len, &err);
 		if (err){
 		if (err){
 					LOG(L_ERR, "ERROR: parse_via: invalid port number <%.*s>\n",
 					LOG(L_ERR, "ERROR: parse_via: invalid port number <%.*s>\n",
 						vb->port_str.len, vb->port_str.s);
 						vb->port_str.len, vb->port_str.s);

+ 4 - 4
resolve.h

@@ -134,12 +134,12 @@ static inline struct ip_addr* str2ip(str* st)
 	static struct ip_addr ip;
 	static struct ip_addr ip;
 	unsigned char* s;
 	unsigned char* s;
 
 
-	s = st->s;
+	s=(unsigned char*)st->s;
 
 
 	/*init*/
 	/*init*/
 	ip.u.addr32[0]=0;
 	ip.u.addr32[0]=0;
 	i=0;
 	i=0;
-	limit=st->s + st->len;
+	limit=(unsigned char*)(st->s + st->len);
 
 
 	for(;s<limit ;s++){
 	for(;s<limit ;s++){
 		if (*s=='.'){
 		if (*s=='.'){
@@ -187,7 +187,7 @@ static inline struct ip_addr* str2ip6(str* st)
 	unsigned char* s;
 	unsigned char* s;
 	
 	
 	/* init */
 	/* init */
-	s=st->s;
+	s=(unsigned char*)st->s;
 	i=idx1=rest=0;
 	i=idx1=rest=0;
 	double_colon=0;
 	double_colon=0;
 	no_colons=0;
 	no_colons=0;
@@ -195,7 +195,7 @@ static inline struct ip_addr* str2ip6(str* st)
 	ip.len=16;
 	ip.len=16;
 	addr_start=ip.u.addr16;
 	addr_start=ip.u.addr16;
 	addr=addr_start;
 	addr=addr_start;
-	limit=st->s+st->len;
+	limit=(unsigned char*)(st->s+st->len);
 	memset(addr_start, 0 , 8*sizeof(unsigned short));
 	memset(addr_start, 0 , 8*sizeof(unsigned short));
 	memset(addr_end, 0 , 8*sizeof(unsigned short));
 	memset(addr_end, 0 , 8*sizeof(unsigned short));
 	for (; s<limit; s++){
 	for (; s<limit; s++){

+ 11 - 12
route.c

@@ -29,8 +29,9 @@
  *
  *
  * History:
  * History:
  * --------
  * --------
- * 2003-02-28 scratchpad compatibility abandoned (jiri)
- * 2003-01-28 scratchpad removed, src_port introduced (jiri)
+ * 2003-02-28  scratchpad compatibility abandoned (jiri)
+ * 2003-01-28  scratchpad removed, src_port introduced (jiri)
+ * 2003-03-10  updated to the new module exports format (andrei)
  */
  */
 
 
  
  
@@ -141,6 +142,7 @@ static int fix_actions(struct action* a)
 	struct proxy_l* p;
 	struct proxy_l* p;
 	char *tmp;
 	char *tmp;
 	int ret,r;
 	int ret,r;
+	cmd_export_t* cmd;
 	struct sr_module* mod;
 	struct sr_module* mod;
 	str s;
 	str s;
 	
 	
@@ -215,19 +217,16 @@ static int fix_actions(struct action* a)
 				}
 				}
 				break;
 				break;
 			case MODULE_T:
 			case MODULE_T:
-				if ((mod=find_module(t->p1.data, &r))!=0){
-					DBG("fixing %s %s\n", mod->path,
-							mod->exports->cmd_names[r]);
-					if (mod->exports->fixup_pointers[r]){
-						if (mod->exports->param_no[r]>0){
-							ret=mod->exports->fixup_pointers[r](&t->p2.data,
-																1);
+				if ((mod=find_module(t->p1.data, &cmd))!=0){
+					DBG("fixing %s %s\n", mod->path, cmd->name);
+					if (cmd->fixup){
+						if (cmd->param_no>0){
+							ret=cmd->fixup(&t->p2.data, 1);
 							t->p2_type=MODFIXUP_ST;
 							t->p2_type=MODFIXUP_ST;
 							if (ret<0) return ret;
 							if (ret<0) return ret;
 						}
 						}
-						if (mod->exports->param_no[r]>1){
-							ret=mod->exports->fixup_pointers[r](&t->p3.data,
-																2);
+						if (cmd->param_no>1){
+							ret=cmd->fixup(&t->p3.data, 2);
 							t->p3_type=MODFIXUP_ST;
 							t->p3_type=MODFIXUP_ST;
 							if (ret<0) return ret;
 							if (ret<0) return ret;
 						}
 						}

+ 24 - 16
sr_module.c

@@ -23,6 +23,12 @@
  * along with this program; if not, write to the Free Software 
  * along with this program; if not, write to the Free Software 
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
  */
+/*
+ * History:
+ * --------
+ *  2003-03-10  switched to new module_exports format: updated find_export,
+ *               find_export_param, find_module (andrei)
+ */
 
 
 
 
 #include "sr_module.h"
 #include "sr_module.h"
@@ -191,15 +197,15 @@ skip:
 cmd_function find_export(char* name, int param_no)
 cmd_function find_export(char* name, int param_no)
 {
 {
 	struct sr_module* t;
 	struct sr_module* t;
-	int r;
+	cmd_export_t* cmd;
 
 
 	for(t=modules;t;t=t->next){
 	for(t=modules;t;t=t->next){
-		for(r=0;r<t->exports->cmd_no;r++){
-			if((strcmp(name, t->exports->cmd_names[r])==0)&&
-				(t->exports->param_no[r]==param_no) ){
+		for(cmd=t->exports->cmds; cmd && cmd->name; cmd++){
+			if((strcmp(name, cmd->name)==0)&&
+				(cmd->param_no==param_no) ){
 				DBG("find_export: found <%s> in module %s [%s]\n",
 				DBG("find_export: found <%s> in module %s [%s]\n",
 						name, t->exports->name, t->path);
 						name, t->exports->name, t->path);
-				return t->exports->cmd_pointers[r];
+				return cmd->function;
 			}
 			}
 		}
 		}
 	}
 	}
@@ -211,16 +217,16 @@ cmd_function find_export(char* name, int param_no)
 void* find_param_export(char* mod, char* name, modparam_t type)
 void* find_param_export(char* mod, char* name, modparam_t type)
 {
 {
 	struct sr_module* t;
 	struct sr_module* t;
-	int r;
+	param_export_t* param;
 
 
 	for(t = modules; t; t = t->next) {
 	for(t = modules; t; t = t->next) {
 		if (strcmp(mod, t->exports->name) == 0) {
 		if (strcmp(mod, t->exports->name) == 0) {
-			for(r = 0; r < t->exports->par_no; r++) {
-				if ((strcmp(name, t->exports->param_names[r]) == 0) &&
-				    (t->exports->param_types[r] == type)) {
+			for(param=t->exports->params;param && param->name ; param++) {
+				if ((strcmp(name, param->name) == 0) &&
+				    (param->type == type)) {
 					DBG("find_param_export: found <%s> in module %s [%s]\n",
 					DBG("find_param_export: found <%s> in module %s [%s]\n",
 					    name, t->exports->name, t->path);
 					    name, t->exports->name, t->path);
-					return t->exports->param_pointers[r];
+					return param->param_pointer;
 				}
 				}
 			}
 			}
 		}
 		}
@@ -233,15 +239,17 @@ void* find_param_export(char* mod, char* name, modparam_t type)
 
 
 
 
 /* finds a module, given a pointer to a module function *
 /* finds a module, given a pointer to a module function *
- * returns pointer to module, & if i i!=0, *i=the function index */
-struct sr_module* find_module(void* f, int *i)
+ * returns pointer to module, & if  c!=0, *c=pointer to the
+ * function cmd_export structure*/
+struct sr_module* find_module(void* f, cmd_export_t  **c)
 {
 {
 	struct sr_module* t;
 	struct sr_module* t;
-	int r;
+	cmd_export_t* cmd;
+	
 	for (t=modules;t;t=t->next){
 	for (t=modules;t;t=t->next){
-		for(r=0;r<t->exports->cmd_no;r++) 
-			if (f==(void*)t->exports->cmd_pointers[r]) {
-				if (i) *i=r;
+		for(cmd=t->exports->cmds; cmd && cmd->name; cmd++) 
+			if (f==(void*)cmd->function) {
+				if (c) *c=cmd;
 				return t;
 				return t;
 			}
 			}
 	}
 	}

+ 44 - 24
sr_module.h

@@ -26,6 +26,12 @@
  * along with this program; if not, write to the Free Software 
  * along with this program; if not, write to the Free Software 
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
  */
+/*
+ * History:
+ * --------
+ *  2003-03-10  changed module exports interface: added struct cmd_export
+ *               and param_export (andrei)
+ */
 
 
 
 
 #ifndef sr_module_h
 #ifndef sr_module_h
@@ -49,49 +55,63 @@ typedef enum {
 } modparam_t;       /* Allowed types of parameters */
 } modparam_t;       /* Allowed types of parameters */
 
 
 
 
+struct cmd_export_ {
+	char* name;             /* null terminated command name */
+	cmd_function function;  /* pointer to the corresponding function */
+	int param_no;           /* number of parameters used by the function */
+	fixup_function fixup;   /* pointer to the function called to "fix" the
+							   parameters */
+};
+
+
+struct param_export_ {
+	char* name;             /* null terminated param. name */
+	modparam_t type;        /* param. type */
+	void* param_pointer;    /* pointer to the param. memory location */
+};
+
+
+typedef struct cmd_export_ cmd_export_t;
+typedef struct param_export_ param_export_t;
+
 struct module_exports{
 struct module_exports{
 	char* name;                     /* null terminated module name */
 	char* name;                     /* null terminated module name */
-	char** cmd_names;               /* cmd names registered by this modules */
-	cmd_function* cmd_pointers;     /* pointers to the corresponding
-									   functions */
-	int* param_no;                  /* number of parameters used
-									   by the function */
-	fixup_function* fixup_pointers; /* pointers to functions called to "fix"
-										the params, e.g: precompile a re */
-	int cmd_no;                     /* number of registered commands
-										(size of cmd_{names,pointers} */
-
-	char** param_names;    /* parameter names registered by this modules */
-	modparam_t* param_types; /* Type of parameters */
-	void** param_pointers; /* Pointers to the corresponding memory locations */
-	int par_no;            /* number of registered parameters */
-
-
-	init_function init_f;         /* Initilization function */
-	response_function response_f; /* function used for responses,
-									returns yes or no; can be null */
-	destroy_function destroy_f;  /* function called when the module should
-									be "destroyed", e.g: on ser exit;
-									can be null */
+	
+	cmd_export_t* cmds;             /* null terminated array of the exported
+									   commands */
+	param_export_t* params;         /* null terminated array of the exported
+									   module parameters */
+
+	init_function init_f;           /* Initilization function */
+	response_function response_f;   /* function used for responses,
+									   returns yes or no; can be null */
+	destroy_function destroy_f;     /* function called when the module should
+									   be "destroyed", e.g: on ser exit;
+									   can be null */
 	onbreak_function onbreak_f;
 	onbreak_function onbreak_f;
 	child_init_function init_child_f;  /* function called by all processes
 	child_init_function init_child_f;  /* function called by all processes
 										  after the fork */
 										  after the fork */
 };
 };
 
 
+
+
+
+
 struct sr_module{
 struct sr_module{
 	char* path;
 	char* path;
 	void* handle;
 	void* handle;
 	struct module_exports* exports;
 	struct module_exports* exports;
 	struct sr_module* next;
 	struct sr_module* next;
 };
 };
- 
+
+
 struct sr_module* modules; /* global module list*/
 struct sr_module* modules; /* global module list*/
 
 
 int register_builtin_modules();
 int register_builtin_modules();
 int register_module(struct module_exports*, char*,  void*);
 int register_module(struct module_exports*, char*,  void*);
 int load_module(char* path);
 int load_module(char* path);
 cmd_function find_export(char* name, int param_no);
 cmd_function find_export(char* name, int param_no);
-struct sr_module* find_module(void *f, int* r);
+struct sr_module* find_module(void *f, cmd_export_t** cmd);
 void destroy_modules();
 void destroy_modules();
 int init_child(int rank);
 int init_child(int rank);
 int init_modules(void);
 int init_modules(void);

+ 0 - 1
tcp_main.c

@@ -515,7 +515,6 @@ static int send2child(struct tcp_connection* tcpconn)
 			idx=i;
 			idx=i;
 			min_busy=0;
 			min_busy=0;
 			break;
 			break;
-			return 0;
 		}else if (min_busy>tcp_children[i].busy){
 		}else if (min_busy>tcp_children[i].busy){
 			min_busy=tcp_children[i].busy;
 			min_busy=tcp_children[i].busy;
 			idx=i;
 			idx=i;

+ 2 - 2
test/th-uri-fast.cfg

@@ -5,10 +5,10 @@
 #
 #
 
 
 
 
-debug=3          # debug level (cmd line: -dddddddddd)
+#debug=3          # debug level (cmd line: -dddddddddd)
 #fork=yes          # (cmd. line: -D)
 #fork=yes          # (cmd. line: -D)
 #fork=no
 #fork=no
-log_stderror=yes # (cmd line: -E)
+#log_stderror=yes # (cmd line: -E)
 #log_stderror=no	# (cmd line: -E)
 #log_stderror=no	# (cmd line: -E)
 
 
 
 

+ 4 - 2
ut.h

@@ -94,15 +94,17 @@ static char fourbits2char[16] = { '0', '1', '2', '3', '4', '5',
 /* converts a str to an u. short, returns the u. short and sets *err on
 /* converts a str to an u. short, returns the u. short and sets *err on
  * error and if err!=null
  * error and if err!=null
   */
   */
-static inline unsigned short str2s(unsigned char* str, unsigned int len,
+static inline unsigned short str2s(char* s, unsigned int len,
 									int *err)
 									int *err)
 {
 {
 	unsigned short ret;
 	unsigned short ret;
 	int i;
 	int i;
 	unsigned char *limit;
 	unsigned char *limit;
 	unsigned char *init;
 	unsigned char *init;
+	unsigned char* str;
 
 
 	/*init*/
 	/*init*/
+	str=(unsigned char*)s;
 	ret=i=0;
 	ret=i=0;
 	limit=str+len;
 	limit=str+len;
 	init=str;
 	init=str;
@@ -147,7 +149,7 @@ static inline int btostr( char *p,  unsigned char val)
 
 
 
 
 
 
-/* returns a pointer to a static buffer containint l in asciiz & sets len */
+/* returns a pointer to a static buffer containing l in asciiz & sets len */
 static inline char* int2str(unsigned int l, int* len)
 static inline char* int2str(unsigned int l, int* len)
 {
 {
 	static char r[11]; /* 10 digits + 0 */
 	static char r[11]; /* 10 digits + 0 */