/************** tabrest C++ Program Source Code File (.CPP) ************/ /* PROGRAM NAME: tabrest Version 2.1 */ /* (C) Copyright to the author Olivier BERTRAND 2018 - 2021 */ /* This program is the REST Web API support for MariaDB. */ /* The way Connect handles NOSQL data returned by REST queries is */ /* just by retrieving it as a file and then leave the existing data */ /* type tables (JSON, XML or CSV) process it as usual. */ /***********************************************************************/
/***********************************************************************/ /* Definitions needed by the included files. */ /***********************************************************************/ #include <my_global.h> // All MariaDB stuff #include <mysqld.h> #include <mysqld_error.h> #include <sql_error.h> #if !defined(_WIN32) && !defined(_WINDOWS) #include <sys/types.h> #include <sys/wait.h> #endif// !_WIN32 && !_WINDOWS
/***********************************************************************/ /* Include application header files: */ /* global.h is header containing all global declarations. */ /* plgdbsem.h is header containing the DB application declarations. */ /***********************************************************************/ #include"global.h" #include"plgdbsem.h" #include"xtable.h" #include"filamtxt.h" #include"tabdos.h" #include"plgxml.h" #ifdefined(XML_SUPPORT) #include"tabxml.h" #endif// XML_SUPPORT #include"tabjson.h" #include"tabfmt.h" #include"tabrest.h"
if (pID == 0) { // Code executed by child process
execlp("curl", "curl", fn, "--", buf, (char*)NULL);
// If execlp() is successful, we should not reach this next line.
strcpy(g->Message, "Unsuccessful execlp from vfork()"); exit(1);
} elseif (pID < 0) { // failed to fork
strcpy(g->Message, "Failed to fork");
rc = 1;
} else { // Parent process
wait(NULL); // Wait for the child to terminate
} // endif pID #endif// !_WIN32
return rc;
} // end of Xcurl
/***********************************************************************/ /* GetREST: load the Rest lib and get the Rest function. */ /***********************************************************************/
XGETREST GetRestFunction(PGLOBAL g)
{ if (getRestFnc) return getRestFnc;
#if !defined(REST_SOURCE) if (trace(515))
htrc("Looking for GetRest library\n");
// Get the function returning an instance of the external DEF class if (!(getRestFnc = (XGETREST)GetProcAddress((HINSTANCE)Hdll, "restGetFile"))) { char buf[256];
DWORD rc = GetLastError();
strcat(strcpy(filename, tab), ".");
n = strlen(filename);
// Fold ftype to lower case for (int i = 0; i < m; i++)
filename[n + i] = tolower(ftype[i]);
fn = filename;
tp->subtype = PlugDup(g, fn);
snprintf(g->Message, sizeof(g->Message), "No file name. Table will use %s", fn);
PUSH_WARNING(g->Message);
} // endif fn
// We used the file name relative to recorded datapath
PlugSetPath(filename, fn, db);
remove(filename);
// Retrieve the file from the web and copy it locally if (curl)
rc = Xcurl(g, http, uri, filename); else
rc = grf(g->Message, trace(515), http, uri, filename);
// We used the file name relative to recorded datapath
PlugSetPath(filename, Fn, GetPath());
remove(filename);
// Retrieve the file from the web and copy it locally if (curl) {
rc = Xcurl(g, Http, Uri, filename);
xtrc(515, "Return from Xcurl: rc=%d\n", rc);
} else {
rc = grf(g->Message, xt, Http, Uri, filename);
xtrc(515, "Return from restGetFile: rc=%d\n", rc);
} // endelse
if (rc) { // strcpy(g->Message, "Cannot access to curl nor casablanca"); returntrue;
} elseswitch (n) { case1: Tdp = new (g) JSONDEF; break; #ifdefined(XML_SUPPORT) case2: Tdp = new (g) XMLDEF; break; #endif// XML_SUPPORT case3: Tdp = new (g) CSVDEF; break; default: Tdp = NULL;
} // endswitch n
// Do make the table/view definition if (Tdp && Tdp->Define(g, Cat, Name, Schema, "REST"))
Tdp = NULL; // Error occurred
if (xt)
htrc("Tdp defined\n", rc);
// Return true in case of error return (Tdp == NULL);
} // end of DefineAM
/***********************************************************************/ /* GetTable: makes a new Table Description Block. */ /***********************************************************************/
PTDB RESTDEF::GetTable(PGLOBAL g, MODE m)
{ if (trace(515))
htrc("REST GetTable mode=%d\n", m);
if (m != MODE_READ && m != MODE_READX && m != MODE_ANY) {
strcpy(g->Message, "REST tables are currently read only"); return NULL;
} // endif m
return Tdp->GetTable(g, m); // Leave file type do the job
} // end of GetTable
/* ---------------------- End of Class RESTDEF ----------------------- */
Messung V0.5 in Prozent
¤ Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.0.0Bemerkung:
(vorverarbeitet am 2026-10-08)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.