Cross reference for sk/cd_socket.c of index.

# 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

- `#include ";/home/shane/release/RIP/include/rip.h";`
  - `#include </home/shane/release/RIP/include/config.h>`
  - `#include <sys/param.h>`
  - `#include <glib.h>`
  - `#include ";/home/shane/release/RIP/include/AU_util.h";`
    - `#include <stdio.h>`
    - `#include <stdlib.h>`
    - `#include <string.h>`
    - `#include <sys/types.h>`
    - `#include <unistd.h>`
    - `#include <regex.h>`
    - `#include <glib.h>`
  - `#include ";/home/shane/release/RIP/include/aa.h";`
    - `#include ";/home/shane/release/RIP/include/iproutines.h";`
      - `#include <sys/types.h>`
      - `#include <glib.h>`
      - `#include </home/shane/release/RIP/include/inet6def.h>`
      - `#include </home/shane/release/RIP/include/erroutines.h>`
  - `#include ";/home/shane/release/RIP/include/access_control.h";`
    - `#include ";/home/shane/release/RIP/include/timediff.h";`
      - `#include <sys/time.h>`
    - `#include ";/home/shane/release/RIP/include/erroutines.h";`
    - `#include ";/home/shane/release/RIP/include/iproutines.h";`
    - `#include ";/home/shane/release/RIP/include/rxroutines.h";`
      - `#include <glib.h>`
      - `#include <pthread.h>`
      - `#include <stubs.h>`
      - `#include </home/shane/release/RIP/include/memwrap.h>`
      - `#include <stdio.h>`
      - `#include <iproutines.h>`
      - `#include <erroutines.h>`
      - `#include ";/home/shane/release/RIP/include/sk.h";`
        - `#include ";/home/shane/release/RIP/include/stubs.h";`
        - `#include <sys/time.h>`
        - `#include <unistd.h>`
        - `#include <sys/types.h>`
        - `#include <sys/socket.h>`
        - `#include <netinet/in.h>`
        - `#include <netdb.h>`
        - `#include <pthread.h>`
        - `#include <stdlib.h>`
        - `#include <errno.h>`
        - `#include <fcntl.h>`
        - `#include <signal.h>`
        - `#include <stdio.h>`
        - `#include ";/home/shane/release/RIP/include/iproutines.h";`
      - `#include ";/home/shane/release/RIP/include/thread.h";`
    - `#include ";/home/shane/release/RIP/include/mysql_driver.h";`
      - `#include ";/usr/local/mysql/include/mysql/mysql.h";`
        - `#include <sys/types.h>`
        - `#include ";/usr/local/mysql/include/mysql/mysql_com.h";`
        - `#include ";/usr/local/mysql/include/mysql/mysql_version.h";`
      - `#include ";/usr/local/mysql/include/mysql/mysqld_error.h";`
      - `#include ";/home/shane/release/RIP/include/erroutines.h";`
  - `#include ";/home/shane/release/RIP/include/bitmask.h";`
  - `#include ";/home/shane/release/RIP/include/ca_adminAttribs.h";`
  - `#include ";/home/shane/release/RIP/include/ca_configFns.h";`
    - `#include ";/home/shane/release/RIP/include/ca_defs.h";`
      - `#include <pthread.h>`
      - `#include <glib.h>`
    - `#include <memwrap.h>`
    - `#include <erroutines.h>`
  - `#include ";/home/shane/release/RIP/include/ca_defs.h";`
  - `#include ";/home/shane/release/RIP/include/ca_dictionary.h";`
  - `#include ";/home/shane/release/RIP/include/ca_macros.h";`
    - `#include ";/home/shane/release/RIP/include/ca_adminAttribs.h";`
  - `#include ";/home/shane/release/RIP/include/ca_srcAttribs.h";`
  - `#include ";/home/shane/release/RIP/include/comparisons.h";`
  - `#include ";/home/shane/release/RIP/include/constants.h";`
    - `#include <glib.h>`
  - `#include ";/home/shane/release/RIP/include/defs.h";`
    - `#include <glib.h>`
    - `#include ";/home/shane/release/RIP/include/bitmask.h";`
    - `#include ";/home/shane/release/RIP/include/DF_class_enum.def";`
    - `#include ";/home/shane/release/RIP/include/DF_class_mask.def";`
    - `#include ";/home/shane/release/RIP/include/DF_attribute_enum.def";`
    - `#include ";/home/shane/release/RIP/include/DF_attribute_inv_attr_mask.def";`
    - `#include ";/home/shane/release/RIP/include/which_keytypes.h";`
      - `#include ";/home/shane/release/RIP/include/bitmask.h";`
    - `#include ";/home/shane/release/RIP/include/iproutines.h";`
    - `#include ";/home/shane/release/RIP/include/rxroutines.h";`
  - `#include ";/home/shane/release/RIP/include/er_arrays.h";`
    - `#include ";/home/shane/release/RIP/include/erroutines.h";`
  - `#include ";/home/shane/release/RIP/include/er_aspects.h";`
  - `#include ";/home/shane/release/RIP/include/er_facilities.h";`
  - `#include ";/home/shane/release/RIP/include/er_formats.h";`
  - `#include ";/home/shane/release/RIP/include/er_macro.h";`
    - `#include ";/home/shane/release/RIP/include/sk.h";`
  - `#include ";/home/shane/release/RIP/include/er_paths.h";`
    - `#include <sys/param.h>`
    - `#include <glib.h>`
  - `#include ";/home/shane/release/RIP/include/er_yacc_helper.h";`
  - `#include ";/home/shane/release/RIP/include/erroutines.h";`
  - `#include ";/home/shane/release/RIP/include/fdwrap.h";`
    - `#include <stdio.h>`
  - `#include ";/home/shane/release/RIP/include/mg_getopt.h";`
  - `#include ";/home/shane/release/RIP/include/globaldefs.h";`
  - `#include ";/home/shane/release/RIP/include/gpg.h";`
    - `#include <netdb.h>`
    - `#include <unistd.h>`
    - `#include ";/home/shane/release/RIP/include/mail_parser.h";`
      - `#include ";/home/shane/release/RIP/include/gpg.h";`
      - `#include ";/home/shane/release/RIP/include/memwrap.h";`
  - `#include ";/home/shane/release/RIP/include/inet6def.h";`
  - `#include ";/home/shane/release/RIP/include/iproutines.h";`
  - `#include ";/home/shane/release/RIP/include/mail_parser.h";`
  - `#include ";/home/shane/release/RIP/include/memwrap.h";`
  - `#include ";/home/shane/release/RIP/include/mm.h";`
    - `#include ";/home/dbase/src/orange/imap-2001a/c-client/mail.h";`
      - `#include ";/home/dbase/src/orange/imap-2001a/c-client/linkage.h";`
    - `#include ";/home/dbase/src/orange/imap-2001a/c-client/osdep.h";`
      - `#include <string.h>`
      - `#include <sys/types.h>`
      - `#include <stdlib.h>`
      - `#include <dirent.h>`
      - `#include <fcntl.h>`
      - `#include <unistd.h>`
      - `#include <time.h>`
      - `#include <utime.h>`
      - `#include <syslog.h>`
      - `#include <sys/file.h>`
      - `#include <ustat.h>`
      - `#include ";/home/dbase/src/orange/imap-2001a/c-client/env_unix.h";`
        - `#include ";/home/dbase/src/orange/imap-2001a/c-client/env.h";`
      - `#include ";/home/dbase/src/orange/imap-2001a/c-client/fs.h";`
      - `#include ";/home/dbase/src/orange/imap-2001a/c-client/ftl.h";`
      - `#include ";/home/dbase/src/orange/imap-2001a/c-client/nl.h";`
      - `#include ";/home/dbase/src/orange/imap-2001a/c-client/tcp.h";`
      - `#include ";/home/dbase/src/orange/imap-2001a/c-client/flocksim.h";`
    - `#include ";/home/shane/release/RIP/include/gpg.h";`
    - `#include ";/home/shane/release/RIP/include/mail_parser.h";`
    - `#include ";/home/shane/release/RIP/include/memwrap.h";`
    - `#include ";/usr/local/include/glib-1.2/glib.h";`
  - `#include ";/home/shane/release/RIP/include/mysql_driver.h";`
  - `#include ";/home/shane/release/RIP/include/nh.h";`
    - `#include <mysql_driver.h>`
  - `#include ";/home/shane/release/RIP/include/notification.h";`
    - `#include <stdarg.h>`
    - `#include <stdio.h>`
    - `#include <strings.h>`
    - `#include <unistd.h>`
    - `#include <stdlib.h>`
    - `#include <time.h>`
    - `#include <glib.h>`
    - `#include ";/home/shane/release/RIP/include/UP_util.h";`
      - `#include ";/home/shane/release/RIP/include/syntax_api.h";`
  - `#include ";/home/shane/release/RIP/include/numconv.h";`
  - `#include ";/home/shane/release/RIP/include/pc_commands.h";`
  - `#include ";/home/shane/release/RIP/include/properties.h";`
  - `#include ";/home/shane/release/RIP/include/protocol_config.h";`
  - `#include ";/home/shane/release/RIP/include/protocol_mirror.h";`
    - `#include <glib.h>`
    - `#include ";/home/shane/release/RIP/include/mysql_driver.h";`
    - `#include ";/home/shane/release/RIP/include/iproutines.h";`
    - `#include ";/home/shane/release/RIP/include/aa.h";`
      - `#include ";/home/shane/release/RIP/include/iproutines.h";`
  - `#include ";/home/shane/release/RIP/include/protocol_whois.h";`
    - `#include ";/home/shane/release/RIP/include/query_command.h";`
      - `#include <glib.h>`
      - `#include ";/home/shane/release/RIP/include/bitmask.h";`
      - `#include ";/home/shane/release/RIP/include/sk.h";`
  - `#include ";/home/shane/release/RIP/include/query_command.h";`
  - `#include ";/home/shane/release/RIP/include/query_instructions.h";`
    - `#include ";/home/shane/release/RIP/include/rxroutines.h";`
    - `#include ";/home/shane/release/RIP/include/iproutines.h";`
    - `#include ";/home/shane/release/RIP/include/mysql_driver.h";`
    - `#include ";/home/shane/release/RIP/include/query_command.h";`
    - `#include ";/home/shane/release/RIP/include/defs.h";`
    - `#include ";/home/shane/release/RIP/include/which_keytypes.h";`
    - `#include ";/home/shane/release/RIP/include/access_control.h";`
    - `#include ";/home/shane/release/RIP/include/ca_configFns.h";`
    - `#include ";/home/shane/release/RIP/include/ca_dictionary.h";`
    - `#include ";/home/shane/release/RIP/include/ca_macros.h";`
    - `#include ";/home/shane/release/RIP/include/ca_srcAttribs.h";`
  - `#include ";/home/shane/release/RIP/include/rp.h";`
    - `#include <stddef.h>`
    - `#include <glib.h>`
    - `#include <pthread.h>`
    - `#include <defs.h>`
    - `#include <iproutines.h>`
    - `#include <erroutines.h>`
    - `#include <rxroutines.h>`
    - `#include <mysql_driver.h>`
    - `#include ";/home/shane/release/RIP/include/ca_defs.h";`
    - `#include <thread.h>`
  - `#include ";/home/shane/release/RIP/include/rxroutines.h";`
  - `#include ";/home/shane/release/RIP/include/server.h";`
  - `#include ";/home/shane/release/RIP/include/sk.h";`
  - `#include ";/home/shane/release/RIP/include/stubs.h";`
  - `#include ";/home/shane/release/RIP/include/syntax_api.h";`
  - `#include ";/home/shane/release/RIP/include/ta.h";`
    - `#include <glib.h>`
    - `#include <pthread.h>`
    - `#include <stdio.h>`
    - `#include ";/home/shane/release/RIP/include/stubs.h";`
    - `#include ";/home/shane/release/RIP/include/memwrap.h";`
    - `#include ";/home/shane/release/RIP/include/sk.h";`
    - `#include ";/home/shane/release/RIP/include/timediff.h";`
  - `#include ";/home/shane/release/RIP/include/thread.h";`
  - `#include ";/home/shane/release/RIP/include/timediff.h";`
  - `#include ";/home/shane/release/RIP/include/ud.h";`
  - `#include ";/home/shane/release/RIP/include/ud_int.h";`
    - `#include <stdio.h>`
    - `#include <strings.h>`
    - `#include <glib.h>`
    - `#include <stdlib.h>`
    - `#include <ctype.h>`
    - `#include <unistd.h>`
    - `#include ";/home/shane/release/RIP/include/defs.h";`
    - `#include ";/home/shane/release/RIP/include/mysql_driver.h";`
    - `#include ";/home/shane/release/RIP/include/iproutines.h";`
    - `#include ";/home/shane/release/RIP/include/erroutines.h";`
    - `#include ";/home/shane/release/RIP/include/rp.h";`
    - `#include ";/home/shane/release/RIP/include/nh.h";`
    - `#include ";/home/shane/release/RIP/include/sk.h";`
    - `#include ";/home/shane/release/RIP/include/memwrap.h";`
    - `#include ";/home/shane/release/RIP/include/ca_configFns.h";`
    - `#include ";/home/shane/release/RIP/include/ca_dictionary.h";`
    - `#include ";/home/shane/release/RIP/include/ca_macros.h";`
    - `#include ";/home/shane/release/RIP/include/ca_srcAttribs.h";`
    - `#include ";/home/shane/release/RIP/include/globaldefs.h";`
    - `#include ";/home/shane/release/RIP/include/bitmask.h";`
    - `#include ";/home/shane/release/RIP/include/which_keytypes.h";`
  - `#include ";/home/shane/release/RIP/include/ud_tr.h";`
    - `#include ";/home/shane/release/RIP/include/ud_int.h";`
  - `#include ";/home/shane/release/RIP/include/ut_string.h";`
  - `#include ";/home/shane/release/RIP/include/wh_queries.h";`
    - `#include ";/home/shane/release/RIP/include/sk.h";`
  - `#include ";/home/shane/release/RIP/include/which_keytypes.h";`

## 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()