CWB
Functions | Variables
cqpserver.c File Reference
#include "server.h"
#include "auth.h"
#include "cqi.h"
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include "../cl/cl.h"
#include "../cl/macros.h"
#include "../cqp/cqp.h"
#include "../cqp/options.h"
#include "../cqp/corpmanag.h"
#include "../cqp/groups.h"

Functions

void cqiserver_welcome (void)
 Prints the CQi server welcome and copyright message. More...
 
void cqiserver_unknown_command_error (int cmd)
 Shuts down the server with an "unknown CQi command" error condition. More...
 
void cqiserver_wrong_command_error (int cmd)
 Shuts down the server with an "CQi command not allowed here" error condition. More...
 
void cqiserver_internal_error (char *function, char *reason)
 Shuts down the server with an "internal error" condition. More...
 
void send_cl_error (void)
 Sends the current CL error value to the client. More...
 
void do_cqi_corpus_list_corpora (void)
 
void do_cqi_corpus_charset (void)
 
void do_cqi_corpus_properties (void)
 
void send_cqi_corpus_attributes (Corpus *c, int type)
 
void do_cqi_corpus_attributes (int type)
 
void do_cqi_corpus_full_name (void)
 
void do_cqi_corpus_structural_attribute_has_values (void)
 
void do_cqi_cl_attribute_size (void)
 
void do_cqi_cl_lexicon_size (void)
 
void do_cqi_cl_drop_attribute (void)
 
void do_cqi_cl_str2id (void)
 
void do_cqi_cl_id2str (void)
 
void do_cqi_cl_id2freq (void)
 
void do_cqi_cl_cpos2str (void)
 
void do_cqi_cl_cpos2id (void)
 
void do_cqi_cl_cpos2struc (void)
 
void do_cqi_cl_cpos2lbound (void)
 
void do_cqi_cl_cpos2rbound (void)
 
void do_cqi_cl_cpos2alg (void)
 
void do_cqi_cl_struc2str (void)
 
void do_cqi_cl_id2cpos (void)
 
void do_cqi_cl_idlist2cpos (void)
 
void do_cqi_cl_regex2id (void)
 
void do_cqi_cl_struc2cpos (void)
 
void do_cqi_cl_alg2cpos (void)
 
void do_cqi_cqp_list_subcorpora (void)
 
int query_has_semicolon (char *query)
 Tests whether or nto the final non-blank character in a string is a semicolon. More...
 
void do_cqi_cqp_query (void)
 
void do_cqi_cqp_subcorpus_size (void)
 
char * cqi_field_name (cqi_byte field)
 Returns string representations of CQI_CONST_FIELD_ values. More...
 
void do_cqi_cqp_subcorpus_has_field (void)
 
void do_cqi_send_minus_one_list (int n)
 Sends n instances of integer -1 to the client. More...
 
void do_cqi_cqp_dump_subcorpus (void)
 
void do_cqi_cqp_drop_subcorpus (void)
 
void do_cqi_cqp_fdist_1 (void)
 
void do_cqi_cqp_fdist_2 (void)
 
void interpreter (void)
 The CQP server's command interpreter loop. More...
 
int main (int argc, char *argv[])
 Main function for the cqpserver app. More...
 

Variables

char * user = ""
 String containing the username sent by the currently-connect CQi client. More...
 
char * passwd = ""
 String containing the password sent by the currently-connect CQi client. More...
 

Function Documentation

char* cqi_field_name ( cqi_byte  field)

Returns string representations of CQI_CONST_FIELD_ values.

Utility function, used for debugging output & to check valid fields in subroutines below.

TODO as a utiltiy, shouldn't this be in the cqi library (server.c?)

References CQI_CONST_FIELD_KEYWORD, CQI_CONST_FIELD_MATCH, CQI_CONST_FIELD_MATCHEND, and CQI_CONST_FIELD_TARGET.

Referenced by do_cqi_cqp_dump_subcorpus(), do_cqi_cqp_fdist_1(), do_cqi_cqp_fdist_2(), and do_cqi_cqp_subcorpus_has_field().

void cqiserver_internal_error ( char *  function,
char *  reason 
)

