/* ====================================================================
 * FTD4Linux Software License, Version 1.0
 *
 * Copyright (c) 2000-2004 The FTD4Linux Development Team.  All rights
 * reserved.
 *
 * 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. The end-user documentation included with the redistribution,
 *    if any, must include the following acknowledgment:
 *       "This product includes software developed by the
 *        FTD4Linux Development Team (http://www.ftd4linux.2y.net/)."
 *    Alternately, this acknowledgment may appear in the software itself,
 *    if and wherever such third-party acknowledgments normally appear.
 *
 * 4. The names "FTD" and "FTD4Linux" must
 *    not be used to endorse or promote products derived from this
 *    software without prior written permission. For written
 *    permission, please contact alguno@ftd4linux.2y.net.
 *
 * 5. Products derived from this software may not be called "FTD4Linux",
 *    nor may "FTD4Linux" appear in their name, without prior written
 *    permission of the FTD4Linux Development Team.
 *
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED 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 FTD4LINUX DEVELOPMENT TEAM OR
 * ITS 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.
 */

#include <stdio.h>
#include <stdlib.h>
#include "ftd_gui_main.h"
#include "ftd_gui_center.h"
#include "ftd_gui_worksheet.h"
#include "ftd_gui_center_eventinfo.h"
#include "ftd_gui_kudos.h"
#include "ftd_gui_message.h"
#include "ftd_gui_errhandler.h"
#include "ftd_gui_xslt.h"
#include "ftd_gui_browser.h"
#include "ftd_gui_parse.h"

static void  ftd_gui_center_eventinfo_load_finished (GtkWidget *caller, gpointer data);

