comparison OrthancCppClient/HttpClient.cpp @ 60:77aec9be0a51 orthanc-renaming

renaming of cppclient
author Sebastien Jodogne <s.jodogne@gmail.com>
date Sun, 16 Sep 2012 09:29:54 +0200
parents 4bc019d2f969
children aa6c8a942952
comparison
equal deleted inserted replaced
59:c996319e90bc 60:77aec9be0a51
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 * Permission is hereby granted, free of charge, to any person 6 * Permission is hereby granted, free of charge, to any person
7 * obtaining a copy of this software and associated documentation 7 * obtaining a copy of this software and associated documentation
29 29
30 #include <string.h> 30 #include <string.h>
31 #include <curl/curl.h> 31 #include <curl/curl.h>
32 32
33 33
34 namespace Palanthir 34 namespace Orthanc
35 { 35 {
36 struct HttpClient::PImpl 36 struct HttpClient::PImpl
37 { 37 {
38 CURL* curl_; 38 CURL* curl_;
39 struct curl_slist *postHeaders_; 39 struct curl_slist *postHeaders_;
86 86
87 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_WRITEFUNCTION, &CurlCallback)); 87 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_WRITEFUNCTION, &CurlCallback));
88 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_HEADER, 0)); 88 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_HEADER, 0));
89 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_FOLLOWLOCATION, 1)); 89 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_FOLLOWLOCATION, 1));
90 90
91 #if PALANTHIR_SSL_ENABLED == 1 91 #if ORTHANC_SSL_ENABLED == 1
92 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_SSL_VERIFYPEER, 0)); 92 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_SSL_VERIFYPEER, 0));
93 #endif 93 #endif
94 94
95 url_ = ""; 95 url_ = "";
96 method_ = Palanthir_HttpMethod_Get; 96 method_ = Orthanc_HttpMethod_Get;
97 lastStatus_ = Palanthir_HttpStatus_200_Ok; 97 lastStatus_ = Orthanc_HttpStatus_200_Ok;
98 isVerbose_ = false; 98 isVerbose_ = false;
99 } 99 }
100 100
101 101
102 HttpClient::~HttpClient() 102 HttpClient::~HttpClient()
128 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_WRITEDATA, &answer)); 128 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_WRITEDATA, &answer));
129 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_HTTPHEADER, NULL)); 129 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_HTTPHEADER, NULL));
130 130
131 switch (method_) 131 switch (method_)
132 { 132 {
133 case Palanthir_HttpMethod_Get: 133 case Orthanc_HttpMethod_Get:
134 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_HTTPGET, 1L)); 134 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_HTTPGET, 1L));
135 break; 135 break;
136 136
137 case Palanthir_HttpMethod_Post: 137 case Orthanc_HttpMethod_Post:
138 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_POST, 1L)); 138 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_POST, 1L));
139 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_HTTPHEADER, pimpl_->postHeaders_)); 139 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_HTTPHEADER, pimpl_->postHeaders_));
140 140
141 if (postData_.size() > 0) 141 if (postData_.size() > 0)
142 { 142 {
149 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_POSTFIELDSIZE, 0)); 149 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_POSTFIELDSIZE, 0));
150 } 150 }
151 151
152 break; 152 break;
153 153
154 case Palanthir_HttpMethod_Delete: 154 case Orthanc_HttpMethod_Delete:
155 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_NOBODY, 1L)); 155 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_NOBODY, 1L));
156 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_CUSTOMREQUEST, "DELETE")); 156 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_CUSTOMREQUEST, "DELETE"));
157 break; 157 break;
158 158
159 case Palanthir_HttpMethod_Put: 159 case Orthanc_HttpMethod_Put:
160 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_PUT, 1L)); 160 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_PUT, 1L));
161 break; 161 break;
162 162
163 default: 163 default:
164 throw HttpException("HttpClient: Internal error"); 164 throw HttpException("HttpClient: Internal error");
171 CheckCode(curl_easy_getinfo(pimpl_->curl_, CURLINFO_RESPONSE_CODE, &status)); 171 CheckCode(curl_easy_getinfo(pimpl_->curl_, CURLINFO_RESPONSE_CODE, &status));
172 172
173 if (status == 0) 173 if (status == 0)
174 { 174 {
175 // This corresponds to a call to an inexistent host 175 // This corresponds to a call to an inexistent host
176 lastStatus_ = Palanthir_HttpStatus_500_InternalServerError; 176 lastStatus_ = Orthanc_HttpStatus_500_InternalServerError;
177 } 177 }
178 else 178 else
179 { 179 {
180 lastStatus_ = static_cast<Palanthir_HttpStatus>(status); 180 lastStatus_ = static_cast<Orthanc_HttpStatus>(status);
181 } 181 }
182 182
183 return (status >= 200 && status < 300); 183 return (status >= 200 && status < 300);
184 } 184 }
185 185