Commit 20241a33a7a9dbcdc8e45576870c62b328bf1cbb
1 parent
7aa6f7bc
Implement find_hub() and hashub() methods.
The find_hub() method searches for a Hub and retrieves the relevant tokens. So far, no GammaLib own Hub is started if no Hub has been found. The hashub() method checks if all mandatory Hub tokens have a value. No value check is done.
Showing
2 changed files
with
102 additions
and
3 deletions
include/GVOClient.hpp
src/vo/GVOClient.cpp
| ... | ... | @@ -56,6 +56,9 @@ GVOClient::GVOClient(void) |
| 56 | 56 | // Initialise members |
| 57 | 57 | init_members(); |
| 58 | 58 | |
| 59 | + // Find Hub | |
| 60 | + find_hub(); | |
| 61 | + | |
| 59 | 62 | // Return |
| 60 | 63 | return; |
| 61 | 64 | } |
| ... | ... | @@ -188,6 +191,20 @@ void GVOClient::disconnect(void) |
| 188 | 191 | |
| 189 | 192 | |
| 190 | 193 | /***********************************************************************//** |
| 194 | + * @brief Signals if client has Hub information | |
| 195 | + * | |
| 196 | + * @return True if client has Hub information, false otherwise. | |
| 197 | + * | |
| 198 | + * Checks if all mandatory Hub tokens are non-empty. | |
| 199 | + ***************************************************************************/ | |
| 200 | +bool GVOClient::hashub(void) const | |
| 201 | +{ | |
| 202 | + // Return Hub information status | |
| 203 | + return (!m_secret.empty() && !m_hub_url.empty() && !m_version.empty()); | |
| 204 | +} | |
| 205 | + | |
| 206 | + | |
| 207 | +/***********************************************************************//** | |
| 191 | 208 | * @brief Print VO client information |
| 192 | 209 | * |
| 193 | 210 | * @return String containing VO client information |
| ... | ... | @@ -204,7 +221,7 @@ std::string GVOClient::print(void) const |
| 204 | 221 | result.append("\n"+parformat("Hub key")+m_secret); |
| 205 | 222 | result.append("\n"+parformat("Hub URL")+m_hub_url); |
| 206 | 223 | result.append("\n"+parformat("SAMP protocal version")+m_version); |
| 207 | - result.append("\n"+parformat("Client key")+m_version); | |
| 224 | + result.append("\n"+parformat("Client key")+m_client_key); | |
| 208 | 225 | |
| 209 | 226 | // Return result |
| 210 | 227 | return result; |
| ... | ... | @@ -263,11 +280,92 @@ void GVOClient::free_members(void) |
| 263 | 280 | |
| 264 | 281 | /***********************************************************************//** |
| 265 | 282 | * @brief Find SAMP Hub |
| 283 | + * | |
| 284 | + * @return True of SAMP Hub has been found, false otherwise. | |
| 285 | + * | |
| 286 | + * Search a valid SAMP Hub and retrieve all mandatory token for this Hub. | |
| 287 | + * The manadtory tokens are | |
| 288 | + * | |
| 289 | + * samp.secret Opaque text string required for Hub registration | |
| 290 | + * samp.hub.xmlrpc.url XML-RPC endpoint for communication | |
| 291 | + * samp.profile.version Version of SAMP profile | |
| 292 | + * | |
| 293 | + * Implements IVOA standard REC-SAMP-1.3-20120411. | |
| 294 | + * | |
| 295 | + * @todo If no valid Hub was found the method should attempt to start its | |
| 296 | + * own Hub. | |
| 266 | 297 | ***************************************************************************/ |
| 267 | 298 | bool GVOClient::find_hub(void) |
| 268 | 299 | { |
| 269 | - // Return | |
| 270 | - return false; | |
| 300 | + // Allocate line buffer | |
| 301 | + const int n = 1000; | |
| 302 | + char line[n]; | |
| 303 | + | |
| 304 | + // Initialise find flag to false | |
| 305 | + bool found = false; | |
| 306 | + | |
| 307 | + // Get lockfile URL | |
| 308 | + std::string lockurl = hub_lockfile(); | |
| 309 | + | |
| 310 | + // Continue only if a URL has been found | |
| 311 | + if (!lockurl.empty()) { | |
| 312 | + | |
| 313 | + // If we have a file:// prefix then strip it now. This is a kluge | |
| 314 | + // and should be remplaced by a method that allows opening any kind | |
| 315 | + // of URL | |
| 316 | + if (lockurl.compare(0, 7, "file://") == 0) { | |
| 317 | + lockurl = lockurl.substr(7, std::string::npos); | |
| 318 | + } | |
| 319 | + | |
| 320 | + // Open SAMP lockfile. Continue only if opening was successful | |
| 321 | + FILE* fptr = fopen(lockurl.c_str(), "r"); | |
| 322 | + if (fptr != NULL) { | |
| 323 | + | |
| 324 | + // Parse lockfile and search for mandatory tokens | |
| 325 | + while (fgets(line, n, fptr) != NULL) { | |
| 326 | + | |
| 327 | + // Convert line to C++ string | |
| 328 | + std::string cline = std::string(line); | |
| 329 | + | |
| 330 | + // Check for secret key | |
| 331 | + if (cline.compare(0, 12, "samp.secret=") == 0) { | |
| 332 | + m_secret = strip_chars(cline.substr(12, std::string::npos), "\r\n"); | |
| 333 | + } | |
| 334 | + | |
| 335 | + // Check for Hub URL | |
| 336 | + else if (cline.compare(0, 20, "samp.hub.xmlrpc.url=") == 0) { | |
| 337 | + m_hub_url = strip_chars(cline.substr(20, std::string::npos), "\r\n"); | |
| 338 | + } | |
| 339 | + | |
| 340 | + // Check for profile version | |
| 341 | + else if (cline.compare(0, 21, "samp.profile.version=") == 0) { | |
| 342 | + m_version = strip_chars(cline.substr(21, std::string::npos), "\r\n"); | |
| 343 | + } | |
| 344 | + | |
| 345 | + } | |
| 346 | + | |
| 347 | + // Close SAMP lockfile | |
| 348 | + fclose(fptr); | |
| 349 | + | |
| 350 | + // Check for existence of mandatory tokens | |
| 351 | + found = hashub(); | |
| 352 | + } | |
| 353 | + | |
| 354 | + } // endif: URL has been found | |
| 355 | + | |
| 356 | + //TODO: Create GammaLib own Hub in case that no Hub has been found | |
| 357 | + //if (!found) { | |
| 358 | + //} | |
| 359 | + | |
| 360 | + // If no Hub has been found, clear all Hub related members | |
| 361 | + if (!found) { | |
| 362 | + m_secret.clear(); | |
| 363 | + m_hub_url.clear(); | |
| 364 | + m_version.clear(); | |
| 365 | + } | |
| 366 | + | |
| 367 | + // Return find flag | |
| 368 | + return found; | |
| 271 | 369 | } |
| 272 | 370 | |
| 273 | 371 | ... | ... |