everything: shotgun attempt to put PROTO_WS and PROTO_WSS across core and in modules...
authorPeter Dunkley <peter.dunkley@crocodile-rcs.com>
Fri, 29 Jun 2012 23:01:07 +0000 (00:01 +0100)
committerPeter Dunkley <peter.dunkley@crocodile-rcs.com>
Fri, 29 Jun 2012 23:01:07 +0000 (00:01 +0100)
- Bound to have missed something and lots of testing required.

13 files changed:
forward.c
ip_addr.c
modules/sanity/sanity.c
modules/tm/tm.c
modules/tm/ut.h
modules_k/permissions/hash.c
modules_k/permissions/trusted.c
modules_k/presence/subscribe.c
modules_k/presence/utils_func.h
modules_k/pv/pv_core.c
modules_k/registrar/save.c
modules_k/siptrace/siptrace.c
socket_info.c

index 89fe18f..b781661 100644 (file)
--- a/forward.c
+++ b/forward.c
@@ -286,7 +286,9 @@ struct socket_info* get_send_socket2(struct socket_info* force_send_socket,
                   except tcp_main(), see close_extra_socks() */
                if (likely((force_send_socket->socket!=-1 ||
                                                force_send_socket->proto==PROTO_TCP ||
-                                               force_send_socket->proto==PROTO_TLS) &&
+                                               force_send_socket->proto==PROTO_TLS ||
+                                               force_send_socket->proto==PROTO_WS  ||
+                                               force_send_socket->proto==PROTO_WSS) &&
                                        !(force_send_socket->flags & SI_IS_MCAST)))
                                return force_send_socket;
                else{
@@ -338,6 +340,7 @@ not_forced:
                        break;
 #endif
 #ifdef USE_TLS
+               case PROTO_WSS:
                case PROTO_TLS:
                        switch(to->s.sa_family){
                                /* FIXME */
@@ -815,8 +818,10 @@ int forward_reply(struct sip_msg* msg)
        if (
 #ifdef USE_TCP
                        dst.proto==PROTO_TCP
+                       || dst.proto==PROTO_WS
 #ifdef USE_TLS
                        || dst.proto==PROTO_TLS
+                       || dst.proto==PROTO_WSS
 #endif
 #ifdef USE_SCTP
                        ||
index 1b15c96..c071f83 100644 (file)
--- a/ip_addr.c
+++ b/ip_addr.c
@@ -350,6 +350,10 @@ char* get_proto_name(unsigned int proto)
                        return "tls";
                case PROTO_SCTP:
                        return "sctp";
+               case PROTO_WS:
+                       return "ws";
+               case PROTO_WSS:
+                       return "wss";
                default:
                        return "unknown";
        }
index 2331289..f5fe950 100644 (file)
@@ -406,6 +406,32 @@ int check_via_protocol(struct sip_msg* _msg) {
                                return SANITY_CHECK_FAILED;
                        }
                        break;
+               case PROTO_WS:
+                       if (memcmp(_msg->via1->transport.s, "WS", 2) != 0) {
+                               if (_msg->REQ_METHOD != METHOD_ACK) {
+                                       if (sanity_reply(_msg, 400,
+                                                       "Transport Missmatch in Topmost Via") < 0) {
+                                               LOG(L_WARN, "sanity_check(): check_via_protocol():"
+                                                               " failed to send 505 via sl reply\n");
+                                       }
+                               }
+                               DBG("check_via_protocol failed\n");
+                               return SANITY_CHECK_FAILED;
+                       }
+                       break;
+               case PROTO_WSS:
+                       if (memcmp(_msg->via1->transport.s, "WSS", 3) != 0) {
+                               if (_msg->REQ_METHOD != METHOD_ACK) {
+                                       if (sanity_reply(_msg, 400,
+                                                       "Transport Missmatch in Topmost Via") < 0) {
+                                               LOG(L_WARN, "sanity_check(): check_via_protocol():"
+                                                               " failed to send 505 via sl reply\n");
+                                       }
+                               }
+                               DBG("check_via_protocol failed\n");
+                               return SANITY_CHECK_FAILED;
+                       }
+                       break;
                default:
                        LOG(L_WARN, "sanity_check(): check_via_protocol():"
                                        " unknown protocol in received structure\n");
index 3ca56ba..a251826 100644 (file)
@@ -1039,7 +1039,12 @@ inline static int str2proto(char *s, int len) {
                return PROTO_TLS;       
        else if (len == 4 && !strncasecmp(s, "sctp", 4))
                return PROTO_SCTP;
-       else
+       else if (len == 2 && !strncasecmp(s, "ws", 2))
+               return PROTO_WS;
+       else if (len == 3 && !strncasecmp(s, "wss", 3)) {
+               LM_WARN("\"wss\" used somewhere...\n");
+               return PROTO_WS;
+       } else
                return PROTO_NONE;
 }
 
index 3a9f1f2..7e10482 100644 (file)
@@ -92,6 +92,7 @@ inline static enum sip_protos get_proto(enum sip_protos force_proto,
                                case PROTO_SCTP:
 #endif
                                                return proto;
+                               case PROTO_WSS: /* should never see ;transport=wss */
                                default:
                                                LOG(L_ERR, "ERROR: get_proto: unsupported transport:"
                                                                " %d\n", proto );
@@ -104,6 +105,7 @@ inline static enum sip_protos get_proto(enum sip_protos force_proto,
 #endif
 #ifdef USE_TLS
                case PROTO_TLS:
+               case PROTO_WSS:
 #endif
 #ifdef USE_SCTP
                case PROTO_SCTP:
@@ -138,8 +140,10 @@ inline static struct proxy_l *uri2proxy( str *uri, int proto )
                        LOG(L_ERR, "ERROR: uri2proxy: bad transport for sips uri: %d\n",
                                        parsed_uri.proto);
                        return 0;
-               }else
+               }else if (parsed_uri.proto != PROTO_WS)
                        uri_proto=PROTO_TLS;
+               else
+                       uri_proto=PROTO_WS;
        }else
                uri_proto=parsed_uri.proto;
 #ifdef HONOR_MADDR
@@ -196,8 +200,10 @@ inline static int get_uri_send_info(str* uri, str* host, unsigned short* port,
                        LOG(L_ERR, "ERROR: get_uri_send_info: bad transport for"
                                                " sips uri: %d\n", parsed_uri.proto);
                        return -1;
-               }else
+               }else if (parsed_uri.proto != PROTO_WS)
                        uri_proto=PROTO_TLS;
