示例#1
0
void TWorker::work(int socket)
{
    std::string request;
    std::string fileName;
   // setNonBlock(socket);

    if( readRequest(socket, request) ) {
        #if defined(DEBUG)
            std::cout << "\n\nReqest:\n" << request;
        #endif
        std::string answer;
        if( parseRequest(request, fileName) ) {
            std::string context;
            if( getContext(fileName, context) ) {
                answer = createHeader(200, context.size() ) + context;
            }
            else {
                answer = createHeader(404);
            }
        }
        else {
            answer = createHeader(500);
        }
        #if defined(DEBUG)
            std::cout << "\n\nAnswer:\n" << answer;
        #endif
        sendAnswer(socket, answer);
    }
    disconnect(socket);
}
示例#2
0
uintptr_t splitBlock(uintptr_t **cursor, size_t req_size, size_t allocate_size, size_t total_size){
	uintptr_t *header_address = *cursor;
	uintptr_t *footer_address = header_address + (allocate_size / 8) + 1;
	
	uintptr_t *freeHeader_address = footer_address + 1;
	uintptr_t *freeFooter_address = header_address + (total_size / 8) + 1;

	uintptr_t freeSize = total_size - allocate_size - 16;

	uintptr_t allocated_info = createHeader(req_size, allocate_size + 16, MARK_USED);
	uintptr_t free_info = createHeader(0,freeSize + 16 , MARK_FREE);

	*header_address = allocated_info;
	*footer_address = allocated_info;

	*freeHeader_address = free_info;
	*freeFooter_address = free_info;

	*(freeHeader_address + 1) = *(header_address + 1);
	*(freeHeader_address + 2) = *(header_address + 2);

	/* split block resides between two free blocks */
	if((uintptr_t) *(freeHeader_address + 1) != NULL_POINTER 
	&& (uintptr_t) *(freeHeader_address + 2) != NULL_POINTER ){
		uintptr_t *next = (uintptr_t*) *(freeHeader_address + 1);
		uintptr_t *previous = (uintptr_t*) *(freeHeader_address + 2);

		*(next + 2) = (uintptr_t) previous;
		*(previous + 1) = (uintptr_t) next;

		insertHead(freeHeader_address);
	}

	/* split block has a block infront but not behind */
	else if((uintptr_t) *(freeHeader_address + 1) != NULL_POINTER 
		 && (uintptr_t) *(freeHeader_address + 2) == NULL_POINTER ){
		uintptr_t *next = (uintptr_t*) *(freeHeader_address + 1);
		
		*(next + 2) = (uintptr_t) freeHeader_address;

		head = (void *) freeHeader_address;
	}

	/* split block has a block behind but not infront */
	else if((uintptr_t) *(freeHeader_address + 1) == NULL_POINTER 
		 && (uintptr_t) *(freeHeader_address + 2) != NULL_POINTER ){
		uintptr_t *previous = (uintptr_t*) *(freeHeader_address + 2);
		
		*(previous + 1) = (uintptr_t) NULL_POINTER;
		insertHead(freeHeader_address);

	}else{
		/* must of split the only free block in the list*/
		head = (void *) freeHeader_address;
	}

	return 1;
}
QWidget *DlgSettingsExportFormat::createSubPanel ()
{
  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsExportFormat::createSubPanel";

  QWidget *subPanel = new QWidget ();
  QGridLayout *layout = new QGridLayout (subPanel);
  subPanel->setLayout (layout);

  int row = 0;
  createCurveSelection (layout, row);

  createTabWidget (layout,
                   row);

  QWidget *widgetMisc = new QWidget;
  layout->addWidget (widgetMisc, row++, 0, 1, 3);
  QHBoxLayout *layoutMisc = new QHBoxLayout;
  widgetMisc->setLayout (layoutMisc);

  createDelimiters (layoutMisc); // One row of radio buttons
  createHeader (layoutMisc); // Two rows with radio buttons and then header label
  createFileLayout (layoutMisc); // One row of radio buttons

  createPreview (layout, row);

  return subPanel;
}
示例#4
0
//This Function ask for the info of the Header
Header * inputHeaderInfo(){
    Header *info = createHeader();
	char *career, *professor, *subject;
	int course, semester;
	int ln ;
	career = (char *)malloc(50 * sizeof(char));
	professor = (char *)malloc(50 * sizeof(char));
	subject = (char *)malloc(50 * sizeof(char));
	fflush(stdin);
	printf("Career: ");
	fgets(career, 50, stdin);
	strcpy(info->career, career);
	quitEnter(info->career);
	fflush(stdin);
	printf("Semester: ");
	scanf("%d",&semester);
	info->semester = semester;
	fflush(stdin);
	printf("Course: ");
	scanf("%d",&course);
	info->course = course;
	fflush(stdin);
	printf("Professor: ");
	fgets(professor, 50, stdin);
	strcpy(info->professor, professor);
	quitEnter(info->professor);
	fflush(stdin);
	printf("Subject: ");
	fgets(subject, 50, stdin);
	strcpy(info->subject, subject);
	quitEnter(info->subject);
	fflush(stdin);
	return info;
}
示例#5
0
文件: assa.c 项目: LoLei/ESP_WS14
int drawBitMap(char *bmp_name, int **points, int *counter, Parameter *params)
{

    int curheight = 0;
    int curwidth = 0;
    int pixel_buffer[params->width][params->height];
    FILE *fp = NULL;
    if((fp = fopen(bmp_name, "wb")) == NULL)
    {
        //Could not write file
        printf(MSG_WRITE);
        return 3;

    }
    BitMap *bmap;
    if((bmap = (BitMap*) calloc(1, sizeof(BitMap))) == NULL)
    {
        printf(MSG_OOM);
        return 2;
    }
    createHeader(params, bmap);
    fwrite(bmap, 1, sizeof(BitMap), fp);
    free(bmap);
    drawBackground(0x60D0FF, params, pixel_buffer);
    drawCannon(params, pixel_buffer);
    drawLine(points, *counter, 0, 0xFF0000, params, pixel_buffer);

    for(curheight = 0; curheight < params->height; curheight++)
        for(curwidth = 0; curwidth < params->width; curwidth++)
            fwrite( &pixel_buffer[curwidth][curheight], 3, 1, fp);
    fclose(fp);
    return 0;
}
示例#6
0
void* sf_realloc(void* ptr, size_t size){
	if((void *)ptr < start || (void *)ptr >= end){
		errno = ENOMEM;
		return NULL;
	}

	uintptr_t *cursor = (uintptr_t*) (((uintptr_t*) ptr) - 1);

	if((((uintptr_t) cursor) & 0xF) != 0x8){
		errno =ENOMEM;
		return ptr;
	}

	uintptr_t loadSize = get_loadSize(cursor);

	if(loadSize > size){
		uintptr_t blockInfo = createHeader(size, loadSize + 16, MARK_USED);
		*cursor = blockInfo;

		return ptr;
	}
	else{
		errno = ENOMEM; 
		return NULL;
	}

}
示例#7
0
AbilityScreen::AbilityScreen(QWidget* parent):
    QWidget(parent) {

    layout = new QGridLayout(this);
    createHeader();
    setLayout(layout);
}
示例#8
0
// sender uses the function
int send_file(int sock, struct sockaddr_in *recv_adr, char *filename, akh_disconn_response *disconn_response)
{
    uint32_t seg_size = disconn_response->segment_size;
    uint32_t req_num = disconn_response->segment_num;
    uint32_t *seg_list = disconn_response->segment_list;
    uint32_t seg_num;

    akh_pdu_header header;
    char buf[MAX_BUFFER_SIZE];
    packet pac;
    size_t buf_len, pac_len;

    int i;
    for(i = 0; i < req_num; i++) {
        seg_num = seg_list[i];
        header = createHeader(SS, seg_num);
        buf_len = read_segment(buf, seg_size, seg_num, filename);
        pac_len = createPacket(&pac, &header, buf, buf_len);
        sendto(sock, pac, pac_len, 0, (struct sockaddr *)recv_adr, sizeof(*recv_adr));

        deletePacket(pac);

        puts("< send file segment >");
        displayHeader(header);
    }
    return 0;
}
/** Shows information about a Device in the InfoPane
	@param area the current area the widget's dock is in
	@param d the Device to show information about
*/
void InfoPane::showDevice(Qt::DockWidgetArea area, const Device& d)
{
	clear();
	parentWidget()->parentWidget()->setWindowTitle(i18nc("@title:window", "Device Information"));

	int x = 0;
	int y = createHeader(d.name(), cols(area));
	createLabels(i18nc("@label device", "Path:"), d.deviceNode(), cols(area), x, y);

	QString type = QStringLiteral("---");
	QString maxPrimaries = QStringLiteral("---");

	if (d.partitionTable() != NULL)
	{
		type = (d.partitionTable()->isReadOnly())
			? i18nc("@label device", "%1 (read only)", d.partitionTable()->typeName())
			: d.partitionTable()->typeName();
		maxPrimaries = QStringLiteral("%1/%2").arg(d.partitionTable()->numPrimaries()).arg(d.partitionTable()->maxPrimaries());
	}

	createLabels(i18nc("@label device", "Type:"), type, cols(area), x, y);
	createLabels(i18nc("@label device", "Capacity:"), Capacity::formatByteSize(d.capacity()), cols(area), x, y);
	createLabels(i18nc("@label device", "Total sectors:"), QLocale().toString(d.totalSectors()), cols(area), x, y);
	createLabels(i18nc("@label device", "Heads:"), QString::number(d.heads()), cols(area), x, y);
	createLabels(i18nc("@label device", "Cylinders:"), QLocale().toString(d.cylinders()), cols(area), x, y);
	createLabels(i18nc("@label device", "Sectors:"), QLocale().toString(d.sectorsPerTrack()), cols(area), x, y);
	createLabels(i18nc("@label device", "Logical sector size:"), Capacity::formatByteSize(d.logicalSectorSize()), cols(area), x, y);
	createLabels(i18nc("@label device", "Physical sector size:"), Capacity::formatByteSize(d.physicalSectorSize()), cols(area), x, y);
	createLabels(i18nc("@label device", "Cylinder size:"), i18ncp("@label", "1 Sector", "%1 Sectors", d.cylinderSize()), cols(area), x, y);
	createLabels(i18nc("@label device", "Primaries/Max:"), maxPrimaries, cols(area), x, y);
}
示例#10
0
/** Shows information about a Partition in the InfoPane
	@param area the current area the widget's dock is in
	@param p the Partition to show information about
*/
void InfoPane::showPartition(Qt::DockWidgetArea area, const Partition& p)
{
	clear();
	parentWidget()->parentWidget()->setWindowTitle(i18nc("@title:window", "Partition Information"));

	int x = 0;
	int y = createHeader(p.deviceNode(), cols(area));
	if (p.fileSystem().type() == FileSystem::Luks)
	{
		QString deviceNode = p.partitionPath();
		createLabels(i18nc("@label partition", "File system:"), p.fileSystem().name(), cols(area), x, y);
		createLabels(i18nc("@label partition", "Capacity:"), Capacity::formatByteSize(p.capacity()), cols(area), x, y);
		createLabels(i18nc("@label partition", "Cipher name:"), FS::luks::getCipherName(deviceNode), cols(area), x, y);
		createLabels(i18nc("@label partition", "Cipher mode:"), FS::luks::getCipherMode(deviceNode), cols(area), x, y);
		createLabels(i18nc("@label partition", "Hash:"), FS::luks::getHashName(deviceNode), cols(area), x, y);
		createLabels(i18nc("@label partition", "Key size:"), FS::luks::getKeySize(deviceNode), cols(area), x, y);
		createLabels(i18nc("@label partition", "Payload offset:"), FS::luks::getPayloadOffset(deviceNode), cols(area), x, y);
		createLabels(i18nc("@label partition", "First sector:"), QLocale().toString(p.firstSector()), cols(area), x, y);
		createLabels(i18nc("@label partition", "Last sector:"), QLocale().toString(p.lastSector()), cols(area), x, y);
		createLabels(i18nc("@label partition", "Number of sectors:"), QLocale().toString(p.length()), cols(area), x, y);
	}
	else
	{
		createLabels(i18nc("@label partition", "File system:"), p.fileSystem().name(), cols(area), x, y);
		createLabels(i18nc("@label partition", "Capacity:"), Capacity::formatByteSize(p.capacity()), cols(area), x, y);
		createLabels(i18nc("@label partition", "Available:"), Capacity::formatByteSize(p.available()), cols(area), x, y);
		createLabels(i18nc("@label partition", "Used:"), Capacity::formatByteSize(p.used()), cols(area), x, y);
		createLabels(i18nc("@label partition", "First sector:"), QLocale().toString(p.firstSector()), cols(area), x, y);
		createLabels(i18nc("@label partition", "Last sector:"), QLocale().toString(p.lastSector()), cols(area), x, y);
		createLabels(i18nc("@label partition", "Number of sectors:"), QLocale().toString(p.length()), cols(area), x, y);
	}
}
示例#11
0
KNotesSummaryWidget::KNotesSummaryWidget( Kontact::Plugin *plugin,
                                          QWidget *parent, const char *name )
  : Kontact::Summary( parent, name ), mLayout( 0 ), mPlugin( plugin )
{
  QVBoxLayout *mainLayout = new QVBoxLayout( this, 3, 3 );

  QPixmap icon = KGlobal::iconLoader()->loadIcon( "kontact_notes",
                   KIcon::Desktop, KIcon::SizeMedium );
  QWidget* header = createHeader( this, icon, i18n( "Notes" ) );
  mainLayout->addWidget( header );

  mLayout = new QGridLayout( mainLayout, 7, 3, 3 );
  mLayout->setRowStretch( 6, 1 );

  mCalendar = new KCal::CalendarLocal( QString::fromLatin1("UTC") );
  KNotesResourceManager *manager = new KNotesResourceManager();

  QObject::connect( manager, SIGNAL( sigRegisteredNote( KCal::Journal* ) ),
                    this, SLOT( addNote( KCal::Journal* ) ) );
  QObject::connect( manager, SIGNAL( sigDeregisteredNote( KCal::Journal* ) ),
                    this, SLOT( removeNote( KCal::Journal* ) ) );
  manager->load();


  updateView();
}
bool DataObject::create()
{
    QString text = createHeader();
    bool res = saveFile(folder+"/"+name.toLower()+".h",text);
    text = createClass();
    res = saveFile(folder+"/"+name.toLower()+".cpp",text);
    qDebug(res ? " Success!!":" Failed!! ");
    return true;
}
示例#13
0
void FileReceiver::requestFile(std::string fileName)
{
    if (ready)
    {
        FileTransferRequest_t req;
        req.header = createHeader(FileTransferMessage::FILE_TRANSFER_REQUEST);
        strncpy(req.fileName, fileName.c_str(), FILE_NAME_SIZE);
        tcp->sendData(&req, sizeof (FileTransferRequest_t));
    }
}
示例#14
0
TableStageStandings::TableStageStandings(const QStringList &teams, int numOfMarks,
                                         int stageNumber, QWidget *parent) :
    TableStandings(teams, numOfMarks, parent), m_stageNumber(stageNumber)
{
    setColumnCount(m_numOfMiddleCells + 3 + (m_stageNumber != 0 ? 1 : 0));

    createHeader();
    createCells();

    connect(this, SIGNAL(cellChanged(int,int)), SLOT(recalculateAverage()));
}
示例#15
0
void SymbianLog::printMessage(const char* level, const char* msg, PLATFORM_VA_LIST argList) 
{
    iSemaphore.Wait();
    
    StringBuffer currentTime = createCurrentTime(true);
    
    TInt err = file.Open(fsSession, iLogName, EFileWrite|EFileShareAny);
    TInt pos = 0;
    
    if (err == KErrNotFound) 
    {
        // First time: file does not exist. Create it.
        err = file.Create(fsSession, iLogName, EFileWrite|EFileShareAny);
        if (err != KErrNone) {
            setErrorF(err, "SymbianLog: could not open log file (code %d)", err);
            goto finally;
        }
        StringBuffer header = createHeader();
        RBuf8 data;
        data.Assign(stringBufferToNewBuf8(header));
        file.Write(data);
        data.Close();
    }
    else 
    {
        err = file.Seek(ESeekEnd, pos);
        if (err != KErrNone) {
            setErrorF(err, "SymbianLog: seek error on log file (code %d)", err);
            goto finally;
        }
    }

    {
        // Write the data
        StringBuffer line, data;
        line.sprintf("%s -%s- %s", currentTime.c_str(), level, msg);
        data.vsprintf(line.c_str(), argList);
        data.append("\n");
        
        RBuf8 buf;
        buf.Assign(stringBufferToNewBuf8(data));
        file.Write(buf);
        buf.Close();
    }
    
finally:
    file.Close();
    // we need closed file to operate on it
    if ( LogSize() > SYMBIAN_LOG_SIZE ){
        // roll log file
        RollLogFile();
    }
    iSemaphore.Signal();
}
示例#16
0
void onGetArquivo(char *str){

	char nomeDoArquivo[MAX_NOME_ARQ];
	Header header;
	IdPeer dest;
			
	scanf("%s", str);
	
	inicializaSearch();
	
	//Checa se os tokens estao ok
	if(strcmp(str, "arquivo"))
	{
		printHelp();
		return;
	}

	scanf("%s", str);	

	strcpy(nomeDoArquivo,str);
	
	printf("Nome do arquivo: (%s)\n", nomeDoArquivo);
	
	// Checa se ha algum token depois do nome do arquivo
	if(  (str = strtok(NULL, " ") ) != NULL){
		printHelp();
		return;
	}
	
	if(isValida(SEARCHR) || isValida(GETR)) {
		printf("******************************************************\n");
		printf("Buscando arquivo... \nAguarde para realizar nova busca\n");
		printf("******************************************************\n");
		return;
	}
	
	createHeader(&header, SEARCH, dest);
	header.tamDados = strlen(nomeDoArquivo);
	
	#ifdef DEBUG_SEARCH
		printf("Tamanho do nome do arquivo: %d\n", header.tamDados);
	#endif
	
	distribui(header, nomeDoArquivo);
	setNomeArquivoSearch(nomeDoArquivo);
		
	#ifdef DEBUG_SEARCH
		printf("SEARCH distribuida");
	#endif
	
	InsereMensagemResposta(header.numSeq, SEARCHR);
	SetTimer(DadosAplicacao.intervaloTimeout, TIMER_SEARCHR, 0);
}
示例#17
0
void trataSearch(int sockfd, Header& h, char * nomeArquivo)
{
	Header resposta;
	char dados[1];
	FILE *arquivo;
	char sNomeArquivo[MAX_NOME_ARQ];
	
	strncpy(sNomeArquivo, nomeArquivo, h.tamDados);
	sNomeArquivo[h.tamDados] = '\0';
	
	#ifdef DEBUG_SEARCH
		char tmp[TAM_STR_IP + 1];
		IdPeer2StrIp(tmp, h.remetente);
		printf("\n********** RECEBIMENTO DE SEARCH *************\n");
		printf("Remetente: %s\n", tmp);
		printf("NumSeq: %d\n", h.numSeq);
		printf("********************************************\n\n");		
		
		printf("\n\n\n\n********** VOU CHECAR SE TENHO O ARQUIVO !!!! *************\n");
		printf("\n\n\n\n********** NOME DO ARQUIVO: (%s)", sNomeArquivo);
		
	#endif
	
	arquivo = fopen(sNomeArquivo, "r");
	
	if(arquivo) {
		
		printf("\n\n\n\n********** ARQUIVO ENCONTRADO !!!! *************\n");
		
		createHeader(&resposta, SEARCHR, h.remetente);
		resposta.numSeq = h.numSeq;
		
		dados[0] = calcDistancia(&DadosAplicacao.meuIp, &h.remetente );
		resposta.tamDados = sizeof(unsigned char);
		
		if(!escrevePacote(sockfd, resposta, dados))
			puts("Erro ao enviar SEARCHR MSG");
		
		#ifdef DEBUG_SEARCH
			printf("\n********** RESPONDEU SEARCH *************\n");
		#endif
		
		fclose(arquivo);
	}
	
	//***********************************************************
	distribui(h, nomeArquivo);
	//***********************************************************
	
	#ifdef DEBUG_SEARCH
		printf("\n********** DISTRIBUIU SEARCH *************\n");
	#endif
}
示例#18
0
文件: Auth.hpp 项目: konlytest/online
    const std::string getAccessToken()
    {
        std::string encodedHeader = createHeader();
        std::string encodedPayload = createPayload();

        // trim '=' from end of encoded header
        encodedHeader.erase(std::find_if(encodedHeader.rbegin(), encodedHeader.rend(),
                                         [](char& ch)->bool {return ch != '='; }).base(), encodedHeader.end());
        // trim '=' from end of encoded payload
        encodedPayload.erase(std::find_if(encodedPayload.rbegin(), encodedPayload.rend(),
                                          [](char& ch)->bool { return ch != '='; }).base(), encodedPayload.end());
        Log::info("Encoded JWT header: " + encodedHeader);
        Log::info("Encoded JWT payload: " + encodedPayload);

        // Convert to a URL and filename safe variant:
        // Replace '+' with '-' && '/' with '_'
        std::replace(encodedHeader.begin(), encodedHeader.end(), '+','-');
        std::replace(encodedHeader.begin(), encodedHeader.end(), '/','_');

        std::replace(encodedPayload.begin(), encodedPayload.end(), '+','-');
        std::replace(encodedPayload.begin(), encodedPayload.end(), '/','_');

        std::string encodedBody = encodedHeader  + "." +  encodedPayload;

        // sign the encoded body
        _digestEngine.update(encodedBody.c_str(), static_cast<unsigned>(encodedBody.length()));
        Poco::Crypto::DigestEngine::Digest digest = _digestEngine.signature();

        // The signature generated contains CRLF line endings.
        // Use a line ending converter to remove these CRLF
        std::ostringstream ostr;
        Poco::OutputLineEndingConverter lineEndingConv(ostr, "");
        Poco::Base64Encoder encoder(lineEndingConv);
        encoder << std::string(digest.begin(), digest.end());
        encoder.close();
        std::string encodedSig = ostr.str();

        // trim '=' from end of encoded signature
        encodedSig.erase(std::find_if(encodedSig.rbegin(), encodedSig.rend(),
                                      [](char& ch)->bool { return ch != '='; }).base(), encodedSig.end());

        // Be URL and filename safe
        std::replace(encodedSig.begin(), encodedSig.end(), '+','-');
        std::replace(encodedSig.begin(), encodedSig.end(), '/','_');

        Log::info("Sig generated is : " + encodedSig);

        const std::string jwtToken = encodedBody + "." + encodedSig;
        Log::info("JWT token generated: " + jwtToken);

        return jwtToken;
    }
