Ejemplo n.º 1
0
/*
 * Core function to rename a mailbox.
 */
static int
ifcore_rename(lua_State *lua)
{
	const char *s, *u, *p;
	int r;

	if (lua_gettop(lua) != 3)
		luaL_error(lua, "wrong number of arguments");

	luaL_checktype(lua, 1, LUA_TTABLE);
	luaL_checktype(lua, 2, LUA_TSTRING);
	luaL_checktype(lua, 3, LUA_TSTRING);

	lua_pushvalue(lua, 1);
	if (!(s = get_table_string("server")))
		luaL_error(lua, "no mail server specified");
	if (!(u = get_table_string("username")))
		luaL_error(lua, "no username specified");
	p = DISCOVER_PORT(get_table_string("port"), get_table_string("ssl"));
	lua_pop(lua, 1);

	r = request_rename(s, p, u, lua_tostring(lua, 2), lua_tostring(lua, 3));

	lua_pop(lua, 3);

	lua_pushboolean(lua, (r == STATUS_RESPONSE_OK));

	return 1;
}
Ejemplo n.º 2
0
/*
 * Core function to rename a mailbox.
 */
static int
ifcore_rename(lua_State *lua)
{
	int r;

	if (lua_gettop(lua) != 3)
		luaL_error(lua, "wrong number of arguments");
	luaL_checktype(lua, 1, LUA_TLIGHTUSERDATA);
	luaL_checktype(lua, 2, LUA_TSTRING);
	luaL_checktype(lua, 3, LUA_TSTRING);

	while ((r = request_rename((session *)(lua_topointer(lua, 1)),
	    lua_tostring(lua, 2), lua_tostring(lua, 3))) == STATUS_NONE);

	lua_pop(lua, 3);

	if (r == -1)
		return 0;

	lua_pushboolean(lua, (r == STATUS_OK));

	return 1;
}
Ejemplo n.º 3
0
int main (int argc, char* argv[]) {
    menu_option current_option;   // Menu action
    char        arg[BUFSIZE];     // Menu action argument
    char       *host;             // Hostname to connect to
    short       portnum;          // Port of the server
    int         sock,             // Socket to host
                conn;             // Connection to the host

    // Get server hostname
    if (argc == 3) {
        host    = argv[1];        // Extract the hostname
        portnum = atoi(argv[2]);  // Extract the port number
    } else {
        fprintf(stderr, "Usage: %s <host> <port>\n", argv[0]);
        exit(1);
    }

    // Initialize the connection
    printf("Connecting...");
    fflush(stdout);

    if (setup(host, portnum, &sock, &conn) < 0) {
        fprintf(stderr, "\nCould not connect to %s:%d\n", host, portnum);
        exit(1);
    }

    printf("\rConnected to %s:%d\n", host, portnum);

    // Request the desired action from the user
    for (;;) {
        current_option = handle_input(host, arg, sizeof(arg));

        switch (current_option) {

            // Close the socket before quitting
            case QUIT:
                close(sock);
                exit(1);
                break;

            case LISTFILES:
                if (request_file_list(sock) < 0) fatal("[!!] Request File List failed.");
                break;

            case GETFILE:
                if (request_file(sock, arg) < 0) fatal("[!!] Request Get File failed.");
                break;

            case PUTFILE:
                if (request_put(sock, arg) < 0) fatal("[!!] Request Put File failed.");
                break;

            case RENAMEFILE:
                if (request_rename(sock, arg) < 0) fatal("[!! Request Rename failed.");
                break;

            default:
                fprintf(stderr, "[!!] Unknown command\n");
                break;
        }
    }

    return 0;
}