LCOV - code coverage report
Current view: top level - ext/http - php_http_client_response.c (source / functions) Hit Total Coverage
Test: PHP Code Coverage Lines: 52 56 92.9 %
Date: 2015-02-17 20:30:22 Functions: 3 3 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             : ZEND_BEGIN_ARG_INFO_EX(ai_HttpClientResponse_getCookies, 0, 0, 0)
      16             :         ZEND_ARG_INFO(0, flags)
      17             :         ZEND_ARG_INFO(0, allowed_extras)
      18             : ZEND_END_ARG_INFO();
      19           2 : static PHP_METHOD(HttpClientResponse, getCookies)
      20             : {
      21           2 :         long flags = 0;
      22           2 :         zval *allowed_extras_array = NULL;
      23           2 :         int i = 0;
      24           2 :         char **allowed_extras = NULL;
      25           2 :         zval *header = NULL, **entry = NULL;
      26             :         HashPosition pos;
      27             :         php_http_message_object_t *msg;
      28             : 
      29           2 :         if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|la!", &flags, &allowed_extras_array)) {
      30           2 :                 return;
      31             :         }
      32             : 
      33           2 :         msg = zend_object_store_get_object(getThis() TSRMLS_CC);
      34           2 :         array_init(return_value);
      35             : 
      36           2 :         if (allowed_extras_array) {
      37           2 :                 allowed_extras = ecalloc(zend_hash_num_elements(Z_ARRVAL_P(allowed_extras_array)) + 1, sizeof(char *));
      38           4 :                 FOREACH_VAL(pos, allowed_extras_array, entry) {
      39           2 :                         zval *data = php_http_ztyp(IS_STRING, *entry);
      40           2 :                         allowed_extras[i++] = estrndup(Z_STRVAL_P(data), Z_STRLEN_P(data));
      41           2 :                         zval_ptr_dtor(&data);
      42             :                 }
      43             :         }
      44             : 
      45           2 :         if ((header = php_http_message_header(msg->message, ZEND_STRL("Set-Cookie"), 0))) {
      46             :                 php_http_cookie_list_t *list;
      47             : 
      48           2 :                 if (Z_TYPE_P(header) == IS_ARRAY) {
      49             :                         zval **single_header;
      50             : 
      51           3 :                         FOREACH_VAL(pos, header, single_header) {
      52           2 :                                 zval *data = php_http_ztyp(IS_STRING, *single_header);
      53             : 
      54           2 :                                 if ((list = php_http_cookie_list_parse(NULL, Z_STRVAL_P(data), Z_STRLEN_P(data), flags, allowed_extras TSRMLS_CC))) {
      55             :                                         zval *cookie;
      56             : 
      57           2 :                                         MAKE_STD_ZVAL(cookie);
      58           2 :                                         ZVAL_OBJVAL(cookie, php_http_cookie_object_new_ex(php_http_cookie_class_entry, list, NULL TSRMLS_CC), 0);
      59           2 :                                         add_next_index_zval(return_value, cookie);
      60             :                                 }
      61           2 :                                 zval_ptr_dtor(&data);
      62             :                         }
      63             :                 } else {
      64           1 :                         zval *data = php_http_ztyp(IS_STRING, header);
      65           1 :                         if ((list = php_http_cookie_list_parse(NULL, Z_STRVAL_P(data), Z_STRLEN_P(data), flags, allowed_extras TSRMLS_CC))) {
      66             :                                 zval *cookie;
      67             : 
      68           1 :                                 MAKE_STD_ZVAL(cookie);
      69           1 :                                 ZVAL_OBJVAL(cookie, php_http_cookie_object_new_ex(php_http_cookie_class_entry, list, NULL TSRMLS_CC), 0);
      70           1 :                                 add_next_index_zval(return_value, cookie);
      71             :                         }
      72           1 :                         zval_ptr_dtor(&data);
      73             :                 }
      74           2 :                 zval_ptr_dtor(&header);
      75             :         }
      76             : 
      77           2 :         if (allowed_extras) {
      78           4 :                 for (i = 0; allowed_extras[i]; ++i) {
      79           2 :                         efree(allowed_extras[i]);
      80             :                 }
      81           2 :                 efree(allowed_extras);
      82             :         }
      83             : }
      84             : 
      85             : ZEND_BEGIN_ARG_INFO_EX(ai_HttpClientResponse_getTransferInfo, 0, 0, 0)
      86             :         ZEND_ARG_INFO(0, element)
      87             : ZEND_END_ARG_INFO();
      88           3 : static PHP_METHOD(HttpClientResponse, getTransferInfo)
      89             : {
      90           3 :         char *info_name = NULL;
      91           3 :         int info_len = 0;
      92             :         zval *info;
      93             : 
      94           3 :         php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s", &info_name, &info_len), invalid_arg, return);
      95             : 
      96           3 :         info = zend_read_property(php_http_client_response_class_entry, getThis(), ZEND_STRL("transferInfo"), 0 TSRMLS_CC);
      97             : 
      98             :         /* request completed? */
      99           3 :         if (Z_TYPE_P(info) != IS_OBJECT) {
     100           0 :                 php_http_throw(bad_method_call, "Incomplete state", NULL);
     101           0 :                 return;
     102             :         }
     103             : 
     104           3 :         if (info_len && info_name) {
     105           2 :                 info = zend_read_property(NULL, info, php_http_pretty_key(info_name, info_len, 0, 0), info_len, 0 TSRMLS_CC);
     106             : 
     107           2 :                 if (!info) {
     108           0 :                         php_http_throw(unexpected_val, "Could not find transfer info with name '%s'", info_name);
     109           0 :                         return;
     110             :                 }
     111             :         }
     112             : 
     113           3 :         RETURN_ZVAL(info, 1, 0);
     114             : }
     115             : 
     116             : static zend_function_entry php_http_client_response_methods[] = {
     117             :         PHP_ME(HttpClientResponse, getCookies,      ai_HttpClientResponse_getCookies,      ZEND_ACC_PUBLIC)
     118             :         PHP_ME(HttpClientResponse, getTransferInfo, ai_HttpClientResponse_getTransferInfo, ZEND_ACC_PUBLIC)
     119             :         EMPTY_FUNCTION_ENTRY
     120             : };
     121             : 
     122             : zend_class_entry *php_http_client_response_class_entry;
     123             : 
     124         374 : PHP_MINIT_FUNCTION(http_client_response)
     125             : {
     126         374 :         zend_class_entry ce = {0};
     127             : 
     128         374 :         INIT_NS_CLASS_ENTRY(ce, "http\\Client", "Response", php_http_client_response_methods);
     129         374 :         php_http_client_response_class_entry = zend_register_internal_class_ex(&ce, php_http_message_class_entry, NULL TSRMLS_CC);
     130         374 :         zend_declare_property_null(php_http_client_response_class_entry, ZEND_STRL("transferInfo"), ZEND_ACC_PROTECTED TSRMLS_CC);
     131             : 
     132         374 :         return SUCCESS;
     133             : }
     134             : 
     135             : /*
     136             :  * Local variables:
     137             :  * tab-width: 4
     138             :  * c-basic-offset: 4
     139             :  * End:
     140             :  * vim600: noet sw=4 ts=4 fdm=marker
     141             :  * vim<600: noet sw=4 ts=4
     142             :  */
     143             : 

Generated by: LCOV version 1.11