std::string ServiceContext::getServerIpFromClientIp(int clientip) { std::string serverAddress; char host[NI_MAXHOST]; struct ifaddrs *ifaddr = NULL; if (getifaddrs(&ifaddr) == 0) { for (struct ifaddrs* ifa = ifaddr; ifa != NULL; ifa = ifa->ifa_next) { if ( (ifa->ifa_netmask != NULL) && (ifa->ifa_netmask->sa_family == AF_INET) && (ifa->ifa_addr != NULL) && (ifa->ifa_addr->sa_family == AF_INET) ) { struct sockaddr_in* addr = (struct sockaddr_in*)ifa->ifa_addr; struct sockaddr_in* mask = (struct sockaddr_in*)ifa->ifa_netmask; if ( (addr->sin_addr.s_addr & mask->sin_addr.s_addr) == (clientip & mask->sin_addr.s_addr) ) { if (getnameinfo(ifa->ifa_addr, sizeof(struct sockaddr_in), host, sizeof(host), NULL, 0, NI_NUMERICHOST) == 0) { serverAddress = host; break; } } } } } freeifaddrs(ifaddr); if (serverAddress.empty()) { serverAddress = getLocalIp(); } return serverAddress; }
//! Host a server. void LobbyState::hostServer() { // Get the users public and local IP string publicIp = getPublicIp(); string localIp = getLocalIp(); // Add game to the database gDatabase->addServer(mUsername, getPublicIp(), getLocalIp()); // Change the state changeState(PlayingOnline::Instance()); PlayingOnline::Instance()->startServer(); PlayingOnline::Instance()->setPlayerName(mUsername); // Sound gSound->playEffect(GAME_HOSTED_SOUND); }
void NmdcHub::connect(const User* aUser) { checkstate(); dcdebug("NmdcHub::connectToMe %s\n", aUser->getNick().c_str()); if(SETTING(CONNECTION_TYPE) == SettingsManager::CONNECTION_ACTIVE) { send("$ConnectToMe " + toNmdc(aUser->getNick()) + " " + getLocalIp() + ":" + Util::toString(SETTING(IN_PORT)) + "|"); } else { send("$RevConnectToMe " + toNmdc(getNick()) + " " + toNmdc(aUser->getNick()) + "|"); } }
Server::Server() :TimeStep(sf::seconds(1 / 128.f)), TimeSync(sf::seconds(1 / 120.f)) { mListener.listen(sf::Socket::AnyPort); mListener.setBlocking(false); mPeers.push_back(std::unique_ptr<Peer>(new Peer)); std::cout << "Server IP: " << getLocalIp() << "\n"; std::cout << "Server Port: " << mListener.getLocalPort() << "\n"; }
//this function returns my node ID //if my node ID can't be retrieved, return -1 int topology_getMyNodeID() { char* ip = getLocalIp(); int a,b,c,nodeId = 0x100; sscanf(ip,"%d.%d.%d.%d",&a,&b,&c,&nodeId); if(nodeId < 0 || nodeId > 0xff){ return -1; } return nodeId; }
/** * Converts stored data into POST compatible data * @return string containing POST data */ std::string Report::toPost() { std::string data = "&"; data += "localip="; data += getLocalIp(); data += "&wifi="; data += getWifi(); data += "&traceroute="; data += getTraceroute(); return data; }
void AtDrv::getNetworkData(uint8_t *ip, uint8_t *mask, uint8_t *gwip) { if(!isAtMode()) { if(!switchToAtMode()) { INFO1("Can't switch to at mode"); memset(ip, 0, 4); memcpy(mask, 0, 4); memcpy(gwip, 0, 4); goto end; } } getLocalIp(ip); getNetmask(mask); getGateway(gwip); end: return; }
int resolveMAC(SceNetEtherAddr * mac, uint32_t * ip) { // Get Local MAC Address SceNetEtherAddr localMac; getLocalMac(&localMac); // Local MAC Requested if(memcmp(&localMac, mac, sizeof(SceNetEtherAddr)) == 0) { // Get Local IP Address sockaddr_in sockAddr; getLocalIp(&sockAddr); *ip = sockAddr.sin_addr.s_addr; return 0; // return succes } // Multithreading Lock peerlock.lock(); // Peer Reference SceNetAdhocctlPeerInfo * peer = friends; // Iterate Peers for(; peer != NULL; peer = peer->next) { // Found Matching Peer if(memcmp(&peer->mac_addr, mac, sizeof(SceNetEtherAddr)) == 0) { // Copy Data *ip = peer->ip_addr; // Multithreading Unlock peerlock.unlock(); // Return Success return 0; } } // Multithreading Unlock peerlock.unlock(); // Peer not found return -1; }
void NmdcHub::search(int aSizeType, int64_t aSize, int aFileType, const string& aString){ checkstate(); char* buf; char c1 = (aSizeType == SearchManager::SIZE_DONTCARE) ? 'F' : 'T'; char c2 = (aSizeType == SearchManager::SIZE_ATLEAST) ? 'F' : 'T'; string tmp = toNmdc(aString); string::size_type i; while((i = tmp.find(' ')) != string::npos) { tmp[i] = '$'; } int chars = 0; if(SETTING(CONNECTION_TYPE) == SettingsManager::CONNECTION_ACTIVE) { string x = getLocalIp(); buf = new char[x.length() + aString.length() + 64]; chars = sprintf(buf, "$Search %s:%d %c?%c?%s?%d?%s|", x.c_str(), SETTING(IN_PORT), c1, c2, Util::toString(aSize).c_str(), aFileType+1, tmp.c_str()); } else { buf = new char[getNick().length() + aString.length() + 64]; chars = sprintf(buf, "$Search Hub:%s %c?%c?%s?%d?%s|", getNick().c_str(), c1, c2, Util::toString(aSize).c_str(), aFileType+1, tmp.c_str()); } send(buf, chars); delete[] buf; }
void ClientThread::selectPassivePort(){ // Passive mode SOCKET conn; mPassiveDataSocket = INVALID_SOCKET; for (int port = BEGIN_DATA_PORT; port < END_DATA_PORT; port++) { if ( INVALID_SOCKET == (conn=socket(AF_INET,SOCK_STREAM,0))) { continue; } sockaddr_in local_addr; local_addr.sin_family=AF_INET; local_addr.sin_port=htons(port); local_addr.sin_addr.s_addr=0; if (SOCKET_ERROR == bind(conn,(sockaddr *) &local_addr, sizeof(local_addr))) { return; } if (listen(conn, 1)) { // ќшибк return; } SOCKET client_socket; // сокет дл¤ клиента sockaddr_in client_addr; // адрес клиента int client_addr_size=sizeof(client_addr); QString saddr = QString("Entering Passive Mode " + getAddrFormat(getLocalIp(),port)); sendString(FTPProtocol::getInstance()->getResponse(227, saddr)); client_socket=accept(conn, (sockaddr *)&client_addr, &client_addr_size); closesocket(conn); mPassiveDataSocket = client_socket; return; } }
int resolveIP(uint32_t ip, SceNetEtherAddr * mac) { sockaddr_in addr; getLocalIp(&addr); uint32 localIp = addr.sin_addr.s_addr; if(ip == localIp){ getLocalMac(mac); return 0; } // Multithreading Lock peerlock.lock(); // Peer Reference SceNetAdhocctlPeerInfo * peer = friends; // Iterate Peers for(; peer != NULL; peer = peer->next) { // Found Matching Peer if(peer->ip_addr == ip) { // Copy Data *mac = peer->mac_addr; // Multithreading Unlock peerlock.unlock(); // Return Success return 0; } } // Multithreading Unlock peerlock.unlock(); // Peer not found return -1; }
void NmdcHub::onLine(const string& aLine) throw() { lastActivity = GET_TICK(); if(aLine.length() == 0) return; if(aLine[0] != '$') { // Check if we're being banned... if(state != STATE_CONNECTED) { if(Util::findSubString(aLine, "banned") != string::npos) { reconnect = false; } } Speaker<NmdcHubListener>::fire(NmdcHubListener::Message(), this, Util::validateMessage(fromNmdc(aLine), true)); return; } string cmd; string param; string::size_type x; if( (x = aLine.find(' ')) == string::npos) { cmd = aLine; } else { cmd = aLine.substr(0, x); param = aLine.substr(x+1); } if(cmd == "$Search") { if(state != STATE_CONNECTED) { return; } string::size_type i = 0; string::size_type j = param.find(' ', i); if(j == string::npos || i == j) return; string seeker = fromNmdc(param.substr(i, j-i)); // Filter own searches if(SETTING(CONNECTION_TYPE) == SettingsManager::CONNECTION_ACTIVE) { if(seeker == (getLocalIp() + ":" + Util::toString(SETTING(IN_PORT)))) { return; } } else { // Hub:seeker if(Util::stricmp(seeker.c_str() + 4, getNick().c_str()) == 0) { return; } } i = j + 1; { Lock l(cs); u_int32_t tick = GET_TICK(); seekers.push_back(make_pair(seeker, tick)); // First, check if it's a flooder FloodIter fi; for(fi = flooders.begin(); fi != flooders.end(); ++fi) { if(fi->first == seeker) { return; } } int count = 0; for(fi = seekers.begin(); fi != seekers.end(); ++fi) { if(fi->first == seeker) count++; if(count > 7) { if(seeker.compare(0, 4, "Hub:") == 0) Speaker<NmdcHubListener>::fire(NmdcHubListener::SearchFlood(), this, seeker.substr(4)); else Speaker<NmdcHubListener>::fire(NmdcHubListener::SearchFlood(), this, seeker + STRING(NICK_UNKNOWN)); flooders.push_back(make_pair(seeker, tick)); return; } } } int a; if(param[i] == 'F') { a = SearchManager::SIZE_DONTCARE; } else if(param[i+2] == 'F') { a = SearchManager::SIZE_ATLEAST; } else { a = SearchManager::SIZE_ATMOST; } i += 4; j = param.find('?', i); if(j == string::npos || i == j) return; string size = param.substr(i, j-i); i = j + 1; j = param.find('?', i); if(j == string::npos || i == j) return; int type = Util::toInt(param.substr(i, j-i)) - 1; i = j + 1; param = param.substr(i); if(param.size() > 0) { Speaker<NmdcHubListener>::fire(NmdcHubListener::Search(), this, seeker, a, Util::toInt64(size), type, fromNmdc(param)); if(seeker.compare(0, 4, "Hub:") == 0) { User::Ptr u; { Lock l(cs); User::NickIter ni = users.find(seeker.substr(4)); if(ni != users.end() && !ni->second->isSet(User::PASSIVE)) { u = ni->second; u->setFlag(User::PASSIVE); } } if(u) { updated(u); } } } } else if(cmd == "$MyINFO") { string::size_type i, j; i = 5; j = param.find(' ', i); if( (j == string::npos) || (j == i) ) return; string nick = fromNmdc(param.substr(i, j-i)); i = j + 1; User::Ptr u; dcassert(nick.size() > 0); { Lock l(cs); User::NickIter ni = users.find(nick); if(ni == users.end()) { u = users[nick] = ClientManager::getInstance()->getUser(nick, this); } else { u = ni->second; } } j = param.find('$', i); if(j == string::npos) return; string tmpDesc = Util::validateMessage(fromNmdc(param.substr(i, j-i)), true); // Look for a tag... if(tmpDesc.size() > 0 && tmpDesc[tmpDesc.size()-1] == '>') { x = tmpDesc.rfind('<'); if(x != string::npos) { // Hm, we have something... u->setTag(tmpDesc.substr(x)); tmpDesc.erase(x); } else { u->setTag(Util::emptyString); } } else { u->setTag(Util::emptyString); } u->setDescription(tmpDesc); i = j + 3; j = param.find('$', i); if(j == string::npos) return; u->setConnection(fromNmdc(param.substr(i, j-i-1))); i = j + 1; j = param.find('$', i); if(j == string::npos) return; u->setEmail(Util::validateMessage(fromNmdc(param.substr(i, j-i)), true)); i = j + 1; j = param.find('$', i); if(j == string::npos) return; u->setBytesShared(param.substr(i, j-i)); Speaker<NmdcHubListener>::fire(NmdcHubListener::MyInfo(), this, u); } else if(cmd == "$Quit") { if(!param.empty()) { User::Ptr u; { Lock l(cs); User::NickIter i = users.find(fromNmdc(param)); if(i == users.end()) { dcdebug("C::onLine Quitting user %s not found\n", param.c_str()); return; } u = i->second; users.erase(i); } Speaker<NmdcHubListener>::fire(NmdcHubListener::Quit(), this, u); ClientManager::getInstance()->putUserOffline(u, true); } } else if(cmd == "$ConnectToMe") { if(state != STATE_CONNECTED) { return; } string::size_type i = param.find(' '); string::size_type j; if( (i == string::npos) || ((i + 1) >= param.size()) ) { return; } i++; j = param.find(':', i); if(j == string::npos) { return; } string server = fromNmdc(param.substr(i, j-i)); if(j+1 >= param.size()) { return; } string port = param.substr(j+1); ConnectionManager::getInstance()->connect(server, (short)Util::toInt(port), getNick()); Speaker<NmdcHubListener>::fire(NmdcHubListener::ConnectToMe(), this, server, (short)Util::toInt(port)); } else if(cmd == "$RevConnectToMe") { if(state != STATE_CONNECTED) { return; } User::Ptr u; bool up = false; { Lock l(cs); string::size_type j = param.find(' '); if(j == string::npos) { return; } User::NickIter i = users.find(fromNmdc(param.substr(0, j))); if(i == users.end()) { return; } u = i->second; if(!u->isSet(User::PASSIVE)) { u->setFlag(User::PASSIVE); up = true; } } if(u) { if(SETTING(CONNECTION_TYPE) == SettingsManager::CONNECTION_ACTIVE) { connectToMe(u); Speaker<NmdcHubListener>::fire(NmdcHubListener::RevConnectToMe(), this, u); } else { // Notify the user that we're passive too... if(up) revConnectToMe(u); } if(up) updated(u); } } else if(cmd == "$SR") { SearchManager::getInstance()->onSearchResult(aLine); } else if(cmd == "$HubName") { name = fromNmdc(param); Speaker<NmdcHubListener>::fire(NmdcHubListener::HubName(), this); } else if(cmd == "$Supports") { StringTokenizer<string> st(param, ' '); StringList& sl = st.getTokens(); for(StringIter i = sl.begin(); i != sl.end(); ++i) { if(*i == "UserCommand") { supportFlags |= SUPPORTS_USERCOMMAND; } else if(*i == "NoGetINFO") { supportFlags |= SUPPORTS_NOGETINFO; } else if(*i == "UserIP2") { supportFlags |= SUPPORTS_USERIP2; } } Speaker<NmdcHubListener>::fire(NmdcHubListener::Supports(), this, sl); } else if(cmd == "$UserCommand") { string::size_type i = 0; string::size_type j = param.find(' '); if(j == string::npos) return; int type = Util::toInt(param.substr(0, j)); i = j+1; if(type == UserCommand::TYPE_SEPARATOR || type == UserCommand::TYPE_CLEAR) { int ctx = Util::toInt(param.substr(i)); Speaker<NmdcHubListener>::fire(NmdcHubListener::UserCommand(), this, type, ctx, Util::emptyString, Util::emptyString); } else if(type == UserCommand::TYPE_RAW || type == UserCommand::TYPE_RAW_ONCE) { j = param.find(' ', i); if(j == string::npos) return; int ctx = Util::toInt(param.substr(i)); i = j+1; j = param.find('$'); if(j == string::npos) return; string name = fromNmdc(param.substr(i, j-i)); i = j+1; string command = fromNmdc(param.substr(i, param.length() - i)); Speaker<NmdcHubListener>::fire(NmdcHubListener::UserCommand(), this, type, ctx, Util::validateMessage(name, true, false), Util::validateMessage(command, true, false)); } } else if(cmd == "$Lock") { if(state != STATE_LOCK) { return; } state = STATE_HELLO; if(!param.empty()) { string::size_type j = param.find(" Pk="); string lock, pk; if( j != string::npos ) { lock = param.substr(0, j); pk = param.substr(j + 4); } else { // Workaround for faulty linux hubs... j = param.find(" "); if(j != string::npos) lock = param.substr(0, j); else lock = param; } if(CryptoManager::getInstance()->isExtended(lock)) { StringList feat; feat.push_back("UserCommand"); feat.push_back("NoGetINFO"); feat.push_back("NoHello"); feat.push_back("UserIP2"); feat.push_back("TTHSearch"); if(BOOLSETTING(COMPRESS_TRANSFERS)) feat.push_back("GetZBlock"); supports(feat); } key(CryptoManager::getInstance()->makeKey(lock)); validateNick(getNick()); Speaker<NmdcHubListener>::fire(NmdcHubListener::CLock(), this, lock, pk); } } else if(cmd == "$Hello") { if(!param.empty()) { string nick = fromNmdc(param); User::Ptr u = ClientManager::getInstance()->getUser(nick, this); { Lock l(cs); users[nick] = u; } if(getNick() == nick) { setMe(u); u->setFlag(User::DCPLUSPLUS); if(SETTING(CONNECTION_TYPE) != SettingsManager::CONNECTION_ACTIVE) u->setFlag(User::PASSIVE); else u->unsetFlag(User::PASSIVE); } if(state == STATE_HELLO) { state = STATE_CONNECTED; updateCounts(false); version(); getNickList(); myInfo(); } Speaker<NmdcHubListener>::fire(NmdcHubListener::Hello(), this, u); } } else if(cmd == "$ForceMove") { disconnect(); Speaker<NmdcHubListener>::fire(NmdcHubListener::Redirect(), this, param); } else if(cmd == "$HubIsFull") { Speaker<NmdcHubListener>::fire(NmdcHubListener::HubFull(), this); } else if(cmd == "$ValidateDenide") { // Mind the spelling... disconnect(); Speaker<NmdcHubListener>::fire(NmdcHubListener::ValidateDenied(), this); } else if(cmd == "$UserIP") { if(!param.empty()) { User::List v; StringTokenizer<string> t(fromNmdc(param), "$$"); StringList& l = t.getTokens(); for(StringIter it = l.begin(); it != l.end(); ++it) { string::size_type j = 0; if((j = it->find(' ')) == string::npos) continue; if((j+1) == it->length()) continue; v.push_back(ClientManager::getInstance()->getUser(it->substr(0, j), this)); v.back()->setIp(it->substr(j+1)); } Speaker<NmdcHubListener>::fire(NmdcHubListener::UserIp(), this, v); } } else if(cmd == "$NickList") { if(!param.empty()) { User::List v; StringTokenizer<string> t(fromNmdc(param), "$$"); StringList& sl = t.getTokens(); for(StringIter it = sl.begin(); it != sl.end(); ++it) { v.push_back(ClientManager::getInstance()->getUser(*it, this)); } { Lock l(cs); for(User::Iter it2 = v.begin(); it2 != v.end(); ++it2) { users[(*it2)->getNick()] = *it2; } } if(!(getSupportFlags() & SUPPORTS_NOGETINFO)) { string tmp; // Let's assume 10 characters per nick... tmp.reserve(v.size() * (11 + 10 + getNick().length())); for(User::List::const_iterator i = v.begin(); i != v.end(); ++i) { tmp += "$GetINFO "; tmp += (*i)->getNick(); tmp += ' '; tmp += getNick(); tmp += '|'; } if(!tmp.empty()) { send(tmp); } } Speaker<NmdcHubListener>::fire(NmdcHubListener::NickList(), this, v); } } else if(cmd == "$OpList") { if(!param.empty()) { User::List v; StringTokenizer<string> t(fromNmdc(param), "$$"); StringList& sl = t.getTokens(); for(StringIter it = sl.begin(); it != sl.end(); ++it) { v.push_back(ClientManager::getInstance()->getUser(*it, this)); v.back()->setFlag(User::OP); } { Lock l(cs); for(User::Iter it2 = v.begin(); it2 != v.end(); ++it2) { users[(*it2)->getNick()] = *it2; } } Speaker<NmdcHubListener>::fire(NmdcHubListener::OpList(), this, v); updateCounts(false); // Special...to avoid op's complaining that their count is not correctly // updated when they log in (they'll be counted as registered first...) myInfo(); } } else if(cmd == "$To:") { string::size_type i = param.find("From:"); if(i != string::npos) { i+=6; string::size_type j = param.find("$"); if(j != string::npos) { string from = fromNmdc(param.substr(i, j - 1 - i)); if(from.size() > 0 && param.size() > (j + 1)) { Speaker<NmdcHubListener>::fire(NmdcHubListener::PrivateMessage(), this, ClientManager::getInstance()->getUser(from, this, false), Util::validateMessage(fromNmdc(param.substr(j + 1)), true)); } } } } else if(cmd == "$GetPass") { setRegistered(true); Speaker<NmdcHubListener>::fire(NmdcHubListener::GetPassword(), this); } else if(cmd == "$BadPass") { Speaker<NmdcHubListener>::fire(NmdcHubListener::BadPassword(), this); } else if(cmd == "$LogedIn") { Speaker<NmdcHubListener>::fire(NmdcHubListener::LoggedIn(), this); } else { dcassert(cmd[0] == '$'); dcdebug("NmdcHub::onLine Unknown command %s\n", aLine.c_str()); } }
UtlBoolean SipClient::isAcceptableForDestination( const UtlString& hostName, int hostPort, const UtlString& localIp ) { UtlBoolean isAcceptable = FALSE; // Only accept it if the local IP is correct. if (0 == strcmp(getLocalIp(), localIp)) { if( isSharedSocket() ) { // A shared socket implies that it is not connected to any specific far-end host and // therefore can be used to send to any destination. isAcceptable = TRUE; } else { int tempHostPort = portIsValid(hostPort) ? hostPort : defaultPort(); #ifdef TEST_SOCKET Os::Logger::instance().log(FAC_SIP, PRI_DEBUG, "SipClient[%s]::isAcceptableForDestination hostName = '%s', tempHostPort = %d, mRemoteHostName = '%s', mRemoteHostPort = %d, mRemoteSocketAddress = '%s', mReceivedAddress = '%s', mRemoteViaAddress = '%s'", mName.data(), hostName.data(), tempHostPort, mRemoteHostName.data(), mRemoteHostPort, mRemoteSocketAddress.data(), mReceivedAddress.data(), mRemoteViaAddress.data()); #endif // If the ports match and the host is the same as either the // original name that the socket was constructed with or the // name it was resolved to (usually an IP address). if ( mRemoteHostPort == tempHostPort && ( hostName.compareTo(mRemoteHostName, UtlString::ignoreCase) == 0 || hostName.compareTo(mRemoteSocketAddress, UtlString::ignoreCase) == 0)) { isAcceptable = TRUE; } else if ( mRemoteReceivedPort == tempHostPort && hostName.compareTo(mReceivedAddress, UtlString::ignoreCase) == 0) { isAcceptable = TRUE; } else if ( mSocketType == OsSocket::SSL_SOCKET && ( hostName.compareTo(mRemoteHostName, UtlString::ignoreCase) == 0 || hostName.compareTo(mRemoteSocketAddress, UtlString::ignoreCase) == 0 || hostName.compareTo(mReceivedAddress, UtlString::ignoreCase) == 0 || hostName.compareTo(mRemoteViaAddress, UtlString::ignoreCase) == 0 ) ) { isAcceptable = TRUE; } else if ( mRemoteViaPort == tempHostPort && hostName.compareTo(mRemoteViaAddress, UtlString::ignoreCase) == 0) { // Cannot trust what the other side said was their IP address // as this is a bad spoofing/denial of service hole Os::Logger::instance().log(FAC_SIP, PRI_DEBUG, "SipClient[%s]::isAcceptableForDestination matches %s:%d but is not trusted", mName.data(), mRemoteViaAddress.data(), mRemoteViaPort); } } } // Make sure client is okay before declaring it acceptable if( isAcceptable && !isOk() ) { Os::Logger::instance().log(FAC_SIP, PRI_DEBUG, "SipClient[%s]::isAcceptableForDestination('%s', %d, '%s')" " Client matches host/port but is not OK", mName.data(), hostName.data(), hostPort, localIp.data()); isAcceptable = FALSE; } return(isAcceptable); }
int main(int argc, char* argv[]) { std::string url = "http://127.0.0.1:8080"; std::string username; std::string password; int c=0; while ((c = getopt (argc, argv, "hu:p:")) != -1) { switch (c) { case 'u': username = optarg; break; case 'p': password = optarg; break; case 'h': std::cout << argv[0] << " [-u username] [-p password] url" << std::endl; exit(0); break; } } if (optind<argc) { url = argv[optind]; } std::cout << "Connecting to " << url << std::endl; // create connection to devicemgmt.wsdl server DeviceBindingProxy deviceProxy(url.c_str()); // call Device::GetDeviceInformation std::cout << "=>Device::GetDeviceInformation" << std::endl; _tds__GetDeviceInformation tds__GetDeviceInformation; _tds__GetDeviceInformationResponse tds__GetDeviceInformationResponse; addSecurity(deviceProxy.soap, username, password); if (deviceProxy.GetDeviceInformation(&tds__GetDeviceInformation, &tds__GetDeviceInformationResponse) == SOAP_OK) { std::cout << "\tManufacturer:" << tds__GetDeviceInformationResponse.Manufacturer << std::endl; } else { deviceProxy.soap_stream_fault(std::cerr); } // call Device::GetHostname std::cout << "=>Device::GetHostname" << std::endl; _tds__GetHostname tds__GetHostname; _tds__GetHostnameResponse tds__GetHostnameResponse; addSecurity(deviceProxy.soap, username, password); if (deviceProxy.GetHostname(&tds__GetHostname, &tds__GetHostnameResponse) == SOAP_OK) { std::cout << "\tHostname:" << tds__GetHostnameResponse.HostnameInformation->Name->c_str() << std::endl; } else { deviceProxy.soap_stream_fault(std::cerr); } // call Device::GetDNS std::cout << "=>Device::GetDNS" << std::endl; _tds__GetDNS tds__GetDNS; _tds__GetDNSResponse tds__GetDNSResponse; addSecurity(deviceProxy.soap, username, password); if (deviceProxy.GetDNS(&tds__GetDNS, &tds__GetDNSResponse) == SOAP_OK) { for (auto dns : tds__GetDNSResponse.DNSInformation->DNSManual) { if (dns->IPv4Address) { std::cout << "\tDNS:" << dns->IPv4Address->c_str() << std::endl; } } } else { deviceProxy.soap_stream_fault(std::cerr); } // call Device::GetNetworkInterfaces std::cout << "=>Device::GetNetworkInterfaces" << std::endl; _tds__GetNetworkInterfaces tds__GetNetworkInterfaces; _tds__GetNetworkInterfacesResponse tds__GetNetworkInterfacesResponse; addSecurity(deviceProxy.soap, username, password); if (deviceProxy.GetNetworkInterfaces(&tds__GetNetworkInterfaces, &tds__GetNetworkInterfacesResponse) == SOAP_OK) { for (auto iface : tds__GetNetworkInterfacesResponse.NetworkInterfaces) { if (iface->Info != NULL) { std::cout << "\t" << iface->Info->Name->c_str() << " " << iface->Info->HwAddress << std::endl; } if ( (iface->IPv4 != NULL) && (iface->IPv4->Config != NULL) ) { for (auto addr : iface->IPv4->Config->Manual) { std::cout << "\tIP:" << addr->Address << "/" << addr->PrefixLength << std::endl; } } } } else { deviceProxy.soap_stream_fault(std::cerr); } // call Device::GetServices std::cout << "=>Device::GetServices" << std::endl; _tds__GetServices tds__GetServices; tds__GetServices.IncludeCapability = true; _tds__GetServicesResponse tds__GetServicesResponse; addSecurity(deviceProxy.soap, username, password); if (deviceProxy.GetServices(&tds__GetServices, &tds__GetServicesResponse) == SOAP_OK) { for (auto service : tds__GetServicesResponse.Service) { std::cout << "\tns:" << service->Namespace << " " << service->XAddr << " Version:" << service->Version->Major << "." << service->Version->Minor << std::endl; if (service->Capabilities) { std::cout << "\t" << service->Capabilities->__any << std::endl; } } } // call Device::GetCapabilities std::cout << "=>Device::GetCapabilities" << std::endl; _tds__GetCapabilities tds__GetCapabilities; _tds__GetCapabilitiesResponse tds__GetCapabilitiesResponse; addSecurity(deviceProxy.soap, username, password); if (deviceProxy.GetCapabilities(&tds__GetCapabilities, &tds__GetCapabilitiesResponse) == SOAP_OK) { std::unique_ptr<ImagingBindingProxy> imagingProxy; if ( (tds__GetCapabilitiesResponse.Capabilities->Extension != NULL) && (tds__GetCapabilitiesResponse.Capabilities->Imaging != NULL) ) { std::cout << "\tImaging Url:" << tds__GetCapabilitiesResponse.Capabilities->Imaging->XAddr << std::endl; imagingProxy.reset(new ImagingBindingProxy(tds__GetCapabilitiesResponse.Capabilities->Imaging->XAddr.c_str())); } std::unique_ptr<ReplayBindingProxy> replayProxy; if ( (tds__GetCapabilitiesResponse.Capabilities->Extension != NULL) && (tds__GetCapabilitiesResponse.Capabilities->Extension->Replay != NULL) ) { std::cout << "\tReplay Url:" << tds__GetCapabilitiesResponse.Capabilities->Extension->Replay->XAddr << std::endl; replayProxy.reset(new ReplayBindingProxy(tds__GetCapabilitiesResponse.Capabilities->Extension->Replay->XAddr.c_str())); } std::unique_ptr<MediaBindingProxy> mediaProxy; if (tds__GetCapabilitiesResponse.Capabilities->Media != NULL) { std::cout << "\tMedia Url:" << tds__GetCapabilitiesResponse.Capabilities->Media->XAddr << std::endl; mediaProxy.reset(new MediaBindingProxy(tds__GetCapabilitiesResponse.Capabilities->Media->XAddr.c_str())); } std::unique_ptr<ReceiverBindingProxy> receiverProxy; if ( (tds__GetCapabilitiesResponse.Capabilities->Extension != NULL) && (tds__GetCapabilitiesResponse.Capabilities->Extension->Receiver != NULL) ) { std::cout << "\tReceiver Url:" << tds__GetCapabilitiesResponse.Capabilities->Extension->Receiver->XAddr << std::endl; receiverProxy.reset(new ReceiverBindingProxy(tds__GetCapabilitiesResponse.Capabilities->Extension->Receiver->XAddr.c_str())); } std::unique_ptr<RecordingBindingProxy> recordingProxy; if ( (tds__GetCapabilitiesResponse.Capabilities->Extension != NULL) && (tds__GetCapabilitiesResponse.Capabilities->Extension->Recording != NULL) ) { std::cout << "\tRecording Url:" << tds__GetCapabilitiesResponse.Capabilities->Extension->Recording->XAddr << std::endl; recordingProxy.reset(new RecordingBindingProxy(tds__GetCapabilitiesResponse.Capabilities->Extension->Recording->XAddr.c_str())); } std::unique_ptr<SearchBindingProxy> searchProxy; if ( (tds__GetCapabilitiesResponse.Capabilities->Extension != NULL) && (tds__GetCapabilitiesResponse.Capabilities->Extension->Search != NULL) ) { std::cout << "\tSearch Url:" << tds__GetCapabilitiesResponse.Capabilities->Extension->Search->XAddr << std::endl; searchProxy.reset (new SearchBindingProxy(tds__GetCapabilitiesResponse.Capabilities->Extension->Search->XAddr.c_str())); } std::unique_ptr<EventBindingProxy> eventProxy; if (tds__GetCapabilitiesResponse.Capabilities->Events != NULL) { std::cout << "\tEvent Url:" << tds__GetCapabilitiesResponse.Capabilities->Events->XAddr << std::endl; eventProxy.reset(new EventBindingProxy(tds__GetCapabilitiesResponse.Capabilities->Events->XAddr.c_str())); } if (mediaProxy.get() != NULL) { // call Media::GetVideoSources std::cout << "=>Media::GetVideoSources" << std::endl; _trt__GetVideoSources trt__GetVideoSources; _trt__GetVideoSourcesResponse trt__GetVideoSourcesResponse; addSecurity(mediaProxy->soap, username, password); if (mediaProxy->GetVideoSources(&trt__GetVideoSources, &trt__GetVideoSourcesResponse) == SOAP_OK) { for (auto source : trt__GetVideoSourcesResponse.VideoSources) { std::cout << "\t" << source->token; if (source->Resolution) { std::cout << " " << source->Resolution->Width << "x" << source->Resolution->Height; } std::cout << std::endl; _trt__GetVideoEncoderConfiguration trt__GetVideoEncoderConfiguration; trt__GetVideoEncoderConfiguration.ConfigurationToken = source->token; _trt__GetVideoEncoderConfigurationResponse trt__GetVideoEncoderConfigurationResponse; addSecurity(mediaProxy->soap, username, password); if (mediaProxy->GetVideoEncoderConfiguration(&trt__GetVideoEncoderConfiguration, &trt__GetVideoEncoderConfigurationResponse) == SOAP_OK) { std::cout << "\tEncoding:" << trt__GetVideoEncoderConfigurationResponse.Configuration->Encoding << std::endl; if (trt__GetVideoEncoderConfigurationResponse.Configuration->H264) { std::cout << "\tH264Profile:" << trt__GetVideoEncoderConfigurationResponse.Configuration->H264->H264Profile << std::endl; } if (trt__GetVideoEncoderConfigurationResponse.Configuration->Resolution) { std::cout << "\tResolution:" << trt__GetVideoEncoderConfigurationResponse.Configuration->Resolution->Width << "x" << trt__GetVideoEncoderConfigurationResponse.Configuration->Resolution->Height << std::endl; } } _trt__GetVideoEncoderConfigurationOptions trt__GetVideoEncoderConfigurationOptions; trt__GetVideoEncoderConfigurationOptions.ConfigurationToken = soap_new_std__string(mediaProxy->soap); trt__GetVideoEncoderConfigurationOptions.ConfigurationToken->assign(source->token); _trt__GetVideoEncoderConfigurationOptionsResponse trt__GetVideoEncoderConfigurationOptionsResponse; addSecurity(mediaProxy->soap, username, password); if (mediaProxy->GetVideoEncoderConfigurationOptions(&trt__GetVideoEncoderConfigurationOptions, &trt__GetVideoEncoderConfigurationOptionsResponse) == SOAP_OK) { if (trt__GetVideoEncoderConfigurationOptionsResponse.Options->H264) { for (auto res : trt__GetVideoEncoderConfigurationOptionsResponse.Options->H264->ResolutionsAvailable) { std::cout << "\tResolution:" << printResolution(res) << std::endl; } } } if (imagingProxy.get() != NULL) { _timg__GetImagingSettings timg__GetImagingSettings; timg__GetImagingSettings.VideoSourceToken = source->token; _timg__GetImagingSettingsResponse timg__GetImagingSettingsResponse; addSecurity(imagingProxy->soap, username, password); if (imagingProxy->GetImagingSettings(&timg__GetImagingSettings, &timg__GetImagingSettingsResponse) == SOAP_OK) { std::cout << "\tBrightness :" << printPtr (timg__GetImagingSettingsResponse.ImagingSettings->Brightness) << std::endl; std::cout << "\tContrast :" << printPtr (timg__GetImagingSettingsResponse.ImagingSettings->Contrast) << std::endl; std::cout << "\tSaturation :" << printPtr (timg__GetImagingSettingsResponse.ImagingSettings->ColorSaturation) << std::endl; std::cout << "\tSharpness :" << printPtr (timg__GetImagingSettingsResponse.ImagingSettings->Sharpness) << std::endl; std::cout << "\tBacklight :" << printMode(timg__GetImagingSettingsResponse.ImagingSettings->BacklightCompensation) << std::endl; std::cout << "\tWideDynamic :" << printMode(timg__GetImagingSettingsResponse.ImagingSettings->WideDynamicRange) << std::endl; std::cout << "\tExposure :" << printMode(timg__GetImagingSettingsResponse.ImagingSettings->Exposure) << std::endl; if (timg__GetImagingSettingsResponse.ImagingSettings->Exposure) std::cout << "\t\tExposureTime :" << printPtr(timg__GetImagingSettingsResponse.ImagingSettings->Exposure->ExposureTime) << std::endl; std::cout << "\tWhiteBalance:" << printMode(timg__GetImagingSettingsResponse.ImagingSettings->WhiteBalance) << std::endl; } _timg__GetOptions timg__GetOptions; timg__GetOptions.VideoSourceToken = source->token; _timg__GetOptionsResponse timg__GetOptionsResponse; addSecurity(imagingProxy->soap, username, password); if (imagingProxy->GetOptions(&timg__GetOptions, &timg__GetOptionsResponse) == SOAP_OK) { std::cout << "\tBrightness: " << printRangePtr(timg__GetOptionsResponse.ImagingOptions->Brightness) << std::endl; std::cout << "\tContrast : " << printRangePtr(timg__GetOptionsResponse.ImagingOptions->Contrast) << std::endl; std::cout << "\tSaturation: " << printRangePtr(timg__GetOptionsResponse.ImagingOptions->ColorSaturation) << std::endl; std::cout << "\tSharpness : " << printRangePtr(timg__GetOptionsResponse.ImagingOptions->Sharpness) << std::endl; } } } } std::cout << "=>Media::GetProfiles" << std::endl; _trt__GetProfiles trt__GetProfiles; _trt__GetProfilesResponse trt__GetProfilesResponse; addSecurity(mediaProxy->soap, username, password); if (mediaProxy->GetProfiles(&trt__GetProfiles, &trt__GetProfilesResponse) == SOAP_OK) { for (auto profile : trt__GetProfilesResponse.Profiles) { std::string token(profile->token); std::cout << "\tMediaProfile:" << token << std::endl; if (profile->VideoSourceConfiguration) { std::cout << "\ttoken:" << profile->VideoSourceConfiguration->token << std::endl; std::cout << "\tSourceToken:" << profile->VideoSourceConfiguration->SourceToken << std::endl; std::cout << "\tBounds:" << printRectangle(profile->VideoSourceConfiguration->Bounds) << std::endl; } if (profile->VideoEncoderConfiguration) { std::cout << "\ttoken:" << profile->VideoEncoderConfiguration->token << std::endl; std::cout << "\tQuality:" << profile->VideoEncoderConfiguration->Quality << std::endl; std::cout << "\tResolution:" << printResolution(profile->VideoEncoderConfiguration->Resolution) << std::endl; if (profile->VideoEncoderConfiguration->H264) { std::cout << "\tGovLength:" << profile->VideoEncoderConfiguration->H264->GovLength << std::endl; std::cout << "\tH264Profile:" << profile->VideoEncoderConfiguration->H264->H264Profile << std::endl; } } _trt__GetStreamUri trt__GetStreamUri; _trt__GetStreamUriResponse trt__GetStreamUriResponse; trt__GetStreamUri.ProfileToken = token; trt__GetStreamUri.StreamSetup = soap_new_tt__StreamSetup(mediaProxy->soap); trt__GetStreamUri.StreamSetup->Transport = soap_new_tt__Transport(mediaProxy->soap); trt__GetStreamUri.StreamSetup->Transport->Protocol = tt__TransportProtocol__RTSP; addSecurity(mediaProxy->soap, username, password); if (mediaProxy->GetStreamUri(&trt__GetStreamUri, &trt__GetStreamUriResponse) == SOAP_OK) { std::cout << "\tMediaUri:" << trt__GetStreamUriResponse.MediaUri->Uri << std::endl; } } } } if (searchProxy.get() != NULL) { std::cout << "=>Search::GetRecordingSummary" << std::endl; _tse__GetRecordingSummary tse__GetRecordingSummary; _tse__GetRecordingSummaryResponse tse__GetRecordingSummaryResponse; addSecurity(searchProxy->soap, username, password); if (searchProxy->GetRecordingSummary(&tse__GetRecordingSummary, &tse__GetRecordingSummaryResponse) == SOAP_OK) { if (tse__GetRecordingSummaryResponse.Summary) { std::cout << "\tNumberRecordings:" << tse__GetRecordingSummaryResponse.Summary->NumberRecordings << std::endl; std::cout << "\tDataFrom:" << tse__GetRecordingSummaryResponse.Summary->DataFrom << std::endl; std::cout << "\tDataUntil:" << tse__GetRecordingSummaryResponse.Summary->DataUntil << std::endl; } } } if (recordingProxy.get() != NULL) { std::cout << "=>Recording::GetRecordings" << std::endl; _trc__GetRecordings trc__GetRecordings; _trc__GetRecordingsResponse trc__GetRecordingsResponse; addSecurity(recordingProxy->soap, username, password); if (recordingProxy->GetRecordings(&trc__GetRecordings, &trc__GetRecordingsResponse) == SOAP_OK) { for (auto recording : trc__GetRecordingsResponse.RecordingItem) { std::string token(recording->RecordingToken); std::cout << "\tRecording:" << token << std::endl; if (replayProxy.get() != NULL) { _trp__GetReplayUri trp__GetReplayUri; _trp__GetReplayUriResponse trp__GetReplayUriResponse; trp__GetReplayUri.RecordingToken = token; addSecurity(replayProxy->soap, username, password); if (replayProxy->GetReplayUri(&trp__GetReplayUri, &trp__GetReplayUriResponse) == SOAP_OK) { std::cout << "\tReplay Uri:" << trp__GetReplayUriResponse.Uri << std::endl; } } } } std::cout << "=>Recording::GetRecordingJobs" << std::endl; _trc__GetRecordingJobs trc__GetRecordingJobs; _trc__GetRecordingJobsResponse trc__GetRecordingJobsResponse; addSecurity(recordingProxy->soap, username, password); if (recordingProxy->GetRecordingJobs(&trc__GetRecordingJobs, &trc__GetRecordingJobsResponse) == SOAP_OK) { for (auto job : trc__GetRecordingJobsResponse.JobItem) { std::string token(job->JobToken); std::cout << "\tRecordingJob:" << token << std::endl; if (job->JobConfiguration) { std::cout << "\tRecordingToken:" << job->JobConfiguration->RecordingToken << std::endl; for (auto src : job->JobConfiguration->Source) { if (src->SourceToken) { std::cout << "\tSourceToken:" << src->SourceToken->Token << std::endl; std::cout << "\tSourceType:" << src->SourceToken->Type << std::endl; } } } } } } if (receiverProxy.get() != NULL) { std::cout << "=>Receiver::GetReceivers" << std::endl; _trv__GetReceivers trv__GetReceivers; _trv__GetReceiversResponse trv__GetReceiversResponse; addSecurity(receiverProxy->soap, username, password); if (receiverProxy->GetReceivers(&trv__GetReceivers, &trv__GetReceiversResponse) == SOAP_OK) { for (auto receiver : trv__GetReceiversResponse.Receivers) { std::string token(receiver->Token); std::cout << "\tReceiver:" << token << std::endl; if (receiver->Configuration) { std::cout << "\tReceiver mode:" << receiver->Configuration->Mode << " uri:" << receiver->Configuration->MediaUri << std::endl; } } } } if (eventProxy.get() != NULL) { std::cout << "=>Event::CreatePullPoint" << std::endl; _tev__CreatePullPointSubscription tev__CreatePullPointSubscription; _tev__CreatePullPointSubscriptionResponse tev__CreatePullPointSubscriptionResponse; addSecurity(eventProxy->soap, username, password); if (eventProxy->CreatePullPointSubscription(&tev__CreatePullPointSubscription, &tev__CreatePullPointSubscriptionResponse) == SOAP_OK) { std::cout << "\tPullpoint Url:" << tev__CreatePullPointSubscriptionResponse.SubscriptionReference.Address << std::endl; // pull PullPointSubscriptionBindingProxy pullpoint(tev__CreatePullPointSubscriptionResponse.SubscriptionReference.Address); soap_wsse_add_Security(pullpoint.soap); _tev__PullMessages tev__PullMessages; tev__PullMessages.Timeout = "PT10S"; tev__PullMessages.MessageLimit = 100; _tev__PullMessagesResponse tev__PullMessagesResponse; if (pullpoint.PullMessages(&tev__PullMessages, &tev__PullMessagesResponse) == SOAP_OK) { for (auto msg : tev__PullMessagesResponse.wsnt__NotificationMessage) { std::cout << "\tMessage:" << msg->Message.__any << std::endl; } } // subscribe NotificationConsumerBindingService consumer; consumer.soap->accept_timeout=5; consumer.bind(NULL,0,10); std::thread th(&NotificationConsumerBindingService::run, &consumer, 0); NotificationProducerBindingProxy producer(tev__CreatePullPointSubscriptionResponse.SubscriptionReference.Address); soap_wsse_add_Security(producer.soap); // build url to the server struct sockaddr_in sin; socklen_t len = sizeof(sin); std::ostringstream os; os << "http://" << getLocalIp() ; if (getsockname(consumer.soap->master, (struct sockaddr *)&sin, &len) != -1) { os << ":" << ntohs(sin.sin_port); } std::string url(os.str()); std::cout << "notification endpoint:" << url << std::endl; _wsnt__Subscribe wsnt__Subscribe; wsnt__Subscribe.ConsumerReference.Address = strcpy((char*)soap_malloc(producer.soap, url.size()+1), url.c_str()); _wsnt__SubscribeResponse wsnt__SubscribeResponse; if (producer.Subscribe(&wsnt__Subscribe, &wsnt__SubscribeResponse) == SOAP_OK) { std::cout << "SubscriptionReference:" << wsnt__SubscribeResponse.SubscriptionReference.Address << std::endl; } else { producer.soap_stream_fault(std::cerr); } th.join(); } } } return 0; }