diff options
author | Kartik Gupta <kartikgupta0909@gmail.com> | 2015-07-22 16:42:37 +0530 |
---|---|---|
committer | Clément DAVID <clement.david@scilab-enterprises.com> | 2016-03-10 11:42:56 +0100 |
commit | 452dee4294769a749cbf996b0cb6902c1fc94e60 (patch) | |
tree | 052ad7bd1a7c929c1b37dfcd2563844735517fe1 | |
parent | 9486b1d51167021c997ff0a1df7f50f6921c0fa5 (diff) | |
download | scilab-atoms-improvements.zip scilab-atoms-improvements.tar.gz |
postURL addedatoms-improvements
Change-Id: If5542443b90721e268f3b6a01041f0ebbac11f1a
-rw-r--r-- | scilab/modules/fileio/Makefile.am | 3 | ||||
-rw-r--r-- | scilab/modules/fileio/Makefile.in | 17 | ||||
-rw-r--r-- | scilab/modules/fileio/fileio.vcxproj | 1 | ||||
-rw-r--r-- | scilab/modules/fileio/fileio.vcxproj.filters | 3 | ||||
-rw-r--r-- | scilab/modules/fileio/help/en_US/postURL.xml | 158 | ||||
-rw-r--r-- | scilab/modules/fileio/includes/gw_fileio.h | 1 | ||||
-rw-r--r-- | scilab/modules/fileio/sci_gateway/c/gw_fileio.c | 3 | ||||
-rw-r--r-- | scilab/modules/fileio/sci_gateway/c/sci_postURL.c | 269 | ||||
-rw-r--r-- | scilab/modules/fileio/sci_gateway/fileio_gateway.xml | 1 | ||||
-rw-r--r-- | scilab/modules/fileio/src/c/dlManager.c | 261 | ||||
-rw-r--r-- | scilab/modules/fileio/src/c/dlManager.h | 2 | ||||
-rw-r--r-- | scilab/modules/fileio/tests/unit_tests/postURL.dia.ref | 26 | ||||
-rw-r--r-- | scilab/modules/fileio/tests/unit_tests/postURL.tst | 29 |
13 files changed, 769 insertions, 5 deletions
diff --git a/scilab/modules/fileio/Makefile.am b/scilab/modules/fileio/Makefile.am index 7c2839c..2b4657c 100644 --- a/scilab/modules/fileio/Makefile.am +++ b/scilab/modules/fileio/Makefile.am | |||
@@ -114,7 +114,8 @@ sci_gateway/c/sci_splitURL.c \ | |||
114 | sci_gateway/c/sci_archive_list.c \ | 114 | sci_gateway/c/sci_archive_list.c \ |
115 | sci_gateway/c/sci_archive_extract.c \ | 115 | sci_gateway/c/sci_archive_extract.c \ |
116 | sci_gateway/c/sci_archive_compress.c \ | 116 | sci_gateway/c/sci_archive_compress.c \ |
117 | sci_gateway/c/sci_getURLheader.c | 117 | sci_gateway/c/sci_getURLheader.c \ |
118 | sci_gateway/c/sci_postURL.c | ||
118 | 119 | ||
119 | libscifileio_la_CPPFLAGS = -I$(srcdir)/includes/ \ | 120 | libscifileio_la_CPPFLAGS = -I$(srcdir)/includes/ \ |
120 | -I$(srcdir)/src/c/ \ | 121 | -I$(srcdir)/src/c/ \ |
diff --git a/scilab/modules/fileio/Makefile.in b/scilab/modules/fileio/Makefile.in index 3efbdd5..e681546 100644 --- a/scilab/modules/fileio/Makefile.in +++ b/scilab/modules/fileio/Makefile.in | |||
@@ -287,7 +287,8 @@ am__objects_2 = sci_gateway/c/libscifileio_la-gw_fileio.lo \ | |||
287 | sci_gateway/c/libscifileio_la-sci_archive_list.lo \ | 287 | sci_gateway/c/libscifileio_la-sci_archive_list.lo \ |
288 | sci_gateway/c/libscifileio_la-sci_archive_extract.lo \ | 288 | sci_gateway/c/libscifileio_la-sci_archive_extract.lo \ |
289 | sci_gateway/c/libscifileio_la-sci_archive_compress.lo \ | 289 | sci_gateway/c/libscifileio_la-sci_archive_compress.lo \ |
290 | sci_gateway/c/libscifileio_la-sci_getURLheader.lo | 290 | sci_gateway/c/libscifileio_la-sci_getURLheader.lo \ |
291 | sci_gateway/c/libscifileio_la-sci_postURL.lo | ||
291 | am_libscifileio_la_OBJECTS = $(am__objects_2) | 292 | am_libscifileio_la_OBJECTS = $(am__objects_2) |
292 | libscifileio_la_OBJECTS = $(am_libscifileio_la_OBJECTS) | 293 | libscifileio_la_OBJECTS = $(am_libscifileio_la_OBJECTS) |
293 | @MAINTAINER_MODE_FALSE@am_libscifileio_la_rpath = | 294 | @MAINTAINER_MODE_FALSE@am_libscifileio_la_rpath = |
@@ -745,7 +746,8 @@ sci_gateway/c/sci_splitURL.c \ | |||
745 | sci_gateway/c/sci_archive_list.c \ | 746 | sci_gateway/c/sci_archive_list.c \ |
746 | sci_gateway/c/sci_archive_extract.c \ | 747 | sci_gateway/c/sci_archive_extract.c \ |
747 | sci_gateway/c/sci_archive_compress.c \ | 748 | sci_gateway/c/sci_archive_compress.c \ |
748 | sci_gateway/c/sci_getURLheader.c | 749 | sci_gateway/c/sci_getURLheader.c \ |
750 | sci_gateway/c/sci_postURL.c | ||
749 | 751 | ||
750 | libscifileio_la_CPPFLAGS = -I$(srcdir)/includes/ \ | 752 | libscifileio_la_CPPFLAGS = -I$(srcdir)/includes/ \ |
751 | -I$(srcdir)/src/c/ \ | 753 | -I$(srcdir)/src/c/ \ |
@@ -1234,6 +1236,9 @@ sci_gateway/c/libscifileio_la-sci_archive_compress.lo: \ | |||
1234 | sci_gateway/c/libscifileio_la-sci_getURLheader.lo: \ | 1236 | sci_gateway/c/libscifileio_la-sci_getURLheader.lo: \ |
1235 | sci_gateway/c/$(am__dirstamp) \ | 1237 | sci_gateway/c/$(am__dirstamp) \ |
1236 | sci_gateway/c/$(DEPDIR)/$(am__dirstamp) | 1238 | sci_gateway/c/$(DEPDIR)/$(am__dirstamp) |
1239 | sci_gateway/c/libscifileio_la-sci_postURL.lo: \ | ||
1240 | sci_gateway/c/$(am__dirstamp) \ | ||
1241 | sci_gateway/c/$(DEPDIR)/$(am__dirstamp) | ||
1237 | 1242 | ||
1238 | libscifileio.la: $(libscifileio_la_OBJECTS) $(libscifileio_la_DEPENDENCIES) $(EXTRA_libscifileio_la_DEPENDENCIES) | 1243 | libscifileio.la: $(libscifileio_la_OBJECTS) $(libscifileio_la_DEPENDENCIES) $(EXTRA_libscifileio_la_DEPENDENCIES) |
1239 | $(AM_V_CCLD)$(LINK) $(am_libscifileio_la_rpath) $(libscifileio_la_OBJECTS) $(libscifileio_la_LIBADD) $(LIBS) | 1244 | $(AM_V_CCLD)$(LINK) $(am_libscifileio_la_rpath) $(libscifileio_la_OBJECTS) $(libscifileio_la_LIBADD) $(LIBS) |
@@ -1296,6 +1301,7 @@ distclean-compile: | |||
1296 | @AMDEP_TRUE@@am__include@ @am__quote@sci_gateway/c/$(DEPDIR)/libscifileio_la-sci_newest.Plo@am__quote@ | 1301 | @AMDEP_TRUE@@am__include@ @am__quote@sci_gateway/c/$(DEPDIR)/libscifileio_la-sci_newest.Plo@am__quote@ |
1297 | @AMDEP_TRUE@@am__include@ @am__quote@sci_gateway/c/$(DEPDIR)/libscifileio_la-sci_pathconvert.Plo@am__quote@ | 1302 | @AMDEP_TRUE@@am__include@ @am__quote@sci_gateway/c/$(DEPDIR)/libscifileio_la-sci_pathconvert.Plo@am__quote@ |
1298 | @AMDEP_TRUE@@am__include@ @am__quote@sci_gateway/c/$(DEPDIR)/libscifileio_la-sci_pathsep.Plo@am__quote@ | 1303 | @AMDEP_TRUE@@am__include@ @am__quote@sci_gateway/c/$(DEPDIR)/libscifileio_la-sci_pathsep.Plo@am__quote@ |
1304 | @AMDEP_TRUE@@am__include@ @am__quote@sci_gateway/c/$(DEPDIR)/libscifileio_la-sci_postURL.Plo@am__quote@ | ||
1299 | @AMDEP_TRUE@@am__include@ @am__quote@sci_gateway/c/$(DEPDIR)/libscifileio_la-sci_pwd.Plo@am__quote@ | 1305 | @AMDEP_TRUE@@am__include@ @am__quote@sci_gateway/c/$(DEPDIR)/libscifileio_la-sci_pwd.Plo@am__quote@ |
1300 | @AMDEP_TRUE@@am__include@ @am__quote@sci_gateway/c/$(DEPDIR)/libscifileio_la-sci_removedir.Plo@am__quote@ | 1306 | @AMDEP_TRUE@@am__include@ @am__quote@sci_gateway/c/$(DEPDIR)/libscifileio_la-sci_removedir.Plo@am__quote@ |
1301 | @AMDEP_TRUE@@am__include@ @am__quote@sci_gateway/c/$(DEPDIR)/libscifileio_la-sci_splitURL.Plo@am__quote@ | 1307 | @AMDEP_TRUE@@am__include@ @am__quote@sci_gateway/c/$(DEPDIR)/libscifileio_la-sci_splitURL.Plo@am__quote@ |
@@ -2145,6 +2151,13 @@ sci_gateway/c/libscifileio_la-sci_getURLheader.lo: sci_gateway/c/sci_getURLheade | |||
2145 | @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ | 2151 | @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ |
2146 | @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libscifileio_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o sci_gateway/c/libscifileio_la-sci_getURLheader.lo `test -f 'sci_gateway/c/sci_getURLheader.c' || echo '$(srcdir)/'`sci_gateway/c/sci_getURLheader.c | 2152 | @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libscifileio_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o sci_gateway/c/libscifileio_la-sci_getURLheader.lo `test -f 'sci_gateway/c/sci_getURLheader.c' || echo '$(srcdir)/'`sci_gateway/c/sci_getURLheader.c |
2147 | 2153 | ||
2154 | sci_gateway/c/libscifileio_la-sci_postURL.lo: sci_gateway/c/sci_postURL.c | ||
2155 | @am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libscifileio_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT sci_gateway/c/libscifileio_la-sci_postURL.lo -MD -MP -MF sci_gateway/c/$(DEPDIR)/libscifileio_la-sci_postURL.Tpo -c -o sci_gateway/c/libscifileio_la-sci_postURL.lo `test -f 'sci_gateway/c/sci_postURL.c' || echo '$(srcdir)/'`sci_gateway/c/sci_postURL.c | ||
2156 | @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) sci_gateway/c/$(DEPDIR)/libscifileio_la-sci_postURL.Tpo sci_gateway/c/$(DEPDIR)/libscifileio_la-sci_postURL.Plo | ||
2157 | @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='sci_gateway/c/sci_postURL.c' object='sci_gateway/c/libscifileio_la-sci_postURL.lo' libtool=yes @AMDEPBACKSLASH@ | ||
2158 | @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ | ||
2159 | @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libscifileio_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o sci_gateway/c/libscifileio_la-sci_postURL.lo `test -f 'sci_gateway/c/sci_postURL.c' || echo '$(srcdir)/'`sci_gateway/c/sci_postURL.c | ||
2160 | |||
2148 | mostlyclean-libtool: | 2161 | mostlyclean-libtool: |
2149 | -rm -f *.lo | 2162 | -rm -f *.lo |
2150 | 2163 | ||
diff --git a/scilab/modules/fileio/fileio.vcxproj b/scilab/modules/fileio/fileio.vcxproj index 6c86a58..9a7365a 100644 --- a/scilab/modules/fileio/fileio.vcxproj +++ b/scilab/modules/fileio/fileio.vcxproj | |||
@@ -213,6 +213,7 @@ lib /DEF:"$(ProjectDir)Preferences_Import.def" /SUBSYSTEM:WINDOWS /MACHINE:$(Pla | |||
213 | <ClCompile Include="sci_gateway\c\sci_archive_list.c" /> | 213 | <ClCompile Include="sci_gateway\c\sci_archive_list.c" /> |
214 | <ClCompile Include="sci_gateway\c\sci_getURL.c" /> | 214 | <ClCompile Include="sci_gateway\c\sci_getURL.c" /> |
215 | <ClCompile Include="sci_gateway\c\sci_getURLheader.c" /> | 215 | <ClCompile Include="sci_gateway\c\sci_getURLheader.c" /> |
216 | <ClCompile Include="sci_gateway\c\sci_postURL.c" /> | ||
216 | <ClCompile Include="sci_gateway\c\sci_splitURL.c" /> | 217 | <ClCompile Include="sci_gateway\c\sci_splitURL.c" /> |
217 | <ClCompile Include="sci_gateway\c\sci_tempname.c" /> | 218 | <ClCompile Include="sci_gateway\c\sci_tempname.c" /> |
218 | <ClCompile Include="src\c\addfile.c" /> | 219 | <ClCompile Include="src\c\addfile.c" /> |
diff --git a/scilab/modules/fileio/fileio.vcxproj.filters b/scilab/modules/fileio/fileio.vcxproj.filters index e9b3205..ca2f098 100644 --- a/scilab/modules/fileio/fileio.vcxproj.filters +++ b/scilab/modules/fileio/fileio.vcxproj.filters | |||
@@ -177,6 +177,9 @@ | |||
177 | <ClCompile Include="src\c\scanf_functions.c"> | 177 | <ClCompile Include="src\c\scanf_functions.c"> |
178 | <Filter>Source Files</Filter> | 178 | <Filter>Source Files</Filter> |
179 | </ClCompile> | 179 | </ClCompile> |
180 | <ClCompile Include="sci_gateway\c\sci_postURL.c"> | ||
181 | <Filter>Source Files</Filter> | ||
182 | </ClCompile> | ||
180 | <ClCompile Include="sci_gateway\c\sci_archive_compress.c"> | 183 | <ClCompile Include="sci_gateway\c\sci_archive_compress.c"> |
181 | <Filter>Source Files</Filter> | 184 | <Filter>Source Files</Filter> |
182 | </ClCompile> | 185 | </ClCompile> |
diff --git a/scilab/modules/fileio/help/en_US/postURL.xml b/scilab/modules/fileio/help/en_US/postURL.xml new file mode 100644 index 0000000..86e94a7 --- /dev/null +++ b/scilab/modules/fileio/help/en_US/postURL.xml | |||
@@ -0,0 +1,158 @@ | |||
1 | <?xml version="1.0" encoding="UTF-8"?> | ||
2 | <!-- | ||
3 | * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab | ||
4 | * Copyright (C) - S/E - Kartik Gupta | ||
5 | * | ||
6 | * This file must be used under the terms of the CeCILL. | ||
7 | * This source file is licensed as described in the file COPYING, which | ||
8 | * you should have received as part of this distribution. The terms | ||
9 | * are also available at | ||
10 | * http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt | ||
11 | * | ||
12 | --> | ||
13 | <refentry xml:id="postURL" xml:lang="en" | ||
14 | xmlns="http://docbook.org/ns/docbook" | ||
15 | xmlns:xlink="http://www.w3.org/1999/xlink" | ||
16 | xmlns:svg="http://www.w3.org/2000/svg" | ||
17 | xmlns:ns3="http://www.w3.org/1999/xhtml" | ||
18 | xmlns:mml="http://www.w3.org/1998/Math/MathML" | ||
19 | xmlns:scilab="http://www.scilab.org" | ||
20 | xmlns:db="http://docbook.org/ns/docbook"> | ||
21 | |||
22 | <refnamediv> | ||
23 | <refname>postURL</refname> | ||
24 | |||
25 | <refpurpose>Post to a URL and downloading the response (HTTP, HTTPS...) </refpurpose> | ||
26 | </refnamediv> | ||
27 | |||
28 | <refsynopsisdiv> | ||
29 | <title>Calling Sequence</title> | ||
30 | |||
31 | <synopsis>filename = postURL(URL,post_argument_names,post_argument_values); | ||
32 | [filename, [content]] = postURL(URL,post_argument_list,post_argument_values [, targetDir [, username [, password]]]]); | ||
33 | [filename, [content]] = postURL(URL,post_argument_list,post_argument_values [, targetFile [, username [, password]]]]); | ||
34 | </synopsis> | ||
35 | </refsynopsisdiv> | ||
36 | |||
37 | <refsection> | ||
38 | <title>Arguments</title> | ||
39 | <variablelist> | ||
40 | <varlistentry> | ||
41 | <term>URL</term> | ||
42 | <listitem> | ||
43 | <para>String: An URL. Supported and tested: HTTP, HTTPS, FTP (IPv4 and IPv6)</para> | ||
44 | </listitem> | ||
45 | </varlistentry> | ||
46 | <varlistentry> | ||
47 | <term>post_argument_list</term> | ||
48 | <listitem> | ||
49 | <para>A list of strings containing the names of the post variables</para> | ||
50 | </listitem> | ||
51 | </varlistentry> | ||
52 | <varlistentry> | ||
53 | <term>post_argument_values</term> | ||
54 | <listitem> | ||
55 | <para>A list of strings containing the values for the variables mentioned in the post_argument_list in the same order.</para> | ||
56 | </listitem> | ||
57 | </varlistentry> | ||
58 | <varlistentry> | ||
59 | <term>targetDir</term> | ||
60 | <listitem> | ||
61 | <para>String optional parameter: In which directory the file will be stored (current directory if empty)</para> | ||
62 | </listitem> | ||
63 | </varlistentry> | ||
64 | <varlistentry> | ||
65 | <term>targetFile</term> | ||
66 | <listitem> | ||
67 | <para>String optional parameter: Where (and under which name) the file will be stored (current directory if empty)</para> | ||
68 | </listitem> | ||
69 | </varlistentry> | ||
70 | <varlistentry> | ||
71 | <term>username</term> | ||
72 | <listitem> | ||
73 | <para>String optional parameter: Username for the websites which require authentication</para> | ||
74 | </listitem> | ||
75 | </varlistentry> | ||
76 | <varlistentry> | ||
77 | <term>password</term> | ||
78 | <listitem> | ||
79 | <para>String optional parameter: Password for the websites which require authentication</para> | ||
80 | </listitem> | ||
81 | </varlistentry> | ||
82 | <varlistentry> | ||
83 | <term>filename</term> | ||
84 | <listitem> | ||
85 | <para>String: The path to the downloaded file</para> | ||
86 | </listitem> | ||
87 | </varlistentry> | ||
88 | <varlistentry> | ||
89 | <term>content</term> | ||
90 | <listitem> | ||
91 | <para>String: The content to the downloaded file</para> | ||
92 | </listitem> | ||
93 | </varlistentry> | ||
94 | </variablelist> | ||
95 | </refsection> | ||
96 | |||
97 | <refsection> | ||
98 | <title>Description</title> | ||
99 | |||
100 | <para>Posting to a URL and downloading the reponse</para> | ||
101 | |||
102 | <para> | ||
103 | postURL posts to a URL and downloads the reponse. By default, postURL will use the same name as provided in the URL. However, under some circumstances (for example, <emphasis role="italic">http://www.scilab.org/</emphasis>), the filename is not provided by the URL itself, postURL will rename the file to <emphasis role="italic">index.html</emphasis> | ||
104 | </para> | ||
105 | |||
106 | <para>content contains the content of a page pointed by an URL.</para> | ||
107 | |||
108 | <para> | ||
109 | This function is based on the <ulink url="http://curl.haxx.se/libcurl/">curl library</ulink>. | ||
110 | </para> | ||
111 | <para>post_argument_list and the post_argument_values contains the post variables and their values to be posted on the page.</para> | ||
112 | |||
113 | <para> Username and Password can be specified for the websites which required authentication. The authentication method used is the CURLAUTH_ANY provided by CURLOPT_HTTPAUTH parameter of the libcurl library.</para> | ||
114 | |||
115 | <para>IPv6 (and obviously IPv4) are supported out-of-the box by postURL.</para> | ||
116 | |||
117 | <para>Proxy configuration is enabled in this version, it can be modified in the Preferences under the rubric "Internet".</para> | ||
118 | |||
119 | <para> | ||
120 | The <emphasis role="italic">CURLOPT_FOLLOWLOCATION</emphasis> curl option is activated to make sure the download follow the URL. | ||
121 | </para> | ||
122 | |||
123 | <para> | ||
124 | <literal>postURL</literal> is based on libcurl. The version of this library in the official Scilab binary has been compiled with HTTP, HTTPS, FTP and FTPS support. If Scilab has been installed through a packaging system in a distribution, it is likely that <ulink url="http://curl.haxx.se/docs/features.html">other protocols</ulink> than HTTP, HTTPS and FTPS will work. However, they have not been tested enough. | ||
125 | </para> | ||
126 | |||
127 | </refsection> | ||
128 | |||
129 | <refsection> | ||
130 | <title>Examples</title> | ||
131 | |||
132 | <programlisting role="example"> | ||
133 | |||
134 | filename = postURL("http://example.com",["var1","var2"],["test1","test2"]); | ||
135 | </programlisting> | ||
136 | </refsection> | ||
137 | <refsection role="see also"> | ||
138 | <title>See Also</title> | ||
139 | <simplelist type="inline"> | ||
140 | <member> | ||
141 | <link linkend="splitURL">splitURL</link> | ||
142 | </member> | ||
143 | </simplelist> | ||
144 | </refsection> | ||
145 | |||
146 | <refsection> | ||
147 | <title>History</title> | ||
148 | <revhistory> | ||
149 | <revision> | ||
150 | <revnumber>5.6.0</revnumber> | ||
151 | <revremark> | ||
152 | Function <literal>postURL()</literal> introduced | ||
153 | </revremark> | ||
154 | </revision> | ||
155 | </revhistory> | ||
156 | </refsection> | ||
157 | |||
158 | </refentry> | ||
diff --git a/scilab/modules/fileio/includes/gw_fileio.h b/scilab/modules/fileio/includes/gw_fileio.h index 2139ee7..9c58e5f 100644 --- a/scilab/modules/fileio/includes/gw_fileio.h +++ b/scilab/modules/fileio/includes/gw_fileio.h | |||
@@ -67,6 +67,7 @@ int sci_archive_list(char *fname, unsigned long fname_len); | |||
67 | int sci_archive_extract(char *fname, unsigned long fname_len); | 67 | int sci_archive_extract(char *fname, unsigned long fname_len); |
68 | int sci_archive_compress(char *fname, unsigned long fname_len); | 68 | int sci_archive_compress(char *fname, unsigned long fname_len); |
69 | int sci_getURLheader(char *fname, unsigned long fname_len); | 69 | int sci_getURLheader(char *fname, unsigned long fname_len); |
70 | int sci_postURL(char *fname, unsigned long fname_len); | ||
70 | /*--------------------------------------------------------------------------*/ | 71 | /*--------------------------------------------------------------------------*/ |
71 | #endif /* __GW_FILEIO_H__ */ | 72 | #endif /* __GW_FILEIO_H__ */ |
72 | /*--------------------------------------------------------------------------*/ | 73 | /*--------------------------------------------------------------------------*/ |
diff --git a/scilab/modules/fileio/sci_gateway/c/gw_fileio.c b/scilab/modules/fileio/sci_gateway/c/gw_fileio.c index 4838cb2..a6e5204 100644 --- a/scilab/modules/fileio/sci_gateway/c/gw_fileio.c +++ b/scilab/modules/fileio/sci_gateway/c/gw_fileio.c | |||
@@ -71,7 +71,8 @@ static gw_generic_table Tab[] = | |||
71 | {sci_archive_list, "archiveList"}, | 71 | {sci_archive_list, "archiveList"}, |
72 | {sci_archive_extract, "archiveExtract"}, | 72 | {sci_archive_extract, "archiveExtract"}, |
73 | {sci_archive_compress, "archiveCompress"}, | 73 | {sci_archive_compress, "archiveCompress"}, |
74 | {sci_getURLheader, "getURLheader"} | 74 | {sci_getURLheader, "getURLheader"}, |
75 | {sci_postURL, "postURL"} | ||
75 | }; | 76 | }; |
76 | /*--------------------------------------------------------------------------*/ | 77 | /*--------------------------------------------------------------------------*/ |
77 | int gw_fileio(void) | 78 | int gw_fileio(void) |
diff --git a/scilab/modules/fileio/sci_gateway/c/sci_postURL.c b/scilab/modules/fileio/sci_gateway/c/sci_postURL.c new file mode 100644 index 0000000..018197a --- /dev/null +++ b/scilab/modules/fileio/sci_gateway/c/sci_postURL.c | |||
@@ -0,0 +1,269 @@ | |||
1 | /* | ||
2 | * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab | ||
3 | * Copyright (C) 2015 - Kartik Gupta | ||
4 | * | ||
5 | * This file must be used under the terms of the CeCILL. | ||
6 | * This source file is licensed as described in the file COPYING, which | ||
7 | * you should have received as part of this distribution. The terms | ||
8 | * are also available at | ||
9 | * http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt | ||
10 | * | ||
11 | */ | ||
12 | /*--------------------------------------------------------------------------*/ | ||
13 | #include <stdlib.h> | ||
14 | #include <string.h> | ||
15 | #include "gw_fileio.h" | ||
16 | #include "api_scilab.h" | ||
17 | #include "MALLOC.h" | ||
18 | #include "Scierror.h" | ||
19 | #include "localization.h" | ||
20 | #include "PATH_MAX.h" | ||
21 | #include "freeArrayOfString.h" | ||
22 | #include "expandPathVariable.h" | ||
23 | #ifdef _MSC_VER | ||
24 | #include "strdup_windows.h" | ||
25 | #endif | ||
26 | #include <unistd.h> | ||
27 | #include "isdir.h" | ||
28 | #include "createdirectory.h" | ||
29 | #include "scicurdir.h" | ||
30 | #include "archive_compress.h" | ||
31 | #include "dlManager.h" | ||
32 | /*--------------------------------------------------------------------------*/ | ||
33 | int sci_postURL(char *fname, unsigned long fname_len) | ||
34 | { | ||
35 | SciErr sciErr; | ||
36 | int *piAddressVarOne = NULL; | ||
37 | char *pStVarOne = NULL; | ||
38 | char *pStVarOneExpanded = NULL; | ||
39 | |||
40 | int ret = 0; | ||
41 | int *piAddressVarTwo = NULL; | ||
42 | char **pStVarTwo = NULL; | ||
43 | int m1 = 0; | ||
44 | int n1 = 0; | ||
45 | int i = 0; | ||
46 | |||
47 | int *piAddressVarThree = NULL; | ||
48 | char **pStVarThree = NULL; | ||
49 | int m2 = 0; | ||
50 | int n2 = 0; | ||
51 | |||
52 | char *username = NULL; | ||
53 | char *password = NULL; | ||
54 | char *dest = NULL; | ||
55 | CheckRhs(3, 5); | ||
56 | CheckLhs(1, 2); | ||
57 | int result = 0; | ||
58 | int *error = 0; | ||
59 | int iRhs = nbInputArgument(pvApiCtx); | ||
60 | char *filePath = NULL; | ||
61 | char *content; | ||
62 | char *url; | ||
63 | |||
64 | sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddressVarOne); | ||
65 | if (sciErr.iErr) | ||
66 | { | ||
67 | printError(&sciErr, 0); | ||
68 | Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 1); | ||
69 | return 0; | ||
70 | } | ||
71 | |||
72 | if (isStringType(pvApiCtx, piAddressVarOne) == 0 || isScalar(pvApiCtx, piAddressVarOne) == 0) | ||
73 | { | ||
74 | Scierror(999, _("%s: Wrong type for input argument #%d: A string expected.\n"), fname, 1); | ||
75 | return 0; | ||
76 | } | ||
77 | |||
78 | |||
79 | sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddressVarTwo); | ||
80 | if (sciErr.iErr) | ||
81 | { | ||
82 | printError(&sciErr, 0); | ||
83 | Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 1); | ||
84 | return 0; | ||
85 | } | ||
86 | |||
87 | if (isDoubleType(pvApiCtx, piAddressVarTwo)) | ||
88 | { | ||
89 | if (isEmptyMatrix(pvApiCtx, piAddressVarTwo)) | ||
90 | { | ||
91 | if (createEmptyMatrix(pvApiCtx, Rhs + 2)) | ||
92 | { | ||
93 | Scierror(999, _("%s: Memory allocation error.\n"), fname); | ||
94 | return 0; | ||
95 | } | ||
96 | } | ||
97 | else | ||
98 | { | ||
99 | Scierror(999, _("%s: Wrong type for input argument #%d: String array expected.\n"), fname, 1); | ||
100 | return 0; | ||
101 | } | ||
102 | |||
103 | LhsVar(1) = Rhs + 1; | ||
104 | PutLhsVar(); | ||
105 | return 0; | ||
106 | } | ||
107 | |||
108 | if (isStringType(pvApiCtx, piAddressVarTwo) == 0) | ||
109 | { | ||
110 | Scierror(999, _("%s: Wrong type for input argument #%d: String array expected.\n"), fname, 2); | ||
111 | return 0; | ||
112 | } | ||
113 | |||
114 | if (getAllocatedMatrixOfString(pvApiCtx, piAddressVarTwo, &m1, &n1, &pStVarTwo)) | ||
115 | { | ||
116 | Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 2); | ||
117 | return 0; | ||
118 | } | ||
119 | |||
120 | sciErr = getVarAddressFromPosition(pvApiCtx, 3, &piAddressVarThree); | ||
121 | if (sciErr.iErr) | ||
122 | { | ||
123 | printError(&sciErr, 0); | ||
124 | Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 3); | ||
125 | return 0; | ||
126 | } | ||
127 | |||
128 | if (isDoubleType(pvApiCtx, piAddressVarThree)) | ||
129 | { | ||
130 | if (isEmptyMatrix(pvApiCtx, piAddressVarThree)) | ||
131 | { | ||
132 | if (createEmptyMatrix(pvApiCtx, Rhs + 3)) | ||
133 | { | ||
134 | Scierror(999, _("%s: Memory allocation error.\n"), fname); | ||
135 | return 0; | ||
136 | } | ||
137 | } | ||
138 | else | ||
139 | { | ||
140 | Scierror(999, _("%s: Wrong type for input argument #%d: String array expected.\n"), fname, 3); | ||
141 | return 0; | ||
142 | } | ||
143 | |||
144 | LhsVar(1) = Rhs + 1; | ||
145 | PutLhsVar(); | ||
146 | return 0; | ||
147 | } | ||
148 | |||
149 | if (isStringType(pvApiCtx, piAddressVarThree) == 0) | ||
150 | { | ||
151 | Scierror(999, _("%s: Wrong type for input argument #%d: String array expected.\n"), fname, 3); | ||
152 | return 0; | ||
153 | } | ||
154 | |||
155 | if (getAllocatedMatrixOfString(pvApiCtx, piAddressVarThree, &m2, &n2, &pStVarThree)) | ||
156 | { | ||
157 | Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 3); | ||
158 | return 0; | ||
159 | } | ||
160 | |||
161 | if(m1*n1 != m2*n2) | ||
162 | { | ||
163 | Scierror(999, _("%s: Sorry the number of post values are not equal to number of post arguments\n"), fname); | ||
164 | } | ||
165 | |||
166 | if (iRhs > 3) | ||
167 | { | ||
168 | int *piAddressVarFour = NULL; | ||
169 | sciErr = getVarAddressFromPosition(pvApiCtx, 4, &piAddressVarFour); | ||
170 | if (sciErr.iErr) | ||
171 | { | ||
172 | Scierror(999, _("%s:Sorry memory allocation error \n"), fname); | ||
173 | return 0; | ||
174 | } | ||
175 | ret = getAllocatedSingleString(pvApiCtx, piAddressVarFour, &dest); | ||
176 | if (ret) | ||
177 | { | ||
178 | Scierror(999, _("%s:Sorry memory allocation error \n"), fname); | ||
179 | return 0; | ||
180 | } | ||
181 | |||
182 | } | ||
183 | |||
184 | if (iRhs > 4) | ||
185 | { | ||
186 | int *piAddressVarFive = NULL; | ||
187 | sciErr = getVarAddressFromPosition(pvApiCtx, 5, &piAddressVarFive); | ||
188 | if (sciErr.iErr) | ||
189 | { | ||
190 | Scierror(999, _("%s:Sorry memory allocation error \n"), fname); | ||
191 | return 0; | ||
192 | } | ||
193 | ret = getAllocatedSingleString(pvApiCtx, piAddressVarFive, &username); | ||
194 | if(ret) | ||
195 | { | ||
196 | Scierror(999, _("%s:Sorry memory allocation error \n"), fname); | ||
197 | return 0; | ||
198 | } | ||
199 | } | ||
200 | |||
201 | if (iRhs > 5) | ||
202 | { | ||
203 | int *piAddressVarSix = NULL; | ||
204 | sciErr = getVarAddressFromPosition(pvApiCtx, 6, &piAddressVarSix); | ||
205 | if (sciErr.iErr) | ||
206 | { | ||
207 | Scierror(999, _("%s:Sorry memory allocation error \n"), fname); | ||
208 | return 0; | ||
209 | } | ||
210 | ret = getAllocatedSingleString(pvApiCtx, piAddressVarSix, &password); | ||
211 | if(ret) | ||
212 | { | ||
213 | Scierror(999, _("%s:Sorry memory allocation error \n"), fname); | ||
214 | return 0; | ||
215 | } | ||
216 | } | ||
217 | |||
218 | |||
219 | if (getAllocatedSingleString(pvApiCtx, piAddressVarOne, &url)) | ||
220 | { | ||
221 | if (pStVarOne) | ||
222 | { | ||
223 | freeAllocatedSingleWideString(pStVarOne); | ||
224 | } | ||
225 | |||
226 | Scierror(999, _("%s: Memory allocation error.\n"), fname); | ||
227 | return 0; | ||
228 | } | ||
229 | |||
230 | pStVarTwo[m1*n1] = NULL; | ||
231 | pStVarThree[m1*n1] = NULL; | ||
232 | result = 1; | ||
233 | filePath = postFile(url, pStVarTwo,pStVarThree,dest, username, password, &content); | ||
234 | if (filePath) | ||
235 | { | ||
236 | //Return the second argument which si the file name | ||
237 | ret = createSingleString(pvApiCtx, iRhs + 1, filePath); | ||
238 | FREE(filePath); | ||
239 | filePath = NULL; | ||
240 | if (ret) | ||
241 | { | ||
242 | Scierror(999, _("%s: Could not create the output argument.\n")); | ||
243 | return 0; | ||
244 | } | ||
245 | } | ||
246 | |||
247 | if (content && nbOutputArgument(pvApiCtx) == 2) | ||
248 | { | ||
249 | //create new variable with the content | ||
250 | int res = createSingleString(pvApiCtx, iRhs + 2, content); | ||
251 | if (res) | ||
252 | { | ||
253 | Scierror(999, _("%s: Could not create the output argument.\n")); | ||
254 | return 0; | ||
255 | } | ||
256 | } | ||
257 | |||
258 | AssignOutputVariable(pvApiCtx, 1) = iRhs + 1; | ||
259 | AssignOutputVariable(pvApiCtx, 2) = iRhs + 2; | ||
260 | ReturnArguments(pvApiCtx); | ||
261 | |||
262 | freeAllocatedSingleString(pStVarOne); | ||
263 | freeAllocatedSingleString(pStVarTwo); | ||
264 | return 0; | ||
265 | |||
266 | } | ||
267 | /*--------------------------------------------------------------------------*/ | ||
268 | |||
269 | |||
diff --git a/scilab/modules/fileio/sci_gateway/fileio_gateway.xml b/scilab/modules/fileio/sci_gateway/fileio_gateway.xml index 2fbdcfe..6e810fd 100644 --- a/scilab/modules/fileio/sci_gateway/fileio_gateway.xml +++ b/scilab/modules/fileio/sci_gateway/fileio_gateway.xml | |||
@@ -85,4 +85,5 @@ | |||
85 | <PRIMITIVE gatewayId="34" primitiveId="50" primitiveName="archiveExtract" /> | 85 | <PRIMITIVE gatewayId="34" primitiveId="50" primitiveName="archiveExtract" /> |
86 | <PRIMITIVE gatewayId="34" primitiveId="51" primitiveName="archiveCompress" /> | 86 | <PRIMITIVE gatewayId="34" primitiveId="51" primitiveName="archiveCompress" /> |
87 | <PRIMITIVE gatewayId="34" primitiveId="52" primitiveName="getURLheader" /> | 87 | <PRIMITIVE gatewayId="34" primitiveId="52" primitiveName="getURLheader" /> |
88 | <PRIMITIVE gatewayId="34" primitiveId="53" primitiveName="postURL" /> | ||
88 | </GATEWAY> | 89 | </GATEWAY> |
diff --git a/scilab/modules/fileio/src/c/dlManager.c b/scilab/modules/fileio/src/c/dlManager.c index d539e21..e9f66dd 100644 --- a/scilab/modules/fileio/src/c/dlManager.c +++ b/scilab/modules/fileio/src/c/dlManager.c | |||
@@ -450,6 +450,267 @@ char *downloadFile(char *url, char *dest, char *username, char *password, char * | |||
450 | return filename; | 450 | return filename; |
451 | } | 451 | } |
452 | /* ==================================================================== */ | 452 | /* ==================================================================== */ |
453 | char *postFile(char *url, char **arguments, char **values, char *dest, char *username, char *password, char **content) | ||
454 | { | ||
455 | CURL *curl; | ||
456 | CURLcode res; | ||
457 | char *filename = NULL; | ||
458 | FILE *file; | ||
459 | inputString buffer; | ||
460 | inputString header_buffer; | ||
461 | char *destdir = NULL; | ||
462 | char *destfile = NULL; | ||
463 | |||
464 | curl = curl_easy_init(); | ||
465 | if (curl == NULL) | ||
466 | { | ||
467 | Scierror(999, "Failed opening the curl handle.\n"); | ||
468 | return NULL; | ||
469 | } | ||
470 | |||
471 | init_string(&buffer); | ||
472 | res = curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, errorBuffer); | ||
473 | if (res != CURLE_OK) | ||
474 | { | ||
475 | Scierror(999, "Failed to set error buffer [%d]\n", res); | ||
476 | return NULL; | ||
477 | } | ||
478 | |||
479 | // Get destination directory and filename | ||
480 | if (dest != NULL) | ||
481 | { | ||
482 | // Destination is specified in argument | ||
483 | char* pathdrive = (char*)MALLOC(sizeof(char) * (PATH_MAX + 1)); | ||
484 | char* pathdir = (char*)MALLOC(sizeof(char) * (PATH_MAX + 1)); | ||
485 | char* pathfile = (char*)MALLOC(sizeof(char) * (PATH_MAX + 1)); | ||
486 | char* pathext = (char*)MALLOC(sizeof(char) * (PATH_MAX + 1)); | ||
487 | |||
488 | splitpath(dest, TRUE, pathdrive, pathdir, pathfile, pathext); | ||
489 | |||
490 | if (!isdir(dest)) | ||
491 | { | ||
492 | // Destination is a file | ||
493 | destdir = (char *)MALLOC((strlen(pathdrive) + strlen(pathdir) + 1) * sizeof(char)); | ||
494 | strcpy(destdir, pathdrive); | ||
495 | strcat(destdir, pathdir); | ||
496 | |||
497 | // Get filename | ||
498 | destfile = (char *)MALLOC((strlen(pathfile) + strlen(pathext) + 1) * sizeof(char)); | ||
499 | strcpy(destfile, pathfile); | ||
500 | strcat(destfile, pathext); | ||
501 | } | ||
502 | else | ||
503 | { | ||
504 | // Destination is a directory | ||
505 | destdir = (char *)MALLOC((strlen(pathdrive) + strlen(pathdir) + strlen(pathfile) + strlen(pathext) + strlen(DIR_SEPARATOR) + 1) * sizeof(char)); | ||
506 | strcpy(destdir, pathdrive); | ||
507 | strcat(destdir, pathdir); | ||
508 | strcat(destdir, pathfile); | ||
509 | strcat(destdir, pathext); | ||
510 | strcat(destdir, DIR_SEPARATOR); | ||
511 | |||
512 | // Retrieve filename from URL | ||
513 | destfile = getFileNameFromURL(url); | ||
514 | } | ||
515 | |||
516 | FREE(pathdrive); | ||
517 | FREE(pathdir); | ||
518 | FREE(pathfile); | ||
519 | FREE(pathext); | ||
520 | } | ||
521 | else | ||
522 | { | ||
523 | // Destination is not specified in argument | ||
524 | // Destination directory is current dir | ||
525 | int err = 0; | ||
526 | char *currentdir; | ||
527 | currentdir = scigetcwd(&err); | ||
528 | if (!err) | ||
529 | { | ||
530 | destdir = (char *)MALLOC((strlen(currentdir) + strlen(DIR_SEPARATOR) + 1) * sizeof(char)); | ||
531 | strcpy(destdir, currentdir); | ||
532 | strcat(destdir, DIR_SEPARATOR); | ||
533 | FREE(currentdir); | ||
534 | } | ||
535 | else | ||
536 | { | ||
537 | Scierror(999, _("Failed getting current dir, error code: %d\n"), err); | ||
538 | return NULL; | ||
539 | } | ||
540 | |||
541 | // Destination filename retrieved from URL | ||
542 | destfile = getFileNameFromURL(url); | ||
543 | } | ||
544 | |||
545 | if (destfile == NULL) | ||
546 | { | ||
547 | return NULL; | ||
548 | } | ||
549 | |||
550 | // Build file path | ||
551 | filename = (char *)MALLOC((strlen(destdir) + strlen(destfile) + 1) * sizeof(char)); | ||
552 | strcpy(filename, destdir); | ||
553 | strcat(filename, destfile); | ||
554 | FREE(destdir); | ||
555 | FREE(destfile); | ||
556 | res = curl_easy_setopt(curl, CURLOPT_URL, url); | ||
557 | if (res != CURLE_OK) | ||
558 | { | ||
559 | Scierror(999, _("Failed to set URL [%s]\n"), errorBuffer); | ||
560 | FREE(filename); | ||
561 | return NULL; | ||
562 | } | ||
563 | |||
564 | //Set authentication variables | ||
565 | if (username != NULL) | ||
566 | { | ||
567 | char * userpass; | ||
568 | int uplen = (int)strlen(username); | ||
569 | if (password != NULL) | ||
570 | { | ||
571 | uplen = uplen + (int)strlen(password); | ||
572 | } | ||
573 | |||
574 | userpass = (char *)MALLOC((uplen + 2) * sizeof(char)); | ||
575 | |||
576 | strcpy(userpass, username); | ||
577 | strcat(userpass, ":"); | ||
578 | if (password != NULL) | ||
579 | { | ||
580 | strcat(userpass, password); | ||
581 | } | ||
582 | |||
583 | res = curl_easy_setopt(curl, CURLOPT_HTTPAUTH, CURLAUTH_ANY); | ||
584 | if (res != CURLE_OK) | ||
585 | { | ||
586 | FREE(filename); | ||
587 | FREE(userpass); | ||
588 | Scierror(999, "Failed to set httpauth type to ANY [%s]\n", errorBuffer); | ||
589 | return NULL; | ||
590 | } | ||
591 | |||
592 | res = curl_easy_setopt(curl, CURLOPT_USERPWD, userpass); | ||
593 | if (res != CURLE_OK) | ||
594 | { | ||
595 | FREE(filename); | ||
596 | Scierror(999, _("Failed to set user:pwd [%s]\n"), errorBuffer); | ||
597 | return NULL; | ||
598 | } | ||
599 | } /* end authentication section */ | ||
600 | |||
601 | { | ||
602 | //Set proxy variables | ||
603 | char *proxyHost = NULL; | ||
604 | char *proxyUserPwd = NULL; | ||
605 | long proxyPort = 1080; | ||
606 | int proxySet = 0; | ||
607 | |||
608 | proxySet = getProxyValues(&proxyHost, &proxyPort, &proxyUserPwd); | ||
609 | |||
610 | if (proxySet == 1) | ||
611 | { | ||
612 | res = curl_easy_setopt(curl, CURLOPT_PROXY, proxyHost); | ||
613 | if (res != CURLE_OK) | ||
614 | { | ||
615 | FREE(proxyHost); | ||
616 | FREE(proxyUserPwd); | ||
617 | FREE(filename); | ||
618 | Scierror(999, _("Failed to set proxy host [%s]\n"), errorBuffer); | ||
619 | return NULL; | ||
620 | } | ||
621 | |||
622 | res = curl_easy_setopt(curl, CURLOPT_PROXYPORT, proxyPort); | ||
623 | if (res != CURLE_OK) | ||
624 | { | ||
625 | FREE(proxyHost); | ||
626 | FREE(proxyUserPwd); | ||
627 | FREE(filename); | ||
628 | Scierror(999, _("Failed to set proxy port [%s]\n"), errorBuffer); | ||
629 | return NULL; | ||
630 | } | ||
631 | if (proxyUserPwd != NULL) | ||
632 | { | ||
633 | res = curl_easy_setopt(curl, CURLOPT_PROXYUSERPWD, proxyUserPwd); | ||
634 | if (res != CURLE_OK) | ||
635 | { | ||
636 | FREE(proxyHost); | ||
637 | FREE(proxyUserPwd); | ||
638 | FREE(filename); | ||
639 | Scierror(999, _("Failed to set proxy user:password [%s]\n"), errorBuffer); | ||
640 | return NULL; | ||
641 | } | ||
642 | } | ||
643 | |||
644 | FREE(proxyHost); | ||
645 | FREE(proxyUserPwd); | ||
646 | } | ||
647 | } /* end of the set of the proxy */ | ||
648 | char post_string[1024]; | ||
649 | int i = 0; | ||
650 | while(arguments[i]!=NULL) | ||
651 | { | ||
652 | strcat(post_string,arguments[i]); | ||
653 | strcat(post_string,"="); | ||
654 | strcat(post_string,values[i]); | ||
655 | strcat(post_string,"&"); | ||
656 | i++; | ||
657 | } | ||
658 | post_string[strlen(post_string)-1]=0; | ||
659 | curl_easy_setopt(curl, CURLOPT_POSTFIELDS, post_string); | ||
660 | res = curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writefunc); | ||
661 | if (res != CURLE_OK) | ||
662 | { | ||
663 | FREE(filename); | ||
664 | Scierror(999, _("Failed to set write function [%s]\n"), errorBuffer); | ||
665 | return NULL; | ||
666 | } | ||
667 | |||
668 | //Get data to be written to the variable | ||
669 | res = curl_easy_setopt(curl, CURLOPT_WRITEDATA, &buffer); | ||
670 | if (res != CURLE_OK) | ||
671 | { | ||
672 | FREE(filename); | ||
673 | free_string(&buffer); | ||
674 | Scierror(999, _("Failed to set write data [%s]\n"), errorBuffer); | ||
675 | return NULL; | ||
676 | } | ||
677 | |||
678 | // Follow redirects | ||
679 | res = curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1); | ||
680 | if (res != CURLE_OK) | ||
681 | { | ||
682 | FREE(filename); | ||
683 | free_string(&buffer); | ||
684 | Scierror(999, _("Failed to set 'Follow Location' [%s]\n"), errorBuffer); | ||
685 | return NULL; | ||
686 | } | ||
687 | // curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L); | ||
688 | res = curl_easy_perform(curl); | ||
689 | if (res != 0) | ||
690 | { | ||
691 | FREE(filename); | ||
692 | free_string(&buffer); | ||
693 | Scierror(999, _("Transfer did not complete successfully: %s\n"), errorBuffer); | ||
694 | return NULL; | ||
695 | } | ||
696 | |||
697 | wcfopen(file, (char*)filename, "wb"); | ||
698 | if (file == NULL) | ||
699 | { | ||
700 | Scierror(999, _("Failed opening '%s' for writing.\n"), filename); | ||
701 | FREE(filename); | ||
702 | return NULL; | ||
703 | } | ||
704 | /* Write the file */ | ||
705 | fwrite(buffer.ptr, sizeof(char), buffer.len, file); | ||
706 | *content = buffer.ptr; | ||
707 | |||
708 | /* always cleanup */ | ||
709 | curl_easy_cleanup(curl); | ||
710 | fclose(file); | ||
711 | return filename; | ||
712 | |||
713 | } | ||
453 | static char *Curl_basename(char *path) | 714 | static char *Curl_basename(char *path) |
454 | { | 715 | { |
455 | char *s1 = NULL; | 716 | char *s1 = NULL; |
diff --git a/scilab/modules/fileio/src/c/dlManager.h b/scilab/modules/fileio/src/c/dlManager.h index 8efcf93..37e1851 100644 --- a/scilab/modules/fileio/src/c/dlManager.h +++ b/scilab/modules/fileio/src/c/dlManager.h | |||
@@ -25,5 +25,5 @@ | |||
25 | * @return the file pointer | 25 | * @return the file pointer |
26 | */ | 26 | */ |
27 | char *downloadFile(char *url, char *dest, char *username, char *password, char **content, int header); | 27 | char *downloadFile(char *url, char *dest, char *username, char *password, char **content, int header); |
28 | 28 | char *postFile(char *url, char **arguments, char **values, char *dest, char *username, char *password, char **content); | |
29 | #endif /* __DLMANAGER_H__ */ | 29 | #endif /* __DLMANAGER_H__ */ |
diff --git a/scilab/modules/fileio/tests/unit_tests/postURL.dia.ref b/scilab/modules/fileio/tests/unit_tests/postURL.dia.ref new file mode 100644 index 0000000..d894b0b --- /dev/null +++ b/scilab/modules/fileio/tests/unit_tests/postURL.dia.ref | |||
@@ -0,0 +1,26 @@ | |||
1 | // ============================================================================ | ||
2 | // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab | ||
3 | // Copyright (C) 2015 - Kartik Gupta | ||
4 | // | ||
5 | // This file is distributed under the same license as the Scilab package. | ||
6 | // ============================================================================ | ||
7 | // <-- CLI SHELL MODE --> | ||
8 | // ============================================================================ | ||
9 | // Unitary tests for postURL function | ||
10 | // ============================================================================ | ||
11 | filename = postURL("http://researchweb.iiit.ac.in/~kartik.gupta/index.php",["var1","var2"],["test1","test2"],"test.txt") | ||
12 | filename = | ||
13 | |||
14 | test.txt | ||
15 | assert_checktrue(isfile("test.txt")); | ||
16 | fd = mopen("test.txt"); | ||
17 | assert_checktrue(fd>0); | ||
18 | line = mgetl(fd); | ||
19 | words = strsplit(line," "); | ||
20 | assert_checkequal(length(length(words)),2); | ||
21 | assert_checkequal(words(1),"test1"); | ||
22 | assert_checkequal(words(2),"test2"); | ||
23 | deletefile("test.txt"); | ||
24 | assert_checkerror("postURL(''http://researchweb.iiit.ac.in/~kartik.gupta/index.php'',[''var1'',''var2''],[''test1'']);",[],999); | ||
25 | assert_checkerror("postURL(''http://researchweb.iiit.ac.in/~kartik.gupta/index.php'',[''var1'',''var2''],''test1'');",[],999); | ||
26 | assert_checkerror("postURL(''http://researchweb.iiit.ac.in/~kartik.gupta/index.php'',[''var2''],[''test1'',''test2'']);",[],999); | ||
diff --git a/scilab/modules/fileio/tests/unit_tests/postURL.tst b/scilab/modules/fileio/tests/unit_tests/postURL.tst new file mode 100644 index 0000000..281a9e6 --- /dev/null +++ b/scilab/modules/fileio/tests/unit_tests/postURL.tst | |||
@@ -0,0 +1,29 @@ | |||
1 | // ============================================================================ | ||
2 | // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab | ||
3 | // Copyright (C) 2015 - Kartik Gupta | ||
4 | // | ||
5 | // This file is distributed under the same license as the Scilab package. | ||
6 | // ============================================================================ | ||
7 | |||
8 | // <-- CLI SHELL MODE --> | ||
9 | |||
10 | // ============================================================================ | ||
11 | // Unitary tests for postURL function | ||
12 | // ============================================================================ | ||
13 | |||
14 | filename = postURL("http://researchweb.iiit.ac.in/~kartik.gupta/index.php",["var1","var2"],["test1","test2"],"test.txt") | ||
15 | assert_checktrue(isfile("test.txt")); | ||
16 | fd = mopen("test.txt"); | ||
17 | assert_checktrue(fd>0); | ||
18 | line = mgetl(fd); | ||
19 | words = strsplit(line," "); | ||
20 | assert_checkequal(length(length(words)),2); | ||
21 | assert_checkequal(words(1),"test1"); | ||
22 | assert_checkequal(words(2),"test2"); | ||
23 | deletefile("test.txt"); | ||
24 | |||
25 | assert_checkerror("postURL(''http://researchweb.iiit.ac.in/~kartik.gupta/index.php'',[''var1'',''var2''],[''test1'']);",[],999); | ||
26 | |||
27 | assert_checkerror("postURL(''http://researchweb.iiit.ac.in/~kartik.gupta/index.php'',[''var1'',''var2''],''test1'');",[],999); | ||
28 | |||
29 | assert_checkerror("postURL(''http://researchweb.iiit.ac.in/~kartik.gupta/index.php'',[''var2''],[''test1'',''test2'']);",[],999); | ||