示例#19
0
void LogView::setModel(TaskModel *taskModel) {
    _model = taskModel;
    _logScene = new LogScene(this);
    _headerScene = new QGraphicsScene(this);
    _headerView.setScene(_headerScene);
    _hourScene = new QGraphicsScene(this);
    _hourView.setScene(_hourScene);
    _headerView.setAlignment(Qt::AlignLeft | Qt::AlignTop);
    _logView.setScene(_logScene);
    _logView.setAlignment(Qt::AlignLeft | Qt::AlignTop);

    _logScene->setModel(_model);
    createHeader();
}
示例#20
0
void init_heapSpace(void){
	inc_heapSpace();

	uintptr_t *header_address = (uintptr_t *) (((uintptr_t *)start) + 1);
	uintptr_t *footer_address = (uintptr_t *) (((uintptr_t *)end) - 2);
	uintptr_t init_info = createHeader(STD_SBRK_REQ, STD_SBRK_REQ - 16, MARK_FREE);

	*header_address = init_info;
	*footer_address = init_info;

	*(header_address + 1) = NULL_POINTER; /* set next to NULL POINTER */
	*(header_address + 2) = NULL_POINTER; /* set previous to NULL POINTER */
	head = (void *) header_address;
}
void WaveWriter::write()
{
	createHeader();

	FILE *wav_file;
	wav_file = fopen("audio/osc_test.wav", "wb");

	if(wav_file)
	{
		std::cout<<"Writing header...";
		fwrite(header_, 1, sizeof(header_), wav_file);
		std::cout<<"Done\nWriting wave...";
		fwrite(wave_, sizeof(*wave_), SAMPLE_RATE*PLAY_LENGTH, wav_file);
		std::cout<<"Done\n";
		fclose(wav_file);
	}
} 
示例#22
0
 //! Verify state of a file
 void CFile::checkFile(void)
 {
   if (mode.isEmpty() || mode.getValue() == mode_attr::write)
   {
     CTimer::get("Files : create headers").resume();
     if (!isOpen) createHeader();
     CTimer::get("Files : create headers").suspend();
     checkSync();
   }
   else
   {
     CTimer::get("Files : open headers").resume();
     if (!isOpen) openInReadMode();
     CTimer::get("Files : open headers").suspend();
   }
   checkSplit();
 }