FtdGuiCenterEventInfo *
ftd_gui_center_eventinfo_new(int post_id)
{
    GtkWidget *tabby;
    FtdGuiCenterEventInfo *eventinfo;
    FtdEvent *event;
    char bericht[64];
    int teller;
    int pagenum = -1;
    char *volledigeFilename;
    char *tmp;
    gsize len;
    FtdString *inhoud;
    FtdString *inhoud2;
    char *data_dir;
    FTDEventlist *eventlist;

    if (ftd_config_get()->geenTabbedBrowsing) {
        if (gui->worksheet->center->eventinfo[0]) {
            ftd_gui_center_eventinfo_sluiten(gui->worksheet->center->eventinfo[0]->cmdclose, NULL);
        }
    }

    /* Controle of er niet reeds een venster open is met info over de gevraagde posting */
    for (teller = 0; teller < MAX_EVENT_INFO; teller++) {
        if (gui->worksheet->center->eventinfo[teller] == NULL) {
            if (pagenum == -1) {
                pagenum = teller;
            }
            continue;
        }

        if (gui->worksheet->center->eventinfo[teller]->post_id == post_id) {
            int page = gtk_notebook_page_num(GTK_NOTEBOOK(gui->worksheet->center->widget), gui->worksheet->center->eventinfo[teller]->widget);
            gtk_notebook_set_current_page (GTK_NOTEBOOK (gui->worksheet->center->widget), page);

            return NULL;
        }

        if (teller == MAX_EVENT_INFO - 1 && pagenum == -1) {
            char bericht[1024];
            snprintf(bericht, sizeof(bericht), "Er mogen maximaal %i postings tegelijk geopend zijn\n"
                                               "Gelieve eerst een te sluiten alvorens een nieuwe proberen te openen.", MAX_EVENT_INFO);

            ftd_gui_dialog_show(NULL, bericht, gui->window, FALSE);
            return NULL;
        }
    }

    eventlist = ftd_eventlist_get();
    event = ftd_eventlist_lookup_id(eventlist, post_id);
    g_object_unref(eventlist);

    eventinfo = (FtdGuiCenterEventInfo *) g_malloc0(sizeof(FtdGuiCenterEventInfo));
    eventinfo->post_id = post_id;
    eventinfo->pagenum = pagenum;

    gui->worksheet->center->eventinfo[pagenum] = eventinfo;

    /* Initialiseer de inhoud van het schermpie */
    eventinfo->browser_data = ftd_gui_browser_new(gui->worksheet->center->widget, FALSE);
    eventinfo->widget = ftd_gui_browser_get_widget(eventinfo->browser_data);

    /* Voeg een pagina toe aan de notebook, met bijbehorend sluit-knopje */
    if (event && event->title) {
        FtdString *tmp = ftd_string_replace(event->title, "&amp;", "&");
        if (ftd_string_length(tmp) > 20) {
            char title[21];
            strncpy(title, ftd_string_value(tmp), 21); // Dit levert onder Win32 een truncate melding op, maar dat is ook de bedoeling in deze situatie
            title[20] = '\0';
            snprintf(bericht, sizeof(bericht), "%s...", title);
        } else {
            snprintf(bericht, sizeof(bericht), "%s", ftd_string_value(tmp));
        }

        ftd_event_free(event);
        event = NULL;
    } else {
        snprintf(bericht, sizeof(bericht), "FTD #%i", post_id);
    }

    eventinfo->label = gtk_label_new (bericht);
    gtk_widget_show (eventinfo->label);

    tabby = gtk_hbox_new(FALSE, 3);
    eventinfo->cmdclose = gtk_button_new();
    gtk_widget_set_size_request(GTK_WIDGET(eventinfo->cmdclose), 16, 16);
    gtk_container_add(GTK_CONTAINER(eventinfo->cmdclose), gtk_image_new_from_stock(GTK_STOCK_CLOSE, GTK_ICON_SIZE_MENU));
    gtk_widget_show_all (eventinfo->cmdclose);
    gtk_button_set_relief(GTK_BUTTON(eventinfo->cmdclose), GTK_RELIEF_NONE);

    volledigeFilename = ftd_file_parse_data_dir("/images/loading.gif");
    eventinfo->loading_icon = gtk_image_new_from_file(volledigeFilename);
    g_free(volledigeFilename);
    gtk_widget_show(eventinfo->loading_icon);

    gtk_box_pack_start(GTK_BOX(tabby), eventinfo->loading_icon, FALSE, FALSE, 0);
    gtk_box_pack_start(GTK_BOX(tabby), eventinfo->label, TRUE, TRUE, 0);
    gtk_box_pack_start(GTK_BOX(tabby), eventinfo->cmdclose, FALSE, FALSE, 0);

    //gtk_notebook_append_page(GTK_NOTEBOOK(gui->worksheet->center->widget), ftd_gui_browser_get_widget(eventinfo->browser_data), tabby);
    gtk_notebook_set_tab_label (GTK_NOTEBOOK (gui->worksheet->center->widget),
                                gtk_notebook_get_nth_page (
                                    GTK_NOTEBOOK (gui->worksheet->center->widget), -1), tabby);

    /* Signal handler voor het afsluiten knopje */
    g_signal_connect (GTK_WIDGET (eventinfo->cmdclose), "clicked", G_CALLBACK(ftd_gui_center_eventinfo_sluiten), NULL);

    /* Signal handler om de url klikjes vanuit het componentje op te vangen */
    ftd_gui_browser_set_link_clicked_cb(eventinfo->browser_data, ftd_gui_center_eventinfo_open_uri, NULL);

    //ftd_gui_center_eventinfo_show(ftd_gui_browser_get_widget(eventinfo->browser_data), NULL);

    /* Trek gelijk de aandacht */
//    gtk_widget_grab_focus (GTK_WIDGET (eventinfo->widget));
    if (!ftd_config_get()->openPostinfoOpAchtergrond) {
        gtk_notebook_set_current_page (GTK_NOTEBOOK (gui->worksheet->center->widget), -1);
    }

    // Open een tijdelijke pagina totdat de definitieve pagina gegenereerd is
    volledigeFilename = ftd_file_parse_data_dir("/postinfo.html");
    if (!g_file_get_contents(volledigeFilename, &tmp, &len, NULL)) {
        char *msg = g_strdup_printf("Het openen van '%s' is mislukt. Dit is een teken dat de OpenFTD installatie niet volledig is!", volledigeFilename);
        ftd_gui_dialog_show(NULL, msg, gui->window, TRUE);
        gtk_main_quit();
        return;
    }

    // In de postinfo.html staat nog een {$imgDir} vermeld. Deze moet
    // vervangen worden door de echte imgDir
#ifdef WIN32
    {
        char *data_dir2;
        data_dir = ftd_file_parse_data_filename("images/");
        data_dir2 = g_strdup_printf("file://%s\\", data_dir);
        inhoud = ftd_string_new(tmp);
        inhoud2 = ftd_string_replace(inhoud, "{$imgDir}/", data_dir2);
        g_free(data_dir2);
    }
#else
    data_dir = ftd_file_parse_data_filename("images");
    inhoud = ftd_string_new(tmp);
    inhoud2 = ftd_string_replace(inhoud, "{$imgDir}", data_dir);
#endif

    ftd_file_save(HTML_EVENTINFO_FILE, inhoud2, FALSE);

    ftd_string_free(inhoud);
    ftd_string_free(inhoud2);
    g_free(volledigeFilename);
    g_free(data_dir);
    g_free(tmp);

    eventinfo->is_waiting_for_data = TRUE;

    ftd_gui_browser_set_load_finished_cb(eventinfo->browser_data, ftd_gui_center_eventinfo_load_finished, eventinfo);

    ftd_gui_browser_navigate(eventinfo->browser_data, HTML_EVENTINFO_FILE);

    return eventinfo;
}

