typedef struct dba_handler {
char *name;
- int (*open)(dba_info * TSRMLS_DC);
+ int (*open)(dba_info *, char **error TSRMLS_DC);
void (*close)(dba_info * TSRMLS_DC);
char* (*fetch)(dba_info *, char *, int, int, int * TSRMLS_DC);
int (*update)(dba_info *, char *, int, char *, int, int TSRMLS_DC);
dba_mode_t modenr;
dba_info *info;
dba_handler *hptr;
- char *key = NULL;
+ char *key = NULL, *error = NULL;
int keylen = 0;
int i;
for (hptr = handler; hptr->name && strcasecmp(hptr->name, Z_STRVAL_PP(args[2])); hptr++);
if (!hptr->name) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "No such handler: %s", Z_STRVAL_PP(args[2]));
+ php_error_docref2(NULL TSRMLS_CC, Z_STRVAL_PP(args[0]), Z_STRVAL_PP(args[1]), E_WARNING, "No such handler: %s", Z_STRVAL_PP(args[2]));
FREENOW;
RETURN_FALSE;
}
modenr = DBA_TRUNC;
break;
default:
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Illegal DBA mode: %s", Z_STRVAL_PP(args[1]));
+ php_error_docref2(NULL TSRMLS_CC, Z_STRVAL_PP(args[0]), Z_STRVAL_PP(args[1]), E_WARNING, "Illegal DBA mode");
FREENOW;
RETURN_FALSE;
}
info->argv = args + 3;
info->hnd = NULL;
- if (hptr->open(info TSRMLS_CC) != SUCCESS) {
+ if (hptr->open(info, &error TSRMLS_CC) != SUCCESS) {
dba_close(info TSRMLS_CC);
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Driver initialization failed for handler: %s", Z_STRVAL_PP(args[2]));
+ php_error_docref2(NULL TSRMLS_CC, Z_STRVAL_PP(args[0]), Z_STRVAL_PP(args[1]), E_WARNING, "Driver initialization failed for handler: %s%s%s", Z_STRVAL_PP(args[2]), error?": ":"", error?error:"");
FREENOW;
RETURN_FALSE;
}
make = 0;
file = php_stream_open_wrapper(info->path, "rb", STREAM_MUST_SEEK|IGNORE_PATH|ENFORCE_SAFE_MODE, NULL);
if (!file) {
+ *error = "Unable to open file";
return FAILURE;
}
#else
file = VCWD_OPEN(info->path, O_RDONLY);
if (file < 0) {
+ *error = "Unable to open file";
return FAILURE;
}
#endif
make = 1;
file = php_stream_open_wrapper(info->path, "wb", STREAM_MUST_SEEK|IGNORE_PATH|ENFORCE_SAFE_MODE, NULL);
if (!file) {
+ *error = "Unable to open file";
return FAILURE;
}
break;
case DBA_WRITER:
+ *error = "Update operations are not supported";
return FAILURE; /* not supported */
#endif
default:
- /* currently not supported: */
+ *error = "Currently not supported";
return FAILURE;
}
cdb = ecalloc(sizeof(dba_cdb), 1);
if (!cdb) {
+ pinfo->dbf = cdb;
#if DBA_CDB_BUILTIN
php_stream_close(file);
#else
close(file);
#endif
+ *error = "Out of memory";
return FAILURE;
}
info->mode == DBA_WRITER ? 0 :
info->mode == DBA_TRUNC ? DB_CREATE | DB_TRUNCATE : -1;
- if (gmode == -1)
- return FAILURE;
+ if (gmode == -1) {
+ return FAILURE;/* not possible */
+ }
if (info->argc > 0) {
convert_to_long_ex(info->argv[0]);
}
info->dbf = ecalloc(sizeof(dba_db2_data), 1);
+ if (!info->dbf) {
+ *error = "Out of memory";
+ return FAILURE;
+ }
((dba_db2_data *) info->dbf)->dbp = dbp;
return SUCCESS;
}
info->mode == DBA_TRUNC ? DB_CREATE | DB_TRUNCATE : -1;
if (gmode == -1)
- return FAILURE;
+ return FAILURE; /* not possible */
if (info->argc > 0) {
convert_to_long_ex(info->argv[0]);
dba_db3_data *data;
data = emalloc(sizeof(*data));
+ if (!data) {
+ *error = "Out of memory";
+ return FAILURE;
+ }
data->dbp = dbp;
data->cursor = NULL;
info->dbf = data;
}
info->dbf = ecalloc(sizeof(dba_dbm_data), 1);
+ if (!info->dbf) {
+ *error = "Out of memory";
+ return FAILURE;
+ }
return SUCCESS;
}
info->mode == DBA_TRUNC ? GDBM_NEWDB : -1;
if(gmode == -1)
- return FAILURE;
+ return FAILURE; /* not possible */
if(info->argc > 0) {
convert_to_long_ex(info->argv[0]);
((dba_gdbm_data *) info->dbf)->dbf = dbf;
return SUCCESS;
}
+ *error = "Out of memory";
return FAILURE;
}
gmode = O_RDWR | O_CREAT | O_TRUNC;
break;
default:
- return FAILURE;
+ return FAILURE; /* not possible */
}
if(info->argc > 0) {
pinfo->dbf = dbf;
return SUCCESS;
}
+ *error = "Out of memory";
return FAILURE;
}
/* common prototypes which must be supplied by modules */
#define DBA_OPEN_FUNC(x) \
- int dba_open_##x(dba_info *info TSRMLS_DC)
+ int dba_open_##x(dba_info *info, char **error TSRMLS_DC)
#define DBA_CLOSE_FUNC(x) \
void dba_close_##x(dba_info *info TSRMLS_DC)
#define DBA_FETCH_FUNC(x) \