/* * sortServerByInst */ static int sortServerByInst( const void *srv1, const void *srv2 ) { if( SRV( srv1 ) == NULL ) { return( 1 ); } if( SRV( srv2 ) == NULL ) { return( -1 ); } return( stricmp( SRV( srv1 )->instname, SRV( srv2 )->instname ) ); }
/* * sortServerByServer */ static int sortServerByServer( const void *srv1, const void *srv2 ) { if( SRV( srv1 ) == NULL ) { return( 1 ); } if( SRV( srv2 ) == NULL ) { return( -1 ); } return( stricmp( SRV( srv1 )->server, SRV( srv2 )->server ) ); }
static SRV call_cn(string iCommand, deque<string>& iArguments, deque<string>& oValues) { // 名前と命令を関連付けたmap typedef SRV (*Command)(deque<string>&, deque<string>&); static map<string, Command> theMap; if ( theMap.empty() ) { // 初回準備 #define d(iName) \ SRV _##iName(deque<string>&, deque<string>&); \ theMap[ #iName ] = _##iName // 命令一覧の宣言と関連付け。 d(at); #undef d } // 命令の存在を確認 map<string, Command>::const_iterator i = theMap.find(iCommand); if ( i==theMap.end() ) { return SRV(400, string()+"Error: '"+iCommand+"'という名前の命令は定義されていません。"); } // 実際に呼ぶ return i->second(iArguments, oValues); }
SRV _at(deque<string>& iArguments, deque<string>& oValues) { if ( iArguments.size()==2 ) { } else return SRV(400, "引数が正しくありません。"); return 200; }
SRV cn::request(deque<string>& iArguments, deque<string>& oValues) { if ( iArguments.size()<1 ) return SRV(400, "命令が指定されていません"); // 最初の引数は命令名として扱う string theCommand = iArguments.front(); iArguments.pop_front(); return call_cn(theCommand, iArguments, oValues); }
BaseResolver::SRVPriorityList* BaseResolver::SRVCacheFactory::get(std::string key, int& ttl, SAS::TrailId trail) { TRC_DEBUG("SRV cache factory called for %s", key.c_str()); SRVPriorityList* srv_list = NULL; DnsResult result = _dns_client->dns_query(key, ns_t_srv, trail); if (!result.records().empty()) { // We have a result. TRC_DEBUG("SRV query returned %d records", result.records().size()); srv_list = new SRVPriorityList; ttl = result.ttl(); // Sort the records on priority. std::sort(result.records().begin(), result.records().end(), compare_srv_priority); // Now rearrange the results in to an SRV priority list (a map of vectors // for each priority level). for (std::vector<DnsRRecord*>::const_iterator i = result.records().begin(); i != result.records().end(); ++i) { DnsSrvRecord* srv_record = (DnsSrvRecord*)(*i); // Get the appropriate priority list of SRVs. std::vector<SRV>& plist = (*srv_list)[srv_record->priority()]; // Add a new entry for this SRV. plist.push_back(SRV()); SRV& srv = plist.back(); srv.target = srv_record->target(); srv.port = srv_record->port(); srv.priority = srv_record->priority(); srv.weight = srv_record->weight(); // Adjust the weight. Any items which have weight 0 are increase to // weight of one, and non-zero weights are multiplied by 100. This gives // the right behaviour as per RFC2782 - when all weights are zero we // round-robin (but still have the ability to blacklist) and when there // are non-zero weights the zero weighted items have a small (but not // specified in RFC2782) chance of selection. srv.weight = (srv.weight == 0) ? 1 : srv.weight * 100; } } else { // No results from SRV query, so return no entry with the default TTL ttl = _default_ttl; } return srv_list; }
static int openssl_sni_servername_cb (SSL *ssl, int *ad, void *arg) { ret_t ret; int re; const char *servername; cherokee_connection_t *conn; cherokee_buffer_t tmp; cherokee_server_t *srv = SRV(arg); cherokee_virtual_server_t *vsrv = NULL; UNUSED(ad); /* Get the pointer to the socket */ conn = SSL_get_app_data (ssl); if (unlikely (conn == NULL)) { LOG_ERROR (CHEROKEE_ERROR_SSL_SOCKET, ssl); return SSL_TLSEXT_ERR_ALERT_FATAL; } cherokee_buffer_init(&tmp); cherokee_buffer_ensure_size(&tmp, 40); /* Read the SNI server name */ servername = SSL_get_servername (ssl, TLSEXT_NAMETYPE_host_name); if (servername == NULL) { /* Set the server name to the IP address if we couldn't get the host name via SNI */ cherokee_socket_ntop (&conn->socket, tmp.buf, tmp.size); TRACE (ENTRIES, "No SNI: Did not provide a server name, using IP='%s' as servername.\n", tmp.buf); } else { cherokee_buffer_add (&tmp, servername, strlen(servername)); TRACE (ENTRIES, "SNI: Switching to servername='%s'\n", servername); } /* Look up and change the vserver */ ret = cherokee_cryptor_libssl_find_vserver(ssl, srv, &tmp, conn); if (ret != ret_ok) { re = SSL_TLSEXT_ERR_NOACK; } else { re = SSL_TLSEXT_ERR_OK; } cherokee_buffer_mrproper (&tmp); return re; }