Browse code

core, lib, modules: restructured source code tree

- new folder src/ to hold the source code for main project applications
- main.c is in src/
- all core files are subfolder are in src/core/
- modules are in src/modules/
- libs are in src/lib/
- application Makefiles are in src/
- application binary is built in src/ (src/kamailio)

Daniel-Constantin Mierla authored on 07/12/2016 11:03:51
Showing 1 changed files
1 1
deleted file mode 100644
... ...
@@ -1,326 +0,0 @@
1
-/*
2
- * Copyright (C) 2001-2003 FhG Fokus
3
- *
4
- * This file is part of Kamailio, a free SIP server.
5
- *
6
- * Kamailio is free software; you can redistribute it and/or modify
7
- * it under the terms of the GNU General Public License as published by
8
- * the Free Software Foundation; either version 2 of the License, or
9
- * (at your option) any later version
10
- *
11
- * Kamailio is distributed in the hope that it will be useful,
12
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
- * GNU General Public License for more details.
15
- *
16
- * You should have received a copy of the GNU General Public License
17
- * along with this program; if not, write to the Free Software
18
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
19
- */
20
-
21
-/*!
22
- * \file
23
- * \brief Kamailio core ::
24
- * \ingroup core
25
- * Module: \ref core
26
- */
27
-
28
-#ifdef USE_TCP
29
-
30
-#include "pass_fd.h"
31
-
32
-#include <sys/types.h>
33
-#include <sys/socket.h>
34
-#include <sys/uio.h>
35
-#include <stdlib.h> /* for NULL definition on openbsd */
36
-#include <errno.h>
37
-#include <string.h>
38
-#ifdef NO_MSG_WAITALL
39
-#include <poll.h>
40
-#endif /* NO_MSG_WAITALL */
41
-
42
-#include "dprint.h"
43
-
44
-
45
-
46
-/** receive all the data or returns error (handles EINTR etc.)
47
- * params: socket
48
- *         data     - buffer for the results
49
- *         data_len -
50
- *         flags    - recv flags for the first recv (see recv(2)), only
51
- *                    0, MSG_WAITALL and MSG_DONTWAIT make sense
52
- * if flags is set to MSG_DONWAIT (or to 0 and the socket fd is non-blocking),
53
- * and if no data is queued on the fd, recv_all will not wait (it will
54
- * return error and set errno to EAGAIN/EWOULDBLOCK). However if even 1 byte
55
- *  is queued, the call will block until the whole data_len was read or an
56
- *  error or eof occurred ("semi-nonblocking" behaviour,  some tcp code
57
- *   counts on it).
58
- * if flags is set to MSG_WAITALL it will block even if no byte is available.
59
- *
60
- * returns: bytes read or error (<0)
61
- * can return < data_len if EOF */
62
-int recv_all(int socket, void* data, int data_len, int flags)
63
-{
64
-	int b_read;
65
-	int n;
66
-#ifdef NO_MSG_WAITALL
67
-	struct pollfd pfd;
68
-#endif /* NO_MSG_WAITALL */
69
-
70
-	b_read=0;
71
-again:
72
-#ifdef NO_MSG_WAITALL
73
-	if (flags & MSG_WAITALL){
74
-		n=-1;
75
-		goto poll_recv; /* simulate MSG_WAITALL */
76
-	}
77
-#endif /* NO_MSG_WAITALL */
78
-	n=recv(socket, (char*)data, data_len, flags);
79
-	if (n<0){
80
-		/* error */
81
-		if (errno==EINTR) goto again; /* signal, try again */
82
-		/* on EAGAIN just return (let the caller know) */
83
-		if ((errno==EAGAIN)||(errno==EWOULDBLOCK)) return n;
84
-			LM_CRIT("1st recv on %d failed: %s\n",
85
-					socket, strerror(errno));
86
-			return n;
87
-	}
88
-	b_read+=n;
89
-	while( (b_read!=data_len) && (n)){
90
-#ifdef NO_MSG_WAITALL
91
-		/* cygwin & win do not support MSG_WAITALL => workaround using poll */
92
-poll_recv:
93
-		n=recv(socket, (char*)data+b_read, data_len-b_read, 0);
94
-#else /* NO_MSG_WAITALL */
95
-		n=recv(socket, (char*)data+b_read, data_len-b_read, MSG_WAITALL);
96
-#endif /* NO_MSG_WAITALL */
97
-		if (n<0){
98
-			/* error */
99
-			if (errno==EINTR) continue; /* signal, try again */
100
-#ifdef NO_MSG_WAITALL
101
-			if (errno==EAGAIN || errno==EWOULDBLOCK){
102
-				/* emulate MSG_WAITALL using poll */
103
-				pfd.fd=socket;
104
-				pfd.events=POLLIN;
105
-poll_retry:
106
-				n=poll(&pfd, 1, -1);
107
-				if (n<0){
108
-					if (errno==EINTR) goto poll_retry;
109
-					LM_CRIT("poll on %d failed: %s\n",
110
-						socket, strerror(errno));
111
-					return n;
112
-				} else continue; /* try recv again */
113
-			}
114
-#endif /* NO_MSG_WAITALL */
115
-			LM_CRIT("2nd recv on %d failed: %s\n",
116
-					socket, strerror(errno));
117
-			return n;
118
-		}
119
-		b_read+=n;
120
-	}
121
-	return b_read;
122
-}
123
-
124
-
125
-
126
-/** sends all data (takes care of signals) (assumes blocking fd)
127
- * returns number of bytes sent or < 0 for an error */
128
-int send_all(int socket, void* data, int data_len)
129
-{
130
-	int n;
131
-
132
-again:
133
-	n=send(socket, data, data_len, 0);
134
-	if (n<0){
135
-			/* error */
136
-		if (errno==EINTR) goto again; /* signal, try again */
137
-		if ((errno!=EAGAIN) &&(errno!=EWOULDBLOCK))
138
-			LM_CRIT("send on %d failed: %s\n",
139
-					socket, strerror(errno));
140
-	}
141
-	return n;
142
-}
143
-
144
-
145
-/** at least 1 byte must be sent! */
146
-int send_fd(int unix_socket, void* data, int data_len, int fd)
147
-{
148
-	struct msghdr msg;
149
-	struct iovec iov[1];
150
-	int ret;
151
-#ifdef HAVE_MSGHDR_MSG_CONTROL
152
-	int* pi;
153
-	struct cmsghdr* cmsg;
154
-	/* make sure msg_control will point to properly aligned data */
155
-	union {
156
-		struct cmsghdr cm;
157
-		char control[CMSG_SPACE(sizeof(fd))];
158
-	}control_un;
159
-
160
-	memset(&msg, 0, sizeof(struct msghdr));
161
-	msg.msg_control=control_un.control;
162
-	/* openbsd doesn't like "more space", msg_controllen must not
163
-	 * include the end padding */
164
-	msg.msg_controllen=CMSG_LEN(sizeof(fd));
165
-
166
-	cmsg=CMSG_FIRSTHDR(&msg);
167
-	cmsg->cmsg_level = SOL_SOCKET;
168
-	cmsg->cmsg_type = SCM_RIGHTS;
169
-	cmsg->cmsg_len = CMSG_LEN(sizeof(fd));
170
-	pi=(int*)CMSG_DATA(cmsg);
171
-	*pi=fd;
172
-	msg.msg_flags=0;
173
-#else
174
-	msg.msg_accrights=(caddr_t) &fd;
175
-	msg.msg_accrightslen=sizeof(fd);
176
-#endif
177
-
178
-	msg.msg_name=0;
179
-	msg.msg_namelen=0;
180
-
181
-	iov[0].iov_base=data;
182
-	iov[0].iov_len=data_len;
183
-	msg.msg_iov=iov;
184
-	msg.msg_iovlen=1;
185
-
186
-again:
187
-	ret=sendmsg(unix_socket, &msg, 0);
188
-	if (ret<0){
189
-		if (errno==EINTR) goto again;
190
-		if ((errno!=EAGAIN) && (errno!=EWOULDBLOCK))
191
-			LM_CRIT("sendmsg failed sending %d on %d: %s (%d)\n",
192
-				fd, unix_socket, strerror(errno), errno);
193
-	}
194
-
195
-	return ret;
196
-}
197
-
198
-
199
-
200
-/** receives a fd and data_len data
201
- * params: unix_socket
202
- *         data
203
- *         data_len
204
- *         fd         - will be set to the passed fd value or -1 if no fd
205
- *                      was passed
206
- *         flags      - 0, MSG_DONTWAIT, MSG_WAITALL; same as recv_all flags
207
- * returns: bytes read on success, -1 on error (and sets errno) */
208
-int receive_fd(int unix_socket, void* data, int data_len, int* fd, int flags)
209
-{
210
-	struct msghdr msg;
211
-	struct iovec iov[1];
212
-	int new_fd;
213
-	int ret;
214
-	int n;
215
-#ifdef NO_MSG_WAITALL
216
-	struct pollfd pfd;
217
-	int f;
218
-#endif /*NO_MSG_WAITALL */
219
-#ifdef HAVE_MSGHDR_MSG_CONTROL
220
-	int* pi;
221
-	struct cmsghdr* cmsg;
222
-	union{
223
-		struct cmsghdr cm;
224
-		char control[CMSG_SPACE(sizeof(new_fd))];
225
-	}control_un;
226
-
227
-	memset(&msg, 0, sizeof(struct msghdr));
228
-	msg.msg_control=control_un.control;
229
-	msg.msg_controllen=sizeof(control_un.control);
230
-#else
231
-	msg.msg_accrights=(caddr_t) &new_fd;
232
-	msg.msg_accrightslen=sizeof(int);
233
-#endif
234
-
235
-	msg.msg_name=0;
236
-	msg.msg_namelen=0;
237
-
238
-	iov[0].iov_base=data;
239
-	iov[0].iov_len=data_len;
240
-	msg.msg_iov=iov;
241
-	msg.msg_iovlen=1;
242
-
243
-#ifdef NO_MSG_WAITALL
244
-	f=flags & ~MSG_WAITALL;
245
-#endif /* NO_MSG_WAITALL */
246
-
247
-again:
248
-#ifdef NO_MSG_WAITALL
249
-		ret=recvmsg(unix_socket, &msg, f);
250
-#else /* NO_MSG_WAITALL */
251
-		ret=recvmsg(unix_socket, &msg, flags);
252
-#endif /* NO_MSG_WAITALL */
253
-	if (ret<0){
254
-		if (errno==EINTR) goto again;
255
-		if ((errno==EAGAIN)||(errno==EWOULDBLOCK)){
256
-#ifdef NO_MSG_WAITALL
257
-			if (flags & MSG_WAITALL){
258
-				/* emulate MSG_WAITALL using poll */
259
-				pfd.fd=unix_socket;
260
-				pfd.events=POLLIN;
261
-poll_again:
262
-				ret=poll(&pfd, 1, -1);
263
-				if (ret>=0) goto again;
264
-				else if (errno==EINTR) goto poll_again;
265
-				LM_CRIT("poll on %d failed: %s\n",
266
-					unix_socket, strerror(errno));
267
-			}
268
-#endif /* NO_MSG_WAITALL */
269
-			goto error;
270
-		}
271
-		LM_CRIT("recvmsg on %d failed: %s\n",
272
-				unix_socket, strerror(errno));
273
-		goto error;
274
-	}
275
-	if (ret==0){
276
-		/* EOF */
277
-		LM_CRIT("EOF on %d\n", unix_socket);
278
-		goto error;
279
-	}
280
-	if (ret<data_len){
281
-		LM_WARN("too few bytes read (%d from %d) trying to fix...\n",
282
-				ret, data_len);
283
-		/* blocking recv_all */
284
-		n=recv_all(unix_socket, (char*)data+ret, data_len-ret, MSG_WAITALL);
285
-		if (n>=0) ret+=n;
286
-		else{
287
-			ret=n;
288
-			goto error;
289
-		}
290
-	}
291
-
292
-#ifdef HAVE_MSGHDR_MSG_CONTROL
293
-	cmsg=CMSG_FIRSTHDR(&msg);
294
-	if ((cmsg!=0) && (cmsg->cmsg_len==CMSG_LEN(sizeof(new_fd)))){
295
-		if (cmsg->cmsg_type!= SCM_RIGHTS){
296
-			LM_ERR("msg control type != SCM_RIGHTS\n");
297
-			ret=-1;
298
-			goto error;
299
-		}
300
-		if (cmsg->cmsg_level!= SOL_SOCKET){
301
-			LM_ERR("msg level != SOL_SOCKET\n");
302
-			ret=-1;
303
-			goto error;
304
-		}
305
-		pi=(int*) CMSG_DATA(cmsg);
306
-		*fd=*pi;
307
-	}else{
308
-		/*LM_ERR("no descriptor passed, cmsg=%p, len=%d\n",
309
-			cmsg, (unsigned)cmsg->cmsg_len); */
310
-		*fd=-1;
311
-		/* it's not really an error */
312
-	}
313
-#else
314
-	if (msg.msg_accrightslen==sizeof(int)){
315
-		*fd=new_fd;
316
-	}else{
317
-		/*LM_ERR("no descriptor passed, accrightslen=%d\n",
318
-			msg.msg_accrightslen); */
319
-		*fd=-1;
320
-	}
321
-#endif
322
-
323
-error:
324
-	return ret;
325
-}
326
-#endif
Browse code

