/*
 * This file was generated automatically by ExtUtils::ParseXS version 3.22 from the
 * contents of GnomeVFSDNSSD.xs. Do not edit this file, edit GnomeVFSDNSSD.xs instead.
 *
 *    ANY CHANGES MADE HERE WILL BE LOST!
 *
 */

#line 1 "xs/GnomeVFSDNSSD.xs"
/*
 * Copyright (C) 2004, 2013 by the gtk2-perl team
 * 
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 * 
 * This library 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
 * Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 * $Id$
 */

#include "vfs2perl.h"
#include <gperl_marshal.h>

/* ------------------------------------------------------------------------- */

static SV *
newSVGnomeVFSDNSSDService (GnomeVFSDNSSDService *service)
{
	HV *hv = newHV ();

	if (service->name)
		hv_store (hv, "name", 4, newSVpv (service->name, 0), 0);
	if (service->type)
		hv_store (hv, "type", 4, newSVpv (service->type, 0), 0);
	if (service->domain)
		hv_store (hv, "domain", 6, newSVpv (service->domain, 0), 0);

	return newRV_noinc ((SV *) hv);
}

/* ------------------------------------------------------------------------- */

static void
hash_table_foreach (char *key, char *value, HV *hv)
{
	if (key)
		hv_store (hv, key, strlen (key),
		          value ? newSVpv (value, 0) : &PL_sv_undef, 0);
}

static SV *
newSVGnomeVFSDNSSDResolveHashTable (GHashTable *table)
{
	HV *hv = newHV ();

	if (table)
		g_hash_table_foreach (table, (GHFunc) hash_table_foreach, hv);

	return newRV_noinc ((SV *) hv);
}

/* ------------------------------------------------------------------------- */

static GPerlCallback *
vfs2perl_dns_sd_resolve_callback_create (SV *func, SV *data)
{
	return gperl_callback_new (func, data, 0, NULL, 0);
}

static void
vfs2perl_dns_sd_resolve_callback (GnomeVFSDNSSDResolveHandle *handle,
                                  GnomeVFSResult result,
                                  const GnomeVFSDNSSDService *service,
                                  const char *host,
                                  int port,
                                  const GHashTable *text,
                                  int text_raw_len,
                                  const char *text_raw,
                                  GPerlCallback* callback)
{
	dGPERL_CALLBACK_MARSHAL_SP;
	GPERL_CALLBACK_MARSHAL_INIT (callback);

	ENTER;
	SAVETMPS;

	PUSHMARK (SP);

	EXTEND (SP, 7);
	PUSHs (sv_2mortal (newSVGnomeVFSDNSSDResolveHandle (handle)));
	PUSHs (sv_2mortal (newSVGnomeVFSResult (result)));
	PUSHs (sv_2mortal (newSVGnomeVFSDNSSDService ((GnomeVFSDNSSDService *) service)));
	PUSHs (host ? sv_2mortal (newSVpv (host, 0)) : &PL_sv_undef);
	PUSHs (sv_2mortal (newSViv (port)));
	PUSHs (sv_2mortal (newSVGnomeVFSDNSSDResolveHashTable ((GHashTable *) text)));
	PUSHs (text_raw ? sv_2mortal (newSVpv (text_raw, text_raw_len)) : &PL_sv_undef);
	if (callback->data)
		XPUSHs (sv_2mortal (newSVsv (callback->data)));

	PUTBACK;

	call_sv (callback->func, G_DISCARD);

	FREETMPS;
	LEAVE;
}

/* ------------------------------------------------------------------------- */

static GPerlCallback *
vfs2perl_dns_sd_browse_callback_create (SV *func, SV *data)
{
	return gperl_callback_new (func, data, 0, NULL, 0);
}

