PHP  
 PHP: Test and Code Coverage Analysis
downloads | QA | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | my php.net 
 

LCOV - code coverage report
Current view: top level - ext/curl - curl_file.c (source / functions) Hit Total Coverage
Test: PHP Code Coverage Lines: 52 55 94.5 %
Date: 2014-10-14 Functions: 12 12 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :    +----------------------------------------------------------------------+
       3             :    | PHP Version 7                                                        |
       4             :    +----------------------------------------------------------------------+
       5             :    | Copyright (c) 1997-2014 The PHP Group                                |
       6             :    +----------------------------------------------------------------------+
       7             :    | This source file is subject to version 3.01 of the PHP license,      |
       8             :    | that is bundled with this package in the file LICENSE, and is        |
       9             :    | available through the world-wide-web at the following url:           |
      10             :    | http://www.php.net/license/3_01.txt                                  |
      11             :    | If you did not receive a copy of the PHP license and are unable to   |
      12             :    | obtain it through the world-wide-web, please send a note to          |
      13             :    | license@php.net so we can mail you a copy immediately.               |
      14             :    +----------------------------------------------------------------------+
      15             :    | Author: Stanislav Malyshev <stas@php.net>                            |
      16             :    +----------------------------------------------------------------------+
      17             :  */
      18             : 
      19             : /* $Id$ */
      20             : 
      21             : #ifdef HAVE_CONFIG_H
      22             : # include "config.h"
      23             : #endif
      24             : 
      25             : #include "php.h"
      26             : #include "Zend/zend_exceptions.h"
      27             : #include "php_curl.h"
      28             : #if HAVE_CURL
      29             : 
      30             : PHP_CURL_API zend_class_entry *curl_CURLFile_class;
      31             : 
      32          10 : static void curlfile_ctor(INTERNAL_FUNCTION_PARAMETERS)
      33             : {
      34          10 :         char *fname = NULL, *mime = NULL, *postname = NULL;
      35             :         size_t fname_len, mime_len, postname_len;
      36          10 :         zval *cf = return_value;
      37             : 
      38          10 :         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|ss", &fname, &fname_len, &mime, &mime_len, &postname, &postname_len) == FAILURE) {
      39           0 :                 return;
      40             :         }
      41             : 
      42          10 :         if (fname) {
      43          10 :                 zend_update_property_string(curl_CURLFile_class, cf, "name", sizeof("name")-1, fname TSRMLS_CC);
      44             :         }
      45             : 
      46          10 :         if (mime) {
      47           6 :                 zend_update_property_string(curl_CURLFile_class, cf, "mime", sizeof("mime")-1, mime TSRMLS_CC);
      48             :         }
      49             : 
      50          10 :         if (postname) {
      51           4 :                 zend_update_property_string(curl_CURLFile_class, cf, "postname", sizeof("postname")-1, postname TSRMLS_CC);
      52             :         }
      53             : }
      54             : 
      55             : /* {{{ proto void CURLFile::__construct(string $name, [string $mimetype [, string $postfilename]])
      56             :    Create the CURLFile object */
      57           5 : ZEND_METHOD(CURLFile, __construct)
      58             : {
      59           5 :         return_value = getThis();
      60           5 :         curlfile_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU);
      61           5 : }
      62             : /* }}} */
      63             : 
      64             : /* {{{ proto CURLFile curl_file_create(string $name, [string $mimetype [, string $postfilename]])
      65             :    Create the CURLFile object */
      66           5 : PHP_FUNCTION(curl_file_create)
      67             : {
      68           5 :     object_init_ex( return_value, curl_CURLFile_class );
      69           5 :     curlfile_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU);
      70           5 : }
      71             : /* }}} */
      72             : 
      73           3 : static void curlfile_get_property(char *name, INTERNAL_FUNCTION_PARAMETERS)
      74             : {
      75             :         zval *res;
      76           3 :         if (zend_parse_parameters_none() == FAILURE) {
      77           0 :                 return;
      78             :         }
      79           3 :         res = zend_read_property(curl_CURLFile_class, getThis(), name, strlen(name), 1 TSRMLS_CC);
      80           9 :         RETURN_ZVAL(res, 1, 0);
      81             : }
      82             : 
      83           2 : static void curlfile_set_property(char *name, INTERNAL_FUNCTION_PARAMETERS)
      84             : {
      85           2 :         char *arg = NULL;
      86             :         size_t arg_len;
      87             : 
      88           2 :         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &arg, &arg_len) == FAILURE) {
      89           0 :                 return;
      90             :         }
      91           2 :         zend_update_property_string(curl_CURLFile_class, getThis(), name, strlen(name), arg TSRMLS_CC);
      92             : }
      93             : 
      94             : /* {{{ proto string CURLFile::getFilename()
      95             :    Get file name */
      96           1 : ZEND_METHOD(CURLFile, getFilename)
      97             : {
      98           1 :         curlfile_get_property("name", INTERNAL_FUNCTION_PARAM_PASSTHRU);
      99           1 : }
     100             : /* }}} */
     101             : 
     102             : /* {{{ proto string CURLFile::getMimeType()
     103             :    Get MIME type */
     104           1 : ZEND_METHOD(CURLFile, getMimeType)
     105             : {
     106           1 :         curlfile_get_property("mime", INTERNAL_FUNCTION_PARAM_PASSTHRU);
     107           1 : }
     108             : /* }}} */
     109             : 
     110             : /* {{{ proto string CURLFile::getPostFilename()
     111             :    Get file name for POST */
     112           1 : ZEND_METHOD(CURLFile, getPostFilename)
     113             : {
     114           1 :         curlfile_get_property("postname", INTERNAL_FUNCTION_PARAM_PASSTHRU);
     115           1 : }
     116             : /* }}} */
     117             : 
     118             : /* {{{ proto void CURLFile::setMimeType(string $mime)
     119             :    Set MIME type */
     120           1 : ZEND_METHOD(CURLFile, setMimeType)
     121             : {
     122           1 :         curlfile_set_property("mime", INTERNAL_FUNCTION_PARAM_PASSTHRU);
     123           1 : }
     124             : /* }}} */
     125             : 
     126             : /* {{{ proto void CURLFile::setPostFilename(string $name)
     127             :    Set file name for POST */
     128           1 : ZEND_METHOD(CURLFile, setPostFilename)
     129             : {
     130           1 :         curlfile_set_property("postname", INTERNAL_FUNCTION_PARAM_PASSTHRU);
     131           1 : }
     132             : /* }}} */
     133             : 
     134             : /* {{{ proto void CURLFile::__wakeup()
     135             :    Unserialization handler */
     136           1 : ZEND_METHOD(CURLFile, __wakeup)
     137             : {
     138           1 :         zend_update_property_string(curl_CURLFile_class, getThis(), "name", sizeof("name")-1, "" TSRMLS_CC);
     139           1 :         zend_throw_exception(NULL, "Unserialization of CURLFile instances is not allowed", 0 TSRMLS_CC);
     140           1 : }
     141             : /* }}} */
     142             : 
     143             : ZEND_BEGIN_ARG_INFO_EX(arginfo_curlfile_create, 0, 0, 1)
     144             :         ZEND_ARG_INFO(0, filename)
     145             :         ZEND_ARG_INFO(0, mimetype)
     146             :         ZEND_ARG_INFO(0, postname)
     147             : ZEND_END_ARG_INFO()
     148             : 
     149             : ZEND_BEGIN_ARG_INFO(arginfo_curlfile_name, 0)
     150             :         ZEND_ARG_INFO(0, name)
     151             : ZEND_END_ARG_INFO()
     152             : 
     153             : 
     154             : static const zend_function_entry curlfile_funcs[] = {
     155             :         PHP_ME(CURLFile,                        __construct,        arginfo_curlfile_create, ZEND_ACC_CTOR|ZEND_ACC_PUBLIC)
     156             :         PHP_ME(CURLFile,                        getFilename,        NULL, ZEND_ACC_PUBLIC)
     157             :         PHP_ME(CURLFile,                        getMimeType,        NULL, ZEND_ACC_PUBLIC)
     158             :         PHP_ME(CURLFile,                        setMimeType,        arginfo_curlfile_name, ZEND_ACC_PUBLIC)
     159             :         PHP_ME(CURLFile,                        getPostFilename,    NULL, ZEND_ACC_PUBLIC)
     160             :         PHP_ME(CURLFile,                        setPostFilename,    arginfo_curlfile_name, ZEND_ACC_PUBLIC)
     161             :         PHP_ME(CURLFile,            __wakeup,           NULL, ZEND_ACC_PUBLIC)
     162             :         PHP_FE_END
     163             : };
     164             : 
     165       20401 : void curlfile_register_class(TSRMLS_D)
     166             : {
     167             :         zend_class_entry ce;
     168       20401 :         INIT_CLASS_ENTRY( ce, "CURLFile", curlfile_funcs );
     169       20401 :         curl_CURLFile_class = zend_register_internal_class(&ce TSRMLS_CC);
     170       20401 :         zend_declare_property_string(curl_CURLFile_class, "name", sizeof("name")-1, "", ZEND_ACC_PUBLIC TSRMLS_CC);
     171       20401 :         zend_declare_property_string(curl_CURLFile_class, "mime", sizeof("mime")-1, "", ZEND_ACC_PUBLIC TSRMLS_CC);
     172       20401 :         zend_declare_property_string(curl_CURLFile_class, "postname", sizeof("postname")-1, "", ZEND_ACC_PUBLIC TSRMLS_CC);
     173       20401 : }
     174             : 
     175             : #endif

Generated by: LCOV version 1.10

Generated at Tue, 14 Oct 2014 07:25:38 +0000 (7 days ago)

Copyright © 2005-2014 The PHP Group
All rights reserved.