/** {{{ proto Win\Gdi\DeviceContext Win\Gdi\Window::beginPaint(array & paint_data) Prepares the specified window for painting. The paint_data reference variable receives information about the painting. */ PHP_METHOD( WinGdiWindow, beginPaint ) { wingdi_devicecontext_object * dc_object, * dc_object_display; wingdi_window_object * window_object = zend_object_store_get_object( getThis() TSRMLS_CC ); zval * paint_data, * paint_data_rect = NULL, * paint_data_hdc = NULL; PAINTSTRUCT paint_struct; HDC hdc; WINGDI_ERROR_HANDLING(); if ( zend_parse_parameters( ZEND_NUM_ARGS() TSRMLS_CC, "z", &paint_data ) == FAILURE ) return; WINGDI_RESTORE_ERRORS(); hdc = BeginPaint( window_object->window_handle, &paint_struct ); if ( !hdc ) { wingdi_create_error( GetLastError(), ce_wingdi_exception TSRMLS_CC ); return; } // Set up return value for a DC object object_init_ex( return_value, ce_wingdi_devicecontext ); dc_object = ( wingdi_devicecontext_object * ) zend_objects_get_address( return_value TSRMLS_CC ); dc_object->hdc = hdc; dc_object->constructed = 1; // Empty whatever the paint_data zval contains, and store in it the data from paint_struct zval_dtor( paint_data ); array_init( paint_data ); // Set up the hdc element object MAKE_STD_ZVAL( paint_data_hdc ); object_init_ex( paint_data_hdc, ce_wingdi_devicecontext ); dc_object_display = ( wingdi_devicecontext_object * ) zend_objects_get_address( paint_data_hdc TSRMLS_CC ); dc_object_display->hdc = paint_struct.hdc; dc_object_display->constructed = 1; add_assoc_zval( paint_data, "hdc", paint_data_hdc ); add_assoc_bool( paint_data, "erase", paint_struct.fErase ); // paint_struct.rcPaint is a RECT structure which maps to a PHP array MAKE_STD_ZVAL( paint_data_rect ); array_init( paint_data_rect ); add_next_index_long( paint_data_rect, paint_struct.rcPaint.left ); add_next_index_long( paint_data_rect, paint_struct.rcPaint.top ); add_next_index_long( paint_data_rect, paint_struct.rcPaint.right ); add_next_index_long( paint_data_rect, paint_struct.rcPaint.bottom ); add_assoc_zval( paint_data, "paint", paint_data_rect ); }
/* {{{ bool mysqli_warning::next() */ PHP_METHOD(mysqli_warning, next) { MYSQLI_WARNING *w; zval *mysqli_warning; mysqli_object *obj = (mysqli_object *)zend_objects_get_address(getThis() TSRMLS_CC); if (obj->ptr) { if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &mysqli_warning, mysqli_warning_class_entry) == FAILURE) { return; } MYSQLI_FETCH_RESOURCE(w, MYSQLI_WARNING *, &mysqli_warning, "mysqli_warning", MYSQLI_STATUS_VALID); if (w && w->next) { w = w->next; ((MYSQLI_RESOURCE *)(obj->ptr))->ptr = w; RETURN_TRUE; } } RETURN_FALSE; }
/** {{{ proto bool Win\Gdi\Window::endPaint( paint_data ); Marks the end of painting in the specified window. */ PHP_METHOD( WinGdiWindow, endPaint ) { wingdi_devicecontext_object * dc_object; wingdi_window_object * window_object = zend_object_store_get_object( getThis() TSRMLS_CC ); HashTable * paint_data; PAINTSTRUCT paint_struct; WINGDI_ERROR_HANDLING(); if ( zend_parse_parameters( ZEND_NUM_ARGS() TSRMLS_CC, "h", &paint_data ) == FAILURE ) return; WINGDI_RESTORE_ERRORS(); // Error checking // Not sure about the error messages if ( ! zend_hash_exists( paint_data, "hdc", strlen( "hdc" ) + 1 ) ) { php_error( E_ERROR, "no 'hdc' element found in array" ); return; } else if ( ! zend_hash_exists( paint_data, "erase", strlen( "erase" ) + 1 ) ) { php_error( E_ERROR, "no 'erase' element found in array" ); return; } else if ( ! zend_hash_exists( paint_data, "paint", strlen( "paint" ) + 1 ) ) { php_error( E_ERROR, "no 'paint' element found in array" ); return; } else { zval ** hdc_element, ** erase_element, ** paint_element, ** left = NULL, ** top = NULL, ** right = NULL, ** bottom = NULL; HashTable * paint_rect; zend_hash_find( paint_data, "hdc", strlen( "hdc" ) + 1, ( void ** ) &hdc_element ); dc_object = ( wingdi_devicecontext_object * ) zend_objects_get_address( * hdc_element TSRMLS_CC ); paint_struct.hdc = dc_object->hdc; zend_hash_find( paint_data, "erase", strlen( "erase" ) + 1, ( void ** ) &erase_element ); paint_struct.fErase = Z_BVAL_PP( erase_element ); zend_hash_find( paint_data, "paint", strlen( "paint" ) + 1, ( void ** ) &paint_element ); if ( Z_TYPE_PP( paint_element ) != IS_ARRAY || zend_hash_num_elements( Z_ARRVAL_PP( paint_element ) ) < 4 ) { php_error( E_ERROR, "expected an array of for elements for 'paint' element of array" ); return; } paint_rect = Z_ARRVAL_PP( paint_element ); // TODO: error checking zend_hash_index_find( paint_rect, 0, ( void ** ) &left ); zend_hash_index_find( paint_rect, 1, ( void ** ) &top ); zend_hash_index_find( paint_rect, 2, ( void ** ) &right ); zend_hash_index_find( paint_rect, 3, ( void ** ) &bottom ); paint_struct.rcPaint.left = Z_LVAL_PP( left ); paint_struct.rcPaint.top = Z_LVAL_PP( top ); paint_struct.rcPaint.right = Z_LVAL_PP( right ); paint_struct.rcPaint.bottom = Z_LVAL_PP( bottom ); RETURN_BOOL( EndPaint( window_object->window_handle, &paint_struct ) ); } }
/* {{{ php_url_encode_hash */ PHPAPI int php_url_encode_hash_ex(HashTable *ht, smart_str *formstr, const char *num_prefix, int num_prefix_len, const char *key_prefix, int key_prefix_len, const char *key_suffix, int key_suffix_len, zval *type, char *arg_sep, int enc_type TSRMLS_DC) { char *key = NULL; char *ekey, *newprefix, *p; int arg_sep_len, ekey_len, key_type, newprefix_len; uint key_len; ulong idx; zval **zdata = NULL, *copyzval; if (!ht) { return FAILURE; } if (ht->nApplyCount > 0) { /* Prevent recursion */ return SUCCESS; } if (!arg_sep) { arg_sep = INI_STR("arg_separator.output"); if (!arg_sep || !strlen(arg_sep)) { arg_sep = URL_DEFAULT_ARG_SEP; } } arg_sep_len = strlen(arg_sep); for (zend_hash_internal_pointer_reset(ht); (key_type = zend_hash_get_current_key_ex(ht, &key, &key_len, &idx, 0, NULL)) != HASH_KEY_NON_EXISTANT; zend_hash_move_forward(ht) ) { if (key_type == HASH_KEY_IS_STRING && key_len && key[key_len-1] == '\0') { /* We don't want that trailing NULL */ key_len -= 1; } /* handling for private & protected object properties */ if (key && *key == '\0' && type != NULL) { const char *tmp; zend_object *zobj = zend_objects_get_address(type TSRMLS_CC); if (zend_check_property_access(zobj, key, key_len-1 TSRMLS_CC) != SUCCESS) { /* private or protected property access outside of the class */ continue; } zend_unmangle_property_name(key, key_len-1, &tmp, (const char**)&key); key_len = strlen(key); } if (zend_hash_get_current_data_ex(ht, (void **)&zdata, NULL) == FAILURE || !zdata || !(*zdata)) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Error traversing form data array"); return FAILURE; } if (Z_TYPE_PP(zdata) == IS_ARRAY || Z_TYPE_PP(zdata) == IS_OBJECT) { if (key_type == HASH_KEY_IS_STRING) { if (enc_type == PHP_QUERY_RFC3986) { ekey = php_raw_url_encode(key, key_len, &ekey_len); } else { ekey = php_url_encode(key, key_len, &ekey_len); } newprefix_len = key_suffix_len + ekey_len + key_prefix_len + 3 /* %5B */; newprefix = emalloc(newprefix_len + 1); p = newprefix; if (key_prefix) { memcpy(p, key_prefix, key_prefix_len); p += key_prefix_len; } memcpy(p, ekey, ekey_len); p += ekey_len; efree(ekey); if (key_suffix) { memcpy(p, key_suffix, key_suffix_len); p += key_suffix_len; } *(p++) = '%'; *(p++) = '5'; *(p++) = 'B'; *p = '\0'; } else { /* Is an integer key */ ekey_len = spprintf(&ekey, 0, "%ld", idx); newprefix_len = key_prefix_len + num_prefix_len + ekey_len + key_suffix_len + 3 /* %5B */; newprefix = emalloc(newprefix_len + 1); p = newprefix; if (key_prefix) { memcpy(p, key_prefix, key_prefix_len); p += key_prefix_len; } memcpy(p, num_prefix, num_prefix_len); p += num_prefix_len; memcpy(p, ekey, ekey_len); p += ekey_len; efree(ekey); if (key_suffix) { memcpy(p, key_suffix, key_suffix_len); p += key_suffix_len; } *(p++) = '%'; *(p++) = '5'; *(p++) = 'B'; *p = '\0'; } ht->nApplyCount++; php_url_encode_hash_ex(HASH_OF(*zdata), formstr, NULL, 0, newprefix, newprefix_len, "%5D", 3, (Z_TYPE_PP(zdata) == IS_OBJECT ? *zdata : NULL), arg_sep, enc_type TSRMLS_CC); ht->nApplyCount--; efree(newprefix); } else if (Z_TYPE_PP(zdata) == IS_NULL || Z_TYPE_PP(zdata) == IS_RESOURCE) { /* Skip these types */ continue; } else { if (formstr->len) { smart_str_appendl(formstr, arg_sep, arg_sep_len); } /* Simple key=value */ smart_str_appendl(formstr, key_prefix, key_prefix_len); if (key_type == HASH_KEY_IS_STRING) { if (enc_type == PHP_QUERY_RFC3986) { ekey = php_raw_url_encode(key, key_len, &ekey_len); } else { ekey = php_url_encode(key, key_len, &ekey_len); } smart_str_appendl(formstr, ekey, ekey_len); efree(ekey); } else { /* Numeric key */ if (num_prefix) { smart_str_appendl(formstr, num_prefix, num_prefix_len); } ekey_len = spprintf(&ekey, 0, "%ld", idx); smart_str_appendl(formstr, ekey, ekey_len); efree(ekey); } smart_str_appendl(formstr, key_suffix, key_suffix_len); smart_str_appendl(formstr, "=", 1); switch (Z_TYPE_PP(zdata)) { case IS_STRING: if (enc_type == PHP_QUERY_RFC3986) { ekey = php_raw_url_encode(Z_STRVAL_PP(zdata), Z_STRLEN_PP(zdata), &ekey_len); } else { ekey = php_url_encode(Z_STRVAL_PP(zdata), Z_STRLEN_PP(zdata), &ekey_len); } break; case IS_LONG: case IS_BOOL: ekey_len = spprintf(&ekey, 0, "%ld", Z_LVAL_PP(zdata)); break; case IS_DOUBLE: ekey_len = spprintf(&ekey, 0, "%.*G", (int) EG(precision), Z_DVAL_PP(zdata)); break; default: /* fall back on convert to string */ MAKE_STD_ZVAL(copyzval); *copyzval = **zdata; zval_copy_ctor(copyzval); convert_to_string_ex(©zval); if (enc_type == PHP_QUERY_RFC3986) { ekey = php_raw_url_encode(Z_STRVAL_P(copyzval), Z_STRLEN_P(copyzval), &ekey_len); } else { ekey = php_url_encode(Z_STRVAL_P(copyzval), Z_STRLEN_P(copyzval), &ekey_len); } zval_ptr_dtor(©zval); } smart_str_appendl(formstr, ekey, ekey_len); efree(ekey); } } return SUCCESS; }