[asterisk-commits] rizzo: branch rizzo/astobj2 r45888 - /team/rizzo/astobj2/main/http.c

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Sun Oct 22 11:13:56 MST 2006


Author: rizzo
Date: Sun Oct 22 13:13:55 2006
New Revision: 45888

URL: http://svn.digium.com/view/asterisk?rev=45888&view=rev
Log:
properly handle failures on ssl requests;
rearrange code to improve readability.


Modified:
    team/rizzo/astobj2/main/http.c

Modified: team/rizzo/astobj2/main/http.c
URL: http://svn.digium.com/view/asterisk/team/rizzo/astobj2/main/http.c?rev=45888&r1=45887&r2=45888&view=diff
==============================================================================
--- team/rizzo/astobj2/main/http.c (original)
+++ team/rizzo/astobj2/main/http.c Sun Oct 22 13:13:55 2006
@@ -463,16 +463,7 @@
 	SSL_free(cookie);
 	return 0;
 }
-#if !defined(HAVE_FUNOPEN) && defined(HAVE_FOPENCOOKIE)
-cookie_io_functions_t myfunctions = {
-	(cookie_read_function_t*)ssl_read,
-	(cookie_write_function_t*)ssl_write,
-	(cookie_seek_function_t*)NULL,
-	(cookie_close_function_t*)ssl_close
-};
-
-#endif
-#endif
+#endif	/* DO_SSL */
 
 static void *ast_httpd_helper_thread(void *data)
 {
@@ -483,30 +474,38 @@
 	char *uri, *c, *title=NULL;
 	int status = 200, contentlength = 0;
 
+	/*
+	 * open a FILE * as appropriate.
+	 */
+	if (!ser->is_ssl)
+		ser->f = fdopen(ser->fd, "w+");
 #ifdef DO_SSL
-	if (ser->is_ssl) {
-		ser->ssl = SSL_new(ssl_ctx);
+	else if ( (ser->ssl = SSL_new(ssl_ctx)) ) {
 		SSL_set_fd(ser->ssl, ser->fd);
-		if (SSL_accept(ser->ssl) == 0) {
+		if (SSL_accept(ser->ssl) == 0)
 			ast_verbose(" error setting up ssl connection");
-			goto done;
-		}
-#if defined(HAVE_FUNOPEN)
-		ser->f = funopen(ser->ssl, ssl_read, ssl_write, NULL, ssl_close);
-#elif defined(HAVE_FOPENCOOKIE)
-		ser->f = fopencookie(ser->ssl, "w+", myfunctions);
+		else {
+#if defined(HAVE_FUNOPEN)	/* the BSD interface */
+			ser->f = funopen(ser->ssl, ssl_read, ssl_write, NULL, ssl_close);
+
+#elif defined(HAVE_FOPENCOOKIE)	/* the glibc/linux interface */
+			static const cookie_io_functions_t cookie_funcs = {
+				ssl_read, ssl_write, NULL, ssl_close
+			};
+			ser->f = fopencookie(ser->ssl, "w+", cookie_funcs);
 #else
-#error missing funopen/fopencookie support
+			/* could add other methods here */
 #endif
-	} else
-#endif
-	ser->f = fdopen(ser->fd, "w+");
+		}
+		if (!ser->f)	/* no success opening descriptor stacking */
+			SSL_free(ser->ssl);
+	}
+#endif /* DO_SSL */
 
 	if (!ser->f) {
-		ast_log(LOG_WARNING, "fdopen/funopen failed!\n");
 		close(ser->fd);
-		free(ser);
-		return NULL;
+		ast_log(LOG_WARNING, "FILE * open failed!\n");
+		goto done;
 	}
 
 	if (!fgets(buf, sizeof(buf), ser->f))
@@ -620,7 +619,8 @@
 		free(title);
 
 done:
-	fclose(ser->f);
+	if (ser->f)
+		fclose(ser->f);
 	free(ser);
 	return NULL;
 }



More information about the asterisk-commits mailing list