本文整理汇总了C++中FG函数的典型用法代码示例。如果您正苦于以下问题:C++ FG函数的具体用法?C++ FG怎么用?C++ FG使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了FG函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: resize
static void
resize(void)
{
/* Get terminal dimensions */
ioctl(0, TIOCGWINSZ, &w);
/* Clear, move to top separator and set color */
printf(CLEAR_FULL MOVE(2, 1) FG(239));
/* Draw upper separator */
for (int i = 0; i < w.ws_col; i++)
printf("―");
/* Draw bottom bar, set color back to default */
printf(MOVE(%d, 1) " >>> " FG(250), w.ws_row);
/* Mark all buffers as resized for next draw */
rirc->resized = 1;
channel *c = ccur;
do {
c->resized = 1;
} while ((c = channel_switch(c, 1)) != ccur);
/* Draw everything else */
draw(D_FULL);
}
示例2: php_stream_filter_register_factory_volatile
/* API for registering VOLATILE wrappers */
PHPAPI int php_stream_filter_register_factory_volatile(const char *filterpattern, php_stream_filter_factory *factory)
{
if (!FG(stream_filters)) {
ALLOC_HASHTABLE(FG(stream_filters));
zend_hash_init(FG(stream_filters), zend_hash_num_elements(&stream_filters_hash), NULL, NULL, 1);
zend_hash_copy(FG(stream_filters), &stream_filters_hash, NULL);
}
return zend_hash_str_add_ptr(FG(stream_filters), (char*)filterpattern, strlen(filterpattern), factory) ? SUCCESS : FAILURE;
}
示例3: resize
void
resize(void)
{
/* Get terminal dimensions */
ioctl(0, TIOCGWINSZ, &w);
/* Clear, set separator color, move to top separator */
printf(CLEAR_FULL FG(239) MOVE(2, 1));
/* Draw upper separator */
for (i = 0; i < w.ws_col; i++)
printf("―");
/* Draw bottom bar, set color back to default */
printf(MOVE(%d, 1)" >>> " FG(250), w.ws_row);
/* Draw everything else */
draw(D_FULL);
}
示例4: drawmenu
void
drawmenu(void) {
int curpos;
Item *item;
dc->x = 0;
dc->y = 0;
dc->h = bh;
drawrect(dc, 0, 0, mw, mh, True, BG(dc, normcol));
if(prompt && *prompt) {
dc->w = promptw;
drawtext(dc, prompt, selcol);
dc->x = dc->w;
}
/* draw input field */
dc->w = (lines > 0 || !matches) ? mw - dc->x : inputw;
drawtext(dc, text, normcol);
if((curpos = textnw(dc, text, cursor) + dc->h/2 - 2) < dc->w)
drawrect(dc, curpos, 2, 1, dc->h - 4, True, FG(dc, normcol));
/* // Draw hits */
dc->w = textw(dc, hitstxt);
dc->x = mw - dc->w;
drawtext(dc, hitstxt, selcol);
dc->x = 0;
if(lines > 0) {
/* draw vertical list */
dc->w = mw - dc->x;
for(item = curr; item != next; item = item->right) {
dc->y += dc->h;
drawtext(dc, item->text, (item == sel) ? selcol :
(item->out) ? outcol : normcol);
}
}
else if(matches) {
/* draw horizontal list */
dc->x += inputw;
dc->w = textw(dc, "<");
if(curr->left)
drawtext(dc, "<", normcol);
for(item = curr; item != next; item = item->right) {
dc->x += dc->w;
dc->w = MIN(textw(dc, item->text), mw - dc->x - textw(dc, ">"));
drawtext(dc, item->text, (item == sel) ? selcol :
(item->out) ? outcol : normcol);
}
dc->w = textw(dc, ">");
dc->x = mw - dc->w;
if(next)
drawtext(dc, ">", normcol);
}
mapdc(dc, win, mw, mh);
}
示例5: FG
/* We allow very simple pattern matching for filter factories:
* if "convert.charset.utf-8/sjis" is requested, we search first for an exact
* match. If that fails, we try "convert.charset.*", then "convert.*"
* This means that we don't need to clog up the hashtable with a zillion
* charsets (for example) but still be able to provide them all as filters */
PHPAPI php_stream_filter *php_stream_filter_create(const char *filtername, zval *filterparams, uint8_t persistent)
{
HashTable *filter_hash = (FG(stream_filters) ? FG(stream_filters) : &stream_filters_hash);
php_stream_filter_factory *factory = NULL;
php_stream_filter *filter = NULL;
size_t n;
char *period;
n = strlen(filtername);
if (NULL != (factory = zend_hash_str_find_ptr(filter_hash, filtername, n))) {
filter = factory->create_filter(filtername, filterparams, persistent);
} else if ((period = strrchr(filtername, '.'))) {
/* try a wildcard */
char *wildname;
wildname = emalloc(n+3);
memcpy(wildname, filtername, n+1);
period = wildname + (period - filtername);
while (period && !filter) {
*period = '\0';
strncat(wildname, ".*", 2);
if (NULL != (factory = zend_hash_str_find_ptr(filter_hash, wildname, strlen(wildname)))) {
filter = factory->create_filter(filtername, filterparams, persistent);
}
*period = '\0';
period = strrchr(wildname, '.');
}
efree(wildname);
}
if (filter == NULL) {
/* TODO: these need correct docrefs */
if (factory == NULL)
php_error_docref(NULL, E_WARNING, "unable to locate filter \"%s\"", filtername);
else
php_error_docref(NULL, E_WARNING, "unable to create or locate filter \"%s\"", filtername);
}
return filter;
}
示例6: drawtextn
void
drawtextn(DC *dc, const char *text, size_t n, unsigned long col[ColLast]) {
int x = dc->x + dc->font.height/2;
int y = dc->y + dc->font.ascent+1;
XSetForeground(dc->dpy, dc->gc, FG(dc, col));
if(dc->font.set)
XmbDrawString(dc->dpy, dc->canvas, dc->font.set, dc->gc, x, y, text, n);
else {
XSetFont(dc->dpy, dc->gc, dc->font.xfont->fid);
XDrawString(dc->dpy, dc->canvas, dc->gc, x, y, text, n);
}
}
示例7: print_line
int
print_line(int row, line *l)
{
if (l < ccur->chat)
l += SCROLLBACK_BUFFER;
if (!l->len || l == ccur->cur_line)
return 3;
int count = 1;
char *ptr1, *ptr2, *wrap;
ptr1 = l->text;
ptr2 = l->text + l->len;
while ((ptr1 = word_wrap(ptr1, ptr2)) != NULL && ptr1 != ptr2)
count++;
if (row - count > 2)
row = print_line(row - count, l - 1) + count - 1;
ptr1 = l->text;
if ((wrap = word_wrap(ptr1, ptr2)) != NULL)
row = print_more(wrap, ptr2, row);
else
wrap = ptr2;
int from_fg;
char *from_bg = "";
if (l->type == LINE_JOIN || l->type == LINE_PART || l->type == LINE_QUIT)
from_fg = 239;
else if (l->type == LINE_PINGED)
from_fg = 255, from_bg = BG(1);
else
from_fg = nick_col(l->from);
if (row > 2) {
printf("\x1b[%d;1H\x1b[2K", row);
printf(FG(239)" %02d:%02d %*s"FG(%d)"%s%s"BG_R FG(239)" ~ "FG(250),
l->time_h, l->time_m,
(int)(ccur->nick_pad - strlen(l->from)), "",
from_fg, from_bg, l->from);
while (ptr1 < wrap)
putchar(*ptr1++);
}
示例8: sapi_cli_select
static inline int sapi_cli_select(int fd)
{
fd_set wfd, dfd;
struct timeval tv;
int ret;
FD_ZERO(&wfd);
FD_ZERO(&dfd);
PHP_SAFE_FD_SET(fd, &wfd);
tv.tv_sec = (long)FG(default_socket_timeout);
tv.tv_usec = 0;
ret = php_select(fd+1, &dfd, &wfd, &dfd, &tv);
return ret != -1;
}
示例9: FG
/* {{{ php_ssh2_session_connect
* Connect to an SSH server with requested methods
*/
LIBSSH2_SESSION *php_ssh2_session_connect(char *host, int port, zval *methods, zval *callbacks)
{
LIBSSH2_SESSION *session;
int socket;
php_ssh2_session_data *data;
struct timeval tv;
zend_string *hash_lookup_zstring;
tv.tv_sec = FG(default_socket_timeout);
tv.tv_usec = 0;
socket = php_network_connect_socket_to_host(host, port, SOCK_STREAM, 0, &tv, NULL, NULL, NULL, 0, STREAM_SOCKOP_NONE);
if (socket <= 0) {
php_error_docref(NULL, E_WARNING, "Unable to connect to %s on port %d", host, port);
return NULL;
}
data = ecalloc(1, sizeof(php_ssh2_session_data));
data->socket = socket;
session = libssh2_session_init_ex(php_ssh2_alloc_cb, php_ssh2_free_cb, php_ssh2_realloc_cb, data);
if (!session) {
php_error_docref(NULL, E_WARNING, "Unable to initialize SSH2 session");
efree(data);
closesocket(socket);
return NULL;
}
libssh2_banner_set(session, LIBSSH2_SSH_DEFAULT_BANNER " PHP");
/* Override method preferences */
if (methods) {
zval *container;
if (php_ssh2_set_method(session, HASH_OF(methods), "kex", sizeof("kex") - 1, LIBSSH2_METHOD_KEX)) {
php_error_docref(NULL, E_WARNING, "Failed overriding KEX method");
}
if (php_ssh2_set_method(session, HASH_OF(methods), "hostkey", sizeof("hostkey") - 1, LIBSSH2_METHOD_HOSTKEY)) {
php_error_docref(NULL, E_WARNING, "Failed overriding HOSTKEY method");
}
hash_lookup_zstring = zend_string_init("client_to_server", sizeof("client_to_server") - 1, 0);
if ((container = zend_hash_find(HASH_OF(methods), hash_lookup_zstring)) != NULL && Z_TYPE_P(container) == IS_ARRAY) {
if (php_ssh2_set_method(session, HASH_OF(container), "crypt", sizeof("crypt") - 1, LIBSSH2_METHOD_CRYPT_CS)) {
php_error_docref(NULL, E_WARNING, "Failed overriding client to server CRYPT method");
}
if (php_ssh2_set_method(session, HASH_OF(container), "mac", sizeof("mac") - 1, LIBSSH2_METHOD_MAC_CS)) {
php_error_docref(NULL, E_WARNING, "Failed overriding client to server MAC method");
}
if (php_ssh2_set_method(session, HASH_OF(container), "comp", sizeof("comp") - 1, LIBSSH2_METHOD_COMP_CS)) {
php_error_docref(NULL, E_WARNING, "Failed overriding client to server COMP method");
}
if (php_ssh2_set_method(session, HASH_OF(container), "lang", sizeof("lang") - 1, LIBSSH2_METHOD_LANG_CS)) {
php_error_docref(NULL, E_WARNING, "Failed overriding client to server LANG method");
}
}
zend_string_release(hash_lookup_zstring);
hash_lookup_zstring = zend_string_init("server_to_client", sizeof("server_to_client") - 1, 0);
if ((container = zend_hash_find(HASH_OF(methods), hash_lookup_zstring)) != NULL && Z_TYPE_P(container) == IS_ARRAY) {
if (php_ssh2_set_method(session, HASH_OF(container), "crypt", sizeof("crypt") - 1, LIBSSH2_METHOD_CRYPT_SC)) {
php_error_docref(NULL, E_WARNING, "Failed overriding server to client CRYPT method");
}
if (php_ssh2_set_method(session, HASH_OF(container), "mac", sizeof("mac") - 1, LIBSSH2_METHOD_MAC_SC)) {
php_error_docref(NULL, E_WARNING, "Failed overriding server to client MAC method");
}
if (php_ssh2_set_method(session, HASH_OF(container), "comp", sizeof("comp") - 1, LIBSSH2_METHOD_COMP_SC)) {
php_error_docref(NULL, E_WARNING, "Failed overriding server to client COMP method");
}
if (php_ssh2_set_method(session, HASH_OF(container), "lang", sizeof("lang") - 1, LIBSSH2_METHOD_LANG_SC)) {
php_error_docref(NULL, E_WARNING, "Failed overriding server to client LANG method");
}
}
zend_string_release(hash_lookup_zstring);
}
/* Register Callbacks */
if (callbacks) {
/* ignore debug disconnect macerror */
if (php_ssh2_set_callback(session, HASH_OF(callbacks), "ignore", sizeof("ignore") - 1, LIBSSH2_CALLBACK_IGNORE, data)) {
php_error_docref(NULL, E_WARNING, "Failed setting IGNORE callback");
}
if (php_ssh2_set_callback(session, HASH_OF(callbacks), "debug", sizeof("debug") - 1, LIBSSH2_CALLBACK_DEBUG, data)) {
php_error_docref(NULL, E_WARNING, "Failed setting DEBUG callback");
}
if (php_ssh2_set_callback(session, HASH_OF(callbacks), "macerror", sizeof("macerror") - 1, LIBSSH2_CALLBACK_MACERROR, data)) {
php_error_docref(NULL, E_WARNING, "Failed setting MACERROR callback");
}
if (php_ssh2_set_callback(session, HASH_OF(callbacks), "disconnect", sizeof("disconnect") - 1, LIBSSH2_CALLBACK_DISCONNECT, data)) {
php_error_docref(NULL, E_WARNING, "Failed setting DISCONNECT callback");
}
}
//.........这里部分代码省略.........
示例10: php_stream_wrapper_log_error
php_stream *php_stream_url_wrap_http_ex(php_stream_wrapper *wrapper,
const char *path, const char *mode, int options, char **opened_path,
php_stream_context *context, int redirect_max, int flags STREAMS_DC TSRMLS_DC) /* {{{ */
{
php_stream *stream = NULL;
php_url *resource = NULL;
int use_ssl;
int use_proxy = 0;
char *scratch = NULL;
char *tmp = NULL;
char *ua_str = NULL;
zval **ua_zval = NULL, **tmpzval = NULL, *ssl_proxy_peer_name = NULL;
int scratch_len = 0;
int body = 0;
char location[HTTP_HEADER_BLOCK_SIZE];
zval *response_header = NULL;
int reqok = 0;
char *http_header_line = NULL;
char tmp_line[128];
size_t chunk_size = 0, file_size = 0;
int eol_detect = 0;
char *transport_string, *errstr = NULL;
int transport_len, have_header = 0, request_fulluri = 0, ignore_errors = 0;
char *protocol_version = NULL;
int protocol_version_len = 3; /* Default: "1.0" */
struct timeval timeout;
char *user_headers = NULL;
int header_init = ((flags & HTTP_WRAPPER_HEADER_INIT) != 0);
int redirected = ((flags & HTTP_WRAPPER_REDIRECTED) != 0);
int follow_location = 1;
php_stream_filter *transfer_encoding = NULL;
int response_code;
tmp_line[0] = '\0';
if (redirect_max < 1) {
php_stream_wrapper_log_error(wrapper, options TSRMLS_CC, "Redirection limit reached, aborting");
return NULL;
}
resource = php_url_parse(path);
if (resource == NULL) {
return NULL;
}
if (strncasecmp(resource->scheme, "http", sizeof("http")) && strncasecmp(resource->scheme, "https", sizeof("https"))) {
if (!context ||
php_stream_context_get_option(context, wrapper->wops->label, "proxy", &tmpzval) == FAILURE ||
Z_TYPE_PP(tmpzval) != IS_STRING ||
Z_STRLEN_PP(tmpzval) <= 0) {
php_url_free(resource);
return php_stream_open_wrapper_ex(path, mode, REPORT_ERRORS, NULL, context);
}
/* Called from a non-http wrapper with http proxying requested (i.e. ftp) */
request_fulluri = 1;
use_ssl = 0;
use_proxy = 1;
transport_len = Z_STRLEN_PP(tmpzval);
transport_string = estrndup(Z_STRVAL_PP(tmpzval), Z_STRLEN_PP(tmpzval));
} else {
/* Normal http request (possibly with proxy) */
if (strpbrk(mode, "awx+")) {
php_stream_wrapper_log_error(wrapper, options TSRMLS_CC, "HTTP wrapper does not support writeable connections");
php_url_free(resource);
return NULL;
}
use_ssl = resource->scheme && (strlen(resource->scheme) > 4) && resource->scheme[4] == 's';
/* choose default ports */
if (use_ssl && resource->port == 0)
resource->port = 443;
else if (resource->port == 0)
resource->port = 80;
if (context &&
php_stream_context_get_option(context, wrapper->wops->label, "proxy", &tmpzval) == SUCCESS &&
Z_TYPE_PP(tmpzval) == IS_STRING &&
Z_STRLEN_PP(tmpzval) > 0) {
use_proxy = 1;
transport_len = Z_STRLEN_PP(tmpzval);
transport_string = estrndup(Z_STRVAL_PP(tmpzval), Z_STRLEN_PP(tmpzval));
} else {
transport_len = spprintf(&transport_string, 0, "%s://%s:%d", use_ssl ? "ssl" : "tcp", resource->host, resource->port);
}
}
if (context && php_stream_context_get_option(context, wrapper->wops->label, "timeout", &tmpzval) == SUCCESS) {
SEPARATE_ZVAL(tmpzval);
convert_to_double_ex(tmpzval);
timeout.tv_sec = (time_t) Z_DVAL_PP(tmpzval);
timeout.tv_usec = (size_t) ((Z_DVAL_PP(tmpzval) - timeout.tv_sec) * 1000000);
} else {
timeout.tv_sec = FG(default_socket_timeout);
timeout.tv_usec = 0;
}
stream = php_stream_xport_create(transport_string, transport_len, options,
STREAM_XPORT_CLIENT | STREAM_XPORT_CONNECT,
//.........这里部分代码省略.........
示例11: get
VT get(const V& v) const
{
return FG()(v);
}
示例12: ZVAL_UNDEF
//.........这里部分代码省略.........
return NULL;
}
use_ssl = resource->scheme && (strlen(resource->scheme) > 4) && resource->scheme[4] == 's';
/* choose default ports */
if (use_ssl && resource->port == 0)
resource->port = 443;
else if (resource->port == 0)
resource->port = 80;
if (context &&
(tmpzval = php_stream_context_get_option(context, wrapper->wops->label, "proxy")) != NULL &&
Z_TYPE_P(tmpzval) == IS_STRING &&
Z_STRLEN_P(tmpzval) > 0) {
use_proxy = 1;
transport_len = Z_STRLEN_P(tmpzval);
transport_string = estrndup(Z_STRVAL_P(tmpzval), Z_STRLEN_P(tmpzval));
} else {
transport_len = spprintf(&transport_string, 0, "%s://%s:%d", use_ssl ? "ssl" : "tcp", resource->host, resource->port);
}
}
if (context && (tmpzval = php_stream_context_get_option(context, wrapper->wops->label, "timeout")) != NULL) {
double d = zval_get_double(tmpzval);
#ifndef PHP_WIN32
timeout.tv_sec = (time_t) d;
timeout.tv_usec = (size_t) ((d - timeout.tv_sec) * 1000000);
#else
timeout.tv_sec = (long) d;
timeout.tv_usec = (long) ((d - timeout.tv_sec) * 1000000);
#endif
} else {
#ifndef PHP_WIN32
timeout.tv_sec = FG(default_socket_timeout);
#else
timeout.tv_sec = (long)FG(default_socket_timeout);
#endif
timeout.tv_usec = 0;
}
stream = php_stream_xport_create(transport_string, transport_len, options,
STREAM_XPORT_CLIENT | STREAM_XPORT_CONNECT,
NULL, &timeout, context, &errstr, NULL);
if (stream) {
php_stream_set_option(stream, PHP_STREAM_OPTION_READ_TIMEOUT, 0, &timeout);
}
if (errstr) {
php_stream_wrapper_log_error(wrapper, options, "%s", ZSTR_VAL(errstr));
zend_string_release(errstr);
errstr = NULL;
}
efree(transport_string);
if (stream && use_proxy && use_ssl) {
smart_str header = {0};
/* Set peer_name or name verification will try to use the proxy server name */
if (!context || (tmpzval = php_stream_context_get_option(context, "ssl", "peer_name")) == NULL) {
ZVAL_STRING(&ssl_proxy_peer_name, resource->host);
php_stream_context_set_option(PHP_STREAM_CONTEXT(stream), "ssl", "peer_name", &ssl_proxy_peer_name);
zval_ptr_dtor(&ssl_proxy_peer_name);
}
示例13: php_hash_do_hash_hmac
static void php_hash_do_hash_hmac(INTERNAL_FUNCTION_PARAMETERS, int isfilename, zend_bool raw_output_default) /* {{{ */
{
char *algo, *data, *digest, *key, *K;
int algo_len, data_len, key_len, i;
zend_uchar data_type = IS_STRING, key_type = IS_STRING;
zend_bool raw_output = raw_output_default;
const php_hash_ops *ops;
void *context;
php_stream *stream = NULL;
#if PHP_MAJOR_VERSION >= 6
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "stt|b", &algo, &algo_len, &data, &data_len, &data_type, &key, &key_len, &key_type, &raw_output) == FAILURE) {
return;
}
if (data_type == IS_UNICODE) {
if (isfilename) {
if (php_stream_path_encode(NULL, &data, &data_len, (UChar *)data, data_len, REPORT_ERRORS, FG(default_context)) == FAILURE) {
RETURN_FALSE;
}
} else {
data = zend_unicode_to_ascii((UChar*)data, data_len TSRMLS_CC);
if (!data) {
/* Non-ASCII Unicode string passed for raw hashing */
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Binary or ASCII-Unicode string expected, non-ASCII-Unicode string received");
RETURN_FALSE;
}
}
}
if (key_type == IS_UNICODE) {
key = zend_unicode_to_ascii((UChar*)key, key_len TSRMLS_CC);
if (!key) {
/* Non-ASCII Unicode key passed for raw hashing */
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Binary or ASCII-Unicode key expected, non-ASCII-Unicode key received");
if (data_type == IS_UNICODE) {
efree(data);
}
RETURN_FALSE;
}
}
#else
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sss|b", &algo, &algo_len, &data, &data_len, &key, &key_len, &raw_output) == FAILURE) {
return;
}
#endif
/* Assume failure */
RETVAL_FALSE;
ops = php_hash_fetch_ops(algo, algo_len);
if (!ops) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unknown hashing algorithm: %s", algo);
goto hmac_done;
}
if (isfilename) {
stream = php_stream_open_wrapper_ex(data, "rb", REPORT_ERRORS, NULL, DEFAULT_CONTEXT);
if (!stream) {
/* Stream will report errors opening file */
goto hmac_done;
}
}
context = emalloc(ops->context_size);
ops->hash_init(context);
K = emalloc(ops->block_size);
memset(K, 0, ops->block_size);
if (key_len > ops->block_size) {
/* Reduce the key first */
ops->hash_update(context, (unsigned char *) key, key_len);
ops->hash_final((unsigned char *) K, context);
/* Make the context ready to start over */
ops->hash_init(context);
} else {
memcpy(K, key, key_len);
}
/* XOR ipad */
for(i=0; i < ops->block_size; i++) {
K[i] ^= 0x36;
}
ops->hash_update(context, (unsigned char *) K, ops->block_size);
if (isfilename) {
char buf[1024];
int n;
while ((n = php_stream_read(stream, buf, sizeof(buf))) > 0) {
ops->hash_update(context, (unsigned char *) buf, n);
}
php_stream_close(stream);
} else {
ops->hash_update(context, (unsigned char *) data, data_len);
}
digest = emalloc(ops->digest_size + 1);
ops->hash_final((unsigned char *) digest, context);
/* Convert K to opad -- 0x6A = 0x36 ^ 0x5C */
//.........这里部分代码省略.........
示例14: php_hash_do_hash
static void php_hash_do_hash(INTERNAL_FUNCTION_PARAMETERS, int isfilename, zend_bool raw_output_default) /* {{{ */
{
zend_string *digest;
char *algo, *data;
size_t algo_len, data_len;
zend_bool raw_output = raw_output_default;
const php_hash_ops *ops;
void *context;
php_stream *stream = NULL;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss|b", &algo, &algo_len, &data, &data_len, &raw_output) == FAILURE) {
return;
}
ops = php_hash_fetch_ops(algo, algo_len);
if (!ops) {
php_error_docref(NULL, E_WARNING, "Unknown hashing algorithm: %s", algo);
RETURN_FALSE;
}
if (isfilename) {
if (CHECK_NULL_PATH(data, data_len)) {
php_error_docref(NULL, E_WARNING, "Invalid path");
RETURN_FALSE;
}
stream = php_stream_open_wrapper_ex(data, "rb", REPORT_ERRORS, NULL, FG(default_context));
if (!stream) {
/* Stream will report errors opening file */
RETURN_FALSE;
}
}
context = emalloc(ops->context_size);
ops->hash_init(context);
if (isfilename) {
char buf[1024];
size_t n;
while ((n = php_stream_read(stream, buf, sizeof(buf))) > 0) {
ops->hash_update(context, (unsigned char *) buf, n);
}
php_stream_close(stream);
} else {
ops->hash_update(context, (unsigned char *) data, data_len);
}
digest = zend_string_alloc(ops->digest_size, 0);
ops->hash_final((unsigned char *) ZSTR_VAL(digest), context);
efree(context);
if (raw_output) {
ZSTR_VAL(digest)[ops->digest_size] = 0;
RETURN_NEW_STR(digest);
} else {
zend_string *hex_digest = zend_string_safe_alloc(ops->digest_size, 2, 0, 0);
php_hash_bin2hex(ZSTR_VAL(hex_digest), (unsigned char *) ZSTR_VAL(digest), ops->digest_size);
ZSTR_VAL(hex_digest)[2 * ops->digest_size] = 0;
zend_string_release(digest);
RETURN_NEW_STR(hex_digest);
}
}
示例15: php_sockop_set_option
static int php_sockop_set_option(php_stream *stream, int option, int value, void *ptrparam)
{
int oldmode, flags;
php_netstream_data_t *sock = (php_netstream_data_t*)stream->abstract;
php_stream_xport_param *xparam;
if (!sock) {
return PHP_STREAM_OPTION_RETURN_NOTIMPL;
}
switch(option) {
case PHP_STREAM_OPTION_CHECK_LIVENESS:
{
struct timeval tv;
char buf;
int alive = 1;
if (value == -1) {
if (sock->timeout.tv_sec == -1) {
tv.tv_sec = FG(default_socket_timeout);
tv.tv_usec = 0;
} else {
tv = sock->timeout;
}
} else {
tv.tv_sec = value;
tv.tv_usec = 0;
}
if (sock->socket == -1) {
alive = 0;
} else if (php_pollfd_for(sock->socket, PHP_POLLREADABLE|POLLPRI, &tv) > 0) {
#ifdef PHP_WIN32
int ret;
#else
ssize_t ret;
#endif
int err;
ret = recv(sock->socket, &buf, sizeof(buf), MSG_PEEK);
err = php_socket_errno();
if (0 == ret || /* the counterpart did properly shutdown*/
(0 > ret && err != EWOULDBLOCK && err != EAGAIN)) { /* there was an unrecoverable error */
alive = 0;
}
}
return alive ? PHP_STREAM_OPTION_RETURN_OK : PHP_STREAM_OPTION_RETURN_ERR;
}
case PHP_STREAM_OPTION_BLOCKING:
oldmode = sock->is_blocked;
if (SUCCESS == php_set_sock_blocking(sock->socket, value)) {
sock->is_blocked = value;
return oldmode;
}
return PHP_STREAM_OPTION_RETURN_ERR;
case PHP_STREAM_OPTION_READ_TIMEOUT:
sock->timeout = *(struct timeval*)ptrparam;
sock->timeout_event = 0;
return PHP_STREAM_OPTION_RETURN_OK;
case PHP_STREAM_OPTION_META_DATA_API:
add_assoc_bool((zval *)ptrparam, "timed_out", sock->timeout_event);
add_assoc_bool((zval *)ptrparam, "blocked", sock->is_blocked);
add_assoc_bool((zval *)ptrparam, "eof", stream->eof);
return PHP_STREAM_OPTION_RETURN_OK;
case PHP_STREAM_OPTION_XPORT_API:
xparam = (php_stream_xport_param *)ptrparam;
switch (xparam->op) {
case STREAM_XPORT_OP_LISTEN:
xparam->outputs.returncode = (listen(sock->socket, xparam->inputs.backlog) == 0) ? 0: -1;
return PHP_STREAM_OPTION_RETURN_OK;
case STREAM_XPORT_OP_GET_NAME:
xparam->outputs.returncode = php_network_get_sock_name(sock->socket,
xparam->want_textaddr ? &xparam->outputs.textaddr : NULL,
xparam->want_addr ? &xparam->outputs.addr : NULL,
xparam->want_addr ? &xparam->outputs.addrlen : NULL
);
return PHP_STREAM_OPTION_RETURN_OK;
case STREAM_XPORT_OP_GET_PEER_NAME:
xparam->outputs.returncode = php_network_get_peer_name(sock->socket,
xparam->want_textaddr ? &xparam->outputs.textaddr : NULL,
xparam->want_addr ? &xparam->outputs.addr : NULL,
xparam->want_addr ? &xparam->outputs.addrlen : NULL
);
return PHP_STREAM_OPTION_RETURN_OK;
case STREAM_XPORT_OP_SEND:
flags = 0;
if ((xparam->inputs.flags & STREAM_OOB) == STREAM_OOB) {
flags |= MSG_OOB;
}
xparam->outputs.returncode = sock_sendto(sock,
xparam->inputs.buf, xparam->inputs.buflen,
flags,
//.........这里部分代码省略.........