/*!
 * \file test-client.c
 * \brief Testing client sending JSON requsts to the mod_netconf socket
 * \author Radek Krejci <rkrejci@cesnet.cz>
 * \date 2012
 */
/*
 * Copyright (C) 2012 CESNET
 *
 * LICENSE TERMS
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in
 *    the documentation and/or other materials provided with the
 *    distribution.
 * 3. Neither the name of the Company nor the names of its contributors
 *    may be used to endorse or promote products derived from this
 *    software without specific prior written permission.
 *
 * ALTERNATIVELY, provided that this notice is retained in full, this
 * product may be distributed under the terms of the GNU General Public
 * License (GPL) version 2 or later, in which case the provisions
 * of the GPL apply INSTEAD OF those given above.
 *
 * This software is provided ``as is'', and any express or implied
 * warranties, including, but not limited to, the implied warranties of
 * merchantability and fitness for a particular purpose are disclaimed.
 * In no event shall the company or contributors be liable for any
 * direct, indirect, incidental, special, exemplary, or consequential
 * damages (including, but not limited to, procurement of substitute
 * goods or services; loss of use, data, or profits; or business
 * interruption) however caused and on any theory of liability, whether
 * in contract, strict liability, or tort (including negligence or
 * otherwise) arising in any way out of the use of this software, even
 * if advised of the possibility of such damage.
 *
 */

#define _GNU_SOURCE
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <err.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <json/json.h>
#include <ctype.h>

#define SOCKET_FILENAME "/tmp/mod_netconf.sock"
#define BUFFER_SIZE 40960

typedef enum MSG_TYPE {
	REPLY_OK,
	REPLY_DATA,
	REPLY_ERROR,
	REPLY_INFO,
	MSG_CONNECT,
	MSG_DISCONNECT,
	MSG_GET,
	MSG_GETCONFIG,
	MSG_EDITCONFIG,
	MSG_COPYCONFIG,
	MSG_DELETECONFIG,
	MSG_LOCK,
	MSG_UNLOCK,
	MSG_KILL,
	MSG_INFO,
	MSG_GENERIC
} MSG_TYPE;

void print_help(char* progname)
{
	printf("Usage: %s <command>\n", progname);
	printf("Available commands:\n");
	printf("\tconnect\n");
	printf("\tdisconnect\n");
	printf("\tcopy-config\n");
	printf("\tdelete-config\n");
	printf("\tedit-config\n");
	printf("\tget\n");
	printf("\tget-config\n");
	printf("\tkill-session\n");
	printf("\tlock\n");
	printf("\tunlock\n");
	printf("\tinfo\n");
	printf("\tgeneric\n");
}

/**
 * \brief Get multiline input text.
 *
 * Print given prompt and read text ending with CTRL+D.
 * Output string is terminated by 0. Ending '\n' is removed.
 *
 * On error, err is called!
 *
 * \param[out] output - pointer to memory where string is stored
 * \param[out] size - size of string return by getdelim()
 * \param[in] prompt - text printed as a prompt
 */
void readmultiline(char **output, size_t *size, const char *prompt)
{
	printf(prompt);
	if (getdelim (output, size, 'D' - 0x40, stdin) == -1) {
		if (errno) {
			err(errno, "Cannot read input.");
		}
		*output = (char *) malloc(sizeof(char));
		**output = 0;
		return;
	}
	(*output)[(*size)-1] = 0; /* input text end "sanitation" */
	(*output)[(strlen(*output))-1] = 0; /* input text end "sanitation" */
}

/**
 * \brief Get input text.
 *
 * Print given prompt and read one line of text.
 * Output string is terminated by 0. Ending '\n' is removed.
 *
 * On error, err is called!
 *
 * \param[out] output - pointer to memory where string is stored
 * \param[out] size - size of string return by getline()
 * \param[in] prompt - text printed as a prompt
 */
void readline(char **output, size_t *size, const char *prompt)
{
	printf(prompt);
	if (getline (output, size, stdin) == -1) {
		if (errno) {
			err(errno, "Cannot read input.");
		}
	}
	(*output)[(*size)-1] = 0; /* input text end "sanitation" */
	(*output)[(strlen(*output))-1] = 0; /* input text end "sanitation" */
}

