CWB
|
typedef unsigned char cqi_byte |
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...
port | The integer identifier of the port to listen on. |
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 | ) |
References cqi_errno, CQI_ERROR_SYNTAX_ERROR, and CQI_STATUS_OK.
Referenced by split_attribute_spec().
int check_corpus_name | ( | char * | name | ) |
References cqi_errno, CQI_ERROR_SYNTAX_ERROR, and CQI_STATUS_OK.
Referenced by cqi_find_corpus(), do_cqi_cqp_list_subcorpora(), split_attribute_spec(), and split_subcorpus_spec().
int check_subcorpus_name | ( | char * | name | ) |
References cqi_errno, CQI_ERROR_SYNTAX_ERROR, and CQI_STATUS_OK.
Referenced by do_cqi_cqp_query(), and split_subcorpus_spec().
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 | ) |
Sends a general CQi command, without any arguments.
References cqi_flush(), cqi_send_error(), and cqi_send_word().
Referenced by cqi_general_error(), do_cqi_cl_alg2cpos(), do_cqi_cl_attribute_size(), do_cqi_cl_cpos2alg(), do_cqi_cl_cpos2id(), do_cqi_cl_cpos2lbound(), do_cqi_cl_cpos2rbound(), do_cqi_cl_cpos2str(), do_cqi_cl_cpos2struc(), do_cqi_cl_id2cpos(), do_cqi_cl_id2freq(), do_cqi_cl_id2str(), do_cqi_cl_idlist2cpos(), do_cqi_cl_lexicon_size(), do_cqi_cl_regex2id(), do_cqi_cl_str2id(), do_cqi_cl_struc2cpos(), do_cqi_cl_struc2str(), do_cqi_corpus_attributes(), do_cqi_corpus_full_name(), do_cqi_corpus_structural_attribute_has_values(), do_cqi_cqp_drop_subcorpus(), do_cqi_cqp_dump_subcorpus(), do_cqi_cqp_fdist_1(), do_cqi_cqp_fdist_2(), do_cqi_cqp_list_subcorpora(), do_cqi_cqp_query(), do_cqi_cqp_subcorpus_has_field(), do_cqi_cqp_subcorpus_size(), interpreter(), main(), and send_cl_error().
void cqi_data_bool | ( | int | n | ) |
Sends a boolean to the client.
References CQI_DATA_BOOL, cqi_flush(), cqi_send_byte(), cqi_send_error(), and cqi_send_word().
Referenced by do_cqi_corpus_structural_attribute_has_values(), do_cqi_cqp_subcorpus_has_field(), and interpreter().
void cqi_data_bool_list | ( | cqi_byte * | list, |
int | l | ||
) |
Sends a list of booleans to the client.
list | pointer to a block of booleans (each occupying one byte) to send. |
l | the 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.
list | pointer to a block of bytes to send. |
l | the 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 | ) |
Sends an integer to the client.
References CQI_DATA_INT, cqi_flush(), cqi_send_error(), cqi_send_int(), and cqi_send_word().
Referenced by do_cqi_cl_attribute_size(), do_cqi_cl_lexicon_size(), and do_cqi_cqp_subcorpus_size().
void cqi_data_int_int | ( | int | n1, |
int | n2 | ||
) |
Sends a sequence of two integers to the client.
n1 | The first integer sent |
n2 | The 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.
n1 | The first integer sent |
n2 | The second integer sent |
n3 | The third integer sent |
n4 | The 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.
list | pointer to a block of integers to send. |
l | the 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 | ) |
Sends a string to the client.
References CQI_DATA_STRING, cqi_flush(), cqi_send_error(), cqi_send_string(), and cqi_send_word().
Referenced by do_cqi_corpus_charset(), do_cqi_corpus_full_name(), and interpreter().
void cqi_data_string_list | ( | char ** | list, |
int | l | ||
) |
Sends a list of strings to the client.
list | pointer to a block of pointers-to-strings; the strings will be sent. |
l | the 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.
name | Name of the attribute to be deleted |
References att_hash_lookup(), ATT_NONE, att_bucket::attribute, cl_delete_attribute(), and att_bucket::type.
CorpusList* cqi_find_corpus | ( | char * | name | ) |
Gets a pointer to the corpus with the given name.
References access_corpus(), check_corpus_name(), corpus, CQI_CQP_ERROR_NO_SUCH_CORPUS, cqi_errno, CQI_STATUS_OK, findcorpus(), split_subcorpus_spec(), SUB, and SYSTEM.
Referenced by cqi_activate_corpus(), do_cqi_cqp_drop_subcorpus(), do_cqi_cqp_dump_subcorpus(), do_cqi_cqp_fdist_1(), do_cqi_cqp_fdist_2(), do_cqi_cqp_list_subcorpora(), do_cqi_cqp_query(), do_cqi_cqp_subcorpus_has_field(), and do_cqi_cqp_subcorpus_size().
int cqi_flush | ( | void | ) |
Flushes the stream from the CQP server to the client program, emptying its buffer.
Note that under windows, buffered output is not possible, so this function does nothing.
References conn_out, and snoop.
Referenced by cqi_command(), cqi_data_bool(), cqi_data_bool_list(), cqi_data_byte(), cqi_data_byte_list(), cqi_data_int(), cqi_data_int_int(), cqi_data_int_int_int_int(), cqi_data_int_list(), cqi_data_string(), cqi_data_string_list(), do_cqi_cl_cpos2alg(), do_cqi_cl_cpos2id(), do_cqi_cl_cpos2lbound(), do_cqi_cl_cpos2rbound(), do_cqi_cl_cpos2str(), do_cqi_cl_cpos2struc(), do_cqi_cl_id2freq(), do_cqi_cl_id2str(), do_cqi_cl_idlist2cpos(), do_cqi_cl_str2id(), do_cqi_cl_struc2str(), do_cqi_corpus_list_corpora(), do_cqi_cqp_dump_subcorpus(), do_cqi_cqp_fdist_1(), do_cqi_cqp_fdist_2(), do_cqi_cqp_list_subcorpora(), do_cqi_cqp_subcorpus_has_field(), and send_cqi_corpus_attributes().
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
errstring | String 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 | ||
) |
References access_corpus(), att_hash_lookup(), att_bucket::attribute, cl_new_attribute, cl::corpus, CQI_CL_ERROR_NO_SUCH_ATTRIBUTE, CQI_CL_ERROR_WRONG_ATTRIBUTE_TYPE, CQI_CQP_ERROR_NO_SUCH_CORPUS, cqi_errno, CQI_STATUS_OK, findcorpus(), server_debug, split_attribute_spec(), SYSTEM, and att_bucket::type.
Referenced by do_cqi_cl_alg2cpos(), do_cqi_cl_attribute_size(), do_cqi_cl_cpos2alg(), do_cqi_cl_cpos2id(), do_cqi_cl_cpos2lbound(), do_cqi_cl_cpos2rbound(), do_cqi_cl_cpos2str(), do_cqi_cl_cpos2struc(), do_cqi_cl_id2cpos(), do_cqi_cl_id2freq(), do_cqi_cl_id2str(), do_cqi_cl_idlist2cpos(), do_cqi_cl_lexicon_size(), do_cqi_cl_regex2id(), do_cqi_cl_str2id(), do_cqi_cl_struc2cpos(), do_cqi_cl_struc2str(), and do_cqi_corpus_structural_attribute_has_values().
int cqi_read_bool | ( | void | ) |
References cqi_recv_byte(), and cqi_recv_error().
int cqi_read_bool_list | ( | cqi_byte ** | list | ) |
References cl_malloc(), cqi_read_byte(), cqi_read_int(), and snoop.
int cqi_read_byte | ( | void | ) |
int cqi_read_byte_list | ( | cqi_byte ** | list | ) |
References cl_malloc(), cqi_read_byte(), cqi_read_int(), and snoop.
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 | ) |
References cl_malloc(), cqi_read_word(), cqi_recv_bytes(), cqi_recv_error(), and snoop.
Referenced by cqi_read_string_list(), do_cqi_cl_alg2cpos(), do_cqi_cl_attribute_size(), do_cqi_cl_cpos2alg(), do_cqi_cl_cpos2id(), do_cqi_cl_cpos2lbound(), do_cqi_cl_cpos2rbound(), do_cqi_cl_cpos2str(), do_cqi_cl_cpos2struc(), do_cqi_cl_id2cpos(), do_cqi_cl_id2freq(), do_cqi_cl_id2str(), do_cqi_cl_idlist2cpos(), do_cqi_cl_lexicon_size(), do_cqi_cl_regex2id(), do_cqi_cl_str2id(), do_cqi_cl_struc2cpos(), do_cqi_cl_struc2str(), do_cqi_corpus_attributes(), do_cqi_corpus_charset(), do_cqi_corpus_full_name(), do_cqi_corpus_properties(), do_cqi_corpus_structural_attribute_has_values(), do_cqi_cqp_drop_subcorpus(), do_cqi_cqp_dump_subcorpus(), do_cqi_cqp_fdist_1(), do_cqi_cqp_fdist_2(), do_cqi_cqp_list_subcorpora(), do_cqi_cqp_query(), do_cqi_cqp_subcorpus_has_field(), do_cqi_cqp_subcorpus_size(), and main().
int cqi_read_string_list | ( | char *** | list | ) |
References cl_malloc(), cqi_read_int(), cqi_read_string(), and snoop.
Referenced by do_cqi_cl_str2id().
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.
n | The 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). |
nosnoop | Boolean: 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.
list | pointer to a block of bytes to send. |
l | the number of bytes to send. |
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 | ) |
Sends an INT to the client.
An int consists of four bytes in network order.
This function should be called via one of the cqi_data_* functions and not on its own.
References cqi_send_byte(), and snoop.
Referenced by cqi_data_int(), cqi_data_int_int(), cqi_data_int_int_int_int(), cqi_send_byte_list(), cqi_send_int_list(), cqi_send_string_list(), do_cqi_cl_cpos2alg(), do_cqi_cl_cpos2id(), do_cqi_cl_cpos2lbound(), do_cqi_cl_cpos2rbound(), do_cqi_cl_cpos2str(), do_cqi_cl_cpos2struc(), do_cqi_cl_id2freq(), do_cqi_cl_id2str(), do_cqi_cl_str2id(), do_cqi_cl_struc2str(), do_cqi_corpus_list_corpora(), do_cqi_cqp_dump_subcorpus(), do_cqi_cqp_fdist_1(), do_cqi_cqp_fdist_2(), do_cqi_cqp_list_subcorpora(), do_cqi_send_minus_one_list(), and send_cqi_corpus_attributes().
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.
list | pointer to a block of integers to send. |
l | the number of integers to send. |
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.
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.
list | pointer to a block of pointers-to-strings; the strings will be sent. |
l | the 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 | ) |
Sends a WORD to the client.
A word consists of two bytes in network order. Since CQi commands are two bytes, this function can be used to send commands.
This function should be called via one of the cqi_data_* functions and not on its own.
References cqi_send_byte(), and snoop.
Referenced by cqi_command(), cqi_data_bool(), cqi_data_bool_list(), cqi_data_byte(), cqi_data_byte_list(), cqi_data_int(), cqi_data_int_int(), cqi_data_int_int_int_int(), cqi_data_int_list(), cqi_data_string(), cqi_data_string_list(), cqi_send_string(), do_cqi_cl_cpos2alg(), do_cqi_cl_cpos2id(), do_cqi_cl_cpos2lbound(), do_cqi_cl_cpos2rbound(), do_cqi_cl_cpos2str(), do_cqi_cl_cpos2struc(), do_cqi_cl_id2freq(), do_cqi_cl_id2str(), do_cqi_cl_str2id(), do_cqi_cl_struc2str(), do_cqi_corpus_list_corpora(), do_cqi_cqp_dump_subcorpus(), do_cqi_cqp_fdist_1(), do_cqi_cqp_fdist_2(), do_cqi_cqp_list_subcorpora(), and send_cqi_corpus_attributes().
void free_attribute_hash | ( | void | ) |
Frees the global AttHash object and the space that it points to.
TODO better name: att_hash_free
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
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 | ||
) |
References check_attribute_name(), check_corpus_name(), cl_strdup(), cqi_errno, CQI_ERROR_SYNTAX_ERROR, CQI_STATUS_OK, and strdupto().
Referenced by cqi_lookup_attribute().
int split_subcorpus_spec | ( | char * | spec, |
char ** | corpus_name, | ||
char ** | subcorpus_name | ||
) |
References check_corpus_name(), check_subcorpus_name(), cl_free, cl_strdup(), cqi_errno, CQI_STATUS_OK, and strdupto().
Referenced by cqi_find_corpus(), do_cqi_cqp_drop_subcorpus(), and do_cqi_cqp_query().
int cqi_errno |
CQi last error.
Referenced by check_attribute_name(), check_corpus_name(), check_subcorpus_name(), cqi_find_corpus(), cqi_lookup_attribute(), do_cqi_cl_alg2cpos(), do_cqi_cl_attribute_size(), do_cqi_cl_cpos2alg(), do_cqi_cl_cpos2id(), do_cqi_cl_cpos2lbound(), do_cqi_cl_cpos2rbound(), do_cqi_cl_cpos2str(), do_cqi_cl_cpos2struc(), do_cqi_cl_id2cpos(), do_cqi_cl_id2freq(), do_cqi_cl_id2str(), do_cqi_cl_idlist2cpos(), do_cqi_cl_lexicon_size(), do_cqi_cl_regex2id(), do_cqi_cl_str2id(), do_cqi_cl_struc2cpos(), do_cqi_cl_struc2str(), do_cqi_corpus_structural_attribute_has_values(), do_cqi_cqp_drop_subcorpus(), do_cqi_cqp_dump_subcorpus(), do_cqi_cqp_fdist_1(), do_cqi_cqp_fdist_2(), do_cqi_cqp_list_subcorpora(), do_cqi_cqp_query(), do_cqi_cqp_subcorpus_has_field(), do_cqi_cqp_subcorpus_size(), split_attribute_spec(), and split_subcorpus_spec().
char cqi_error_string[] |
String describing the last CQi error.
This can be queried by the client.
Referenced by cqi_general_error(), and interpreter().