core: init structure to 0 for pass fd operations

Daniel-Constantin Mierla authored on 02/11/2016 14:26:53
Showing 1 changed files
... ...
@@ -20,7 +20,7 @@
20 20
 
21 21
 /*!
22 22
  * \file
23
- * \brief Kamailio core :: 
23
+ * \brief Kamailio core ::
24 24
  * \ingroup core
25 25
  * Module: \ref core
26 26
  */
... ...
@@ -46,17 +46,17 @@
46 46
 /** receive all the data or returns error (handles EINTR etc.)
47 47
  * params: socket
48 48
  *         data     - buffer for the results
49
- *         data_len - 
49
+ *         data_len -
50 50
  *         flags    - recv flags for the first recv (see recv(2)), only
51 51
  *                    0, MSG_WAITALL and MSG_DONTWAIT make sense
52 52
  * if flags is set to MSG_DONWAIT (or to 0 and the socket fd is non-blocking),
53
- * and if no data is queued on the fd, recv_all will not wait (it will 
53
+ * and if no data is queued on the fd, recv_all will not wait (it will
54 54
  * return error and set errno to EAGAIN/EWOULDBLOCK). However if even 1 byte
55 55
  *  is queued, the call will block until the whole data_len was read or an
56 56
  *  error or eof occurred ("semi-nonblocking" behaviour,  some tcp code
57 57
  *   counts on it).
58 58
  * if flags is set to MSG_WAITALL it will block even if no byte is available.
59
- *  
59
+ *
60 60
  * returns: bytes read or error (<0)
61 61
  * can return < data_len if EOF */