+               else
+                       uri_proto=PROTO_WS;
        }else
                uri_proto=parsed_uri.proto;
        
@@ -272,8 +278,10 @@ inline static struct dest_info *uri2dst2(struct dest_info* dst,
                        LOG(L_ERR, "ERROR: uri2dst: bad transport for sips uri: %d\n",
                                        parsed_uri.proto);
                        return 0;
-               }else
+               }else if (parsed_uri.proto!=PROTO_WS)
                        uri_proto=PROTO_TLS;
+               else
+                       uri_proto=PROTO_WS;
        }else
                uri_proto=parsed_uri.proto;
        
index 72ebc41..92c5578 100644 (file)
@@ -141,6 +141,10 @@ int hash_table_insert(struct trusted_list** table, char* src_ip,
                np->proto = PROTO_TLS;
        } else if (strcasecmp(proto, "sctp") == 0) {
                np->proto = PROTO_SCTP;
+       } else if (strcasecmp(proto, "ws") == 0) {
+               np->proto = PROTO_WS;
+       } else if (strcasecmp(proto, "wss") == 0) {
+               np->proto = PROTO_WSS;
        } else if (strcasecmp(proto, "none") == 0) {
                shm_free(np);
                return 1;
index 96c03e7..3e79315 100644 (file)
@@ -324,6 +324,22 @@ static inline int match_proto(const char *proto_string, int proto_int)
                }
        }
 
+       if (proto_int == PROTO_WS) {
+               if (strcasecmp(proto_string, "ws") == 0) {
+                       return 1;
+               } else {
+                       return 0;
+               }
+       }
+       
+       if (proto_int == PROTO_WSS) {
+               if (strcasecmp(proto_string, "wss") == 0) {
+                       return 1;
+               } else {
+                       return 0;
+               }
+       }
+
        LM_ERR("unknown request protocol\n");
 
        return 0;
@@ -512,6 +528,13 @@ int allow_trusted_2(struct sip_msg* _msg, char* _src_ip_sp, char* _proto_sp)
            proto_int = PROTO_SCTP;
        } else goto error;
        break;
+    case 'w': case 'W':
+       if (proto.len==2 && strncasecmp(proto.s, "ws", 2) == 0) {
+           proto_int = PROTO_WS;
+       } else if (proto.len==3 && strncasecmp(proto.s, "wss", 3) == 0) {
+           proto_int = PROTO_WSS;
+       } else goto error;
+        break;
     default:
        goto error;
     }
index c8e9960..b413d4c 100644 (file)
@@ -103,6 +103,12 @@ int send_2XX_reply(struct sip_msg * msg, int reply_code, int lexpire,
                                strncpy(tmp.s, ";transport=sctp", 15);
                                tmp.s += 15;
                        break;
+                       case PROTO_WS:
+                       case PROTO_WSS:
+                               strncpy(tmp.s, ";transport=ws", 13);
+                               tmp.s += 13;
+                               hdr_append.len -= 2;
+                       break;
                        default:
                                hdr_append.len -= 15;
                }
