File modules/qi/query_instructions.c

  $Revision: 1.37 $


Sql module (sq). This is a mysql implementation of an sql module.
Status: NOT REVUED, NOT TESTED
Note: this code has been heavily coupled to MySQL, and may need to be changed (to improve performance) if a new RDBMS is used.

Included Files


Preprocessor definitions

String sizes

#define STR_S 63

#define STR_M 255

#define STR_L 1023

#define STR_XL 4095

#define STR_XXL 16383

Execute the query instructions. This is called by a g_list_foreach function, so each of the sources in the "database source" list can be passed into this function.
This function has bloated itself. Can we split it up Marek? (ottrey 13/12/99)
void *database_voidptr Pointer to the database.
void *qis_voidptr Pointer to the query_instructions.
More:

  Authors:
        ottrey
Online References:

#define RIPE_REG 17


Global Function QI_execute()

  Execute the query instructions.  This is called by a g_list_foreach
  function, so each of the sources in the "database source" list can be passed
  into this function.

This function has bloated itself. Can we split it up Marek? (ottrey 13/12/99)
void *qis_voidptr Pointer to the query_instructions.
More:
  Authors:
        ottrey
Online References:
    <LI><A HREF="http://www.gtk.org/rdp/glib/glib-singly-linked-lists.html#G-SLIST-FOREACH">g_list_foreach</A>
void QI_execute ( void* database_voidptr, Query_instructions* qis, Query_environ* qe, acc_st* acc_credit, acl_st* acl )
void* database_voidptr
Pointer to the database.
Query_instructions* qis
&nbs;
Query_environ* qe
&nbs;
acc_st* acc_credit
&nbs;
acl_st* acl
&nbs;
Prototyped in: modules/qi/query_instructions.h
Calls: CO_get_database_port()modules/co/constants.c
  CO_get_host()modules/co/constants.c
  CO_get_password()modules/co/constants.c
  CO_get_user()modules/co/constants.c
  ER_dbg_va()modules/er/er.c
  ER_is_traced()modules/er/er.c
  add_ref_name()modules/qi/query_instructions.c
  insert_radix_serials()modules/qi/query_instructions.c
  run_referral()modules/qi/query_instructions.c
  write_objects()modules/qi/query_instructions.c
  write_radix_immediate()modules/qi/query_instructions.c
  RP_asc_search(), SK_cd_puts(), SQ_close_connection(), SQ_execute_query(), SQ_free_result(), SQ_get_affected_rows(), SQ_get_column_string(), SQ_get_connection(), SQ_row_next(), atoi(), fprintf(), g_list_length(), sprintf(), sscanf(), strcat(), wr_real_free()
Called by: PW_interact()modules/pw/protocol_whois.c
References Variables: Querymodules/df/defs.c

Global Function QI_free()

  Free the query_instructions.

XXX This isn't working too well at the moment.
More:
  Authors:
        ottrey
Online References:
void QI_free ( Query_instructions* qis )
Query_instructions* qis
Query_instructions to be freed.
Prototyped in: modules/qi/query_instructions.h
Calls: instruction_free()modules/qi/query_instructions.c
  wr_real_free()
Called by: PW_interact()modules/pw/protocol_whois.c

Global Function QI_new()

  Create a new set of query_instructions.
Query_instructions* QI_new ( const Query_command* qc, const Query_environ* qe )
const Query_command* qc
The query_command that the instructions are created from.
const Query_environ* qe
The environmental variables that they query is being performed under. More:
  Authors:
        ottrey
Online References:
Prototyped in: modules/qi/query_instructions.h
Calls: ER_dbg_va()modules/er/er.c
  QI_queries_to_string()modules/qi/query_instructions.c
  create_query()modules/qi/query_instructions.c
  map_qc2rx()modules/qi/query_instructions.c
  valid_query()modules/qi/query_instructions.c
  fprintf(), wr_real_calloc(), wr_real_free()
Called by: PW_interact()modules/pw/protocol_whois.c
References Variables: Querymodules/df/defs.c

Global Function QI_queries_to_string()

char* QI_queries_to_string ( Query_instructions* qis )
Prototyped in: modules/qi/query_instructions.h
Calls: fprintf(), strcat(), strcpy(), strlen(), wr_real_realloc()
Called by: QI_new()modules/qi/query_instructions.c
References Variables: Querymodules/df/defs.c

Global Function fast_output()

  This is for the '-F' flag.
  It assumes lines starting with ' ', '\t' or '+' belong to the prior attribute.

