/* -------------------------------------------------------------------- */
/*  ACCORDS PLATFORM                                                    */
/*  (C) 2011 by Iain James Marshall (Prologue) <ijm667@hotmail.com>     */
/* -------------------------------------------------------------------- */
/* Licensed under the Apache License, Version 2.0 (the "License"); 	*/
/* you may not use this file except in compliance with the License. 	*/
/* You may obtain a copy of the License at 				*/
/*  									*/
/*  http://www.apache.org/licenses/LICENSE-2.0 				*/
/*  									*/
/* Unless required by applicable law or agreed to in writing, software 	*/
/* distributed under the License is distributed on an "AS IS" BASIS, 	*/
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 	*/
/* implied. 								*/
/* See the License for the specific language governing permissions and 	*/
/* limitations under the License. 					*/
/* -------------------------------------------------------------------- */

/* STRUKT WARNING : this file has been generated and should not be modified by hand */
#ifndef _azconfig_c_
#define _azconfig_c_

#include "element.h"

#include "azconfig.h"

/*	------------------------------------	*/
/*	l i b e r a t e _ a z _ c o n f i g 	*/
/*	------------------------------------	*/
public struct az_config * liberate_az_config(struct az_config * sptr)
{
	if ( sptr )
	{
		if ( sptr->id )
			 sptr->id = liberate(sptr->id);
		if ( sptr->name )
			 sptr->name = liberate(sptr->name);
		if ( sptr->description )
			 sptr->description = liberate(sptr->description);
		if ( sptr->user )
			 sptr->user = liberate(sptr->user);
		if ( sptr->password )
			 sptr->password = liberate(sptr->password);
		if ( sptr->authenticate )
			 sptr->authenticate = liberate(sptr->authenticate);
		if ( sptr->agent )
			 sptr->agent = liberate(sptr->agent);
		if ( sptr->host )
			 sptr->host = liberate(sptr->host);
		if ( sptr->version )
			 sptr->version = liberate(sptr->version);
		if ( sptr->namespace )
			 sptr->namespace = liberate(sptr->namespace);
		if ( sptr->base )
			 sptr->base = liberate(sptr->base);
		if ( sptr->subscription )
			 sptr->subscription = liberate(sptr->subscription);
		if ( sptr->certificate )
			 sptr->certificate = liberate(sptr->certificate);
		if ( sptr->tls )
			 sptr->tls = liberate(sptr->tls);
		if ( sptr->hostedservice )
			 sptr->hostedservice = liberate(sptr->hostedservice);
		if ( sptr->storageaccount )
			 sptr->storageaccount = liberate(sptr->storageaccount);
		if ( sptr->location )
			 sptr->location = liberate(sptr->location);
		if ( sptr->group )
			 sptr->group = liberate(sptr->group);
		sptr = liberate( sptr );
	}
	return((struct az_config *) 0);

}

/*	------------------------------	*/
/*	r e s e t _ a z _ c o n f i g 	*/
/*	------------------------------	*/
public struct az_config * reset_az_config(struct az_config * sptr)
{
	if ( sptr )
	{
		sptr->id = (char*) 0;
		sptr->name = (char*) 0;
		sptr->description = (char*) 0;
		sptr->user = (char*) 0;
		sptr->password = (char*) 0;
		sptr->authenticate = (char*) 0;
		sptr->agent = (char*) 0;
		sptr->host = (char*) 0;
		sptr->version = (char*) 0;
		sptr->namespace = (char*) 0;
		sptr->base = (char*) 0;
		sptr->subscription = (char*) 0;
		sptr->certificate = (char*) 0;
		sptr->tls = (char*) 0;
		sptr->hostedservice = (char*) 0;
		sptr->storageaccount = (char*) 0;
		sptr->location = (char*) 0;
		sptr->group = (char*) 0;
		sptr->services =  0;
		sptr->current =  0;
	}
	return(sptr);

}