index 8a76944..6a73702 100644 (file)
@@ -117,6 +117,11 @@ static inline int ps_fill_local_contact(struct sip_msg* msg, str *contact)
                proto= "sctp";
                plen = 4;
        }
+       else    
+       if(msg->rcv.proto== PROTO_WS || msg->rcv.proto== PROTO_WSS) {
+               proto= "ws";
+               plen = 2;
+       }
        else
        {
                LM_ERR("unsupported proto\n");
index 370ec1a..cf5bc56 100644 (file)
@@ -868,6 +868,12 @@ int pv_get_proto(struct sip_msg *msg, pv_param_t *param,
                        s.s = "sctp";
                        s.len = 4;
                break;
+               case PROTO_WS:
+                       s.s = "ws";
+                       s.len = 2;
+               case PROTO_WSS:
+                       s.s = "wss";
+                       s.len = 3;
                default:
                        s.s = "NONE";
                        s.len = 4;
index 8f18ea7..4b3eda2 100644 (file)
@@ -440,7 +440,7 @@ static inline int insert_contacts(struct sip_msg* _m, udomain_t* _d, str* _a)
        flags = mem_only;
 #ifdef USE_TCP
        if ( (_m->flags&tcp_persistent_flag) &&
-       (_m->rcv.proto==PROTO_TCP||_m->rcv.proto==PROTO_TLS)) {
+       (_m->rcv.proto==PROTO_TCP||_m->rcv.proto==PROTO_TLS||_m->rcv.proto==PROTO_WS||_m->rcv.proto==PROTO_WSS)) {
                e_max = 0;
                tcp_check = 1;
        } else {
@@ -505,7 +505,7 @@ static inline int insert_contacts(struct sip_msg* _m, udomain_t* _d, str* _a)
                        if (parse_uri( _c->uri.s, _c->uri.len, &uri)<0) {
                                LM_ERR("failed to parse contact <%.*s>\n", 
                                                _c->uri.len, _c->uri.s);
-                       } else if (uri.proto==PROTO_TCP || uri.proto==PROTO_TLS) {
+                       } else if (uri.proto==PROTO_TCP || uri.proto==PROTO_TLS || uri.proto==PROTO_WS || uri.proto==PROTO_WSS) {
                                if (e_max) {
                                        LM_WARN("multiple TCP contacts on single REGISTER\n");
                                        if (expires>e_max) e_max = expires;
@@ -637,7 +637,7 @@ static inline int update_contacts(struct sip_msg* _m, urecord_t* _r,
 
 #ifdef USE_TCP
        if ( (_m->flags&tcp_persistent_flag) &&
-       (_m->rcv.proto==PROTO_TCP||_m->rcv.proto==PROTO_TLS)) {
+       (_m->rcv.proto==PROTO_TCP||_m->rcv.proto==PROTO_TLS||_m->rcv.proto==PROTO_WS||_m->rcv.proto==PROTO_WSS)) {
                e_max = -1;
                tcp_check = 1;
        } else {
@@ -742,7 +742,7 @@ static inline int update_contacts(struct sip_msg* _m, urecord_t* _r,
                        if (parse_uri( _c->uri.s, _c->uri.len, &uri)<0) {
                                LM_ERR("failed to parse contact <%.*s>\n", 
                                                _c->uri.len, _c->uri.s);
-                       } else if (uri.proto==PROTO_TCP || uri.proto==PROTO_TLS) {
+                       } else if (uri.proto==PROTO_TCP || uri.proto==PROTO_TLS || uri.proto==PROTO_WS || uri.proto==PROTO_WSS) {
                                if (e_max>0) {
                                        LM_WARN("multiple TCP contacts on single REGISTER\n");
                                }
index eb893a3..ea2e818 100644 (file)
@@ -478,6 +478,10 @@ static inline int siptrace_copy_proto(int proto, char *buf)
                strcpy(buf, "tls:");
        } else if(proto==PROTO_SCTP) {
                strcpy(buf, "sctp:");
+       } else if(proto==PROTO_WS) {
+               strcpy(buf, "ws:");
+       } else if(proto==PROTO_WSS) {
+               strcpy(buf, "wss:");
        } else {
                strcpy(buf, "udp:");
        }
index ad6fe9b..f8655b9 100644 (file)
@@ -482,6 +482,7 @@ struct socket_info** get_sock_info_list(unsigned short proto)
 #endif
                        break;
                case PROTO_TLS:
+               case PROTO_WSS:
 #ifdef USE_TLS
                        return &tls_listen;
 #endif
@@ -2052,6 +2053,9 @@ void init_proto_order()
                        if (nxt_proto[r]==PROTO_SCTP)
                                nxt_proto[r]=nxt_proto[PROTO_SCTP];
                }
+
+       /* Deliberately skipping PROTO_WS and PROTO_WSS here as these
+          are just upgraded TCP and TLS connections */
 }