unsigned __stdcall serviceDataThread( void* pArguments ){
		ListenSocket * clientDataSocket;
		ClientThreadResource * res = (ClientThreadResource*) pArguments;
		clientDataSocket = acceptRequest(res->dataSocket);
		
		if(res->mode == FTP_DATA_MODE_PASIVE){
			
			if ( res->transferTask == STOR_TRANSFER ){
				storeFile( res , clientDataSocket );
			} else if ( res->transferTask == RETR_TRANSFER ){
				retrieveFile( res , clientDataSocket );
			} else if ( res->transferTask == LIST_TRANSFER ){
				listFiles( res , clientDataSocket );
			}
			
		}else if(res->mode == FTP_DATA_MODE_ACTIVE){
			
			while(res->mode == FTP_DATA_MODE_ACTIVE){		
				
				blockMutex(res->dataMutex );
				executeActiveCommand(res);
				//unblockMutex(res->controlMutex);
			}			
		}

		res->mode = FTP_DATA_MODE_INACTIVE;
		_endthread();
	}
Example #2
0
int main(void)
{
	hashTable arrayHash[MAX];
	linkedData linkArray[MAX];

	initHashArray(arrayHash);
	storeFile(arrayHash,linkArray);
	freeData(arrayHash);

	return 0;
}
Example #3
0
boolean Configuration::setValue(String key, String value) {
	int index = findIndex(key);
	if (index == -1) {
		pair *prop_old = properties;
		properties = new pair[size + 1];
		for (int i = 0; i < size; i++) {
			properties[i] = prop_old[i];
		}
		if (prop_old)
			delete[] prop_old;
		size++;
		index = size - 1;
		properties[index].key = key;
	}
	properties[index].value = value;
	return storeFile();
}
Example #4
0
void processMakeFile(const QFileInfo& file, bool assume_our)
{
    int offset(0);
    bool skipfile(false), modify_file(assume_our);
    QString text=fileToString(file.absoluteFilePath());
    QStringList output;
    while(offset<text.length())
    {
        //qDebug()<<"==========================";
        int off_ss=text.indexOf('#', offset);

        if(off_ss<0)
        {
            //qDebug()<<"tail="<<text.mid(offset);
            output<<text.mid(offset);
            break;
        }

        bool comment_from_newline(true);
        int newlinebefore=off_ss==0 ? 0 : text.lastIndexOf('\n', off_ss)+1;
        for(int i=newlinebefore+1; i<off_ss; ++i)
        {
            if(!text.at(i).isSpace()){
                comment_from_newline=false;
                break;
            }
        }
        int end=text.indexOf('\n', off_ss);
        if(end<0)end=text.length();else ++end;//end if after \n
        //grab more lines
        if(comment_from_newline)
        {
            int tabspace=off_ss-newlinebefore;
            //find more comments from newline
            while(end<text.length())
            {
                int nextss=text.indexOf('#',end);
                if(nextss<0)break;
                //check if there is \n between // and end
                int moreN=text.indexOf('\n', end);
                if(moreN>=0 && moreN<nextss)break;
                //check for [end]...spaces...//
                bool spaces_between(true);
                for(int i=end; i<nextss; ++i)
                {
                    if(!text.at(i).isSpace()){
                        spaces_between=false;
                        break;
                    }
                }
                if(!spaces_between || nextss-end!=tabspace)
                    break;
                end=text.indexOf('\n', nextss);
                if(end<0)end=text.length();else ++end;
            }
        }
        //qDebug()<<"... ... comment at "<<off_ss<<"--"<<end;
        //qDebug()<<text.mid(off_ss, end-off_ss);
        if(RemoveComment(file.absoluteFilePath(), text, off_ss, end, skipfile, modify_file))
        {
            if(offset<off_ss)
            {
                //qDebug()<<"output {"<<text.mid(offset, off_ss-offset)<<"}";
                output<<text.mid(offset,off_ss-offset);
            }
        }
        else
        {
            //qDebug()<<"output2{"<<text.mid(offset, end-offset)<<"}";
            output<<text.mid(offset, end-offset);
        }
        offset=end;
    }
    storeFile(text, file.absoluteFilePath(), output, skipfile, modify_file, true);
}
Example #5
0
/** A new connection was requested
  *
  */
void RainbruRPG::Network::Ftp::FtpTransfer::newConnection(){
  emit(log( "A new connection is requested on transfer channel" ));
  LOGI("A new connection is requested on transfer channel" );
  socket1=server->nextPendingConnection();
  QString filename, s;

  descriptor=socket1->socketDescriptor();
  LOGCATS("Socket descriptor is ");
  LOGCATI( descriptor );
  LOGCAT();

  switch(nextCommand){
  case FTC_NONE:
    LOGW("New connection has no pending command...CLOSED");
    break;
  case FTC_LIST:
    lsResult();
    emit(log("Sending LS result"));
    socket1->write(packetData.toLatin1());
    writeBytes(socket1);
    LOGI( "LIST command complete");
    break;
  case FTC_STOR:
    s="Receiving file ";
    s+=nextOnlyFilename;
    emit(storeFile(nextOnlyFilename));
    emit(log(s));
    break;
  case FTC_RETR:
    LOGI("RETR not yet implemented");
    break;
  }

  //Setting the socket to the FtpDataConnection
  LOGI("registerVisual called");
  LOGCATS("connectionList size : ");
  LOGCATI(connectionList.size());
  LOGCAT();

  QString pport=QString::number(socket1->peerPort());

  bool found=false;

  tConnectionList::const_iterator iter;
  for (iter=connectionList.begin(); iter!=connectionList.end(); iter++){
    if ((*iter)->isThisConnection(socket1->peerAddress().toString(), 
				  pport, nextOnlyFilename)){

      LOGI("Socket correctly added to the FtpDataConnection");
      (*iter)->setSocket(socket1);
      found=true;

      // Setting the command
      if (nextCommand==FTC_STOR){
	(*iter)->commandSTOR(nextFilename);
      }
      else if (nextCommand==FTC_RETR){
	(*iter)->commandRETR(nextFilename);
      }
    }
  }

  // FtpDataConnection not found
  if (!found){
    LOGW("FtpDataConnection not found");
    LOGCATS("Address : ");
    LOGCATS(socket1->peerAddress().toString().toLatin1());
    LOGCATS(" pport : ");
    LOGCATS(pport.toLatin1());
    LOGCATS(" nextFilename : ");
    LOGCATS(nextFilename.toLatin1());
    LOGCAT();
  }
}