Commit 92ad08f8310c78c55d49e1b48052a04c9c286f4c
1 parent
997f99d7
After correcting Hub request answers (ping from list to Map)
Showing
1 changed file
with
53 additions
and
20 deletions
src/vo/GVOHub.cpp
| ... | ... | @@ -196,9 +196,24 @@ void GVOHub::ping_service(const socklen_t& sock) |
| 196 | 196 | std::string msg = ""; |
| 197 | 197 | |
| 198 | 198 | // Set methodResponse elts |
| 199 | - msg.append("<?xml version=\"1.0\"?>\n"); | |
| 199 | + /*msg.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"); | |
| 200 | + msg.append("<methodResponse>\n"); | |
| 201 | + msg.append("\t<params>\n"); | |
| 202 | + msg.append("\t\t<param>\n\t\t\t<value/>\n\t\t</param>\n"); | |
| 203 | + msg.append("\t</params>\n"); | |
| 204 | + msg.append("</methodResponse>\n");*/ | |
| 205 | + | |
| 206 | + //Following Aladin return, ping should answer a map and not a list... here is the map in return. | |
| 207 | + msg.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"); | |
| 200 | 208 | msg.append("<methodResponse>\n"); |
| 209 | + msg.append("\t<params>\n"); | |
| 210 | + msg.append("\t\t<param>\n\t\t\t<value>\n\t\t\t\t<struct>\n"); | |
| 211 | + //msg.append("\t\t\t\t\t<member>\n\t\t\t\t\t\t<name></name>\n\t\t\t\t\t\t<value></value>\n\t\t\t\t\t</member>\n"); | |
| 212 | + msg.append("\t\t\t\t\t<member>\n\t\t\t\t\t\t<name>samp.status</name>\n\t\t\t\t\t\t<value>samp.ok</value>\n\t\t\t\t\t</member>\n"); | |
| 213 | + msg.append("\t\t\t\t</struct>\n\t\t\t</value>\n\t\t</param>\n"); | |
| 214 | + msg.append("\t</params>\n"); | |
| 201 | 215 | msg.append("</methodResponse>\n"); |
| 216 | + | |
| 202 | 217 | int length = msg.length(); |
| 203 | 218 | |
| 204 | 219 | int n = write(sock,msg.c_str(),length); |
| ... | ... | @@ -208,6 +223,7 @@ void GVOHub::ping_service(const socklen_t& sock) |
| 208 | 223 | throw GException::invalid_value(G_HANDLE_REQUEST, msg); |
| 209 | 224 | } |
| 210 | 225 | |
| 226 | + printf(msg.c_str()); | |
| 211 | 227 | printf("Response message sent\n"); |
| 212 | 228 | //Return |
| 213 | 229 | return; |
| ... | ... | @@ -225,7 +241,7 @@ void GVOHub::register_service(const GXml& xml, const socklen_t& sock) |
| 225 | 241 | |
| 226 | 242 | // Declare message |
| 227 | 243 | std::string msg = ""; |
| 228 | - char buffer[124]; | |
| 244 | + char selfid[124]; | |
| 229 | 245 | char privatekey[124]; |
| 230 | 246 | char cl_id[256]; |
| 231 | 247 | int i; |
| ... | ... | @@ -233,12 +249,10 @@ void GVOHub::register_service(const GXml& xml, const socklen_t& sock) |
| 233 | 249 | std::string translator = "http://localhost:8001/"; |
| 234 | 250 | printf("Message composition\n"); |
| 235 | 251 | |
| 236 | - FILE* fptr = fopen("SAMP-registered.txt", "w"); | |
| 252 | + FILE* fptr = fopen("SAMP-registered.txt", "a"); | |
| 237 | 253 | if (fptr != NULL) { |
| 238 | - | |
| 239 | 254 | // If successfull writes application definition |
| 240 | - fputs ("# SAMP registered applications and Methods \n",fptr); | |
| 241 | - sprintf(cl_id,"Registered client-key:%d\n", m_nb_clients); | |
| 255 | + sprintf(cl_id,"Registered client-key:%d\n", m_nb_clients); | |
| 242 | 256 | fputs (cl_id,fptr); |
| 243 | 257 | } |
| 244 | 258 | |
| ... | ... | @@ -246,21 +260,19 @@ void GVOHub::register_service(const GXml& xml, const socklen_t& sock) |
| 246 | 260 | fclose(fptr); |
| 247 | 261 | |
| 248 | 262 | printf("Message composition 2 \n"); |
| 249 | - sprintf(buffer,"<member><name>samp.self-id</name><value><string>client-id:%d</string></value></member>\n",m_nb_clients); | |
| 250 | - sprintf(privatekey,"<member><name>samp.private-key</name><value><string>client-key:%d</string></value></member>\n",m_nb_clients); | |
| 251 | - printf(buffer); | |
| 263 | + sprintf(selfid,"<member><name>samp.self-id</name><value>c%d</value></member>\n",m_nb_clients); | |
| 264 | + sprintf(privatekey,"<member><name>samp.private-key</name><value>%s</value></member>\n",m_secret.c_str()); | |
| 252 | 265 | m_nb_clients ++; |
| 253 | 266 | |
| 254 | 267 | // Set methodResponse elts |
| 255 | - msg.append("<?xml version=\"1.0\"?>\n"); | |
| 268 | + msg.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"); | |
| 256 | 269 | msg.append("<methodResponse>\n"); |
| 257 | 270 | msg.append("\t<params>\n"); |
| 258 | 271 | msg.append("\t\t<param>\n\t\t\t<value>\n\t\t\t\t<struct>\n"); |
| 259 | - //msg.append("<member><name>samp.private-key</name><value><string>client-key:" + m_hub_id + "</string></value></member>\n"); | |
| 272 | + msg.append("<member><name>samp.hub-id</name><value>" + m_hub_id + "</value></member>\n"); | |
| 273 | + msg.append(selfid); | |
| 260 | 274 | msg.append(privatekey); |
| 261 | - msg.append("<member><name>samp.hub-id</name><value><string>client-id:" + m_hub_id + "</string></value></member>\n"); | |
| 262 | - msg.append(buffer); | |
| 263 | - msg.append("<member><name>samp.url-translator</name><value><string>" + translator + "</string></value></member>\n"); | |
| 275 | + msg.append("<member><name>samp.url-translator</name><value>" + translator + "</value></member>\n"); | |
| 264 | 276 | msg.append("</struct></value></param>\n"); |
| 265 | 277 | msg.append("</params>\n"); |
| 266 | 278 | msg.append("</methodResponse>\n"); |
| ... | ... | @@ -356,7 +368,7 @@ void GVOHub::register_metadata(const GXml& xml,const socklen_t& sock) |
| 356 | 368 | //The hub response to Metadata declaration has no usefull content and can be discarded by the client. |
| 357 | 369 | // Set methodResponse elts |
| 358 | 370 | msg.append("<?xml version=\"1.0\"?>\n"); |
| 359 | - msg.append("<methodResponse>\n"); | |
| 371 | + msg.append("<methodResponse><params><param><value/></param></params>\n"); | |
| 360 | 372 | msg.append("</methodResponse>\n"); |
| 361 | 373 | |
| 362 | 374 | int length = msg.length(); |
| ... | ... | @@ -445,20 +457,31 @@ void GVOHub::get_registered_clients(const GXml& xml,const socklen_t& sock) |
| 445 | 457 | |
| 446 | 458 | //The hub response to rpc callback declaration has no usefull content and can be discarded by the client. |
| 447 | 459 | // Set methodResponse elts |
| 448 | - msg.append("<?xml version=\"1.0\"?>\n"); | |
| 460 | + msg.append("<?xml version=\'1.0\' encoding=\"UTF-8\"?>\n"); | |
| 449 | 461 | msg.append("<methodResponse>\n"); |
| 462 | + msg.append("\t<params>\n"); | |
| 463 | + msg.append("\t\t<param>\n\t\t\t<value>\n\t\t\t\t<array>\n\t\t\t\t\t<data>\n"); | |
| 464 | + //msg.append("\t\t\t\t\t\t<value>%s</value>\n",m_hub_id.c_str()); | |
| 465 | + msg.append("\t\t\t\t\t\t<value>c1</value>\n"); | |
| 466 | + msg.append("\t\t\t\t\t\t<value>c2</value>\n"); | |
| 467 | + //For each registered client insert <value>id of client (type cn n being client number)</value> | |
| 468 | + msg.append("\t\t\t\t\t</data>\n\t\t\t\t</array>\n\t\t\t</value>\n"); | |
| 469 | + msg.append("\t\t</param>\n"); | |
| 470 | + msg.append("\t</params>\n"); | |
| 450 | 471 | msg.append("</methodResponse>\n"); |
| 472 | + | |
| 451 | 473 | |
| 452 | - int length = msg.length(); | |
| 474 | + //int length = msg.length(); | |
| 453 | 475 | |
| 454 | - int n = write(sock,msg.c_str(),length); | |
| 476 | + int n = write(sock,msg.c_str(),msg.length()); | |
| 455 | 477 | if (n < 0) { |
| 456 | 478 | printf("Could not write socket buffer.\n"); |
| 457 | 479 | std::string msg = "Could not write socket buffer."; |
| 458 | 480 | throw GException::invalid_value(G_HANDLE_REQUEST, msg); |
| 459 | 481 | } |
| 460 | - | |
| 482 | + printf(msg.c_str()); | |
| 461 | 483 | printf("Response message sent\n"); |
| 484 | + | |
| 462 | 485 | //Return |
| 463 | 486 | return; |
| 464 | 487 | } |
| ... | ... | @@ -597,7 +620,7 @@ void GVOHub::init_members(void) |
| 597 | 620 | m_hub_port = "8001"; |
| 598 | 621 | m_version = "1.3"; |
| 599 | 622 | m_client_key.clear(); |
| 600 | - m_hub_id = "b79884e0"; | |
| 623 | + m_hub_id = "gammalib_hub"; | |
| 601 | 624 | //m_client_id.clear(); |
| 602 | 625 | m_socket = -1; // Signals no socket |
| 603 | 626 | m_nb_clients = 0; // No registered clients at initialization |
| ... | ... | @@ -681,6 +704,16 @@ void GVOHub::init_hub(void) |
| 681 | 704 | |
| 682 | 705 | // Close SAMP lockfile |
| 683 | 706 | fclose(fptr); |
| 707 | + | |
| 708 | + fptr = fopen("SAMP-registered.txt", "a"); | |
| 709 | + if (fptr != NULL) { | |
| 710 | + | |
| 711 | + // If successfull writes application definition | |
| 712 | + fputs ("# SAMP registered applications and Methods \n",fptr); | |
| 713 | + } | |
| 714 | + | |
| 715 | + // Closes file | |
| 716 | + fclose(fptr); | |
| 684 | 717 | |
| 685 | 718 | // Return |
| 686 | 719 | return; | ... | ... |