/*	------------------------------------	*/
/*	a l l o c a t e _ a z _ c o n f i g 	*/
/*	------------------------------------	*/
public struct az_config * allocate_az_config()
{
	struct az_config * sptr;
	if (!( sptr = allocate( sizeof( struct az_config ) ) ))
		return( sptr );
	else	return( reset_az_config(sptr) );
}

/*	------------------------------	*/
/*	x m l i n _ a z _ c o n f i g 	*/
/*	------------------------------	*/
public int xmlin_az_config(struct az_config * sptr,struct xml_element * eptr)
{
	struct xml_element * wptr;
	if (!( eptr )) return(0);
	if (!( sptr )) return(0);
	for ( wptr=eptr->first; wptr != (struct xml_element *) 0; wptr=wptr->next)
	{
		if (!( strcmp(wptr->name,"id") ))
		{
			if ( wptr->value ) { sptr->id = allocate_string(wptr->value); }
		}
		else if (!( strcmp(wptr->name,"name") ))
		{
			if ( wptr->value ) { sptr->name = allocate_string(wptr->value); }
		}
		else if (!( strcmp(wptr->name,"description") ))
		{
			if ( wptr->value ) { sptr->description = allocate_string(wptr->value); }
		}
		else if (!( strcmp(wptr->name,"user") ))
		{
			if ( wptr->value ) { sptr->user = allocate_string(wptr->value); }
		}
		else if (!( strcmp(wptr->name,"password") ))
		{
			if ( wptr->value ) { sptr->password = allocate_string(wptr->value); }
		}
		else if (!( strcmp(wptr->name,"authenticate") ))
		{
			if ( wptr->value ) { sptr->authenticate = allocate_string(wptr->value); }
		}
		else if (!( strcmp(wptr->name,"agent") ))
		{
			if ( wptr->value ) { sptr->agent = allocate_string(wptr->value); }
		}
		else if (!( strcmp(wptr->name,"host") ))
		{
			if ( wptr->value ) { sptr->host = allocate_string(wptr->value); }
		}
		else if (!( strcmp(wptr->name,"version") ))
		{
			if ( wptr->value ) { sptr->version = allocate_string(wptr->value); }
		}
		else if (!( strcmp(wptr->name,"namespace") ))
		{
			if ( wptr->value ) { sptr->namespace = allocate_string(wptr->value); }
		}
		else if (!( strcmp(wptr->name,"base") ))
		{
			if ( wptr->value ) { sptr->base = allocate_string(wptr->value); }
		}
		else if (!( strcmp(wptr->name,"subscription") ))
		{
			if ( wptr->value ) { sptr->subscription = allocate_string(wptr->value); }
		}
		else if (!( strcmp(wptr->name,"certificate") ))
		{
			if ( wptr->value ) { sptr->certificate = allocate_string(wptr->value); }
		}
		else if (!( strcmp(wptr->name,"tls") ))
		{
			if ( wptr->value ) { sptr->tls = allocate_string(wptr->value); }
		}
		else if (!( strcmp(wptr->name,"hostedservice") ))
		{
			if ( wptr->value ) { sptr->hostedservice = allocate_string(wptr->value); }
		}
		else if (!( strcmp(wptr->name,"storageaccount") ))
		{
			if ( wptr->value ) { sptr->storageaccount = allocate_string(wptr->value); }
		}
		else if (!( strcmp(wptr->name,"location") ))
		{
			if ( wptr->value ) { sptr->location = allocate_string(wptr->value); }
		}
		else if (!( strcmp(wptr->name,"group") ))
		{
			if ( wptr->value ) { sptr->group = allocate_string(wptr->value); }
		}
		else if (!( strcmp(wptr->name,"services") ))
		{
			if ( wptr->value ) { sptr->services = atoi(wptr->value); }
		}
		else if (!( strcmp(wptr->name,"current") ))
		{
			if ( wptr->value ) { sptr->current = atoi(wptr->value); }
		}
	}
	return(0);

}

