浏览代码

- compile fixes: ser & tm + tcp compiles on linux, freebsd, openbsd & netbsd

Andrei Pelinescu-Onciul 22 年之前
父节点
当前提交
b988daef50
共有 11 个文件被更改,包括 45 次插入31 次删除
  1. 2 1
      Makefile.defs
  2. 5 2
      fifo_server.c
  3. 2 2
      main.c
  4. 5 5
      modules/tm/tm.c
  5. 3 2
      parser/msg_parser.c
  6. 3 3
      parser/parse_content.c
  7. 2 2
      parser/parse_content.h
  8. 6 5
      pass_fd.c
  9. 1 1
      route.c
  10. 8 2
      tcp_main.c
  11. 8 6
      tcp_read.c

+ 2 - 1
Makefile.defs

@@ -530,7 +530,8 @@ LIBS= -lfl -ldl -lresolv
 
 #os specific stuff
 ifeq ($(OS), linux)
-	DEFS+=-DHAVE_GETHOSTBYNAME2 -DHAVE_UNION_SEMUN -DHAVE_SCHED_YIELD
+	DEFS+=-DHAVE_GETHOSTBYNAME2 -DHAVE_UNION_SEMUN -DHAVE_SCHED_YIELD \
+			-DHAVE_MSG_NOSIGNAL
 	ifneq ($(found_lock_method), yes)
 		DEFS+= -DUSE_SYSV_SEM  # try posix sems
 		found_lock_method=yes

+ 5 - 2
fifo_server.c

@@ -63,13 +63,16 @@
 #include <unistd.h>
 #include <stdio.h>
 #include <errno.h>
-#include <sys/types.h>
 #include <sys/stat.h>
 #include <fcntl.h>
 #include <signal.h>
 #include <string.h>
 #include <time.h>
 #include <stdarg.h>
+#ifdef USE_TCP
+#include <sys/socket.h>
+#endif
+
 #include "dprint.h"
 #include "ut.h"
 #include "error.h"
@@ -512,7 +515,7 @@ int open_fifo_server()
 	}
 	memcpy(up_since_ctime,t,strlen(t)+1);
 #ifdef USE_TCP