示例#23
0
int main ( void ){
   inicializaArvore(); //deve funcionar para as proximas funções funcionarem.
   createHeader(); //para as funçoes funcionarem o header deve ser criado, se o header foi criado então a função está correta
   
   CU_pSuite pSuite = NULL;

   /* initialize the CUnit test registry */
   if ( CUE_SUCCESS != CU_initialize_registry() )
      return CU_get_error();

   /* add a suite to the registry */
   pSuite = CU_add_suite( "max_test_suite", init_suite, clean_suite );
   if ( NULL == pSuite ) {
      CU_cleanup_registry();
      return CU_get_error();
   }

   /* add the tests to the suite */
   if ( (NULL == CU_add_test(pSuite, "Inserir", test_insere)) ||
        (NULL == CU_add_test(pSuite, "atualizar", test_atualiza)) ||
        (NULL == CU_add_test(pSuite, "excluir", test_exclui))
      )
   {
      CU_cleanup_registry();
      return CU_get_error();
   }

   // Run all tests using the basic interface
   CU_basic_set_mode(CU_BRM_VERBOSE);
   CU_basic_run_tests();
   printf("\n");
   CU_basic_show_failures(CU_get_failure_list());
   printf("\n\n");
/*
   // Run all tests using the automated interface
   CU_automated_run_tests();
   CU_list_tests_to_file();

   // Run all tests using the console interface
   CU_console_run_tests();
*/
   /* Clean up registry and return */
   CU_cleanup_registry();
   return CU_get_error();
}
示例#24
0
void TollsManagement::writeTollsToFile(const TollContainerType& tolls, const std::string& existingFile, 
		const std::string& newFile, StarNetwork* net){
	FileWriter writer(newFile);
	FileReader reader(existingFile);

	createHeader(writer, reader);

	std::string line("");
	int guessIndex = 0;
	while (reader.isGood()) {
		line = reader.getNextLine();
		if (!Utils::deleteWhiteSpaces(line).empty()) {
			writeLinkToFile(writer, line, tolls, net, guessIndex);
			++guessIndex;
		}
	}
	
};
示例#25
0
void trataTimerHello(){
	int i;
	Header h;
	// Checa 'Hello's' recebidos.
	// TODO
	
	// Envia 'Hello's'.
	for(i=0 ; i<MAX_VIZINHOS ; i++)	{
		if(vizinhos[i].sockfd > 0) {
			createHeader(&h, HELLO, vizinhos[i].vizinho);
			h.tamDados = 0;
			if(!escrevePacote(vizinhos[i].sockfd, h, NULL))
				puts("Erro no envio de HELLO");
		}
	}
	
	SetTimer( DadosAplicacao.intervaloHello, TIMER_HELLO, 0 );
}
示例#26
0
void allocateBlock(uintptr_t **cursor, size_t req_size, size_t allocate_size){
	uintptr_t *header_address = *cursor;
	uintptr_t *footer_address = header_address + (allocate_size / 8) + 1;

	uintptr_t allocated_info = createHeader(req_size, allocate_size + 16, MARK_USED);
	*header_address = allocated_info;
	*footer_address = allocated_info;

	/* allocated block resided between two free blocks */
	if((uintptr_t) *(header_address + 1) != NULL_POINTER 
	&& (uintptr_t) *(header_address + 2) != NULL_POINTER ){
		
		uintptr_t *next = (uintptr_t*) *(header_address + 1);
		uintptr_t *previous = (uintptr_t*) *(header_address + 2);

		*(next + 2) = (uintptr_t) previous;
		*(previous + 1) = (uintptr_t) next;

	}

	/* allocated block has a block infront but not behind */
	else if((uintptr_t) *(header_address + 1) != NULL_POINTER 
		 && (uintptr_t) *(header_address + 2) == NULL_POINTER ){
		
		uintptr_t *next = (uintptr_t*) *(header_address + 1);
		
		*(next + 2) = (uintptr_t) NULL_POINTER;

		head = (void *) next;
	}

	/* allocated block has a block behind but not infront */
	else if((uintptr_t) *(header_address + 1) == NULL_POINTER 
		 && (uintptr_t) *(header_address + 2) != NULL_POINTER ){
		
		uintptr_t *previous = (uintptr_t*) *(header_address + 2);
		
		*(previous + 1) = (uintptr_t) NULL_POINTER;

	}else{
		/* must of allocated the only free block in the list*/
		head = (uintptr_t *) NULL_POINTER;
	}	
}
示例#27
0
int evt_GetLastAction(char*apikey, Action * action)
{
	connect();
	
	char * urlPath = createGetLastActionURLPath(action->thng);
	char * header = createHeader(apikey);
	
	int responseCode = HTTP_Get(socket, EVRYTHNG_API_HOST, urlPath, header, respHeader, ARRAY_SIZE(respHeader), respBody, ARRAY_SIZE(respBody),200);
	
	if (responseCode == 200)
	{
		parseAction(action, respBody);
	}

	disconnect();
	free(urlPath);
	free(header);
	
	return responseCode;	
}
示例#28
0
/**
* EVT interface
*/
int evt_GetPropertyValue(char* apikey, char* thngId, char* propertyName, Property *property)
{
	connect();
	
	char * urlPath = createGetPropertyURLPath(thngId, propertyName);
	char * header = createHeader(apikey);
	
	int responseCode = HTTP_Get(socket, EVRYTHNG_API_HOST, urlPath, header, respHeader, ARRAY_SIZE(respHeader), respBody, ARRAY_SIZE(respBody),200);
	
	if (responseCode == 200)
	{
		parseProperty(property, respBody);
	}

	disconnect();
	free(urlPath);
	free(header);
	
	return responseCode;	
};
示例#29
0
void SymbianLog::reset(const char* title) 
{
    iSemaphore.Wait();
    
    TInt err = file.Replace(fsSession, iLogName, EFileWrite|EFileShareAny);
    if (err != KErrNone) {
        setErrorF(err, "SymbianLog: error resetting the log file (code %d)", err);
        return;
    }
    
    // Write the Header
    StringBuffer header = createHeader(title);
    RBuf8 buf;
    buf.Assign(stringBufferToNewBuf8(header));
    file.Write(buf);
    buf.Close();
    
    file.Close();
    iSemaphore.Signal();
}
示例#30
0
void disparaHello()
{
	Header hello;
	IdPeer destino;

	// Destino serah setado pela funcao distribui()	
	memset( &destino, 0, sizeof(IdPeer));
	
	createHeader(&hello, HELLO, destino);
	hello.tamDados = 0;
	#ifdef DEBUG
		printf("\n\n");
		puts("*****************************************");
		puts("Vou distribuir hello");
		puts("*****************************************");
		printf("\n");
	#endif
	
	distribui(hello, NULL);
}