/*	--------------------------------------	*/
/*	r e s t _ o c c i _ a z _ c o n f i g 	*/
/*	--------------------------------------	*/
public int rest_occi_az_config(FILE * fh,struct az_config * sptr,char * prefix, char * nptr)
{
	struct xml_element * wptr;
	if (!( sptr )) return(0);
	fprintf(fh,"POST /%s/ HTTP/1.1\r\n",nptr);
	fprintf(fh,"Category: %s; scheme='http://scheme.%s.org/occi/%s#'; class='kind';\r\n",nptr,prefix,prefix);
	fprintf(fh,"X-OCCI-Attribute: %s.%s.id='%s'\r\n",prefix,nptr,(sptr->id?sptr->id:""));
	fprintf(fh,"X-OCCI-Attribute: %s.%s.name='%s'\r\n",prefix,nptr,(sptr->name?sptr->name:""));
	fprintf(fh,"X-OCCI-Attribute: %s.%s.description='%s'\r\n",prefix,nptr,(sptr->description?sptr->description:""));
	fprintf(fh,"X-OCCI-Attribute: %s.%s.user='%s'\r\n",prefix,nptr,(sptr->user?sptr->user:""));
	fprintf(fh,"X-OCCI-Attribute: %s.%s.password='%s'\r\n",prefix,nptr,(sptr->password?sptr->password:""));
	fprintf(fh,"X-OCCI-Attribute: %s.%s.authenticate='%s'\r\n",prefix,nptr,(sptr->authenticate?sptr->authenticate:""));
	fprintf(fh,"X-OCCI-Attribute: %s.%s.agent='%s'\r\n",prefix,nptr,(sptr->agent?sptr->agent:""));
	fprintf(fh,"X-OCCI-Attribute: %s.%s.host='%s'\r\n",prefix,nptr,(sptr->host?sptr->host:""));
	fprintf(fh,"X-OCCI-Attribute: %s.%s.version='%s'\r\n",prefix,nptr,(sptr->version?sptr->version:""));
	fprintf(fh,"X-OCCI-Attribute: %s.%s.namespace='%s'\r\n",prefix,nptr,(sptr->namespace?sptr->namespace:""));
	fprintf(fh,"X-OCCI-Attribute: %s.%s.base='%s'\r\n",prefix,nptr,(sptr->base?sptr->base:""));
	fprintf(fh,"X-OCCI-Attribute: %s.%s.subscription='%s'\r\n",prefix,nptr,(sptr->subscription?sptr->subscription:""));
	fprintf(fh,"X-OCCI-Attribute: %s.%s.certificate='%s'\r\n",prefix,nptr,(sptr->certificate?sptr->certificate:""));
	fprintf(fh,"X-OCCI-Attribute: %s.%s.tls='%s'\r\n",prefix,nptr,(sptr->tls?sptr->tls:""));
	fprintf(fh,"X-OCCI-Attribute: %s.%s.hostedservice='%s'\r\n",prefix,nptr,(sptr->hostedservice?sptr->hostedservice:""));
	fprintf(fh,"X-OCCI-Attribute: %s.%s.storageaccount='%s'\r\n",prefix,nptr,(sptr->storageaccount?sptr->storageaccount:""));
	fprintf(fh,"X-OCCI-Attribute: %s.%s.location='%s'\r\n",prefix,nptr,(sptr->location?sptr->location:""));
	fprintf(fh,"X-OCCI-Attribute: %s.%s.group='%s'\r\n",prefix,nptr,(sptr->group?sptr->group:""));
	fprintf(fh,"X-OCCI-Attribute: %s.%s.services='%u'\r\n",prefix,nptr,sptr->services);
	fprintf(fh,"X-OCCI-Attribute: %s.%s.current='%u'\r\n",prefix,nptr,sptr->current);
	return(0);

}

#endif	/* _azconfig_cazconfig_c_ */
