Explore Enterprise Education Gitee Premium Gitee AI AI teammates
Fetch the repository succeeded.
Open Source > Development Lib > Programming Language/Scripting Language &&
Donate
Please sign in before you donate.
Scan WeChat QR to Pay
Cancel
Complete
Prompt
Switch to Alipay.
OK
Cancel
13 Star 69 Fork 22

johnsonyl/cpps

Create your Gitee Account
Explore and code with more than 14 million developers,Free private repositories !:)
Sign up
Already have an account? Sign in
文件
master
Branches (1)
Tags (4)
master
v1.0.3-beta
v1.0.3
v1.0.2
v1.0.0
master
Branches (1)
Tags (4)
master
v1.0.3-beta
v1.0.3
v1.0.2
v1.0.0
Clone or Download
Clone/Download
Prompt
To download the code, please copy the following command and execute it in the terminal
To ensure that your submitted code identity is correctly recognized by Gitee, please execute the following command.
When using the SSH protocol for the first time to clone or push code, follow the prompts below to complete the SSH configuration.
1 Generate RSA keys.
2 Obtain the content of the RSA public key and configure it in SSH Public Keys
To use SVN on Gitee, please visit the usage guide
When using the HTTPS protocol, the command line will prompt for account and password verification as follows. For security reasons, Gitee recommends configure and use personal access tokens instead of login passwords for cloning, pushing, and other operations.
Username for 'https://gitee.com': userName
Password for 'https://userName@gitee.com': # Private Token
master
Branches (1)
Tags (4)
master
v1.0.3-beta
v1.0.3
v1.0.2
v1.0.0
cpps
/
libs
/
socket
/
socket.cpp
cpps
/
libs
/
socket
/
socket.cpp
socket.cpp 10.07 KB
Copy Edit Raw Blame History
johnsonyl authored 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