static void
ftd_gui_center_eventinfo_load_finished (GtkWidget *caller, gpointer data)
{
    FtdGuiCenterEventInfo *eventinfo = (FtdGuiCenterEventInfo *) data;

    if (eventinfo->is_waiting_for_data) {
        return;
    }

    // Verberg het 'loading' icoontje
    gtk_widget_hide(eventinfo->loading_icon);
}

void
ftd_gui_center_eventinfo_show (GtkWidget *caller, gpointer data)
{
    FtdGuiCenterEventInfo *eventinfo;
    int teller;
    gboolean found = FALSE;

    g_assert(gui);
    g_assert(gui->worksheet);
    g_assert(gui->worksheet->center);

    /* Achterhaal waar we precies zitten */
    for (teller = 0; teller < MAX_EVENT_INFO; teller++) {
        if (gui->worksheet->center->eventinfo[teller]) {
            if (caller == gui->worksheet->center->eventinfo[teller]->widget) {
                found = TRUE;
                break;
            }
        }
    }

    if (!found) {
        g_warning("ftd_gui_center_eventinfo_show(): Kan juiste postinfo niet vinden\n");
        return;
    }

    eventinfo = gui->worksheet->center->eventinfo[teller];

    eventinfo->is_waiting_for_data = FALSE;

    ftd_gui_browser_navigate(eventinfo->browser_data, HTML_EVENTINFO_FILE);
}

void
ftd_gui_center_eventinfo_sluiten (GtkWidget *caller, gpointer data)
{
    FtdGuiCenterEventInfo *eventinfo;
    int teller;
    gboolean found = FALSE;

    g_assert(gui);
    g_assert(gui->worksheet);
    g_assert(gui->worksheet->center);

    /* Achterhaal waar we precies zitten */
    for (teller = 0; teller < MAX_EVENT_INFO; teller++) {
        if (gui->worksheet->center->eventinfo[teller]) {
            if (caller == gui->worksheet->center->eventinfo[teller]->cmdclose) {
                found = TRUE;
                break;
            }
        }
    }

    if (!found) {
        g_warning("ftd_gui_center_eventinfo_sluiten(): Kan juiste postinfo niet vinden\n");
        return;
    }

    eventinfo = gui->worksheet->center->eventinfo[teller];

    /* Verwijder de pagina uit de notebook waar het schermpje in geplaatst is */
    ftd_gui_browser_destroy(eventinfo->browser_data);
    eventinfo->browser_data = NULL;
    eventinfo->widget = NULL;

    // Voorkom een threading probleem
    if (!eventinfo->still_in_use) {
        FTDEventlist *eventlist = ftd_eventlist_get();
        ftd_eventlist_set_posting_is_active(eventlist, eventinfo->post_id, FALSE);
        g_object_unref(eventlist);

        g_free(eventinfo);
    } else {
        eventinfo->can_be_destroyed = TRUE;
    }

    /* Verwijder deze postinfo uit de core */
    gui->worksheet->center->eventinfo[teller] = NULL;
}

