int opendir(char *name) { struct stat sb; int fd; if (stat(name, &sb) < 0) return -1; if (!S_ISDIR(sb.st_mode)) { errno = ENOTDIR; return -1; } /* XXX rewind needed for some dirs */ #ifdef __INTERNAL_LIBSA_CREAD if ((fd = oopen(name, O_RDONLY)) >= 0) olseek(fd, 0, 0); #else if ((fd = open(name, O_RDONLY)) >= 0) lseek(fd, 0, SEEK_SET); #endif return fd; }
kobo_form_t *st_options_base_t::open() { sounds = 0; cfg_form = oopen(); cfg_form->open(prefs); return cfg_form; }
/* {{{ proto int ora_open(int connection) Open an Oracle cursor */ void php3_Ora_Open(INTERNAL_FUNCTION_PARAMETERS) { /* conn_index */ pval *arg; oraConnection *conn = NULL; oraCursor *cursor = NULL; int conn_ind; if (ARG_COUNT(ht) != 1 || getParameters(ht, 1, &arg) == FAILURE) { WRONG_PARAM_COUNT; } convert_to_long(arg); conn_ind = arg->value.lval; conn = ora_get_conn(list,plist, conn_ind); if (conn == NULL) { RETURN_FALSE; } if ((cursor = (oraCursor *)emalloc(sizeof(oraCursor))) == NULL){ php3_error(E_WARNING, "Out of memory"); RETURN_FALSE; } memset(cursor, 0, sizeof(oraCursor)); if (oopen(&cursor->cda, &conn->lda, (text *) 0, -1, -1, (text *) 0, -1)) { php3_error(E_WARNING, "Unable to open new cursor (%s)", ora_error(&cursor->cda)); efree(cursor); RETURN_FALSE; } cursor->open = 1; cursor->conn_ptr = conn; cursor->conn_id = conn_ind; RETURN_RESOURCE(ora_add_cursor(list, cursor)); }
int open(const char *p, int f, mode_t m) { int r; static int (*oopen) (const char *, int, mode_t)= 0; DP; R(open); r = oopen(p, f, m); if (r >= 0) emit(f & wmode ? 'w' : 'r', p); DD; return r; }
static int _ora_ping(oraConnection *conn) { Cda_Def cda; if (oopen(&cda, &conn->lda, (text *) 0, -1, -1, (text *) 0, -1)) { return 0; } if (oparse(&cda, "select sysdate from dual", (sb4) - 1, 0, VERSION_7)) { oclose(&cda); return 0; } oclose(&cda); return 1; }
int stat(const char *str, struct stat *sb) { int fd, rv; #ifdef __INTERNAL_LIBSA_CREAD if ((fd = oopen(str, 0)) < 0) #else if ((fd = open(str, 0)) < 0) #endif return (-1); rv = fstat(fd, sb); #ifdef __INTERNAL_LIBSA_CREAD (void)oclose(fd); #else (void)close(fd); #endif return (rv); }
Cda_Def *DBConnection_ORACLE::ExecuteQuery(char *p_query, DBString *p_arguments, int p_argument_count) { int t_affected_rows; t_affected_rows = 0; unsigned int t_query_length; t_query_length = strlen(p_query); Cda_Def *t_cursor; t_cursor = new Cda_Def; bool t_success; t_success = true; sword t_error; if (t_success) { t_error = oopen(t_cursor, getLDA(), (text *)0, -1, -1, NULL, -1); if (t_error != 0) t_success = false; } char *t_parsed_query; t_parsed_query = p_query; PlaceholderMap t_placeholder_map; if (p_argument_count != 0) { t_placeholder_map . length = 0; t_placeholder_map . elements = new int[p_argument_count + 1]; DBBuffer t_query_buffer(t_query_length + 1); t_success = processQuery(p_query, t_query_buffer, queryCallback, &t_placeholder_map); t_query_length = t_query_buffer . getSize(); t_parsed_query = t_query_buffer . grab(); } if (t_success) { if (oparse(t_cursor, (text *)t_parsed_query, t_query_length, DEFER_PARSE, PARSE_V7_LNG) != 0) t_success = false; } if (t_success) { if (!BindVariables(t_cursor, p_arguments, p_argument_count, &t_placeholder_map)) t_success = false; } if (t_success) { t_error = oexec(t_cursor); if (t_error != 0) t_success = false; } if (!t_success) { delete t_cursor; t_cursor = NULL; } return t_cursor; }
static int perform_oracle_search(uschar *query, uschar *server, uschar **resultptr, uschar **errmsg, BOOL *defer_break) { Cda_Def *cda = NULL; struct cda_def *oracle_handle = NULL; Ora_Describe *desc = NULL; Ora_Define *def = NULL; void *hda = NULL; int i; int ssize = 0; int offset = 0; int yield = DEFER; unsigned int num_fields = 0; uschar *result = NULL; oracle_connection *cn = NULL; uschar *server_copy = NULL; uschar *sdata[4]; uschar tmp[1024]; /* Disaggregate the parameters from the server argument. The order is host, database, user, password. We can write to the string, since it is in a nextinlist temporary buffer. The copy of the string that is used for caching has the password removed. This copy is also used for debugging output. */ for (i = 3; i > 0; i--) { uschar *pp = Ustrrchr(server, '/'); if (pp == NULL) { *errmsg = string_sprintf("incomplete ORACLE server data: %s", server); *defer_break = TRUE; return DEFER; } *pp++ = 0; sdata[i] = pp; if (i == 3) server_copy = string_copy(server); /* sans password */ } sdata[0] = server; /* What's left at the start */ /* If the database is the empty string, set it NULL - the query must then define it. */ if (sdata[1][0] == 0) sdata[1] = NULL; /* See if we have a cached connection to the server */ for (cn = oracle_connections; cn != NULL; cn = cn->next) { if (strcmp(cn->server, server_copy) == 0) { oracle_handle = cn->handle; hda = cn->hda_mem; break; } } /* If no cached connection, we must set one up */ if (cn == NULL) { DEBUG(D_lookup) debug_printf("ORACLE new connection: host=%s database=%s " "user=%s\n", sdata[0], sdata[1], sdata[2]); /* Get store for a new connection, initialize it, and connect to the server */ oracle_handle = store_get(sizeof(struct cda_def)); hda = store_get(HDA_SIZE); memset(hda,'\0',HDA_SIZE); /* * Perform a default (blocking) login * * sdata[0] = tnsname (service name - typically host name) * sdata[1] = dbname - not used at present * sdata[2] = username * sdata[3] = passwd */ if(olog(oracle_handle, hda, sdata[2], -1, sdata[3], -1, sdata[0], -1, (ub4)OCI_LM_DEF) != 0) { *errmsg = oracle_error(oracle_handle, oracle_handle->rc, US"connection failed"); *defer_break = FALSE; goto ORACLE_EXIT_NO_VALS; } /* Add the connection to the cache */ cn = store_get(sizeof(oracle_connection)); cn->server = server_copy; cn->handle = oracle_handle; cn->next = oracle_connections; cn->hda_mem = hda; oracle_connections = cn; } /* Else use a previously cached connection - we can write to the server string to obliterate the password because it is in a nextinlist temporary buffer. */ else { DEBUG(D_lookup) debug_printf("ORACLE using cached connection for %s\n", server_copy); } /* We have a connection. Open a cursor and run the query */ cda = store_get(sizeof(Cda_Def)); if (oopen(cda, oracle_handle, (text *)0, -1, -1, (text *)0, -1) != 0) { *errmsg = oracle_error(oracle_handle, cda->rc, "failed to open cursor"); *defer_break = FALSE; goto ORACLE_EXIT_NO_VALS; } if (oparse(cda, (text *)query, (sb4) -1, (sword)PARSE_NO_DEFER, (ub4)PARSE_V7_LNG) != 0) { *errmsg = oracle_error(oracle_handle, cda->rc, "query failed"); *defer_break = FALSE; oclose(cda); goto ORACLE_EXIT_NO_VALS; } /* Find the number of fields returned and sort out their types. If the number is one, we don't add field names to the data. Otherwise we do. */ def = store_get(sizeof(Ora_Define)*MAX_SELECT_LIST_SIZE); desc = store_get(sizeof(Ora_Describe)*MAX_SELECT_LIST_SIZE); if ((num_fields = describe_define(cda,def,desc)) == -1) { *errmsg = oracle_error(oracle_handle, cda->rc, "describe_define failed"); *defer_break = FALSE; goto ORACLE_EXIT; } if (oexec(cda)!=0) { *errmsg = oracle_error(oracle_handle, cda->rc, "oexec failed"); *defer_break = FALSE; goto ORACLE_EXIT; } /* Get the fields and construct the result string. If there is more than one row, we insert '\n' between them. */ while (cda->rc != NO_DATA_FOUND) /* Loop for each row */ { ofetch(cda); if(cda->rc == NO_DATA_FOUND) break; if (result != NULL) result = string_cat(result, &ssize, &offset, "\n", 1); /* Single field - just add on the data */ if (num_fields == 1) result = string_cat(result, &ssize, &offset, def[0].buf, def[0].col_retlen); /* Multiple fields - precede by file name, removing {lead,trail}ing WS */ else for (i = 0; i < num_fields; i++) { int slen; uschar *s = US desc[i].buf; while (*s != 0 && isspace(*s)) s++; slen = Ustrlen(s); while (slen > 0 && isspace(s[slen-1])) slen--; result = string_cat(result, &ssize, &offset, s, slen); result = string_cat(result, &ssize, &offset, US"=", 1); /* int and float type wont ever need escaping. Otherwise, quote the value if it contains spaces or is empty. */ if (desc[i].dbtype != INT_TYPE && desc[i].dbtype != FLOAT_TYPE && (def[i].buf[0] == 0 || strchr(def[i].buf, ' ') != NULL)) { int j; result = string_cat(result, &ssize, &offset, "\"", 1); for (j = 0; j < def[i].col_retlen; j++) { if (def[i].buf[j] == '\"' || def[i].buf[j] == '\\') result = string_cat(result, &ssize, &offset, "\\", 1); result = string_cat(result, &ssize, &offset, def[i].buf+j, 1); } result = string_cat(result, &ssize, &offset, "\"", 1); } else switch(desc[i].dbtype) { case INT_TYPE: sprintf(CS tmp, "%d", def[i].int_buf); result = string_cat(result, &ssize, &offset, tmp, Ustrlen(tmp)); break; case FLOAT_TYPE: sprintf(CS tmp, "%f", def[i].flt_buf); result = string_cat(result, &ssize, &offset, tmp, Ustrlen(tmp)); break; case STRING_TYPE: result = string_cat(result, &ssize, &offset, def[i].buf, def[i].col_retlen); break; default: *errmsg = string_sprintf("ORACLE: unknown field type %d", desc[i].dbtype); *defer_break = FALSE; result = NULL; goto ORACLE_EXIT; } result = string_cat(result, &ssize, &offset, " ", 1); } } /* If result is NULL then no data has been found and so we return FAIL. Otherwise, we must terminate the string which has been built; string_cat() always leaves enough room for a terminating zero. */ if (result == NULL) { yield = FAIL; *errmsg = "ORACLE: no data found"; } else { result[offset] = 0; store_reset(result + offset + 1); } /* Get here by goto from various error checks. */ ORACLE_EXIT: /* Close the cursor; don't close the connection, as it is cached. */ oclose(cda); ORACLE_EXIT_NO_VALS: /* Non-NULL result indicates a sucessful result */ if (result != NULL) { *resultptr = result; return OK; } else { DEBUG(D_lookup) debug_printf("%s\n", *errmsg); return yield; /* FAIL or DEFER */ } }
/* * Function: setup * * Description: This routine does the necessary setup to execute the SQL * statement. Specifically, it does the open, parse, bind and * define phases as needed. * */ void setup() { colp *colsptr; /* temporary pointer */ sword colindex; if (oopen(&cda, &lda, (text *) 0, -1, -1, (text *) 0, -1)) /* open */ { err_report(&cda); do_exit(OCI_EXIT_FAILURE); } if (oparse(&cda, sqlstmt, (sb4) -1, DEFER_PARSE, /* parse */ (ub4) VERSION_7)) { err_report(&cda); do_exit(OCI_EXIT_FAILURE); } /* bind the scalar */ if (obndra(&cda, (text *)":numins", -1, (ub1 *)&numinsert, (sword)sizeof(numinsert), SQLT_INT, -1, (sb2 *) 0, (ub2 *)0, (ub2 *)0, (ub4)0, (ub4 *)0, (text *)0, -1, -1)) /* bind */ { err_report(&cda); do_exit(OCI_EXIT_FAILURE); } if (obndra(&cda, (text *)":retval", -1, (ub1 *)&retval, (sword)sizeof(retval), SQLT_INT, -1, (sb2 *) 0, (ub2 *)0, (ub2 *)0, (ub4)0, (ub4 *)0, (text *)0, -1, -1)) /* bind */ { err_report(&cda); do_exit(OCI_EXIT_FAILURE); } cols = malloc_col(NUMCOLS); colsptr = cols; for (colindex = 0; colindex < NUMCOLS; colindex++, colsptr++) { colsptr->c_size = coltable[colindex].size; colsptr->c_type = coltable[colindex].type; colsptr->c_indp = (sb2*)malloc((size_t)(MAX_ROWS_PER_INSERT*sizeof(sb2))); memset((dvoid *)colsptr->c_indp, 0, MAX_ROWS_PER_INSERT * sizeof(sb2)); colsptr->c_rlen = (ub2*)malloc((size_t)(MAX_ROWS_PER_INSERT*sizeof(ub2))); memset((dvoid *)colsptr->c_rlen, 0, MAX_ROWS_PER_INSERT * sizeof(ub2)); colsptr->c_rcode = (ub2*)malloc((size_t)(MAX_ROWS_PER_INSERT*sizeof(ub2))); memset((dvoid *)colsptr->c_rcode, 0, MAX_ROWS_PER_INSERT * sizeof(ub2)); colsptr->c_buf = (ub1 *)malloc((size_t)(MAX_ROWS_PER_INSERT*colsptr->c_size)); memset((dvoid *)colsptr->c_buf, 0, MAX_ROWS_PER_INSERT * colsptr->c_size); colsptr->c_curlen = 0; switch (colindex) { case(0) : /* GOTCHA!!! - need to pass in zeroes for mal and cal parameters when running a regular insert. Set it to non-zero when using plsql */ if (obndra(&cda, (text *)":col1", -1, colsptr->c_buf, colsptr->c_size, (sword)colsptr->c_type, (sword) -1, (sb2 *)colsptr->c_indp, colsptr->c_rlen, colsptr->c_rcode, (ub4)MAX_ROWS_PER_INSERT, (ub4 *)&(colsptr->c_curlen), (text *)0, -1, -1)) { err_report(&cda); do_exit(OCI_EXIT_FAILURE); } break; } } }
/* {{{ proto int ora_do(int connection, int cursor) Parse and execute a statement and fetch first result row */ void php3_Ora_Do(INTERNAL_FUNCTION_PARAMETERS) { pval *argv[2]; oraConnection *conn = NULL; oraCursor *cursor = NULL; text *query; if (ARG_COUNT(ht) != 2 || getParametersArray(ht, 2, argv) == FAILURE) { WRONG_PARAM_COUNT; } convert_to_long(argv[0]); convert_to_string(argv[1]); conn = ora_get_conn(list,plist, argv[0]->value.lval); if (conn == NULL) { RETURN_FALSE; } if ((cursor = (oraCursor *)emalloc(sizeof(oraCursor))) == NULL){ php3_error(E_WARNING, "Out of memory"); RETURN_FALSE; } memset(cursor, 0, sizeof(oraCursor)); query = (text *) estrndup(argv[1]->value.str.val,argv[1]->value.str.len); if (query == NULL) { php3_error(E_WARNING, "Invalid query in Ora_Do"); RETURN_FALSE; } cursor->query = query; if (oopen(&cursor->cda, &conn->lda, (text *) 0, -1, -1, (text *) 0, -1)) { php3_error(E_WARNING, "Unable to open new cursor (%s)", ora_error(&cursor->cda)); efree(cursor); RETURN_FALSE; } cursor->open = 1; cursor->conn_ptr = conn; cursor->conn_id = argv[0]->value.lval; /* Prepare stmt */ if (oparse(&cursor->cda, query, (sb4) - 1, 1, VERSION_7)){ php3_error(E_WARNING, "Ora_Do failed (%s)", ora_error(&cursor->cda)); _close_oracur(cursor); RETURN_FALSE; } /* Execute stmt (and fetch 1st row for selects) */ if (cursor->cda.ft == FT_SELECT) { if (ora_describe_define(cursor) < 0){ /* error message is given by ora_describe_define() */ _close_oracur(cursor); RETURN_FALSE; } if (oexfet(&cursor->cda, 1, 0, 0)) { php3_error(E_WARNING, "Ora_Do failed (%s)", ora_error(&cursor->cda)); _close_oracur(cursor); RETURN_FALSE; } cursor->fetched = 1; } else { if (oexec(&cursor->cda)) { php3_error(E_WARNING, "Ora_Do failed (%s)", ora_error(&cursor->cda)); _close_oracur(cursor); RETURN_FALSE; } } RETURN_RESOURCE(ora_add_cursor(list, cursor)); }