#include <cpps/cpps.h>
#ifdef _WIN32
#pragma warning(disable: 4098)
#include <Windows.h>
#include <WinSock2.h>
#endif
using namespace cpps;
using namespace std;
#include "cpps_socket.h"
#include "cpps_socket_client.h"
#include "cpps_socket_server.h"
#include "cpps_socket_server_client.h"
#include "cpps_socket_httpserver.h"
#include "cpps_socket_httpserver_request.h"
#include "cpps_socket_httpserver_session.h"
#include <openssl/ssl.h>
namespace cpps {
std::string cpps_getcwd();
std::string cpps_io_readfile(std::string filepath); bool cpps_io_file_exists(std::string path);
}
std::string cpps_socket_prasehtml2str2(cpps::C* c, int32 & __htmltextblockidx, cpps::object::vector &vec,std::string& __s, std::string& take, std::string& __html, size_t& pos, char startsep1, char startsep2, std::string endsep)
{
std::string ret;
char chr = __html[pos];
if (chr == startsep1)
{
char chr2 = __html[pos + 1];
if (chr2 == startsep2)
{
if (!take.empty()) {
vec.push_back(cpps::object::create(c, take));
char fmtstr[1024];
sprintf(fmtstr, "echo __htmltextblock[%d];\n", __htmltextblockidx);
__s += fmtstr;
++__htmltextblockidx;
take.clear();
}
size_t pos2 = __html.find(endsep, pos+2);
if (pos2 == std::string::npos) {
return ret;
}
pos += 2;
ret = __html.substr(pos, pos2 - pos);
pos = pos2 + 2;
}
}
return ret;
}
inline std::string& lTrim(std::string& ss)
{
std::string::iterator p = find_if(ss.begin(), ss.end(), [](char code) { return !isspace(code); });
ss.erase(ss.begin(), p);
return ss;
}
inline std::string& rTrim(std::string & ss)
{
std::string::reverse_iterator p = find_if(ss.rbegin(), ss.rend(), [](char code) { return !isspace(code); });
ss.erase(p.base(), ss.end());
return ss;
}
inline std::string& trim(std::string & st)
{
lTrim(rTrim(st));
return st;
}
std::string cpps_socket_prasehtml2str(cpps::C* c,cpps_socket_httpserver_request*request, std::string path, object __htmltextblock)
{
cpps::object::vector vct(__htmltextblock);
std::string __html = cpps_io_readfile(path);
std::string __s = "";
size_t pos = 0;
size_t size = __html.size();
int32 __htmltextblockidx = 0;
std::string take;
while (pos < size) {
char chr = __html[pos];
if (chr == '{') {
char chr2 = __html[pos+1];
if (chr2 == '{')
{
std::string r = cpps_socket_prasehtml2str2(c, __htmltextblockidx, vct, __s, take, __html, pos, '{', '{', "}}");
if (!r.empty()) {
__s += "echo ";
__s += r;
__s += ";\n";
continue;
}
}
else if (chr2 == '%')
{
std::string r = cpps_socket_prasehtml2str2(c, __htmltextblockidx, vct, __s, take, __html, pos, '{', '%', "%}");
if (!r.empty()) {
trim(r);
if (r[0] == '@')
{
if (r.find("@page(") == 0) {
size_t pos2 = r.rfind(')');
if (pos2 != std::string::npos) {
std::string path = cpps_getcwd() + "/" + r.substr(strlen("@page("), pos2 - strlen("@page("));
if (cpps_io_file_exists(path)) {
std::string content = cpps_io_readfile(path);
size += content.size();
__html.insert(pos, content);
}
}
}
else if (r.find("@csrf_token") == 0)
{
object csrftoken = (request && request->getsession()) ? request->getsession()->get("csrftoken",nil) : object();
std::string csrfmiddlewaretoken = "<input type='hidden' name='csrfmiddlewaretoken' value='" + csrftoken.tostring() + "' />";
size += csrfmiddlewaretoken.size();
__html.insert(pos, csrfmiddlewaretoken);
}
}
else
__s += r;
continue;
}
}
}
++pos;
take.append(1, chr);
}
if (!take.empty())
{
vct.push_back(cpps::object::create(c, take));
char fmtstr[1024];
sprintf(fmtstr, "echo __htmltextblock[%d];\n", __htmltextblockidx);
__s += fmtstr;
++__htmltextblockidx;
take.clear();
}
return __s;
}
cpps_value cpps_ssl_ctx_new(C* c, std::string certificate_file, std::string privatekey_file)
{
cpps_create_class_var(CPPS_SSL_CTX, c, ret, _ctx);
_ctx->ctx = SSL_CTX_new(TLSv1_2_server_method());
if (_ctx->ctx == NULL) {
return cpps::nil;
}
/* 载入用户的数字证书, 此证书用来发送给客户端。 证书里包含有公钥 */
if (SSL_CTX_use_certificate_file(_ctx->ctx, certificate_file.c_str(), SSL_FILETYPE_PEM) <= 0) {
return cpps::nil;
}
/* 载入用户私钥 */
if (SSL_CTX_use_PrivateKey_file(_ctx->ctx, privatekey_file.c_str(), SSL_FILETYPE_PEM) <= 0) {
return cpps::nil;
}
/* 检查用户私钥是否正确 */
if (!SSL_CTX_check_private_key(_ctx->ctx)) {
return cpps::nil;
}
return ret;
}
cpps_export_void cpps_attach(cpps::C* c)
{
#ifdef _WIN32
WSADATA wsadata;
WSAStartup(0x0202, &wsadata);
#endif
cpps::cpps_init_cpps_class(c);
cpps::_module(c,"socket")[
def_inside("prasehtml2str",cpps_socket_prasehtml2str),
def_inside("SSL_CTX_NEW", cpps_ssl_ctx_new),
_class<CPPS_SSL_CTX>("SSL_CTX")
.def("release",&CPPS_SSL_CTX::release),
_class<cpps_socket_server>("server")
.def("setoption", &cpps_socket_server::setoption)
.def_inside("listen", &cpps_socket_server::listen)
.def("run", &cpps_socket_server::run)
.def("send", &cpps_socket_server::send)
.def("closesocket", &cpps_socket_server::closesocket)
.def("stop", &cpps_socket_server::stop)
.def("isrunning", &cpps_socket_server::isrunning)
.def("get_send_count", &cpps_socket_server::get_send_count)
.def("get_write_count", &cpps_socket_server::get_write_count)
.def("get_recv_count", &cpps_socket_server::get_recv_count),
_class<cpps_socket_httpserver>("httpserver")
.def("setoption", &cpps_socket_httpserver::setoption)
.def_inside("listen", &cpps_socket_httpserver::listen)
.def("add_type", &cpps_socket_httpserver::add_type)
.def("get_type", &cpps_socket_httpserver::get_type)
.def("run", &cpps_socket_httpserver::run)
.def("register_handlefunc", &cpps_socket_httpserver::register_handlefunc)
.def("register_controller", &cpps_socket_httpserver::register_controller)
.def("stop", &cpps_socket_httpserver::stop)
.def("close", &cpps_socket_httpserver::closesocket)
.def("closesocket", &cpps_socket_httpserver::closesocket)
.def("shutdown", &cpps_socket_httpserver::shutdown)
.def("isrunning", &cpps_socket_httpserver::isrunning)
.def("get_send_count", &cpps_socket_server::get_send_count)
.def("get_write_count", &cpps_socket_server::get_write_count)
.def("get_request", &cpps_socket_httpserver::get_request)
.def("get_recv_count", &cpps_socket_server::get_recv_count),
_class<cpps_socket_client>("client")
.def("setoption", &cpps_socket_client::setoption)
.def("run", &cpps_socket_client::run)
.def_inside("connect", &cpps_socket_client::connect)
.def("send", &cpps_socket_client::send)
.def("isconnect", &cpps_socket_client::isconnect)
.def("closesocket", &cpps_socket_client::closesocket)
.def("close", &cpps_socket_client::closesocket)
.def("setuserdata", &cpps_socket_client::setuserdata)
.def("getuserdata", &cpps_socket_client::getuserdata)
.def("get_send_count", &cpps_socket_client::get_send_count)
.def("get_write_count", &cpps_socket_client::get_write_count)
.def("get_recv_count", &cpps_socket_client::get_recv_count),
_class< cpps_socket_httpserver_request>("httprequest")
.def("addheader", &cpps_socket_httpserver_request::addheader)
.def("append", &cpps_socket_httpserver_request::append)
.def("send", &cpps_socket_httpserver_request::send)
.def("getparam", &cpps_socket_httpserver_request::getparam)
.def("get", &cpps_socket_httpserver_request::get)
.def("post", &cpps_socket_httpserver_request::post)
.def("getheader", &cpps_socket_httpserver_request::getheader)
.def("geturi", &cpps_socket_httpserver_request::geturi)
.def("getpath", &cpps_socket_httpserver_request::getpath)
.def("getbuffer", &cpps_socket_httpserver_request::getbuffer)
.def("setcookie", &cpps_socket_httpserver_request::setcookie)
.def("getcookie", &cpps_socket_httpserver_request::getcookie)
.def("createsession", &cpps_socket_httpserver_request::createsession)
.def("getfiledata", &cpps_socket_httpserver_request::getfiledata)
.def_inside("paramslist", &cpps_socket_httpserver_request::paramslistfunc)
.def_inside("getlist", &cpps_socket_httpserver_request::getlistfunc)
.def_inside("postlist", &cpps_socket_httpserver_request::postlistfunc)
.def("send_header", &cpps_socket_httpserver_request::send_header)
.def("send_body", &cpps_socket_httpserver_request::send_body)
.def("getheaderdata", &cpps_socket_httpserver_request::getheaderdata)
.def("getmethod", &cpps_socket_httpserver_request::getmethod)
.def_inside("getheaders", &cpps_socket_httpserver_request::getheaders)
.def("session", &cpps_socket_httpserver_request::getsession)
.def("close", &cpps_socket_httpserver_request::close)
.def("getsocketindex", &cpps_socket_httpserver_request::getsocketindex)
.def("get_ip_address", &cpps_socket_httpserver_request::get_ip_address)
.def("get_port", &cpps_socket_httpserver_request::get_port)
.def("shutdown", &cpps_socket_httpserver_request::shutdown),
_class< cpps_socket_httpserver_request_filedata>("filedata")
.def("name", &cpps_socket_httpserver_request_filedata::name)
.def("filename", &cpps_socket_httpserver_request_filedata::filename)
.def("content_type", &cpps_socket_httpserver_request_filedata::content_type)
.def("getfilesize", &cpps_socket_httpserver_request_filedata::getfilesize)
.def("getbuffer", &cpps_socket_httpserver_request_filedata::buffer),
_class< cpps_socket_httpserver_session>("httpsession")
.def("get",&cpps_socket_httpserver_session::get)
.def("set",&cpps_socket_httpserver_session::set)
.def("clear",&cpps_socket_httpserver_session::clear)
.def("remove",&cpps_socket_httpserver_session::remove)
];
}
cpps_export_void cpps_detach(cpps::C * c)
{
cpps::_unmodule(c, "socket");
#ifdef _WIN32
WSACleanup();
#endif
}
cpps_export_finish
Loading...
Report
Report success
We will send you the feedback within 2 working days through the letter!
Please fill in the reason for the report carefully. Provide as detailed a description as possible.
Please select a report type
Cancel
Send
误判申诉

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

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