int main (int argc, char* argv[])
{
	json_object* msg = NULL, *reply = NULL, *capabilities = NULL;
	const char* msg_text;
	int sock;
	struct sockaddr_un addr;
	size_t len;
	char *buffer;
	char* line = NULL, *chunked_msg_text;
	int i, alen;
	int buffer_size, buffer_len, ret, chunk_len;
	char c, chunk_len_str[12];

	if (argc != 2) {
		print_help(argv[0]);
		return (2);
	}

	/* connect to the daemon */
	sock = socket(PF_UNIX, SOCK_STREAM, 0);
	if (sock == -1) {
		fprintf(stderr, "Creating socket failed (%s)", strerror(errno));
		return (EXIT_FAILURE);
	}
	addr.sun_family = AF_UNIX;
	strncpy(addr.sun_path, SOCKET_FILENAME, sizeof(addr.sun_path));
	len = strlen(addr.sun_path) + sizeof(addr.sun_family);
	if (connect(sock, (struct sockaddr *) &addr, len) == -1) {
		fprintf(stderr, "Connecting to mod_netconf (%s) failed (%s)", SOCKET_FILENAME, strerror(errno));
		close(sock);
		return (EXIT_FAILURE);
	}

	line = malloc(sizeof(char) * BUFFER_SIZE);

	if (strcmp(argv[1], "connect") == 0) {
		/*
		 * create NETCONF session
		 */
		msg = json_object_new_object();
		json_object_object_add(msg, "type", json_object_new_int(MSG_CONNECT));
		readline(&line, &len, "Hostname: ");
		json_object_object_add(msg, "host", json_object_new_string(line));
		readline(&line, &len, "Port: ");
		json_object_object_add(msg, "port", json_object_new_string(line));
		readline(&line, &len, "Username: ");
		json_object_object_add(msg, "user", json_object_new_string(line));
		system("stty -echo");
		readline(&line, &len, "Password: ");
		system("stty echo");
		printf("\n");
		json_object_object_add(msg, "pass", json_object_new_string(line));

		/* clean read password - it is needless because we have a copy in json... :-( */
		memset(line, 'X', len);
		free(line);
		line = NULL;

		printf("Supported capabilities\n");
		capabilities = json_object_new_array();
		json_object_object_add(msg, "capabilities", capabilities);
		while (1) {
			readline(&line, &len, "Next capability (empty for end): ");
			if (strlen(line) == 0) {
				break;
			}
			json_object_array_add (capabilities, json_object_new_string(line));
		}
	} else if (strcmp(argv[1], "disconnect") == 0) {
		/*
		 * Close NETCONF session
		 */
		msg = json_object_new_object();
		json_object_object_add(msg, "type", json_object_new_int(MSG_DISCONNECT));
		readline(&line, &len, "Session: ");
		json_object_object_add(msg, "session", json_object_new_string(line));
	} else if (strcmp(argv[1], "copy-config") == 0) {
		/*
		 * NETCONF <copy-config>
		 */
		msg = json_object_new_object();
		json_object_object_add(msg, "type", json_object_new_int(MSG_COPYCONFIG));
		readline(&line, &len, "Session: ");
		json_object_object_add(msg, "session", json_object_new_string(line));
		readline(&line, &len, "Source (running|startup|candidate): ");
		if (strlen(line) > 0) {
			json_object_object_add(msg, "source", json_object_new_string(line));
		} else {
			readmultiline(&line, &len, "Configuration data (ending with CTRL+D): ");
			json_object_object_add(msg, "config", json_object_new_string(line));
		}
		readline(&line, &len, "Target (running|startup|candidate): ");
		json_object_object_add(msg, "target", json_object_new_string(line));
	} else if (strcmp(argv[1], "delete-config") == 0) {
		/*
		 * NETCONF <delete-config>
		 */
		msg = json_object_new_object();
		json_object_object_add(msg, "type", json_object_new_int(MSG_DELETECONFIG));
		readline(&line, &len, "Session: ");
		json_object_object_add(msg, "session", json_object_new_string(line));
		readline(&line, &len, "Target (running|startup|candidate): ");
		json_object_object_add(msg, "target", json_object_new_string(line));
	} else if (strcmp(argv[1], "edit-config") == 0) {
		/*
		 * NETCONF <edit-config>
		 */
		msg = json_object_new_object();
		json_object_object_add(msg, "type", json_object_new_int(MSG_EDITCONFIG));
		readline(&line, &len, "Session: ");
		json_object_object_add(msg, "session", json_object_new_string(line));
		readline(&line, &len, "Target (running|startup|candidate): ");
		json_object_object_add(msg, "target", json_object_new_string(line));
		readline(&line, &len, "Default operation (merge|replace|none): ");
		if (strlen(line) > 0) {
			json_object_object_add(msg, "default-operation", json_object_new_string(line));
		}
		readline(&line, &len, "Error option (stop-on-error|continue-on-error|rollback-on-error): ");
		if (strlen(line) > 0) {
			json_object_object_add(msg, "error-option", json_object_new_string(line));
		}
		readmultiline(&line, &len, "Configuration data (ending with CTRL+D): ");
		json_object_object_add(msg, "config", json_object_new_string(line));
	} else if (strcmp(argv[1], "get") == 0) {
		/*
		 * NETCONF <get>
		 */
		msg = json_object_new_object();
		json_object_object_add(msg, "type", json_object_new_int(MSG_GET));
		readline(&line, &len, "Session: ");
		json_object_object_add(msg, "session", json_object_new_string(line));
		readmultiline(&line, &len, "Filter (ending with CTRL+D): ");
		if (strlen(line) > 0) {
			json_object_object_add(msg, "filter", json_object_new_string(line));
		}
	} else if (strcmp(argv[1], "get-config") == 0) {
		/*
		 * NETCONF <get-config>
		 */
		msg = json_object_new_object();
		json_object_object_add(msg, "type", json_object_new_int(MSG_GETCONFIG));
		readline(&line, &len, "Session: ");
		json_object_object_add(msg, "session", json_object_new_string(line));
		readline(&line, &len, "Source (running|startup|candidate): ");
		json_object_object_add(msg, "source", json_object_new_string(line));
		readmultiline(&line, &len, "Filter (ending with CTRL+D): ");
		if (strlen(line) > 0) {
			json_object_object_add(msg, "filter", json_object_new_string(line));
		}
	} else if (strcmp(argv[1], "kill-session") == 0) {
		/*
		 * NETCONF <kill-session>
		 */
		msg = json_object_new_object();
		json_object_object_add(msg, "type", json_object_new_int(MSG_KILL));
		readline(&line, &len, "Session: ");
		json_object_object_add(msg, "session", json_object_new_string(line));
		readline(&line, &len, "Kill session with ID: ");
		json_object_object_add(msg, "session-id", json_object_new_string(line));
	} else if (strcmp(argv[1], "lock") == 0) {
		/*
		 * NETCONF <lock>
		 */
		msg = json_object_new_object();
		json_object_object_add(msg, "type", json_object_new_int(MSG_LOCK));
		readline(&line, &len, "Session: ");
		json_object_object_add(msg, "session", json_object_new_string(line));
		readline(&line, &len, "Target (running|startup|candidate): ");
		json_object_object_add(msg, "target", json_object_new_string(line));
	} else if (strcmp(argv[1], "unlock") == 0) {
		/*
		 * NETCONF <unlock>
		 */
		msg = json_object_new_object();
		json_object_object_add(msg, "type", json_object_new_int(MSG_UNLOCK));
		readline(&line, &len,"Session: ");
		json_object_object_add(msg, "session", json_object_new_string(line));
		readline(&line, &len, "Target (running|startup|candidate): ");
		json_object_object_add(msg, "target", json_object_new_string(line));
	} else if (strcmp(argv[1], "info") == 0) {
		/*
		 * Get information about NETCONF session
		 */
		msg = json_object_new_object();
		json_object_object_add(msg, "type", json_object_new_int(MSG_INFO));
		readline(&line, &len, "Session: ");
		json_object_object_add(msg, "session", json_object_new_string(line));
	} else if (strcmp(argv[1], "generic") == 0) {
		/*
		 * Generic NETCONF request
		 */
		msg = json_object_new_object();
		json_object_object_add(msg, "type", json_object_new_int(MSG_GENERIC));
		readline(&line, &len, "Session: ");
		json_object_object_add(msg, "session", json_object_new_string(line));
		readmultiline(&line, &len, "NETCONF <rpc> content (ending with CTRL+D): ");
		json_object_object_add(msg, "content", json_object_new_string(line));
	} else {
		/*
		 * Unknown request
		 */
		fprintf(stderr, "Unknown command %s\n", argv[1]);
		close(sock);
		return (EXIT_FAILURE);
	}

	/* send the message */
	if (msg != NULL) {
		msg_text = json_object_to_json_string(msg);
		asprintf (&chunked_msg_text, "\n#%d\n%s\n##\n", (int)strlen(msg_text), msg_text);

		if (json_object_object_get(msg, "pass") == NULL) {
			/* print message only if it does not contain password */
			printf("Sending: %s\n", msg_text);
		}
		send(sock, chunked_msg_text, strlen(chunked_msg_text) + 1, 0);

		json_object_put(msg);
		free (chunked_msg_text);
	} else {
		close(sock);
		return (EXIT_FAILURE);
	}

	/* read json in chunked framing */
	buffer_size = 0;
	buffer_len = 0;
	buffer = NULL;
	while (1) {
		/* read chunk length */
		if ((ret = recv (sock, &c, 1, 0)) != 1 || c != '\n') {
			free (buffer);
			buffer = NULL;
			break;
		}
		if ((ret = recv (sock, &c, 1, 0)) != 1 || c != '#') {
			free (buffer);
			buffer = NULL;
			break;
		}
		i=0;
		memset (chunk_len_str, 0, 12);
		while ((ret = recv (sock, &c, 1, 0) == 1 && (isdigit(c) || c == '#'))) {
			if (i==0 && c == '#') {
				if (recv (sock, &c, 1, 0) != 1 || c != '\n') {
					/* end but invalid */
					free (buffer);
					buffer = NULL;
				}
				/* end of message, double-loop break */
				goto msg_complete;
			}
			chunk_len_str[i++] = c;
		}
		if (c != '\n') {
			free (buffer);
			buffer = NULL;
			break;
		}
		if ((chunk_len = atoi (chunk_len_str)) == 0) {
			free (buffer);
			buffer = NULL;
			break;
		}
		buffer_size += chunk_len+1;
		buffer = realloc (buffer, sizeof(char)*buffer_size);
		if ((ret = recv (sock, buffer+buffer_len, chunk_len, 0)) == -1 || ret != chunk_len) {
			free (buffer);
			buffer = NULL;
			break;
		}
		buffer_len += ret;
	}
msg_complete:

	if (buffer != NULL) {
		reply = json_tokener_parse(buffer);
		free (buffer);
	} else {
		reply = NULL;
	}

	printf("Received:\n");
	if (reply == NULL) {
		printf("(null)\n");
	} else {
		json_object_object_foreach(reply, key, value) {
			printf("Key: %s, Value: ", key);
			switch (json_object_get_type(value)) {
			case json_type_string:
				printf("%s\n", json_object_get_string(value));
				break;
			case json_type_int:
				printf("%d\n", json_object_get_int(value));
				break;
			case json_type_array:
				printf("\n");
				alen = json_object_array_length(value);
				for (i = 0; i < alen; i++) {
					printf("\t(%d) %s\n", i, json_object_get_string(json_object_array_get_idx(value, i)));
				}
				break;
			default:
				printf("\n");
				break;
			}
		}
		json_object_put(reply);
	}
	close(sock);
	free(line);

	return (EXIT_SUCCESS);
}
