LCOV - code coverage report
Current view: top level - ext/http - php_http_object.c (source / functions) Hit Total Coverage
Test: PHP Code Coverage Lines: 56 60 93.3 %
Date: 2015-02-17 20:30:22 Functions: 7 7 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :     +--------------------------------------------------------------------+
       3             :     | PECL :: http                                                       |
       4             :     +--------------------------------------------------------------------+
       5             :     | Redistribution and use in source and binary forms, with or without |
       6             :     | modification, are permitted provided that the conditions mentioned |
       7             :     | in the accompanying LICENSE file are met.                          |
       8             :     +--------------------------------------------------------------------+
       9             :     | Copyright (c) 2004-2014, Michael Wallner <mike@php.net>            |
      10             :     +--------------------------------------------------------------------+
      11             : */
      12             : 
      13             : #include "php_http_api.h"
      14             : 
      15          70 : zend_object_value php_http_object_new(zend_class_entry *ce TSRMLS_DC)
      16             : {
      17          70 :         return php_http_object_new_ex(ce, NULL, NULL TSRMLS_CC);
      18             : }
      19             : 
      20          70 : zend_object_value php_http_object_new_ex(zend_class_entry *ce, void *nothing, php_http_object_t **ptr TSRMLS_DC)
      21             : {
      22             :         php_http_object_t *o;
      23             : 
      24          70 :         o = ecalloc(1, sizeof(php_http_object_t));
      25          70 :         zend_object_std_init((zend_object *) o, ce TSRMLS_CC);
      26          70 :         object_properties_init((zend_object *) o, ce);
      27             : 
      28          70 :         if (ptr) {
      29           0 :                 *ptr = o;
      30             :         }
      31             : 
      32          70 :         o->zv.handle = zend_objects_store_put(o, NULL, (zend_objects_free_object_storage_t) zend_objects_free_object_storage, NULL TSRMLS_CC);
      33          70 :         o->zv.handlers = zend_get_std_object_handlers();
      34             : 
      35          70 :         return o->zv;
      36             : }
      37             : 
      38          21 : STATUS php_http_new(zend_object_value *ovp, zend_class_entry *ce, php_http_new_t create, zend_class_entry *parent_ce, void *intern_ptr, void **obj_ptr TSRMLS_DC)
      39             : {
      40             :         zend_object_value ov;
      41             : 
      42          21 :         if (!ce) {
      43           0 :                 ce = parent_ce;
      44          21 :         } else if (parent_ce && !instanceof_function(ce, parent_ce TSRMLS_CC)) {
      45           0 :                 php_http_throw(unexpected_val, "Class %s does not extend %s", ce->name, parent_ce->name);
      46           0 :                 return FAILURE;
      47             :         }
      48             : 
      49          21 :         ov = create(ce, intern_ptr, obj_ptr TSRMLS_CC);
      50          21 :         if (ovp) {
      51           3 :                 *ovp = ov;
      52             :         }
      53          21 :         return SUCCESS;
      54             : }
      55             : 
      56          42 : php_http_object_method_t *php_http_object_method_init(php_http_object_method_t *cb, zval *zobject, const char *method_str, size_t method_len TSRMLS_DC)
      57             : {
      58             :         zval *zfn;
      59             : 
      60          42 :         if (!cb) {
      61           2 :                 cb = ecalloc(1, sizeof(*cb));
      62             :         } else {
      63          40 :                 memset(cb, 0, sizeof(*cb));
      64             :         }
      65             : 
      66          42 :         MAKE_STD_ZVAL(zfn);
      67          42 :         ZVAL_STRINGL(zfn, method_str, method_len, 1);
      68             : 
      69          42 :         cb->fci.size = sizeof(cb->fci);
      70          42 :         cb->fci.function_name = zfn;
      71          42 :         cb->fcc.initialized = 1;
      72          42 :         cb->fcc.calling_scope = cb->fcc.called_scope = Z_OBJCE_P(zobject);
      73          42 :         cb->fcc.function_handler = Z_OBJ_HT_P(zobject)->get_method(&zobject, Z_STRVAL_P(cb->fci.function_name), Z_STRLEN_P(cb->fci.function_name), NULL TSRMLS_CC);
      74             : 
      75          42 :         return cb;
      76             : }
      77             : 
      78          43 : void php_http_object_method_dtor(php_http_object_method_t *cb)
      79             : {
      80          43 :         if (cb->fci.function_name) {
      81          42 :                 zval_ptr_dtor(&cb->fci.function_name);
      82          42 :                 cb->fci.function_name = NULL;
      83             :         }
      84          43 : }
      85             : 
      86          41 : void php_http_object_method_free(php_http_object_method_t **cb)
      87             : {
      88          41 :         if (*cb) {
      89           2 :                 php_http_object_method_dtor(*cb);
      90           2 :                 efree(*cb);
      91           2 :                 *cb = NULL;
      92             :         }
      93          41 : }
      94             : 
      95       16926 : STATUS php_http_object_method_call(php_http_object_method_t *cb, zval *zobject, zval **retval_ptr, int argc, zval ***args TSRMLS_DC)
      96             : {
      97             :         STATUS rv;
      98       16926 :         zval *retval = NULL;
      99             : 
     100       16926 :         Z_ADDREF_P(zobject);
     101       16926 :         cb->fci.object_ptr = zobject;
     102       16926 :         cb->fcc.object_ptr = zobject;
     103             : 
     104       16926 :         cb->fci.retval_ptr_ptr = retval_ptr ? retval_ptr : &retval;
     105             : 
     106       16926 :         cb->fci.param_count = argc;
     107       16926 :         cb->fci.params = args;
     108             : 
     109       16926 :         if (cb->fcc.called_scope != Z_OBJCE_P(zobject)) {
     110          17 :                 cb->fcc.called_scope = Z_OBJCE_P(zobject);
     111          17 :                 cb->fcc.function_handler = Z_OBJ_HT_P(zobject)->get_method(&zobject, Z_STRVAL_P(cb->fci.function_name), Z_STRLEN_P(cb->fci.function_name), NULL TSRMLS_CC);
     112             :         }
     113             : 
     114       16926 :         rv = zend_call_function(&cb->fci, &cb->fcc TSRMLS_CC);
     115             : 
     116       16926 :         zval_ptr_dtor(&zobject);
     117       16926 :         if (!retval_ptr && retval) {
     118       16926 :                 zval_ptr_dtor(&retval);
     119             :         }
     120             : 
     121       16926 :         return rv;
     122             : }
     123             : 
     124             : /*
     125             :  * Local variables:
     126             :  * tab-width: 4
     127             :  * c-basic-offset: 4
     128             :  * End:
     129             :  * vim600: noet sw=4 ts=4 fdm=marker
     130             :  * vim<600: noet sw=4 ts=4
     131             :  */
     132             : 

Generated by: LCOV version 1.11