[svn-commits] russell: branch group/res_config_ldap r72704 - in /team/group/res_config_ldap...

SVN commits to the Digium repositories svn-commits at lists.digium.com
Fri Jun 29 15:45:55 CDT 2007


Author: russell
Date: Fri Jun 29 15:45:54 2007
New Revision: 72704

URL: http://svn.digium.com/view/asterisk?view=rev&rev=72704
Log:
Merged revisions 72666,72670,72700-72701 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/trunk

........
r72666 | rizzo | 2007-06-29 14:09:36 -0500 (Fri, 29 Jun 2007) | 1 line

72665 not applicable to trunk
........
r72670 | mmichelson | 2007-06-29 15:02:00 -0500 (Fri, 29 Jun 2007) | 8 lines

Found a grievous logical error in get_vm_state_by_imapuser.
The imapuser being passed in was never getting compared to imapusers of any of the vm_states
in the vmstates list.

I also found some places in the code where I used my typical brace style and changed it to match
the typical Asterisk brace style.


........
r72700 | rizzo | 2007-06-29 15:33:35 -0500 (Fri, 29 Jun 2007) | 20 lines

Make sure that we properly recurse in subdirectories to
check dependencies for libraries.
Because these targets (e.g. minimime/libmmime.a) are real ones,
declaring them .PHONY would cause them to be rebuilt every time
(see e.g. SVN 64355).

As a workaround I am using the following CHECK_SUBDIR target:

  CHECK_SUBDIR:  # do nothing, just make sure that we recurse in the subdir/
  minimime/libmmime.a: CHECK_SUBDIR
	@cd minimime && $(MAKE) libmmime.a

which seems to do a better job than .PHONY (probably because
.PHONY forces the rebuild even if the recursive make does not think
it is necessary).

If this turns out to be the correct approach, we can then
merge it back into 1.4


........
r72701 | russell | 2007-06-29 15:35:09 -0500 (Fri, 29 Jun 2007) | 7 lines

Merge changes from team/russell/http_filetxfer

Handle transferring large files from the built-in http server.  Previously, the
code attempted to malloc a block as large as the file itself.  Now it uses the
sendfile() system call so that the file isn't copied into userspace at all if
it is available.  Otherwise, it just uses a read/write of small chunks at a time.

........

Modified:
    team/group/res_config_ldap/   (props changed)
    team/group/res_config_ldap/apps/app_voicemail.c
    team/group/res_config_ldap/configure
    team/group/res_config_ldap/configure.ac
    team/group/res_config_ldap/include/asterisk/autoconfig.h.in
    team/group/res_config_ldap/include/asterisk/http.h
    team/group/res_config_ldap/main/Makefile
    team/group/res_config_ldap/main/http.c
    team/group/res_config_ldap/main/manager.c

Propchange: team/group/res_config_ldap/
------------------------------------------------------------------------------
    automerge = *

Propchange: team/group/res_config_ldap/
------------------------------------------------------------------------------
Binary property 'branch-1.4-blocked' - no diff available.

Propchange: team/group/res_config_ldap/
------------------------------------------------------------------------------
--- svnmerge-integrated (original)
+++ svnmerge-integrated Fri Jun 29 15:45:54 2007
@@ -1,1 +1,1 @@
-/trunk:1-72627
+/trunk:1-72703

Modified: team/group/res_config_ldap/apps/app_voicemail.c
URL: http://svn.digium.com/view/asterisk/team/group/res_config_ldap/apps/app_voicemail.c?view=diff&rev=72704&r1=72703&r2=72704
==============================================================================
--- team/group/res_config_ldap/apps/app_voicemail.c (original)
+++ team/group/res_config_ldap/apps/app_voicemail.c Fri Jun 29 15:45:54 2007
@@ -2647,7 +2647,7 @@
 	 ast_debug(3,"Mailbox is set to %s\n",mailbox);
 
  	/* If no mailbox, return immediately */
- 	if (ast_strlen_zero(mailbox))
+ 	if (ast_strlen_zero(mailbox)) 
  		return 0;
 
  	if (strchr(mailbox, ',')) {
@@ -2694,7 +2694,7 @@
 		free_user(vmu);
 		return -1;
  	}