-	if (socketpair(AF_LOCAL, SOCK_STREAM, 0, sockfd)<0){
+	if (socketpair(AF_UNIX, SOCK_STREAM, 0, sockfd)<0){
 			LOG(L_ERR, "ERROR: open_fifo_server: socketpair failed: %s\n",
 				strerror(errno));
 			return -1;

+ 2 - 2
main.c

@@ -712,7 +712,7 @@ int main_loop()
 			for(i=0;i<children_no;i++){
 				process_no++;
 #ifdef USE_TCP
-		 		if (socketpair(AF_LOCAL, SOCK_STREAM, 0, sockfd)<0){
+		 		if (socketpair(AF_UNIX, SOCK_STREAM, 0, sockfd)<0){
 					LOG(L_ERR, "ERROR: main_loop: socketpair failed: %s\n",
 						strerror(errno));
 					goto error;
@@ -770,7 +770,7 @@ int main_loop()
 #endif
 	{
 #ifdef USE_TCP
- 		if (socketpair(AF_LOCAL, SOCK_STREAM, 0, sockfd)<0){
+ 		if (socketpair(AF_UNIX, SOCK_STREAM, 0, sockfd)<0){
 			LOG(L_ERR, "ERROR: main_loop: socketpair failed: %s\n",
 				strerror(errno));
 			goto error;

+ 5 - 5
modules/tm/tm.c

@@ -355,7 +355,7 @@ struct module_exports exports= {
 
 inline static int fixup_str2int( void** param, int param_no)
 {
-	unsigned int go_to;
+	unsigned long go_to;
 	int err;
 
 	if (param_no==1) {
@@ -530,7 +530,7 @@ inline static int fixup_hostport2proxy(void** param, int param_no)
 /* (char *code, char *reason_phrase)==>(int code, r_p as is) */
 inline static int fixup_t_send_reply(void** param, int param_no)
 {
-	unsigned int code;
+	unsigned long code;
 	int err;
 
 	if (param_no==1){
@@ -619,9 +619,9 @@ inline static int w_t_reply(struct sip_msg* msg, char* str, char* str2)
 	 */
 	if (rmode==MODE_ONREPLY_REQUEST) { 
 		DBG("DEBUG: t_reply_unsafe called from w_t_reply\n");
-		return t_reply_unsafe(t, msg, (unsigned int) str, str2);
+		return t_reply_unsafe(t, msg, (unsigned int)(long) str, str2);
 	} else {
-		return t_reply( t, msg, (unsigned int) str, str2);
+		return t_reply( t, msg, (unsigned int)(long) str, str2);
 	}
 }
 
@@ -698,7 +698,7 @@ inline static int w_t_newtran( struct sip_msg* p_msg, char* foo, char* bar )
 
 inline static int w_t_on_negative( struct sip_msg* msg, char *go_to, char *foo )
 {
-	return t_on_negative( (unsigned int ) go_to );
+	return t_on_negative( (unsigned int )(long) go_to );
 }
 
 inline static int w_t_relay_to( struct sip_msg  *p_msg , 

+ 3 - 2
parser/msg_parser.c

@@ -173,9 +173,10 @@ char* get_hdr_field(char* buf, char* end, struct hdr_field* hdr)
 				LOG(L_ERR, "ERROR:get_hdr_field: bad content_length header\n");
 				goto error;
 			}
-			hdr->parsed=(void*)integer;
+			hdr->parsed=(void*)(long)integer;
 			hdr->body.len=tmp-hdr->body.s;
-			DBG("DEBUG: get_hdr_body : content_length=%d\n",(int)hdr->parsed);
+			DBG("DEBUG: get_hdr_body : content_length=%d\n",
+					(int)(long)hdr->parsed);
 			break;
 		case HDR_CONTENTTYPE:
 		case HDR_FROM:

+ 3 - 3
parser/parse_content.c

@@ -117,7 +117,7 @@ int parse_content_type_hdr( struct sip_msg *msg )
 			{'p',CONTENT_TYPE_APPLICATION_SDP,0,-1},
 	};
 	int node;
-	int mime;
+	long mime;
 	char *mark;
 	char *p, *end;
 
@@ -203,11 +203,11 @@ int parse_content_type_hdr( struct sip_msg *msg )
 		goto error;
 
 	mime = ((mime==-1)?CONTENT_TYPE_UNKNOWN:mime);
-	(int)(msg->content_type->parsed) = mime;
+	msg->content_type->parsed = (void*)mime;
 	return mime;
 error:
 	LOG(L_ERR,"ERROR:parse_content_type: parse error near char [%d][%c] "
-		"offset=%d\n",*p,*p,p-msg->content_type->body.s);
+		"offset=%d\n",*p,*p,(int)(p-msg->content_type->body.s));
 	return -1;
 }
 

+ 2 - 2
parser/parse_content.h

@@ -45,13 +45,13 @@
 /*
  * returns the content-length value of a sip_msg as an integer
  */
-#define get_content_length(_msg_)   ((int)((_msg_)->content_length->parsed))
+#define get_content_length(_msg_)   ((long)((_msg_)->content_length->parsed))
 
 
 /*
  * returns the content-type value of a sip_msg as an integer
  */
-#define get_content_type(_msg_)   ((int)((_msg_)->content_type->parsed))
+#define get_content_type(_msg_)   ((long)((_msg_)->content_type->parsed))
 
 
 

+ 6 - 5
pass_fd.c

@@ -29,9 +29,10 @@
 
 #include <sys/types.h>
 #include <sys/socket.h>
+#include <sys/uio.h>
+#include <stdlib.h> /* for NULL definition on openbsd */
 
-/* remove this after replacing fprintf*/
-#include <stdio.h>
+#include "dprint.h"
 
 
 /* at least 1 byte must be sent! */
@@ -100,18 +101,18 @@ int receive_fd(int unix_socket, void* data, int data_len, int* fd)
 	cmsg=CMSG_FIRSTHDR(&msg);
 	if ((cmsg!=0) && (cmsg->cmsg_len==CMSG_LEN(sizeof(new_fd)))){
 		if (cmsg->cmsg_type!= SCM_RIGHTS){
-			fprintf(stderr, " msg control type != SCM_RIGHTS\n");
+			LOG(L_ERR, "receive_fd: msg control type != SCM_RIGHTS\n");
 			ret=-1;
 			goto error;
 		}
 		if (cmsg->cmsg_level!= SOL_SOCKET){
-			fprintf(stderr, " msg level != SOL_SOCKET\n");
+			LOG(L_ERR, "receive_fd: msg level != SOL_SOCKET\n");
 			ret=-1;
 			goto error;
 		}
 		*fd=*((int*) CMSG_DATA(cmsg));
 	}else{
-		fprintf(stderr, " no descriptor passed, cmsg=%p, len=%d\n",
+		LOG(L_ERR, "receive_fd: no descriptor passed, cmsg=%p, len=%d\n",
 				cmsg, cmsg->cmsg_len);
 		*fd=-1;
 		/* it's not really an error */

+ 1 - 1
route.c

@@ -249,7 +249,7 @@ static int comp_port( int port, void *param, int op, int subtype )
 		LOG(L_CRIT, "BUG: comp_port: number expected: %d\n", subtype );
 		return E_BUG;
 	}
-	return port==(int)param;
+	return port==(long)param;
 }
 
 /* eval_elem helping function, returns str op param */

+ 8 - 2
tcp_main.c

@@ -33,10 +33,10 @@
 #error "shared memory support needed (add -DSHM_MEM to Makefile.defs)"
 #endif
 
-#include <sys/select.h>
 
 #include <sys/time.h>
 #include <sys/types.h>
+#include <sys/select.h>
 #include <sys/socket.h>
 #include <sys/uio.h>  /* writev*/
 
@@ -348,7 +348,13 @@ get_fd:
 send_it:
 	DBG("tcp_send: sending...\n");
 	lock_get(&c->write_lock);
-	n=send(fd, buf, len, MSG_NOSIGNAL);
+	n=send(fd, buf, len,
+#ifdef HAVE_MSG_NOSIGNAL
+			MSG_NOSIGNAL
+#else
+			0
+#endif
+			);
 	lock_release(&c->write_lock);
 	DBG("tcp_send: after write: c= %p n=%d fd=%d\n",c, n, fd);
 	DBG("tcp_send: buf=\n%.*s\n", (int)len, buf);

+ 8 - 6
tcp_read.c

@@ -37,10 +37,10 @@
 #include <errno.h>
 #include <string.h>
 
-#include <sys/select.h>
 
 #include <sys/time.h>
 #include <sys/types.h>
+#include <sys/select.h>
 #include <sys/socket.h>
 
 #include <unistd.h>
@@ -368,9 +368,11 @@ again:
 			bytes=tcp_read_headers(req, s);
 						/* if timeout state=0; goto end__req; */
 			DBG("read= %d bytes, parsed=%d, state=%d, error=%d\n",
-					bytes, req->parsed-req->start, req->state, req->error );
+					bytes, (int)(req->parsed-req->start), req->state,
+					req->error );
 			DBG("tcp_read_req: last char=%X, parsed msg=\n%.*s\n",
-					*(req->parsed-1), req->parsed-req->start, req->start);
+					*(req->parsed-1), (int)(req->parsed-req->start),
+					req->start);
 			if (bytes==-1){
 				LOG(L_ERR, "ERROR: tcp_read_req: error reading \n");
 				resp=CONN_ERROR;
@@ -386,8 +388,8 @@ again:
 		if (req->error!=TCP_REQ_OK){
 			LOG(L_ERR,"ERROR: tcp_read_req: bad request, state=%d, error=%d "
 					  "buf:\n%.*s\nparsed:\n%.*s\n", req->state, req->error,
-					  req->pos-req->buf, req->buf,
-					  req->parsed-req->start, req->start);
+					  (int)(req->pos-req->buf), req->buf,
+					  (int)(req->parsed-req->start), req->start);
 			DBG("- received from: port %d, ip -", ntohs(con->rcv.src_port));
 			print_ip(&con->rcv.src_ip); DBG("-\n");
 			resp=CONN_ERROR;
@@ -398,7 +400,7 @@ again:
 			DBG("- received from: port %d, ip - ", ntohs(con->rcv.src_port));
 			print_ip(&con->rcv.src_ip); DBG("-\n");
 			DBG("tcp_read_req: headers:\n%.*s.\n",
-					req->body-req->start, req->start);
+					(int)(req->body-req->start), req->start);
 			if (req->has_content_len){
 				DBG("tcp_read_req: content-length= %d\n", req->content_len);
 				DBG("tcp_read_req: body:\n%.*s\n", req->content_len,req->body);