取消
提交

About

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

Releases (3)

All

The Open Source Evaluation Index is derived from the OSS Compass evaluation system, which evaluates projects around the following three dimensions

1. Open source ecosystem

  • Productivity: To evaluate the ability of open-source projects to output software artifacts and open-source value.
  • Innovation: Used to evaluate the degree of diversity of open source software and its ecosystem.
  • Robustness: Used to evaluate the ability of open-source projects to resist internal and external interference and self recover in the face of changing development environments.

2. Collaboration, People, Software

  • Collaboration: represents the degree and depth of collaboration in open source development behavior.
  • Observe the influence of core personnel in open source projects, and examine the evaluations of users and developers on open source projects from a third-party perspective.
  • Software: Evaluate the value of products exported from open-source projects and their ultimate destination. It is also a concrete manifestation of "open source software", one of the oldest mainstream directions in open source evaluation.

3. Evaluation model

    Based on the dimensions of "open source ecosystem" and "collaboration, people, and software", identify quantifiable indicators directly or indirectly related to this goal, quantitatively evaluate the health and ecology of open source projects, and ultimately form an open source evaluation index.

Contributors

All

Activities

can not load any more
Edit
About
Homepage
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/cppscript/cpps.git
git@gitee.com:cppscript/cpps.git
cppscript
cpps
cpps
master
Going to Help Center

Search

Comment
Repository Report
Back to the top
Login prompt
This operation requires login to the code cloud account. Please log in before operating.
Go to login
No account. Register

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