开源 企业版 高校版 私有云 模力方舟 AI 队友
代码拉取完成,页面将自动刷新
开源项目 > 程序开发 > 编程语言/脚本语言 &&
捐赠
捐赠前请先登录
扫描微信二维码支付
取消
支付完成
支付提示
将跳转至支付宝完成支付
确定
取消
13 Star 69 Fork 22

johnsonyl/cpps

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
已有帐号? 立即登录
文件
master
分支 (1)
标签 (4)
master
v1.0.3-beta
v1.0.3
v1.0.2
v1.0.0
master
分支 (1)
标签 (4)
master
v1.0.3-beta
v1.0.3
v1.0.2
v1.0.0
克隆/下载
克隆/下载
提示
下载代码请复制以下命令到终端执行
为确保你提交的代码身份被 Gitee 正确识别,请执行以下命令完成配置
初次使用 SSH 协议进行代码克隆、推送等操作时,需按下述提示完成 SSH 配置
1 生成 RSA 密钥
2 获取 RSA 公钥内容,并配置到 SSH公钥
在 Gitee 上使用 SVN,请访问 使用指南
使用 HTTPS 协议时,命令行会出现如下账号密码验证步骤。基于安全考虑,Gitee 建议 配置并使用私人令牌 替代登录密码进行克隆、推送等操作
Username for 'https://gitee.com': userName
Password for 'https://userName@gitee.com': # 私人令牌
master
分支 (1)
标签 (4)
master
v1.0.3-beta
v1.0.3
v1.0.2
v1.0.0
cpps
/
libs
/
socket
/
cpps_socket_httpserver.cpp
cpps
/
libs
/
socket
/
cpps_socket_httpserver.cpp
cpps_socket_httpserver.cpp 20.87 KB
一键复制 编辑 原始数据 按行查看 历史
johnsonyl 提交于 2024年11月27日 23:07 +08:00 . 更新了一些第三方库的版本
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679
#include "cpps_socket_httpserver.h"
#include "cpps_socket_httpserver_request.h"
#include "cpps_socket_httpserver_controller.h"
#include "cpps_socket_httpserver_session.h"
#include "cpps_socket_httpserver_cachefile.h"
#include "cpps_socket_server_client.h"
#include "http_parser.h"
namespace cpps {
void cpps_string_real_tolower(std::string& s);
bool cpps_io_file_exists(std::string path);
std::string cpps_io_getfileext(std::string str);
std::string cpps_io_readfile(std::string filepath);
std::string cpps_getcwd();
cpps_integer cpps_time_gettime();
cpps_integer cpps_io_last_write_time(std::string path);
cpps_socket_httpserver::cpps_socket_httpserver()
{
http_running = false;
}
cpps_socket_httpserver::~cpps_socket_httpserver()
{
stop();
}
void cpps_socket_httpserver::setcstate(cpps::C* cstate)
{
c = cstate;
}
cpps_socket_httpserver* cpps_socket_httpserver::setoption(cpps::object opt)
{
if (cpps::type(opt["ip"]) == CPPS_TSTRING) http_option.option_ip = object_cast<std::string>(opt["ip"]);
http_option.exceptionfunc = opt["exceptionfunc"];
http_option.notfoundfunc = opt["notfoundfunc"];
http_option.writefunc = opt["writefunc"];
http_option.userdata = opt["userdata"];
server_option.option_ip = http_option.option_ip;
server_option.option_ssl = opt["ssl"];
server_option.option_certificate_file = opt["certificate_file"];
server_option.option_privatekey_file = opt["privatekey_file"];
server_option.option_servername_callback = opt["servername_callback"];
if (server_option.option_ssl.tobool()) {
SSL_library_init();
OpenSSL_add_all_algorithms();
SSL_load_error_strings();
}
return this;
}
cpps_socket_httpserver* cpps_socket_httpserver::listen(cpps::C* cstate, cpps::usint16 port, cpps::object _ssl_port)
{
setcstate(cstate);
cpps_socket_server::listen(cstate, port, _ssl_port);
if (!sever_running) return this;
createuuidfunc = cpps::object::globals(c)["__socket_httpserver_createuuid"];
if(!createuuidfunc.isfunction())
throw cpps_error(__FILE__, __LINE__, cpps_error_normalerror, "__socket_httpserver_createuuid not found...\r\n");
SESSION_ENABLED = cpps::object::globals(c)["SESSION_ENABLED"].tobool();
SESSION_ENGINE = cpps::object::globals(c)["SESSION_ENGINE"].tostring();
SESSION_FILE_PATH = cpps::object::globals(c)["SESSION_FILE_PATH"].tostring();
SESSION_COOKIE_NAME = cpps::object::globals(c)["SESSION_COOKIE_NAME"].tostring();
SESSION_COOKIE_PATH = cpps::object::globals(c)["SESSION_COOKIE_PATH"].tostring();
SESSION_COOKIE_DOMAIN = cpps::object::globals(c)["SESSION_COOKIE_DOMAIN"].tostring();
SESSION_COOKIE_SECURE = cpps::object::globals(c)["SESSION_COOKIE_SECURE"].tobool();
SESSION_COOKIE_HTTPONLY = cpps::object::globals(c)["SESSION_COOKIE_HTTPONLY"].tobool();
SESSION_EXPIRE_AT_BROWSER_CLOSE = cpps::object::globals(c)["SESSION_EXPIRE_AT_BROWSER_CLOSE"].tobool();
SESSION_SAVE_EVERY_REQUEST = cpps::object::globals(c)["SESSION_SAVE_EVERY_REQUEST"].tobool();
SESSION_COOKIE_AGE = cpps::object::globals(c)["SESSION_COOKIE_AGE"].toint();
http_running = true;
return this;
}
unsigned char ToHex(unsigned char x)
{
return x > 9 ? x + 55 : x + 48;
}
unsigned char FromHex(unsigned char x)
{
unsigned char y = 0;
if (x >= 'A' && x <= 'Z') y = x - 'A' + 10;
else if (x >= 'a' && x <= 'z') y = x - 'a' + 10;
else if (x >= '0' && x <= '9') y = x - '0';
return y;
}
std::string urlencode(std::string str)
{
std::string strTemp = "";
size_t length = str.length();
for (size_t i = 0; i < length; i++)
{
if (isalnum((unsigned char)str[i]) ||
(str[i] == '-') ||
(str[i] == '_') ||
(str[i] == '.') ||
(str[i] == '~'))
strTemp += str[i];
else if (str[i] == ' ')
{
strTemp += '%';
strTemp += '2';
strTemp += '0';
}
else
{
strTemp += '%';
strTemp += ToHex((unsigned char)str[i] >> 4);
strTemp += ToHex((unsigned char)str[i] % 16);
}
}
return strTemp;
}
std::string urldecode(std::string str)
{
std::string strTemp = "";
size_t length = str.length();
for (size_t i = 0; i < length; i++)
{
if (str[i] == '+') strTemp += ' ';
else if (str[i] == '%')
{
unsigned char high = FromHex((unsigned char)str[++i]);
unsigned char low = FromHex((unsigned char)str[++i]);
strTemp += high * 16 + low;
}
else strTemp += str[i];
}
return strTemp;
}
void http_parse_query_str(std::string& uri, PARAMSLIST& list)
{
//a=10&b=20&c=&d=&=10
size_t i = 0;
while (i != std::string::npos && i < uri.size()) {
size_t ii = uri.find('=',i);
if (ii == std::string::npos) {
break;
}
if (ii == i + 1) {
break; //&= is wrong.need keys.
}
std::string field = uri.substr(i, ii - i);
ii++;
size_t iii = uri.find("&", ii);
if (iii == std::string::npos) {
list[field] = urldecode(uri.substr(ii));
break;
}
list[field] = urldecode(uri.substr(ii, iii - ii));
i = iii + 1;
}
}
void cpps_socket_httpserver::generic_handler(struct http_request& req, void* handler)
{
cpps_socket_httpserver* httpserver = (cpps_socket_httpserver*)handler;
cpps_create_class_var(cpps_socket_httpserver_request, httpserver->c, cpps_request_var, cpps_request_ptr);
cpps_request_ptr->server = httpserver;
cpps_request_ptr->socket_index = req.socket_index;
cpps_request_ptr->path = req.path;
cpps_request_ptr->keepalive = req.keepalive;
cpps_request_ptr->support_gzip = req.support_gzip;
cpps_request_ptr->method = req.method;
cpps_request_ptr->ip_address = req.ip_address;
cpps_request_ptr->port = (cpps_integer)req.port;
httpserver->request_list.insert(http_request_list::value_type(req.socket_index, cpps_request_var));
if (!req.uri.empty())
{
cpps_request_ptr->uri = req.uri;
http_parse_query_str(req.uri, cpps_request_ptr->getlist);
for (auto item : cpps_request_ptr->getlist)
cpps_request_ptr->paramslist[item.first] = item.second;
}
for (auto item : req.headers)
cpps_request_ptr->input_headerslist.insert(PARAMSLIST::value_type(item.first, item.second));
size_t ibsize = req.body_len;
if (ibsize > 0)
{
cpps_request_ptr->input_buffer.append(req.body_buf, req.body_len);
if (cpps_request_ptr->isformdata()) {
cpps_request_ptr->parse_form_data(cpps_request_ptr->input_buffer);
}
else {
http_parse_query_str(cpps_request_ptr->input_buffer, cpps_request_ptr->postlist);
for (auto item : cpps_request_ptr->postlist)
cpps_request_ptr->paramslist[item.first] = item.second;
}
}
ibsize = req.header_len;
if (ibsize > 0) {
cpps_request_ptr->header_buffer.append(req.header_buf, req.header_len);
}
cpps_stack* takestack = httpserver->c->getcallstack()->empty() ? NULL : httpserver->c->getcallstack()->at(httpserver->c->getcallstack()->size() - 1);
try
{
//1.先找路由
std::string path = cpps_request_ptr->path;
cpps_string_real_tolower(path);
cpps::object func = httpserver->gethandlefunc(path);
if (cpps::type(func) == CPPS_TFUNCTION)
{
cpps_socket_httpserver_bindsession(httpserver, cpps_request_ptr);
dofunction(httpserver->c, func, cpps_request_var);
return;
}
//2.找controller.
cpps::object controller_object;
const cpps_socket_httpserver_controller controller = cpps_socket_httpserver_parse_controlloer(path);
if (path == "/") //找默认controller.
{
controller_object = httpserver->http_default_class_route;
}
else
{
controller_object = httpserver->getcontroller(controller.controllername);
}
if (cpps::type(controller_object) == CPPS_TCLASS)
{
cpps::cpps_cppsclass* cppsclass = cpps_to_cpps_cppsclass(controller_object.value);
if (cppsclass->iscppsclass())
{
std::string method = "index";
if (!controller.method.empty()) method = controller.method;
cpps_domain* leftdomain = NULL;
cpps_regvar *var = cppsclass->getvar(method, leftdomain, true,true);
if (var) //找到method了.
{
//创建变量.
cpps_socket_httpserver_bindsession(httpserver, cpps_request_ptr);
cpps::object cppsclassvar;
newcppsclasvar(httpserver->c, cppsclass, &cppsclassvar.getval());
doclassfunction(httpserver->c, cppsclassvar, var->getval(), cpps_request_var);
return;
}
}
}
//3.找本地文件(cache么?)
std::string filepath = cpps_getcwd() + httpserver->getwwwroot() + path;
std::string ext = cpps_io_getfileext(path);
if (ext.empty()) {
filepath += "/index.html";
ext = "html";
}
bool b = cpps_io_file_exists(filepath);
if (b)
{
const std::string& mime_type = httpserver->get_type_ref(ext);
if (!mime_type.empty()) {
cpps_request_ptr->real_addheader(CACHE_CONTROL, "max-age=2592000, public");
cpps_request_ptr->real_addheader(CONTENT_TYPE, mime_type.c_str());
cpps_request_ptr->real_addheader(SERVER_HEADER, "Cpps Server");
cpps_request_ptr->real_addheader(CONNECTION, "close");
cpps_integer last_write_time = cpps_io_last_write_time(filepath);
auto cachefile = httpserver->get_cachefile(path);
if (cachefile == NULL )
{
std::string content = cpps_io_readfile(filepath);
cachefile = httpserver->create_cachefile(path, content, last_write_time);
}
if (cachefile->getlast_write_time() != last_write_time) {
std::string content = cpps_io_readfile(filepath);
cachefile->setcontent(content);
}
cpps_request_ptr->append(cachefile->getcontent());
cpps_request_ptr->send(200, "OK");
return;
}
}
//4.找不到执行notfound
func = httpserver->http_option.notfoundfunc;
if (cpps::type(func) == CPPS_TFUNCTION)
{
dofunction(httpserver->c, func, cpps_request_var);
return;
}
//4.没有绑定notfound的话...
cpps_request_ptr->append("Sorry,not found.\n");
cpps_request_ptr->send( 404, "NOT FOUND");
}
catch (cpps_error e)
{
//5.脚本异常的话...
std::string errmsg;
char errbuffer[8192];
sprintf(errbuffer, "error: %d : %s file:%s line:%d \nError stack information:\n", e.error(), e.what().c_str(), e.file().c_str(), e.line());
errmsg.append(errbuffer);
std::vector<cpps_stack*>* stacklist = httpserver->c->getcallstack();
for (std::vector<cpps_stack*>::reverse_iterator it = stacklist->rbegin(); it != stacklist->rend(); ++it)
{
cpps::cpps_stack* stack = *it;
sprintf(errbuffer, "file:%s [%d] %s\n", stack->f, stack->l, stack->func);
errmsg.append(errbuffer);
}
cpps_pop_stack_to_here(httpserver->c, takestack); //清栈
cpps::object func = httpserver->http_option.exceptionfunc;
if (cpps::type(func) == CPPS_TFUNCTION)
{
dofunction(httpserver->c, func, cpps_request_var, errmsg);
return;
}
//6.没有找到脚本异常的话...
cpps_request_ptr->append("Sorry,SERVER ERROR.\n");
cpps_request_ptr->send(500, "SERVER ERROR");
}
}
void cpps_socket_httpserver::register_handlefunc(std::string path, cpps::object func)
{
cpps_string_real_tolower(path);
http_route_list[path] = func;
}
void cpps_socket_httpserver::register_controller(cpps::object cls, cpps_value defaultset)
{
bool bdefaultset = defaultset.tt == CPPS_TBOOLEAN ? defaultset.value.b : false;
if (cpps::type(cls) == CPPS_TCLASS)
{
cpps::cpps_cppsclass* cppsclass = cpps_to_cpps_cppsclass(cls.value);
if (cppsclass->iscppsclass())
{
std::string s = cppsclass->getclassname();
cpps_string_real_tolower(s);
http_class_route_list[s] = cls;
if(bdefaultset)
http_default_class_route = cls;
}
}
}
bool cpps_socket_httpserver::isrunning()
{
return http_running;
}
void cpps_socket_httpserver::run()
{
cpps_socket_server::run();
update_session();
}
void cpps_socket_httpserver::stop()
{
cpps_socket_server::stop();
for (auto session : session_list)
{
cpps_socket_httpserver_session* sess = session.second;
CPPSDELETE(sess);
}
session_list.clear();
auto it = cachefile_list.begin();
for (; it != cachefile_list.end(); ++it) {
cpps_socket_httpserver_cachefile* file = it->second;
CPPSDELETE( file);
}
cachefile_list.clear();
http_running = false;
}
void cpps_socket_httpserver::add_type(std::string mime, std::string ext)
{
mime_types.insert(http_mime_type::value_type(ext, mime));
}
const std::string& cpps_socket_httpserver::get_type_ref(std::string& ext)
{
return mime_types[ext];
}
std::string cpps_socket_httpserver::get_type(std::string ext)
{
return mime_types[ext];
}
cpps::object cpps_socket_httpserver::gethandlefunc(std::string path)
{
cpps::object ret;
auto it = http_route_list.find(path);
if (it != http_route_list.end()) {
ret = it->second;
}
return ret;
}
cpps::object cpps_socket_httpserver::getcontroller(std::string controllername)
{
cpps::object ret;
auto it = http_class_route_list.find(controllername);
if (it != http_class_route_list.end()) {
ret = it->second;
}
return ret;
}
cpps::cpps_socket_httpserver_session* cpps_socket_httpserver::create_seesion(cpps::C* c)
{
std::string sesionid = object_cast<std::string>(dofunction(c, createuuidfunc));
std::string csrf_token = object_cast<std::string>(dofunction(c, createuuidfunc));
if (sesionid.empty()) return NULL;
cpps_socket_httpserver_session* session = CPPSNEW( cpps_socket_httpserver_session)();
session->session_id = sesionid;
session->set_expire(cpps_time_gettime() + SESSION_COOKIE_AGE);
session->set("csrftoken", cpps_value(c,csrf_token));
session_list.insert(http_session_list::value_type(sesionid, session));
return session;
}
cpps::cpps_socket_httpserver_session* cpps_socket_httpserver::get_session(std::string session_id)
{
cpps_socket_httpserver_session* ret = NULL;
auto it = session_list.find(session_id);
if (it != session_list.end())
{
ret = it->second;
}
return ret;
}
cpps::cpps_socket_httpserver_cachefile* cpps_socket_httpserver::create_cachefile(std::string& filepath, std::string& content,cpps_integer last_write_time)
{
cpps_socket_httpserver_cachefile* cachefile = CPPSNEW( cpps_socket_httpserver_cachefile)();
cachefile->setfilepath(filepath);
cachefile->setcontent(content);
cachefile->setlast_write_time(last_write_time);
cachefile_list.insert(http_cachefile_list::value_type(filepath, cachefile));
return cachefile;
}
cpps::cpps_socket_httpserver_cachefile* cpps_socket_httpserver::get_cachefile(std::string filepath)
{
cpps_socket_httpserver_cachefile* ret = NULL;
auto it = cachefile_list.find(filepath);
if (it != cachefile_list.end())
{
ret = it->second;
}
return ret;
}
int header_field_cb(http_parser* p, const char* buf, size_t len)
{
http_request* req = (struct http_request*)p->data;
req->field.clear();
req->field.append(buf, len);
return 0;
}
int header_value_cb(http_parser* p, const char* buf, size_t len)
{
http_request* req = (struct http_request*)p->data;
std::string value;
value.append(buf, len);
if ("Accept-Encoding" == req->field) {
req->support_gzip = value.find("gzip") != std::string::npos;
}
req->headers[req->field] = value;
return 0;
}
int request_url_cb(http_parser* p, const char* buf, size_t len)
{
http_request* req = (struct http_request*)p->data;
std::string url;
url.append(buf, len);
size_t pos = url.find('?');
req->path.append(url.substr(0,pos));
if (pos != std::string::npos)
req->uri.append(url.substr(pos + 1));
return 0;
}
int body_cb(http_parser* p, const char* buf, size_t len)
{
return 0;
}
int headers_complete_cb(http_parser* p)
{
http_request* req = (struct http_request*)p->data;
req->keepalive = http_should_keep_alive(p);
return -1;
}
int message_begin_cb(http_parser* p)
{
http_request* req = (struct http_request*)p->data;
req->method = http_method_str( (http_method)p->method );
return 0;
}
int message_complete_cb(http_parser* p)
{
return 0;
}
int chunk_header_cb(http_parser* parser)
{
return 0;
}
int chunk_complete_cb(http_parser* p)
{
return 0;
}
void cpps_socket_httpserver::onReadCallback(cpps_socket* sock, ssize_t nread, const char* buf)
{
cpps_socket_server_client* client = (cpps_socket_server_client*)sock;
if (nread > 0)
{
client->readbuffer(buf, nread);
http_request request;
http_parser parser;
request.support_gzip = false;
request.body_len = 0;
request.header_len = 0;
parser.data = (void*)&request;
http_parser_init(&parser, HTTP_REQUEST);
http_parser_settings settings = { message_begin_cb, request_url_cb, nullptr, header_field_cb, header_value_cb,
headers_complete_cb, body_cb, message_complete_cb, chunk_header_cb, chunk_complete_cb };
size_t parsed = http_parser_execute(&parser, &settings, client->buffer.c_str(), client->buffer.size());
if (!request.headers["Content-Length"].empty())
{
auto content_length = atoll(request.headers["Content-Length"].c_str());
if ((client->buffer.size() - parsed) < (size_t)content_length)
{
return;
}
request.body_buf = client->buffer.c_str() + parsed + 1;
request.body_len = size_t(content_length);
}
else if ((parsed + 1) != client->buffer.size()) {
return;
}
request.header_buf = client->buffer.c_str();
request.header_len = parsed + 1;
request.ip_address = client->socket_ip;
request.port = (usint16)client->socket_port;
//request.body.append(request.body_buf, request.body_len);
request.socket_index = client->socket_index;
client->recv_count++;
generic_handler(request, this);
client->buffer.clear();
}
else if (nread < 0)
{
client->close("normal close.", onClsoe);
}
}
void cpps_socket_httpserver::onWriteCallback(cpps_socket* sock, ssize_t nread, const char* buf)
{
if (cpps::type(http_option.writefunc) == CPPS_TFUNCTION)
{
cpps_socket_server_client* client = (cpps_socket_server_client*)sock;
std::string _s(buf, nread);
cpps::dofunction(c, http_option.writefunc, _s, this, client->socket_index);
//close
/*if (client->isShutdown() && client->get_send_count() == client->get_write_count()) {
closesocket(client->socket_index);
}*/
}
}
void cpps_socket_httpserver::onClsoeCallback(cpps_socket* sock)
{
cpps_socket_server_client* client = (cpps_socket_server_client*)sock;
request_list.erase(client->socket_index);
}
void cpps_socket_httpserver::update_session()
{
auto it = session_list.begin();
for (; it != session_list.end();) {
auto session = it->second;
if (cpps_time_gettime() >= session->session_expire || session->needremove) {
CPPSDELETE(session);
it = session_list.erase(it);
}
else {
++it;
}
}
}
void cpps_socket_httpserver::cpps_socket_httpserver_bindsession(cpps_socket_httpserver* httpserver, cpps_socket_httpserver_request* cpps_request_ptr,bool create_session)
{
if (httpserver->SESSION_ENABLED) {
std::string sessionid = cpps_request_ptr->getcookie(httpserver->SESSION_COOKIE_NAME);
cpps_socket_httpserver_session* session = NULL;
if (!sessionid.empty()) {
//check session;
session = httpserver->get_session(sessionid);
if (session) {
session->set_expire(cpps_time_gettime() + httpserver->SESSION_COOKIE_AGE);//加时.
}
}
//不应该直接创建session.应该由后台创建.
if (!session && create_session) {
session = httpserver->create_seesion(httpserver->c);
cpps_request_ptr->setcookie(httpserver->SESSION_COOKIE_NAME, session->session_id, cpps::object::create(httpserver->c, httpserver->SESSION_COOKIE_PATH), cpps::object::create(httpserver->c, httpserver->SESSION_COOKIE_DOMAIN), cpps::object::create(httpserver->c, httpserver->SESSION_COOKIE_AGE));
object csrftoken = session->get("csrftoken", nil);
cpps_request_ptr->setcookie("csrftoken", csrftoken.tostring(), cpps::object::create(httpserver->c, httpserver->SESSION_COOKIE_PATH), cpps::object::create(httpserver->c, httpserver->SESSION_COOKIE_DOMAIN), cpps::object::create(httpserver->c, httpserver->SESSION_COOKIE_AGE));
}
cpps_request_ptr->setsession(session);
}
}
std::string cpps_socket_httpserver::getwwwroot()
{
return _wwwroot ;
}
void cpps_socket_httpserver::setwwwroot(std::string wwwroot)
{
_wwwroot = wwwroot + "/";
}
void cpps_socket_httpserver::setuserdata(cpps::object userdata)
{
http_option.userdata = userdata;
}
cpps_value cpps_socket_httpserver::getuserdata()
{
return http_option.userdata.getval();
}
cpps_value cpps_socket_httpserver::get_request(cpps_integer socket_index)
{
cpps_value ret;
http_request_list::iterator it = request_list.find(socket_index);
if (it != request_list.end()) {
ret = it->second;
}
return ret;
}
}
Loading...
举报
举报成功
我们将于2个工作日内通过站内信反馈结果给你!
请认真填写举报原因,尽可能描述详细。
请选择举报类型
取消
发送
误判申诉

