/*
 * main.h
 * 
 * Copyright (C) 2006  Josef Kufner <jk@myserver.cz>
 * 
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 */
#ifndef JK_MAIN_H
#define JK_MAIN_H

#include <loudmouth/loudmouth.h>
#include "message.h"

/* verbose levels */
enum {
	D_ERR = 0, D_NORMAL, D_VERBOSE, D_DEBUG, D__MAX
};
/* null terminated array of verbose level names */
extern gchar *verbose_level_str[D__MAX + 1];

/*
 * Debuging staff
 *
 */
#define PROG_NAME	"netboard-jabber"

#define print_msg(level, msg, arg...)					\
{									\
	if (level == D_ERR)						\
		show_error(msg, ##arg);					\
	if (level <= verbose) {						\
		if (level >= D_DEBUG) {					\
			g_printerr(PROG_NAME ":%s:%d:%s " msg "\n",	\
					__FILE__, __LINE__, __func__,	\
					##arg);				\
		} else {						\
			g_printerr(PROG_NAME ": " msg "\n", ##arg );	\
		}							\
	}								\
}                                                                                                                                                                         

/* global variables */
extern gchar *j_configure;
extern gchar *j_profile;
extern gchar *j_server;
extern gint j_port;
extern gchar *j_username;
extern gchar *j_nick;
extern gchar *j_password;
extern gchar *j_resource;
extern gchar *j_room;
extern gchar *j_room_passwd;
extern gchar *j_fingerprint;
extern int j_use_ssl, j_lax_ssl;
extern gchar *j_room_complete, *j_from_complete;
extern gchar *j_dbg_level_string;
extern gint verbose_flag;
extern gint verbose;
extern gchar expected_fingerprint[20];

extern LmConnection *connection;
extern GMainContext *main_context;
extern GMainLoop *main_loop;

struct s_opt_query {
	char *opt;
	MESSAGE_ITEM_TYPE type;
	void *var;
	int received;
};
extern struct s_opt_query opt_query[];

extern gchar start_time[32];

gchar *get_part_name(const gchar *username);
gchar *print_finger(const gchar *fpr, unsigned int size);

void open_connection(void);
void m_send(LmMessage *m, LmConnection *connection);

void show_error(char *fmt, ...);

#endif

