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 char* pcURL = wide_string_to_UTF8(in[0]->getAs<types::String>()->get(0));
64 curl_easy_setopt(curl, CURLOPT_URL, pcURL);
67 // common optional argument
68 if(checkCommonOpt((void*)curl, opt, fname))
70 return types::Function::Error;
73 // set proxy information
74 if(sciCurlObj->setProxy(curl))
76 Scierror(999, _("%s: Wrong proxy information, please check in the 'internet' Scilab preference.\n"), fname);
77 return types::Function::Error;
80 curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "DELETE");
81 sciCurlObj->getResultAsObject(curl);
83 res = curl_easy_perform(curl);
86 Scierror(999, _("%s: CURL execution failed.\n%s\n"), fname, curl_easy_strerror(res));
88 return types::Function::Error;
91 out.push_back(sciCurlObj->getResult());
96 curl_easy_getinfo (curl, CURLINFO_RESPONSE_CODE, &http_code);
97 out.push_back(new types::Double((double)http_code));
100 curl_easy_cleanup(curl);
101 return types::Function::OK;