File sk/cd_socket.c

  $Revision: 1.8 $

Socket module - cd_socket.c - basic read/write socket routines defined in terms of connection data structures with timeouts and storing information about broken connections.
Status: NOT REVUED, TESTED
Design and implementation by Marek Bukowy.

Included Files


Preprocessor definitions

#define SKBUFLEN 2047

Global Variable Lock

pthread_mutex_t Lock
Included from /home/shane/release/RIP/include/ca_defs.h
Visible in:  aa/aa.c
   ac/ac_persistence.c
   ac/access_control.c
   au/AU_util.c
   ca/ca_configFns.c
   ca/ca_initFn.c
   ca/ca_sanityCheck.c
   ca/ca_sourceLoader.c
   ca/ca_values.c
   co/constants.c
   df/defs.c
   er/er.c
   er/er_arrays.c
   er/er_macro.c
   er/er_paths.c
   er/er_print.c
   ip/ip.c
   ma/bitmask.c
   mm/mm.c
   nh/nh.c
   pa/gpg.c
   pa/spawn.c
   pc/pc_commands.c
   pc/protocol_config.c
   pm/pm_serials.c
   pm/protocol_mirror.c
   pr/properties.c
   pw/protocol_whois.c
   qc/mg_getopt.c
   qc/query_command.c
   qi/query_instructions.c
   rp/rp_convert.c
   rp/rp_load.c
   rp/rp_search.c
   rp/rp_tree.c
   rp/rp_update.c
   rx/rx_node.c
   rx/rx_print.c
   rx/rx_search.c
   rx/rx_tree.c
   sk/cd_socket.c
Used in: ca_get_adminIntElement()ca/ca_configFns.c
  ca_get_adminStrElement()ca/ca_configFns.c
  ca_get_boolean()ca/ca_configFns.c
  ca_get_dirlist()ca/ca_configFns.c
  ca_get_int()ca/ca_configFns.c
  ca_get_string()ca/ca_configFns.c
  ca_set_boolean()ca/ca_configFns.c
  ca_srchandle2Intelement()ca/ca_configFns.c
  ca_srchandle2Strelement()ca/ca_configFns.c

Global Function SK_cd_close()

  Wrapper around the close(2) system call, 

  Author:
        marek
int SK_cd_close ( sk_conn_st* condat )
int SK_cd_close
returns the error codes of close(2).
sk_conn_st* condat
Pointer to the connection data structure.
Prototyped in: /home/shane/release/RIP/include/sk.h
Calls: SK_close()

Global Function SK_cd_free()

  Destroys the data allocated and anchored by the connection data structure.
void SK_cd_free ( sk_conn_st* condat )
sk_conn_st* condat
Pointer to the connection data structure.
Prototyped in: /home/shane/release/RIP/include/sk.h
Calls: UT_free_real()
Called by: PW_interact()pw/protocol_whois.c

Global Function SK_cd_gets()

  Read from a socket, until a linefeed character is received or the buffer
  fills up to the maximum size "count". If the connection data has non-zero
  timeout value for reading, it is used here between calls to read 
  the next 1 character.

More: if the connection structure has bad status for this connection from previous calls, no read will be attempted.
  Author:
        marek

Side Effects: broken connections get registered in the connection structure.
int SK_cd_gets ( sk_conn_st* condat, char* str, size_t count )
int SK_cd_gets
Returns the total_count of bytes read, or inverted error codes (negative numbers): (- SK_DISCONNECT) on broken connection, (- SK_TIMEOUT) on timeout.
sk_conn_st* condat
connection data
char* str
The buffer to store the data received from the socket.
size_t count
size of the buffer.
Prototyped in: /home/shane/release/RIP/include/sk.h
Calls: sk_fill_rd_buf()sk/cd_socket.c
  fprintf(), memchr(), memcpy(), memmove()
Called by: PC_interact()pc/protocol_config.c
  PM_interact()pm/protocol_mirror.c
  PW_interact()pw/protocol_whois.c
  authenticate_user()pc/protocol_config.c

Global Function SK_cd_make()

  Construct a connection data given the socket or file descriptor.
  Also performs the getpeername check and stores the IP in an allocated
  string.