gboolean
ftd_gui_center_eventinfo_open_uri (GtkWidget *embed, const char *uri, gpointer data)
{
    FtdGuiCenterEventInfo *eventinfo;
    int teller;
    gboolean found = FALSE;
    char *begin;

    g_assert(gui);
    g_assert(gui->worksheet);
    g_assert(gui->worksheet->center);

    /* Achterhaal waar we precies zitten */
    for (teller = 0; teller < MAX_EVENT_INFO; teller++) {
        if (gui->worksheet->center->eventinfo[teller]) {
            if (embed == gui->worksheet->center->eventinfo[teller]->widget) {
                found = TRUE;
                break;
            }
        }
    }

    if (!found) {
        g_warning("ftd_gui_center_eventinfo_open_uri(): Kan juiste postinfo niet vinden\n");
        return TRUE;
    }

    eventinfo = gui->worksheet->center->eventinfo[teller];

    /* =======================
     * #nzb
     * =======================
     */
    begin = strstr(uri, "#nzb");
    if (begin) {
        ftd_gui_nzb_popup(eventinfo->post_id);
        return TRUE;
    }

    /* =======================
     * #post
     * =======================
     */
    begin = strstr(uri, "#post");
    if (begin) {
        ftd_gui_center_eventlist_open_uri(embed, uri, data);

        return TRUE;
    }

    /* =======================
     * Externe URL's (#link)
     * =======================
     */
    begin = strstr(uri, "#link");
    if (begin) {
        begin += 5;

        ftd_gui_center_launch_browser(begin);

        return TRUE;
    }

    /* =======================
     * #ftdmail
     * =======================
    */
    if (strstr(uri, "#ftdmail")) {
        char *user = strstr(uri, "#ftdmail") + 8;
        ftd_gui_message_new(user, "", NULL, 0, NULL);
        return TRUE;
    }

    /* =======================
     * #forumpost
     * =======================
     */
    if (strstr(uri, "#forumpost")) {
        ftd_gui_message_new("", "", NULL, eventinfo->post_id, NULL);
        return TRUE;
    }

    /* =======================
     * #quote
     * =======================
     */
    if (strstr(uri, "#quote")) {
        int messId = atoi(strstr(uri, "#quote") + 6);
        FTDEventlist *eventlist;
        FtdEvent *event;
        FtdEventForumReactie *reactie = NULL;
        FtdList *list;

        eventlist = ftd_eventlist_get();
        event = ftd_eventlist_lookup_id(eventlist, eventinfo->post_id);
        g_object_unref(eventlist);

        g_assert(event->forum);

        list = event->forum->forum_reacties;
        while (list) {
            reactie = ftd_list_value(list);

            if (reactie->messageId == messId) {
                break;
            }

            reactie = NULL;

            list = ftd_list_next(list);
        }

        ftd_gui_message_new("", "", NULL, eventinfo->post_id, reactie);

        ftd_event_free(event);

        return TRUE;
    }

    /* =======================
     * #info
     * =======================
    */
    begin = strstr(uri, "#info");
    if (begin) {
        ftd_gui_profile_show(begin + 5);

        return TRUE;
    }

    /* =======================
     * #kudos
     * =======================
     */
    if (strstr(uri, "#kudos")) {
        int saldo, aantal;
        FtdErrorCode retval;
        char *errmsg = NULL;

        retval = ftd_kudos_get(eventinfo->post_id, &saldo, &aantal, &errmsg);
        if (retval != ERROR_NONE) {
            ftd_gui_errhandler(gui->window, FTD_ONDERDEEL_KUDOS_GET, retval, errmsg);
            return TRUE;
        }
        ftd_gui_kudos_new(eventinfo->post_id, saldo, aantal);
        return TRUE;
    }

    /* ======================
     * #report
     * ======================
     */
    if (strstr(uri, "#report")) {
        int messId = atoi(strstr(uri, "#report") + 7);

        ftd_gui_modje_create(eventinfo->post_id, messId);

        return TRUE;
    }

    if (strstr(uri, "#x")) {
        ftd_gui_dialog_show(NULL, "Not yet implemented", gui->window, TRUE);
        return TRUE;
    }

    /* =======================
     * #showkudos
     * =======================
    */
    if (strstr(uri, "#showkudos")) {
        ftd_gui_dialog_show(NULL, "Not yet implemented", gui->window, TRUE);
        return TRUE;
    }

    /* =======================
     * #dllist
     * =======================
    */
    if (strstr(uri, "#dllist")) {
        if (ftd_watchlist_is_in_list(eventinfo->post_id)) {
            char * path_tmp = NULL;
            FtdString * path_tmp2 = NULL;
            FtdString * path_tmp3 = NULL;
            FtdString * path_tmp4 = NULL;
            char * path = NULL;
            char buf[2048];
            char buf2[1024];

            // Postid is reeds aanwezig in de watchlist -> verwijderen
            ftd_watchlist_remove(eventinfo->post_id);

            // Pas het watchlist icoontje in de geopende postinfo aan
            path_tmp = ftd_file_parse_data_dir(NULL);
            path_tmp2 = ftd_string_new(path_tmp);
            path_tmp3 = ftd_string_replace(path_tmp2, " ", "%20");
            path_tmp4 = ftd_string_replace(path_tmp3, "\\", "/");
            path = ftd_string_value(path_tmp4);
            snprintf(buf, sizeof(buf), "file://%s/images/b4-1.bmp", path);
            ftd_string_free(path_tmp4);
            ftd_string_free(path_tmp3);
            ftd_string_free(path_tmp2);
            g_free(path_tmp);

            ftd_gui_browser_set_element_attribute(eventinfo->browser_data, "dlbut", "src", buf);

            // Pas het watchlist icoontje in de postlist aan
            path_tmp = ftd_file_parse_data_dir(NULL);
            path_tmp2 = ftd_string_new(path_tmp);
            path_tmp3 = ftd_string_replace(path_tmp2, " ", "%20");
            path_tmp4 = ftd_string_replace(path_tmp3, "\\", "/");
            path = ftd_string_value(path_tmp4);
            snprintf(buf, sizeof(buf), "file://%s/images/dlb1a.bmp", path);
            ftd_string_free(path_tmp4);
            ftd_string_free(path_tmp3);
            ftd_string_free(path_tmp2);
            g_free(path_tmp);

            snprintf(buf2, sizeof(buf2), "p%d", eventinfo->post_id);

#ifdef NO_EXTERNAL_BROWSER
            if (gui->worksheet->center->eventlist) {
                ftd_gui_center_eventlist_toggle_watchlist (eventinfo->post_id);
            }
#else
            if( gui->worksheet->center->eventlist ) {
                ftd_gui_browser_set_element_attribute( gui->worksheet->center->eventlist->browser_data, buf2, "src", buf );
            }
#endif
        } else {
            char * path_tmp = NULL;
            FtdString * path_tmp2 = NULL;
            FtdString * path_tmp3 = NULL;
            FtdString * path_tmp4 = NULL;
            char * path = NULL;
            char buf[2048];
            char buf2[1024];

            ftd_watchlist_add(eventinfo->post_id);

            // Pas het watchlist icoontje in de geopende postinfo aan
            path_tmp = ftd_file_parse_data_dir(NULL);
            path_tmp2 = ftd_string_new(path_tmp);
            path_tmp3 = ftd_string_replace(path_tmp2, " ", "%20");
            path_tmp4 = ftd_string_replace(path_tmp3, "\\", "/");
            path = ftd_string_value(path_tmp4);
            snprintf(buf, sizeof(buf), "file://%s/images/b4-3.bmp", path);
            ftd_string_free(path_tmp4);
            ftd_string_free(path_tmp3);
            ftd_string_free(path_tmp2);
            g_free(path_tmp);

            ftd_gui_browser_set_element_attribute(eventinfo->browser_data, "dlbut", "src", buf);

            // Pas het watchlist icoontje in de postlist aan
            path_tmp = ftd_file_parse_data_dir(NULL);
            path_tmp2 = ftd_string_new(path_tmp);
            path_tmp3 = ftd_string_replace(path_tmp2, " ", "%20");
            path_tmp4 = ftd_string_replace(path_tmp3, "\\", "/");
            path = ftd_string_value(path_tmp4);
            snprintf(buf, sizeof(buf), "file://%s/images/dlb2a.bmp", path);
            ftd_string_free(path_tmp4);
            ftd_string_free(path_tmp3);
            ftd_string_free(path_tmp2);
            g_free(path_tmp);

            snprintf(buf2, sizeof(buf2), "p%d", eventinfo->post_id);

#ifdef NO_EXTERNAL_BROWSER
            if (gui->worksheet->center->eventlist) {
                ftd_gui_center_eventlist_toggle_watchlist (eventinfo->post_id);
            }
#else
            if( gui->worksheet->center->eventlist ) {
                ftd_gui_browser_set_element_attribute( gui->worksheet->center->eventlist->browser_data, buf2, "src", buf );
            }
#endif
        }

        return TRUE;
    }

    return FALSE;
}