62 62
 int recv_all(int socket, void* data, int data_len, int flags)
... ...
@@ -66,7 +66,7 @@ int recv_all(int socket, void* data, int data_len, int flags)
66 66
 #ifdef NO_MSG_WAITALL
67 67
 	struct pollfd pfd;
68 68
 #endif /* NO_MSG_WAITALL */
69
-	
69
+
70 70
 	b_read=0;
71 71
 again:
72 72
 #ifdef NO_MSG_WAITALL
... ...
@@ -104,7 +104,7 @@ poll_recv:
104 104
 				pfd.events=POLLIN;
105 105
 poll_retry:
106 106
 				n=poll(&pfd, 1, -1);
107
-				if (n<0){ 
107
+				if (n<0){
108 108
 					if (errno==EINTR) goto poll_retry;
109 109
 					LM_CRIT("poll on %d failed: %s\n",
110 110
 						socket, strerror(errno));
... ...
@@ -128,7 +128,7 @@ poll_retry:
128 128
 int send_all(int socket, void* data, int data_len)
129 129
 {
130 130
 	int n;
131
-	
131
+
132 132
 again:
133 133
 	n=send(socket, data, data_len, 0);
134 134
 	if (n<0){
... ...
@@ -156,12 +156,13 @@ int send_fd(int unix_socket, void* data, int data_len, int fd)
156 156
 		struct cmsghdr cm;
157 157
 		char control[CMSG_SPACE(sizeof(fd))];
158 158
 	}control_un;
159
-	
159
+
160
+	memset(&msg, 0, sizeof(struct msghdr));
160 161
 	msg.msg_control=control_un.control;
161 162
 	/* openbsd doesn't like "more space", msg_controllen must not
162 163
 	 * include the end padding */
163 164
 	msg.msg_controllen=CMSG_LEN(sizeof(fd));
164
-	
165
+
165 166
 	cmsg=CMSG_FIRSTHDR(&msg);
166 167
 	cmsg->cmsg_level = SOL_SOCKET;
167 168
 	cmsg->cmsg_type = SCM_RIGHTS;
... ...
@@ -173,15 +174,15 @@ int send_fd(int unix_socket, void* data, int data_len, int fd)
173 174
 	msg.msg_accrights=(caddr_t) &fd;
174 175
 	msg.msg_accrightslen=sizeof(fd);
175 176
 #endif
176
-	
177
+
177 178
 	msg.msg_name=0;
178 179
 	msg.msg_namelen=0;
179
-	
180
+
180 181
 	iov[0].iov_base=data;
181 182
 	iov[0].iov_len=data_len;
182 183
 	msg.msg_iov=iov;
183 184
 	msg.msg_iovlen=1;
184
-	
185
+
185 186
 again:
186 187
 	ret=sendmsg(unix_socket, &msg, 0);
187 188
 	if (ret<0){
... ...
@@ -190,14 +191,14 @@ again:
190 191
 			LM_CRIT("sendmsg failed sending %d on %d: %s (%d)\n",
191 192
 				fd, unix_socket, strerror(errno), errno);
192 193
 	}
193
-	
194
+
194 195
 	return ret;
195 196
 }
196 197
 
197 198
 
198 199
 
199 200
 /** receives a fd and data_len data
200
- * params: unix_socket 
201
+ * params: unix_socket
201 202
  *         data
202 203
  *         data_len
203 204
  *         fd         - will be set to the passed fd value or -1 if no fd
... ...
@@ -222,22 +223,23 @@ int receive_fd(int unix_socket, void* data, int data_len, int* fd, int flags)
222 223
 		struct cmsghdr cm;
223 224
 		char control[CMSG_SPACE(sizeof(new_fd))];
224 225
 	}control_un;
225
-	
226
+
227
+	memset(&msg, 0, sizeof(struct msghdr));
226 228
 	msg.msg_control=control_un.control;
227 229
 	msg.msg_controllen=sizeof(control_un.control);
228 230
 #else
229 231
 	msg.msg_accrights=(caddr_t) &new_fd;
230 232
 	msg.msg_accrightslen=sizeof(int);
231 233
 #endif
232
-	
234
+
233 235
 	msg.msg_name=0;
234 236
 	msg.msg_namelen=0;
235
-	
237
+
236 238
 	iov[0].iov_base=data;
237 239
 	iov[0].iov_len=data_len;
238 240
 	msg.msg_iov=iov;
239 241
 	msg.msg_iovlen=1;
240
-	
242
+
241 243
 #ifdef NO_MSG_WAITALL
242 244
 	f=flags & ~MSG_WAITALL;
243 245
 #endif /* NO_MSG_WAITALL */
... ...
@@ -286,7 +288,7 @@ poll_again:
286 288
 			goto error;
287 289
 		}
288 290
 	}
