Commit ff174423 authored by Ruben Jesus Garcia Hernandez's avatar Ruben Jesus Garcia Hernandez
Browse files

Add http authentification using token.

Explicitly disable pagination
Add missing files to openvr project
parent ed9e6db9
...@@ -52,6 +52,7 @@ const char * loadConfigFileErrors[] = ...@@ -52,6 +52,7 @@ const char * loadConfigFileErrors[] =
"No basis vectors, but repetitions requested", //-13 "No basis vectors, but repetitions requested", //-13
"Error loading config file",// -14 "Error loading config file",// -14
"Error reading atomglyph", //-15 "Error reading atomglyph", //-15
"Error reading token", //-16
"Error loading xyz file, add 100 to see the error",//<-100 "Error loading xyz file, add 100 to see the error",//<-100
"Error loading cube file, add 100 to see the error",//<-200 "Error loading cube file, add 100 to see the error",//<-200
"Error loading json file, add 200 to see the error",//<-300 "Error loading json file, add 200 to see the error",//<-300
...@@ -67,9 +68,9 @@ else ...@@ -67,9 +68,9 @@ else
int readString(FILE *f, char *s) int readString(FILE *f, char *s)
{ {
char s2[100]; char s2[2048];
int r, c; int r, c;
r = fscanf(f, "%99s", s2); r = fscanf(f, "%2047s", s2);
if (r!=1) if (r!=1)
return -1; return -1;
if (s2[0]!='"') { if (s2[0]!='"') {
...@@ -135,6 +136,7 @@ int loadConfigFile(const char * f) ...@@ -135,6 +136,7 @@ int loadConfigFile(const char * f)
for (int i=0;i<3;i++) for (int i=0;i<3;i++)
userpos[i] = 0; userpos[i] = 0;
solid=0; solid=0;
char *token=0;
// //
FILE *F = fopen(f, "r"); FILE *F = fopen(f, "r");
if (F == 0) if (F == 0)
...@@ -312,7 +314,7 @@ int loadConfigFile(const char * f) ...@@ -312,7 +314,7 @@ int loadConfigFile(const char * f)
sprintf (url, "%s%s", base_url, material); sprintf (url, "%s%s", base_url, material);
//rgh fixme, we know only one //rgh fixme, we know only one
eprintf ("load config file start, before readAtomsJsonURL"); eprintf ("load config file start, before readAtomsJsonURL");
e = readAtomsJsonURL (url, &numAtoms, &timesteps, &atoms, abc, &clonedAtoms); e = readAtomsJsonURL (url, &numAtoms, &timesteps, &atoms, abc, &clonedAtoms, token);
eprintf ("load config file start, after readAtomsJsonURL"); eprintf ("load config file start, after readAtomsJsonURL");
if (e<0) if (e<0)
return e-300; return e-300;
...@@ -348,6 +350,13 @@ int loadConfigFile(const char * f) ...@@ -348,6 +350,13 @@ int loadConfigFile(const char * f)
solid=new Solid(Solid::Type::Tetrahedron); solid=new Solid(Solid::Type::Tetrahedron);
else else
return -15; return -15;
} else if (!strcmp (s, "token")) {
if (token)
delete (token);
token=new char [2048];
r=readString (F, token);
if (r!=0)
return -16;
} else if (!strcmp (s, "\x0d")) { //discard windows newline (problem in Sebastian Kokott's phone (?!) } else if (!strcmp (s, "\x0d")) { //discard windows newline (problem in Sebastian Kokott's phone (?!)
continue; continue;
} else { } else {
......
...@@ -312,7 +312,7 @@ const char * readAtomsJsonErrors[] = { ...@@ -312,7 +312,7 @@ const char * readAtomsJsonErrors[] = {
}; };
int readAtomsJsonURL (const char *const f, int **numatoms, int *timesteps, float ***pos, float abc[3][3], int readAtomsJsonURL (const char *const f, int **numatoms, int *timesteps, float ***pos, float abc[3][3],
std::vector<float>** clonedAtoms) std::vector<float>** clonedAtoms, const char *const token)
{ {
eprintf ("readAtomsJsonURL start"); eprintf ("readAtomsJsonURL start");
...@@ -327,12 +327,12 @@ if (r==1) ...@@ -327,12 +327,12 @@ if (r==1)
if (r<2) { if (r<2) {
#if defined(WIN32) #if defined(WIN32)
//possibly https or other unsupported protocol, fall back to wget //possibly https or other unsupported protocol, fall back to wget
return readAtomsJsonURLwget (f, numatoms, timesteps, pos, abc, clonedAtoms); return readAtomsJsonURLwget (f, numatoms, timesteps, pos, abc, clonedAtoms, token);
#else #else
return -3; return -3;
#endif #endif
} }
sprintf (url, "%s%s", page, "/cells"); sprintf (url, "%s%s", page, "/cells?pagination=off");
sprintf (file, "%s%s", TMPDIR, "material_cells.json"); sprintf (file, "%s%s", TMPDIR, "material_cells.json");
out=fopen(file , "w"); out=fopen(file , "w");
if (out==nullptr) { if (out==nullptr) {
...@@ -341,13 +341,27 @@ if (out==nullptr) { ...@@ -341,13 +341,27 @@ if (out==nullptr) {
} }
happyhttp::Connection conn( host, port ); happyhttp::Connection conn( host, port );
conn.setcallbacks( nullptr, OnData, nullptr, 0 ); conn.setcallbacks( nullptr, OnData, nullptr, 0 );
conn.request( "GET", url, 0, 0,0 );
//https://github.com/Zintinio/HappyHTTP/issues/9
const char*headers[3];
char base64[2048];
if (token) {
headers[0]="Authorization";
sprintf (base64, "Basic %s", token);
headers[1]=base64;
headers[2]=0;
conn.request( "GET", url, headers, 0,0 );
} else {
conn.request( "GET", url, 0, 0,0 );
}
while( conn.outstanding() ) while( conn.outstanding() )
conn.pump(); conn.pump();
fclose(out); fclose(out);
conn.close(); conn.close();
sprintf (url, "%s%s", page, "/elements"); sprintf (url, "%s%s", page, "/elements?pagination=off");
sprintf (file, "%s%s", TMPDIR, "material_elements.json"); sprintf (file, "%s%s", TMPDIR, "material_elements.json");
out=fopen(file , "w"); out=fopen(file , "w");
...@@ -355,7 +369,13 @@ if (out==nullptr) { ...@@ -355,7 +369,13 @@ if (out==nullptr) {
eprintf ("Could not open file for writing: %s", file); eprintf ("Could not open file for writing: %s", file);
return -1; return -1;
} }
conn.request( "GET", url, 0, 0,0 );
if (token) {
conn.request( "GET", url, headers, 0,0 );
} else {
conn.request( "GET", url, 0, 0,0 );
}
while( conn.outstanding() ) while( conn.outstanding() )
conn.pump(); conn.pump();
} catch (const happyhttp::Wobbly& w) { } catch (const happyhttp::Wobbly& w) {
...@@ -366,6 +386,10 @@ while( conn.outstanding() ) ...@@ -366,6 +386,10 @@ while( conn.outstanding() )
eprintf( "error %s\n", w.what()); eprintf( "error %s\n", w.what());
#endif #endif
fclose(out); fclose(out);
#if defined(WIN32)
return readAtomsJsonURLwget (f, numatoms, timesteps, pos, abc, clonedAtoms, token);
#endif
return -3; return -3;
} }
fclose(out); fclose(out);
...@@ -376,23 +400,31 @@ fclose(out); ...@@ -376,23 +400,31 @@ fclose(out);
char file [2048]; char file [2048];
sprintf (file, "%s%s", TMPDIR, "material"); sprintf (file, "%s%s", TMPDIR, "material");
eprintf ("readAtomsJsonURL before return"); eprintf ("readAtomsJsonURL before return");
return readAtomsJson (file, numatoms, timesteps, pos, abc, clonedAtoms); return readAtomsJson (file, numatoms, timesteps, pos, abc, clonedAtoms, token);
} }
#if defined(WIN32) #if defined(WIN32)
//base64 encoded token
int readAtomsJsonURLwget (const char *const f, int **numatoms, int *timesteps, float ***pos, float abc[3][3], int readAtomsJsonURLwget (const char *const f, int **numatoms, int *timesteps, float ***pos, float abc[3][3],
std::vector<float>** clonedAtoms) std::vector<float>** clonedAtoms, const char *const token)
{ {
char cmd[2048]; char cmd[2048];
int ret; int ret;
sprintf (cmd, "wget %s/cells -O material_cells.json", f); if (token)
sprintf (cmd, "wget --header \"Authorization:Basic %s\" %s/cells?pagination=off -O material_cells.json", token, f);
else
sprintf (cmd, "wget %s/cells?pagination=off -O material_cells.json", f);
ret=system(cmd); ret=system(cmd);
if (ret!=0) if (ret!=0)
return (-3); return (-3);
sprintf (cmd, "wget %s/elements -O material_elements.json", f); if (token)
sprintf (cmd, "wget --header \"Authorization:Basic %s\" %s/elements?pagination=off -O material_elements.json", token, f);
else
sprintf (cmd, "wget %s/elements?pagination=off -O material_elements.json", f);
ret=system(cmd); ret=system(cmd);
if (ret!=0)
return(-3); return(-3);
return readAtomsJson ("material", numatoms, timesteps, pos, abc, clonedAtoms); return readAtomsJson ("material", numatoms, timesteps, pos, abc, clonedAtoms, token);
} }
#endif #endif
...@@ -410,7 +442,7 @@ void add (std::vector<float> *v, float x, float y, float z, float a) ...@@ -410,7 +442,7 @@ void add (std::vector<float> *v, float x, float y, float z, float a)
} }
int readAtomsJson (const char *const f, int **numatoms, int *timesteps, float ***pos, float abc[3][3], int readAtomsJson (const char *const f, int **numatoms, int *timesteps, float ***pos, float abc[3][3],
std::vector<float>** clonedAtoms) std::vector<float>** clonedAtoms, const char *const token)
{ {
eprintf ("readAtomsJson start"); eprintf ("readAtomsJson start");
char file[512]; char file[512];
......
...@@ -15,10 +15,10 @@ extern const char * TMPDIR; ...@@ -15,10 +15,10 @@ extern const char * TMPDIR;
int readAtomsXYZ(const char *const file, int **numatoms, int *timesteps, float ***pos); int readAtomsXYZ(const char *const file, int **numatoms, int *timesteps, float ***pos);
int readAtomsCube(const char *const file, int **numatoms, int *timesteps, float ***pos); int readAtomsCube(const char *const file, int **numatoms, int *timesteps, float ***pos);
int readAtomsJson (const char *const file, int **numatoms, int *timesteps, float ***pos, float abc[3][3], std::vector<float>** clonedAtoms); int readAtomsJson (const char *const file, int **numatoms, int *timesteps, float ***pos, float abc[3][3], std::vector<float>** clonedAtoms, const char *const token=0);
int readAtomsJsonURL (const char *const f, int **numatoms, int *timesteps, float ***pos, float abc[3][3], std::vector<float>** clonedAtoms); int readAtomsJsonURL (const char *const f, int **numatoms, int *timesteps, float ***pos, float abc[3][3], std::vector<float>** clonedAtoms, const char *const token=0);
#if defined(WIN32) #if defined(WIN32)
int readAtomsJsonURLwget (const char *const f, int **numatoms, int *timesteps, float ***pos, float abc[3][3], std::vector<float>** clonedAtoms); int readAtomsJsonURLwget (const char *const f, int **numatoms, int *timesteps, float ***pos, float abc[3][3], std::vector<float>** clonedAtoms, const char *const token=0);
#endif #endif
const float MISSINGRADIUS=0.2f; const float MISSINGRADIUS=0.2f;
const float MISSINGR=1.f; const float MISSINGR=1.f;
......
...@@ -178,6 +178,7 @@ ...@@ -178,6 +178,7 @@
<ClCompile Include="NOMADVRLib\atomsGL.cpp" /> <ClCompile Include="NOMADVRLib\atomsGL.cpp" />
<ClCompile Include="NOMADVRLib\CompileGLShader.cpp" /> <ClCompile Include="NOMADVRLib\CompileGLShader.cpp" />
<ClCompile Include="NOMADVRLib\ConfigFile.cpp" /> <ClCompile Include="NOMADVRLib\ConfigFile.cpp" />
<ClCompile Include="NOMADVRLib\IsoShaders.cpp" />
<ClCompile Include="NOMADVRLib\IsosurfacesGL.cpp" /> <ClCompile Include="NOMADVRLib\IsosurfacesGL.cpp" />
<ClCompile Include="NOMADVRLib\polyhedron.cpp" /> <ClCompile Include="NOMADVRLib\polyhedron.cpp" />
<ClCompile Include="NOMADVRLib\TessShaders.cpp" /> <ClCompile Include="NOMADVRLib\TessShaders.cpp" />
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment