"Fossies" - the Fresh Open Source Software Archive

Member "opensips-3.0.1/modules/db_mysql/my_con.h" (16 Apr 2019, 3559 Bytes) of package /linux/misc/opensips-3.0.1.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. See also the last Fossies "Diffs" side-by-side code changes report for "my_con.h": 2.4.5_vs_3.0.0.

    1 /*
    2  * Copyright (C) 2001-2003 FhG Fokus
    3  * Copyright (C) 2008 1&1 Internet AG
    4  *
    5  * This file is part of opensips, a free SIP server.
    6  *
    7  * opensips is free software; you can redistribute it and/or modify
    8  * it under the terms of the GNU General Public License as published by
    9  * the Free Software Foundation; either version 2 of the License, or
   10  * (at your option) any later version
   11  *
   12  * opensips is distributed in the hope that it will be useful,
   13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
   14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   15  * GNU General Public License for more details.
   16  *
   17  * You should have received a copy of the GNU General Public License
   18  * along with this program; if not, write to the Free Software
   19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
   20  */
   21 
   22 #ifndef MY_CON_H
   23 #define MY_CON_H
   24 
   25 #include "../../db/db_pool.h"
   26 #include "../../db/db_id.h"
   27 
   28 #include <time.h>
   29 #include <mysql.h>
   30 
   31 #include "../tls_mgm/tls_helper.h"
   32 #if (defined LIBMYSQL_VERSION_ID) && (LIBMYSQL_VERSION_ID >= 80000)
   33 # define my_bool bool
   34 #endif
   35 
   36 #define PREP_STMT_VAL_LEN   1024
   37 
   38 struct bind_icontent {
   39     unsigned long len;
   40     my_bool null;
   41 };
   42 
   43 struct bind_ocontent {
   44     char buf[PREP_STMT_VAL_LEN];
   45     unsigned long len;
   46     my_bool null;
   47     my_bool error;
   48 };
   49 
   50 
   51 struct my_stmt_ctx {
   52     MYSQL_STMT *stmt;
   53     str table;
   54     str query;
   55     int has_out;
   56     struct my_stmt_ctx *next;
   57 };
   58 
   59 struct prep_stmt {
   60     struct my_stmt_ctx *stmts;
   61     struct my_stmt_ctx *ctx;
   62     /*in*/
   63     MYSQL_BIND *bind_in;
   64     struct bind_icontent *in_bufs;
   65     /*out*/
   66     int cols_out;
   67     MYSQL_BIND *bind_out;
   68     struct bind_ocontent *out_bufs;
   69     /*linking*/
   70     struct prep_stmt *next;
   71 };
   72 
   73 
   74 struct my_con {
   75     struct db_id* id;        /**< Connection identifier */
   76     unsigned int ref;        /**< Reference count */
   77     struct pool_con *async_pool; /**< Subpool of identical database handles */
   78     int no_transfers;        /**< Number of async queries to this backend */
   79     struct db_transfer *transfers; /**< Array of ongoing async operations */
   80     struct pool_con *next;   /**< Next element in the pool (different db_id) */
   81 
   82     MYSQL_RES* res;          /* Actual result */
   83     MYSQL* con;              /* Connection representation */
   84     MYSQL_ROW row;           /* Actual row in the result */
   85     unsigned int init;       /* If the mysql conn was initialized */
   86 
   87     struct prep_stmt *ps_list; /* list of prepared statements */
   88     unsigned int disconnected; /* (CR_CONNECTION_ERROR) was detected */
   89 
   90     struct tls_domain *tls_dom;;  /* TLS domain */
   91 };
   92 
   93 
   94 
   95 /*
   96  * Some convenience wrappers
   97  */
   98 #define CON_RESULT(db_con)     (((struct my_con*)((db_con)->tail))->res)
   99 #define CON_CONNECTION(db_con) (((struct my_con*)((db_con)->tail))->con)
  100 #define CON_ROW(db_con)        (((struct my_con*)((db_con)->tail))->row)
  101 #define CON_PS_LIST(db_con)    (((struct my_con*)((db_con)->tail))->ps_list)
  102 #define CON_DISCON(db_con)     (((struct my_con*)((db_con)->tail))->disconnected)
  103 
  104 #define CON_MYSQL_PS(db_con) \
  105     ((struct prep_stmt*)(CON_CURR_PS(db_con)))
  106 #define CON_PS_STMT(db_con) \
  107     (CON_MYSQL_PS(db_con)->ctx->stmt)
  108 #define CON_PS_STMTS(db_con) \
  109     (CON_MYSQL_PS(db_con)->stmts)
  110 #define CON_PS_OUTCOL(_db_con, _i) \
  111     ((CON_MYSQL_PS(_db_con)->out_bufs)[_i])
  112 
  113 
  114 int db_mysql_connect(struct my_con* ptr);
  115 
  116 
  117 /*
  118  * Create a new connection structure,
  119  * open the MySQL connection and set reference count to 1
  120  */
  121 struct my_con* db_mysql_new_connection(const struct db_id* id);
  122 
  123 
  124 /*
  125  * Close the connection and release memory
  126  */
  127 void db_mysql_free_connection(struct pool_con* con);
  128 
  129 #endif /* MY_CON_H */