1 /** @file 2 3 ALPNSupport implements common methods and members to 4 support protocols for ALPN negotiation 5 6 @section license License 7 8 Licensed to the Apache Software Foundation (ASF) under one 9 or more contributor license agreements. See the NOTICE file 10 distributed with this work for additional information 11 regarding copyright ownership. The ASF licenses this file 12 to you under the Apache License, Version 2.0 (the 13 "License"); you may not use this file except in compliance 14 with the License. You may obtain a copy of the License at 15 16 http://www.apache.org/licenses/LICENSE-2.0 17 18 Unless required by applicable law or agreed to in writing, software 19 distributed under the License is distributed on an "AS IS" BASIS, 20 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 See the License for the specific language governing permissions and 22 limitations under the License. 23 */ 24 25 #pragma once 26 #include "records/I_RecHttp.h" 27 28 class SSLNextProtocolSet; 29 class SSLNextProtocolAccept; 30 class Continuation; 31 32 class ALPNSupport 33 { 34 public: 35 void registerNextProtocolSet(SSLNextProtocolSet *, const SessionProtocolSet &protos); 36 void disableProtocol(int idx); 37 void enableProtocol(int idx); 38 void clear(); 39 bool setSelectedProtocol(const unsigned char *proto, unsigned int len); 40 41 Continuation * endpoint()42 endpoint() const 43 { 44 return npnEndpoint; 45 } 46 47 bool getNPN(const unsigned char ** out,unsigned int * outlen)48 getNPN(const unsigned char **out, unsigned int *outlen) const 49 { 50 if (this->npn && this->npnsz) { 51 *out = this->npn; 52 *outlen = this->npnsz; 53 return true; 54 } 55 return false; 56 } 57 58 const SSLNextProtocolSet * getNextProtocolSet()59 getNextProtocolSet() const 60 { 61 return npnSet; 62 } 63 64 void set_negotiated_protocol_id(const ts::TextView &proto); 65 int get_negotiated_protocol_id() const; 66 67 private: 68 const SSLNextProtocolSet *npnSet = nullptr; 69 SessionProtocolSet protoenabled; 70 // Local copies of the npn strings 71 unsigned char *npn = nullptr; 72 size_t npnsz = 0; 73 Continuation *npnEndpoint = nullptr; 74 int _negotiated_proto_id = SessionProtocolNameRegistry::INVALID; 75 }; 76 77 // 78 // Inline functions 79 // 80 81 inline void set_negotiated_protocol_id(const ts::TextView & proto)82ALPNSupport::set_negotiated_protocol_id(const ts::TextView &proto) 83 { 84 _negotiated_proto_id = globalSessionProtocolNameRegistry.indexFor(proto); 85 } 86 87 inline int get_negotiated_protocol_id()88ALPNSupport::get_negotiated_protocol_id() const 89 { 90 return _negotiated_proto_id; 91 } 92