void SK_cd_make ( sk_conn_st* condat, int sock, unsigned timeout )
sk_conn_st* condat
pointer to where the data is to be stored.
int sock
The socket or file descriptor.
unsigned timeout
Read timeout (used in SK_cd_gets) in seconds. Value of 0 disables the timeout.
Prototyped in: /home/shane/release/RIP/include/sk.h
Calls: SK_getpeerip(), SK_getpeername(), fprintf(), memset()
Called by: PW_interact()pw/protocol_whois.c

Global Function SK_cd_printf()

  Printf-like function to print to socket/file specified by connection
  data structure. First writes the text to a temporary buffer, then
  uses SK_cd_puts to print it. Maintains a 2K static buffer, and allocates
  more memory if this is not enough.


  Author:
        marek
int SK_cd_printf ( sk_conn_st* condat, char* txt, ... )
int SK_cd_printf
Returns the SK_cd_puts error code/return value.
sk_conn_st* condat
Pointer to the connection data structure.
char* txt
Format text to be written
...
more arguments (like printf)
Prototyped in: /home/shane/release/RIP/include/sk.h
Calls: SK_cd_puts()sk/cd_socket.c
  UT_free_real(), UT_malloc_real(), __builtin_next_arg(), __builtin_saveregs(), vsnprintf()
Called by: PC_interact()pc/protocol_config.c
  QC_fill()qc/query_command.c
  er_macro_list_hook()er/er_macro.c
  process_input()pc/protocol_config.c
  qi_prep_run_refer()qi/query_instructions.c
  show_uptime()pc/pc_commands.c

Global Function SK_cd_puts()

   This function writes a character string out to a socket, unless 
   the connection is broken. 

char *str The buffer to be written to the socket.
More: if the connection structure has bad status for this connection from previous calls, no write will be attempted.

Side Effects: broken connections get registered in the connection structure
int SK_cd_puts ( sk_conn_st* condat, const char* str )
int SK_cd_puts
Returns the total_count of bytes written, or inverted error codes (negative numbers): (- SK_DISCONNECT) on broken connection, (- SK_INTERRUPT) on control-c received, (- SK_TIMEOUT) on timeout.
sk_conn_st* condat
Pointer to the connection data structure.
const char* str
 
Prototyped in: /home/shane/release/RIP/include/sk.h
Calls: SK_puts()
Called by: PC_interact()pc/protocol_config.c
  PM_interact()pm/protocol_mirror.c
  PW_interact()pw/protocol_whois.c
  PW_process_qc()pw/protocol_whois.c
  QC_fill()qc/query_command.c
  SK_cd_printf()sk/cd_socket.c
  __report_sql_error()qi/query_instructions.c
  authenticate_user()pc/protocol_config.c
  display_file()pw/protocol_whois.c
  process_input()pc/protocol_config.c
  qi_prep_run_refer()qi/query_instructions.c
  run_referral()qi/query_instructions.c
  rx_tree_print()rx/rx_print.c
  rx_walk_hook_printnode()rx/rx_print.c
  write_radix_immediate()qi/query_instructions.c
  write_results()qi/query_instructions.c

Local Function asctime_r()

static char* asctime_r ( const struct tm* __tm, char* __buf )
Included from: /usr/include/time.h
Calls: __posix_asctime_r()

Local Function ctime_r()

static char* ctime_r ( const time_t* __time, char* __buf )
Included from: /usr/include/time.h
Calls: __posix_ctime_r()

Local Function getlogin_r()

static int getlogin_r ( char* __name, int __len )
Included from: /usr/include/unistd.h
Calls: __posix_getlogin_r()

Local Function readdir_r()

static int readdir_r ( DIR* __dp, struct dirent* __ent, struct dirent** __res )
Included from: /usr/include/dirent.h
Calls: __posix_readdir_r()

Local Function sigwait()

static int sigwait ( const sigset_t* __setp, int* __signo )
Included from: /usr/include/signal.h
Calls: __posix_sigwait()

Local Function sk_fill_rd_buf()

static int sk_fill_rd_buf ( sk_conn_st* condat )
Calls: ER_perror()er/er.c
  ___errno(), memset(), read(), select(), strerror()
Called by: SK_cd_gets()sk/cd_socket.c

Local Function ttyname_r()

static int ttyname_r ( int __fildes, char* __buf, size_t __size )
Included from: /usr/include/unistd.h
Calls: __posix_ttyname_r()