static void
vfs2perl_dns_sd_browse_callback (GnomeVFSDNSSDBrowseHandle *handle,
                                 GnomeVFSDNSSDServiceStatus status,
                                 const GnomeVFSDNSSDService *service,
                                 GPerlCallback* callback)
{
	dGPERL_CALLBACK_MARSHAL_SP;
	GPERL_CALLBACK_MARSHAL_INIT (callback);

	ENTER;
	SAVETMPS;

	PUSHMARK (SP);

	EXTEND (SP, 3);
	PUSHs (sv_2mortal (newSVGnomeVFSDNSSDBrowseHandle (handle)));
	PUSHs (sv_2mortal (newSVGnomeVFSDNSSDServiceStatus (status)));
	PUSHs (sv_2mortal (newSVGnomeVFSDNSSDService ((GnomeVFSDNSSDService *) service)));
	if (callback->data)
		XPUSHs (sv_2mortal (newSVsv (callback->data)));

	PUTBACK;

	call_sv (callback->func, G_DISCARD);

	FREETMPS;
	LEAVE;
}

/* ------------------------------------------------------------------------- */

#line 157 "xs/GnomeVFSDNSSD.c"
#ifndef PERL_UNUSED_VAR
#  define PERL_UNUSED_VAR(var) if (0) var = var
#endif

#ifndef dVAR
#  define dVAR		dNOOP
#endif


/* This stuff is not part of the API! You have been warned. */
#ifndef PERL_VERSION_DECIMAL
#  define PERL_VERSION_DECIMAL(r,v,s) (r*1000000 + v*1000 + s)
#endif
#ifndef PERL_DECIMAL_VERSION
#  define PERL_DECIMAL_VERSION \
	  PERL_VERSION_DECIMAL(PERL_REVISION,PERL_VERSION,PERL_SUBVERSION)
#endif
#ifndef PERL_VERSION_GE
#  define PERL_VERSION_GE(r,v,s) \
	  (PERL_DECIMAL_VERSION >= PERL_VERSION_DECIMAL(r,v,s))
#endif
#ifndef PERL_VERSION_LE
#  define PERL_VERSION_LE(r,v,s) \
	  (PERL_DECIMAL_VERSION <= PERL_VERSION_DECIMAL(r,v,s))
#endif

/* XS_INTERNAL is the explicit static-linkage variant of the default
 * XS macro.
 *
 * XS_EXTERNAL is the same as XS_INTERNAL except it does not include
 * "STATIC", ie. it exports XSUB symbols. You probably don't want that
 * for anything but the BOOT XSUB.
 *
 * See XSUB.h in core!
 */


/* TODO: This might be compatible further back than 5.10.0. */
#if PERL_VERSION_GE(5, 10, 0) && PERL_VERSION_LE(5, 15, 1)
#  undef XS_EXTERNAL
#  undef XS_INTERNAL
#  if defined(__CYGWIN__) && defined(USE_DYNAMIC_LOADING)
#    define XS_EXTERNAL(name) __declspec(dllexport) XSPROTO(name)
#    define XS_INTERNAL(name) STATIC XSPROTO(name)
#  endif
#  if defined(__SYMBIAN32__)
#    define XS_EXTERNAL(name) EXPORT_C XSPROTO(name)
#    define XS_INTERNAL(name) EXPORT_C STATIC XSPROTO(name)
#  endif
#  ifndef XS_EXTERNAL
#    if defined(HASATTRIBUTE_UNUSED) && !defined(__cplusplus)
#      define XS_EXTERNAL(name) void name(pTHX_ CV* cv __attribute__unused__)
#      define XS_INTERNAL(name) STATIC void name(pTHX_ CV* cv __attribute__unused__)
#    else
#      ifdef __cplusplus
#        define XS_EXTERNAL(name) extern "C" XSPROTO(name)
#        define XS_INTERNAL(name) static XSPROTO(name)
#      else
#        define XS_EXTERNAL(name) XSPROTO(name)
#        define XS_INTERNAL(name) STATIC XSPROTO(name)
#      endif
#    endif
#  endif
#endif

/* perl >= 5.10.0 && perl <= 5.15.1 */


/* The XS_EXTERNAL macro is used for functions that must not be static
 * like the boot XSUB of a module. If perl didn't have an XS_EXTERNAL
 * macro defined, the best we can do is assume XS is the same.
 * Dito for XS_INTERNAL.
 */
