Url::Url(const char* url_string) : m_port(-1) { const char *protocol_break = strstr(url_string, "://"); if(protocol_break == nullptr) { protocol_break = url_string; } else { int protocol_size = protocol_break - url_string; m_protocol = std::string(url_string, protocol_size); protocol_break += 3; } const char *host_break = strstr(protocol_break, "/"); int host_size; if(host_break == nullptr) { host_size = strlen(protocol_break); m_host = std::string(protocol_break, host_size); ParseHost(); return; } else { host_size = host_break - protocol_break; } m_host = std::string(protocol_break, host_size); ParseHost(); const char *path_break = strchr(host_break, '\0'); if(path_break == nullptr) return; int path_size = path_break - host_break; m_path = std::string(host_break, path_size); }
unsigned Stream::Create(std::unique_ptr<util::Stream> *result, Client *client, const char *url) { std::string host; IPEndPoint ipe; std::string path; ParseURL(url, &host, &path); std::string hostonly; ParseHost(host, 80, &hostonly, &ipe.port); ipe.addr = IPAddress::Resolve(hostonly.c_str()); if (ipe.addr.addr == 0) return ENOENT; Stream *stm = new Stream(client, ipe, host, path); LOG(HTTP) << "hs" << stm << ": " << url << "\n"; result->reset(stm); return 0; }
static BOOL ReadConfiguration(void) { unsigned int i; if (! ReadBongoConfiguration(GlobalConfig, "global")) { return FALSE; } if (! ReadBongoConfiguration(AVirusConfigSchema, "antivirus")) { return FALSE; } for (i=0; i < AVirus.clamd.hostlist->len; i++) { char *hostitem = g_array_index(AVirus.clamd.hostlist, char*, i); char *lHost = MemStrdup(hostitem); char *host; int port=AVIRUS_DEFAULT_PORT, weight=AVIRUS_DEFAULT_WEIGHT; ParseHost(lHost, &host, &port, &weight); ConnAddressPoolAddHost(&AVirus.clamd.hosts, host, port, weight); MemFree(lHost); } return TRUE; }
static void ReadAccessFile( const char *fname ) { HostEntry *hostList, **hostPtr = &hostList; AliasEntry *aliasList, **aliasPtr = &aliasList; AclEntry *acList, **acPtr = &acList, *acl; ListenEntry *listenList, **listenPtr = &listenList; char *displayOrAlias, *hostOrAlias; File file; int nHosts, nAliases, nAcls, nListens, nChars, error, bad; int i, len; nHosts = nAliases = nAcls = nListens = nChars = error = 0; if (!readFile( &file, fname, "XDMCP access control" )) goto sendacl; while ((displayOrAlias = ReadWord( &file, &len, FALSE ))) { if (*displayOrAlias == ALIAS_CHARACTER) { if (!(*aliasPtr = (AliasEntry *)Malloc( sizeof(AliasEntry)))) { error = 1; break; } (*aliasPtr)->name = displayOrAlias + 1; nChars += len; (*aliasPtr)->hosts = nHosts; (*aliasPtr)->pHosts = hostPtr; (*aliasPtr)->nhosts = 0; (*aliasPtr)->hasBad = 0; while ((hostOrAlias = ReadWord( &file, &len, TRUE ))) { if (ParseHost( &nHosts, &hostPtr, &nChars, hostOrAlias, len, PARSE_NO_BCAST )) (*aliasPtr)->nhosts++; else (*aliasPtr)->hasBad = 1; } aliasPtr = &(*aliasPtr)->next; nAliases++; } else if (!strcmp( displayOrAlias, LISTEN_STRING )) { if (!(*listenPtr = (ListenEntry *)Malloc( sizeof(ListenEntry)))) { error = 1; break; } (*listenPtr)->iface = nHosts; if (!(hostOrAlias = ReadWord( &file, &len, TRUE )) || !strcmp( hostOrAlias, WILDCARD_STRING ) || !ParseHost( &nHosts, &hostPtr, &nChars, hostOrAlias, len, PARSE_NO_BCAST|PARSE_NO_PAT|PARSE_NO_ALIAS )) { (*listenPtr)->iface = -1; } (*listenPtr)->mcasts = nHosts; (*listenPtr)->nmcasts = 0; while ((hostOrAlias = ReadWord( &file, &len, TRUE ))) { if (ParseHost( &nHosts, &hostPtr, &nChars, hostOrAlias, len, PARSE_NO_BCAST|PARSE_NO_PAT|PARSE_NO_ALIAS )) (*listenPtr)->nmcasts++; } listenPtr = &(*listenPtr)->next; nListens++; } else { if (!(*acPtr = (AclEntry *)Malloc( sizeof(AclEntry)))) { error = 1; break; } (*acPtr)->flags = 0; if (*displayOrAlias == NEGATE_CHARACTER) { (*acPtr)->flags |= a_notAllowed; displayOrAlias++; } else if (*displayOrAlias == EQUAL_CHARACTER) displayOrAlias++; (*acPtr)->entries = nHosts; (*acPtr)->pEntries = hostPtr; (*acPtr)->nentries = 1; if (!ParseHost( &nHosts, &hostPtr, &nChars, displayOrAlias, len, PARSE_NO_BCAST )) { bad = 1; if ((*acPtr)->flags & a_notAllowed) { LogError( "XDMCP ACL: unresolved host in denying rule\n" ); error = 1; } } else bad = 0; (*acPtr)->hosts = nHosts; (*acPtr)->pHosts = hostPtr; (*acPtr)->nhosts = 0; while ((hostOrAlias = ReadWord( &file, &len, TRUE ))) { if (!strcmp( hostOrAlias, CHOOSER_STRING )) (*acPtr)->flags |= a_useChooser; else if (!strcmp( hostOrAlias, NOBROADCAST_STRING )) (*acPtr)->flags |= a_notBroadcast; else { if (ParseHost( &nHosts, &hostPtr, &nChars, hostOrAlias, len, PARSE_NO_PAT )) (*acPtr)->nhosts++; } } if (!bad) { acPtr = &(*acPtr)->next; nAcls++; } } } if (!nListens) { if (!(*listenPtr = (ListenEntry *)Malloc( sizeof(ListenEntry)))) error = 1; else { (*listenPtr)->iface = -1; (*listenPtr)->mcasts = nHosts; (*listenPtr)->nmcasts = 0; #if defined(IPv6) && defined(AF_INET6) && defined(XDM_DEFAULT_MCAST_ADDR6) if (ParseHost( &nHosts, &hostPtr, &nChars, XDM_DEFAULT_MCAST_ADDR6, sizeof(XDM_DEFAULT_MCAST_ADDR6)-1, PARSE_ALL )) (*listenPtr)->nmcasts++; #endif nListens++; } } for (acl = acList, i = 0; i < nAcls; i++, acl = acl->next) if (checkHostlist( acl->pEntries, acl->nentries, aliasList, nAliases, 0, (acl->flags & a_notAllowed) ? CHECK_NOT : 0 ) || checkHostlist( acl->pHosts, acl->nhosts, aliasList, nAliases, 0, CHECK_NO_PAT )) error = 1; if (error) { nHosts = nAliases = nAcls = nListens = nChars = 0; sendacl: LogError( "No XDMCP requests will be granted\n" ); } GSendInt( nHosts ); GSendInt( nListens ); GSendInt( nAliases ); GSendInt( nAcls ); GSendInt( nChars ); for (i = 0; i < nHosts; i++, hostList = hostList->next) { GSendInt( hostList->type ); switch (hostList->type) { case HOST_ALIAS: GSendStr( hostList->entry.aliasPattern ); break; case HOST_PATTERN: GSendStr( hostList->entry.hostPattern ); break; case HOST_ADDRESS: GSendArr( hostList->entry.displayAddress.hostAddrLen, hostList->entry.displayAddress.hostAddress ); GSendInt( hostList->entry.displayAddress.connectionType ); break; } } for (i = 0; i < nListens; i++, listenList = listenList->next) { GSendInt( listenList->iface ); GSendInt( listenList->mcasts ); GSendInt( listenList->nmcasts ); } for (i = 0; i < nAliases; i++, aliasList = aliasList->next) { GSendStr( aliasList->name ); GSendInt( aliasList->hosts ); GSendInt( aliasList->nhosts ); } for (i = 0; i < nAcls; i++, acList = acList->next) { GSendInt( acList->entries ); GSendInt( acList->nentries ); GSendInt( acList->hosts ); GSendInt( acList->nhosts ); GSendInt( acList->flags ); } }