-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcsaori_base.h
134 lines (101 loc) · 3.11 KB
/
csaori_base.h
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
/*
* csaori_base.h
*/
#pragma once
#pragma warning(disable : 4786)
#define SAORIAPI extern "C" __declspec(dllexport)
#define SAORICDECL __cdecl
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <string>
#include <vector>
#include <map>
#include <sstream>
#include "csaori_util.h"
//SAORI INTERFACES
SAORIAPI BOOL SAORICDECL load(HGLOBAL h,long len);
SAORIAPI BOOL SAORICDECL unload();
SAORIAPI HGLOBAL SAORICDECL request(HGLOBAL h,long* len);
//DLLMain
BOOL APIENTRY DllMain( HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved);
extern HINSTANCE g_hModule;
typedef enum {
SAORIRESULT_FORCE_OK=0,
SAORIRESULT_OK=200,
SAORIRESULT_NO_CONTENT=204,
SAORIRESULT_BAD_REQUEST=400,
SAORIRESULT_INTERNAL_SERVER_ERROR=500
} SAORIRESULT;
//Classes
class CSAORIBase;
typedef std::map<string_t,string_t> map_strpair;
typedef std::vector<string_t> vector_str;
class CSAORIInput{
private:
const CSAORIBase &base;
CSAORIInput(void); //DUMMY
public:
CSAORIInput(const CSAORIBase &b) : base(b) {
}
unsigned int codepage;
string_t cmd;
string_t id;
vector_str args;
map_strpair opts;
bool parseString(const string_t &src);
};
class CSAORIOutput{
private:
const CSAORIBase &base;
CSAORIOutput(void); //DUMMY
public:
CSAORIOutput(const CSAORIBase &b) : base(b) {
}
unsigned int codepage;
SAORIRESULT result_code;
string_t result;
vector_str values;
map_strpair opts;
string_t toString();
void setResultEmpty();
bool parseString(const string_t &src);
};
class CSAORIBase {
public:
CSAORIBase() : module_handle(NULL) , call_id(0) {
setlocale( LC_ALL, "Japanese");
}
virtual ~CSAORIBase() {
; //NOOP
}
private:
string_t module_path;
HANDLE module_handle;
unsigned int call_id;
public:
//Internal Functions
void setModulePath(const std::string &str,bool isUTF8);
void setModuleHandle(HANDLE hMod);
const string_t& getModulePath(void) const { return module_path; }
HANDLE getModuleHandle(void) { return module_handle; }
std::string request(const std::string &req);
//Check relative path and convert to full path
std::string checkAndModifyPath(const std::string &path);
string_t checkAndModifyPathW(const string_t &path);
//exec call unique id
unsigned int getLastCallID() { return call_id; }
//Interface specific constant string functions to override
virtual const string_t& s_saori_version(void) const = 0;
virtual const string_t& s_saori_def(void) const = 0;
virtual const string_t& s_saori_argument(void) const = 0;
virtual const string_t& s_saori_value(void) const = 0;
virtual const string_t& s_saori_result(void) const = 0;
//Prologue / Epilogue
virtual void exec_before(const CSAORIInput& in,CSAORIOutput& out) { }
virtual void exec_after(const CSAORIInput& in,CSAORIOutput& out) { }
//Public functions to implement.
virtual void exec(const CSAORIInput& in,CSAORIOutput& out) = 0;
virtual bool exec_insecure(const CSAORIInput& in,CSAORIOutput& out) { return false; } //SecLevel Remote : Optional
virtual bool unload() = 0;
virtual bool load() = 0;
};