<commit_before>/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
/*
 * eas-daemon
 * Copyright (C)  2011 <>
 * 
 * eas-daemon 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 3 of the License, or
 * (at your option) any later version.
 * 
 * eas-daemon 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.
 * 
 * You should have received a copy of the GNU General Public License along
 * with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#include "eas-connection.h"
#include <libsoup/soup.h>

#include <wbxml/wbxml.h>
#include <libedataserver/e-flag.h>
#include <libxml/xmlreader.h> // xmlDoc

#include "eas-accounts.h"
#include "eas-connection-errors.h"

// List of includes for each request type
#include "eas-sync-folder-hierarchy-req.h"
#include "eas-provision-req.h"
#include "eas-sync-req.h"
#include "eas-get-email-body-req.h"
#include "eas-get-email-attachment-req.h"
#include "eas-send-email-req.h"
#include "eas-delete-email-req.h"
#include "eas-update-calendar-req.h"
#include "eas-update-email-req.h"
#include "eas-add-calendar-req.h"

struct _EasConnectionPrivate
{
	SoupSession* soup_session;
	GThread* soup_thread;
	GMainLoop* soup_loop;
	GMainContext* soup_context;
	
	gchar* server_uri;
	gchar* username;
	gchar* password;

	gchar* device_type;
	gchar* device_id;

	gchar* policy_key;

	gchar* request_cmd;
	xmlDoc* request_doc;
	EasRequestBase* request;
	GError **request_error;
};

#define EAS_CONNECTION_PRIVATE(o)  (G_TYPE_INSTANCE_GET_PRIVATE ((o), EAS_TYPE_CONNECTION, EasConnectionPrivate))

static void connection_authenticate (SoupSession *sess, SoupMessage *msg, 
                                     SoupAuth *auth, gboolean retrying, 
                                     gpointer data);
static gpointer eas_soup_thread (gpointer user_data);
static void handle_server_response (SoupSession *session, SoupMessage *msg, gpointer data);
static void wbxml2xml(const WB_UTINY *wbxml, const WB_LONG wbxml_len, WB_UTINY **xml, WB_ULONG *xml_len);

G_DEFINE_TYPE (EasConnection, eas_connection, G_TYPE_OBJECT);

static void
eas_connection_init (EasConnection *self)
{
	EasConnectionPrivate *priv;
	self->priv = priv = EAS_CONNECTION_PRIVATE(self);

	g_debug("eas_connection_init++");

    priv->soup_context = g_main_context_new ();
    priv->soup_loop = g_main_loop_new (priv->soup_context, FALSE);

    priv->soup_thread = g_thread_create (eas_soup_thread, priv, TRUE, NULL);
    
    /* create the SoupSession for this connection */
    priv->soup_session = 
        soup_session_async_new_with_options (SOUP_SESSION_USE_NTLM, 
                                             TRUE, 
                                             SOUP_SESSION_ASYNC_CONTEXT, 
                                             priv->soup_context, 
                                             NULL);

    g_signal_connect (priv->soup_session, 
                      "authenticate", 
                      G_CALLBACK(connection_authenticate), 
                      self);<commit_msg>fix build error after merge<commit_after>/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
/*
 * eas-daemon
 * Copyright (C)  2011 <>
 * 
 * eas-daemon 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 3 of the License, or
 * (at your option) any later version.
 * 
 * eas-daemon 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.
 * 
 * You should have received a copy of the GNU General Public License along
 * with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#include "eas-connection.h"
#include <libsoup/soup.h>

#include <wbxml/wbxml.h>
#include <libedataserver/e-flag.h>
#include <libxml/xmlreader.h> // xmlDoc

#include "eas-accounts.h"
#include "eas-connection-errors.h"

// List of includes for each request type
#include "eas-sync-folder-hierarchy-req.h"
#include "eas-provision-req.h"
#include "eas-sync-req.h"
#include "eas-get-email-body-req.h"
#include "eas-get-email-attachment-req.h"
#include "eas-send-email-req.h"
#include "eas-delete-email-req.h"
#include "eas-update-calendar-req.h"
#include "eas-update-email-req.h"
#include "eas-add-calendar-req.h"

struct _EasConnectionPrivate
{
	SoupSession* soup_session;
	GThread* soup_thread;
	GMainLoop* soup_loop;
	GMainContext* soup_context;
	
	gchar* server_uri;
	gchar* username;
	gchar* password;

	gchar* device_type;
	gchar* device_id;

	gchar* policy_key;

	gchar* request_cmd;
	xmlDoc* request_doc;
	EasRequestBase* request;
	GError **request_error;
};

#define EAS_CONNECTION_PRIVATE(o)  (G_TYPE_INSTANCE_GET_PRIVATE ((o), EAS_TYPE_CONNECTION, EasConnectionPrivate))

static void connection_authenticate (SoupSession *sess, SoupMessage *msg, 
                                     SoupAuth *auth, gboolean retrying, 
                                     gpointer data);
static gpointer eas_soup_thread (gpointer user_data);
static void handle_server_response (SoupSession *session, SoupMessage *msg, gpointer data);
static gboolean wbxml2xml(const WB_UTINY *wbxml, const WB_LONG wbxml_len, WB_UTINY **xml, WB_ULONG *xml_len);

G_DEFINE_TYPE (EasConnection, eas_connection, G_TYPE_OBJECT);

static void
eas_connection_init (EasConnection *self)
{
	EasConnectionPrivate *priv;
	self->priv = priv = EAS_CONNECTION_PRIVATE(self);

	g_debug("eas_connection_init++");

    priv->soup_context = g_main_context_new ();
    priv->soup_loop = g_main_loop_new (priv->soup_context, FALSE);

    priv->soup_thread = g_thread_create (eas_soup_thread, priv, TRUE, NULL);
    
    /* create the SoupSession for this connection */
    priv->soup_session = 
        soup_session_async_new_with_options (SOUP_SESSION_USE_NTLM, 
                                             TRUE, 
                                             SOUP_SESSION_ASYNC_CONTEXT, 
                                             priv->soup_context, 
                                             NULL);

    g_signal_connect (priv->soup_session, 
                      "authenticate", 
                      G_CALLBACK(connection_authenticate), 
                      self);
{'fraction_non_alphanumeric': 0.10071942446043165, 'fraction_numerical': 0.002398081534772182, 'mean_word_length': 3.0126277811184607, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 24}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 20, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3084642', 'n_tokens_mistral': 2186, 'n_tokens_neox': 2065, 'n_words': 547}