Skip to content

Commit 87c4da1

Browse files
committed
jsonopen fix
1 parent f5ed07e commit 87c4da1

File tree

5 files changed

+31
-38
lines changed

5 files changed

+31
-38
lines changed

SRC/common.h

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,18 +34,7 @@ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
3434
#define NOMAIN 1
3535
#endif
3636

37-
#ifdef LOEBNER
38-
#define DISCARDSERVER 1
39-
#define DISCARDTCPOPEN 1
40-
#define DISCARDMYSQL 1
41-
#define DISCARDPOSTGRES 1
42-
#define DISCARDMONGO 1
43-
#define DISCARDCOUNTER 1
44-
#define DISCARDCLIENT 1
45-
#define DISCARDJSONOPEN 1
46-
#define DISCARDJAVASCRIPT 1
47-
48-
#elif WIN32
37+
#ifdef WIN32
4938
//#define USERPATHPREFIX 1
5039

5140
#elif IOS

SRC/evserver.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,9 @@ int fork_child(ev_child *child_watcher = 0)
303303

304304
// child
305305
ev_loop_fork(l_g);
306+
#ifndef DISCARDJSONOPEN
306307
CurlShutdown();
308+
#endif
307309
for (int i = 0; i < cur_children_g; i++) ev_child_stop(l_g, &children_g[i]);
308310
cur_children_g = 0;
309311
parent_g = false;

SRC/json.cpp

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -512,6 +512,29 @@ static int my_trace(CURL *handle, curl_infotype type, char *data, size_t size, v
512512
return 0;
513513
}
514514

515+
FunctionResult InitCurl()
516+
{
517+
// Get curl ready -- do this ONCE only during run of CS
518+
if (!curl_done_init) {
519+
#ifdef WIN32
520+
if (InitWinsock() == FAILRULE_BIT) // only init winsock one per any use- we might have done this from TCPOPEN or PGCode
521+
{
522+
ReportBug((char*)"Winsock init failed");
523+
return FAILRULE_BIT;
524+
}
525+
#endif
526+
curl_global_init(CURL_GLOBAL_SSL);
527+
curl_done_init = true;
528+
}
529+
return NOPROBLEM_BIT;
530+
}
531+
532+
void CurlShutdown()
533+
{
534+
if (curl_done_init) curl_global_cleanup();
535+
curl_done_init = false;
536+
}
537+
515538
// This is the function we pass to LC, which writes the output to a BufferStruct
516539
static size_t CurlWriteMemoryCallback(void *ptr, size_t size, size_t nmemb, void *data) {
517540
size_t realsize = size * nmemb;
@@ -532,29 +555,6 @@ static size_t CurlWriteMemoryCallback(void *ptr, size_t size, size_t nmemb, void
532555
return realsize;
533556
}
534557

535-
void CurlShutdown()
536-
{
537-
if (curl_done_init) curl_global_cleanup ();
538-
curl_done_init = false;
539-
}
540-
541-
FunctionResult InitCurl()
542-
{
543-
// Get curl ready -- do this ONCE only during run of CS
544-
if (!curl_done_init) {
545-
#ifdef WIN32
546-
if (InitWinsock() == FAILRULE_BIT) // only init winsock one per any use- we might have done this from TCPOPEN or PGCode
547-
{
548-
ReportBug((char*)"Winsock init failed");
549-
return FAILRULE_BIT;
550-
}
551-
#endif
552-
curl_global_init(CURL_GLOBAL_SSL);
553-
curl_done_init = true;
554-
}
555-
return NOPROBLEM_BIT;
556-
}
557-
558558
char* UrlEncodePiece(char* input)
559559
{
560560
InitCurl();

SRC/json.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,18 +36,18 @@ FunctionResult JSONDeleteCode(char* buffer);
3636
FunctionResult JSONCopyCode(char* buffer);
3737
FunctionResult JSONCreateCode(char* buffer);
3838
FunctionResult JSONReadCSVCode(char* buffer);
39-
FunctionResult InitCurl();
4039
MEANING GetUniqueJsonComposite(char* prefix);
4140
MEANING jsonValue(char* value, unsigned int& flags);
4241
void JsonRenumber(FACT* F);
4342
void jkillfact(WORDP D);
4443
void InitJSONNames();
4544
char* jwrite(char* buffer, WORDP D, int subject);
45+
FunctionResult InitCurl();
46+
void CurlShutdown();
4647

4748
#ifndef DISCARDJSONOPEN
4849
char* UrlEncodePiece(char* input);
4950
FunctionResult JSONOpenCode(char* buffer);
50-
void CurlShutdown();
5151
#endif
5252

5353
#endif

SRC/mainSystem.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -819,7 +819,8 @@ static size_t ConfigCallback(void *contents, size_t size, size_t nmemb, void *us
819819
}
820820

821821
static void LoadconfigFromUrl(char*configUrl, char**configUrlHeaders, int headerCount){
822-
InitCurl();
822+
#ifndef DISCARDJSONOPEN
823+
InitCurl();
823824
CURL *req = curl_easy_init();
824825
string response_string;
825826
curl_easy_setopt(req, CURLOPT_CUSTOMREQUEST, "GET");
@@ -855,6 +856,7 @@ static void LoadconfigFromUrl(char*configUrl, char**configUrlHeaders, int header
855856
curl_easy_cleanup(req);
856857
CurlShutdown();
857858
ProcessConfigLines();
859+
#endif
858860
}
859861

860862
static void ReadConfig()

0 commit comments

Comments
 (0)