此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。

如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。

取消
提交

简介

CPPS是一种轻量级的嵌入式脚本语言,其语法类似于C++。它具有当前主流语言的许多特性,包括协程、面向对象、lambda、闭包、泛型变量、自定义模块支持、GC垃圾收集和跨平台。CPPS将程序解释为字节码,通过内置语法解析在虚拟机中运行
取消

发行版 (3)

全部

开源评估指数源自 OSS-Compass 评估体系,评估体系围绕以下三个维度对项目展开评估:

1. 开源生态

  • 生产力:来评估开源项目输出软件制品和开源价值的能力。
  • 创新力:用于评估开源软件及其生态系统的多样化程度。
  • 稳健性:用于评估开源项目面对多变的发展环境,抵御内外干扰并自我恢复的能力。

2. 协作、人、软件

  • 协作:代表了开源开发行为中协作的程度和深度。
  • 人:观察开源项目核心人员在开源项目中的影响力,并通过第三方视角考察用户和开发者对开源项目的评价。
  • 软件:从开源项目对外输出的制品评估其价值最终落脚点。也是开源评估最"古老"的主流方向之一"开源软件" 的具体表现。

3. 评估模型

    基于"开源生态"与"协作、人、软件"的维度,找到与该目标直接或间接相关的可量化指标,对开源项目健康与生态进行量化评估,最终形成开源评估指数。

贡献者

全部

近期动态

不能加载更多了
编辑仓库简介
简介内容
主页
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/cppscript/cpps.git
git@gitee.com:cppscript/cpps.git
cppscript
cpps
cpps
master
点此查找更多帮助

搜索帮助

评论
仓库举报
回到顶部
登录提示
该操作需登录 Gitee 帐号,请先登录后再操作。
立即登录
没有帐号,去注册

AltStyle によって変換されたページ (->オリジナル) /