- 
+
  	/* check if someone is accessing this box right now... */
 	if ((vms_p = get_vm_state_by_imapuser(vmu->imapuser, 1)) || (vms_p = get_vm_state_by_mailbox(mailboxnc, 1))) {
 		ast_debug(3,"Returning before search - user is logged in\n");
@@ -2703,7 +2703,7 @@
 		free_user(vmu);
  		return 0;
  	}
- 
+
  	/* add one if not there... */
 	if (!(vms_p = get_vm_state_by_imapuser(vmu->imapuser, 0)) && !(vms_p = get_vm_state_by_mailbox(mailboxnc, 0))) {
 		ast_debug(3,"Adding new vmstate for %s\n",vmu->imapuser);
@@ -3187,8 +3187,9 @@
 			ast_log(LOG_NOTICE,"Can not leave voicemail, unable to count messages\n");
 			return -1;
 		}
-		if((vms = get_vm_state_by_mailbox(ext,0))) 
+		if((vms = get_vm_state_by_mailbox(ext,0)))  
 			vms->newmessages++; /*still need to increment new message count*/
+		
 		/* here is a big difference! We add one to it later */
 		msgnum = newmsgs + oldmsgs;
 		ast_debug(3, "Messagecount set to %d\n",msgnum);
@@ -5031,8 +5032,7 @@
 		return -1;
 	}
 
