LCOV - code coverage report
Current view: top level - include - ctlib.h (source / functions) Hit Total Coverage
Test: FreeTDS coverage Lines: 1 1 100.0 %
Date: 2026-11-07 23:58:45 Functions: 0 0 -

          Line data    Source code
       1             : /* FreeTDS - Library of routines accessing Sybase and Microsoft databases
       2             :  * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004  Brian Bruns
       3             :  *
       4             :  * This library is free software; you can redistribute it and/or
       5             :  * modify it under the terms of the GNU Library General Public
       6             :  * License as published by the Free Software Foundation; either
       7             :  * version 2 of the License, or (at your option) any later version.
       8             :  *
       9             :  * This library is distributed in the hope that it will be useful,
      10             :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      11             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      12             :  * Library General Public License for more details.
      13             :  *
      14             :  * You should have received a copy of the GNU Library General Public
      15             :  * License along with this library; if not, write to the
      16             :  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
      17             :  * Boston, MA 02111-1307, USA.
      18             :  */
      19             : 
      20             : #ifndef _tdsguard_gH4tOYBTzynx4DgqFzOEbB_
      21             : #define _tdsguard_gH4tOYBTzynx4DgqFzOEbB_
      22             : 
      23             : #include <freetds/tds.h>
      24             : #include <freetds/tds/convert.h>
      25             : #include <freetds/utils/string.h>
      26             : #include <freetds/bool.h>
      27             : 
      28             : /*
      29             :  * Internal (not part of the exposed API) prototypes and such.
      30             :  */
      31             : 
      32             : #include <freetds/pushvis.h>
      33             : 
      34             : #ifdef __cplusplus
      35             : extern "C"
      36             : {
      37             : #if 0
      38             : }
      39             : #endif
      40             : #endif
      41             : 
      42             : /* Fix a problem with Windows headers */
      43             : #undef small
      44             : 
      45             : /*
      46             :  * internal types
      47             :  */
      48             : struct _cs_config
      49             : {
      50             :         bool cs_expose_formats;
      51             :         bool cs_note_empty_data;
      52             : };
      53             : 
      54             : /* Code changed for error handling */
      55             : /* Code changes starts here - CT_DIAG - 01 */
      56             : 
      57             : /* This structure is used in CT_DIAG */
      58             : 
      59             : struct cs_diag_msg_client
      60             : {
      61             :         struct cs_diag_msg_client *next;
      62             :         CS_CLIENTMSG clientmsg;
      63             : };
      64             : 
      65             : typedef struct {
      66             :         CS_MSGNUM msgnumber;
      67             :         CS_INT state;
      68             :         CS_INT severity;
      69             :         CS_CHAR text[CS_MAX_MSG];
      70             :         CS_INT textlen;
      71             :         CS_CHAR svrname[132];
      72             :         CS_INT svrnlen;
      73             :         CS_CHAR proc[132];
      74             :         CS_INT proclen;
      75             :         CS_INT line;
      76             :         CS_INT status;
      77             :         CS_BYTE sqlstate[CS_SQLSTATE_SIZE];
      78             :         CS_INT sqlstatelen;
      79             : } CS_SERVERMSG_SMALL;
      80             : 
      81             : typedef struct {
      82             :         CS_MSGNUM msgnumber;
      83             :         CS_INT state;
      84             :         CS_INT severity;
      85             :         CS_CHAR text[CS_MAX_MSG];
      86             :         CS_INT textlen;
      87             :         CS_CHAR svrname[256];
      88             :         CS_INT svrnlen;
      89             :         CS_CHAR proc[256];
      90             :         CS_INT proclen;
      91             :         CS_INT line;
      92             :         CS_INT status;
      93             :         CS_BYTE sqlstate[CS_SQLSTATE_SIZE];
      94             :         CS_INT sqlstatelen;
      95             : } CS_SERVERMSG_LARGE;
      96             : 
      97             : typedef struct {
      98             :         CS_MSGNUM msgnumber;
      99             :         CS_INT state;
     100             :         CS_INT severity;
     101             :         CS_CHAR text[CS_MAX_MSG];
     102             :         CS_INT textlen;
     103             : } CS_SERVERMSG_COMMON1;
     104             : 
     105             : typedef struct {
     106             :         CS_INT line;
     107             :         CS_INT status;
     108             :         CS_BYTE sqlstate[CS_SQLSTATE_SIZE];
     109             :         CS_INT sqlstatelen;
     110             : } CS_SERVERMSG_COMMON2;
     111             : 
     112             : typedef union
     113             : {
     114             :         CS_SERVERMSG_SMALL small;
     115             :         CS_SERVERMSG_LARGE large;
     116             :         CS_SERVERMSG_COMMON1 common;
     117             :         CS_SERVERMSG user;
     118             : } CS_SERVERMSG_INTERNAL;
     119             : 
     120             : struct cs_diag_msg_svr
     121             : {
     122             :         struct cs_diag_msg_svr *next;
     123             :         CS_SERVERMSG_INTERNAL servermsg;
     124             : };
     125             : 
     126             : /* Code changes ends here - CT_DIAG - 01 */
     127             : 
     128             : struct cs_diag_msg
     129             : {
     130             :         CS_CLIENTMSG *msg;
     131             :         struct cs_diag_msg *next;
     132             : };
     133             : 
     134             : struct _cs_context
     135             : {
     136             :         CS_INT date_convert_fmt;
     137             :         CS_INT cs_errhandletype;
     138             :         CS_INT cs_diag_msglimit;
     139             : 
     140             :         /* added for storing the maximum messages limit CT_DIAG */
     141             :         /* code changes starts here - CT_DIAG - 02 */
     142             : 
     143             :         CS_INT cs_diag_msglimit_client;
     144             :         CS_INT cs_diag_msglimit_server;
     145             :         CS_INT cs_diag_msglimit_total;
     146             :         struct cs_diag_msg_client *clientstore;
     147             :         struct cs_diag_msg_svr *svrstore;
     148             : 
     149             :         /* code changes ends here - CT_DIAG - 02 */
     150             : 
     151             :         struct cs_diag_msg *msgstore;
     152             :         CS_CSLIBMSG_FUNC cslibmsg_cb;
     153             :         CS_CLIENTMSG_FUNC clientmsg_cb;
     154             :         CS_SERVERMSG_FUNC servermsg_cb;
     155             :         CS_INTERRUPT_FUNC interrupt_cb;
     156             :         /* code changes start here - CS_CONFIG - 01*/
     157             :         void *userdata;
     158             :         int userdata_len;
     159             :         /* code changes end here - CS_CONFIG - 01*/
     160             :         TDSCONTEXT *tds_ctx;
     161             :         CS_CONFIG config;
     162             :         int login_timeout;  /**< not used unless positive */
     163             :         int query_timeout;  /**< not used unless positive */
     164             : 
     165             :         /** structures uses large identifiers */
     166             :         bool use_large_identifiers;
     167             : 
     168             :         /** version passed to cs_ctx_alloc/ct_init (CS_VERSION_xxx) */
     169             :         CS_INT version;
     170             : };
     171             : 
     172             : static inline size_t cs_servermsg_len(CS_CONTEXT *ctx)
     173             : {
     174          60 :         if (ctx->use_large_identifiers)
     175             :                 return sizeof(CS_SERVERMSG_LARGE);
     176             :         return sizeof(CS_SERVERMSG_SMALL);
     177             : }
     178             : 
     179             : /*
     180             :  * internal typedefs
     181             :  */
     182             : typedef struct _ct_colinfo
     183             : {
     184             :         TDS_SMALLINT *indicator;
     185             : }
     186             : CT_COLINFO;
     187             : 
     188             : typedef struct _cs_dynamic CS_DYNAMIC;
     189             : 
     190             : struct _cs_connection
     191             : {
     192             :         CS_CONTEXT *ctx;
     193             :         TDSLOGIN *tds_login;
     194             :         TDSSOCKET *tds_socket;
     195             :         CS_CLIENTMSG_FUNC clientmsg_cb;
     196             :         CS_SERVERMSG_FUNC servermsg_cb;
     197             :         CS_INTERRUPT_FUNC interrupt_cb;
     198             :         void *userdata;
     199             :         int userdata_len;
     200             :         CS_LOCALE *locale;
     201             :         CS_COMMAND *cmds;
     202             :         CS_DYNAMIC *dynlist;
     203             :         char *server_addr;
     204             :         bool network_auth;
     205             : };
     206             : 
     207             : /*
     208             :  * Formerly CSREMOTE_PROC_PARAM, this structure can be used in other
     209             :  * places, too.
     210             :  */
     211             : 
     212             : typedef struct _cs_param
     213             : {
     214             :         struct _cs_param *next;
     215             :         char *name;
     216             :         int status;
     217             :         int datatype;
     218             :         CS_INT maxlen;
     219             :         CS_INT scale;
     220             :         CS_INT precision;
     221             :         CS_INT *datalen;
     222             :         CS_SMALLINT *ind;
     223             :         CS_BYTE *value;
     224             :         int param_by_value;
     225             :         CS_INT datalen_value;
     226             :         CS_SMALLINT indicator_value;
     227             : } CS_PARAM;
     228             : 
     229             : /*
     230             :  * Code added for RPC functionality - SUHA
     231             :  * RPC Code changes starts here
     232             :  */
     233             : 
     234             : typedef CS_PARAM CSREMOTE_PROC_PARAM;
     235             : 
     236             : typedef struct _csremote_proc
     237             : {
     238             :         char *name;
     239             :         CS_SMALLINT options;
     240             :         CSREMOTE_PROC_PARAM *param_list;
     241             : } CSREMOTE_PROC;
     242             : 
     243             : /*
     244             :  * Structure CS_COMMAND changed for RPC functionality -SUHA
     245             :  * Added CSREMOTE_PROC *rpc to CS_COMMAND structure
     246             :  */
     247             : 
     248             : typedef CS_PARAM CS_DYNAMIC_PARAM;
     249             : 
     250             : struct _cs_dynamic
     251             : {
     252             :         struct _cs_dynamic *next;
     253             :         char *id;
     254             :         char *stmt;
     255             :         CS_DYNAMIC_PARAM *param_list;
     256             :         TDSDYNAMIC *tdsdyn;
     257             : }; 
     258             : 
     259             : /* specific FreeTDS commands */
     260             : #define CS_DYNAMIC_CMD   160
     261             : #define CS_CUR_CMD       161
     262             : 
     263             : /* values for cs_command.results_state */
     264             : 
     265             : #define _CS_RES_NONE            -1
     266             : #define _CS_RES_INIT            0
     267             : #define _CS_RES_RESULTSET_EMPTY 1
     268             : #define _CS_RES_RESULTSET_ROWS  2
     269             : #define _CS_RES_STATUS          3
     270             : #define _CS_RES_CMD_DONE        4
     271             : #define _CS_RES_CMD_SUCCEED     5
     272             : #define _CS_RES_END_RESULTS     6
     273             : #define _CS_RES_DESCRIBE_RESULT 7
     274             : 
     275             : /* values for cs_command.command_state */
     276             : 
     277             : #define _CS_COMMAND_IDLE        0
     278             : #define _CS_COMMAND_BUILDING    1
     279             : #define _CS_COMMAND_READY       2
     280             : #define _CS_COMMAND_SENT        3
     281             : 
     282             : /* values for cs_command.cancel_state */
     283             : #define _CS_CANCEL_NOCANCEL     0
     284             : #define _CS_CANCEL_PENDING      1
     285             : 
     286             : struct _cs_command
     287             : {
     288             :         struct _cs_command *next;
     289             :         CS_INT command_state;
     290             :         CS_INT results_state;
     291             :         CS_INT cancel_state;
     292             :         CS_INT cursor_state;
     293             :         CS_CONNECTION *con;
     294             :         CS_INT command_type;
     295             :         CS_CHAR *query;
     296             :         short dynamic_cmd;
     297             :         CS_DYNAMIC *dyn;
     298             :         int row_prefetched;
     299             :         int curr_result_type;
     300             :         int bind_count;
     301             :         int get_data_item;
     302             :         int get_data_bytes_returned;
     303             :         CS_IODESC *iodesc;
     304             :         CS_INT send_data_started;
     305             :         CSREMOTE_PROC *rpc;
     306             :         CS_PARAM *input_params;
     307             :         CS_INT client_cursor_id;
     308             :         TDSCURSOR *cursor;
     309             :         void *userdata;
     310             :         int userdata_len;
     311             : };
     312             : 
     313             : struct _cs_blkdesc
     314             : {
     315             :         TDSBCPINFO bcpinfo;
     316             : };
     317             : 
     318             : 
     319             : #define _CS_ERRHAND_INLINE 1
     320             : #define _CS_ERRHAND_CB     2
     321             : 
     322             : struct _cs_locale
     323             : {
     324             :         char *language;
     325             :         char *charset;
     326             :         char *time;
     327             :         char *collate;
     328             : };
     329             : 
     330             : /* internal defines for cursor processing */
     331             : 
     332             : #define _CS_CURS_TYPE_UNACTIONED TDS_CURSOR_STATE_UNACTIONED
     333             : #define _CS_CURS_TYPE_REQUESTED  TDS_CURSOR_STATE_REQUESTED
     334             : #define _CS_CURS_TYPE_SENT       TDS_CURSOR_STATE_SENT
     335             : 
     336             : typedef struct {
     337             :         CS_CHAR name[132];
     338             :         CS_INT namelen;
     339             :         CS_INT datatype;
     340             :         CS_INT format;
     341             :         CS_INT maxlength;
     342             :         CS_INT scale;
     343             :         CS_INT precision;
     344             :         CS_INT status;
     345             :         CS_INT count;
     346             :         CS_INT usertype;
     347             :         CS_LOCALE *locale;
     348             : } CS_DATAFMT_SMALL;
     349             : 
     350             : typedef struct {
     351             :         CS_CHAR name[256];
     352             :         CS_INT namelen;
     353             :         CS_INT datatype;
     354             :         CS_INT format;
     355             :         CS_INT maxlength;
     356             :         CS_INT scale;
     357             :         CS_INT precision;
     358             :         CS_INT status;
     359             :         CS_INT count;
     360             :         CS_INT usertype;
     361             :         CS_LOCALE *locale;
     362             : } CS_DATAFMT_LARGE;
     363             : 
     364             : typedef struct {
     365             :         CS_INT datatype;
     366             :         CS_INT format;
     367             :         CS_INT maxlength;
     368             :         CS_INT scale;
     369             :         CS_INT precision;
     370             :         CS_INT status;
     371             :         CS_INT count;
     372             :         CS_INT usertype;
     373             :         CS_LOCALE *locale;
     374             : } CS_DATAFMT_COMMON;
     375             : 
     376             : typedef union
     377             : {
     378             :         CS_DATAFMT_SMALL small;
     379             :         CS_DATAFMT_LARGE large;
     380             :         CS_DATAFMT user;
     381             : } CS_DATAFMT_INTERNAL;
     382             : 
     383             : #if ENABLE_EXTRA_CHECKS
     384             : #define CS_QUERY_HAS_FOR_UPDATE 9500
     385             : #endif
     386             : 
     387             : /*
     388             :  * internal prototypes
     389             :  */
     390             : TDSRET _ct_handle_server_message(const TDSCONTEXT * ctxptr, TDSSOCKET * tdsptr, TDSMESSAGE * msgptr);
     391             : int _ct_handle_client_message(const TDSCONTEXT * ctxptr, TDSSOCKET * tdsptr, TDSMESSAGE * msgptr);
     392             : int _ct_handle_interrupt(void * ptr);
     393             : TDS_SERVER_TYPE _ct_get_server_type(TDSSOCKET *tds, int datatype);
     394             : int _ct_bind_data(CS_CONTEXT *ctx, TDSRESULTINFO * resinfo, TDSRESULTINFO *bindinfo, CS_INT offset);
     395             : int _ct_get_client_type(const TDSCOLUMN *col, bool describe);
     396             : void _ctclient_msg(CS_CONTEXT *ctx, CS_CONNECTION * con, const char *funcname,
     397             :                    int layer, int origin, int severity, int number,
     398             :                    const char *fmt, ...);
     399             : CS_INT _ct_diag_clearmsg(CS_CONTEXT * context, CS_INT type);
     400             : void _cs_locale_free(CS_LOCALE *locale);
     401             : CS_LOCALE *_cs_locale_copy(CS_LOCALE *orig);
     402             : int _cs_locale_copy_inplace(CS_LOCALE *new_locale, CS_LOCALE *orig);
     403             : CS_INT _ct_get_string_length(const char *buf, CS_INT buflen);
     404             : 
     405             : int _cs_convert_not_client(CS_CONTEXT *ctx, const TDSCOLUMN *curcol, CONV_RESULT *convert_buffer, unsigned char **p_src);
     406             : 
     407             : TDS_INT _cs_cs2tds(CS_CONTEXT * ctx, const CS_DATAFMT_COMMON * srcfmt, const void *srcdata, int desttype, CONV_RESULT * cres);
     408             : CS_RETCODE _cs_convert(CS_CONTEXT * ctx, const CS_DATAFMT_COMMON * srcfmt, CS_VOID * srcdata,
     409             :                        const CS_DATAFMT_COMMON * destfmt, CS_VOID * destdata, CS_INT * resultlen);
     410             : bool _ct_is_large_identifiers_version(CS_INT version);
     411             : const CS_DATAFMT_COMMON * _ct_datafmt_common(CS_CONTEXT * ctx, const CS_DATAFMT * datafmt);
     412             : const CS_DATAFMT_LARGE *_ct_datafmt_conv_in(CS_CONTEXT * ctx, const CS_DATAFMT * datafmt, CS_DATAFMT_LARGE * fmtbuf);
     413             : CS_DATAFMT_LARGE *_ct_datafmt_conv_prepare(CS_CONTEXT * ctx, CS_DATAFMT * datafmt, CS_DATAFMT_LARGE * fmtbuf);
     414             : void _ct_datafmt_conv_back(CS_DATAFMT * datafmt, CS_DATAFMT_LARGE * fmtbuf);
     415             : 
     416             : CS_RETCODE _ct_props_dstr(CS_CONNECTION * con, DSTR *s, CS_INT action, CS_VOID * buffer, CS_INT buflen, CS_INT * outlen);
     417             : 
     418             : #ifdef __cplusplus
     419             : #if 0
     420             : {
     421             : #endif
     422             : }
     423             : #endif
     424             : 
     425             : #include <freetds/popvis.h>
     426             : 
     427             : #endif

Generated by: LCOV version 1.13