Esempio n. 1
0
static void parse(client *c)
{
	switch(c->state)
	{
		case CONNECTING:
			login_send_banner(c);
			login_ask_username(c);
			c->state = USERNAME;
		break;
		case USERNAME:
			handle_username(c);
			login_ask_password(c);
			c->state = PASSWORD;
		break;
		case PASSWORD:
			/* TODO: check the username and password */
			login_client(c);
			c->state = CONNECTED;
			client_prompt(c);
		break;
		case CONNECTED:
			/* TODO: parse the command prompt */
			//send_prompt(c);
			parse_command(c);
			client_prompt(c);
		break;
	}
}
Esempio n. 2
0
int main (int argc, char *argv[] )
{
    lscp_client_t *pClient;
    char *pszHost = "localhost";
    char  szLine[1024];
    int  cchLine;
    lscp_status_t ret;

#if defined(WIN32)
    if (WSAStartup(MAKEWORD(1, 1), &_wsaData) != 0) {
        fprintf(stderr, "lscp_client: WSAStartup failed.\n");
        return -1;
    }
#endif

    if (argc > 1)
        pszHost = argv[1];

    pClient = lscp_client_create(pszHost, SERVER_PORT, client_callback, NULL);
    if (pClient == NULL)
        return -1;

    client_usage();
    client_prompt();

    while (fgets(szLine, sizeof(szLine) - 3, stdin)) {

        cchLine = strlen(szLine);
        while (cchLine > 0 && (szLine[cchLine - 1] == '\n' || szLine[cchLine - 1] == '\r'))
            cchLine--;
        szLine[cchLine] = '\0';

        if (strcmp(szLine, "exit") == 0 || strcmp(szLine, "quit") == 0)
            break;
        else
        if (strcmp(szLine, "subscribe") == 0)
            lscp_client_subscribe(pClient, LSCP_EVENT_MISCELLANEOUS);
        else
        if (strcmp(szLine, "unsubscribe") == 0)
            lscp_client_unsubscribe(pClient, LSCP_EVENT_MISCELLANEOUS);
        else
        if (strcmp(szLine, "test") == 0)
            client_test_all(pClient, 0);
        else
        if (strcmp(szLine, "teststep") == 0 || strcmp(szLine, "test step") == 0)
            client_test_all(pClient, 1);
        else
        if (cchLine > 0 && strcmp(szLine, "help") != 0) {
            szLine[cchLine++] = '\r';
            szLine[cchLine++] = '\n';
            szLine[cchLine]   = '\0';
            ret = lscp_client_query(pClient, szLine);
            printf("%s\n(errno = %d)\n", lscp_client_get_result(pClient), lscp_client_get_errno(pClient));
            if (ret == LSCP_QUIT)
                break;
        }
        else client_usage();

        client_prompt();
    }

    lscp_client_destroy(pClient);

#if defined(WIN32)
    WSACleanup();
#endif

    return 0;
}