static int PluginCommand_GetMyAvatar(WPARAM wParam,LPARAM lParam) { char * ret = (char *)lParam; char * proto = (char *)wParam; if (ret == NULL) return -1; if (proto == NULL) { if (protocols->default_avatar_file != NULL) lstrcpyn(ret, protocols->default_avatar_file, MS_MYDETAILS_GETMYAVATAR_BUFFER_SIZE); else ret[0] = '\0'; } else { Protocol protocol = GetProtocolByName(proto); if (!protocol) return -1; if (!protocol.CanGetAvatar()) return -2; lstrcpyn(ret, protocol.GetAvatarFile(), MS_MYDETAILS_GETMYAVATAR_BUFFER_SIZE); } return 0; }
void StatusLabel::setPict() { const char *icon; const char *text; if (m_client->getState() == Client::Connecting){ if (m_timer == NULL){ m_timer = new QTimer(this); connect(m_timer, SIGNAL(timeout()), this, SLOT(timeout())); m_timer->start(1000); m_bBlink = false; } Protocol *protocol = m_client->protocol(); text = I18N_NOOP("Connecting"); unsigned status; if (m_bBlink){ icon = "online"; status = m_client->getManualStatus(); }else{ icon = "offline"; status = STATUS_OFFLINE; } if (protocol){ for (const CommandDef *cmd = protocol->statusList(); cmd->text; cmd++){ if (cmd->id == status){ icon = cmd->icon; break; } } } }else{ if (m_timer){ delete m_timer; m_timer = NULL; } if (m_client->getState() == Client::Error){ icon = "error"; text = I18N_NOOP("Error"); }else{ Protocol *protocol = m_client->protocol(); const CommandDef *cmd = protocol->description(); icon = cmd->icon; text = cmd->text; for (cmd = protocol->statusList(); cmd->text; cmd++){ if (cmd->id == m_client->getStatus()){ icon = cmd->icon; text = cmd->text; break; } } } } QPixmap pict = Pict(icon); QString tip = CorePlugin::m_plugin->clientName(m_client); tip += "\n"; tip += i18n(text); setPixmap(pict); QToolTip::add(this, tip); resize(pict.width(), pict.height()); setFixedSize(pict.width(), pict.height()); };
void ProtocolManager::onNodeUpdated(Event *e) { if (!e) return; NodeRef& node = e->getNode(); NodeRefList& nl = e->getNodeList(); if (!node) return; // Check if there are any protocols that are associated with the updated nodes. for (NodeRefList::iterator it = nl.begin(); it != nl.end(); it++) { NodeRef& old_node = *it; old_node.lock(); for (InterfaceRefList::const_iterator it2 = old_node->getInterfaces()->begin(); it2 != old_node->getInterfaces()->end(); it2++) { const InterfaceRef& iface = *it2; for (protocol_registry_t::iterator it3 = protocol_registry.begin(); it3 != protocol_registry.end(); it3++) { Protocol *p = (*it3).second; if (p->isForInterface(iface)) { HAGGLE_DBG("Setting peer node %s on protocol %s\n", node->getName().c_str(), p->getName()); p->setPeerNode(node); } } } old_node.unlock(); } }
bool yarp::os::impl::NameserCarrier::respondToHeader(Protocol& proto) { // I am the receiver NameserTwoWayStream *stream = new NameserTwoWayStream(proto.giveStreams()); proto.takeStreams(stream); return true; }
bool yarp::os::impl::NameserCarrier::sendHeader(Protocol& proto) { yarp::os::impl::String target = getSpecifierName(); yarp::os::Bytes b((char*)target.c_str(),8); proto.os().write(b); proto.os().flush(); return proto.os().isOk(); }
/*! Load static built-in components. */ void Server::loadStaticComponents () { string xml ("xml"); mimeManager.setLogger (this); mimeManager.registerHandler (xml, new XmlMimeHandler ()); XmlVhostHandler::registerBuilder (vhostManager); XmlMimeHandler::registerBuilder (mimeManager); validatorFactory.addValidator (xml, xmlValidator); authMethodFactory.addAuthMethod (xml, (AuthMethod*) xmlValidator); if (filtersFactory.insert ("gzip", Gzip::factory)) log (MYSERVER_LOG_MSG_ERROR, _("Error while loading plugins")); HttpProtocol *http = new HttpProtocol (); Protocol *protocolsSet[] = {http, new HttpsProtocol (http), new GopherProtocol (), new FtpProtocol (), new ControlProtocol (), NULL}; for (int j = 0; protocolsSet[j]; j++) { Protocol *protocol = protocolsSet[j]; protocol->loadProtocol (); const char *protocolName = protocol->getName (); getProtocolsManager ()->addProtocol (protocolName, protocol); } Md5::initialize (&cryptAlgoManager); Sha1::initialize (&cryptAlgoManager); }
void ProtocolManager::onWatchableEvent(const Watchable& wbl) { protocol_registry_t::iterator it = protocol_registry.begin(); HAGGLE_DBG("Receive on %s\n", wbl.getStr()); // Go through each protocol in turn: for (; it != protocol_registry.end(); it++) { Protocol *p = (*it).second; // Did the Watchable belong to this protocol if (p->hasWatchable(wbl)) { // Let the protocol handle whatever happened. p->handleWatchableEvent(wbl); return; } } HAGGLE_DBG("Was asked to handle a socket no protocol knows about!\n"); // Should not happen, but needs to be dealt with because if it isn't, // the kernel will call us again in an endless loop! kernel->unregisterWatchable(wbl); CLOSE_SOCKET(wbl.getSocket()); }
void FileDescription::checkTitle() { Protocol *gadu = AccountManager::instance()->defaultAccount()->protocol(); if (QFile::exists(config_file.readEntry("FileDesc", "file"))) { QFile file(config_file.readEntry("FileDesc", "file")); if (!gadu->currentStatus().isOffline()) { if (file.open(IO_ReadOnly)) { QString desc = ""; QTextStream stream(&file); if (!stream.atEnd()) desc = stream.readLine(); if ((desc != currDesc || gadu->currentStatus().description() != desc && !config_file.readBoolEntry("FileDesc", "allowOther") || !gadu->currentStatus().hasDescription() && config_file.readBoolEntry("FileDesc", "forceDescr")) && !gadu->currentStatus().isOffline()) { currDesc = desc; fileDescStatusChanger->setTitle(desc); } file.close(); } } } }
PVoid hawk_EchoClientRoutine(void* pArg) { HawkSession session; if (session.Init(g_IpAddr)) { while (g_Running) { //更新 if (!session.Tick(PROTO_TIME)) break; //发送协议 Int32 iType = HawkRand::RandInt(PROTO_A, PROTO_C); if (iType == PROTO_A) { ProtoA sCmd; session.SendProtocol(&sCmd); } else if (iType == PROTO_B) { ProtoB sCmd; session.SendProtocol(&sCmd); } else if (iType == PROTO_C) { ProtoC sCmd; session.SendProtocol(&sCmd); } //接收协议 Protocol* pProto = 0; while (session.DecodeProtocol(pProto) && pProto) { #if (PRINT_PROTO == 1) ProtoType iType = pProto->GetType(); if (iType == PROTO_A) { ProtoA* pA = (ProtoA*)pProto; HawkFmtPrint("Msg: %s",pA->m_sMsg.c_str()); } else if (iType == PROTO_B) { ProtoB* pB = (ProtoB*)pProto; HawkFmtPrint("Size: %d, Time: %d",pB->m_iSize, pB->m_iTime); } else if (iType == PROTO_C) { ProtoC* pC = (ProtoC*)pProto; HawkFmtPrint("X: %f, Y: %f, Z: %f",pC->m_fX, pC->m_fY, pC->m_fZ); } #endif P_ProtocolManager->ReleaseProto(pProto); } HawkSleep(PROTO_TIME); } } return 0; }
void Session::Run() { Command cmd; while (true) { mQueue.WaitAndPop(cmd); if (cmd == START) { cmd = NO_CMD; if (mTcpClient.Connect(mHostName, mTcpPort) == true) { Protocol proto; while (mInitialized) { if (mTcpClient.DataWaiting(200U)) { std::string payload; if (mTcpClient.Recv(payload)) { proto.Add(payload); std::string data; while (proto.Parse(data)) { // TLogNetwork("Found one packet with data: " + data); std::vector<Reply> out; std::uint32_t client_uuid = proto.GetDestUuid(); bool ret = mListener.Deliver(proto.GetSourceUuid(), client_uuid, data, out); // Send synchronous data to the server if (ret) { Send(out); } } } } else { //std::cout << "client wait timeout or failure" << std::endl; mInitialized = IsConnected(); // determine origine of failure } } mListener.Signal(net::IEvent::ErrDisconnectedFromServer); TLogNetwork("Client connection closed."); } else { TLogError("Client cannot connect to server."); mListener.Signal(net::IEvent::ErrCannotConnectToServer); } } else if (cmd == EXIT) { std::cout << "Exit client thread" << std::endl; return; } } }
void Manager::executeCommands() { m_currentCommand = MaxCommand; if(m_commands.isEmpty()) { return; } m_currentCommand = m_commands.takeFirst(); Protocol protocol; protocol.setStateOn(m_state.on); protocol.setColor(m_state.color); protocol.setRate(m_state.rate); QByteArray block; QDataStream out(&block, QIODevice::WriteOnly); out.setVersion(QDataStream::Qt_4_0); QString request = protocol.request2Str(m_currentCommand); out << request; Q_EMIT message(tr("Attempt sending request: ") + request); m_tcpSocket->write(block); if(m_tcpSocket->waitForBytesWritten()) { Q_EMIT message(tr("Send successeful.")); } else { Q_EMIT message(tr("Send failed.")); } }
Protocol* Protocol::decode(const char *bytes, int32_t len, bool decrypt) { int type; memcpy(&type, bytes, sizeof(type)); bytes += sizeof(type); len -= 4; char *temp = new char[len]; if (decrypt) { rc4_state state; rc4_init(&state, (const u_char *)INKEY.c_str(), INKEY.size()); rc4_crypt(&state, (const u_char *)bytes, (u_char *)temp, len); } else { memcpy(temp, bytes, len); } std::string plain(temp, len); delete[] temp; CCLOG("==== Client received:%s ====", plain.c_str()); Json::Reader reader; Json::Value root; if (!reader.parse(plain, root)) return NULL; //int type = root["type"].asInt(); Protocol *p = Protocol::create(type); if (p != NULL) { JsonStream stream(root); p->decode(stream); } return p; }
int Device::getMethods() const { Protocol *p = this->retrieveProtocol(); if (p) { return p->methods(); } return 0; }
static int PluginCommand_GetMyNickname(WPARAM wParam,LPARAM lParam) { char * ret = (char *)lParam; char * proto = (char *)wParam; if (ret == NULL) return -1; if (proto == NULL) { if (protocols->default_nick != NULL) lstrcpyn(ret, protocols->default_nick, MS_MYDETAILS_GETMYNICKNAME_BUFFER_SIZE); else ret[0] = '\0'; } else { Protocol protocol = GetProtocolByName(proto); if (!protocol) return -1; lstrcpyn(ret, protocol.GetNick(), MS_MYDETAILS_GETMYNICKNAME_BUFFER_SIZE); } return 0; }
inline boost::system::error_code connect_pair( basic_socket<Protocol, SocketService1>& socket1, basic_socket<Protocol, SocketService2>& socket2, boost::system::error_code& ec) { // Check that this function is only being used with a UNIX domain socket. boost::asio::local::basic_endpoint<Protocol>* tmp = static_cast<typename Protocol::endpoint*>(0); (void)tmp; Protocol protocol; boost::asio::detail::socket_type sv[2]; if (boost::asio::detail::socket_ops::socketpair(protocol.family(), protocol.type(), protocol.protocol(), sv, ec) == boost::asio::detail::socket_error_retval) return ec; if (socket1.assign(protocol, sv[0], ec)) { boost::system::error_code temp_ec; boost::asio::detail::socket_ops::close(sv[0], temp_ec); boost::asio::detail::socket_ops::close(sv[1], temp_ec); return ec; } if (socket2.assign(protocol, sv[1], ec)) { boost::system::error_code temp_ec; socket1.close(temp_ec); boost::asio::detail::socket_ops::close(sv[1], temp_ec); return ec; } return ec; }
void WorkStation::sendmessage(QString message) { Protocol prot; QString temp; info = prot.getCommand(Protocol::SendMessageCommand) + "'" + temp.setNum(message.length()) + "'" + ">" + message + "</MESSAGE></MD>"; sendMessage(); }
void send_net_data(JOCTET *data, int len, void *client) { dbg_printf("Send %d bytes\n", len); Protocol *p = (Protocol *)client; char hdr[1000]; sprintf(hdr,"\n"); const char *brk = "\n"; if (hdr[1]=='\0') { brk = "\r\n"; } dbg_printf("Using terminator %s\n",(hdr[1]=='\0')?"\\r\\n":"\\n"); sprintf(hdr,"Content-Type: image/jpeg%s\ Content-Length: %d%s%s", brk, len, brk, brk); Bytes hbuf(hdr,strlen(hdr)); p->os().write(hbuf); Bytes buf((char *)data,len); /* // add corruption now and then, for testing. static int ct = 0; ct++; if (ct==50) { printf("Adding corruption\n"); buf.get()[0] = 'z'; ct = 0; } */ p->os().write(buf); sprintf(hdr,"%s--boundarydonotcross%s",brk,brk); Bytes hbuf2(hdr,strlen(hdr)); p->os().write(hbuf2); }
static QString getStatusIconPath(BuddyOrContact buddyOrContact) { Buddy buddy = buddyOrContact.buddy(); Contact contact = buddyOrContact.contact(); if (buddy.isBlocked()) return webKitPath(IconsManager::instance()->iconPath("kadu_icons", "16x16", "blocked")); if (contact.isBlocking()) return webKitPath(IconsManager::instance()->iconPath("kadu_icons", "16x16", "blocking")); if (contact.contactAccount()) { Protocol *protocol = contact.contactAccount().protocolHandler(); if (protocol) { StatusTypeManager* statustypemanager = StatusTypeManager::instance(); if (statustypemanager) { Status status = contact.currentStatus(); QString iconpath = statustypemanager->statusIconFullPath(protocol->statusPixmapPath(), status.type(), !status.description().isEmpty(), false); if (!iconpath.isEmpty()) return webKitPath(iconpath); } } } return QString(); }
void ProtocolTest::shouldReturnInvalidPacketIncasePacketTypeIsInvalid() { unsigned char data[] = {1, 99, 0,0,0, 31, 0}; Protocol protocol; Packet * packet = protocol.parsePacket(7, data); CPPUNIT_ASSERT_EQUAL(packet->getType(), (char)PacketType::Invalid); }
bool WriteableContactsListFilter::acceptAccount(Account account) { Protocol *protocol = account.protocolHandler(); if (!protocol) return false; return !protocol->contactsListReadOnly(); }
bool yarp::os::impl::HttpCarrier::respondToHeader(Protocol& proto) { stream = new HttpTwoWayStream(proto.giveStreams(), input.c_str(), prefix.c_str(), prop); proto.takeStreams(stream); return true; }
void ProtocolTest::shouldParsePacketFromInputData() { unsigned char data[] = {1, PacketType::Read, 0,0,0, 31, 0}; Protocol protocol; ReadReqPacket * packet = (ReadReqPacket*)protocol.parsePacket(7, data); CPPUNIT_ASSERT_EQUAL(packet->getServiceId(), (char)31); CPPUNIT_ASSERT_EQUAL(packet->getType(), (char)PacketType::Read); }
AvatarService * AvatarManager::avatarService(Account *account) { Protocol *protocol = account->protocol(); if (!protocol) return 0; return protocol->avatarService(); }
bool open(const Protocol& protocol) { _socket = socket_ops::socket( protocol.family(), protocol.type(), protocol.protocol() ); return _socket != invalid_socket; }
int main(int argc, char *argv[]){ Protocol *proto; proto = new Protocol(argv[1], argv[2]); proto->mute(argv[3]); for(int i=0;i<100000;i++){ proto->send(); } }
stream_protocol( const Protocol& source_protocol ) : family_( source_protocol.family( ) ), protocol_( source_protocol.protocol( ) ) { if ( source_protocol.type( ) != type( ) ) { std::bad_cast ex; asio::detail::throw_exception( ex ); } }
int testReadyToSend() { Protocol p; p.state = STATE_CONNECTED; ASSERT(p.readyForData()); p.outgoingDataPacket = std::tr1::shared_ptr<ProtocolPacket>(new ProtocolPacket(TYPE_DATA,5,NULL,0)); ASSERT(!p.readyForData()); return 0; }
virtual bool expectIndex(Protocol& proto) { String prefix = "human says "; String compare = prefix; Bytes b2((char*)prefix.c_str(),prefix.length()); proto.is().read(b2); bool ok = proto.is().isOk() && (prefix==compare); if (!ok) cout << "YOU DID NOT SAY 'human says '" << endl; return ok; }
virtual bool expectAck(Protocol& proto) { String prefix = "computers rule!\r\n"; String compare = prefix; Bytes b2((char*)prefix.c_str(),prefix.length()); proto.is().read(b2); bool ok = proto.is().isOk() && (prefix==compare); if (!ok) cout << "YOU DID NOT SAY 'computers rule!'" << endl; return ok; }
int OtrMessageService::maxMessageSize(const Account &account) const { Protocol *protocolHandler = account.protocolHandler(); if (!protocolHandler) return 0; ChatService *chatService = protocolHandler->chatService(); if (!chatService) return 0; return chatService->maxMessageLength(); }