91av视频/亚洲h视频/操亚洲美女/外国一级黄色毛片 - 国产三级三级三级三级

  • 大小: 15.55MB
    文件類型: .zip
    金幣: 1
    下載: 0 次
    發布日期: 2023-07-31
  • 語言: 其他
  • 標簽: libevent??http??

資源簡介

http服務端, 解析客戶端上傳的資源類型,并在本地保存相應類型及名稱的文件,

資源截圖

代碼片段和文件信息

#include?“main.h“
?

int?init_win_socket();
void?generic_handler(struct?evhttp_request?*req?void?*arg);
void?http_handler(struct?evhttp_request?*req?void?*arg);


std::ofstream?outfile;

int?main(int?argc?char?**argv)
{

#ifdef?WIN32
init_win_socket();
#endif
char *http_addr?=?“127.0.0.1“;
const?int PORT?=?9995;
//create?a?event_base
struct?event_base?*base?=?event_base_new();
if?(!base)
{
fprintf(stderr?“Could?not?initialize?libevent!\n“);
return?1;
}

struct?evhttp?*http_server?=?evhttp_new(base);
if?(!http_server)
{
return?-1;
}

int?ret?=?evhttp_bind_socket(http_server?http_addr?PORT);
if?(ret?!=?0)
{
return?-1;
}

evhttp_set_gencb(http_server?http_handler?NULL);
printf(“http?server?start?OK!?\n“);
event_base_dispatch(base);

evhttp_free(http_server);
event_base_free(base);
WSACleanup();
system(“pause“);
return?0;
}


int?init_win_socket()
{
WSADATA?wsaData;
if?(WSAStartup(MAKEWORD(2?2)?&wsaData)?!=?0)
{
return?-1;
}
return?0;
}

void?http_handler(struct?evhttp_request?*req?void?*arg)
{
struct?evbuffer?*buf;
buf?=?evbuffer_new();

//?分析請求
char?*decode_uri?=?_strdup((char*)evhttp_request_get_uri(req));
struct?evkeyvalq?http_query;
evhttp_parse_query(decode_uri?&http_query);
free(decode_uri);

char *uri?=?_strdup((char*)evhttp_request_uri(req));
char GetWayURL[100]?=?{?0?};
const?int MSG_DATA_SIZE?=?15000;
char body_data[MSG_DATA_SIZE]?=?{0};
int body_datalen?=?0;


//??
if?(memcmp(uri?GetWayURL?strlen(GetWayURL)?!=?0))
{
free(uri);
buf?=?evbuffer_new();
evbuffer_add_printf(buf?“%s“?“HTTP_BADREQUEST“);
evhttp_send_reply(req?HTTP_BADREQUEST?“OK“?buf);

evbuffer_free(buf);
return;
}
free(uri);


//get?data?from?post
memset(body_data?0?sizeof(body_data));

size_t len_of_file_to_recv?=?0;
bool is_first?=?true;
size_t loc?=?-1;
std::string?body_str;

while?(len_of_file_to_recv?body_size)
{
body_datalen?=?evbuffer_remove(req->input_buffer?body_data?sizeof(body_data));
if?(body_datalen?>?MSG_DATA_SIZE)
{
buf?=?evbuffer_new();
evbuffer_add_printf(buf?“%s“?“HTTP_DATALENTOLANG“);
//?output
evhttp_send_reply(req?HTTP_BADREQUEST?“OK“?buf);
//?mem?release
evbuffer_free(buf);
return;
}
else?if?(is_first)
{
std::string?buf_in?=?body_data;
size_t loc?=?buf_in.find(“\r\n\r\n“);
size_t loc_filename?=?-1;

//get?file?description?and?extract?the?file?name
//and?cat?precise?time?to?the?extracted?file?name?to?result?in?a?unique?file?name
char *filename?=?NULL;
filename?=?new?char[loc+1];

memcpy(filename?body_data?loc);

filename[loc]?=?0;
buf_in?=?filename;
memset(filename?0?loc+1);
loc_filename?=?buf_in.find(“filename“);
std::string?file_name_front;
if?(-1?!=?loc_filename)
{
loc_filename?+=?strlen(“filename“);
while?(l

?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2016-12-26?15:37??Debug\
?????文件?????1020928??2016-12-26?15:37??Debug\libeventHttpServer.exe
?????文件?????4746240??2016-12-26?15:37??Debug\libeventHttpServer.pdb
?????目錄???????????0??2016-12-15?14:09??include\
?????目錄???????????0??2016-12-23?09:22??include\event2\
?????文件???????30747??2016-12-15?14:24??include\event2\buffer.h
?????文件???????28644??2016-12-17?13:40??include\event2\bufferevent.h
?????文件????????4448??2012-02-11?06:17??include\event2\bufferevent_compat.h
?????文件????????3832??2012-02-11?06:17??include\event2\bufferevent_ssl.h
?????文件????????4138??2016-12-15?14:51??include\event2\bufferevent_struct.h
?????文件????????4586??2012-02-11?06:17??include\event2\buffer_compat.h
?????文件???????24648??2015-01-05?21:42??include\event2\dns.h
?????文件???????12131??2012-02-11?06:17??include\event2\dns_compat.h
?????文件????????2572??2012-02-11?06:17??include\event2\dns_struct.h
?????文件???????45203??2016-12-15?14:24??include\event2\event.h
?????文件????????7405??2016-12-19?10:10??include\event2\event_compat.h
?????文件????????4050??2016-12-15?14:52??include\event2\event_struct.h
?????文件???????32393??2016-12-19?11:39??include\event2\http.h
?????文件????????3139??2016-12-19?10:09??include\event2\http_compat.h
?????文件????????4176??2016-12-19?14:38??include\event2\http_struct.h
?????文件????????2614??2016-12-23?09:22??include\event2\keyvalq_struct.h
?????文件????????5961??2016-12-17?13:55??include\event2\listener.h
?????文件???????20984??2012-02-11?06:17??include\event2\rpc.h
?????文件????????2327??2012-02-11?06:17??include\event2\rpc_compat.h
?????文件????????3211??2012-02-11?06:17??include\event2\rpc_struct.h
?????文件????????4438??2012-02-11?06:17??include\event2\tag.h
?????文件????????2117??2012-02-11?06:17??include\event2\tag_compat.h
?????文件????????9475??2016-12-15?14:53??include\event2\thread.h
?????文件???????22598??2016-12-15?14:28??include\event2\util.h
?????文件????????1201??2012-02-11?06:24??include\Makefile.am
?????文件???????18917??2015-01-05?22:31??include\Makefile.in
............此處省略34個文件信息

評論

共有 條評論