/*Method to disconnect from ORACLE server*/ void DBConnection_ORACLE::disconnect() { if (!isConnected) return; closeCursors(); ologof(&lda); isConnected = False; }
static void oracle_tidy(void) { oracle_connection *cn; while ((cn = oracle_connections) != NULL) { oracle_connections = cn->next; DEBUG(D_lookup) debug_printf("close ORACLE connection: %s\n", cn->server); ologof(cn->handle); } }
static int _close_oraconn(oraConnection *conn) { ORACLE_TLS_VARS; conn->open = 0; ologof(&conn->lda); ORACLE_GLOBAL(php3_oracle_module).num_links--; efree(conn); _php3_hash_del(ORACLE_GLOBAL(php3_oracle_module).conns,(void*)&conn,sizeof(void*)); return 1; }
void php3_Ora_Do_Logon(INTERNAL_FUNCTION_PARAMETERS, int persistent) { char *user = NULL; char *pwd = NULL; pval *arg1, *arg2; oraConnection *db_conn; list_entry *index_ptr; char *hashed_details; int hashed_len, len, id; ORACLE_TLS_VARS; if (getParameters(ht, 2, &arg1, &arg2) == FAILURE) { WRONG_PARAM_COUNT; } convert_to_string(arg1); convert_to_string(arg2); user = arg1->value.str.val; pwd = arg2->value.str.val; if (!ORACLE_GLOBAL(php3_oracle_module).allow_persistent) { persistent = 0; } if (ORACLE_GLOBAL(php3_oracle_module).max_links != -1 && ORACLE_GLOBAL(php3_oracle_module).num_links >= ORACLE_GLOBAL(php3_oracle_module).max_links) { php3_error(E_WARNING, "Oracle: Too many open links (%d)", ORACLE_GLOBAL(php3_oracle_module).num_links); RETURN_FALSE; } /* the user requested a persistent connection */ if (persistent && ORACLE_GLOBAL(php3_oracle_module).max_persistent != -1 && ORACLE_GLOBAL(php3_oracle_module).num_persistent >= ORACLE_GLOBAL(php3_oracle_module).max_persistent) { php3_error(E_WARNING,"Oracle: Too many open persistent links (%d)", ORACLE_GLOBAL(php3_oracle_module).num_persistent); RETURN_FALSE; } len = strlen(user) + strlen(pwd) + 9; hashed_details = emalloc(len); if (hashed_details == NULL) { php3_error(E_WARNING, "Out of memory"); RETURN_FALSE; } hashed_len = _php3_sprintf(hashed_details, "ora_%s_%s", user, pwd); /* try to find if we already have this link in our persistent list, * no matter if it is to be persistent or not */ if (_php3_hash_find(plist, hashed_details, hashed_len + 1, (void **) &index_ptr) == FAILURE) { /* the link is not in the persistent list */ list_entry new_index_ptr; if (persistent) db_conn = (oraConnection *)malloc(sizeof(oraConnection)); else db_conn = (oraConnection *)emalloc(sizeof(oraConnection)); if (db_conn == NULL){ efree(hashed_details); php3_error(E_WARNING, "Out of memory"); RETURN_FALSE; } memset((void *) db_conn,0,sizeof(oraConnection)); #if HAS_OLOG if (olog(&db_conn->lda, db_conn->hda, user, strlen(user), pwd, strlen(pwd), 0, -1, OCI_LM_DEF)) { #else if (orlon(&db_conn->lda, db_conn->hda, user, strlen(user), pwd, strlen(pwd), 0)) { #endif php3_error(E_WARNING, "Unable to connect to ORACLE (%s)", ora_error(&db_conn->lda)); /* The next line is to provide error information * for OraError && OraErrorCode calls */ db_err_conn = *db_conn; if (persistent) free(db_conn); else efree(db_conn); efree(hashed_details); RETURN_FALSE; } db_conn->open = 1; if (persistent){ /*new_le.type = ORACLE_GLOBAL(php3_oracle_module).le_pconn; new_le.ptr = db_conn;*/ RETVAL_RESOURCE(php3_plist_insert(db_conn, ORACLE_GLOBAL(php3_oracle_module).le_pconn)); new_index_ptr.ptr = (void *) return_value->value.lval; new_index_ptr.type = le_index_ptr; if (_php3_hash_update(plist,hashed_details,hashed_len + 1,(void *) &new_index_ptr, sizeof(list_entry),NULL) == FAILURE) { ologof(&db_conn->lda); free(db_conn); efree(hashed_details); php3_error(E_WARNING, "Can't update hashed details list"); RETURN_FALSE; } ORACLE_GLOBAL(php3_oracle_module).num_persistent++; } else { /* non persistent, simply add to list */ RETVAL_RESOURCE(php3_list_insert(db_conn, ORACLE_GLOBAL(php3_oracle_module).le_conn)); } ORACLE_GLOBAL(php3_oracle_module).num_links++; } else { int type; /* the link is already in the persistent list */ if (index_ptr->type != le_index_ptr) { efree(hashed_details); php3_error(E_WARNING, "Oops, something went completly wrong"); RETURN_FALSE; } id = (int) index_ptr->ptr; db_conn = (oraConnection *)php3_plist_find(id, &type); if (db_conn && (type == ORACLE_GLOBAL(php3_oracle_module).le_conn || type == ORACLE_GLOBAL(php3_oracle_module).le_pconn)){ if(!_ora_ping(db_conn)) { /* XXX Reinitialize lda, hda ? */ #if HAS_OLOG if(olog(&db_conn->lda, db_conn->hda, user, strlen(user), pwd, strlen(pwd), 0, -1, OCI_LM_DEF)) { #else if(orlon(&db_conn->lda, db_conn->hda, user, strlen(user), pwd, strlen(pwd), 0)) { #endif /* The next line is to provide error information * for OraError && OraErrorCode calls */ db_err_conn = *db_conn; php3_error(E_WARNING, "Unable to reconnect to ORACLE (%s)", ora_error(&db_conn->lda)); /* Delete list entry for this connection */ php3_plist_delete(id); /* Delete hashed list entry for this dead connection */ _php3_hash_del(plist, hashed_details, hashed_len); efree(hashed_details); RETURN_FALSE; } } RETVAL_RESOURCE(id); } } _php3_hash_add(ORACLE_GLOBAL(php3_oracle_module).conns, (void*)&db_conn, sizeof(void*), (void*)&db_conn, sizeof(void*), NULL); efree(hashed_details); } /* {{{ proto int ora_logoff(int connection) Close an Oracle connection */ void php3_Ora_Logoff(INTERNAL_FUNCTION_PARAMETERS) { /* conn_index */ int type, ind; oraConnection *conn; pval *arg; ORACLE_TLS_VARS; if (getParameters(ht, 1, &arg) == FAILURE) { WRONG_PARAM_COUNT; } convert_to_long(arg); ind = (int)arg->value.lval; conn = (oraConnection *)php3_list_find(ind, &type); if (!conn || (type != ORACLE_GLOBAL(php3_oracle_module).le_conn && type != ORACLE_GLOBAL(php3_oracle_module).le_pconn)) { return; } php3_list_delete(ind); }