Fast isn't fast anymore - it's just there for compatibility reasons. This could be speed up if there were breaks out of the loops, once it matched something. (Wanna add a goto Marek? :-) ).
More:
  Authors:
        ottrey
Online References:
char* fast_output ( const char* str )
const char* str
ng The string to be "fast outputed".
Calls: DF_get_attribute_code()modules/df/defs.c
  DF_get_attribute_names()modules/df/defs.c
  fprintf(), g_strsplit(), sprintf(), strcat(), strchr(), strcpy(), strlen(), strncmp(), wr_real_malloc()
Called by: write_results()modules/qi/query_instructions.c

Global Function filter()

  Basically it's for the '-K' flag for non-set (and non-radix) objects.
  It assumes lines starting with ' ', '\t' or '+' belong to the prior attribute.

This could be speed up if there were breaks out of the loops, once it matched something. (Wanna add a goto Marek? :-) ).
More:
  Authors:
        ottrey
Online References:
char* filter ( const char* str )
const char* str
ng The string to be filtered.
Calls: DF_get_filter_names()modules/df/defs.c
  fprintf(), g_strsplit(), sprintf(), strcat(), strcpy(), strlen(), strncmp(), wr_real_malloc()
Called by: write_results()modules/qi/query_instructions.c

Global Function run_referral()

void run_referral ( MYSQL* sql_connection, Query_instructions* qis, Query_environ* qe, int qi_index )
Calls: ER_dbg_va()modules/er/er.c
  SK_cd_puts(), SQ_execute_query(), SQ_free_result(), SQ_get_column_string(), SQ_num_rows(), SQ_row_next(), WH_sock(), __eprintf(), fprintf(), index(), snprintf(), sprintf(), sscanf(), strcat(), strcmp(), strcpy(), strlen()
Called by: QI_execute()modules/qi/query_instructions.c
References Variables: Querymodules/df/defs.c

Local Function add_filter()

static void add_filter ( char* query_str, const Query_command* qc )
Calls: MA_bitcount()modules/ma/bitmask.c
  MA_isset()modules/ma/bitmask.c
  sprintf(), strcat(), strcpy(), strlen()
Called by: create_query()modules/qi/query_instructions.c

Local Function add_ref_name()

static void add_ref_name ( MYSQL* sql_connection, char* rectable, char* allnames )
Calls: create_name_query()modules/qi/query_instructions.c
  SQ_execute_query(), fprintf(), sprintf(), strlen()
Called by: QI_execute()modules/qi/query_instructions.c

Local Function create_name_query()

  Create an sql query for the names table. 

More:
  Authors:
  ottrey
Online References:
static void create_name_query ( char* query_str, const char* sql_query, const char* keys )
Calls: g_strfreev(), g_string_free(), g_string_sized_new(), g_string_sprintfa(), g_strsplit(), sprintf()
Called by: add_ref_name()modules/qi/query_instructions.c
  create_query()modules/qi/query_instructions.c

Local Function create_query()

  Create an sql query from the query_command and the matching keytype and the
  selected inverse attributes.
  Note this clears the first inv_attribute it sees, so is called sequentially
  until there are no inv_attributes left.

WK_Type keytype The matching keytype.
mask_t *inv_attrs_bitmap The selected inverse attributes.
More:
  Authors:
        ottrey
Online References:
static char* create_query ( const Query_t q, const Query_command* qc )
const Query_t q
&nbs;
const Query_command* qc
The query command.
Calls: IP_rang_b2_space()modules/ip/ip.c
  IP_rang_b2v4()modules/ip/ip.c
  IP_smart_range()modules/ip/ip.c
  MA_bitcount()modules/ma/bitmask.c
  NOERR()modules/er/er.c
  add_filter()modules/qi/query_instructions.c
  create_name_query()modules/qi/query_instructions.c
  fprintf(), sprintf(), strcpy(), strlen(), wr_real_malloc()
Called by: QI_new()modules/qi/query_instructions.c

Local Function insert_radix_serials()

  Insert the radix serial numbers into a temporary table in the database.

