/*
 * This file was generated automatically by xsubpp version 1.9508 from the
 * contents of API.xs. Do not edit this file, edit API.xs instead.
 *
 *	ANY CHANGES MADE HERE WILL BE LOST!
 *
 */

#line 1 "API.xs"
#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"

#include "ppport.h"

#include <varnish/varnishapi.h>

#include "const-c.inc"

int
dispatch_callback(void *priv, enum shmlogtag tag, unsigned fd, unsigned len,
    unsigned spec, const char *ptr) {
    dSP;
    int count;
    int rv;

    ENTER;
    SAVETMPS;
    PUSHMARK(SP);
    XPUSHs(sv_2mortal(newSVpv(VSL_tags[tag],0)));
    XPUSHs(sv_2mortal(newSViv(fd)));
    XPUSHs(sv_2mortal(newSViv(spec)));
    XPUSHs(sv_2mortal(newSVpv(ptr,0)));
    PUTBACK;
    count = call_sv((SV*) priv, G_SCALAR);
    SPAGAIN;
    rv = POPi;
    PUTBACK;    
    FREETMPS;
    LEAVE;
    return (rv);
}


SV*
get_field_type() {
		 dTHX;
	     HV* fields;
	     fields = newHV();
#define MAC_STAT(type, l, field, description)	\
	{ \
	  char * tmp = #field; \
	  hv_store(fields, #type, strlen(#type), newSVpv(&tmp[1], 1),0); \
		}\
		
#include <varnish/stat_field.h>
#undef MAC_STAT
       return newRV_noinc((SV*) fields);
}

SV*
get_field_descriptions() {
		 dTHX;
	     HV* fields;
	     fields = newHV();
#define MAC_STAT(type, l, field, description)	\
	  hv_store(fields, #type, strlen(#type), newSVpv(description, 0),0); \
		
#include <varnish/stat_field.h>
#undef MAC_STAT
       return newRV_noinc((SV*) fields);
}

SV*
get_tags() {
		 dTHX;
	     HV* fields;
	     fields = newHV();
	     int i = 1;
#define SLTM(foo)       \
	  hv_store(fields, #foo, strlen(#foo), newSViv(i++),0); \

#include <varnish/shmlog_tags.h>		
#undef SLTM
       return newRV_noinc((SV*) fields);
}

IV
get_stat(struct varnish_stats *VSL_stats, const char* stat) {


#define MAC_STAT(type, l, field, description)	\
  if(!strcmp(#type, stat)) {			\
    return VSL_stats->type;			\
  }				   \
			   
#include <varnish/stat_field.h>
#undef MAC_STAT

}


#line 104 "API.c"

/* INCLUDE:  Including 'const-xs.inc' from 'API.xs' */


XS(XS_Varnish__API_constant); /* prototype to pass -Wmissing-prototypes */
XS(XS_Varnish__API_constant)
{
    dXSARGS;
    if (items != 1)
	Perl_croak(aTHX_ "Usage: Varnish::API::constant(sv)");
    SP -= items;
    {
#line 4 "const-xs.inc"
#ifdef dXSTARG
	dXSTARG; /* Faster if we have it.  */
#else
	dTARGET;
#endif
	STRLEN		len;
        int		type;
	IV		iv;
	/* NV		nv;	Uncomment this if you need to return NVs */
	/* const char	*pv;	Uncomment this if you need to return PVs */
#line 128 "API.c"
	SV *	sv = ST(0);
	const char *	s = SvPV(sv, len);
#line 18 "const-xs.inc"
        /* Change this to constant(aTHX_ s, len, &iv, &nv);
           if you need to return both NVs and IVs */
	type = constant(aTHX_ s, len, &iv);
      /* Return 1 or 2 items. First is error message, or undef if no error.
           Second, if present, is found value */
        switch (type) {
        case PERL_constant_NOTFOUND:
          sv = sv_2mortal(newSVpvf("%s is not a valid Varnish::API macro", s));
          PUSHs(sv);
          break;
        case PERL_constant_NOTDEF:
          sv = sv_2mortal(newSVpvf(
	    "Your vendor has not defined Varnish::API macro %s, used", s));
          PUSHs(sv);
          break;
        case PERL_constant_ISIV:
          EXTEND(SP, 1);
          PUSHs(&PL_sv_undef);
          PUSHi(iv);
          break;
	/* Uncomment this if you need to return NOs
        case PERL_constant_ISNO:
          EXTEND(SP, 1);
          PUSHs(&PL_sv_undef);
          PUSHs(&PL_sv_no);
          break; */
	/* Uncomment this if you need to return NVs
        case PERL_constant_ISNV:
          EXTEND(SP, 1);
          PUSHs(&PL_sv_undef);
          PUSHn(nv);
          break; */
	/* Uncomment this if you need to return PVs
        case PERL_constant_ISPV:
          EXTEND(SP, 1);
          PUSHs(&PL_sv_undef);
          PUSHp(pv, strlen(pv));
          break; */
	/* Uncomment this if you need to return PVNs
        case PERL_constant_ISPVN:
          EXTEND(SP, 1);
          PUSHs(&PL_sv_undef);
          PUSHp(pv, iv);
          break; */
	/* Uncomment this if you need to return SVs
        case PERL_constant_ISSV:
          EXTEND(SP, 1);
          PUSHs(&PL_sv_undef);
          PUSHs(sv);
          break; */
	/* Uncomment this if you need to return UNDEFs
        case PERL_constant_ISUNDEF:
          break; */
	/* Uncomment this if you need to return UVs
        case PERL_constant_ISUV:
          EXTEND(SP, 1);
          PUSHs(&PL_sv_undef);
          PUSHu((UV)iv);
          break; */
	/* Uncomment this if you need to return YESs
        case PERL_constant_ISYES:
          EXTEND(SP, 1);
          PUSHs(&PL_sv_undef);
          PUSHs(&PL_sv_yes);
          break; */
        default:
          sv = sv_2mortal(newSVpvf(
	    "Unexpected return type %d while processing Varnish::API macro %s, used",
               type, s));
          PUSHs(sv);
        }
#line 203 "API.c"
	PUTBACK;
	return;
    }
}


/* INCLUDE: Returning to 'API.xs' from 'const-xs.inc' */


XS(XS_Varnish__API_VSL_GetStatFieldTypes); /* prototype to pass -Wmissing-prototypes */
XS(XS_Varnish__API_VSL_GetStatFieldTypes)
{
    dXSARGS;
    if (items != 0)
	Perl_croak(aTHX_ "Usage: Varnish::API::VSL_GetStatFieldTypes()");
    {
	SV *	RETVAL;
#line 102 "API.xs"
	RETVAL = get_field_type();
#line 223 "API.c"
	ST(0) = RETVAL;
	sv_2mortal(ST(0));
    }
    XSRETURN(1);
}


XS(XS_Varnish__API_VSL_GetTags); /* prototype to pass -Wmissing-prototypes */
XS(XS_Varnish__API_VSL_GetTags)
{
    dXSARGS;
    if (items != 0)
	Perl_croak(aTHX_ "Usage: Varnish::API::VSL_GetTags()");
    {
	SV *	RETVAL;
#line 109 "API.xs"
	RETVAL = get_tags();
#line 241 "API.c"
	ST(0) = RETVAL;
	sv_2mortal(ST(0));
    }
    XSRETURN(1);
}


XS(XS_Varnish__API_VSL_GetStatFieldDescriptions); /* prototype to pass -Wmissing-prototypes */
XS(XS_Varnish__API_VSL_GetStatFieldDescriptions)
{
    dXSARGS;
    if (items != 0)
	Perl_croak(aTHX_ "Usage: Varnish::API::VSL_GetStatFieldDescriptions()");
    {
	SV *	RETVAL;
#line 117 "API.xs"
	RETVAL = get_field_descriptions();
#line 259 "API.c"
	ST(0) = RETVAL;
	sv_2mortal(ST(0));
    }
    XSRETURN(1);
}


XS(XS_Varnish__API_SHMLOG_ID); /* prototype to pass -Wmissing-prototypes */
XS(XS_Varnish__API_SHMLOG_ID)
{
    dXSARGS;
    if (items != 1)
	Perl_croak(aTHX_ "Usage: Varnish::API::SHMLOG_ID(logentry)");
    {
	SV*	logentry = ST(0);
	unsigned int	RETVAL;
	dXSTARG;
#line 126 "API.xs"
	RETVAL = SHMLOG_ID((unsigned char*) SvPVbyte_nolen(logentry));
#line 279 "API.c"
	XSprePUSH; PUSHu((UV)RETVAL);
    }
    XSRETURN(1);
}


XS(XS_Varnish__API_SHMLOG_LEN); /* prototype to pass -Wmissing-prototypes */
XS(XS_Varnish__API_SHMLOG_LEN)
{
    dXSARGS;
    if (items != 1)
	Perl_croak(aTHX_ "Usage: Varnish::API::SHMLOG_LEN(logentry)");
    {
	SV*	logentry = ST(0);
	unsigned int	RETVAL;
	dXSTARG;
#line 134 "API.xs"
	RETVAL = SHMLOG_LEN((unsigned char*) SvPVbyte_nolen(logentry));
#line 298 "API.c"
	XSprePUSH; PUSHu((UV)RETVAL);
    }
    XSRETURN(1);
}


XS(XS_Varnish__API_SHMLOG_TAG); /* prototype to pass -Wmissing-prototypes */
XS(XS_Varnish__API_SHMLOG_TAG)
{
    dXSARGS;
    if (items != 1)
	Perl_croak(aTHX_ "Usage: Varnish::API::SHMLOG_TAG(logentry)");
    {
	unsigned char*	logentry = (unsigned char *)SvPV_nolen(ST(0));
	unsigned int	RETVAL;
	dXSTARG;
#line 142 "API.xs"
	enum shmlogtag tag;
	tag = logentry[SHMLOG_TAG];
	RETVAL = tag;
#line 319 "API.c"
	XSprePUSH; PUSHu((UV)RETVAL);
    }
    XSRETURN(1);
}


XS(XS_Varnish__API_SHMLOG_DATA); /* prototype to pass -Wmissing-prototypes */
XS(XS_Varnish__API_SHMLOG_DATA)
{
    dXSARGS;
    if (items != 1)
	Perl_croak(aTHX_ "Usage: Varnish::API::SHMLOG_DATA(logentry)");
    {
	unsigned char*	logentry = (unsigned char *)SvPV_nolen(ST(0));
	char *	RETVAL;
	dXSTARG;
#line 154 "API.xs"
	RETVAL = logentry + SHMLOG_DATA;
#line 338 "API.c"
	sv_setpv(TARG, RETVAL); XSprePUSH; PUSHTARG;
    }
    XSRETURN(1);
}


XS(XS_Varnish__API_VSL_tags); /* prototype to pass -Wmissing-prototypes */
XS(XS_Varnish__API_VSL_tags)
{
    dXSARGS;
    if (items != 1)
	Perl_croak(aTHX_ "Usage: Varnish::API::VSL_tags(tag)");
    {
	int	tag = (int)SvIV(ST(0));
	char *	RETVAL;
	dXSTARG;
#line 162 "API.xs"
	RETVAL = (char*) VSL_tags[tag];
#line 357 "API.c"
	sv_setpv(TARG, RETVAL); XSprePUSH; PUSHTARG;
    }
    XSRETURN(1);
}


XS(XS_Varnish__API_VSL_Dispatch); /* prototype to pass -Wmissing-prototypes */
XS(XS_Varnish__API_VSL_Dispatch)
{
    dXSARGS;
    if (items != 2)
	Perl_croak(aTHX_ "Usage: Varnish::API::VSL_Dispatch(vd, func)");
    SP -= items;
    {
	SV*	vd = ST(0);
	SV*	func = ST(1);
	int	RETVAL;
	dXSTARG;
#line 171 "API.xs"
	struct VSL_data* data = (struct VSL_data*) SvIV(vd);
	VSL_Dispatch(data, dispatch_callback, func);
#line 379 "API.c"
	PUTBACK;
	return;
    }
}


XS(XS_Varnish__API_VSL_Name); /* prototype to pass -Wmissing-prototypes */
XS(XS_Varnish__API_VSL_Name)
{
    dXSARGS;
    if (items != 0)
	Perl_croak(aTHX_ "Usage: Varnish::API::VSL_Name()");
    {
	const char *	RETVAL;
	dXSTARG;

	RETVAL = VSL_Name();
	sv_setpv(TARG, RETVAL); XSprePUSH; PUSHTARG;
    }
    XSRETURN(1);
}


XS(XS_Varnish__API_VSL_New); /* prototype to pass -Wmissing-prototypes */
XS(XS_Varnish__API_VSL_New)
{
    dXSARGS;
    if (items != 0)
	Perl_croak(aTHX_ "Usage: Varnish::API::VSL_New()");
   PERL_UNUSED_VAR(ax); /* -Wall */
    SP -= items;
    {
	SV *	RETVAL;
#line 181 "API.xs"
	struct VSL_data* vd = VSL_New();
	ST(0) = newSViv((IV)vd);
	sv_2mortal(ST(0));
	XSRETURN(1);
#line 418 "API.c"
	PUTBACK;
	return;
    }
}


XS(XS_Varnish__API_VSL_NextLog); /* prototype to pass -Wmissing-prototypes */
XS(XS_Varnish__API_VSL_NextLog)
{
    dXSARGS;
    if (items != 1)
	Perl_croak(aTHX_ "Usage: Varnish::API::VSL_NextLog(vd)");
    SP -= items;
    {
	SV*	vd = ST(0);
	SV *	RETVAL;
#line 190 "API.xs"
	STRLEN strlen;
	struct VSL_data* data = (struct VSL_data*) SvIV(vd);
	unsigned char *p;
	VSL_NextLog(data, &p);
	ST(0) = newSVpv(p, SHMLOG_DATA + SHMLOG_LEN(p));
	sv_2mortal(ST(0));
	XSRETURN(1);
#line 443 "API.c"
	PUTBACK;
	return;
    }
}


XS(XS_Varnish__API_VSL_NonBlocking); /* prototype to pass -Wmissing-prototypes */
XS(XS_Varnish__API_VSL_NonBlocking)
{
    dXSARGS;
    if (items != 2)
	Perl_croak(aTHX_ "Usage: Varnish::API::VSL_NonBlocking(vd, nb)");
    {
	SV*	vd = ST(0);
	int	nb = (int)SvIV(ST(1));
#line 203 "API.xs"
	struct VSL_data* data = (struct VSL_data*) SvIV(vd);
	VSL_NonBlocking(data, nb);
#line 462 "API.c"
    }
    XSRETURN_EMPTY;
}


XS(XS_Varnish__API_VSL_OpenLog); /* prototype to pass -Wmissing-prototypes */
XS(XS_Varnish__API_VSL_OpenLog)
{
    dXSARGS;
    if (items != 2)
	Perl_croak(aTHX_ "Usage: Varnish::API::VSL_OpenLog(vd, varnish_name)");
    {
	SV*	vd = ST(0);
	const char *	varnish_name = (const char *)SvPV_nolen(ST(1));
	int	RETVAL;
	dXSTARG;
#line 211 "API.xs"
	struct VSL_data* data = (struct VSL_data*) SvIV(vd);
	VSL_OpenLog(data, varnish_name);
#line 482 "API.c"
    }
    XSRETURN(1);
}


XS(XS_Varnish__API_VSL_OpenStats); /* prototype to pass -Wmissing-prototypes */
XS(XS_Varnish__API_VSL_OpenStats)
{
    dXSARGS;
    if (items != 1)
	Perl_croak(aTHX_ "Usage: Varnish::API::VSL_OpenStats(varnish_name)");
    SP -= items;
    {
	const char *	varnish_name = (const char *)SvPV_nolen(ST(0));
	SV *	RETVAL;
#line 219 "API.xs"
	struct varnish_stats *stats = VSL_OpenStats(varnish_name);
	ST(0) = newSViv((IV)stats);
	sv_2mortal(ST(0));
	XSRETURN(1);
#line 503 "API.c"
	PUTBACK;
	return;
    }
}


XS(XS_Varnish__API_VSL_GetStat); /* prototype to pass -Wmissing-prototypes */
XS(XS_Varnish__API_VSL_GetStat)
{
    dXSARGS;
    if (items != 2)
	Perl_croak(aTHX_ "Usage: Varnish::API::VSL_GetStat(sd, stat)");
    {
	SV*	sd = ST(0);
	const char *	stat = (const char *)SvPV_nolen(ST(1));
	SV *	RETVAL;
#line 229 "API.xs"
	struct varnish_stats * stats = (struct varnish_stats *)SvIV(sd);
	IV nr = get_stat(stats, stat);
	RETVAL = newSViv(nr);
#line 524 "API.c"
	ST(0) = RETVAL;
	sv_2mortal(ST(0));
    }
    XSRETURN(1);
}


XS(XS_Varnish__API_varnish_instance); /* prototype to pass -Wmissing-prototypes */
XS(XS_Varnish__API_varnish_instance)
{
    dXSARGS;
    if (items != 5)
	Perl_croak(aTHX_ "Usage: Varnish::API::varnish_instance(n_arg, name, namelen, dir, dirlen)");
    {
	const char *	n_arg = (const char *)SvPV_nolen(ST(0));
	char *	name = (char *)SvPV_nolen(ST(1));
	size_t	namelen = (size_t)SvUV(ST(2));
	char *	dir = (char *)SvPV_nolen(ST(3));
	size_t	dirlen = (size_t)SvUV(ST(4));
	int	RETVAL;
	dXSTARG;

	RETVAL = varnish_instance(n_arg, name, namelen, dir, dirlen);
	XSprePUSH; PUSHi((IV)RETVAL);
    }
    XSRETURN(1);
}

#ifdef __cplusplus
extern "C"
#endif
XS(boot_Varnish__API); /* prototype to pass -Wmissing-prototypes */
XS(boot_Varnish__API)
{
    dXSARGS;
    char* file = __FILE__;

    XS_VERSION_BOOTCHECK ;

        newXS("Varnish::API::constant", XS_Varnish__API_constant, file);
        newXS("Varnish::API::VSL_GetStatFieldTypes", XS_Varnish__API_VSL_GetStatFieldTypes, file);
        newXS("Varnish::API::VSL_GetTags", XS_Varnish__API_VSL_GetTags, file);
        newXS("Varnish::API::VSL_GetStatFieldDescriptions", XS_Varnish__API_VSL_GetStatFieldDescriptions, file);
        newXS("Varnish::API::SHMLOG_ID", XS_Varnish__API_SHMLOG_ID, file);
        newXS("Varnish::API::SHMLOG_LEN", XS_Varnish__API_SHMLOG_LEN, file);
        newXS("Varnish::API::SHMLOG_TAG", XS_Varnish__API_SHMLOG_TAG, file);
        newXS("Varnish::API::SHMLOG_DATA", XS_Varnish__API_SHMLOG_DATA, file);
        newXS("Varnish::API::VSL_tags", XS_Varnish__API_VSL_tags, file);
        newXS("Varnish::API::VSL_Dispatch", XS_Varnish__API_VSL_Dispatch, file);
        newXS("Varnish::API::VSL_Name", XS_Varnish__API_VSL_Name, file);
        newXS("Varnish::API::VSL_New", XS_Varnish__API_VSL_New, file);
        newXS("Varnish::API::VSL_NextLog", XS_Varnish__API_VSL_NextLog, file);
        newXS("Varnish::API::VSL_NonBlocking", XS_Varnish__API_VSL_NonBlocking, file);
        newXS("Varnish::API::VSL_OpenLog", XS_Varnish__API_VSL_OpenLog, file);
        newXS("Varnish::API::VSL_OpenStats", XS_Varnish__API_VSL_OpenStats, file);
        newXS("Varnish::API::VSL_GetStat", XS_Varnish__API_VSL_GetStat, file);
        newXS("Varnish::API::varnish_instance", XS_Varnish__API_varnish_instance, file);
    XSRETURN_YES;
}

