repo
stringlengths 1
152
⌀ | file
stringlengths 14
221
| code
stringlengths 501
25k
| file_length
int64 501
25k
| avg_line_length
float64 20
99.5
| max_line_length
int64 21
134
| extension_type
stringclasses 2
values |
---|---|---|---|---|---|---|
php-src
|
php-src-master/ext/pdo_dblib/pdo_dblib.c
|
/*
+----------------------------------------------------------------------+
| Copyright (c) The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| https://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| [email protected] so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Author: Wez Furlong <[email protected]> |
| Frank M. Kromann <[email protected]> |
+----------------------------------------------------------------------+
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include "php.h"
#include "php_ini.h"
#include "ext/standard/info.h"
#include "pdo/php_pdo.h"
#include "pdo/php_pdo_driver.h"
#include "php_pdo_dblib.h"
#include "php_pdo_dblib_int.h"
#include "zend_exceptions.h"
ZEND_DECLARE_MODULE_GLOBALS(dblib)
static PHP_GINIT_FUNCTION(dblib);
static const zend_module_dep pdo_dblib_deps[] = {
ZEND_MOD_REQUIRED("pdo")
ZEND_MOD_END
};
#ifdef PDO_DBLIB_IS_MSSQL
zend_module_entry pdo_mssql_module_entry = {
#else
zend_module_entry pdo_dblib_module_entry = {
#endif
STANDARD_MODULE_HEADER_EX, NULL,
pdo_dblib_deps,
#ifdef PDO_DBLIB_IS_MSSQL
"pdo_mssql",
#elif defined(PHP_WIN32)
"pdo_sybase",
#else
"pdo_dblib",
#endif
NULL,
PHP_MINIT(pdo_dblib),
PHP_MSHUTDOWN(pdo_dblib),
NULL,
PHP_RSHUTDOWN(pdo_dblib),
PHP_MINFO(pdo_dblib),
PHP_PDO_DBLIB_VERSION,
PHP_MODULE_GLOBALS(dblib),
PHP_GINIT(dblib),
NULL,
NULL,
STANDARD_MODULE_PROPERTIES_EX
};
#if defined(COMPILE_DL_PDO_DBLIB) || defined(COMPILE_DL_PDO_MSSQL)
#ifdef ZTS
ZEND_TSRMLS_CACHE_DEFINE()
#endif
#ifdef PDO_DBLIB_IS_MSSQL
ZEND_GET_MODULE(pdo_mssql)
#else
ZEND_GET_MODULE(pdo_dblib)
#endif
#endif
int pdo_dblib_error_handler(DBPROCESS *dbproc, int severity, int dberr,
int oserr, char *dberrstr, char *oserrstr)
{
pdo_dblib_err *einfo;
char *state = "HY000";
if(dbproc) {
einfo = (pdo_dblib_err*)dbgetuserdata(dbproc);
if (!einfo) einfo = &DBLIB_G(err);
} else {
einfo = &DBLIB_G(err);
}
einfo->severity = severity;
einfo->oserr = oserr;
einfo->dberr = dberr;
if (einfo->oserrstr) {
efree(einfo->oserrstr);
}
if (einfo->dberrstr) {
efree(einfo->dberrstr);
}
if (oserrstr) {
einfo->oserrstr = estrdup(oserrstr);
} else {
einfo->oserrstr = NULL;
}
if (dberrstr) {
einfo->dberrstr = estrdup(dberrstr);
} else {
einfo->dberrstr = NULL;
}
switch (dberr) {
case SYBESEOF:
case SYBEFCON: state = "01002"; break;
case SYBEMEM: state = "HY001"; break;
case SYBEPWD: state = "28000"; break;
}
strcpy(einfo->sqlstate, state);
return INT_CANCEL;
}
int pdo_dblib_msg_handler(DBPROCESS *dbproc, DBINT msgno, int msgstate,
int severity, char *msgtext, char *srvname, char *procname, int line)
{
pdo_dblib_err *einfo;
if (severity) {
einfo = (pdo_dblib_err*)dbgetuserdata(dbproc);
if (!einfo) {
einfo = &DBLIB_G(err);
}
if (einfo->lastmsg) {
efree(einfo->lastmsg);
}
einfo->lastmsg = estrdup(msgtext);
}
return 0;
}
void pdo_dblib_err_dtor(pdo_dblib_err *err)
{
if (!err) {
return;
}
if (err->dberrstr) {
efree(err->dberrstr);
err->dberrstr = NULL;
}
if (err->lastmsg) {
efree(err->lastmsg);
err->lastmsg = NULL;
}
if (err->oserrstr) {
efree(err->oserrstr);
err->oserrstr = NULL;
}
}
static PHP_GINIT_FUNCTION(dblib)
{
#if defined(ZTS) && (defined(COMPILE_DL_PDO_DBLIB) || defined(COMPILE_DL_PDO_MSSQL))
ZEND_TSRMLS_CACHE_UPDATE();
#endif
memset(dblib_globals, 0, sizeof(*dblib_globals));
dblib_globals->err.sqlstate = dblib_globals->sqlstate;
}
PHP_RSHUTDOWN_FUNCTION(pdo_dblib)
{
if (DBLIB_G(err).oserrstr) {
efree(DBLIB_G(err).oserrstr);
DBLIB_G(err).oserrstr = NULL;
}
if (DBLIB_G(err).dberrstr) {
efree(DBLIB_G(err).dberrstr);
DBLIB_G(err).dberrstr = NULL;
}
if (DBLIB_G(err).lastmsg) {
efree(DBLIB_G(err).lastmsg);
DBLIB_G(err).lastmsg = NULL;
}
return SUCCESS;
}
PHP_MINIT_FUNCTION(pdo_dblib)
{
REGISTER_PDO_CLASS_CONST_LONG("DBLIB_ATTR_CONNECTION_TIMEOUT", (long) PDO_DBLIB_ATTR_CONNECTION_TIMEOUT);
REGISTER_PDO_CLASS_CONST_LONG("DBLIB_ATTR_QUERY_TIMEOUT", (long) PDO_DBLIB_ATTR_QUERY_TIMEOUT);
REGISTER_PDO_CLASS_CONST_LONG("DBLIB_ATTR_STRINGIFY_UNIQUEIDENTIFIER", (long) PDO_DBLIB_ATTR_STRINGIFY_UNIQUEIDENTIFIER);
REGISTER_PDO_CLASS_CONST_LONG("DBLIB_ATTR_VERSION", (long) PDO_DBLIB_ATTR_VERSION);
REGISTER_PDO_CLASS_CONST_LONG("DBLIB_ATTR_TDS_VERSION", (long) PDO_DBLIB_ATTR_TDS_VERSION);
REGISTER_PDO_CLASS_CONST_LONG("DBLIB_ATTR_SKIP_EMPTY_ROWSETS", (long) PDO_DBLIB_ATTR_SKIP_EMPTY_ROWSETS);
REGISTER_PDO_CLASS_CONST_LONG("DBLIB_ATTR_DATETIME_CONVERT", (long) PDO_DBLIB_ATTR_DATETIME_CONVERT);
if (FAIL == dbinit()) {
return FAILURE;
}
if (FAILURE == php_pdo_register_driver(&pdo_dblib_driver)) {
return FAILURE;
}
#ifndef PHP_DBLIB_IS_MSSQL
dberrhandle((EHANDLEFUNC) pdo_dblib_error_handler);
dbmsghandle((MHANDLEFUNC) pdo_dblib_msg_handler);
#endif
return SUCCESS;
}
PHP_MSHUTDOWN_FUNCTION(pdo_dblib)
{
php_pdo_unregister_driver(&pdo_dblib_driver);
dbexit();
return SUCCESS;
}
PHP_MINFO_FUNCTION(pdo_dblib)
{
php_info_print_table_start();
php_info_print_table_row(2, "PDO Driver for "
#ifdef PDO_DBLIB_IS_MSSQL
"MSSQL"
#elif defined(PHP_WIN32)
"FreeTDS/Sybase/MSSQL"
#else
"FreeTDS/Sybase"
#endif
" DB-lib", "enabled");
php_info_print_table_row(2, "Flavour", PDO_DBLIB_FLAVOUR);
php_info_print_table_end();
}
| 5,903 | 23.806723 | 122 |
c
|
php-src
|
php-src-master/ext/pdo_dblib/php_pdo_dblib.h
|
/*
+----------------------------------------------------------------------+
| Copyright (c) The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| https://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| [email protected] so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Author: Wez Furlong <[email protected]> |
| Frank M. Kromann <[email protected]> |
+----------------------------------------------------------------------+
*/
#ifndef PHP_PDO_DBLIB_H
#define PHP_PDO_DBLIB_H
#ifdef PDO_DBLIB_IS_MSSQL
extern zend_module_entry pdo_mssql_module_entry;
#define phpext_pdo_mssql_ptr &pdo_mssql_module_entry
#else
extern zend_module_entry pdo_dblib_module_entry;
#define phpext_pdo_dblib_ptr &pdo_dblib_module_entry
#endif
#include "php_version.h"
#define PHP_PDO_DBLIB_VERSION PHP_VERSION
#ifdef ZTS
# include "TSRM.h"
#endif
PHP_MINIT_FUNCTION(pdo_dblib);
PHP_MSHUTDOWN_FUNCTION(pdo_dblib);
PHP_MINFO_FUNCTION(pdo_dblib);
PHP_RSHUTDOWN_FUNCTION(pdo_dblib);
#endif
| 1,596 | 37.02381 | 74 |
h
|
php-src
|
php-src-master/ext/pdo_dblib/php_pdo_dblib_int.h
|
/*
+----------------------------------------------------------------------+
| Copyright (c) The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| https://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| [email protected] so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Author: Wez Furlong <[email protected]> |
| Frank M. Kromann <[email protected]> |
+----------------------------------------------------------------------+
*/
#ifndef PHP_PDO_DBLIB_INT_H
#define PHP_PDO_DBLIB_INT_H
#ifndef PDO_DBLIB_FLAVOUR
# define PDO_DBLIB_FLAVOUR "Generic DB-lib"
#endif
#ifdef PHP_DBLIB_IS_MSSQL
# include <sqlfront.h>
# include <sqldb.h>
# define DBERRHANDLE(a, b) dbprocerrhandle(a, b)
# define DBMSGHANDLE(a, b) dbprocmsghandle(a, b)
# define EHANDLEFUNC DBERRHANDLE_PROC
# define MHANDLEFUNC DBMSGHANDLE_PROC
# define DBSETOPT(a, b, c) dbsetopt(a, b, c)
# define SYBESMSG SQLESMSG
# define SYBESEOF SQLESEOF
# define SYBEFCON SQLECONN /* SQLEFCON does not exist in MS SQL Server. */
# define SYBEMEM SQLEMEM
# define SYBEPWD SQLEPWD
#else
# include <sybfront.h>
# include <sybdb.h>
# include <syberror.h>
/* alias some types */
# define SQLTEXT SYBTEXT
# define SQLCHAR SYBCHAR
# define SQLVARCHAR SYBVARCHAR
# define SQLINT1 SYBINT1
# define SQLINT2 SYBINT2
# define SQLINT4 SYBINT4
# define SQLINT8 SYBINT8
# define SQLINTN SYBINTN
# define SQLBIT SYBBIT
# define SQLFLT4 SYBREAL
# define SQLFLT8 SYBFLT8
# define SQLFLTN SYBFLTN
# define SQLDECIMAL SYBDECIMAL
# define SQLNUMERIC SYBNUMERIC
# define SQLDATETIME SYBDATETIME
# define SQLDATETIM4 SYBDATETIME4
# define SQLDATETIMN SYBDATETIMN
# ifdef SYBMSDATETIME2
# define SQLMSDATETIME2 SYBMSDATETIME2
# endif
# define SQLMONEY SYBMONEY
# define SQLMONEY4 SYBMONEY4
# define SQLMONEYN SYBMONEYN
# define SQLIMAGE SYBIMAGE
# define SQLBINARY SYBBINARY
# define SQLVARBINARY SYBVARBINARY
# ifdef SYBUNIQUE
# define SQLUNIQUE SYBUNIQUE
#else
# define SQLUNIQUE 36 /* FreeTDS Hack */
# endif
# define DBERRHANDLE(a, b) dberrhandle(b)
# define DBMSGHANDLE(a, b) dbmsghandle(b)
# define DBSETOPT(a, b, c) dbsetopt(a, b, c, -1)
# define NO_MORE_RPC_RESULTS 3
# define dbfreelogin dbloginfree
# define dbrpcexec dbrpcsend
typedef short TDS_SHORT;
# ifndef PHP_WIN32
typedef unsigned char *LPBYTE;
# endif
typedef float DBFLT4;
#endif
/* hardcoded string length from FreeTDS
* src/tds/convert.c:tds_convert_datetimeall()
*/
# define DATETIME_MAX_LEN 63
int pdo_dblib_error_handler(DBPROCESS *dbproc, int severity, int dberr,
int oserr, char *dberrstr, char *oserrstr);
int pdo_dblib_msg_handler(DBPROCESS *dbproc, DBINT msgno, int msgstate,
int severity, char *msgtext, char *srvname, char *procname, int line);
extern const pdo_driver_t pdo_dblib_driver;
extern const struct pdo_stmt_methods dblib_stmt_methods;
typedef struct {
int severity;
int oserr;
int dberr;
char *oserrstr;
char *dberrstr;
char *sqlstate;
char *lastmsg;
} pdo_dblib_err;
void pdo_dblib_err_dtor(pdo_dblib_err *err);
typedef struct {
LOGINREC *login;
DBPROCESS *link;
pdo_dblib_err err;
unsigned assume_national_character_set_strings:1;
unsigned stringify_uniqueidentifier:1;
unsigned skip_empty_rowsets:1;
unsigned datetime_convert:1;
} pdo_dblib_db_handle;
typedef struct {
pdo_dblib_db_handle *H;
pdo_dblib_err err;
unsigned int computed_column_name_count;
} pdo_dblib_stmt;
typedef struct {
const char* key;
int value;
} pdo_dblib_keyval;
ZEND_BEGIN_MODULE_GLOBALS(dblib)
pdo_dblib_err err;
char sqlstate[6];
ZEND_END_MODULE_GLOBALS(dblib)
#if defined(ZTS) && (defined(COMPILE_DL_PDO_DBLIB) || defined(COMPILE_DL_PDO_MSSQL))
ZEND_TSRMLS_CACHE_EXTERN()
#endif
ZEND_EXTERN_MODULE_GLOBALS(dblib)
#define DBLIB_G(v) ZEND_MODULE_GLOBALS_ACCESSOR(dblib, v)
ZEND_EXTERN_MODULE_GLOBALS(dblib)
enum {
PDO_DBLIB_ATTR_CONNECTION_TIMEOUT = PDO_ATTR_DRIVER_SPECIFIC,
PDO_DBLIB_ATTR_QUERY_TIMEOUT,
PDO_DBLIB_ATTR_STRINGIFY_UNIQUEIDENTIFIER,
PDO_DBLIB_ATTR_VERSION,
PDO_DBLIB_ATTR_TDS_VERSION,
PDO_DBLIB_ATTR_SKIP_EMPTY_ROWSETS,
PDO_DBLIB_ATTR_DATETIME_CONVERT,
};
#endif
| 4,686 | 27.23494 | 84 |
h
|
php-src
|
php-src-master/ext/pdo_firebird/firebird_statement.c
|
/*
+----------------------------------------------------------------------+
| Copyright (c) The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| https://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| [email protected] so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Author: Ard Biesheuvel <[email protected]> |
+----------------------------------------------------------------------+
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "php.h"
#include "php_ini.h"
#include "ext/standard/info.h"
#include "pdo/php_pdo.h"
#include "pdo/php_pdo_driver.h"
#include "php_pdo_firebird.h"
#include "php_pdo_firebird_int.h"
#include <time.h>
#define RECORD_ERROR(stmt) _firebird_error(NULL, stmt, __FILE__, __LINE__)
#define READ_AND_RETURN_USING_MEMCPY(type, sqldata) do { \
type ret; \
memcpy(&ret, sqldata, sizeof(ret)); \
return ret; \
} while (0);
static zend_always_inline ISC_INT64 get_isc_int64_from_sqldata(const ISC_SCHAR *sqldata)
{
READ_AND_RETURN_USING_MEMCPY(ISC_INT64, sqldata);
}
static zend_always_inline ISC_LONG get_isc_long_from_sqldata(const ISC_SCHAR *sqldata)
{
READ_AND_RETURN_USING_MEMCPY(ISC_LONG, sqldata);
}
static zend_always_inline double get_double_from_sqldata(const ISC_SCHAR *sqldata)
{
READ_AND_RETURN_USING_MEMCPY(double, sqldata);
}
static zend_always_inline ISC_TIMESTAMP get_isc_timestamp_from_sqldata(const ISC_SCHAR *sqldata)
{
READ_AND_RETURN_USING_MEMCPY(ISC_TIMESTAMP, sqldata);
}
static zend_always_inline ISC_QUAD get_isc_quad_from_sqldata(const ISC_SCHAR *sqldata)
{
READ_AND_RETURN_USING_MEMCPY(ISC_QUAD, sqldata);
}
/* free the allocated space for passing field values to the db and back */
static void free_sqlda(XSQLDA const *sqlda) /* {{{ */
{
int i;
for (i = 0; i < sqlda->sqld; ++i) {
XSQLVAR const *var = &sqlda->sqlvar[i];
if (var->sqlind) {
efree(var->sqlind);
}
}
}
/* }}} */
/* called by PDO to clean up a statement handle */
static int firebird_stmt_dtor(pdo_stmt_t *stmt) /* {{{ */
{
pdo_firebird_stmt *S = (pdo_firebird_stmt*)stmt->driver_data;
int result = 1;
/* release the statement */
if (isc_dsql_free_statement(S->H->isc_status, &S->stmt, DSQL_drop)) {
RECORD_ERROR(stmt);
result = 0;
}
zend_hash_destroy(S->named_params);
FREE_HASHTABLE(S->named_params);
/* clean up the input descriptor */
if (S->in_sqlda) {
free_sqlda(S->in_sqlda);
efree(S->in_sqlda);
}
free_sqlda(&S->out_sqlda);
efree(S);
return result;
}
/* }}} */
/* called by PDO to execute a prepared query */
static int firebird_stmt_execute(pdo_stmt_t *stmt) /* {{{ */
{
pdo_firebird_stmt *S = (pdo_firebird_stmt*)stmt->driver_data;
pdo_firebird_db_handle *H = S->H;
zend_ulong affected_rows = 0;
static char info_count[] = {isc_info_sql_records};
char result[64];
do {
/* named or open cursors should be closed first */
if ((*S->name || S->cursor_open) && isc_dsql_free_statement(H->isc_status, &S->stmt, DSQL_close)) {
break;
}
S->cursor_open = 0;
/* allocate storage for the output data */
if (S->out_sqlda.sqld) {
unsigned int i;
for (i = 0; i < S->out_sqlda.sqld; i++) {
XSQLVAR *var = &S->out_sqlda.sqlvar[i];
if (var->sqlind) {
efree(var->sqlind);
}
var->sqlind = (void*)ecalloc(1, var->sqllen + 2 * sizeof(short));
var->sqldata = &((char*)var->sqlind)[sizeof(short)];
}
}
if (S->statement_type == isc_info_sql_stmt_exec_procedure) {
if (isc_dsql_execute2(H->isc_status, &H->tr, &S->stmt, PDO_FB_SQLDA_VERSION, S->in_sqlda, &S->out_sqlda)) {
break;
}
} else if (isc_dsql_execute(H->isc_status, &H->tr, &S->stmt, PDO_FB_SQLDA_VERSION, S->in_sqlda)) {
break;
}
/* Determine how many rows have changed. In this case we are
* only interested in rows changed, not rows retrieved. That
* should be handled by the client when fetching. */
stmt->row_count = affected_rows;
switch (S->statement_type) {
case isc_info_sql_stmt_insert:
case isc_info_sql_stmt_update:
case isc_info_sql_stmt_delete:
case isc_info_sql_stmt_exec_procedure:
if (isc_dsql_sql_info(H->isc_status, &S->stmt, sizeof ( info_count),
info_count, sizeof(result), result)) {
break;
}
if (result[0] == isc_info_sql_records) {
unsigned i = 3, result_size = isc_vax_integer(&result[1], 2);
if (result_size > sizeof(result)) {
goto error;
}
while (result[i] != isc_info_end && i < result_size) {
short len = (short) isc_vax_integer(&result[i + 1], 2);
if (len != 1 && len != 2 && len != 4) {
goto error;
}
if (result[i] != isc_info_req_select_count) {
affected_rows += isc_vax_integer(&result[i + 3], len);
}
i += len + 3;
}
stmt->row_count = affected_rows;
}
/* TODO Dead code or assert one of the previous cases are hit? */
default:
;
}
/* commit? */
if (stmt->dbh->auto_commit && isc_commit_retaining(H->isc_status, &H->tr)) {
break;
}
*S->name = 0;
S->cursor_open = S->out_sqlda.sqln && (S->statement_type != isc_info_sql_stmt_exec_procedure);
S->exhausted = !S->out_sqlda.sqln; /* There are data to fetch */
return 1;
} while (0);
error:
RECORD_ERROR(stmt);
return 0;
}
/* }}} */
/* called by PDO to fetch the next row from a statement */
static int firebird_stmt_fetch(pdo_stmt_t *stmt, /* {{{ */
enum pdo_fetch_orientation ori, zend_long offset)
{
pdo_firebird_stmt *S = (pdo_firebird_stmt*)stmt->driver_data;
pdo_firebird_db_handle *H = S->H;
if (!stmt->executed) {
strcpy(stmt->error_code, "HY000");
H->last_app_error = "Cannot fetch from a closed cursor";
} else if (!S->exhausted) {
if (S->statement_type == isc_info_sql_stmt_exec_procedure) {
stmt->row_count = 1;
S->exhausted = 1;
return 1;
}
if (isc_dsql_fetch(H->isc_status, &S->stmt, PDO_FB_SQLDA_VERSION, &S->out_sqlda)) {
if (H->isc_status[0] && H->isc_status[1]) {
RECORD_ERROR(stmt);
}
S->exhausted = 1;
return 0;
}
stmt->row_count++;
return 1;
}
return 0;
}
/* }}} */
/* called by PDO to retrieve information about the fields being returned */
static int firebird_stmt_describe(pdo_stmt_t *stmt, int colno) /* {{{ */
{
pdo_firebird_stmt *S = (pdo_firebird_stmt*)stmt->driver_data;
struct pdo_column_data *col = &stmt->columns[colno];
XSQLVAR *var = &S->out_sqlda.sqlvar[colno];
int colname_len;
char *cp;
if ((var->sqltype & ~1) == SQL_TEXT) {
var->sqltype = SQL_VARYING | (var->sqltype & 1);
}
colname_len = (S->H->fetch_table_names && var->relname_length)
? (var->aliasname_length + var->relname_length + 1)
: (var->aliasname_length);
col->precision = -var->sqlscale;
col->maxlen = var->sqllen;
col->name = zend_string_alloc(colname_len, 0);
cp = ZSTR_VAL(col->name);
if (colname_len > var->aliasname_length) {
memmove(cp, var->relname, var->relname_length);
cp += var->relname_length;
*cp++ = '.';
}
memmove(cp, var->aliasname, var->aliasname_length);
*(cp+var->aliasname_length) = '\0';
return 1;
}
/* }}} */
static int firebird_stmt_get_column_meta(pdo_stmt_t *stmt, zend_long colno, zval *return_value)
{
pdo_firebird_stmt *S = (pdo_firebird_stmt *) stmt->driver_data;
XSQLVAR *var = &S->out_sqlda.sqlvar[colno];
enum pdo_param_type param_type;
if (var->sqlscale < 0) {
param_type = PDO_PARAM_STR;
} else {
switch (var->sqltype & ~1) {
case SQL_SHORT:
case SQL_LONG:
#if SIZEOF_ZEND_LONG >= 8
case SQL_INT64:
#endif
param_type = PDO_PARAM_INT;
break;
#ifdef SQL_BOOLEAN
case SQL_BOOLEAN:
param_type = PDO_PARAM_BOOL;
break;
#endif
default:
param_type = PDO_PARAM_STR;
break;
}
}
array_init(return_value);
add_assoc_long(return_value, "pdo_type", param_type);
return 1;
}
/* fetch a blob into a fetch buffer */
static int firebird_fetch_blob(pdo_stmt_t *stmt, int colno, zval *result, ISC_QUAD *blob_id)
{
pdo_firebird_stmt *S = (pdo_firebird_stmt*)stmt->driver_data;
pdo_firebird_db_handle *H = S->H;
isc_blob_handle blobh = PDO_FIREBIRD_HANDLE_INITIALIZER;
char const bl_item = isc_info_blob_total_length;
char bl_info[20];
unsigned short i;
int retval = 0;
size_t len = 0;
if (isc_open_blob(H->isc_status, &H->db, &H->tr, &blobh, blob_id)) {
RECORD_ERROR(stmt);
return 0;
}
if (isc_blob_info(H->isc_status, &blobh, 1, const_cast(&bl_item),
sizeof(bl_info), bl_info)) {
RECORD_ERROR(stmt);
goto fetch_blob_end;
}
/* find total length of blob's data */
for (i = 0; i < sizeof(bl_info); ) {
unsigned short item_len;
char item = bl_info[i++];
if (item == isc_info_end || item == isc_info_truncated || item == isc_info_error
|| i >= sizeof(bl_info)) {
H->last_app_error = "Couldn't determine BLOB size";
goto fetch_blob_end;
}
item_len = (unsigned short) isc_vax_integer(&bl_info[i], 2);
if (item == isc_info_blob_total_length) {
len = isc_vax_integer(&bl_info[i+2], item_len);
break;
}
i += item_len+2;
}
/* we've found the blob's length, now fetch! */
if (len) {
zend_ulong cur_len;
unsigned short seg_len;
ISC_STATUS stat;
zend_string *str;
/* prevent overflow */
if (len > ZSTR_MAX_LEN) {
result = 0;
goto fetch_blob_end;
}
str = zend_string_alloc(len, 0);
for (cur_len = stat = 0; (!stat || stat == isc_segment) && cur_len < len; cur_len += seg_len) {
unsigned short chunk_size = (len - cur_len) > USHRT_MAX ? USHRT_MAX
: (unsigned short)(len - cur_len);
stat = isc_get_segment(H->isc_status, &blobh, &seg_len, chunk_size, ZSTR_VAL(str) + cur_len);
}
ZSTR_VAL(str)[len] = '\0';
ZVAL_STR(result, str);
if (H->isc_status[0] == 1 && (stat != 0 && stat != isc_segstr_eof && stat != isc_segment)) {
H->last_app_error = "Error reading from BLOB";
goto fetch_blob_end;
}
}
retval = 1;
fetch_blob_end:
if (isc_close_blob(H->isc_status, &blobh)) {
RECORD_ERROR(stmt);
return 0;
}
return retval;
}
/* }}} */
static int firebird_stmt_get_col(
pdo_stmt_t *stmt, int colno, zval *result, enum pdo_param_type *type)
{
pdo_firebird_stmt *S = (pdo_firebird_stmt*)stmt->driver_data;
XSQLVAR const *var = &S->out_sqlda.sqlvar[colno];
if (*var->sqlind == -1) {
ZVAL_NULL(result);
} else {
if (var->sqlscale < 0) {
static ISC_INT64 const scales[] = { 1, 10, 100, 1000,
10000,
100000,
1000000,
10000000,
100000000,
1000000000,
LL_LIT(10000000000),
LL_LIT(100000000000),
LL_LIT(1000000000000),
LL_LIT(10000000000000),
LL_LIT(100000000000000),
LL_LIT(1000000000000000),
LL_LIT(10000000000000000),
LL_LIT(100000000000000000),
LL_LIT(1000000000000000000)
};
ISC_INT64 n, f = scales[-var->sqlscale];
zend_string *str;
switch (var->sqltype & ~1) {
case SQL_SHORT:
n = *(short*)var->sqldata;
break;
case SQL_LONG:
n = get_isc_long_from_sqldata(var->sqldata);
break;
case SQL_INT64:
n = get_isc_int64_from_sqldata(var->sqldata);
break;
case SQL_DOUBLE:
break;
EMPTY_SWITCH_DEFAULT_CASE()
}
if ((var->sqltype & ~1) == SQL_DOUBLE) {
str = zend_strpprintf(0, "%.*F", -var->sqlscale, get_double_from_sqldata(var->sqldata));
} else if (n >= 0) {
str = zend_strpprintf(0, "%" LL_MASK "d.%0*" LL_MASK "d",
n / f, -var->sqlscale, n % f);
} else if (n <= -f) {
str = zend_strpprintf(0, "%" LL_MASK "d.%0*" LL_MASK "d",
n / f, -var->sqlscale, -n % f);
} else {
str = zend_strpprintf(0, "-0.%0*" LL_MASK "d", -var->sqlscale, -n % f);
}
ZVAL_STR(result, str);
} else {
switch (var->sqltype & ~1) {
struct tm t;
char *fmt;
case SQL_VARYING:
ZVAL_STRINGL_FAST(result, &var->sqldata[2], *(short*)var->sqldata);
break;
case SQL_TEXT:
ZVAL_STRINGL_FAST(result, var->sqldata, var->sqllen);
break;
case SQL_SHORT:
ZVAL_LONG(result, *(short*)var->sqldata);
break;
case SQL_LONG:
ZVAL_LONG(result, get_isc_long_from_sqldata(var->sqldata));
break;
case SQL_INT64:
#if SIZEOF_ZEND_LONG >= 8
ZVAL_LONG(result, get_isc_int64_from_sqldata(var->sqldata));
#else
ZVAL_STR(result, zend_strpprintf(0, "%" LL_MASK "d", get_isc_int64_from_sqldata(var->sqldata)));
#endif
break;
case SQL_FLOAT:
/* TODO: Why is this not returned as the native type? */
ZVAL_STR(result, zend_strpprintf(0, "%F", *(float*)var->sqldata));
break;
case SQL_DOUBLE:
/* TODO: Why is this not returned as the native type? */
ZVAL_STR(result, zend_strpprintf(0, "%F", get_double_from_sqldata(var->sqldata)));
break;
#ifdef SQL_BOOLEAN
case SQL_BOOLEAN:
ZVAL_BOOL(result, *(FB_BOOLEAN*)var->sqldata);
break;
#endif
case SQL_TYPE_DATE:
isc_decode_sql_date((ISC_DATE*)var->sqldata, &t);
fmt = S->H->date_format ? S->H->date_format : PDO_FB_DEF_DATE_FMT;
if (0) {
case SQL_TYPE_TIME:
isc_decode_sql_time((ISC_TIME*)var->sqldata, &t);
fmt = S->H->time_format ? S->H->time_format : PDO_FB_DEF_TIME_FMT;
} else if (0) {
case SQL_TIMESTAMP:
{
ISC_TIMESTAMP timestamp = get_isc_timestamp_from_sqldata(var->sqldata);
isc_decode_timestamp(×tamp, &t);
}
fmt = S->H->timestamp_format ? S->H->timestamp_format : PDO_FB_DEF_TIMESTAMP_FMT;
}
/* convert the timestamp into a string */
char buf[80];
size_t len = strftime(buf, sizeof(buf), fmt, &t);
ZVAL_STRINGL(result, buf, len);
break;
case SQL_BLOB: {
ISC_QUAD quad = get_isc_quad_from_sqldata(var->sqldata);
return firebird_fetch_blob(stmt, colno, result, &quad);
}
}
}
}
return 1;
}
static int firebird_bind_blob(pdo_stmt_t *stmt, ISC_QUAD *blob_id, zval *param)
{
pdo_firebird_stmt *S = (pdo_firebird_stmt*)stmt->driver_data;
pdo_firebird_db_handle *H = S->H;
isc_blob_handle h = PDO_FIREBIRD_HANDLE_INITIALIZER;
zval data;
zend_ulong put_cnt = 0, rem_cnt;
unsigned short chunk_size;
int result = 1;
if (isc_create_blob(H->isc_status, &H->db, &H->tr, &h, blob_id)) {
RECORD_ERROR(stmt);
return 0;
}
if (Z_TYPE_P(param) != IS_STRING) {
ZVAL_STR(&data, zval_get_string_func(param));
} else {
ZVAL_COPY_VALUE(&data, param);
}
for (rem_cnt = Z_STRLEN(data); rem_cnt > 0; rem_cnt -= chunk_size) {
chunk_size = rem_cnt > USHRT_MAX ? USHRT_MAX : (unsigned short)rem_cnt;
if (isc_put_segment(H->isc_status, &h, chunk_size, &Z_STRVAL(data)[put_cnt])) {
RECORD_ERROR(stmt);
result = 0;
break;
}
put_cnt += chunk_size;
}
if (Z_TYPE_P(param) != IS_STRING) {
zval_ptr_dtor_str(&data);
}
if (isc_close_blob(H->isc_status, &h)) {
RECORD_ERROR(stmt);
return 0;
}
return result;
}
static int firebird_stmt_param_hook(pdo_stmt_t *stmt, struct pdo_bound_param_data *param, /* {{{ */
enum pdo_param_event event_type)
{
pdo_firebird_stmt *S = (pdo_firebird_stmt*)stmt->driver_data;
XSQLDA *sqlda = param->is_param ? S->in_sqlda : &S->out_sqlda;
XSQLVAR *var;
if (event_type == PDO_PARAM_EVT_FREE) { /* not used */
return 1;
}
if (!sqlda || param->paramno >= sqlda->sqld) {
strcpy(stmt->error_code, "HY093");
S->H->last_app_error = "Invalid parameter index";
return 0;
}
if (param->is_param && param->paramno == -1) {
zval *index;
/* try to determine the index by looking in the named_params hash */
if ((index = zend_hash_find(S->named_params, param->name)) != NULL) {
param->paramno = Z_LVAL_P(index);
} else {
/* ... or by looking in the input descriptor */
int i;
for (i = 0; i < sqlda->sqld; ++i) {
XSQLVAR *var = &sqlda->sqlvar[i];
if ((var->aliasname_length && !strncasecmp(ZSTR_VAL(param->name), var->aliasname,
min(ZSTR_LEN(param->name), var->aliasname_length)))
|| (var->sqlname_length && !strncasecmp(ZSTR_VAL(param->name), var->sqlname,
min(ZSTR_LEN(param->name), var->sqlname_length)))) {
param->paramno = i;
break;
}
}
if (i >= sqlda->sqld) {
strcpy(stmt->error_code, "HY093");
S->H->last_app_error = "Invalid parameter name";
return 0;
}
}
}
var = &sqlda->sqlvar[param->paramno];
switch (event_type) {
zval *parameter;
case PDO_PARAM_EVT_ALLOC:
if (param->is_param) {
/* allocate the parameter */
if (var->sqlind) {
efree(var->sqlind);
}
var->sqlind = (void*)emalloc(var->sqllen + 2*sizeof(short));
var->sqldata = &((char*)var->sqlind)[sizeof(short)];
}
break;
case PDO_PARAM_EVT_EXEC_PRE:
if (!param->is_param) {
break;
}
*var->sqlind = 0;
if (Z_ISREF(param->parameter)) {
parameter = Z_REFVAL(param->parameter);
} else {
parameter = ¶m->parameter;
}
if (Z_TYPE_P(parameter) == IS_RESOURCE) {
php_stream *stm = NULL;
php_stream_from_zval_no_verify(stm, parameter);
if (stm) {
zend_string *mem = php_stream_copy_to_mem(stm, PHP_STREAM_COPY_ALL, 0);
zval_ptr_dtor(parameter);
ZVAL_STR(parameter, mem ? mem : ZSTR_EMPTY_ALLOC());
} else {
pdo_raise_impl_error(stmt->dbh, stmt, "HY105", "Expected a stream resource");
return 0;
}
}
switch (var->sqltype & ~1) {
case SQL_ARRAY:
strcpy(stmt->error_code, "HY000");
S->H->last_app_error = "Cannot bind to array field";
return 0;
case SQL_BLOB: {
if (Z_TYPE_P(parameter) == IS_NULL) {
/* Check if field allow NULL values */
if (~var->sqltype & 1) {
strcpy(stmt->error_code, "HY105");
S->H->last_app_error = "Parameter requires non-null value";
return 0;
}
*var->sqlind = -1;
return 1;
}
ISC_QUAD quad = get_isc_quad_from_sqldata(var->sqldata);
if (firebird_bind_blob(stmt, &quad, parameter) != 0) {
memcpy(var->sqldata, &quad, sizeof(quad));
return 1;
}
return 0;
}
}
#ifdef SQL_BOOLEAN
/* keep native BOOLEAN type */
if ((var->sqltype & ~1) == SQL_BOOLEAN) {
switch (Z_TYPE_P(parameter)) {
case IS_LONG:
case IS_DOUBLE:
case IS_TRUE:
case IS_FALSE:
*(FB_BOOLEAN*)var->sqldata = zend_is_true(parameter) ? FB_TRUE : FB_FALSE;
break;
case IS_STRING:
{
zend_long lval;
double dval;
if (Z_STRLEN_P(parameter) == 0) {
*(FB_BOOLEAN*)var->sqldata = FB_FALSE;
break;
}
switch (is_numeric_string(Z_STRVAL_P(parameter), Z_STRLEN_P(parameter), &lval, &dval, 0)) {
case IS_LONG:
*(FB_BOOLEAN*)var->sqldata = (lval != 0) ? FB_TRUE : FB_FALSE;
break;
case IS_DOUBLE:
*(FB_BOOLEAN*)var->sqldata = (dval != 0) ? FB_TRUE : FB_FALSE;
break;
default:
if (!zend_binary_strncasecmp(Z_STRVAL_P(parameter), Z_STRLEN_P(parameter), "true", 4, 4)) {
*(FB_BOOLEAN*)var->sqldata = FB_TRUE;
} else if (!zend_binary_strncasecmp(Z_STRVAL_P(parameter), Z_STRLEN_P(parameter), "false", 5, 5)) {
*(FB_BOOLEAN*)var->sqldata = FB_FALSE;
} else {
strcpy(stmt->error_code, "HY105");
S->H->last_app_error = "Cannot convert string to boolean";
return 0;
}
}
}
break;
case IS_NULL:
*var->sqlind = -1;
break;
default:
strcpy(stmt->error_code, "HY105");
S->H->last_app_error = "Binding arrays/objects is not supported";
return 0;
}
break;
}
#endif
/* check if a NULL should be inserted */
switch (Z_TYPE_P(parameter)) {
int force_null;
case IS_LONG:
/* keep the allow-NULL flag */
var->sqltype = (sizeof(zend_long) == 8 ? SQL_INT64 : SQL_LONG) | (var->sqltype & 1);
var->sqldata = (void*)&Z_LVAL_P(parameter);
var->sqllen = sizeof(zend_long);
break;
case IS_DOUBLE:
/* keep the allow-NULL flag */
var->sqltype = SQL_DOUBLE | (var->sqltype & 1);
var->sqldata = (void*)&Z_DVAL_P(parameter);
var->sqllen = sizeof(double);
break;
case IS_STRING:
force_null = 0;
/* for these types, an empty string can be handled like a NULL value */
switch (var->sqltype & ~1) {
case SQL_SHORT:
case SQL_LONG:
case SQL_INT64:
case SQL_FLOAT:
case SQL_DOUBLE:
case SQL_TIMESTAMP:
case SQL_TYPE_DATE:
case SQL_TYPE_TIME:
force_null = (Z_STRLEN_P(parameter) == 0);
}
if (!force_null) {
/* keep the allow-NULL flag */
var->sqltype = SQL_TEXT | (var->sqltype & 1);
var->sqldata = Z_STRVAL_P(parameter);
var->sqllen = Z_STRLEN_P(parameter);
break;
}
ZEND_FALLTHROUGH;
case IS_NULL:
/* complain if this field doesn't allow NULL values */
if (~var->sqltype & 1) {
strcpy(stmt->error_code, "HY105");
S->H->last_app_error = "Parameter requires non-null value";
return 0;
}
*var->sqlind = -1;
break;
default:
strcpy(stmt->error_code, "HY105");
S->H->last_app_error = "Binding arrays/objects is not supported";
return 0;
}
break;
case PDO_PARAM_EVT_FETCH_POST:
if (param->paramno == -1) {
return 0;
}
if (param->is_param) {
break;
}
if (Z_ISREF(param->parameter)) {
parameter = Z_REFVAL(param->parameter);
} else {
parameter = ¶m->parameter;
}
zval_ptr_dtor(parameter);
ZVAL_NULL(parameter);
return firebird_stmt_get_col(stmt, param->paramno, parameter, NULL);
default:
;
}
return 1;
}
/* }}} */
static int firebird_stmt_set_attribute(pdo_stmt_t *stmt, zend_long attr, zval *val) /* {{{ */
{
pdo_firebird_stmt *S = (pdo_firebird_stmt*)stmt->driver_data;
switch (attr) {
default:
return 0;
case PDO_ATTR_CURSOR_NAME:
if (!try_convert_to_string(val)) {
return 0;
}
if (isc_dsql_set_cursor_name(S->H->isc_status, &S->stmt, Z_STRVAL_P(val),0)) {
RECORD_ERROR(stmt);
return 0;
}
strlcpy(S->name, Z_STRVAL_P(val), sizeof(S->name));
break;
}
return 1;
}
/* }}} */
static int firebird_stmt_get_attribute(pdo_stmt_t *stmt, zend_long attr, zval *val) /* {{{ */
{
pdo_firebird_stmt *S = (pdo_firebird_stmt*)stmt->driver_data;
switch (attr) {
default:
return 0;
case PDO_ATTR_CURSOR_NAME:
if (*S->name) {
ZVAL_STRING(val, S->name);
} else {
ZVAL_NULL(val);
}
break;
}
return 1;
}
/* }}} */
static int firebird_stmt_cursor_closer(pdo_stmt_t *stmt) /* {{{ */
{
pdo_firebird_stmt *S = (pdo_firebird_stmt*)stmt->driver_data;
/* close the statement handle */
if ((*S->name || S->cursor_open) && isc_dsql_free_statement(S->H->isc_status, &S->stmt, DSQL_close)) {
RECORD_ERROR(stmt);
return 0;
}
*S->name = 0;
S->cursor_open = 0;
return 1;
}
/* }}} */
const struct pdo_stmt_methods firebird_stmt_methods = { /* {{{ */
firebird_stmt_dtor,
firebird_stmt_execute,
firebird_stmt_fetch,
firebird_stmt_describe,
firebird_stmt_get_col,
firebird_stmt_param_hook,
firebird_stmt_set_attribute,
firebird_stmt_get_attribute,
firebird_stmt_get_column_meta,
NULL, /* next_rowset_func */
firebird_stmt_cursor_closer
};
/* }}} */
| 23,523 | 26.321719 | 110 |
c
|
php-src
|
php-src-master/ext/pdo_firebird/pdo_firebird.c
|
/*
+----------------------------------------------------------------------+
| Copyright (c) The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| https://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| [email protected] so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Author: Ard Biesheuvel <[email protected]> |
+----------------------------------------------------------------------+
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "php.h"
#include "php_ini.h"
#include "ext/standard/info.h"
#include "pdo/php_pdo.h"
#include "pdo/php_pdo_driver.h"
#include "php_pdo_firebird.h"
#include "php_pdo_firebird_int.h"
/* {{{ pdo_firebird_deps */
static const zend_module_dep pdo_firebird_deps[] = {
ZEND_MOD_REQUIRED("pdo")
ZEND_MOD_END
};
/* }}} */
zend_module_entry pdo_firebird_module_entry = { /* {{{ */
STANDARD_MODULE_HEADER_EX, NULL,
pdo_firebird_deps,
"PDO_Firebird",
NULL,
PHP_MINIT(pdo_firebird),
PHP_MSHUTDOWN(pdo_firebird),
NULL,
NULL,
PHP_MINFO(pdo_firebird),
PHP_PDO_FIREBIRD_VERSION,
STANDARD_MODULE_PROPERTIES
};
/* }}} */
#ifdef COMPILE_DL_PDO_FIREBIRD
ZEND_GET_MODULE(pdo_firebird)
#endif
PHP_MINIT_FUNCTION(pdo_firebird) /* {{{ */
{
REGISTER_PDO_CLASS_CONST_LONG("FB_ATTR_DATE_FORMAT", (zend_long) PDO_FB_ATTR_DATE_FORMAT);
REGISTER_PDO_CLASS_CONST_LONG("FB_ATTR_TIME_FORMAT", (zend_long) PDO_FB_ATTR_TIME_FORMAT);
REGISTER_PDO_CLASS_CONST_LONG("FB_ATTR_TIMESTAMP_FORMAT", (zend_long) PDO_FB_ATTR_TIMESTAMP_FORMAT);
if (FAILURE == php_pdo_register_driver(&pdo_firebird_driver)) {
return FAILURE;
}
#ifdef ZEND_SIGNALS
/* firebird replaces some signals at runtime, suppress warnings. */
SIGG(check) = 0;
#endif
return SUCCESS;
}
/* }}} */
PHP_MSHUTDOWN_FUNCTION(pdo_firebird) /* {{{ */
{
php_pdo_unregister_driver(&pdo_firebird_driver);
return SUCCESS;
}
/* }}} */
PHP_MINFO_FUNCTION(pdo_firebird) /* {{{ */
{
char version[64];
isc_get_client_version(version);
php_info_print_table_start();
php_info_print_table_row(2, "PDO Driver for Firebird", "enabled");
php_info_print_table_row(2, "Client Library Version", version);
php_info_print_table_end();
}
/* }}} */
| 2,725 | 28.311828 | 101 |
c
|
php-src
|
php-src-master/ext/pdo_firebird/php_pdo_firebird.h
|
/*
+----------------------------------------------------------------------+
| Copyright (c) The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| https://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| [email protected] so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Author: Ard Biesheuvel <[email protected]> |
+----------------------------------------------------------------------+
*/
#ifndef PHP_PDO_FIREBIRD_H
#define PHP_PDO_FIREBIRD_H
extern zend_module_entry pdo_firebird_module_entry;
#define phpext_pdo_firebird_ptr &pdo_firebird_module_entry
#include "php_version.h"
#define PHP_PDO_FIREBIRD_VERSION PHP_VERSION
#ifdef ZTS
#include "TSRM.h"
#endif
PHP_MINIT_FUNCTION(pdo_firebird);
PHP_MSHUTDOWN_FUNCTION(pdo_firebird);
PHP_RINIT_FUNCTION(pdo_firebird);
PHP_RSHUTDOWN_FUNCTION(pdo_firebird);
PHP_MINFO_FUNCTION(pdo_firebird);
#endif /* PHP_PDO_FIREBIRD_H */
| 1,468 | 38.702703 | 74 |
h
|
php-src
|
php-src-master/ext/pdo_firebird/php_pdo_firebird_int.h
|
/*
+----------------------------------------------------------------------+
| Copyright (c) The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| https://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| [email protected] so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Author: Ard Biesheuvel <[email protected]> |
+----------------------------------------------------------------------+
*/
#ifndef PHP_PDO_FIREBIRD_INT_H
#define PHP_PDO_FIREBIRD_INT_H
#include <ibase.h>
#ifdef SQLDA_VERSION
#define PDO_FB_SQLDA_VERSION SQLDA_VERSION
#else
#define PDO_FB_SQLDA_VERSION 1
#endif
#define PDO_FB_DIALECT 3
#define PDO_FB_DEF_DATE_FMT "%Y-%m-%d"
#define PDO_FB_DEF_TIME_FMT "%H:%M:%S"
#define PDO_FB_DEF_TIMESTAMP_FMT PDO_FB_DEF_DATE_FMT " " PDO_FB_DEF_TIME_FMT
#define SHORT_MAX (1 << (8*sizeof(short)-1))
#if SIZEOF_ZEND_LONG == 8 && !defined(PHP_WIN32)
# define LL_LIT(lit) lit ## L
#else
# define LL_LIT(lit) lit ## LL
#endif
#define LL_MASK "ll"
/* Firebird API has a couple of missing const decls in its API */
#define const_cast(s) ((char*)(s))
#ifdef PHP_WIN32
typedef void (__stdcall *info_func_t)(char*);
#else
typedef void (*info_func_t)(char*);
#endif
#ifndef min
#define min(a,b) ((a)<(b)?(a):(b))
#endif
#if defined(_LP64) || defined(__LP64__) || defined(__arch64__) || defined(_WIN64)
# define PDO_FIREBIRD_HANDLE_INITIALIZER 0U
#else
# define PDO_FIREBIRD_HANDLE_INITIALIZER NULL
#endif
typedef struct {
/* the result of the last API call */
ISC_STATUS isc_status[20];
/* the connection handle */
isc_db_handle db;
/* the transaction handle */
isc_tr_handle tr;
/* the last error that didn't come from the API */
char const *last_app_error;
/* date and time format strings, can be set by the set_attribute method */
char *date_format;
char *time_format;
char *timestamp_format;
unsigned sql_dialect:2;
/* prepend table names on column names in fetch */
unsigned fetch_table_names:1;
unsigned _reserved:29;
} pdo_firebird_db_handle;
typedef struct {
/* the link that owns this statement */
pdo_firebird_db_handle *H;
/* the statement handle */
isc_stmt_handle stmt;
/* the name of the cursor (if it has one) */
char name[32];
/* the type of statement that was issued */
char statement_type:8;
/* whether EOF was reached for this statement */
unsigned exhausted:1;
/* successful isc_dsql_execute opens a cursor */
unsigned cursor_open:1;
unsigned _reserved:22;
/* the named params that were converted to ?'s by the driver */
HashTable *named_params;
/* the input SQLDA */
XSQLDA *in_sqlda;
/* the output SQLDA */
XSQLDA out_sqlda; /* last member */
} pdo_firebird_stmt;
extern const pdo_driver_t pdo_firebird_driver;
extern const struct pdo_stmt_methods firebird_stmt_methods;
void _firebird_error(pdo_dbh_t *dbh, pdo_stmt_t *stmt, char const *file, zend_long line);
enum {
PDO_FB_ATTR_DATE_FORMAT = PDO_ATTR_DRIVER_SPECIFIC,
PDO_FB_ATTR_TIME_FORMAT,
PDO_FB_ATTR_TIMESTAMP_FORMAT,
};
#endif /* PHP_PDO_FIREBIRD_INT_H */
| 3,599 | 25.277372 | 89 |
h
|
php-src
|
php-src-master/ext/pdo_mysql/mysql_statement.c
|
/*
+----------------------------------------------------------------------+
| Copyright (c) The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| https://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| [email protected] so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Author: George Schlossnagle <[email protected]> |
| Wez Furlong <[email protected]> |
| Johannes Schlueter <[email protected]> |
+----------------------------------------------------------------------+
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "php.h"
#include "php_ini.h"
#include "ext/standard/info.h"
#include "pdo/php_pdo.h"
#include "pdo/php_pdo_driver.h"
#include "php_pdo_mysql.h"
#include "php_pdo_mysql_int.h"
#ifdef PDO_USE_MYSQLND
# define pdo_mysql_stmt_execute_prepared(stmt) pdo_mysql_stmt_execute_prepared_mysqlnd(stmt)
#else
# define pdo_mysql_stmt_execute_prepared(stmt) pdo_mysql_stmt_execute_prepared_libmysql(stmt)
#endif
static void pdo_mysql_free_result(pdo_mysql_stmt *S)
{
if (S->result) {
#ifndef PDO_USE_MYSQLND
if (S->bound_result) {
/* We can't use stmt->column_count here, because it gets reset before the
* next_rowset handler is called. */
unsigned column_count = mysql_num_fields(S->result);
for (unsigned i = 0; i < column_count; i++) {
efree(S->bound_result[i].buffer);
}
efree(S->bound_result);
efree(S->out_null);
efree(S->out_length);
S->bound_result = NULL;
}
#else
if (S->current_row) {
unsigned column_count = mysql_num_fields(S->result);
for (unsigned i = 0; i < column_count; i++) {
zval_ptr_dtor_nogc(&S->current_row[i]);
}
efree(S->current_row);
S->current_row = NULL;
}
#endif
mysql_free_result(S->result);
S->result = NULL;
}
}
static int pdo_mysql_stmt_dtor(pdo_stmt_t *stmt) /* {{{ */
{
pdo_mysql_stmt *S = (pdo_mysql_stmt*)stmt->driver_data;
PDO_DBG_ENTER("pdo_mysql_stmt_dtor");
PDO_DBG_INF_FMT("stmt=%p", S->stmt);
pdo_mysql_free_result(S);
if (S->einfo.errmsg) {
pefree(S->einfo.errmsg, stmt->dbh->is_persistent);
S->einfo.errmsg = NULL;
}
if (S->stmt) {
mysql_stmt_close(S->stmt);
S->stmt = NULL;
}
#ifndef PDO_USE_MYSQLND
if (S->params) {
efree(S->params);
}
if (S->in_null) {
efree(S->in_null);
}
if (S->in_length) {
efree(S->in_length);
}
#endif
if (!S->done && !Z_ISUNDEF(stmt->database_object_handle)
&& IS_OBJ_VALID(EG(objects_store).object_buckets[Z_OBJ_HANDLE(stmt->database_object_handle)])
&& (!(OBJ_FLAGS(Z_OBJ(stmt->database_object_handle)) & IS_OBJ_FREE_CALLED))) {
while (mysql_more_results(S->H->server)) {
MYSQL_RES *res;
if (mysql_next_result(S->H->server) != 0) {
break;
}
res = mysql_store_result(S->H->server);
if (res) {
mysql_free_result(res);
}
}
}
efree(S);
PDO_DBG_RETURN(1);
}
/* }}} */
static void pdo_mysql_stmt_set_row_count(pdo_stmt_t *stmt) /* {{{ */
{
pdo_mysql_stmt *S = stmt->driver_data;
zend_long row_count = (zend_long) mysql_stmt_affected_rows(S->stmt);
if (row_count != (zend_long)-1) {
stmt->row_count = row_count;
}
}
/* }}} */
static int pdo_mysql_fill_stmt_from_result(pdo_stmt_t *stmt) /* {{{ */
{
pdo_mysql_stmt *S = (pdo_mysql_stmt*)stmt->driver_data;
pdo_mysql_db_handle *H = S->H;
my_ulonglong row_count;
PDO_DBG_ENTER("pdo_mysql_fill_stmt_from_result");
row_count = mysql_affected_rows(H->server);
if (row_count == (my_ulonglong)-1) {
/* we either have a query that returned a result set or an error occurred
lets see if we have access to a result set */
if (!H->buffered) {
S->result = mysql_use_result(H->server);
} else {
S->result = mysql_store_result(H->server);
}
if (NULL == S->result) {
pdo_mysql_error_stmt(stmt);
PDO_DBG_RETURN(0);
}
stmt->row_count = (zend_long) mysql_num_rows(S->result);
php_pdo_stmt_set_column_count(stmt, (int) mysql_num_fields(S->result));
S->fields = mysql_fetch_fields(S->result);
} else {
/* this was a DML or DDL query (INSERT, UPDATE, DELETE, ... */
stmt->row_count = (zend_long) row_count;
}
PDO_DBG_RETURN(1);
}
/* }}} */
static bool pdo_mysql_stmt_after_execute_prepared(pdo_stmt_t *stmt) {
pdo_mysql_stmt *S = stmt->driver_data;
pdo_mysql_db_handle *H = S->H;
#ifdef PDO_USE_MYSQLND
/* For SHOW/DESCRIBE and others the column/field count is not available before execute. */
php_pdo_stmt_set_column_count(stmt, mysql_stmt_field_count(S->stmt));
for (int i = 0; i < stmt->column_count; i++) {
mysqlnd_stmt_bind_one_result(S->stmt, i);
}
S->result = mysqlnd_stmt_result_metadata(S->stmt);
if (S->result) {
S->fields = mysql_fetch_fields(S->result);
/* If buffered, pre-fetch all the data */
if (H->buffered) {
if (mysql_stmt_store_result(S->stmt)) {
pdo_mysql_error_stmt(stmt);
return false;
}
}
}
#else
/* figure out the result set format, if any */
S->result = mysql_stmt_result_metadata(S->stmt);
if (S->result) {
int calc_max_length = H->buffered && S->max_length == 1;
S->fields = mysql_fetch_fields(S->result);
php_pdo_stmt_set_column_count(stmt, (int)mysql_num_fields(S->result));
S->bound_result = ecalloc(stmt->column_count, sizeof(MYSQL_BIND));
S->out_null = ecalloc(stmt->column_count, sizeof(my_bool));
S->out_length = ecalloc(stmt->column_count, sizeof(zend_ulong));
/* summon memory to hold the row */
for (int i = 0; i < stmt->column_count; i++) {
if (calc_max_length && S->fields[i].type == FIELD_TYPE_BLOB) {
my_bool on = 1;
mysql_stmt_attr_set(S->stmt, STMT_ATTR_UPDATE_MAX_LENGTH, &on);
calc_max_length = 0;
}
switch (S->fields[i].type) {
case FIELD_TYPE_INT24:
S->bound_result[i].buffer_length = MAX_MEDIUMINT_WIDTH + 1;
break;
case FIELD_TYPE_LONG:
S->bound_result[i].buffer_length = MAX_INT_WIDTH + 1;
break;
case FIELD_TYPE_LONGLONG:
S->bound_result[i].buffer_length = MAX_BIGINT_WIDTH + 1;
break;
case FIELD_TYPE_TINY:
S->bound_result[i].buffer_length = MAX_TINYINT_WIDTH + 1;
break;
case FIELD_TYPE_SHORT:
S->bound_result[i].buffer_length = MAX_SMALLINT_WIDTH + 1;
break;
default:
S->bound_result[i].buffer_length =
S->fields[i].max_length? S->fields[i].max_length:
S->fields[i].length;
/* work-around for longtext and alike */
if (S->bound_result[i].buffer_length > H->max_buffer_size) {
S->bound_result[i].buffer_length = H->max_buffer_size;
}
}
/* there are cases where the length reported by mysql is too short.
* eg: when describing a table that contains an enum column. Since
* we have no way of knowing the true length either, we'll bump up
* our buffer size to a reasonable size, just in case */
if (S->fields[i].max_length == 0 && S->bound_result[i].buffer_length < 128 && MYSQL_TYPE_VAR_STRING) {
S->bound_result[i].buffer_length = 128;
}
S->out_length[i] = 0;
S->bound_result[i].buffer = emalloc(S->bound_result[i].buffer_length);
S->bound_result[i].is_null = &S->out_null[i];
S->bound_result[i].length = &S->out_length[i];
S->bound_result[i].buffer_type = MYSQL_TYPE_STRING;
}
if (mysql_stmt_bind_result(S->stmt, S->bound_result)) {
pdo_mysql_error_stmt(stmt);
PDO_DBG_RETURN(0);
}
/* if buffered, pre-fetch all the data */
if (H->buffered) {
if (mysql_stmt_store_result(S->stmt)) {
pdo_mysql_error_stmt(stmt);
PDO_DBG_RETURN(0);
}
}
}
#endif
pdo_mysql_stmt_set_row_count(stmt);
return true;
}
#ifndef PDO_USE_MYSQLND
static int pdo_mysql_stmt_execute_prepared_libmysql(pdo_stmt_t *stmt) /* {{{ */
{
pdo_mysql_stmt *S = stmt->driver_data;
PDO_DBG_ENTER("pdo_mysql_stmt_execute_prepared_libmysql");
/* (re)bind the parameters */
if (mysql_stmt_bind_param(S->stmt, S->params) || mysql_stmt_execute(S->stmt)) {
if (S->params) {
memset(S->params, 0, S->num_params * sizeof(MYSQL_BIND));
}
pdo_mysql_error_stmt(stmt);
if (mysql_stmt_errno(S->stmt) == 2057) {
/* CR_NEW_STMT_METADATA makes the statement unusable */
S->stmt = NULL;
}
PDO_DBG_RETURN(0);
}
PDO_DBG_RETURN(pdo_mysql_stmt_after_execute_prepared(stmt));
}
/* }}} */
#endif
#ifdef PDO_USE_MYSQLND
static int pdo_mysql_stmt_execute_prepared_mysqlnd(pdo_stmt_t *stmt) /* {{{ */
{
pdo_mysql_stmt *S = stmt->driver_data;
PDO_DBG_ENTER("pdo_mysql_stmt_execute_prepared_mysqlnd");
if (mysql_stmt_execute(S->stmt)) {
pdo_mysql_error_stmt(stmt);
PDO_DBG_RETURN(0);
}
PDO_DBG_RETURN(pdo_mysql_stmt_after_execute_prepared(stmt));
}
/* }}} */
#endif
static int pdo_mysql_stmt_execute(pdo_stmt_t *stmt) /* {{{ */
{
pdo_mysql_stmt *S = (pdo_mysql_stmt*)stmt->driver_data;
pdo_mysql_db_handle *H = S->H;
PDO_DBG_ENTER("pdo_mysql_stmt_execute");
PDO_DBG_INF_FMT("stmt=%p", S->stmt);
/* ensure that we free any previous unfetched results */
pdo_mysql_free_result(S);
S->done = 0;
if (S->stmt) {
uint32_t num_bound_params =
stmt->bound_params ? zend_hash_num_elements(stmt->bound_params) : 0;
if (num_bound_params < (uint32_t) S->num_params) {
/* too few parameter bound */
PDO_DBG_ERR("too few parameters bound");
strcpy(stmt->error_code, "HY093");
PDO_DBG_RETURN(0);
}
PDO_DBG_RETURN(pdo_mysql_stmt_execute_prepared(stmt));
}
if (mysql_real_query(H->server, ZSTR_VAL(stmt->active_query_string), ZSTR_LEN(stmt->active_query_string)) != 0) {
pdo_mysql_error_stmt(stmt);
PDO_DBG_RETURN(0);
}
PDO_DBG_RETURN(pdo_mysql_fill_stmt_from_result(stmt));
}
/* }}} */
static int pdo_mysql_stmt_next_rowset(pdo_stmt_t *stmt) /* {{{ */
{
pdo_mysql_stmt *S = (pdo_mysql_stmt*)stmt->driver_data;
pdo_mysql_db_handle *H = S->H;
PDO_DBG_ENTER("pdo_mysql_stmt_next_rowset");
PDO_DBG_INF_FMT("stmt=%p", S->stmt);
/* ensure that we free any previous unfetched results */
pdo_mysql_free_result(S);
if (S->stmt) {
mysql_stmt_free_result(S->stmt);
if (mysql_stmt_next_result(S->stmt)) {
pdo_mysql_error_stmt(stmt);
S->done = 1;
PDO_DBG_RETURN(0);
}
PDO_DBG_RETURN(pdo_mysql_stmt_after_execute_prepared(stmt));
} else {
if (mysql_next_result(H->server)) {
pdo_mysql_error_stmt(stmt);
S->done = 1;
PDO_DBG_RETURN(0);
}
PDO_DBG_RETURN(pdo_mysql_fill_stmt_from_result(stmt));
}
}
/* }}} */
static const char * const pdo_param_event_names[] =
{
"PDO_PARAM_EVT_ALLOC",
"PDO_PARAM_EVT_FREE",
"PDO_PARAM_EVT_EXEC_PRE",
"PDO_PARAM_EVT_EXEC_POST",
"PDO_PARAM_EVT_FETCH_PRE",
"PDO_PARAM_EVT_FETCH_POST",
"PDO_PARAM_EVT_NORMALIZE",
};
#ifndef PDO_USE_MYSQLND
static unsigned char libmysql_false_buffer = 0;
static unsigned char libmysql_true_buffer = 1;
#endif
static int pdo_mysql_stmt_param_hook(pdo_stmt_t *stmt, struct pdo_bound_param_data *param, enum pdo_param_event event_type) /* {{{ */
{
zval *parameter;
#ifndef PDO_USE_MYSQLND
PDO_MYSQL_PARAM_BIND *b;
#endif
pdo_mysql_stmt *S = (pdo_mysql_stmt*)stmt->driver_data;
PDO_DBG_ENTER("pdo_mysql_stmt_param_hook");
PDO_DBG_INF_FMT("stmt=%p", S->stmt);
PDO_DBG_INF_FMT("event = %s", pdo_param_event_names[event_type]);
if (S->stmt && param->is_param) {
switch (event_type) {
case PDO_PARAM_EVT_ALLOC:
/* sanity check parameter number range */
if (param->paramno < 0 || param->paramno >= S->num_params) {
strcpy(stmt->error_code, "HY093");
PDO_DBG_RETURN(0);
}
#ifndef PDO_USE_MYSQLND
b = &S->params[param->paramno];
param->driver_data = b;
b->is_null = &S->in_null[param->paramno];
b->length = &S->in_length[param->paramno];
/* recall how many parameters have been provided */
#endif
PDO_DBG_RETURN(1);
case PDO_PARAM_EVT_EXEC_PRE:
if (!Z_ISREF(param->parameter)) {
parameter = ¶m->parameter;
} else {
parameter = Z_REFVAL(param->parameter);
}
#ifdef PDO_USE_MYSQLND
if (PDO_PARAM_TYPE(param->param_type) == PDO_PARAM_NULL || (Z_TYPE_P(parameter) == IS_NULL)) {
mysqlnd_stmt_bind_one_param(S->stmt, param->paramno, parameter, MYSQL_TYPE_NULL);
PDO_DBG_RETURN(1);
}
#else
b = (PDO_MYSQL_PARAM_BIND*)param->driver_data;
*b->is_null = 0;
if (PDO_PARAM_TYPE(param->param_type) == PDO_PARAM_NULL || Z_TYPE_P(parameter) == IS_NULL) {
*b->is_null = 1;
b->buffer_type = MYSQL_TYPE_STRING;
b->buffer = NULL;
b->buffer_length = 0;
*b->length = 0;
PDO_DBG_RETURN(1);
}
#endif /* PDO_USE_MYSQLND */
switch (PDO_PARAM_TYPE(param->param_type)) {
case PDO_PARAM_STMT:
PDO_DBG_RETURN(0);
case PDO_PARAM_LOB:
PDO_DBG_INF("PDO_PARAM_LOB");
if (!Z_ISREF(param->parameter)) {
parameter = ¶m->parameter;
} else {
parameter = Z_REFVAL(param->parameter);
}
if (Z_TYPE_P(parameter) == IS_RESOURCE) {
php_stream *stm = NULL;
php_stream_from_zval_no_verify(stm, parameter);
if (stm) {
zend_string *mem = php_stream_copy_to_mem(stm, PHP_STREAM_COPY_ALL, 0);
zval_ptr_dtor(parameter);
ZVAL_STR(parameter, mem ? mem : ZSTR_EMPTY_ALLOC());
} else {
pdo_raise_impl_error(stmt->dbh, stmt, "HY105", "Expected a stream resource");
return 0;
}
}
/* fall through */
default:
;
}
#ifdef PDO_USE_MYSQLND
/* Is it really correct to check the zval's type? - But well, that's what the old code below does, too */
PDO_DBG_INF_FMT("param->parameter->type=%d", Z_TYPE(param->parameter));
if (!Z_ISREF(param->parameter)) {
parameter = ¶m->parameter;
} else {
parameter = Z_REFVAL(param->parameter);
}
switch (Z_TYPE_P(parameter)) {
case IS_STRING:
mysqlnd_stmt_bind_one_param(S->stmt, param->paramno, parameter, MYSQL_TYPE_VAR_STRING);
break;
case IS_LONG:
#if SIZEOF_ZEND_LONG==8
mysqlnd_stmt_bind_one_param(S->stmt, param->paramno, parameter, MYSQL_TYPE_LONGLONG);
#elif SIZEOF_ZEND_LONG==4
mysqlnd_stmt_bind_one_param(S->stmt, param->paramno, parameter, MYSQL_TYPE_LONG);
#endif /* SIZEOF_LONG */
break;
case IS_TRUE:
case IS_FALSE:
mysqlnd_stmt_bind_one_param(S->stmt, param->paramno, parameter, MYSQL_TYPE_TINY);
break;
case IS_DOUBLE:
mysqlnd_stmt_bind_one_param(S->stmt, param->paramno, parameter, MYSQL_TYPE_DOUBLE);
break;
default:
PDO_DBG_RETURN(0);
}
PDO_DBG_RETURN(1);
#else
PDO_DBG_INF_FMT("param->parameter->type=%d", Z_TYPE(param->parameter));
if (!Z_ISREF(param->parameter)) {
parameter = ¶m->parameter;
} else {
parameter = Z_REFVAL(param->parameter);
}
switch (Z_TYPE_P(parameter)) {
case IS_STRING:
b->buffer_type = MYSQL_TYPE_STRING;
b->buffer = Z_STRVAL_P(parameter);
b->buffer_length = Z_STRLEN_P(parameter);
*b->length = Z_STRLEN_P(parameter);
PDO_DBG_RETURN(1);
case IS_FALSE:
b->buffer_type = MYSQL_TYPE_TINY;
b->buffer = &libmysql_false_buffer;
PDO_DBG_RETURN(1);
case IS_TRUE:
b->buffer_type = MYSQL_TYPE_TINY;
b->buffer = &libmysql_true_buffer;
PDO_DBG_RETURN(1);
case IS_LONG:
b->buffer_type = MYSQL_TYPE_LONG;
b->buffer = &Z_LVAL_P(parameter);
PDO_DBG_RETURN(1);
case IS_DOUBLE:
b->buffer_type = MYSQL_TYPE_DOUBLE;
b->buffer = &Z_DVAL_P(parameter);
PDO_DBG_RETURN(1);
default:
PDO_DBG_RETURN(0);
}
#endif /* PDO_USE_MYSQLND */
case PDO_PARAM_EVT_FREE:
case PDO_PARAM_EVT_EXEC_POST:
case PDO_PARAM_EVT_FETCH_PRE:
case PDO_PARAM_EVT_FETCH_POST:
case PDO_PARAM_EVT_NORMALIZE:
/* do nothing */
break;
}
}
PDO_DBG_RETURN(1);
}
/* }}} */
static int pdo_mysql_stmt_fetch(pdo_stmt_t *stmt, enum pdo_fetch_orientation ori, zend_long offset) /* {{{ */
{
pdo_mysql_stmt *S = (pdo_mysql_stmt*)stmt->driver_data;
if (!S->result) {
PDO_DBG_RETURN(0);
}
#ifdef PDO_USE_MYSQLND
bool fetched_anything;
PDO_DBG_ENTER("pdo_mysql_stmt_fetch");
PDO_DBG_INF_FMT("stmt=%p", S->stmt);
if (S->stmt) {
if (FAIL == mysqlnd_stmt_fetch(S->stmt, &fetched_anything) || !fetched_anything) {
pdo_mysql_error_stmt(stmt);
PDO_DBG_RETURN(0);
}
PDO_DBG_RETURN(1);
}
zval *row_data;
if (mysqlnd_fetch_row_zval(S->result, &row_data, &fetched_anything) == FAIL) {
pdo_mysql_error_stmt(stmt);
PDO_DBG_RETURN(0);
}
if (!fetched_anything) {
PDO_DBG_RETURN(0);
}
if (!S->current_row) {
S->current_row = ecalloc(sizeof(zval), stmt->column_count);
}
for (unsigned i = 0; i < stmt->column_count; i++) {
zval_ptr_dtor_nogc(&S->current_row[i]);
ZVAL_COPY_VALUE(&S->current_row[i], &row_data[i]);
}
PDO_DBG_RETURN(1);
#else
int ret;
if (S->stmt) {
ret = mysql_stmt_fetch(S->stmt);
# ifdef MYSQL_DATA_TRUNCATED
if (ret == MYSQL_DATA_TRUNCATED) {
ret = 0;
}
# endif
if (ret) {
if (ret != MYSQL_NO_DATA) {
pdo_mysql_error_stmt(stmt);
}
PDO_DBG_RETURN(0);
}
PDO_DBG_RETURN(1);
}
if ((S->current_data = mysql_fetch_row(S->result)) == NULL) {
if (!S->H->buffered && mysql_errno(S->H->server)) {
pdo_mysql_error_stmt(stmt);
}
PDO_DBG_RETURN(0);
}
S->current_lengths = mysql_fetch_lengths(S->result);
PDO_DBG_RETURN(1);
#endif /* PDO_USE_MYSQLND */
}
/* }}} */
static int pdo_mysql_stmt_describe(pdo_stmt_t *stmt, int colno) /* {{{ */
{
pdo_mysql_stmt *S = (pdo_mysql_stmt*)stmt->driver_data;
struct pdo_column_data *cols = stmt->columns;
int i;
PDO_DBG_ENTER("pdo_mysql_stmt_describe");
PDO_DBG_INF_FMT("stmt=%p", S->stmt);
if (!S->result) {
PDO_DBG_RETURN(0);
}
if (colno >= stmt->column_count) {
/* error invalid column */
PDO_DBG_RETURN(0);
}
/* fetch all on demand, this seems easiest
** if we've been here before bail out
*/
if (cols[0].name) {
PDO_DBG_RETURN(1);
}
for (i = 0; i < stmt->column_count; i++) {
if (S->H->fetch_table_names) {
cols[i].name = strpprintf(0, "%s.%s", S->fields[i].table, S->fields[i].name);
} else {
#ifdef PDO_USE_MYSQLND
cols[i].name = zend_string_copy(S->fields[i].sname);
#else
cols[i].name = zend_string_init(S->fields[i].name, S->fields[i].name_length, 0);
#endif
}
cols[i].precision = S->fields[i].decimals;
cols[i].maxlen = S->fields[i].length;
}
PDO_DBG_RETURN(1);
}
/* }}} */
static int pdo_mysql_stmt_get_col(
pdo_stmt_t *stmt, int colno, zval *result, enum pdo_param_type *type) /* {{{ */
{
pdo_mysql_stmt *S = (pdo_mysql_stmt*)stmt->driver_data;
PDO_DBG_ENTER("pdo_mysql_stmt_get_col");
PDO_DBG_INF_FMT("stmt=%p", S->stmt);
if (!S->result) {
PDO_DBG_RETURN(0);
}
if (colno >= stmt->column_count) {
/* error invalid column */
PDO_DBG_RETURN(0);
}
#ifdef PDO_USE_MYSQLND
if (S->stmt) {
ZVAL_COPY(result, &S->stmt->data->result_bind[colno].zv);
} else {
ZVAL_COPY(result, &S->current_row[colno]);
}
PDO_DBG_RETURN(1);
#else
if (S->stmt) {
if (S->out_null[colno]) {
PDO_DBG_RETURN(1);
}
size_t length = S->out_length[colno];
if (length > S->bound_result[colno].buffer_length) {
/* mysql lied about the column width */
strcpy(stmt->error_code, "01004"); /* truncated */
length = S->out_length[colno] = S->bound_result[colno].buffer_length;
}
ZVAL_STRINGL_FAST(result, S->bound_result[colno].buffer, length);
PDO_DBG_RETURN(1);
}
if (S->current_data == NULL) {
PDO_DBG_RETURN(0);
}
if (S->current_data[colno]) {
ZVAL_STRINGL_FAST(result, S->current_data[colno], S->current_lengths[colno]);
}
PDO_DBG_RETURN(1);
#endif
} /* }}} */
static char *type_to_name_native(int type) /* {{{ */
{
#define PDO_MYSQL_NATIVE_TYPE_NAME(x) case FIELD_TYPE_##x: return #x;
switch (type) {
PDO_MYSQL_NATIVE_TYPE_NAME(STRING)
PDO_MYSQL_NATIVE_TYPE_NAME(VAR_STRING)
#ifdef FIELD_TYPE_TINY
PDO_MYSQL_NATIVE_TYPE_NAME(TINY)
#endif
#ifdef FIELD_TYPE_BIT
PDO_MYSQL_NATIVE_TYPE_NAME(BIT)
#endif
PDO_MYSQL_NATIVE_TYPE_NAME(SHORT)
PDO_MYSQL_NATIVE_TYPE_NAME(LONG)
PDO_MYSQL_NATIVE_TYPE_NAME(LONGLONG)
PDO_MYSQL_NATIVE_TYPE_NAME(INT24)
PDO_MYSQL_NATIVE_TYPE_NAME(FLOAT)
PDO_MYSQL_NATIVE_TYPE_NAME(DOUBLE)
PDO_MYSQL_NATIVE_TYPE_NAME(DECIMAL)
#ifdef FIELD_TYPE_NEWDECIMAL
PDO_MYSQL_NATIVE_TYPE_NAME(NEWDECIMAL)
#endif
#ifdef FIELD_TYPE_GEOMETRY
PDO_MYSQL_NATIVE_TYPE_NAME(GEOMETRY)
#endif
PDO_MYSQL_NATIVE_TYPE_NAME(TIMESTAMP)
#ifdef FIELD_TYPE_YEAR
PDO_MYSQL_NATIVE_TYPE_NAME(YEAR)
#endif
PDO_MYSQL_NATIVE_TYPE_NAME(SET)
PDO_MYSQL_NATIVE_TYPE_NAME(ENUM)
PDO_MYSQL_NATIVE_TYPE_NAME(DATE)
#ifdef FIELD_TYPE_NEWDATE
PDO_MYSQL_NATIVE_TYPE_NAME(NEWDATE)
#endif
PDO_MYSQL_NATIVE_TYPE_NAME(TIME)
PDO_MYSQL_NATIVE_TYPE_NAME(DATETIME)
PDO_MYSQL_NATIVE_TYPE_NAME(TINY_BLOB)
PDO_MYSQL_NATIVE_TYPE_NAME(MEDIUM_BLOB)
PDO_MYSQL_NATIVE_TYPE_NAME(LONG_BLOB)
PDO_MYSQL_NATIVE_TYPE_NAME(BLOB)
PDO_MYSQL_NATIVE_TYPE_NAME(NULL)
default:
return NULL;
}
#undef PDO_MYSQL_NATIVE_TYPE_NAME
} /* }}} */
static int pdo_mysql_stmt_col_meta(pdo_stmt_t *stmt, zend_long colno, zval *return_value) /* {{{ */
{
pdo_mysql_stmt *S = (pdo_mysql_stmt*)stmt->driver_data;
const MYSQL_FIELD *F;
zval flags;
char *str;
PDO_DBG_ENTER("pdo_mysql_stmt_col_meta");
PDO_DBG_INF_FMT("stmt=%p", S->stmt);
if (!S->result) {
PDO_DBG_RETURN(FAILURE);
}
if (colno >= stmt->column_count) {
/* error invalid column */
PDO_DBG_RETURN(FAILURE);
}
array_init(return_value);
array_init(&flags);
F = S->fields + colno;
if (F->def) {
add_assoc_string(return_value, "mysql:def", F->def);
}
if (IS_NOT_NULL(F->flags)) {
add_next_index_string(&flags, "not_null");
}
if (IS_PRI_KEY(F->flags)) {
add_next_index_string(&flags, "primary_key");
}
if (F->flags & MULTIPLE_KEY_FLAG) {
add_next_index_string(&flags, "multiple_key");
}
if (F->flags & UNIQUE_KEY_FLAG) {
add_next_index_string(&flags, "unique_key");
}
if (IS_BLOB(F->flags)) {
add_next_index_string(&flags, "blob");
}
str = type_to_name_native(F->type);
if (str) {
add_assoc_string(return_value, "native_type", str);
}
enum pdo_param_type param_type;
switch (F->type) {
case MYSQL_TYPE_BIT:
case MYSQL_TYPE_YEAR:
case MYSQL_TYPE_TINY:
case MYSQL_TYPE_SHORT:
case MYSQL_TYPE_INT24:
case MYSQL_TYPE_LONG:
#if SIZEOF_ZEND_LONG==8
case MYSQL_TYPE_LONGLONG:
#endif
param_type = PDO_PARAM_INT;
break;
default:
param_type = PDO_PARAM_STR;
break;
}
add_assoc_long(return_value, "pdo_type", param_type);
add_assoc_zval(return_value, "flags", &flags);
add_assoc_string(return_value, "table", (char *) (F->table?F->table : ""));
PDO_DBG_RETURN(SUCCESS);
} /* }}} */
static int pdo_mysql_stmt_cursor_closer(pdo_stmt_t *stmt) /* {{{ */
{
pdo_mysql_stmt *S = (pdo_mysql_stmt*)stmt->driver_data;
PDO_DBG_ENTER("pdo_mysql_stmt_cursor_closer");
PDO_DBG_INF_FMT("stmt=%p", S->stmt);
S->done = 1;
pdo_mysql_free_result(S);
if (S->stmt) {
mysql_stmt_free_result(S->stmt);
}
while (mysql_more_results(S->H->server)) {
MYSQL_RES *res;
if (mysql_next_result(S->H->server) != 0) {
pdo_mysql_error_stmt(stmt);
PDO_DBG_RETURN(0);
}
res = mysql_store_result(S->H->server);
if (res) {
mysql_free_result(res);
}
}
PDO_DBG_RETURN(1);
}
/* }}} */
const struct pdo_stmt_methods mysql_stmt_methods = {
pdo_mysql_stmt_dtor,
pdo_mysql_stmt_execute,
pdo_mysql_stmt_fetch,
pdo_mysql_stmt_describe,
pdo_mysql_stmt_get_col,
pdo_mysql_stmt_param_hook,
NULL, /* set_attr */
NULL, /* get_attr */
pdo_mysql_stmt_col_meta,
pdo_mysql_stmt_next_rowset,
pdo_mysql_stmt_cursor_closer
};
| 23,959 | 26.351598 | 133 |
c
|
php-src
|
php-src-master/ext/pdo_mysql/php_pdo_mysql.h
|
/*
+----------------------------------------------------------------------+
| Copyright (c) The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| https://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| [email protected] so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Author: George Schlossnagle <[email protected]> |
+----------------------------------------------------------------------+
*/
#ifndef PHP_PDO_MYSQL_H
#define PHP_PDO_MYSQL_H
extern zend_module_entry pdo_mysql_module_entry;
#define phpext_pdo_mysql_ptr &pdo_mysql_module_entry
#include "php_version.h"
#define PHP_PDO_MYSQL_VERSION PHP_VERSION
#ifdef PHP_WIN32
#define PHP_PDO_MYSQL_API __declspec(dllexport)
#else
#define PHP_PDO_MYSQL_API
#endif
#ifdef ZTS
#include "TSRM.h"
#endif
#endif /* PHP_PDO_MYSQL_H */
| 1,374 | 35.184211 | 74 |
h
|
php-src
|
php-src-master/ext/pdo_oci/pdo_oci.c
|
/*
+----------------------------------------------------------------------+
| Copyright (c) The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| https://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| [email protected] so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Author: Wez Furlong <[email protected]> |
+----------------------------------------------------------------------+
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "php.h"
#include "php_ini.h"
#include "ext/standard/info.h"
#include "pdo/php_pdo.h"
#include "pdo/php_pdo_driver.h"
#include "php_pdo_oci.h"
#include "php_pdo_oci_int.h"
#ifdef ZTS
#include <TSRM/TSRM.h>
#endif
/* {{{ pdo_oci_module_entry */
static const zend_module_dep pdo_oci_deps[] = {
ZEND_MOD_REQUIRED("pdo")
ZEND_MOD_END
};
zend_module_entry pdo_oci_module_entry = {
STANDARD_MODULE_HEADER_EX, NULL,
pdo_oci_deps,
"PDO_OCI",
NULL,
PHP_MINIT(pdo_oci),
PHP_MSHUTDOWN(pdo_oci),
PHP_RINIT(pdo_oci),
NULL,
PHP_MINFO(pdo_oci),
PHP_PDO_OCI_VERSION,
STANDARD_MODULE_PROPERTIES
};
/* }}} */
#ifdef COMPILE_DL_PDO_OCI
ZEND_GET_MODULE(pdo_oci)
#endif
const ub4 PDO_OCI_INIT_MODE =
#if 0 && defined(OCI_SHARED)
/* shared mode is known to be bad for PHP */
OCI_SHARED
#else
OCI_DEFAULT
#endif
#ifdef OCI_OBJECT
|OCI_OBJECT
#endif
#ifdef ZTS
|OCI_THREADED
#endif
;
/* true global environment */
OCIEnv *pdo_oci_Env = NULL;
#ifdef ZTS
/* lock for pdo_oci_Env initialization */
static MUTEX_T pdo_oci_env_mutex;
#endif
/* {{{ PHP_MINIT_FUNCTION */
PHP_MINIT_FUNCTION(pdo_oci)
{
REGISTER_PDO_CLASS_CONST_LONG("OCI_ATTR_ACTION", (zend_long)PDO_OCI_ATTR_ACTION);
REGISTER_PDO_CLASS_CONST_LONG("OCI_ATTR_CLIENT_INFO", (zend_long)PDO_OCI_ATTR_CLIENT_INFO);
REGISTER_PDO_CLASS_CONST_LONG("OCI_ATTR_CLIENT_IDENTIFIER", (zend_long)PDO_OCI_ATTR_CLIENT_IDENTIFIER);
REGISTER_PDO_CLASS_CONST_LONG("OCI_ATTR_MODULE", (zend_long)PDO_OCI_ATTR_MODULE);
REGISTER_PDO_CLASS_CONST_LONG("OCI_ATTR_CALL_TIMEOUT", (zend_long)PDO_OCI_ATTR_CALL_TIMEOUT);
if (FAILURE == php_pdo_register_driver(&pdo_oci_driver)) {
return FAILURE;
}
// Defer OCI init to PHP_RINIT_FUNCTION because with php-fpm,
// NLS_LANG is not yet available here.
#ifdef ZTS
pdo_oci_env_mutex = tsrm_mutex_alloc();
#endif
return SUCCESS;
}
/* }}} */
/* {{{ PHP_RINIT_FUNCTION */
PHP_RINIT_FUNCTION(pdo_oci)
{
if (!pdo_oci_Env) {
#ifdef ZTS
tsrm_mutex_lock(pdo_oci_env_mutex);
if (!pdo_oci_Env) { // double-checked locking idiom
#endif
#ifdef HAVE_OCIENVCREATE
OCIEnvCreate(&pdo_oci_Env, PDO_OCI_INIT_MODE, NULL, NULL, NULL, NULL, 0, NULL);
#else
OCIInitialize(PDO_OCI_INIT_MODE, NULL, NULL, NULL, NULL);
OCIEnvInit(&pdo_oci_Env, OCI_DEFAULT, 0, NULL);
#endif
#ifdef ZTS
}
tsrm_mutex_unlock(pdo_oci_env_mutex);
#endif
}
return SUCCESS;
}
/* }}} */
/* {{{ PHP_MSHUTDOWN_FUNCTION */
PHP_MSHUTDOWN_FUNCTION(pdo_oci)
{
php_pdo_unregister_driver(&pdo_oci_driver);
if (pdo_oci_Env) {
OCIHandleFree((dvoid*)pdo_oci_Env, OCI_HTYPE_ENV);
}
#ifdef ZTS
tsrm_mutex_free(pdo_oci_env_mutex);
#endif
return SUCCESS;
}
/* }}} */
/* {{{ PHP_MINFO_FUNCTION */
PHP_MINFO_FUNCTION(pdo_oci)
{
php_info_print_table_start();
php_info_print_table_row(2, "PDO Driver for OCI 8 and later", "enabled");
php_info_print_table_end();
}
/* }}} */
| 3,883 | 24.220779 | 104 |
c
|
php-src
|
php-src-master/ext/pdo_oci/php_pdo_oci.h
|
/*
+----------------------------------------------------------------------+
| Copyright (c) The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| https://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| [email protected] so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Author: Wez Furlong <[email protected]> |
+----------------------------------------------------------------------+
*/
#ifndef PHP_PDO_OCI_H
#define PHP_PDO_OCI_H
extern zend_module_entry pdo_oci_module_entry;
#define phpext_pdo_oci_ptr &pdo_oci_module_entry
#include "php_version.h"
#define PHP_PDO_OCI_VERSION PHP_VERSION
#ifdef ZTS
#include "TSRM.h"
#endif
PHP_MINIT_FUNCTION(pdo_oci);
PHP_MSHUTDOWN_FUNCTION(pdo_oci);
PHP_RINIT_FUNCTION(pdo_oci);
PHP_RSHUTDOWN_FUNCTION(pdo_oci);
PHP_MINFO_FUNCTION(pdo_oci);
#endif /* PHP_PDO_OCI_H */
| 1,408 | 37.081081 | 74 |
h
|
php-src
|
php-src-master/ext/pdo_oci/php_pdo_oci_int.h
|
/*
+----------------------------------------------------------------------+
| Copyright (c) The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| https://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| [email protected] so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Author: Wez Furlong <[email protected]> |
+----------------------------------------------------------------------+
*/
#ifndef PHP_PDO_OCI_INT_H
#define PHP_PDO_OCI_INT_H
#include "zend_portability.h"
ZEND_CGG_DIAGNOSTIC_IGNORED_START("-Wstrict-prototypes")
#include <oci.h>
ZEND_CGG_DIAGNOSTIC_IGNORED_END
typedef struct {
const char *file;
int line;
sb4 errcode;
char *errmsg;
} pdo_oci_error_info;
/* stuff we use in an OCI database handle */
typedef struct {
OCIServer *server;
OCISession *session;
OCIEnv *env;
OCIError *err;
OCISvcCtx *svc;
/* OCI9; 0 == use NLS_LANG */
ub4 prefetch;
ub2 charset;
sword last_err;
sb4 max_char_width;
unsigned attached:1;
unsigned _reserved:31;
pdo_oci_error_info einfo;
} pdo_oci_db_handle;
typedef struct {
OCIDefine *def;
ub2 fetched_len;
ub2 retcode;
sb2 indicator;
char *data;
ub4 datalen;
ub2 dtype;
} pdo_oci_column;
typedef struct {
pdo_oci_db_handle *H;
OCIStmt *stmt;
OCIError *err;
sword last_err;
ub2 stmt_type;
ub4 exec_type;
pdo_oci_column *cols;
pdo_oci_error_info einfo;
unsigned int have_blobs:1;
} pdo_oci_stmt;
typedef struct {
OCIBind *bind; /* allocated by OCI */
sb2 oci_type;
sb2 indicator;
ub2 retcode;
ub4 actual_len;
dvoid *thing; /* for LOBS, REFCURSORS etc. */
unsigned used_for_output;
} pdo_oci_bound_param;
extern const ub4 PDO_OCI_INIT_MODE;
extern const pdo_driver_t pdo_oci_driver;
extern OCIEnv *pdo_oci_Env;
ub4 _oci_error(OCIError *err, pdo_dbh_t *dbh, pdo_stmt_t *stmt, char *what, sword status, int isinit, const char *file, int line);
#define oci_init_error(w) _oci_error(H->err, dbh, NULL, w, H->last_err, TRUE, __FILE__, __LINE__)
#define oci_drv_error(w) _oci_error(H->err, dbh, NULL, w, H->last_err, FALSE, __FILE__, __LINE__)
#define oci_stmt_error(w) _oci_error(S->err, stmt->dbh, stmt, w, S->last_err, FALSE, __FILE__, __LINE__)
extern const struct pdo_stmt_methods oci_stmt_methods;
/* Default prefetch size in number of rows */
#define PDO_OCI_PREFETCH_DEFAULT 100
/* Arbitrary assumed row length for prefetch memory limit calcuation */
#define PDO_OCI_PREFETCH_ROWSIZE 1024
enum {
PDO_OCI_ATTR_ACTION = PDO_ATTR_DRIVER_SPECIFIC,
PDO_OCI_ATTR_CLIENT_INFO,
PDO_OCI_ATTR_CLIENT_IDENTIFIER,
PDO_OCI_ATTR_MODULE,
PDO_OCI_ATTR_CALL_TIMEOUT
};
#endif /* PHP_PDO_OCI_INT_H */
| 3,218 | 26.512821 | 130 |
h
|
php-src
|
php-src-master/ext/pdo_odbc/php_pdo_odbc.h
|
/*
+----------------------------------------------------------------------+
| Copyright (c) The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| https://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| [email protected] so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Author: Wez Furlong <[email protected]> |
+----------------------------------------------------------------------+
*/
#ifndef PHP_PDO_ODBC_H
#define PHP_PDO_ODBC_H
extern zend_module_entry pdo_odbc_module_entry;
#define phpext_pdo_odbc_ptr &pdo_odbc_module_entry
#include "php_version.h"
#define PHP_PDO_ODBC_VERSION PHP_VERSION
#ifdef ZTS
#include "TSRM.h"
#endif
PHP_MINIT_FUNCTION(pdo_odbc);
PHP_MSHUTDOWN_FUNCTION(pdo_odbc);
PHP_RINIT_FUNCTION(pdo_odbc);
PHP_RSHUTDOWN_FUNCTION(pdo_odbc);
PHP_MINFO_FUNCTION(pdo_odbc);
#endif /* PHP_PDO_ODBC_H */
| 1,420 | 37.405405 | 74 |
h
|
php-src
|
php-src-master/ext/pdo_odbc/php_pdo_odbc_int.h
|
/*
+----------------------------------------------------------------------+
| Copyright (c) The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| https://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| [email protected] so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Author: Wez Furlong <[email protected]> |
+----------------------------------------------------------------------+
*/
#ifdef PHP_WIN32
# define PDO_ODBC_TYPE "Win32"
#endif
#ifndef PDO_ODBC_TYPE
# warning Please fix configure to give your ODBC libraries a name
# define PDO_ODBC_TYPE "Unknown"
#endif
/* {{{ Roll a dice, pick a header at random... */
#ifdef HAVE_SQLCLI1_H
# include <sqlcli1.h>
# if defined(DB268K) && HAVE_LIBRARYMANAGER_H
# include <LibraryManager.h>
# endif
#endif
#ifdef HAVE_ODBC_H
# include <odbc.h>
#endif
#ifdef HAVE_IODBC_H
# include <iodbc.h>
#endif
#if defined(HAVE_SQLUNIX_H) && !defined(PHP_WIN32)
# include <sqlunix.h>
#endif
#ifdef HAVE_SQLTYPES_H
# include <sqltypes.h>
#endif
#ifdef HAVE_SQLUCODE_H
# include <sqlucode.h>
#endif
#ifdef HAVE_SQL_H
# include <sql.h>
#endif
#ifdef HAVE_ISQL_H
# include <isql.h>
#endif
#ifdef HAVE_SQLEXT_H
# include <sqlext.h>
#endif
#ifdef HAVE_ISQLEXT_H
# include <isqlext.h>
#endif
#ifdef HAVE_UDBCEXT_H
# include <udbcext.h>
#endif
#ifdef HAVE_CLI0CORE_H
# include <cli0core.h>
#endif
#ifdef HAVE_CLI0EXT1_H
# include <cli0ext.h>
#endif
#ifdef HAVE_CLI0CLI_H
# include <cli0cli.h>
#endif
#ifdef HAVE_CLI0DEFS_H
# include <cli0defs.h>
#endif
#ifdef HAVE_CLI0ENV_H
# include <cli0env.h>
#endif
#ifdef HAVE_ODBCSDK_H
# include <odbcsdk.h>
#endif
/* }}} */
/* {{{ Figure out the type for handles */
#if !defined(HENV) && !defined(SQLHENV) && defined(SQLHANDLE)
# define PDO_ODBC_HENV SQLHANDLE
# define PDO_ODBC_HDBC SQLHANDLE
# define PDO_ODBC_HSTMT SQLHANDLE
#elif !defined(HENV) && (defined(SQLHENV) || defined(DB2CLI_VER))
# define PDO_ODBC_HENV SQLHENV
# define PDO_ODBC_HDBC SQLHDBC
# define PDO_ODBC_HSTMT SQLHSTMT
#else
# define PDO_ODBC_HENV HENV
# define PDO_ODBC_HDBC HDBC
# define PDO_ODBC_HSTMT HSTMT
#endif
/* }}} */
typedef struct {
char last_state[6];
char last_err_msg[SQL_MAX_MESSAGE_LENGTH];
SDWORD last_error;
const char *file, *what;
int line;
} pdo_odbc_errinfo;
typedef struct {
PDO_ODBC_HENV env;
PDO_ODBC_HDBC dbc;
pdo_odbc_errinfo einfo;
unsigned assume_utf8:1;
unsigned _spare:31;
} pdo_odbc_db_handle;
typedef struct {
char *data;
zend_ulong datalen;
SQLLEN fetched_len;
SWORD coltype;
char colname[128];
unsigned is_long;
unsigned is_unicode:1;
unsigned _spare:31;
} pdo_odbc_column;
typedef struct {
PDO_ODBC_HSTMT stmt;
pdo_odbc_column *cols;
pdo_odbc_db_handle *H;
pdo_odbc_errinfo einfo;
char *convbuf;
zend_ulong convbufsize;
unsigned going_long:1;
unsigned assume_utf8:1;
signed col_count:16;
unsigned _spare:14;
} pdo_odbc_stmt;
typedef struct {
SQLLEN len;
SQLSMALLINT paramtype;
char *outbuf;
unsigned is_unicode:1;
unsigned _spare:31;
} pdo_odbc_param;
extern const pdo_driver_t pdo_odbc_driver;
extern const struct pdo_stmt_methods odbc_stmt_methods;
void pdo_odbc_error(pdo_dbh_t *dbh, pdo_stmt_t *stmt, PDO_ODBC_HSTMT statement, char *what, const char *file, int line);
#define pdo_odbc_drv_error(what) pdo_odbc_error(dbh, NULL, SQL_NULL_HSTMT, what, __FILE__, __LINE__)
#define pdo_odbc_stmt_error(what) pdo_odbc_error(stmt->dbh, stmt, SQL_NULL_HSTMT, what, __FILE__, __LINE__)
#define pdo_odbc_doer_error(what) pdo_odbc_error(dbh, NULL, stmt, what, __FILE__, __LINE__)
void pdo_odbc_init_error_table(void);
void pdo_odbc_fini_error_table(void);
#ifdef SQL_ATTR_CONNECTION_POOLING
extern zend_ulong pdo_odbc_pool_on;
extern zend_ulong pdo_odbc_pool_mode;
#endif
enum {
PDO_ODBC_ATTR_USE_CURSOR_LIBRARY = PDO_ATTR_DRIVER_SPECIFIC,
PDO_ODBC_ATTR_ASSUME_UTF8 /* assume that input strings are UTF-8 when feeding data to unicode columns */
};
| 4,486 | 23.38587 | 120 |
h
|
php-src
|
php-src-master/ext/pdo_pgsql/pdo_pgsql.c
|
/*
+----------------------------------------------------------------------+
| Copyright (c) The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| https://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| [email protected] so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Author: Edin Kadribasic <[email protected]> |
+----------------------------------------------------------------------+
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "php.h"
#include "php_ini.h"
#include "ext/standard/info.h"
#include "pdo/php_pdo.h"
#include "pdo/php_pdo_driver.h"
#include "php_pdo_pgsql.h"
#include "php_pdo_pgsql_int.h"
/* {{{ pdo_sqlite_deps */
static const zend_module_dep pdo_pgsql_deps[] = {
ZEND_MOD_REQUIRED("pdo")
ZEND_MOD_END
};
/* }}} */
/* {{{ pdo_pgsql_module_entry */
zend_module_entry pdo_pgsql_module_entry = {
STANDARD_MODULE_HEADER_EX, NULL,
pdo_pgsql_deps,
"pdo_pgsql",
NULL,
PHP_MINIT(pdo_pgsql),
PHP_MSHUTDOWN(pdo_pgsql),
NULL,
NULL,
PHP_MINFO(pdo_pgsql),
PHP_PDO_PGSQL_VERSION,
STANDARD_MODULE_PROPERTIES
};
/* }}} */
#ifdef COMPILE_DL_PDO_PGSQL
ZEND_GET_MODULE(pdo_pgsql)
#endif
/* true global environment */
/* {{{ PHP_MINIT_FUNCTION */
PHP_MINIT_FUNCTION(pdo_pgsql)
{
REGISTER_PDO_CLASS_CONST_LONG("PGSQL_ATTR_DISABLE_PREPARES", PDO_PGSQL_ATTR_DISABLE_PREPARES);
REGISTER_PDO_CLASS_CONST_LONG("PGSQL_TRANSACTION_IDLE", (zend_long)PGSQL_TRANSACTION_IDLE);
REGISTER_PDO_CLASS_CONST_LONG("PGSQL_TRANSACTION_ACTIVE", (zend_long)PGSQL_TRANSACTION_ACTIVE);
REGISTER_PDO_CLASS_CONST_LONG("PGSQL_TRANSACTION_INTRANS", (zend_long)PGSQL_TRANSACTION_INTRANS);
REGISTER_PDO_CLASS_CONST_LONG("PGSQL_TRANSACTION_INERROR", (zend_long)PGSQL_TRANSACTION_INERROR);
REGISTER_PDO_CLASS_CONST_LONG("PGSQL_TRANSACTION_UNKNOWN", (zend_long)PGSQL_TRANSACTION_UNKNOWN);
return php_pdo_register_driver(&pdo_pgsql_driver);
}
/* }}} */
/* {{{ PHP_MSHUTDOWN_FUNCTION */
PHP_MSHUTDOWN_FUNCTION(pdo_pgsql)
{
php_pdo_unregister_driver(&pdo_pgsql_driver);
return SUCCESS;
}
/* }}} */
/* {{{ PHP_MINFO_FUNCTION */
PHP_MINFO_FUNCTION(pdo_pgsql)
{
char buf[16];
php_info_print_table_start();
php_info_print_table_row(2, "PDO Driver for PostgreSQL", "enabled");
pdo_libpq_version(buf, sizeof(buf));
php_info_print_table_row(2, "PostgreSQL(libpq) Version", buf);
php_info_print_table_end();
}
/* }}} */
| 2,920 | 30.75 | 98 |
c
|
php-src
|
php-src-master/ext/pdo_pgsql/pgsql_driver_arginfo.h
|
/* This is a generated file, edit the .stub.php file instead.
* Stub hash: b30fa6327876dc1090ee5397253c935e4566a8fe */
ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(arginfo_class_PDO_PGSql_Ext_pgsqlCopyFromArray, 0, 2, _IS_BOOL, 0)
ZEND_ARG_TYPE_INFO(0, tableName, IS_STRING, 0)
ZEND_ARG_TYPE_INFO(0, rows, IS_ARRAY, 0)
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, separator, IS_STRING, 0, "\"\\t\"")
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, nullAs, IS_STRING, 0, "\"\\\\\\\\N\"")
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, fields, IS_STRING, 1, "null")
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(arginfo_class_PDO_PGSql_Ext_pgsqlCopyFromFile, 0, 2, _IS_BOOL, 0)
ZEND_ARG_TYPE_INFO(0, tableName, IS_STRING, 0)
ZEND_ARG_TYPE_INFO(0, filename, IS_STRING, 0)
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, separator, IS_STRING, 0, "\"\\t\"")
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, nullAs, IS_STRING, 0, "\"\\\\\\\\N\"")
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, fields, IS_STRING, 1, "null")
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_MASK_EX(arginfo_class_PDO_PGSql_Ext_pgsqlCopyToArray, 0, 1, MAY_BE_ARRAY|MAY_BE_FALSE)
ZEND_ARG_TYPE_INFO(0, tableName, IS_STRING, 0)
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, separator, IS_STRING, 0, "\"\\t\"")
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, nullAs, IS_STRING, 0, "\"\\\\\\\\N\"")
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, fields, IS_STRING, 1, "null")
ZEND_END_ARG_INFO()
#define arginfo_class_PDO_PGSql_Ext_pgsqlCopyToFile arginfo_class_PDO_PGSql_Ext_pgsqlCopyFromFile
ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_MASK_EX(arginfo_class_PDO_PGSql_Ext_pgsqlLOBCreate, 0, 0, MAY_BE_STRING|MAY_BE_FALSE)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_PDO_PGSql_Ext_pgsqlLOBOpen, 0, 0, 1)
ZEND_ARG_TYPE_INFO(0, oid, IS_STRING, 0)
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, mode, IS_STRING, 0, "\"rb\"")
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(arginfo_class_PDO_PGSql_Ext_pgsqlLOBUnlink, 0, 1, _IS_BOOL, 0)
ZEND_ARG_TYPE_INFO(0, oid, IS_STRING, 0)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_MASK_EX(arginfo_class_PDO_PGSql_Ext_pgsqlGetNotify, 0, 0, MAY_BE_ARRAY|MAY_BE_FALSE)
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, fetchMode, IS_LONG, 0, "PDO::FETCH_USE_DEFAULT")
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, timeoutMilliseconds, IS_LONG, 0, "0")
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(arginfo_class_PDO_PGSql_Ext_pgsqlGetPid, 0, 0, IS_LONG, 0)
ZEND_END_ARG_INFO()
ZEND_METHOD(PDO_PGSql_Ext, pgsqlCopyFromArray);
ZEND_METHOD(PDO_PGSql_Ext, pgsqlCopyFromFile);
ZEND_METHOD(PDO_PGSql_Ext, pgsqlCopyToArray);
ZEND_METHOD(PDO_PGSql_Ext, pgsqlCopyToFile);
ZEND_METHOD(PDO_PGSql_Ext, pgsqlLOBCreate);
ZEND_METHOD(PDO_PGSql_Ext, pgsqlLOBOpen);
ZEND_METHOD(PDO_PGSql_Ext, pgsqlLOBUnlink);
ZEND_METHOD(PDO_PGSql_Ext, pgsqlGetNotify);
ZEND_METHOD(PDO_PGSql_Ext, pgsqlGetPid);
static const zend_function_entry class_PDO_PGSql_Ext_methods[] = {
ZEND_ME(PDO_PGSql_Ext, pgsqlCopyFromArray, arginfo_class_PDO_PGSql_Ext_pgsqlCopyFromArray, ZEND_ACC_PUBLIC)
ZEND_ME(PDO_PGSql_Ext, pgsqlCopyFromFile, arginfo_class_PDO_PGSql_Ext_pgsqlCopyFromFile, ZEND_ACC_PUBLIC)
ZEND_ME(PDO_PGSql_Ext, pgsqlCopyToArray, arginfo_class_PDO_PGSql_Ext_pgsqlCopyToArray, ZEND_ACC_PUBLIC)
ZEND_ME(PDO_PGSql_Ext, pgsqlCopyToFile, arginfo_class_PDO_PGSql_Ext_pgsqlCopyToFile, ZEND_ACC_PUBLIC)
ZEND_ME(PDO_PGSql_Ext, pgsqlLOBCreate, arginfo_class_PDO_PGSql_Ext_pgsqlLOBCreate, ZEND_ACC_PUBLIC)
ZEND_ME(PDO_PGSql_Ext, pgsqlLOBOpen, arginfo_class_PDO_PGSql_Ext_pgsqlLOBOpen, ZEND_ACC_PUBLIC)
ZEND_ME(PDO_PGSql_Ext, pgsqlLOBUnlink, arginfo_class_PDO_PGSql_Ext_pgsqlLOBUnlink, ZEND_ACC_PUBLIC)
ZEND_ME(PDO_PGSql_Ext, pgsqlGetNotify, arginfo_class_PDO_PGSql_Ext_pgsqlGetNotify, ZEND_ACC_PUBLIC)
ZEND_ME(PDO_PGSql_Ext, pgsqlGetPid, arginfo_class_PDO_PGSql_Ext_pgsqlGetPid, ZEND_ACC_PUBLIC)
ZEND_FE_END
};
| 3,960 | 53.260274 | 128 |
h
|
php-src
|
php-src-master/ext/pdo_pgsql/pgsql_statement.c
|
/*
+----------------------------------------------------------------------+
| Copyright (c) The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| https://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| [email protected] so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Authors: Edin Kadribasic <[email protected]> |
| Ilia Alshanestsky <[email protected]> |
| Wez Furlong <[email protected]> |
+----------------------------------------------------------------------+
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "php.h"
#include "php_ini.h"
#include "ext/standard/info.h"
#include "pdo/php_pdo.h"
#include "pdo/php_pdo_driver.h"
#include "php_pdo_pgsql.h"
#include "php_pdo_pgsql_int.h"
#ifdef HAVE_NETINET_IN_H
#include <netinet/in.h>
#endif
/* from postgresql/src/include/catalog/pg_type.h */
#define BOOLLABEL "bool"
#define BOOLOID 16
#define BYTEALABEL "bytea"
#define BYTEAOID 17
#define DATELABEL "date"
#define DATEOID 1082
#define INT2LABEL "int2"
#define INT2OID 21
#define INT4LABEL "int4"
#define INT4OID 23
#define INT8LABEL "int8"
#define INT8OID 20
#define OIDOID 26
#define TEXTLABEL "text"
#define TEXTOID 25
#define TIMESTAMPLABEL "timestamp"
#define TIMESTAMPOID 1114
#define VARCHARLABEL "varchar"
#define VARCHAROID 1043
static int pgsql_stmt_dtor(pdo_stmt_t *stmt)
{
pdo_pgsql_stmt *S = (pdo_pgsql_stmt*)stmt->driver_data;
bool server_obj_usable = !Z_ISUNDEF(stmt->database_object_handle)
&& IS_OBJ_VALID(EG(objects_store).object_buckets[Z_OBJ_HANDLE(stmt->database_object_handle)])
&& !(OBJ_FLAGS(Z_OBJ(stmt->database_object_handle)) & IS_OBJ_FREE_CALLED);
if (S->result) {
/* free the resource */
PQclear(S->result);
S->result = NULL;
}
if (S->stmt_name) {
if (S->is_prepared && server_obj_usable) {
pdo_pgsql_db_handle *H = S->H;
char *q = NULL;
PGresult *res;
spprintf(&q, 0, "DEALLOCATE %s", S->stmt_name);
res = PQexec(H->server, q);
efree(q);
if (res) {
PQclear(res);
}
}
efree(S->stmt_name);
S->stmt_name = NULL;
}
if (S->param_lengths) {
efree(S->param_lengths);
S->param_lengths = NULL;
}
if (S->param_values) {
efree(S->param_values);
S->param_values = NULL;
}
if (S->param_formats) {
efree(S->param_formats);
S->param_formats = NULL;
}
if (S->param_types) {
efree(S->param_types);
S->param_types = NULL;
}
if (S->query) {
zend_string_release(S->query);
S->query = NULL;
}
if (S->cursor_name) {
if (server_obj_usable) {
pdo_pgsql_db_handle *H = S->H;
char *q = NULL;
PGresult *res;
spprintf(&q, 0, "CLOSE %s", S->cursor_name);
res = PQexec(H->server, q);
efree(q);
if (res) PQclear(res);
}
efree(S->cursor_name);
S->cursor_name = NULL;
}
if(S->cols) {
efree(S->cols);
S->cols = NULL;
}
efree(S);
stmt->driver_data = NULL;
return 1;
}
static int pgsql_stmt_execute(pdo_stmt_t *stmt)
{
pdo_pgsql_stmt *S = (pdo_pgsql_stmt*)stmt->driver_data;
pdo_pgsql_db_handle *H = S->H;
ExecStatusType status;
bool in_trans = stmt->dbh->methods->in_transaction(stmt->dbh);
/* ensure that we free any previous unfetched results */
if(S->result) {
PQclear(S->result);
S->result = NULL;
}
S->current_row = 0;
if (S->cursor_name) {
char *q = NULL;
if (S->is_prepared) {
spprintf(&q, 0, "CLOSE %s", S->cursor_name);
PQclear(PQexec(H->server, q));
efree(q);
}
spprintf(&q, 0, "DECLARE %s SCROLL CURSOR WITH HOLD FOR %s", S->cursor_name, ZSTR_VAL(stmt->active_query_string));
S->result = PQexec(H->server, q);
efree(q);
/* check if declare failed */
status = PQresultStatus(S->result);
if (status != PGRES_COMMAND_OK && status != PGRES_TUPLES_OK) {
pdo_pgsql_error_stmt(stmt, status, pdo_pgsql_sqlstate(S->result));
return 0;
}
PQclear(S->result);
/* the cursor was declared correctly */
S->is_prepared = 1;
/* fetch to be able to get the number of tuples later, but don't advance the cursor pointer */
spprintf(&q, 0, "FETCH FORWARD 0 FROM %s", S->cursor_name);
S->result = PQexec(H->server, q);
efree(q);
} else if (S->stmt_name) {
/* using a prepared statement */
if (!S->is_prepared) {
stmt_retry:
/* we deferred the prepare until now, because we didn't
* know anything about the parameter types; now we do */
S->result = PQprepare(H->server, S->stmt_name, ZSTR_VAL(S->query),
stmt->bound_params ? zend_hash_num_elements(stmt->bound_params) : 0,
S->param_types);
status = PQresultStatus(S->result);
switch (status) {
case PGRES_COMMAND_OK:
case PGRES_TUPLES_OK:
/* it worked */
S->is_prepared = 1;
PQclear(S->result);
break;
default: {
char *sqlstate = pdo_pgsql_sqlstate(S->result);
/* 42P05 means that the prepared statement already existed. this can happen if you use
* a connection pooling software line pgpool which doesn't close the db-connection once
* php disconnects. if php dies (no chance to run RSHUTDOWN) during execution it has no
* chance to DEALLOCATE the prepared statements it has created. so, if we hit a 42P05 we
* deallocate it and retry ONCE (thies 2005.12.15)
*/
if (sqlstate && !strcmp(sqlstate, "42P05")) {
char buf[100]; /* stmt_name == "pdo_crsr_%08x" */
PGresult *res;
snprintf(buf, sizeof(buf), "DEALLOCATE %s", S->stmt_name);
res = PQexec(H->server, buf);
if (res) {
PQclear(res);
}
goto stmt_retry;
} else {
pdo_pgsql_error_stmt(stmt, status, sqlstate);
return 0;
}
}
}
}
S->result = PQexecPrepared(H->server, S->stmt_name,
stmt->bound_params ?
zend_hash_num_elements(stmt->bound_params) :
0,
(const char**)S->param_values,
S->param_lengths,
S->param_formats,
0);
} else if (stmt->supports_placeholders == PDO_PLACEHOLDER_NAMED) {
/* execute query with parameters */
S->result = PQexecParams(H->server, ZSTR_VAL(S->query),
stmt->bound_params ? zend_hash_num_elements(stmt->bound_params) : 0,
S->param_types,
(const char**)S->param_values,
S->param_lengths,
S->param_formats,
0);
} else {
/* execute plain query (with embedded parameters) */
S->result = PQexec(H->server, ZSTR_VAL(stmt->active_query_string));
}
status = PQresultStatus(S->result);
if (status != PGRES_COMMAND_OK && status != PGRES_TUPLES_OK) {
pdo_pgsql_error_stmt(stmt, status, pdo_pgsql_sqlstate(S->result));
return 0;
}
stmt->column_count = (int) PQnfields(S->result);
if (S->cols == NULL) {
S->cols = ecalloc(stmt->column_count, sizeof(pdo_pgsql_column));
}
if (status == PGRES_COMMAND_OK) {
stmt->row_count = ZEND_ATOL(PQcmdTuples(S->result));
H->pgoid = PQoidValue(S->result);
} else {
stmt->row_count = (zend_long)PQntuples(S->result);
}
if (in_trans && !stmt->dbh->methods->in_transaction(stmt->dbh)) {
pdo_pgsql_close_lob_streams(stmt->dbh);
}
return 1;
}
static int pgsql_stmt_param_hook(pdo_stmt_t *stmt, struct pdo_bound_param_data *param,
enum pdo_param_event event_type)
{
pdo_pgsql_stmt *S = (pdo_pgsql_stmt*)stmt->driver_data;
if (stmt->supports_placeholders == PDO_PLACEHOLDER_NAMED && param->is_param) {
switch (event_type) {
case PDO_PARAM_EVT_FREE:
if (param->driver_data) {
efree(param->driver_data);
}
break;
case PDO_PARAM_EVT_NORMALIZE:
/* decode name from $1, $2 into 0, 1 etc. */
if (param->name) {
if (ZSTR_VAL(param->name)[0] == '$') {
param->paramno = ZEND_ATOL(ZSTR_VAL(param->name) + 1);
} else {
/* resolve parameter name to rewritten name */
zend_string *namevar;
if (stmt->bound_param_map && (namevar = zend_hash_find_ptr(stmt->bound_param_map,
param->name)) != NULL) {
param->paramno = ZEND_ATOL(ZSTR_VAL(namevar) + 1);
param->paramno--;
} else {
pdo_pgsql_error_stmt_msg(stmt, 0, "HY093", ZSTR_VAL(param->name));
return 0;
}
}
}
break;
case PDO_PARAM_EVT_ALLOC:
if (!stmt->bound_param_map) {
return 1;
}
if (!zend_hash_index_exists(stmt->bound_param_map, param->paramno)) {
pdo_pgsql_error_stmt_msg(stmt, 0, "HY093", "parameter was not defined");
return 0;
}
ZEND_FALLTHROUGH;
case PDO_PARAM_EVT_EXEC_POST:
case PDO_PARAM_EVT_FETCH_PRE:
case PDO_PARAM_EVT_FETCH_POST:
/* work is handled by EVT_NORMALIZE */
return 1;
case PDO_PARAM_EVT_EXEC_PRE:
if (!stmt->bound_param_map) {
return 1;
}
if (!S->param_values) {
S->param_values = ecalloc(
zend_hash_num_elements(stmt->bound_param_map),
sizeof(char*));
S->param_lengths = ecalloc(
zend_hash_num_elements(stmt->bound_param_map),
sizeof(int));
S->param_formats = ecalloc(
zend_hash_num_elements(stmt->bound_param_map),
sizeof(int));
S->param_types = ecalloc(
zend_hash_num_elements(stmt->bound_param_map),
sizeof(Oid));
}
if (param->paramno >= 0) {
zval *parameter;
/*
if (param->paramno >= zend_hash_num_elements(stmt->bound_params)) {
pdo_raise_impl_error(stmt->dbh, stmt, "HY093", "parameter was not defined");
return 0;
}
*/
if (Z_ISREF(param->parameter)) {
parameter = Z_REFVAL(param->parameter);
} else {
parameter = ¶m->parameter;
}
if (PDO_PARAM_TYPE(param->param_type) == PDO_PARAM_LOB &&
Z_TYPE_P(parameter) == IS_RESOURCE) {
php_stream *stm;
php_stream_from_zval_no_verify(stm, parameter);
if (stm) {
if (php_stream_is(stm, &pdo_pgsql_lob_stream_ops)) {
struct pdo_pgsql_lob_self *self = (struct pdo_pgsql_lob_self*)stm->abstract;
pdo_pgsql_bound_param *P = param->driver_data;
if (P == NULL) {
P = ecalloc(1, sizeof(*P));
param->driver_data = P;
}
P->oid = htonl(self->oid);
S->param_values[param->paramno] = (char*)&P->oid;
S->param_lengths[param->paramno] = sizeof(P->oid);
S->param_formats[param->paramno] = 1;
S->param_types[param->paramno] = OIDOID;
return 1;
} else {
zend_string *str = php_stream_copy_to_mem(stm, PHP_STREAM_COPY_ALL, 0);
if (str != NULL) {
ZVAL_STR(parameter, str);
} else {
ZVAL_EMPTY_STRING(parameter);
}
}
} else {
/* expected a stream resource */
pdo_pgsql_error_stmt(stmt, PGRES_FATAL_ERROR, "HY105");
return 0;
}
}
if (PDO_PARAM_TYPE(param->param_type) == PDO_PARAM_NULL ||
Z_TYPE_P(parameter) == IS_NULL) {
S->param_values[param->paramno] = NULL;
S->param_lengths[param->paramno] = 0;
} else if (Z_TYPE_P(parameter) == IS_FALSE || Z_TYPE_P(parameter) == IS_TRUE) {
S->param_values[param->paramno] = Z_TYPE_P(parameter) == IS_TRUE ? "t" : "f";
S->param_lengths[param->paramno] = 1;
S->param_formats[param->paramno] = 0;
} else {
convert_to_string(parameter);
S->param_values[param->paramno] = Z_STRVAL_P(parameter);
S->param_lengths[param->paramno] = Z_STRLEN_P(parameter);
S->param_formats[param->paramno] = 0;
}
if (PDO_PARAM_TYPE(param->param_type) == PDO_PARAM_LOB) {
S->param_types[param->paramno] = 0;
S->param_formats[param->paramno] = 1;
} else {
S->param_types[param->paramno] = 0;
}
}
break;
}
} else if (param->is_param && event_type == PDO_PARAM_EVT_NORMALIZE) {
/* We need to manually convert to a pg native boolean value */
if (PDO_PARAM_TYPE(param->param_type) == PDO_PARAM_BOOL &&
((param->param_type & PDO_PARAM_INPUT_OUTPUT) != PDO_PARAM_INPUT_OUTPUT)) {
const char *s = zend_is_true(¶m->parameter) ? "t" : "f";
param->param_type = PDO_PARAM_STR;
zval_ptr_dtor(¶m->parameter);
ZVAL_STRINGL(¶m->parameter, s, 1);
}
}
return 1;
}
static int pgsql_stmt_fetch(pdo_stmt_t *stmt,
enum pdo_fetch_orientation ori, zend_long offset)
{
pdo_pgsql_stmt *S = (pdo_pgsql_stmt*)stmt->driver_data;
if (S->cursor_name) {
char *ori_str = NULL;
char *q = NULL;
ExecStatusType status;
switch (ori) {
case PDO_FETCH_ORI_NEXT: spprintf(&ori_str, 0, "NEXT"); break;
case PDO_FETCH_ORI_PRIOR: spprintf(&ori_str, 0, "BACKWARD"); break;
case PDO_FETCH_ORI_FIRST: spprintf(&ori_str, 0, "FIRST"); break;
case PDO_FETCH_ORI_LAST: spprintf(&ori_str, 0, "LAST"); break;
case PDO_FETCH_ORI_ABS: spprintf(&ori_str, 0, "ABSOLUTE " ZEND_LONG_FMT, offset); break;
case PDO_FETCH_ORI_REL: spprintf(&ori_str, 0, "RELATIVE " ZEND_LONG_FMT, offset); break;
default:
return 0;
}
if(S->result) {
PQclear(S->result);
S->result = NULL;
}
spprintf(&q, 0, "FETCH %s FROM %s", ori_str, S->cursor_name);
efree(ori_str);
S->result = PQexec(S->H->server, q);
efree(q);
status = PQresultStatus(S->result);
if (status != PGRES_COMMAND_OK && status != PGRES_TUPLES_OK) {
pdo_pgsql_error_stmt(stmt, status, pdo_pgsql_sqlstate(S->result));
return 0;
}
if (PQntuples(S->result)) {
S->current_row = 1;
return 1;
} else {
return 0;
}
} else {
if (S->current_row < stmt->row_count) {
S->current_row++;
return 1;
} else {
return 0;
}
}
}
static int pgsql_stmt_describe(pdo_stmt_t *stmt, int colno)
{
pdo_pgsql_stmt *S = (pdo_pgsql_stmt*)stmt->driver_data;
struct pdo_column_data *cols = stmt->columns;
char *str;
if (!S->result) {
return 0;
}
str = PQfname(S->result, colno);
cols[colno].name = zend_string_init(str, strlen(str), 0);
cols[colno].maxlen = PQfsize(S->result, colno);
cols[colno].precision = PQfmod(S->result, colno);
S->cols[colno].pgsql_type = PQftype(S->result, colno);
return 1;
}
static int pgsql_stmt_get_col(pdo_stmt_t *stmt, int colno, zval *result, enum pdo_param_type *type)
{
pdo_pgsql_stmt *S = (pdo_pgsql_stmt*)stmt->driver_data;
if (!S->result) {
return 0;
}
/* We have already increased count by 1 in pgsql_stmt_fetch() */
if (PQgetisnull(S->result, S->current_row - 1, colno)) { /* Check if we got NULL */
ZVAL_NULL(result);
} else {
char *ptr = PQgetvalue(S->result, S->current_row - 1, colno);
size_t len = PQgetlength(S->result, S->current_row - 1, colno);
switch (S->cols[colno].pgsql_type) {
case BOOLOID:
ZVAL_BOOL(result, *ptr == 't');
break;
case INT2OID:
case INT4OID:
#if SIZEOF_ZEND_LONG >= 8
case INT8OID:
#endif
ZVAL_LONG(result, ZEND_ATOL(ptr));
break;
case OIDOID: {
char *end_ptr;
Oid oid = (Oid)strtoul(ptr, &end_ptr, 10);
if (type && *type == PDO_PARAM_LOB) {
/* If column was bound as LOB, return a stream. */
int loid = lo_open(S->H->server, oid, INV_READ);
if (loid >= 0) {
php_stream *stream = pdo_pgsql_create_lob_stream(&stmt->database_object_handle, loid, oid);
if (stream) {
php_stream_to_zval(stream, result);
return 1;
}
}
return 0;
} else {
/* Otherwise return OID as integer. */
ZVAL_LONG(result, oid);
}
break;
}
case BYTEAOID: {
size_t tmp_len;
char *tmp_ptr = (char *)PQunescapeBytea((unsigned char *) ptr, &tmp_len);
if (!tmp_ptr) {
/* PQunescapeBytea returned an error */
return 0;
}
zend_string *str = zend_string_init(tmp_ptr, tmp_len, 0);
php_stream *stream = php_stream_memory_open(TEMP_STREAM_READONLY, str);
php_stream_to_zval(stream, result);
zend_string_release(str);
PQfreemem(tmp_ptr);
break;
}
default:
ZVAL_STRINGL_FAST(result, ptr, len);
break;
}
}
return 1;
}
static zend_always_inline char * pdo_pgsql_translate_oid_to_table(Oid oid, PGconn *conn)
{
char *table_name = NULL;
PGresult *tmp_res;
char *querystr = NULL;
spprintf(&querystr, 0, "SELECT RELNAME FROM PG_CLASS WHERE OID=%d", oid);
if ((tmp_res = PQexec(conn, querystr)) == NULL || PQresultStatus(tmp_res) != PGRES_TUPLES_OK) {
if (tmp_res) {
PQclear(tmp_res);
}
efree(querystr);
return 0;
}
efree(querystr);
if (1 == PQgetisnull(tmp_res, 0, 0) || (table_name = PQgetvalue(tmp_res, 0, 0)) == NULL) {
PQclear(tmp_res);
return 0;
}
table_name = estrdup(table_name);
PQclear(tmp_res);
return table_name;
}
static int pgsql_stmt_get_column_meta(pdo_stmt_t *stmt, zend_long colno, zval *return_value)
{
pdo_pgsql_stmt *S = (pdo_pgsql_stmt*)stmt->driver_data;
PGresult *res;
char *q=NULL;
ExecStatusType status;
Oid table_oid;
char *table_name=NULL;
if (!S->result) {
return FAILURE;
}
if (colno >= stmt->column_count) {
return FAILURE;
}
array_init(return_value);
add_assoc_long(return_value, "pgsql:oid", S->cols[colno].pgsql_type);
table_oid = PQftable(S->result, colno);
add_assoc_long(return_value, "pgsql:table_oid", table_oid);
table_name = pdo_pgsql_translate_oid_to_table(table_oid, S->H->server);
if (table_name) {
add_assoc_string(return_value, "table", table_name);
efree(table_name);
}
switch (S->cols[colno].pgsql_type) {
case BOOLOID:
add_assoc_string(return_value, "native_type", BOOLLABEL);
break;
case BYTEAOID:
add_assoc_string(return_value, "native_type", BYTEALABEL);
break;
case INT8OID:
add_assoc_string(return_value, "native_type", INT8LABEL);
break;
case INT2OID:
add_assoc_string(return_value, "native_type", INT2LABEL);
break;
case INT4OID:
add_assoc_string(return_value, "native_type", INT4LABEL);
break;
case TEXTOID:
add_assoc_string(return_value, "native_type", TEXTLABEL);
break;
case VARCHAROID:
add_assoc_string(return_value, "native_type", VARCHARLABEL);
break;
case DATEOID:
add_assoc_string(return_value, "native_type", DATELABEL);
break;
case TIMESTAMPOID:
add_assoc_string(return_value, "native_type", TIMESTAMPLABEL);
break;
default:
/* Fetch metadata from Postgres system catalogue */
spprintf(&q, 0, "SELECT TYPNAME FROM PG_TYPE WHERE OID=%u", S->cols[colno].pgsql_type);
res = PQexec(S->H->server, q);
efree(q);
status = PQresultStatus(res);
if (status == PGRES_TUPLES_OK && 1 == PQntuples(res)) {
add_assoc_string(return_value, "native_type", PQgetvalue(res, 0, 0));
}
PQclear(res);
}
enum pdo_param_type param_type;
switch (S->cols[colno].pgsql_type) {
case BOOLOID:
param_type = PDO_PARAM_BOOL;
break;
case INT2OID:
case INT4OID:
case INT8OID:
param_type = PDO_PARAM_INT;
break;
case OIDOID:
case BYTEAOID:
param_type = PDO_PARAM_LOB;
break;
default:
param_type = PDO_PARAM_STR;
}
add_assoc_long(return_value, "pdo_type", param_type);
return 1;
}
static int pdo_pgsql_stmt_cursor_closer(pdo_stmt_t *stmt)
{
return 1;
}
const struct pdo_stmt_methods pgsql_stmt_methods = {
pgsql_stmt_dtor,
pgsql_stmt_execute,
pgsql_stmt_fetch,
pgsql_stmt_describe,
pgsql_stmt_get_col,
pgsql_stmt_param_hook,
NULL, /* set_attr */
NULL, /* get_attr */
pgsql_stmt_get_column_meta,
NULL, /* next_rowset */
pdo_pgsql_stmt_cursor_closer
};
| 19,652 | 27.11588 | 116 |
c
|
php-src
|
php-src-master/ext/pdo_pgsql/php_pdo_pgsql.h
|
/*
+----------------------------------------------------------------------+
| Copyright (c) The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| https://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| [email protected] so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Author: Edin Kadribasic <[email protected]> |
+----------------------------------------------------------------------+
*/
#ifndef PHP_PDO_PGSQL_H
#define PHP_PDO_PGSQL_H
#include <libpq-fe.h>
extern zend_module_entry pdo_pgsql_module_entry;
#define phpext_pdo_pgsql_ptr &pdo_pgsql_module_entry
#include "php_version.h"
#define PHP_PDO_PGSQL_VERSION PHP_VERSION
#ifdef ZTS
#include "TSRM.h"
#endif
PHP_MINIT_FUNCTION(pdo_pgsql);
PHP_MSHUTDOWN_FUNCTION(pdo_pgsql);
PHP_MINFO_FUNCTION(pdo_pgsql);
#endif /* PHP_PDO_PGSQL_H */
| 1,389 | 36.567568 | 74 |
h
|
php-src
|
php-src-master/ext/pdo_sqlite/pdo_sqlite.c
|
/*
+----------------------------------------------------------------------+
| Copyright (c) The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| https://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| [email protected] so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Author: Wez Furlong <[email protected]> |
+----------------------------------------------------------------------+
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "php.h"
#include "php_ini.h"
#include "ext/standard/info.h"
#include "pdo/php_pdo.h"
#include "pdo/php_pdo_driver.h"
#include "php_pdo_sqlite.h"
#include "php_pdo_sqlite_int.h"
#include "zend_exceptions.h"
/* {{{ pdo_sqlite_deps */
static const zend_module_dep pdo_sqlite_deps[] = {
ZEND_MOD_REQUIRED("pdo")
ZEND_MOD_END
};
/* }}} */
/* {{{ pdo_sqlite_module_entry */
zend_module_entry pdo_sqlite_module_entry = {
STANDARD_MODULE_HEADER_EX, NULL,
pdo_sqlite_deps,
"pdo_sqlite",
NULL,
PHP_MINIT(pdo_sqlite),
PHP_MSHUTDOWN(pdo_sqlite),
NULL,
NULL,
PHP_MINFO(pdo_sqlite),
PHP_PDO_SQLITE_VERSION,
STANDARD_MODULE_PROPERTIES
};
/* }}} */
#if defined(COMPILE_DL_PDO_SQLITE) || defined(COMPILE_DL_PDO_SQLITE_EXTERNAL)
ZEND_GET_MODULE(pdo_sqlite)
#endif
/* {{{ PHP_MINIT_FUNCTION */
PHP_MINIT_FUNCTION(pdo_sqlite)
{
#ifdef SQLITE_DETERMINISTIC
REGISTER_PDO_CLASS_CONST_LONG("SQLITE_DETERMINISTIC", (zend_long)SQLITE_DETERMINISTIC);
#endif
REGISTER_PDO_CLASS_CONST_LONG("SQLITE_ATTR_OPEN_FLAGS", (zend_long)PDO_SQLITE_ATTR_OPEN_FLAGS);
REGISTER_PDO_CLASS_CONST_LONG("SQLITE_OPEN_READONLY", (zend_long)SQLITE_OPEN_READONLY);
REGISTER_PDO_CLASS_CONST_LONG("SQLITE_OPEN_READWRITE", (zend_long)SQLITE_OPEN_READWRITE);
REGISTER_PDO_CLASS_CONST_LONG("SQLITE_OPEN_CREATE", (zend_long)SQLITE_OPEN_CREATE);
REGISTER_PDO_CLASS_CONST_LONG("SQLITE_ATTR_READONLY_STATEMENT", (zend_long)PDO_SQLITE_ATTR_READONLY_STATEMENT);
REGISTER_PDO_CLASS_CONST_LONG("SQLITE_ATTR_EXTENDED_RESULT_CODES", (zend_long)PDO_SQLITE_ATTR_EXTENDED_RESULT_CODES);
return php_pdo_register_driver(&pdo_sqlite_driver);
}
/* }}} */
/* {{{ PHP_MSHUTDOWN_FUNCTION */
PHP_MSHUTDOWN_FUNCTION(pdo_sqlite)
{
php_pdo_unregister_driver(&pdo_sqlite_driver);
return SUCCESS;
}
/* }}} */
/* {{{ PHP_MINFO_FUNCTION */
PHP_MINFO_FUNCTION(pdo_sqlite)
{
php_info_print_table_start();
php_info_print_table_row(2, "PDO Driver for SQLite 3.x", "enabled");
php_info_print_table_row(2, "SQLite Library", sqlite3_libversion());
php_info_print_table_end();
}
/* }}} */
| 3,073 | 32.413043 | 118 |
c
|
php-src
|
php-src-master/ext/pdo_sqlite/php_pdo_sqlite.h
|
/*
+----------------------------------------------------------------------+
| Copyright (c) The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| https://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| [email protected] so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Author: Wez Furlong <[email protected]> |
+----------------------------------------------------------------------+
*/
#ifndef PHP_PDO_SQLITE_H
#define PHP_PDO_SQLITE_H
extern zend_module_entry pdo_sqlite_module_entry;
#define phpext_pdo_sqlite_ptr &pdo_sqlite_module_entry
#include "php_version.h"
#define PHP_PDO_SQLITE_VERSION PHP_VERSION
#ifdef ZTS
#include "TSRM.h"
#endif
PHP_MINIT_FUNCTION(pdo_sqlite);
PHP_MSHUTDOWN_FUNCTION(pdo_sqlite);
PHP_RINIT_FUNCTION(pdo_sqlite);
PHP_RSHUTDOWN_FUNCTION(pdo_sqlite);
PHP_MINFO_FUNCTION(pdo_sqlite);
#endif /* PHP_PDO_SQLITE_H */
| 1,444 | 38.054054 | 74 |
h
|
php-src
|
php-src-master/ext/pdo_sqlite/php_pdo_sqlite_int.h
|
/*
+----------------------------------------------------------------------+
| Copyright (c) The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| https://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| [email protected] so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Author: Wez Furlong <[email protected]> |
+----------------------------------------------------------------------+
*/
#ifndef PHP_PDO_SQLITE_INT_H
#define PHP_PDO_SQLITE_INT_H
#include <sqlite3.h>
typedef struct {
const char *file;
int line;
unsigned int errcode;
char *errmsg;
} pdo_sqlite_error_info;
struct pdo_sqlite_fci {
zend_fcall_info fci;
zend_fcall_info_cache fcc;
};
struct pdo_sqlite_func {
struct pdo_sqlite_func *next;
zval func, step, fini;
int argc;
const char *funcname;
/* accelerated callback references */
struct pdo_sqlite_fci afunc, astep, afini;
};
struct pdo_sqlite_collation {
struct pdo_sqlite_collation *next;
const char *name;
zval callback;
struct pdo_sqlite_fci fc;
};
typedef struct {
sqlite3 *db;
pdo_sqlite_error_info einfo;
struct pdo_sqlite_func *funcs;
struct pdo_sqlite_collation *collations;
} pdo_sqlite_db_handle;
typedef struct {
pdo_sqlite_db_handle *H;
sqlite3_stmt *stmt;
unsigned pre_fetched:1;
unsigned done:1;
} pdo_sqlite_stmt;
extern const pdo_driver_t pdo_sqlite_driver;
extern int _pdo_sqlite_error(pdo_dbh_t *dbh, pdo_stmt_t *stmt, const char *file, int line);
#define pdo_sqlite_error(s) _pdo_sqlite_error(s, NULL, __FILE__, __LINE__)
#define pdo_sqlite_error_stmt(s) _pdo_sqlite_error(stmt->dbh, stmt, __FILE__, __LINE__)
extern const struct pdo_stmt_methods sqlite_stmt_methods;
enum {
PDO_SQLITE_ATTR_OPEN_FLAGS = PDO_ATTR_DRIVER_SPECIFIC,
PDO_SQLITE_ATTR_READONLY_STATEMENT,
PDO_SQLITE_ATTR_EXTENDED_RESULT_CODES
};
#endif
| 2,387 | 28.121951 | 91 |
h
|
php-src
|
php-src-master/ext/pdo_sqlite/sqlite_driver.c
|
/*
+----------------------------------------------------------------------+
| Copyright (c) The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| https://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| [email protected] so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Author: Wez Furlong <[email protected]> |
+----------------------------------------------------------------------+
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "php.h"
#include "php_ini.h"
#include "ext/standard/info.h"
#include "pdo/php_pdo.h"
#include "pdo/php_pdo_driver.h"
#include "php_pdo_sqlite.h"
#include "php_pdo_sqlite_int.h"
#include "zend_exceptions.h"
#include "sqlite_driver_arginfo.h"
int _pdo_sqlite_error(pdo_dbh_t *dbh, pdo_stmt_t *stmt, const char *file, int line) /* {{{ */
{
pdo_sqlite_db_handle *H = (pdo_sqlite_db_handle *)dbh->driver_data;
pdo_error_type *pdo_err = stmt ? &stmt->error_code : &dbh->error_code;
pdo_sqlite_error_info *einfo = &H->einfo;
einfo->errcode = sqlite3_errcode(H->db);
einfo->file = file;
einfo->line = line;
if (einfo->errcode != SQLITE_OK) {
if (einfo->errmsg) {
pefree(einfo->errmsg, dbh->is_persistent);
}
einfo->errmsg = pestrdup((char*)sqlite3_errmsg(H->db), dbh->is_persistent);
} else { /* no error */
strncpy(*pdo_err, PDO_ERR_NONE, sizeof(*pdo_err));
return 0;
}
switch (einfo->errcode) {
case SQLITE_NOTFOUND:
strncpy(*pdo_err, "42S02", sizeof(*pdo_err));
break;
case SQLITE_INTERRUPT:
strncpy(*pdo_err, "01002", sizeof(*pdo_err));
break;
case SQLITE_NOLFS:
strncpy(*pdo_err, "HYC00", sizeof(*pdo_err));
break;
case SQLITE_TOOBIG:
strncpy(*pdo_err, "22001", sizeof(*pdo_err));
break;
case SQLITE_CONSTRAINT:
strncpy(*pdo_err, "23000", sizeof(*pdo_err));
break;
case SQLITE_ERROR:
default:
strncpy(*pdo_err, "HY000", sizeof(*pdo_err));
break;
}
if (!dbh->methods) {
pdo_throw_exception(einfo->errcode, einfo->errmsg, pdo_err);
}
return einfo->errcode;
}
/* }}} */
static void pdo_sqlite_fetch_error_func(pdo_dbh_t *dbh, pdo_stmt_t *stmt, zval *info)
{
pdo_sqlite_db_handle *H = (pdo_sqlite_db_handle *)dbh->driver_data;
pdo_sqlite_error_info *einfo = &H->einfo;
if (einfo->errcode) {
add_next_index_long(info, einfo->errcode);
add_next_index_string(info, einfo->errmsg);
}
}
static void pdo_sqlite_cleanup_callbacks(pdo_sqlite_db_handle *H)
{
struct pdo_sqlite_func *func;
while (H->funcs) {
func = H->funcs;
H->funcs = func->next;
if (H->db) {
/* delete the function from the handle */
sqlite3_create_function(H->db,
func->funcname,
func->argc,
SQLITE_UTF8,
func,
NULL, NULL, NULL);
}
efree((char*)func->funcname);
if (!Z_ISUNDEF(func->func)) {
zval_ptr_dtor(&func->func);
}
if (!Z_ISUNDEF(func->step)) {
zval_ptr_dtor(&func->step);
}
if (!Z_ISUNDEF(func->fini)) {
zval_ptr_dtor(&func->fini);
}
efree(func);
}
while (H->collations) {
struct pdo_sqlite_collation *collation;
collation = H->collations;
H->collations = collation->next;
if (H->db) {
/* delete the collation from the handle */
sqlite3_create_collation(H->db,
collation->name,
SQLITE_UTF8,
collation,
NULL);
}
efree((char*)collation->name);
if (!Z_ISUNDEF(collation->callback)) {
zval_ptr_dtor(&collation->callback);
}
efree(collation);
}
}
static void sqlite_handle_closer(pdo_dbh_t *dbh) /* {{{ */
{
pdo_sqlite_db_handle *H = (pdo_sqlite_db_handle *)dbh->driver_data;
if (H) {
pdo_sqlite_error_info *einfo = &H->einfo;
pdo_sqlite_cleanup_callbacks(H);
if (H->db) {
#ifdef HAVE_SQLITE3_CLOSE_V2
sqlite3_close_v2(H->db);
#else
sqlite3_close(H->db);
#endif
H->db = NULL;
}
if (einfo->errmsg) {
pefree(einfo->errmsg, dbh->is_persistent);
einfo->errmsg = NULL;
}
pefree(H, dbh->is_persistent);
dbh->driver_data = NULL;
}
}
/* }}} */
static bool sqlite_handle_preparer(pdo_dbh_t *dbh, zend_string *sql, pdo_stmt_t *stmt, zval *driver_options)
{
pdo_sqlite_db_handle *H = (pdo_sqlite_db_handle *)dbh->driver_data;
pdo_sqlite_stmt *S = ecalloc(1, sizeof(pdo_sqlite_stmt));
int i;
const char *tail;
S->H = H;
stmt->driver_data = S;
stmt->methods = &sqlite_stmt_methods;
stmt->supports_placeholders = PDO_PLACEHOLDER_POSITIONAL|PDO_PLACEHOLDER_NAMED;
if (PDO_CURSOR_FWDONLY != pdo_attr_lval(driver_options, PDO_ATTR_CURSOR, PDO_CURSOR_FWDONLY)) {
H->einfo.errcode = SQLITE_ERROR;
pdo_sqlite_error(dbh);
return false;
}
i = sqlite3_prepare_v2(H->db, ZSTR_VAL(sql), ZSTR_LEN(sql), &S->stmt, &tail);
if (i == SQLITE_OK) {
return true;
}
pdo_sqlite_error(dbh);
return false;
}
static zend_long sqlite_handle_doer(pdo_dbh_t *dbh, const zend_string *sql)
{
pdo_sqlite_db_handle *H = (pdo_sqlite_db_handle *)dbh->driver_data;
if (sqlite3_exec(H->db, ZSTR_VAL(sql), NULL, NULL, NULL) != SQLITE_OK) {
pdo_sqlite_error(dbh);
return -1;
} else {
return sqlite3_changes(H->db);
}
}
static zend_string *pdo_sqlite_last_insert_id(pdo_dbh_t *dbh, const zend_string *name)
{
pdo_sqlite_db_handle *H = (pdo_sqlite_db_handle *)dbh->driver_data;
return zend_i64_to_str(sqlite3_last_insert_rowid(H->db));
}
/* NB: doesn't handle binary strings... use prepared stmts for that */
static zend_string* sqlite_handle_quoter(pdo_dbh_t *dbh, const zend_string *unquoted, enum pdo_param_type paramtype)
{
char *quoted;
if (ZSTR_LEN(unquoted) > (INT_MAX - 3) / 2) {
return NULL;
}
quoted = safe_emalloc(2, ZSTR_LEN(unquoted), 3);
/* TODO use %Q format? */
sqlite3_snprintf(2*ZSTR_LEN(unquoted) + 3, quoted, "'%q'", ZSTR_VAL(unquoted));
zend_string *quoted_str = zend_string_init(quoted, strlen(quoted), 0);
efree(quoted);
return quoted_str;
}
static bool sqlite_handle_begin(pdo_dbh_t *dbh)
{
pdo_sqlite_db_handle *H = (pdo_sqlite_db_handle *)dbh->driver_data;
if (sqlite3_exec(H->db, "BEGIN", NULL, NULL, NULL) != SQLITE_OK) {
pdo_sqlite_error(dbh);
return false;
}
return true;
}
static bool sqlite_handle_commit(pdo_dbh_t *dbh)
{
pdo_sqlite_db_handle *H = (pdo_sqlite_db_handle *)dbh->driver_data;
if (sqlite3_exec(H->db, "COMMIT", NULL, NULL, NULL) != SQLITE_OK) {
pdo_sqlite_error(dbh);
return false;
}
return true;
}
static bool sqlite_handle_rollback(pdo_dbh_t *dbh)
{
pdo_sqlite_db_handle *H = (pdo_sqlite_db_handle *)dbh->driver_data;
if (sqlite3_exec(H->db, "ROLLBACK", NULL, NULL, NULL) != SQLITE_OK) {
pdo_sqlite_error(dbh);
return false;
}
return true;
}
static int pdo_sqlite_get_attribute(pdo_dbh_t *dbh, zend_long attr, zval *return_value)
{
switch (attr) {
case PDO_ATTR_CLIENT_VERSION:
case PDO_ATTR_SERVER_VERSION:
ZVAL_STRING(return_value, (char *)sqlite3_libversion());
break;
default:
return 0;
}
return 1;
}
static bool pdo_sqlite_set_attr(pdo_dbh_t *dbh, zend_long attr, zval *val)
{
pdo_sqlite_db_handle *H = (pdo_sqlite_db_handle *)dbh->driver_data;
zend_long lval;
switch (attr) {
case PDO_ATTR_TIMEOUT:
if (!pdo_get_long_param(&lval, val)) {
return false;
}
sqlite3_busy_timeout(H->db, lval * 1000);
return true;
case PDO_SQLITE_ATTR_EXTENDED_RESULT_CODES:
if (!pdo_get_long_param(&lval, val)) {
return false;
}
sqlite3_extended_result_codes(H->db, lval);
return true;
}
return false;
}
typedef struct {
zval val;
zend_long row;
} aggregate_context;
static int do_callback(struct pdo_sqlite_fci *fc, zval *cb,
int argc, sqlite3_value **argv, sqlite3_context *context,
int is_agg)
{
zval *zargs = NULL;
zval retval;
int i;
int ret;
int fake_argc;
aggregate_context *agg_context = NULL;
if (is_agg) {
is_agg = 2;
}
fake_argc = argc + is_agg;
fc->fci.size = sizeof(fc->fci);
ZVAL_COPY_VALUE(&fc->fci.function_name, cb);
fc->fci.object = NULL;
fc->fci.retval = &retval;
fc->fci.param_count = fake_argc;
/* build up the params */
if (fake_argc) {
zargs = safe_emalloc(fake_argc, sizeof(zval), 0);
}
if (is_agg) {
agg_context = sqlite3_aggregate_context(context, sizeof(aggregate_context));
if (!agg_context) {
efree(zargs);
return FAILURE;
}
if (Z_ISUNDEF(agg_context->val)) {
ZVAL_NEW_REF(&agg_context->val, &EG(uninitialized_zval));
}
ZVAL_COPY_VALUE(&zargs[0], &agg_context->val);
ZVAL_LONG(&zargs[1], ++agg_context->row);
}
for (i = 0; i < argc; i++) {
/* get the value */
switch (sqlite3_value_type(argv[i])) {
case SQLITE_INTEGER:
ZVAL_LONG(&zargs[i + is_agg], sqlite3_value_int(argv[i]));
break;
case SQLITE_FLOAT:
ZVAL_DOUBLE(&zargs[i + is_agg], sqlite3_value_double(argv[i]));
break;
case SQLITE_NULL:
ZVAL_NULL(&zargs[i + is_agg]);
break;
case SQLITE_BLOB:
case SQLITE3_TEXT:
default:
ZVAL_STRINGL(&zargs[i + is_agg], (char*)sqlite3_value_text(argv[i]), sqlite3_value_bytes(argv[i]));
break;
}
}
fc->fci.params = zargs;
if ((ret = zend_call_function(&fc->fci, &fc->fcc)) == FAILURE) {
php_error_docref(NULL, E_WARNING, "An error occurred while invoking the callback");
}
/* clean up the params */
if (zargs) {
for (i = is_agg; i < fake_argc; i++) {
zval_ptr_dtor(&zargs[i]);
}
if (is_agg) {
zval_ptr_dtor(&zargs[1]);
}
efree(zargs);
}
if (!is_agg || !argv) {
/* only set the sqlite return value if we are a scalar function,
* or if we are finalizing an aggregate */
if (!Z_ISUNDEF(retval)) {
switch (Z_TYPE(retval)) {
case IS_LONG:
sqlite3_result_int(context, Z_LVAL(retval));
break;
case IS_NULL:
sqlite3_result_null(context);
break;
case IS_DOUBLE:
sqlite3_result_double(context, Z_DVAL(retval));
break;
default:
if (!try_convert_to_string(&retval)) {
ret = FAILURE;
break;
}
sqlite3_result_text(context, Z_STRVAL(retval), Z_STRLEN(retval), SQLITE_TRANSIENT);
break;
}
} else {
sqlite3_result_error(context, "failed to invoke callback", 0);
}
if (agg_context) {
zval_ptr_dtor(&agg_context->val);
}
} else {
/* we're stepping in an aggregate; the return value goes into
* the context */
if (agg_context) {
if (Z_ISUNDEF(retval)) {
zval_ptr_dtor(&agg_context->val);
return FAILURE;
}
zval_ptr_dtor(Z_REFVAL(agg_context->val));
ZVAL_COPY_VALUE(Z_REFVAL(agg_context->val), &retval);
ZVAL_UNDEF(&retval);
}
}
if (!Z_ISUNDEF(retval)) {
zval_ptr_dtor(&retval);
}
return ret;
}
static void php_sqlite3_func_callback(sqlite3_context *context, int argc,
sqlite3_value **argv)
{
struct pdo_sqlite_func *func = (struct pdo_sqlite_func*)sqlite3_user_data(context);
do_callback(&func->afunc, &func->func, argc, argv, context, 0);
}
static void php_sqlite3_func_step_callback(sqlite3_context *context, int argc,
sqlite3_value **argv)
{
struct pdo_sqlite_func *func = (struct pdo_sqlite_func*)sqlite3_user_data(context);
do_callback(&func->astep, &func->step, argc, argv, context, 1);
}
static void php_sqlite3_func_final_callback(sqlite3_context *context)
{
struct pdo_sqlite_func *func = (struct pdo_sqlite_func*)sqlite3_user_data(context);
do_callback(&func->afini, &func->fini, 0, NULL, context, 1);
}
static int php_sqlite3_collation_callback(void *context,
int string1_len, const void *string1,
int string2_len, const void *string2)
{
int ret;
zval zargs[2];
zval retval;
struct pdo_sqlite_collation *collation = (struct pdo_sqlite_collation*) context;
collation->fc.fci.size = sizeof(collation->fc.fci);
ZVAL_COPY_VALUE(&collation->fc.fci.function_name, &collation->callback);
collation->fc.fci.object = NULL;
collation->fc.fci.retval = &retval;
// Prepare the arguments.
ZVAL_STRINGL(&zargs[0], (char *) string1, string1_len);
ZVAL_STRINGL(&zargs[1], (char *) string2, string2_len);
collation->fc.fci.param_count = 2;
collation->fc.fci.params = zargs;
if ((ret = zend_call_function(&collation->fc.fci, &collation->fc.fcc)) == FAILURE) {
php_error_docref(NULL, E_WARNING, "An error occurred while invoking the callback");
} else if (!Z_ISUNDEF(retval)) {
if (Z_TYPE(retval) != IS_LONG) {
convert_to_long(&retval);
}
ret = 0;
if (Z_LVAL(retval) > 0) {
ret = 1;
} else if (Z_LVAL(retval) < 0) {
ret = -1;
}
zval_ptr_dtor(&retval);
}
zval_ptr_dtor(&zargs[0]);
zval_ptr_dtor(&zargs[1]);
return ret;
}
/* {{{ bool SQLite::sqliteCreateFunction(string name, callable callback [, int argcount, int flags])
Registers a UDF with the sqlite db handle */
PHP_METHOD(PDO_SQLite_Ext, sqliteCreateFunction)
{
struct pdo_sqlite_func *func;
zend_fcall_info fci;
zend_fcall_info_cache fcc;
char *func_name;
size_t func_name_len;
zend_long argc = -1;
zend_long flags = 0;
pdo_dbh_t *dbh;
pdo_sqlite_db_handle *H;
int ret;
ZEND_PARSE_PARAMETERS_START(2, 4)
Z_PARAM_STRING(func_name, func_name_len)
Z_PARAM_FUNC(fci, fcc)
Z_PARAM_OPTIONAL
Z_PARAM_LONG(argc)
Z_PARAM_LONG(flags)
ZEND_PARSE_PARAMETERS_END();
dbh = Z_PDO_DBH_P(ZEND_THIS);
PDO_CONSTRUCT_CHECK;
H = (pdo_sqlite_db_handle *)dbh->driver_data;
func = (struct pdo_sqlite_func*)ecalloc(1, sizeof(*func));
ret = sqlite3_create_function(H->db, func_name, argc, flags | SQLITE_UTF8,
func, php_sqlite3_func_callback, NULL, NULL);
if (ret == SQLITE_OK) {
func->funcname = estrdup(func_name);
ZVAL_COPY(&func->func, &fci.function_name);
func->argc = argc;
func->next = H->funcs;
H->funcs = func;
RETURN_TRUE;
}
efree(func);
RETURN_FALSE;
}
/* }}} */
/* {{{ bool SQLite::sqliteCreateAggregate(string name, callable step, callable fini [, int argcount])
Registers a UDF with the sqlite db handle */
/* The step function should have the prototype:
mixed step(mixed $context, int $rownumber, $value [, $value2 [, ...]])
$context will be null for the first row; on subsequent rows it will have
the value that was previously returned from the step function; you should
use this to maintain state for the aggregate.
The fini function should have the prototype:
mixed fini(mixed $context, int $rownumber)
$context will hold the return value from the very last call to the step function.
rownumber will hold the number of rows over which the aggregate was performed.
The return value of this function will be used as the return value for this
aggregate UDF.
*/
PHP_METHOD(PDO_SQLite_Ext, sqliteCreateAggregate)
{
struct pdo_sqlite_func *func;
zend_fcall_info step_fci, fini_fci;
zend_fcall_info_cache step_fcc, fini_fcc;
char *func_name;
size_t func_name_len;
zend_long argc = -1;
pdo_dbh_t *dbh;
pdo_sqlite_db_handle *H;
int ret;
ZEND_PARSE_PARAMETERS_START(3, 4)
Z_PARAM_STRING(func_name, func_name_len)
Z_PARAM_FUNC(step_fci, step_fcc)
Z_PARAM_FUNC(fini_fci, fini_fcc)
Z_PARAM_OPTIONAL
Z_PARAM_LONG(argc)
ZEND_PARSE_PARAMETERS_END();
dbh = Z_PDO_DBH_P(ZEND_THIS);
PDO_CONSTRUCT_CHECK;
H = (pdo_sqlite_db_handle *)dbh->driver_data;
func = (struct pdo_sqlite_func*)ecalloc(1, sizeof(*func));
ret = sqlite3_create_function(H->db, func_name, argc, SQLITE_UTF8,
func, NULL, php_sqlite3_func_step_callback, php_sqlite3_func_final_callback);
if (ret == SQLITE_OK) {
func->funcname = estrdup(func_name);
ZVAL_COPY(&func->step, &step_fci.function_name);
ZVAL_COPY(&func->fini, &fini_fci.function_name);
func->argc = argc;
func->next = H->funcs;
H->funcs = func;
RETURN_TRUE;
}
efree(func);
RETURN_FALSE;
}
/* }}} */
/* {{{ bool SQLite::sqliteCreateCollation(string name, callable callback)
Registers a collation with the sqlite db handle */
PHP_METHOD(PDO_SQLite_Ext, sqliteCreateCollation)
{
struct pdo_sqlite_collation *collation;
zend_fcall_info fci;
zend_fcall_info_cache fcc;
char *collation_name;
size_t collation_name_len;
pdo_dbh_t *dbh;
pdo_sqlite_db_handle *H;
int ret;
ZEND_PARSE_PARAMETERS_START(2, 2)
Z_PARAM_STRING(collation_name, collation_name_len)
Z_PARAM_FUNC(fci, fcc)
ZEND_PARSE_PARAMETERS_END();
dbh = Z_PDO_DBH_P(ZEND_THIS);
PDO_CONSTRUCT_CHECK;
H = (pdo_sqlite_db_handle *)dbh->driver_data;
collation = (struct pdo_sqlite_collation*)ecalloc(1, sizeof(*collation));
ret = sqlite3_create_collation(H->db, collation_name, SQLITE_UTF8, collation, php_sqlite3_collation_callback);
if (ret == SQLITE_OK) {
collation->name = estrdup(collation_name);
ZVAL_COPY(&collation->callback, &fci.function_name);
collation->next = H->collations;
H->collations = collation;
RETURN_TRUE;
}
efree(collation);
RETURN_FALSE;
}
/* }}} */
static const zend_function_entry *get_driver_methods(pdo_dbh_t *dbh, int kind)
{
switch (kind) {
case PDO_DBH_DRIVER_METHOD_KIND_DBH:
return class_PDO_SQLite_Ext_methods;
default:
return NULL;
}
}
static void pdo_sqlite_request_shutdown(pdo_dbh_t *dbh)
{
pdo_sqlite_db_handle *H = (pdo_sqlite_db_handle *)dbh->driver_data;
/* unregister functions, so that they don't linger for the next
* request */
if (H) {
pdo_sqlite_cleanup_callbacks(H);
}
}
static void pdo_sqlite_get_gc(pdo_dbh_t *dbh, zend_get_gc_buffer *gc_buffer)
{
pdo_sqlite_db_handle *H = dbh->driver_data;
struct pdo_sqlite_func *func = H->funcs;
while (func) {
zend_get_gc_buffer_add_zval(gc_buffer, &func->func);
zend_get_gc_buffer_add_zval(gc_buffer, &func->step);
zend_get_gc_buffer_add_zval(gc_buffer, &func->fini);
func = func->next;
}
struct pdo_sqlite_collation *collation = H->collations;
while (collation) {
zend_get_gc_buffer_add_zval(gc_buffer, &collation->callback);
collation = collation->next;
}
}
static const struct pdo_dbh_methods sqlite_methods = {
sqlite_handle_closer,
sqlite_handle_preparer,
sqlite_handle_doer,
sqlite_handle_quoter,
sqlite_handle_begin,
sqlite_handle_commit,
sqlite_handle_rollback,
pdo_sqlite_set_attr,
pdo_sqlite_last_insert_id,
pdo_sqlite_fetch_error_func,
pdo_sqlite_get_attribute,
NULL, /* check_liveness: not needed */
get_driver_methods,
pdo_sqlite_request_shutdown,
NULL, /* in transaction, use PDO's internal tracking mechanism */
pdo_sqlite_get_gc
};
static char *make_filename_safe(const char *filename)
{
if (!filename) {
return NULL;
}
if (*filename && strncasecmp(filename, "file:", 5) == 0) {
if (PG(open_basedir) && *PG(open_basedir)) {
return NULL;
}
return estrdup(filename);
}
if (*filename && memcmp(filename, ":memory:", sizeof(":memory:"))) {
char *fullpath = expand_filepath(filename, NULL);
if (!fullpath) {
return NULL;
}
if (php_check_open_basedir(fullpath)) {
efree(fullpath);
return NULL;
}
return fullpath;
}
return estrdup(filename);
}
static int authorizer(void *autharg, int access_type, const char *arg3, const char *arg4,
const char *arg5, const char *arg6)
{
char *filename;
switch (access_type) {
case SQLITE_ATTACH: {
filename = make_filename_safe(arg3);
if (!filename) {
return SQLITE_DENY;
}
efree(filename);
return SQLITE_OK;
}
default:
/* access allowed */
return SQLITE_OK;
}
}
static int pdo_sqlite_handle_factory(pdo_dbh_t *dbh, zval *driver_options) /* {{{ */
{
pdo_sqlite_db_handle *H;
int i, ret = 0;
zend_long timeout = 60, flags;
char *filename;
H = pecalloc(1, sizeof(pdo_sqlite_db_handle), dbh->is_persistent);
H->einfo.errcode = 0;
H->einfo.errmsg = NULL;
dbh->driver_data = H;
/* skip all but this one param event */
dbh->skip_param_evt = 0x7F ^ (1 << PDO_PARAM_EVT_EXEC_PRE);
filename = make_filename_safe(dbh->data_source);
if (!filename) {
zend_throw_exception_ex(php_pdo_get_exception(), 0,
"open_basedir prohibits opening %s",
dbh->data_source);
goto cleanup;
}
flags = pdo_attr_lval(driver_options, PDO_SQLITE_ATTR_OPEN_FLAGS, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE);
if (!(PG(open_basedir) && *PG(open_basedir))) {
flags |= SQLITE_OPEN_URI;
}
i = sqlite3_open_v2(filename, &H->db, flags, NULL);
efree(filename);
if (i != SQLITE_OK) {
pdo_sqlite_error(dbh);
goto cleanup;
}
if (PG(open_basedir) && *PG(open_basedir)) {
sqlite3_set_authorizer(H->db, authorizer, NULL);
}
if (driver_options) {
timeout = pdo_attr_lval(driver_options, PDO_ATTR_TIMEOUT, timeout);
}
sqlite3_busy_timeout(H->db, timeout * 1000);
dbh->alloc_own_columns = 1;
dbh->max_escaped_char_length = 2;
ret = 1;
cleanup:
dbh->methods = &sqlite_methods;
return ret;
}
/* }}} */
const pdo_driver_t pdo_sqlite_driver = {
PDO_DRIVER_HEADER(sqlite),
pdo_sqlite_handle_factory
};
| 20,934 | 23.892985 | 116 |
c
|
php-src
|
php-src-master/ext/pdo_sqlite/sqlite_driver_arginfo.h
|
/* This is a generated file, edit the .stub.php file instead.
* Stub hash: dc901bd60d17c1a2cdb40a118e2c6cd6eb0396e3 */
ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(arginfo_class_PDO_SQLite_Ext_sqliteCreateFunction, 0, 2, _IS_BOOL, 0)
ZEND_ARG_TYPE_INFO(0, name, IS_STRING, 0)
ZEND_ARG_TYPE_INFO(0, callback, IS_CALLABLE, 0)
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, numArgs, IS_LONG, 0, "-1")
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, flags, IS_LONG, 0, "0")
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(arginfo_class_PDO_SQLite_Ext_sqliteCreateAggregate, 0, 3, _IS_BOOL, 0)
ZEND_ARG_TYPE_INFO(0, name, IS_STRING, 0)
ZEND_ARG_TYPE_INFO(0, step, IS_CALLABLE, 0)
ZEND_ARG_TYPE_INFO(0, finalize, IS_CALLABLE, 0)
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, numArgs, IS_LONG, 0, "-1")
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(arginfo_class_PDO_SQLite_Ext_sqliteCreateCollation, 0, 2, _IS_BOOL, 0)
ZEND_ARG_TYPE_INFO(0, name, IS_STRING, 0)
ZEND_ARG_TYPE_INFO(0, callback, IS_CALLABLE, 0)
ZEND_END_ARG_INFO()
ZEND_METHOD(PDO_SQLite_Ext, sqliteCreateFunction);
ZEND_METHOD(PDO_SQLite_Ext, sqliteCreateAggregate);
ZEND_METHOD(PDO_SQLite_Ext, sqliteCreateCollation);
static const zend_function_entry class_PDO_SQLite_Ext_methods[] = {
ZEND_ME(PDO_SQLite_Ext, sqliteCreateFunction, arginfo_class_PDO_SQLite_Ext_sqliteCreateFunction, ZEND_ACC_PUBLIC)
ZEND_ME(PDO_SQLite_Ext, sqliteCreateAggregate, arginfo_class_PDO_SQLite_Ext_sqliteCreateAggregate, ZEND_ACC_PUBLIC)
ZEND_ME(PDO_SQLite_Ext, sqliteCreateCollation, arginfo_class_PDO_SQLite_Ext_sqliteCreateCollation, ZEND_ACC_PUBLIC)
ZEND_FE_END
};
| 1,662 | 46.514286 | 120 |
h
|
php-src
|
php-src-master/ext/pdo_sqlite/sqlite_statement.c
|
/*
+----------------------------------------------------------------------+
| Copyright (c) The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| https://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| [email protected] so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Author: Wez Furlong <[email protected]> |
+----------------------------------------------------------------------+
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "php.h"
#include "php_ini.h"
#include "ext/standard/info.h"
#include "pdo/php_pdo.h"
#include "pdo/php_pdo_driver.h"
#include "php_pdo_sqlite.h"
#include "php_pdo_sqlite_int.h"
static int pdo_sqlite_stmt_dtor(pdo_stmt_t *stmt)
{
pdo_sqlite_stmt *S = (pdo_sqlite_stmt*)stmt->driver_data;
if (S->stmt) {
sqlite3_finalize(S->stmt);
S->stmt = NULL;
}
efree(S);
return 1;
}
static int pdo_sqlite_stmt_execute(pdo_stmt_t *stmt)
{
pdo_sqlite_stmt *S = (pdo_sqlite_stmt*)stmt->driver_data;
if (stmt->executed && !S->done) {
sqlite3_reset(S->stmt);
}
S->done = 0;
switch (sqlite3_step(S->stmt)) {
case SQLITE_ROW:
S->pre_fetched = 1;
php_pdo_stmt_set_column_count(stmt, sqlite3_data_count(S->stmt));
return 1;
case SQLITE_DONE:
php_pdo_stmt_set_column_count(stmt, sqlite3_column_count(S->stmt));
stmt->row_count = sqlite3_changes(S->H->db);
sqlite3_reset(S->stmt);
S->done = 1;
return 1;
case SQLITE_ERROR:
sqlite3_reset(S->stmt);
ZEND_FALLTHROUGH;
case SQLITE_MISUSE:
case SQLITE_BUSY:
default:
pdo_sqlite_error_stmt(stmt);
return 0;
}
}
static int pdo_sqlite_stmt_param_hook(pdo_stmt_t *stmt, struct pdo_bound_param_data *param,
enum pdo_param_event event_type)
{
pdo_sqlite_stmt *S = (pdo_sqlite_stmt*)stmt->driver_data;
zval *parameter;
switch (event_type) {
case PDO_PARAM_EVT_EXEC_PRE:
if (stmt->executed && !S->done) {
sqlite3_reset(S->stmt);
S->done = 1;
}
if (param->is_param) {
if (param->paramno == -1) {
param->paramno = sqlite3_bind_parameter_index(S->stmt, ZSTR_VAL(param->name)) - 1;
}
switch (PDO_PARAM_TYPE(param->param_type)) {
case PDO_PARAM_STMT:
return 0;
case PDO_PARAM_NULL:
if (sqlite3_bind_null(S->stmt, param->paramno + 1) == SQLITE_OK) {
return 1;
}
pdo_sqlite_error_stmt(stmt);
return 0;
case PDO_PARAM_INT:
case PDO_PARAM_BOOL:
if (Z_ISREF(param->parameter)) {
parameter = Z_REFVAL(param->parameter);
} else {
parameter = ¶m->parameter;
}
if (Z_TYPE_P(parameter) == IS_NULL) {
if (sqlite3_bind_null(S->stmt, param->paramno + 1) == SQLITE_OK) {
return 1;
}
} else {
convert_to_long(parameter);
#if ZEND_LONG_MAX > 2147483647
if (SQLITE_OK == sqlite3_bind_int64(S->stmt, param->paramno + 1, Z_LVAL_P(parameter))) {
return 1;
}
#else
if (SQLITE_OK == sqlite3_bind_int(S->stmt, param->paramno + 1, Z_LVAL_P(parameter))) {
return 1;
}
#endif
}
pdo_sqlite_error_stmt(stmt);
return 0;
case PDO_PARAM_LOB:
if (Z_ISREF(param->parameter)) {
parameter = Z_REFVAL(param->parameter);
} else {
parameter = ¶m->parameter;
}
if (Z_TYPE_P(parameter) == IS_RESOURCE) {
php_stream *stm = NULL;
php_stream_from_zval_no_verify(stm, parameter);
if (stm) {
zend_string *mem = php_stream_copy_to_mem(stm, PHP_STREAM_COPY_ALL, 0);
zval_ptr_dtor(parameter);
ZVAL_STR(parameter, mem ? mem : ZSTR_EMPTY_ALLOC());
} else {
pdo_raise_impl_error(stmt->dbh, stmt, "HY105", "Expected a stream resource");
return 0;
}
} else if (Z_TYPE_P(parameter) == IS_NULL) {
if (sqlite3_bind_null(S->stmt, param->paramno + 1) == SQLITE_OK) {
return 1;
}
pdo_sqlite_error_stmt(stmt);
return 0;
} else {
if (!try_convert_to_string(parameter)) {
return 0;
}
}
if (SQLITE_OK == sqlite3_bind_blob(S->stmt, param->paramno + 1,
Z_STRVAL_P(parameter),
Z_STRLEN_P(parameter),
SQLITE_STATIC)) {
return 1;
}
return 0;
case PDO_PARAM_STR:
default:
if (Z_ISREF(param->parameter)) {
parameter = Z_REFVAL(param->parameter);
} else {
parameter = ¶m->parameter;
}
if (Z_TYPE_P(parameter) == IS_NULL) {
if (sqlite3_bind_null(S->stmt, param->paramno + 1) == SQLITE_OK) {
return 1;
}
} else {
if (!try_convert_to_string(parameter)) {
return 0;
}
if (SQLITE_OK == sqlite3_bind_text(S->stmt, param->paramno + 1,
Z_STRVAL_P(parameter),
Z_STRLEN_P(parameter),
SQLITE_STATIC)) {
return 1;
}
}
pdo_sqlite_error_stmt(stmt);
return 0;
}
}
break;
default:
;
}
return 1;
}
static int pdo_sqlite_stmt_fetch(pdo_stmt_t *stmt,
enum pdo_fetch_orientation ori, zend_long offset)
{
pdo_sqlite_stmt *S = (pdo_sqlite_stmt*)stmt->driver_data;
int i;
if (!S->stmt) {
return 0;
}
if (S->pre_fetched) {
S->pre_fetched = 0;
return 1;
}
if (S->done) {
return 0;
}
i = sqlite3_step(S->stmt);
switch (i) {
case SQLITE_ROW:
return 1;
case SQLITE_DONE:
S->done = 1;
sqlite3_reset(S->stmt);
return 0;
case SQLITE_ERROR:
sqlite3_reset(S->stmt);
ZEND_FALLTHROUGH;
default:
pdo_sqlite_error_stmt(stmt);
return 0;
}
}
static int pdo_sqlite_stmt_describe(pdo_stmt_t *stmt, int colno)
{
pdo_sqlite_stmt *S = (pdo_sqlite_stmt*)stmt->driver_data;
const char *str;
if(colno >= sqlite3_column_count(S->stmt)) {
/* error invalid column */
pdo_sqlite_error_stmt(stmt);
return 0;
}
str = sqlite3_column_name(S->stmt, colno);
stmt->columns[colno].name = zend_string_init(str, strlen(str), 0);
stmt->columns[colno].maxlen = SIZE_MAX;
stmt->columns[colno].precision = 0;
return 1;
}
static int pdo_sqlite_stmt_get_col(
pdo_stmt_t *stmt, int colno, zval *result, enum pdo_param_type *type)
{
pdo_sqlite_stmt *S = (pdo_sqlite_stmt*)stmt->driver_data;
if (!S->stmt) {
return 0;
}
if(colno >= sqlite3_data_count(S->stmt)) {
/* error invalid column */
pdo_sqlite_error_stmt(stmt);
return 0;
}
switch (sqlite3_column_type(S->stmt, colno)) {
case SQLITE_NULL:
ZVAL_NULL(result);
return 1;
case SQLITE_INTEGER: {
int64_t i = sqlite3_column_int64(S->stmt, colno);
#if SIZEOF_ZEND_LONG < 8
if (i > ZEND_LONG_MAX || i < ZEND_LONG_MIN) {
ZVAL_STRINGL(result,
(char *) sqlite3_column_text(S->stmt, colno),
sqlite3_column_bytes(S->stmt, colno));
return 1;
}
#endif
ZVAL_LONG(result, i);
return 1;
}
case SQLITE_FLOAT:
ZVAL_DOUBLE(result, sqlite3_column_double(S->stmt, colno));
return 1;
case SQLITE_BLOB:
ZVAL_STRINGL_FAST(result,
sqlite3_column_blob(S->stmt, colno), sqlite3_column_bytes(S->stmt, colno));
return 1;
default:
ZVAL_STRINGL_FAST(result,
(char *) sqlite3_column_text(S->stmt, colno), sqlite3_column_bytes(S->stmt, colno));
return 1;
}
}
static int pdo_sqlite_stmt_col_meta(pdo_stmt_t *stmt, zend_long colno, zval *return_value)
{
pdo_sqlite_stmt *S = (pdo_sqlite_stmt*)stmt->driver_data;
const char *str;
zval flags;
if (!S->stmt) {
return FAILURE;
}
if(colno >= sqlite3_column_count(S->stmt)) {
/* error invalid column */
pdo_sqlite_error_stmt(stmt);
return FAILURE;
}
array_init(return_value);
array_init(&flags);
switch (sqlite3_column_type(S->stmt, colno)) {
case SQLITE_NULL:
add_assoc_str(return_value, "native_type", ZSTR_KNOWN(ZEND_STR_NULL_LOWERCASE));
add_assoc_long(return_value, "pdo_type", PDO_PARAM_NULL);
break;
case SQLITE_FLOAT:
add_assoc_str(return_value, "native_type", ZSTR_KNOWN(ZEND_STR_DOUBLE));
add_assoc_long(return_value, "pdo_type", PDO_PARAM_STR);
break;
case SQLITE_BLOB:
add_next_index_string(&flags, "blob");
/* TODO Check this is correct */
ZEND_FALLTHROUGH;
case SQLITE_TEXT:
add_assoc_str(return_value, "native_type", ZSTR_KNOWN(ZEND_STR_STRING));
add_assoc_long(return_value, "pdo_type", PDO_PARAM_STR);
break;
case SQLITE_INTEGER:
add_assoc_str(return_value, "native_type", ZSTR_KNOWN(ZEND_STR_INTEGER));
add_assoc_long(return_value, "pdo_type", PDO_PARAM_INT);
break;
}
str = sqlite3_column_decltype(S->stmt, colno);
if (str) {
add_assoc_string(return_value, "sqlite:decl_type", (char *)str);
}
#ifdef HAVE_SQLITE3_COLUMN_TABLE_NAME
str = sqlite3_column_table_name(S->stmt, colno);
if (str) {
add_assoc_string(return_value, "table", (char *)str);
}
#endif
add_assoc_zval(return_value, "flags", &flags);
return SUCCESS;
}
static int pdo_sqlite_stmt_cursor_closer(pdo_stmt_t *stmt)
{
pdo_sqlite_stmt *S = (pdo_sqlite_stmt*)stmt->driver_data;
sqlite3_reset(S->stmt);
return 1;
}
static int pdo_sqlite_stmt_get_attribute(pdo_stmt_t *stmt, zend_long attr, zval *val)
{
pdo_sqlite_stmt *S = (pdo_sqlite_stmt*)stmt->driver_data;
switch (attr) {
case PDO_SQLITE_ATTR_READONLY_STATEMENT:
ZVAL_FALSE(val);
#if SQLITE_VERSION_NUMBER >= 3007004
if (sqlite3_stmt_readonly(S->stmt)) {
ZVAL_TRUE(val);
}
#endif
break;
default:
return 0;
}
return 1;
}
const struct pdo_stmt_methods sqlite_stmt_methods = {
pdo_sqlite_stmt_dtor,
pdo_sqlite_stmt_execute,
pdo_sqlite_stmt_fetch,
pdo_sqlite_stmt_describe,
pdo_sqlite_stmt_get_col,
pdo_sqlite_stmt_param_hook,
NULL, /* set_attr */
pdo_sqlite_stmt_get_attribute, /* get_attr */
pdo_sqlite_stmt_col_meta,
NULL, /* next_rowset */
pdo_sqlite_stmt_cursor_closer
};
| 10,251 | 24.31358 | 95 |
c
|
php-src
|
php-src-master/ext/phar/func_interceptors.h
|
/*
+----------------------------------------------------------------------+
| phar php single-file executable PHP extension |
+----------------------------------------------------------------------+
| Copyright (c) The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| https://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| [email protected] so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Authors: Gregory Beaver <[email protected]> |
| Marcus Boerger <[email protected]> |
+----------------------------------------------------------------------+
*/
BEGIN_EXTERN_C()
void phar_intercept_functions(void);
void phar_release_functions(void);
void phar_intercept_functions_init(void);
void phar_intercept_functions_shutdown(void);
void phar_save_orig_functions(void);
void phar_restore_orig_functions(void);
END_EXTERN_C()
| 1,476 | 51.75 | 74 |
h
|
php-src
|
php-src-master/ext/phar/pharzip.h
|
/*
+----------------------------------------------------------------------+
| phar php single-file executable PHP extension |
+----------------------------------------------------------------------+
| Copyright (c) The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| https://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| [email protected] so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Authors: Gregory Beaver <[email protected]> |
| Marcus Boerger <[email protected]> |
+----------------------------------------------------------------------+
*/
typedef struct _phar_zip_file_header {
char signature[4]; /* local file header signature 4 bytes (0x04034b50) */
char zipversion[2]; /* version needed to extract 2 bytes */
char flags[2]; /* general purpose bit flag 2 bytes */
char compressed[2]; /* compression method 2 bytes */
char timestamp[2]; /* last mod file time 2 bytes */
char datestamp[2]; /* last mod file date 2 bytes */
char crc32[4]; /* crc-32 4 bytes */
char compsize[4]; /* compressed size 4 bytes */
char uncompsize[4]; /* uncompressed size 4 bytes */
char filename_len[2]; /* file name length 2 bytes */
char extra_len[2]; /* extra field length 2 bytes */
/* file name (variable size) */
/* extra field (variable size) */
} phar_zip_file_header;
/* unused in this release */
typedef struct _phar_zip_file_datadesc {
char signature[4]; /* signature (optional) 4 bytes */
char crc32[4]; /* crc-32 4 bytes */
char compsize[4]; /* compressed size 4 bytes */
char uncompsize[4]; /* uncompressed size 4 bytes */
} phar_zip_data_desc;
/* unused in this release */
typedef struct _phar_zip_file_datadesc_zip64 {
char crc32[4]; /* crc-32 4 bytes */
char compsize[4]; /* compressed size 8 bytes */
char compsize2[4];
char uncompsize[4]; /* uncompressed size 8 bytes */
char uncompsize2[4];
} phar_zip_data_desc_zip64;
typedef struct _phar_zip_archive_extra_data_record {
char signature[4]; /* archive extra data signature 4 bytes (0x08064b50) */
char len[4]; /* extra field length 4 bytes */
/* extra field data (variable size) */
} phar_zip_archive_extra_data_record;
/* madeby/extractneeded value if bzip2 compression is used */
#define PHAR_ZIP_BZIP2 "46"
/* madeby/extractneeded value for other cases */
#define PHAR_ZIP_NORM "20"
#define PHAR_ZIP_FLAG_ENCRYPTED 0x0001
/* data descriptor present for this file */
#define PHAR_ZIP_FLAG_DATADESC 0x0008
#define PHAR_ZIP_FLAG_UTF8 0x0400
/*
0 - The file is stored (no compression)
1 - The file is Shrunk
2 - The file is Reduced with compression factor 1
3 - The file is Reduced with compression factor 2
4 - The file is Reduced with compression factor 3
5 - The file is Reduced with compression factor 4
6 - The file is Imploded
7 - Reserved for Tokenizing compression algorithm
8 - The file is Deflated
9 - Enhanced Deflating using Deflate64(tm)
10 - PKWARE Data Compression Library Imploding (old IBM TERSE)
11 - Reserved by PKWARE
12 - File is compressed using BZIP2 algorithm
13 - Reserved by PKWARE
14 - LZMA (EFS)
15 - Reserved by PKWARE
16 - Reserved by PKWARE
17 - Reserved by PKWARE
18 - File is compressed using IBM TERSE (new)
19 - IBM LZ77 z Architecture (PFS)
97 - WavPack compressed data
98 - PPMd version I, Rev 1
*/
#define PHAR_ZIP_COMP_NONE 0
#define PHAR_ZIP_COMP_DEFLATE 8
#define PHAR_ZIP_COMP_BZIP2 12
/*
-ASi Unix Extra Field:
====================
The following is the layout of the ASi extra block for Unix. The
local-header and central-header versions are identical.
(Last Revision 19960916)
Value Size Description
----- ---- -----------
(Unix3) 0x756e Short tag for this extra block type ("nu")
TSize Short total data size for this block
CRC Long CRC-32 of the remaining data
Mode Short file permissions
SizDev Long symlink'd size OR major/minor dev num
UID Short user ID
GID Short group ID
(var.) variable symbolic link filename
Mode is the standard Unix st_mode field from struct stat, containing
user/group/other permissions, setuid/setgid and symlink info, etc.
If Mode indicates that this file is a symbolic link, SizDev is the
size of the file to which the link points. Otherwise, if the file
is a device, SizDev contains the standard Unix st_rdev field from
struct stat (includes the major and minor numbers of the device).
SizDev is undefined in other cases.
If Mode indicates that the file is a symbolic link, the final field
will be the name of the file to which the link points. The file-
name length can be inferred from TSize.
[Note that TSize may incorrectly refer to the data size not counting
the CRC; i.e., it may be four bytes too small.]
*/
typedef struct _phar_zip_extra_field_header {
char tag[2];
char size[2];
} phar_zip_extra_field_header;
typedef struct _phar_zip_unix3 {
char tag[2]; /* 0x756e Short tag for this extra block type ("nu") */
char size[2]; /* TSize Short total data size for this block */
char crc32[4]; /* CRC Long CRC-32 of the remaining data */
char perms[2]; /* Mode Short file permissions */
char symlinksize[4]; /* SizDev Long symlink'd size OR major/minor dev num */
char uid[2]; /* UID Short user ID */
char gid[2]; /* GID Short group ID */
/* (var.) variable symbolic link filename */
} phar_zip_unix3;
typedef struct _phar_zip_central_dir_file {
char signature[4]; /* central file header signature 4 bytes (0x02014b50) */
char madeby[2]; /* version made by 2 bytes */
char zipversion[2]; /* version needed to extract 2 bytes */
char flags[2]; /* general purpose bit flag 2 bytes */
char compressed[2]; /* compression method 2 bytes */
char timestamp[2]; /* last mod file time 2 bytes */
char datestamp[2]; /* last mod file date 2 bytes */
char crc32[4]; /* crc-32 4 bytes */
char compsize[4]; /* compressed size 4 bytes */
char uncompsize[4]; /* uncompressed size 4 bytes */
char filename_len[2]; /* file name length 2 bytes */
char extra_len[2]; /* extra field length 2 bytes */
char comment_len[2]; /* file comment length 2 bytes */
char disknumber[2]; /* disk number start 2 bytes */
char internal_atts[2]; /* internal file attributes 2 bytes */
char external_atts[4]; /* external file attributes 4 bytes */
char offset[4]; /* relative offset of local header 4 bytes */
/* file name (variable size) */
/* extra field (variable size) */
/* file comment (variable size) */
} phar_zip_central_dir_file;
typedef struct _phar_zip_dir_signature {
char signature[4]; /* header signature 4 bytes (0x05054b50) */
char size[2]; /* size of data 2 bytes */
} phar_zip_dir_signature;
/* unused in this release */
typedef struct _phar_zip64_dir_end {
char signature[4]; /* zip64 end of central dir
signature 4 bytes (0x06064b50) */
char size1[4]; /* size of zip64 end of central
directory record 8 bytes */
char size2[4];
char madeby[2]; /* version made by 2 bytes */
char extractneeded[2]; /* version needed to extract 2 bytes */
char disknum[4]; /* number of this disk 4 bytes */
char cdir_num[4]; /* number of the disk with the
start of the central directory 4 bytes */
char entries1[4]; /* total number of entries in the
central directory on this disk 8 bytes */
char entries2[4];
char entriestotal1[4]; /* total number of entries in the
central directory 8 bytes */
char entriestotal2[4];
char cdirsize1[4]; /* size of the central directory 8 bytes */
char cdirsize2[4];
char offset1[4]; /* offset of start of central
directory with respect to
the starting disk number 8 bytes */
char offset2[4];
/* zip64 extensible data sector (variable size) */
} phar_zip64_dir_end;
/* unused in this release */
typedef struct _phar_zip64_dir_locator {
char signature[4]; /* zip64 end of central dir locator
signature 4 bytes (0x07064b50) */
char disknum[4]; /* number of the disk with the
start of the zip64 end of
central directory 4 bytes */
char diroffset1[4]; /* relative offset of the zip64
end of central directory record 8 bytes */
char diroffset2[4];
char totaldisks[4]; /* total number of disks 4 bytes */
} phar_zip64_dir_locator;
typedef struct _phar_zip_dir_end {
char signature[4]; /* end of central dir signature 4 bytes (0x06054b50) */
char disknumber[2]; /* number of this disk 2 bytes */
char centraldisk[2]; /* number of the disk with the
start of the central directory 2 bytes */
char counthere[2]; /* total number of entries in the
central directory on this disk 2 bytes */
char count[2]; /* total number of entries in
the central directory 2 bytes */
char cdir_size[4]; /* size of the central directory 4 bytes */
char cdir_offset[4]; /* offset of start of central
directory with respect to
the starting disk number 4 bytes */
char comment_len[2]; /* .ZIP file comment length 2 bytes */
/* .ZIP file comment (variable size) */
} phar_zip_dir_end;
| 11,504 | 48.166667 | 93 |
h
|
php-src
|
php-src-master/ext/phar/php_phar.h
|
/*
+----------------------------------------------------------------------+
| phar php single-file executable PHP extension |
+----------------------------------------------------------------------+
| Copyright (c) The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| https://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| [email protected] so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Authors: Gregory Beaver <[email protected]> |
| Marcus Boerger <[email protected]> |
+----------------------------------------------------------------------+
*/
#ifndef PHP_PHAR_H
#define PHP_PHAR_H
#define PHP_PHAR_VERSION PHP_VERSION
#include "ext/standard/basic_functions.h"
extern zend_module_entry phar_module_entry;
#define phpext_phar_ptr &phar_module_entry
#ifdef PHP_WIN32
#define PHP_PHAR_API __declspec(dllexport)
#else
#define PHP_PHAR_API PHPAPI
#endif
PHP_PHAR_API int phar_resolve_alias(char *alias, size_t alias_len, char **filename, size_t *filename_len);
#endif /* PHP_PHAR_H */
| 1,648 | 42.394737 | 106 |
h
|
php-src
|
php-src-master/ext/phar/tar.h
|
#ifndef __PHAR_TAR_H
#define __PHAR_TAR_H
/*
+----------------------------------------------------------------------+
| TAR archive support for Phar |
+----------------------------------------------------------------------+
| Copyright (c) The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| https://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| [email protected] so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Authors: Dmitry Stogov <[email protected]> |
| Gregory Beaver <[email protected]> |
+----------------------------------------------------------------------+
*/
#ifdef PHP_WIN32
#pragma pack(1)
# define PHAR_TAR_PACK
#elif defined(__sgi)
# define PHAR_TAR_PACK
#elif defined(__GNUC__)
# define PHAR_TAR_PACK __attribute__((__packed__))
#else
# define PHAR_TAR_PACK
#endif
#if defined(__sgi)
# pragma pack 0
#endif
/**
* the format of the header block for a file, in the older UNIX-compatible
* TAR format
*/
typedef struct _old_tar_header { /* {{{ */
char name[100]; /* name of file;
directory is indicated by a trailing slash (/) */
char mode[8]; /* file mode */
char uid[8]; /* owner user ID */
char gid[8]; /* owner group ID */
char size[12]; /* length of file in bytes */
char mtime[12]; /* modify time of file */
char checksum[8]; /* checksum for header */
char link; /* indicator for links;
1 for a linked file,
2 for a symbolic link,
0 otherwise */
char linkname[100]; /* name of linked file */
} PHAR_TAR_PACK old_tar_header;
/* }}} */
#if defined(__sgi)
# pragma pack 0
#endif
/**
* the new USTAR header format.
* Note that tar can determine that the USTAR format is being used by the
* presence of the null-terminated string "ustar" in the magic field.
*/
typedef struct _tar_header { /* {{{ */
char name[100]; /* name of file */
char mode[8]; /* file mode */
char uid[8]; /* owner user ID */
char gid[8]; /* owner group ID */
char size[12]; /* length of file in bytes */
char mtime[12]; /* modify time of file */
char checksum[8]; /* checksum for header */
char typeflag; /* type of file
0 Regular file
1 Link to another file already archived
2 Symbolic link
3 Character special device
4 Block special device
5 Directory
6 FIFO special file
7 Reserved */
char linkname[100]; /* name of linked file */
char magic[6]; /* USTAR indicator */
char version[2]; /* USTAR version */
char uname[32]; /* owner user name */
char gname[32]; /* owner group name */
char devmajor[8]; /* device major number */
char devminor[8]; /* device minor number */
char prefix[155]; /* prefix for file name;
the value of the prefix field, if non-null,
is prefixed to the name field to allow names
longer then 100 characters */
char padding[12]; /* unused zeroed bytes */
} PHAR_TAR_PACK tar_header;
/* }}} */
#ifdef PHP_WIN32
#pragma pack()
#endif
#endif /* __PHAR_TAR_H */
| 3,981 | 38.039216 | 75 |
h
|
php-src
|
php-src-master/ext/posix/php_posix.h
|
/*
+----------------------------------------------------------------------+
| Copyright (c) The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| https://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| [email protected] so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Author: Kristian Koehntopp <[email protected]> |
+----------------------------------------------------------------------+
*/
#ifndef PHP_POSIX_H
#define PHP_POSIX_H
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#ifdef HAVE_POSIX
#ifndef DLEXPORT
#define DLEXPORT
#endif
extern zend_module_entry posix_module_entry;
#define posix_module_ptr &posix_module_entry
#include "php_version.h"
#define PHP_POSIX_VERSION PHP_VERSION
ZEND_BEGIN_MODULE_GLOBALS(posix)
int last_error;
ZEND_END_MODULE_GLOBALS(posix)
#if defined(ZTS) && defined(COMPILE_DL_POSIX)
ZEND_TSRMLS_CACHE_EXTERN()
#endif
ZEND_EXTERN_MODULE_GLOBALS(posix)
#define POSIX_G(v) ZEND_MODULE_GLOBALS_ACCESSOR(posix, v)
#else
#define posix_module_ptr NULL
#endif
#define phpext_posix_ptr posix_module_ptr
#endif /* PHP_POSIX_H */
| 1,671 | 29.4 | 75 |
h
|
php-src
|
php-src-master/ext/posix/posix_arginfo.h
|
/* This is a generated file, edit the .stub.php file instead.
* Stub hash: 5a4a863892761475f2d34d9463e0660b0a8ede5d */
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_posix_kill, 0, 2, _IS_BOOL, 0)
ZEND_ARG_TYPE_INFO(0, process_id, IS_LONG, 0)
ZEND_ARG_TYPE_INFO(0, signal, IS_LONG, 0)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_posix_getpid, 0, 0, IS_LONG, 0)
ZEND_END_ARG_INFO()
#define arginfo_posix_getppid arginfo_posix_getpid
#define arginfo_posix_getuid arginfo_posix_getpid
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_posix_setuid, 0, 1, _IS_BOOL, 0)
ZEND_ARG_TYPE_INFO(0, user_id, IS_LONG, 0)
ZEND_END_ARG_INFO()
#define arginfo_posix_geteuid arginfo_posix_getpid
#if defined(HAVE_SETEUID)
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_posix_seteuid, 0, 1, _IS_BOOL, 0)
ZEND_ARG_TYPE_INFO(0, user_id, IS_LONG, 0)
ZEND_END_ARG_INFO()
#endif
#define arginfo_posix_getgid arginfo_posix_getpid
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_posix_setgid, 0, 1, _IS_BOOL, 0)
ZEND_ARG_TYPE_INFO(0, group_id, IS_LONG, 0)
ZEND_END_ARG_INFO()
#define arginfo_posix_getegid arginfo_posix_getpid
#if defined(HAVE_SETEGID)
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_posix_setegid, 0, 1, _IS_BOOL, 0)
ZEND_ARG_TYPE_INFO(0, group_id, IS_LONG, 0)
ZEND_END_ARG_INFO()
#endif
#if defined(HAVE_GETGROUPS)
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_posix_getgroups, 0, 0, MAY_BE_ARRAY|MAY_BE_FALSE)
ZEND_END_ARG_INFO()
#endif
#if defined(HAVE_GETLOGIN)
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_posix_getlogin, 0, 0, MAY_BE_STRING|MAY_BE_FALSE)
ZEND_END_ARG_INFO()
#endif
#define arginfo_posix_getpgrp arginfo_posix_getpid
#if defined(HAVE_SETSID)
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_posix_setsid, 0, 0, IS_LONG, 0)
ZEND_END_ARG_INFO()
#endif
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_posix_setpgid, 0, 2, _IS_BOOL, 0)
ZEND_ARG_TYPE_INFO(0, process_id, IS_LONG, 0)
ZEND_ARG_TYPE_INFO(0, process_group_id, IS_LONG, 0)
ZEND_END_ARG_INFO()
#if defined(HAVE_GETPGID)
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_posix_getpgid, 0, 1, MAY_BE_LONG|MAY_BE_FALSE)
ZEND_ARG_TYPE_INFO(0, process_id, IS_LONG, 0)
ZEND_END_ARG_INFO()
#endif
#if defined(HAVE_GETSID)
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_posix_getsid, 0, 1, MAY_BE_LONG|MAY_BE_FALSE)
ZEND_ARG_TYPE_INFO(0, process_id, IS_LONG, 0)
ZEND_END_ARG_INFO()
#endif
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_posix_uname, 0, 0, MAY_BE_ARRAY|MAY_BE_FALSE)
ZEND_END_ARG_INFO()
#define arginfo_posix_times arginfo_posix_uname
#if defined(HAVE_CTERMID)
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_posix_ctermid, 0, 0, MAY_BE_STRING|MAY_BE_FALSE)
ZEND_END_ARG_INFO()
#endif
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_posix_ttyname, 0, 1, MAY_BE_STRING|MAY_BE_FALSE)
ZEND_ARG_INFO(0, file_descriptor)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_posix_isatty, 0, 1, _IS_BOOL, 0)
ZEND_ARG_INFO(0, file_descriptor)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_posix_getcwd, 0, 0, MAY_BE_STRING|MAY_BE_FALSE)
ZEND_END_ARG_INFO()
#if defined(HAVE_MKFIFO)
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_posix_mkfifo, 0, 2, _IS_BOOL, 0)
ZEND_ARG_TYPE_INFO(0, filename, IS_STRING, 0)
ZEND_ARG_TYPE_INFO(0, permissions, IS_LONG, 0)
ZEND_END_ARG_INFO()
#endif
#if defined(HAVE_MKNOD)
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_posix_mknod, 0, 2, _IS_BOOL, 0)
ZEND_ARG_TYPE_INFO(0, filename, IS_STRING, 0)
ZEND_ARG_TYPE_INFO(0, flags, IS_LONG, 0)
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, major, IS_LONG, 0, "0")
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, minor, IS_LONG, 0, "0")
ZEND_END_ARG_INFO()
#endif
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_posix_access, 0, 1, _IS_BOOL, 0)
ZEND_ARG_TYPE_INFO(0, filename, IS_STRING, 0)
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, flags, IS_LONG, 0, "0")
ZEND_END_ARG_INFO()
#if defined(HAVE_EACCESS)
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_posix_eaccess, 0, 1, _IS_BOOL, 0)
ZEND_ARG_TYPE_INFO(0, filename, IS_STRING, 0)
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, flags, IS_LONG, 0, "0")
ZEND_END_ARG_INFO()
#endif
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_posix_getgrnam, 0, 1, MAY_BE_ARRAY|MAY_BE_FALSE)
ZEND_ARG_TYPE_INFO(0, name, IS_STRING, 0)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_posix_getgrgid, 0, 1, MAY_BE_ARRAY|MAY_BE_FALSE)
ZEND_ARG_TYPE_INFO(0, group_id, IS_LONG, 0)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_posix_getpwnam, 0, 1, MAY_BE_ARRAY|MAY_BE_FALSE)
ZEND_ARG_TYPE_INFO(0, username, IS_STRING, 0)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_posix_getpwuid, 0, 1, MAY_BE_ARRAY|MAY_BE_FALSE)
ZEND_ARG_TYPE_INFO(0, user_id, IS_LONG, 0)
ZEND_END_ARG_INFO()
#if defined(HAVE_GETRLIMIT)
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_posix_getrlimit, 0, 0, MAY_BE_ARRAY|MAY_BE_FALSE)
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, resource, IS_LONG, 1, "null")
ZEND_END_ARG_INFO()
#endif
#if defined(HAVE_SETRLIMIT)
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_posix_setrlimit, 0, 3, _IS_BOOL, 0)
ZEND_ARG_TYPE_INFO(0, resource, IS_LONG, 0)
ZEND_ARG_TYPE_INFO(0, soft_limit, IS_LONG, 0)
ZEND_ARG_TYPE_INFO(0, hard_limit, IS_LONG, 0)
ZEND_END_ARG_INFO()
#endif
#define arginfo_posix_get_last_error arginfo_posix_getpid
#define arginfo_posix_errno arginfo_posix_getpid
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_posix_strerror, 0, 1, IS_STRING, 0)
ZEND_ARG_TYPE_INFO(0, error_code, IS_LONG, 0)
ZEND_END_ARG_INFO()
#if defined(HAVE_INITGROUPS)
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_posix_initgroups, 0, 2, _IS_BOOL, 0)
ZEND_ARG_TYPE_INFO(0, username, IS_STRING, 0)
ZEND_ARG_TYPE_INFO(0, group_id, IS_LONG, 0)
ZEND_END_ARG_INFO()
#endif
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_posix_sysconf, 0, 1, IS_LONG, 0)
ZEND_ARG_TYPE_INFO(0, conf_id, IS_LONG, 0)
ZEND_END_ARG_INFO()
#if defined(HAVE_POSIX_PATHCONF)
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_posix_pathconf, 0, 2, MAY_BE_LONG|MAY_BE_FALSE)
ZEND_ARG_TYPE_INFO(0, path, IS_STRING, 0)
ZEND_ARG_TYPE_INFO(0, name, IS_LONG, 0)
ZEND_END_ARG_INFO()
#endif
#if defined(HAVE_POSIX_PATHCONF)
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_posix_fpathconf, 0, 2, MAY_BE_LONG|MAY_BE_FALSE)
ZEND_ARG_INFO(0, file_descriptor)
ZEND_ARG_TYPE_INFO(0, name, IS_LONG, 0)
ZEND_END_ARG_INFO()
#endif
ZEND_FUNCTION(posix_kill);
ZEND_FUNCTION(posix_getpid);
ZEND_FUNCTION(posix_getppid);
ZEND_FUNCTION(posix_getuid);
ZEND_FUNCTION(posix_setuid);
ZEND_FUNCTION(posix_geteuid);
#if defined(HAVE_SETEUID)
ZEND_FUNCTION(posix_seteuid);
#endif
ZEND_FUNCTION(posix_getgid);
ZEND_FUNCTION(posix_setgid);
ZEND_FUNCTION(posix_getegid);
#if defined(HAVE_SETEGID)
ZEND_FUNCTION(posix_setegid);
#endif
#if defined(HAVE_GETGROUPS)
ZEND_FUNCTION(posix_getgroups);
#endif
#if defined(HAVE_GETLOGIN)
ZEND_FUNCTION(posix_getlogin);
#endif
ZEND_FUNCTION(posix_getpgrp);
#if defined(HAVE_SETSID)
ZEND_FUNCTION(posix_setsid);
#endif
ZEND_FUNCTION(posix_setpgid);
#if defined(HAVE_GETPGID)
ZEND_FUNCTION(posix_getpgid);
#endif
#if defined(HAVE_GETSID)
ZEND_FUNCTION(posix_getsid);
#endif
ZEND_FUNCTION(posix_uname);
ZEND_FUNCTION(posix_times);
#if defined(HAVE_CTERMID)
ZEND_FUNCTION(posix_ctermid);
#endif
ZEND_FUNCTION(posix_ttyname);
ZEND_FUNCTION(posix_isatty);
ZEND_FUNCTION(posix_getcwd);
#if defined(HAVE_MKFIFO)
ZEND_FUNCTION(posix_mkfifo);
#endif
#if defined(HAVE_MKNOD)
ZEND_FUNCTION(posix_mknod);
#endif
ZEND_FUNCTION(posix_access);
#if defined(HAVE_EACCESS)
ZEND_FUNCTION(posix_eaccess);
#endif
ZEND_FUNCTION(posix_getgrnam);
ZEND_FUNCTION(posix_getgrgid);
ZEND_FUNCTION(posix_getpwnam);
ZEND_FUNCTION(posix_getpwuid);
#if defined(HAVE_GETRLIMIT)
ZEND_FUNCTION(posix_getrlimit);
#endif
#if defined(HAVE_SETRLIMIT)
ZEND_FUNCTION(posix_setrlimit);
#endif
ZEND_FUNCTION(posix_get_last_error);
ZEND_FUNCTION(posix_strerror);
#if defined(HAVE_INITGROUPS)
ZEND_FUNCTION(posix_initgroups);
#endif
ZEND_FUNCTION(posix_sysconf);
#if defined(HAVE_POSIX_PATHCONF)
ZEND_FUNCTION(posix_pathconf);
#endif
#if defined(HAVE_POSIX_PATHCONF)
ZEND_FUNCTION(posix_fpathconf);
#endif
static const zend_function_entry ext_functions[] = {
ZEND_FE(posix_kill, arginfo_posix_kill)
ZEND_FE(posix_getpid, arginfo_posix_getpid)
ZEND_FE(posix_getppid, arginfo_posix_getppid)
ZEND_FE(posix_getuid, arginfo_posix_getuid)
ZEND_FE(posix_setuid, arginfo_posix_setuid)
ZEND_FE(posix_geteuid, arginfo_posix_geteuid)
#if defined(HAVE_SETEUID)
ZEND_FE(posix_seteuid, arginfo_posix_seteuid)
#endif
ZEND_FE(posix_getgid, arginfo_posix_getgid)
ZEND_FE(posix_setgid, arginfo_posix_setgid)
ZEND_FE(posix_getegid, arginfo_posix_getegid)
#if defined(HAVE_SETEGID)
ZEND_FE(posix_setegid, arginfo_posix_setegid)
#endif
#if defined(HAVE_GETGROUPS)
ZEND_FE(posix_getgroups, arginfo_posix_getgroups)
#endif
#if defined(HAVE_GETLOGIN)
ZEND_FE(posix_getlogin, arginfo_posix_getlogin)
#endif
ZEND_FE(posix_getpgrp, arginfo_posix_getpgrp)
#if defined(HAVE_SETSID)
ZEND_FE(posix_setsid, arginfo_posix_setsid)
#endif
ZEND_FE(posix_setpgid, arginfo_posix_setpgid)
#if defined(HAVE_GETPGID)
ZEND_FE(posix_getpgid, arginfo_posix_getpgid)
#endif
#if defined(HAVE_GETSID)
ZEND_FE(posix_getsid, arginfo_posix_getsid)
#endif
ZEND_FE(posix_uname, arginfo_posix_uname)
ZEND_FE(posix_times, arginfo_posix_times)
#if defined(HAVE_CTERMID)
ZEND_FE(posix_ctermid, arginfo_posix_ctermid)
#endif
ZEND_FE(posix_ttyname, arginfo_posix_ttyname)
ZEND_FE(posix_isatty, arginfo_posix_isatty)
ZEND_FE(posix_getcwd, arginfo_posix_getcwd)
#if defined(HAVE_MKFIFO)
ZEND_FE(posix_mkfifo, arginfo_posix_mkfifo)
#endif
#if defined(HAVE_MKNOD)
ZEND_FE(posix_mknod, arginfo_posix_mknod)
#endif
ZEND_FE(posix_access, arginfo_posix_access)
#if defined(HAVE_EACCESS)
ZEND_FE(posix_eaccess, arginfo_posix_eaccess)
#endif
ZEND_FE(posix_getgrnam, arginfo_posix_getgrnam)
ZEND_FE(posix_getgrgid, arginfo_posix_getgrgid)
ZEND_FE(posix_getpwnam, arginfo_posix_getpwnam)
ZEND_FE(posix_getpwuid, arginfo_posix_getpwuid)
#if defined(HAVE_GETRLIMIT)
ZEND_FE(posix_getrlimit, arginfo_posix_getrlimit)
#endif
#if defined(HAVE_SETRLIMIT)
ZEND_FE(posix_setrlimit, arginfo_posix_setrlimit)
#endif
ZEND_FE(posix_get_last_error, arginfo_posix_get_last_error)
ZEND_FALIAS(posix_errno, posix_get_last_error, arginfo_posix_errno)
ZEND_FE(posix_strerror, arginfo_posix_strerror)
#if defined(HAVE_INITGROUPS)
ZEND_FE(posix_initgroups, arginfo_posix_initgroups)
#endif
ZEND_FE(posix_sysconf, arginfo_posix_sysconf)
#if defined(HAVE_POSIX_PATHCONF)
ZEND_FE(posix_pathconf, arginfo_posix_pathconf)
#endif
#if defined(HAVE_POSIX_PATHCONF)
ZEND_FE(posix_fpathconf, arginfo_posix_fpathconf)
#endif
ZEND_FE_END
};
static void register_posix_symbols(int module_number)
{
REGISTER_LONG_CONSTANT("POSIX_F_OK", F_OK, CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("POSIX_X_OK", X_OK, CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("POSIX_W_OK", W_OK, CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("POSIX_R_OK", R_OK, CONST_PERSISTENT);
#if defined(S_IFREG)
REGISTER_LONG_CONSTANT("POSIX_S_IFREG", S_IFREG, CONST_PERSISTENT);
#endif
#if defined(S_IFCHR)
REGISTER_LONG_CONSTANT("POSIX_S_IFCHR", S_IFCHR, CONST_PERSISTENT);
#endif
#if defined(S_IFBLK)
REGISTER_LONG_CONSTANT("POSIX_S_IFBLK", S_IFBLK, CONST_PERSISTENT);
#endif
#if defined(S_IFIFO)
REGISTER_LONG_CONSTANT("POSIX_S_IFIFO", S_IFIFO, CONST_PERSISTENT);
#endif
#if defined(S_IFSOCK)
REGISTER_LONG_CONSTANT("POSIX_S_IFSOCK", S_IFSOCK, CONST_PERSISTENT);
#endif
#if defined(RLIMIT_AS)
REGISTER_LONG_CONSTANT("POSIX_RLIMIT_AS", RLIMIT_AS, CONST_PERSISTENT);
#endif
#if defined(RLIMIT_CORE)
REGISTER_LONG_CONSTANT("POSIX_RLIMIT_CORE", RLIMIT_CORE, CONST_PERSISTENT);
#endif
#if defined(RLIMIT_CPU)
REGISTER_LONG_CONSTANT("POSIX_RLIMIT_CPU", RLIMIT_CPU, CONST_PERSISTENT);
#endif
#if defined(RLIMIT_DATA)
REGISTER_LONG_CONSTANT("POSIX_RLIMIT_DATA", RLIMIT_DATA, CONST_PERSISTENT);
#endif
#if defined(RLIMIT_FSIZE)
REGISTER_LONG_CONSTANT("POSIX_RLIMIT_FSIZE", RLIMIT_FSIZE, CONST_PERSISTENT);
#endif
#if defined(RLIMIT_LOCKS)
REGISTER_LONG_CONSTANT("POSIX_RLIMIT_LOCKS", RLIMIT_LOCKS, CONST_PERSISTENT);
#endif
#if defined(RLIMIT_MEMLOCK)
REGISTER_LONG_CONSTANT("POSIX_RLIMIT_MEMLOCK", RLIMIT_MEMLOCK, CONST_PERSISTENT);
#endif
#if defined(RLIMIT_MSGQUEUE)
REGISTER_LONG_CONSTANT("POSIX_RLIMIT_MSGQUEUE", RLIMIT_MSGQUEUE, CONST_PERSISTENT);
#endif
#if defined(RLIMIT_NICE)
REGISTER_LONG_CONSTANT("POSIX_RLIMIT_NICE", RLIMIT_NICE, CONST_PERSISTENT);
#endif
#if defined(RLIMIT_NOFILE)
REGISTER_LONG_CONSTANT("POSIX_RLIMIT_NOFILE", RLIMIT_NOFILE, CONST_PERSISTENT);
#endif
#if defined(RLIMIT_NPROC)
REGISTER_LONG_CONSTANT("POSIX_RLIMIT_NPROC", RLIMIT_NPROC, CONST_PERSISTENT);
#endif
#if defined(RLIMIT_RSS)
REGISTER_LONG_CONSTANT("POSIX_RLIMIT_RSS", RLIMIT_RSS, CONST_PERSISTENT);
#endif
#if defined(RLIMIT_RTPRIO)
REGISTER_LONG_CONSTANT("POSIX_RLIMIT_RTPRIO", RLIMIT_RTPRIO, CONST_PERSISTENT);
#endif
#if defined(RLIMIT_RTTIME)
REGISTER_LONG_CONSTANT("POSIX_RLIMIT_RTTIME", RLIMIT_RTTIME, CONST_PERSISTENT);
#endif
#if defined(RLIMIT_SIGPENDING)
REGISTER_LONG_CONSTANT("POSIX_RLIMIT_SIGPENDING", RLIMIT_SIGPENDING, CONST_PERSISTENT);
#endif
#if defined(RLIMIT_STACK)
REGISTER_LONG_CONSTANT("POSIX_RLIMIT_STACK", RLIMIT_STACK, CONST_PERSISTENT);
#endif
#if defined(RLIMIT_KQUEUES)
REGISTER_LONG_CONSTANT("POSIX_RLIMIT_KQUEUES", RLIMIT_KQUEUES, CONST_PERSISTENT);
#endif
#if defined(RLIMIT_NPTS)
REGISTER_LONG_CONSTANT("POSIX_RLIMIT_NPTS", RLIMIT_NPTS, CONST_PERSISTENT);
#endif
#if defined(HAVE_SETRLIMIT)
REGISTER_LONG_CONSTANT("POSIX_RLIMIT_INFINITY", RLIM_INFINITY, CONST_PERSISTENT);
#endif
#if defined(_SC_ARG_MAX)
REGISTER_LONG_CONSTANT("POSIX_SC_ARG_MAX", _SC_ARG_MAX, CONST_PERSISTENT);
#endif
#if defined(_SC_PAGESIZE)
REGISTER_LONG_CONSTANT("POSIX_SC_PAGESIZE", _SC_PAGESIZE, CONST_PERSISTENT);
#endif
#if defined(_SC_NPROCESSORS_CONF)
REGISTER_LONG_CONSTANT("POSIX_SC_NPROCESSORS_CONF", _SC_NPROCESSORS_CONF, CONST_PERSISTENT);
#endif
#if defined(_SC_NPROCESSORS_ONLN)
REGISTER_LONG_CONSTANT("POSIX_SC_NPROCESSORS_ONLN", _SC_NPROCESSORS_ONLN, CONST_PERSISTENT);
#endif
#if defined(_PC_LINK_MAX)
REGISTER_LONG_CONSTANT("POSIX_PC_LINK_MAX", _PC_LINK_MAX, CONST_PERSISTENT);
#endif
#if defined(_PC_MAX_CANON)
REGISTER_LONG_CONSTANT("POSIX_PC_MAX_CANON", _PC_MAX_CANON, CONST_PERSISTENT);
#endif
#if defined(_PC_MAX_INPUT)
REGISTER_LONG_CONSTANT("POSIX_PC_MAX_INPUT", _PC_MAX_INPUT, CONST_PERSISTENT);
#endif
#if defined(_PC_NAME_MAX)
REGISTER_LONG_CONSTANT("POSIX_PC_NAME_MAX", _PC_NAME_MAX, CONST_PERSISTENT);
#endif
#if defined(_PC_PATH_MAX)
REGISTER_LONG_CONSTANT("POSIX_PC_PATH_MAX", _PC_PATH_MAX, CONST_PERSISTENT);
#endif
#if defined(_PC_PIPE_BUF)
REGISTER_LONG_CONSTANT("POSIX_PC_PIPE_BUF", _PC_PIPE_BUF, CONST_PERSISTENT);
#endif
#if defined(_PC_CHOWN_RESTRICTED)
REGISTER_LONG_CONSTANT("POSIX_PC_CHOWN_RESTRICTED", _PC_CHOWN_RESTRICTED, CONST_PERSISTENT);
#endif
#if defined(_PC_NO_TRUNC)
REGISTER_LONG_CONSTANT("POSIX_PC_NO_TRUNC", _PC_NO_TRUNC, CONST_PERSISTENT);
#endif
#if defined(_PC_ALLOC_SIZE_MIN)
REGISTER_LONG_CONSTANT("POSIX_PC_ALLOC_SIZE_MIN", _PC_ALLOC_SIZE_MIN, CONST_PERSISTENT);
#endif
#if defined(_PC_SYMLINK_MAX)
REGISTER_LONG_CONSTANT("POSIX_PC_SYMLINK_MAX", _PC_SYMLINK_MAX, CONST_PERSISTENT);
#endif
}
| 15,380 | 32.364425 | 97 |
h
|
php-src
|
php-src-master/ext/pspell/php_pspell.h
|
/*
+----------------------------------------------------------------------+
| Copyright (c) The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| https://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| [email protected] so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Author: Vlad Krupin <[email protected]> |
+----------------------------------------------------------------------+
*/
#ifndef _PSPELL_H
#define _PSPELL_H
#ifdef HAVE_PSPELL
extern zend_module_entry pspell_module_entry;
#define pspell_module_ptr &pspell_module_entry
#include "php_version.h"
#define PHP_PSPELL_VERSION PHP_VERSION
#else
#define pspell_module_ptr NULL
#endif
#define phpext_pspell_ptr pspell_module_ptr
#endif /* _PSPELL_H */
| 1,322 | 39.090909 | 75 |
h
|
php-src
|
php-src-master/ext/pspell/pspell.c
|
/*
+----------------------------------------------------------------------+
| Copyright (c) The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| https://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| [email protected] so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Author: Vlad Krupin <[email protected]> |
+----------------------------------------------------------------------+
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "php.h"
#include <stdlib.h>
#include <ctype.h>
#include <stdio.h>
#ifdef HAVE_PSPELL
/* this will enforce compatibility in .12 version (broken after .11.2) */
#define USE_ORIGINAL_MANAGER_FUNCS
#include "php_pspell.h"
#include <pspell.h>
#include "ext/standard/info.h"
#define PSPELL_FAST 1L
#define PSPELL_NORMAL 2L
#define PSPELL_BAD_SPELLERS 3L
#define PSPELL_SPEED_MASK_INTERNAL 3L
#define PSPELL_RUN_TOGETHER 8L
#include "pspell_arginfo.h"
/* Largest ignored word can be 999 characters (this seems sane enough),
* and it takes 3 bytes to represent that (see pspell_config_ignore)
*/
#define PSPELL_LARGEST_WORD 3
static PHP_MINIT_FUNCTION(pspell);
static PHP_MINFO_FUNCTION(pspell);
static zend_class_entry *php_pspell_ce = NULL;
static zend_object_handlers php_pspell_handlers;
static zend_class_entry *php_pspell_config_ce = NULL;
static zend_object_handlers php_pspell_config_handlers;
zend_module_entry pspell_module_entry = {
STANDARD_MODULE_HEADER,
"pspell",
ext_functions,
PHP_MINIT(pspell),
NULL,
NULL,
NULL,
PHP_MINFO(pspell),
PHP_PSPELL_VERSION,
STANDARD_MODULE_PROPERTIES,
};
#ifdef COMPILE_DL_PSPELL
ZEND_GET_MODULE(pspell)
#endif
/* class PSpell */
typedef struct _php_pspell_object {
PspellManager *mgr;
zend_object std;
} php_pspell_object;
static php_pspell_object *php_pspell_object_from_zend_object(zend_object *zobj) {
return ((php_pspell_object*)(zobj + 1)) - 1;
}
static zend_object *php_pspell_object_to_zend_object(php_pspell_object *obj) {
return ((zend_object*)(obj + 1)) - 1;
}
static zend_function *php_pspell_object_get_constructor(zend_object *object)
{
zend_throw_error(NULL, "You cannot initialize a PSpell\\Dictionary object except through helper functions");
return NULL;
}
static zend_object *php_pspell_object_create(zend_class_entry *ce)
{
php_pspell_object *obj = zend_object_alloc(sizeof(php_pspell_object), ce);
zend_object *zobj = php_pspell_object_to_zend_object(obj);
obj->mgr = NULL;
zend_object_std_init(zobj, ce);
object_properties_init(zobj, ce);
zobj->handlers = &php_pspell_handlers;
return zobj;
}
static void php_pspell_object_free(zend_object *zobj) {
delete_pspell_manager(php_pspell_object_from_zend_object(zobj)->mgr);
}
/* class PSpellConfig */
typedef struct _php_pspell_config_object {
PspellConfig *cfg;
zend_object std;
} php_pspell_config_object;
static php_pspell_config_object *php_pspell_config_object_from_zend_object(zend_object *zobj) {
return ((php_pspell_config_object*)(zobj + 1)) - 1;
}
static zend_object *php_pspell_config_object_to_zend_object(php_pspell_config_object *obj) {
return ((zend_object*)(obj + 1)) - 1;
}
static zend_function *php_pspell_config_object_get_constructor(zend_object *object)
{
zend_throw_error(NULL, "You cannot initialize a PSpell\\Config object except through helper functions");
return NULL;
}
static zend_object *php_pspell_config_object_create(zend_class_entry *ce)
{
php_pspell_config_object *obj = zend_object_alloc(sizeof(php_pspell_config_object), ce);
zend_object *zobj = php_pspell_config_object_to_zend_object(obj);
obj->cfg = NULL;
zend_object_std_init(zobj, ce);
object_properties_init(zobj, ce);
zobj->handlers = &php_pspell_config_handlers;
return zobj;
}
static void php_pspell_config_object_free(zend_object *zobj) {
delete_pspell_config(php_pspell_config_object_from_zend_object(zobj)->cfg);
}
/* {{{ PHP_MINIT_FUNCTION */
static PHP_MINIT_FUNCTION(pspell)
{
php_pspell_ce = register_class_PSpell_Dictionary();
php_pspell_ce->create_object = php_pspell_object_create;
memcpy(&php_pspell_handlers, &std_object_handlers, sizeof(zend_object_handlers));
php_pspell_handlers.clone_obj = NULL;
php_pspell_handlers.free_obj = php_pspell_object_free;
php_pspell_handlers.get_constructor = php_pspell_object_get_constructor;
php_pspell_handlers.offset = XtOffsetOf(php_pspell_object, std);
php_pspell_config_ce = register_class_PSpell_Config();
php_pspell_config_ce->create_object = php_pspell_config_object_create;
memcpy(&php_pspell_config_handlers, &std_object_handlers, sizeof(zend_object_handlers));
php_pspell_config_handlers.clone_obj = NULL;
php_pspell_config_handlers.free_obj = php_pspell_config_object_free;
php_pspell_config_handlers.get_constructor = php_pspell_config_object_get_constructor;
php_pspell_config_handlers.offset = XtOffsetOf(php_pspell_config_object, std);
register_pspell_symbols(module_number);
return SUCCESS;
}
/* }}} */
/* {{{ Load a dictionary */
PHP_FUNCTION(pspell_new)
{
char *language, *spelling = NULL, *jargon = NULL, *encoding = NULL;
size_t language_len, spelling_len = 0, jargon_len = 0, encoding_len = 0;
zend_long mode = Z_L(0), speed = Z_L(0);
int argc = ZEND_NUM_ARGS();
#ifdef PHP_WIN32
TCHAR aspell_dir[200];
TCHAR data_dir[220];
TCHAR dict_dir[220];
HKEY hkey;
DWORD dwType,dwLen;
#endif
PspellCanHaveError *ret;
PspellConfig *config;
if (zend_parse_parameters(argc, "s|sssl", &language, &language_len, &spelling, &spelling_len,
&jargon, &jargon_len, &encoding, &encoding_len, &mode) == FAILURE) {
RETURN_THROWS();
}
config = new_pspell_config();
#ifdef PHP_WIN32
/* If aspell was installed using installer, we should have a key
* pointing to the location of the dictionaries
*/
if (0 == RegOpenKey(HKEY_LOCAL_MACHINE, "Software\\Aspell", &hkey)) {
LONG result;
dwLen = sizeof(aspell_dir) - 1;
result = RegQueryValueEx(hkey, "", NULL, &dwType, (LPBYTE)&aspell_dir, &dwLen);
RegCloseKey(hkey);
if (result == ERROR_SUCCESS) {
strlcpy(data_dir, aspell_dir, sizeof(data_dir));
strlcat(data_dir, "\\data", sizeof(data_dir));
strlcpy(dict_dir, aspell_dir, sizeof(dict_dir));
strlcat(dict_dir, "\\dict", sizeof(dict_dir));
pspell_config_replace(config, "data-dir", data_dir);
pspell_config_replace(config, "dict-dir", dict_dir);
}
}
#endif
pspell_config_replace(config, "language-tag", language);
if (spelling_len) {
pspell_config_replace(config, "spelling", spelling);
}
if (jargon_len) {
pspell_config_replace(config, "jargon", jargon);
}
if (encoding_len) {
pspell_config_replace(config, "encoding", encoding);
}
if (mode) {
speed = mode & PSPELL_SPEED_MASK_INTERNAL;
/* First check what mode we want (how many suggestions) */
if (speed == PSPELL_FAST) {
pspell_config_replace(config, "sug-mode", "fast");
} else if (speed == PSPELL_NORMAL) {
pspell_config_replace(config, "sug-mode", "normal");
} else if (speed == PSPELL_BAD_SPELLERS) {
pspell_config_replace(config, "sug-mode", "bad-spellers");
}
/* Then we see if run-together words should be treated as valid components */
if (mode & PSPELL_RUN_TOGETHER) {
pspell_config_replace(config, "run-together", "true");
}
}
ret = new_pspell_manager(config);
delete_pspell_config(config);
if (pspell_error_number(ret) != 0) {
php_error_docref(NULL, E_WARNING, "PSPELL couldn't open the dictionary. reason: %s", pspell_error_message(ret));
delete_pspell_can_have_error(ret);
RETURN_FALSE;
}
object_init_ex(return_value, php_pspell_ce);
php_pspell_object_from_zend_object(Z_OBJ_P(return_value))->mgr = to_pspell_manager(ret);
}
/* }}} */
/* {{{ Load a dictionary with a personal wordlist*/
PHP_FUNCTION(pspell_new_personal)
{
char *personal, *language, *spelling = NULL, *jargon = NULL, *encoding = NULL;
size_t personal_len, language_len, spelling_len = 0, jargon_len = 0, encoding_len = 0;
zend_long mode = Z_L(0), speed = Z_L(0);
int argc = ZEND_NUM_ARGS();
#ifdef PHP_WIN32
TCHAR aspell_dir[200];
TCHAR data_dir[220];
TCHAR dict_dir[220];
HKEY hkey;
DWORD dwType,dwLen;
#endif
PspellCanHaveError *ret;
PspellConfig *config;
if (zend_parse_parameters(argc, "ps|sssl", &personal, &personal_len, &language, &language_len,
&spelling, &spelling_len, &jargon, &jargon_len, &encoding, &encoding_len, &mode) == FAILURE) {
RETURN_THROWS();
}
config = new_pspell_config();
#ifdef PHP_WIN32
/* If aspell was installed using installer, we should have a key
* pointing to the location of the dictionaries
*/
if (0 == RegOpenKey(HKEY_LOCAL_MACHINE, "Software\\Aspell", &hkey)) {
LONG result;
dwLen = sizeof(aspell_dir) - 1;
result = RegQueryValueEx(hkey, "", NULL, &dwType, (LPBYTE)&aspell_dir, &dwLen);
RegCloseKey(hkey);
if (result == ERROR_SUCCESS) {
strlcpy(data_dir, aspell_dir, sizeof(data_dir));
strlcat(data_dir, "\\data", sizeof(data_dir));
strlcpy(dict_dir, aspell_dir, sizeof(dict_dir));
strlcat(dict_dir, "\\dict", sizeof(dict_dir));
pspell_config_replace(config, "data-dir", data_dir);
pspell_config_replace(config, "dict-dir", dict_dir);
}
}
#endif
if (php_check_open_basedir(personal)) {
delete_pspell_config(config);
RETURN_FALSE;
}
pspell_config_replace(config, "personal", personal);
pspell_config_replace(config, "save-repl", "false");
pspell_config_replace(config, "language-tag", language);
if (spelling_len) {
pspell_config_replace(config, "spelling", spelling);
}
if (jargon_len) {
pspell_config_replace(config, "jargon", jargon);
}
if (encoding_len) {
pspell_config_replace(config, "encoding", encoding);
}
if (mode) {
speed = mode & PSPELL_SPEED_MASK_INTERNAL;
/* First check what mode we want (how many suggestions) */
if (speed == PSPELL_FAST) {
pspell_config_replace(config, "sug-mode", "fast");
} else if (speed == PSPELL_NORMAL) {
pspell_config_replace(config, "sug-mode", "normal");
} else if (speed == PSPELL_BAD_SPELLERS) {
pspell_config_replace(config, "sug-mode", "bad-spellers");
}
/* Then we see if run-together words should be treated as valid components */
if (mode & PSPELL_RUN_TOGETHER) {
pspell_config_replace(config, "run-together", "true");
}
}
ret = new_pspell_manager(config);
delete_pspell_config(config);
if (pspell_error_number(ret) != 0) {
php_error_docref(NULL, E_WARNING, "PSPELL couldn't open the dictionary. reason: %s", pspell_error_message(ret));
delete_pspell_can_have_error(ret);
RETURN_FALSE;
}
object_init_ex(return_value, php_pspell_ce);
php_pspell_object_from_zend_object(Z_OBJ_P(return_value))->mgr = to_pspell_manager(ret);
}
/* }}} */
/* {{{ Load a dictionary based on the given config */
PHP_FUNCTION(pspell_new_config)
{
zval *zcfg;
PspellCanHaveError *ret;
PspellConfig *config;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "O", &zcfg, php_pspell_config_ce) == FAILURE) {
RETURN_THROWS();
}
config = php_pspell_config_object_from_zend_object(Z_OBJ_P(zcfg))->cfg;
ret = new_pspell_manager(config);
if (pspell_error_number(ret) != 0) {
php_error_docref(NULL, E_WARNING, "PSPELL couldn't open the dictionary. reason: %s", pspell_error_message(ret));
delete_pspell_can_have_error(ret);
RETURN_FALSE;
}
object_init_ex(return_value, php_pspell_ce);
php_pspell_object_from_zend_object(Z_OBJ_P(return_value))->mgr = to_pspell_manager(ret);
}
/* }}} */
/* {{{ Returns true if word is valid */
PHP_FUNCTION(pspell_check)
{
zval *zmgr;
zend_string *word;
PspellManager *manager;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "OS", &zmgr, php_pspell_ce, &word) == FAILURE) {
RETURN_THROWS();
}
manager = php_pspell_object_from_zend_object(Z_OBJ_P(zmgr))->mgr;
if (pspell_manager_check(manager, ZSTR_VAL(word))) {
RETURN_TRUE;
} else {
RETURN_FALSE;
}
}
/* }}} */
/* {{{ Returns array of suggestions */
PHP_FUNCTION(pspell_suggest)
{
zval *zmgr;
zend_string *word;
PspellManager *manager;
const PspellWordList *wl;
const char *sug;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "OS", &zmgr, php_pspell_ce, &word) == FAILURE) {
RETURN_THROWS();
}
manager = php_pspell_object_from_zend_object(Z_OBJ_P(zmgr))->mgr;
array_init(return_value);
wl = pspell_manager_suggest(manager, ZSTR_VAL(word));
if (wl) {
PspellStringEmulation *els = pspell_word_list_elements(wl);
while ((sug = pspell_string_emulation_next(els)) != 0) {
add_next_index_string(return_value,(char *)sug);
}
delete_pspell_string_emulation(els);
} else {
php_error_docref(NULL, E_WARNING, "PSPELL had a problem. details: %s", pspell_manager_error_message(manager));
RETURN_FALSE;
}
}
/* }}} */
/* {{{ Notify the dictionary of a user-selected replacement */
PHP_FUNCTION(pspell_store_replacement)
{
zval *zmgr;
zend_string *miss, *corr;
PspellManager *manager;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "OSS", &zmgr, php_pspell_ce, &miss, &corr) == FAILURE) {
RETURN_THROWS();
}
manager = php_pspell_object_from_zend_object(Z_OBJ_P(zmgr))->mgr;
pspell_manager_store_replacement(manager, ZSTR_VAL(miss), ZSTR_VAL(corr));
if (pspell_manager_error_number(manager) == 0) {
RETURN_TRUE;
} else {
php_error_docref(NULL, E_WARNING, "pspell_store_replacement() gave error: %s", pspell_manager_error_message(manager));
RETURN_FALSE;
}
}
/* }}} */
/* {{{ Adds a word to a personal list */
PHP_FUNCTION(pspell_add_to_personal)
{
zval *zmgr;
zend_string *word;
PspellManager *manager;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "OS", &zmgr, php_pspell_ce, &word) == FAILURE) {
RETURN_THROWS();
}
manager = php_pspell_object_from_zend_object(Z_OBJ_P(zmgr))->mgr;
/*If the word is empty, we have to return; otherwise we'll segfault! ouch!*/
if (ZSTR_LEN(word) == 0) {
RETURN_FALSE;
}
pspell_manager_add_to_personal(manager, ZSTR_VAL(word));
if (pspell_manager_error_number(manager) == 0) {
RETURN_TRUE;
} else {
php_error_docref(NULL, E_WARNING, "pspell_add_to_personal() gave error: %s", pspell_manager_error_message(manager));
RETURN_FALSE;
}
}
/* }}} */
/* {{{ Adds a word to the current session */
PHP_FUNCTION(pspell_add_to_session)
{
zval *zmgr;
zend_string *word;
PspellManager *manager;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "OS", &zmgr, php_pspell_ce, &word) == FAILURE) {
RETURN_THROWS();
}
manager = php_pspell_object_from_zend_object(Z_OBJ_P(zmgr))->mgr;
/*If the word is empty, we have to return; otherwise we'll segfault! ouch!*/
if (ZSTR_LEN(word) == 0) {
RETURN_FALSE;
}
pspell_manager_add_to_session(manager, ZSTR_VAL(word));
if (pspell_manager_error_number(manager) == 0) {
RETURN_TRUE;
} else {
php_error_docref(NULL, E_WARNING, "pspell_add_to_session() gave error: %s", pspell_manager_error_message(manager));
RETURN_FALSE;
}
}
/* }}} */
/* {{{ Clears the current session */
PHP_FUNCTION(pspell_clear_session)
{
zval *zmgr;
PspellManager *manager;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "O", &zmgr, php_pspell_ce) == FAILURE) {
RETURN_THROWS();
}
manager = php_pspell_object_from_zend_object(Z_OBJ_P(zmgr))->mgr;
pspell_manager_clear_session(manager);
if (pspell_manager_error_number(manager) == 0) {
RETURN_TRUE;
} else {
php_error_docref(NULL, E_WARNING, "pspell_clear_session() gave error: %s", pspell_manager_error_message(manager));
RETURN_FALSE;
}
}
/* }}} */
/* {{{ Saves the current (personal) wordlist */
PHP_FUNCTION(pspell_save_wordlist)
{
zval *zmgr;
PspellManager *manager;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "O", &zmgr, php_pspell_ce) == FAILURE) {
RETURN_THROWS();
}
manager = php_pspell_object_from_zend_object(Z_OBJ_P(zmgr))->mgr;
pspell_manager_save_all_word_lists(manager);
if (pspell_manager_error_number(manager) == 0) {
RETURN_TRUE;
} else {
php_error_docref(NULL, E_WARNING, "pspell_save_wordlist() gave error: %s", pspell_manager_error_message(manager));
RETURN_FALSE;
}
}
/* }}} */
/* {{{ Create a new config to be used later to create a manager */
PHP_FUNCTION(pspell_config_create)
{
char *language, *spelling = NULL, *jargon = NULL, *encoding = NULL;
size_t language_len, spelling_len = 0, jargon_len = 0, encoding_len = 0;
PspellConfig *config;
#ifdef PHP_WIN32
TCHAR aspell_dir[200];
TCHAR data_dir[220];
TCHAR dict_dir[220];
HKEY hkey;
DWORD dwType,dwLen;
#endif
if (zend_parse_parameters(ZEND_NUM_ARGS(), "s|sss", &language, &language_len, &spelling, &spelling_len,
&jargon, &jargon_len, &encoding, &encoding_len) == FAILURE) {
RETURN_THROWS();
}
config = new_pspell_config();
#ifdef PHP_WIN32
/* If aspell was installed using installer, we should have a key
* pointing to the location of the dictionaries
*/
if (0 == RegOpenKey(HKEY_LOCAL_MACHINE, "Software\\Aspell", &hkey)) {
LONG result;
dwLen = sizeof(aspell_dir) - 1;
result = RegQueryValueEx(hkey, "", NULL, &dwType, (LPBYTE)&aspell_dir, &dwLen);
RegCloseKey(hkey);
if (result == ERROR_SUCCESS) {
strlcpy(data_dir, aspell_dir, sizeof(data_dir));
strlcat(data_dir, "\\data", sizeof(data_dir));
strlcpy(dict_dir, aspell_dir, sizeof(dict_dir));
strlcat(dict_dir, "\\dict", sizeof(dict_dir));
pspell_config_replace(config, "data-dir", data_dir);
pspell_config_replace(config, "dict-dir", dict_dir);
}
}
#endif
pspell_config_replace(config, "language-tag", language);
if (spelling_len) {
pspell_config_replace(config, "spelling", spelling);
}
if (jargon_len) {
pspell_config_replace(config, "jargon", jargon);
}
if (encoding_len) {
pspell_config_replace(config, "encoding", encoding);
}
/* By default I do not want to write anything anywhere because it'll try to write to $HOME
which is not what we want */
pspell_config_replace(config, "save-repl", "false");
object_init_ex(return_value, php_pspell_config_ce);
php_pspell_config_object_from_zend_object(Z_OBJ_P(return_value))->cfg = config;
}
/* }}} */
/* {{{ Consider run-together words as valid components */
PHP_FUNCTION(pspell_config_runtogether)
{
zval *zcfg;
bool runtogether;
PspellConfig *config;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "Ob", &zcfg, php_pspell_config_ce, &runtogether) == FAILURE) {
RETURN_THROWS();
}
config = php_pspell_config_object_from_zend_object(Z_OBJ_P(zcfg))->cfg;
pspell_config_replace(config, "run-together", runtogether ? "true" : "false");
RETURN_TRUE;
}
/* }}} */
/* {{{ Select mode for config (PSPELL_FAST, PSPELL_NORMAL or PSPELL_BAD_SPELLERS) */
PHP_FUNCTION(pspell_config_mode)
{
zval *zcfg;
zend_long mode;
PspellConfig *config;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "Ol", &zcfg, php_pspell_config_ce, &mode) == FAILURE) {
RETURN_THROWS();
}
config = php_pspell_config_object_from_zend_object(Z_OBJ_P(zcfg))->cfg;
/* First check what mode we want (how many suggestions) */
if (mode == PSPELL_FAST) {
pspell_config_replace(config, "sug-mode", "fast");
} else if (mode == PSPELL_NORMAL) {
pspell_config_replace(config, "sug-mode", "normal");
} else if (mode == PSPELL_BAD_SPELLERS) {
pspell_config_replace(config, "sug-mode", "bad-spellers");
}
RETURN_TRUE;
}
/* }}} */
/* {{{ Ignore words <= n chars */
PHP_FUNCTION(pspell_config_ignore)
{
char ignore_str[MAX_LENGTH_OF_LONG + 1];
zval *zcfg;
zend_long ignore = 0L;
PspellConfig *config;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "Ol", &zcfg, php_pspell_config_ce, &ignore) == FAILURE) {
RETURN_THROWS();
}
config = php_pspell_config_object_from_zend_object(Z_OBJ_P(zcfg))->cfg;
snprintf(ignore_str, sizeof(ignore_str), ZEND_LONG_FMT, ignore);
pspell_config_replace(config, "ignore", ignore_str);
RETURN_TRUE;
}
/* }}} */
static void pspell_config_path(INTERNAL_FUNCTION_PARAMETERS, char *option)
{
zval *zcfg;
zend_string *value;
PspellConfig *config;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "OP", &zcfg, php_pspell_config_ce, &value) == FAILURE) {
RETURN_THROWS();
}
config = php_pspell_config_object_from_zend_object(Z_OBJ_P(zcfg))->cfg;
if (php_check_open_basedir(ZSTR_VAL(value))) {
RETURN_FALSE;
}
pspell_config_replace(config, option, ZSTR_VAL(value));
RETURN_TRUE;
}
/* {{{ Use a personal dictionary for this config */
PHP_FUNCTION(pspell_config_personal)
{
pspell_config_path(INTERNAL_FUNCTION_PARAM_PASSTHRU, "personal");
}
/* }}} */
/* {{{ location of the main word list */
PHP_FUNCTION(pspell_config_dict_dir)
{
pspell_config_path(INTERNAL_FUNCTION_PARAM_PASSTHRU, "dict-dir");
}
/* }}} */
/* {{{ location of language data files */
PHP_FUNCTION(pspell_config_data_dir)
{
pspell_config_path(INTERNAL_FUNCTION_PARAM_PASSTHRU, "data-dir");
}
/* }}} */
/* {{{ Use a personal dictionary with replacement pairs for this config */
PHP_FUNCTION(pspell_config_repl)
{
zval *zcfg;
zend_string *repl;
PspellConfig *config;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "OP", &zcfg, php_pspell_config_ce, &repl) == FAILURE) {
RETURN_THROWS();
}
config = php_pspell_config_object_from_zend_object(Z_OBJ_P(zcfg))->cfg;
pspell_config_replace(config, "save-repl", "true");
if (php_check_open_basedir(ZSTR_VAL(repl))) {
RETURN_FALSE;
}
pspell_config_replace(config, "repl", ZSTR_VAL(repl));
RETURN_TRUE;
}
/* }}} */
/* {{{ Save replacement pairs when personal list is saved for this config */
PHP_FUNCTION(pspell_config_save_repl)
{
zval *zcfg;
bool save;
PspellConfig *config;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "Ob", &zcfg, php_pspell_config_ce, &save) == FAILURE) {
RETURN_THROWS();
}
config = php_pspell_config_object_from_zend_object(Z_OBJ_P(zcfg))->cfg;
pspell_config_replace(config, "save-repl", save ? "true" : "false");
RETURN_TRUE;
}
/* }}} */
/* {{{ PHP_MINFO_FUNCTION */
static PHP_MINFO_FUNCTION(pspell)
{
php_info_print_table_start();
php_info_print_table_row(2, "PSpell Support", "enabled");
php_info_print_table_end();
}
/* }}} */
#endif
| 22,334 | 27.343909 | 120 |
c
|
php-src
|
php-src-master/ext/pspell/pspell_arginfo.h
|
/* This is a generated file, edit the .stub.php file instead.
* Stub hash: 8d35f61a0b48c5422b31e78f587d9258fd3e8e37 */
ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_pspell_new, 0, 1, PSpell\\Dictionary, MAY_BE_FALSE)
ZEND_ARG_TYPE_INFO(0, language, IS_STRING, 0)
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, spelling, IS_STRING, 0, "\"\"")
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, jargon, IS_STRING, 0, "\"\"")
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, encoding, IS_STRING, 0, "\"\"")
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, mode, IS_LONG, 0, "0")
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_pspell_new_personal, 0, 2, PSpell\\Dictionary, MAY_BE_FALSE)
ZEND_ARG_TYPE_INFO(0, filename, IS_STRING, 0)
ZEND_ARG_TYPE_INFO(0, language, IS_STRING, 0)
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, spelling, IS_STRING, 0, "\"\"")
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, jargon, IS_STRING, 0, "\"\"")
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, encoding, IS_STRING, 0, "\"\"")
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, mode, IS_LONG, 0, "0")
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_pspell_new_config, 0, 1, PSpell\\Dictionary, MAY_BE_FALSE)
ZEND_ARG_OBJ_INFO(0, config, PSpell\\Config, 0)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_pspell_check, 0, 2, _IS_BOOL, 0)
ZEND_ARG_OBJ_INFO(0, dictionary, PSpell\\Dictionary, 0)
ZEND_ARG_TYPE_INFO(0, word, IS_STRING, 0)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_pspell_suggest, 0, 2, MAY_BE_ARRAY|MAY_BE_FALSE)
ZEND_ARG_OBJ_INFO(0, dictionary, PSpell\\Dictionary, 0)
ZEND_ARG_TYPE_INFO(0, word, IS_STRING, 0)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_pspell_store_replacement, 0, 3, _IS_BOOL, 0)
ZEND_ARG_OBJ_INFO(0, dictionary, PSpell\\Dictionary, 0)
ZEND_ARG_TYPE_INFO(0, misspelled, IS_STRING, 0)
ZEND_ARG_TYPE_INFO(0, correct, IS_STRING, 0)
ZEND_END_ARG_INFO()
#define arginfo_pspell_add_to_personal arginfo_pspell_check
#define arginfo_pspell_add_to_session arginfo_pspell_check
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_pspell_clear_session, 0, 1, _IS_BOOL, 0)
ZEND_ARG_OBJ_INFO(0, dictionary, PSpell\\Dictionary, 0)
ZEND_END_ARG_INFO()
#define arginfo_pspell_save_wordlist arginfo_pspell_clear_session
ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_pspell_config_create, 0, 1, PSpell\\Config, 0)
ZEND_ARG_TYPE_INFO(0, language, IS_STRING, 0)
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, spelling, IS_STRING, 0, "\"\"")
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, jargon, IS_STRING, 0, "\"\"")
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, encoding, IS_STRING, 0, "\"\"")
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_pspell_config_runtogether, 0, 2, _IS_BOOL, 0)
ZEND_ARG_OBJ_INFO(0, config, PSpell\\Config, 0)
ZEND_ARG_TYPE_INFO(0, allow, _IS_BOOL, 0)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_pspell_config_mode, 0, 2, _IS_BOOL, 0)
ZEND_ARG_OBJ_INFO(0, config, PSpell\\Config, 0)
ZEND_ARG_TYPE_INFO(0, mode, IS_LONG, 0)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_pspell_config_ignore, 0, 2, _IS_BOOL, 0)
ZEND_ARG_OBJ_INFO(0, config, PSpell\\Config, 0)
ZEND_ARG_TYPE_INFO(0, min_length, IS_LONG, 0)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_pspell_config_personal, 0, 2, _IS_BOOL, 0)
ZEND_ARG_OBJ_INFO(0, config, PSpell\\Config, 0)
ZEND_ARG_TYPE_INFO(0, filename, IS_STRING, 0)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_pspell_config_dict_dir, 0, 2, _IS_BOOL, 0)
ZEND_ARG_OBJ_INFO(0, config, PSpell\\Config, 0)
ZEND_ARG_TYPE_INFO(0, directory, IS_STRING, 0)
ZEND_END_ARG_INFO()
#define arginfo_pspell_config_data_dir arginfo_pspell_config_dict_dir
#define arginfo_pspell_config_repl arginfo_pspell_config_personal
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_pspell_config_save_repl, 0, 2, _IS_BOOL, 0)
ZEND_ARG_OBJ_INFO(0, config, PSpell\\Config, 0)
ZEND_ARG_TYPE_INFO(0, save, _IS_BOOL, 0)
ZEND_END_ARG_INFO()
ZEND_FUNCTION(pspell_new);
ZEND_FUNCTION(pspell_new_personal);
ZEND_FUNCTION(pspell_new_config);
ZEND_FUNCTION(pspell_check);
ZEND_FUNCTION(pspell_suggest);
ZEND_FUNCTION(pspell_store_replacement);
ZEND_FUNCTION(pspell_add_to_personal);
ZEND_FUNCTION(pspell_add_to_session);
ZEND_FUNCTION(pspell_clear_session);
ZEND_FUNCTION(pspell_save_wordlist);
ZEND_FUNCTION(pspell_config_create);
ZEND_FUNCTION(pspell_config_runtogether);
ZEND_FUNCTION(pspell_config_mode);
ZEND_FUNCTION(pspell_config_ignore);
ZEND_FUNCTION(pspell_config_personal);
ZEND_FUNCTION(pspell_config_dict_dir);
ZEND_FUNCTION(pspell_config_data_dir);
ZEND_FUNCTION(pspell_config_repl);
ZEND_FUNCTION(pspell_config_save_repl);
static const zend_function_entry ext_functions[] = {
ZEND_FE(pspell_new, arginfo_pspell_new)
ZEND_FE(pspell_new_personal, arginfo_pspell_new_personal)
ZEND_FE(pspell_new_config, arginfo_pspell_new_config)
ZEND_FE(pspell_check, arginfo_pspell_check)
ZEND_FE(pspell_suggest, arginfo_pspell_suggest)
ZEND_FE(pspell_store_replacement, arginfo_pspell_store_replacement)
ZEND_FE(pspell_add_to_personal, arginfo_pspell_add_to_personal)
ZEND_FE(pspell_add_to_session, arginfo_pspell_add_to_session)
ZEND_FE(pspell_clear_session, arginfo_pspell_clear_session)
ZEND_FE(pspell_save_wordlist, arginfo_pspell_save_wordlist)
ZEND_FE(pspell_config_create, arginfo_pspell_config_create)
ZEND_FE(pspell_config_runtogether, arginfo_pspell_config_runtogether)
ZEND_FE(pspell_config_mode, arginfo_pspell_config_mode)
ZEND_FE(pspell_config_ignore, arginfo_pspell_config_ignore)
ZEND_FE(pspell_config_personal, arginfo_pspell_config_personal)
ZEND_FE(pspell_config_dict_dir, arginfo_pspell_config_dict_dir)
ZEND_FE(pspell_config_data_dir, arginfo_pspell_config_data_dir)
ZEND_FE(pspell_config_repl, arginfo_pspell_config_repl)
ZEND_FE(pspell_config_save_repl, arginfo_pspell_config_save_repl)
ZEND_FE_END
};
static const zend_function_entry class_PSpell_Dictionary_methods[] = {
ZEND_FE_END
};
static const zend_function_entry class_PSpell_Config_methods[] = {
ZEND_FE_END
};
static void register_pspell_symbols(int module_number)
{
REGISTER_LONG_CONSTANT("PSPELL_FAST", PSPELL_FAST, CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("PSPELL_NORMAL", PSPELL_NORMAL, CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("PSPELL_BAD_SPELLERS", PSPELL_BAD_SPELLERS, CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("PSPELL_RUN_TOGETHER", PSPELL_RUN_TOGETHER, CONST_PERSISTENT);
}
static zend_class_entry *register_class_PSpell_Dictionary(void)
{
zend_class_entry ce, *class_entry;
INIT_NS_CLASS_ENTRY(ce, "PSpell", "Dictionary", class_PSpell_Dictionary_methods);
class_entry = zend_register_internal_class_ex(&ce, NULL);
class_entry->ce_flags |= ZEND_ACC_FINAL|ZEND_ACC_NO_DYNAMIC_PROPERTIES|ZEND_ACC_NOT_SERIALIZABLE;
return class_entry;
}
static zend_class_entry *register_class_PSpell_Config(void)
{
zend_class_entry ce, *class_entry;
INIT_NS_CLASS_ENTRY(ce, "PSpell", "Config", class_PSpell_Config_methods);
class_entry = zend_register_internal_class_ex(&ce, NULL);
class_entry->ce_flags |= ZEND_ACC_FINAL|ZEND_ACC_NO_DYNAMIC_PROPERTIES|ZEND_ACC_NOT_SERIALIZABLE;
return class_entry;
}
| 7,246 | 40.176136 | 112 |
h
|
php-src
|
php-src-master/ext/random/engine_combinedlcg.c
|
/*
+----------------------------------------------------------------------+
| Copyright (c) The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| https://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| [email protected] so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Authors: Sascha Schumann <[email protected]> |
| Go Kudo <[email protected]> |
+----------------------------------------------------------------------+
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include "php.h"
#include "php_random.h"
#include "Zend/zend_exceptions.h"
/*
* combinedLCG() returns a pseudo random number in the range of (0, 1).
* The function combines two CGs with periods of
* 2^31 - 85 and 2^31 - 249. The period of this function
* is equal to the product of both primes.
*/
#define MODMULT(a, b, c, m, s) q = s / a; s = b * (s - a * q) - c * q; if (s < 0) s += m
static void seed(php_random_status *status, uint64_t seed)
{
php_random_status_state_combinedlcg *s = status->state;
s->state[0] = seed & 0xffffffffU;
s->state[1] = seed >> 32;
}
static uint64_t generate(php_random_status *status)
{
php_random_status_state_combinedlcg *s = status->state;
int32_t q, z;
MODMULT(53668, 40014, 12211, 2147483563L, s->state[0]);
MODMULT(52774, 40692, 3791, 2147483399L, s->state[1]);
z = s->state[0] - s->state[1];
if (z < 1) {
z += 2147483562;
}
return (uint64_t) z;
}
static zend_long range(php_random_status *status, zend_long min, zend_long max)
{
return php_random_range(&php_random_algo_combinedlcg, status, min, max);
}
static bool serialize(php_random_status *status, HashTable *data)
{
php_random_status_state_combinedlcg *s = status->state;
zval t;
for (uint32_t i = 0; i < 2; i++) {
ZVAL_STR(&t, php_random_bin2hex_le(&s->state[i], sizeof(uint32_t)));
zend_hash_next_index_insert(data, &t);
}
return true;
}
static bool unserialize(php_random_status *status, HashTable *data)
{
php_random_status_state_combinedlcg *s = status->state;
zval *t;
for (uint32_t i = 0; i < 2; i++) {
t = zend_hash_index_find(data, i);
if (!t || Z_TYPE_P(t) != IS_STRING || Z_STRLEN_P(t) != (2 * sizeof(uint32_t))) {
return false;
}
if (!php_random_hex2bin_le(Z_STR_P(t), &s->state[i])) {
return false;
}
}
return true;
}
const php_random_algo php_random_algo_combinedlcg = {
sizeof(uint32_t),
sizeof(php_random_status_state_combinedlcg),
seed,
generate,
range,
serialize,
unserialize
};
/* {{{ php_random_combinedlcg_seed_default */
PHPAPI void php_random_combinedlcg_seed_default(php_random_status_state_combinedlcg *state)
{
struct timeval tv;
if (gettimeofday(&tv, NULL) == 0) {
state->state[0] = tv.tv_usec ^ (tv.tv_usec << 11);
} else {
state->state[0] = 1;
}
#ifdef ZTS
state->state[1] = (zend_long) tsrm_thread_id();
#else
state->state[1] = (zend_long) getpid();
#endif
/* Add entropy to s2 by calling gettimeofday() again */
if (gettimeofday(&tv, NULL) == 0) {
state->state[1] ^= (tv.tv_usec << 11);
}
}
/* }}} */
| 3,640 | 27.445313 | 91 |
c
|
php-src
|
php-src-master/ext/random/engine_mt19937.c
|
/*
+----------------------------------------------------------------------+
| Copyright (c) The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| https://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| [email protected] so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Authors: Rasmus Lerdorf <[email protected]> |
| Zeev Suraski <[email protected]> |
| Pedro Melo <[email protected]> |
| Sterling Hughes <[email protected]> |
| Go Kudo <[email protected]> |
| |
| Based on code from: Richard J. Wagner <[email protected]> |
| Makoto Matsumoto <[email protected]> |
| Takuji Nishimura |
| Shawn Cokus <[email protected]> |
+----------------------------------------------------------------------+
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include "php.h"
#include "php_random.h"
#include "Zend/zend_exceptions.h"
/*
The following mt19937 algorithms are based on a C++ class MTRand by
Richard J. Wagner. For more information see the web page at
http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/VERSIONS/C-LANG/MersenneTwister.h
Mersenne Twister random number generator -- a C++ class MTRand
Based on code by Makoto Matsumoto, Takuji Nishimura, and Shawn Cokus
Richard J. Wagner v1.0 15 May 2003 [email protected]
The Mersenne Twister is an algorithm for generating random numbers. It
was designed with consideration of the flaws in various other generators.
The period, 2^19937-1, and the order of equidistribution, 623 dimensions,
are far greater. The generator is also fast; it avoids multiplication and
division, and it benefits from caches and pipelines. For more information
see the inventors' web page at http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/emt.html
Reference
M. Matsumoto and T. Nishimura, "Mersenne Twister: A 623-Dimensionally
Equidistributed Uniform Pseudo-Random Number Generator", ACM Transactions on
Modeling and Computer Simulation, Vol. 8, No. 1, January 1998, pp 3-30.
Copyright (C) 1997 - 2002, Makoto Matsumoto and Takuji Nishimura,
Copyright (C) 2000 - 2003, Richard J. Wagner
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. The names of its contributors may not be used to endorse or promote
products derived from this software without specific prior written
permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#define N MT_N /* length of state vector */
#define M (397) /* a period parameter */
#define hiBit(u) ((u) & 0x80000000U) /* mask all but highest bit of u */
#define loBit(u) ((u) & 0x00000001U) /* mask all but lowest bit of u */
#define loBits(u) ((u) & 0x7FFFFFFFU) /* mask the highest bit of u */
#define mixBits(u, v) (hiBit(u) | loBits(v)) /* move hi bit of u to hi bit of v */
#define twist(m,u,v) (m ^ (mixBits(u,v) >> 1) ^ ((uint32_t)(-(int32_t)(loBit(v))) & 0x9908b0dfU))
#define twist_php(m,u,v) (m ^ (mixBits(u,v) >> 1) ^ ((uint32_t)(-(int32_t)(loBit(u))) & 0x9908b0dfU))
static inline void mt19937_reload(php_random_status_state_mt19937 *state)
{
uint32_t *p = state->state;
if (state->mode == MT_RAND_MT19937) {
for (uint32_t i = N - M; i--; ++p) {
*p = twist(p[M], p[0], p[1]);
}
for (uint32_t i = M; --i; ++p) {
*p = twist(p[M-N], p[0], p[1]);
}
*p = twist(p[M-N], p[0], state->state[0]);
} else {
for (uint32_t i = N - M; i--; ++p) {
*p = twist_php(p[M], p[0], p[1]);
}
for (uint32_t i = M; --i; ++p) {
*p = twist_php(p[M-N], p[0], p[1]);
}
*p = twist_php(p[M-N], p[0], state->state[0]);
}
state->count = 0;
}
static inline void mt19937_seed_state(php_random_status_state_mt19937 *state, uint64_t seed)
{
uint32_t i, prev_state;
/* Initialize generator state with seed
See Knuth TAOCP Vol 2, 3rd Ed, p.106 for multiplier.
In previous versions, most significant bits (MSBs) of the seed affect
only MSBs of the state array. Modified 9 Jan 2002 by Makoto Matsumoto. */
state->state[0] = seed & 0xffffffffU;
for (i = 1; i < MT_N; i++) {
prev_state = state->state[i - 1];
state->state[i] = (1812433253U * (prev_state ^ (prev_state >> 30)) + i) & 0xffffffffU;
}
state->count = i;
mt19937_reload(state);
}
static void seed(php_random_status *status, uint64_t seed)
{
mt19937_seed_state(status->state, seed);
}
static uint64_t generate(php_random_status *status)
{
php_random_status_state_mt19937 *s = status->state;
uint32_t s1;
if (s->count >= MT_N) {
mt19937_reload(s);
}
s1 = s->state[s->count++];
s1 ^= (s1 >> 11);
s1 ^= (s1 << 7) & 0x9d2c5680U;
s1 ^= (s1 << 15) & 0xefc60000U;
return (uint64_t) (s1 ^ (s1 >> 18));
}
static zend_long range(php_random_status *status, zend_long min, zend_long max)
{
return php_random_range(&php_random_algo_mt19937, status, min, max);
}
static bool serialize(php_random_status *status, HashTable *data)
{
php_random_status_state_mt19937 *s = status->state;
zval t;
for (uint32_t i = 0; i < MT_N; i++) {
ZVAL_STR(&t, php_random_bin2hex_le(&s->state[i], sizeof(uint32_t)));
zend_hash_next_index_insert(data, &t);
}
ZVAL_LONG(&t, s->count);
zend_hash_next_index_insert(data, &t);
ZVAL_LONG(&t, s->mode);
zend_hash_next_index_insert(data, &t);
return true;
}
static bool unserialize(php_random_status *status, HashTable *data)
{
php_random_status_state_mt19937 *s = status->state;
zval *t;
/* Verify the expected number of elements, this implicitly ensures that no additional elements are present. */
if (zend_hash_num_elements(data) != (MT_N + 2)) {
return false;
}
for (uint32_t i = 0; i < MT_N; i++) {
t = zend_hash_index_find(data, i);
if (!t || Z_TYPE_P(t) != IS_STRING || Z_STRLEN_P(t) != (2 * sizeof(uint32_t))) {
return false;
}
if (!php_random_hex2bin_le(Z_STR_P(t), &s->state[i])) {
return false;
}
}
t = zend_hash_index_find(data, MT_N);
if (!t || Z_TYPE_P(t) != IS_LONG) {
return false;
}
s->count = Z_LVAL_P(t);
if (s->count > MT_N) {
return false;
}
t = zend_hash_index_find(data, MT_N + 1);
if (!t || Z_TYPE_P(t) != IS_LONG) {
return false;
}
s->mode = Z_LVAL_P(t);
if (s->mode != MT_RAND_MT19937 && s->mode != MT_RAND_PHP) {
return false;
}
return true;
}
const php_random_algo php_random_algo_mt19937 = {
sizeof(uint32_t),
sizeof(php_random_status_state_mt19937),
seed,
generate,
range,
serialize,
unserialize
};
/* {{{ php_random_mt19937_seed_default */
PHPAPI void php_random_mt19937_seed_default(php_random_status_state_mt19937 *state)
{
zend_long seed = 0;
if (php_random_bytes_silent(&seed, sizeof(zend_long)) == FAILURE) {
seed = GENERATE_SEED();
}
mt19937_seed_state(state, (uint64_t) seed);
}
/* }}} */
/* {{{ Random\Engine\Mt19937::__construct() */
PHP_METHOD(Random_Engine_Mt19937, __construct)
{
php_random_engine *engine = Z_RANDOM_ENGINE_P(ZEND_THIS);
php_random_status_state_mt19937 *state = engine->status->state;
zend_long seed, mode = MT_RAND_MT19937;
bool seed_is_null = true;
ZEND_PARSE_PARAMETERS_START(0, 2)
Z_PARAM_OPTIONAL;
Z_PARAM_LONG_OR_NULL(seed, seed_is_null);
Z_PARAM_LONG(mode);
ZEND_PARSE_PARAMETERS_END();
switch (mode) {
case MT_RAND_MT19937:
state->mode = MT_RAND_MT19937;
break;
case MT_RAND_PHP:
zend_error(E_DEPRECATED, "The MT_RAND_PHP variant of Mt19937 is deprecated");
state->mode = MT_RAND_PHP;
break;
default:
zend_argument_value_error(2, "must be either MT_RAND_MT19937 or MT_RAND_PHP");
RETURN_THROWS();
}
if (seed_is_null) {
/* MT19937 has a very large state, uses CSPRNG for seeding only */
if (php_random_bytes_throw(&seed, sizeof(zend_long)) == FAILURE) {
zend_throw_exception(random_ce_Random_RandomException, "Failed to generate a random seed", 0);
RETURN_THROWS();
}
}
engine->algo->seed(engine->status, seed);
}
/* }}} */
/* {{{ Random\Engine\Mt19937::generate() */
PHP_METHOD(Random_Engine_Mt19937, generate)
{
php_random_engine *engine = Z_RANDOM_ENGINE_P(ZEND_THIS);
uint64_t generated;
size_t size;
zend_string *bytes;
ZEND_PARSE_PARAMETERS_NONE();
generated = engine->algo->generate(engine->status);
size = engine->status->last_generated_size;
if (EG(exception)) {
RETURN_THROWS();
}
bytes = zend_string_alloc(size, false);
/* Endianness safe copy */
for (size_t i = 0; i < size; i++) {
ZSTR_VAL(bytes)[i] = (generated >> (i * 8)) & 0xff;
}
ZSTR_VAL(bytes)[size] = '\0';
RETURN_STR(bytes);
}
/* }}} */
/* {{{ Random\Engine\Mt19937::__serialize() */
PHP_METHOD(Random_Engine_Mt19937, __serialize)
{
php_random_engine *engine = Z_RANDOM_ENGINE_P(ZEND_THIS);
zval t;
ZEND_PARSE_PARAMETERS_NONE();
array_init(return_value);
/* members */
ZVAL_ARR(&t, zend_std_get_properties(&engine->std));
Z_TRY_ADDREF(t);
zend_hash_next_index_insert(Z_ARRVAL_P(return_value), &t);
/* state */
array_init(&t);
if (!engine->algo->serialize(engine->status, Z_ARRVAL(t))) {
zend_throw_exception(NULL, "Engine serialize failed", 0);
RETURN_THROWS();
}
zend_hash_next_index_insert(Z_ARRVAL_P(return_value), &t);
}
/* }}} */
/* {{{ Random\Engine\Mt19937::__unserialize() */
PHP_METHOD(Random_Engine_Mt19937, __unserialize)
{
php_random_engine *engine = Z_RANDOM_ENGINE_P(ZEND_THIS);
HashTable *d;
zval *t;
ZEND_PARSE_PARAMETERS_START(1, 1)
Z_PARAM_ARRAY_HT(d);
ZEND_PARSE_PARAMETERS_END();
/* Verify the expected number of elements, this implicitly ensures that no additional elements are present. */
if (zend_hash_num_elements(d) != 2) {
zend_throw_exception_ex(NULL, 0, "Invalid serialization data for %s object", ZSTR_VAL(engine->std.ce->name));
RETURN_THROWS();
}
/* members */
t = zend_hash_index_find(d, 0);
if (!t || Z_TYPE_P(t) != IS_ARRAY) {
zend_throw_exception_ex(NULL, 0, "Invalid serialization data for %s object", ZSTR_VAL(engine->std.ce->name));
RETURN_THROWS();
}
object_properties_load(&engine->std, Z_ARRVAL_P(t));
if (EG(exception)) {
zend_throw_exception_ex(NULL, 0, "Invalid serialization data for %s object", ZSTR_VAL(engine->std.ce->name));
RETURN_THROWS();
}
/* state */
t = zend_hash_index_find(d, 1);
if (!t || Z_TYPE_P(t) != IS_ARRAY) {
zend_throw_exception_ex(NULL, 0, "Invalid serialization data for %s object", ZSTR_VAL(engine->std.ce->name));
RETURN_THROWS();
}
if (!engine->algo->unserialize(engine->status, Z_ARRVAL_P(t))) {
zend_throw_exception_ex(NULL, 0, "Invalid serialization data for %s object", ZSTR_VAL(engine->std.ce->name));
RETURN_THROWS();
}
}
/* }}} */
/* {{{ Random\Engine\Mt19937::__debugInfo() */
PHP_METHOD(Random_Engine_Mt19937, __debugInfo)
{
php_random_engine *engine = Z_RANDOM_ENGINE_P(ZEND_THIS);
zval t;
ZEND_PARSE_PARAMETERS_NONE();
if (!engine->std.properties) {
rebuild_object_properties(&engine->std);
}
ZVAL_ARR(return_value, zend_array_dup(engine->std.properties));
if (engine->algo->serialize) {
array_init(&t);
if (!engine->algo->serialize(engine->status, Z_ARRVAL(t))) {
zend_throw_exception(NULL, "Engine serialize failed", 0);
RETURN_THROWS();
}
zend_hash_str_add(Z_ARR_P(return_value), "__states", strlen("__states"), &t);
}
}
/* }}} */
| 13,221 | 31.646914 | 111 |
c
|
php-src
|
php-src-master/ext/random/engine_pcgoneseq128xslrr64.c
|
/*
+----------------------------------------------------------------------+
| Copyright (c) The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| https://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| [email protected] so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Author: Go Kudo <[email protected]> |
| |
| Based on code from: Melissa O'Neill <[email protected]> |
+----------------------------------------------------------------------+
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include "php.h"
#include "php_random.h"
#include "Zend/zend_exceptions.h"
static inline void step(php_random_status_state_pcgoneseq128xslrr64 *s)
{
s->state = php_random_uint128_add(
php_random_uint128_multiply(s->state, php_random_uint128_constant(2549297995355413924ULL,4865540595714422341ULL)),
php_random_uint128_constant(6364136223846793005ULL,1442695040888963407ULL)
);
}
static inline void seed128(php_random_status *status, php_random_uint128_t seed)
{
php_random_status_state_pcgoneseq128xslrr64 *s = status->state;
s->state = php_random_uint128_constant(0ULL, 0ULL);
step(s);
s->state = php_random_uint128_add(s->state, seed);
step(s);
}
static void seed(php_random_status *status, uint64_t seed)
{
seed128(status, php_random_uint128_constant(0ULL, seed));
}
static uint64_t generate(php_random_status *status)
{
php_random_status_state_pcgoneseq128xslrr64 *s = status->state;
step(s);
return php_random_pcgoneseq128xslrr64_rotr64(s->state);
}
static zend_long range(php_random_status *status, zend_long min, zend_long max)
{
return php_random_range(&php_random_algo_pcgoneseq128xslrr64, status, min, max);
}
static bool serialize(php_random_status *status, HashTable *data)
{
php_random_status_state_pcgoneseq128xslrr64 *s = status->state;
uint64_t u;
zval z;
u = php_random_uint128_hi(s->state);
ZVAL_STR(&z, php_random_bin2hex_le(&u, sizeof(uint64_t)));
zend_hash_next_index_insert(data, &z);
u = php_random_uint128_lo(s->state);
ZVAL_STR(&z, php_random_bin2hex_le(&u, sizeof(uint64_t)));
zend_hash_next_index_insert(data, &z);
return true;
}
static bool unserialize(php_random_status *status, HashTable *data)
{
php_random_status_state_pcgoneseq128xslrr64 *s = status->state;
uint64_t u[2];
zval *t;
/* Verify the expected number of elements, this implicitly ensures that no additional elements are present. */
if (zend_hash_num_elements(data) != 2) {
return false;
}
for (uint32_t i = 0; i < 2; i++) {
t = zend_hash_index_find(data, i);
if (!t || Z_TYPE_P(t) != IS_STRING || Z_STRLEN_P(t) != (2 * sizeof(uint64_t))) {
return false;
}
if (!php_random_hex2bin_le(Z_STR_P(t), &u[i])) {
return false;
}
}
s->state = php_random_uint128_constant(u[0], u[1]);
return true;
}
const php_random_algo php_random_algo_pcgoneseq128xslrr64 = {
sizeof(uint64_t),
sizeof(php_random_status_state_pcgoneseq128xslrr64),
seed,
generate,
range,
serialize,
unserialize
};
/* {{{ php_random_pcgoneseq128xslrr64_advance */
PHPAPI void php_random_pcgoneseq128xslrr64_advance(php_random_status_state_pcgoneseq128xslrr64 *state, uint64_t advance)
{
php_random_uint128_t
cur_mult = php_random_uint128_constant(2549297995355413924ULL,4865540595714422341ULL),
cur_plus = php_random_uint128_constant(6364136223846793005ULL,1442695040888963407ULL),
acc_mult = php_random_uint128_constant(0ULL, 1ULL),
acc_plus = php_random_uint128_constant(0ULL, 0ULL);
while (advance > 0) {
if (advance & 1) {
acc_mult = php_random_uint128_multiply(acc_mult, cur_mult);
acc_plus = php_random_uint128_add(php_random_uint128_multiply(acc_plus, cur_mult), cur_plus);
}
cur_plus = php_random_uint128_multiply(php_random_uint128_add(cur_mult, php_random_uint128_constant(0ULL, 1ULL)), cur_plus);
cur_mult = php_random_uint128_multiply(cur_mult, cur_mult);
advance /= 2;
}
state->state = php_random_uint128_add(php_random_uint128_multiply(acc_mult, state->state), acc_plus);
}
/* }}} */
/* {{{ Random\Engine\PcgOneseq128XslRr64::__construct */
PHP_METHOD(Random_Engine_PcgOneseq128XslRr64, __construct)
{
php_random_engine *engine = Z_RANDOM_ENGINE_P(ZEND_THIS);
php_random_status_state_pcgoneseq128xslrr64 *state = engine->status->state;
zend_string *str_seed = NULL;
zend_long int_seed = 0;
bool seed_is_null = true;
uint32_t i, j;
uint64_t t[2];
ZEND_PARSE_PARAMETERS_START(0, 1)
Z_PARAM_OPTIONAL;
Z_PARAM_STR_OR_LONG_OR_NULL(str_seed, int_seed, seed_is_null);
ZEND_PARSE_PARAMETERS_END();
if (seed_is_null) {
if (php_random_bytes_throw(&state->state, sizeof(php_random_uint128_t)) == FAILURE) {
zend_throw_exception(random_ce_Random_RandomException, "Failed to generate a random seed", 0);
RETURN_THROWS();
}
} else {
if (str_seed) {
/* char (byte: 8 bit) * 16 = 128 bits */
if (ZSTR_LEN(str_seed) == 16) {
/* Endianness safe copy */
for (i = 0; i < 2; i++) {
t[i] = 0;
for (j = 0; j < 8; j++) {
t[i] += ((uint64_t) (unsigned char) ZSTR_VAL(str_seed)[(i * 8) + j]) << (j * 8);
}
}
seed128(engine->status, php_random_uint128_constant(t[0], t[1]));
} else {
zend_argument_value_error(1, "must be a 16 byte (128 bit) string");
RETURN_THROWS();
}
} else {
engine->algo->seed(engine->status, int_seed);
}
}
}
/* }}} */
/* {{{ Random\Engine\PcgOneseq128XslRr64::jump() */
PHP_METHOD(Random_Engine_PcgOneseq128XslRr64, jump)
{
php_random_engine *engine = Z_RANDOM_ENGINE_P(ZEND_THIS);
php_random_status_state_pcgoneseq128xslrr64 *state = engine->status->state;
zend_long advance = 0;
ZEND_PARSE_PARAMETERS_START(1, 1)
Z_PARAM_LONG(advance);
ZEND_PARSE_PARAMETERS_END();
if (UNEXPECTED(advance < 0)) {
zend_argument_value_error(1, "must be greater than or equal to 0");
RETURN_THROWS();
}
php_random_pcgoneseq128xslrr64_advance(state, advance);
}
/* }}} */
| 6,533 | 31.507463 | 126 |
c
|
php-src
|
php-src-master/ext/random/engine_secure.c
|
/*
+----------------------------------------------------------------------+
| Copyright (c) The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| https://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| [email protected] so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Authors: Sammy Kaye Powers <[email protected]> |
| Go Kudo <[email protected]> |
+----------------------------------------------------------------------+
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include "php.h"
#include "php_random.h"
#include "Zend/zend_exceptions.h"
static uint64_t generate(php_random_status *status)
{
zend_ulong r = 0;
php_random_bytes_throw(&r, sizeof(zend_ulong));
return r;
}
static zend_long range(php_random_status *status, zend_long min, zend_long max)
{
zend_long result = 0;
php_random_int_throw(min, max, &result);
return result;
}
const php_random_algo php_random_algo_secure = {
sizeof(zend_ulong),
0,
NULL,
generate,
range,
NULL,
NULL
};
| 1,620 | 29.018519 | 79 |
c
|
php-src
|
php-src-master/ext/random/engine_user.c
|
/*
+----------------------------------------------------------------------+
| Copyright (c) The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| https://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| [email protected] so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Author: Go Kudo <[email protected]> |
+----------------------------------------------------------------------+
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include "php.h"
#include "php_random.h"
static uint64_t generate(php_random_status *status)
{
php_random_status_state_user *s = status->state;
uint64_t result = 0;
size_t size;
zval retval;
zend_call_known_instance_method_with_0_params(s->generate_method, s->object, &retval);
if (EG(exception)) {
return 0;
}
/* Store generated size in a state */
size = Z_STRLEN(retval);
/* Guard for over 64-bit results */
if (size > sizeof(uint64_t)) {
size = sizeof(uint64_t);
}
status->last_generated_size = size;
if (size > 0) {
/* Endianness safe copy */
for (size_t i = 0; i < size; i++) {
result += ((uint64_t) (unsigned char) Z_STRVAL(retval)[i]) << (8 * i);
}
} else {
zend_throw_error(random_ce_Random_BrokenRandomEngineError, "A random engine must return a non-empty string");
return 0;
}
zval_ptr_dtor(&retval);
return result;
}
static zend_long range(php_random_status *status, zend_long min, zend_long max)
{
return php_random_range(&php_random_algo_user, status, min, max);
}
const php_random_algo php_random_algo_user = {
0,
sizeof(php_random_status_state_user),
NULL,
generate,
range,
NULL,
NULL,
};
| 2,202 | 28.373333 | 111 |
c
|
php-src
|
php-src-master/ext/random/engine_xoshiro256starstar.c
|
/*
+----------------------------------------------------------------------+
| Copyright (c) The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| https://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| [email protected] so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Author: Go Kudo <[email protected]> |
| |
| Based on code from: David Blackman |
| Sebastiano Vigna <[email protected]> |
+----------------------------------------------------------------------+
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include "php.h"
#include "php_random.h"
#include "Zend/zend_exceptions.h"
static inline uint64_t splitmix64(uint64_t *seed)
{
uint64_t r;
r = (*seed += 0x9e3779b97f4a7c15ULL);
r = (r ^ (r >> 30)) * 0xbf58476d1ce4e5b9ULL;
r = (r ^ (r >> 27)) * 0x94d049bb133111ebULL;
return (r ^ (r >> 31));
}
ZEND_ATTRIBUTE_CONST static inline uint64_t rotl(const uint64_t x, int k)
{
return (x << k) | (x >> (64 - k));
}
static inline uint64_t generate_state(php_random_status_state_xoshiro256starstar *s)
{
const uint64_t r = rotl(s->state[1] * 5, 7) * 9;
const uint64_t t = s->state[1] << 17;
s->state[2] ^= s->state[0];
s->state[3] ^= s->state[1];
s->state[1] ^= s->state[2];
s->state[0] ^= s->state[3];
s->state[2] ^= t;
s->state[3] = rotl(s->state[3], 45);
return r;
}
static inline void jump(php_random_status_state_xoshiro256starstar *state, const uint64_t *jmp)
{
uint64_t s0 = 0, s1 = 0, s2 = 0, s3 = 0;
for (uint32_t i = 0; i < 4; i++) {
for (uint32_t j = 0; j < 64; j++) {
if (jmp[i] & 1ULL << j) {
s0 ^= state->state[0];
s1 ^= state->state[1];
s2 ^= state->state[2];
s3 ^= state->state[3];
}
generate_state(state);
}
}
state->state[0] = s0;
state->state[1] = s1;
state->state[2] = s2;
state->state[3] = s3;
}
static inline void seed256(php_random_status *status, uint64_t s0, uint64_t s1, uint64_t s2, uint64_t s3)
{
php_random_status_state_xoshiro256starstar *s = status->state;
s->state[0] = s0;
s->state[1] = s1;
s->state[2] = s2;
s->state[3] = s3;
}
static void seed(php_random_status *status, uint64_t seed)
{
uint64_t s[4];
s[0] = splitmix64(&seed);
s[1] = splitmix64(&seed);
s[2] = splitmix64(&seed);
s[3] = splitmix64(&seed);
seed256(status, s[0], s[1], s[2], s[3]);
}
static uint64_t generate(php_random_status *status)
{
return generate_state(status->state);
}
static zend_long range(php_random_status *status, zend_long min, zend_long max)
{
return php_random_range(&php_random_algo_xoshiro256starstar, status, min, max);
}
static bool serialize(php_random_status *status, HashTable *data)
{
php_random_status_state_xoshiro256starstar *s = status->state;
zval t;
for (uint32_t i = 0; i < 4; i++) {
ZVAL_STR(&t, php_random_bin2hex_le(&s->state[i], sizeof(uint64_t)));
zend_hash_next_index_insert(data, &t);
}
return true;
}
static bool unserialize(php_random_status *status, HashTable *data)
{
php_random_status_state_xoshiro256starstar *s = status->state;
zval *t;
/* Verify the expected number of elements, this implicitly ensures that no additional elements are present. */
if (zend_hash_num_elements(data) != 4) {
return false;
}
for (uint32_t i = 0; i < 4; i++) {
t = zend_hash_index_find(data, i);
if (!t || Z_TYPE_P(t) != IS_STRING || Z_STRLEN_P(t) != (2 * sizeof(uint64_t))) {
return false;
}
if (!php_random_hex2bin_le(Z_STR_P(t), &s->state[i])) {
return false;
}
}
return true;
}
const php_random_algo php_random_algo_xoshiro256starstar = {
sizeof(uint64_t),
sizeof(php_random_status_state_xoshiro256starstar),
seed,
generate,
range,
serialize,
unserialize
};
PHPAPI void php_random_xoshiro256starstar_jump(php_random_status_state_xoshiro256starstar *state)
{
static const uint64_t jmp[] = {0x180ec6d33cfd0aba, 0xd5a61266f0c9392c, 0xa9582618e03fc9aa, 0x39abdc4529b1661c};
jump(state, jmp);
}
PHPAPI void php_random_xoshiro256starstar_jump_long(php_random_status_state_xoshiro256starstar *state)
{
static const uint64_t jmp[] = {0x76e15d3efefdcbbf, 0xc5004e441c522fb3, 0x77710069854ee241, 0x39109bb02acbe635};
jump(state, jmp);
}
/* {{{ Random\Engine\Xoshiro256StarStar::jump() */
PHP_METHOD(Random_Engine_Xoshiro256StarStar, jump)
{
php_random_engine *engine = Z_RANDOM_ENGINE_P(ZEND_THIS);
php_random_status_state_xoshiro256starstar *state = engine->status->state;
ZEND_PARSE_PARAMETERS_NONE();
php_random_xoshiro256starstar_jump(state);
}
/* }}} */
/* {{{ Random\Engine\Xoshiro256StarStar::jumpLong() */
PHP_METHOD(Random_Engine_Xoshiro256StarStar, jumpLong)
{
php_random_engine *engine = Z_RANDOM_ENGINE_P(ZEND_THIS);
php_random_status_state_xoshiro256starstar *state = engine->status->state;
ZEND_PARSE_PARAMETERS_NONE();
php_random_xoshiro256starstar_jump_long(state);
}
/* }}} */
/* {{{ Random\Engine\Xoshiro256StarStar::__construct */
PHP_METHOD(Random_Engine_Xoshiro256StarStar, __construct)
{
php_random_engine *engine = Z_RANDOM_ENGINE_P(ZEND_THIS);
php_random_status_state_xoshiro256starstar *state = engine->status->state;
zend_string *str_seed = NULL;
zend_long int_seed = 0;
bool seed_is_null = true;
ZEND_PARSE_PARAMETERS_START(0, 1)
Z_PARAM_OPTIONAL;
Z_PARAM_STR_OR_LONG_OR_NULL(str_seed, int_seed, seed_is_null);
ZEND_PARSE_PARAMETERS_END();
if (seed_is_null) {
do {
if (php_random_bytes_throw(&state->state, 32) == FAILURE) {
zend_throw_exception(random_ce_Random_RandomException, "Failed to generate a random seed", 0);
RETURN_THROWS();
}
} while (UNEXPECTED(state->state[0] == 0 && state->state[1] == 0 && state->state[2] == 0 && state->state[3] == 0));
} else {
if (str_seed) {
/* char (byte: 8 bit) * 32 = 256 bits */
if (ZSTR_LEN(str_seed) == 32) {
uint64_t t[4];
/* Endianness safe copy */
for (uint32_t i = 0; i < 4; i++) {
t[i] = 0;
for (uint32_t j = 0; j < 8; j++) {
t[i] += ((uint64_t) (unsigned char) ZSTR_VAL(str_seed)[(i * 8) + j]) << (j * 8);
}
}
if (UNEXPECTED(t[0] == 0 && t[1] == 0 && t[2] == 0 && t[3] == 0)) {
zend_argument_value_error(1, "must not consist entirely of NUL bytes");
RETURN_THROWS();
}
seed256(engine->status, t[0], t[1], t[2], t[3]);
} else {
zend_argument_value_error(1, "must be a 32 byte (256 bit) string");
RETURN_THROWS();
}
} else {
engine->algo->seed(engine->status, (uint64_t) int_seed);
}
}
}
/* }}} */
| 7,135 | 27.658635 | 117 |
c
|
php-src
|
php-src-master/ext/random/gammasection.c
|
/*
+----------------------------------------------------------------------+
| Copyright (c) The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| https://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| [email protected] so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Authors: Tim Düsterhus <[email protected]> |
| |
| Based on code from: Frédéric Goualard |
+----------------------------------------------------------------------+
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include "php.h"
#include "php_random.h"
#include <math.h>
/* This file implements the γ-section algorithm as published in:
*
* Drawing Random Floating-Point Numbers from an Interval. Frédéric
* Goualard, ACM Trans. Model. Comput. Simul., 32:3, 2022.
* https://doi.org/10.1145/3503512
*/
static double gamma_low(double x)
{
return x - nextafter(x, -DBL_MAX);
}
static double gamma_high(double x)
{
return nextafter(x, DBL_MAX) - x;
}
static double gamma_max(double x, double y)
{
return (fabs(x) > fabs(y)) ? gamma_high(x) : gamma_low(y);
}
static uint64_t ceilint(double a, double b, double g)
{
double s = b / g - a / g;
double e;
if (fabs(a) <= fabs(b)) {
e = -a / g - (s - b / g);
} else {
e = b / g - (s + a / g);
}
double si = ceil(s);
return (s != si) ? (uint64_t)si : (uint64_t)si + (e > 0);
}
PHPAPI double php_random_gammasection_closed_open(const php_random_algo *algo, php_random_status *status, double min, double max)
{
double g = gamma_max(min, max);
uint64_t hi = ceilint(min, max, g);
if (UNEXPECTED(max <= min || hi < 1)) {
return NAN;
}
uint64_t k = 1 + php_random_range64(algo, status, hi - 1); /* [1, hi] */
if (fabs(min) <= fabs(max)) {
return k == hi ? min : max - k * g;
} else {
return min + (k - 1) * g;
}
}
PHPAPI double php_random_gammasection_closed_closed(const php_random_algo *algo, php_random_status *status, double min, double max)
{
double g = gamma_max(min, max);
uint64_t hi = ceilint(min, max, g);
if (UNEXPECTED(max < min)) {
return NAN;
}
uint64_t k = php_random_range64(algo, status, hi); /* [0, hi] */
if (fabs(min) <= fabs(max)) {
return k == hi ? min : max - k * g;
} else {
return k == hi ? max : min + k * g;
}
}
PHPAPI double php_random_gammasection_open_closed(const php_random_algo *algo, php_random_status *status, double min, double max)
{
double g = gamma_max(min, max);
uint64_t hi = ceilint(min, max, g);
if (UNEXPECTED(max <= min || hi < 1)) {
return NAN;
}
uint64_t k = php_random_range64(algo, status, hi - 1); /* [0, hi - 1] */
if (fabs(min) <= fabs(max)) {
return max - k * g;
} else {
return k == (hi - 1) ? max : min + (k + 1) * g;
}
}
PHPAPI double php_random_gammasection_open_open(const php_random_algo *algo, php_random_status *status, double min, double max)
{
double g = gamma_max(min, max);
uint64_t hi = ceilint(min, max, g);
if (UNEXPECTED(max <= min || hi < 2)) {
return NAN;
}
uint64_t k = 1 + php_random_range64(algo, status, hi - 2); /* [1, hi - 1] */
if (fabs(min) <= fabs(max)) {
return max - k * g;
} else {
return min + k * g;
}
}
| 3,805 | 26.985294 | 131 |
c
|
php-src
|
php-src-master/ext/readline/php_readline.h
|
/*
+----------------------------------------------------------------------+
| Copyright (c) The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| https://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| [email protected] so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Author: Thies C. Arntzen <[email protected]> |
+----------------------------------------------------------------------+
*/
#ifndef PHP_READLINE_H
#define PHP_READLINE_H
#if HAVE_LIBEDIT
#define READLINE_LIB "libedit"
#else
#define READLINE_LIB "readline"
#endif
#if HAVE_LIBREADLINE || HAVE_LIBEDIT
extern zend_module_entry readline_module_entry;
#define phpext_readline_ptr &readline_module_entry
#include "php_version.h"
#define PHP_READLINE_VERSION PHP_VERSION
#else
#define phpext_readline_ptr NULL
#endif /* HAVE_LIBREADLINE */
#endif /* PHP_READLINE_H */
| 1,441 | 34.170732 | 75 |
h
|
php-src
|
php-src-master/ext/readline/readline.c
|
/*
+----------------------------------------------------------------------+
| Copyright (c) The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| https://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| [email protected] so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Author: Thies C. Arntzen <[email protected]> |
+----------------------------------------------------------------------+
*/
/* {{{ includes & prototypes */
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "php.h"
#include "php_readline.h"
#include "readline_cli.h"
#include "readline_arginfo.h"
#if HAVE_LIBREADLINE || HAVE_LIBEDIT
#ifndef HAVE_RL_COMPLETION_MATCHES
#define rl_completion_matches completion_matches
#endif
#ifdef HAVE_LIBEDIT
#include <editline/readline.h>
#else
#include <readline/readline.h>
#include <readline/history.h>
#endif
#if HAVE_RL_CALLBACK_READ_CHAR
static zval _prepped_callback;
#endif
static zval _readline_completion;
static zval _readline_array;
PHP_MINIT_FUNCTION(readline);
PHP_MSHUTDOWN_FUNCTION(readline);
PHP_RSHUTDOWN_FUNCTION(readline);
PHP_MINFO_FUNCTION(readline);
/* }}} */
/* {{{ module stuff */
zend_module_entry readline_module_entry = {
STANDARD_MODULE_HEADER,
"readline",
ext_functions,
PHP_MINIT(readline),
PHP_MSHUTDOWN(readline),
NULL,
PHP_RSHUTDOWN(readline),
PHP_MINFO(readline),
PHP_READLINE_VERSION,
STANDARD_MODULE_PROPERTIES
};
#ifdef COMPILE_DL_READLINE
ZEND_GET_MODULE(readline)
#endif
PHP_MINIT_FUNCTION(readline)
{
#if HAVE_LIBREADLINE
/* libedit don't need this call which set the tty in cooked mode */
using_history();
#endif
ZVAL_UNDEF(&_readline_completion);
#if HAVE_RL_CALLBACK_READ_CHAR
ZVAL_UNDEF(&_prepped_callback);
#endif
register_readline_symbols(module_number);
return PHP_MINIT(cli_readline)(INIT_FUNC_ARGS_PASSTHRU);
}
PHP_MSHUTDOWN_FUNCTION(readline)
{
return PHP_MSHUTDOWN(cli_readline)(SHUTDOWN_FUNC_ARGS_PASSTHRU);
}
PHP_RSHUTDOWN_FUNCTION(readline)
{
zval_ptr_dtor(&_readline_completion);
ZVAL_UNDEF(&_readline_completion);
#if HAVE_RL_CALLBACK_READ_CHAR
if (Z_TYPE(_prepped_callback) != IS_UNDEF) {
rl_callback_handler_remove();
zval_ptr_dtor(&_prepped_callback);
ZVAL_UNDEF(&_prepped_callback);
}
#endif
return SUCCESS;
}
PHP_MINFO_FUNCTION(readline)
{
PHP_MINFO(cli_readline)(ZEND_MODULE_INFO_FUNC_ARGS_PASSTHRU);
}
/* }}} */
/* {{{ Reads a line */
PHP_FUNCTION(readline)
{
char *prompt = NULL;
size_t prompt_len;
char *result;
if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS(), "|s!", &prompt, &prompt_len)) {
RETURN_THROWS();
}
result = readline(prompt);
if (! result) {
RETURN_FALSE;
} else {
RETVAL_STRING(result);
free(result);
}
}
/* }}} */
#define SAFE_STRING(s) ((s)?(char*)(s):"")
/* {{{ Gets/sets various internal readline variables. */
PHP_FUNCTION(readline_info)
{
zend_string *what = NULL;
zval *value = NULL;
size_t oldval;
char *oldstr;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "|S!z!", &what, &value) == FAILURE) {
RETURN_THROWS();
}
if (!what) {
array_init(return_value);
add_assoc_string(return_value,"line_buffer",SAFE_STRING(rl_line_buffer));
add_assoc_long(return_value,"point",rl_point);
#ifndef PHP_WIN32
add_assoc_long(return_value,"end",rl_end);
#endif
#ifdef HAVE_LIBREADLINE
add_assoc_long(return_value,"mark",rl_mark);
add_assoc_long(return_value,"done",rl_done);
add_assoc_long(return_value,"pending_input",rl_pending_input);
add_assoc_string(return_value,"prompt",SAFE_STRING(rl_prompt));
add_assoc_string(return_value,"terminal_name",(char *)SAFE_STRING(rl_terminal_name));
add_assoc_str(return_value, "completion_append_character",
rl_completion_append_character == 0
? ZSTR_EMPTY_ALLOC()
: ZSTR_CHAR(rl_completion_append_character));
add_assoc_bool(return_value,"completion_suppress_append",rl_completion_suppress_append);
#endif
#if HAVE_ERASE_EMPTY_LINE
add_assoc_long(return_value,"erase_empty_line",rl_erase_empty_line);
#endif
#ifndef PHP_WIN32
add_assoc_string(return_value,"library_version",(char *)SAFE_STRING(rl_library_version));
#endif
add_assoc_string(return_value,"readline_name",(char *)SAFE_STRING(rl_readline_name));
add_assoc_long(return_value,"attempted_completion_over",rl_attempted_completion_over);
} else {
if (zend_string_equals_literal_ci(what,"line_buffer")) {
oldstr = rl_line_buffer;
if (value) {
/* XXX if (rl_line_buffer) free(rl_line_buffer); */
if (!try_convert_to_string(value)) {
RETURN_THROWS();
}
rl_line_buffer = strdup(Z_STRVAL_P(value));
}
RETVAL_STRING(SAFE_STRING(oldstr));
} else if (zend_string_equals_literal_ci(what, "point")) {
RETVAL_LONG(rl_point);
#ifndef PHP_WIN32
} else if (zend_string_equals_literal_ci(what, "end")) {
RETVAL_LONG(rl_end);
#endif
#ifdef HAVE_LIBREADLINE
} else if (zend_string_equals_literal_ci(what, "mark")) {
RETVAL_LONG(rl_mark);
} else if (zend_string_equals_literal_ci(what, "done")) {
oldval = rl_done;
if (value) {
rl_done = zval_get_long(value);
}
RETVAL_LONG(oldval);
} else if (zend_string_equals_literal_ci(what, "pending_input")) {
oldval = rl_pending_input;
if (value) {
if (!try_convert_to_string(value)) {
RETURN_THROWS();
}
rl_pending_input = Z_STRVAL_P(value)[0];
}
RETVAL_LONG(oldval);
} else if (zend_string_equals_literal_ci(what, "prompt")) {
RETVAL_STRING(SAFE_STRING(rl_prompt));
} else if (zend_string_equals_literal_ci(what, "terminal_name")) {
RETVAL_STRING((char *)SAFE_STRING(rl_terminal_name));
} else if (zend_string_equals_literal_ci(what, "completion_suppress_append")) {
oldval = rl_completion_suppress_append;
if (value) {
rl_completion_suppress_append = zend_is_true(value);
}
RETVAL_BOOL(oldval);
} else if (zend_string_equals_literal_ci(what, "completion_append_character")) {
oldval = rl_completion_append_character;
if (value) {
if (!try_convert_to_string(value)) {
RETURN_THROWS();
}
rl_completion_append_character = (int)Z_STRVAL_P(value)[0];
}
RETVAL_INTERNED_STR(
oldval == 0 ? ZSTR_EMPTY_ALLOC() : ZSTR_CHAR(oldval));
#endif
#if HAVE_ERASE_EMPTY_LINE
} else if (zend_string_equals_literal_ci(what, "erase_empty_line")) {
oldval = rl_erase_empty_line;
if (value) {
rl_erase_empty_line = zval_get_long(value);
}
RETVAL_LONG(oldval);
#endif
#ifndef PHP_WIN32
} else if (zend_string_equals_literal_ci(what,"library_version")) {
RETVAL_STRING((char *)SAFE_STRING(rl_library_version));
#endif
} else if (zend_string_equals_literal_ci(what, "readline_name")) {
oldstr = (char*)rl_readline_name;
if (value) {
/* XXX if (rl_readline_name) free(rl_readline_name); */
if (!try_convert_to_string(value)) {
RETURN_THROWS();
}
rl_readline_name = strdup(Z_STRVAL_P(value));
}
RETVAL_STRING(SAFE_STRING(oldstr));
} else if (zend_string_equals_literal_ci(what, "attempted_completion_over")) {
oldval = rl_attempted_completion_over;
if (value) {
rl_attempted_completion_over = zval_get_long(value);
}
RETVAL_LONG(oldval);
}
}
}
/* }}} */
/* {{{ Adds a line to the history */
PHP_FUNCTION(readline_add_history)
{
char *arg;
size_t arg_len;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &arg, &arg_len) == FAILURE) {
RETURN_THROWS();
}
add_history(arg);
RETURN_TRUE;
}
/* }}} */
/* {{{ Clears the history */
PHP_FUNCTION(readline_clear_history)
{
if (zend_parse_parameters_none() == FAILURE) {
RETURN_THROWS();
}
#if HAVE_LIBEDIT
/* clear_history is the only function where rl_initialize
is not call to ensure correct allocation */
using_history();
#endif
clear_history();
RETURN_TRUE;
}
/* }}} */
#ifdef HAVE_HISTORY_LIST
/* {{{ Lists the history */
PHP_FUNCTION(readline_list_history)
{
HIST_ENTRY **history;
if (zend_parse_parameters_none() == FAILURE) {
RETURN_THROWS();
}
array_init(return_value);
#if defined(HAVE_LIBEDIT) && defined(PHP_WIN32) /* Winedit on Windows */
history = history_list();
if (history) {
int i, n = history_length();
for (i = 0; i < n; i++) {
add_next_index_string(return_value, history[i]->line);
}
}
#elif defined(HAVE_LIBEDIT) /* libedit */
{
HISTORY_STATE *hs;
int i;
using_history();
hs = history_get_history_state();
if (hs && hs->length) {
history = history_list();
if (history) {
for (i = 0; i < hs->length; i++) {
add_next_index_string(return_value, history[i]->line);
}
}
}
free(hs);
}
#else /* readline */
history = history_list();
if (history) {
int i;
for (i = 0; history[i]; i++) {
add_next_index_string(return_value, history[i]->line);
}
}
#endif
}
/* }}} */
#endif
/* {{{ Reads the history */
PHP_FUNCTION(readline_read_history)
{
char *arg = NULL;
size_t arg_len;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "|p!", &arg, &arg_len) == FAILURE) {
RETURN_THROWS();
}
if (arg && php_check_open_basedir(arg)) {
RETURN_FALSE;
}
/* XXX from & to NYI */
if (read_history(arg)) {
/* If filename is NULL, then read from `~/.history' */
RETURN_FALSE;
} else {
RETURN_TRUE;
}
}
/* }}} */
/* {{{ Writes the history */
PHP_FUNCTION(readline_write_history)
{
char *arg = NULL;
size_t arg_len;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "|p!", &arg, &arg_len) == FAILURE) {
RETURN_THROWS();
}
if (arg && php_check_open_basedir(arg)) {
RETURN_FALSE;
}
if (write_history(arg)) {
RETURN_FALSE;
} else {
RETURN_TRUE;
}
}
/* }}} */
/* {{{ Readline completion function? */
static char *_readline_command_generator(const char *text, int state)
{
HashTable *myht = Z_ARRVAL(_readline_array);
zval *entry;
if (!state) {
zend_hash_internal_pointer_reset(myht);
}
while ((entry = zend_hash_get_current_data(myht)) != NULL) {
zend_hash_move_forward(myht);
convert_to_string(entry);
if (strncmp (Z_STRVAL_P(entry), text, strlen(text)) == 0) {
return (strdup(Z_STRVAL_P(entry)));
}
}
return NULL;
}
static void _readline_string_zval(zval *ret, const char *str)
{
if (str) {
ZVAL_STRING(ret, (char*)str);
} else {
ZVAL_NULL(ret);
}
}
static void _readline_long_zval(zval *ret, long l)
{
ZVAL_LONG(ret, l);
}
char **php_readline_completion_cb(const char *text, int start, int end)
{
zval params[3];
char **matches = NULL;
_readline_string_zval(¶ms[0], text);
_readline_long_zval(¶ms[1], start);
_readline_long_zval(¶ms[2], end);
if (call_user_function(NULL, NULL, &_readline_completion, &_readline_array, 3, params) == SUCCESS) {
if (Z_TYPE(_readline_array) == IS_ARRAY) {
SEPARATE_ARRAY(&_readline_array);
if (zend_hash_num_elements(Z_ARRVAL(_readline_array))) {
matches = rl_completion_matches(text,_readline_command_generator);
} else {
/* libedit will read matches[2] */
matches = calloc(sizeof(char *), 3);
if (!matches) {
return NULL;
}
matches[0] = strdup("");
}
}
}
zval_ptr_dtor(¶ms[0]);
zval_ptr_dtor(&_readline_array);
return matches;
}
PHP_FUNCTION(readline_completion_function)
{
zend_fcall_info fci;
zend_fcall_info_cache fcc;
if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS(), "f", &fci, &fcc)) {
RETURN_THROWS();
}
zval_ptr_dtor(&_readline_completion);
ZVAL_COPY(&_readline_completion, &fci.function_name);
/* NOTE: The rl_attempted_completion_function variable (and others) are part of the readline library, not php */
rl_attempted_completion_function = php_readline_completion_cb;
if (rl_attempted_completion_function == NULL) {
RETURN_FALSE;
}
RETURN_TRUE;
}
/* }}} */
#if HAVE_RL_CALLBACK_READ_CHAR
static void php_rl_callback_handler(char *the_line)
{
zval params[1];
zval dummy;
ZVAL_NULL(&dummy);
_readline_string_zval(¶ms[0], the_line);
call_user_function(NULL, NULL, &_prepped_callback, &dummy, 1, params);
zval_ptr_dtor(¶ms[0]);
zval_ptr_dtor(&dummy);
}
/* {{{ Initializes the readline callback interface and terminal, prints the prompt and returns immediately */
PHP_FUNCTION(readline_callback_handler_install)
{
char *prompt;
zend_fcall_info fci;
zend_fcall_info_cache fcc;
size_t prompt_len;
if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS(), "sf", &prompt, &prompt_len, &fci, &fcc)) {
RETURN_THROWS();
}
if (Z_TYPE(_prepped_callback) != IS_UNDEF) {
rl_callback_handler_remove();
zval_ptr_dtor(&_prepped_callback);
}
ZVAL_COPY(&_prepped_callback, &fci.function_name);
rl_callback_handler_install(prompt, php_rl_callback_handler);
RETURN_TRUE;
}
/* }}} */
/* {{{ Informs the readline callback interface that a character is ready for input */
PHP_FUNCTION(readline_callback_read_char)
{
if (zend_parse_parameters_none() == FAILURE) {
RETURN_THROWS();
}
if (Z_TYPE(_prepped_callback) != IS_UNDEF) {
rl_callback_read_char();
}
}
/* }}} */
/* {{{ Removes a previously installed callback handler and restores terminal settings */
PHP_FUNCTION(readline_callback_handler_remove)
{
if (zend_parse_parameters_none() == FAILURE) {
RETURN_THROWS();
}
if (Z_TYPE(_prepped_callback) != IS_UNDEF) {
rl_callback_handler_remove();
zval_ptr_dtor(&_prepped_callback);
ZVAL_UNDEF(&_prepped_callback);
RETURN_TRUE;
}
RETURN_FALSE;
}
/* }}} */
/* {{{ Ask readline to redraw the display */
PHP_FUNCTION(readline_redisplay)
{
if (zend_parse_parameters_none() == FAILURE) {
RETURN_THROWS();
}
#if HAVE_LIBEDIT
/* seems libedit doesn't take care of rl_initialize in rl_redisplay
* see bug #72538 */
using_history();
#endif
rl_redisplay();
}
/* }}} */
#endif
#if HAVE_RL_ON_NEW_LINE
/* {{{ Inform readline that the cursor has moved to a new line */
PHP_FUNCTION(readline_on_new_line)
{
if (zend_parse_parameters_none() == FAILURE) {
RETURN_THROWS();
}
rl_on_new_line();
}
/* }}} */
#endif
#endif /* HAVE_LIBREADLINE */
| 14,384 | 22.895349 | 113 |
c
|
php-src
|
php-src-master/ext/readline/readline_arginfo.h
|
/* This is a generated file, edit the .stub.php file instead.
* Stub hash: 64d630be9ea75d584a4a999dd4d4c6bc769f5aca */
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_readline, 0, 0, MAY_BE_STRING|MAY_BE_FALSE)
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, prompt, IS_STRING, 1, "null")
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_readline_info, 0, 0, IS_MIXED, 0)
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, var_name, IS_STRING, 1, "null")
ZEND_ARG_INFO_WITH_DEFAULT_VALUE(0, value, "null")
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_readline_add_history, 0, 1, _IS_BOOL, 0)
ZEND_ARG_TYPE_INFO(0, prompt, IS_STRING, 0)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_readline_clear_history, 0, 0, _IS_BOOL, 0)
ZEND_END_ARG_INFO()
#if defined(HAVE_HISTORY_LIST)
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_readline_list_history, 0, 0, IS_ARRAY, 0)
ZEND_END_ARG_INFO()
#endif
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_readline_read_history, 0, 0, _IS_BOOL, 0)
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, filename, IS_STRING, 1, "null")
ZEND_END_ARG_INFO()
#define arginfo_readline_write_history arginfo_readline_read_history
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_readline_completion_function, 0, 1, _IS_BOOL, 0)
ZEND_ARG_TYPE_INFO(0, callback, IS_CALLABLE, 0)
ZEND_END_ARG_INFO()
#if HAVE_RL_CALLBACK_READ_CHAR
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_readline_callback_handler_install, 0, 2, _IS_BOOL, 0)
ZEND_ARG_TYPE_INFO(0, prompt, IS_STRING, 0)
ZEND_ARG_TYPE_INFO(0, callback, IS_CALLABLE, 0)
ZEND_END_ARG_INFO()
#endif
#if HAVE_RL_CALLBACK_READ_CHAR
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_readline_callback_read_char, 0, 0, IS_VOID, 0)
ZEND_END_ARG_INFO()
#endif
#if HAVE_RL_CALLBACK_READ_CHAR
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_readline_callback_handler_remove, 0, 0, _IS_BOOL, 0)
ZEND_END_ARG_INFO()
#endif
#if HAVE_RL_CALLBACK_READ_CHAR
#define arginfo_readline_redisplay arginfo_readline_callback_read_char
#endif
#if HAVE_RL_CALLBACK_READ_CHAR && HAVE_RL_ON_NEW_LINE
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_readline_on_new_line, 0, 0, IS_VOID, 0)
ZEND_END_ARG_INFO()
#endif
ZEND_FUNCTION(readline);
ZEND_FUNCTION(readline_info);
ZEND_FUNCTION(readline_add_history);
ZEND_FUNCTION(readline_clear_history);
#if defined(HAVE_HISTORY_LIST)
ZEND_FUNCTION(readline_list_history);
#endif
ZEND_FUNCTION(readline_read_history);
ZEND_FUNCTION(readline_write_history);
ZEND_FUNCTION(readline_completion_function);
#if HAVE_RL_CALLBACK_READ_CHAR
ZEND_FUNCTION(readline_callback_handler_install);
#endif
#if HAVE_RL_CALLBACK_READ_CHAR
ZEND_FUNCTION(readline_callback_read_char);
#endif
#if HAVE_RL_CALLBACK_READ_CHAR
ZEND_FUNCTION(readline_callback_handler_remove);
#endif
#if HAVE_RL_CALLBACK_READ_CHAR
ZEND_FUNCTION(readline_redisplay);
#endif
#if HAVE_RL_CALLBACK_READ_CHAR && HAVE_RL_ON_NEW_LINE
ZEND_FUNCTION(readline_on_new_line);
#endif
static const zend_function_entry ext_functions[] = {
ZEND_FE(readline, arginfo_readline)
ZEND_FE(readline_info, arginfo_readline_info)
ZEND_FE(readline_add_history, arginfo_readline_add_history)
ZEND_FE(readline_clear_history, arginfo_readline_clear_history)
#if defined(HAVE_HISTORY_LIST)
ZEND_FE(readline_list_history, arginfo_readline_list_history)
#endif
ZEND_FE(readline_read_history, arginfo_readline_read_history)
ZEND_FE(readline_write_history, arginfo_readline_write_history)
ZEND_FE(readline_completion_function, arginfo_readline_completion_function)
#if HAVE_RL_CALLBACK_READ_CHAR
ZEND_FE(readline_callback_handler_install, arginfo_readline_callback_handler_install)
#endif
#if HAVE_RL_CALLBACK_READ_CHAR
ZEND_FE(readline_callback_read_char, arginfo_readline_callback_read_char)
#endif
#if HAVE_RL_CALLBACK_READ_CHAR
ZEND_FE(readline_callback_handler_remove, arginfo_readline_callback_handler_remove)
#endif
#if HAVE_RL_CALLBACK_READ_CHAR
ZEND_FE(readline_redisplay, arginfo_readline_redisplay)
#endif
#if HAVE_RL_CALLBACK_READ_CHAR && HAVE_RL_ON_NEW_LINE
ZEND_FE(readline_on_new_line, arginfo_readline_on_new_line)
#endif
ZEND_FE_END
};
static void register_readline_symbols(int module_number)
{
REGISTER_STRING_CONSTANT("READLINE_LIB", READLINE_LIB, CONST_PERSISTENT);
}
| 4,282 | 34.106557 | 101 |
h
|
php-src
|
php-src-master/ext/readline/readline_cli.c
|
/*
+----------------------------------------------------------------------+
| Copyright (c) The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| https://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| [email protected] so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Author: Marcus Boerger <[email protected]> |
| Johannes Schlueter <[email protected]> |
+----------------------------------------------------------------------+
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "php.h"
#ifndef HAVE_RL_COMPLETION_MATCHES
#define rl_completion_matches completion_matches
#endif
#include "php_globals.h"
#include "php_variables.h"
#include "zend_hash.h"
#include "zend_modules.h"
#include "SAPI.h"
#include <locale.h>
#include "zend.h"
#include "zend_extensions.h"
#include "php_ini.h"
#include "php_globals.h"
#include "php_main.h"
#include "fopen_wrappers.h"
#include "ext/standard/php_standard.h"
#include "zend_smart_str.h"
#ifdef __riscos__
#include <unixlib/local.h>
#endif
#if HAVE_LIBEDIT
#include <editline/readline.h>
#else
#include <readline/readline.h>
#include <readline/history.h>
#endif
#include "zend_compile.h"
#include "zend_execute.h"
#include "zend_highlight.h"
#include "zend_exceptions.h"
#include "sapi/cli/cli.h"
#include "readline_cli.h"
#if defined(COMPILE_DL_READLINE) && !defined(PHP_WIN32)
#include <dlfcn.h>
#endif
#ifndef RTLD_DEFAULT
#define RTLD_DEFAULT NULL
#endif
#define DEFAULT_PROMPT "\\b \\> "
ZEND_DECLARE_MODULE_GLOBALS(cli_readline)
static char php_last_char = '\0';
static FILE *pager_pipe = NULL;
static size_t readline_shell_write(const char *str, size_t str_length) /* {{{ */
{
if (CLIR_G(prompt_str)) {
smart_str_appendl(CLIR_G(prompt_str), str, str_length);
return str_length;
}
if (CLIR_G(pager) && *CLIR_G(pager) && !pager_pipe) {
pager_pipe = VCWD_POPEN(CLIR_G(pager), "w");
}
if (pager_pipe) {
return fwrite(str, 1, MIN(str_length, 16384), pager_pipe);
}
return -1;
}
/* }}} */
static size_t readline_shell_ub_write(const char *str, size_t str_length) /* {{{ */
{
/* We just store the last char here and then pass back to the
caller (sapi_cli_single_write in sapi/cli) which will actually
write due to -1 return code */
php_last_char = str[str_length-1];
return (size_t) -1;
}
/* }}} */
static void cli_readline_init_globals(zend_cli_readline_globals *rg)
{
rg->pager = NULL;
rg->prompt = NULL;
rg->prompt_str = NULL;
}
PHP_INI_BEGIN()
STD_PHP_INI_ENTRY("cli.pager", "", PHP_INI_ALL, OnUpdateString, pager, zend_cli_readline_globals, cli_readline_globals)
STD_PHP_INI_ENTRY("cli.prompt", DEFAULT_PROMPT, PHP_INI_ALL, OnUpdateString, prompt, zend_cli_readline_globals, cli_readline_globals)
PHP_INI_END()
typedef enum {
body,
sstring,
dstring,
sstring_esc,
dstring_esc,
comment_line,
comment_block,
heredoc_start,
heredoc,
outside,
} php_code_type;
static zend_string *cli_get_prompt(char *block, char prompt) /* {{{ */
{
smart_str retval = {0};
char *prompt_spec = CLIR_G(prompt) ? CLIR_G(prompt) : DEFAULT_PROMPT;
bool unicode_warned = false;
do {
if (*prompt_spec == '\\') {
switch (prompt_spec[1]) {
case '\\':
smart_str_appendc(&retval, '\\');
prompt_spec++;
break;
case 'n':
smart_str_appendc(&retval, '\n');
prompt_spec++;
break;
case 't':
smart_str_appendc(&retval, '\t');
prompt_spec++;
break;
case 'e':
smart_str_appendc(&retval, '\033');
prompt_spec++;
break;
case 'v':
smart_str_appends(&retval, PHP_VERSION);
prompt_spec++;
break;
case 'b':
smart_str_appends(&retval, block);
prompt_spec++;
break;
case '>':
smart_str_appendc(&retval, prompt);
prompt_spec++;
break;
case '`':
smart_str_appendc(&retval, '`');
prompt_spec++;
break;
default:
smart_str_appendc(&retval, '\\');
break;
}
} else if (*prompt_spec == '`') {
char *prompt_end = strstr(prompt_spec + 1, "`");
char *code;
if (prompt_end) {
code = estrndup(prompt_spec + 1, prompt_end - prompt_spec - 1);
CLIR_G(prompt_str) = &retval;
zend_try {
zend_eval_stringl(code, prompt_end - prompt_spec - 1, NULL, "php prompt code");
} zend_end_try();
CLIR_G(prompt_str) = NULL;
efree(code);
prompt_spec = prompt_end;
}
} else {
if (!(*prompt_spec & 0x80)) {
smart_str_appendc(&retval, *prompt_spec);
} else {
if (!unicode_warned) {
zend_error(E_WARNING,
"prompt contains unsupported unicode characters");
unicode_warned = true;
}
smart_str_appendc(&retval, '?');
}
}
} while (++prompt_spec && *prompt_spec);
smart_str_0(&retval);
return retval.s;
}
/* }}} */
static int cli_is_valid_code(char *code, size_t len, zend_string **prompt) /* {{{ */
{
int valid_end = 1, last_valid_end;
int brackets_count = 0;
int brace_count = 0;
size_t i;
php_code_type code_type = body;
char *heredoc_tag = NULL;
size_t heredoc_len;
for (i = 0; i < len; ++i) {
switch(code_type) {
default:
switch(code[i]) {
case '{':
brackets_count++;
valid_end = 0;
break;
case '}':
if (brackets_count > 0) {
brackets_count--;
}
valid_end = brackets_count ? 0 : 1;
break;
case '(':
brace_count++;
valid_end = 0;
break;
case ')':
if (brace_count > 0) {
brace_count--;
}
valid_end = 0;
break;
case ';':
valid_end = brace_count == 0 && brackets_count == 0;
break;
case ' ':
case '\r':
case '\n':
case '\t':
break;
case '\'':
code_type = sstring;
break;
case '"':
code_type = dstring;
break;
case '#':
if (code[i+1] == '[') {
valid_end = 0;
break;
}
code_type = comment_line;
break;
case '/':
if (code[i+1] == '/') {
i++;
code_type = comment_line;
break;
}
if (code[i+1] == '*') {
last_valid_end = valid_end;
valid_end = 0;
code_type = comment_block;
i++;
break;
}
valid_end = 0;
break;
case '?':
if (code[i+1] == '>') {
i++;
code_type = outside;
break;
}
valid_end = 0;
break;
case '<':
valid_end = 0;
if (i + 2 < len && code[i+1] == '<' && code[i+2] == '<') {
i += 2;
code_type = heredoc_start;
heredoc_tag = NULL;
heredoc_len = 0;
}
break;
default:
valid_end = 0;
break;
}
break;
case sstring:
if (code[i] == '\\') {
code_type = sstring_esc;
} else {
if (code[i] == '\'') {
code_type = body;
}
}
break;
case sstring_esc:
code_type = sstring;
break;
case dstring:
if (code[i] == '\\') {
code_type = dstring_esc;
} else {
if (code[i] == '"') {
code_type = body;
}
}
break;
case dstring_esc:
code_type = dstring;
break;
case comment_line:
if (code[i] == '\n') {
code_type = body;
}
break;
case comment_block:
if (code[i-1] == '*' && code[i] == '/') {
code_type = body;
valid_end = last_valid_end;
}
break;
case heredoc_start:
switch(code[i]) {
case ' ':
case '\t':
case '\'':
break;
case '\r':
case '\n':
if (heredoc_tag) {
code_type = heredoc;
} else {
/* Malformed heredoc without label */
code_type = body;
}
break;
default:
if (!heredoc_tag) {
heredoc_tag = code+i;
}
heredoc_len++;
break;
}
break;
case heredoc:
ZEND_ASSERT(heredoc_tag);
if (!strncmp(code + i - heredoc_len + 1, heredoc_tag, heredoc_len)) {
unsigned char c = code[i + 1];
char *p = code + i - heredoc_len;
if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || (c >= '0' && c <= '9') || c == '_' || c >= 0x80) break;
while (*p == ' ' || *p == '\t') p--;
if (*p != '\n') break;
code_type = body;
}
break;
case outside:
if ((CG(short_tags) && !strncmp(code+i-1, "<?", 2))
|| (i > 3 && !strncmp(code+i-4, "<?php", 5))
) {
code_type = body;
}
break;
}
}
switch (code_type) {
default:
if (brace_count) {
*prompt = cli_get_prompt("php", '(');
} else if (brackets_count) {
*prompt = cli_get_prompt("php", '{');
} else {
*prompt = cli_get_prompt("php", '>');
}
break;
case sstring:
case sstring_esc:
*prompt = cli_get_prompt("php", '\'');
break;
case dstring:
case dstring_esc:
*prompt = cli_get_prompt("php", '"');
break;
case comment_block:
*prompt = cli_get_prompt("/* ", '>');
break;
case heredoc:
*prompt = cli_get_prompt("<<<", '>');
break;
case outside:
*prompt = cli_get_prompt(" ", '>');
break;
}
if (!valid_end || brackets_count) {
return 0;
} else {
return 1;
}
}
/* }}} */
static char *cli_completion_generator_ht(const char *text, size_t textlen, int *state, HashTable *ht, void **pData) /* {{{ */
{
zend_string *name;
zend_ulong number;
if (!(*state % 2)) {
zend_hash_internal_pointer_reset(ht);
(*state)++;
}
while(zend_hash_has_more_elements(ht) == SUCCESS) {
zend_hash_get_current_key(ht, &name, &number);
if (!textlen || !strncmp(ZSTR_VAL(name), text, textlen)) {
if (pData) {
*pData = zend_hash_get_current_data_ptr(ht);
}
zend_hash_move_forward(ht);
return ZSTR_VAL(name);
}
if (zend_hash_move_forward(ht) == FAILURE) {
break;
}
}
(*state)++;
return NULL;
} /* }}} */
static char *cli_completion_generator_var(const char *text, size_t textlen, int *state) /* {{{ */
{
char *retval, *tmp;
zend_array *symbol_table = &EG(symbol_table);
tmp = retval = cli_completion_generator_ht(text + 1, textlen - 1, state, symbol_table, NULL);
if (retval) {
retval = malloc(strlen(tmp) + 2);
retval[0] = '$';
strcpy(&retval[1], tmp);
rl_completion_append_character = '\0';
}
return retval;
} /* }}} */
static char *cli_completion_generator_ini(const char *text, size_t textlen, int *state) /* {{{ */
{
char *retval, *tmp;
tmp = retval = cli_completion_generator_ht(text + 1, textlen - 1, state, EG(ini_directives), NULL);
if (retval) {
retval = malloc(strlen(tmp) + 2);
retval[0] = '#';
strcpy(&retval[1], tmp);
rl_completion_append_character = '=';
}
return retval;
} /* }}} */
static char *cli_completion_generator_func(const char *text, size_t textlen, int *state, HashTable *ht) /* {{{ */
{
zend_function *func;
char *retval = cli_completion_generator_ht(text, textlen, state, ht, (void**)&func);
if (retval) {
rl_completion_append_character = '(';
retval = strdup(ZSTR_VAL(func->common.function_name));
}
return retval;
} /* }}} */
static char *cli_completion_generator_class(const char *text, size_t textlen, int *state) /* {{{ */
{
zend_class_entry *ce;
char *retval = cli_completion_generator_ht(text, textlen, state, EG(class_table), (void**)&ce);
if (retval) {
rl_completion_append_character = '\0';
retval = strdup(ZSTR_VAL(ce->name));
}
return retval;
} /* }}} */
static char *cli_completion_generator_define(const char *text, size_t textlen, int *state, HashTable *ht) /* {{{ */
{
zend_class_entry **pce;
char *retval = cli_completion_generator_ht(text, textlen, state, ht, (void**)&pce);
if (retval) {
rl_completion_append_character = '\0';
retval = strdup(retval);
}
return retval;
} /* }}} */
static int cli_completion_state;
static char *cli_completion_generator(const char *text, int index) /* {{{ */
{
/*
TODO:
- constants
- maybe array keys
- language constructs and other things outside a hashtable (echo, try, function, class, ...)
- object/class members
- future: respect scope ("php > function foo() { $[tab]" should only expand to local variables...)
*/
char *retval = NULL;
size_t textlen = strlen(text);
if (!index) {
cli_completion_state = 0;
}
if (text[0] == '$') {
retval = cli_completion_generator_var(text, textlen, &cli_completion_state);
} else if (text[0] == '#' && text[1] != '[') {
retval = cli_completion_generator_ini(text, textlen, &cli_completion_state);
} else {
char *lc_text, *class_name_end;
zend_string *class_name = NULL;
zend_class_entry *ce = NULL;
class_name_end = strstr(text, "::");
if (class_name_end) {
size_t class_name_len = class_name_end - text;
class_name = zend_string_alloc(class_name_len, 0);
zend_str_tolower_copy(ZSTR_VAL(class_name), text, class_name_len);
if ((ce = zend_lookup_class(class_name)) == NULL) {
zend_string_release_ex(class_name, 0);
return NULL;
}
lc_text = zend_str_tolower_dup(class_name_end + 2, textlen - 2 - class_name_len);
textlen -= (class_name_len + 2);
} else {
lc_text = zend_str_tolower_dup(text, textlen);
}
switch (cli_completion_state) {
case 0:
case 1:
retval = cli_completion_generator_func(lc_text, textlen, &cli_completion_state, ce ? &ce->function_table : EG(function_table));
if (retval) {
break;
}
ZEND_FALLTHROUGH;
case 2:
case 3:
retval = cli_completion_generator_define(text, textlen, &cli_completion_state, ce ? &ce->constants_table : EG(zend_constants));
if (retval || ce) {
break;
}
ZEND_FALLTHROUGH;
case 4:
case 5:
retval = cli_completion_generator_class(lc_text, textlen, &cli_completion_state);
break;
default:
break;
}
efree(lc_text);
if (class_name) {
zend_string_release_ex(class_name, 0);
}
if (ce && retval) {
size_t len = ZSTR_LEN(ce->name) + 2 + strlen(retval) + 1;
char *tmp = malloc(len);
snprintf(tmp, len, "%s::%s", ZSTR_VAL(ce->name), retval);
free(retval);
retval = tmp;
}
}
return retval;
} /* }}} */
static char **cli_code_completion(const char *text, int start, int end) /* {{{ */
{
return rl_completion_matches(text, cli_completion_generator);
}
/* }}} */
static int readline_shell_run(void) /* {{{ */
{
char *line;
size_t size = 4096, pos = 0, len;
char *code = emalloc(size);
zend_string *prompt = cli_get_prompt("php", '>');
char *history_file;
int history_lines_to_write = 0;
if (PG(auto_prepend_file) && PG(auto_prepend_file)[0]) {
zend_file_handle prepend_file;
zend_stream_init_filename(&prepend_file, PG(auto_prepend_file));
zend_execute_scripts(ZEND_REQUIRE, NULL, 1, &prepend_file);
zend_destroy_file_handle(&prepend_file);
}
#ifndef PHP_WIN32
history_file = tilde_expand("~/.php_history");
#else
spprintf(&history_file, MAX_PATH, "%s/.php_history", getenv("USERPROFILE"));
#endif
/* Install the default completion function for 'php -a'.
*
* But if readline_completion_function() was called by PHP code prior to the shell starting
* (e.g. with 'php -d auto_prepend_file=prepend.php -a'),
* then use that instead of PHP's default. */
if (rl_attempted_completion_function != php_readline_completion_cb) {
rl_attempted_completion_function = cli_code_completion;
}
#ifndef PHP_WIN32
rl_special_prefixes = "$";
#endif
read_history(history_file);
EG(exit_status) = 0;
while ((line = readline(ZSTR_VAL(prompt))) != NULL) {
if (strcmp(line, "exit") == 0 || strcmp(line, "quit") == 0) {
free(line);
break;
}
if (!pos && !*line) {
free(line);
continue;
}
len = strlen(line);
if (line[0] == '#' && line[1] != '[') {
char *param = strstr(&line[1], "=");
if (param) {
zend_string *cmd;
param++;
cmd = zend_string_init(&line[1], param - &line[1] - 1, 0);
zend_alter_ini_entry_chars_ex(cmd, param, strlen(param), PHP_INI_USER, PHP_INI_STAGE_RUNTIME, 0);
zend_string_release_ex(cmd, 0);
add_history(line);
zend_string_release_ex(prompt, 0);
/* TODO: This might be wrong! */
prompt = cli_get_prompt("php", '>');
continue;
}
}
if (pos + len + 2 > size) {
size = pos + len + 2;
code = erealloc(code, size);
}
memcpy(&code[pos], line, len);
pos += len;
code[pos] = '\n';
code[++pos] = '\0';
if (*line) {
add_history(line);
history_lines_to_write += 1;
}
free(line);
zend_string_release_ex(prompt, 0);
if (!cli_is_valid_code(code, pos, &prompt)) {
continue;
}
if (history_lines_to_write) {
#if HAVE_LIBEDIT
write_history(history_file);
#else
append_history(history_lines_to_write, history_file);
#endif
history_lines_to_write = 0;
}
zend_try {
zend_eval_stringl(code, pos, NULL, "php shell code");
} zend_end_try();
pos = 0;
if (!pager_pipe && php_last_char != '\0' && php_last_char != '\n') {
php_write("\n", 1);
}
if (EG(exception)) {
zend_exception_error(EG(exception), E_WARNING);
}
if (pager_pipe) {
fclose(pager_pipe);
pager_pipe = NULL;
}
php_last_char = '\0';
}
#ifdef PHP_WIN32
efree(history_file);
#else
free(history_file);
#endif
efree(code);
zend_string_release_ex(prompt, 0);
return EG(exit_status);
}
/* }}} */
#ifdef PHP_WIN32
typedef cli_shell_callbacks_t *(__cdecl *get_cli_shell_callbacks)(void);
#define GET_SHELL_CB(cb) \
do { \
get_cli_shell_callbacks get_callbacks; \
HMODULE hMod = GetModuleHandle("php.exe"); \
(cb) = NULL; \
if (strlen(sapi_module.name) >= 3 && 0 == strncmp("cli", sapi_module.name, 3)) { \
get_callbacks = (get_cli_shell_callbacks)GetProcAddress(hMod, "php_cli_get_shell_callbacks"); \
if (get_callbacks) { \
(cb) = get_callbacks(); \
} \
} \
} while(0)
#else
/*
#ifdef COMPILE_DL_READLINE
This dlsym() is always used as even the CGI SAPI is linked against "CLI"-only
extensions. If that is being changed dlsym() should only be used when building
this extension sharedto offer compatibility.
*/
#define GET_SHELL_CB(cb) \
do { \
(cb) = NULL; \
cli_shell_callbacks_t *(*get_callbacks)(void); \
get_callbacks = dlsym(RTLD_DEFAULT, "php_cli_get_shell_callbacks"); \
if (get_callbacks) { \
(cb) = get_callbacks(); \
} \
} while(0)
/*#else
#define GET_SHELL_CB(cb) (cb) = php_cli_get_shell_callbacks()
#endif*/
#endif
PHP_MINIT_FUNCTION(cli_readline)
{
cli_shell_callbacks_t *cb;
ZEND_INIT_MODULE_GLOBALS(cli_readline, cli_readline_init_globals, NULL);
REGISTER_INI_ENTRIES();
GET_SHELL_CB(cb);
if (cb) {
cb->cli_shell_write = readline_shell_write;
cb->cli_shell_ub_write = readline_shell_ub_write;
cb->cli_shell_run = readline_shell_run;
}
return SUCCESS;
}
PHP_MSHUTDOWN_FUNCTION(cli_readline)
{
cli_shell_callbacks_t *cb;
UNREGISTER_INI_ENTRIES();
GET_SHELL_CB(cb);
if (cb) {
cb->cli_shell_write = NULL;
cb->cli_shell_ub_write = NULL;
cb->cli_shell_run = NULL;
}
return SUCCESS;
}
PHP_MINFO_FUNCTION(cli_readline)
{
php_info_print_table_start();
php_info_print_table_row(2, "Readline Support", "enabled");
#ifdef PHP_WIN32
php_info_print_table_row(2, "Readline library", "WinEditLine");
#else
php_info_print_table_row(2, "Readline library", (rl_library_version ? rl_library_version : "Unknown"));
#endif
php_info_print_table_end();
DISPLAY_INI_ENTRIES();
}
| 19,635 | 23.152522 | 134 |
c
|
php-src
|
php-src-master/ext/readline/readline_cli.h
|
/*
+----------------------------------------------------------------------+
| Copyright (c) The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| https://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| [email protected] so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Author: Marcus Boerger <[email protected]> |
| Johannes Schlueter <[email protected]> |
+----------------------------------------------------------------------+
*/
#include "php.h"
#include "zend_smart_str_public.h"
ZEND_BEGIN_MODULE_GLOBALS(cli_readline)
char *pager;
char *prompt;
smart_str *prompt_str;
ZEND_END_MODULE_GLOBALS(cli_readline)
#ifdef ZTS
# define CLIR_G(v) TSRMG(cli_readline_globals_id, zend_cli_readline_globals *, v)
#else
# define CLIR_G(v) (cli_readline_globals.v)
#endif
extern PHP_MINIT_FUNCTION(cli_readline);
extern PHP_MSHUTDOWN_FUNCTION(cli_readline);
extern PHP_MINFO_FUNCTION(cli_readline);
char **php_readline_completion_cb(const char *text, int start, int end);
ZEND_EXTERN_MODULE_GLOBALS(cli_readline)
| 1,650 | 40.275 | 81 |
h
|
php-src
|
php-src-master/ext/reflection/php_reflection.h
|
/*
+----------------------------------------------------------------------+
| Copyright (c) The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| https://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| [email protected] so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Authors: George Schlossnagle <[email protected]> |
+----------------------------------------------------------------------+
*/
#ifndef PHP_REFLECTION_H
#define PHP_REFLECTION_H
#include "php.h"
extern zend_module_entry reflection_module_entry;
#define phpext_reflection_ptr &reflection_module_entry
#define PHP_REFLECTION_VERSION PHP_VERSION
BEGIN_EXTERN_C()
/* Class entry pointers */
extern PHPAPI zend_class_entry *reflector_ptr;
extern PHPAPI zend_class_entry *reflection_exception_ptr;
extern PHPAPI zend_class_entry *reflection_ptr;
extern PHPAPI zend_class_entry *reflection_function_abstract_ptr;
extern PHPAPI zend_class_entry *reflection_function_ptr;
extern PHPAPI zend_class_entry *reflection_parameter_ptr;
extern PHPAPI zend_class_entry *reflection_type_ptr;
extern PHPAPI zend_class_entry *reflection_named_type_ptr;
extern PHPAPI zend_class_entry *reflection_class_ptr;
extern PHPAPI zend_class_entry *reflection_object_ptr;
extern PHPAPI zend_class_entry *reflection_method_ptr;
extern PHPAPI zend_class_entry *reflection_property_ptr;
extern PHPAPI zend_class_entry *reflection_extension_ptr;
extern PHPAPI zend_class_entry *reflection_zend_extension_ptr;
extern PHPAPI zend_class_entry *reflection_reference_ptr;
extern PHPAPI zend_class_entry *reflection_attribute_ptr;
extern PHPAPI zend_class_entry *reflection_enum_ptr;
extern PHPAPI zend_class_entry *reflection_enum_unit_case_ptr;
extern PHPAPI zend_class_entry *reflection_enum_backed_case_ptr;
extern PHPAPI zend_class_entry *reflection_fiber_ptr;
PHPAPI void zend_reflection_class_factory(zend_class_entry *ce, zval *object);
END_EXTERN_C()
#endif /* PHP_REFLECTION_H */
| 2,525 | 44.107143 | 78 |
h
|
php-src
|
php-src-master/ext/session/mod_files.h
|
/*
+----------------------------------------------------------------------+
| Copyright (c) The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| https://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| [email protected] so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Author: Sascha Schumann <[email protected]> |
+----------------------------------------------------------------------+
*/
#ifndef MOD_FILES_H
#define MOD_FILES_H
extern const ps_module ps_mod_files;
#define ps_files_ptr &ps_mod_files
PS_FUNCS_UPDATE_TIMESTAMP(files);
#endif
| 1,152 | 43.346154 | 75 |
h
|
php-src
|
php-src-master/ext/session/mod_mm.h
|
/*
+----------------------------------------------------------------------+
| Copyright (c) The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| https://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| [email protected] so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Author: Sascha Schumann <[email protected]> |
+----------------------------------------------------------------------+
*/
#ifndef MOD_MM_H
#define MOD_MM_H
#ifdef HAVE_LIBMM
#include "php_session.h"
PHP_MINIT_FUNCTION(ps_mm);
PHP_MSHUTDOWN_FUNCTION(ps_mm);
extern const ps_module ps_mod_mm;
#define ps_mm_ptr &ps_mod_mm
PS_FUNCS(mm);
#endif
#endif
| 1,228 | 35.147059 | 75 |
h
|
php-src
|
php-src-master/ext/session/mod_user.h
|
/*
+----------------------------------------------------------------------+
| Copyright (c) The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| https://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| [email protected] so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Author: Sascha Schumann <[email protected]> |
+----------------------------------------------------------------------+
*/
#ifndef MOD_USER_H
#define MOD_USER_H
extern const ps_module ps_mod_user;
#define ps_user_ptr &ps_mod_user
PS_FUNCS_UPDATE_TIMESTAMP(user);
#endif
| 1,146 | 43.115385 | 75 |
h
|
php-src
|
php-src-master/ext/session/mod_user_class.c
|
/*
+----------------------------------------------------------------------+
| Copyright (c) The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| https://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| [email protected] so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Author: Arpad Ray <[email protected]> |
+----------------------------------------------------------------------+
*/
#include "php.h"
#include "php_session.h"
#define PS_SANITY_CHECK \
if (PS(session_status) != php_session_active) { \
zend_throw_error(NULL, "Session is not active"); \
RETURN_THROWS(); \
} \
if (PS(default_mod) == NULL) { \
zend_throw_error(NULL, "Cannot call default session handler"); \
RETURN_THROWS(); \
}
#define PS_SANITY_CHECK_IS_OPEN \
PS_SANITY_CHECK; \
if (!PS(mod_user_is_open)) { \
php_error_docref(NULL, E_WARNING, "Parent session handler is not open"); \
RETURN_FALSE; \
}
/* {{{ Wraps the old open handler */
PHP_METHOD(SessionHandler, open)
{
char *save_path = NULL, *session_name = NULL;
size_t save_path_len, session_name_len;
zend_result ret;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss", &save_path, &save_path_len, &session_name, &session_name_len) == FAILURE) {
RETURN_THROWS();
}
PS_SANITY_CHECK;
PS(mod_user_is_open) = 1;
zend_try {
ret = PS(default_mod)->s_open(&PS(mod_data), save_path, session_name);
} zend_catch {
PS(session_status) = php_session_none;
zend_bailout();
} zend_end_try();
RETURN_BOOL(SUCCESS == ret);
}
/* }}} */
/* {{{ Wraps the old close handler */
PHP_METHOD(SessionHandler, close)
{
zend_result ret;
// don't return on failure, since not closing the default handler
// could result in memory leaks or other nasties
zend_parse_parameters_none();
PS_SANITY_CHECK_IS_OPEN;
PS(mod_user_is_open) = 0;
zend_try {
ret = PS(default_mod)->s_close(&PS(mod_data));
} zend_catch {
PS(session_status) = php_session_none;
zend_bailout();
} zend_end_try();
RETURN_BOOL(SUCCESS == ret);
}
/* }}} */
/* {{{ Wraps the old read handler */
PHP_METHOD(SessionHandler, read)
{
zend_string *val;
zend_string *key;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "S", &key) == FAILURE) {
RETURN_THROWS();
}
PS_SANITY_CHECK_IS_OPEN;
if (PS(default_mod)->s_read(&PS(mod_data), key, &val, PS(gc_maxlifetime)) == FAILURE) {
RETURN_FALSE;
}
RETURN_STR(val);
}
/* }}} */
/* {{{ Wraps the old write handler */
PHP_METHOD(SessionHandler, write)
{
zend_string *key, *val;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "SS", &key, &val) == FAILURE) {
RETURN_THROWS();
}
PS_SANITY_CHECK_IS_OPEN;
RETURN_BOOL(SUCCESS == PS(default_mod)->s_write(&PS(mod_data), key, val, PS(gc_maxlifetime)));
}
/* }}} */
/* {{{ Wraps the old destroy handler */
PHP_METHOD(SessionHandler, destroy)
{
zend_string *key;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "S", &key) == FAILURE) {
RETURN_THROWS();
}
PS_SANITY_CHECK_IS_OPEN;
RETURN_BOOL(SUCCESS == PS(default_mod)->s_destroy(&PS(mod_data), key));
}
/* }}} */
/* {{{ Wraps the old gc handler */
PHP_METHOD(SessionHandler, gc)
{
zend_long maxlifetime;
zend_long nrdels = -1;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &maxlifetime) == FAILURE) {
RETURN_THROWS();
}
PS_SANITY_CHECK_IS_OPEN;
if (PS(default_mod)->s_gc(&PS(mod_data), maxlifetime, &nrdels) == FAILURE) {
RETURN_FALSE;
}
RETURN_LONG(nrdels);
}
/* }}} */
/* {{{ Wraps the old create_sid handler */
PHP_METHOD(SessionHandler, create_sid)
{
zend_string *id;
if (zend_parse_parameters_none() == FAILURE) {
RETURN_THROWS();
}
PS_SANITY_CHECK;
id = PS(default_mod)->s_create_sid(&PS(mod_data));
RETURN_STR(id);
}
/* }}} */
| 4,277 | 23.872093 | 125 |
c
|
php-src
|
php-src-master/ext/session/php_session.h
|
/*
+----------------------------------------------------------------------+
| Copyright (c) The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| https://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| [email protected] so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Author: Sascha Schumann <[email protected]> |
+----------------------------------------------------------------------+
*/
#ifndef PHP_SESSION_H
#define PHP_SESSION_H
#include "ext/standard/php_var.h"
#include "ext/hash/php_hash.h"
#define PHP_SESSION_API 20161017
#include "php_version.h"
#define PHP_SESSION_VERSION PHP_VERSION
/* save handler macros */
#define PS_OPEN_ARGS void **mod_data, const char *save_path, const char *session_name
#define PS_CLOSE_ARGS void **mod_data
#define PS_READ_ARGS void **mod_data, zend_string *key, zend_string **val, zend_long maxlifetime
#define PS_WRITE_ARGS void **mod_data, zend_string *key, zend_string *val, zend_long maxlifetime
#define PS_DESTROY_ARGS void **mod_data, zend_string *key
#define PS_GC_ARGS void **mod_data, zend_long maxlifetime, zend_long *nrdels
#define PS_CREATE_SID_ARGS void **mod_data
#define PS_VALIDATE_SID_ARGS void **mod_data, zend_string *key
#define PS_UPDATE_TIMESTAMP_ARGS void **mod_data, zend_string *key, zend_string *val, zend_long maxlifetime
typedef struct ps_module_struct {
const char *s_name;
zend_result (*s_open)(PS_OPEN_ARGS);
zend_result (*s_close)(PS_CLOSE_ARGS);
zend_result (*s_read)(PS_READ_ARGS);
zend_result (*s_write)(PS_WRITE_ARGS);
zend_result (*s_destroy)(PS_DESTROY_ARGS);
zend_long (*s_gc)(PS_GC_ARGS);
zend_string *(*s_create_sid)(PS_CREATE_SID_ARGS);
zend_result (*s_validate_sid)(PS_VALIDATE_SID_ARGS);
zend_result (*s_update_timestamp)(PS_UPDATE_TIMESTAMP_ARGS);
} ps_module;
#define PS_GET_MOD_DATA() *mod_data
#define PS_SET_MOD_DATA(a) *mod_data = (a)
#define PS_OPEN_FUNC(x) zend_result ps_open_##x(PS_OPEN_ARGS)
#define PS_CLOSE_FUNC(x) zend_result ps_close_##x(PS_CLOSE_ARGS)
#define PS_READ_FUNC(x) zend_result ps_read_##x(PS_READ_ARGS)
#define PS_WRITE_FUNC(x) zend_result ps_write_##x(PS_WRITE_ARGS)
#define PS_DESTROY_FUNC(x) zend_result ps_delete_##x(PS_DESTROY_ARGS)
#define PS_GC_FUNC(x) zend_long ps_gc_##x(PS_GC_ARGS)
#define PS_CREATE_SID_FUNC(x) zend_string *ps_create_sid_##x(PS_CREATE_SID_ARGS)
#define PS_VALIDATE_SID_FUNC(x) zend_result ps_validate_sid_##x(PS_VALIDATE_SID_ARGS)
#define PS_UPDATE_TIMESTAMP_FUNC(x) zend_result ps_update_timestamp_##x(PS_UPDATE_TIMESTAMP_ARGS)
/* Legacy save handler module definitions */
#define PS_FUNCS(x) \
PS_OPEN_FUNC(x); \
PS_CLOSE_FUNC(x); \
PS_READ_FUNC(x); \
PS_WRITE_FUNC(x); \
PS_DESTROY_FUNC(x); \
PS_GC_FUNC(x); \
PS_CREATE_SID_FUNC(x)
#define PS_MOD(x) \
#x, ps_open_##x, ps_close_##x, ps_read_##x, ps_write_##x, \
ps_delete_##x, ps_gc_##x, php_session_create_id, \
php_session_validate_sid, php_session_update_timestamp
/* Legacy SID creation enabled save handler module definitions */
#define PS_FUNCS_SID(x) \
PS_OPEN_FUNC(x); \
PS_CLOSE_FUNC(x); \
PS_READ_FUNC(x); \
PS_WRITE_FUNC(x); \
PS_DESTROY_FUNC(x); \
PS_GC_FUNC(x); \
PS_CREATE_SID_FUNC(x); \
PS_VALIDATE_SID_FUNC(x); \
PS_UPDATE_TIMESTAMP_FUNC(x);
#define PS_MOD_SID(x) \
#x, ps_open_##x, ps_close_##x, ps_read_##x, ps_write_##x, \
ps_delete_##x, ps_gc_##x, ps_create_sid_##x, \
php_session_validate_sid, php_session_update_timestamp
/* Update timestamp enabled save handler module definitions
New save handlers should use this API */
#define PS_FUNCS_UPDATE_TIMESTAMP(x) \
PS_OPEN_FUNC(x); \
PS_CLOSE_FUNC(x); \
PS_READ_FUNC(x); \
PS_WRITE_FUNC(x); \
PS_DESTROY_FUNC(x); \
PS_GC_FUNC(x); \
PS_CREATE_SID_FUNC(x); \
PS_VALIDATE_SID_FUNC(x); \
PS_UPDATE_TIMESTAMP_FUNC(x);
#define PS_MOD_UPDATE_TIMESTAMP(x) \
#x, ps_open_##x, ps_close_##x, ps_read_##x, ps_write_##x, \
ps_delete_##x, ps_gc_##x, ps_create_sid_##x, \
ps_validate_sid_##x, ps_update_timestamp_##x
typedef enum {
php_session_disabled,
php_session_none,
php_session_active
} php_session_status;
typedef struct _php_session_rfc1867_progress {
size_t sname_len;
zval sid;
smart_str key;
zend_long update_step;
zend_long next_update;
double next_update_time;
bool cancel_upload;
bool apply_trans_sid;
size_t content_length;
zval data; /* the array exported to session data */
zval *post_bytes_processed; /* data["bytes_processed"] */
zval files; /* data["files"] array */
zval current_file; /* array of currently uploading file */
zval *current_file_bytes_processed;
} php_session_rfc1867_progress;
typedef struct _php_ps_globals {
char *save_path;
char *session_name;
zend_string *id;
char *extern_referer_chk;
char *cache_limiter;
zend_long cookie_lifetime;
char *cookie_path;
char *cookie_domain;
bool cookie_secure;
bool cookie_httponly;
char *cookie_samesite;
const ps_module *mod;
const ps_module *default_mod;
void *mod_data;
php_session_status session_status;
zend_string *session_started_filename;
uint32_t session_started_lineno;
zend_long gc_probability;
zend_long gc_divisor;
zend_long gc_maxlifetime;
int module_number;
zend_long cache_expire;
struct {
zval ps_open;
zval ps_close;
zval ps_read;
zval ps_write;
zval ps_destroy;
zval ps_gc;
zval ps_create_sid;
zval ps_validate_sid;
zval ps_update_timestamp;
} mod_user_names;
bool mod_user_implemented;
bool mod_user_is_open;
zend_string *mod_user_class_name;
const struct ps_serializer_struct *serializer;
zval http_session_vars;
bool auto_start;
bool use_cookies;
bool use_only_cookies;
bool use_trans_sid; /* contains the INI value of whether to use trans-sid */
zend_long sid_length;
zend_long sid_bits_per_character;
bool send_cookie;
bool define_sid;
php_session_rfc1867_progress *rfc1867_progress;
bool rfc1867_enabled; /* session.upload_progress.enabled */
bool rfc1867_cleanup; /* session.upload_progress.cleanup */
char *rfc1867_prefix; /* session.upload_progress.prefix */
char *rfc1867_name; /* session.upload_progress.name */
zend_long rfc1867_freq; /* session.upload_progress.freq */
double rfc1867_min_freq; /* session.upload_progress.min_freq */
bool use_strict_mode; /* whether or not PHP accepts unknown session ids */
bool lazy_write; /* omit session write when it is possible */
bool in_save_handler; /* state if session is in save handler or not */
bool set_handler; /* state if session module i setting handler or not */
zend_string *session_vars; /* serialized original session data */
} php_ps_globals;
typedef php_ps_globals zend_ps_globals;
extern zend_module_entry session_module_entry;
#define phpext_session_ptr &session_module_entry
#ifdef ZTS
#define PS(v) ZEND_TSRMG(ps_globals_id, php_ps_globals *, v)
#ifdef COMPILE_DL_SESSION
ZEND_TSRMLS_CACHE_EXTERN()
#endif
#else
#define PS(v) (ps_globals.v)
#endif
#define PS_SERIALIZER_ENCODE_ARGS void
#define PS_SERIALIZER_DECODE_ARGS const char *val, size_t vallen
typedef struct ps_serializer_struct {
const char *name;
zend_string *(*encode)(PS_SERIALIZER_ENCODE_ARGS);
zend_result (*decode)(PS_SERIALIZER_DECODE_ARGS);
} ps_serializer;
#define PS_SERIALIZER_ENCODE_NAME(x) ps_srlzr_encode_##x
#define PS_SERIALIZER_DECODE_NAME(x) ps_srlzr_decode_##x
#define PS_SERIALIZER_ENCODE_FUNC(x) \
zend_string *PS_SERIALIZER_ENCODE_NAME(x)(PS_SERIALIZER_ENCODE_ARGS)
#define PS_SERIALIZER_DECODE_FUNC(x) \
zend_result PS_SERIALIZER_DECODE_NAME(x)(PS_SERIALIZER_DECODE_ARGS)
#define PS_SERIALIZER_FUNCS(x) \
PS_SERIALIZER_ENCODE_FUNC(x); \
PS_SERIALIZER_DECODE_FUNC(x)
#define PS_SERIALIZER_ENTRY(x) \
{ #x, PS_SERIALIZER_ENCODE_NAME(x), PS_SERIALIZER_DECODE_NAME(x) }
/* default create id function */
PHPAPI zend_string *php_session_create_id(PS_CREATE_SID_ARGS);
/* Dummy PS module functions */
PHPAPI zend_result php_session_validate_sid(PS_VALIDATE_SID_ARGS);
PHPAPI zend_result php_session_update_timestamp(PS_UPDATE_TIMESTAMP_ARGS);
PHPAPI void session_adapt_url(const char *url, size_t url_len, char **new_url, size_t *new_len);
PHPAPI zend_result php_session_destroy(void);
PHPAPI void php_add_session_var(zend_string *name);
PHPAPI zval *php_set_session_var(zend_string *name, zval *state_val, php_unserialize_data_t *var_hash);
PHPAPI zval *php_get_session_var(zend_string *name);
PHPAPI zend_result php_session_register_module(const ps_module *);
PHPAPI zend_result php_session_register_serializer(const char *name,
zend_string *(*encode)(PS_SERIALIZER_ENCODE_ARGS),
zend_result (*decode)(PS_SERIALIZER_DECODE_ARGS));
PHPAPI zend_result php_session_start(void);
PHPAPI zend_result php_session_flush(int write);
PHPAPI const ps_module *_php_find_ps_module(const char *name);
PHPAPI const ps_serializer *_php_find_ps_serializer(const char *name);
PHPAPI zend_result php_session_valid_key(const char *key);
PHPAPI zend_result php_session_reset_id(void);
#define PS_ADD_VARL(name) do { \
php_add_session_var(name); \
} while (0)
#define PS_ADD_VAR(name) PS_ADD_VARL(name)
#define PS_DEL_VARL(name) do { \
if (!Z_ISNULL(PS(http_session_vars))) { \
zend_hash_del(Z_ARRVAL(PS(http_session_vars)), name); \
} \
} while (0)
#define PS_ENCODE_VARS \
zend_string *key; \
zend_ulong num_key; \
zval *struc;
#define PS_ENCODE_LOOP(code) do { \
HashTable *_ht = Z_ARRVAL_P(Z_REFVAL(PS(http_session_vars))); \
ZEND_HASH_FOREACH_KEY(_ht, num_key, key) { \
if (key == NULL) { \
php_error_docref(NULL, E_WARNING, \
"Skipping numeric key " ZEND_LONG_FMT, num_key);\
continue; \
} \
if ((struc = php_get_session_var(key))) { \
code; \
} \
} ZEND_HASH_FOREACH_END(); \
} while(0)
PHPAPI ZEND_EXTERN_MODULE_GLOBALS(ps)
void php_session_auto_start(void *data);
extern PHPAPI zend_class_entry *php_session_class_entry;
extern PHPAPI zend_class_entry *php_session_iface_entry;
extern PHPAPI zend_class_entry *php_session_id_iface_entry;
extern PHPAPI zend_class_entry *php_session_update_timestamp_iface_entry;
extern PHP_METHOD(SessionHandler, open);
extern PHP_METHOD(SessionHandler, close);
extern PHP_METHOD(SessionHandler, read);
extern PHP_METHOD(SessionHandler, write);
extern PHP_METHOD(SessionHandler, destroy);
extern PHP_METHOD(SessionHandler, gc);
extern PHP_METHOD(SessionHandler, create_sid);
#endif
| 11,153 | 33.425926 | 107 |
h
|
php-src
|
php-src-master/ext/shmop/php_shmop.h
|
/*
+----------------------------------------------------------------------+
| Copyright (c) The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| https://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| [email protected] so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Authors: Slava Poliakov <[email protected]> |
| Ilia Alshanetsky <[email protected]> |
+----------------------------------------------------------------------+
*/
#ifndef PHP_SHMOP_H
#define PHP_SHMOP_H
#ifdef HAVE_SHMOP
extern zend_module_entry shmop_module_entry;
#define phpext_shmop_ptr &shmop_module_entry
#include "php_version.h"
#define PHP_SHMOP_VERSION PHP_VERSION
PHP_MINIT_FUNCTION(shmop);
PHP_MINFO_FUNCTION(shmop);
#ifdef PHP_WIN32
# include "win32/ipc.h"
#endif
#else
#define phpext_shmop_ptr NULL
#endif
#endif /* PHP_SHMOP_H */
| 1,461 | 33.809524 | 75 |
h
|
php-src
|
php-src-master/ext/shmop/shmop.c
|
/*
+----------------------------------------------------------------------+
| PHP version 7 |
+----------------------------------------------------------------------+
| Copyright (c) The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| https://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| [email protected] so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Authors: Slava Poliakov <[email protected]> |
| Ilia Alshanetsky <[email protected]> |
+----------------------------------------------------------------------+
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "php.h"
#include "php_ini.h"
#include "php_shmop.h"
#include "shmop_arginfo.h"
# ifndef PHP_WIN32
# include <sys/ipc.h>
# include <sys/shm.h>
#else
#include "tsrm_win32.h"
#endif
#ifdef HAVE_SHMOP
#include "ext/standard/info.h"
/* {{{ shmop_module_entry */
zend_module_entry shmop_module_entry = {
STANDARD_MODULE_HEADER,
"shmop",
ext_functions,
PHP_MINIT(shmop),
NULL,
NULL,
NULL,
PHP_MINFO(shmop),
PHP_SHMOP_VERSION,
STANDARD_MODULE_PROPERTIES
};
/* }}} */
#ifdef COMPILE_DL_SHMOP
ZEND_GET_MODULE(shmop)
#endif
typedef struct php_shmop
{
int shmid;
key_t key;
int shmflg;
int shmatflg;
char *addr;
zend_long size;
zend_object std;
} php_shmop;
zend_class_entry *shmop_ce;
static zend_object_handlers shmop_object_handlers;
static inline php_shmop *shmop_from_obj(zend_object *obj)
{
return (php_shmop *)((char *)(obj) - XtOffsetOf(php_shmop, std));
}
#define Z_SHMOP_P(zv) shmop_from_obj(Z_OBJ_P(zv))
static zend_object *shmop_create_object(zend_class_entry *class_type)
{
php_shmop *intern = zend_object_alloc(sizeof(php_shmop), class_type);
zend_object_std_init(&intern->std, class_type);
object_properties_init(&intern->std, class_type);
return &intern->std;
}
static zend_function *shmop_get_constructor(zend_object *object)
{
zend_throw_error(NULL, "Cannot directly construct Shmop, use shmop_open() instead");
return NULL;
}
static void shmop_free_obj(zend_object *object)
{
php_shmop *shmop = shmop_from_obj(object);
shmdt(shmop->addr);
zend_object_std_dtor(&shmop->std);
}
/* {{{ PHP_MINIT_FUNCTION */
PHP_MINIT_FUNCTION(shmop)
{
shmop_ce = register_class_Shmop();
shmop_ce->create_object = shmop_create_object;
shmop_ce->default_object_handlers = &shmop_object_handlers;
memcpy(&shmop_object_handlers, &std_object_handlers, sizeof(zend_object_handlers));
shmop_object_handlers.offset = XtOffsetOf(php_shmop, std);
shmop_object_handlers.free_obj = shmop_free_obj;
shmop_object_handlers.get_constructor = shmop_get_constructor;
shmop_object_handlers.clone_obj = NULL;
shmop_object_handlers.compare = zend_objects_not_comparable;
return SUCCESS;
}
/* }}} */
/* {{{ PHP_MINFO_FUNCTION */
PHP_MINFO_FUNCTION(shmop)
{
php_info_print_table_start();
php_info_print_table_row(2, "shmop support", "enabled");
php_info_print_table_end();
}
/* }}} */
/* {{{ gets and attaches a shared memory segment */
PHP_FUNCTION(shmop_open)
{
zend_long key, mode, size;
php_shmop *shmop;
struct shmid_ds shm;
char *flags;
size_t flags_len;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "lsll", &key, &flags, &flags_len, &mode, &size) == FAILURE) {
RETURN_THROWS();
}
if (flags_len != 1) {
zend_argument_value_error(2, "must be a valid access mode");
RETURN_THROWS();
}
object_init_ex(return_value, shmop_ce);
shmop = Z_SHMOP_P(return_value);
shmop->key = key;
shmop->shmflg |= mode;
switch (flags[0])
{
case 'a':
shmop->shmatflg |= SHM_RDONLY;
break;
case 'c':
shmop->shmflg |= IPC_CREAT;
shmop->size = size;
break;
case 'n':
shmop->shmflg |= (IPC_CREAT | IPC_EXCL);
shmop->size = size;
break;
case 'w':
/* noop
shm segment is being opened for read & write
will fail if segment does not exist
*/
break;
default:
zend_argument_value_error(2, "must be a valid access mode");
goto err;
}
if (shmop->shmflg & IPC_CREAT && shmop->size < 1) {
zend_argument_value_error(4, "must be greater than 0 for the \"c\" and \"n\" access modes");
goto err;
}
shmop->shmid = shmget(shmop->key, shmop->size, shmop->shmflg);
if (shmop->shmid == -1) {
php_error_docref(NULL, E_WARNING, "Unable to attach or create shared memory segment \"%s\"", strerror(errno));
goto err;
}
if (shmctl(shmop->shmid, IPC_STAT, &shm)) {
/* please do not add coverage here: the segment would be leaked and impossible to delete via php */
php_error_docref(NULL, E_WARNING, "Unable to get shared memory segment information \"%s\"", strerror(errno));
goto err;
}
if (shm.shm_segsz > ZEND_LONG_MAX) {
zend_argument_value_error(4, "is too large");
goto err;
}
shmop->addr = shmat(shmop->shmid, 0, shmop->shmatflg);
if (shmop->addr == (char*) -1) {
php_error_docref(NULL, E_WARNING, "Unable to attach to shared memory segment \"%s\"", strerror(errno));
goto err;
}
shmop->size = shm.shm_segsz;
return;
err:
zend_object_release(Z_OBJ_P(return_value));
RETURN_FALSE;
}
/* }}} */
/* {{{ reads from a shm segment */
PHP_FUNCTION(shmop_read)
{
zval *shmid;
zend_long start, count;
php_shmop *shmop;
char *startaddr;
int bytes;
zend_string *return_string;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "Oll", &shmid, shmop_ce, &start, &count) == FAILURE) {
RETURN_THROWS();
}
shmop = Z_SHMOP_P(shmid);
if (start < 0 || start > shmop->size) {
zend_argument_value_error(2, "must be between 0 and the segment size");
RETURN_THROWS();
}
if (count < 0 || start > (ZEND_LONG_MAX - count) || start + count > shmop->size) {
zend_argument_value_error(3, "is out of range");
RETURN_THROWS();
}
startaddr = shmop->addr + start;
bytes = count ? count : shmop->size - start;
return_string = zend_string_init(startaddr, bytes, 0);
RETURN_NEW_STR(return_string);
}
/* }}} */
/* {{{ used to close a shared memory segment; now a NOP */
PHP_FUNCTION(shmop_close)
{
zval *shmid;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "O", &shmid, shmop_ce) == FAILURE) {
RETURN_THROWS();
}
}
/* }}} */
/* {{{ returns the shm size */
PHP_FUNCTION(shmop_size)
{
zval *shmid;
php_shmop *shmop;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "O", &shmid, shmop_ce) == FAILURE) {
RETURN_THROWS();
}
shmop = Z_SHMOP_P(shmid);
RETURN_LONG(shmop->size);
}
/* }}} */
/* {{{ writes to a shared memory segment */
PHP_FUNCTION(shmop_write)
{
php_shmop *shmop;
zend_long writesize;
zend_long offset;
zend_string *data;
zval *shmid;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "OSl", &shmid, shmop_ce, &data, &offset) == FAILURE) {
RETURN_THROWS();
}
shmop = Z_SHMOP_P(shmid);
if ((shmop->shmatflg & SHM_RDONLY) == SHM_RDONLY) {
zend_throw_error(NULL, "Read-only segment cannot be written");
RETURN_THROWS();
}
if (offset < 0 || offset > shmop->size) {
zend_argument_value_error(3, "is out of range");
RETURN_THROWS();
}
writesize = ((zend_long)ZSTR_LEN(data) < shmop->size - offset) ? (zend_long)ZSTR_LEN(data) : shmop->size - offset;
memcpy(shmop->addr + offset, ZSTR_VAL(data), writesize);
RETURN_LONG(writesize);
}
/* }}} */
/* {{{ mark segment for deletion */
PHP_FUNCTION(shmop_delete)
{
zval *shmid;
php_shmop *shmop;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "O", &shmid, shmop_ce) == FAILURE) {
RETURN_THROWS();
}
shmop = Z_SHMOP_P(shmid);
if (shmctl(shmop->shmid, IPC_RMID, NULL)) {
php_error_docref(NULL, E_WARNING, "Can't mark segment for deletion (are you the owner?)");
RETURN_FALSE;
}
RETURN_TRUE;
}
/* }}} */
#endif /* HAVE_SHMOP */
| 8,206 | 23.645646 | 115 |
c
|
php-src
|
php-src-master/ext/shmop/shmop_arginfo.h
|
/* This is a generated file, edit the .stub.php file instead.
* Stub hash: 6055f4edb68a7caed517dbb80f4d5265865dd91d */
ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_shmop_open, 0, 4, Shmop, MAY_BE_FALSE)
ZEND_ARG_TYPE_INFO(0, key, IS_LONG, 0)
ZEND_ARG_TYPE_INFO(0, mode, IS_STRING, 0)
ZEND_ARG_TYPE_INFO(0, permissions, IS_LONG, 0)
ZEND_ARG_TYPE_INFO(0, size, IS_LONG, 0)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_shmop_read, 0, 3, IS_STRING, 0)
ZEND_ARG_OBJ_INFO(0, shmop, Shmop, 0)
ZEND_ARG_TYPE_INFO(0, offset, IS_LONG, 0)
ZEND_ARG_TYPE_INFO(0, size, IS_LONG, 0)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_shmop_close, 0, 1, IS_VOID, 0)
ZEND_ARG_OBJ_INFO(0, shmop, Shmop, 0)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_shmop_size, 0, 1, IS_LONG, 0)
ZEND_ARG_OBJ_INFO(0, shmop, Shmop, 0)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_shmop_write, 0, 3, IS_LONG, 0)
ZEND_ARG_OBJ_INFO(0, shmop, Shmop, 0)
ZEND_ARG_TYPE_INFO(0, data, IS_STRING, 0)
ZEND_ARG_TYPE_INFO(0, offset, IS_LONG, 0)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_shmop_delete, 0, 1, _IS_BOOL, 0)
ZEND_ARG_OBJ_INFO(0, shmop, Shmop, 0)
ZEND_END_ARG_INFO()
ZEND_FUNCTION(shmop_open);
ZEND_FUNCTION(shmop_read);
ZEND_FUNCTION(shmop_close);
ZEND_FUNCTION(shmop_size);
ZEND_FUNCTION(shmop_write);
ZEND_FUNCTION(shmop_delete);
static const zend_function_entry ext_functions[] = {
ZEND_FE(shmop_open, arginfo_shmop_open)
ZEND_FE(shmop_read, arginfo_shmop_read)
ZEND_DEP_FE(shmop_close, arginfo_shmop_close)
ZEND_FE(shmop_size, arginfo_shmop_size)
ZEND_FE(shmop_write, arginfo_shmop_write)
ZEND_FE(shmop_delete, arginfo_shmop_delete)
ZEND_FE_END
};
static const zend_function_entry class_Shmop_methods[] = {
ZEND_FE_END
};
static zend_class_entry *register_class_Shmop(void)
{
zend_class_entry ce, *class_entry;
INIT_CLASS_ENTRY(ce, "Shmop", class_Shmop_methods);
class_entry = zend_register_internal_class_ex(&ce, NULL);
class_entry->ce_flags |= ZEND_ACC_FINAL|ZEND_ACC_NO_DYNAMIC_PROPERTIES|ZEND_ACC_NOT_SERIALIZABLE;
return class_entry;
}
| 2,172 | 30.492754 | 98 |
h
|
php-src
|
php-src-master/ext/simplexml/php_simplexml.h
|
/*
+----------------------------------------------------------------------+
| Copyright (c) The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| https://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| [email protected] so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Author: Sterling Hughes <[email protected]> |
+----------------------------------------------------------------------+
*/
#ifndef PHP_SIMPLEXML_H
#define PHP_SIMPLEXML_H
extern zend_module_entry simplexml_module_entry;
#define phpext_simplexml_ptr &simplexml_module_entry
#include "php_version.h"
#define PHP_SIMPLEXML_VERSION PHP_VERSION
#ifdef ZTS
#include "TSRM.h"
#endif
#include "ext/libxml/php_libxml.h"
#include <libxml/parser.h>
#include <libxml/parserInternals.h>
#include <libxml/tree.h>
#include <libxml/uri.h>
#include <libxml/xmlerror.h>
#include <libxml/xinclude.h>
#include <libxml/xpath.h>
#include <libxml/xpathInternals.h>
#include <libxml/xpointer.h>
#include <libxml/xmlschemas.h>
PHP_MINIT_FUNCTION(simplexml);
PHP_MSHUTDOWN_FUNCTION(simplexml);
PHP_MINFO_FUNCTION(simplexml);
typedef enum {
SXE_ITER_NONE = 0,
SXE_ITER_ELEMENT = 1,
SXE_ITER_CHILD = 2,
SXE_ITER_ATTRLIST = 3
} SXE_ITER;
typedef struct {
php_libxml_node_ptr *node;
php_libxml_ref_obj *document;
HashTable *properties;
xmlXPathContextPtr xpath;
struct {
xmlChar *name;
xmlChar *nsprefix;
int isprefix;
SXE_ITER type;
zval data;
} iter;
zval tmp;
zend_function *fptr_count;
zend_object zo;
} php_sxe_object;
#ifdef PHP_WIN32
# ifdef PHP_SIMPLEXML_EXPORTS
# define PHP_SXE_API __declspec(dllexport)
# else
# define PHP_SXE_API __declspec(dllimport)
# endif
#else
# define PHP_SXE_API ZEND_API
#endif
extern PHP_SXE_API zend_class_entry *ce_SimpleXMLIterator;
extern PHP_SXE_API zend_class_entry *ce_SimpleXMLElement;
PHP_SXE_API zend_class_entry *sxe_get_element_class_entry(void);
#endif
| 2,553 | 28.697674 | 74 |
h
|
php-src
|
php-src-master/ext/simplexml/php_simplexml_exports.h
|
/*
+----------------------------------------------------------------------+
| Copyright (c) The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| https://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| [email protected] so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Author: Sterling Hughes <[email protected]> |
| Marcus Boerger <[email protected]> |
| Rob Richards <[email protected]> |
+----------------------------------------------------------------------+
*/
#ifndef PHP_SIMPLEXML_EXPORTS_H
#define PHP_SIMPLEXML_EXPORTS_H
#include "php_simplexml.h"
#define SKIP_TEXT(__p) \
if ((__p)->type == XML_TEXT_NODE) { \
goto next_iter; \
}
#define GET_NODE(__s, __n) { \
if ((__s)->node && (__s)->node->node) { \
__n = (__s)->node->node; \
} else { \
__n = NULL; \
zend_throw_error(NULL, "SimpleXMLElement is not properly initialized"); \
} \
}
PHP_SXE_API zend_object *sxe_object_new(zend_class_entry *ce);
static inline php_sxe_object *php_sxe_fetch_object(zend_object *obj) /* {{{ */ {
return (php_sxe_object *)((char*)(obj) - XtOffsetOf(php_sxe_object, zo));
}
/* }}} */
#define Z_SXEOBJ_P(zv) php_sxe_fetch_object(Z_OBJ_P((zv)))
typedef struct {
zend_object_iterator intern;
php_sxe_object *sxe;
} php_sxe_iterator;
PHP_SXE_API void php_sxe_rewind_iterator(php_sxe_object *sxe);
PHP_SXE_API void php_sxe_move_forward_iterator(php_sxe_object *sxe);
#endif /* PHP_SIMPLEXML_EXPORTS_H */
| 2,089 | 36.321429 | 80 |
h
|
php-src
|
php-src-master/ext/skeleton/skeleton.c
|
%HEADER%
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include "php.h"
#include "ext/standard/info.h"
#include "php_%EXTNAME%.h"
#include "%EXTNAME%_arginfo.h"
/* For compatibility with older PHP versions */
#ifndef ZEND_PARSE_PARAMETERS_NONE
#define ZEND_PARSE_PARAMETERS_NONE() \
ZEND_PARSE_PARAMETERS_START(0, 0) \
ZEND_PARSE_PARAMETERS_END()
#endif
/* {{{ void test1() */
PHP_FUNCTION(test1)
{
ZEND_PARSE_PARAMETERS_NONE();
php_printf("The extension %s is loaded and working!\r\n", "%EXTNAME%");
}
/* }}} */
/* {{{ string test2( [ string $var ] ) */
PHP_FUNCTION(test2)
{
char *var = "World";
size_t var_len = sizeof("World") - 1;
zend_string *retval;
ZEND_PARSE_PARAMETERS_START(0, 1)
Z_PARAM_OPTIONAL
Z_PARAM_STRING(var, var_len)
ZEND_PARSE_PARAMETERS_END();
retval = strpprintf(0, "Hello %s", var);
RETURN_STR(retval);
}
/* }}}*/
/* {{{ PHP_RINIT_FUNCTION */
PHP_RINIT_FUNCTION(%EXTNAME%)
{
#if defined(ZTS) && defined(COMPILE_DL_%EXTNAMECAPS%)
ZEND_TSRMLS_CACHE_UPDATE();
#endif
return SUCCESS;
}
/* }}} */
/* {{{ PHP_MINFO_FUNCTION */
PHP_MINFO_FUNCTION(%EXTNAME%)
{
php_info_print_table_start();
php_info_print_table_row(2, "%EXTNAME% support", "enabled");
php_info_print_table_end();
}
/* }}} */
/* {{{ %EXTNAME%_module_entry */
zend_module_entry %EXTNAME%_module_entry = {
STANDARD_MODULE_HEADER,
"%EXTNAME%", /* Extension name */
ext_functions, /* zend_function_entry */
NULL, /* PHP_MINIT - Module initialization */
NULL, /* PHP_MSHUTDOWN - Module shutdown */
PHP_RINIT(%EXTNAME%), /* PHP_RINIT - Request initialization */
NULL, /* PHP_RSHUTDOWN - Request shutdown */
PHP_MINFO(%EXTNAME%), /* PHP_MINFO - Module info */
PHP_%EXTNAMECAPS%_VERSION, /* Version */
STANDARD_MODULE_PROPERTIES
};
/* }}} */
#ifdef COMPILE_DL_%EXTNAMECAPS%
# ifdef ZTS
ZEND_TSRMLS_CACHE_DEFINE()
# endif
ZEND_GET_MODULE(%EXTNAME%)
#endif
| 1,907 | 20.931034 | 72 |
c
|
php-src
|
php-src-master/ext/skeleton/skeleton_arginfo.h
|
/* This is a generated file, edit the .stub.php file instead.
* Stub hash: 54b0ffc3af871b189435266df516f7575c1b9675 */
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_test1, 0, 0, IS_VOID, 0)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_test2, 0, 0, IS_STRING, 0)
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, str, IS_STRING, 0, "\"\"")
ZEND_END_ARG_INFO()
ZEND_FUNCTION(test1);
ZEND_FUNCTION(test2);
static const zend_function_entry ext_functions[] = {
ZEND_FE(test1, arginfo_test1)
ZEND_FE(test2, arginfo_test2)
ZEND_FE_END
};
| 558 | 25.619048 | 74 |
h
|
php-src
|
php-src-master/ext/snmp/php_snmp.h
|
/*
+----------------------------------------------------------------------+
| Copyright (c) The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| https://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| [email protected] so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Authors: Rasmus Lerdorf <[email protected]> |
| Mike Jackson <[email protected]> |
| Steven Lawrance <[email protected]> |
| Harrie Hazewinkel <[email protected]> |
| Johann Hanne <[email protected]> |
| Boris Lytockin <[email protected]> |
+----------------------------------------------------------------------+
*/
#ifndef PHP_SNMP_H
#define PHP_SNMP_H
#define PHP_SNMP_VERSION PHP_VERSION
#ifdef HAVE_SNMP
#ifndef DLEXPORT
#define DLEXPORT
#endif
extern zend_module_entry snmp_module_entry;
#define snmp_module_ptr &snmp_module_entry
#ifdef ZTS
#include "TSRM.h"
#endif
#include <net-snmp/net-snmp-config.h>
#include <net-snmp/net-snmp-includes.h>
PHP_MINIT_FUNCTION(snmp);
PHP_MSHUTDOWN_FUNCTION(snmp);
PHP_MINFO_FUNCTION(snmp);
typedef struct _php_snmp_object {
struct snmp_session *session;
int max_oids;
int valueretrieval;
int quick_print;
int enum_print;
int oid_output_format;
int snmp_errno;
int oid_increasing_check;
int exceptions_enabled;
char snmp_errstr[256];
zend_object zo;
} php_snmp_object;
static inline php_snmp_object *php_snmp_fetch_object(zend_object *obj) {
return (php_snmp_object *)((char*)(obj) - XtOffsetOf(php_snmp_object, zo));
}
#define Z_SNMP_P(zv) php_snmp_fetch_object(Z_OBJ_P((zv)))
typedef int (*php_snmp_read_t)(php_snmp_object *snmp_object, zval *retval);
typedef int (*php_snmp_write_t)(php_snmp_object *snmp_object, zval *newval);
typedef struct _ptp_snmp_prop_handler {
const char *name;
size_t name_length;
php_snmp_read_t read_func;
php_snmp_write_t write_func;
} php_snmp_prop_handler;
typedef struct _snmpobjarg {
char *oid;
char type;
char *value;
oid name[MAX_OID_LEN];
size_t name_length;
} snmpobjarg;
ZEND_BEGIN_MODULE_GLOBALS(snmp)
int valueretrieval;
ZEND_END_MODULE_GLOBALS(snmp)
#ifdef ZTS
#define SNMP_G(v) TSRMG(snmp_globals_id, zend_snmp_globals *, v)
#else
#define SNMP_G(v) (snmp_globals.v)
#endif
#define SNMP_VALUE_LIBRARY (0 << 0)
#define SNMP_VALUE_PLAIN (1 << 0)
#define SNMP_VALUE_OBJECT (1 << 1)
#define PHP_SNMP_ERRNO_NOERROR 0
#define PHP_SNMP_ERRNO_GENERIC (1 << 1)
#define PHP_SNMP_ERRNO_TIMEOUT (1 << 2)
#define PHP_SNMP_ERRNO_ERROR_IN_REPLY (1 << 3)
#define PHP_SNMP_ERRNO_OID_NOT_INCREASING (1 << 4)
#define PHP_SNMP_ERRNO_OID_PARSING_ERROR (1 << 5)
#define PHP_SNMP_ERRNO_MULTIPLE_SET_QUERIES (1 << 6)
#define PHP_SNMP_ERRNO_ANY ( \
PHP_SNMP_ERRNO_GENERIC | \
PHP_SNMP_ERRNO_TIMEOUT | \
PHP_SNMP_ERRNO_ERROR_IN_REPLY | \
PHP_SNMP_ERRNO_OID_NOT_INCREASING | \
PHP_SNMP_ERRNO_OID_PARSING_ERROR | \
PHP_SNMP_ERRNO_MULTIPLE_SET_QUERIES | \
PHP_SNMP_ERRNO_NOERROR \
)
#else
#define snmp_module_ptr NULL
#endif /* HAVE_SNMP */
#define phpext_snmp_ptr snmp_module_ptr
#endif /* PHP_SNMP_H */
| 3,769 | 29.16 | 76 |
h
|
php-src
|
php-src-master/ext/soap/php_encoding.h
|
/*
+----------------------------------------------------------------------+
| Copyright (c) The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| https://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| [email protected] so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Authors: Brad Lafountain <[email protected]> |
| Shane Caraveo <[email protected]> |
| Dmitry Stogov <[email protected]> |
+----------------------------------------------------------------------+
*/
#ifndef PHP_ENCODING_H
#define PHP_ENCODING_H
#define XSD_1999_NAMESPACE "http://www.w3.org/1999/XMLSchema"
#define XSD_1999_TIMEINSTANT 401
#define XSD_1999_TIMEINSTANT_STRING "timeInstant"
#define SOAP_1_1_ENV_NAMESPACE "http://schemas.xmlsoap.org/soap/envelope/"
#define SOAP_1_1_ENV_NS_PREFIX "SOAP-ENV"
#define SOAP_1_2_ENV_NAMESPACE "http://www.w3.org/2003/05/soap-envelope"
#define SOAP_1_2_ENV_NS_PREFIX "env"
#define SOAP_1_1_ENC_NAMESPACE "http://schemas.xmlsoap.org/soap/encoding/"
#define SOAP_1_1_ENC_NS_PREFIX "SOAP-ENC"
#define SOAP_1_2_ENC_NAMESPACE "http://www.w3.org/2003/05/soap-encoding"
#define SOAP_1_2_ENC_NS_PREFIX "enc"
#define SCHEMA_NAMESPACE "http://www.w3.org/2001/XMLSchema"
#define XSD_NAMESPACE "http://www.w3.org/2001/XMLSchema"
#define XSD_NS_PREFIX "xsd"
#define XSI_NAMESPACE "http://www.w3.org/2001/XMLSchema-instance"
#define XSI_NS_PREFIX "xsi"
#define XML_NAMESPACE "http://www.w3.org/XML/1998/namespace"
#define XML_NS_PREFIX "xml"
#define XSD_STRING 101
#define XSD_STRING_STRING "string"
#define XSD_BOOLEAN 102
#define XSD_BOOLEAN_STRING "boolean"
#define XSD_DECIMAL 103
#define XSD_DECIMAL_STRING "decimal"
#define XSD_FLOAT 104
#define XSD_FLOAT_STRING "float"
#define XSD_DOUBLE 105
#define XSD_DOUBLE_STRING "double"
#define XSD_DURATION 106
#define XSD_DURATION_STRING "duration"
#define XSD_DATETIME 107
#define XSD_DATETIME_STRING "dateTime"
#define XSD_TIME 108
#define XSD_TIME_STRING "time"
#define XSD_DATE 109
#define XSD_DATE_STRING "date"
#define XSD_GYEARMONTH 110
#define XSD_GYEARMONTH_STRING "gYearMonth"
#define XSD_GYEAR 111
#define XSD_GYEAR_STRING "gYear"
#define XSD_GMONTHDAY 112
#define XSD_GMONTHDAY_STRING "gMonthDay"
#define XSD_GDAY 113
#define XSD_GDAY_STRING "gDay"
#define XSD_GMONTH 114
#define XSD_GMONTH_STRING "gMonth"
#define XSD_HEXBINARY 115
#define XSD_HEXBINARY_STRING "hexBinary"
#define XSD_BASE64BINARY 116
#define XSD_BASE64BINARY_STRING "base64Binary"
#define XSD_ANYURI 117
#define XSD_ANYURI_STRING "anyURI"
#define XSD_QNAME 118
#define XSD_QNAME_STRING "QName"
#define XSD_NOTATION 119
#define XSD_NOTATION_STRING "NOTATION"
#define XSD_NORMALIZEDSTRING 120
#define XSD_NORMALIZEDSTRING_STRING "normalizedString"
#define XSD_TOKEN 121
#define XSD_TOKEN_STRING "token"
#define XSD_LANGUAGE 122
#define XSD_LANGUAGE_STRING "language"
#define XSD_NMTOKEN 123
#define XSD_NMTOKEN_STRING "NMTOKEN"
#define XSD_NAME 124
#define XSD_NAME_STRING "Name"
#define XSD_NCNAME 125
#define XSD_NCNAME_STRING "NCName"
#define XSD_ID 126
#define XSD_ID_STRING "ID"
#define XSD_IDREF 127
#define XSD_IDREF_STRING "IDREF"
#define XSD_IDREFS 128
#define XSD_IDREFS_STRING "IDREFS"
#define XSD_ENTITY 129
#define XSD_ENTITY_STRING "ENTITY"
#define XSD_ENTITIES 130
#define XSD_ENTITIES_STRING "ENTITIES"
#define XSD_INTEGER 131
#define XSD_INTEGER_STRING "integer"
#define XSD_NONPOSITIVEINTEGER 132
#define XSD_NONPOSITIVEINTEGER_STRING "nonPositiveInteger"
#define XSD_NEGATIVEINTEGER 133
#define XSD_NEGATIVEINTEGER_STRING "negativeInteger"
#define XSD_LONG 134
#define XSD_LONG_STRING "long"
#define XSD_INT 135
#define XSD_INT_STRING "int"
#define XSD_SHORT 136
#define XSD_SHORT_STRING "short"
#define XSD_BYTE 137
#define XSD_BYTE_STRING "byte"
#define XSD_NONNEGATIVEINTEGER 138
#define XSD_NONNEGATIVEINTEGER_STRING "nonNegativeInteger"
#define XSD_UNSIGNEDLONG 139
#define XSD_UNSIGNEDLONG_STRING "unsignedLong"
#define XSD_UNSIGNEDINT 140
#define XSD_UNSIGNEDINT_STRING "unsignedInt"
#define XSD_UNSIGNEDSHORT 141
#define XSD_UNSIGNEDSHORT_STRING "unsignedShort"
#define XSD_UNSIGNEDBYTE 142
#define XSD_UNSIGNEDBYTE_STRING "unsignedByte"
#define XSD_POSITIVEINTEGER 143
#define XSD_POSITIVEINTEGER_STRING "positiveInteger"
#define XSD_NMTOKENS 144
#define XSD_NMTOKENS_STRING "NMTOKENS"
#define XSD_ANYTYPE 145
#define XSD_ANYTYPE_STRING "anyType"
#define XSD_UR_TYPE 146
#define XSD_UR_TYPE_STRING "ur-type"
#define XSD_ANYXML 147
#define APACHE_NAMESPACE "http://xml.apache.org/xml-soap"
#define APACHE_MAP 200
#define APACHE_MAP_STRING "Map"
#define SOAP_ENC_ARRAY 300
#define SOAP_ENC_ARRAY_STRING "Array"
#define SOAP_ENC_OBJECT 301
#define SOAP_ENC_OBJECT_STRING "Struct"
#define WSDL_NAMESPACE "http://schemas.xmlsoap.org/wsdl/"
#define WSDL_NS_PREFIX "wsdl"
#define WSDL_SOAP11_NAMESPACE "http://schemas.xmlsoap.org/wsdl/soap/"
#define WSDL_SOAP12_NAMESPACE "http://schemas.xmlsoap.org/wsdl/soap12/"
#define RPC_SOAP12_NAMESPACE "http://www.w3.org/2003/05/soap-rpc"
#define RPC_SOAP12_NS_PREFIX "rpc"
#define WSDL_HTTP11_NAMESPACE "http://schemas.xmlsoap.org/wsdl/http/"
#define WSDL_HTTP12_NAMESPACE "http://www.w3.org/2003/05/soap/bindings/HTTP/"
#define WSDL_HTTP_NS_PREFIX "http"
#define WSDL_HTTP_TRANSPORT "http://schemas.xmlsoap.org/soap/http"
#define WSDL_MIME_NAMESPACE "http://schemas.xmlsoap.org/wsdl/mime/"
#define WSDL_DIME_NAMESPACE "http://schemas.xmlsoap.org/ws/2002/04/dime/wsdl/"
#define WSDL_DIME_OPEN "http://schemas.xmlsoap.org/ws/2002/04/dime/open-layout"
#define WSDL_DIME_CLOSED "http://schemas.xmlsoap.org/ws/2002/04/dime/closed-layout"
#define UNKNOWN_TYPE 999998
#define END_KNOWN_TYPES 999999
#define Z_VAR_ENC_TYPE_P(zv) php_soap_deref(OBJ_PROP_NUM(Z_OBJ_P(zv), 0))
#define Z_VAR_ENC_VALUE_P(zv) php_soap_deref(OBJ_PROP_NUM(Z_OBJ_P(zv), 1))
#define Z_VAR_ENC_STYPE_P(zv) php_soap_deref(OBJ_PROP_NUM(Z_OBJ_P(zv), 2))
#define Z_VAR_ENC_NS_P(zv) php_soap_deref(OBJ_PROP_NUM(Z_OBJ_P(zv), 3))
#define Z_VAR_ENC_NAME_P(zv) php_soap_deref(OBJ_PROP_NUM(Z_OBJ_P(zv), 4))
#define Z_VAR_ENC_NAMENS_P(zv) php_soap_deref(OBJ_PROP_NUM(Z_OBJ_P(zv), 5))
struct _encodeType {
int type;
char *type_str;
char *ns;
sdlTypePtr sdl_type;
soapMappingPtr map;
};
struct _encode {
encodeType details;
zval *(*to_zval)(zval *ret, encodeTypePtr type, xmlNodePtr data);
xmlNodePtr (*to_xml)(encodeTypePtr type, zval *data, int style, xmlNodePtr parent);
};
/* Master functions all encode/decode should be called thur these functions */
xmlNodePtr master_to_xml(encodePtr encode, zval *data, int style, xmlNodePtr parent);
zval *master_to_zval(zval *ret, encodePtr encode, xmlNodePtr data);
/* user defined mapping */
xmlNodePtr to_xml_user(encodeTypePtr type, zval *data, int style, xmlNodePtr parent);
zval *to_zval_user(zval *ret, encodeTypePtr type, xmlNodePtr node);
void whiteSpace_replace(xmlChar* str);
void whiteSpace_collapse(xmlChar* str);
xmlNodePtr sdl_guess_convert_xml(encodeTypePtr enc, zval* data, int style, xmlNodePtr parent);
zval *sdl_guess_convert_zval(zval *ret, encodeTypePtr enc, xmlNodePtr data);
void encode_finish(void);
void encode_reset_ns(void);
xmlNsPtr encode_add_ns(xmlNodePtr node, const char* ns);
encodePtr get_conversion(int encode);
void delete_encoder(zval *zv);
void delete_encoder_persistent(zval *zv);
extern const encode defaultEncoding[];
extern int numDefaultEncodings;
#endif
| 7,997 | 35.190045 | 94 |
h
|
php-src
|
php-src-master/ext/soap/php_http.h
|
/*
+----------------------------------------------------------------------+
| Copyright (c) The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| https://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| [email protected] so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Authors: Brad Lafountain <[email protected]> |
| Shane Caraveo <[email protected]> |
| Dmitry Stogov <[email protected]> |
+----------------------------------------------------------------------+
*/
#ifndef PHP_HTTP_H
#define PHP_HTTP_H
int make_http_soap_request(zval *this_ptr,
zend_string *request,
char *location,
char *soapaction,
int soap_version,
zval *response);
int proxy_authentication(zval* this_ptr, smart_str* soap_headers);
int basic_authentication(zval* this_ptr, smart_str* soap_headers);
void http_context_headers(php_stream_context* context,
bool has_authorization,
bool has_proxy_authorization,
bool has_cookies,
smart_str* soap_headers);
#endif
| 1,876 | 49.72973 | 74 |
h
|
php-src
|
php-src-master/ext/soap/php_schema.h
|
/*
+----------------------------------------------------------------------+
| Copyright (c) The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| https://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| [email protected] so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Authors: Brad Lafountain <[email protected]> |
| Shane Caraveo <[email protected]> |
| Dmitry Stogov <[email protected]> |
+----------------------------------------------------------------------+
*/
#ifndef PHP_SCHEMA_H
#define PHP_SCHEMA_H
int load_schema(sdlCtx *ctx, xmlNodePtr schema);
void schema_pass2(sdlCtx *ctx);
void delete_model(zval *zv);
void delete_model_persistent(zval *zv);
void delete_type(zval *zv);
void delete_type_persistent(zval *zv);
void delete_extra_attribute(zval *zv);
void delete_extra_attribute_persistent(zval *zv);
void delete_attribute(zval *zv);
void delete_attribute_persistent(zval *zv);
void delete_restriction_var_int(sdlRestrictionIntPtr ptr);
void delete_restriction_var_int_persistent(sdlRestrictionIntPtr ptr);
void delete_restriction_var_char(zval *zv);
void delete_restriction_var_char_int(sdlRestrictionCharPtr ptr);
void delete_restriction_var_char_persistent(zval *zv);
void delete_restriction_var_char_persistent_int(sdlRestrictionCharPtr ptr);
#endif
| 1,935 | 47.4 | 75 |
h
|
php-src
|
php-src-master/ext/soap/php_sdl.h
|
/*
+----------------------------------------------------------------------+
| Copyright (c) The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| https://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| [email protected] so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Authors: Brad Lafountain <[email protected]> |
| Shane Caraveo <[email protected]> |
| Dmitry Stogov <[email protected]> |
+----------------------------------------------------------------------+
*/
#ifndef PHP_SDL_H
#define PHP_SDL_H
#define XSD_WHITESPACE_COLLAPSE 1
#define XSD_WHITESPACE_PRESERVE 1
#define XSD_WHITESPACE_REPLACE 1
typedef enum _sdlBindingType {
BINDING_SOAP = 1,
BINDING_HTTP = 2
} sdlBindingType;
typedef enum _sdlEncodingStyle {
SOAP_RPC = 1,
SOAP_DOCUMENT = 2
} sdlEncodingStyle;
typedef enum _sdlRpcEncodingStyle {
SOAP_ENCODING_DEFAULT = 0,
SOAP_ENCODING_1_1 = 1,
SOAP_ENCODING_1_2 = 2
} sdlRpcEncodingStyle;
typedef enum _sdlEncodingUse {
SOAP_ENCODED = 1,
SOAP_LITERAL = 2
} sdlEncodingUse;
typedef enum _sdlTransport {
SOAP_TRANSPORT_HTTP = 1
} sdlTransport;
struct _sdl {
HashTable functions; /* array of sdlFunction */
HashTable *types; /* array of sdlTypesPtr */
HashTable *elements; /* array of sdlTypesPtr */
HashTable *encoders; /* array of encodePtr */
HashTable *bindings; /* array of sdlBindings (key'd by name) */
HashTable *requests; /* array of sdlFunction (references) */
HashTable *groups; /* array of sdlTypesPtr */
char *target_ns;
char *source;
bool is_persistent;
};
typedef struct sdlCtx {
sdlPtr sdl;
HashTable docs; /* array of xmlDocPtr */
HashTable messages; /* array of xmlNodePtr */
HashTable bindings; /* array of xmlNodePtr */
HashTable portTypes; /* array of xmlNodePtr */
HashTable services; /* array of xmlNodePtr */
HashTable *attributes; /* array of sdlAttributePtr */
HashTable *attributeGroups; /* array of sdlTypesPtr */
php_stream_context *context;
zval old_header;
} sdlCtx;
struct _sdlBinding {
char *name;
char *location;
sdlBindingType bindingType;
void *bindingAttributes; /* sdlSoapBindingPtr */
};
/* Soap Binding Specific stuff */
struct _sdlSoapBinding {
sdlEncodingStyle style;
sdlTransport transport; /* not implemented yet */
};
typedef struct _sdlSoapBindingFunctionHeader {
char *name;
char *ns;
sdlEncodingUse use;
sdlTypePtr element;
encodePtr encode;
sdlRpcEncodingStyle encodingStyle; /* not implemented yet */
HashTable *headerfaults; /* array of sdlSoapBindingFunctionHeaderPtr */
} sdlSoapBindingFunctionHeader, *sdlSoapBindingFunctionHeaderPtr;
typedef struct _sdlSoapBindingFunctionFault {
char *ns;
sdlEncodingUse use;
sdlRpcEncodingStyle encodingStyle; /* not implemented yet */
} sdlSoapBindingFunctionFault, *sdlSoapBindingFunctionFaultPtr;
struct _sdlSoapBindingFunctionBody {
char *ns;
sdlEncodingUse use;
sdlRpcEncodingStyle encodingStyle; /* not implemented yet */
HashTable *headers; /* array of sdlSoapBindingFunctionHeaderPtr */
};
struct _sdlSoapBindingFunction {
char *soapAction;
sdlEncodingStyle style;
sdlSoapBindingFunctionBody input;
sdlSoapBindingFunctionBody output;
};
struct _sdlRestrictionInt {
int value;
char fixed;
};
struct _sdlRestrictionChar {
char *value;
char fixed;
};
struct _sdlRestrictions {
HashTable *enumeration; /* array of sdlRestrictionCharPtr */
sdlRestrictionIntPtr minExclusive;
sdlRestrictionIntPtr minInclusive;
sdlRestrictionIntPtr maxExclusive;
sdlRestrictionIntPtr maxInclusive;
sdlRestrictionIntPtr totalDigits;
sdlRestrictionIntPtr fractionDigits;
sdlRestrictionIntPtr length;
sdlRestrictionIntPtr minLength;
sdlRestrictionIntPtr maxLength;
sdlRestrictionCharPtr whiteSpace;
sdlRestrictionCharPtr pattern;
};
typedef enum _sdlContentKind {
XSD_CONTENT_ELEMENT,
XSD_CONTENT_SEQUENCE,
XSD_CONTENT_ALL,
XSD_CONTENT_CHOICE,
XSD_CONTENT_GROUP_REF,
XSD_CONTENT_GROUP,
XSD_CONTENT_ANY
} sdlContentKind;
typedef struct _sdlContentModel sdlContentModel, *sdlContentModelPtr;
struct _sdlContentModel {
sdlContentKind kind;
int min_occurs;
int max_occurs;
union {
sdlTypePtr element; /* pointer to element */
sdlTypePtr group; /* pointer to group */
HashTable *content; /* array of sdlContentModel for sequnce,all,choice*/
char *group_ref; /* reference to group */
} u;
};
typedef enum _sdlTypeKind {
XSD_TYPEKIND_SIMPLE,
XSD_TYPEKIND_LIST,
XSD_TYPEKIND_UNION,
XSD_TYPEKIND_COMPLEX,
XSD_TYPEKIND_RESTRICTION,
XSD_TYPEKIND_EXTENSION
} sdlTypeKind;
typedef enum _sdlUse {
XSD_USE_DEFAULT,
XSD_USE_OPTIONAL,
XSD_USE_PROHIBITED,
XSD_USE_REQUIRED
} sdlUse;
typedef enum _sdlForm {
XSD_FORM_DEFAULT,
XSD_FORM_QUALIFIED,
XSD_FORM_UNQUALIFIED
} sdlForm;
struct _sdlType {
sdlTypeKind kind;
char *name;
char *namens;
char nillable;
HashTable *elements; /* array of sdlTypePtr */
HashTable *attributes; /* array of sdlAttributePtr */
sdlRestrictionsPtr restrictions;
encodePtr encode;
sdlContentModelPtr model;
char *def;
char *fixed;
char *ref;
sdlForm form;
};
struct _sdlParam {
int order;
sdlTypePtr element;
encodePtr encode;
char *paramName;
};
typedef struct _sdlFault {
char *name;
HashTable *details; /* array of sdlParamPtr */
void *bindingAttributes; /* sdlSoapBindingFunctionFaultPtr */
} sdlFault, *sdlFaultPtr;
struct _sdlFunction {
char *functionName;
char *requestName;
char *responseName;
HashTable *requestParameters; /* array of sdlParamPtr */
HashTable *responseParameters; /* array of sdlParamPtr (this should only be one) */
struct _sdlBinding *binding;
void *bindingAttributes; /* sdlSoapBindingFunctionPtr */
HashTable *faults; /* array of sdlFaultPtr */
};
typedef struct _sdlExtraAttribute {
char *ns;
char *val;
} sdlExtraAttribute, *sdlExtraAttributePtr;
struct _sdlAttribute {
char *name;
char *namens;
char *ref;
char *def;
char *fixed;
sdlForm form;
sdlUse use;
HashTable *extraAttributes; /* array of sdlExtraAttribute */
encodePtr encode;
};
sdlPtr get_sdl(zval *this_ptr, char *uri, zend_long cache_wsdl);
encodePtr get_encoder_from_prefix(sdlPtr sdl, xmlNodePtr data, const xmlChar *type);
encodePtr get_encoder(sdlPtr sdl, const char *ns, const char *type);
encodePtr get_encoder_ex(sdlPtr sdl, const char *nscat, int len);
sdlBindingPtr get_binding_from_type(sdlPtr sdl, sdlBindingType type);
sdlBindingPtr get_binding_from_name(sdlPtr sdl, char *name, char *ns);
void delete_sdl(void *handle);
void delete_sdl_impl(void *handle);
void sdl_set_uri_credentials(sdlCtx *ctx, char *uri);
void sdl_restore_uri_credentials(sdlCtx *ctx);
#endif
| 7,975 | 28.540741 | 93 |
h
|
php-src
|
php-src-master/ext/soap/php_soap.h
|
/*
+----------------------------------------------------------------------+
| Copyright (c) The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| https://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| [email protected] so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Authors: Brad Lafountain <[email protected]> |
| Shane Caraveo <[email protected]> |
| Dmitry Stogov <[email protected]> |
+----------------------------------------------------------------------+
*/
#ifndef PHP_SOAP_H
#define PHP_SOAP_H
#include "php.h"
#include "php_globals.h"
#include "ext/standard/info.h"
#include "ext/standard/php_standard.h"
#if defined(HAVE_PHP_SESSION) && !defined(COMPILE_DL_SESSION)
#include "ext/session/php_session.h"
#endif
#include "zend_smart_str.h"
#include "php_ini.h"
#include "SAPI.h"
#include <libxml/parser.h>
#include <libxml/xpath.h>
#define PHP_SOAP_VERSION PHP_VERSION
#ifndef PHP_WIN32
# define TRUE 1
# define FALSE 0
# define stricmp strcasecmp
#endif
extern int le_url;
typedef struct _encodeType encodeType, *encodeTypePtr;
typedef struct _encode encode, *encodePtr;
typedef struct _sdl sdl, *sdlPtr;
typedef struct _sdlRestrictionInt sdlRestrictionInt, *sdlRestrictionIntPtr;
typedef struct _sdlRestrictionChar sdlRestrictionChar, *sdlRestrictionCharPtr;
typedef struct _sdlRestrictions sdlRestrictions, *sdlRestrictionsPtr;
typedef struct _sdlType sdlType, *sdlTypePtr;
typedef struct _sdlParam sdlParam, *sdlParamPtr;
typedef struct _sdlFunction sdlFunction, *sdlFunctionPtr;
typedef struct _sdlAttribute sdlAttribute, *sdlAttributePtr;
typedef struct _sdlBinding sdlBinding, *sdlBindingPtr;
typedef struct _sdlSoapBinding sdlSoapBinding, *sdlSoapBindingPtr;
typedef struct _sdlSoapBindingFunction sdlSoapBindingFunction, *sdlSoapBindingFunctionPtr;
typedef struct _sdlSoapBindingFunctionBody sdlSoapBindingFunctionBody, *sdlSoapBindingFunctionBodyPtr;
typedef struct _soapMapping soapMapping, *soapMappingPtr;
typedef struct _soapService soapService, *soapServicePtr;
#include "php_xml.h"
#include "php_encoding.h"
#include "php_sdl.h"
#include "php_schema.h"
#include "php_http.h"
#include "php_packet_soap.h"
struct _soapMapping {
zval to_xml;
zval to_zval;
};
struct _soapHeader;
struct _soapService {
sdlPtr sdl;
struct _soap_functions {
HashTable *ft;
int functions_all;
} soap_functions;
struct _soap_class {
zend_class_entry *ce;
zval *argv;
int argc;
int persistence;
} soap_class;
zval soap_object;
HashTable *typemap;
int version;
int type;
char *actor;
char *uri;
xmlCharEncodingHandlerPtr encoding;
HashTable *class_map;
int features;
struct _soapHeader **soap_headers_ptr;
int send_errors;
};
#define SOAP_CLASS 1
#define SOAP_FUNCTIONS 2
#define SOAP_OBJECT 3
#define SOAP_FUNCTIONS_ALL 999
#define SOAP_MAP_FUNCTION 1
#define SOAP_MAP_CLASS 2
#define SOAP_PERSISTENCE_SESSION 1
#define SOAP_PERSISTENCE_REQUEST 2
#define SOAP_1_1 1
#define SOAP_1_2 2
#define SOAP_ACTOR_NEXT 1
#define SOAP_ACTOR_NONE 2
#define SOAP_ACTOR_UNLIMATERECEIVER 3
#define SOAP_1_1_ACTOR_NEXT "http://schemas.xmlsoap.org/soap/actor/next"
#define SOAP_1_2_ACTOR_NEXT "http://www.w3.org/2003/05/soap-envelope/role/next"
#define SOAP_1_2_ACTOR_NONE "http://www.w3.org/2003/05/soap-envelope/role/none"
#define SOAP_1_2_ACTOR_UNLIMATERECEIVER "http://www.w3.org/2003/05/soap-envelope/role/ultimateReceiver"
#define SOAP_COMPRESSION_ACCEPT 0x20
#define SOAP_COMPRESSION_GZIP 0x00
#define SOAP_COMPRESSION_DEFLATE 0x10
#define SOAP_AUTHENTICATION_BASIC 0
#define SOAP_AUTHENTICATION_DIGEST 1
#define SOAP_SINGLE_ELEMENT_ARRAYS (1<<0)
#define SOAP_WAIT_ONE_WAY_CALLS (1<<1)
#define SOAP_USE_XSI_ARRAY_TYPE (1<<2)
#define WSDL_CACHE_NONE 0x0
#define WSDL_CACHE_DISK 0x1
#define WSDL_CACHE_MEMORY 0x2
#define WSDL_CACHE_BOTH 0x3
/* New SOAP SSL Method Constants */
#define SOAP_SSL_METHOD_TLS 0
#define SOAP_SSL_METHOD_SSLv2 1
#define SOAP_SSL_METHOD_SSLv3 2
#define SOAP_SSL_METHOD_SSLv23 3
ZEND_BEGIN_MODULE_GLOBALS(soap)
HashTable defEncNs; /* mapping of default namespaces to prefixes */
HashTable defEnc;
HashTable defEncIndex;
HashTable *typemap;
int cur_uniq_ns;
int soap_version;
sdlPtr sdl;
bool use_soap_error_handler;
char* error_code;
zval error_object;
char cache;
char cache_mode;
char cache_enabled;
char* cache_dir;
zend_long cache_ttl;
zend_long cache_limit;
HashTable *mem_cache;
xmlCharEncodingHandlerPtr encoding;
HashTable *class_map;
int features;
HashTable wsdl_cache;
int cur_uniq_ref;
HashTable *ref_map;
ZEND_END_MODULE_GLOBALS(soap)
#ifdef ZTS
#include "TSRM.h"
#endif
extern zend_module_entry soap_module_entry;
#define soap_module_ptr &soap_module_entry
#define phpext_soap_ptr soap_module_ptr
ZEND_EXTERN_MODULE_GLOBALS(soap)
#define SOAP_GLOBAL(v) ZEND_MODULE_GLOBALS_ACCESSOR(soap, v)
#if defined(ZTS) && defined(COMPILE_DL_SOAP)
ZEND_TSRMLS_CACHE_EXTERN()
#endif
extern zend_class_entry* soap_class_entry;
extern zend_class_entry* soap_var_class_entry;
void add_soap_fault(zval *obj, char *fault_code, char *fault_string, char *fault_actor, zval *fault_detail);
#define soap_error0(severity, format) \
php_error(severity, "SOAP-ERROR: " format)
#define soap_error1(severity, format, param1) \
php_error(severity, "SOAP-ERROR: " format, param1)
#define soap_error2(severity, format, param1, param2) \
php_error(severity, "SOAP-ERROR: " format, param1, param2)
#define soap_error3(severity, format, param1, param2, param3) \
php_error(severity, "SOAP-ERROR: " format, param1, param2, param3)
static zend_always_inline zval *php_soap_deref(zval *zv) {
if (UNEXPECTED(Z_TYPE_P(zv) == IS_REFERENCE)) {
return Z_REFVAL_P(zv);
}
return zv;
}
#define Z_CLIENT_URI_P(zv) php_soap_deref(OBJ_PROP_NUM(Z_OBJ_P(zv), 0))
#define Z_CLIENT_STYLE_P(zv) php_soap_deref(OBJ_PROP_NUM(Z_OBJ_P(zv), 1))
#define Z_CLIENT_USE_P(zv) php_soap_deref(OBJ_PROP_NUM(Z_OBJ_P(zv), 2))
#define Z_CLIENT_LOCATION_P(zv) php_soap_deref(OBJ_PROP_NUM(Z_OBJ_P(zv), 3))
#define Z_CLIENT_TRACE_P(zv) php_soap_deref(OBJ_PROP_NUM(Z_OBJ_P(zv), 4))
#define Z_CLIENT_COMPRESSION_P(zv) php_soap_deref(OBJ_PROP_NUM(Z_OBJ_P(zv), 5))
#define Z_CLIENT_SDL_P(zv) php_soap_deref(OBJ_PROP_NUM(Z_OBJ_P(zv), 6))
#define Z_CLIENT_TYPEMAP_P(zv) php_soap_deref(OBJ_PROP_NUM(Z_OBJ_P(zv), 7))
#define Z_CLIENT_HTTPSOCKET_P(zv) php_soap_deref(OBJ_PROP_NUM(Z_OBJ_P(zv), 8))
#define Z_CLIENT_HTTPURL_P(zv) php_soap_deref(OBJ_PROP_NUM(Z_OBJ_P(zv), 9))
#define Z_CLIENT_LOGIN_P(zv) php_soap_deref(OBJ_PROP_NUM(Z_OBJ_P(zv), 10))
#define Z_CLIENT_PASSWORD_P(zv) php_soap_deref(OBJ_PROP_NUM(Z_OBJ_P(zv), 11))
#define Z_CLIENT_USE_DIGEST_P(zv) php_soap_deref(OBJ_PROP_NUM(Z_OBJ_P(zv), 12))
#define Z_CLIENT_DIGEST_P(zv) php_soap_deref(OBJ_PROP_NUM(Z_OBJ_P(zv), 13))
#define Z_CLIENT_PROXY_HOST_P(zv) php_soap_deref(OBJ_PROP_NUM(Z_OBJ_P(zv), 14))
#define Z_CLIENT_PROXY_PORT_P(zv) php_soap_deref(OBJ_PROP_NUM(Z_OBJ_P(zv), 15))
#define Z_CLIENT_PROXY_LOGIN_P(zv) php_soap_deref(OBJ_PROP_NUM(Z_OBJ_P(zv), 16))
#define Z_CLIENT_PROXY_PASSWORD_P(zv) php_soap_deref(OBJ_PROP_NUM(Z_OBJ_P(zv), 17))
#define Z_CLIENT_EXCEPTIONS_P(zv) php_soap_deref(OBJ_PROP_NUM(Z_OBJ_P(zv), 18))
#define Z_CLIENT_ENCODING_P(zv) php_soap_deref(OBJ_PROP_NUM(Z_OBJ_P(zv), 19))
#define Z_CLIENT_CLASSMAP_P(zv) php_soap_deref(OBJ_PROP_NUM(Z_OBJ_P(zv), 20))
#define Z_CLIENT_FEATURES_P(zv) php_soap_deref(OBJ_PROP_NUM(Z_OBJ_P(zv), 21))
#define Z_CLIENT_CONNECTION_TIMEOUT_P(zv) php_soap_deref(OBJ_PROP_NUM(Z_OBJ_P(zv), 22))
#define Z_CLIENT_STREAM_CONTEXT_P(zv) php_soap_deref(OBJ_PROP_NUM(Z_OBJ_P(zv), 23))
#define Z_CLIENT_USER_AGENT_P(zv) php_soap_deref(OBJ_PROP_NUM(Z_OBJ_P(zv), 24))
#define Z_CLIENT_KEEP_ALIVE_P(zv) php_soap_deref(OBJ_PROP_NUM(Z_OBJ_P(zv), 25))
#define Z_CLIENT_SSL_METHOD_P(zv) php_soap_deref(OBJ_PROP_NUM(Z_OBJ_P(zv), 26))
#define Z_CLIENT_SOAP_VERSION_P(zv) php_soap_deref(OBJ_PROP_NUM(Z_OBJ_P(zv), 27))
#define Z_CLIENT_USE_PROXY_P(zv) php_soap_deref(OBJ_PROP_NUM(Z_OBJ_P(zv), 28))
#define Z_CLIENT_COOKIES_P(zv) php_soap_deref(OBJ_PROP_NUM(Z_OBJ_P(zv), 29))
#define Z_CLIENT_DEFAULT_HEADERS_P(zv) php_soap_deref(OBJ_PROP_NUM(Z_OBJ_P(zv), 30))
#define Z_CLIENT_SOAP_FAULT_P(zv) php_soap_deref(OBJ_PROP_NUM(Z_OBJ_P(zv), 31))
#define Z_CLIENT_LAST_REQUEST_P(zv) php_soap_deref(OBJ_PROP_NUM(Z_OBJ_P(zv), 32))
#define Z_CLIENT_LAST_RESPONSE_P(zv) php_soap_deref(OBJ_PROP_NUM(Z_OBJ_P(zv), 33))
#define Z_CLIENT_LAST_REQUEST_HEADERS_P(zv) php_soap_deref(OBJ_PROP_NUM(Z_OBJ_P(zv), 34))
#define Z_CLIENT_LAST_RESPONSE_HEADERS_P(zv) php_soap_deref(OBJ_PROP_NUM(Z_OBJ_P(zv), 35))
#endif
| 9,423 | 35.669261 | 108 |
h
|
php-src
|
php-src-master/ext/sockets/conversions.h
|
#ifndef PHP_SOCK_CONVERSIONS_H
#define PHP_SOCK_CONVERSIONS_H 1
#include <php.h>
#ifndef PHP_WIN32
# include <netinet/in.h>
# include <sys/socket.h>
# if defined(__FreeBSD__) || defined(__NetBSD__)
# include <sys/un.h>
# if defined(__FreeBSD__)
// we can't fully implement the ancillary data feature with
// the legacy sockcred/LOCAL_CREDS pair (due to lack of process
// id handling), so we disable it since only the
// sockcred2/LOCAL_CREDS_PERSISTENT pair can address it.
# undef LOCAL_CREDS
# endif
# endif
#else
# include <Ws2tcpip.h>
#endif
#include "php_sockets.h"
/* TYPE DEFINITIONS */
struct err_s {
int has_error;
char *msg;
int level;
int should_free;
};
struct key_value {
const char *key;
unsigned key_size;
void *value;
};
/* the complete types of these two are not relevant to the outside */
typedef struct _ser_context ser_context;
typedef struct _res_context res_context;
#define KEY_RECVMSG_RET "recvmsg_ret"
typedef void (from_zval_write_field)(const zval *arr_value, char *field, ser_context *ctx);
typedef void (to_zval_read_field)(const char *data, zval *zv, res_context *ctx);
/* VARIABLE DECLARATIONS */
extern const struct key_value empty_key_value_list[];
/* AUX FUNCTIONS */
void err_msg_dispose(struct err_s *err);
void allocations_dispose(zend_llist **allocations);
/* CONVERSION FUNCTIONS */
void from_zval_write_int(const zval *arr_value, char *field, ser_context *ctx);
void to_zval_read_int(const char *data, zval *zv, res_context *ctx);
#ifdef IPV6_PKTINFO
void from_zval_write_in6_pktinfo(const zval *container, char *in6_pktinfo_c, ser_context *ctx);
void to_zval_read_in6_pktinfo(const char *data, zval *zv, res_context *ctx);
#endif
#if defined(SO_PASSCRED) || defined(LOCAL_CREDS_PERSISTENT) || defined(LOCAL_CREDS)
void from_zval_write_ucred(const zval *container, char *ucred_c, ser_context *ctx);
void to_zval_read_ucred(const char *data, zval *zv, res_context *ctx);
#endif
#ifdef SCM_RIGHTS
size_t calculate_scm_rights_space(const zval *arr, ser_context *ctx);
void from_zval_write_fd_array(const zval *arr, char *int_arr, ser_context *ctx);
void to_zval_read_fd_array(const char *data, zval *zv, res_context *ctx);
#endif
void from_zval_write_msghdr_send(const zval *container, char *msghdr_c, ser_context *ctx);
void from_zval_write_msghdr_recv(const zval *container, char *msghdr_c, ser_context *ctx);
void to_zval_read_msghdr(const char *msghdr_c, zval *zv, res_context *ctx);
/* ENTRY POINTS FOR CONVERSIONS */
void *from_zval_run_conversions(const zval *container,
php_socket *sock,
from_zval_write_field *writer,
size_t struct_size,
const char *top_name,
zend_llist **allocations /* out */,
struct err_s *err /* in/out */);
zval *to_zval_run_conversions(const char *structure,
to_zval_read_field *reader,
const char *top_name,
const struct key_value *key_value_pairs,
struct err_s *err, zval *zv);
#endif
| 3,024 | 30.842105 | 95 |
h
|
php-src
|
php-src-master/ext/sockets/multicast.h
|
/*
+----------------------------------------------------------------------+
| Copyright (c) The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| https://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| [email protected] so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Authors: Gustavo Lopes <[email protected]> |
+----------------------------------------------------------------------+
*/
#if defined(MCAST_JOIN_GROUP) && !defined(__APPLE__)
# define RFC3678_API 1
/* has block/unblock and source membership, in this case for both IPv4 and IPv6 */
# define HAS_MCAST_EXT 1
#elif defined(IP_ADD_SOURCE_MEMBERSHIP) && !defined(__APPLE__)
/* has block/unblock and source membership, but only for IPv4 */
# define HAS_MCAST_EXT 1
#endif
#ifndef RFC3678_API
# define PHP_MCAST_JOIN_GROUP IP_ADD_MEMBERSHIP
# define PHP_MCAST_LEAVE_GROUP IP_DROP_MEMBERSHIP
# ifdef HAS_MCAST_EXT
# define PHP_MCAST_BLOCK_SOURCE IP_BLOCK_SOURCE
# define PHP_MCAST_UNBLOCK_SOURCE IP_UNBLOCK_SOURCE
# define PHP_MCAST_JOIN_SOURCE_GROUP IP_ADD_SOURCE_MEMBERSHIP
# define PHP_MCAST_LEAVE_SOURCE_GROUP IP_DROP_SOURCE_MEMBERSHIP
# endif
#else
# define PHP_MCAST_JOIN_GROUP MCAST_JOIN_GROUP
# define PHP_MCAST_LEAVE_GROUP MCAST_LEAVE_GROUP
# define PHP_MCAST_BLOCK_SOURCE MCAST_BLOCK_SOURCE
# define PHP_MCAST_UNBLOCK_SOURCE MCAST_UNBLOCK_SOURCE
# define PHP_MCAST_JOIN_SOURCE_GROUP MCAST_JOIN_SOURCE_GROUP
# define PHP_MCAST_LEAVE_SOURCE_GROUP MCAST_LEAVE_SOURCE_GROUP
#endif
int php_do_setsockopt_ip_mcast(php_socket *php_sock,
int level,
int optname,
zval *arg4);
int php_do_setsockopt_ipv6_mcast(php_socket *php_sock,
int level,
int optname,
zval *arg4);
zend_result php_if_index_to_addr4(
unsigned if_index,
php_socket *php_sock,
struct in_addr *out_addr);
zend_result php_add4_to_if_index(
struct in_addr *addr,
php_socket *php_sock,
unsigned *if_index);
zend_result php_string_to_if_index(const char *val, unsigned *out);
int php_mcast_join(
php_socket *sock,
int level,
struct sockaddr *group,
socklen_t group_len,
unsigned int if_index);
int php_mcast_leave(
php_socket *sock,
int level,
struct sockaddr *group,
socklen_t group_len,
unsigned int if_index);
#ifdef HAS_MCAST_EXT
int php_mcast_join_source(
php_socket *sock,
int level,
struct sockaddr *group,
socklen_t group_len,
struct sockaddr *source,
socklen_t source_len,
unsigned int if_index);
int php_mcast_leave_source(
php_socket *sock,
int level,
struct sockaddr *group,
socklen_t group_len,
struct sockaddr *source,
socklen_t source_len,
unsigned int if_index);
int php_mcast_block_source(
php_socket *sock,
int level,
struct sockaddr *group,
socklen_t group_len,
struct sockaddr *source,
socklen_t source_len,
unsigned int if_index);
int php_mcast_unblock_source(
php_socket *sock,
int level,
struct sockaddr *group,
socklen_t group_len,
struct sockaddr *source,
socklen_t source_len,
unsigned int if_index);
#endif
| 3,635 | 30.076923 | 82 |
h
|
php-src
|
php-src-master/ext/sockets/php_sockets.h
|
/*
+----------------------------------------------------------------------+
| Copyright (c) The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| https://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| [email protected] so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Authors: Chris Vandomelen <[email protected]> |
| Sterling Hughes <[email protected]> |
| |
| WinSock: Daniel Beulshausen <[email protected]> |
+----------------------------------------------------------------------+
*/
#ifndef PHP_SOCKETS_H
#define PHP_SOCKETS_H
#if HAVE_CONFIG_H
# include "config.h"
#endif
#if HAVE_SOCKETS
#include <php.h>
#ifdef PHP_WIN32
# include "windows_common.h"
#else
# define IS_INVALID_SOCKET(a) (a->bsd_socket < 0)
#endif
#define PHP_SOCKETS_VERSION PHP_VERSION
extern zend_module_entry sockets_module_entry;
#define phpext_sockets_ptr &sockets_module_entry
#ifdef PHP_WIN32
#include <Winsock2.h>
#else
#if HAVE_SYS_SOCKET_H
#include <sys/socket.h>
#endif
#endif
#ifndef PHP_WIN32
typedef int PHP_SOCKET;
#else
typedef SOCKET PHP_SOCKET;
#endif
#ifdef PHP_WIN32
# ifdef PHP_SOCKETS_EXPORTS
# define PHP_SOCKETS_API __declspec(dllexport)
# else
# define PHP_SOCKETS_API __declspec(dllimport)
# endif
#elif defined(__GNUC__) && __GNUC__ >= 4
# define PHP_SOCKETS_API __attribute__ ((visibility("default")))
#else
# define PHP_SOCKETS_API
#endif
/* Socket class */
typedef struct {
PHP_SOCKET bsd_socket;
int type;
int error;
int blocking;
zval zstream;
zend_object std;
} php_socket;
extern PHP_SOCKETS_API zend_class_entry *socket_ce;
static inline php_socket *socket_from_obj(zend_object *obj) {
return (php_socket *)((char *)(obj) - XtOffsetOf(php_socket, std));
}
#define Z_SOCKET_P(zv) socket_from_obj(Z_OBJ_P(zv))
#define ENSURE_SOCKET_VALID(php_sock) do { \
if (IS_INVALID_SOCKET(php_sock)) { \
zend_argument_error(NULL, 1, "has already been closed"); \
RETURN_THROWS(); \
} \
} while (0)
#ifdef PHP_WIN32
struct sockaddr_un {
short sun_family;
char sun_path[108];
};
#endif
#define PHP_SOCKET_ERROR(socket, msg, errn) \
do { \
int _err = (errn); /* save value to avoid repeated calls to WSAGetLastError() on Windows */ \
(socket)->error = _err; \
SOCKETS_G(last_error) = _err; \
if (_err != EAGAIN && _err != EWOULDBLOCK && _err != EINPROGRESS) { \
php_error_docref(NULL, E_WARNING, "%s [%d]: %s", msg, _err, sockets_strerror(_err)); \
} \
} while (0)
ZEND_BEGIN_MODULE_GLOBALS(sockets)
int last_error;
char *strerror_buf;
#ifdef PHP_WIN32
uint32_t wsa_child_count;
HashTable wsa_info;
#endif
ZEND_END_MODULE_GLOBALS(sockets)
PHP_SOCKETS_API ZEND_EXTERN_MODULE_GLOBALS(sockets)
#define SOCKETS_G(v) ZEND_MODULE_GLOBALS_ACCESSOR(sockets, v)
enum sockopt_return {
SOCKOPT_ERROR,
SOCKOPT_CONTINUE,
SOCKOPT_SUCCESS
};
PHP_SOCKETS_API char *sockets_strerror(int error);
PHP_SOCKETS_API bool socket_import_file_descriptor(PHP_SOCKET socket, php_socket *retsock);
#else
#define phpext_sockets_ptr NULL
#endif
#if defined(_AIX) && !defined(HAVE_SA_SS_FAMILY)
# define ss_family __ss_family
#endif
#ifndef MSG_EOF
#ifdef MSG_FIN
#define MSG_EOF MSG_FIN
#endif
#endif
#ifndef MSG_WAITALL
#ifdef LINUX
#define MSG_WAITALL 0x00000100
#else
#define MSG_WAITALL 0x00000000
#endif
#endif
#define PHP_NORMAL_READ 0x0001
#define PHP_BINARY_READ 0x0002
#ifdef WIN32
#define PHP_SOCKET_EINTR WSAEINTR
#elif defined(EINTR)
#define PHP_SOCKET_EINTR EINTR
#endif
#ifdef WIN32
#define PHP_SOCKET_EBADF WSAEBADF
#elif defined(EBADF)
#define PHP_SOCKET_EBADF EBADF
#endif
#ifdef WIN32
#define PHP_SOCKET_EACCES WSAEACCES
#elif defined(EACCES)
#define PHP_SOCKET_EACCES EACCES
#endif
#ifdef WIN32
#define PHP_SOCKET_EFAULT WSAEFAULT
#elif defined(EFAULT)
#define PHP_SOCKET_EFAULT EFAULT
#endif
#ifdef WIN32
#define PHP_SOCKET_EINVAL WSAEINVAL
#elif defined(EINVAL)
#define PHP_SOCKET_EINVAL EINVAL
#endif
#ifdef ENFILE
#define PHP_SOCKET_ENFILE ENFILE
#endif
#ifdef WIN32
#define PHP_SOCKET_EMFILE WSAEMFILE
#elif defined(EMFILE)
#define PHP_SOCKET_EMFILE EMFILE
#endif
#ifdef WIN32
#define PHP_SOCKET_EWOULDBLOCK WSAEWOULDBLOCK
#elif defined(EWOULDBLOCK)
#define PHP_SOCKET_EWOULDBLOCK EWOULDBLOCK
#endif
#ifdef WIN32
#define PHP_SOCKET_EINPROGRESS WSAEINPROGRESS
#elif defined(EINPROGRESS)
#define PHP_SOCKET_EINPROGRESS EINPROGRESS
#endif
#ifdef WIN32
#define PHP_SOCKET_EALREADY WSAEALREADY
#elif defined(EALREADY)
#define PHP_SOCKET_EALREADY EALREADY
#endif
#ifdef WIN32
#define PHP_SOCKET_ENOTSOCK WSAENOTSOCK
#elif defined(ENOTSOCK)
#define PHP_SOCKET_ENOTSOCK ENOTSOCK
#endif
#ifdef WIN32
#define PHP_SOCKET_EDESTADDRREQ WSAEDESTADDRREQ
#elif defined(EDESTADDRREQ)
#define PHP_SOCKET_EDESTADDRREQ EDESTADDRREQ
#endif
#ifdef WIN32
#define PHP_SOCKET_EMSGSIZE WSAEMSGSIZE
#elif defined(EMSGSIZE)
#define PHP_SOCKET_EMSGSIZE EMSGSIZE
#endif
#ifdef WIN32
#define PHP_SOCKET_EPROTOTYPE WSAEPROTOTYPE
#elif defined(EPROTOTYPE)
#define PHP_SOCKET_EPROTOTYPE EPROTOTYPE
#endif
#ifdef WIN32
#define PHP_SOCKET_ENOPROTOOPT WSAENOPROTOOPT
#elif defined(ENOPROTOOPT)
#define PHP_SOCKET_ENOPROTOOPT ENOPROTOOPT
#endif
#ifdef WIN32
#define PHP_SOCKET_EPROTONOSUPPORT WSAEPROTONOSUPPORT
#elif defined(EPROTONOSUPPORT)
#define PHP_SOCKET_EPROTONOSUPPORT EPROTONOSUPPORT
#endif
#ifdef WIN32
#define PHP_SOCKET_ESOCKTNOSUPPORT WSAESOCKTNOSUPPORT
#elif defined(ESOCKTNOSUPPORT)
#define PHP_SOCKET_ESOCKTNOSUPPORT ESOCKTNOSUPPORT
#endif
#ifdef WIN32
#define PHP_SOCKET_EOPNOTSUPP WSAEOPNOTSUPP
#elif defined(EOPNOTSUPP)
#define PHP_SOCKET_EOPNOTSUPP EOPNOTSUPP
#endif
#ifdef WIN32
#define PHP_SOCKET_EPFNOSUPPORT WSAEPFNOSUPPORT
#elif defined(EPFNOSUPPORT)
#define PHP_SOCKET_EPFNOSUPPORT EPFNOSUPPORT
#endif
#ifdef WIN32
#define PHP_SOCKET_EAFNOSUPPORT WSAEAFNOSUPPORT
#elif defined(EAFNOSUPPORT)
#define PHP_SOCKET_EAFNOSUPPORT EAFNOSUPPORT
#endif
#ifdef WIN32
#define PHP_SOCKET_EADDRINUSE WSAEADDRINUSE
#elif defined(EADDRINUSE)
#define PHP_SOCKET_EADDRINUSE EADDRINUSE
#endif
#ifdef WIN32
#define PHP_SOCKET_EADDRNOTAVAIL WSAEADDRNOTAVAIL
#elif defined(EADDRNOTAVAIL)
#define PHP_SOCKET_EADDRNOTAVAIL EADDRNOTAVAIL
#endif
#ifdef WIN32
#define PHP_SOCKET_ENETDOWN WSAENETDOWN
#elif defined(ENETDOWN)
#define PHP_SOCKET_ENETDOWN ENETDOWN
#endif
#ifdef WIN32
#define PHP_SOCKET_ENETUNREACH WSAENETUNREACH
#elif defined(ENETUNREACH)
#define PHP_SOCKET_ENETUNREACH ENETUNREACH
#endif
#ifdef WIN32
#define PHP_SOCKET_ENETRESET WSAENETRESET
#elif defined(ENETRESET)
#define PHP_SOCKET_ENETRESET ENETRESET
#endif
#ifdef WIN32
#define PHP_SOCKET_ECONNABORTED WSAECONNABORTED
#elif defined(ECONNABORTED)
#define PHP_SOCKET_ECONNABORTED ECONNABORTED
#endif
#ifdef WIN32
#define PHP_SOCKET_ECONNRESET WSAECONNRESET
#elif defined(ECONNRESET)
#define PHP_SOCKET_ECONNRESET ECONNRESET
#endif
#ifdef WIN32
#define PHP_SOCKET_ENOBUFS WSAENOBUFS
#elif defined(ENOBUFS)
#define PHP_SOCKET_ENOBUFS ENOBUFS
#endif
#ifdef WIN32
#define PHP_SOCKET_EISCONN WSAEISCONN
#elif defined(EISCONN)
#define PHP_SOCKET_EISCONN EISCONN
#endif
#ifdef WIN32
#define PHP_SOCKET_ENOTCONN WSAENOTCONN
#elif defined(ENOTCONN)
#define PHP_SOCKET_ENOTCONN ENOTCONN
#endif
#ifdef WIN32
#define PHP_SOCKET_ESHUTDOWN WSAESHUTDOWN
#elif defined(ESHUTDOWN)
#define PHP_SOCKET_ESHUTDOWN ESHUTDOWN
#endif
#ifdef WIN32
#define PHP_SOCKET_ETOOMANYREFS WSAETOOMANYREFS
#elif defined(ETOOMANYREFS)
#define PHP_SOCKET_ETOOMANYREFS ETOOMANYREFS
#endif
#ifdef WIN32
#define PHP_SOCKET_ETIMEDOUT WSAETIMEDOUT
#elif defined(ETIMEDOUT)
#define PHP_SOCKET_ETIMEDOUT ETIMEDOUT
#endif
#ifdef WIN32
#define PHP_SOCKET_ECONNREFUSED WSAECONNREFUSED
#elif defined(ECONNREFUSED)
#define PHP_SOCKET_ECONNREFUSED ECONNREFUSED
#endif
#ifdef WIN32
#define PHP_SOCKET_ELOOP WSAELOOP
#elif defined(ELOOP)
#define PHP_SOCKET_ELOOP ELOOP
#endif
#ifdef WIN32
#define PHP_SOCKET_ENAMETOOLONG WSAENAMETOOLONG
#elif defined(ENAMETOOLONG)
#define PHP_SOCKET_ENAMETOOLONG ENAMETOOLONG
#endif
#ifdef WIN32
#define PHP_SOCKET_EHOSTDOWN WSAEHOSTDOWN
#elif defined(EHOSTDOWN)
#define PHP_SOCKET_EHOSTDOWN EHOSTDOWN
#endif
#ifdef WIN32
#define PHP_SOCKET_EHOSTUNREACH WSAEHOSTUNREACH
#elif defined(EHOSTUNREACH)
#define PHP_SOCKET_EHOSTUNREACH EHOSTUNREACH
#endif
#ifdef WIN32
#define PHP_SOCKET_ENOTEMPTY WSAENOTEMPTY
#elif defined(ENOTEMPTY)
#define PHP_SOCKET_ENOTEMPTY ENOTEMPTY
#endif
#ifdef WIN32
#define PHP_SOCKET_EUSERS WSAEUSERS
#elif defined(EUSERS)
#define PHP_SOCKET_EUSERS EUSERS
#endif
#ifdef WIN32
#define PHP_SOCKET_EDQUOT WSAEDQUOT
#elif defined(EDQUOT)
#define PHP_SOCKET_EDQUOT EDQUOT
#endif
#ifdef WIN32
#define PHP_SOCKET_EREMOTE WSAEREMOTE
#elif defined(EREMOTE)
#define PHP_SOCKET_EREMOTE EREMOTE
#endif
#endif
| 9,380 | 22.04914 | 96 |
h
|
php-src
|
php-src-master/ext/sockets/sendrecvmsg.c
|
/*
+----------------------------------------------------------------------+
| Copyright (c) The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| https://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| [email protected] so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Authors: Gustavo Lopes <[email protected]> |
+----------------------------------------------------------------------+
*/
#ifdef __sun
/* to enable 'new' ancillary data layout instead */
# define _XPG4_2
#endif
#include <php.h>
#include "php_sockets.h"
#include "sendrecvmsg.h"
#include "conversions.h"
#include <limits.h>
#include <Zend/zend_llist.h>
#ifdef ZTS
#include <TSRM/TSRM.h>
#endif
#define MAX_USER_BUFF_SIZE ((size_t)(100*1024*1024))
#define DEFAULT_BUFF_SIZE 8192
#define MAX_ARRAY_KEY_SIZE 128
#ifdef PHP_WIN32
#include "windows_common.h"
#include <Mswsock.h>
#define msghdr _WSAMSG
static GUID WSARecvMsg_GUID = WSAID_WSARECVMSG;
static __declspec(thread) LPFN_WSARECVMSG WSARecvMsg = NULL;
inline ssize_t recvmsg(int sockfd, struct msghdr *msg, int flags)
{
DWORD recvd = 0,
bytesReturned;
if (WSARecvMsg == NULL) {
int res = WSAIoctl((SOCKET) sockfd, SIO_GET_EXTENSION_FUNCTION_POINTER,
&WSARecvMsg_GUID, sizeof(WSARecvMsg_GUID),
&WSARecvMsg, sizeof(WSARecvMsg),
&bytesReturned, NULL, NULL);
if (res != 0) {
return -1;
}
}
msg->dwFlags = (DWORD)flags;
return WSARecvMsg((SOCKET)sockfd, msg, &recvd, NULL, NULL) == 0
? (ssize_t)recvd
: -1;
}
inline ssize_t sendmsg(int sockfd, const struct msghdr *msg, int flags)
{
DWORD sent = 0;
return WSASendMsg((SOCKET)sockfd, (struct msghdr*)msg, (DWORD)flags, &sent, NULL, NULL) == 0
? (ssize_t)sent
: -1;
}
#endif
#define LONG_CHECK_VALID_INT(l, arg_pos) \
do { \
if ((l) < INT_MIN || (l) > INT_MAX) { \
zend_argument_value_error((arg_pos), "must be between %d and %d", INT_MIN, INT_MAX); \
RETURN_THROWS(); \
} \
} while (0)
static struct {
int initialized;
HashTable ht;
} ancillary_registry;
static void ancillary_registery_free_elem(zval *el) {
pefree(Z_PTR_P(el), 1);
}
#ifdef ZTS
static MUTEX_T ancillary_mutex;
#endif
static void init_ancillary_registry(void)
{
ancillary_reg_entry entry;
anc_reg_key key;
ancillary_registry.initialized = 1;
zend_hash_init(&ancillary_registry.ht, 32, NULL, ancillary_registery_free_elem, 1);
#define PUT_ENTRY(sizev, var_size, calc, from, to, level, type) \
entry.size = sizev; \
entry.var_el_size = var_size; \
entry.calc_space = calc; \
entry.from_array = from; \
entry.to_array = to; \
key.cmsg_level = level; \
key.cmsg_type = type; \
zend_hash_str_update_mem(&ancillary_registry.ht, (char*)&key, sizeof(key), (void*)&entry, sizeof(entry))
#if defined(IPV6_PKTINFO) && HAVE_IPV6
PUT_ENTRY(sizeof(struct in6_pktinfo), 0, 0, from_zval_write_in6_pktinfo,
to_zval_read_in6_pktinfo, IPPROTO_IPV6, IPV6_PKTINFO);
#endif
#if defined(IPV6_HOPLIMIT) && HAVE_IPV6
PUT_ENTRY(sizeof(int), 0, 0, from_zval_write_int,
to_zval_read_int, IPPROTO_IPV6, IPV6_HOPLIMIT);
#endif
#if defined(IPV6_TCLASS) && HAVE_IPV6
PUT_ENTRY(sizeof(int), 0, 0, from_zval_write_int,
to_zval_read_int, IPPROTO_IPV6, IPV6_TCLASS);
#endif
#ifdef SO_PASSCRED
#ifdef ANC_CREDS_UCRED
PUT_ENTRY(sizeof(struct ucred), 0, 0, from_zval_write_ucred,
to_zval_read_ucred, SOL_SOCKET, SCM_CREDENTIALS);
#else
PUT_ENTRY(sizeof(struct cmsgcred), 0, 0, from_zval_write_ucred,
to_zval_read_ucred, SOL_SOCKET, SCM_CREDS);
#endif
#endif
#if defined(LOCAL_CREDS_PERSISTENT)
PUT_ENTRY(SOCKCRED2SIZE(1), 1, 0, from_zval_write_ucred,
to_zval_read_ucred, SOL_SOCKET, SCM_CREDS2);
#elif defined(LOCAL_CREDS)
PUT_ENTRY(SOCKCREDSIZE(1), 1, 0, from_zval_write_ucred,
to_zval_read_ucred, SOL_SOCKET, SCM_CREDS);
#endif
#ifdef SCM_RIGHTS
PUT_ENTRY(0, sizeof(int), calculate_scm_rights_space, from_zval_write_fd_array,
to_zval_read_fd_array, SOL_SOCKET, SCM_RIGHTS);
#endif
}
static void destroy_ancillary_registry(void)
{
if (ancillary_registry.initialized) {
zend_hash_destroy(&ancillary_registry.ht);
ancillary_registry.initialized = 0;
}
}
ancillary_reg_entry *get_ancillary_reg_entry(int cmsg_level, int msg_type)
{
anc_reg_key key = { cmsg_level, msg_type };
ancillary_reg_entry *entry;
#ifdef ZTS
tsrm_mutex_lock(ancillary_mutex);
#endif
if (!ancillary_registry.initialized) {
init_ancillary_registry();
}
#ifdef ZTS
tsrm_mutex_unlock(ancillary_mutex);
#endif
if ((entry = zend_hash_str_find_ptr(&ancillary_registry.ht, (char*)&key, sizeof(key))) != NULL) {
return entry;
} else {
return NULL;
}
}
PHP_FUNCTION(socket_sendmsg)
{
zval *zsocket,
*zmsg;
zend_long flags = 0;
php_socket *php_sock;
struct msghdr *msghdr;
zend_llist *allocations;
struct err_s err = {0};
ssize_t res;
/* zmsg should be passed by ref */
if (zend_parse_parameters(ZEND_NUM_ARGS(), "Oa|l", &zsocket, socket_ce, &zmsg, &flags) == FAILURE) {
RETURN_THROWS();
}
LONG_CHECK_VALID_INT(flags, 3);
php_sock = Z_SOCKET_P(zsocket);
ENSURE_SOCKET_VALID(php_sock);
msghdr = from_zval_run_conversions(zmsg, php_sock, from_zval_write_msghdr_send,
sizeof(*msghdr), "msghdr", &allocations, &err);
if (err.has_error) {
err_msg_dispose(&err);
RETURN_FALSE;
}
res = sendmsg(php_sock->bsd_socket, msghdr, (int)flags);
if (res != -1) {
RETVAL_LONG((zend_long)res);
} else {
PHP_SOCKET_ERROR(php_sock, "Error in sendmsg", errno);
RETVAL_FALSE;
}
allocations_dispose(&allocations);
}
PHP_FUNCTION(socket_recvmsg)
{
zval *zsocket,
*zmsg;
zend_long flags = 0;
php_socket *php_sock;
ssize_t res;
struct msghdr *msghdr;
zend_llist *allocations;
struct err_s err = {0};
//ssize_t recvmsg(int sockfd, struct msghdr *msg, int flags);
if (zend_parse_parameters(ZEND_NUM_ARGS(), "Oa|l", &zsocket, socket_ce, &zmsg, &flags) == FAILURE) {
RETURN_THROWS();
}
LONG_CHECK_VALID_INT(flags, 3);
php_sock = Z_SOCKET_P(zsocket);
ENSURE_SOCKET_VALID(php_sock);
msghdr = from_zval_run_conversions(zmsg, php_sock, from_zval_write_msghdr_recv,
sizeof(*msghdr), "msghdr", &allocations, &err);
if (err.has_error) {
err_msg_dispose(&err);
RETURN_FALSE;
}
res = recvmsg(php_sock->bsd_socket, msghdr, (int)flags);
if (res != -1) {
zval *zres, tmp;
struct key_value kv[] = {
{KEY_RECVMSG_RET, sizeof(KEY_RECVMSG_RET), &res},
{0}
};
zres = to_zval_run_conversions((char *)msghdr, to_zval_read_msghdr,
"msghdr", kv, &err, &tmp);
/* we don;t need msghdr anymore; free it */
msghdr = NULL;
zval_ptr_dtor(zmsg);
if (!err.has_error) {
ZVAL_COPY_VALUE(zmsg, zres);
} else {
err_msg_dispose(&err);
ZVAL_FALSE(zmsg);
/* no need to destroy/free zres -- it's NULL in this circumstance */
assert(zres == NULL);
}
RETVAL_LONG((zend_long)res);
} else {
SOCKETS_G(last_error) = errno;
php_error_docref(NULL, E_WARNING, "Error in recvmsg [%d]: %s",
errno, sockets_strerror(errno));
RETVAL_FALSE;
}
allocations_dispose(&allocations);
}
PHP_FUNCTION(socket_cmsg_space)
{
zend_long level,
type,
n = 0;
ancillary_reg_entry *entry;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "ll|l",
&level, &type, &n) == FAILURE) {
RETURN_THROWS();
}
LONG_CHECK_VALID_INT(level, 1);
LONG_CHECK_VALID_INT(type, 2);
LONG_CHECK_VALID_INT(n, 3);
if (n < 0) {
zend_argument_value_error(3, "must be greater than or equal to 0");
RETURN_THROWS();
}
entry = get_ancillary_reg_entry(level, type);
if (entry == NULL) {
zend_value_error("Pair level " ZEND_LONG_FMT " and/or type " ZEND_LONG_FMT " is not supported",
level, type);
RETURN_THROWS();
}
if (entry->var_el_size > 0) {
/* Leading underscore to avoid symbol collision on AIX. */
size_t _rem_size = ZEND_LONG_MAX - entry->size;
size_t n_max = _rem_size / entry->var_el_size;
size_t size = entry->size + n * entry->var_el_size;
size_t total_size = CMSG_SPACE(size);
if (n > n_max /* zend_long overflow */
|| total_size > ZEND_LONG_MAX
|| total_size < size /* align overflow */) {
zend_argument_value_error(3, "is too large");
RETURN_THROWS();
}
}
RETURN_LONG((zend_long)CMSG_SPACE(entry->size + n * entry->var_el_size));
}
#if HAVE_IPV6
int php_do_setsockopt_ipv6_rfc3542(php_socket *php_sock, int level, int optname, zval *arg4)
{
struct err_s err = {0};
zend_llist *allocations = NULL;
void *opt_ptr;
socklen_t optlen;
int retval;
assert(level == IPPROTO_IPV6);
switch (optname) {
#ifdef IPV6_PKTINFO
case IPV6_PKTINFO:
#ifdef PHP_WIN32
if (Z_TYPE_P(arg4) == IS_ARRAY) {
php_error_docref(NULL, E_WARNING, "Windows does not "
"support sticky IPV6_PKTINFO");
return FAILURE;
} else {
/* windows has no IPV6_RECVPKTINFO, and uses IPV6_PKTINFO
* for the same effect. We define IPV6_RECVPKTINFO to be
* IPV6_PKTINFO, so assume the assume user used IPV6_RECVPKTINFO */
return 1;
}
#endif
opt_ptr = from_zval_run_conversions(arg4, php_sock, from_zval_write_in6_pktinfo,
sizeof(struct in6_pktinfo), "in6_pktinfo", &allocations, &err);
if (err.has_error) {
err_msg_dispose(&err);
return FAILURE;
}
optlen = sizeof(struct in6_pktinfo);
goto dosockopt;
#endif
}
/* we also support IPV6_TCLASS, but that can be handled by the default
* integer optval handling in the caller */
return 1;
dosockopt:
retval = setsockopt(php_sock->bsd_socket, level, optname, opt_ptr, optlen);
if (retval != 0) {
PHP_SOCKET_ERROR(php_sock, "Unable to set socket option", errno);
}
allocations_dispose(&allocations);
return retval != 0 ? FAILURE : SUCCESS;
}
int php_do_getsockopt_ipv6_rfc3542(php_socket *php_sock, int level, int optname, zval *result)
{
struct err_s err = {0};
void *buffer;
socklen_t size;
int res;
to_zval_read_field *reader;
assert(level == IPPROTO_IPV6);
switch (optname) {
#ifdef IPV6_PKTINFO
case IPV6_PKTINFO:
size = sizeof(struct in6_pktinfo);
reader = &to_zval_read_in6_pktinfo;
break;
#endif
default:
return 1;
}
buffer = ecalloc(1, size);
res = getsockopt(php_sock->bsd_socket, level, optname, buffer, &size);
if (res != 0) {
PHP_SOCKET_ERROR(php_sock, "unable to get socket option", errno);
} else {
zval tmp;
zval *zv = to_zval_run_conversions(buffer, reader, "in6_pktinfo",
empty_key_value_list, &err, &tmp);
if (err.has_error) {
err_msg_dispose(&err);
res = -1;
} else {
ZVAL_COPY_VALUE(result, zv);
}
}
efree(buffer);
return res == 0 ? SUCCESS : FAILURE;
}
#endif /* HAVE_IPV6 */
void php_socket_sendrecvmsg_init(INIT_FUNC_ARGS)
{
#ifdef ZTS
ancillary_mutex = tsrm_mutex_alloc();
#endif
}
void php_socket_sendrecvmsg_shutdown(SHUTDOWN_FUNC_ARGS)
{
#ifdef ZTS
tsrm_mutex_free(ancillary_mutex);
#endif
destroy_ancillary_registry();
}
| 11,340 | 24.892694 | 105 |
c
|
php-src
|
php-src-master/ext/sockets/sendrecvmsg.h
|
#ifndef PHP_SENDRECVMSG_H
#define PHP_SENDRECVMSG_H 1
#include <php.h>
#include "conversions.h"
/* for sockets.c */
#ifdef PHP_WIN32
#define IPV6_RECVPKTINFO IPV6_PKTINFO
#define IPV6_RECVHOPLIMIT IPV6_HOPLIMIT
#endif
void php_socket_sendrecvmsg_init(INIT_FUNC_ARGS);
void php_socket_sendrecvmsg_shutdown(SHUTDOWN_FUNC_ARGS);
int php_do_setsockopt_ipv6_rfc3542(php_socket *php_sock, int level, int optname, zval *arg4);
int php_do_getsockopt_ipv6_rfc3542(php_socket *php_sock, int level, int optname, zval *result);
/* for conversions.c */
typedef struct {
int cmsg_level; /* originating protocol */
int cmsg_type; /* protocol-specific type */
} anc_reg_key;
typedef size_t (calculate_req_space)(const zval *value, ser_context *ctx);
typedef struct {
socklen_t size; /* size of native structure */
socklen_t var_el_size; /* size of repeatable component */
calculate_req_space *calc_space;
from_zval_write_field *from_array;
to_zval_read_field *to_array;
} ancillary_reg_entry;
ancillary_reg_entry *get_ancillary_reg_entry(int cmsg_level, int msg_type);
#endif
| 1,077 | 26.641026 | 95 |
h
|
php-src
|
php-src-master/ext/sockets/sockaddr_conv.c
|
#include <php.h>
#include <php_network.h>
#include "php_sockets.h"
#ifdef PHP_WIN32
#include "windows_common.h"
#else
#include <netdb.h>
#include <arpa/inet.h>
#endif
extern zend_result php_string_to_if_index(const char *val, unsigned *out);
#if HAVE_IPV6
/* Sets addr by hostname, or by ip in string form (AF_INET6) */
int php_set_inet6_addr(struct sockaddr_in6 *sin6, char *string, php_socket *php_sock) /* {{{ */
{
struct in6_addr tmp;
#if HAVE_GETADDRINFO
struct addrinfo hints;
struct addrinfo *addrinfo = NULL;
#endif
char *scope = strchr(string, '%');
if (inet_pton(AF_INET6, string, &tmp)) {
memcpy(&(sin6->sin6_addr.s6_addr), &(tmp.s6_addr), sizeof(struct in6_addr));
} else {
#if HAVE_GETADDRINFO
memset(&hints, 0, sizeof(struct addrinfo));
hints.ai_family = AF_INET6;
#if HAVE_AI_V4MAPPED
hints.ai_flags = AI_V4MAPPED | AI_ADDRCONFIG;
#else
hints.ai_flags = AI_ADDRCONFIG;
#endif
getaddrinfo(string, NULL, &hints, &addrinfo);
if (!addrinfo) {
#ifdef PHP_WIN32
PHP_SOCKET_ERROR(php_sock, "Host lookup failed", WSAGetLastError());
#else
PHP_SOCKET_ERROR(php_sock, "Host lookup failed", (-10000 - h_errno));
#endif
return 0;
}
if (addrinfo->ai_family != PF_INET6 || addrinfo->ai_addrlen != sizeof(struct sockaddr_in6)) {
php_error_docref(NULL, E_WARNING, "Host lookup failed: Non AF_INET6 domain returned on AF_INET6 socket");
freeaddrinfo(addrinfo);
return 0;
}
memcpy(&(sin6->sin6_addr.s6_addr), ((struct sockaddr_in6*)(addrinfo->ai_addr))->sin6_addr.s6_addr, sizeof(struct in6_addr));
freeaddrinfo(addrinfo);
#else
/* No IPv6 specific hostname resolution is available on this system? */
php_error_docref(NULL, E_WARNING, "Host lookup failed: getaddrinfo() not available on this system");
return 0;
#endif
}
if (scope) {
zend_long lval = 0;
double dval = 0;
unsigned scope_id = 0;
scope++;
if (IS_LONG == is_numeric_string(scope, strlen(scope), &lval, &dval, 0)) {
if (lval > 0 && (zend_ulong)lval <= UINT_MAX) {
scope_id = lval;
}
} else {
php_string_to_if_index(scope, &scope_id);
}
sin6->sin6_scope_id = scope_id;
}
return 1;
}
/* }}} */
#endif
/* Sets addr by hostname, or by ip in string form (AF_INET) */
int php_set_inet_addr(struct sockaddr_in *sin, char *string, php_socket *php_sock) /* {{{ */
{
struct in_addr tmp;
struct hostent *host_entry;
#ifdef HAVE_INET_PTON
if (inet_pton(AF_INET, string, &tmp)) {
#else
if (inet_aton(string, &tmp)) {
#endif
sin->sin_addr.s_addr = tmp.s_addr;
} else {
if (strlen(string) > MAXFQDNLEN || ! (host_entry = php_network_gethostbyname(string))) {
/* Note: < -10000 indicates a host lookup error */
#ifdef PHP_WIN32
PHP_SOCKET_ERROR(php_sock, "Host lookup failed", WSAGetLastError());
#else
PHP_SOCKET_ERROR(php_sock, "Host lookup failed", (-10000 - h_errno));
#endif
return 0;
}
if (host_entry->h_addrtype != AF_INET) {
php_error_docref(NULL, E_WARNING, "Host lookup failed: Non AF_INET domain returned on AF_INET socket");
return 0;
}
memcpy(&(sin->sin_addr.s_addr), host_entry->h_addr_list[0], host_entry->h_length);
}
return 1;
}
/* }}} */
/* Sets addr by hostname or by ip in string form (AF_INET or AF_INET6,
* depending on the socket) */
int php_set_inet46_addr(php_sockaddr_storage *ss, socklen_t *ss_len, char *string, php_socket *php_sock) /* {{{ */
{
if (php_sock->type == AF_INET) {
struct sockaddr_in t = {0};
if (php_set_inet_addr(&t, string, php_sock)) {
memcpy(ss, &t, sizeof t);
ss->ss_family = AF_INET;
*ss_len = sizeof(t);
return 1;
}
}
#if HAVE_IPV6
else if (php_sock->type == AF_INET6) {
struct sockaddr_in6 t = {0};
if (php_set_inet6_addr(&t, string, php_sock)) {
memcpy(ss, &t, sizeof t);
ss->ss_family = AF_INET6;
*ss_len = sizeof(t);
return 1;
}
}
#endif
else {
php_error_docref(NULL, E_WARNING,
"IP address used in the context of an unexpected type of socket");
}
return 0;
}
| 3,948 | 25.503356 | 126 |
c
|
php-src
|
php-src-master/ext/sockets/sockaddr_conv.h
|
#ifndef PHP_SOCKADR_CONV_H
#define PHP_SOCKADR_CONV_H
#include <php_network.h>
#include "php_sockets.h" /* php_socket */
#ifndef PHP_WIN32
# include <netinet/in.h>
#else
# include <Winsock2.h>
#endif
/*
* Convert an IPv6 literal or a hostname info a sockaddr_in6.
* The IPv6 literal can be a IPv4 mapped address (like ::ffff:127.0.0.1).
* If the hostname yields no IPv6 addresses, a mapped IPv4 address may be returned (AI_V4MAPPED)
*/
int php_set_inet6_addr(struct sockaddr_in6 *sin6, char *string, php_socket *php_sock);
/*
* Convert an IPv4 literal or a hostname into a sockaddr_in.
*/
int php_set_inet_addr(struct sockaddr_in *sin, char *string, php_socket *php_sock);
/*
* Calls either php_set_inet6_addr() or php_set_inet_addr(), depending on the type of the socket.
*/
int php_set_inet46_addr(php_sockaddr_storage *ss, socklen_t *ss_len, char *string, php_socket *php_sock);
#endif
| 904 | 27.28125 | 105 |
h
|
php-src
|
php-src-master/ext/sockets/windows_common.h
|
/*
+----------------------------------------------------------------------+
| Copyright (c) The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| https://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| [email protected] so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
*/
#ifndef WINDOWS_COMMON_H
#define WINDOWS_COMMON_H
#include <Winsock2.h>
#define NTDDI_XP NTDDI_WINXP /* bug in SDK */
#include <IPHlpApi.h> /* conflicting definition of CMSG_DATA */
#undef NTDDI_XP
#define HAVE_IF_NAMETOINDEX 1
#define IS_INVALID_SOCKET(a) (a->bsd_socket == INVALID_SOCKET)
#ifdef errno
# undef errno
#endif
#define errno WSAGetLastError()
#define h_errno WSAGetLastError()
#define set_errno(a) WSASetLastError(a)
#define close(a) closesocket(a)
#ifdef ENETUNREACH /* errno.h probably included */
# undef EWOULDBLOCK
# undef EINPROGRESS
# undef EALREADY
# undef ENOTSOCK
# undef EDESTADDRREQ
# undef EMSGSIZE
# undef EPROTOTYPE
# undef ENOPROTOOPT
# undef EPROTONOSUPPORT
# undef ESOCKTNOSUPPORT
# undef EOPNOTSUPP
# undef EPFNOSUPPORT
# undef EAFNOSUPPORT
# undef EADDRINUSE
# undef EADDRNOTAVAIL
# undef ENETDOWN
# undef ENETUNREACH
# undef ENETRESET
# undef ECONNABORTED
# undef ECONNRESET
# undef ENOBUFS
# undef EISCONN
# undef ENOTCONN
# undef ESHUTDOWN
# undef ETOOMANYREFS
# undef ETIMEDOUT
# undef ECONNREFUSED
# undef ELOOP
# undef ENAMETOOLONG
# undef EHOSTDOWN
# undef EHOSTUNREACH
# undef ENOTEMPTY
# undef EPROCLIM
# undef EUSERS
# undef EDQUOT
# undef ESTALE
# undef EREMOTE
# undef EAGAIN
#endif
/* section disabled in WinSock2.h */
#define EWOULDBLOCK WSAEWOULDBLOCK
#define EINPROGRESS WSAEINPROGRESS
#define EALREADY WSAEALREADY
#define ENOTSOCK WSAENOTSOCK
#define EDESTADDRREQ WSAEDESTADDRREQ
#define EMSGSIZE WSAEMSGSIZE
#define EPROTOTYPE WSAEPROTOTYPE
#define ENOPROTOOPT WSAENOPROTOOPT
#define EPROTONOSUPPORT WSAEPROTONOSUPPORT
#define ESOCKTNOSUPPORT WSAESOCKTNOSUPPORT
#define EOPNOTSUPP WSAEOPNOTSUPP
#define EPFNOSUPPORT WSAEPFNOSUPPORT
#define EAFNOSUPPORT WSAEAFNOSUPPORT
#define EADDRINUSE WSAEADDRINUSE
#define EADDRNOTAVAIL WSAEADDRNOTAVAIL
#define ENETDOWN WSAENETDOWN
#define ENETUNREACH WSAENETUNREACH
#define ENETRESET WSAENETRESET
#define ECONNABORTED WSAECONNABORTED
#define ECONNRESET WSAECONNRESET
#define ENOBUFS WSAENOBUFS
#define EISCONN WSAEISCONN
#define ENOTCONN WSAENOTCONN
#define ESHUTDOWN WSAESHUTDOWN
#define ETOOMANYREFS WSAETOOMANYREFS
#define ETIMEDOUT WSAETIMEDOUT
#define ECONNREFUSED WSAECONNREFUSED
#define ELOOP WSAELOOP
#define ENAMETOOLONG WSAENAMETOOLONG
#define EHOSTDOWN WSAEHOSTDOWN
#define EHOSTUNREACH WSAEHOSTUNREACH
#define ENOTEMPTY WSAENOTEMPTY
#define EPROCLIM WSAEPROCLIM
#define EUSERS WSAEUSERS
#define EDQUOT WSAEDQUOT
#define ESTALE WSAESTALE
#define EREMOTE WSAEREMOTE
/* and an extra one */
#define EAGAIN WSAEWOULDBLOCK
#endif
| 3,879 | 31.605042 | 75 |
h
|
php-src
|
php-src-master/ext/sodium/php_libsodium.h
|
/*
+----------------------------------------------------------------------+
| Copyright (c) The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| https://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| [email protected] so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Authors: Frank Denis <[email protected]> |
+----------------------------------------------------------------------+
*/
#ifndef PHP_LIBSODIUM_H
#define PHP_LIBSODIUM_H
extern zend_module_entry sodium_module_entry;
#define phpext_sodium_ptr &sodium_module_entry
#define PHP_SODIUM_VERSION PHP_VERSION
#ifdef ZTS
# include "TSRM.h"
#endif
#define SODIUM_LIBRARY_VERSION() (char *) (void *) sodium_version_string()
#define SODIUM_CRYPTO_BOX_KEYPAIRBYTES() crypto_box_SECRETKEYBYTES + crypto_box_PUBLICKEYBYTES
#define SODIUM_CRYPTO_KX_KEYPAIRBYTES() crypto_kx_SECRETKEYBYTES + crypto_kx_PUBLICKEYBYTES
#define SODIUM_CRYPTO_SIGN_KEYPAIRBYTES() crypto_sign_SECRETKEYBYTES + crypto_sign_PUBLICKEYBYTES
PHP_MINIT_FUNCTION(sodium);
PHP_MINIT_FUNCTION(sodium_password_hash);
PHP_MSHUTDOWN_FUNCTION(sodium);
PHP_RINIT_FUNCTION(sodium);
PHP_RSHUTDOWN_FUNCTION(sodium);
PHP_MINFO_FUNCTION(sodium);
#endif /* PHP_LIBSODIUM_H */
| 1,800 | 39.022222 | 97 |
h
|
php-src
|
php-src-master/ext/sodium/sodium_pwhash.c
|
/*
+----------------------------------------------------------------------+
| Copyright (c) The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| https://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| [email protected] so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Authors: Sara Golemon <[email protected]> |
+----------------------------------------------------------------------+
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include "php.h"
#include "php_libsodium.h"
#include "ext/standard/php_password.h"
#include <sodium.h>
#if SODIUM_LIBRARY_VERSION_MAJOR > 9 || (SODIUM_LIBRARY_VERSION_MAJOR == 9 && SODIUM_LIBRARY_VERSION_MINOR >= 6)
/**
* MEMLIMIT is normalized to KB even though sodium uses Bytes in order to
* present a consistent user-facing API.
*
* Threads are fixed at 1 by libsodium.
*
* When updating these values, synchronize ext/standard/php_password.h values.
*/
#define PHP_SODIUM_PWHASH_MEMLIMIT (64 << 10)
#define PHP_SODIUM_PWHASH_OPSLIMIT 4
#define PHP_SODIUM_PWHASH_THREADS 1
static inline int get_options(zend_array *options, size_t *memlimit, size_t *opslimit) {
zval *opt;
*opslimit = PHP_SODIUM_PWHASH_OPSLIMIT;
*memlimit = PHP_SODIUM_PWHASH_MEMLIMIT << 10;
if (!options) {
return SUCCESS;
}
if ((opt = zend_hash_str_find(options, "memory_cost", strlen("memory_cost")))) {
zend_long smemlimit = zval_get_long(opt);
if ((smemlimit < 0) || (smemlimit < crypto_pwhash_MEMLIMIT_MIN >> 10) || (smemlimit > (crypto_pwhash_MEMLIMIT_MAX >> 10))) {
zend_value_error("Memory cost is outside of allowed memory range");
return FAILURE;
}
*memlimit = smemlimit << 10;
}
if ((opt = zend_hash_str_find(options, "time_cost", strlen("time_cost")))) {
*opslimit = zval_get_long(opt);
if ((*opslimit < crypto_pwhash_OPSLIMIT_MIN) || (*opslimit > crypto_pwhash_OPSLIMIT_MAX)) {
zend_value_error("Time cost is outside of allowed time range");
return FAILURE;
}
}
if ((opt = zend_hash_str_find(options, "threads", strlen("threads"))) && (zval_get_long(opt) != 1)) {
zend_value_error("A thread value other than 1 is not supported by this implementation");
return FAILURE;
}
return SUCCESS;
}
static zend_string *php_sodium_argon2_hash(const zend_string *password, zend_array *options, int alg) {
size_t opslimit, memlimit;
zend_string *ret;
if ((ZSTR_LEN(password) >= 0xffffffff)) {
zend_value_error("Password is too long");
return NULL;
}
if (get_options(options, &memlimit, &opslimit) == FAILURE) {
return NULL;
}
ret = zend_string_alloc(crypto_pwhash_STRBYTES - 1, 0);
if (crypto_pwhash_str_alg(ZSTR_VAL(ret), ZSTR_VAL(password), ZSTR_LEN(password), opslimit, memlimit, alg)) {
zend_value_error("Unexpected failure hashing password");
zend_string_release(ret);
return NULL;
}
ZSTR_LEN(ret) = strlen(ZSTR_VAL(ret));
ZSTR_VAL(ret)[ZSTR_LEN(ret)] = 0;
return ret;
}
static bool php_sodium_argon2_verify(const zend_string *password, const zend_string *hash) {
if ((ZSTR_LEN(password) >= 0xffffffff) || (ZSTR_LEN(hash) >= 0xffffffff)) {
return 0;
}
return crypto_pwhash_str_verify(ZSTR_VAL(hash), ZSTR_VAL(password), ZSTR_LEN(password)) == 0;
}
static bool php_sodium_argon2_needs_rehash(const zend_string *hash, zend_array *options) {
size_t opslimit, memlimit;
if (get_options(options, &memlimit, &opslimit) == FAILURE) {
return 1;
}
return crypto_pwhash_str_needs_rehash(ZSTR_VAL(hash), opslimit, memlimit);
}
static int php_sodium_argon2_get_info(zval *return_value, const zend_string *hash) {
const char* p = NULL;
zend_long v = 0, threads = 1;
zend_long memory_cost = PHP_SODIUM_PWHASH_MEMLIMIT;
zend_long time_cost = PHP_SODIUM_PWHASH_OPSLIMIT;
if (!hash || (ZSTR_LEN(hash) < sizeof("$argon2id$"))) {
return FAILURE;
}
p = ZSTR_VAL(hash);
if (!memcmp(p, "$argon2i$", strlen("$argon2i$"))) {
p += strlen("$argon2i$");
} else if (!memcmp(p, "$argon2id$", strlen("$argon2id$"))) {
p += strlen("$argon2id$");
} else {
return FAILURE;
}
sscanf(p, "v=" ZEND_LONG_FMT "$m=" ZEND_LONG_FMT ",t=" ZEND_LONG_FMT ",p=" ZEND_LONG_FMT,
&v, &memory_cost, &time_cost, &threads);
add_assoc_long(return_value, "memory_cost", memory_cost);
add_assoc_long(return_value, "time_cost", time_cost);
add_assoc_long(return_value, "threads", threads);
return SUCCESS;
}
/* argon2i specific methods */
static zend_string *php_sodium_argon2i_hash(const zend_string *password, zend_array *options) {
return php_sodium_argon2_hash(password, options, crypto_pwhash_ALG_ARGON2I13);
}
static const php_password_algo sodium_algo_argon2i = {
"argon2i",
php_sodium_argon2i_hash,
php_sodium_argon2_verify,
php_sodium_argon2_needs_rehash,
php_sodium_argon2_get_info,
NULL,
};
/* argon2id specific methods */
static zend_string *php_sodium_argon2id_hash(const zend_string *password, zend_array *options) {
return php_sodium_argon2_hash(password, options, crypto_pwhash_ALG_ARGON2ID13);
}
static const php_password_algo sodium_algo_argon2id = {
"argon2id",
php_sodium_argon2id_hash,
php_sodium_argon2_verify,
php_sodium_argon2_needs_rehash,
php_sodium_argon2_get_info,
NULL,
};
PHP_MINIT_FUNCTION(sodium_password_hash) /* {{{ */ {
zend_string *argon2i = ZSTR_INIT_LITERAL("argon2i", 1);
if (php_password_algo_find(argon2i)) {
/* Nothing to do. Core has registered these algorithms for us. */
zend_string_release(argon2i);
return SUCCESS;
}
zend_string_release(argon2i);
if (FAILURE == php_password_algo_register("argon2i", &sodium_algo_argon2i)) {
return FAILURE;
}
REGISTER_STRING_CONSTANT("PASSWORD_ARGON2I", "argon2i", CONST_PERSISTENT);
if (FAILURE == php_password_algo_register("argon2id", &sodium_algo_argon2id)) {
return FAILURE;
}
REGISTER_STRING_CONSTANT("PASSWORD_ARGON2ID", "argon2id", CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("PASSWORD_ARGON2_DEFAULT_MEMORY_COST", PHP_SODIUM_PWHASH_MEMLIMIT, CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("PASSWORD_ARGON2_DEFAULT_TIME_COST", PHP_SODIUM_PWHASH_OPSLIMIT, CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("PASSWORD_ARGON2_DEFAULT_THREADS", PHP_SODIUM_PWHASH_THREADS, CONST_PERSISTENT);
REGISTER_STRING_CONSTANT("PASSWORD_ARGON2_PROVIDER", "sodium", CONST_PERSISTENT);
return SUCCESS;
}
/* }}} */
#endif /* HAVE_SODIUM_PASSWORD_HASH */
| 6,868 | 32.507317 | 126 |
c
|
php-src
|
php-src-master/ext/spl/php_spl.c
|
/*
+----------------------------------------------------------------------+
| Copyright (c) The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| https://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| [email protected] so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Authors: Marcus Boerger <[email protected]> |
+----------------------------------------------------------------------+
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "php.h"
#include "php_ini.h"
#include "php_main.h"
#include "ext/standard/info.h"
#include "php_spl.h"
#include "php_spl_arginfo.h"
#include "spl_functions.h"
#include "spl_engine.h"
#include "spl_array.h"
#include "spl_directory.h"
#include "spl_iterators.h"
#include "spl_exceptions.h"
#include "spl_observer.h"
#include "spl_dllist.h"
#include "spl_fixedarray.h"
#include "spl_heap.h"
#include "zend_exceptions.h"
#include "zend_interfaces.h"
#include "main/snprintf.h"
#ifdef COMPILE_DL_SPL
ZEND_GET_MODULE(spl)
#endif
ZEND_TLS zend_string *spl_autoload_extensions;
ZEND_TLS HashTable *spl_autoload_functions;
#define SPL_DEFAULT_FILE_EXTENSIONS ".inc,.php"
static zend_class_entry * spl_find_ce_by_name(zend_string *name, bool autoload)
{
zend_class_entry *ce;
if (!autoload) {
zend_string *lc_name = zend_string_tolower(name);
ce = zend_hash_find_ptr(EG(class_table), lc_name);
zend_string_release(lc_name);
} else {
ce = zend_lookup_class(name);
}
if (ce == NULL) {
php_error_docref(NULL, E_WARNING, "Class %s does not exist%s", ZSTR_VAL(name), autoload ? " and could not be loaded" : "");
return NULL;
}
return ce;
}
/* {{{ Return an array containing the names of all parent classes */
PHP_FUNCTION(class_parents)
{
zval *obj;
zend_class_entry *parent_class, *ce;
bool autoload = 1;
/* We do not use Z_PARAM_OBJ_OR_STR here to be able to exclude int, float, and bool which are bogus class names */
if (zend_parse_parameters(ZEND_NUM_ARGS(), "z|b", &obj, &autoload) == FAILURE) {
RETURN_THROWS();
}
if (Z_TYPE_P(obj) != IS_OBJECT && Z_TYPE_P(obj) != IS_STRING) {
zend_argument_type_error(1, "must be of type object|string, %s given", zend_zval_value_name(obj));
RETURN_THROWS();
}
if (Z_TYPE_P(obj) == IS_STRING) {
if (NULL == (ce = spl_find_ce_by_name(Z_STR_P(obj), autoload))) {
RETURN_FALSE;
}
} else {
ce = Z_OBJCE_P(obj);
}
array_init(return_value);
parent_class = ce->parent;
while (parent_class) {
spl_add_class_name(return_value, parent_class, 0, 0);
parent_class = parent_class->parent;
}
}
/* }}} */
/* {{{ Return all classes and interfaces implemented by SPL */
PHP_FUNCTION(class_implements)
{
zval *obj;
bool autoload = 1;
zend_class_entry *ce;
/* We do not use Z_PARAM_OBJ_OR_STR here to be able to exclude int, float, and bool which are bogus class names */
if (zend_parse_parameters(ZEND_NUM_ARGS(), "z|b", &obj, &autoload) == FAILURE) {
RETURN_THROWS();
}
if (Z_TYPE_P(obj) != IS_OBJECT && Z_TYPE_P(obj) != IS_STRING) {
zend_argument_type_error(1, "must be of type object|string, %s given", zend_zval_value_name(obj));
RETURN_THROWS();
}
if (Z_TYPE_P(obj) == IS_STRING) {
if (NULL == (ce = spl_find_ce_by_name(Z_STR_P(obj), autoload))) {
RETURN_FALSE;
}
} else {
ce = Z_OBJCE_P(obj);
}
array_init(return_value);
spl_add_interfaces(return_value, ce, 1, ZEND_ACC_INTERFACE);
}
/* }}} */
/* {{{ Return all traits used by a class. */
PHP_FUNCTION(class_uses)
{
zval *obj;
bool autoload = 1;
zend_class_entry *ce;
/* We do not use Z_PARAM_OBJ_OR_STR here to be able to exclude int, float, and bool which are bogus class names */
if (zend_parse_parameters(ZEND_NUM_ARGS(), "z|b", &obj, &autoload) == FAILURE) {
RETURN_THROWS();
}
if (Z_TYPE_P(obj) != IS_OBJECT && Z_TYPE_P(obj) != IS_STRING) {
zend_argument_type_error(1, "must be of type object|string, %s given", zend_zval_value_name(obj));
RETURN_THROWS();
}
if (Z_TYPE_P(obj) == IS_STRING) {
if (NULL == (ce = spl_find_ce_by_name(Z_STR_P(obj), autoload))) {
RETURN_FALSE;
}
} else {
ce = Z_OBJCE_P(obj);
}
array_init(return_value);
spl_add_traits(return_value, ce, 1, ZEND_ACC_TRAIT);
}
/* }}} */
#define SPL_ADD_CLASS(class_name, z_list, sub, allow, ce_flags) \
spl_add_classes(spl_ce_ ## class_name, z_list, sub, allow, ce_flags)
#define SPL_LIST_CLASSES(z_list, sub, allow, ce_flags) \
SPL_ADD_CLASS(AppendIterator, z_list, sub, allow, ce_flags); \
SPL_ADD_CLASS(ArrayIterator, z_list, sub, allow, ce_flags); \
SPL_ADD_CLASS(ArrayObject, z_list, sub, allow, ce_flags); \
SPL_ADD_CLASS(BadFunctionCallException, z_list, sub, allow, ce_flags); \
SPL_ADD_CLASS(BadMethodCallException, z_list, sub, allow, ce_flags); \
SPL_ADD_CLASS(CachingIterator, z_list, sub, allow, ce_flags); \
SPL_ADD_CLASS(CallbackFilterIterator, z_list, sub, allow, ce_flags); \
SPL_ADD_CLASS(DirectoryIterator, z_list, sub, allow, ce_flags); \
SPL_ADD_CLASS(DomainException, z_list, sub, allow, ce_flags); \
SPL_ADD_CLASS(EmptyIterator, z_list, sub, allow, ce_flags); \
SPL_ADD_CLASS(FilesystemIterator, z_list, sub, allow, ce_flags); \
SPL_ADD_CLASS(FilterIterator, z_list, sub, allow, ce_flags); \
SPL_ADD_CLASS(GlobIterator, z_list, sub, allow, ce_flags); \
SPL_ADD_CLASS(InfiniteIterator, z_list, sub, allow, ce_flags); \
SPL_ADD_CLASS(InvalidArgumentException, z_list, sub, allow, ce_flags); \
SPL_ADD_CLASS(IteratorIterator, z_list, sub, allow, ce_flags); \
SPL_ADD_CLASS(LengthException, z_list, sub, allow, ce_flags); \
SPL_ADD_CLASS(LimitIterator, z_list, sub, allow, ce_flags); \
SPL_ADD_CLASS(LogicException, z_list, sub, allow, ce_flags); \
SPL_ADD_CLASS(MultipleIterator, z_list, sub, allow, ce_flags); \
SPL_ADD_CLASS(NoRewindIterator, z_list, sub, allow, ce_flags); \
SPL_ADD_CLASS(OuterIterator, z_list, sub, allow, ce_flags); \
SPL_ADD_CLASS(OutOfBoundsException, z_list, sub, allow, ce_flags); \
SPL_ADD_CLASS(OutOfRangeException, z_list, sub, allow, ce_flags); \
SPL_ADD_CLASS(OverflowException, z_list, sub, allow, ce_flags); \
SPL_ADD_CLASS(ParentIterator, z_list, sub, allow, ce_flags); \
SPL_ADD_CLASS(RangeException, z_list, sub, allow, ce_flags); \
SPL_ADD_CLASS(RecursiveArrayIterator, z_list, sub, allow, ce_flags); \
SPL_ADD_CLASS(RecursiveCachingIterator, z_list, sub, allow, ce_flags); \
SPL_ADD_CLASS(RecursiveCallbackFilterIterator, z_list, sub, allow, ce_flags); \
SPL_ADD_CLASS(RecursiveDirectoryIterator, z_list, sub, allow, ce_flags); \
SPL_ADD_CLASS(RecursiveFilterIterator, z_list, sub, allow, ce_flags); \
SPL_ADD_CLASS(RecursiveIterator, z_list, sub, allow, ce_flags); \
SPL_ADD_CLASS(RecursiveIteratorIterator, z_list, sub, allow, ce_flags); \
SPL_ADD_CLASS(RecursiveRegexIterator, z_list, sub, allow, ce_flags); \
SPL_ADD_CLASS(RecursiveTreeIterator, z_list, sub, allow, ce_flags); \
SPL_ADD_CLASS(RegexIterator, z_list, sub, allow, ce_flags); \
SPL_ADD_CLASS(RuntimeException, z_list, sub, allow, ce_flags); \
SPL_ADD_CLASS(SeekableIterator, z_list, sub, allow, ce_flags); \
SPL_ADD_CLASS(SplDoublyLinkedList, z_list, sub, allow, ce_flags); \
SPL_ADD_CLASS(SplFileInfo, z_list, sub, allow, ce_flags); \
SPL_ADD_CLASS(SplFileObject, z_list, sub, allow, ce_flags); \
SPL_ADD_CLASS(SplFixedArray, z_list, sub, allow, ce_flags); \
SPL_ADD_CLASS(SplHeap, z_list, sub, allow, ce_flags); \
SPL_ADD_CLASS(SplMinHeap, z_list, sub, allow, ce_flags); \
SPL_ADD_CLASS(SplMaxHeap, z_list, sub, allow, ce_flags); \
SPL_ADD_CLASS(SplObjectStorage, z_list, sub, allow, ce_flags); \
SPL_ADD_CLASS(SplObserver, z_list, sub, allow, ce_flags); \
SPL_ADD_CLASS(SplPriorityQueue, z_list, sub, allow, ce_flags); \
SPL_ADD_CLASS(SplQueue, z_list, sub, allow, ce_flags); \
SPL_ADD_CLASS(SplStack, z_list, sub, allow, ce_flags); \
SPL_ADD_CLASS(SplSubject, z_list, sub, allow, ce_flags); \
SPL_ADD_CLASS(SplTempFileObject, z_list, sub, allow, ce_flags); \
SPL_ADD_CLASS(UnderflowException, z_list, sub, allow, ce_flags); \
SPL_ADD_CLASS(UnexpectedValueException, z_list, sub, allow, ce_flags); \
/* {{{ Return an array containing the names of all clsses and interfaces defined in SPL */
PHP_FUNCTION(spl_classes)
{
if (zend_parse_parameters_none() == FAILURE) {
RETURN_THROWS();
}
array_init(return_value);
SPL_LIST_CLASSES(return_value, 0, 0, 0)
}
/* }}} */
static int spl_autoload(zend_string *class_name, zend_string *lc_name, const char *ext, int ext_len) /* {{{ */
{
zend_string *class_file;
zval dummy;
zend_file_handle file_handle;
zend_op_array *new_op_array;
zval result;
int ret;
class_file = zend_strpprintf(0, "%s%.*s", ZSTR_VAL(lc_name), ext_len, ext);
#if DEFAULT_SLASH != '\\'
{
char *ptr = ZSTR_VAL(class_file);
char *end = ptr + ZSTR_LEN(class_file);
while ((ptr = memchr(ptr, '\\', (end - ptr))) != NULL) {
*ptr = DEFAULT_SLASH;
}
}
#endif
zend_stream_init_filename_ex(&file_handle, class_file);
ret = php_stream_open_for_zend_ex(&file_handle, USE_PATH|STREAM_OPEN_FOR_INCLUDE);
if (ret == SUCCESS) {
zend_string *opened_path;
if (!file_handle.opened_path) {
file_handle.opened_path = zend_string_copy(class_file);
}
opened_path = zend_string_copy(file_handle.opened_path);
ZVAL_NULL(&dummy);
if (zend_hash_add(&EG(included_files), opened_path, &dummy)) {
new_op_array = zend_compile_file(&file_handle, ZEND_REQUIRE);
} else {
new_op_array = NULL;
}
zend_string_release_ex(opened_path, 0);
if (new_op_array) {
uint32_t orig_jit_trace_num = EG(jit_trace_num);
ZVAL_UNDEF(&result);
zend_execute(new_op_array, &result);
EG(jit_trace_num) = orig_jit_trace_num;
destroy_op_array(new_op_array);
efree(new_op_array);
if (!EG(exception)) {
zval_ptr_dtor(&result);
}
zend_destroy_file_handle(&file_handle);
zend_string_release(class_file);
return zend_hash_exists(EG(class_table), lc_name);
}
}
zend_destroy_file_handle(&file_handle);
zend_string_release(class_file);
return 0;
} /* }}} */
/* {{{ Default autoloader implementation */
PHP_FUNCTION(spl_autoload)
{
int pos_len, pos1_len;
char *pos, *pos1;
zend_string *class_name, *lc_name, *file_exts = NULL;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "S|S!", &class_name, &file_exts) == FAILURE) {
RETURN_THROWS();
}
if (!file_exts) {
file_exts = spl_autoload_extensions;
}
if (file_exts == NULL) { /* autoload_extensions is not initialized, set to defaults */
pos = SPL_DEFAULT_FILE_EXTENSIONS;
pos_len = sizeof(SPL_DEFAULT_FILE_EXTENSIONS) - 1;
} else {
pos = ZSTR_VAL(file_exts);
pos_len = (int)ZSTR_LEN(file_exts);
}
lc_name = zend_string_tolower(class_name);
while (pos && *pos && !EG(exception)) {
pos1 = strchr(pos, ',');
if (pos1) {
pos1_len = (int)(pos1 - pos);
} else {
pos1_len = pos_len;
}
if (spl_autoload(class_name, lc_name, pos, pos1_len)) {
break; /* loaded */
}
pos = pos1 ? pos1 + 1 : NULL;
pos_len = pos1? pos_len - pos1_len - 1 : 0;
}
zend_string_release(lc_name);
} /* }}} */
/* {{{ Register and return default file extensions for spl_autoload */
PHP_FUNCTION(spl_autoload_extensions)
{
zend_string *file_exts = NULL;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "|S!", &file_exts) == FAILURE) {
RETURN_THROWS();
}
if (file_exts) {
if (spl_autoload_extensions) {
zend_string_release_ex(spl_autoload_extensions, 0);
}
spl_autoload_extensions = zend_string_copy(file_exts);
}
if (spl_autoload_extensions == NULL) {
RETURN_STRINGL(SPL_DEFAULT_FILE_EXTENSIONS, sizeof(SPL_DEFAULT_FILE_EXTENSIONS) - 1);
} else {
zend_string_addref(spl_autoload_extensions);
RETURN_STR(spl_autoload_extensions);
}
} /* }}} */
typedef struct {
zend_function *func_ptr;
zend_object *obj;
zend_object *closure;
zend_class_entry *ce;
} autoload_func_info;
static void autoload_func_info_destroy(autoload_func_info *alfi) {
if (alfi->obj) {
zend_object_release(alfi->obj);
}
if (alfi->func_ptr &&
UNEXPECTED(alfi->func_ptr->common.fn_flags & ZEND_ACC_CALL_VIA_TRAMPOLINE)) {
zend_string_release_ex(alfi->func_ptr->common.function_name, 0);
zend_free_trampoline(alfi->func_ptr);
}
if (alfi->closure) {
zend_object_release(alfi->closure);
}
efree(alfi);
}
static void autoload_func_info_zval_dtor(zval *element)
{
autoload_func_info_destroy(Z_PTR_P(element));
}
static autoload_func_info *autoload_func_info_from_fci(
zend_fcall_info *fci, zend_fcall_info_cache *fcc) {
autoload_func_info *alfi = emalloc(sizeof(autoload_func_info));
alfi->ce = fcc->calling_scope;
alfi->func_ptr = fcc->function_handler;
alfi->obj = fcc->object;
if (alfi->obj) {
GC_ADDREF(alfi->obj);
}
if (Z_TYPE(fci->function_name) == IS_OBJECT) {
alfi->closure = Z_OBJ(fci->function_name);
GC_ADDREF(alfi->closure);
} else {
alfi->closure = NULL;
}
return alfi;
}
static bool autoload_func_info_equals(
const autoload_func_info *alfi1, const autoload_func_info *alfi2) {
if (UNEXPECTED(
(alfi1->func_ptr->common.fn_flags & ZEND_ACC_CALL_VIA_TRAMPOLINE) &&
(alfi2->func_ptr->common.fn_flags & ZEND_ACC_CALL_VIA_TRAMPOLINE)
)) {
return alfi1->obj == alfi2->obj
&& alfi1->ce == alfi2->ce
&& alfi1->closure == alfi2->closure
&& zend_string_equals(alfi1->func_ptr->common.function_name, alfi2->func_ptr->common.function_name)
;
}
return alfi1->func_ptr == alfi2->func_ptr
&& alfi1->obj == alfi2->obj
&& alfi1->ce == alfi2->ce
&& alfi1->closure == alfi2->closure;
}
static zend_class_entry *spl_perform_autoload(zend_string *class_name, zend_string *lc_name) {
if (!spl_autoload_functions) {
return NULL;
}
/* We don't use ZEND_HASH_MAP_FOREACH here,
* because autoloaders may be added/removed during autoloading. */
HashPosition pos;
zend_hash_internal_pointer_reset_ex(spl_autoload_functions, &pos);
while (1) {
autoload_func_info *alfi =
zend_hash_get_current_data_ptr_ex(spl_autoload_functions, &pos);
if (!alfi) {
break;
}
zend_function *func = alfi->func_ptr;
if (UNEXPECTED(func->common.fn_flags & ZEND_ACC_CALL_VIA_TRAMPOLINE)) {
func = emalloc(sizeof(zend_op_array));
memcpy(func, alfi->func_ptr, sizeof(zend_op_array));
zend_string_addref(func->op_array.function_name);
}
zval param;
ZVAL_STR(¶m, class_name);
zend_call_known_function(func, alfi->obj, alfi->ce, NULL, 1, ¶m, NULL);
if (EG(exception)) {
break;
}
if (ZSTR_HAS_CE_CACHE(class_name) && ZSTR_GET_CE_CACHE(class_name)) {
return (zend_class_entry*)ZSTR_GET_CE_CACHE(class_name);
} else {
zend_class_entry *ce = zend_hash_find_ptr(EG(class_table), lc_name);
if (ce) {
return ce;
}
}
zend_hash_move_forward_ex(spl_autoload_functions, &pos);
}
return NULL;
}
/* {{{ Try all registered autoload function to load the requested class */
PHP_FUNCTION(spl_autoload_call)
{
zend_string *class_name;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "S", &class_name) == FAILURE) {
RETURN_THROWS();
}
zend_string *lc_name = zend_string_tolower(class_name);
spl_perform_autoload(class_name, lc_name);
zend_string_release(lc_name);
} /* }}} */
#define HT_MOVE_TAIL_TO_HEAD(ht) \
ZEND_ASSERT(!HT_IS_PACKED(ht)); \
do { \
Bucket tmp = (ht)->arData[(ht)->nNumUsed-1]; \
memmove((ht)->arData + 1, (ht)->arData, \
sizeof(Bucket) * ((ht)->nNumUsed - 1)); \
(ht)->arData[0] = tmp; \
zend_hash_rehash(ht); \
} while (0)
static Bucket *spl_find_registered_function(autoload_func_info *find_alfi) {
if (!spl_autoload_functions) {
return NULL;
}
autoload_func_info *alfi;
ZEND_HASH_MAP_FOREACH_PTR(spl_autoload_functions, alfi) {
if (autoload_func_info_equals(alfi, find_alfi)) {
return _p;
}
} ZEND_HASH_FOREACH_END();
return NULL;
}
/* {{{ Register given function as autoloader */
PHP_FUNCTION(spl_autoload_register)
{
bool do_throw = 1;
bool prepend = 0;
zend_fcall_info fci = {0};
zend_fcall_info_cache fcc;
autoload_func_info *alfi;
ZEND_PARSE_PARAMETERS_START(0, 3)
Z_PARAM_OPTIONAL
Z_PARAM_FUNC_OR_NULL(fci, fcc)
Z_PARAM_BOOL(do_throw)
Z_PARAM_BOOL(prepend)
ZEND_PARSE_PARAMETERS_END();
if (!do_throw) {
php_error_docref(NULL, E_NOTICE, "Argument #2 ($do_throw) has been ignored, "
"spl_autoload_register() will always throw");
}
if (!spl_autoload_functions) {
ALLOC_HASHTABLE(spl_autoload_functions);
zend_hash_init(spl_autoload_functions, 1, NULL, autoload_func_info_zval_dtor, 0);
/* Initialize as non-packed hash table for prepend functionality. */
zend_hash_real_init_mixed(spl_autoload_functions);
}
/* If first arg is not null */
if (ZEND_FCI_INITIALIZED(fci)) {
if (!fcc.function_handler) {
/* Call trampoline has been cleared by zpp. Refetch it, because we want to deal
* with it outselves. It is important that it is not refetched on every call,
* because calls may occur from different scopes. */
zend_is_callable_ex(&fci.function_name, NULL, IS_CALLABLE_SUPPRESS_DEPRECATIONS, NULL, &fcc, NULL);
}
if (fcc.function_handler->type == ZEND_INTERNAL_FUNCTION &&
fcc.function_handler->internal_function.handler == zif_spl_autoload_call) {
zend_argument_value_error(1, "must not be the spl_autoload_call() function");
RETURN_THROWS();
}
alfi = autoload_func_info_from_fci(&fci, &fcc);
if (UNEXPECTED(alfi->func_ptr == &EG(trampoline))) {
zend_function *copy = emalloc(sizeof(zend_op_array));
memcpy(copy, alfi->func_ptr, sizeof(zend_op_array));
alfi->func_ptr->common.function_name = NULL;
alfi->func_ptr = copy;
}
} else {
alfi = emalloc(sizeof(autoload_func_info));
alfi->func_ptr = zend_hash_str_find_ptr(
CG(function_table), "spl_autoload", sizeof("spl_autoload") - 1);
alfi->obj = NULL;
alfi->ce = NULL;
alfi->closure = NULL;
}
if (spl_find_registered_function(alfi)) {
autoload_func_info_destroy(alfi);
RETURN_TRUE;
}
zend_hash_next_index_insert_ptr(spl_autoload_functions, alfi);
if (prepend && spl_autoload_functions->nNumOfElements > 1) {
/* Move the newly created element to the head of the hashtable */
HT_MOVE_TAIL_TO_HEAD(spl_autoload_functions);
}
RETURN_TRUE;
} /* }}} */
/* {{{ Unregister given function as autoloader */
PHP_FUNCTION(spl_autoload_unregister)
{
zend_fcall_info fci;
zend_fcall_info_cache fcc;
ZEND_PARSE_PARAMETERS_START(1, 1)
Z_PARAM_FUNC(fci, fcc)
ZEND_PARSE_PARAMETERS_END();
if (fcc.function_handler && zend_string_equals_literal(
fcc.function_handler->common.function_name, "spl_autoload_call")) {
/* Don't destroy the hash table, as we might be iterating over it right now. */
zend_hash_clean(spl_autoload_functions);
RETURN_TRUE;
}
if (!fcc.function_handler) {
/* Call trampoline has been cleared by zpp. Refetch it, because we want to deal
* with it outselves. It is important that it is not refetched on every call,
* because calls may occur from different scopes. */
zend_is_callable_ex(&fci.function_name, NULL, 0, NULL, &fcc, NULL);
}
autoload_func_info *alfi = autoload_func_info_from_fci(&fci, &fcc);
Bucket *p = spl_find_registered_function(alfi);
autoload_func_info_destroy(alfi);
if (p) {
zend_hash_del_bucket(spl_autoload_functions, p);
RETURN_TRUE;
}
RETURN_FALSE;
} /* }}} */
/* {{{ Return all registered autoloader functions */
PHP_FUNCTION(spl_autoload_functions)
{
autoload_func_info *alfi;
if (zend_parse_parameters_none() == FAILURE) {
RETURN_THROWS();
}
array_init(return_value);
if (spl_autoload_functions) {
ZEND_HASH_MAP_FOREACH_PTR(spl_autoload_functions, alfi) {
if (alfi->closure) {
GC_ADDREF(alfi->closure);
add_next_index_object(return_value, alfi->closure);
} else if (alfi->func_ptr->common.scope) {
zval tmp;
array_init(&tmp);
if (alfi->obj) {
GC_ADDREF(alfi->obj);
add_next_index_object(&tmp, alfi->obj);
} else {
add_next_index_str(&tmp, zend_string_copy(alfi->ce->name));
}
add_next_index_str(&tmp, zend_string_copy(alfi->func_ptr->common.function_name));
add_next_index_zval(return_value, &tmp);
} else {
add_next_index_str(return_value, zend_string_copy(alfi->func_ptr->common.function_name));
}
} ZEND_HASH_FOREACH_END();
}
} /* }}} */
/* {{{ Return hash id for given object */
PHP_FUNCTION(spl_object_hash)
{
zend_object *obj;
ZEND_PARSE_PARAMETERS_START(1, 1)
Z_PARAM_OBJ(obj)
ZEND_PARSE_PARAMETERS_END();
RETURN_NEW_STR(php_spl_object_hash(obj));
}
/* }}} */
/* {{{ Returns the integer object handle for the given object */
PHP_FUNCTION(spl_object_id)
{
zend_object *obj;
ZEND_PARSE_PARAMETERS_START(1, 1)
Z_PARAM_OBJ(obj)
ZEND_PARSE_PARAMETERS_END();
RETURN_LONG((zend_long)obj->handle);
}
/* }}} */
PHPAPI zend_string *php_spl_object_hash(zend_object *obj) /* {{{*/
{
return strpprintf(32, "%016zx0000000000000000", (intptr_t)obj->handle);
}
/* }}} */
static void spl_build_class_list_string(zval *entry, char **list) /* {{{ */
{
char *res;
spprintf(&res, 0, "%s, %s", *list, Z_STRVAL_P(entry));
efree(*list);
*list = res;
} /* }}} */
/* {{{ PHP_MINFO(spl) */
PHP_MINFO_FUNCTION(spl)
{
zval list, *zv;
char *strg;
php_info_print_table_start();
php_info_print_table_row(2, "SPL support", "enabled");
array_init(&list);
SPL_LIST_CLASSES(&list, 0, 1, ZEND_ACC_INTERFACE)
strg = estrdup("");
ZEND_HASH_MAP_FOREACH_VAL(Z_ARRVAL_P(&list), zv) {
spl_build_class_list_string(zv, &strg);
} ZEND_HASH_FOREACH_END();
zend_array_destroy(Z_ARR(list));
php_info_print_table_row(2, "Interfaces", strg + 2);
efree(strg);
array_init(&list);
SPL_LIST_CLASSES(&list, 0, -1, ZEND_ACC_INTERFACE)
strg = estrdup("");
ZEND_HASH_MAP_FOREACH_VAL(Z_ARRVAL_P(&list), zv) {
spl_build_class_list_string(zv, &strg);
} ZEND_HASH_FOREACH_END();
zend_array_destroy(Z_ARR(list));
php_info_print_table_row(2, "Classes", strg + 2);
efree(strg);
php_info_print_table_end();
}
/* }}} */
/* {{{ PHP_MINIT_FUNCTION(spl) */
PHP_MINIT_FUNCTION(spl)
{
zend_autoload = spl_perform_autoload;
PHP_MINIT(spl_exceptions)(INIT_FUNC_ARGS_PASSTHRU);
PHP_MINIT(spl_iterators)(INIT_FUNC_ARGS_PASSTHRU);
PHP_MINIT(spl_array)(INIT_FUNC_ARGS_PASSTHRU);
PHP_MINIT(spl_directory)(INIT_FUNC_ARGS_PASSTHRU);
PHP_MINIT(spl_dllist)(INIT_FUNC_ARGS_PASSTHRU);
PHP_MINIT(spl_heap)(INIT_FUNC_ARGS_PASSTHRU);
PHP_MINIT(spl_fixedarray)(INIT_FUNC_ARGS_PASSTHRU);
PHP_MINIT(spl_observer)(INIT_FUNC_ARGS_PASSTHRU);
return SUCCESS;
}
/* }}} */
PHP_RINIT_FUNCTION(spl) /* {{{ */
{
spl_autoload_extensions = NULL;
spl_autoload_functions = NULL;
return SUCCESS;
} /* }}} */
PHP_RSHUTDOWN_FUNCTION(spl) /* {{{ */
{
if (spl_autoload_extensions) {
zend_string_release_ex(spl_autoload_extensions, 0);
spl_autoload_extensions = NULL;
}
if (spl_autoload_functions) {
zend_hash_destroy(spl_autoload_functions);
FREE_HASHTABLE(spl_autoload_functions);
spl_autoload_functions = NULL;
}
return SUCCESS;
} /* }}} */
static const zend_module_dep spl_deps[] = {
ZEND_MOD_REQUIRED("json")
ZEND_MOD_END
};
zend_module_entry spl_module_entry = {
STANDARD_MODULE_HEADER_EX, NULL,
spl_deps,
"SPL",
ext_functions,
PHP_MINIT(spl),
NULL,
PHP_RINIT(spl),
PHP_RSHUTDOWN(spl),
PHP_MINFO(spl),
PHP_SPL_VERSION,
STANDARD_MODULE_PROPERTIES
};
| 23,735 | 29.469833 | 125 |
c
|
php-src
|
php-src-master/ext/spl/php_spl.h
|
/*
+----------------------------------------------------------------------+
| Copyright (c) The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| https://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| [email protected] so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Authors: Marcus Boerger <[email protected]> |
+----------------------------------------------------------------------+
*/
#ifndef PHP_SPL_H
#define PHP_SPL_H
#include "php.h"
#include <stdarg.h>
#define PHP_SPL_VERSION PHP_VERSION
extern zend_module_entry spl_module_entry;
#define phpext_spl_ptr &spl_module_entry
#ifdef PHP_WIN32
# ifdef SPL_EXPORTS
# define SPL_API __declspec(dllexport)
# elif defined(COMPILE_DL_SPL)
# define SPL_API __declspec(dllimport)
# else
# define SPL_API /* nothing */
# endif
#elif defined(__GNUC__) && __GNUC__ >= 4
# define SPL_API __attribute__ ((visibility("default")))
#else
# define SPL_API
#endif
#if defined(PHP_WIN32) && !defined(COMPILE_DL_SPL)
#undef phpext_spl
#define phpext_spl NULL
#endif
PHP_MINIT_FUNCTION(spl);
PHP_MSHUTDOWN_FUNCTION(spl);
PHP_RINIT_FUNCTION(spl);
PHP_RSHUTDOWN_FUNCTION(spl);
PHP_MINFO_FUNCTION(spl);
PHPAPI zend_string *php_spl_object_hash(zend_object *obj);
#endif /* PHP_SPL_H */
| 1,835 | 31.785714 | 75 |
h
|
php-src
|
php-src-master/ext/spl/php_spl_arginfo.h
|
/* This is a generated file, edit the .stub.php file instead.
* Stub hash: 21ec2dcca99c85c90afcd319da76016a9f678dc2 */
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_class_implements, 0, 1, MAY_BE_ARRAY|MAY_BE_FALSE)
ZEND_ARG_INFO(0, object_or_class)
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, autoload, _IS_BOOL, 0, "true")
ZEND_END_ARG_INFO()
#define arginfo_class_parents arginfo_class_implements
#define arginfo_class_uses arginfo_class_implements
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_spl_autoload, 0, 1, IS_VOID, 0)
ZEND_ARG_TYPE_INFO(0, class, IS_STRING, 0)
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, file_extensions, IS_STRING, 1, "null")
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_spl_autoload_call, 0, 1, IS_VOID, 0)
ZEND_ARG_TYPE_INFO(0, class, IS_STRING, 0)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_spl_autoload_extensions, 0, 0, IS_STRING, 0)
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, file_extensions, IS_STRING, 1, "null")
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_spl_autoload_functions, 0, 0, IS_ARRAY, 0)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_spl_autoload_register, 0, 0, _IS_BOOL, 0)
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, callback, IS_CALLABLE, 1, "null")
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, throw, _IS_BOOL, 0, "true")
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, prepend, _IS_BOOL, 0, "false")
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_spl_autoload_unregister, 0, 1, _IS_BOOL, 0)
ZEND_ARG_TYPE_INFO(0, callback, IS_CALLABLE, 0)
ZEND_END_ARG_INFO()
#define arginfo_spl_classes arginfo_spl_autoload_functions
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_spl_object_hash, 0, 1, IS_STRING, 0)
ZEND_ARG_TYPE_INFO(0, object, IS_OBJECT, 0)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_spl_object_id, 0, 1, IS_LONG, 0)
ZEND_ARG_TYPE_INFO(0, object, IS_OBJECT, 0)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_iterator_apply, 0, 2, IS_LONG, 0)
ZEND_ARG_OBJ_INFO(0, iterator, Traversable, 0)
ZEND_ARG_TYPE_INFO(0, callback, IS_CALLABLE, 0)
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, args, IS_ARRAY, 1, "null")
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_iterator_count, 0, 1, IS_LONG, 0)
ZEND_ARG_OBJ_TYPE_MASK(0, iterator, Traversable, MAY_BE_ARRAY, NULL)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_iterator_to_array, 0, 1, IS_ARRAY, 0)
ZEND_ARG_OBJ_TYPE_MASK(0, iterator, Traversable, MAY_BE_ARRAY, NULL)
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, preserve_keys, _IS_BOOL, 0, "true")
ZEND_END_ARG_INFO()
ZEND_FUNCTION(class_implements);
ZEND_FUNCTION(class_parents);
ZEND_FUNCTION(class_uses);
ZEND_FUNCTION(spl_autoload);
ZEND_FUNCTION(spl_autoload_call);
ZEND_FUNCTION(spl_autoload_extensions);
ZEND_FUNCTION(spl_autoload_functions);
ZEND_FUNCTION(spl_autoload_register);
ZEND_FUNCTION(spl_autoload_unregister);
ZEND_FUNCTION(spl_classes);
ZEND_FUNCTION(spl_object_hash);
ZEND_FUNCTION(spl_object_id);
ZEND_FUNCTION(iterator_apply);
ZEND_FUNCTION(iterator_count);
ZEND_FUNCTION(iterator_to_array);
static const zend_function_entry ext_functions[] = {
ZEND_FE(class_implements, arginfo_class_implements)
ZEND_FE(class_parents, arginfo_class_parents)
ZEND_FE(class_uses, arginfo_class_uses)
ZEND_FE(spl_autoload, arginfo_spl_autoload)
ZEND_FE(spl_autoload_call, arginfo_spl_autoload_call)
ZEND_FE(spl_autoload_extensions, arginfo_spl_autoload_extensions)
ZEND_FE(spl_autoload_functions, arginfo_spl_autoload_functions)
ZEND_FE(spl_autoload_register, arginfo_spl_autoload_register)
ZEND_FE(spl_autoload_unregister, arginfo_spl_autoload_unregister)
ZEND_FE(spl_classes, arginfo_spl_classes)
ZEND_FE(spl_object_hash, arginfo_spl_object_hash)
ZEND_FE(spl_object_id, arginfo_spl_object_id)
ZEND_FE(iterator_apply, arginfo_iterator_apply)
ZEND_FE(iterator_count, arginfo_iterator_count)
ZEND_FE(iterator_to_array, arginfo_iterator_to_array)
ZEND_FE_END
};
| 4,053 | 39.54 | 98 |
h
|
php-src
|
php-src-master/ext/spl/spl_array.h
|
/*
+----------------------------------------------------------------------+
| Copyright (c) The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| https://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| [email protected] so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Authors: Marcus Boerger <[email protected]> |
+----------------------------------------------------------------------+
*/
#ifndef SPL_ARRAY_H
#define SPL_ARRAY_H
#include "php.h"
#include "php_spl.h"
#include "spl_iterators.h"
#define SPL_ARRAY_STD_PROP_LIST 0x00000001
#define SPL_ARRAY_ARRAY_AS_PROPS 0x00000002
#define SPL_ARRAY_CHILD_ARRAYS_ONLY 0x00000004
#define SPL_ARRAY_IS_SELF 0x01000000
#define SPL_ARRAY_USE_OTHER 0x02000000
#define SPL_ARRAY_INT_MASK 0xFFFF0000
#define SPL_ARRAY_CLONE_MASK 0x0100FFFF
#define SPL_ARRAY_METHOD_NO_ARG 0
#define SPL_ARRAY_METHOD_CALLBACK_ARG 1
#define SPL_ARRAY_METHOD_SORT_FLAGS_ARG 2
extern PHPAPI zend_class_entry *spl_ce_ArrayObject;
extern PHPAPI zend_class_entry *spl_ce_ArrayIterator;
extern PHPAPI zend_class_entry *spl_ce_RecursiveArrayIterator;
PHP_MINIT_FUNCTION(spl_array);
extern void spl_array_iterator_append(zval *object, zval *append_value);
extern void spl_array_iterator_key(zval *object, zval *return_value);
#endif /* SPL_ARRAY_H */
| 1,935 | 41.086957 | 75 |
h
|
php-src
|
php-src-master/ext/spl/spl_directory.h
|
/*
+----------------------------------------------------------------------+
| Copyright (c) The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| https://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| [email protected] so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Authors: Marcus Boerger <[email protected]> |
+----------------------------------------------------------------------+
*/
#ifndef SPL_DIRECTORY_H
#define SPL_DIRECTORY_H
#include "php.h"
#include "php_spl.h"
extern PHPAPI zend_class_entry *spl_ce_SplFileInfo;
extern PHPAPI zend_class_entry *spl_ce_DirectoryIterator;
extern PHPAPI zend_class_entry *spl_ce_FilesystemIterator;
extern PHPAPI zend_class_entry *spl_ce_RecursiveDirectoryIterator;
extern PHPAPI zend_class_entry *spl_ce_GlobIterator;
extern PHPAPI zend_class_entry *spl_ce_SplFileObject;
extern PHPAPI zend_class_entry *spl_ce_SplTempFileObject;
PHP_MINIT_FUNCTION(spl_directory);
/* Internal objecte structure and helpers for Directory and File SPL objects */
typedef struct _spl_filesystem_object spl_filesystem_object;
typedef void (*spl_foreign_dtor_t)(spl_filesystem_object *object);
typedef void (*spl_foreign_clone_t)(spl_filesystem_object *src, spl_filesystem_object *dst);
PHPAPI zend_string *spl_filesystem_object_get_path(spl_filesystem_object *intern);
typedef struct _spl_other_handler {
spl_foreign_dtor_t dtor;
spl_foreign_clone_t clone;
} spl_other_handler;
typedef enum {
SPL_FS_INFO, /* must be 0 */
SPL_FS_DIR,
SPL_FS_FILE
} SPL_FS_OBJ_TYPE;
struct _spl_filesystem_object {
void *oth;
const spl_other_handler *oth_handler;
zend_string *path;
zend_string *orig_path;
zend_string *file_name;
SPL_FS_OBJ_TYPE type;
zend_long flags;
zend_class_entry *file_class;
zend_class_entry *info_class;
union {
struct {
php_stream *dirp;
zend_string *sub_path;
int index;
zend_function *func_rewind;
zend_function *func_next;
zend_function *func_valid;
php_stream_dirent entry;
} dir;
struct {
php_stream *stream;
php_stream_context *context;
zval *zcontext;
zend_string *open_mode;
zval current_zval;
char *current_line;
size_t current_line_len;
size_t max_line_len;
zend_long current_line_num;
zval zresource;
zend_function *func_getCurr;
char delimiter;
char enclosure;
int escape;
} file;
} u;
zend_object std;
};
#define SPL_FILE_OBJECT_DROP_NEW_LINE 0x00000001 /* drop new lines */
#define SPL_FILE_OBJECT_READ_AHEAD 0x00000002 /* read on rewind/next */
#define SPL_FILE_OBJECT_SKIP_EMPTY 0x00000004 /* skip empty lines */
#define SPL_FILE_OBJECT_READ_CSV 0x00000008 /* read via fgetcsv */
#define SPL_FILE_OBJECT_MASK 0x0000000F /* read via fgetcsv */
#define SPL_FILE_DIR_CURRENT_AS_FILEINFO 0x00000000 /* make RecursiveDirectoryTree::current() return SplFileInfo */
#define SPL_FILE_DIR_CURRENT_AS_SELF 0x00000010 /* make RecursiveDirectoryTree::current() return getSelf() */
#define SPL_FILE_DIR_CURRENT_AS_PATHNAME 0x00000020 /* make RecursiveDirectoryTree::current() return getPathname() */
#define SPL_FILE_DIR_CURRENT_MODE_MASK 0x000000F0 /* mask RecursiveDirectoryTree::current() */
#define SPL_FILE_DIR_CURRENT(intern,mode) ((intern->flags&SPL_FILE_DIR_CURRENT_MODE_MASK)==mode)
#define SPL_FILE_DIR_KEY_AS_PATHNAME 0x00000000 /* make RecursiveDirectoryTree::key() return getPathname() */
#define SPL_FILE_DIR_KEY_AS_FILENAME 0x00000100 /* make RecursiveDirectoryTree::key() return getFilename() */
#define SPL_FILE_DIR_KEY_MODE_MASK 0x00000F00 /* mask RecursiveDirectoryTree::key() */
#define SPL_FILE_NEW_CURRENT_AND_KEY SPL_FILE_DIR_KEY_AS_FILENAME|SPL_FILE_DIR_CURRENT_AS_FILEINFO
#define SPL_FILE_DIR_KEY(intern,mode) ((intern->flags&SPL_FILE_DIR_KEY_MODE_MASK)==mode)
#define SPL_FILE_DIR_SKIPDOTS 0x00001000 /* Tells whether it should skip dots or not */
#define SPL_FILE_DIR_UNIXPATHS 0x00002000 /* Whether to unixify path separators */
#define SPL_FILE_DIR_FOLLOW_SYMLINKS 0x00004000 /* make RecursiveDirectoryTree::hasChildren() follow symlinks */
#define SPL_FILE_DIR_OTHERS_MASK 0x00007000 /* mask used for get/setFlags */
#endif /* SPL_DIRECTORY_H */
| 5,131 | 43.241379 | 119 |
h
|
php-src
|
php-src-master/ext/spl/spl_dllist.h
|
/*
+----------------------------------------------------------------------+
| Copyright (c) The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| https://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| [email protected] so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Authors: Etienne Kneuss <[email protected]> |
+----------------------------------------------------------------------+
*/
#ifndef SPL_DLLIST_H
#define SPL_DLLIST_H
#include "php.h"
#include "php_spl.h"
#define SPL_DLLIST_IT_KEEP 0x00000000
#define SPL_DLLIST_IT_FIFO 0x00000000 /* FIFO flag makes the iterator traverse the structure as a FirstInFirstOut */
#define SPL_DLLIST_IT_DELETE 0x00000001 /* Delete flag makes the iterator delete the current element on next */
#define SPL_DLLIST_IT_LIFO 0x00000002 /* LIFO flag makes the iterator traverse the structure as a LastInFirstOut */
#define SPL_DLLIST_IT_MASK 0x00000003 /* Mask to isolate flags related to iterators */
#define SPL_DLLIST_IT_FIX 0x00000004 /* Backward/Forward bit is fixed */
extern PHPAPI zend_class_entry *spl_ce_SplDoublyLinkedList;
extern PHPAPI zend_class_entry *spl_ce_SplQueue;
extern PHPAPI zend_class_entry *spl_ce_SplStack;
PHP_MINIT_FUNCTION(spl_dllist);
#endif /* SPL_DLLIST_H */
| 1,851 | 49.054054 | 118 |
h
|
php-src
|
php-src-master/ext/spl/spl_engine.h
|
/*
+----------------------------------------------------------------------+
| Copyright (c) The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| https://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| [email protected] so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Authors: Marcus Boerger <[email protected]> |
+----------------------------------------------------------------------+
*/
#ifndef SPL_ENGINE_H
#define SPL_ENGINE_H
#include "php.h"
#include "php_spl.h"
#include "zend_interfaces.h"
static inline void spl_instantiate_arg_ex1(zend_class_entry *pce, zval *retval, zval *arg1)
{
object_init_ex(retval, pce);
zend_call_known_instance_method_with_1_params(pce->constructor, Z_OBJ_P(retval), NULL, arg1);
}
static inline void spl_instantiate_arg_ex2(
zend_class_entry *pce, zval *retval, zval *arg1, zval *arg2)
{
object_init_ex(retval, pce);
zend_call_known_instance_method_with_2_params(
pce->constructor, Z_OBJ_P(retval), NULL, arg1, arg2);
}
static inline void spl_instantiate_arg_n(
zend_class_entry *pce, zval *retval, uint32_t argc, zval *argv)
{
object_init_ex(retval, pce);
zend_call_known_instance_method(pce->constructor, Z_OBJ_P(retval), NULL, argc, argv);
}
#endif /* SPL_ENGINE_H */
| 1,831 | 38.826087 | 94 |
h
|
php-src
|
php-src-master/ext/spl/spl_exceptions.c
|
/*
+----------------------------------------------------------------------+
| Copyright (c) The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| https://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| [email protected] so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Authors: Marcus Boerger <[email protected]> |
+----------------------------------------------------------------------+
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include "php.h"
#include "php_ini.h"
#include "ext/standard/info.h"
#include "zend_interfaces.h"
#include "zend_exceptions.h"
#include "spl_exceptions_arginfo.h"
#include "php_spl.h"
#include "spl_functions.h"
#include "spl_engine.h"
#include "spl_exceptions.h"
PHPAPI zend_class_entry *spl_ce_LogicException;
PHPAPI zend_class_entry *spl_ce_BadFunctionCallException;
PHPAPI zend_class_entry *spl_ce_BadMethodCallException;
PHPAPI zend_class_entry *spl_ce_DomainException;
PHPAPI zend_class_entry *spl_ce_InvalidArgumentException;
PHPAPI zend_class_entry *spl_ce_LengthException;
PHPAPI zend_class_entry *spl_ce_OutOfRangeException;
PHPAPI zend_class_entry *spl_ce_RuntimeException;
PHPAPI zend_class_entry *spl_ce_OutOfBoundsException;
PHPAPI zend_class_entry *spl_ce_OverflowException;
PHPAPI zend_class_entry *spl_ce_RangeException;
PHPAPI zend_class_entry *spl_ce_UnderflowException;
PHPAPI zend_class_entry *spl_ce_UnexpectedValueException;
#define spl_ce_Exception zend_ce_exception
/* {{{ PHP_MINIT_FUNCTION(spl_exceptions) */
PHP_MINIT_FUNCTION(spl_exceptions)
{
spl_ce_LogicException = register_class_LogicException(zend_ce_exception);
spl_ce_BadFunctionCallException = register_class_BadFunctionCallException(spl_ce_LogicException);
spl_ce_BadMethodCallException = register_class_BadMethodCallException(spl_ce_BadFunctionCallException);
spl_ce_DomainException = register_class_DomainException(spl_ce_LogicException);
spl_ce_InvalidArgumentException = register_class_InvalidArgumentException(spl_ce_LogicException);
spl_ce_LengthException = register_class_LengthException(spl_ce_LogicException);
spl_ce_OutOfRangeException = register_class_OutOfRangeException(spl_ce_LogicException);
spl_ce_RuntimeException = register_class_RuntimeException(zend_ce_exception);
spl_ce_OutOfBoundsException = register_class_OutOfBoundsException(spl_ce_RuntimeException);
spl_ce_OverflowException = register_class_OverflowException(spl_ce_RuntimeException);
spl_ce_RangeException = register_class_RangeException(spl_ce_RuntimeException);
spl_ce_UnderflowException = register_class_UnderflowException(spl_ce_RuntimeException);
spl_ce_UnexpectedValueException = register_class_UnexpectedValueException(spl_ce_RuntimeException);
return SUCCESS;
}
/* }}} */
| 3,312 | 46.328571 | 104 |
c
|
php-src
|
php-src-master/ext/spl/spl_exceptions.h
|
/*
+----------------------------------------------------------------------+
| Copyright (c) The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| https://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| [email protected] so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Authors: Marcus Boerger <[email protected]> |
+----------------------------------------------------------------------+
*/
#ifndef SPL_EXCEPTIONS_H
#define SPL_EXCEPTIONS_H
#include "php.h"
#include "php_spl.h"
extern PHPAPI zend_class_entry *spl_ce_LogicException;
extern PHPAPI zend_class_entry *spl_ce_BadFunctionCallException;
extern PHPAPI zend_class_entry *spl_ce_BadMethodCallException;
extern PHPAPI zend_class_entry *spl_ce_DomainException;
extern PHPAPI zend_class_entry *spl_ce_InvalidArgumentException;
extern PHPAPI zend_class_entry *spl_ce_LengthException;
extern PHPAPI zend_class_entry *spl_ce_OutOfRangeException;
extern PHPAPI zend_class_entry *spl_ce_RuntimeException;
extern PHPAPI zend_class_entry *spl_ce_OutOfBoundsException;
extern PHPAPI zend_class_entry *spl_ce_OverflowException;
extern PHPAPI zend_class_entry *spl_ce_RangeException;
extern PHPAPI zend_class_entry *spl_ce_UnderflowException;
extern PHPAPI zend_class_entry *spl_ce_UnexpectedValueException;
PHP_MINIT_FUNCTION(spl_exceptions);
#endif /* SPL_EXCEPTIONS_H */
| 1,930 | 46.097561 | 75 |
h
|
php-src
|
php-src-master/ext/spl/spl_exceptions_arginfo.h
|
/* This is a generated file, edit the .stub.php file instead.
* Stub hash: 07475caecc81ab3b38a04905f874615af1126289 */
static const zend_function_entry class_LogicException_methods[] = {
ZEND_FE_END
};
static const zend_function_entry class_BadFunctionCallException_methods[] = {
ZEND_FE_END
};
static const zend_function_entry class_BadMethodCallException_methods[] = {
ZEND_FE_END
};
static const zend_function_entry class_DomainException_methods[] = {
ZEND_FE_END
};
static const zend_function_entry class_InvalidArgumentException_methods[] = {
ZEND_FE_END
};
static const zend_function_entry class_LengthException_methods[] = {
ZEND_FE_END
};
static const zend_function_entry class_OutOfRangeException_methods[] = {
ZEND_FE_END
};
static const zend_function_entry class_RuntimeException_methods[] = {
ZEND_FE_END
};
static const zend_function_entry class_OutOfBoundsException_methods[] = {
ZEND_FE_END
};
static const zend_function_entry class_OverflowException_methods[] = {
ZEND_FE_END
};
static const zend_function_entry class_RangeException_methods[] = {
ZEND_FE_END
};
static const zend_function_entry class_UnderflowException_methods[] = {
ZEND_FE_END
};
static const zend_function_entry class_UnexpectedValueException_methods[] = {
ZEND_FE_END
};
static zend_class_entry *register_class_LogicException(zend_class_entry *class_entry_Exception)
{
zend_class_entry ce, *class_entry;
INIT_CLASS_ENTRY(ce, "LogicException", class_LogicException_methods);
class_entry = zend_register_internal_class_ex(&ce, class_entry_Exception);
return class_entry;
}
static zend_class_entry *register_class_BadFunctionCallException(zend_class_entry *class_entry_LogicException)
{
zend_class_entry ce, *class_entry;
INIT_CLASS_ENTRY(ce, "BadFunctionCallException", class_BadFunctionCallException_methods);
class_entry = zend_register_internal_class_ex(&ce, class_entry_LogicException);
return class_entry;
}
static zend_class_entry *register_class_BadMethodCallException(zend_class_entry *class_entry_BadFunctionCallException)
{
zend_class_entry ce, *class_entry;
INIT_CLASS_ENTRY(ce, "BadMethodCallException", class_BadMethodCallException_methods);
class_entry = zend_register_internal_class_ex(&ce, class_entry_BadFunctionCallException);
return class_entry;
}
static zend_class_entry *register_class_DomainException(zend_class_entry *class_entry_LogicException)
{
zend_class_entry ce, *class_entry;
INIT_CLASS_ENTRY(ce, "DomainException", class_DomainException_methods);
class_entry = zend_register_internal_class_ex(&ce, class_entry_LogicException);
return class_entry;
}
static zend_class_entry *register_class_InvalidArgumentException(zend_class_entry *class_entry_LogicException)
{
zend_class_entry ce, *class_entry;
INIT_CLASS_ENTRY(ce, "InvalidArgumentException", class_InvalidArgumentException_methods);
class_entry = zend_register_internal_class_ex(&ce, class_entry_LogicException);
return class_entry;
}
static zend_class_entry *register_class_LengthException(zend_class_entry *class_entry_LogicException)
{
zend_class_entry ce, *class_entry;
INIT_CLASS_ENTRY(ce, "LengthException", class_LengthException_methods);
class_entry = zend_register_internal_class_ex(&ce, class_entry_LogicException);
return class_entry;
}
static zend_class_entry *register_class_OutOfRangeException(zend_class_entry *class_entry_LogicException)
{
zend_class_entry ce, *class_entry;
INIT_CLASS_ENTRY(ce, "OutOfRangeException", class_OutOfRangeException_methods);
class_entry = zend_register_internal_class_ex(&ce, class_entry_LogicException);
return class_entry;
}
static zend_class_entry *register_class_RuntimeException(zend_class_entry *class_entry_Exception)
{
zend_class_entry ce, *class_entry;
INIT_CLASS_ENTRY(ce, "RuntimeException", class_RuntimeException_methods);
class_entry = zend_register_internal_class_ex(&ce, class_entry_Exception);
return class_entry;
}
static zend_class_entry *register_class_OutOfBoundsException(zend_class_entry *class_entry_RuntimeException)
{
zend_class_entry ce, *class_entry;
INIT_CLASS_ENTRY(ce, "OutOfBoundsException", class_OutOfBoundsException_methods);
class_entry = zend_register_internal_class_ex(&ce, class_entry_RuntimeException);
return class_entry;
}
static zend_class_entry *register_class_OverflowException(zend_class_entry *class_entry_RuntimeException)
{
zend_class_entry ce, *class_entry;
INIT_CLASS_ENTRY(ce, "OverflowException", class_OverflowException_methods);
class_entry = zend_register_internal_class_ex(&ce, class_entry_RuntimeException);
return class_entry;
}
static zend_class_entry *register_class_RangeException(zend_class_entry *class_entry_RuntimeException)
{
zend_class_entry ce, *class_entry;
INIT_CLASS_ENTRY(ce, "RangeException", class_RangeException_methods);
class_entry = zend_register_internal_class_ex(&ce, class_entry_RuntimeException);
return class_entry;
}
static zend_class_entry *register_class_UnderflowException(zend_class_entry *class_entry_RuntimeException)
{
zend_class_entry ce, *class_entry;
INIT_CLASS_ENTRY(ce, "UnderflowException", class_UnderflowException_methods);
class_entry = zend_register_internal_class_ex(&ce, class_entry_RuntimeException);
return class_entry;
}
static zend_class_entry *register_class_UnexpectedValueException(zend_class_entry *class_entry_RuntimeException)
{
zend_class_entry ce, *class_entry;
INIT_CLASS_ENTRY(ce, "UnexpectedValueException", class_UnexpectedValueException_methods);
class_entry = zend_register_internal_class_ex(&ce, class_entry_RuntimeException);
return class_entry;
}
| 5,621 | 27.11 | 118 |
h
|
php-src
|
php-src-master/ext/spl/spl_fixedarray.h
|
/*
+----------------------------------------------------------------------+
| Copyright (c) The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| https://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| [email protected] so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Author: Antony Dovgal <[email protected]> |
| Etienne Kneuss <[email protected]> |
+----------------------------------------------------------------------+
*/
#ifndef SPL_FIXEDARRAY_H
#define SPL_FIXEDARRAY_H
extern PHPAPI zend_class_entry *spl_ce_SplFixedArray;
PHP_MINIT_FUNCTION(spl_fixedarray);
#endif /* SPL_FIXEDARRAY_H */
| 1,230 | 46.346154 | 74 |
h
|
php-src
|
php-src-master/ext/spl/spl_functions.c
|
/*
+----------------------------------------------------------------------+
| Copyright (c) The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| https://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| [email protected] so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Authors: Marcus Boerger <[email protected]> |
+----------------------------------------------------------------------+
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "php.h"
#include "php_spl.h"
/* {{{ spl_add_class_name */
void spl_add_class_name(zval *list, zend_class_entry *pce, int allow, int ce_flags)
{
if (!allow || (allow > 0 && (pce->ce_flags & ce_flags)) || (allow < 0 && !(pce->ce_flags & ce_flags))) {
zval *tmp;
if ((tmp = zend_hash_find(Z_ARRVAL_P(list), pce->name)) == NULL) {
zval t;
ZVAL_STR_COPY(&t, pce->name);
zend_hash_add(Z_ARRVAL_P(list), pce->name, &t);
}
}
}
/* }}} */
/* {{{ spl_add_interfaces */
void spl_add_interfaces(zval *list, zend_class_entry * pce, int allow, int ce_flags)
{
if (pce->num_interfaces) {
ZEND_ASSERT(pce->ce_flags & ZEND_ACC_LINKED);
for (uint32_t num_interfaces = 0; num_interfaces < pce->num_interfaces; num_interfaces++) {
spl_add_class_name(list, pce->interfaces[num_interfaces], allow, ce_flags);
}
}
}
/* }}} */
/* {{{ spl_add_traits */
void spl_add_traits(zval *list, zend_class_entry * pce, int allow, int ce_flags)
{
zend_class_entry *trait;
for (uint32_t num_traits = 0; num_traits < pce->num_traits; num_traits++) {
trait = zend_fetch_class_by_name(pce->trait_names[num_traits].name,
pce->trait_names[num_traits].lc_name, ZEND_FETCH_CLASS_TRAIT);
ZEND_ASSERT(trait);
spl_add_class_name(list, trait, allow, ce_flags);
}
}
/* }}} */
/* {{{ spl_add_classes */
void spl_add_classes(zend_class_entry *pce, zval *list, bool sub, int allow, int ce_flags)
{
ZEND_ASSERT(pce);
spl_add_class_name(list, pce, allow, ce_flags);
if (sub) {
spl_add_interfaces(list, pce, allow, ce_flags);
while (pce->parent) {
pce = pce->parent;
spl_add_classes(pce, list, sub, allow, ce_flags);
}
}
}
/* }}} */
zend_string * spl_gen_private_prop_name(zend_class_entry *ce, char *prop_name, size_t prop_len) /* {{{ */
{
return zend_mangle_property_name(ZSTR_VAL(ce->name), ZSTR_LEN(ce->name), prop_name, prop_len, 0);
}
/* }}} */
| 2,915 | 32.906977 | 105 |
c
|
php-src
|
php-src-master/ext/spl/spl_functions.h
|
/*
+----------------------------------------------------------------------+
| Copyright (c) The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| https://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| [email protected] so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Authors: Marcus Boerger <[email protected]> |
+----------------------------------------------------------------------+
*/
#ifndef PHP_FUNCTIONS_H
#define PHP_FUNCTIONS_H
#include "php.h"
typedef zend_object* (*create_object_func_t)(zend_class_entry *class_type);
/* sub: whether to allow subclasses/interfaces
allow = 0: allow all classes and interfaces
allow > 0: allow all that match and mask ce_flags
allow < 0: disallow all that match and mask ce_flags
*/
void spl_add_class_name(zval * list, zend_class_entry * pce, int allow, int ce_flags);
void spl_add_interfaces(zval * list, zend_class_entry * pce, int allow, int ce_flags);
void spl_add_traits(zval * list, zend_class_entry * pce, int allow, int ce_flags);
void spl_add_classes(zend_class_entry *pce, zval *list, bool sub, int allow, int ce_flags);
/* caller must efree(return) */
zend_string *spl_gen_private_prop_name(zend_class_entry *ce, char *prop_name, size_t prop_len);
#endif /* PHP_FUNCTIONS_H */
| 1,855 | 47.842105 | 95 |
h
|
php-src
|
php-src-master/ext/spl/spl_heap.h
|
/*
+----------------------------------------------------------------------+
| Copyright (c) The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| https://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| [email protected] so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Authors: Etienne Kneuss <[email protected]> |
+----------------------------------------------------------------------+
*/
#ifndef SPL_HEAP_H
#define SPL_HEAP_H
#include "php.h"
#include "php_spl.h"
#define SPL_PQUEUE_EXTR_MASK 0x00000003
#define SPL_PQUEUE_EXTR_BOTH 0x00000003
#define SPL_PQUEUE_EXTR_DATA 0x00000001
#define SPL_PQUEUE_EXTR_PRIORITY 0x00000002
extern PHPAPI zend_class_entry *spl_ce_SplHeap;
extern PHPAPI zend_class_entry *spl_ce_SplMinHeap;
extern PHPAPI zend_class_entry *spl_ce_SplMaxHeap;
extern PHPAPI zend_class_entry *spl_ce_SplPriorityQueue;
PHP_MINIT_FUNCTION(spl_heap);
#endif /* SPL_HEAP_H */
| 1,515 | 39.972973 | 75 |
h
|
php-src
|
php-src-master/ext/spl/spl_iterators.h
|
/*
+----------------------------------------------------------------------+
| Copyright (c) The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| https://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| [email protected] so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Authors: Marcus Boerger <[email protected]> |
+----------------------------------------------------------------------+
*/
#ifndef SPL_ITERATORS_H
#define SPL_ITERATORS_H
#include "php.h"
#include "php_spl.h"
extern PHPAPI zend_class_entry *spl_ce_AppendIterator;
extern PHPAPI zend_class_entry *spl_ce_CachingIterator;
extern PHPAPI zend_class_entry *spl_ce_CallbackFilterIterator;
extern PHPAPI zend_class_entry *spl_ce_EmptyIterator;
extern PHPAPI zend_class_entry *spl_ce_FilterIterator;
extern PHPAPI zend_class_entry *spl_ce_InfiniteIterator;
extern PHPAPI zend_class_entry *spl_ce_IteratorIterator;
extern PHPAPI zend_class_entry *spl_ce_LimitIterator;
extern PHPAPI zend_class_entry *spl_ce_NoRewindIterator;
extern PHPAPI zend_class_entry *spl_ce_OuterIterator;
extern PHPAPI zend_class_entry *spl_ce_ParentIterator;
extern PHPAPI zend_class_entry *spl_ce_RecursiveCachingIterator;
extern PHPAPI zend_class_entry *spl_ce_RecursiveCallbackFilterIterator;
extern PHPAPI zend_class_entry *spl_ce_RecursiveFilterIterator;
extern PHPAPI zend_class_entry *spl_ce_RecursiveIterator;
extern PHPAPI zend_class_entry *spl_ce_RecursiveIteratorIterator;
extern PHPAPI zend_class_entry *spl_ce_RecursiveRegexIterator;
extern PHPAPI zend_class_entry *spl_ce_RecursiveTreeIterator;
extern PHPAPI zend_class_entry *spl_ce_RegexIterator;
extern PHPAPI zend_class_entry *spl_ce_SeekableIterator;
PHP_MINIT_FUNCTION(spl_iterators);
typedef enum {
RIT_LEAVES_ONLY = 0,
RIT_SELF_FIRST = 1,
RIT_CHILD_FIRST = 2
} RecursiveIteratorMode;
#define RIT_CATCH_GET_CHILD CIT_CATCH_GET_CHILD
typedef enum {
RTIT_BYPASS_CURRENT = 4,
RTIT_BYPASS_KEY = 8
} RecursiveTreeIteratorFlags;
typedef enum {
DIT_Default = 0,
DIT_FilterIterator = DIT_Default,
DIT_RecursiveFilterIterator = DIT_Default,
DIT_ParentIterator = DIT_Default,
DIT_LimitIterator,
DIT_CachingIterator,
DIT_RecursiveCachingIterator,
DIT_IteratorIterator,
DIT_NoRewindIterator,
DIT_InfiniteIterator,
DIT_AppendIterator,
DIT_RegexIterator,
DIT_RecursiveRegexIterator,
DIT_CallbackFilterIterator,
DIT_RecursiveCallbackFilterIterator,
DIT_Unknown = ~0
} dual_it_type;
typedef enum {
RIT_Default = 0,
RIT_RecursiveIteratorIterator = RIT_Default,
RIT_RecursiveTreeIterator,
RIT_Unknow = ~0
} recursive_it_it_type;
enum {
/* public */
CIT_CALL_TOSTRING = 0x00000001,
CIT_TOSTRING_USE_KEY = 0x00000002,
CIT_TOSTRING_USE_CURRENT = 0x00000004,
CIT_TOSTRING_USE_INNER = 0x00000008,
CIT_CATCH_GET_CHILD = 0x00000010,
CIT_FULL_CACHE = 0x00000100,
CIT_PUBLIC = 0x0000FFFF,
/* private */
CIT_VALID = 0x00010000,
CIT_HAS_CHILDREN = 0x00020000
};
enum {
/* public */
REGIT_USE_KEY = 0x00000001,
REGIT_INVERTED = 0x00000002
};
typedef enum {
REGIT_MODE_MATCH,
REGIT_MODE_GET_MATCH,
REGIT_MODE_ALL_MATCHES,
REGIT_MODE_SPLIT,
REGIT_MODE_REPLACE,
REGIT_MODE_MAX
} regex_mode;
typedef int (*spl_iterator_apply_func_t)(zend_object_iterator *iter, void *puser);
PHPAPI zend_result spl_iterator_apply(zval *obj, spl_iterator_apply_func_t apply_func, void *puser);
#endif /* SPL_ITERATORS_H */
| 4,033 | 32.616667 | 100 |
h
|
php-src
|
php-src-master/ext/spl/spl_observer.h
|
/*
+----------------------------------------------------------------------+
| Copyright (c) The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| https://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| [email protected] so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Authors: Marcus Boerger <[email protected]> |
+----------------------------------------------------------------------+
*/
#ifndef SPL_OBSERVER_H
#define SPL_OBSERVER_H
#include "php.h"
#include "php_spl.h"
typedef enum {
MIT_NEED_ANY = 0,
MIT_NEED_ALL = 1,
MIT_KEYS_NUMERIC = 0,
MIT_KEYS_ASSOC = 2
} MultipleIteratorFlags;
extern PHPAPI zend_class_entry *spl_ce_SplObserver;
extern PHPAPI zend_class_entry *spl_ce_SplSubject;
extern PHPAPI zend_class_entry *spl_ce_SplObjectStorage;
extern PHPAPI zend_class_entry *spl_ce_MultipleIterator;
PHP_MINIT_FUNCTION(spl_observer);
#endif /* SPL_OBSERVER_H */
| 1,495 | 38.368421 | 75 |
h
|
php-src
|
php-src-master/ext/sqlite3/php_sqlite3.h
|
/*
+----------------------------------------------------------------------+
| Copyright (c) The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| https://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| [email protected] so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Authors: Scott MacVicar <[email protected]> |
+----------------------------------------------------------------------+
*/
#ifndef PHP_SQLITE3_H
#define PHP_SQLITE3_H
#define PHP_SQLITE3_VERSION PHP_VERSION
extern zend_module_entry sqlite3_module_entry;
#define phpext_sqlite3_ptr &sqlite3_module_entry
ZEND_BEGIN_MODULE_GLOBALS(sqlite3)
char *extension_dir;
int dbconfig_defensive;
ZEND_END_MODULE_GLOBALS(sqlite3)
#if defined(ZTS) && defined(COMPILE_DL_SQLITE3)
ZEND_TSRMLS_CACHE_EXTERN()
#endif
ZEND_EXTERN_MODULE_GLOBALS(sqlite3)
#define SQLITE3G(v) ZEND_MODULE_GLOBALS_ACCESSOR(sqlite3, v)
#define PHP_SQLITE3_ASSOC 1<<0
#define PHP_SQLITE3_NUM 1<<1
#define PHP_SQLITE3_BOTH (PHP_SQLITE3_ASSOC|PHP_SQLITE3_NUM)
#endif
| 1,605 | 37.238095 | 75 |
h
|
php-src
|
php-src-master/ext/sqlite3/php_sqlite3_structs.h
|
/*
+----------------------------------------------------------------------+
| Copyright (c) The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| https://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| [email protected] so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Authors: Scott MacVicar <[email protected]> |
+----------------------------------------------------------------------+
*/
#ifndef PHP_SQLITE_STRUCTS_H
#define PHP_SQLITE_STRUCTS_H
#include <sqlite3.h>
/* for backwards compatibility reasons */
#ifndef SQLITE_OPEN_READONLY
#define SQLITE_OPEN_READONLY 0x00000001
#endif
#ifndef SQLITE_OPEN_READWRITE
#define SQLITE_OPEN_READWRITE 0x00000002
#endif
#ifndef SQLITE_OPEN_CREATE
#define SQLITE_OPEN_CREATE 0x00000004
#endif
/* Structure for SQLite Statement Parameter. */
struct php_sqlite3_bound_param {
zend_long param_number;
zend_string *name;
zend_long type;
zval parameter;
};
/* Structure for SQLite function. */
typedef struct _php_sqlite3_func {
struct _php_sqlite3_func *next;
const char *func_name;
int argc;
zend_fcall_info_cache func;
zend_fcall_info_cache step;
zend_fcall_info_cache fini;
} php_sqlite3_func;
/* Structure for SQLite collation function */
typedef struct _php_sqlite3_collation {
struct _php_sqlite3_collation *next;
const char *collation_name;
zend_fcall_info_cache cmp_func;
} php_sqlite3_collation;
/* Structure for SQLite Database object. */
typedef struct _php_sqlite3_db_object {
int initialised;
sqlite3 *db;
php_sqlite3_func *funcs;
php_sqlite3_collation *collations;
zend_fcall_info_cache authorizer_fcc;
bool exception;
zend_llist free_list;
zend_object zo;
} php_sqlite3_db_object;
static inline php_sqlite3_db_object *php_sqlite3_db_from_obj(zend_object *obj) {
return (php_sqlite3_db_object*)((char*)(obj) - XtOffsetOf(php_sqlite3_db_object, zo));
}
#define Z_SQLITE3_DB_P(zv) php_sqlite3_db_from_obj(Z_OBJ_P((zv)))
/* Structure for SQLite Database object. */
typedef struct _php_sqlite3_agg_context {
zval zval_context;
zend_long row_count;
} php_sqlite3_agg_context;
typedef struct _php_sqlite3_stmt_object php_sqlite3_stmt;
typedef struct _php_sqlite3_result_object php_sqlite3_result;
/* sqlite3 objects to be destroyed */
typedef struct _php_sqlite3_free_list {
zval stmt_obj_zval;
php_sqlite3_stmt *stmt_obj;
} php_sqlite3_free_list;
/* Structure for SQLite Result object. */
struct _php_sqlite3_result_object {
php_sqlite3_db_object *db_obj;
php_sqlite3_stmt *stmt_obj;
zval stmt_obj_zval;
/* Cache of column names to speed up repeated fetchArray(SQLITE3_ASSOC) calls.
* Cache is cleared on reset() and finalize() calls. */
int column_count;
zend_string **column_names;
int is_prepared_statement;
zend_object zo;
};
static inline php_sqlite3_result *php_sqlite3_result_from_obj(zend_object *obj) {
return (php_sqlite3_result*)((char*)(obj) - XtOffsetOf(php_sqlite3_result, zo));
}
#define Z_SQLITE3_RESULT_P(zv) php_sqlite3_result_from_obj(Z_OBJ_P((zv)))
/* Structure for SQLite Statement object. */
struct _php_sqlite3_stmt_object {
sqlite3_stmt *stmt;
php_sqlite3_db_object *db_obj;
zval db_obj_zval;
int initialised;
/* Keep track of the zvals for bound parameters */
HashTable *bound_params;
zend_object zo;
};
static inline php_sqlite3_stmt *php_sqlite3_stmt_from_obj(zend_object *obj) {
return (php_sqlite3_stmt*)((char*)(obj) - XtOffsetOf(php_sqlite3_stmt, zo));
}
#define Z_SQLITE3_STMT_P(zv) php_sqlite3_stmt_from_obj(Z_OBJ_P((zv)))
#endif
| 4,099 | 28.496403 | 87 |
h
|
php-src
|
php-src-master/ext/standard/crc32.c
|
/*
+----------------------------------------------------------------------+
| Copyright (c) The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| https://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| [email protected] so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Author: Rasmus Lerdorf <[email protected]> |
+----------------------------------------------------------------------+
*/
#include "php.h"
#include "basic_functions.h"
#include "crc32.h"
#include "crc32_x86.h"
#ifdef HAVE_AARCH64_CRC32
#ifndef PHP_WIN32
# include <arm_acle.h>
#endif
# if defined(__linux__)
# include <sys/auxv.h>
# include <asm/hwcap.h>
# elif defined(__APPLE__)
# include <sys/sysctl.h>
# elif defined(__FreeBSD__)
# include <sys/auxv.h>
static unsigned long getauxval(unsigned long key) {
unsigned long ret = 0;
if (elf_aux_info(key, &ret, sizeof(ret)) != 0)
return 0;
return ret;
}
# endif
static inline int has_crc32_insn() {
/* Only go through the runtime detection once. */
static int res = -1;
if (res != -1)
return res;
# if defined(HWCAP_CRC32)
res = getauxval(AT_HWCAP) & HWCAP_CRC32;
return res;
# elif defined(HWCAP2_CRC32)
res = getauxval(AT_HWCAP2) & HWCAP2_CRC32;
return res;
# elif defined(__APPLE__)
size_t reslen = sizeof(res);
if (sysctlbyname("hw.optional.armv8_crc32", &res, &reslen, NULL, 0) < 0)
res = 0;
return res;
# elif defined(WIN32)
res = (int)IsProcessorFeaturePresent(PF_ARM_V8_CRC32_INSTRUCTIONS_AVAILABLE);
return res;
# else
res = 0;
return res;
# endif
}
# if defined(__GNUC__)
# if!defined(__clang__)
# pragma GCC push_options
# pragma GCC target ("+nothing+crc")
# else
# pragma clang attribute push(__attribute__((target("+nothing+crc"))), apply_to=function)
# endif
# endif
static uint32_t crc32_aarch64(uint32_t crc, const char *p, size_t nr) {
while (nr >= sizeof(uint64_t)) {
crc = __crc32d(crc, *(uint64_t *)p);
p += sizeof(uint64_t);
nr -= sizeof(uint64_t);
}
if (nr >= sizeof(int32_t)) {
crc = __crc32w(crc, *(uint32_t *)p);
p += sizeof(uint32_t);
nr -= sizeof(uint32_t);
}
if (nr >= sizeof(int16_t)) {
crc = __crc32h(crc, *(uint16_t *)p);
p += sizeof(uint16_t);
nr -= sizeof(uint16_t);
}
if (nr) {
crc = __crc32b(crc, *p);
}
return crc;
}
# if defined(__GNUC__)
# if !defined(__clang__)
# pragma GCC pop_options
# else
# pragma clang attribute pop
# endif
# endif
#endif
PHPAPI uint32_t php_crc32_bulk_update(uint32_t crc, const char *p, size_t nr)
{
#ifdef HAVE_AARCH64_CRC32
if (has_crc32_insn()) {
crc = crc32_aarch64(crc, p, nr);
return crc;
}
#endif
#if ZEND_INTRIN_SSE4_2_PCLMUL_NATIVE || ZEND_INTRIN_SSE4_2_PCLMUL_RESOLVER
size_t nr_simd = crc32_x86_simd_update(X86_CRC32B, &crc, (const unsigned char *)p, nr);
nr -= nr_simd;
p += nr_simd;
#endif
/* The trailing part */
for (; nr--; ++p) {
crc = ((crc >> 8) & 0x00FFFFFF) ^ crc32tab[(crc ^ (*p)) & 0xFF ];
}
return crc;
}
PHPAPI int php_crc32_stream_bulk_update(uint32_t *crc, php_stream *fp, size_t nr)
{
size_t handled = 0, n;
char buf[1024];
while (handled < nr) {
n = nr - handled;
n = (n < sizeof(buf)) ? n : sizeof(buf); /* tweak to buf size */
n = php_stream_read(fp, buf, n);
if (n > 0) {
*crc = php_crc32_bulk_update(*crc, buf, n);
handled += n;
} else { /* EOF */
return FAILURE;
}
}
return SUCCESS;
}
/* {{{ Calculate the crc32 polynomial of a string */
PHP_FUNCTION(crc32)
{
char *p;
size_t nr;
uint32_t crc = php_crc32_bulk_init();
ZEND_PARSE_PARAMETERS_START(1, 1)
Z_PARAM_STRING(p, nr)
ZEND_PARSE_PARAMETERS_END();
crc = php_crc32_bulk_update(crc, p, nr);
RETURN_LONG(php_crc32_bulk_end(crc));
}
/* }}} */
| 4,254 | 24.787879 | 91 |
c
|
php-src
|
php-src-master/ext/standard/crc32.h
|
/*
+----------------------------------------------------------------------+
| Copyright (c) The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| https://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| [email protected] so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Author: Rasmus Lerdorf <[email protected]> |
+----------------------------------------------------------------------+
*/
/*
* This code implements the AUTODIN II polynomial
* The variable corresponding to the macro argument "crc" should
* be an unsigned long.
* Original code by Spencer Garrett <[email protected]>
*/
#define CRC32(crc, ch) (crc = (crc >> 8) ^ crc32tab[(crc ^ (ch)) & 0xff])
#define php_crc32_bulk_init() (0 ^ 0xffffffff)
#define php_crc32_bulk_end(c) ((c) ^ 0xffffffff)
PHPAPI uint32_t php_crc32_bulk_update(uint32_t crc, const char *p, size_t nr);
/* Return FAILURE if stream reading fail */
PHPAPI int php_crc32_stream_bulk_update(uint32_t *crc, php_stream *fp, size_t nr);
/* generated using the AUTODIN II polynomial
* x^32 + x^26 + x^23 + x^22 + x^16 +
* x^12 + x^11 + x^10 + x^8 + x^7 + x^5 + x^4 + x^2 + x^1 + 1
*/
static const unsigned int crc32tab[256] = {
0x00000000, 0x77073096, 0xee0e612c, 0x990951ba,
0x076dc419, 0x706af48f, 0xe963a535, 0x9e6495a3,
0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988,
0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91,
0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de,
0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7,
0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec,
0x14015c4f, 0x63066cd9, 0xfa0f3d63, 0x8d080df5,
0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172,
0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b,
0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940,
0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59,
0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116,
0x21b4f4b5, 0x56b3c423, 0xcfba9599, 0xb8bda50f,
0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d,
0x76dc4190, 0x01db7106, 0x98d220bc, 0xefd5102a,
0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433,
0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818,
0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01,
0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e,
0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457,
0x65b0d9c6, 0x12b7e950, 0x8bbeb8ea, 0xfcb9887c,
0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65,
0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2,
0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb,
0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0,
0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9,
0x5005713c, 0x270241aa, 0xbe0b1010, 0xc90c2086,
0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4,
0x59b33d17, 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad,
0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a,
0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683,
0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8,
0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1,
0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe,
0xf762575d, 0x806567cb, 0x196c3671, 0x6e6b06e7,
0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc,
0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5,
0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252,
0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b,
0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60,
0xdf60efc3, 0xa867df55, 0x316e8eef, 0x4669be79,
0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f,
0xc5ba3bbe, 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04,
0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d,
0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a,
0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713,
0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38,
0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21,
0x86d3d2d4, 0xf1d4e242, 0x68ddb3f8, 0x1fda836e,
0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777,
0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c,
0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45,
0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2,
0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db,
0xaed16a4a, 0xd9d65adc, 0x40df0b66, 0x37d83bf0,
0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6,
0xbad03605, 0xcdd70693, 0x54de5729, 0x23d967bf,
0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94,
0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d,
};
| 4,908 | 45.752381 | 82 |
h
|
php-src
|
php-src-master/ext/standard/crc32_x86.h
|
/*
+----------------------------------------------------------------------+
| Copyright (c) The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| https://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| [email protected] so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Author: Frank Du <[email protected]> |
+----------------------------------------------------------------------+
*/
#ifndef _CRC32_X86_HEADER_H_
#define _CRC32_X86_HEADER_H_
#include "php.h"
typedef enum {
/* polynomial: 0x04C11DB7, used by bzip */
X86_CRC32 = 0,
/*
polynomial: 0x04C11DB7 with reversed ordering,
used by ethernet (IEEE 802.3), gzip, zip, png, etc
*/
X86_CRC32B,
/*
polynomial: 0x1EDC6F41 with reversed ordering,
used by iSCSI, SCTP, Btrfs, ext4, etc
*/
X86_CRC32C,
X86_CRC32_MAX,
} X86_CRC32_TYPE;
#if ZEND_INTRIN_SSE4_2_PCLMUL_FUNC_PTR
PHP_MINIT_FUNCTION(crc32_x86_intrin);
#endif
#if ZEND_INTRIN_SSE4_2_PCLMUL_NATIVE || ZEND_INTRIN_SSE4_2_PCLMUL_RESOLVER
/* Return the size processed by SIMD routine */
size_t crc32_x86_simd_update(X86_CRC32_TYPE type, uint32_t *crc, const unsigned char *p, size_t nr);
#else
static inline size_t crc32_x86_simd_update(X86_CRC32_TYPE type, uint32_t *crc, const unsigned char *p, size_t nr)
{
return 0;
}
#endif
#endif
| 1,861 | 34.132075 | 113 |
h
|
php-src
|
php-src-master/ext/standard/credits.h
|
/*
+----------------------------------------------------------------------+
| Copyright (c) The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| https://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| [email protected] so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Authors: Rasmus Lerdorf <[email protected]> |
| Zeev Suraski <[email protected]> |
+----------------------------------------------------------------------+
*/
#ifndef CREDITS_H
#define CREDITS_H
#ifndef HAVE_CREDITS_DEFS
#define HAVE_CREDITS_DEFS
#define PHP_CREDITS_GROUP (1<<0)
#define PHP_CREDITS_GENERAL (1<<1)
#define PHP_CREDITS_SAPI (1<<2)
#define PHP_CREDITS_MODULES (1<<3)
#define PHP_CREDITS_DOCS (1<<4)
#define PHP_CREDITS_FULLPAGE (1<<5)
#define PHP_CREDITS_QA (1<<6)
#define PHP_CREDITS_WEB (1<<7)
#define PHP_CREDITS_ALL 0xFFFFFFFF
#endif /* HAVE_CREDITS_DEFS */
PHPAPI void php_print_credits(int flag);
#endif
| 1,562 | 39.076923 | 75 |
h
|
php-src
|
php-src-master/ext/standard/credits_sapi.h
|
/*
DO NOT EDIT THIS FILE!
it has been automatically created by scripts/dev/credits from
the information found in the various ext/.../CREDITS and
sapi/.../CREDITS files
if you want to change an entry you have to edit the appropriate
CREDITS file instead
*/
CREDIT_LINE("Apache 2.0 Handler", "Ian Holsman, Justin Erenkrantz (based on Apache 2.0 Filter code)");
CREDIT_LINE("CGI / FastCGI", "Rasmus Lerdorf, Stig Bakken, Shane Caraveo, Dmitry Stogov");
CREDIT_LINE("CLI", "Edin Kadribasic, Marcus Boerger, Johannes Schlueter, Moriyoshi Koizumi, Xinchen Hui");
CREDIT_LINE("Embed", "Edin Kadribasic");
CREDIT_LINE("FastCGI Process Manager", "Andrei Nigmatulin, dreamcat4, Antony Dovgal, Jerome Loyet");
CREDIT_LINE("litespeed", "George Wang");
CREDIT_LINE("phpdbg", "Felipe Pena, Joe Watkins, Bob Weinand");
| 835 | 40.8 | 106 |
h
|
php-src
|
php-src-master/ext/standard/crypt.c
|
/*
+----------------------------------------------------------------------+
| Copyright (c) The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| https://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| [email protected] so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Authors: Stig Bakken <[email protected]> |
| Zeev Suraski <[email protected]> |
| Rasmus Lerdorf <[email protected]> |
| Pierre Joye <[email protected]> |
+----------------------------------------------------------------------+
*/
#include <stdlib.h>
#include "php.h"
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#if PHP_USE_PHP_CRYPT_R
# include "php_crypt_r.h"
# include "crypt_freesec.h"
#else
# ifdef HAVE_CRYPT_H
# if defined(CRYPT_R_GNU_SOURCE) && !defined(_GNU_SOURCE)
# define _GNU_SOURCE
# endif
# include <crypt.h>
# endif
#endif
#include <time.h>
#include <string.h>
#ifdef PHP_WIN32
#include <process.h>
#endif
#include "php_crypt.h"
#include "ext/random/php_random.h"
/* Used to check DES salts to ensure that they contain only valid characters */
#define IS_VALID_SALT_CHARACTER(c) (((c) >= '.' && (c) <= '9') || ((c) >= 'A' && (c) <= 'Z') || ((c) >= 'a' && (c) <= 'z'))
PHP_MINIT_FUNCTION(crypt) /* {{{ */
{
#if PHP_USE_PHP_CRYPT_R
php_init_crypt_r();
#endif
return SUCCESS;
}
/* }}} */
PHP_MSHUTDOWN_FUNCTION(crypt) /* {{{ */
{
#if PHP_USE_PHP_CRYPT_R
php_shutdown_crypt_r();
#endif
return SUCCESS;
}
/* }}} */
PHPAPI zend_string *php_crypt(const char *password, const int pass_len, const char *salt, int salt_len, bool quiet)
{
char *crypt_res;
zend_string *result;
if (salt[0] == '*' && (salt[1] == '0' || salt[1] == '1')) {
return NULL;
}
/* Windows (win32/crypt) has a stripped down version of libxcrypt and
a CryptoApi md5_crypt implementation */
#if PHP_USE_PHP_CRYPT_R
{
struct php_crypt_extended_data buffer;
if (salt[0]=='$' && salt[1]=='1' && salt[2]=='$') {
char output[MD5_HASH_MAX_LEN], *out;
out = php_md5_crypt_r(password, salt, output);
if (out) {
return zend_string_init(out, strlen(out), 0);
}
return NULL;
} else if (salt[0]=='$' && salt[1]=='6' && salt[2]=='$') {
char *output;
output = emalloc(PHP_MAX_SALT_LEN);
crypt_res = php_sha512_crypt_r(password, salt, output, PHP_MAX_SALT_LEN);
if (!crypt_res) {
ZEND_SECURE_ZERO(output, PHP_MAX_SALT_LEN);
efree(output);
return NULL;
} else {
result = zend_string_init(output, strlen(output), 0);
ZEND_SECURE_ZERO(output, PHP_MAX_SALT_LEN);
efree(output);
return result;
}
} else if (salt[0]=='$' && salt[1]=='5' && salt[2]=='$') {
char *output;
output = emalloc(PHP_MAX_SALT_LEN);
crypt_res = php_sha256_crypt_r(password, salt, output, PHP_MAX_SALT_LEN);
if (!crypt_res) {
ZEND_SECURE_ZERO(output, PHP_MAX_SALT_LEN);
efree(output);
return NULL;
} else {
result = zend_string_init(output, strlen(output), 0);
ZEND_SECURE_ZERO(output, PHP_MAX_SALT_LEN);
efree(output);
return result;
}
} else if (
salt[0] == '$' &&
salt[1] == '2' &&
salt[2] != 0 &&
salt[3] == '$') {
char output[PHP_MAX_SALT_LEN + 1];
memset(output, 0, PHP_MAX_SALT_LEN + 1);
crypt_res = php_crypt_blowfish_rn(password, salt, output, sizeof(output));
if (!crypt_res) {
ZEND_SECURE_ZERO(output, PHP_MAX_SALT_LEN + 1);
return NULL;
} else {
result = zend_string_init(output, strlen(output), 0);
ZEND_SECURE_ZERO(output, PHP_MAX_SALT_LEN + 1);
return result;
}
} else if (salt[0] == '_'
|| (IS_VALID_SALT_CHARACTER(salt[0]) && IS_VALID_SALT_CHARACTER(salt[1]))) {
/* DES Fallback */
memset(&buffer, 0, sizeof(buffer));
_crypt_extended_init_r();
crypt_res = _crypt_extended_r((const unsigned char *) password, salt, &buffer);
if (!crypt_res || (salt[0] == '*' && salt[1] == '0')) {
return NULL;
} else {
result = zend_string_init(crypt_res, strlen(crypt_res), 0);
return result;
}
} else {
/* Unknown hash type */
return NULL;
}
}
#else
# if defined(HAVE_CRYPT_R) && (defined(_REENTRANT) || defined(_THREAD_SAFE))
# if defined(CRYPT_R_STRUCT_CRYPT_DATA)
struct crypt_data buffer;
memset(&buffer, 0, sizeof(buffer));
# elif defined(CRYPT_R_CRYPTD)
CRYPTD buffer;
# else
# error Data struct used by crypt_r() is unknown. Please report.
# endif
crypt_res = crypt_r(password, salt, &buffer);
# elif defined(HAVE_CRYPT)
crypt_res = crypt(password, salt);
# else
# error No crypt() implementation
# endif
#endif
if (!crypt_res || (salt[0] == '*' && salt[1] == '0')) {
return NULL;
} else {
result = zend_string_init(crypt_res, strlen(crypt_res), 0);
return result;
}
}
/* }}} */
/* {{{ Hash a string */
PHP_FUNCTION(crypt)
{
char salt[PHP_MAX_SALT_LEN + 1];
char *str, *salt_in = NULL;
size_t str_len, salt_in_len = 0;
zend_string *result;
ZEND_PARSE_PARAMETERS_START(2, 2)
Z_PARAM_STRING(str, str_len)
Z_PARAM_STRING(salt_in, salt_in_len)
ZEND_PARSE_PARAMETERS_END();
salt[0] = salt[PHP_MAX_SALT_LEN] = '\0';
/* This will produce suitable results if people depend on DES-encryption
* available (passing always 2-character salt). At least for glibc6.1 */
memset(&salt[1], '$', PHP_MAX_SALT_LEN - 1);
memcpy(salt, salt_in, MIN(PHP_MAX_SALT_LEN, salt_in_len));
salt_in_len = MIN(PHP_MAX_SALT_LEN, salt_in_len);
salt[salt_in_len] = '\0';
if ((result = php_crypt(str, (int)str_len, salt, (int)salt_in_len, 0)) == NULL) {
if (salt[0] == '*' && salt[1] == '0') {
RETURN_STRING("*1");
} else {
RETURN_STRING("*0");
}
}
RETURN_STR(result);
}
/* }}} */
| 6,300 | 27.382883 | 123 |
c
|
php-src
|
php-src-master/ext/standard/crypt_blowfish.h
|
/*
* Written by Solar Designer <solar at openwall.com> in 2000-2011.
* No copyright is claimed, and the software is hereby placed in the public
* domain. In case this attempt to disclaim copyright and place the software
* in the public domain is deemed null and void, then the software is
* Copyright (c) 2000-2011 Solar Designer and it is hereby released to the
* general public under the following terms:
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted.
*
* There's ABSOLUTELY NO WARRANTY, express or implied.
*
* See crypt_blowfish.c for more information.
*/
#ifndef _CRYPT_BLOWFISH_H
#define _CRYPT_BLOWFISH_H
extern char *php_crypt_blowfish_rn(const char *key, const char *setting,
char *output, int size);
#endif
| 790 | 31.958333 | 76 |
h
|
php-src
|
php-src-master/ext/standard/crypt_freesec.c
|
/*
* This version is derived from the original implementation of FreeSec
* (release 1.1) by David Burren. I've reviewed the changes made in
* OpenBSD (as of 2.7) and modified the original code in a similar way
* where applicable. I've also made it reentrant and made a number of
* other changes.
* - Solar Designer <solar at openwall.com>
*/
/*
* FreeSec: libcrypt for NetBSD
*
* Copyright (c) 1994 David Burren
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the author nor the names of other contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Owl: Owl/packages/glibc/crypt_freesec.c,v 1.4 2005/11/16 13:08:32 solar Exp $
*
* This is an original implementation of the DES and the crypt(3) interfaces
* by David Burren <davidb at werj.com.au>.
*
* An excellent reference on the underlying algorithm (and related
* algorithms) is:
*
* B. Schneier, Applied Cryptography: protocols, algorithms,
* and source code in C, John Wiley & Sons, 1994.
*
* Note that in that book's description of DES the lookups for the initial,
* pbox, and final permutations are inverted (this has been brought to the
* attention of the author). A list of errata for this book has been
* posted to the sci.crypt newsgroup by the author and is available for FTP.
*
* ARCHITECTURE ASSUMPTIONS:
* This code used to have some nasty ones, but these have been removed
* by now. The code requires a 32-bit integer type, though.
*/
#include <sys/types.h>
#include <string.h>
#ifdef TEST
#include <stdio.h>
#endif
#include "crypt_freesec.h"
#define _PASSWORD_EFMT1 '_'
static const uint8_t IP[64] = {
58, 50, 42, 34, 26, 18, 10, 2, 60, 52, 44, 36, 28, 20, 12, 4,
62, 54, 46, 38, 30, 22, 14, 6, 64, 56, 48, 40, 32, 24, 16, 8,
57, 49, 41, 33, 25, 17, 9, 1, 59, 51, 43, 35, 27, 19, 11, 3,
61, 53, 45, 37, 29, 21, 13, 5, 63, 55, 47, 39, 31, 23, 15, 7
};
static const uint8_t key_perm[56] = {
57, 49, 41, 33, 25, 17, 9, 1, 58, 50, 42, 34, 26, 18,
10, 2, 59, 51, 43, 35, 27, 19, 11, 3, 60, 52, 44, 36,
63, 55, 47, 39, 31, 23, 15, 7, 62, 54, 46, 38, 30, 22,
14, 6, 61, 53, 45, 37, 29, 21, 13, 5, 28, 20, 12, 4
};
static const uint8_t key_shifts[16] = {
1, 1, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 1
};
static const uint8_t comp_perm[48] = {
14, 17, 11, 24, 1, 5, 3, 28, 15, 6, 21, 10,
23, 19, 12, 4, 26, 8, 16, 7, 27, 20, 13, 2,
41, 52, 31, 37, 47, 55, 30, 40, 51, 45, 33, 48,
44, 49, 39, 56, 34, 53, 46, 42, 50, 36, 29, 32
};
/*
* No E box is used, as it's replaced by some ANDs, shifts, and ORs.
*/
static const uint8_t sbox[8][64] = {
{
14, 4, 13, 1, 2, 15, 11, 8, 3, 10, 6, 12, 5, 9, 0, 7,
0, 15, 7, 4, 14, 2, 13, 1, 10, 6, 12, 11, 9, 5, 3, 8,
4, 1, 14, 8, 13, 6, 2, 11, 15, 12, 9, 7, 3, 10, 5, 0,
15, 12, 8, 2, 4, 9, 1, 7, 5, 11, 3, 14, 10, 0, 6, 13
},
{
15, 1, 8, 14, 6, 11, 3, 4, 9, 7, 2, 13, 12, 0, 5, 10,
3, 13, 4, 7, 15, 2, 8, 14, 12, 0, 1, 10, 6, 9, 11, 5,
0, 14, 7, 11, 10, 4, 13, 1, 5, 8, 12, 6, 9, 3, 2, 15,
13, 8, 10, 1, 3, 15, 4, 2, 11, 6, 7, 12, 0, 5, 14, 9
},
{
10, 0, 9, 14, 6, 3, 15, 5, 1, 13, 12, 7, 11, 4, 2, 8,
13, 7, 0, 9, 3, 4, 6, 10, 2, 8, 5, 14, 12, 11, 15, 1,
13, 6, 4, 9, 8, 15, 3, 0, 11, 1, 2, 12, 5, 10, 14, 7,
1, 10, 13, 0, 6, 9, 8, 7, 4, 15, 14, 3, 11, 5, 2, 12
},
{
7, 13, 14, 3, 0, 6, 9, 10, 1, 2, 8, 5, 11, 12, 4, 15,
13, 8, 11, 5, 6, 15, 0, 3, 4, 7, 2, 12, 1, 10, 14, 9,
10, 6, 9, 0, 12, 11, 7, 13, 15, 1, 3, 14, 5, 2, 8, 4,
3, 15, 0, 6, 10, 1, 13, 8, 9, 4, 5, 11, 12, 7, 2, 14
},
{
2, 12, 4, 1, 7, 10, 11, 6, 8, 5, 3, 15, 13, 0, 14, 9,
14, 11, 2, 12, 4, 7, 13, 1, 5, 0, 15, 10, 3, 9, 8, 6,
4, 2, 1, 11, 10, 13, 7, 8, 15, 9, 12, 5, 6, 3, 0, 14,
11, 8, 12, 7, 1, 14, 2, 13, 6, 15, 0, 9, 10, 4, 5, 3
},
{
12, 1, 10, 15, 9, 2, 6, 8, 0, 13, 3, 4, 14, 7, 5, 11,
10, 15, 4, 2, 7, 12, 9, 5, 6, 1, 13, 14, 0, 11, 3, 8,
9, 14, 15, 5, 2, 8, 12, 3, 7, 0, 4, 10, 1, 13, 11, 6,
4, 3, 2, 12, 9, 5, 15, 10, 11, 14, 1, 7, 6, 0, 8, 13
},
{
4, 11, 2, 14, 15, 0, 8, 13, 3, 12, 9, 7, 5, 10, 6, 1,
13, 0, 11, 7, 4, 9, 1, 10, 14, 3, 5, 12, 2, 15, 8, 6,
1, 4, 11, 13, 12, 3, 7, 14, 10, 15, 6, 8, 0, 5, 9, 2,
6, 11, 13, 8, 1, 4, 10, 7, 9, 5, 0, 15, 14, 2, 3, 12
},
{
13, 2, 8, 4, 6, 15, 11, 1, 10, 9, 3, 14, 5, 0, 12, 7,
1, 15, 13, 8, 10, 3, 7, 4, 12, 5, 6, 11, 0, 14, 9, 2,
7, 11, 4, 1, 9, 12, 14, 2, 0, 6, 10, 13, 15, 3, 5, 8,
2, 1, 14, 7, 4, 10, 8, 13, 15, 12, 9, 0, 3, 5, 6, 11
}
};
static const uint8_t pbox[32] = {
16, 7, 20, 21, 29, 12, 28, 17, 1, 15, 23, 26, 5, 18, 31, 10,
2, 8, 24, 14, 32, 27, 3, 9, 19, 13, 30, 6, 22, 11, 4, 25
};
static const uint32_t bits32[32] =
{
0x80000000, 0x40000000, 0x20000000, 0x10000000,
0x08000000, 0x04000000, 0x02000000, 0x01000000,
0x00800000, 0x00400000, 0x00200000, 0x00100000,
0x00080000, 0x00040000, 0x00020000, 0x00010000,
0x00008000, 0x00004000, 0x00002000, 0x00001000,
0x00000800, 0x00000400, 0x00000200, 0x00000100,
0x00000080, 0x00000040, 0x00000020, 0x00000010,
0x00000008, 0x00000004, 0x00000002, 0x00000001
};
static const uint8_t bits8[8] = { 0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01 };
static const unsigned char ascii64[] =
"./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
static uint8_t m_sbox[4][4096];
static uint32_t psbox[4][256];
static uint32_t ip_maskl[8][256], ip_maskr[8][256];
static uint32_t fp_maskl[8][256], fp_maskr[8][256];
static uint32_t key_perm_maskl[8][128], key_perm_maskr[8][128];
static uint32_t comp_maskl[8][128], comp_maskr[8][128];
static inline int
ascii_to_bin(char ch)
{
signed char sch = ch;
int retval;
retval = sch - '.';
if (sch >= 'A') {
retval = sch - ('A' - 12);
if (sch >= 'a')
retval = sch - ('a' - 38);
}
retval &= 0x3f;
return(retval);
}
/*
* When we choose to "support" invalid salts, nevertheless disallow those
* containing characters that would violate the passwd file format.
*/
static inline int
ascii_is_unsafe(char ch)
{
return !ch || ch == '\n' || ch == ':';
}
void
_crypt_extended_init(void)
{
int i, j, b, k, inbit, obit;
uint32_t *p, *il, *ir, *fl, *fr;
const uint32_t *bits28, *bits24;
uint8_t inv_key_perm[64];
uint8_t inv_comp_perm[56];
uint8_t init_perm[64], final_perm[64];
uint8_t u_sbox[8][64];
uint8_t un_pbox[32];
bits24 = (bits28 = bits32 + 4) + 4;
/*
* Invert the S-boxes, reordering the input bits.
*/
for (i = 0; i < 8; i++)
for (j = 0; j < 64; j++) {
b = (j & 0x20) | ((j & 1) << 4) | ((j >> 1) & 0xf);
u_sbox[i][j] = sbox[i][b];
}
/*
* Convert the inverted S-boxes into 4 arrays of 8 bits.
* Each will handle 12 bits of the S-box input.
*/
for (b = 0; b < 4; b++)
for (i = 0; i < 64; i++)
for (j = 0; j < 64; j++)
m_sbox[b][(i << 6) | j] =
(u_sbox[(b << 1)][i] << 4) |
u_sbox[(b << 1) + 1][j];
/*
* Set up the initial & final permutations into a useful form, and
* initialise the inverted key permutation.
*/
for (i = 0; i < 64; i++) {
init_perm[final_perm[i] = IP[i] - 1] = i;
inv_key_perm[i] = 255;
}
/*
* Invert the key permutation and initialise the inverted key
* compression permutation.
*/
for (i = 0; i < 56; i++) {
inv_key_perm[key_perm[i] - 1] = i;
inv_comp_perm[i] = 255;
}
/*
* Invert the key compression permutation.
*/
for (i = 0; i < 48; i++) {
inv_comp_perm[comp_perm[i] - 1] = i;
}
/*
* Set up the OR-mask arrays for the initial and final permutations,
* and for the key initial and compression permutations.
*/
for (k = 0; k < 8; k++) {
for (i = 0; i < 256; i++) {
*(il = &ip_maskl[k][i]) = 0;
*(ir = &ip_maskr[k][i]) = 0;
*(fl = &fp_maskl[k][i]) = 0;
*(fr = &fp_maskr[k][i]) = 0;
for (j = 0; j < 8; j++) {
inbit = 8 * k + j;
if (i & bits8[j]) {
if ((obit = init_perm[inbit]) < 32)
*il |= bits32[obit];
else
*ir |= bits32[obit-32];
if ((obit = final_perm[inbit]) < 32)
*fl |= bits32[obit];
else
*fr |= bits32[obit - 32];
}
}
}
for (i = 0; i < 128; i++) {
*(il = &key_perm_maskl[k][i]) = 0;
*(ir = &key_perm_maskr[k][i]) = 0;
for (j = 0; j < 7; j++) {
inbit = 8 * k + j;
if (i & bits8[j + 1]) {
if ((obit = inv_key_perm[inbit]) == 255)
continue;
if (obit < 28)
*il |= bits28[obit];
else
*ir |= bits28[obit - 28];
}
}
*(il = &comp_maskl[k][i]) = 0;
*(ir = &comp_maskr[k][i]) = 0;
for (j = 0; j < 7; j++) {
inbit = 7 * k + j;
if (i & bits8[j + 1]) {
if ((obit=inv_comp_perm[inbit]) == 255)
continue;
if (obit < 24)
*il |= bits24[obit];
else
*ir |= bits24[obit - 24];
}
}
}
}
/*
* Invert the P-box permutation, and convert into OR-masks for
* handling the output of the S-box arrays setup above.
*/
for (i = 0; i < 32; i++)
un_pbox[pbox[i] - 1] = i;
for (b = 0; b < 4; b++)
for (i = 0; i < 256; i++) {
*(p = &psbox[b][i]) = 0;
for (j = 0; j < 8; j++) {
if (i & bits8[j])
*p |= bits32[un_pbox[8 * b + j]];
}
}
}
static void
des_init_local(struct php_crypt_extended_data *data)
{
data->old_rawkey0 = data->old_rawkey1 = 0;
data->saltbits = 0;
data->old_salt = 0;
data->initialized = 1;
}
static void
setup_salt(uint32_t salt, struct php_crypt_extended_data *data)
{
uint32_t obit, saltbit, saltbits;
int i;
if (salt == data->old_salt)
return;
data->old_salt = salt;
saltbits = 0;
saltbit = 1;
obit = 0x800000;
for (i = 0; i < 24; i++) {
if (salt & saltbit)
saltbits |= obit;
saltbit <<= 1;
obit >>= 1;
}
data->saltbits = saltbits;
}
static int
des_setkey(const char *key, struct php_crypt_extended_data *data)
{
uint32_t k0, k1, rawkey0, rawkey1;
int shifts, round;
rawkey0 =
(uint32_t)(uint8_t)key[3] |
((uint32_t)(uint8_t)key[2] << 8) |
((uint32_t)(uint8_t)key[1] << 16) |
((uint32_t)(uint8_t)key[0] << 24);
rawkey1 =
(uint32_t)(uint8_t)key[7] |
((uint32_t)(uint8_t)key[6] << 8) |
((uint32_t)(uint8_t)key[5] << 16) |
((uint32_t)(uint8_t)key[4] << 24);
if ((rawkey0 | rawkey1)
&& rawkey0 == data->old_rawkey0
&& rawkey1 == data->old_rawkey1) {
/*
* Already setup for this key.
* This optimisation fails on a zero key (which is weak and
* has bad parity anyway) in order to simplify the starting
* conditions.
*/
return(0);
}
data->old_rawkey0 = rawkey0;
data->old_rawkey1 = rawkey1;
/*
* Do key permutation and split into two 28-bit subkeys.
*/
k0 = key_perm_maskl[0][rawkey0 >> 25]
| key_perm_maskl[1][(rawkey0 >> 17) & 0x7f]
| key_perm_maskl[2][(rawkey0 >> 9) & 0x7f]
| key_perm_maskl[3][(rawkey0 >> 1) & 0x7f]
| key_perm_maskl[4][rawkey1 >> 25]
| key_perm_maskl[5][(rawkey1 >> 17) & 0x7f]
| key_perm_maskl[6][(rawkey1 >> 9) & 0x7f]
| key_perm_maskl[7][(rawkey1 >> 1) & 0x7f];
k1 = key_perm_maskr[0][rawkey0 >> 25]
| key_perm_maskr[1][(rawkey0 >> 17) & 0x7f]
| key_perm_maskr[2][(rawkey0 >> 9) & 0x7f]
| key_perm_maskr[3][(rawkey0 >> 1) & 0x7f]
| key_perm_maskr[4][rawkey1 >> 25]
| key_perm_maskr[5][(rawkey1 >> 17) & 0x7f]
| key_perm_maskr[6][(rawkey1 >> 9) & 0x7f]
| key_perm_maskr[7][(rawkey1 >> 1) & 0x7f];
/*
* Rotate subkeys and do compression permutation.
*/
shifts = 0;
for (round = 0; round < 16; round++) {
uint32_t t0, t1;
shifts += key_shifts[round];
t0 = (k0 << shifts) | (k0 >> (28 - shifts));
t1 = (k1 << shifts) | (k1 >> (28 - shifts));
data->de_keysl[15 - round] =
data->en_keysl[round] = comp_maskl[0][(t0 >> 21) & 0x7f]
| comp_maskl[1][(t0 >> 14) & 0x7f]
| comp_maskl[2][(t0 >> 7) & 0x7f]
| comp_maskl[3][t0 & 0x7f]
| comp_maskl[4][(t1 >> 21) & 0x7f]
| comp_maskl[5][(t1 >> 14) & 0x7f]
| comp_maskl[6][(t1 >> 7) & 0x7f]
| comp_maskl[7][t1 & 0x7f];
data->de_keysr[15 - round] =
data->en_keysr[round] = comp_maskr[0][(t0 >> 21) & 0x7f]
| comp_maskr[1][(t0 >> 14) & 0x7f]
| comp_maskr[2][(t0 >> 7) & 0x7f]
| comp_maskr[3][t0 & 0x7f]
| comp_maskr[4][(t1 >> 21) & 0x7f]
| comp_maskr[5][(t1 >> 14) & 0x7f]
| comp_maskr[6][(t1 >> 7) & 0x7f]
| comp_maskr[7][t1 & 0x7f];
}
return(0);
}
static int
do_des(uint32_t l_in, uint32_t r_in, uint32_t *l_out, uint32_t *r_out,
int count, struct php_crypt_extended_data *data)
{
/*
* l_in, r_in, l_out, and r_out are in pseudo-"big-endian" format.
*/
uint32_t l, r, *kl, *kr, *kl1, *kr1;
uint32_t f, r48l, r48r, saltbits;
int round;
if (count == 0) {
return(1);
} else if (count > 0) {
/*
* Encrypting
*/
kl1 = data->en_keysl;
kr1 = data->en_keysr;
} else {
/*
* Decrypting
*/
count = -count;
kl1 = data->de_keysl;
kr1 = data->de_keysr;
}
/*
* Do initial permutation (IP).
*/
l = ip_maskl[0][l_in >> 24]
| ip_maskl[1][(l_in >> 16) & 0xff]
| ip_maskl[2][(l_in >> 8) & 0xff]
| ip_maskl[3][l_in & 0xff]
| ip_maskl[4][r_in >> 24]
| ip_maskl[5][(r_in >> 16) & 0xff]
| ip_maskl[6][(r_in >> 8) & 0xff]
| ip_maskl[7][r_in & 0xff];
r = ip_maskr[0][l_in >> 24]
| ip_maskr[1][(l_in >> 16) & 0xff]
| ip_maskr[2][(l_in >> 8) & 0xff]
| ip_maskr[3][l_in & 0xff]
| ip_maskr[4][r_in >> 24]
| ip_maskr[5][(r_in >> 16) & 0xff]
| ip_maskr[6][(r_in >> 8) & 0xff]
| ip_maskr[7][r_in & 0xff];
saltbits = data->saltbits;
while (count--) {
/*
* Do each round.
*/
kl = kl1;
kr = kr1;
round = 16;
while (round--) {
/*
* Expand R to 48 bits (simulate the E-box).
*/
r48l = ((r & 0x00000001) << 23)
| ((r & 0xf8000000) >> 9)
| ((r & 0x1f800000) >> 11)
| ((r & 0x01f80000) >> 13)
| ((r & 0x001f8000) >> 15);
r48r = ((r & 0x0001f800) << 7)
| ((r & 0x00001f80) << 5)
| ((r & 0x000001f8) << 3)
| ((r & 0x0000001f) << 1)
| ((r & 0x80000000) >> 31);
/*
* Do salting for crypt() and friends, and
* XOR with the permuted key.
*/
f = (r48l ^ r48r) & saltbits;
r48l ^= f ^ *kl++;
r48r ^= f ^ *kr++;
/*
* Do sbox lookups (which shrink it back to 32 bits)
* and do the pbox permutation at the same time.
*/
f = psbox[0][m_sbox[0][r48l >> 12]]
| psbox[1][m_sbox[1][r48l & 0xfff]]
| psbox[2][m_sbox[2][r48r >> 12]]
| psbox[3][m_sbox[3][r48r & 0xfff]];
/*
* Now that we've permuted things, complete f().
*/
f ^= l;
l = r;
r = f;
}
r = l;
l = f;
}
/*
* Do final permutation (inverse of IP).
*/
*l_out = fp_maskl[0][l >> 24]
| fp_maskl[1][(l >> 16) & 0xff]
| fp_maskl[2][(l >> 8) & 0xff]
| fp_maskl[3][l & 0xff]
| fp_maskl[4][r >> 24]
| fp_maskl[5][(r >> 16) & 0xff]
| fp_maskl[6][(r >> 8) & 0xff]
| fp_maskl[7][r & 0xff];
*r_out = fp_maskr[0][l >> 24]
| fp_maskr[1][(l >> 16) & 0xff]
| fp_maskr[2][(l >> 8) & 0xff]
| fp_maskr[3][l & 0xff]
| fp_maskr[4][r >> 24]
| fp_maskr[5][(r >> 16) & 0xff]
| fp_maskr[6][(r >> 8) & 0xff]
| fp_maskr[7][r & 0xff];
return(0);
}
static int
des_cipher(const char *in, char *out, uint32_t salt, int count,
struct php_crypt_extended_data *data)
{
uint32_t l_out = 0, r_out = 0, rawl, rawr;
int retval;
setup_salt(salt, data);
rawl =
(uint32_t)(uint8_t)in[3] |
((uint32_t)(uint8_t)in[2] << 8) |
((uint32_t)(uint8_t)in[1] << 16) |
((uint32_t)(uint8_t)in[0] << 24);
rawr =
(uint32_t)(uint8_t)in[7] |
((uint32_t)(uint8_t)in[6] << 8) |
((uint32_t)(uint8_t)in[5] << 16) |
((uint32_t)(uint8_t)in[4] << 24);
retval = do_des(rawl, rawr, &l_out, &r_out, count, data);
out[0] = l_out >> 24;
out[1] = l_out >> 16;
out[2] = l_out >> 8;
out[3] = l_out;
out[4] = r_out >> 24;
out[5] = r_out >> 16;
out[6] = r_out >> 8;
out[7] = r_out;
return(retval);
}
char *
_crypt_extended_r(const unsigned char *key, const char *setting,
struct php_crypt_extended_data *data)
{
int i;
uint32_t count, salt, l, r0, r1, keybuf[2];
uint8_t *p, *q;
if (!data->initialized)
des_init_local(data);
/*
* Copy the key, shifting each character up by one bit
* and padding with zeros.
*/
q = (uint8_t *) keybuf;
while ((size_t)(q - (uint8_t *) keybuf) < sizeof(keybuf)) {
*q++ = *key << 1;
if (*key)
key++;
}
if (des_setkey((char *) keybuf, data))
return(NULL);
if (*setting == _PASSWORD_EFMT1) {
/*
* "new"-style:
* setting - underscore, 4 chars of count, 4 chars of salt
* key - unlimited characters
*/
for (i = 1, count = 0; i < 5; i++) {
int value = ascii_to_bin(setting[i]);
if (ascii64[value] != setting[i])
return(NULL);
count |= value << (i - 1) * 6;
}
if (!count)
return(NULL);
for (i = 5, salt = 0; i < 9; i++) {
int value = ascii_to_bin(setting[i]);
if (ascii64[value] != setting[i])
return(NULL);
salt |= value << (i - 5) * 6;
}
while (*key) {
/*
* Encrypt the key with itself.
*/
if (des_cipher((char *) keybuf, (char *) keybuf,
0, 1, data))
return(NULL);
/*
* And XOR with the next 8 characters of the key.
*/
q = (uint8_t *) keybuf;
while ((size_t)(q - (uint8_t *) keybuf) < sizeof(keybuf) && *key)
*q++ ^= *key++ << 1;
if (des_setkey((char *) keybuf, data))
return(NULL);
}
memcpy(data->output, setting, 9);
data->output[9] = '\0';
p = (uint8_t *) data->output + 9;
} else {
/*
* "old"-style:
* setting - 2 chars of salt
* key - up to 8 characters
*/
count = 25;
if (ascii_is_unsafe(setting[0]) || ascii_is_unsafe(setting[1]))
return(NULL);
salt = (ascii_to_bin(setting[1]) << 6)
| ascii_to_bin(setting[0]);
data->output[0] = setting[0];
data->output[1] = setting[1];
p = (uint8_t *) data->output + 2;
}
setup_salt(salt, data);
/*
* Do it.
*/
if (do_des(0, 0, &r0, &r1, count, data))
return(NULL);
/*
* Now encode the result...
*/
l = (r0 >> 8);
*p++ = ascii64[(l >> 18) & 0x3f];
*p++ = ascii64[(l >> 12) & 0x3f];
*p++ = ascii64[(l >> 6) & 0x3f];
*p++ = ascii64[l & 0x3f];
l = (r0 << 16) | ((r1 >> 16) & 0xffff);
*p++ = ascii64[(l >> 18) & 0x3f];
*p++ = ascii64[(l >> 12) & 0x3f];
*p++ = ascii64[(l >> 6) & 0x3f];
*p++ = ascii64[l & 0x3f];
l = r1 << 2;
*p++ = ascii64[(l >> 12) & 0x3f];
*p++ = ascii64[(l >> 6) & 0x3f];
*p++ = ascii64[l & 0x3f];
*p = 0;
return(data->output);
}
#ifdef TEST
static char *
_crypt_extended(const char *key, const char *setting)
{
static int initialized = 0;
static struct php_crypt_extended_data data;
if (!initialized) {
_crypt_extended_init();
initialized = 1;
data.initialized = 0;
}
return _crypt_extended_r(key, setting, &data);
}
#define crypt _crypt_extended
static const struct {
const char *hash;
const char *pw;
} tests[] = {
/* "new"-style */
{"_J9..CCCCXBrJUJV154M", "U*U*U*U*"},
{"_J9..CCCCXUhOBTXzaiE", "U*U***U"},
{"_J9..CCCC4gQ.mB/PffM", "U*U***U*"},
{"_J9..XXXXvlzQGqpPPdk", "*U*U*U*U"},
{"_J9..XXXXsqM/YSSP..Y", "*U*U*U*U*"},
{"_J9..XXXXVL7qJCnku0I", "*U*U*U*U*U*U*U*U"},
{"_J9..XXXXAj8cFbP5scI", "*U*U*U*U*U*U*U*U*"},
{"_J9..SDizh.vll5VED9g", "ab1234567"},
{"_J9..SDizRjWQ/zePPHc", "cr1234567"},
{"_J9..SDizxmRI1GjnQuE", "zxyDPWgydbQjgq"},
{"_K9..SaltNrQgIYUAeoY", "726 even"},
{"_J9..SDSD5YGyRCr4W4c", ""},
/* "old"-style, valid salts */
{"CCNf8Sbh3HDfQ", "U*U*U*U*"},
{"CCX.K.MFy4Ois", "U*U***U"},
{"CC4rMpbg9AMZ.", "U*U***U*"},
{"XXxzOu6maQKqQ", "*U*U*U*U"},
{"SDbsugeBiC58A", ""},
{"./xZjzHv5vzVE", "password"},
{"0A2hXM1rXbYgo", "password"},
{"A9RXdR23Y.cY6", "password"},
{"ZziFATVXHo2.6", "password"},
{"zZDDIZ0NOlPzw", "password"},
/* "old"-style, "reasonable" invalid salts, UFC-crypt behavior expected */
{"\001\002wyd0KZo65Jo", "password"},
{"a_C10Dk/ExaG.", "password"},
{"~\377.5OTsRVjwLo", "password"},
/* The below are erroneous inputs, so NULL return is expected/required */
{"", ""}, /* no salt */
{" ", ""}, /* setting string is too short */
{"a:", ""}, /* unsafe character */
{"\na", ""}, /* unsafe character */
{"_/......", ""}, /* setting string is too short for its type */
{"_........", ""}, /* zero iteration count */
{"_/!......", ""}, /* invalid character in count */
{"_/......!", ""}, /* invalid character in salt */
{NULL}
};
int main(void)
{
int i;
for (i = 0; tests[i].hash; i++) {
char *hash = crypt(tests[i].pw, tests[i].hash);
if (!hash && strlen(tests[i].hash) < 13)
continue; /* expected failure */
if (!strcmp(hash, tests[i].hash))
continue; /* expected success */
puts("FAILED");
return 1;
}
puts("PASSED");
return 0;
}
#endif
| 22,075 | 26.560549 | 83 |
c
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.