Author: ruschein
Date: 2011-09-20 16:23:18 -0700 (Tue, 20 Sep 2011)
New Revision: 26903
Added:
csplugins/trunk/ucsd/ruschein/GSFS/progs/GsSessionTest.cc
Modified:
csplugins/trunk/ucsd/ruschein/GSFS/progs/GsSession.cc
csplugins/trunk/ucsd/ruschein/GSFS/progs/GsSession.h
csplugins/trunk/ucsd/ruschein/GSFS/progs/Makefile
Log:
Work in progress.
Modified: csplugins/trunk/ucsd/ruschein/GSFS/progs/GsSession.cc
===================================================================
--- csplugins/trunk/ucsd/ruschein/GSFS/progs/GsSession.cc 2011-09-20
23:10:08 UTC (rev 26902)
+++ csplugins/trunk/ucsd/ruschein/GSFS/progs/GsSession.cc 2011-09-20
23:23:18 UTC (rev 26903)
@@ -1,23 +1,40 @@
#include "GsSession.h"
+#include <Downloader.h>
+#include <IniFile.h>
+#include <MiscUtil.h>
+#include <UrlUtil.h>
GsSession::GsSession(): isInitialised_(false) {
+ initialise();
}
-GsSession::GsSession(const std::string &token): isInitialised_(false) {
- token_ = token;
+namespace {
+
+
+std::string GetToken() {
+ const IniFile iniFile(MiscUtil::GetEnv("HOME") + "/etc/GSIdentity.ini");
+ const std::string identityServerUrl = iniFile.getString("",
"server_url");
+ const std::string username = UrlUtil::UrlEncode(iniFile.getString("",
"username"));
+ const std::string password = UrlUtil::UrlEncode(iniFile.getString("",
"password"));
+ const char * const colonSlashSlash =
std::strstr(identityServerUrl.c_str(), "://");
+ if (!colonSlashSlash)
+ throw std::runtime_error("identity server URL does not contain
\"://\"!");
+ const ptrdiff_t prefixLength = colonSlashSlash -
identityServerUrl.c_str() + 3;
+ const std::string authUrl = identityServerUrl.substr(0, prefixLength) +
username + ":" + password
+ + "@" +
identityServerUrl.substr(prefixLength);
+ Downloader downloader(authUrl);
+ if (downloader.anErrorOccurred())
+ throw std::runtime_error("authentication server error: " +
downloader.getLastErrorMessage());
+ return downloader.getMessageBody();
}
-bool GsSession::login(const std::string &/*username*/, const std::string
&/*password*/) {
- if (!isInitialised_)
- initialise();
+} // unnamed namespace
- return true;
-}
-
void GsSession::initialise() {
+ token_ = GetToken();
isInitialised_ = true;
}
Modified: csplugins/trunk/ucsd/ruschein/GSFS/progs/GsSession.h
===================================================================
--- csplugins/trunk/ucsd/ruschein/GSFS/progs/GsSession.h 2011-09-20
23:10:08 UTC (rev 26902)
+++ csplugins/trunk/ucsd/ruschein/GSFS/progs/GsSession.h 2011-09-20
23:23:18 UTC (rev 26903)
@@ -14,17 +14,10 @@
bool isInitialised_;
- std::string identityServiceUrl_;
std::string dataManagerServiceUrl_;
public:
- /**
- * Basic constructor uses the default URL for the Identity Service.
- */
GsSession();
-
- GsSession(const std::string &token);
-
- bool login(const std::string &username, const std::string &password);
+ inline const std::string getSessionToken() { return token_; }
private:
void initialise();
};
Added: csplugins/trunk/ucsd/ruschein/GSFS/progs/GsSessionTest.cc
===================================================================
--- csplugins/trunk/ucsd/ruschein/GSFS/progs/GsSessionTest.cc
(rev 0)
+++ csplugins/trunk/ucsd/ruschein/GSFS/progs/GsSessionTest.cc 2011-09-20
23:23:18 UTC (rev 26903)
@@ -0,0 +1,9 @@
+#include <iostream>
+#include <stdexcept>
+#include "GsSession.h"
+
+
+int main() {
+ GsSession session;
+ std::cout << "Session token = " << session.getSessionToken() << '\n';
+}
Modified: csplugins/trunk/ucsd/ruschein/GSFS/progs/Makefile
===================================================================
--- csplugins/trunk/ucsd/ruschein/GSFS/progs/Makefile 2011-09-20 23:10:08 UTC
(rev 26902)
+++ csplugins/trunk/ucsd/ruschein/GSFS/progs/Makefile 2011-09-20 23:23:18 UTC
(rev 26903)
@@ -1,7 +1,7 @@
CXX = g++-mp-4.4
CXXFLAGS = -W -Wall -Werror -I../include
LIBS = -lcurl -lpcre -lssl -lcrypto -L/opt/local/lib -lmagic -lz -L
../lib -liViaCoreSubset
-PROGS = FetchPage GSAuth
+PROGS = FetchPage GSAuth GsSessionTest
all: $(PROGS)
@@ -21,5 +21,11 @@
GsSession.o: GsSession.cc GsSession.h
$(CXX) $(CXXFLAGS) -I. -c $<
+GsSessionTest.o: GsSessionTest.cc GsSession.h
+ $(CXX) $(CXXFLAGS) -I. -c $<
+
+GsSessionTest: GsSessionTest.o GsSession.o
+ $(CXX) -o $@ $^ $(LIBS)
+
clean:
rm -f *.o *~ $(PROGS)
--
You received this message because you are subscribed to the Google Groups
"cytoscape-cvs" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/cytoscape-cvs?hl=en.