Ejemplo n.º 1
0
static void sendadc1(struct socket *sk, int sep, wchar_t *arg)
{
    char *mbsbuf;
    wchar_t *buf;
    size_t bufsize, bufdata;
    
    buf = NULL;
    bufsize = bufdata = 0;
    if(sep)
	addtobuf(buf, L' ');
    for(; *arg != L'\0'; arg++) {
	if(*arg == L' ')
	    bufcat(buf, L"\\s", 2);
	else if(*arg == L'\n')
	    bufcat(buf, L"\\n", 2);
	else if(*arg == L'\\')
	    bufcat(buf, L"\\\\", 2);
	else
	    addtobuf(buf, *arg);
    }
    addtobuf(buf, L'\0');
    mbsbuf = icwcstombs(buf, "utf-8");
    sockqueue(sk, mbsbuf, strlen(mbsbuf));
    free(mbsbuf);
}
Ejemplo n.º 2
0
/* send a request for a directory item */
int
nfs_readdir(struct cookie *pfh, int cookie, int size,
	void (*func) (uintptr_t , int, int, struct nfs_filename *, int),
	uintptr_t token)
{
    readdirargs_t args;

    struct pbuf *pbuf;
    
    /* now the user data struct is setup, do some call stuff! */
    pbuf = initbuf(NFS_NUMBER, NFS_VERSION, NFSPROC_READDIR);

    /* copy the buffer */
    memcpy(&args.dir, pfh, sizeof(struct cookie));
    
    /* set the cookie */
    args.cookie = cookie;
    args.count = size;

    /* copy the arguments into the packet */
    addtobuf(pbuf, (char*) &args, sizeof(args));

    /* make the call! */
    return rpc_send(pbuf, nfs_port, nfs_readdir_cb, func, token);
}
Ejemplo n.º 3
0
int
nfs_write(struct cookie *fh, int offset, int count, void *data,
     void (*func) (uintptr_t, int, fattr_t *),
     uintptr_t token)
{
    struct pbuf *pbuf;
    writeargs_t args;
    
    /* now the user data struct is setup, do some call stuff! */
    pbuf = initbuf(NFS_NUMBER, NFS_VERSION, NFSPROC_WRITE);

    /* copy in the fhandle */
    memcpy(&args.file, (char*) fh, sizeof(struct cookie));
    
    args.offset = offset;
    args.beginoffset = 0; /* unused as per RFC */
    args.totalcount = 0;  /* unused as per RFC */
    
    /* add them to the buffer */
    addtobuf(pbuf, (char*) &args, sizeof(args));
    
    /* put the data in */
    adddata(pbuf, data, count);

    return rpc_send(pbuf, nfs_port, nfs_write_cb, func, token);
}
Ejemplo n.º 4
0
unsigned int
map_getport(mapping_t* pmap)
{
    int port;
    struct pbuf *pbuf;
    struct pbuf *ret;
    debug("Getting port\n");
    pmap->port = 0;
    
    /* add the xid */
    pbuf = initbuf(PMAP_NUMBER, PMAP_VERSION, PMAPPROC_GETPORT);
    
    /* pack up the map struct */
    addtobuf(pbuf, (char*) pmap, sizeof(mapping_t));
    
    /* make the call */
    ret = rpc_call(pbuf, PMAP_PORT);

    assert(ret != NULL);
    
    /* now we can extract the port */
    getfrombuf(ret, (char*) &port, sizeof(port));
    
    pmap->port = port;
    
    debug("Got port %d\n", port);

    return 0;
}
Ejemplo n.º 5
0
Archivo: transport.c Proyecto: gz/aos10
/* Add a fixed sized buffer to the packet */
void
adddata(struct pbuf* pbuf, char *data, int size)
{
    int padded;
    int fill = 0;
    
    padded = size;

    addtobuf(pbuf, (char*) &size, sizeof(int));
    
    addtobuf(pbuf, data, size);

    if (padded % 4) {
	addtobuf(pbuf, (char*) &fill, 4 - (padded % 4) );
    }	
}
Ejemplo n.º 6
0
int
nfs_create(struct cookie *fh, char *name, sattr_t *sat,
     void (*func) (uintptr_t, int, struct cookie *, fattr_t *),
     uintptr_t token)
{
    struct pbuf *pbuf;
    
    /* now the user data struct is setup, do some call stuff! */
    pbuf = initbuf(NFS_NUMBER, NFS_VERSION, NFSPROC_CREATE);

    /* put in the fhandle */
    addtobuf(pbuf, (char*) fh, sizeof(struct cookie));
    
    /* put in the name */
    addstring(pbuf, name);
    
    addtobuf(pbuf, (char*) sat, sizeof(sattr_t));

    return rpc_send(pbuf, nfs_port, nfs_create_cb, func, token);
}
Ejemplo n.º 7
0
int
nfs_getattr(struct cookie *fh,
       void (*func) (uintptr_t, int, fattr_t *), 
       uintptr_t token)
{
    struct pbuf *pbuf;

    /* now the user data struct is setup, do some call stuff! */
    pbuf = initbuf(NFS_NUMBER, NFS_VERSION, NFSPROC_GETATTR);
    
    /* put in the fhandle */
    addtobuf(pbuf, (char*) fh, sizeof(struct cookie));
    
    /* send it! */
    return rpc_send(pbuf, nfs_port, nfs_getattr_cb, func, token);
}
Ejemplo n.º 8
0
/* remove a file named 'name' in directory 'cwd' */
int
nfs_remove(struct cookie *cwd, char *name, 
       void (*func) (uintptr_t, int), uintptr_t token)
{
    struct pbuf *pbuf;

    /* now the user data struct is setup, do some call stuff! */
    pbuf = initbuf(NFS_NUMBER, NFS_VERSION, NFSPROC_REMOVE);
    
    /* put in the fhandle */
    addtobuf(pbuf, (char*) cwd, sizeof(struct cookie));
    
    /* put in the name */
    addstring(pbuf, name);
    
    /* send it! */
    return rpc_send(pbuf, nfs_port, nfs_remove_cb, func, token);
}
Ejemplo n.º 9
0
int
nfs_read(struct cookie *fh, int pos, int count,
     void (*func) (uintptr_t, int, fattr_t *, int, char *),
     uintptr_t token)
{
    struct pbuf *pbuf;
    readargs_t args;
    
    /* now the user data struct is setup, do some call stuff! */
    pbuf = initbuf(NFS_NUMBER, NFS_VERSION, NFSPROC_READ);

    /* copy in the fhandle */
    memcpy(&args.file, (char*) fh, sizeof(struct cookie));
    
    args.offset = pos;
    args.count = count;
    args.totalcount = 0;  /* unused as per RFC */
    
    /* add them to the buffer */
    addtobuf(pbuf, (char*) &args, sizeof(args));
    
    return rpc_send(pbuf, nfs_port, nfs_read_cb, func, token);
}
Ejemplo n.º 10
0
Archivo: transport.c Proyecto: gz/aos10
/* for synchronous calls */
struct pbuf *
initbuf(int prognum, int vernum, int procnum)
{
    xid_t txid = get_xid();
    int calltype = MSG_CALL;
    call_body bod;
    opaque_auth_t cred, verf;
    int nsize;
    int tval;
    struct pbuf *pbuf;
    
    pbuf = pbuf_alloc(PBUF_TRANSPORT, UDP_PAYLOAD, PBUF_RAM);
    assert(pbuf != NULL);

    pbuf->arg[0] = pbuf->payload;

    debug("Creating txid: %d\n", txid);

    /* add the xid */
    addtobuf(pbuf, (char*) &txid, sizeof(xid_t));

    /* set it to call */
    addtobuf(pbuf, (char*) &calltype, sizeof(int));

    /* add the call body - prog/proc info */
    bod.rpcvers = SRPC_VERSION;
    bod.prog = prognum;  /* that's NFS, dammit */
    bod.vers = vernum;
    bod.proc = procnum;
    
    addtobuf(pbuf, (char*) &bod, sizeof(bod));

    /* work out size of name */
    nsize = strlen(NFS_MACHINE_NAME);

    if(nsize % 4)
	nsize += 4 - (nsize % 4);
    
    /* now add the authentication */
    cred.flavour = AUTH_UNIX;
    cred.size = 5 * sizeof(int) + nsize;

    addtobuf(pbuf, (char*) &cred, sizeof(cred));

    /* add the STAMP field */
    tval = 37; /* FIXME: Magic number! */
    addtobuf(pbuf, (char*) &tval, sizeof(tval));

    /* add machine name */
    addstring(pbuf, NFS_MACHINE_NAME);

    /* add uid */
    tval = 0; /* root */
    addtobuf(pbuf, (char*) &tval, sizeof(tval));

    /* add gid */
    tval = 0; /* root */
    addtobuf(pbuf, (char*) &tval, sizeof(tval));

    /* add gids */
    tval = 0;
    addtobuf(pbuf, (char*) &tval, sizeof(tval));

    verf.flavour = AUTH_NULL;
    verf.size = 0;

    addtobuf(pbuf, (char*) &verf, sizeof(verf));

    return pbuf;

}
Ejemplo n.º 11
0
static void pipefdcb(struct conduit *conduit, int fd, GdkInputCondition condition)
{
    struct data *data;
    int ret;
    char *p, *p2, *cmd;
    char **args;
    size_t argssize, argsdata;
    struct transfer *transfer;
    
    data = (struct data *)conduit->cdata;
    if(conduit->state == CNDS_SYN)
	condconnected(conduit);
    sizebuf2(data->inbuf, data->inbufdata + 80, 1);
    ret = read(data->fd, data->inbuf + data->inbufdata, data->inbufsize - data->inbufdata);
    if(ret < 0)
    {
	if((errno == EINTR) || (errno == EAGAIN)) /* Shouldn't happen, but, oh well... */
	    return;
	perror("conduit-pipe: read");
	gdk_input_remove(data->gdktag);
	close(data->fd);
	kill(-data->subproc, SIGHUP);
	data->gdktag = -1;
	data->fd = -1;
	data->subproc = 0;
	conddisconn(conduit);
    }
    if(ret == 0)
    {
	gdk_input_remove(data->gdktag);
	close(data->fd);
	kill(-data->subproc, SIGHUP);
	data->gdktag = -1;
	data->fd = -1;
	data->subproc = 0;
	conddisconn(conduit);
    }
    data->inbufdata += ret;
    while((p = memchr(data->inbuf, '\n', data->inbufdata)) != NULL)
    {
	*p = 0;
	cmd = sstrdup(data->inbuf);
	memmove(data->inbuf, p + 1, data->inbufdata -= (p - data->inbuf) + 1);
	args = NULL;
	argssize = argsdata = 0;
	p = cmd;
	do
	{
	    if((p2 = strchr(p, '\t')) != NULL)
		*(p2++) = 0;
	    addtobuf(args, p);
	    p = p2;
	} while(p2 != NULL);
	if(!strcmp(args[0], "N") && (argsdata >= 4))
	{
	    transfer = newtransfer(conduit, args[1], atoi(args[2]), atoi(args[3]));
	}
	if(!strcmp(args[0], "D") && (argsdata >= 2))
	{
	    if((transfer = findtransferbytag(conduit, args[1])) != NULL)
		freetransfer(transfer);
	}
	if(!strcmp(args[0], "S") && (argsdata >= 3))
	{
	    if((transfer = findtransferbytag(conduit, args[1])) != NULL)
		transfersetsize(transfer, atoi(args[2]));
	}
	if(!strcmp(args[0], "P") && (argsdata >= 3))
	{
	    if((transfer = findtransferbytag(conduit, args[1])) != NULL)
		transfersetpos(transfer, atoi(args[2]));
	}
	free(args);
	free(cmd);
    }
}