adding ap_get_protocol(c) which safeguards against NULL returns, for use instead...
authorStefan Eissing <icing@apache.org>
Wed, 26 Aug 2015 08:58:45 +0000 (08:58 +0000)
committerStefan Eissing <icing@apache.org>
Wed, 26 Aug 2015 08:58:45 +0000 (08:58 +0000)
git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1697855 13f79535-47bb-0310-9956-ffa450edef68

include/http_protocol.h
modules/http2/h2_h2.c
modules/http2/h2_switch.c
modules/ssl/ssl_engine_io.c
server/core.c
server/protocol.c

index cd52fa5bb0c06dc34c795d21bdbd526ba82f2999..846df2f05c8046cfa8198aef64551a3e334a17a2 100644 (file)
@@ -723,8 +723,8 @@ AP_DECLARE_HOOK(apr_port_t,default_port,(const request_rec *r))
  * @param c The current connection
  * @param r The current request or NULL
  * @param s The server/virtual host selected
- * @param offers a list of protocol identifiers offered by the client
- * @param proposals the list of protocol identifiers proposed by the hooks
+ * @param offers A list of protocol identifiers offered by the client
+ * @param proposals The list of protocol identifiers proposed by the hooks
  * @return OK or DECLINED
  */
 AP_DECLARE_HOOK(int,protocol_propose,(conn_rec *c, request_rec *r,
@@ -752,7 +752,7 @@ AP_DECLARE_HOOK(int,protocol_propose,(conn_rec *c, request_rec *r,
  * @param c The current connection
  * @param r The current request or NULL
  * @param s The server/virtual host selected
- * @param choices a list of protocol identifiers, normally the clients whishes
+ * @param choices A list of protocol identifiers, normally the clients whishes
  * @param proposals the list of protocol identifiers proposed by the hooks
  * @return OK or DECLINED
  */
@@ -765,8 +765,11 @@ AP_DECLARE_HOOK(int,protocol_switch,(conn_rec *c, request_rec *r,
  * protocol switching must register here and return the correct protocol
  * identifier for connections they switched.
  *
+ * To find out the protocol for the current connection, better call
+ * @see ap_get_protocol which internally uses this hook.
+ *
  * @param c The current connection
- * @return The identifier of the protocol in place
+ * @return The identifier of the protocol in place or NULL
  */
 AP_DECLARE_HOOK(const char *,protocol_get,(const conn_rec *c))
     
@@ -778,8 +781,8 @@ AP_DECLARE_HOOK(const char *,protocol_get,(const conn_rec *c))
  * @param c The current connection
  * @param r The current request or NULL
  * @param s The server/virtual host selected
- * @param choices a list of protocol identifiers, normally the clients whishes
- * @return the selected protocol
+ * @param choices A list of protocol identifiers, normally the clients whishes
+ * @return The selected protocol
  */
 AP_DECLARE(const char *) ap_select_protocol(conn_rec *c, request_rec *r, 
                                             server_rec *s,
@@ -803,6 +806,19 @@ AP_DECLARE(apr_status_t) ap_switch_protocol(conn_rec *c, request_rec *r,
                                             server_rec *s,
                                             const char *protocol);
 
+/**
+ * Call the protocol_get hook to determine the protocol currently in use
+ * for the given connection.
+ *
+ * Unless another protocol has been switch to, will default to
+ * @see AP_PROTOCOL_HTTP1 and modules implementing a  new protocol must
+ * report a switched connection via the protocol_get hook.
+ *
+ * @param c The connection to determine the protocol for
+ * @return the protocol in use, never NULL
+ */
+AP_DECLARE(const char *) ap_get_protocol(conn_rec *c);
+
 /** @see ap_bucket_type_error */
 typedef struct ap_bucket_error ap_bucket_error;
 
index 5d729f4621112902c7b84aa5a57fda284667c98f..a253c01abb6968e31c469d6e049ea81039a0f573 100644 (file)
@@ -161,7 +161,7 @@ int h2_h2_process_conn(conn_rec* c)
      * -> sniff for the magic PRIamble. On TLS, this might trigger the ALPN.
      */
     if (!h2_ctx_protocol_get(c) 
-        && !strcmp(AP_PROTOCOL_HTTP1, ap_run_protocol_get(c))) {
+        && !strcmp(AP_PROTOCOL_HTTP1, ap_get_protocol(c))) {
         apr_status_t status;
         
         temp = apr_brigade_create(c->pool, c->bucket_alloc);
@@ -170,7 +170,7 @@ int h2_h2_process_conn(conn_rec* c)
 
         if (status == APR_SUCCESS) {
             if (h2_ctx_protocol_get(c) 
-                || strcmp(AP_PROTOCOL_HTTP1, ap_run_protocol_get(c))) {
+                || strcmp(AP_PROTOCOL_HTTP1, ap_get_protocol(c))) {
                 /* h2 or another protocol has been selected. */
             }
             else {
index b0926ce161d8f27fe93dfbd0199288f0f1bfbb12..fd769833b0a7c4c85eaa4f42439cb54a81eb0003 100644 (file)
@@ -65,7 +65,7 @@ static int h2_protocol_propose(conn_rec *c, request_rec *r,
     int proposed = 0;
     const char **protos = h2_h2_is_tls(c)? h2_tls_protos : h2_clear_protos;
     
-    if (strcmp(AP_PROTOCOL_HTTP1, ap_run_protocol_get(c))) {
+    if (strcmp(AP_PROTOCOL_HTTP1, ap_get_protocol(c))) {
         /* We do not know how to switch from anything else but http/1.1.
          */
         ap_log_cerror(APLOG_MARK, APLOG_DEBUG, 0, c,
index 10d38fea233b2ad350f29b23d64a083653516a42..0cc013dcb51ecfea94d15659195a3e7763a34489 100644 (file)
@@ -1505,7 +1505,7 @@ static apr_status_t ssl_io_filter_input(ap_filter_t *f,
                           APLOGNO(02836) "ALPN selected protocol: '%s'",
                           protocol);
             
-            if (strcmp(protocol, ap_run_protocol_get(f->c))) {
+            if (strcmp(protocol, ap_get_protocol(f->c))) {
                 status = ap_switch_protocol(f->c, NULL, sslconn->server,
                                             protocol);
                 if (status != APR_SUCCESS) {
index 2c23dff99b560ebb0bb2e84b09ecce17d7505c84..b16267bc771b218a4739dbeaa0bf1266d80294cb 100644 (file)
@@ -5282,11 +5282,6 @@ static void core_dump_config(apr_pool_t *p, server_rec *s)
     }
 }
 
-static const char *core_protocol_get(const conn_rec *c) 
-{
-    return AP_PROTOCOL_HTTP1;
-}
-
 static int core_upgrade_handler(request_rec *r)
 {
     conn_rec *c = r->connection;
@@ -5308,7 +5303,7 @@ static int core_upgrade_handler(request_rec *r)
             if (offers && offers->nelts > 0) {
                 const char *protocol = ap_select_protocol(c, r, r->server,
                                                           offers);
-                if (strcmp(protocol, ap_run_protocol_get(c))) {
+                if (strcmp(protocol, ap_get_protocol(c))) {
                     ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(02909)
                                   "Upgrade selects '%s'", protocol);
                     /* Let the client know what we are upgrading to. */
@@ -5385,7 +5380,6 @@ static void register_hooks(apr_pool_t *p)
     ap_hook_open_htaccess(ap_open_htaccess, NULL, NULL, APR_HOOK_REALLY_LAST);
     ap_hook_optional_fn_retrieve(core_optional_fn_retrieve, NULL, NULL,
                                  APR_HOOK_MIDDLE);
-    ap_hook_protocol_get(core_protocol_get, NULL, NULL, APR_HOOK_REALLY_LAST);
     
     /* register the core's insert_filter hook and register core-provided
      * filters
index 444e25cc18f74b8b20bf4094d18b7b01fc2ce407..cc23ae176c5f0d958951dfece8d3cedd7526414b 100644 (file)
@@ -1971,13 +1971,19 @@ static int protocol_cmp(apr_array_header_t *preferences,
     return strcmp(proto1, proto2);
 }
 
+AP_DECLARE(const char *) ap_get_protocol(conn_rec *c)
+{
+    const char *protocol = ap_run_protocol_get(c);
+    return protocol? protocol : AP_PROTOCOL_HTTP1;
+}
+
 AP_DECLARE(const char *) ap_select_protocol(conn_rec *c, request_rec *r, 
                                             server_rec *s,
                                             apr_array_header_t *choices)
 {
     apr_pool_t *pool = r? r->pool : c->pool;
     apr_array_header_t *proposals;
-    const char *protocol = NULL, *existing = ap_run_protocol_get(c);
+    const char *protocol = NULL, *existing = ap_get_protocol(c);
     core_server_config *conf = ap_get_core_module_config(s->module_config);
 
     if (APLOGcdebug(c)) {
@@ -2038,7 +2044,7 @@ AP_DECLARE(apr_status_t) ap_switch_protocol(conn_rec *c, request_rec *r,
                                             server_rec *s,
                                             const char *protocol)
 {
-    const char *current = ap_run_protocol_get(c);
+    const char *current = ap_get_protocol(c);
     int rc;
     
     if (!strcmp(current, protocol)) {