void TCParser::_parseProfileName(const std::vector<std::string> &args) { std::string *name = createJoin(args, " "); doProfileName(*name); delete name; }
void TCParser::_parseProfileAvatarAlpha(const std::vector<std::string> &args) { std::string *bitmap = createJoin(args, " "); doProfileAvatarAlpha(*bitmap); delete bitmap; }
void TCParser::_parseProfileText(const std::vector<std::string> &args) { std::string *text = createJoin(args, " "); doProfileText(*text); delete text; }
void TCParser::_parseMessage(const std::vector<std::string> &args) { if (args.size() == 0) { _parserError(tcrec_cmd_message, "Empty message content"); return; } std::string * msg = createJoin(args, " "); doMessage(*msg); delete msg; }
void TCParser::_parseClient(const std::vector<std::string> &args) { if (args.size() == 0) { _parserError(tcrec_cmd_version, "Empty client argument"); return; } std::string *text = createJoin(args, " "); doClient(*text); delete text; }
void TCParser::_parseFileData(const std::vector<std::string> &args) { if (args.size() < 4) { _parserError(tcrec_cmd_filedata, "Bad filedata argument"); return; } std::string *data = createJoin(args, 3, " "); if (data) { doFileData(args[0], args[1], args[2], *data); delete data; } else doFileData(args[0], args[1], args[2], ""); }
bool ConfigReader::createConfig() { bool inProcessingMode = false; while(!atEnd()) { TokenType token = readNext(); // First, check if processing is possible if(token == StartElement && name() == "olvisConfig") { inProcessingMode = true; continue; } if(!inProcessingMode) continue; switch(token) { case StartElement: if(name() == "makroFilter") createMakroFilter(); else if(name() == "processor") createProcessor(); else if(name() == "buffer") createBuffer(); else if(name() == "join") createJoin(); else if(name() == "filter") { createFilter(); // Filter could not be created, cancel loading if(mCurrentFilter == -1){ return false; } } else if(name() == "port") setPort(); else if(name() == "makroInput") addMakroInput(); else if(name() == "makroOutput") addMakroOutput(); else if(name() == "processorOutput") addProcessorOutput(); else if(name() == "source") setSource(); else if(name() == "connection") connectProcessors(); else if(name() == "inputConnection") connectProcessorInput(); mCurrentData = ""; break; case Characters: mCurrentData += text(); break; case EndElement: if(name() == "processor") mCurrentProcessor = 0; else if(name() == "filter") mCurrentFilter = 0; else if(name() == "port") mCurrentPort = ""; else if(name() == "value") setValue(); else if(name() == "olvisConfig") inProcessingMode = false; break; default: break; } } // Default: Return true, as config was loaded return true; }
int joinServantNtwk() { int i=0,status = 0; struct sockaddr_in beacon_addr; struct hostent *beaconNode; int beasockOptLen = sizeof(int); bool beasockOpt = true; time_t mysystime; pthread_t myThreadsTemp[2]; int myThreadsTempCtr = 0; int joinSocket = 0; for(i=0 ; i < nonBeaconNodeInfo->no_of_beacons ; i++) { joinSocket = 0; if((joinSocket = socket(AF_INET,SOCK_STREAM,0)) == -1) { writeErrorToLogFile((char *)"\nError creating socket\n"); i--; continue; } if((setsockopt(joinSocket,SOL_SOCKET,SO_REUSEADDR,&beasockOpt,beasockOptLen)) == -1) { writeErrorToLogFile((char *)"Error in setting socket opt"); i--; continue; } char beaconip[16]; beacon_addr.sin_family = AF_INET; beaconNode = gethostbyname(nonBeaconNodeInfo->beaconsHostNames[i]); memset(beaconip,0,16); strcpy(beaconip,inet_ntoa(*((struct in_addr *)beaconNode->h_addr_list[0]))); free(beaconNode); beacon_addr.sin_addr.s_addr = inet_addr(beaconip); beacon_addr.sin_port = htons(nonBeaconNodeInfo->beaconport[i]); /* * Send connection request */ status = connect(joinSocket,(struct sockaddr *)&beacon_addr,sizeof(beacon_addr)); // connect to the host and port specified in if (status < 0) { writeErrorToLogFile((char *)"\nError connecting to server\n"); } else { status = i; break; } } if(status < 0) { return -1; } else { /* * Create connection details */ connectionDetails *cd = new connectionDetails; strcpy(cd->hostname,nonBeaconNodeInfo->beaconsHostNames[status]); cd->port = nonBeaconNodeInfo->beaconport[status]; cd->socketDesc = joinSocket; pthread_cond_init(&cd->messagingQueueCV,NULL); pthread_mutex_init(&cd->messagingQueueLock,NULL); pthread_mutex_init(&cd->connectionLock,NULL); cd->threadsExitedCount = 0; cd->notOperational = 0; cd->isJoinConnection = 0; cd->tiebreak = 0; mysystime = time(NULL); cd->lastReadActivity = mysystime; cd->lastWriteActivity = mysystime; cd->helloStatus = 0; cd->wellKnownPort = nonBeaconNodeInfo->beaconport[status]; char charkey[100] = "\0"; sprintf(charkey,"%s%d",nonBeaconNodeInfo->beaconsHostNames[status],nonBeaconNodeInfo->beaconport[status]); string key = string(charkey); /* * Add connection details to the map */ pthread_mutex_lock(&connectedNeighborsMapLock); connectedNeighborsMap.insert(CONNMAPTYPE::value_type(key,cd)); pthread_mutex_unlock(&connectedNeighborsMapLock); char *mapk = (char *)malloc(100); memset(mapk,0,100); strcpy(mapk,charkey); /* * Create JOIN message and send over this temporary connection */ struct joinMessage *myJoinMsg = createJoin(nonBeaconNodeInfo->location,nonBeaconNodeInfo->port,nonBeaconNodeInfo->hostname); struct message *mymessage; mymessage = CreateMessageHeader(JOIN, /*Mess Type*/ nonBeaconNodeInfo->ttl, /* TTL */ myJoinMsg -> dataLength, /*DataLength Message Body */ NULL, /*char *messageHeader*/ NULL, /*char *message*/ (void*)myJoinMsg, /*void *messageStruct*/ mapk,/*char* temp_connectedNeighborsMapKey*/ MYMESSAGE, /* MyMessage or NotMyMessage*/ nonBeaconNodeInfo /*Node Info Pointer*/); /* * Add the message to my message cache */ char keytype[256] = "\0"; int i = 0; while(i<20) { keytype[i] = *(mymessage->uoid + i); i++; } string keyTemp = string(keytype); pthread_mutex_lock(&messageCacheMapLock); messageCacheMap.insert(MESSCACHEMAPTYPE::value_type(keyTemp,mymessage)); pthread_mutex_unlock(&messageCacheMapLock); sendMessageToNode(mymessage); /* * create child threads for reader and writer */ usleep(1000); pthread_t childThread1; pthread_create(&childThread1,NULL,(void* (*)(void*))reader,mapk); myThreadsTemp[myThreadsTempCtr] = childThread1; myThreadsTempCtr++; pthread_t childThread2; pthread_create(&childThread2,NULL,(void* (*)(void*))writer,mapk); myThreadsTemp[myThreadsTempCtr] = childThread2; myThreadsTempCtr++; for(i = 0; i < myThreadsTempCtr; i++) { pthread_join(myThreadsTemp[i],NULL); } } pthread_mutex_lock(&connectedNeighborsMapLock); for(connectedNeighborsMapIter = connectedNeighborsMap.begin(); connectedNeighborsMapIter != connectedNeighborsMap.end();connectedNeighborsMapIter++) { connectedNeighborsMap.erase(connectedNeighborsMapIter->first); } pthread_mutex_unlock(&connectedNeighborsMapLock); return 1; }
TCFileReceive::TCFileReceive(const std::string & uuid, const std::string & folder, const std::string & fileName, uint64_t fileSize, uint64_t blockSize) { std::string fullpath = folder + "/" + fileName; struct stat st; // Init vars nextStart = 0; _uuid = uuid; _fsize = fileSize; _bsize = blockSize; // Check that the file already exist if (stat(fullpath.c_str(), &st) != 0) { _fpath = fullpath; _fname = fileName; _file = fopen(fullpath.c_str(), "w"); if (!_file) throw std::string("core_frec_err_cant_open"); } else { std::vector<std::string> *its = createExplode(fileName, "."); std::string *name, *ext; char buffer[512]; uint32_t idx = 1; // Get the extension if (its->size() > 1) { ext = new std::string("."); ext->append(its->at(its->size() - 1)); its->erase(its->begin() + (long)(its->size() - 1)); } else ext = new std::string(""); // Get the name name = createJoin(*its, "."); // Search for a good name while (1) { snprintf(buffer, sizeof(buffer), "-%u", idx); fullpath = folder + "/" + *name + buffer + *ext; if (stat(fullpath.c_str(), &st) != 0) { _fpath = fullpath; _fname = *name + buffer + *ext; _file = fopen(fullpath.c_str(), "w"); if (!_file) throw std::string("core_frec_err_cant_open"); break; } idx++; } // Clean delete its; delete name; delete ext; } }