#ifndef XS_EXTERNAL
#  define XS_EXTERNAL(name) XS(name)
#endif
#ifndef XS_INTERNAL
#  define XS_INTERNAL(name) XS(name)
#endif

/* Now, finally, after all this mess, we want an ExtUtils::ParseXS
 * internal macro that we're free to redefine for varying linkage due
 * to the EXPORT_XSUB_SYMBOLS XS keyword. This is internal, use
 * XS_EXTERNAL(name) or XS_INTERNAL(name) in your code if you need to!
 */

#undef XS_EUPXS
#if defined(PERL_EUPXS_ALWAYS_EXPORT)
#  define XS_EUPXS(name) XS_EXTERNAL(name)
#else
   /* default to internal */
#  define XS_EUPXS(name) XS_INTERNAL(name)
#endif

#ifndef PERL_ARGS_ASSERT_CROAK_XS_USAGE
#define PERL_ARGS_ASSERT_CROAK_XS_USAGE assert(cv); assert(params)

/* prototype to pass -Wmissing-prototypes */
STATIC void
S_croak_xs_usage(pTHX_ const CV *const cv, const char *const params);

STATIC void
S_croak_xs_usage(pTHX_ const CV *const cv, const char *const params)
{
    const GV *const gv = CvGV(cv);

    PERL_ARGS_ASSERT_CROAK_XS_USAGE;

    if (gv) {
        const char *const gvname = GvNAME(gv);
        const HV *const stash = GvSTASH(gv);
        const char *const hvname = stash ? HvNAME(stash) : NULL;

        if (hvname)
            Perl_croak(aTHX_ "Usage: %s::%s(%s)", hvname, gvname, params);
        else
            Perl_croak(aTHX_ "Usage: %s(%s)", gvname, params);
    } else {
        /* Pants. I don't think that it should be possible to get here. */
        Perl_croak(aTHX_ "Usage: CODE(0x%"UVxf")(%s)", PTR2UV(cv), params);
    }
}
#undef  PERL_ARGS_ASSERT_CROAK_XS_USAGE

#ifdef PERL_IMPLICIT_CONTEXT
#define croak_xs_usage(a,b)    S_croak_xs_usage(aTHX_ a,b)
#else
#define croak_xs_usage        S_croak_xs_usage
#endif

#endif

/* NOTE: the prototype of newXSproto() is different in versions of perls,
 * so we define a portable version of newXSproto()
 */
#ifdef newXS_flags
#define newXSproto_portable(name, c_impl, file, proto) newXS_flags(name, c_impl, file, proto, 0)
#else
#define newXSproto_portable(name, c_impl, file, proto) (PL_Sv=(SV*)newXS(name, c_impl, file), sv_setpv(PL_Sv, proto), (CV*)PL_Sv)
#endif /* !defined(newXS_flags) */

#line 299 "xs/GnomeVFSDNSSD.c"

XS_EUPXS(XS_Gnome2__VFS__DNSSD_browse); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Gnome2__VFS__DNSSD_browse)
{
    dVAR; dXSARGS;
    if (items < 4 || items > 5)
       croak_xs_usage(cv,  "class, domain, type, func, data = NULL");
    PERL_UNUSED_VAR(ax); /* -Wall */
    SP -= items;
    {
	const char *	domain = (const char *)SvPV_nolen(ST(1))
;
	const char *	type = (const char *)SvPV_nolen(ST(2))
;
	SV *	func = ST(3)
;
	SV *	data;
#line 157 "xs/GnomeVFSDNSSD.xs"
	GnomeVFSDNSSDBrowseHandle *handle;
	GnomeVFSResult result;
	GPerlCallback *callback;
#line 321 "xs/GnomeVFSDNSSD.c"

	if (items < 5)
	    data = NULL;
	else {
	    data = ST(4)
;
	}
#line 161 "xs/GnomeVFSDNSSD.xs"
	callback = vfs2perl_dns_sd_browse_callback_create (func, data);

	result = gnome_vfs_dns_sd_browse (&handle,
	                                  domain,
	                                  type,
	                                  (GnomeVFSDNSSDBrowseCallback)
	                                    vfs2perl_dns_sd_browse_callback,
	                                  callback,
	                                  (GDestroyNotify)
	                                    gperl_callback_destroy);

	EXTEND (sp, 2);
	PUSHs (sv_2mortal (newSVGnomeVFSResult (result)));
	PUSHs (sv_2mortal (newSVGnomeVFSDNSSDBrowseHandle (handle)));
#line 344 "xs/GnomeVFSDNSSD.c"
	PUTBACK;
	return;
    }
}