Shuts down the server with an "internal error" condition.

Both parameters will be printed as part of the shutdown error message.

Parameters
functionString: should be name of the calling function, that is, the point where the error was raised.
reasonString containing any other explanatory details about the error.

Referenced by do_cqi_cqp_dump_subcorpus(), and do_cqi_cqp_subcorpus_has_field().

void cqiserver_unknown_command_error ( int  cmd)

Shuts down the server with an "unknown CQi command" error condition.

Parameters
cmdThe integer representing the unknown command received from the client.

Referenced by interpreter().

void cqiserver_welcome ( void  )

Prints the CQi server welcome and copyright message.

References CQI_MAJOR_VERSION, CQI_MINOR_VERSION, and VERSION.

Referenced by main().

void cqiserver_wrong_command_error ( int  cmd)

Shuts down the server with an "CQi command not allowed here" error condition.

Parameters
cmdThe integer representing the wrong command received from the client.

Referenced by interpreter(), and main().

void do_cqi_cl_alg2cpos ( void  )
void do_cqi_cl_attribute_size ( void  )
void do_cqi_cl_cpos2alg ( void  )
void do_cqi_cl_cpos2id ( void  )
void do_cqi_cl_cpos2lbound ( void  )
void do_cqi_cl_cpos2rbound ( void  )
void do_cqi_cl_cpos2str ( void  )
void do_cqi_cl_cpos2struc ( void  )
void do_cqi_cl_drop_attribute ( void  )

References cqi_general_error(), and server_debug.

Referenced by interpreter().

void do_cqi_cl_id2cpos ( void  )
void do_cqi_cl_id2freq ( void  )
void do_cqi_cl_id2str ( void  )
void do_cqi_cl_idlist2cpos ( void  )
void do_cqi_cl_lexicon_size ( void  )
void do_cqi_cl_regex2id ( void  )
void do_cqi_cl_str2id ( void  )
void do_cqi_cl_struc2cpos ( void  )
void do_cqi_cl_struc2str ( void  )
void do_cqi_corpus_attributes ( int  type)
void do_cqi_corpus_charset ( void  )
void do_cqi_corpus_full_name ( void  )
void do_cqi_corpus_list_corpora ( void  )
void do_cqi_corpus_properties ( void  )
void do_cqi_corpus_structural_attribute_has_values ( void  )
void do_cqi_cqp_drop_subcorpus ( void  )
void do_cqi_cqp_dump_subcorpus ( void  )
void do_cqi_cqp_fdist_1 ( void  )
void do_cqi_cqp_fdist_2 ( void  )
void do_cqi_cqp_list_subcorpora ( void  )
void do_cqi_cqp_query ( void  )
void do_cqi_cqp_subcorpus_has_field ( void  )
void do_cqi_cqp_subcorpus_size ( void  )
void do_cqi_send_minus_one_list ( int  n)

Sends n instances of integer -1 to the client.

Utility function for do_cqi_cqp_dump_subcorpus().

This is the error condition of the CQI_CQP_DUMP_SUBCORPUS command: it returns a list of (-1) values if requested field is not set.

It is assumed that the length of the lsit has already been sent.

Parameters
nLength of list to send.

References cqi_send_int().

Referenced by do_cqi_cqp_dump_subcorpus().

void interpreter ( void  )

The CQP server's command interpreter loop.

The loops starts running when this function is called, and when the exit command is reveived (CQI_CTRL_BYE) (returns on exit)

