Skip to content

Commit

Permalink
crest-patch (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
nyood committed Jan 16, 2022
1 parent 3254444 commit eb35887
Show file tree
Hide file tree
Showing 388 changed files with 3,486 additions and 21,723 deletions.
54 changes: 54 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
git:
depth: 3

language: cpp
os: linux

env:
global:
- SOURCEMOD_VERSION=1.10-dev
- TARGET_ARCH=x86,x86_64

jobs:
include:
- name: "Linux clang"
compiler: clang
python: 3.8
os: linux
addons:
apt:
packages:
- g++-multilib
- lib32z1-dev

install:
- pip install --upgrade pip
- pip install setuptools
- git clone https://github.com/alliedmodders/sourcemod.git -b $SOURCEMOD_VERSION --depth 1 -j8 --recurse-submodules --shallow-submodules $TRAVIS_BUILD_DIR/../sourcemod
- bash $TRAVIS_BUILD_DIR/travis/checkout-deps

before_script:
- mkdir $TRAVIS_BUILD_DIR/build && cd $TRAVIS_BUILD_DIR/build

script:
- python ../configure.py --enable-optimize --targets=$TARGET_ARCH
- ambuild

before_deploy:
- cd $TRAVIS_BUILD_DIR/build/package
- zip -r crest-${TRAVIS_OS_NAME}-${TRAVIS_BUILD_NUMBER}.zip *
- mkdir $TRAVIS_BUILD_DIR/deploy
- cp $TRAVIS_BUILD_DIR/build/package/crest-${TRAVIS_OS_NAME}-${TRAVIS_BUILD_NUMBER}.zip $TRAVIS_BUILD_DIR/deploy

deploy:
provider: releases
token:
secure: IN4z91bO27nvEUuWbe05j4yhqGJjSX67PAc0T7MqxzFrXKRyA3nyUrEHO6b3gp70IedNXxbwqfoCxN+FZGStJeAyEULHkTzl7GC9hCIHv+HW+1R6ZGAxkf2PZFyHrW85TaJ8mK3MfzxlSEUGgJoZXMpMHS0KLHgzXgDGg2+bto3Ijc9hY7Bqc7iMZqJxUfhQ1mrJua75vrvG/fQ3Q1dIzQTUqejDK9rfdOOuEnqXP2WGwXlbsdyz/3J1V2QPTbZzm4hjxYAGX20nXElW6cngreOfciihZKRZOc57L3Tc5MKf30bRWBQXBQgAPycO9tGaDcW9LI2mYasaPwHCLwNjrvWeNisY8C/XfoY249eDcjDLFbXELljNIaIyKwMxV9X5vOI2ue24sqCzquSijJT5/N+X+eGA9GyfAVs6/FRDdkW7k7BauaFkQxQNy6j0dJFl3AZXJ6vWPu7r2MwyXblrSV65LxuMZEHGRZl/bTK/BoyrhyEqKtLLjwt+eIaArg2JaQAU09OHj5MDDd2koP9IEYowoJ86wdazuBVYYPos5EpS9ub1DAjHQL5HRytVM/0gmCN9PFrk2jvsB8n+C62molU2+bJSK4nbDBcdKio98y86t79MClqSB+SrEur6t+nre8/PiXWhiDMi8F67WsobAIXPXO1xcsalgect7IV6lJI=
file_glob: true
file: $TRAVIS_BUILD_DIR/deploy/*
skip_cleanup: true
on:
tags: true

notifications:
email: false
6 changes: 1 addition & 5 deletions AMBuilder
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@
import os

libcurl = builder.Build('curl/lib/AMBuilder')
libjansson = builder.Build('jansson/src/AMBuilder')
libmbedtls = builder.Build('mbedtls/library/AMBuilder')
libnghttp2 = builder.Build('nghttp2/lib/AMBuilder')
libuv = builder.Build('libuv/src/AMBuilder')
libz = builder.Build('zlib/AMBuilder')

for cxx in builder.targets:
binary = Extension.Library(builder, cxx, 'rip.ext')
binary = Extension.Library(builder, cxx, 'crest.ext')
arch = binary.compiler.target.arch

binary.sources += [
Expand All @@ -20,13 +19,11 @@ for cxx in builder.targets:
'httpfilecontext.cpp',
'httpformcontext.cpp',
'http_natives.cpp',
'json_natives.cpp',
os.path.join(Extension.sm_root, 'public', 'smsdk_ext.cpp'),
]

binary.compiler.includes += [
os.path.join(builder.sourcePath, 'curl', 'include'),
os.path.join(builder.sourcePath, 'jansson', 'include'),
os.path.join(builder.sourcePath, 'libuv', 'include'),
]

Expand All @@ -41,7 +38,6 @@ for cxx in builder.targets:

binary.compiler.postlink += [
libcurl[arch].binary,
libjansson[arch].binary,
libmbedtls[arch].binary,
libnghttp2[arch].binary,
libuv[arch].binary,
Expand Down
14 changes: 7 additions & 7 deletions PackageScript
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ builder.SetBuildFolder('package')
folder_list = [
'addons/sourcemod/extensions',
'addons/sourcemod/scripting/include',
'addons/sourcemod/scripting/include/ripext',
# 'addons/sourcemod/scripting/include/ripext',
#'addons/sourcemod/gamedata',
#'addons/sourcemod/configs',
'addons/sourcemod/configs/ripext',
'addons/sourcemod/configs/crest',
]

if 'x86_64' in Extension.target_archs:
Expand All @@ -37,11 +37,11 @@ def CopyFiles(src, dest, files):

# Include files
CopyFiles('pawn/scripting/include', 'addons/sourcemod/scripting/include',
[ 'ripext.inc' ]
)
CopyFiles('pawn/scripting/include/ripext', 'addons/sourcemod/scripting/include/ripext',
[ 'http.inc', 'json.inc' ]
[ 'crest.inc' ]
)
# CopyFiles('pawn/scripting/include/ripext', 'addons/sourcemod/scripting/include/ripext',
# [ 'http.inc' ]
# )

# GameData files
#CopyFiles('gamedata', 'addons/sourcemod/gamedata',
Expand All @@ -56,7 +56,7 @@ CopyFiles('pawn/scripting/include/ripext', 'addons/sourcemod/scripting/include/r
# 'otherconfig.cfg,
# ]
#)
CopyFiles(builder.buildPath, 'addons/sourcemod/configs/ripext',
CopyFiles('pawn/configs/crest', 'addons/sourcemod/configs/crest',
[ 'ca-bundle.crt' ]
)

Expand Down
38 changes: 6 additions & 32 deletions extension.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,6 @@ HandleType_t htHTTPRequest;
HTTPResponseHandler g_HTTPResponseHandler;
HandleType_t htHTTPResponse;

JSONHandler g_JSONHandler;
HandleType_t htJSON;

JSONObjectKeysHandler g_JSONObjectKeysHandler;
HandleType_t htJSONObjectKeys;

static void CheckCompletedRequests()
{
CURLMsg *message;
Expand Down Expand Up @@ -215,8 +209,7 @@ static void FrameHook(bool simulating)
bool RipExt::SDK_OnLoad(char *error, size_t maxlength, bool late)
{
sharesys->AddNatives(myself, http_natives);
sharesys->AddNatives(myself, json_natives);
sharesys->RegisterLibrary(myself, "ripext");
sharesys->RegisterLibrary(myself, "crest");

/* Initialize cURL */
CURLcode res = curl_global_init(CURL_GLOBAL_ALL);
Expand All @@ -243,17 +236,10 @@ bool RipExt::SDK_OnLoad(char *error, size_t maxlength, bool late)
haHTTPResponse.access[HandleAccess_Delete] = HANDLE_RESTRICT_IDENTITY;
haHTTPResponse.access[HandleAccess_Read] = HANDLE_RESTRICT_IDENTITY;

/* Set up access rights for the 'JSON' handle type */
HandleAccess haJSON;
haJSON.access[HandleAccess_Clone] = 0;
haJSON.access[HandleAccess_Delete] = 0;
haJSON.access[HandleAccess_Read] = 0;

htHTTPClient = handlesys->CreateType("HTTPClient", &g_HTTPClientHandler, 0, NULL, NULL, myself->GetIdentity(), NULL);
htHTTPRequest = handlesys->CreateType("HTTPRequest", &g_HTTPRequestHandler, 0, NULL, NULL, myself->GetIdentity(), NULL);
htHTTPResponse = handlesys->CreateType("HTTPResponse", &g_HTTPResponseHandler, 0, NULL, &haHTTPResponse, myself->GetIdentity(), NULL);
htJSON = handlesys->CreateType("JSON", &g_JSONHandler, 0, NULL, &haJSON, myself->GetIdentity(), NULL);
htJSONObjectKeys = handlesys->CreateType("JSONObjectKeys", &g_JSONObjectKeysHandler, 0, NULL, NULL, myself->GetIdentity(), NULL);
//
htHTTPClient = handlesys->CreateType("HTTP", &g_HTTPClientHandler, 0, NULL, NULL, myself->GetIdentity(), NULL);
htHTTPRequest = handlesys->CreateType("HTTPReq", &g_HTTPRequestHandler, 0, NULL, NULL, myself->GetIdentity(), NULL);
htHTTPResponse = handlesys->CreateType("HTTPRes", &g_HTTPResponseHandler, 0, NULL, &haHTTPResponse, myself->GetIdentity(), NULL);

smutils->AddGameFrameHook(&FrameHook);
smutils->BuildPath(Path_SM, caBundlePath, sizeof(caBundlePath), SM_RIPEXT_CA_BUNDLE_PATH);
Expand All @@ -273,8 +259,6 @@ void RipExt::SDK_OnUnload()
handlesys->RemoveType(htHTTPClient, myself->GetIdentity());
handlesys->RemoveType(htHTTPRequest, myself->GetIdentity());
handlesys->RemoveType(htHTTPResponse, myself->GetIdentity());
handlesys->RemoveType(htJSON, myself->GetIdentity());
handlesys->RemoveType(htJSONObjectKeys, myself->GetIdentity());

smutils->RemoveGameFrameHook(&FrameHook);
}
Expand All @@ -299,14 +283,4 @@ void HTTPRequestHandler::OnHandleDestroy(HandleType_t type, void *object)
void HTTPResponseHandler::OnHandleDestroy(HandleType_t type, void *object)
{
/* Response objects are automatically cleaned up */
}