mask_t bitmap The bitmap of attribute to be converted.
SQ_connection_t *sql_connection The connection to the database.
XXX Hmmmmm this isn't really a good place to free things... infact it's quite nasty. :-(
More:
  Authors:
        ottrey
Online References:
    <LI><A HREF="http://www.gtk.org/rdp/glib/glib-doubly-linked-lists.html">Glist</A>
static void insert_radix_serials ( MYSQL* sql_connection, char* id_table, GList* datlist )
MYSQL* sql_connection
&nbs;
char* id_table
The id of the temporary table (This is a result of the hacky way we've tried to get MySQL to do sub-selects.)
GList* datlist
The list of data from the radix tree.
Calls: SQ_execute_query(), fprintf(), g_list_first(), sprintf(), wr_real_clear_list(), wr_real_free()
Called by: QI_execute()modules/qi/query_instructions.c

Local Function instruction_free()

  Free the instruction.

More:
  Authors:
        ottrey
Online References:
static void instruction_free ( Query_instruction* qi )
Query_instruction* qi
query_instruction to be freed.
Calls: wr_real_free()
Called by: QI_free()modules/qi/query_instructions.c

Local Function map_qc2rx()

  The mapping between a query_command and a radix query.

More:
  Authors:
        ottrey
Online References:
static int map_qc2rx ( Query_instruction* qi, const Query_command* qc )
Query_instruction* qi
The Query Instruction to be created from the mapping of the query command.
const Query_command* qc
The query command to be mapped.
Calls: ER_dbg_va()modules/er/er.c
Called by: QI_new()modules/qi/query_instructions.c

Local Function valid_query()

  Determine if this query should be conducted or not.

If it was an inverse query - it the attribute appears in the query command's bitmap. If it was a lookup query - if the attribute appears in the object type bitmap or disregard if there is no object_type bitmap (Ie object filter).
mask_t bitmap The bitmap of attribute to be converted.
static int valid_query ( const Query_command* qc, const Query_t q )
const Query_command* qc
The query_command that the instructions are created from.
const Query_t q
The query being investigated.
Calls: MA_bitcount()modules/ma/bitmask.c
  MA_isset()modules/ma/bitmask.c
  fprintf()
Called by: QI_new()modules/qi/query_instructions.c

Local Function write_objects()

  This is linked into MySQL by the fact that MySQL doesn't have sub selects
  (yet).  The queries are done in two stages.  Make some temporary tables and
  insert into them.  Then use them in the next select.

SQ_connection_t *sql_connection The connection to the database.
More:
  Authors:
        ottrey
static void write_objects ( MYSQL* sql_connection, char* id_table, unsigned int filtered, unsigned int fast, sk_conn_st* condat, acc_st* acc_credit, acl_st* acl )
MYSQL* sql_connection
&nbs;
char* id_table
The id of the temporary table (This is a result of the hacky way we've tried to get MySQL to do sub-selects.)
unsigned int filtered
&nbs;
unsigned int fast
&nbs;
sk_conn_st* condat
Connection data for the client
acc_st* acc_credit
&nbs;
acl_st* acl
&nbs;
Calls: write_results()modules/qi/query_instructions.c
  SQ_execute_query(), SQ_free_result(), fprintf(), sprintf()
Called by: QI_execute()modules/qi/query_instructions.c

Local Function write_radix_immediate()

  Display the immediate data carried with the objects returned by the
  radix tree.

More:
  Authors:
        marek
Online References:


Also free the list of answers.
static void write_radix_immediate ( GList* datlist, sk_conn_st* condat, acc_st* acc_credit )
GList* datlist
The linked list of dataleaf copies sk_conn_st *condat Connection data for the client acc_st *acc_credit Accounting struct
sk_conn_st* condat
&nbs;
acc_st* acc_credit
&nbs;
Calls: SK_cd_puts(), g_list_first(), wr_real_clear_list(), wr_real_free()
Called by: QI_execute()modules/qi/query_instructions.c

Local Function write_results()

  Write the results to the client socket.

SQ_result_set_t *result The result set returned from the sql query. unsigned filtered if the objects should go through a filter (-K) sk_conn_st *condat Connection data for the client int maxobjects max # of objects to write
XXX NB. this is very dependendant on what rows are returned in the result!!!
More:
  Authors:
        ottrey
Online References:
static int write_results ( MYSQL_RES* result, unsigned filtered, unsigned fast, sk_conn_st* condat, acc_st* acc_credit, acl_st* acl )
Calls: ER_dbg_va()modules/er/er.c
  fast_output()modules/qi/query_instructions.c
  filter()modules/qi/query_instructions.c
  SK_cd_puts(), SQ_get_column_string(), SQ_row_next(), atoi(), fprintf(), wr_real_free()
Called by: write_objects()modules/qi/query_instructions.c