References ATT_ALIGN, ATT_POS, ATT_STRUC, CQI_ASK_FEATURE, CQI_ASK_FEATURE_CL_2_3, CQI_ASK_FEATURE_CQI_1_0, CQI_ASK_FEATURE_CQP_2_3, CQI_CL, CQI_CL_ALG2CPOS, CQI_CL_ATTRIBUTE_SIZE, CQI_CL_CPOS2ALG, CQI_CL_CPOS2ID, CQI_CL_CPOS2LBOUND, CQI_CL_CPOS2RBOUND, CQI_CL_CPOS2STR, CQI_CL_CPOS2STRUC, CQI_CL_DROP_ATTRIBUTE, CQI_CL_ID2CPOS, CQI_CL_ID2FREQ, CQI_CL_ID2STR, CQI_CL_IDLIST2CPOS, CQI_CL_LEXICON_SIZE, CQI_CL_REGEX2ID, CQI_CL_STR2ID, CQI_CL_STRUC2CPOS, CQI_CL_STRUC2STR, cqi_command(), CQI_CONST_NO, CQI_CONST_YES, CQI_CORPUS, CQI_CORPUS_ALIGNMENT_ATTRIBUTES, CQI_CORPUS_CHARSET, CQI_CORPUS_FULL_NAME, CQI_CORPUS_LIST_CORPORA, CQI_CORPUS_POSITIONAL_ATTRIBUTES, CQI_CORPUS_PROPERTIES, CQI_CORPUS_STRUCTURAL_ATTRIBUTE_HAS_VALUES, CQI_CORPUS_STRUCTURAL_ATTRIBUTES, CQI_CQP, CQI_CQP_DROP_SUBCORPUS, CQI_CQP_DUMP_SUBCORPUS, CQI_CQP_FDIST_1, CQI_CQP_FDIST_2, CQI_CQP_LIST_SUBCORPORA, CQI_CQP_QUERY, CQI_CQP_SUBCORPUS_HAS_FIELD, CQI_CQP_SUBCORPUS_SIZE, CQI_CTRL, CQI_CTRL_BYE, CQI_CTRL_CONNECT, CQI_CTRL_LAST_GENERAL_ERROR, CQI_CTRL_PING, CQI_CTRL_USER_ABORT, cqi_data_bool(), cqi_data_string(), cqi_error_string, cqi_read_command(), CQI_STATUS_BYE_OK, CQI_STATUS_PING_OK, cqiserver_unknown_command_error(), cqiserver_wrong_command_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_drop_attribute(), 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_list_corpora(), 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 server_debug.

Referenced by main().

int main ( int  argc,
char *  argv[] 
)
int query_has_semicolon ( char *  query)

Tests whether or nto the final non-blank character in a string is a semicolon.

CQP queries must be terminated with a single semicolon; multiple semicolons will produce an error to occur – so we have to check and add a semicolon if necessary.

Returns
Boolean: true iff the final non-blank character is a semicolon.

Referenced by do_cqi_cqp_query().

void send_cl_error ( void  )

Sends the current CL error value to the client.

This function takes the current contents of of the CL library's global cl_errno error value and sends it to the client.

It takes the CL error consant and translates it into the corresponding CQI_CL_ERROR_* constant.

NB: This function shuts down the server with an error condition if cl_errno does not actually contain an error condition.

See also
cl_errno

References CDA_EATTTYPE, CDA_EBADREGEX, CDA_EIDORNG, CDA_EIDXORNG, CDA_ENODATA, CDA_ENOMEM, CDA_ENYI, CDA_EOTHER, CDA_EPATTERN, CDA_EPOSORNG, CDA_OK, cl_errno, CQI_CL_ERROR_CORPUS_ACCESS, CQI_CL_ERROR_INTERNAL, CQI_CL_ERROR_OUT_OF_MEMORY, CQI_CL_ERROR_OUT_OF_RANGE, CQI_CL_ERROR_REGEX, CQI_CL_ERROR_WRONG_ATTRIBUTE_TYPE, cqi_command(), and server_debug.

Referenced by do_cqi_cl_alg2cpos(), do_cqi_cl_attribute_size(), do_cqi_cl_id2cpos(), do_cqi_cl_idlist2cpos(), do_cqi_cl_lexicon_size(), do_cqi_cl_regex2id(), and do_cqi_cl_struc2cpos().

void send_cqi_corpus_attributes ( Corpus c,
int  type 
)

Variable Documentation

char* passwd = ""

String containing the password sent by the currently-connect CQi client.

Referenced by ascii_print_corpus_header(), check_access_conditions(), html_print_corpus_header(), latex_print_corpus_header(), main(), and sgml_print_corpus_header().

char* user = ""

String containing the username sent by the currently-connect CQi client.

Referenced by authenticate_user(), check_grant(), do_cqi_cqp_query(), find_user(), main(), and show_grants().