void JSONHandler::OnHandleDestroy(HandleType_t type, void *object)
{
json_decref((json_t *)object);
}

void JSONObjectKeysHandler::OnHandleDestroy(HandleType_t type, void *object)
{
delete (struct JSONObjectKeys *)object;
}
}
44 changes: 3 additions & 41 deletions extension.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,14 @@

#include <string>
#include <curl/curl.h>
#include <jansson.h>
#include <sm_stringhashmap.h>
#include <stdlib.h>
#include <string.h>
#include <uv.h>
#include "smsdk_ext.h"

#define SM_RIPEXT_CA_BUNDLE_PATH "configs/ripext/ca-bundle.crt"
#define SM_RIPEXT_USER_AGENT "sm-ripext/" SMEXT_CONF_VERSION
#define SM_RIPEXT_CA_BUNDLE_PATH "configs/crest/ca-bundle.crt"
#define SM_RIPEXT_USER_AGENT "crest/" SMEXT_CONF_VERSION

extern uv_loop_t *g_Loop;

Expand Down Expand Up @@ -72,32 +71,14 @@ struct CurlContext {

struct HTTPResponse {
long status = 0;
json_t *data = NULL;
char *data = NULL;
Handle_t hndlData = BAD_HANDLE;
HTTPHeaderMap headers;

char *body = NULL;
size_t size = 0;
};

struct JSONObjectKeys {
JSONObjectKeys(json_t *object) : object(object), iter(json_object_iter(object)) {}

const char *GetKey()
{
return json_object_iter_key(iter);
}

void Next()
{
iter = json_object_iter_next(object, iter);
}

private:
json_t *object;
void *iter;
};


/**
* @brief Implementation of the REST in Pawn Extension.
Expand Down Expand Up @@ -197,18 +178,6 @@ class HTTPResponseHandler : public IHandleTypeDispatch
void OnHandleDestroy(HandleType_t type, void *object);
};

class JSONHandler : public IHandleTypeDispatch
{
public:
void OnHandleDestroy(HandleType_t type, void *object);
};

class JSONObjectKeysHandler : public IHandleTypeDispatch
{
public:
void OnHandleDestroy(HandleType_t type, void *object);
};

extern RipExt g_RipExt;

extern HTTPClientHandler g_HTTPClientHandler;
Expand All @@ -220,13 +189,6 @@ extern HandleType_t htHTTPRequest;
extern HTTPResponseHandler g_HTTPResponseHandler;
extern HandleType_t htHTTPResponse;

extern JSONHandler g_JSONHandler;
extern HandleType_t htJSON;

extern JSONObjectKeysHandler g_JSONObjectKeysHandler;
extern HandleType_t htJSONObjectKeys;

extern const sp_nativeinfo_t http_natives[];
extern const sp_nativeinfo_t json_natives[];

#endif // _INCLUDE_SOURCEMOD_EXTENSION_PROPER_H_
Loading

0 comments on commit eb35887

Please sign in to comment.