Exemplo n.º 1
0
Client
MCinitClientRecord(Client c, oid user, bstream *fin, stream *fout)
{
	str prompt;

	c->user = user;
	c->username = 0;
	c->scenario = NULL;
	c->oldscenario = NULL;
	c->srcFile = NULL;
	c->blkmode = 0;

	c->fdin = fin ? fin : bstream_create(GDKin, 0);
	c->yycur = 0;
	c->bak = NULL;

	c->listing = 0;
	c->fdout = fout ? fout : GDKstdout;
	c->mdb = 0;
	c->history = 0;
	c->curprg = c->backup = 0;
	c->glb = 0;

	/* remove garbage from previous connection */
	if (c->nspace) {
		freeModule(c->nspace);
		c->nspace = 0;
	}

	c->father = NULL;
	c->login = c->lastcmd = time(0);
	//c->active = 0;
	c->session = GDKusec();
	c->qtimeout = 0;
	c->stimeout = 0;
	c->stage = 0;
	c->itrace = 0;
	c->debugOptimizer = c->debugScheduler = 0;
	c->flags = MCdefault;
	c->errbuf = 0;

	prompt = !fin ? GDKgetenv("monet_prompt") : PROMPT1;
	c->prompt = GDKstrdup(prompt);
	c->promptlength = strlen(prompt);

	c->actions = 0;
	c->totaltime = 0;
	/* create a recycler cache */
	c->exception_buf_initialized = 0;
	c->error_row = c->error_fld = c->error_msg = c->error_input = NULL;
	(void) AUTHgetUsername(&c->username, c);
	MT_sema_init(&c->s, 0, "Client->s");
	return c;
}
Exemplo n.º 2
0
static Client
MCinitClientRecord(Client c, oid user, bstream *fin, stream *fout)
{
	const char *prompt;

	c->user = user;
	c->username = 0;
	c->scenario = NULL;
	c->oldscenario = NULL;
	c->srcFile = NULL;
	c->blkmode = 0;

	c->fdin = fin ? fin : bstream_create(GDKin, 0);
	if ( c->fdin == NULL){
		MT_lock_set(&mal_contextLock);
		c->mode = FREECLIENT;
		MT_lock_unset(&mal_contextLock);
		showException(GDKout, MAL, "initClientRecord", MAL_MALLOC_FAIL);
		return NULL;
	}
	c->yycur = 0;
	c->bak = NULL;

	c->listing = 0;
	c->fdout = fout ? fout : GDKstdout;
	c->mdb = 0;
	c->history = 0;
	c->curprg = c->backup = 0;
	c->glb = 0;

	/* remove garbage from previous connection
	 * be aware, a user can introduce several modules
	 * that should be freed to avoid memory leaks */
	c->usermodule = c->curmodule = 0;

	c->father = NULL;
	c->login = c->lastcmd = time(0);
	//c->active = 0;
	c->session = GDKusec();
	c->qtimeout = 0;
	c->stimeout = 0;
	c->itrace = 0;
	c->flags = 0;
	c->errbuf = 0;

	prompt = !fin ? GDKgetenv("monet_prompt") : PROMPT1;
	c->prompt = GDKstrdup(prompt);
	if ( c->prompt == NULL){
		if (fin == NULL) {
			c->fdin->s = NULL;
			bstream_destroy(c->fdin);
			MT_lock_set(&mal_contextLock);
			c->mode = FREECLIENT;
			MT_lock_unset(&mal_contextLock);
		}
		showException(GDKout, MAL, "initClientRecord", MAL_MALLOC_FAIL);
		return NULL;
	}
	c->promptlength = strlen(prompt);

	c->actions = 0;
	c->exception_buf_initialized = 0;
	c->error_row = c->error_fld = c->error_msg = c->error_input = NULL;
	c->wlc_kind = 0;
	c->wlc = NULL;
#ifndef HAVE_EMBEDDED /* no authentication in embedded mode */
	{
		str msg = AUTHgetUsername(&c->username, c);
		if (msg)				/* shouldn't happen */
			freeException(msg);
	}
#endif
	c->blocksize = BLOCK;
	c->protocol = PROTOCOL_9;

	c->filetrans = false;
	c->query = NULL;

	char name[16];
	snprintf(name, sizeof(name), "Client%d->s", (int) (c - mal_clients));
	MT_sema_init(&c->s, 0, name);
	return c;
}