Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
MariaDB
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexedi
MariaDB
Commits
8c617e99
Commit
8c617e99
authored
Nov 11, 2020
by
Olivier Bertrand
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add getting REST query answer via curl. modified storage/connect/tabrest.cpp
parent
878065b4
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
68 additions
and
17 deletions
+68
-17
storage/connect/tabrest.cpp
storage/connect/tabrest.cpp
+68
-17
No files found.
storage/connect/tabrest.cpp
View file @
8c617e99
...
@@ -42,7 +42,13 @@
...
@@ -42,7 +42,13 @@
#include "tabfmt.h"
#include "tabfmt.h"
#include "tabrest.h"
#include "tabrest.h"
#if defined(__WIN__) || defined(_WINDOWS)
#define popen _popen
#define pclose _pclose
#endif
static
XGETREST
getRestFnc
=
NULL
;
static
XGETREST
getRestFnc
=
NULL
;
static
int
Xcurl
(
PGLOBAL
g
,
PCSZ
Http
,
PCSZ
Uri
,
PCSZ
filename
);
#if !defined(MARIADB)
#if !defined(MARIADB)
/***********************************************************************/
/***********************************************************************/
...
@@ -71,6 +77,40 @@ PTABDEF __stdcall GetREST(PGLOBAL g, void *memp)
...
@@ -71,6 +77,40 @@ PTABDEF __stdcall GetREST(PGLOBAL g, void *memp)
}
// end of GetREST
}
// end of GetREST
#endif // !MARIADB
#endif // !MARIADB
/***********************************************************************/
/* Xcurl: retrieve the REST answer by executing curl. */
/***********************************************************************/
int
Xcurl
(
PGLOBAL
g
,
PCSZ
Http
,
PCSZ
Uri
,
PCSZ
filename
)
{
char
buf
[
1024
];
int
rc
;
FILE
*
pipe
;
if
(
Uri
)
{
if
(
*
Uri
==
'/'
||
Http
[
strlen
(
Http
)
-
1
]
==
'/'
)
sprintf
(
buf
,
"curl %s%s > %s"
,
Http
,
Uri
,
filename
);
else
sprintf
(
buf
,
"curl %s/%s > %s"
,
Http
,
Uri
,
filename
);
}
else
sprintf
(
buf
,
"curl %s > %s"
,
Http
,
filename
);
if
((
pipe
=
popen
(
buf
,
"rt"
)))
{
if
(
trace
(
515
))
while
(
fgets
(
buf
,
sizeof
(
buf
),
pipe
))
{
htrc
(
"%s"
,
buf
);
}
// endwhile
pclose
(
pipe
);
rc
=
0
;
}
else
{
sprintf
(
g
->
Message
,
"curl failed, errno =%d"
,
errno
);
rc
=
1
;
}
// endif pipe
return
rc
;
}
// end od Xcurl
/***********************************************************************/
/***********************************************************************/
/* GetREST: get the external TABDEF from OEM module. */
/* GetREST: get the external TABDEF from OEM module. */
/***********************************************************************/
/***********************************************************************/
...
@@ -148,13 +188,15 @@ PQRYRES RESTColumns(PGLOBAL g, PTOS tp, char *tab, char *db, bool info)
...
@@ -148,13 +188,15 @@ PQRYRES RESTColumns(PGLOBAL g, PTOS tp, char *tab, char *db, bool info)
PQRYRES
__stdcall
ColREST
(
PGLOBAL
g
,
PTOS
tp
,
char
*
tab
,
char
*
db
,
bool
info
)
PQRYRES
__stdcall
ColREST
(
PGLOBAL
g
,
PTOS
tp
,
char
*
tab
,
char
*
db
,
bool
info
)
#endif // !MARIADB
#endif // !MARIADB
{
{
PQRYRES
qrp
=
NULL
;
PQRYRES
qrp
=
NULL
;
char
filename
[
_MAX_PATH
+
1
];
// MAX PATH ???
char
filename
[
_MAX_PATH
+
1
];
// MAX PATH ???
PCSZ
http
,
uri
,
fn
,
ftype
;
int
rc
;
bool
curl
=
false
;
PCSZ
http
,
uri
,
fn
,
ftype
;
XGETREST
grf
=
GetRestFunction
(
g
);
XGETREST
grf
=
GetRestFunction
(
g
);
if
(
!
grf
)
if
(
!
grf
)
return
NULL
;
curl
=
true
;
http
=
GetStringTableOption
(
g
,
tp
,
"Http"
,
NULL
);
http
=
GetStringTableOption
(
g
,
tp
,
"Http"
,
NULL
);
uri
=
GetStringTableOption
(
g
,
tp
,
"Uri"
,
NULL
);
uri
=
GetStringTableOption
(
g
,
tp
,
"Uri"
,
NULL
);
...
@@ -182,13 +224,17 @@ PQRYRES __stdcall ColREST(PGLOBAL g, PTOS tp, char *tab, char *db, bool info)
...
@@ -182,13 +224,17 @@ PQRYRES __stdcall ColREST(PGLOBAL g, PTOS tp, char *tab, char *db, bool info)
// We used the file name relative to recorded datapath
// We used the file name relative to recorded datapath
PlugSetPath
(
filename
,
fn
,
db
);
PlugSetPath
(
filename
,
fn
,
db
);
//strcat(strcat(strcat(strcpy(filename, "."), slash), db), slash);
curl
=
GetBooleanTableOption
(
g
,
tp
,
"Curl"
,
curl
);
//strncat(filename, fn, _MAX_PATH - strlen(filename));
// Retrieve the file from the web and copy it locally
// Retrieve the file from the web and copy it locally
if
(
http
&&
grf
(
g
->
Message
,
trace
(
515
),
http
,
uri
,
filename
))
{
if
(
curl
)
// sprintf(g->Message, "Failed to get file at %s", http);
rc
=
Xcurl
(
g
,
http
,
uri
,
filename
);
}
else
if
(
!
stricmp
(
ftype
,
"JSON"
))
else
rc
=
grf
(
g
->
Message
,
trace
(
515
),
http
,
uri
,
filename
);
if
(
rc
)
return
NULL
;
else
if
(
!
stricmp
(
ftype
,
"JSON"
))
qrp
=
JSONColumns
(
g
,
db
,
NULL
,
tp
,
info
);
qrp
=
JSONColumns
(
g
,
db
,
NULL
,
tp
,
info
);
else
if
(
!
stricmp
(
ftype
,
"CSV"
))
else
if
(
!
stricmp
(
ftype
,
"CSV"
))
qrp
=
CSVColumns
(
g
,
NULL
,
tp
,
info
);
qrp
=
CSVColumns
(
g
,
NULL
,
tp
,
info
);
...
@@ -209,14 +255,14 @@ PQRYRES __stdcall ColREST(PGLOBAL g, PTOS tp, char *tab, char *db, bool info)
...
@@ -209,14 +255,14 @@ PQRYRES __stdcall ColREST(PGLOBAL g, PTOS tp, char *tab, char *db, bool info)
/***********************************************************************/
/***********************************************************************/
bool
RESTDEF
::
DefineAM
(
PGLOBAL
g
,
LPCSTR
am
,
int
poff
)
bool
RESTDEF
::
DefineAM
(
PGLOBAL
g
,
LPCSTR
am
,
int
poff
)
{
{
char
filename
[
_MAX_PATH
+
1
];
char
filename
[
_MAX_PATH
+
1
];
int
rc
=
0
,
n
;
int
rc
=
0
,
n
;
bool
xt
=
trace
(
515
);
bool
curl
=
false
,
xt
=
trace
(
515
);
LPCSTR
ftype
;
LPCSTR
ftype
;
XGETREST
grf
=
GetRestFunction
(
g
);
XGETREST
grf
=
GetRestFunction
(
g
);
if
(
!
grf
)
if
(
!
grf
)
return
true
;
curl
=
true
;
#if defined(MARIADB)
#if defined(MARIADB)
ftype
=
GetStringCatInfo
(
g
,
"Type"
,
"JSON"
);
ftype
=
GetStringCatInfo
(
g
,
"Type"
,
"JSON"
);
...
@@ -235,8 +281,8 @@ bool RESTDEF::DefineAM(PGLOBAL g, LPCSTR am, int poff)
...
@@ -235,8 +281,8 @@ bool RESTDEF::DefineAM(PGLOBAL g, LPCSTR am, int poff)
:
(
!
stricmp
(
ftype
,
"CSV"
))
?
3
:
0
;
:
(
!
stricmp
(
ftype
,
"CSV"
))
?
3
:
0
;
if
(
n
==
0
)
{
if
(
n
==
0
)
{
htrc
(
"DefineAM: Unsupported REST table type %s
"
,
am
);
htrc
(
"DefineAM: Unsupported REST table type %s
\n
"
,
ftype
);
sprintf
(
g
->
Message
,
"Unsupported REST table type %s"
,
am
);
sprintf
(
g
->
Message
,
"Unsupported REST table type %s"
,
ftype
);
return
true
;
return
true
;
}
// endif n
}
// endif n
...
@@ -247,8 +293,13 @@ bool RESTDEF::DefineAM(PGLOBAL g, LPCSTR am, int poff)
...
@@ -247,8 +293,13 @@ bool RESTDEF::DefineAM(PGLOBAL g, LPCSTR am, int poff)
// We used the file name relative to recorded datapath
// We used the file name relative to recorded datapath
PlugSetPath
(
filename
,
Fn
,
GetPath
());
PlugSetPath
(
filename
,
Fn
,
GetPath
());
curl
=
GetBoolCatInfo
(
"Curl"
,
curl
);
// Retrieve the file from the web and copy it locally
// Retrieve the file from the web and copy it locally
rc
=
grf
(
g
->
Message
,
xt
,
Http
,
Uri
,
filename
);
if
(
curl
)
rc
=
Xcurl
(
g
,
Http
,
Uri
,
filename
);
else
rc
=
grf
(
g
->
Message
,
xt
,
Http
,
Uri
,
filename
);
if
(
xt
)
if
(
xt
)
htrc
(
"Return from restGetFile: rc=%d
\n
"
,
rc
);
htrc
(
"Return from restGetFile: rc=%d
\n
"
,
rc
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment