+PHP_HTTP_API zend_bool php_http_message_is_multipart(php_http_message_t *msg, char **boundary)
+{
+ zval *ct = php_http_message_header(msg, ZEND_STRL("Content-Type"), 1);
+ zend_bool is_multipart = 0;
+ TSRMLS_FETCH_FROM_CTX(msg->ts);
+
+ if (ct) {
+ php_http_params_opts_t popts;
+ HashTable params;
+
+ ZEND_INIT_SYMTABLE(¶ms);
+ php_http_params_opts_default_get(&popts);
+ popts.input.str = Z_STRVAL_P(ct);
+ popts.input.len = Z_STRLEN_P(ct);
+
+ if (php_http_params_parse(¶ms, &popts TSRMLS_CC)) {
+ zval **cur, **arg;
+ char *ct_str;
+
+ zend_hash_internal_pointer_reset(¶ms);
+
+ if (SUCCESS == zend_hash_get_current_data(¶ms, (void *) &cur)
+ && Z_TYPE_PP(cur) == IS_ARRAY
+ && HASH_KEY_IS_STRING == zend_hash_get_current_key(¶ms, &ct_str, NULL, 0)
+ ) {
+ if (php_http_match(ct_str, "multipart", PHP_HTTP_MATCH_WORD)) {
+ is_multipart = 1;
+
+ /* get boundary */
+ if (boundary
+ && SUCCESS == zend_hash_find(Z_ARRVAL_PP(cur), ZEND_STRS("arguments"), (void *) &arg)
+ && Z_TYPE_PP(arg) == IS_ARRAY
+ ) {
+ zval **val;
+ HashPosition pos;
+ php_http_array_hashkey_t key = php_http_array_hashkey_init(0);
+
+ FOREACH_KEYVAL(pos, *arg, key, val) {
+ if (key.type == HASH_KEY_IS_STRING && !strcasecmp(key.str, "boundary")) {
+ zval *bnd = php_http_ztyp(IS_STRING, *val);
+
+ if (Z_STRLEN_P(bnd)) {
+ *boundary = estrndup(Z_STRVAL_P(bnd), Z_STRLEN_P(bnd));
+ }
+ zval_ptr_dtor(&bnd);
+ }
+ }
+ }
+ }
+ }
+ }
+ zend_hash_destroy(¶ms);
+ zval_ptr_dtor(&ct);
+ }
+
+ return is_multipart;
+}