XS_EUPXS(XS_Gnome2__VFS__DNSSD_resolve); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Gnome2__VFS__DNSSD_resolve)
{
    dVAR; dXSARGS;
    if (items < 6 || items > 7)
       croak_xs_usage(cv,  "class, name, type, domain, timeout, func, data=NULL");
    PERL_UNUSED_VAR(ax); /* -Wall */
    SP -= items;
    {
	const char *	name = (const char *)SvPV_nolen(ST(1))
;
	const char *	type = (const char *)SvPV_nolen(ST(2))
;
	const char *	domain = (const char *)SvPV_nolen(ST(3))
;
	int	timeout = (int)SvIV(ST(4))
;
	SV *	func = ST(5)
;
	SV *	data;
#line 186 "xs/GnomeVFSDNSSD.xs"
	GnomeVFSDNSSDResolveHandle *handle;
	GnomeVFSResult result;
	GPerlCallback *callback;
#line 375 "xs/GnomeVFSDNSSD.c"

	if (items < 7)
	    data = NULL;
	else {
	    data = ST(6)
;
	}
#line 190 "xs/GnomeVFSDNSSD.xs"
	callback = vfs2perl_dns_sd_resolve_callback_create (func, data);

	result = gnome_vfs_dns_sd_resolve (&handle,
	                                   name,
	                                   type,
	                                   domain,
	                                   timeout,
	                                   (GnomeVFSDNSSDResolveCallback)
	                                     vfs2perl_dns_sd_resolve_callback,
	                                   callback,
	                                   (GDestroyNotify)
	                                     gperl_callback_destroy);

	EXTEND (sp, 2);
	PUSHs (sv_2mortal (newSVGnomeVFSResult (result)));
	PUSHs (sv_2mortal (newSVGnomeVFSDNSSDResolveHandle (handle)));
#line 400 "xs/GnomeVFSDNSSD.c"
	PUTBACK;
	return;
    }
}


XS_EUPXS(XS_Gnome2__VFS__DNSSD_browse_sync); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Gnome2__VFS__DNSSD_browse_sync)
{
    dVAR; dXSARGS;
    if (items != 4)
       croak_xs_usage(cv,  "class, domain, type, timeout_msec");
    PERL_UNUSED_VAR(ax); /* -Wall */
    SP -= items;
    {
	const char *	domain = (const char *)SvPV_nolen(ST(1))
;
	const char *	type = (const char *)SvPV_nolen(ST(2))
;
	int	timeout_msec = (int)SvIV(ST(3))
;
#line 214 "xs/GnomeVFSDNSSD.xs"
	GnomeVFSResult result;
	int n_services, i;
	GnomeVFSDNSSDService *services = NULL;
#line 426 "xs/GnomeVFSDNSSD.c"
#line 218 "xs/GnomeVFSDNSSD.xs"
	result = gnome_vfs_dns_sd_browse_sync (domain, type, timeout_msec, &n_services, &services);

	PUSHs (sv_2mortal (newSVGnomeVFSResult (result)));

	if (result == GNOME_VFS_OK && services) {
		for (i = 0; i < n_services; i++) {
			XPUSHs (sv_2mortal (newSVGnomeVFSDNSSDService (&services[i])));
		}
		gnome_vfs_dns_sd_service_list_free (services, n_services);
	}
#line 438 "xs/GnomeVFSDNSSD.c"
	PUTBACK;
	return;
    }
}


