Beispiel #1
0
Log* ReadLog(char* Directory, char* FileName)
{
	HANDLE hFile = CreateFile(Directory, GENERIC_READ, 0, NULL,
		OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);

	if (hFile == INVALID_HANDLE_VALUE)
		return NULL;

	//now read the thing, line by line
	DWORD Size = GetFileSize(hFile, NULL);
	char* Data = new char[Size+1];
	DWORD dw;
	ReadFile(hFile, Data, Size, &dw, NULL);
	CloseHandle(hFile);

	if (dw != Size)
		return NULL;
	Data[Size] = 0;

	LinkedList* Regs = NULL;
	LinkedList* Files = NULL;

	//now the thing is in memory, lets have a go at parsing
	int Pos = 0;
	while(true)
	{
		char* Line = GetLine(Data, &Pos);
		if (Line == NULL) break;

		char* Fields[10];
		GetFields(Line, Fields);

		//ok, now parse a line
		if (Fields[0][0] == 0 || strcmp(Fields[0], "NOTE") == 0)
			; //discard, a comment
		else if (strcmp(Fields[0], "FILE") == 0)
			Files = NewLinkedList(ReadLogFile(Fields, Directory, FileName), Files);
		else if (strcmp(Fields[0], "REG") == 0)
			Regs = NewLinkedList(ReadLogReg(Fields), Regs);
	}

	//now lets make a Log structure
	Log* log = new Log;
	log->Files = (File**) LinkedListToArray(Files, &log->nFile);
	log->Registrys = (Registry**) LinkedListToArray(Regs, &log->nRegistry);

	return log;
}
void page_response(HttpHeader *header){
	bool reset=FALSE;
	bool prepare=TRUE;
    char* action=header->action;
    OUTD("action=%s",action);
	Ql_memset(__data_buf,0,4096);
	Ql_memset(__s_buf,0,10240);
    
    if (Ql_strstr(header->action, "/")) {
		get_main_page( __est_connection ? "System state is start":"System state stop");
        OUTD("main page",NULL);
	}
	else if (Ql_strstr(action,"reboot")) {
		get_rebot_page();
		reset=TRUE;
	}
	else if (Ql_strstr(action,"settings?")) {
		char* pch=NULL;
		char* last=NULL;
		//OUTD("parse setting action:%s",pch);
		pch=strtok_r(action+9,"&",&last);
	  //OUTD("parse command:%s",pch);
     while (pch!=NULL) {
        setCommand(pch);
        pch=strtok_r(NULL,"&",&last);
		//OUTD("parse command:%s",pch);
    }
	
     WriteSettings();
	 ReadSettings();
	 get_main_page("Save settings controller is OK");
	}
	else if (Ql_strstr(action,"date?")) {
		bool sdt=SetLocDate(action+5);
		get_main_page(sdt ? "Set date and time is OK":"Error set date and time");
	}
	else if (Ql_strstr(action,"stop")) {
		StopEstConnection();
		get_main_page("Recive command Stop");
	}
	else if (Ql_strstr(action,"run")) {
		nSTATE=STATE_EST_SOCKET_CREATE;
		get_main_page("Recive command Start");
	}
	else if (Ql_strstr(action,"log")) {
		u16 size=0;
		ReadLogFile(&size);
		Ql_sprintf(__s_buf,__download_page,size);
		//Ql_strcpy(&__s_buf[Ql_strlen(__s_buf)],__buf_log);
		
		Ql_memcpy(&__s_buf[Ql_strlen(__s_buf)],__buf_log,size);
		OUTD("__download_page:%d file size:%d buffer-len:%d",Ql_strlen(__download_page),size,Ql_strlen(__s_buf));
		
		prepare=FALSE;
	}
    else if (Ql_strstr(action, "autorize")) {
        Ql_sprintf(__s_buf,__autorize,0);
        prepare=FALSE;
        OUTD("set autorize",NULL);
    }
    else {
		get_error_page();
		Ql_sprintf(__s_buf,__error_page,0);
		prepare=FALSE;
	}
	if (prepare) {
        //if (header->set_cookie) {
          //   Ql_sprintf(__s_buf, __ok_page, Ql_strlen(__data_buf),"\r\nSet-Cookie: __ztp=987654321\r\n"); 
        //}
        Ql_sprintf(__s_buf, __ok_page, Ql_strlen(__data_buf)); 
		Ql_strcpy(&__s_buf[Ql_strlen(__s_buf)],__data_buf);
        OUTD("sbuf:%d dbuf:%d",Ql_strlen(__s_buf),Ql_strlen(__data_buf));
        
	}
	if (reset) {
		Ql_Sleep(10000);
		Ql_Reset(0);
	}
}