Esempio n. 1
0
void
do_cqi_cqp_list_subcorpora(void)
{
  char *corpus;
  CorpusList *cl, *mother;
  int n = 0;
  
  corpus = cqi_read_string();
  if (server_debug)
   Rprintf( "CQi: CQI_CQP_LIST_SUBCORPORA(%s)\n", corpus);
  mother = cqi_find_corpus(corpus);
  if (!check_corpus_name(corpus) || mother == NULL) 
    cqi_command(cqi_errno);
  else {

    /* ugly, but it's easiest ... first count corpora, then return names one by one */
    for (cl = FirstCorpusFromList(); cl != NULL; cl = NextCorpusFromList(cl)) {
      if (cl->type == SUB && cl->corpus == mother->corpus)
        n++;
    }
    cqi_send_word(CQI_DATA_STRING_LIST);
    cqi_send_int(n);
    for (cl = FirstCorpusFromList(); cl != NULL; cl = NextCorpusFromList(cl)) {
      if (cl->type == SUB && cl->corpus == mother->corpus)
        cqi_send_string(cl->name);
    }
    cqi_flush();

  }
  free(corpus);
}
Esempio n. 2
0
/* 
 * ------------------------------------------------------------------------
 * 
 * "rcqpCmd_list_corpora()" --
 * 
 * 
 * 
 * ------------------------------------------------------------------------
 */
SEXP rcqpCmd_list_corpora()
{
	SEXP			result = R_NilValue;
	CorpusList *	cl;
	int				i = 0, n = 0;
	
	/* First count corpora */
	for (cl = FirstCorpusFromList(); cl != NULL; cl = NextCorpusFromList(cl)) {
		if (cl->type == SYSTEM) n++;
	}

	result = PROTECT(allocVector(STRSXP, n));

	/* Then build list of names */
	for (cl = FirstCorpusFromList(); cl != NULL; cl = NextCorpusFromList(cl)) {
		if (cl->type == SYSTEM) {
			SET_STRING_ELT(result, i, mkChar(cl->name));
			i++;
		}
	}
	
	UNPROTECT(1);

	return result;
}
Esempio n. 3
0
void
do_cqi_corpus_list_corpora(void)
{
  CorpusList *cl;
  int n = 0;
  
  if (server_debug)
   Rprintf( "CQi: CQI_CORPUS_LIST_CORPORA()\n");
  /* ugly, but it's easiest ... first count corpora, then return names one by one */
  for (cl = FirstCorpusFromList(); cl != NULL; cl = NextCorpusFromList(cl)) {
    if (cl->type == SYSTEM)
      n++;
  }
  cqi_send_word(CQI_DATA_STRING_LIST);
  cqi_send_int(n);
  for (cl = FirstCorpusFromList(); cl != NULL; cl = NextCorpusFromList(cl)) {
    if (cl->type == SYSTEM)
      cqi_send_string(cl->name);
  }
  cqi_flush();
}
Esempio n. 4
0
/* 
 * ------------------------------------------------------------------------
 * 
 * "rcqpCmd_list_subcorpora(SEXP inCorpus)" --
 * 
 * 
 * 
 * ------------------------------------------------------------------------
 */
SEXP rcqpCmd_list_subcorpora(SEXP inCorpus)
{
	SEXP			result = R_NilValue;
	char *			corpus;
	CorpusList		*cl, *mother;
	int				i = 0, n = 0;
	
	PROTECT(inCorpus);

	corpus = (char*)CHAR(STRING_ELT(inCorpus,0));

	mother = cqi_find_corpus(corpus);
	if (!check_corpus_name(corpus) || mother == NULL) {
		UNPROTECT(1);
		rcqp_error_code(cqi_errno);
	} else {
		/* First count subcorpora */
		for (cl = FirstCorpusFromList(); cl != NULL; cl = NextCorpusFromList(cl)) {
			if (cl->type == SUB && cl->corpus == mother->corpus) n++;
		}
		
		result = PROTECT(allocVector(STRSXP, n));

		/* Then build list of names */
		for (cl = FirstCorpusFromList(); cl != NULL; cl = NextCorpusFromList(cl)) {
			if (cl->type == SUB && cl->corpus == mother->corpus) {
				SET_STRING_ELT(result, i, mkChar(cl->name));
				i++;
			}
		}
	}
	
	UNPROTECT(2);
	
	return result;
}
Esempio n. 5
0
/**
 * 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;
}