XS_EUPXS(XS_Gnome2__VFS__DNSSD_resolve_sync); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Gnome2__VFS__DNSSD_resolve_sync)
{
    dVAR; dXSARGS;
    if (items != 5)
       croak_xs_usage(cv,  "class, name, type, domain, timeout_msec");
    PERL_UNUSED_VAR(ax); /* -Wall */
    SP -= items;
    {
	const char *	name = (const char *)SvPV_nolen(ST(1))
;
	const char *	type = (const char *)SvPV_nolen(ST(2))
;
	const char *	domain = (const char *)SvPV_nolen(ST(3))
;
	int	timeout_msec = (int)SvIV(ST(4))
;
#line 237 "xs/GnomeVFSDNSSD.xs"
	GnomeVFSResult result;
	char *host = NULL;
	int port;
	GHashTable *text = NULL;
	int text_raw_len;
	char *text_raw = NULL;
#line 469 "xs/GnomeVFSDNSSD.c"
#line 244 "xs/GnomeVFSDNSSD.xs"
	result = gnome_vfs_dns_sd_resolve_sync (name, type, domain, timeout_msec, &host, &port, &text, &text_raw_len, &text_raw);

	EXTEND (sp, 5);
	PUSHs (sv_2mortal (newSVGnomeVFSResult (result)));
	PUSHs (host ? sv_2mortal (newSVpv (host, 0)) : &PL_sv_undef);
	PUSHs (sv_2mortal (newSViv (port)));
	PUSHs (sv_2mortal (newSVGnomeVFSDNSSDResolveHashTable (text)));
	PUSHs (text_raw ? sv_2mortal (newSVpv (text_raw, text_raw_len)) : &PL_sv_undef);

	if (host)
		g_free (host);
	if (text_raw)
		g_free (text_raw);
	if (text)
		g_hash_table_destroy (text);
#line 486 "xs/GnomeVFSDNSSD.c"
	PUTBACK;
	return;
    }
}


XS_EUPXS(XS_Gnome2__VFS__DNSSD_list_browse_domains_sync); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Gnome2__VFS__DNSSD_list_browse_domains_sync)
{
    dVAR; dXSARGS;
    if (items != 3)
       croak_xs_usage(cv,  "class, domain, timeout_msec");
    PERL_UNUSED_VAR(ax); /* -Wall */
    SP -= items;
    {
	const char *	domain = (const char *)SvPV_nolen(ST(1))
;
	int	timeout_msec = (int)SvIV(ST(2))
;
#line 266 "xs/GnomeVFSDNSSD.xs"
	GnomeVFSResult result;
	GList *domains = NULL, *i;
#line 509 "xs/GnomeVFSDNSSD.c"
#line 269 "xs/GnomeVFSDNSSD.xs"
	result = gnome_vfs_dns_sd_list_browse_domains_sync (domain, timeout_msec, &domains);

	PUSHs (sv_2mortal (newSVGnomeVFSResult (result)));

	if (result == GNOME_VFS_OK) {
		for (i = domains; i; i = i->next) {
			if (i->data) {
				XPUSHs (sv_2mortal (newSVpv (i->data, 0)));
				g_free (i->data);
			}
		}
	}

	g_list_free (domains);
#line 525 "xs/GnomeVFSDNSSD.c"
	PUTBACK;
	return;
    }
}


XS_EUPXS(XS_Gnome2__VFS_get_default_browse_domains); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Gnome2__VFS_get_default_browse_domains)
{
    dVAR; dXSARGS;
    if (items != 1)
       croak_xs_usage(cv,  "class");
    PERL_UNUSED_VAR(ax); /* -Wall */
    SP -= items;
    {
#line 295 "xs/GnomeVFSDNSSD.xs"
	GList *domains = NULL, *i;
#line 543 "xs/GnomeVFSDNSSD.c"
#line 297 "xs/GnomeVFSDNSSD.xs"
	PERL_UNUSED_VAR (ax);
	domains = gnome_vfs_get_default_browse_domains ();

	for (i = domains; i; i = i->next) {
		if (i->data) {
			XPUSHs (sv_2mortal (newSVpv (i->data, 0)));
			g_free (i->data);
		}
	}

	g_list_free (domains);
#line 556 "xs/GnomeVFSDNSSD.c"
	PUTBACK;
	return;
    }
}


