-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathLibSettings.c
118 lines (91 loc) · 3.12 KB
/
LibSettings.c
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
#include "defines.h"
#include "includes.h"
#include "Vars.h"
#include "libUseful.h"
#include <sys/mman.h>
/* These functions provide an interface for setting variables that */
/* are used by libUseful itself */
int LibUsefulFlags=0;
static ListNode *LibUsefulSettings=NULL;
ListNode *LibUsefulValuesGetHead()
{
return(LibUsefulSettings);
}
void LibUsefulInitSettings()
{
char *Tempstr=NULL;
LibUsefulSettings=ListCreate(LIST_FLAG_CACHE);
SetVar(LibUsefulSettings, "LibUseful:Version", __LIBUSEFUL_VERSION__);
Tempstr=MCopyStr(Tempstr, __LIBUSEFUL_BUILD_DATE__, " ", __LIBUSEFUL_BUILD_TIME__, NULL);
SetVar(LibUsefulSettings, "LibUseful:BuildTime", Tempstr);
#ifdef USE_LGPL
SetVar(LibUsefulSettings, "LibUseful:License", "LGPLv3");
#else
SetVar(LibUsefulSettings, "LibUseful:License", "GPLv3");
#endif
Tempstr=FormatStr(Tempstr, "%d", 4096 * 10000);
SetVar(LibUsefulSettings, "MaxDocumentSize", Tempstr);
Tempstr=FormatStr(Tempstr, "%d", 4096 * 10000);
SetVar(LibUsefulSettings, "WEBSOCKET:MaxFrameSize", Tempstr);
DestroyString(Tempstr);
}
void LibUsefulSetHTTPFlag(int Flag, const char *Value)
{
int Flags;
if (strtobool(Value)) Flags=HTTPGetFlags() | Flag;
else Flags=HTTPGetFlags() & ~Flag;
HTTPSetFlags(Flags);
}
void LibUsefulSetValue(const char *Name, const char *Value)
{
if (! LibUsefulSettings) LibUsefulInitSettings();
if (strcasecmp(Name,"HTTP:Debug")==0) LibUsefulSetHTTPFlag(HTTP_DEBUG, Value);
if (strcasecmp(Name,"HTTP:NoCookies")==0) LibUsefulSetHTTPFlag(HTTP_NOCOOKIES, Value);
if (strcasecmp(Name,"HTTP:NoCompress")==0) LibUsefulSetHTTPFlag(HTTP_NOCOMPRESS, Value);
if (strcasecmp(Name,"HTTP:NoCompression")==0) LibUsefulSetHTTPFlag(HTTP_NOCOMPRESS, Value);
if (strcasecmp(Name,"HTTP:NoRedirect")==0) LibUsefulSetHTTPFlag(HTTP_NOREDIRECT, Value);
if (strcasecmp(Name,"HTTP:NoCache")==0) LibUsefulSetHTTPFlag(HTTP_NOCACHE, Value);
if (strcasecmp(Name,"StrLenCache")==0)
{
if (! strtobool(Value)) LibUsefulFlags |= LU_STRLEN_NOCACHE;
else LibUsefulFlags &= ~LU_STRLEN_NOCACHE;
}
SetVar(LibUsefulSettings,Name,Value);
}
const char *LibUsefulGetValue(const char *Name)
{
if (! LibUsefulSettings) LibUsefulInitSettings();
if (!StrValid(Name)) return("");
return(GetVar(LibUsefulSettings,Name));
}
int LibUsefulGetBool(const char *Name)
{
return(strtobool(LibUsefulGetValue(Name)));
}
int LibUsefulGetInteger(const char *Name)
{
const char *ptr;
ptr=LibUsefulGetValue(Name);
if (StrValid(ptr)) return(atoi(ptr));
return(0);
}
int LibUsefulDebugActive()
{
if (StrValid(getenv("LIBUSEFUL_DEBUG"))) return(TRUE);
if (LibUsefulGetBool("libUseful:Debug")) return(TRUE);
return(FALSE);
}
void LibUsefulAtExit()
{
#ifdef HAVE_MUNLOCKALL
if (LibUsefulFlags & LU_MLOCKALL) munlockall();
#endif
if (LibUsefulFlags & LU_CONTAINER) FileSystemUnMount("/","lazy");
ConnectionHopCloseAll();
CredsStoreDestroy();
}
void LibUsefulSetupAtExit()
{
if (! (LibUsefulFlags & LU_ATEXIT_REGISTERED)) atexit(LibUsefulAtExit);
LibUsefulFlags |= LU_ATEXIT_REGISTERED;
}