/**
 * Verwerkt de informatie van een event om naar een nette HTML-pagina.
 *
 * @arg     postid      Het FTD-nummer van het event dat gepresenteerd moet worden.
 *
 * @return  Een code die aangeeft of het goed ging.
 */
FtdErrorCode
ftd_gui_center_eventinfo_process(int postid)
{
    FtdString *res;
    FtdString *tmp;
    FtdEvent *event;
    char buf[2048];
    char *path;
    char *path_tmp;
    FtdString *path_tmp2;
    FtdString *path_tmp3;
    FtdString *path_tmp4;
    FTDEventlist *eventlist;
    char *xslt_path;

    eventlist = ftd_eventlist_get();
    event = ftd_eventlist_lookup_id(eventlist, postid);
    g_object_unref(eventlist);

    if (!event) {
        g_print(__FILE__ ":%i postid = %i\n", __LINE__, postid);
        return ERROR_ORIGEVENT;
    }

    // Plak alle event info tesamen
    res = ftd_string_new("<EventInfo>\n");

    path_tmp = ftd_file_parse_data_dir(NULL);
    path_tmp2 = ftd_string_new(path_tmp);
    path_tmp3 = ftd_string_replace(path_tmp2, " ", "%20");
    path_tmp4 = ftd_string_replace(path_tmp3, "\\", "/");
    path = ftd_string_value(path_tmp4);
    snprintf(buf, sizeof(buf), RANZIGE_JAVASCRIPT_POSTINFO, path, path, path, path, path, path);
    res = ftd_string_append(res, buf);
    ftd_string_free(path_tmp4);
    ftd_string_free(path_tmp3);
    ftd_string_free(path_tmp2);
    g_free(path_tmp);

    // Event info
    tmp = ftd_events_sort_print(event, FALSE, 0, ftd_gui_parse);
    res = ftd_string_append(res, ftd_string_value(tmp));
    ftd_string_free(tmp);

    res = ftd_string_append(res, "</EventInfo>\n");

    ftd_event_free(event);

    xslt_path = XSLT_TYPE_POSTINFO;
    if (ftd_gui_xslt_process(res, xslt_path, HTML_EVENTINFO_FILE) != 0) {
        g_warning("ftd_gui_center_eventinfo_process(): foutje...kan eventinfo niet parsen\n");
        ftd_string_free (res);
        g_free(xslt_path);
        return ERROR_PARSE;
    }

    g_free(xslt_path);
    ftd_string_free(res);

    return ERROR_NONE;
}
