Beispiel #1
0
static Rboolean sock_open(Rconnection con)
{
    Rsockconn thisconn = (Rsockconn)con->connprivate;
    int sock, sock1, mlen;
    int timeout = thisconn->timeout;
    char buf[256];

    if(timeout == NA_INTEGER || timeout <= 0) timeout = 60;
    thisconn->pend = thisconn->pstart = thisconn->inbuf;

    if(thisconn->server) {
	sock1 = R_SockOpen(thisconn->port);
	if(sock1 < 0) {
	    warning("port %d cannot be opened", thisconn->port);
	    return FALSE;
	}
	/* use try-catch to close socket on jump. */
	try {
	    sock = R_SockListen(sock1, buf, 256, timeout);
	}
	catch (...) {
	    R_SockClose(sock1);
	    throw;
	}

	if(sock < 0) {
	    warning("problem in listening on this socket");
	    R_SockClose(sock1);
	    return FALSE;
	}
	free(con->description);
	con->description = (char *) malloc(strlen(buf) + 10);
	sprintf(con->description, "<-%s:%d", buf, thisconn->port);
	R_SockClose(sock1);
    } else {
	sock = R_SockConnect(thisconn->port, con->description, timeout);
	if(sock < 0) {
	    warning("%s:%d cannot be opened", con->description, thisconn->port);
	    return FALSE;
	}
	sprintf(buf, "->%s:%d", con->description, thisconn->port);
	strcpy(con->description, buf);
    }
    thisconn->fd = sock;

    mlen = int( strlen(con->mode));
    con->isopen = TRUE;
    if(mlen >= 2 && con->mode[mlen - 1] == 'b') con->text = FALSE;
    else con->text = TRUE;
    set_iconv(con); /* OK for output, at least */
    con->save = -1000;
    return TRUE;
}
Beispiel #2
0
struct reg_parse* reg_parse_new(const void* ctx,
				struct reg_parse_callback cb,
				const char* str_enc, unsigned flags)
{
	struct reg_parse* s = talloc_zero(ctx, struct reg_parse);
	if (s == NULL)
		return NULL;
	s->key     = cbuf_new(s);
	s->valname = cbuf_new(s);
	s->valblob = cbuf_new(s);
	s->tmp     = cbuf_new(s);
	if ( (s->tmp == NULL) || (s->valblob == NULL)
	     || (s->valname == NULL) || (s->key == NULL) )
	{
		goto fail;
	}

	s->reg_format_callback.writeline = (reg_format_callback_writeline_t)&reg_parse_line;
	s->reg_format_callback.data      = s;

	s->valtype = 0;
	if (cb.key == NULL) {
		cb.key = (reg_parse_callback_key_t)&nop;
	}
	if (cb.val == NULL) {
		cb.val = (reg_parse_callback_val_t)&nop;
	}
	if (cb.val_del == NULL) {
		cb.val_del = (reg_parse_callback_val_del_t)&nop;
	}
	if (cb.comment == NULL) {
		cb.comment = (reg_parse_callback_comment_t)&nop;
	}

	s->call = cb;
	s->linenum = 0;
	s->state = STATE_DEFAULT;
	s->flags = flags;

	if (str_enc && !set_iconv(&s->str2UTF16, "UTF-16LE", str_enc)) {
		DEBUG(0, ("reg_parse_new: failed to set encoding: %s",
			  str_enc));
		goto fail;
	}

	assert(&s->reg_format_callback == (struct reg_format_callback*)s);
	return s;
fail:
	talloc_free(s);
	return NULL;
}