XS_EUPXS(XS_Gnome2__VFS__DNSSD__Browse__Handle_stop); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Gnome2__VFS__DNSSD__Browse__Handle_stop)
{
    dVAR; dXSARGS;
    if (items != 1)
       croak_xs_usage(cv,  "handle");
    {
	GnomeVFSDNSSDBrowseHandle *	handle = SvGnomeVFSDNSSDBrowseHandle (ST(0))
;
	GnomeVFSResult	RETVAL;
#line 318 "xs/GnomeVFSDNSSD.xs"
	RETVAL = gnome_vfs_dns_sd_stop_browse (handle);
#line 575 "xs/GnomeVFSDNSSD.c"
	ST(0) = newSVGnomeVFSResult (RETVAL);
	sv_2mortal(ST(0));
    }
    XSRETURN(1);
}


XS_EUPXS(XS_Gnome2__VFS__DNSSD__Resolve__Handle_cancel); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Gnome2__VFS__DNSSD__Resolve__Handle_cancel)
{
    dVAR; dXSARGS;
    if (items != 1)
       croak_xs_usage(cv,  "handle");
    {
	GnomeVFSDNSSDResolveHandle *	handle = SvGnomeVFSDNSSDResolveHandle (ST(0))
;
	GnomeVFSResult	RETVAL;
#line 329 "xs/GnomeVFSDNSSD.xs"
	RETVAL = gnome_vfs_dns_sd_cancel_resolve (handle);
#line 595 "xs/GnomeVFSDNSSD.c"
	ST(0) = newSVGnomeVFSResult (RETVAL);
	sv_2mortal(ST(0));
    }
    XSRETURN(1);
}

#ifdef __cplusplus
extern "C"
#endif
XS_EXTERNAL(boot_Gnome2__VFS__DNSSD); /* prototype to pass -Wmissing-prototypes */
XS_EXTERNAL(boot_Gnome2__VFS__DNSSD)
{
    dVAR; dXSARGS;
#if (PERL_REVISION == 5 && PERL_VERSION < 9)
    char* file = __FILE__;
#else
    const char* file = __FILE__;
#endif

    PERL_UNUSED_VAR(cv); /* -W */
    PERL_UNUSED_VAR(items); /* -W */
#ifdef XS_APIVERSION_BOOTCHECK
    XS_APIVERSION_BOOTCHECK;
#endif
    XS_VERSION_BOOTCHECK;

        newXS("Gnome2::VFS::DNSSD::browse", XS_Gnome2__VFS__DNSSD_browse, file);
        newXS("Gnome2::VFS::DNSSD::resolve", XS_Gnome2__VFS__DNSSD_resolve, file);
        newXS("Gnome2::VFS::DNSSD::browse_sync", XS_Gnome2__VFS__DNSSD_browse_sync, file);
        newXS("Gnome2::VFS::DNSSD::resolve_sync", XS_Gnome2__VFS__DNSSD_resolve_sync, file);
        newXS("Gnome2::VFS::DNSSD::list_browse_domains_sync", XS_Gnome2__VFS__DNSSD_list_browse_domains_sync, file);
        newXS("Gnome2::VFS::get_default_browse_domains", XS_Gnome2__VFS_get_default_browse_domains, file);
        newXS("Gnome2::VFS::DNSSD::Browse::Handle::stop", XS_Gnome2__VFS__DNSSD__Browse__Handle_stop, file);
        newXS("Gnome2::VFS::DNSSD::Resolve::Handle::cancel", XS_Gnome2__VFS__DNSSD__Resolve__Handle_cancel, file);
#if (PERL_REVISION == 5 && PERL_VERSION >= 9)
  if (PL_unitcheckav)
       call_list(PL_scopestack_ix, PL_unitcheckav);
#endif
    XSRETURN_YES;
}

