1 /*
2 +----------------------------------------------------------------------+
3 | Copyright (c) The PHP Group |
4 +----------------------------------------------------------------------+
5 | This source file is subject to version 3.01 of the PHP license, |
6 | that is bundled with this package in the file LICENSE, and is |
7 | available through the world-wide-web at the following url: |
8 | http://www.php.net/license/3_01.txt |
9 | If you did not receive a copy of the PHP license and are unable to |
10 | obtain it through the world-wide-web, please send a note to |
11 | license@php.net so we can mail you a copy immediately. |
12 +----------------------------------------------------------------------+
13 | Author: Stanislav Malyshev <stas@php.net> |
14 +----------------------------------------------------------------------+
15 */
16
17 #ifdef HAVE_CONFIG_H
18 # include "config.h"
19 #endif
20
21 #include "php.h"
22 #include "Zend/zend_exceptions.h"
23 #include "Zend/zend_interfaces.h"
24 #include "curl_private.h"
25 #include "curl_file_arginfo.h"
26
27 PHP_CURL_API zend_class_entry *curl_CURLFile_class;
28
curlfile_ctor(INTERNAL_FUNCTION_PARAMETERS)29 static void curlfile_ctor(INTERNAL_FUNCTION_PARAMETERS)
30 {
31 zend_string *fname, *mime = NULL, *postname = NULL;
32 zval *cf = return_value;
33
34 ZEND_PARSE_PARAMETERS_START(1,3)
35 Z_PARAM_PATH_STR(fname)
36 Z_PARAM_OPTIONAL
37 Z_PARAM_STR_OR_NULL(mime)
38 Z_PARAM_STR_OR_NULL(postname)
39 ZEND_PARSE_PARAMETERS_END();
40
41 zend_update_property_string(curl_CURLFile_class, Z_OBJ_P(cf), "name", sizeof("name")-1, ZSTR_VAL(fname));
42
43 if (mime) {
44 zend_update_property_string(curl_CURLFile_class, Z_OBJ_P(cf), "mime", sizeof("mime")-1, ZSTR_VAL(mime));
45 }
46
47 if (postname) {
48 zend_update_property_string(curl_CURLFile_class, Z_OBJ_P(cf), "postname", sizeof("postname")-1, ZSTR_VAL(postname));
49 }
50 }
51
52 /* {{{ Create the CURLFile object */
ZEND_METHOD(CURLFile,__construct)53 ZEND_METHOD(CURLFile, __construct)
54 {
55 return_value = ZEND_THIS;
56 curlfile_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU);
57 }
58 /* }}} */
59
60 /* {{{ Create the CURLFile object */
PHP_FUNCTION(curl_file_create)61 PHP_FUNCTION(curl_file_create)
62 {
63 object_init_ex( return_value, curl_CURLFile_class );
64 curlfile_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU);
65 }
66 /* }}} */
67
curlfile_get_property(char * name,size_t name_len,INTERNAL_FUNCTION_PARAMETERS)68 static void curlfile_get_property(char *name, size_t name_len, INTERNAL_FUNCTION_PARAMETERS)
69 {
70 zval *res, rv;
71
72 ZEND_PARSE_PARAMETERS_NONE();
73 res = zend_read_property(curl_CURLFile_class, Z_OBJ_P(ZEND_THIS), name, name_len, 1, &rv);
74 ZVAL_COPY_DEREF(return_value, res);
75 }
76
curlfile_set_property(char * name,size_t name_len,INTERNAL_FUNCTION_PARAMETERS)77 static void curlfile_set_property(char *name, size_t name_len, INTERNAL_FUNCTION_PARAMETERS)
78 {
79 zend_string *arg;
80
81 ZEND_PARSE_PARAMETERS_START(1,1)
82 Z_PARAM_STR(arg)
83 ZEND_PARSE_PARAMETERS_END();
84
85 zend_update_property_string(curl_CURLFile_class, Z_OBJ_P(ZEND_THIS), name, name_len, ZSTR_VAL(arg));
86 }
87
88 /* {{{ Get file name */
ZEND_METHOD(CURLFile,getFilename)89 ZEND_METHOD(CURLFile, getFilename)
90 {
91 curlfile_get_property("name", sizeof("name")-1, INTERNAL_FUNCTION_PARAM_PASSTHRU);
92 }
93 /* }}} */
94
95 /* {{{ Get MIME type */
ZEND_METHOD(CURLFile,getMimeType)96 ZEND_METHOD(CURLFile, getMimeType)
97 {
98 curlfile_get_property("mime", sizeof("mime")-1, INTERNAL_FUNCTION_PARAM_PASSTHRU);
99 }
100 /* }}} */
101
102 /* {{{ Get file name for POST */
ZEND_METHOD(CURLFile,getPostFilename)103 ZEND_METHOD(CURLFile, getPostFilename)
104 {
105 curlfile_get_property("postname", sizeof("postname")-1, INTERNAL_FUNCTION_PARAM_PASSTHRU);
106 }
107 /* }}} */
108
109 /* {{{ Set MIME type */
ZEND_METHOD(CURLFile,setMimeType)110 ZEND_METHOD(CURLFile, setMimeType)
111 {
112 curlfile_set_property("mime", sizeof("mime")-1, INTERNAL_FUNCTION_PARAM_PASSTHRU);
113 }
114 /* }}} */
115
116 /* {{{ Set file name for POST */
ZEND_METHOD(CURLFile,setPostFilename)117 ZEND_METHOD(CURLFile, setPostFilename)
118 {
119 curlfile_set_property("postname", sizeof("postname")-1, INTERNAL_FUNCTION_PARAM_PASSTHRU);
120 }
121 /* }}} */
122
curlfile_register_class(void)123 void curlfile_register_class(void)
124 {
125 zend_class_entry ce;
126 INIT_CLASS_ENTRY( ce, "CURLFile", class_CURLFile_methods );
127 curl_CURLFile_class = zend_register_internal_class(&ce);
128 curl_CURLFile_class->serialize = zend_class_serialize_deny;
129 curl_CURLFile_class->unserialize = zend_class_unserialize_deny;
130 zend_declare_property_string(curl_CURLFile_class, "name", sizeof("name")-1, "", ZEND_ACC_PUBLIC);
131 zend_declare_property_string(curl_CURLFile_class, "mime", sizeof("mime")-1, "", ZEND_ACC_PUBLIC);
132 zend_declare_property_string(curl_CURLFile_class, "postname", sizeof("postname")-1, "", ZEND_ACC_PUBLIC);
133 }
134