comparison Core/HttpServer/MongooseServer.cpp @ 59:c996319e90bc orthanc-renaming

renaming in Core
author Sebastien Jodogne <s.jodogne@gmail.com>
date Sun, 16 Sep 2012 09:28:56 +0200
parents a15e90e5d6fc
children a6e41de88a53
comparison
equal deleted inserted replaced
58:6da7fc87efaa 59:c996319e90bc
1 /** 1 /**
2 * Palanthir - A Lightweight, RESTful DICOM Store 2 * Orthanc - A Lightweight, RESTful DICOM Store
3 * Copyright (C) 2012 Medical Physics Department, CHU of Liege, 3 * Copyright (C) 2012 Medical Physics Department, CHU of Liege,
4 * Belgium 4 * Belgium
5 * 5 *
6 * This program is free software: you can redistribute it and/or 6 * This program is free software: you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as 7 * modify it under the terms of the GNU General Public License as
29 #include <iostream> 29 #include <iostream>
30 #include <string.h> 30 #include <string.h>
31 #include <stdio.h> 31 #include <stdio.h>
32 #include <boost/thread.hpp> 32 #include <boost/thread.hpp>
33 33
34 #include "../PalanthirException.h" 34 #include "../OrthancException.h"
35 #include "../ChunkedBuffer.h" 35 #include "../ChunkedBuffer.h"
36 #include "mongoose.h" 36 #include "mongoose.h"
37 37
38 38
39 #define PALANTHIR_REALM "Palanthir Secure Area" 39 #define ORTHANC_REALM "Orthanc Secure Area"
40 40
41 static const long LOCALHOST = (127ll << 24) + 1ll; 41 static const long LOCALHOST = (127ll << 24) + 1ll;
42 42
43 43
44 namespace Palanthir 44 namespace Orthanc
45 { 45 {
46 static const char multipart[] = "multipart/form-data; boundary="; 46 static const char multipart[] = "multipart/form-data; boundary=";
47 static unsigned int multipartLength = sizeof(multipart) / sizeof(char) - 1; 47 static unsigned int multipartLength = sizeof(multipart) / sizeof(char) - 1;
48 48
49 49
400 400
401 401
402 static void SendUnauthorized(HttpOutput& output) 402 static void SendUnauthorized(HttpOutput& output)
403 { 403 {
404 std::string s = "HTTP/1.1 401 Unauthorized\r\n" 404 std::string s = "HTTP/1.1 401 Unauthorized\r\n"
405 "WWW-Authenticate: Basic realm=\"" PALANTHIR_REALM "\"" 405 "WWW-Authenticate: Basic realm=\"" ORTHANC_REALM "\""
406 "\r\n\r\n"; 406 "\r\n\r\n";
407 output.Send(&s[0], s.size()); 407 output.Send(&s[0], s.size());
408 } 408 }
409 409
410 410
479 else if (!strcmp(request->request_method, "POST")) 479 else if (!strcmp(request->request_method, "POST"))
480 { 480 {
481 HttpHandler::Arguments::const_iterator ct = headers.find("content-type"); 481 HttpHandler::Arguments::const_iterator ct = headers.find("content-type");
482 if (ct == headers.end()) 482 if (ct == headers.end())
483 { 483 {
484 output.SendHeader(Palanthir_HttpStatus_400_BadRequest); 484 output.SendHeader(Orthanc_HttpStatus_400_BadRequest);
485 return (void*) ""; 485 return (void*) "";
486 } 486 }
487 487
488 PostDataStatus status; 488 PostDataStatus status;
489 489
499 } 499 }
500 500
501 switch (status) 501 switch (status)
502 { 502 {
503 case PostDataStatus_NoLength: 503 case PostDataStatus_NoLength:
504 output.SendHeader(Palanthir_HttpStatus_411_LengthRequired); 504 output.SendHeader(Orthanc_HttpStatus_411_LengthRequired);
505 return (void*) ""; 505 return (void*) "";
506 506
507 case PostDataStatus_Failure: 507 case PostDataStatus_Failure:
508 output.SendHeader(Palanthir_HttpStatus_400_BadRequest); 508 output.SendHeader(Orthanc_HttpStatus_400_BadRequest);
509 return (void*) ""; 509 return (void*) "";
510 510
511 case PostDataStatus_Pending: 511 case PostDataStatus_Pending:
512 output.AnswerBuffer(""); 512 output.AnswerBuffer("");
513 return (void*) ""; 513 return (void*) "";
526 try 526 try
527 { 527 {
528 handler->Handle(output, std::string(request->request_method), 528 handler->Handle(output, std::string(request->request_method),
529 uri, headers, arguments, postData); 529 uri, headers, arguments, postData);
530 } 530 }
531 catch (PalanthirException& e) 531 catch (OrthancException& e)
532 { 532 {
533 std::cerr << "MongooseServer Exception [" << e.What() << "]" << std::endl; 533 std::cerr << "MongooseServer Exception [" << e.What() << "]" << std::endl;
534 output.SendHeader(Palanthir_HttpStatus_500_InternalServerError); 534 output.SendHeader(Orthanc_HttpStatus_500_InternalServerError);
535 } 535 }
536 } 536 }
537 else 537 else
538 { 538 {
539 output.SendHeader(Palanthir_HttpStatus_404_NotFound); 539 output.SendHeader(Orthanc_HttpStatus_404_NotFound);
540 } 540 }
541 541
542 // Mark as processed 542 // Mark as processed
543 return (void*) ""; 543 return (void*) "";
544 } 544 }
597 }; 597 };
598 598
599 pimpl_->context_ = mg_start(&Callback, this, options); 599 pimpl_->context_ = mg_start(&Callback, this, options);
600 if (!pimpl_->context_) 600 if (!pimpl_->context_)
601 { 601 {
602 throw PalanthirException("Unable to launch the Mongoose server"); 602 throw OrthancException("Unable to launch the Mongoose server");
603 } 603 }
604 } 604 }
605 } 605 }
606 606
607 void MongooseServer::Stop() 607 void MongooseServer::Stop()
652 652
653 void MongooseServer::SetSslEnabled(bool enabled) 653 void MongooseServer::SetSslEnabled(bool enabled)
654 { 654 {
655 Stop(); 655 Stop();
656 656
657 #if PALANTHIR_SSL_ENABLED == 0 657 #if ORTHANC_SSL_ENABLED == 0
658 if (enabled) 658 if (enabled)
659 { 659 {
660 throw PalanthirException("Palanthir has been built without SSL support"); 660 throw OrthancException("Orthanc has been built without SSL support");
661 } 661 }
662 else 662 else
663 { 663 {
664 ssl_ = false; 664 ssl_ = false;
665 } 665 }