void do_cqi_cqp_drop_subcorpus(void) { char *subcorpus; CorpusList *cl; char *c, *sc; subcorpus = cqi_read_string(); if (server_debug) Rprintf( "CQi: CQI_CQP_DROP_SUBCORPUS('%s')\n", subcorpus); /* make sure it is a subcorpus, not a root corpus */ if (!split_subcorpus_spec(subcorpus, &c, &sc)) cqi_command(cqi_errno); else if (sc == NULL) { free(c); cqi_command(CQI_ERROR_SYNTAX_ERROR); } else { free(c); free(sc); cl = cqi_find_corpus(subcorpus); if (cl == NULL) cqi_command(cqi_errno); else { dropcorpus(cl); cqi_command(CQI_STATUS_OK); } } free(subcorpus); }
/* * ------------------------------------------------------------------------ * * "rcqpCmd_drop_subcorpus(SEXP inSubcorpus)" -- * * * * ------------------------------------------------------------------------ */ SEXP rcqpCmd_drop_subcorpus(SEXP inSubcorpus) { SEXP result = R_NilValue; char * subcorpus; char *c, *sc; CorpusList * cl; PROTECT(inSubcorpus); subcorpus = (char*)CHAR(STRING_ELT(inSubcorpus,0)); /* Make sure it is a subcorpus, not a root corpus */ if (!split_subcorpus_spec(subcorpus, &c, &sc)) { UNPROTECT(1); rcqp_error_code(cqi_errno); } else if (sc == NULL) { free(c); UNPROTECT(1); error("can't drop a root corpus."); } else { free(c); free(sc); cl = cqi_find_corpus(subcorpus); if (cl == NULL) { UNPROTECT(1); rcqp_error_code(cqi_errno); } else { dropcorpus(cl); } } UNPROTECT(1); return result; }
/** * Main function for the cqpserver app. */ int main(int argc, char *argv[]) { int cmd; which_app = cqpserver; /* TODO: shouldn't these come AFTER initialize_cqp(), as that function may overwrite these values with defaults? * or maybe I've missed some subtlety here....*/ silent = 1; paging = autoshow = auto_save = 0; if (!initialize_cqp(argc, argv)) { Rprintf( "CQPserver: ERROR Couldn't initialise CQP engine.\n"); rcqp_receive_error(1); } cqiserver_welcome(); if (localhost) { add_host_to_list("127.0.0.1"); /* in -L mode, connections from localhost are automatically accepted */ } if (0 < accept_connection(server_port)) { if (server_log) Rprintf("CQPserver: Connected. Waiting for CONNECT request.\n"); } else { Rprintf( "CQPserver: ERROR Connection failed.\n"); rcqp_receive_error(1); } /* establish CQi connection: wait for CONNECT request */ cmd = cqi_read_command(); if (cmd != CQI_CTRL_CONNECT) { if (server_log) Rprintf("CQPserver: Connection refused.\n"); cqiserver_wrong_command_error(cmd); } user = cqi_read_string(); passwd = cqi_read_string(); if (server_log) Rprintf("CQPserver: CONNECT user = '******' passwd = '%s' pid = %d\n", user, passwd, (int)getpid()); /* check password here (always required !!) */ if (!authenticate_user(user, passwd)) { Rprintf("CQPserver: Wrong username or password. Connection refused.\n"); /* TODO shouldn't this be to stderr as it is not conditional on server_log? */ cqi_command(CQI_ERROR_CONNECT_REFUSED); } else { cqi_command(CQI_STATUS_CONNECT_OK); /* re-randomize for query lock key generation */ cl_randomize(); /* check which corpora the user is granted access to */ { CorpusList *cl = FirstCorpusFromList(); while (cl != NULL) { if (!check_grant(user, cl->name)) dropcorpus(cl); cl = NextCorpusFromList(cl); } } /* start command interpreter loop */ interpreter(); if (server_log) Rprintf("CQPserver: User '%s' has logged off.\n", user); } /* connection terminated; clean up and exit */ Rprintf("CQPserver: Exit. (pid = %d)\n", (int)getpid()); /* TODO should we check cqp_error_status as in the main cqp app? */ return 0; }