2 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 * Copyright (C) 2017 - ESI-Group - Cedric DELAMARRE
6 * This file is hereby licensed under the terms of the GNU GPL v2.0,
7 * pursuant to article 5.3.4 of the CeCILL v.2.1.
8 * This file was originally licensed under the terms of the CeCILL v2.1,
9 * and continues to be available under such terms.
10 * For more information, see the COPYING file which you should have received
11 * along with this program.
14 /*--------------------------------------------------------------------------*/
16 #include <curl/curl.h>
17 #include "webtools_gw.hxx"
18 #include "function.hxx"
21 #include "sciCurl.hxx"
25 #include "localization.h"
28 #include "sci_malloc.h"
30 /*--------------------------------------------------------------------------*/
31 static const char fname[] = "http_delete";
32 types::Function::ReturnValue sci_http_delete(types::typed_list &in, types::optional_list &opt, int _iRetCount, types::typed_list &out)
34 SciCurl* sciCurlObj = SciCurl::getInstance();
35 CURLcode res = CURLE_OK;
39 Scierror(77, _("%s: Wrong number of input argument(s): %d expected.\n"), fname, 1);
40 return types::Function::Error;
45 Scierror(78, _("%s: Wrong number of output argument(s): %d to %d expected.\n"), fname, 1, 2);
46 return types::Function::Error;
50 if(in[0]->isString() == false && in[0]->getAs<types::String>()->isScalar() == false)
52 Scierror(999, _("%s: Wrong type for input argument #%d: A scalar string expected.\n"), fname, 1);
53 return types::Function::Error;
56 CURL* curl = curl_easy_init();
59 Scierror(999, _("%s: CURL initialization failed.\n"), fname);
60 return types::Function::Error;
63 sciCurlObj->setCommonHeaders(curl);
65 char* pcURL = wide_string_to_UTF8(in[0]->getAs<types::String>()->get(0));
66 curl_easy_setopt(curl, CURLOPT_URL, pcURL);
69 // common optional argument
70 if(checkCommonOpt((void*)curl, opt, fname))
72 return types::Function::Error;
75 // set proxy information
76 if(sciCurlObj->setProxy(curl))
78 Scierror(999, _("%s: Wrong proxy information, please check in the 'internet' Scilab preference.\n"), fname);
79 return types::Function::Error;
82 curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "DELETE");
83 sciCurlObj->getResultAsObject(curl);
85 res = curl_easy_perform(curl);
88 Scierror(999, _("%s: CURL execution failed.\n%s\n"), fname, curl_easy_strerror(res));
90 return types::Function::Error;
93 out.push_back(sciCurlObj->getResult());
98 curl_easy_getinfo (curl, CURLINFO_RESPONSE_CODE, &http_code);
99 out.push_back(new types::Double((double)http_code));
102 curl_easy_cleanup(curl);
103 return types::Function::OK;