289
-	
291
+
290 292
 #ifdef HAVE_MSGHDR_MSG_CONTROL
291 293
 	cmsg=CMSG_FIRSTHDR(&msg);
292 294
 	if ((cmsg!=0) && (cmsg->cmsg_len==CMSG_LEN(sizeof(new_fd)))){
... ...
@@ -317,7 +319,7 @@ poll_again:
317 319
 		*fd=-1;
318 320
 	}
319 321
 #endif
320
-	
322
+
321 323
 error:
322 324
 	return ret;
323 325
 }
Browse code

core: fix spelling errors catched by lintian #688

Victor Seva authored on 29/06/2016 14:48:09
Showing 1 changed files
... ...
@@ -53,7 +53,7 @@
53 53
  * and if no data is queued on the fd, recv_all will not wait (it will 
54 54
  * return error and set errno to EAGAIN/EWOULDBLOCK). However if even 1 byte
55 55
  *  is queued, the call will block until the whole data_len was read or an
56
- *  error or eof occured ("semi-nonblocking" behaviour,  some tcp code
56
+ *  error or eof occurred ("semi-nonblocking" behaviour,  some tcp code
57 57
  *   counts on it).
58 58
  * if flags is set to MSG_WAITALL it will block even if no byte is available.
59 59
  *  
Browse code

core Update headers, change "SIP-router" to "Kamailio", update doxygen file headers

Olle E. Johansson authored on 03/01/2015 14:15:58
Showing 1 changed files
... ...
@@ -8,11 +8,6 @@
8 8
  * the Free Software Foundation; either version 2 of the License, or
9 9
  * (at your option) any later version
10 10
  *
11
- * For a license to use the ser software under conditions
12
- * other than those described here, or to purchase support for this
13
- * software, please contact iptel.org by e-mail at the following addresses:
14
- *    info@iptel.org
15
- *
16 11
  * Kamailio is distributed in the hope that it will be useful,
17 12
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 13
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Browse code

Core Removed history, svn $id$ and doxygen udpates on the .c files

Olle E. Johansson authored on 03/01/2015 09:53:17
Showing 1 changed files
... ...
@@ -1,11 +1,9 @@
1 1
 /*
2
- * $Id$
3
- *
4 2
  * Copyright (C) 2001-2003 FhG Fokus
5 3
  *
6
- * This file is part of ser, a free SIP server.
4
+ * This file is part of Kamailio, a free SIP server.
7 5
  *
8
- * ser is free software; you can redistribute it and/or modify
6
+ * Kamailio is free software; you can redistribute it and/or modify
9 7
  * it under the terms of the GNU General Public License as published by
10 8
  * the Free Software Foundation; either version 2 of the License, or
11 9
  * (at your option) any later version
... ...
@@ -15,7 +13,7 @@
15 13
  * software, please contact iptel.org by e-mail at the following addresses:
16 14
  *    info@iptel.org
17 15
  *
18
- * ser is distributed in the hope that it will be useful,
16
+ * Kamailio is distributed in the hope that it will be useful,
19 17
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 18
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21 19
  * GNU General Public License for more details.
... ...
@@ -24,21 +22,10 @@
24 22
  * along with this program; if not, write to the Free Software
25 23
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
26 24
  */
27
- /*
28
-  * History:
29
-  * --------
30
-  *  2002-11-29  created by andrei
31
-  *  2003-02-20  added solaris support (! HAVE_MSGHDR_MSG_CONTROL) (andrei)
32
-  *  2003-11-03  added send_all, recv_all  and updated send/get_fd
33
-  *               to handle signals  (andrei)
34
-  *  2005-06-13  added flags to recv_all & receive_fd, to allow full blocking
35
-  *              or semi-nonblocking mode (andrei)
36
-  *  2008-04-30  added MSG_WAITALL emulation for cygwin (andrei)
37
-  */
38 25
 
39 26
 /*!
40 27
  * \file
41
- * \brief SIP-router core :: 
28
+ * \brief Kamailio core :: 
42 29
  * \ingroup core
43 30
  * Module: \ref core
44 31
  */
... ...
@@ -61,7 +48,7 @@
61 48
 
62 49
 
63 50
 
64
-/* receive all the data or returns error (handles EINTR etc.)
51
+/** receive all the data or returns error (handles EINTR etc.)
65 52
  * params: socket
66 53
  *         data     - buffer for the results
67 54
  *         data_len - 
... ...
@@ -141,7 +128,7 @@ poll_retry:
141 128
 
142 129
 
143 130
 
144
-/* sends all data (takes care of signals) (assumes blocking fd)
131
+/** sends all data (takes care of signals) (assumes blocking fd)
145 132
  * returns number of bytes sent or < 0 for an error */
146 133
 int send_all(int socket, void* data, int data_len)
147 134
 {
... ...
@@ -160,7 +147,7 @@ again:
160 147
 }
161 148
 
162 149
 
163
-/* at least 1 byte must be sent! */
150
+/** at least 1 byte must be sent! */
164 151
 int send_fd(int unix_socket, void* data, int data_len, int fd)
165 152
 {
166 153
 	struct msghdr msg;
... ...
@@ -214,7 +201,7 @@ again:
214 201
 
215 202
 
216 203
 
217
-/* receives a fd and data_len data
204
+/** receives a fd and data_len data
218 205
  * params: unix_socket 
219 206
  *         data
220 207
  *         data_len
Browse code

pass_fd.c: logging: convert LOG to LM_*

Ovidiu Sas authored on 03/10/2014 19:12:27
Showing 1 changed files
... ...
@@ -99,7 +99,7 @@ again:
99 99
 		if (errno==EINTR) goto again; /* signal, try again */
100 100
 		/* on EAGAIN just return (let the caller know) */
101 101
 		if ((errno==EAGAIN)||(errno==EWOULDBLOCK)) return n;
102
-			LOG(L_CRIT, "ERROR: recv_all: 1st recv on %d failed: %s\n",
102
+			LM_CRIT("1st recv on %d failed: %s\n",
103 103
 					socket, strerror(errno));
104 104
 			return n;
105 105
 	}
... ...
@@ -124,13 +124,13 @@ poll_retry:
124 124
 				n=poll(&pfd, 1, -1);
125 125
 				if (n<0){ 
126 126
 					if (errno==EINTR) goto poll_retry;
127
-					LOG(L_CRIT, "ERROR: recv_all: poll on %d failed: %s\n",
128
-								socket, strerror(errno));
127
+					LM_CRIT("poll on %d failed: %s\n",
128
+						socket, strerror(errno));
129 129
 					return n;
130 130
 				} else continue; /* try recv again */
131 131
 			}
132 132
 #endif /* NO_MSG_WAITALL */
133
-			LOG(L_CRIT, "ERROR: recv_all: 2nd recv on %d failed: %s\n",
133
+			LM_CRIT("2nd recv on %d failed: %s\n",
134 134
 					socket, strerror(errno));
135 135
 			return n;
136 136
 		}
... ...
@@ -153,7 +153,7 @@ again:
153 153
 			/* error */
154 154
 		if (errno==EINTR) goto again; /* signal, try again */
155 155
 		if ((errno!=EAGAIN) &&(errno!=EWOULDBLOCK))
156
-			LOG(L_CRIT, "ERROR: send_all: send on %d failed: %s\n",
156
+			LM_CRIT("send on %d failed: %s\n",
157 157
 					socket, strerror(errno));
158 158
 	}
159 159
 	return n;
... ...
@@ -205,8 +205,8 @@ again:
205 205
 	if (ret<0){
206 206
 		if (errno==EINTR) goto again;
207 207
 		if ((errno!=EAGAIN) && (errno!=EWOULDBLOCK))
208
-			LOG(L_CRIT, "ERROR: send_fd: sendmsg failed sending %d on %d:"
209
-						" %s (%d)\n", fd, unix_socket, strerror(errno), errno);
208
+			LM_CRIT("sendmsg failed sending %d on %d: %s (%d)\n",
209
+				fd, unix_socket, strerror(errno), errno);
210 210
 	}
211 211
 	
212 212
 	return ret;
... ...
@@ -278,24 +278,24 @@ poll_again:
278 278
 				ret=poll(&pfd, 1, -1);
279 279
 				if (ret>=0) goto again;
280 280
 				else if (errno==EINTR) goto poll_again;
281
-				LOG(L_CRIT, "ERROR: receive_fd: poll on %d failed: %s\n",
282
-							unix_socket, strerror(errno));
281
+				LM_CRIT("poll on %d failed: %s\n",
282
+					unix_socket, strerror(errno));
283 283
 			}
