CWB
Typedefs | Functions | Variables

server.h File Reference

#include "../cl/cl.h"
#include "../cqp/corpmanag.h"

Typedefs

Functions

Variables


Typedef Documentation

typedef unsigned char cqi_byte

Function Documentation

int accept_connection ( int  port)

Wait for, and then process, an attempt by a client to initiate a connection to cqpserver via TCP/IP.

Note that this function may or may not fork the cqpserver process.

If forking happens, then the child handles the connection, whereas the parent carries on waiting for further connections.

On Windows, forking never happens (since Windows doesn't support it).

On *nix, forking happens UNLESS the global private_server is true. (Actually, if private_server is true, then forking still happens, but the parent process immeidately exits.)

TODO: a better name would be server_accept_connection or somesuch...

Parameters:
portThe integer identifier of the port to listen on.
Returns:
A > 0 value (actually the socket ID of the incoming connection) if all is OK; otherwise -1.

References ATTHASHSIZE, check_host(), client_addr, conn_out, connfd, CQI_PORT, localhost, make_attribute_hash(), private_server, remote_address, remote_host, server_debug, server_log, server_quit, and sockfd.

Referenced by main().

int check_attribute_name ( char *  name)
int check_corpus_name ( char *  name)
int check_subcorpus_name ( char *  name)
char* combine_subcorpus_spec ( char *  corpus_name,
char *  subcorpus_name 
)

References cl_malloc(), and cl_strdup().

Referenced by do_cqi_cqp_query().

int cqi_activate_corpus ( char *  name)

Activates the named corpus.

References cqi_find_corpus(), server_debug, and set_current_corpus().

Referenced by do_cqi_cqp_query().

void cqi_command ( int  command)
void cqi_data_bool ( int  n)
void cqi_data_bool_list ( cqi_byte list,
int  l 
)

Sends a list of booleans to the client.

Parameters:
listpointer to a block of booleans (each occupying one byte) to send.
lthe number of bytes to send.

References CQI_DATA_BOOL_LIST, cqi_flush(), cqi_send_byte_list(), cqi_send_error(), and cqi_send_word().

void cqi_data_byte ( int  n)

Sends a byte of data to the client.

References CQI_DATA_BYTE, cqi_flush(), cqi_send_byte(), cqi_send_error(), and cqi_send_word().

void cqi_data_byte_list ( cqi_byte list,
int  l 
)

Sends a byte list to the client.

Parameters:
listpointer to a block of bytes to send.
lthe number of bytes to send.

References CQI_DATA_BYTE_LIST, cqi_flush(), cqi_send_byte_list(), cqi_send_error(), and cqi_send_word().

void cqi_data_int ( int  n)
void cqi_data_int_int ( int  n1,
int  n2 
)

Sends a sequence of two integers to the client.

Parameters:
n1The first integer sent
n2The second integer sent

References CQI_DATA_INT_INT, cqi_flush(), cqi_send_error(), cqi_send_int(), and cqi_send_word().

Referenced by do_cqi_cl_struc2cpos().

void cqi_data_int_int_int_int ( int  n1,
int  n2,
int  n3,
int  n4 
)

Sends a sequence of four integers to the client.

Parameters:
n1The first integer sent
n2The second integer sent
n3The third integer sent
n4The fourth integer sent

References CQI_DATA_INT_INT_INT_INT, cqi_flush(), cqi_send_error(), cqi_send_int(), and cqi_send_word().

Referenced by do_cqi_cl_alg2cpos().

void cqi_data_int_list ( int *  list,
int  l 
)

Sends a list of integers to the client.

Parameters:
listpointer to a block of integers to send.
lthe number of integers to send.

References CQI_DATA_INT_LIST, cqi_flush(), cqi_send_error(), cqi_send_int_list(), and cqi_send_word().

Referenced by do_cqi_cl_id2cpos(), do_cqi_cl_idlist2cpos(), and do_cqi_cl_regex2id().

void cqi_data_string ( char *  str)
void cqi_data_string_list ( char **  list,
int  l 
)

Sends a list of strings to the client.

Parameters:
listpointer to a block of pointers-to-strings; the strings will be sent.
lthe number of strings to send.

References CQI_DATA_STRING_LIST, cqi_flush(), cqi_send_error(), cqi_send_string_list(), and cqi_send_word().

Referenced by do_cqi_corpus_properties().

int cqi_drop_attribute ( char *  name)

Drops the named attribute from memory.

The attribute name is looked up in the global hash, and then cl_delete_attribute() is called on the result.

See also:
cl_delete_attribute
Parameters:
nameName of the attribute to be deleted
Returns:
Boolean: true for all OK, otherwise false

References att_hash_lookup(), ATT_NONE, att_bucket::attribute, cl_delete_attribute(), and att_bucket::type.

CorpusList* cqi_find_corpus ( char *  name)
int cqi_flush ( void  )
void cqi_general_error ( char *  errstring)

General error reporting function.

Note that unlike other CQi error functions, this function sends an error message to the outgoing connection, rather than printing to the server's STDERR. Also note that the program doesn't exit!

The error message is placed into the global variable cqi_error_string, whence it can be accessed by the client if the CQI_CTRL_LAST_GENERAL_ERROR is sent to the server.

TODO a better name would be cqi_error_general

Parameters:
errstringString containing the error message.

References cqi_command(), CQI_ERROR_GENERAL_ERROR, cqi_error_string, cqi_internal_error(), and GENERAL_ERROR_SIZE.

Referenced by do_cqi_cl_drop_attribute(), and do_cqi_corpus_attributes().

Attribute* cqi_lookup_attribute ( char *  name,
int  type 
)
int cqi_read_bool ( void  )
int cqi_read_bool_list ( cqi_byte **  list)
int cqi_read_byte ( void  )
int cqi_read_byte_list ( cqi_byte **  list)
int cqi_read_command ( void  )

References CQI_PAD, cqi_read_byte(), and server_debug.

Referenced by interpreter(), and main().

int cqi_read_int ( void  )
int cqi_read_int_list ( int **  list)
char* cqi_read_string ( void  )
int cqi_read_string_list ( char ***  list)
int cqi_read_word ( void  )

References cqi_read_byte(), and snoop.

Referenced by cqi_read_string().

int cqi_recv_byte ( void  )

References connfd, MSG_WAITALL, and snoop.

Referenced by cqi_read_bool(), and cqi_read_byte().

int cqi_recv_bytes ( cqi_byte buf,
int  n 
)

References connfd, MSG_WAITALL, and snoop.

Referenced by cqi_read_string().

int cqi_send_byte ( int  n,
int  nosnoop 
)

Sends a BYTE to the client.

This function should be called via one of the cqi_data_* functions and not on its own.

This is the fundamental "sending" function, and the only one that calls the underlying OS-specific file stream/socket functions.

Parameters:
nThe byte to send. NOTE that as the parameter is an int, numbers bigger than 0xff can be passed. BUT all content except the lowest-order 8-bits are discarded (0xff is used as a mask with bitwise-and).
nosnoopBoolean: if true, snoop functionality is overridden (to allow for non-repetition of messages when called from a function that has already printed a message)

References conn_out, connfd, MSG_WAITALL, and snoop.

Referenced by cqi_data_bool(), cqi_data_byte(), cqi_send_byte_list(), cqi_send_int(), cqi_send_string(), and cqi_send_word().

int cqi_send_byte_list ( cqi_byte list,
int  l 
)

Sends a BYTE[] (byte list) to the client.

This function should be called via one of the cqi_data_* functions and not on its own.

Parameters:
listpointer to a block of bytes to send.
lthe number of bytes to send.
Returns:
Boolean: true if everything OK, otherwise false.

References cqi_send_byte(), and cqi_send_int().

Referenced by cqi_data_bool_list(), and cqi_data_byte_list().

int cqi_send_int ( int  n)
int cqi_send_int_list ( int *  list,
int  l 
)

Sends an INT[] (integer list) to the client.

This function should be called via one of the cqi_data_* functions and not on its own.

Parameters:
listpointer to a block of integers to send.
lthe number of integers to send.
Returns:
Boolean: true if everything OK, otherwise false.

References cqi_send_int().

Referenced by cqi_data_int_list().

int cqi_send_string ( char *  str)

Sends a STRING to the client.

CQi strings are NOT null-terminated -- so while the argument to this function needs to be a null-terminated string, the string that actually gets sent across the network will not be.

This function should be called via one of the cqi_data_* functions and not on its own.

Returns:
Boolean: true if everything OK, otherwise false.

References cqi_send_byte(), cqi_send_word(), and snoop.

Referenced by cqi_data_string(), cqi_send_string_list(), do_cqi_cl_cpos2str(), do_cqi_cl_id2str(), do_cqi_cl_struc2str(), do_cqi_corpus_list_corpora(), do_cqi_cqp_list_subcorpora(), and send_cqi_corpus_attributes().

int cqi_send_string_list ( char **  list,
int  l 
)

Sends a STRING[] (string list) to the client.

This function should be called via one of the cqi_data_* functions and not on its own.

Parameters:
listpointer to a block of pointers-to-strings; the strings will be sent.
lthe number of strings to send.

References cqi_send_int(), and cqi_send_string().

Referenced by cqi_data_string_list().

int cqi_send_word ( int  n)
void free_attribute_hash ( void  )

Frees the global AttHash object and the space that it points to.

TODO better name: att_hash_free

See also:
AttHash

References att_hashtable::space.

void make_attribute_hash ( int  size)

This function has to be called once to initialise the global attribute hash.

TODO better name: att_hash_make

See also:
AttHash

References bytes, cl_malloc(), att_hashtable::code, find_prime(), att_hashtable::size, and att_hashtable::space.

Referenced by accept_connection().

int split_attribute_spec ( char *  spec,
char **  corpus_name,
char **  attribute_name 
)
int split_subcorpus_spec ( char *  spec,
char **  corpus_name,
char **  subcorpus_name 
)

Variable Documentation

int cqi_errno

String describing the last CQi error.

This can be queried by the client.

Referenced by cqi_general_error(), and interpreter().