Asterisk - The Open Source Telephony Project  18.5.0
Functions
res_odbc_transaction.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

struct odbc_objast_odbc_retrieve_transaction_obj (struct ast_channel *chan, const char *objname)
 Retrieve an ODBC transaction connection with the given ODBC class name. More...
 

Function Documentation

◆ ast_odbc_retrieve_transaction_obj()

struct odbc_obj* ast_odbc_retrieve_transaction_obj ( struct ast_channel chan,
const char *  objname 
)

Retrieve an ODBC transaction connection with the given ODBC class name.

Note
The name passed here is not the name of the transaction but the name of the ODBC class defined in res_odbc.conf.
Do not call ast_odbc_release_obj() on the retrieved connection. Calling this function does not make you the owner of the connection.

XXX This function is majorly flawed because it ignores properties of transactions and simply finds one that corresponds to the given DSN. The problem here is that transactions have names and they maintain which transaction is "active" for operations like transaction creation, commit, and rollback. However, when it comes to intermediary operations to be made on the transactions, all that is ignored. It means that if a channel has created multiple transactions for the same DSN, it's a crapshoot which of those transactions the operation will be performed on. This can potentially lead to baffling errors under the right circumstances.

XXX The semantics of this function make for writing some awkward code. If you use func_odbc as an example, it has to first try to retrieve a transactional connection, then failing that, create a non-transactional connection. The result is that it has to remember which type of connection it's using and know whether to release the connection when completed or not. It would be much better if callers did not have to jump through such hoops.

Parameters
chanChannel on which the ODBC transaction was created
objnameThe name of the ODBC class configured in res_odbc.conf
Return values
NULLTransaction connection could not be found.
non-NULLA transactional connection

Definition at line 466 of file res_odbc_transaction.c.

References ast_channel_datastore_find(), ast_channel_lock, ast_channel_unlock, AST_LIST_HEAD, AST_LIST_LOCK, AST_LIST_TRAVERSE, AST_LIST_UNLOCK, ast_odbc_class_get_name(), ast_datastore::data, odbc_txn_frame::list, NULL, odbc_txn_frame::obj, and odbc_obj::parent.

Referenced by acf_odbc_write().

467 {
468  struct ast_datastore *txn_store;
469  AST_LIST_HEAD(, odbc_txn_frame) *oldlist;
470  struct odbc_txn_frame *txn = NULL;
471 
472  if (!chan || !objname) {
473  /* No channel == no transaction */
474  return NULL;
475  }
476 
477  ast_channel_lock(chan);
478  if ((txn_store = ast_channel_datastore_find(chan, &txn_info, NULL))) {
479  oldlist = txn_store->data;
480  } else {
481  ast_channel_unlock(chan);
482  return NULL;
483  }
484 
485  AST_LIST_LOCK(oldlist);
486  ast_channel_unlock(chan);
487 
488  AST_LIST_TRAVERSE(oldlist, txn, list) {
489  if (txn->obj && txn->obj->parent && !strcmp(ast_odbc_class_get_name(txn->obj->parent), objname)) {
490  AST_LIST_UNLOCK(oldlist);
491  return txn->obj;
492  }
493  }
494  AST_LIST_UNLOCK(oldlist);
495  return NULL;
496 }
#define ast_channel_lock(chan)
Definition: channel.h:2945
#define AST_LIST_LOCK(head)
Locks a list.
Definition: linkedlists.h:39
#define AST_LIST_HEAD(name, type)
Defines a structure to be used to hold a list of specified type.
Definition: linkedlists.h:172
#define AST_LIST_UNLOCK(head)
Attempts to unlock a list.
Definition: linkedlists.h:139
Structure for a data store object.
Definition: datastore.h:68
struct ast_datastore * ast_channel_datastore_find(struct ast_channel *chan, const struct ast_datastore_info *info, const char *uid)
Find a datastore on a channel.
Definition: channel.c:2404
#define NULL
Definition: resample.c:96
struct odbc_class * parent
Definition: res_odbc.h:48
static const struct ast_datastore_info txn_info
struct odbc_obj * obj
Definition: res_odbc.c:118
#define AST_LIST_TRAVERSE(head, var, field)
Loops over (traverses) the entries in a list.
Definition: linkedlists.h:490
#define ast_channel_unlock(chan)
Definition: channel.h:2946
void * data
Definition: datastore.h:70
struct odbc_txn_frame::@470 list
const char * ast_odbc_class_get_name(struct odbc_class *class)
Get the name of an ODBC class.
Definition: res_odbc.c:559