-	for (i = 0; i < vms_p->mailstream->nmsgs; i++)
-	{
+	for (i = 0; i < vms_p->mailstream->nmsgs; i++) {
 		mail_fetchstructure(vms_p->mailstream, i + 1, &body);
 		/* We have the body, now we extract the file name of the first attachment. */
 		if (body->nested.part->next && body->nested.part->next->body.parameter->value) {
@@ -5042,8 +5042,7 @@
 			return -1;
 		}
 		filename = strsep(&attachment, ".");
-		if (!strcmp(filename, file))
-		{
+		if (!strcmp(filename, file)) {
 			ast_copy_string(vms_p->fn, dir, sizeof(vms_p->fn));
 			vms_p->msgArray[vms_p->curmsg] = i + 1;
 			save_body(body, vms_p, "2", attachment);
@@ -5083,8 +5082,7 @@
 			return -1;
 		}
 		filename = strsep(&attachment, ".");
-		if (!strcmp(filename, file))
-		{
+		if (!strcmp(filename, file)) {
 			sprintf (arg,"%d", i+1);
 			mail_setflag (vms->mailstream,arg,"\\DELETED");
 		}
@@ -9495,7 +9493,7 @@
 			continue;
 		}
 
-		if (interactive == 2 || vlist->vms->interactive == interactive) {
+		if (!strcmp(vlist->vms->imapuser, user) && (interactive == 2 || vlist->vms->interactive == interactive)) {
 			AST_LIST_UNLOCK(&vmstates);
 			return vlist->vms;
 		}

Modified: team/group/res_config_ldap/configure
URL: http://svn.digium.com/view/asterisk/team/group/res_config_ldap/configure?view=diff&rev=72704&r1=72703&r2=72704
==============================================================================
--- team/group/res_config_ldap/configure (original)
+++ team/group/res_config_ldap/configure Fri Jun 29 15:45:54 2007
@@ -1,5 +1,5 @@
 #! /bin/sh
-# From configure.ac Revision: 71746 .
+# From configure.ac Revision: 72628 .
 # Guess values for system-dependent variables and create Makefiles.
 # Generated by GNU Autoconf 2.61.
 #
@@ -16509,6 +16509,66 @@
 
 
 
+cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+#include <stdlib.h>
+     #include <sys/sendfile.h>
+int
+main ()
+{
+sendfile(1, 0, NULL, 1);
+  ;
+  return 0;
+}
+
+_ACEOF
+rm -f conftest.$ac_objext
+if { (ac_try="$ac_compile"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+  (eval "$ac_compile") 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } && {
+	 test -z "$ac_c_werror_flag" ||
+	 test ! -s conftest.err
+       } && test -s conftest.$ac_objext; then
+
+    { echo "$as_me:$LINENO: result: yes" >&5
+echo "${ECHO_T}yes" >&6; }
+       have_sendfile=yes
+
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+
+    { echo "$as_me:$LINENO: result: no" >&5
+echo "${ECHO_T}no" >&6; }
+       have_sendfile=no
+
+
+fi
+
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+if test "${have_sendfile}" = "yes"; then
+
+cat >>confdefs.h <<\_ACEOF
+#define HAVE_SENDFILE 1
+_ACEOF
+
+fi
+
 # do the package library checks now
 
 

Modified: team/group/res_config_ldap/configure.ac
URL: http://svn.digium.com/view/asterisk/team/group/res_config_ldap/configure.ac?view=diff&rev=72704&r1=72703&r2=72704
==============================================================================
--- team/group/res_config_ldap/configure.ac (original)
+++ team/group/res_config_ldap/configure.ac Fri Jun 29 15:45:54 2007
@@ -364,6 +364,23 @@
                 [AC_DEFINE_UNQUOTED([HAVE_OSX_ATOMICS], 1, [Define to 1 if OSX atomic operations are supported.])])
 
 AC_CHECK_SIZEOF(int)
+
+AC_COMPILE_IFELSE(
+  [AC_LANG_PROGRAM(
+    [#include <stdlib.h>
+     #include <sys/sendfile.h>],
+    [sendfile(1, 0, NULL, 1);])
+  ],[
+    AC_MSG_RESULT(yes)
+       have_sendfile=yes
+  ],[
+    AC_MSG_RESULT(no)
+       have_sendfile=no
+  ]
+)
+if test "${have_sendfile}" = "yes"; then
+  AC_DEFINE([HAVE_SENDFILE], 1, [Define if your system has the sendfile syscall.])
+fi
 
 # do the package library checks now
 

Modified: team/group/res_config_ldap/include/asterisk/autoconfig.h.in
URL: http://svn.digium.com/view/asterisk/team/group/res_config_ldap/include/asterisk/autoconfig.h.in?view=diff&rev=72704&r1=72703&r2=72704
==============================================================================
--- team/group/res_config_ldap/include/asterisk/autoconfig.h.in (original)
+++ team/group/res_config_ldap/include/asterisk/autoconfig.h.in Fri Jun 29 15:45:54 2007
@@ -399,6 +399,9 @@
 
 /* Define to 1 if you have the `select' function. */
 #undef HAVE_SELECT
+
+/* Define if your system has the sendfile syscall. */
+#undef HAVE_SENDFILE
 
 /* Define to 1 if you have the `setenv' function. */
 #undef HAVE_SETENV

Modified: team/group/res_config_ldap/include/asterisk/http.h
URL: http://svn.digium.com/view/asterisk/team/group/res_config_ldap/include/asterisk/http.h?view=diff&rev=72704&r1=72703&r2=72704
==============================================================================
--- team/group/res_config_ldap/include/asterisk/http.h (original)
+++ team/group/res_config_ldap/include/asterisk/http.h Fri Jun 29 15:45:54 2007
@@ -147,7 +147,7 @@
    content is specified) 
 \endverbatim
 */
-typedef struct ast_str *(*ast_http_callback)(struct sockaddr_in *requestor, const char *uri, struct ast_variable *params, int *status, char **title, int *contentlength);
+typedef struct ast_str *(*ast_http_callback)(struct server_instance *ser, const char *uri, struct ast_variable *params, int *status, char **title, int *contentlength);
 
 /*! \brief Definition of a URI reachable in the embedded HTTP server */
 struct ast_http_uri {

Modified: team/group/res_config_ldap/main/Makefile
URL: http://svn.digium.com/view/asterisk/team/group/res_config_ldap/main/Makefile?view=diff&rev=72704&r1=72703&r2=72704
==============================================================================
--- team/group/res_config_ldap/main/Makefile (original)
+++ team/group/res_config_ldap/main/Makefile Fri Jun 29 15:45:54 2007
@@ -100,11 +100,13 @@
   ASTLINK=
 endif
 
-editline/libedit.a:
+CHECK_SUBDIR:	# do nothing, just make sure that we recurse in the subdir/
+
+editline/libedit.a: CHECK_SUBDIR
 	cd editline && test -f config.h || CFLAGS="$(PTHREAD_CFLAGS) $(ASTCFLAGS:-Werror=)" LDFLAGS="$(ASTLDFLAGS)" ./configure --build=$(BUILD_PLATFORM) --host=$(HOST_PLATFORM) --with-ncurses=$(NCURSES_DIR) --with-curses=$(CURSES_DIR) --with-termcap=$(TERMCAP_DIR) --with-tinfo=$(TINFO_DIR)
 	$(MAKE) -C editline libedit.a
 
-db1-ast/libdb1.a:
+db1-ast/libdb1.a: CHECK_SUBDIR
 	CFLAGS="$(ASTCFLAGS)" LDFLAGS="$(ASTLDFLAGS)" $(MAKE) -C db1-ast libdb1.a
 
 ast_expr2.c ast_expr2.h:
@@ -133,7 +135,7 @@
   H323LDLIBS=
 endif
 
-minimime/libmmime.a:
+minimime/libmmime.a: CHECK_SUBDIR
 	@cd minimime && $(MAKE) libmmime.a
 
 asterisk: $(OBJS) editline/libedit.a db1-ast/libdb1.a minimime/libmmime.a $(AST_EMBED_LDSCRIPTS)

Modified: team/group/res_config_ldap/main/http.c
URL: http://svn.digium.com/view/asterisk/team/group/res_config_ldap/main/http.c?view=diff&rev=72704&r1=72703&r2=72704
==============================================================================
--- team/group/res_config_ldap/main/http.c (original)
+++ team/group/res_config_ldap/main/http.c Fri Jun 29 15:45:54 2007
@@ -48,6 +48,10 @@
 #include <fcntl.h>
 #include <pthread.h>
 
+#ifdef HAVE_SENDFILE
+#include <sys/sendfile.h>
+#endif
+
 #include "minimime/mm.h"
 
 #include "asterisk/cli.h"
@@ -145,9 +149,8 @@
 	return wkspace;
 }
 
-static struct ast_str *static_callback(struct sockaddr_in *req, const char *uri, struct ast_variable *vars, int *status, char **title, int *contentlength)
-{
-	struct ast_str *result;
+static struct ast_str *static_callback(struct server_instance *ser, const char *uri, struct ast_variable *vars, int *status, char **title, int *contentlength)
+{
 	char *path;
 	char *ftype;
 	const char *mtype;
@@ -155,6 +158,8 @@
 	struct stat st;
 	int len;
 	int fd;
+	time_t t;
+	char buf[256];
 
 	/* Yuck.  I'm not really sold on this, but if you don't deliver static content it makes your configuration 
 	   substantially more challenging, but this seems like a rather irritating feature creep on Asterisk. */
@@ -185,21 +190,28 @@
 	if (fd < 0)
 		goto out403;
 
-	len = st.st_size + strlen(mtype) + 40;
-	result = ast_str_create(len);
-	if (result == NULL)	/* XXX not really but... */
-		goto out403;
-
-	ast_str_append(&result, 0, "Content-type: %s\r\n\r\n", mtype);
-	*contentlength = read(fd, result->str + result->used, st.st_size);
-	if (*contentlength < 0) {
-		close(fd);
-		ast_free(result);
-		goto out403;
-	}
-	result->used += *contentlength;
+	time(&t);
+	strftime(buf, sizeof(buf), "%a, %d %b %Y %H:%M:%S GMT", gmtime(&t));
+	fprintf(ser->f, "HTTP/1.1 200 OK\r\n"
+		"Server: Asterisk/%s\r\n"
+		"Date: %s\r\n"
+		"Connection: close\r\n"
+		"Cache-Control: no-cache, no-store\r\n"
+		"Content-Length: %d\r\n"
+		"Content-type: %s\r\n\r\n",
+		ASTERISK_VERSION, buf, (int) st.st_size, mtype);
+
+	fflush(ser->f);
+
+#ifdef HAVE_SENDFILE
+	sendfile(ser->fd, fd, NULL, st.st_size);
+#else
+	while ((len = read(fd, buf, sizeof(buf))) > 0)
+		write(ser->fd, buf, len);
+#endif
+
 	close(fd);
-	return result;
+	return NULL;
 
 out404:
 	*status = 404;
@@ -213,7 +225,7 @@
 }
 
 
-static struct ast_str *httpstatus_callback(struct sockaddr_in *req, const char *uri, struct ast_variable *vars, int *status, char **title, int *contentlength)
+static struct ast_str *httpstatus_callback(struct server_instance *ser, const char *uri, struct ast_variable *vars, int *status, char **title, int *contentlength)
 {
 	struct ast_str *out = ast_str_create(512);
 	struct ast_variable *v;
@@ -541,7 +553,7 @@
 	return ast_http_error(200, "OK", NULL, "File successfully uploaded.");
 }
 
-static struct ast_str *handle_uri(struct sockaddr_in *sin, char *uri, int *status, 
+static struct ast_str *handle_uri(struct server_instance *ser, char *uri, int *status, 
 	char **title, int *contentlength, struct ast_variable **cookies, 
 	unsigned int *static_content)
 {
@@ -627,7 +639,7 @@
 	if (urih) {
 		if (urih->static_content)
 			*static_content = 1;
-		out = urih->callback(sin, uri, vars, status, title, contentlength);
+		out = urih->callback(ser, uri, vars, status, title, contentlength);
 		AST_RWLIST_UNLOCK(&uris);
 	} else {
 		out = ast_http_error(404, "Not Found", NULL,
@@ -834,14 +846,12 @@
 		out = ast_http_error(501, "Not Implemented", NULL,
 			"Attempt to use unimplemented / unsupported method");
 	else	/* try to serve it */
-		out = handle_uri(&ser->requestor, uri, &status, &title, &contentlength, &vars, &static_content);
+		out = handle_uri(ser, uri, &status, &title, &contentlength, &vars, &static_content);
 
 	/* If they aren't mopped up already, clean up the cookies */
 	if (vars)
 		ast_variables_destroy(vars);
 
-	if (out == NULL)
-		out = ast_http_error(500, "Internal Error", NULL, "Internal Server Error");
 	if (out) {
 		time_t t = time(NULL);
 		char timebuf[256];

Modified: team/group/res_config_ldap/main/manager.c
URL: http://svn.digium.com/view/asterisk/team/group/res_config_ldap/main/manager.c?view=diff&rev=72704&r1=72703&r2=72704
==============================================================================
--- team/group/res_config_ldap/main/manager.c (original)
+++ team/group/res_config_ldap/main/manager.c Fri Jun 29 15:45:54 2007
@@ -3182,19 +3182,19 @@
 	return out;
 }
 
-static struct ast_str *manager_http_callback(struct sockaddr_in *requestor, const char *uri, struct ast_variable *params, int *status, char **title, int *contentlength)
-{
-	return generic_http_callback(FORMAT_HTML, requestor, uri, params, status, title, contentlength);
-}
-
-static struct ast_str *mxml_http_callback(struct sockaddr_in *requestor, const char *uri, struct ast_variable *params, int *status, char **title, int *contentlength)
-{
-	return generic_http_callback(FORMAT_XML, requestor, uri, params, status, title, contentlength);
-}
-
-static struct ast_str *rawman_http_callback(struct sockaddr_in *requestor, const char *uri, struct ast_variable *params, int *status, char **title, int *contentlength)
-{
-	return generic_http_callback(FORMAT_RAW, requestor, uri, params, status, title, contentlength);
+static struct ast_str *manager_http_callback(struct server_instance *ser, const char *uri, struct ast_variable *params, int *status, char **title, int *contentlength)
+{
+	return generic_http_callback(FORMAT_HTML, &ser->requestor, uri, params, status, title, contentlength);
+}
+
+static struct ast_str *mxml_http_callback(struct server_instance *ser, const char *uri, struct ast_variable *params, int *status, char **title, int *contentlength)
+{
+	return generic_http_callback(FORMAT_XML, &ser->requestor, uri, params, status, title, contentlength);
+}
+
+static struct ast_str *rawman_http_callback(struct server_instance *ser, const char *uri, struct ast_variable *params, int *status, char **title, int *contentlength)
+{
+	return generic_http_callback(FORMAT_RAW, &ser->requestor, uri, params, status, title, contentlength);
 }
 
 struct ast_http_uri rawmanuri = {




More information about the svn-commits mailing list