void MPICommunicator::communicate(DataField* field){ std::string controlName = "CS"; MPI_Comm csComm = clientNameCommMap[controlName]; MPI_Status status; // Receiving the clinet name to communicate with MPI_Probe(0, MPI_ANY_TAG, csComm, &status); int lengthOfClientName; MPI_Get_count(&status, MPI_CHAR, &lengthOfClientName); char *buf = new char[lengthOfClientName]; MPI_Recv(buf,lengthOfClientName,MPI_CHAR,0,MPI_ANY_TAG,csComm, &status); std::string clientName(buf, lengthOfClientName); delete [] buf; // Receiving what to do with the client int whatToDo; MPI_Recv(&whatToDo,1,MPI_INT,0,MPI_ANY_TAG,csComm, &status); switch(whatToDo){ case 1: // Receive MPI_Comm clientToRecvFrom = clientNameCommMap[clientName]; field->receive(clientToRecvFrom); break; case 2: // Send MPI_Comm clientToSendTo = clientNameCommMap[clientName]; field->send(clientToSendTo); break; } }
bool QXmppVersionManager::handleStanza(const QDomElement &element) { if (element.tagName() == "iq" && QXmppVersionIq::isVersionIq(element)) { QXmppVersionIq versionIq; versionIq.parse(element); if(versionIq.type() == QXmppIq::Get) { // respond to query QXmppVersionIq responseIq; responseIq.setType(QXmppIq::Result); responseIq.setId(versionIq.id()); responseIq.setTo(versionIq.from()); responseIq.setName(clientName()); responseIq.setVersion(clientVersion()); responseIq.setOs(clientOs()); client()->sendPacket(responseIq); } emit versionReceived(versionIq); return true; } return false; }
QValueList<Mirror> Sites::siteList() { KURL url; url.setProtocol( "http" ); url.setHost( "freedb.freedb.org" ); url.setPort( 80 ); url.setPath( "/~cddb/cddb.cgi" ); url.setQuery( QString::null ); QString hello = QString("%1 %2 %3 %4") .arg(user_, localHostName_, clientName(), clientVersion()); url.addQueryItem( "cmd", "sites" ); url.addQueryItem( "hello", hello ); url.addQueryItem( "proto", "5" ); QValueList<Mirror> result; QString tmpFile; if( KIO::NetAccess::download( url, tmpFile, 0 ) ) { result = readFile( tmpFile ); KIO::NetAccess::removeTempFile( tmpFile ); } return result; }
void ScriptEngineRemoteLocal::disconnected() { m_server_socket->deleteLater(); if (!m_command.isEmpty()) { bool successfulRun = currentPythonEngineAgros()->runScript(m_command); } m_client_socket = new QLocalSocket(); connect(m_client_socket, SIGNAL(error(QLocalSocket::LocalSocketError)), this, SLOT(displayError(QLocalSocket::LocalSocketError))); m_client_socket->connectToServer(clientName()); if (m_client_socket->waitForConnected(1000)) { ErrorResult result = currentPythonEngineAgros()->parseError(); QTextStream out(m_client_socket); out << result.error(); out.flush(); m_client_socket->waitForBytesWritten(); } else { displayError(QLocalSocket::ConnectionRefusedError); } delete m_client_socket; }
void ProxyPlugin::clientData(TCPClient *client, ProxyData &cdata) { for (unsigned i = 1;; i++){ const char *proxyCfg = getClients(i); if ((proxyCfg == NULL) || (*proxyCfg == 0)) break; ProxyData wdata(proxyCfg); if (wdata.Client.ptr && (clientName(client) == wdata.Client.ptr)){ cdata = wdata; cdata.Default.bValue = false; set_str(&cdata.Client.ptr, clientName(client).c_str()); return; } } cdata = data; set_str(&cdata.Client.ptr, clientName(client).c_str()); cdata.Default.bValue = true; clear_list(&cdata.Clients); }
void CDDBPLookup::sendHandshake() { QString handshake = QString::fromLatin1( "cddb hello %1 %2 %3 %4" ) .arg( user_ ) .arg( localHostName_ ) .arg( clientName() ) .arg( clientVersion() ); writeLine( handshake ); }
void HTTPLookup::makeURL( const QString & cmd ) { QString hello = QString::fromLatin1("%1 %2 %3 %4") .arg(user_, localHostName_, clientName(), clientVersion()); // The whole query has to constructed each time as the // CDDB CGI script expects the parameters in strict order QUrlQuery query; query.addQueryItem( QLatin1String( "cmd" ), cmd ); query.addQueryItem( QLatin1String( "hello" ), hello ); query.addQueryItem( QLatin1String( "proto" ), QLatin1String( "6" ) ); cgiURL_.setQuery( query ); }
static jlong nativeInitSensorEventQueue(JNIEnv *env, jclass clazz, jlong sensorManager, jobject eventQWeak, jobject msgQ, jfloatArray scratch, jstring packageName, jint mode) { SensorManager* mgr = reinterpret_cast<SensorManager*>(sensorManager); ScopedUtfChars packageUtf(env, packageName); String8 clientName(packageUtf.c_str()); sp<SensorEventQueue> queue(mgr->createEventQueue(clientName, mode)); sp<MessageQueue> messageQueue = android_os_MessageQueue_getMessageQueue(env, msgQ); if (messageQueue == NULL) { jniThrowRuntimeException(env, "MessageQueue is not initialized."); return 0; } sp<Receiver> receiver = new Receiver(queue, messageQueue, eventQWeak, scratch); receiver->incStrong((void*)nativeInitSensorEventQueue); return jlong(receiver.get()); }
QXmppDiscoveryIq QXmppDiscoveryManager::capabilities() { QXmppDiscoveryIq iq; iq.setType(QXmppIq::Result); iq.setQueryType(QXmppDiscoveryIq::InfoQuery); // features QStringList features; features << ns_chat_states // XEP-0085: Chat State Notifications << ns_capabilities // XEP-0115 : Entity Capabilities << ns_ping // XEP-0199: XMPP Ping << ns_attention; // XEP-0224: Attention foreach(QXmppClientExtension* extension, client()->extensions()) { if(extension) features << extension->discoveryFeatures(); } iq.setFeatures(features); // identities QList<QXmppDiscoveryIq::Identity> identities; QXmppDiscoveryIq::Identity identity; identity.setCategory(clientCategory()); identity.setType(clientType()); identity.setName(clientName()); identities << identity; foreach(QXmppClientExtension* extension, client()->extensions()) { if(extension) identities << extension->discoveryIdentities(); } iq.setIdentities(identities); return iq; }
status_t BnMMSdkService::onTransact( uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) { switch(code) { case CONNECT_IMAGETRANSFORMUSER: { CHECK_INTERFACE(IMMSdkService, data, reply); sp<NSImageTransform::IImageTransformUser> client; status_t status = connectImageTransformUser(client); reply->writeNoException(); reply->writeInt32(status); if (client != 0) { reply->writeInt32(1); reply->writeStrongBinder(client->asBinder()); } else { reply->writeInt32(0); } return NO_ERROR; } break; case CONNECT_EFFECT: { CHECK_INTERFACE(IMMSdkService, data, reply); String16 clientName(data.readString16()); sp<NSEffect::IEffectUser> client; status_t status = connectEffect(String16(clientName), client); reply->writeNoException(); reply->writeInt32(status); if (client != 0) { reply->writeInt32(1); reply->writeStrongBinder(client->asBinder()); } else { reply->writeInt32(0); } return NO_ERROR; } break; case CONNECT_GESTURE: { CHECK_INTERFACE(IMMSdkService, data, reply); sp<NSGesture::IGestureUser> client; status_t status = connectGesture(client); reply->writeNoException(); reply->writeInt32(status); if (client != 0) { reply->writeInt32(1); reply->writeStrongBinder(client->asBinder()); } else { reply->writeInt32(0); } return NO_ERROR; } break; case CONNECT_HEARTRATE: { CHECK_INTERFACE(IMMSdkService, data, reply); sp<NSHeartrate::IHeartrateUser> client; status_t status = connectHeartrate(client); reply->writeNoException(); reply->writeInt32(status); if (client != 0) { reply->writeInt32(1); reply->writeStrongBinder(client->asBinder()); } else { reply->writeInt32(0); } return NO_ERROR; } break; case DISCONNECT_HEARTRATE: { CHECK_INTERFACE(IMMSdkService, data, reply); status_t status = disconnectHeartrate(); reply->writeNoException(); reply->writeInt32(status); return status; } break; case GET_MMSDK_FEAUTRE_MANAGER: { CHECK_INTERFACE(IMMSdkService, data, reply); sp<NSCam::IFeatureManager> client; status_t status = connectFeatureManager(client); reply->writeNoException(); reply->writeInt32(status); if (client != 0) { reply->writeInt32(1); reply->writeStrongBinder(client->asBinder()); } else { reply->writeInt32(0); } return NO_ERROR; } break; case REGISTER_CAMERA_1_DEVICE: { int callingPid = android::IPCThreadState::self()->getCallingPid(); if (callingPid != getpid()) { status_t status = NO_ERROR; ALOGW("Reject, (calling, current) = (%d, %d) only trust the device on the same process", callingPid, getpid()); reply->writeNoException(); reply->writeInt32(status); return NO_ERROR; } CHECK_INTERFACE(IMMSdkService, data, reply); NSCam::ICamDevice *pDevice = NULL; data.read(reinterpret_cast<NSCam::ICamDevice*>(pDevice), sizeof(NSCam::ICamDevice *)); status_t status = registerCamera1Device(pDevice); reply->writeNoException(); reply->writeInt32(status); return status; } break; case UNREGISTER_CAMERA_1_DEVICE: { int callingPid = android::IPCThreadState::self()->getCallingPid(); if (callingPid != getpid()) { status_t status = NO_ERROR; ALOGW("Reject, (calling, current) = (%d, %d) only trust the device on the same process", callingPid, getpid()); reply->writeNoException(); reply->writeInt32(status); return NO_ERROR; } // CHECK_INTERFACE(IMMSdkService, data, reply); //NSCam::ICamDevice *pDevice = reinterpret_cast<NSCam::ICamDevice*>(data.readPointer()); NSCam::ICamDevice *pDevice = NULL; data.read(reinterpret_cast<NSCam::ICamDevice*>(pDevice), sizeof(NSCam::ICamDevice *)); status_t status = unRegisterCamera1Device(pDevice); reply->writeNoException(); reply->writeInt32(status); return NO_ERROR; }break; default: return BBinder::onTransact(code, data, reply, flags); } }
ServerCatchcopy::inputReturnType ServerCatchcopy::parseInputCurrentProtocol(const uint32_t &client,const uint32_t &orderId,const std::vector<std::string> &returnList) { if(returnList.size()==0) return WrongArgumentListSize; //if is supported std::string firstArgument=returnList.front(); if(firstArgument=="protocol") { if(returnList.size()!=2) return WrongArgumentListSize; emit askProtocolCompatibility(client,orderId,returnList.back()); return Ok; } else if(firstArgument=="protocol extension") { if(returnList.size()>3 || returnList.size()<2) return WrongArgumentListSize; return ExtensionWrong; } else if(firstArgument=="client") { if(returnList.size()!=2) return WrongArgumentListSize; int index=0; int size=clientList.size(); while(index<size) { if(clientList.at(index).id==client) { clientList[index].name=returnList.back(); break; } index++; } emit clientName(client,returnList.back()); clientRegistered(client,orderId); return Replied; } else if(firstArgument=="server") { if(returnList.size()!=2) return WrongArgumentListSize; if(returnList.back()!="name?") return WrongArgument; serverName(client,orderId,name); return Replied; } else if(firstArgument=="cp") { if(returnList.size()<3) return WrongArgumentListSize; std::vector<std::string> sourceList=returnList; sourceList.erase(sourceList.cbegin()); sourceList.pop_back(); emitNewCopy(client,orderId,sourceList,returnList.back()); return Ok; } else if(firstArgument=="cp-?") { if(returnList.size()<2) return WrongArgumentListSize; std::vector<std::string> sourceList=returnList; sourceList.erase(sourceList.cbegin()); emitNewCopyWithoutDestination(client,orderId,sourceList); return Ok; } else if(firstArgument=="mv") { if(returnList.size()<3) return WrongArgumentListSize; std::vector<std::string> sourceList=returnList; sourceList.erase(sourceList.cbegin()); sourceList.pop_back(); emitNewMove(client,orderId,sourceList,returnList.back()); return Ok; } else if(firstArgument=="mv-?") { if(returnList.size()<2) return WrongArgumentListSize; std::vector<std::string> sourceList=returnList; sourceList.erase(sourceList.cbegin()); emitNewMoveWithoutDestination(client,orderId,sourceList); return Ok; } else //if is not supported return UnknowOrder; }
int main(int argc, char* argv[]) { // verify input u8 command = 0; std::string target = ""; //parse commands if (0 == strcmp(argv[0], "unsnag")) { if (argc < 2) { std::cerr << "ERROR: you didn't provide a server. "; std::cerr << "Type snag -h for help" << std::endl; return 1; } command = unsnag; target = argv[1]; } else if (argc == 1) { command = list; } else if (argc == 2) { if (0 == strcmp(argv[1], "-l")) { command = list; } else if (0 == strcmp(argv[1], "-h")) { command = help; } else if (0 == strcmp(argv[1], "-u") || 0 == strcmp(argv[1], "-a") || 0 == strcmp(argv[1], "-d")) { std::cerr << "ERROR: you didn't provide a server. "; std::cerr << "Type snag -h for help" << std::endl; return 1; } else if (argv[1][0] == '-') { std::cerr << "ERROR: unknown command '" << argv[1] << "', "; std::cerr << "Type snag -h for help" << std::endl; return 1; } else { command = snag; target = argv[1]; } } else if (argc > 2) { if (0 == strcmp(argv[1], "-l")) { command = list; std::cerr << "TIP: list command takes no arguments." << std::endl; } else if (0 == strcmp(argv[1], "-h")) { command = help; std::cerr << "TIP: help command takes no arguments." << std::endl; } else if (0 == strcmp(argv[1], "-u")) { command = unsnag; target = argv[2]; } else if (0 == strcmp(argv[1], "-a")) { command = add; target = argv[2]; } else if (0 == strcmp(argv[1], "-d")) { command = del; target = argv[2]; } else { std::cerr << "ERROR: invalid command '" << argv[1] << "', "; std::cerr << "Type snag -h for help" << std::endl; return 1; } } // perform commands if (command == help) { helpCommand(); return 0; } Socket clientSocket = connectToServer(); if (clientSocket == -1) { return 1; } char clientNameBuffer[20]; getlogin_r(clientNameBuffer, 20); std::string clientName(clientNameBuffer); switch(command) { case list: listCommand(clientSocket); return 0; break; case snag: doCommand("s", clientSocket, target, clientName); break; case unsnag: doCommand("u", clientSocket, target, clientName); break; case add: doCommand("a", clientSocket, target, clientName); break; case del: doCommand("d", clientSocket, target, clientName); break; } // get server reply std::cout << std::endl; char buffer[1024]; memset(buffer, 0, 1024); int readLen = read(clientSocket, buffer, 2048); if (readLen < 0) { std::cerr << "ERROR reading from socket" << std::endl; return 1; } std::cout << buffer << std::endl; std::cout << std::endl; } // end main
INT32 _pmdExternClient::authenticate( MsgHeader *pMsg ) { #if defined ( SDB_ENGINE ) INT32 rc = SDB_OK ; BSONObj authObj ; BSONElement user, pass ; rc = extractAuthMsg( pMsg, authObj ) ; if ( rc ) { PD_LOG( PDERROR, "Client[%s] extract auth msg failed, rc: %d", clientName(), rc ) ; goto error ; } user = authObj.getField( SDB_AUTH_USER ) ; pass = authObj.getField( SDB_AUTH_PASSWD ) ; _isAuthed = FALSE ; if ( SDB_ROLE_STANDALONE == pmdGetDBRole() ) // not auth { _isAuthed = TRUE ; goto done ; } else if ( SDB_ROLE_OM == pmdGetDBRole() ) { rc = sdbGetOMManager()->authenticate( authObj, _pEDUCB ) ; if ( rc ) { PD_LOG( PDERROR, "Client[%s] authenticate failed[user: %s, " "passwd: %s], rc: %d", clientName(), user.valuestrsafe(), pass.valuestrsafe(), rc ) ; goto error ; } _isAuthed = TRUE ; } else if ( SDB_ROLE_COORD == pmdGetDBRole() ) { INT64 contextID = -1 ; rtnContextBuf buf ; CoordCB *pCoordcb = pmdGetKRCB()->getCoordCB(); rtnCoordProcesserFactory *pProcesserFactory = pCoordcb->getProcesserFactory(); rtnCoordOperator *pOperator = NULL ; pOperator = pProcesserFactory->getOperator( pMsg->opCode ); rc = pOperator->execute( pMsg, _pEDUCB, contextID, &buf ) ; // special handling for password verification when there is no // addrlist specified. Usually this happen when there is only // one coord node before creating the first catalog if ( MSG_AUTH_VERIFY_REQ == pMsg->opCode && SDB_CAT_NO_ADDR_LIST == rc ) { rc = SDB_OK ; _isAuthed = TRUE ; } else if ( rc ) { PD_LOG( PDERROR, "Client[%s] authenticate failed[user: %s, " "passwd: %s], rc: %d", clientName(), user.valuestrsafe(), pass.valuestrsafe(), rc ) ; goto error ; } else { _isAuthed = TRUE ; } } else { MsgHeader *pAuthRes = NULL ; shardCB *pShard = sdbGetShardCB() ; UINT32 retryTimes = 0 ; MsgOpReply replyHeader ; replyHeader.contextID = -1 ; replyHeader.numReturned = 0 ; while ( TRUE ) { ++retryTimes ; rc = pShard->syncSend( pMsg, CATALOG_GROUPID, TRUE, &pAuthRes ) ; if ( SDB_OK != rc ) { rc = pShard->syncSend( pMsg, CATALOG_GROUPID, FALSE, &pAuthRes ) ; PD_RC_CHECK( rc, PDERROR, "Client[%s] failed to send auth " "req to catalog, rc: %d", clientName(), rc ) ; } if ( NULL == pAuthRes ) { rc = SDB_SYS ; PD_LOG( PDERROR, "syncsend return ok but res is NULL" ) ; goto error ; } rc = MSG_GET_INNER_REPLY_RC(pAuthRes) ; replyHeader.flags = rc ; replyHeader.startFrom = MSG_GET_INNER_REPLY_STARTFROM(pAuthRes) ; ossMemcpy( &(replyHeader.header), pAuthRes, sizeof( MsgHeader ) ) ; /// release recv msg SDB_OSS_FREE( (BYTE*)pAuthRes ) ; pAuthRes = NULL ; if ( SDB_CLS_NOT_PRIMARY == rc && retryTimes < PMD_AUTH_RETRY_TIMES ) { INT32 rcTmp = SDB_OK ; rcTmp = pShard->updatePrimaryByReply( &(replyHeader.header) ) ; if ( SDB_NET_CANNOT_CONNECT == rcTmp ) { /// the node is crashed, sleep some seconds PD_LOG( PDWARNING, "Catalog group primary node is crashed " "but other nodes not aware, sleep %d seconds", NET_NODE_FAULTUP_MIN_TIME ) ; ossSleep( NET_NODE_FAULTUP_MIN_TIME * OSS_ONE_SEC ) ; } if ( rcTmp ) { pShard->updateCatGroup( CLS_SHARD_TIMEOUT ) ; } continue ; } else if ( rc ) { PD_LOG( PDERROR, "Client[%s] authenticate failed[user: %s, " "passwd: %s], rc: %d", clientName(), user.valuestrsafe(), pass.valuestrsafe(), rc ) ; goto error ; } else { _isAuthed = TRUE ; } break ; } } done: if ( SDB_OK == rc && _isAuthed ) { _username = user.valuestrsafe() ; if ( !_username.empty() ) { _password = pass.valuestrsafe() ; } _pEDUCB->setUserInfo( _username, _password ) ; _makeName() ; CHAR szTmp[ 16 ] = { 0 } ; ossSnprintf( szTmp, sizeof(szTmp)-1, "%llu", _pEDUCB->getID() ) ; PD_AUDIT_OP( AUDIT_ACCESS, MSG_AUTH_VERIFY_REQ, AUDIT_OBJ_SESSION, szTmp, SDB_OK, "User[UserName:%s, RemoteIP:%s, RemotePort:%u, " "LocalIP:%s, LocalPort:%u] login succeed", getUsername(), getPeerIPAddr(), getPeerPort(), getLocalIPAddr(), getLocalPort() ) ; } return rc ; error: if ( SDB_AUTH_AUTHORITY_FORBIDDEN == rc ) { _pEDUCB->printInfo( EDU_INFO_ERROR, "username or passwd is wrong" ) ; } goto done ; #else _isAuthed = TRUE ; return SDB_OK ; #endif // SDB_ENGINE }
ServerCatchcopy::inputReturnType ServerCatchcopy::parseInputCurrentProtocol(quint32 client,quint32 orderId,QStringList returnList) { if(returnList.size()==0) return WrongArgumentListSize; //if is supported QString firstArgument=returnList.first(); if(firstArgument=="protocol") { if(returnList.size()!=2) return WrongArgumentListSize; emit askProtocolCompatibility(client,orderId,returnList.last()); return Ok; } else if(firstArgument=="protocol extension") { if(returnList.size()>3 || returnList.size()<2) return WrongArgumentListSize; if(!autoReply) { if(returnList.size()==2) emit askProtocolExtension(client,orderId,returnList.last()); else emit askProtocolExtension(client,orderId,returnList.at(1),returnList.last()); } return ExtensionWrong; } else if(firstArgument=="client") { if(returnList.size()!=2) return WrongArgumentListSize; emit clientName(client,returnList.last()); if(autoReply) { clientRegistered(client,orderId); return Replied; } else { emit clientName(client,orderId,returnList.last()); return Ok; } } else if(firstArgument=="server") { if(returnList.size()!=2) return WrongArgumentListSize; if(returnList.last()!="name?") return WrongArgument; if(autoReply) { serverName(client,orderId,name); return Replied; } else { askServerName(client,orderId); return Ok; } } else if(firstArgument=="cp") { if(returnList.size()<3) return WrongArgumentListSize; QStringList sourceList=returnList; sourceList.removeFirst(); sourceList.removeLast(); emitNewCopy(client,orderId,sourceList,returnList.last()); return Ok; } else if(firstArgument=="cp-?") { if(returnList.size()<2) return WrongArgumentListSize; QStringList sourceList=returnList; sourceList.removeFirst(); emitNewCopy(client,orderId,sourceList); return Ok; } else if(firstArgument=="mv") { if(returnList.size()<3) return WrongArgumentListSize; QStringList sourceList=returnList; sourceList.removeFirst(); sourceList.removeLast(); emitNewMove(client,orderId,sourceList,returnList.last()); return Ok; } else if(firstArgument=="mv-?") { if(returnList.size()<2) return WrongArgumentListSize; QStringList sourceList=returnList; sourceList.removeFirst(); emitNewMove(client,orderId,sourceList); return Ok; } else //if is not supported return UnknowOrder; }