284 284
 #endif /* NO_MSG_WAITALL */
285 285
 			goto error;
286 286
 		}
287
-		LOG(L_CRIT, "ERROR: receive_fd: recvmsg on %d failed: %s\n",
287
+		LM_CRIT("recvmsg on %d failed: %s\n",
288 288
 				unix_socket, strerror(errno));
289 289
 		goto error;
290 290
 	}
291 291
 	if (ret==0){
292 292
 		/* EOF */
293
-		LOG(L_CRIT, "ERROR: receive_fd: EOF on %d\n", unix_socket);
293
+		LM_CRIT("EOF on %d\n", unix_socket);
294 294
 		goto error;
295 295
 	}
296 296
 	if (ret<data_len){
297
-		LOG(L_WARN, "WARNING: receive_fd: too few bytes read (%d from %d)"
298
-				    "trying to fix...\n", ret, data_len);
297
+		LM_WARN("too few bytes read (%d from %d) trying to fix...\n",
298
+				ret, data_len);
299 299
 		/* blocking recv_all */
300 300
 		n=recv_all(unix_socket, (char*)data+ret, data_len-ret, MSG_WAITALL);
301 301
 		if (n>=0) ret+=n;
... ...
@@ -309,21 +309,20 @@ poll_again:
309 309
 	cmsg=CMSG_FIRSTHDR(&msg);
310 310
 	if ((cmsg!=0) && (cmsg->cmsg_len==CMSG_LEN(sizeof(new_fd)))){
311 311
 		if (cmsg->cmsg_type!= SCM_RIGHTS){
312
-			LOG(L_ERR, "ERROR: receive_fd: msg control type != SCM_RIGHTS\n");
312
+			LM_ERR("msg control type != SCM_RIGHTS\n");
313 313
 			ret=-1;
314 314
 			goto error;
315 315
 		}
316 316
 		if (cmsg->cmsg_level!= SOL_SOCKET){
317
-			LOG(L_ERR, "ERROR: receive_fd: msg level != SOL_SOCKET\n");
317
+			LM_ERR("msg level != SOL_SOCKET\n");
318 318
 			ret=-1;
319 319
 			goto error;
320 320
 		}
321 321
 		pi=(int*) CMSG_DATA(cmsg);
322 322
 		*fd=*pi;
323 323
 	}else{
324
-		/*
325
-		LOG(L_ERR, "ERROR: receive_fd: no descriptor passed, cmsg=%p,"
326
-				"len=%d\n", cmsg, (unsigned)cmsg->cmsg_len); */
324
+		/*LM_ERR("no descriptor passed, cmsg=%p, len=%d\n",
325
+			cmsg, (unsigned)cmsg->cmsg_len); */
327 326
 		*fd=-1;
328 327
 		/* it's not really an error */
329 328
 	}
... ...
@@ -331,8 +330,8 @@ poll_again:
331 330
 	if (msg.msg_accrightslen==sizeof(int)){
332 331
 		*fd=new_fd;
333 332
 	}else{
334
-		/*LOG(L_ERR, "ERROR: receive_fd: no descriptor passed,"
335
-				" accrightslen=%d\n", msg.msg_accrightslen); */
333
+		/*LM_ERR("no descriptor passed, accrightslen=%d\n",
334
+			msg.msg_accrightslen); */
336 335
 		*fd=-1;
337 336
 	}
338 337
 #endif
Browse code

all: updated FSF address in GPL text

Anthony Messina authored on 04/07/2014 09:36:37 • Daniel-Constantin Mierla committed on 04/07/2014 09:37:36
Showing 1 changed files
... ...
@@ -22,7 +22,7 @@
22 22
  *
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
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
25
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
26 26
  */
27 27
  /*
28 28
   * History:
Browse code

tcp: more complete error messages

- more information in some error messages (very useful when
debugging)
- spelling fixes

Andrei Pelinescu-Onciul authored on 06/07/2010 21:34:17
Showing 1 changed files
... ...
@@ -205,8 +205,8 @@ again:
205 205
 	if (ret<0){
206 206
 		if (errno==EINTR) goto again;
207 207
 		if ((errno!=EAGAIN) && (errno!=EWOULDBLOCK))
208
-			LOG(L_CRIT, "ERROR: send_fd: sendmsg failed on %d: %s\n",
209
-					unix_socket, strerror(errno));
208
+			LOG(L_CRIT, "ERROR: send_fd: sendmsg failed sending %d on %d:"
209
+						" %s (%d)\n", fd, unix_socket, strerror(errno), errno);
210 210
 	}
211 211
 	
212 212
 	return ret;
Browse code

Merge remote branch 'origin/andrei/pointer_alias_warnings'

compile warning fixes

* origin/andrei/pointer_alias_warnings:
rr(s): fix recently introduced avp_cookie name bug
core: avp aliasing warning fixes
group: fix pointer aliasing warnings
rr: pointer aliasing warning fixes
db_postgres: pointer aliasing warnings fixes
core: pointer aliasing warnings fixed
cfg: fixed pointer aliasing warnings

Conflicts:
cfg/cfg_ctx.h
route.c

Andrei Pelinescu-Onciul authored on 28/01/2010 19:19:49
Showing 0 changed files
Browse code

core: pointer aliasing warnings fixed

Andrei Pelinescu-Onciul authored on 12/10/2009 16:49:28
Showing 1 changed files
... ...
@@ -160,6 +160,7 @@ int send_fd(int unix_socket, void* data, int data_len, int fd)
160 160
 	struct iovec iov[1];
161 161
 	int ret;
162 162
 #ifdef HAVE_MSGHDR_MSG_CONTROL
163
+	int* pi;
163 164
 	struct cmsghdr* cmsg;
164 165
 	/* make sure msg_control will point to properly aligned data */
165 166
 	union {
... ...
@@ -176,7 +177,8 @@ int send_fd(int unix_socket, void* data, int data_len, int fd)
176 177
 	cmsg->cmsg_level = SOL_SOCKET;
177 178
 	cmsg->cmsg_type = SCM_RIGHTS;
178 179
 	cmsg->cmsg_len = CMSG_LEN(sizeof(fd));
179
-	*(int*)CMSG_DATA(cmsg)=fd;
180
+	pi=(int*)CMSG_DATA(cmsg);
181
+	*pi=fd;
180 182
 	msg.msg_flags=0;
181 183
 #else
182 184
 	msg.msg_accrights=(caddr_t) &fd;
... ...
@@ -225,6 +227,7 @@ int receive_fd(int unix_socket, void* data, int data_len, int* fd, int flags)
225 227
 	int f;
226 228
 #endif /*NO_MSG_WAITALL */
227 229
 #ifdef HAVE_MSGHDR_MSG_CONTROL
230
+	int* pi;
228 231
 	struct cmsghdr* cmsg;
229 232
 	union{
230 233
 		struct cmsghdr cm;
... ...
@@ -308,7 +311,8 @@ poll_again:
308 311
 			ret=-1;
309 312
 			goto error;
310 313
 		}
311
-		*fd=*((int*) CMSG_DATA(cmsg));
314
+		pi=(int*) CMSG_DATA(cmsg);
315
+		*fd=*pi;
312 316
 	}else{
313 317
 		/*
314 318
 		LOG(L_ERR, "ERROR: receive_fd: no descriptor passed, cmsg=%p,"
Browse code

Adding doxygen template to all core .c files

Please fill in after the :: to explain the function of this file.

oej authored on 10/10/2009 13:54:13
Showing 1 changed files
... ...
@@ -36,6 +36,13 @@
36 36
   *  2008-04-30  added MSG_WAITALL emulation for cygwin (andrei)
37 37
   */
38 38
 
39
+/*!
40
+ * \file
41
+ * \brief SIP-router core :: 
42
+ * \ingroup core
43
+ * Module: \ref core
44
+ */
45
+
39 46
 #ifdef USE_TCP
40 47
 
41 48
 #include "pass_fd.h"
Browse code

- MSG_WAITALL emulation for OSes that don't support it (win+cygwin)

Andrei Pelinescu-Onciul authored on 30/04/2008 19:54:34
Showing 1 changed files
... ...
@@ -33,16 +33,22 @@
33 33
   *               to handle signals  (andrei)
34 34
   *  2005-06-13  added flags to recv_all & receive_fd, to allow full blocking
35 35
   *              or semi-nonblocking mode (andrei)
36
+  *  2008-04-30  added MSG_WAITALL emulation for cygwin (andrei)
36 37
   */
37 38
 
38 39
 #ifdef USE_TCP
39 40
 
41
+#include "pass_fd.h"
42
+
40 43
 #include <sys/types.h>
41 44
 #include <sys/socket.h>
42 45
 #include <sys/uio.h>
43 46
 #include <stdlib.h> /* for NULL definition on openbsd */
44 47
 #include <errno.h>
45 48
 #include <string.h>
49
+#ifdef NO_MSG_WAITALL
50
+#include <poll.h>
51
+#endif /* NO_MSG_WAITALL */
46 52
 
47 53
 #include "dprint.h"
48 54
 
... ...
@@ -68,9 +74,18 @@ int recv_all(int socket, void* data, int data_len, int flags)
68 74
 {
69 75
 	int b_read;
70 76
 	int n;
77
+#ifdef NO_MSG_WAITALL
78
+	struct pollfd pfd;
79
+#endif /* NO_MSG_WAITALL */
71 80
 	
72 81
 	b_read=0;
73 82
 again:
83
+#ifdef NO_MSG_WAITALL
84
+	if (flags & MSG_WAITALL){
85
+		n=-1;
86
+		goto poll_recv; /* simulate MSG_WAITALL */
87
+	}
88
+#endif /* NO_MSG_WAITALL */
74 89
 	n=recv(socket, (char*)data, data_len, flags);
75 90
 	if (n<0){
76 91
 		/* error */
... ...
@@ -83,10 +98,31 @@ again:
83 98
 	}
84 99
 	b_read+=n;
85 100
 	while( (b_read!=data_len) && (n)){
101
+#ifdef NO_MSG_WAITALL
102
+		/* cygwin & win do not support MSG_WAITALL => workaround using poll */
103
+poll_recv:
104
+		n=recv(socket, (char*)data+b_read, data_len-b_read, 0);
105
+#else /* NO_MSG_WAITALL */
86 106
 		n=recv(socket, (char*)data+b_read, data_len-b_read, MSG_WAITALL);
107
+#endif /* NO_MSG_WAITALL */
87 108
 		if (n<0){
88 109
 			/* error */
89 110
 			if (errno==EINTR) continue; /* signal, try again */
111
+#ifdef NO_MSG_WAITALL
112
+			if (errno==EAGAIN || errno==EWOULDBLOCK){
113
+				/* emulate MSG_WAITALL using poll */
114
+				pfd.fd=socket;
115
+				pfd.events=POLLIN;
116
+poll_retry:
117
+				n=poll(&pfd, 1, -1);
118
+				if (n<0){ 
119
+					if (errno==EINTR) goto poll_retry;
120
+					LOG(L_CRIT, "ERROR: recv_all: poll on %d failed: %s\n",
121
+								socket, strerror(errno));
122
+					return n;
123
+				} else continue; /* try recv again */
124
+			}
125
+#endif /* NO_MSG_WAITALL */
90 126
 			LOG(L_CRIT, "ERROR: recv_all: 2nd recv on %d failed: %s\n",
91 127
 					socket, strerror(errno));
92 128
 			return n;
... ...
@@ -184,6 +220,10 @@ int receive_fd(int unix_socket, void* data, int data_len, int* fd, int flags)
184 220
 	int new_fd;
185 221
 	int ret;
186 222
 	int n;
223
+#ifdef NO_MSG_WAITALL
224
+	struct pollfd pfd;
225
+	int f;
226
+#endif /*NO_MSG_WAITALL */
187 227
 #ifdef HAVE_MSGHDR_MSG_CONTROL
188 228
 	struct cmsghdr* cmsg;
189 229
 	union{
... ...
@@ -206,11 +246,34 @@ int receive_fd(int unix_socket, void* data, int data_len, int* fd, int flags)
206 246
 	msg.msg_iov=iov;
207 247
 	msg.msg_iovlen=1;
208 248
 	
249
+#ifdef NO_MSG_WAITALL
250
+	f=flags & ~MSG_WAITALL;
251
+#endif /* NO_MSG_WAITALL */
252
+
209 253
 again:
210
-	ret=recvmsg(unix_socket, &msg, flags);
254
+#ifdef NO_MSG_WAITALL
255
+		ret=recvmsg(unix_socket, &msg, f);
256
+#else /* NO_MSG_WAITALL */
257
+		ret=recvmsg(unix_socket, &msg, flags);
258
+#endif /* NO_MSG_WAITALL */
211 259
 	if (ret<0){
212 260
 		if (errno==EINTR) goto again;
213
-		if ((errno==EAGAIN)||(errno==EWOULDBLOCK)) goto error;
261
+		if ((errno==EAGAIN)||(errno==EWOULDBLOCK)){
262
+#ifdef NO_MSG_WAITALL
263
+			if (flags & MSG_WAITALL){
264
+				/* emulate MSG_WAITALL using poll */
265
+				pfd.fd=unix_socket;
266
+				pfd.events=POLLIN;
267
+poll_again:
268
+				ret=poll(&pfd, 1, -1);
269
+				if (ret>=0) goto again;
270
+				else if (errno==EINTR) goto poll_again;
271
+				LOG(L_CRIT, "ERROR: receive_fd: poll on %d failed: %s\n",
272
+							unix_socket, strerror(errno));
273
+			}
274
+#endif /* NO_MSG_WAITALL */
275
+			goto error;
276
+		}
214 277
 		LOG(L_CRIT, "ERROR: receive_fd: recvmsg on %d failed: %s\n",
215 278
 				unix_socket, strerror(errno));
216 279
 		goto error;
Browse code

- tcp children control fds are now non-blocking - send fd queue is used when a childs queue is full

Andrei Pelinescu-Onciul authored on 03/02/2006 16:15:18
Showing 1 changed files
... ...
@@ -109,7 +109,8 @@ again:
109 109
 	if (n<0){
110 110
 			/* error */
111 111
 		if (errno==EINTR) goto again; /* signal, try again */
112
-		LOG(L_CRIT, "ERROR: send_all: send on %d failed: %s\n",
112
+		if ((errno!=EAGAIN) &&(errno!=EWOULDBLOCK))
113
+			LOG(L_CRIT, "ERROR: send_all: send on %d failed: %s\n",
113 114
 					socket, strerror(errno));
114 115
 	}
115 116
 	return n;
... ...
@@ -158,8 +159,9 @@ again:
158 159
 	ret=sendmsg(unix_socket, &msg, 0);
159 160
 	if (ret<0){
160 161
 		if (errno==EINTR) goto again;
161
-		LOG(L_CRIT, "ERROR: send_fd: sendmsg failed on %d: %s\n",
162
-				unix_socket, strerror(errno));