text:
/* -------------------------------------------------------------------- */
/*  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. 					*/
/* -------------------------------------------------------------------- */
#ifndef	_dcclient_c
#define	_dcclient_c

// ---------------------------------------
// DELTA CLOUD API CLIENT MODULE
// ---------------------------------------
#include "dcclient.h"
#include "restclient.h"

#define	_CORDS_NONE "none"

struct	dc_api_configuration
{
	char *	authorization;
	char *	tls;
	char *	agent;
	char *	tenant;
	char *	user;
	char *	password;
	char *	host;
};

private struct dc_api_configuration DeltaCloudConfig =
{
	(char *) 0,
	(char *) 0,
	(char *) 0,
	(char *) 0,
	(char *) 0,
	(char *) 0,
	(char *) 0
};

/*	------------------------------------------------------------	*/
/*	 l i b e r a t e _ d c _ a p i _ c o n f i g u r a t i o n	*/
/*	------------------------------------------------------------	*/
public	int	liberate_dc_api_configuration(int status)
{
	if ( DeltaCloudConfig.host )
		DeltaCloudConfig.host = liberate( DeltaCloudConfig.host );
	if ( DeltaCloudConfig.tls )
		DeltaCloudConfig.tls = liberate( DeltaCloudConfig.tls );
	if ( DeltaCloudConfig.agent )
		DeltaCloudConfig.agent = liberate( DeltaCloudConfig.agent );
	if ( DeltaCloudConfig.user )
		DeltaCloudConfig.user = liberate( DeltaCloudConfig.user );
	if ( DeltaCloudConfig.password )
		DeltaCloudConfig.password = liberate( DeltaCloudConfig.password );
	if ( DeltaCloudConfig.tenant )
		DeltaCloudConfig.tenant = liberate( DeltaCloudConfig.tenant );
	if ( DeltaCloudConfig.authorization )
		DeltaCloudConfig.authorization = liberate( DeltaCloudConfig.authorization );
	return(status);
}

/*	------------------------------------------------------------	*/
/*		   d c _ a p i _ c o n f i g u r a t i o n		*/
/*	------------------------------------------------------------	*/
public	int	dc_api_configuration( char * host, char * user, char * password, char * tenant, char * agent, char * tls )
{
	liberate_dc_api_configuration(0);

	if ( host )
		if (!( DeltaCloudConfig.host = allocate_string( host ) ))
			return( liberate_dc_api_configuration(27) );
	if ( user )
		if (!( DeltaCloudConfig.user = allocate_string( user ) ))
			return( liberate_dc_api_configuration(27) );
	if ( password )
		if (!( DeltaCloudConfig.password = allocate_string( password ) ))
			return( liberate_dc_api_configuration(27) );
	if ( tenant )
		if (!( DeltaCloudConfig.tenant = allocate_string( tenant ) ))
			return( liberate_dc_api_configuration(27) );
	if ( agent )
		if (!( DeltaCloudConfig.agent = allocate_string( agent ) ))
			return( liberate_dc_api_configuration(27) );

	if (!( tls ))
		DeltaCloudConfig.tls = (char *) 0;
	else if ((DeltaCloudConfig.tls = allocate_string(tls)) != (char *) 0)
		if ( (!( strlen( DeltaCloudConfig.tls ) )) || ( *(DeltaCloudConfig.tls) == '0' ) )
			DeltaCloudConfig.tls = liberate( DeltaCloudConfig.tls );

	return( 0 );
}

/*	------------------------------------------------------------	*/
/*			d c _ a p i _ f a i l u r e 			*/
/*	------------------------------------------------------------	*/
private struct rest_response * dc_api_failure( struct rest_header * hptr )
{
	liberate_rest_header( hptr );
	return((struct rest_response *) 0);
}

/*	------------------------------------------------------------	*/
/*			d c _ a u t h e n t i c a t e 			*/
/*	------------------------------------------------------------	*/
public	struct	rest_header   *	dc_authenticate	( )
{
	struct	rest_header 	*	hptr=(struct rest_header * ) 0;

	if (!( DeltaCloudConfig.user ))
		return((struct rest_header *) 0);
	else if (!( DeltaCloudConfig.password ))
		return((struct rest_header *) 0);
	else if (!( DeltaCloudConfig.authorization ))
		if (!( DeltaCloudConfig.authorization = rest_encode_credentials( DeltaCloudConfig.user, DeltaCloudConfig.password ) ))
			return((struct rest_header *) 0);

	if (!( DeltaCloudConfig.authorization ))
		return((struct rest_header *) 0);
	else if (!( hptr = rest_create_header( "Authorization", DeltaCloudConfig.authorization ) ))
		return( hptr );
	else if (!( hptr->next = rest_create_header( _HTTP_ACCEPT, "*/*" ) ))
		return( liberate_rest_header( hptr ) );
	else	return((hptr->next->previous = hptr));
}

/*	------------------------------------------------------------	*/
/*			d c _ c o n t e n t _ t y p e			*/
/*	------------------------------------------------------------	*/
public	struct	rest_header   *	dc_content_type( struct rest_header * hptr, char * filename )
{
	struct	rest_header * wptr;
	struct	rest_header * root;
	if (!( filename ))
		return( hptr );
	else
	{
		root = hptr->next;
		if (!( root->next = rest_create_header( "Content-Type", "application/x-www-form-urlencoded" ) ))
			return( hptr );
		else
		{
		 	root->next->previous = root;
			return( hptr );
		}
	}
}

// ---------------------------------------
// REST API INTERFACE FUNCTION
// ---------------------------------------
// REST GET REQUEST URL
// ---------------------------------------
private struct rest_response * dc_get_request(char * nptr)
{
	char	url[_DC_BUFFERSIZE];
	struct rest_header * hptr=(struct rest_header *) 0;
	sprintf(url,"%s%s?format=xml",DeltaCloudConfig.host,nptr);
	if (!( hptr = dc_authenticate()))
		return( dc_api_failure( hptr ) );
	else	return( rest_client_get_request( url, DeltaCloudConfig.tls, DeltaCloudConfig.agent, hptr ) );
}

// ---------------------------------------
// REST DELETE REQUEST URL
// ---------------------------------------
private struct rest_response * dc_delete_request(char * nptr)
{
	char	url[_DC_BUFFERSIZE];
	struct rest_header * hptr=(struct rest_header *) 0;
	sprintf(url,"%s%s?format=xml",DeltaCloudConfig.host,nptr);
	if (!( hptr = dc_authenticate()))
		return( dc_api_failure( hptr ) );
	else	return( rest_client_delete_request( url, DeltaCloudConfig.tls, DeltaCloudConfig.agent, hptr ) );
}

// ---------------------------------------
// REST POST REQUEST URL
// ---------------------------------------
private struct rest_response * dc_post_request(char * nptr,char * filename)
{
	char	url[_DC_BUFFERSIZE];
	struct rest_header * hptr=(struct rest_header *) 0;
	sprintf(url,"%s%s?format=xml",DeltaCloudConfig.host,nptr);
	if (!( hptr = dc_authenticate()))
		return( dc_api_failure( hptr ) );
	else if (!( hptr = dc_content_type( hptr, filename ) ))
		return( dc_api_failure( hptr ) );
	else	return( rest_client_post_request( url, DeltaCloudConfig.tls, DeltaCloudConfig.agent, filename, hptr ) );
}

// ---------------------------------------
// REST PUT REQUEST URL
// ---------------------------------------
private struct rest_response * dc_put_request(char * nptr,char * filename)
{
	char	url[_DC_BUFFERSIZE];
	struct rest_header * hptr=(struct rest_header *) 0;
	sprintf(url,"%s%s?format=xml",DeltaCloudConfig.host,nptr);
	if (!( hptr = dc_authenticate()))
		return( dc_api_failure( hptr ) );
	else if (!( hptr = dc_content_type( hptr, filename ) ))
		return( dc_api_failure( hptr ) );
	else	return( rest_client_put_request( url, DeltaCloudConfig.tls, DeltaCloudConfig.agent, filename, hptr ) );
}

// ---------------------------------------
// 1. API
// ---------------------------------------
// GET /api
// ---------------------------------------
public struct rest_response * dc_list_features()
{
	return(dc_get_request("/api"));
}

// ---------------------------------------
// 3. Compute Resources
// ---------------------------------------
// 3.1 Realms
// ---------------------------------------
// GET /api/realms
// ---------------------------------------
public struct rest_response * dc_list_realms()
{
	return(dc_get_request("/api/realms"));
}

// ---------------------------------------
// GET /api/realms/:id
// ---------------------------------------
public struct rest_response * dc_get_realm(char * id)
{
	char buffer[_DC_BUFFERSIZE];
	sprintf(buffer,"/api/realms/%s",id);
	return(dc_get_request(buffer));
}

// ---------------------------------------
// 3.2 Hardware Profiles
// ---------------------------------------
// GET /api/hardware_profiles
// ---------------------------------------
public struct rest_response * dc_list_profiles()
{
	return(dc_get_request("/api/hardware_profiles"));
}

// ---------------------------------------
// GET /api/hardware profiles/:id
// ---------------------------------------
public struct rest_response * dc_get_profile(char * id)
{
	char buffer[_DC_BUFFERSIZE];
	sprintf(buffer,"/api/hardware_profiles/%s",id);
	return(dc_get_request(buffer));
}

// ---------------------------------------
// 3.3 Images
// ---------------------------------------
// GET /api/images
// ---------------------------------------
public struct rest_response * dc_list_images()
{
	return(dc_get_request("/api/images"));
}

// ---------------------------------------
// GET /api/images/:id
// ---------------------------------------
public struct rest_response * dc_get_image(char * id)
{
	char buffer[_DC_BUFFERSIZE];
	sprintf(buffer,"/api/images/%s",id);
	return(dc_get_request(buffer));
}

// ---------------------------------------
// CREATE IMAGE MESSAGE
// ---------------------------------------
public char * dc_create_image_message( char * instance, char * name, char * description )
{
	char *	filename;
	FILE *	h;
	if (!( filename = rest_temporary_filename("form")))
		return( filename );
	else if (!( h = fopen( filename, "wa" ) ))
		return( liberate( filename ) );
	else
	{

		fprintf(h,"instance_id=%s",instance);

		if ( rest_valid_string(name) )
			fprintf(h,"&name=%s",name);

		if ( rest_valid_string(description) )
			fprintf(h,"&description=%s",description);

		fclose(h);
		return( filename );
	}
}

// ---------------------------------------
// POST /api/images
// ---------------------------------------
public struct rest_response * dc_create_image(char * filename)
{
	char buffer[_DC_BUFFERSIZE];
	sprintf(buffer,"/api/images");
	return(dc_post_request(buffer,filename));
}

// ---------------------------------------
// DELETE /api/images/:id
// ---------------------------------------
public struct rest_response * dc_delete_image(char * id)
{
	char buffer[_DC_BUFFERSIZE];
	sprintf(buffer,"/api/images/%s",id);
	return(dc_delete_request(buffer));
}

// ---------------------------------------
// 3.4 Instance States
// ---------------------------------------
// GET /api/instance_states
// ---------------------------------------
public struct rest_response * dc_list_states()
{
	return(dc_get_request("/api/instance_states"));
}

// ---------------------------------------
// 3.5 Instances
// ---------------------------------------
// GET /api/instances
// ---------------------------------------
public struct rest_response * dc_list_instances()
{
	return(dc_get_request("/api/instances"));
}

// ---------------------------------------
// GET /api/instances/:id
// ---------------------------------------
public struct rest_response * dc_get_instance(char * id)
{
	char buffer[_DC_BUFFERSIZE];
	sprintf(buffer,"/api/instances/%s",id);
	return(dc_get_request(buffer));
}

// ---------------------------------------
// POST /api/instances/:id/:action
// ---------------------------------------
public struct rest_response * dc_instance_action(char * id, char * action)
{
	char buffer[_DC_BUFFERSIZE];
	sprintf(buffer,"/api/instances/%s/%s",id,action);
	return(dc_post_request(buffer,(char *) 0));
}

// ---------------------------------------
// START /api/instances/:id
// ---------------------------------------
public struct rest_response * dc_start_instance( char * id )
{
	return( dc_instance_action( id, "start" ) );
}

// ---------------------------------------
// STOP /api/instances/:id
// ---------------------------------------
public struct rest_response * dc_stop_instance( char * id )
{
	return( dc_instance_action( id, "stop" ) );
}

// ---------------------------------------
// CREATE INSTANCE PARAMETERS
// ---------------------------------------
public char * dc_create_instance_message( char * name, char * profile, char * image, char * firewall, char * zone )
{
	char *	filename;
	FILE *	h;
	if (!( filename = rest_temporary_filename("form")))
		return( filename );
	else if (!( h = fopen( filename, "wa" ) ))
		return( liberate( filename ) );
	else
	{

		fprintf(h,"image_id=%s",image);

		if ( rest_valid_string(name) )
			fprintf(h,"&name=%s",name);

		if ( rest_valid_string(profile) )
			fprintf(h,"&hwp_id=%s",profile);

		if ( rest_valid_string(firewall) )
			fprintf(h,"&firewalls1=%s",firewall);

		if ( rest_valid_string(zone) )
			fprintf(h,"&realm_id=%s",zone);

		fclose(h);
		return( filename );
	}
}

// ---------------------------------------
// POST /api/instances
// ---------------------------------------
public struct rest_response * dc_create_instance( char * filename )
{
	char buffer[_DC_BUFFERSIZE];
	sprintf(buffer,"/api/instances");
	return(dc_post_request(buffer,filename));
}

// ---------------------------------------
// DELETE /api/instances/:id
// ---------------------------------------
public struct rest_response * dc_delete_instance( char * id )
{
	char buffer[_DC_BUFFERSIZE];
	sprintf(buffer,"/api/instances/%s",id);
	return(dc_delete_request(buffer));
}

// ---------------------------------------
// 3.6 Keys
// ---------------------------------------
// GET /api/keys
// ---------------------------------------
public struct rest_response * dc_list_keys()
{
	return(dc_get_request("/api/keys"));
}

// ---------------------------------------
// GET /api/keys/:id
// ---------------------------------------
public struct rest_response * dc_get_key(char * id)
{
	char buffer[_DC_BUFFERSIZE];
	sprintf(buffer,"/api/keys/%s",id);
	return(dc_get_request(buffer));
}

// ---------------------------------------
// CREATE KEY MESSAGE
// ---------------------------------------
public char * dc_create_key_message( char * name )
{
	char *	filename;
	FILE *	h;
	if (!( filename = rest_temporary_filename("form")))
		return( filename );
	else if (!( h = fopen( filename, "wa" ) ))
		return( liberate( filename ) );
	else
	{
		fprintf(h,"name=%s",name);
		fclose(h);
		return( filename );
	}
}

// ---------------------------------------
// POST /api/keys
// ---------------------------------------
public struct rest_response * dc_create_key(char * filename)
{
	char buffer[_DC_BUFFERSIZE];
	sprintf(buffer,"/api/keys");
	return(dc_post_request(buffer,filename));
}

// ---------------------------------------
// DELETE /api/keys/:id
// ---------------------------------------
public struct rest_response * dc_delete_key(char * id)
{
	char buffer[_DC_BUFFERSIZE];
	sprintf(buffer,"/api/keys/%s",id);
	return(dc_delete_request(buffer));
}

// ---------------------------------------
// 3.7 Firewalls
// ---------------------------------------
// GET /api/firewalls
// ---------------------------------------
public struct rest_response * dc_list_firewalls()
{
	return(dc_get_request("/api/firewalls"));
}

// ---------------------------------------
// GET /api/firewalls/:id
// ---------------------------------------
public struct rest_response * dc_get_firewall(char * id)
{
	char buffer[_DC_BUFFERSIZE];
	sprintf(buffer,"/api/firewalls/%s",id);
	return(dc_get_request(buffer));
}

// ---------------------------------------
// CREATE FIREWALL MESSAGE
// ---------------------------------------
public char * dc_create_firewall_message( char * name, char * description )
{
	char *	filename;
	FILE *	h;
	if (!( filename = rest_temporary_filename("form")))
		return( filename );
	else if (!( h = fopen( filename, "wa" ) ))
		return( liberate( filename ) );
	else
	{
		fprintf(h,"name=%s",name);

		if ( rest_valid_string(description) )
			fprintf(h,"&description=%s",description);

		fclose(h);
		return( filename );
	}
}

// ---------------------------------------
// POST /api/firewalls
// ---------------------------------------
public struct rest_response * dc_create_firewall(char * filename)
{
	char buffer[_DC_BUFFERSIZE];
	sprintf(buffer,"/api/firewalls");
	return(dc_post_request(buffer,filename));
}

// ---------------------------------------
// DELETE /api/firewalls/:id
// ---------------------------------------
public struct rest_response * dc_delete_firewall(char * id)
{
	char buffer[_DC_BUFFERSIZE];
	sprintf(buffer,"/api/firewalls/%s",id);
	return(dc_delete_request(buffer));
}

// ---------------------------------------
// CREATE RULE MESSAGE
// ---------------------------------------
public char * dc_create_rule_message( char * proto, char * from, char * to, char * range )
{
	char *	filename;
	FILE *	h;
	if (!( filename = rest_temporary_filename("form")))
		return( filename );
	else if (!( h = fopen( filename, "wa" ) ))
		return( liberate( filename ) );
	else
	{
		fprintf(h,"protocol=%s",proto);
		fprintf(h,"&port_from=%s",from);
		fprintf(h,"&port_to=%s",to);
		fprintf(h,"&ip_address1=%s",range);

		fclose(h);
		return( filename );
	}
}

// ---------------------------------------
// POST /api/firewalls/:id/rules
// ---------------------------------------
public struct rest_response * dc_create_rule(char * id, char * filename)
{
	char buffer[_DC_BUFFERSIZE];
	sprintf(buffer,"/api/firewalls/%s/rules",id);
	return(dc_post_request(buffer,filename));
}

// ---------------------------------------
// DELETE /api/firewalls/:id/:rule_id
// ---------------------------------------
public struct rest_response * dc_delete_rule(char * fwid, char * rid)
{
	char buffer[_DC_BUFFERSIZE];
	sprintf(buffer,"/api/firewalls/%s/%s",fwid,rid);
	return(dc_delete_request(buffer));
}

// ---------------------------------------
// 3.8 Addresses
// ---------------------------------------
// GET /api/addresses
// ---------------------------------------
public struct rest_response * dc_list_addresses()
{
	return(dc_get_request("/api/addresses"));
}

// ---------------------------------------
// GET /api/addresses/:id
// ---------------------------------------
public struct rest_response * dc_get_address(char * id)
{
	char buffer[_DC_BUFFERSIZE];
	sprintf(buffer,"/api/addresses/%s",id);
	return(dc_get_request(buffer));
}

// ---------------------------------------
// POST /api/addresses
// ---------------------------------------
public struct rest_response * dc_create_address()
{
	char buffer[_DC_BUFFERSIZE];
	sprintf(buffer,"/api/addresses");
	return(dc_post_request(buffer,(char *) 0));
}

// ---------------------------------------
// DELETE /api/addresses/:id
// ---------------------------------------
public struct rest_response * dc_delete_address(char * id)
{
	char buffer[_DC_BUFFERSIZE];
	sprintf(buffer,"/api/addresses/%s",id);
	return(dc_delete_request(buffer));
}

// ---------------------------------------
// POST /api/addresses/:id/associate
// ---------------------------------------
public struct rest_response * dc_associate_address(char * id, char * server)
{
	FILE *	h;
	char * filename;
	struct	rest_response * rptr=(struct rest_response *) 0;
	char buffer[_DC_BUFFERSIZE];
	sprintf(buffer,"/api/addresses/%s/associate",id);
	if (( filename = rest_temporary_filename("form")) != (char *) 0)
	{
		if (( h = fopen( filename, "wa" )) != (FILE *) 0)
		{
			fprintf(h,"instance_id=%s",server);
			fclose(h);
			rptr = dc_post_request(buffer,filename);
		}
		filename = liberate( filename );
	}
	return( rptr );
}

// POST /api/addresses/:id/disassociate
public struct rest_response * dc_disassociate_address(char * id)
{
	char buffer[_DC_BUFFERSIZE];
	sprintf(buffer,"/api/addresses/%s/disassociate",id);
	return(dc_post_request(buffer,(char *) 0));
}

// ---------------------------------------
// 3.9 Load Balancers
// ---------------------------------------
// GET /api/load_balancers
// ---------------------------------------
public struct rest_response * dc_list_loadbalancers()
{
	return(dc_get_request("/api/load_balancers"));
}

// ---------------------------------------
// GET /api/load_balancers/:id
// ---------------------------------------
public struct rest_response * dc_get_loadbalancer(char * id)
{
	char buffer[_DC_BUFFERSIZE];
	sprintf(buffer,"/api/load_balancers/%s",id);
	return(dc_get_request(buffer));
}

// ---------------------------------------
// CREATE LOADBALANCER MESSAGE
// ---------------------------------------
public char * dc_create_loadbalancer_message( char * name, char * realm, char * protocol, char * port1, char * port2 )
{
	char *	filename;
	FILE *	h;
	if (!( filename = rest_temporary_filename("form")))
		return( filename );
	else if (!( h = fopen( filename, "wa" ) ))
		return( liberate( filename ) );
	else
	{
		fprintf(h,"name=%s",name);
		fprintf(h,"&realm_id=%s",realm);
		fprintf(h,"&listener_protocol=%s",protocol);
		fprintf(h,"&listener_balancer_port=%s",port1);
		fprintf(h,"&listener_instance_port=%s",port2);

		fclose(h);
		return( filename );
	}
}

// ---------------------------------------
// POST /api/load_balancers
// ---------------------------------------
public struct rest_response * dc_create_loadbalancer(char * filename)
{
	char buffer[_DC_BUFFERSIZE];
	sprintf(buffer,"/api/load_balancers");
	return(dc_post_request(buffer,filename));
}

// ---------------------------------------
// DELETE /api/load_balancers/:id
// ---------------------------------------
public struct rest_response * dc_delete_loadbalancer(char * id)
{
	char buffer[_DC_BUFFERSIZE];
	sprintf(buffer,"/api/load_balancers/%s",id);
	return(dc_delete_request(buffer));
}

// ---------------------------------------
// POST /api/load_balancers/:id/register
// ---------------------------------------
public struct rest_response * dc_register_loadbalancer(char * id,char * server)
{
	FILE *	h;
	char * filename;
	struct	rest_response * rptr=(struct rest_response *) 0;
	char buffer[_DC_BUFFERSIZE];
	sprintf(buffer,"/api/load_balancers/%s/register",id);
	if (( filename = rest_temporary_filename("form")) != (char *) 0)
	{
		if (( h = fopen( filename, "wa" )) != (FILE *) 0)
		{
			fprintf(h,"instance_id=%s",server);
			fclose(h);
			rptr = dc_post_request(buffer,filename);
		}
		filename = liberate( filename );
	}
	return( rptr );
}

// ---------------------------------------
// POST /api/load_balancers/:id/unregister
// ---------------------------------------
public struct rest_response * dc_unregister_loadbalancer(char * id,char * server)
{
	FILE *	h;
	char * filename;
	struct	rest_response * rptr=(struct rest_response *) 0;
	char buffer[_DC_BUFFERSIZE];
	sprintf(buffer,"/api/load_balancers/%s/unregister",id);
	if (( filename = rest_temporary_filename("form")) != (char *) 0)
	{
		if (( h = fopen( filename, "wa" )) != (FILE *) 0)
		{
			fprintf(h,"instance_id=%s",server);
			fclose(h);
			rptr = dc_post_request(buffer,filename);
		}
		filename = liberate( filename );
	}
	return( rptr );
}

// ---------------------------------------
// GET /api/storage_volumes
// ---------------------------------------
public struct rest_response * dc_list_storage()
{
	return(dc_get_request("/api/storage_volumes"));
}

// ---------------------------------------
// GET /api/storage_volumes/:id
// ---------------------------------------
public struct rest_response * dc_get_storage(char * id)
{
	char buffer[_DC_BUFFERSIZE];
	sprintf(buffer,"/api/storage_volumes/%s",id);
	return(dc_get_request(buffer));
}

// ---------------------------------------
// CREATE STORAGE MESSAGE
// ---------------------------------------
public char * dc_create_storage_message(char * name, char * size, char * realm)
{
	char *	filename;
	FILE *	h;
	if (!( filename = rest_temporary_filename("form")))
		return( filename );
	else if (!( h = fopen( filename, "wa" ) ))
		return( liberate( filename ) );
	else
	{
		fprintf(h,"name=%s",name);
		fprintf(h,"&capacity=%s",realm);
		fprintf(h,"&realm_id=%s",realm);
		fclose(h);
		return( filename );
	}
}

// ---------------------------------------
// POST /api/storage_volumes
// ---------------------------------------
public struct rest_response * dc_create_storage(char * filename)
{
	char buffer[_DC_BUFFERSIZE];
	sprintf(buffer,"/api/storage_volumes");
	return(dc_post_request(buffer,filename));
}

// ---------------------------------------
// DELETE /api/storage_volumes/:id
// ---------------------------------------
public struct rest_response * dc_delete_storage(char * id)
{
	char buffer[_DC_BUFFERSIZE];
	sprintf(buffer,"/api/storage_volumes/%s",id);
	return(dc_delete_request(buffer));
}

// ---------------------------------------
// POST /api/storage_volumes/:id/attach
// ---------------------------------------
public struct rest_response * dc_attach_storage(char * id,char * server)
{
	FILE *	h;
	char * filename;
	struct	rest_response * rptr=(struct rest_response *) 0;
	char buffer[_DC_BUFFERSIZE];
	sprintf(buffer,"/api/storage_volumes/%s/attach",id);
	if (( filename = rest_temporary_filename("form")) != (char *) 0)
	{
		if (( h = fopen( filename, "wa" )) != (FILE *) 0)
		{
			fprintf(h,"instance_id=%s",server);
			fclose(h);
			rptr = dc_post_request(buffer,filename);
		}
		filename = liberate( filename );
	}
	return( rptr );
}

// ---------------------------------------
// POST /api/storage_volumes/:id/detach
// ---------------------------------------
public struct rest_response * dc_detach_storage(char * id)
{
	char buffer[_DC_BUFFERSIZE];
	sprintf(buffer,"/api/storage_volumes/%s/detach",id);
	return(dc_post_request(buffer,(char *) 0));
}

// ---------------------------------------
// 4.3 Blob Storage
// ---------------------------------------
// GET /api/buckets
// ---------------------------------------
public struct rest_response * dc_list_buckets()
{
	return(dc_get_request("/api/buckets"));
}

// ---------------------------------------
// GET /api/buckets/:id
// ---------------------------------------
public struct rest_response * dc_get_bucket(char * id)
{
	char buffer[_DC_BUFFERSIZE];
	sprintf(buffer,"/api/buckets/%s",id);
	return(dc_delete_request(buffer));
}

// ---------------------------------------
// CREATE BUCKET MESSAGE
// ---------------------------------------
public char * dc_create_bucket_message(char * name, char * location)
{
	char *	filename;
	FILE *	h;
	if (!( filename = rest_temporary_filename("form")))
		return( filename );
	else if (!( h = fopen( filename, "wa" ) ))
		return( liberate( filename ) );
	else
	{
		fprintf(h,"name=%s",name);
		fprintf(h,"&location=%s",location);
		fclose(h);
		return( filename );
	}
}

// ---------------------------------------
// POST /api/buckets
// ---------------------------------------
public struct rest_response * dc_create_bucket(char * filename)
{
	char buffer[_DC_BUFFERSIZE];
	sprintf(buffer,"/api/buckets");
	return(dc_post_request(buffer,filename));
}

// ---------------------------------------
// DELETE /api/buckets/:id
// ---------------------------------------
public struct rest_response * dc_delete_bucket(char * id)
{
	char buffer[_DC_BUFFERSIZE];
	sprintf(buffer,"/api/buckets/%s",id);
	return(dc_delete_request(buffer));
}

// ---------------------------------------
// GET /api/buckets/:bucket_id/:blob_id
// ---------------------------------------
public struct rest_response * dc_get_blob_info(char * bucket, char * blob)
{
	char buffer[_DC_BUFFERSIZE];
	sprintf(buffer,"/api/buckets/%s/%s",bucket,blob);
	return(dc_get_request(buffer));
}

// ---------------------------------------
// GET /api/buckets/:bucket_id/:blob_id/content
// ---------------------------------------
public struct rest_response * dc_get_blob_content(char * bucket, char * blob)
{
	char buffer[_DC_BUFFERSIZE];
	sprintf(buffer,"/api/buckets/%s/%s/content",bucket,blob);
	return(dc_get_request(buffer));
}

// ---------------------------------------
// PUT /api/buckets/:bucket_id/:blob_id
// ---------------------------------------
public struct rest_response * dc_update_blob(char * bucket, char * blob, char * filename)
{
	char buffer[_DC_BUFFERSIZE];
	sprintf(buffer,"/api/buckets/%s/%s",bucket,blob);
	return(dc_put_request(buffer,filename));
}

// ---------------------------------------
// POST /api/buckets/:bucket_id
// ---------------------------------------
public struct rest_response * dc_create_blob(char * bucket, char *filename)
{
	char buffer[_DC_BUFFERSIZE];
	sprintf(buffer,"/api/buckets/%s",bucket);
	return(dc_post_request(buffer,filename));
}

// ---------------------------------------
// DELETE /api/buckets/:bucket_id/:blob_id
// ---------------------------------------
public struct rest_response * dc_delete_blob(char * bucket, char * blob)
{
	char buffer[_DC_BUFFERSIZE];
	sprintf(buffer,"/api/buckets/%s/%s",bucket,blob);
	return(dc_delete_request(buffer));
}

// ---------------------------------------
// POST /api/buckets/:bucket_id/:blob_id
// ---------------------------------------
public struct rest_response * dc_update_blob_info(char * bucket, char * blob)
{
	char buffer[_DC_BUFFERSIZE];
	sprintf(buffer,"/api/buckets/%s/%s",bucket,blob);
	return(dc_post_request(buffer,(char *) 0));
}

	/* ----------- */
#endif	/* _dcclient_c */
	/* ----------- */

redpajama_set_name: RedPajamaGithub


text:
class ChangeToHeaderAndCcHeaderFromStringToText < ActiveRecord::Migration
  def up
    change_column :messages, :to_header, :text
    change_column :messages, :cc_header, :text
  end
  def down
    change_column :messages, :to_header, :string
    change_column :messages, :cc_header, :string
  end
end


text:
package br.ufc.lps.model;

import java.util.List;

public class MappingItensRnfObjecJson {
	private String name;
	private List<MappingItensRnfObjecJson> children;

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public List<MappingItensRnfObjecJson> getChildren() {
		return children;
	}

	public void setChildren(List<MappingItensRnfObjecJson> children) {
		this.children = children;
	}

	@Override
	public String toString() {
		return "MappingItensRnfObjecJson [name=" + name + ", children=" + children + "]";
	}
}


text:
Called when user starts dragging a draggable column.

    onColumnDragStart = function(event)

This event is triggered when user starts dragging a draggable column. It will receive one argument event
that will contain information what column was dragged.

You can add event listener during the object creation:
<textarea class="javascript">
let grid = new w2grid({
    name    : 'grid',
    columns: [
        { field: 'recid', text: 'ID', size: '50px' },
        { field: 'lname', text: 'Last Name', size: '30%' },
        { field: 'fname', text: 'First Name', size: '30%' },
        { field: 'email', text: 'Email', size: '40%' },
        { field: 'sdate', text: 'End Date', size: '120px' }
    ],
    records: [
        { recid: 1, fname: 'John', lname: 'doe', email: 'vitali@gmail.com', sdate: '1/3/2012' },
        { recid: 2, fname: 'Stuart', lname: 'Motzart', email: 'jdoe@gmail.com', sdate: '2/4/2012' },
        { recid: 3, fname: 'Jin', lname: 'Franson', email: '--', sdate: '4/23/2012' },
        { recid: 4, fname: 'Susan', lname: 'Ottie', email: 'jdoe@gmail.com', sdate: '5/3/2012' },
        { recid: 5, fname: 'Kelly', lname: 'Silver', email: 'jdoe@gmail.com', sdate: '4/3/2012' },
        { recid: 6, fname: 'Francis', lname: 'Gatos', email: 'vitali@gmail.com', sdate: '2/5/2012' }
    ],
    onColumnDragStart: function(event) {
        console.log(event);
    }
});
</textarea>

or after the object has been created:

<textarea class="javascript">
w2ui.grid.on('columnDragStart', function(event) {
    console.log(event);
});
</textarea>

Your event listener can be executed before or after the event has been processed. You can also cancel
the default behavior. See Events page in utilities.


text:
import { Params } from '@angular/router';

export class ActivatedRouteSnapshotMock {
    public paramsGetSpy: jasmine.Spy;
    private _params: Params = {};

    constructor() {
        this._params['id'] = 1;
    }

    setupSpies(): void {
        this.paramsGetSpy = spyOn(this, 'params').and.callThrough();
    }

    get params(): Params {
        return this._params;
    }
}


text:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<META http-equiv="Content-Type" content="text/html; charset=UTF-8">
<TITLE>
Uses of Class org.apache.hadoop.yarn.webapp.hamlet.Hamlet.DL (hadoop-yarn-common 2.3.0 API)
</TITLE>

<META NAME="date" CONTENT="2015-03-06">

<LINK REL ="stylesheet" TYPE="text/css" HREF="../../../../../../../stylesheet.css" TITLE="Style">

      Overview
      Package
      Class
    Use
      Tree
      Deprecated
      Index
      Help

 PREV
 NEXT

  FRAMES
 NO FRAMES

  All Classes

Uses of Class
org.apache.hadoop.yarn.webapp.hamlet.Hamlet.DL

Packages that use Hamlet.DL

org.apache.hadoop.yarn.webapp.hamlet

Uses of Hamlet.DL in org.apache.hadoop.yarn.webapp.hamlet

Methods in org.apache.hadoop.yarn.webapp.hamlet that return Hamlet.DL

 Hamlet.DL<T>
Hamlet.DL.$class(String value)

 Hamlet.DL<T>
Hamlet.DL.$dir(HamletSpec.Dir value)

 Hamlet.DL<T>
Hamlet.DL.$id(String value)

 Hamlet.DL<T>
Hamlet.DL.$lang(String value)

 Hamlet.DL<T>
Hamlet.DL.$onclick(String value)

 Hamlet.DL<T>
Hamlet.DL.$ondblclick(String value)

 Hamlet.DL<T>
Hamlet.DL.$onkeydown(String value)

 Hamlet.DL<T>
Hamlet.DL.$onkeypress(String value)

 Hamlet.DL<T>
Hamlet.DL.$onkeyup(String value)

 Hamlet.DL<T>
Hamlet.DL.$onmousedown(String value)

 Hamlet.DL<T>
Hamlet.DL.$onmousemove(String value)

 Hamlet.DL<T>
Hamlet.DL.$onmouseout(String value)

 Hamlet.DL<T>
Hamlet.DL.$onmouseover(String value)

 Hamlet.DL<T>
Hamlet.DL.$onmouseup(String value)

 Hamlet.DL<T>
Hamlet.DL.$style(String value)

 Hamlet.DL<T>
Hamlet.DL.$title(String value)

 Hamlet.DL<T>
Hamlet.DL.dd(String cdata)

 Hamlet.DL<Hamlet>
Hamlet.dl()

 Hamlet.DL<Hamlet.HTML<T>>
Hamlet.HTML.dl()

 Hamlet.DL<Hamlet.TD<T>>
Hamlet.TD.dl()

 Hamlet.DL<Hamlet.TH<T>>
Hamlet.TH.dl()

 Hamlet.DL<Hamlet.BUTTON<T>>
Hamlet.BUTTON.dl()

 Hamlet.DL<Hamlet.FIELDSET<T>>
Hamlet.FIELDSET.dl()

 Hamlet.DL<Hamlet.FORM<T>>
Hamlet.FORM.dl()

 Hamlet.DL<Hamlet.LI<T>>
Hamlet.LI.dl()

 Hamlet.DL<Hamlet.DD<T>>
Hamlet.DD.dl()

 Hamlet.DL<Hamlet.DEL<T>>
Hamlet.DEL.dl()

 Hamlet.DL<Hamlet.INS<T>>
Hamlet.INS.dl()

 Hamlet.DL<Hamlet.BLOCKQUOTE<T>>
Hamlet.BLOCKQUOTE.dl()

 Hamlet.DL<Hamlet.OBJECT<T>>
Hamlet.OBJECT.dl()

 Hamlet.DL<Hamlet.MAP<T>>
Hamlet.MAP.dl()

 Hamlet.DL<Hamlet.DIV<T>>
Hamlet.DIV.dl()

 Hamlet.DL<Hamlet.BODY<T>>
Hamlet.BODY.dl()

 Hamlet.DL<Hamlet>
Hamlet.dl(String selector)

 Hamlet.DL<Hamlet.HTML<T>>
Hamlet.HTML.dl(String selector)

 Hamlet.DL<Hamlet.TD<T>>
Hamlet.TD.dl(String selector)

 Hamlet.DL<Hamlet.TH<T>>
Hamlet.TH.dl(String selector)

 Hamlet.DL<Hamlet.BUTTON<T>>
Hamlet.BUTTON.dl(String selector)

 Hamlet.DL<Hamlet.FIELDSET<T>>
Hamlet.FIELDSET.dl(String selector)

 Hamlet.DL<Hamlet.FORM<T>>
Hamlet.FORM.dl(String selector)

 Hamlet.DL<Hamlet.LI<T>>
Hamlet.LI.dl(String selector)

 Hamlet.DL<Hamlet.DD<T>>
Hamlet.DD.dl(String selector)

 Hamlet.DL<Hamlet.DEL<T>>
Hamlet.DEL.dl(String selector)

 Hamlet.DL<Hamlet.INS<T>>
Hamlet.INS.dl(String selector)

 Hamlet.DL<Hamlet.BLOCKQUOTE<T>>
Hamlet.BLOCKQUOTE.dl(String selector)

 Hamlet.DL<Hamlet.OBJECT<T>>
Hamlet.OBJECT.dl(String selector)

 Hamlet.DL<Hamlet.MAP<T>>
Hamlet.MAP.dl(String selector)

 Hamlet.DL<Hamlet.DIV<T>>
Hamlet.DIV.dl(String selector)

 Hamlet.DL<Hamlet.BODY<T>>
Hamlet.BODY.dl(String selector)

 Hamlet.DL<T>
Hamlet.DL.dt(String cdata)

Methods in org.apache.hadoop.yarn.webapp.hamlet that return types with arguments of type Hamlet.DL

 Hamlet.DD<Hamlet.DL<T>>
Hamlet.DL.dd()

 Hamlet.DT<Hamlet.DL<T>>
Hamlet.DL.dt()

      Overview
      Package
      Class
    Use
      Tree
      Deprecated
      Index
      Help

 PREV
 NEXT

  FRAMES
 NO FRAMES

  All Classes

Copyright © 2015 Apache Software Foundation. All Rights Reserved.


text:
if ((typeof module!="undefined") && (module.exports)) {
  Gate=require("./gate.js");
  ObjectDescriptor=require("./localObjectDescriptor.js");
  IdFactory=require("./idFactory");
}

function LocalGate() {
  this.ids=new Map();
  this.obj=new Map();
  this.desc=new Map();
  this.idf=new IdFactory();
}

LocalGate.prototype=new Gate();

/**
 * saves a new object under the given id
 * @returns ObjectDescriptor
 * @throws String if object is already registered
**/
LocalGate.prototype.acceptId=function(id,object,callback,name) {
  if (this.ids.get(id)!=undefined) {
    throw new Error("id "+id+" is already in use");
  } else {
    if (this.obj.get(object)!=undefined) {
      throw new Error("object is already used");
    } else {
      var od=new LocalObjectDescriptor(this,object,name);
      this.ids.set(id,od);
      this.obj.set(object,id);
      this.desc.set(od,id);
      callback(id,od);
    }
  }
};

/**
 * creates an id for a new object
**/
LocalGate.prototype.produceId=function(obj,callback,name) {
  var id=this.idf.newId();
  this.acceptId(id,obj,callback,name);
}

LocalGate.prototype.getId=function(obj) {
  return this.obj.get(obj);
}

LocalGate.prototype.getIdByDescriptor=function(descriptor) {
  return this.desc.get(descriptor);
}

LocalGate.prototype.hasId=function(id) {
  return (this.ids.get(id)!=undefined);
}

LocalGate.prototype.getDescriptorById=function(id,callback) {
  var desc=this.ids.get(id);
  if (desc==undefined) {
    throw new Error("id "+id+" is not registered");
  } else {
    callback(desc);
  }
}

LocalGate.prototype.getDescriptorByObj=function(obj,callback) {
  var id=this.getId(obj);
  if (id==undefined) {
    callback(undefined);
  } else {
    callback(this.ids.get(id));
  }
}

if ((typeof module!="undefined") && (module.exports)) {
  module.exports=LocalGate;
}


text:
class AddClaimedPatientId < ActiveRecord::Migration[5.0]
  def change
    change_table :family_members do |t|
      t.integer :claimed_patient_id
    end
  end
end


text:
#region Apache License Version 2.0

#endregion Apache License Version 2.0

using SF.Sys.Reflection;
using System;
using System.Collections.Generic;
using System.Reflection;

namespace SF.Sys.Services
{

	public enum ServiceResolveType
	{
		None,
		Direct,
		Lazy,
		Func,
		ResolveByIdent,
		Enumerable
	}
	public static class ServiceDetectorExtension
	{
		public static ServiceResolveType DetectService(this IServiceDetector Detector, Type Type, out Type RealType)
		{
			ServiceResolveType ResolveType = ServiceResolveType.Direct;
			RealType = Type;

			if (Type.IsGeneric())
			{
				var gtd = Type.GetGenericTypeDefinition();
				if (gtd == typeof(Lazy<>))
					ResolveType = ServiceResolveType.Lazy;
				else if (gtd == typeof(Func<>))
					ResolveType = ServiceResolveType.Func;
				else if (gtd == typeof(TypedInstanceResolver<>))
					ResolveType = ServiceResolveType.ResolveByIdent;
				else if (gtd == typeof(IEnumerable<>))
					return ServiceResolveType.Enumerable;

				if (ResolveType != ServiceResolveType.Direct)
					RealType = Type.GetGenericArguments()[0];
			}
			if (Detector.IsService(RealType))
				return ResolveType;
			if (RealType.IsGeneric() && Detector.IsService(RealType.GetGenericTypeDefinition()))
				return ResolveType;
			if (ResolveType != ServiceResolveType.Direct)
				throw new InvalidOperationException($"䶨Òå·þÎñ:{RealType}");
			return ServiceResolveType.None;
		}
		public static ServiceResolveType DetectService(this IServiceDetector Detector, Type Type)
		{
			return Detector.DetectService(Type, out var rt);
		}
	}
}


text:
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef nsGnomeVFSService_h_
#define nsGnomeVFSService_h_

#include "nsIGnomeVFSService.h"
#include "mozilla/Attributes.h"

#define NS_GNOMEVFSSERVICE_CID \
{0x5f43022c, 0x6194, 0x4b37, {0xb2, 0x6d, 0xe4, 0x10, 0x24, 0x62, 0x52, 0x64}}

class nsGnomeVFSService MOZ_FINAL : public nsIGnomeVFSService
{
public:
  NS_DECL_ISUPPORTS
  NS_DECL_NSIGNOMEVFSSERVICE

  NS_HIDDEN_(nsresult) Init();
};

#endif


text:
/* $OpenBSD: isp_target.c,v 1.1 2000/02/20 21:22:40 mjacob Exp $ */
/*
 * Machine and OS Independent Target Mode Code for the Qlogic SCSI/FC adapters.
 *
 * Copyright (c) 1999 by Matthew Jacob
 * All rights reserved.
 * mjacob@feral.com
 *
 * 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 immediately at the beginning of the file, without modification,
 *    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 name of the author may not be used to endorse or promote products
 *    derived from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS 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 AUTHOR OR 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 header file appropriate for platform we're building on.
 */

#ifdef	__NetBSD__
#include <dev/ic/isp_netbsd.h>
#endif
#ifdef	__FreeBSD__
#include <dev/isp/isp_freebsd.h>
#endif
#ifdef	__OpenBSD__
#include <dev/ic/isp_openbsd.h>
#endif
#ifdef	__linux__
#include "isp_linux.h"
#endif

#ifdef	ISP_TARGET_MODE
int isp_tdebug = 0;

static void isp_got_msg __P((struct ispsoftc *, int, in_entry_t *));
static void isp_got_msg_fc __P((struct ispsoftc *, int, in_fcentry_t *));
static void isp_notify_ack __P((struct ispsoftc *, void *));
static void isp_handle_atio(struct ispsoftc *, at_entry_t *);
static void isp_handle_atio2(struct ispsoftc *, at2_entry_t *);
static void isp_handle_ctio(struct ispsoftc *, ct_entry_t *);
static void isp_handle_ctio2(struct ispsoftc *, ct2_entry_t *);

/*
 * The Qlogic driver gets an interrupt to look at response queue entries.
 * Some of these are status completions for initiatior mode commands, but
 * if target mode is enabled, we get a whole wad of response queue entries
 * to be handled here.
 *
 * Basically the split into 3 main groups: Lun Enable/Modification responses,
 * SCSI Command processing, and Immediate Notification events.
 *
 * You start by writing a request queue entry to enable target mode (and
 * establish some resource limitations which you can modify later).
 * The f/w responds with a LUN ENABLE or LUN MODIFY response with
 * the status of this action. If the enable was successful, you can expect...
 *
 * Response queue entries with SCSI commands encapsulate show up in an ATIO
 * (Accept Target IO) type- sometimes with enough info to stop the command at
 * this level. Ultimately the driver has to feed back to the f/w's request
 * queue a sequence of CTIOs (continue target I/O) that describe data to
 * be moved and/or status to be sent) and finally finishing with sending
 * to the f/w's response queue an ATIO which then completes the handshake
 * with the f/w for that command. There's a lot of variations on this theme,
 * including flags you can set in the CTIO for the Qlogic 2X00 fibre channel
 * cards that 'auto-replenish' the f/w's ATIO count, but this is the basic
 * gist of it.
 *
 * The third group that can show up in the response queue are Immediate
 * Notification events. These include things like notifications of SCSI bus
 * resets, or Bus Device Reset messages or other messages received. This
 * a classic oddbins area. It can get  a little wierd because you then turn
 * around and acknowledge the Immediate Notify by writing an entry onto the
 * request queue and then the f/w turns around and gives you an acknowledgement
 * to *your* acknowledgement on the response queue (the idea being to let
 * the f/w tell you when the event is *really* over I guess).
 *
 */

/*
 * A new response queue entry has arrived. The interrupt service code
 * has already swizzled it into the platform dependent from canonical form.
 *
 * Because of the way this driver is designed, unfortunately most of the
 * actual synchronization work has to be done in the platform specific
 * code- we have no synchroniation primitives in the common code.
 */

int
isp_target_notify(isp, vptr, optrp)
	struct ispsoftc *isp;
	void *vptr;
	u_int16_t *optrp;
{
	u_int16_t status, seqid;
	union {
		at_entry_t	*atiop;
		at2_entry_t	*at2iop;
		ct_entry_t	*ctiop;
		ct2_entry_t	*ct2iop;
		lun_entry_t	*lunenp;
		in_entry_t	*inotp;
		in_fcentry_t	*inot_fcp;
		na_entry_t	*nackp;
		na_fcentry_t	*nack_fcp;
		isphdr_t	*hp;
		void *		*vp;
#define	atiop		unp.atiop
#define	at2iop		unp.at2iop
#define	ctiop		unp.ctiop
#define	ct2iop		unp.ct2iop
#define	lunenp		unp.lunenp
#define	inotp		unp.inotp
#define	inot_fcp	unp.inot_fcp
#define	nackp		unp.nackp
#define	nack_fcp	unp.nack_fcp
#define	hdrp		unp.hp
	} unp;
	int bus, rval = 0;

	unp.vp = vptr;

	ISP_TDQE(isp, "isp_target_notify", (int) *optrp, vptr);

	switch(hdrp->rqs_entry_type) {
	case RQSTYPE_ATIO:
		isp_handle_atio(isp, atiop);
		break;
	case RQSTYPE_CTIO:
		isp_handle_ctio(isp, ctiop);
		break;
	case RQSTYPE_ATIO2:
		isp_handle_atio2(isp, at2iop);
		break;
	case RQSTYPE_CTIO2:
		isp_handle_ctio2(isp, ct2iop);
		break;
	case RQSTYPE_ENABLE_LUN:
	case RQSTYPE_MODIFY_LUN:
		(void) isp_async(isp, ISPASYNC_TARGET_ACTION, vptr);
		break;

	case RQSTYPE_NOTIFY:
		/*
		 * Either the ISP received a SCSI message it can't
		 * handle, or it's returning an Immed. Notify entry
		 * we sent. We can send Immed. Notify entries to
		 * increment the firmware's resource count for them
		 * (we set this initially in the Enable Lun entry).
		 */
		bus = 0;
		if (IS_FC(isp)) {
			status = inot_fcp->in_status;
			seqid = inot_fcp->in_seqid;
		} else {
			status = inotp->in_status & 0xff;
			seqid = inotp->in_seqid;
			if (IS_DUALBUS(isp)) {
				bus = (inotp->in_iid & 0x80) >> 7;
				inotp->in_iid &= ~0x80;
			}
		}
		ITDEBUG(2, ("isp_target_notify: Immediate Notify, "
		    "status=0x%x seqid=0x%x\n", status, seqid));
		switch (status) {
		case IN_RESET:
			(void) isp_async(isp, ISPASYNC_BUS_RESET, &bus);
			break;
		case IN_MSG_RECEIVED:
		case IN_IDE_RECEIVED:
			if (IS_FC(isp)) {
				isp_got_msg_fc(isp, bus, vptr);
			} else {
				isp_got_msg(isp, bus, vptr);
			}
			break;
		case IN_RSRC_UNAVAIL:
			PRINTF("%s: Firmware out of ATIOs\n", isp->isp_name);
			break;
		case IN_ABORT_TASK:
			PRINTF("%s: Abort Task for Initiator %d RX_ID 0x%x\n",
			    isp->isp_name, inot_fcp->in_iid, seqid);
			break;
		case IN_PORT_LOGOUT:
			PRINTF("%s: Port Logout for Initiator %d RX_ID 0x%x\n",
			    isp->isp_name, inot_fcp->in_iid, seqid);
			break;
		case IN_PORT_CHANGED:
			PRINTF("%s: Port Changed for Initiator %d RX_ID 0x%x\n",
			    isp->isp_name, inot_fcp->in_iid, seqid);
			break;
		case IN_GLOBAL_LOGO:
			PRINTF("%s: All ports logged out\n", isp->isp_name);
			break;
		default:
			PRINTF("%s: bad status (0x%x) in isp_target_notify\n",
			    isp->isp_name, status);
			break;
		}
		isp_notify_ack(isp, vptr);
		break;

	case RQSTYPE_NOTIFY_ACK:
		/*
		 * The ISP is acknowledging our acknowledgement of an
		 * Immediate Notify entry for some asynchronous event.
		 */
		if (IS_FC(isp)) {
			ITDEBUG(2, ("%s: Notify Ack status=0x%x seqid 0x%x\n",
			    isp->isp_name, nack_fcp->na_status,
			    nack_fcp->na_seqid));
		} else {
			ITDEBUG(2, ("%s: Notify Ack event 0x%x status=0x%x "
			    "seqid 0x%x\n", isp->isp_name, nackp->na_event,
			    nackp->na_status, nackp->na_seqid));
		}
		break;
	default:
		PRINTF("%s: Unknown entry type 0x%x in isp_target_notify",
		    isp->isp_name, hdrp->rqs_entry_type);
		rval = -1;
		break;
	}
#undef	atiop
#undef	at2iop
#undef	ctiop
#undef	ct2iop
#undef	lunenp
#undef	inotp
#undef	inot_fcp
#undef	nackp
#undef	nack_fcp
#undef	hdrp
	return (rval);
}

/*
 * Toggle (on/off) target mode for bus/target/lun
 *
 * The caller has checked for overlap and legality.
 *
 * Note that not all of bus, target or lun can be paid attention to.
 * Note also that this action will not be complete until the f/w writes
 * response entry. The caller is responsible for synchronizing this.
 */
int
isp_lun_cmd(isp, cmd, bus, tgt, lun, opaque)
	struct ispsoftc *isp;
	int cmd;
	int bus;
	int tgt;
	int lun;
	u_int32_t opaque;
{
	lun_entry_t el;
	u_int16_t iptr, optr;
	void *outp;

	MEMZERO(&el, sizeof (el));
	if (IS_DUALBUS(isp)) {
		el.le_rsvd = (bus & 0x1) << 7;
	}
	el.le_cmd_count = DFLT_CMD_CNT;
	el.le_in_count = DFLT_INOTIFY;
	if (cmd == RQSTYPE_ENABLE_LUN) {
		if (IS_SCSI(isp)) {
			el.le_flags = LUN_TQAE;
			el.le_cdb6len = 12;
			el.le_cdb7len = 12;
		}
	} else if (cmd == -RQSTYPE_ENABLE_LUN) {
		cmd = RQSTYPE_ENABLE_LUN;
		el.le_cmd_count = 0;
		el.le_in_count = 0;
	} else if (cmd == -RQSTYPE_MODIFY_LUN) {
		cmd = RQSTYPE_MODIFY_LUN;
		el.le_ops = LUN_CCDECR | LUN_INDECR;
	} else {
		el.le_ops = LUN_CCINCR | LUN_ININCR;
	}
	el.le_header.rqs_entry_type = cmd;
	el.le_header.rqs_entry_count = 1;
	el.le_reserved = opaque;
	if (IS_SCSI(isp)) {
		el.le_tgt = tgt;
		el.le_lun = lun;
#ifndef	ISP2100_SCCLUN
	} else {
		el.le_lun = lun;
#endif
	}

	if (isp_getrqentry(isp, &iptr, &optr, &outp)) {
		PRINTF("%s: Request Queue Overflow in isp_lun_cmd\n",
		    isp->isp_name);
		return (-1);
	}
	ISP_SWIZ_ENABLE_LUN(isp, outp, &el);
	ISP_TDQE(isp, "isp_lun_cmd", (int) optr, &el);
	ISP_ADD_REQUEST(isp, iptr);
	return (0);
}

int
isp_target_put_entry(isp, ap)
	struct ispsoftc *isp;
	void *ap;
{
	void *outp;
	u_int16_t iptr, optr;
	u_int8_t etype = ((isphdr_t *) ap)->rqs_entry_type;

	if (isp_getrqentry(isp, &iptr, &optr, &outp)) {
		PRINTF("%s: Request Queue Overflow in isp_target_put_entry "
		    "for type 0x%x\n", isp->isp_name, etype);
		return (-1);
	}
	switch (etype) {
	case RQSTYPE_ATIO:
		ISP_SWIZ_ATIO(isp, outp, ap);
		break;
	case RQSTYPE_ATIO2:
		ISP_SWIZ_ATIO2(isp, outp, ap);
		break;
	case RQSTYPE_CTIO:
		ISP_SWIZ_CTIO(isp, outp, ap);
		break;
	case RQSTYPE_CTIO2:
		ISP_SWIZ_CTIO2(isp, outp, ap);
		break;
	default:
		PRINTF("%s: Unknown type 0x%x in isp_put_entry\n",
		    isp->isp_name, etype);
		return (-1);
	}

	ISP_TDQE(isp, "isp_target_put_entry", (int) optr, ap);;

	ISP_ADD_REQUEST(isp, iptr);
	return (0);
}

int
isp_target_put_atio(isp, iid, tgt, lun, ttype, tval)
	struct ispsoftc *isp;
	int iid;
	int tgt;
	int lun;
	int ttype;
	int tval;
{
	union {
		at_entry_t _atio;
		at2_entry_t _atio2;
	} atun;

	MEMZERO(&atun, sizeof atun);
	if (IS_FC(isp)) {
		atun._atio2.at_header.rqs_entry_type = RQSTYPE_ATIO2;
		atun._atio2.at_header.rqs_entry_count = 1;
#ifdef ISP2100_SCCLUN
		atun._atio2.at_scclun = (uint16_t) lun;
#else
		atun._atio2.at_lun = (uint8_t) lun;
#endif
		atun._atio2.at_status = CT_OK;
	} else {
		atun._atio.at_header.rqs_entry_type = RQSTYPE_ATIO;
		atun._atio.at_header.rqs_entry_count = 1;
		atun._atio.at_iid = iid;
		atun._atio.at_tgt = tgt;
		atun._atio.at_lun = lun;
		atun._atio.at_tag_type = ttype;
		atun._atio.at_tag_val = tval;
		atun._atio.at_status = CT_OK;
	}
	return (isp_target_put_entry(isp, &atun));
}

/*
 * Command completion- both for handling cases of no resources or
 * no blackhole driver, or other cases where we have to, inline,
 * finish the command sanely, or for normal command completion.
 *
 * The 'completion' code value has the scsi status byte in the low 8 bits.
 * If status is a CHECK CONDITION and bit 8 is nonzero, then bits 12..15 have
 * the sense key and  bits 16..23 have the ASCQ and bits 24..31 have the ASC
 * values.
 *
 * NB: the key, asc, ascq, cannot be used for parallel SCSI as it doesn't
 * NB: inline SCSI sense reporting.
 *
 * For both parallel && fibre channel, we use the feature that does
 * an automatic resource autoreplenish so we don't have then later do
 * put of an atio to replenish the f/w's resource count.
 */

int
isp_endcmd(struct ispsoftc *isp, void *arg, u_int32_t code, u_int32_t hdl)
{
	int sts;
	union {
		ct_entry_t _ctio;
		ct2_entry_t _ctio2;
	} un;

	MEMZERO(&un, sizeof un);
	sts = code & 0xff;

	if (IS_FC(isp)) {
		at2_entry_t *aep = arg;
		ct2_entry_t *cto = &un._ctio2;

		cto->ct_header.rqs_entry_type = RQSTYPE_CTIO2;
		cto->ct_header.rqs_entry_count = 1;
		cto->ct_iid = aep->at_iid;
#ifndef	ISP2100_SCCLUN
		cto->ct_lun = aep->at_lun;
#endif
		cto->ct_rxid = aep->at_rxid;
		cto->rsp.m1.ct_scsi_status = sts & 0xff;
		cto->ct_flags = CT2_SENDSTATUS | CT2_NO_DATA | CT2_FLAG_MODE1;
		if (hdl == 0) {
			cto->ct_flags |= CT2_CCINCR;
		}
		if (aep->at_datalen) {
			cto->ct_resid = aep->at_datalen;
			cto->ct_flags |= CT2_DATA_UNDER;
		}
		if ((sts & 0xff) == SCSI_CHECK && (sts & ECMD_SVALID)) {
			cto->rsp.m1.ct_resp[0] = 0xf0;
			cto->rsp.m1.ct_resp[2] = (code >> 12) & 0xf;
			cto->rsp.m1.ct_resp[7] = 8;
			cto->rsp.m1.ct_resp[12] = (code >> 24) & 0xff;
			cto->rsp.m1.ct_resp[13] = (code >> 16) & 0xff;
			cto->rsp.m1.ct_senselen = 16;
			cto->ct_flags |= CT2_SNSLEN_VALID;
		}
		cto->ct_reserved = hdl;
	} else {
		at_entry_t *aep = arg;
		ct_entry_t *cto = &un._ctio;

		cto->ct_header.rqs_entry_type = RQSTYPE_CTIO;
		cto->ct_header.rqs_entry_count = 1;
		cto->ct_iid = aep->at_iid;
		cto->ct_tgt = aep->at_tgt;
		cto->ct_lun = aep->at_lun;
		cto->ct_tag_type = aep->at_tag_type;
		cto->ct_tag_val = aep->at_tag_val;
		cto->ct_flags = CT_SENDSTATUS | CT_NO_DATA;
		if (hdl == 0) {
			cto->ct_flags |= CT_CCINCR;
		}
		cto->ct_scsi_status = sts;
		cto->ct_reserved = hdl;
	}
	return (isp_target_put_entry(isp, &un));
}

void
isp_target_async(isp, bus, event)
	struct ispsoftc *isp;
	int bus;
	int event;
{
	tmd_event_t evt;
	tmd_msg_t msg;

	switch (event) {
	/*
	 * These three we handle here to propagate an effective bus reset
	 * upstream, but these do not require any immediate notify actions
	 * so we return when done.
	 */
	case ASYNC_LIP_OCCURRED:
	case ASYNC_LOOP_UP:
	case ASYNC_LOOP_DOWN:
		evt.ev_bus = bus;
		evt.ev_event = event;
		(void) isp_async(isp, ISPASYNC_TARGET_EVENT, &evt);
		return;

	case ASYNC_LOOP_RESET:
	case ASYNC_BUS_RESET:
	case ASYNC_TIMEOUT_RESET:
		if (IS_FC(isp)) {
			return;	/* we'll be getting an inotify instead */
		}
		evt.ev_bus = bus;
		evt.ev_event = event;
		(void) isp_async(isp, ISPASYNC_TARGET_EVENT, &evt);
		break;
	case ASYNC_DEVICE_RESET:
		/*
		 * Bus Device Reset resets a specific target, so
		 * we pass this as a synthesized message.
		 */
		MEMZERO(&msg, sizeof msg);
		if (IS_FC(isp)) {
			msg.nt_iid =
			    ((fcparam *)isp->isp_param)->isp_loopid;
		} else {
			msg.nt_iid =
			    ((sdparam *)isp->isp_param)->isp_initiator_id;
		}
		msg.nt_bus = bus;
		msg.nt_msg[0] = MSG_BUS_DEV_RESET;
		(void) isp_async(isp, ISPASYNC_TARGET_MESSAGE, &msg);
		break;
	default:
		PRINTF("%s: isp_target_async: unknown event 0x%x\n",
		    isp->isp_name, event);
		break;
	}
	isp_notify_ack(isp, NULL);
}

/*
 * Process a received message.
 * The ISP firmware can handle most messages, there are only
 * a few that we need to deal with:
 * - abort: clean up the current command
 * - abort tag and clear queue
 */

static void
isp_got_msg(isp, bus, inp)
	struct ispsoftc *isp;
	int bus;
	in_entry_t *inp;
{
	u_int8_t status = inp->in_status & ~QLTM_SVALID;

	if (status == IN_IDE_RECEIVED || status == IN_MSG_RECEIVED) {
		tmd_msg_t msg;

		MEMZERO(&msg, sizeof (msg));
		msg.nt_bus = bus;
		msg.nt_iid = inp->in_iid;
		msg.nt_tgt = inp->in_tgt;
		msg.nt_lun = inp->in_lun;
		msg.nt_tagtype = inp->in_tag_type;
		msg.nt_tagval = inp->in_tag_val;
		MEMCPY(msg.nt_msg, inp->in_msg, IN_MSGLEN);
		(void) isp_async(isp, ISPASYNC_TARGET_MESSAGE, &msg);
	} else {
		PRINTF("%s: unknown immediate notify status 0x%x\n",
		    isp->isp_name, inp->in_status);
	}
}

/*
 * Synthesize a message from the task management flags in a FCP_CMND_IU.
 */
static void
isp_got_msg_fc(isp, bus, inp)
	struct ispsoftc *isp;
	int bus;
	in_fcentry_t *inp;
{
	static char *f1 = "%s: %s from iid %d lun %d seq 0x%x\n";
	static char *f2 =
	    "%s: unknown %s 0x%x lun %d iid %d task flags 0x%x seq 0x%x\n";

	if (inp->in_status != IN_MSG_RECEIVED) {
		PRINTF(f2, isp->isp_name, "immediate notify status",
		    inp->in_status, inp->in_lun, inp->in_iid,
		    inp->in_task_flags,  inp->in_seqid);
	} else {
		tmd_msg_t msg;

		MEMZERO(&msg, sizeof (msg));
		msg.nt_bus = bus;
		msg.nt_iid = inp->in_iid;
#ifdef	ISP2100_SCCLUN
		msg.nt_lun = inp->in_scclun;
#else
		msg.nt_lun = inp->in_lun;
#endif
		msg.nt_tagval = inp->in_seqid;

		if (inp->in_task_flags & TASK_FLAGS_ABORT_TASK) {
			PRINTF(f1, isp->isp_name, "ABORT TASK",
			    inp->in_iid, inp->in_lun, inp->in_seqid);
			msg.nt_msg[0] = MSG_ABORT_TAG;
		} else if (inp->in_task_flags & TASK_FLAGS_CLEAR_TASK_SET) {
			PRINTF(f1, isp->isp_name, "CLEAR TASK SET",
			    inp->in_iid, inp->in_lun, inp->in_seqid);
			msg.nt_msg[0] = MSG_CLEAR_QUEUE;
		} else if (inp->in_task_flags & TASK_FLAGS_TARGET_RESET) {
			PRINTF(f1, isp->isp_name, "TARGET RESET",
			    inp->in_iid, inp->in_lun, inp->in_seqid);
			msg.nt_msg[0] = MSG_BUS_DEV_RESET;
		} else if (inp->in_task_flags & TASK_FLAGS_CLEAR_ACA) {
			PRINTF(f1, isp->isp_name, "CLEAR ACA",
			    inp->in_iid, inp->in_lun, inp->in_seqid);
			/* ???? */
			msg.nt_msg[0] = MSG_REL_RECOVERY;
		} else if (inp->in_task_flags & TASK_FLAGS_TERMINATE_TASK) {
			PRINTF(f1, isp->isp_name, "TERMINATE TASK",
			    inp->in_iid, inp->in_lun, inp->in_seqid);
			msg.nt_msg[0] = MSG_TERM_IO_PROC;
		} else {
			PRINTF(f2, isp->isp_name, "task flag",
			    inp->in_status, inp->in_lun, inp->in_iid,
			    inp->in_task_flags,  inp->in_seqid);
		}
		if (msg.nt_msg[0]) {
			(void) isp_async(isp, ISPASYNC_TARGET_MESSAGE, &msg);
		}
	}
}

static void
isp_notify_ack(isp, arg)
	struct ispsoftc *isp;
	void *arg;
{
	char storage[QENTRY_LEN];
	u_int16_t iptr, optr;
	void *outp;

	if (isp_getrqentry(isp, &iptr, &optr, &outp)) {
		PRINTF("%s: Request Queue Overflow For isp_notify_ack\n",
		    isp->isp_name);
		return;
	}

	MEMZERO(storage, QENTRY_LEN);

	if (IS_FC(isp)) {
		na_fcentry_t *na = (na_fcentry_t *) storage;
		if (arg) {
			in_fcentry_t *inp = arg;
			MEMCPY(storage, arg, sizeof (isphdr_t));
			na->na_iid = inp->in_iid;
#ifdef	ISP2100_SCCLUN
			na->na_lun = inp->in_scclun;
#else
			na->na_lun = inp->in_lun;
#endif
			na->na_task_flags = inp->in_task_flags;
			na->na_seqid = inp->in_seqid;
			na->na_flags = NAFC_RCOUNT;
			if (inp->in_status == IN_RESET) {
				na->na_flags |= NAFC_RST_CLRD;
			}
		} else {
			na->na_flags = NAFC_RST_CLRD;
		}
		ISP_SWIZ_NOT_ACK_FC(isp, outp, na);
	} else {
		na_entry_t *na = (na_entry_t *) storage;
		if (arg) {
			in_entry_t *inp = arg;
			MEMCPY(storage, arg, sizeof (isphdr_t));
			na->na_iid = inp->in_iid;
			na->na_lun = inp->in_lun;
			na->na_tgt = inp->in_tgt;
			na->na_seqid = inp->in_seqid;
			if (inp->in_status == IN_RESET) {
				na->na_flags = NA_RST_CLRD;
			}
		} else {
			na->na_flags = NA_RST_CLRD;
		}
		ISP_SWIZ_NOT_ACK(isp, outp, na);
	}
	ISP_TDQE(isp, "isp_notify_ack", (int) optr, storage);
	ISP_ADD_REQUEST(isp, iptr);
}

static void
isp_handle_atio(isp, aep)
	struct ispsoftc *isp;
	at_entry_t *aep;
{
	int lun;
	lun = aep->at_lun;
	/*
	 * The firmware status (except for the QLTM_SVALID bit) indicates
	 * why this ATIO was sent to us.
	 *
	 * If QLTM_SVALID is set, the firware has recommended Sense Data.
	 *
	 * If the DISCONNECTS DISABLED bit is set in the flags field,
	 * we're still connected on the SCSI bus - i.e. the initiator
	 * did not set DiscPriv in the identify message. We don't care
	 * about this so it's ignored.
	 */

	switch(aep->at_status & ~QLTM_SVALID) {
	case AT_PATH_INVALID:
		/*
		 * ATIO rejected by the firmware due to disabled lun.
		 */
		PRINTF("%s: rejected ATIO for disabled lun %d\n",
		    isp->isp_name, lun);
		break;
	case AT_NOCAP:
		/*
		 * Requested Capability not available
		 * We sent an ATIO that overflowed the firmware's
		 * command resource count.
		 */
		PRINTF("%s: rejected ATIO for lun %d because of command count"
		    " overflow\n", isp->isp_name, lun);
		break;

	case AT_BDR_MSG:
		/*
		 * If we send an ATIO to the firmware to increment
		 * its command resource count, and the firmware is
		 * recovering from a Bus Device Reset, it returns
		 * the ATIO with this status. We set the command
		 * resource count in the Enable Lun entry and no
		 * not increment it. Therefore we should never get
		 * this status here.
		 */
		PRINTF("%s: ATIO returned for lun %d because it was in the "
		    " middle of coping with a Bus Device Reset\n",
		    isp->isp_name, lun);
		break;

	case AT_CDB:		/* Got a CDB */
	case AT_PHASE_ERROR:	/* Bus Phase Sequence Error */
		/*
		 * Punt to platform specific layer.
		 */
		(void) isp_async(isp, ISPASYNC_TARGET_ACTION, aep);
		break;

	case AT_RESET:
		/*
		 * A bus reset came along an blew away this command. Why
		 * they do this in addition the async event code stuff,
		 * I dunno.
		 *
		 * Ignore it because the async event will clear things
		 * up for us.
		 */
		PRINTF("%s: ATIO returned for lun %d from initiator %d because"
		    " a Bus Reset occurred\n", isp->isp_name, lun,
		    aep->at_iid);
		break;

	default:
		PRINTF("%s: Unknown ATIO status 0x%x from initiator %d for lun"
		    " %d\n", isp->isp_name, aep->at_status, aep->at_iid, lun);
		(void) isp_target_put_atio(isp, aep->at_iid, aep->at_tgt,
		    lun, aep->at_tag_type, aep->at_tag_val);
		break;
	}
}

static void
isp_handle_atio2(isp, aep)
	struct ispsoftc *isp;
	at2_entry_t *aep;
{
	int lun;
#ifdef	ISP2100_SCCLUN
	lun = aep->at_scclun;
#else
	lun = aep->at_lun;
#endif
	/*
	 * The firmware status (except for the QLTM_SVALID bit) indicates
	 * why this ATIO was sent to us.
	 *
	 * If QLTM_SVALID is set, the firware has recommended Sense Data.
	 *
	 * If the DISCONNECTS DISABLED bit is set in the flags field,
	 * we're still connected on the SCSI bus - i.e. the initiator
	 * did not set DiscPriv in the identify message. We don't care
	 * about this so it's ignored.
	 */

	switch(aep->at_status & ~QLTM_SVALID) {
	case AT_PATH_INVALID:
		/*
		 * ATIO rejected by the firmware due to disabled lun.
		 */
		PRINTF("%s: rejected ATIO2 for disabled lun %d\n",
		    isp->isp_name, lun);
		break;
	case AT_NOCAP:
		/*
		 * Requested Capability not available
		 * We sent an ATIO that overflowed the firmware's
		 * command resource count.
		 */
		PRINTF("%s: rejected ATIO2 for lun %d because of command count"
		    " overflow\n", isp->isp_name, lun);
		break;

	case AT_BDR_MSG:
		/*
		 * If we send an ATIO to the firmware to increment
		 * its command resource count, and the firmware is
		 * recovering from a Bus Device Reset, it returns
		 * the ATIO with this status. We set the command
		 * resource count in the Enable Lun entry and no
		 * not increment it. Therefore we should never get
		 * this status here.
		 */
		PRINTF("%s: ATIO2 returned for lun %d because it was in the "
		    " middle of coping with a Bus Device Reset\n",
		    isp->isp_name, lun);
		break;

	case AT_CDB:		/* Got a CDB */
		/*
		 * Punt to platform specific layer.
		 */
		(void) isp_async(isp, ISPASYNC_TARGET_ACTION, aep);
		break;

	case AT_RESET:
		/*
		 * A bus reset came along an blew away this command. Why
		 * they do this in addition the async event code stuff,
		 * I dunno.
		 *
		 * Ignore it because the async event will clear things
		 * up for us.
		 */
		PRINTF("%s: ATIO2 returned for lun %d from initiator %d because"
		    " a Bus Reset occurred\n", isp->isp_name, lun,
		    aep->at_iid);
		break;

	default:
		PRINTF("%s: Unknown ATIO2 status 0x%x from initiator %d for lun"
		    " %d\n", isp->isp_name, aep->at_status, aep->at_iid, lun);
		(void) isp_target_put_atio(isp, aep->at_iid, 0, lun, 0, 0);
		break;
	}
}

static void
isp_handle_ctio(isp, ct)
	struct ispsoftc *isp;
	ct_entry_t *ct;
{
	ISP_SCSI_XFER_T *xs;
	int pl = 0;
	char *fmsg = NULL;

	if (ct->ct_reserved) {
		xs = isp_find_xs(isp, ct->ct_reserved);
		if (xs == NULL)
			pl = 0;
	} else {
		pl = 2;
		xs = NULL;
	}

	switch(ct->ct_status & ~QLTM_SVALID) {
	case CT_OK:
		/*
		 * There are generally 3 possibilities as to why we'd get
		 * this condition:
		 * 	We disconnected after receiving a CDB.
		 * 	We sent or received data.
		 * 	We sent status & command complete.
		 */

		if ((ct->ct_flags & CT_DATAMASK) == CT_NO_DATA) {
			/*
			 * Nothing to do in this case.
			 */
			IDPRINTF(pl, ("%s: CTIO- initiator disconnected OK\n",
			    isp->isp_name));
			return;
		}
		break;

	case CT_BDR_MSG:
		/*
		 * Bus Device Reset message received or the SCSI Bus has
		 * been Reset; the firmware has gone to Bus Free.
		 *
		 * The firmware generates an async mailbox interupt to
		 * notify us of this and returns outstanding CTIOs with this
		 * status. These CTIOs are handled in that same way as
		 * CT_ABORTED ones, so just fall through here.
		 */
		fmsg = "Bus Device Reset";
		/*FALLTHROUGH*/
	case CT_RESET:
		if (fmsg == NULL)
			fmsg = "Bus Reset";
		/*FALLTHROUGH*/
	case CT_ABORTED:
		/*
		 * When an Abort message is received the firmware goes to
		 * Bus Free and returns all outstanding CTIOs with the status
		 * set, then sends us an Immediate Notify entry.
		 */
		if (fmsg == NULL)
			fmsg = "ABORT TASK sent by Initiator";

		PRINTF("%s: CTIO destroyed by %s\n", isp->isp_name, fmsg);
		break;

	case CT_INVAL:
		/*
		 * CTIO rejected by the firmware due to disabled lun.
		 * "Cannot Happen".
		 */
		PRINTF("%s: Firmware rejected CTIO for disabled lun %d\n",
		    isp->isp_name, ct->ct_lun);
		break;

	case CT_NOPATH:
		/*
		 * CTIO rejected by the firmware due "no path for the
		 * nondisconnecting nexus specified". This means that
		 * we tried to access the bus while a non-disconnecting
		 * command is in process.
		 */
		PRINTF("%s: Firmware rejected CTIO for bad nexus %d/%d/%d\n",
		    isp->isp_name, ct->ct_iid, ct->ct_tgt, ct->ct_lun);
		break;

	case CT_RSELTMO:
		fmsg = "Reselection";
		/*FALLTHROUGH*/
	case CT_TIMEOUT:
		if (fmsg == NULL)
			fmsg = "Command";
		PRINTF("%s: Firmware timed out on %s\n", isp->isp_name, fmsg);
		break;

	case CT_ERR:
		fmsg = "Completed with Error";
		/*FALLTHROUGH*/
	case CT_PHASE_ERROR:
		if (fmsg == NULL)
			fmsg = "Phase Sequence Error";
		/*FALLTHROUGH*/
	case CT_TERMINATED:
		if (fmsg == NULL)
			fmsg = "terminated by TERMINATE TRANSFER";
		/*FALLTHROUGH*/
	case CT_NOACK:
		if (fmsg == NULL)
			fmsg = "unacknowledged Immediate Notify pending";

		PRINTF("%s: CTIO returned by f/w- %s\n", isp->isp_name, fmsg);
#if	0
			if (status & SENSEVALID) {
				bcopy((caddr_t) (cep + CTIO_SENSE_OFFSET),
				    (caddr_t) &cdp->cd_sensedata,
				    sizeof(scsi_sense_t));
				cdp->cd_flags |= CDF_SENSEVALID;
			}
#endif
		break;
	default:
		PRINTF("%s: Unknown CTIO status 0x%x\n", isp->isp_name,
		    ct->ct_status & ~QLTM_SVALID);
		break;
	}

	if (xs == NULL) {
		/*
		 * There may be more than one CTIO for a data transfer,
		 * or this may be a status CTIO we're not monitoring.
		 *
		 * The assumption is that they'll all be returned in the
		 * order we got them.
		 */
		if (ct->ct_reserved == 0) {
			if ((ct->ct_flags & CT_SENDSTATUS) == 0) {
				IDPRINTF(pl,
				    ("%s: intermediate CTIO completed ok\n",
				    isp->isp_name));
			} else {
				IDPRINTF(pl,
				    ("%s: unmonitored CTIO completed ok\n",
				    isp->isp_name));
			}
		} else {
			IDPRINTF(pl,
			    ("%s: NO xs for CTIO (handle 0x%x) status 0x%x\n",
			    isp->isp_name, ct->ct_reserved,
			    ct->ct_status & ~QLTM_SVALID));
		}
	} else {
		if (ct->ct_flags & CT_SENDSTATUS) {
			/*
			 * Sent status and command complete.
			 *
			 * We're now really done with this command, so we
			 * punt to the platform dependent layers because
			 * only there can we do the appropriate command
			 * complete thread synchronization.
			 */
			IDPRINTF(pl,
			    ("%s: status CTIO complete\n", isp->isp_name));
		} else {
			/*
			 * Final CTIO completed. Release DMA resources and
			 * notify platform dependent layers.
			 */
			IDPRINTF(pl,
			    ("%s: data CTIO complete\n", isp->isp_name));
			ISP_DMAFREE(isp, xs, ct->ct_reserved);
		}
		(void) isp_async(isp, ISPASYNC_TARGET_ACTION, ct);
		/*
		 * The platform layer will destroy the handle if appropriate.
		 */
	}
}

static void
isp_handle_ctio2(isp, ct)
	struct ispsoftc *isp;
	ct2_entry_t *ct;
{
	ISP_SCSI_XFER_T *xs;
	int pl = 3;
	char *fmsg = NULL;

	if (ct->ct_reserved) {
		xs = isp_find_xs(isp, ct->ct_reserved);
		if (xs == NULL)
			pl = 0;
	} else {
		pl = 2;
		xs = NULL;
	}

	switch(ct->ct_status & ~QLTM_SVALID) {
	case CT_OK:
		/*
		 * There are generally 2 possibilities as to why we'd get
		 * this condition:
		 * 	We sent or received data.
		 * 	We sent status & command complete.
		 */

		break;

	case CT_BDR_MSG:
		/*
		 * Bus Device Reset message received or the SCSI Bus has
		 * been Reset; the firmware has gone to Bus Free.
		 *
		 * The firmware generates an async mailbox interupt to
		 * notify us of this and returns outstanding CTIOs with this
		 * status. These CTIOs are handled in that same way as
		 * CT_ABORTED ones, so just fall through here.
		 */
		fmsg = "Bus Device Reset";
		/*FALLTHROUGH*/
	case CT_RESET:
		if (fmsg == NULL)
			fmsg = "Bus Reset";
		/*FALLTHROUGH*/
	case CT_ABORTED:
		/*
		 * When an Abort message is received the firmware goes to
		 * Bus Free and returns all outstanding CTIOs with the status
		 * set, then sends us an Immediate Notify entry.
		 */
		if (fmsg == NULL)
			fmsg = "ABORT TASK sent by Initiator";

		PRINTF("%s: CTIO2 destroyed by %s\n", isp->isp_name, fmsg);
		break;

	case CT_INVAL:
		/*
		 * CTIO rejected by the firmware - invalid data direction.
		 */
		PRINTF("%s: CTIO2 had wrong data directiond\n", isp->isp_name);
		break;

	case CT_NOPATH:
		/*
		 * CTIO rejected by the firmware due "no path for the
		 * nondisconnecting nexus specified". This means that
		 * we tried to access the bus while a non-disconnecting
		 * command is in process.
		 */
		PRINTF("%s: Firmware rejected CTIO2 for bad nexus %d->%d\n",
		    isp->isp_name, ct->ct_iid, ct->ct_lun);
		break;

	case CT_RSELTMO:
		fmsg = "Reselection";
		/*FALLTHROUGH*/
	case CT_TIMEOUT:
		if (fmsg == NULL)
			fmsg = "Command";
		PRINTF("%s: Firmware timed out on %s\n", isp->isp_name, fmsg);
		break;

	case CT_ERR:
		fmsg = "Completed with Error";
		/*FALLTHROUGH*/
	case CT_PHASE_ERROR:	/* Bus phase sequence error */
		if (fmsg == NULL)
			fmsg = "Phase Sequence Error";
		/*FALLTHROUGH*/
	case CT_TERMINATED:
		if (fmsg == NULL)
			fmsg = "terminated by TERMINATE TRANSFER";
		/*FALLTHROUGH*/
	case CT_LOGOUT:
		if (fmsg == NULL)
			fmsg = "Port Logout";
		/*FALLTHROUGH*/
	case CT_PORTNOTAVAIL:
		if (fmsg == NULL)
			fmsg = "Port not available";
	case CT_NOACK:
		if (fmsg == NULL)
			fmsg = "unacknowledged Immediate Notify pending";

		PRINTF("%s: CTIO returned by f/w- %s\n", isp->isp_name, fmsg);
#if	0
			if (status & SENSEVALID) {
				bcopy((caddr_t) (cep + CTIO_SENSE_OFFSET),
				    (caddr_t) &cdp->cd_sensedata,
				    sizeof(scsi_sense_t));
				cdp->cd_flags |= CDF_SENSEVALID;
			}
#endif
		break;

	case CT_INVRXID:
		/*
		 * CTIO rejected by the firmware because an invalid RX_ID.
		 * Just print a message.
		 */
		PRINTF("%s: CTIO2 completed with Invalid RX_ID 0x%x\n",
		    isp->isp_name, ct->ct_rxid);
		break;

	default:
		IDPRINTF(pl, ("%s: Unknown CTIO status 0x%x\n", isp->isp_name,
		    ct->ct_status & ~QLTM_SVALID));
		break;
	}

	if (xs == NULL) {
		/*
		 * There may be more than one CTIO for a data transfer,
		 * or this may be a status CTIO we're not monitoring.
		 *
		 * The assumption is that they'll all be returned in the
		 * order we got them.
		 */
		if (ct->ct_reserved == 0) {
			if ((ct->ct_flags & CT_SENDSTATUS) == 0) {
				IDPRINTF(pl,
				    ("%s: intermediate CTIO completed ok\n",
				    isp->isp_name));
			} else {
				IDPRINTF(pl,
				    ("%s: unmonitored CTIO completed ok\n",
				    isp->isp_name));
			}
		} else {
			IDPRINTF(pl,
			    ("%s: NO xs for CTIO (handle 0x%x) status 0x%x\n",
			    isp->isp_name, ct->ct_reserved,
			    ct->ct_status & ~QLTM_SVALID));
		}
	} else {
		if (ct->ct_flags & CT_SENDSTATUS) {
			/*
			 * Sent status and command complete.
			 *
			 * We're now really done with this command, so we
			 * punt to the platform dependent layers because
			 * only there can we do the appropriate command
			 * complete thread synchronization.
			 */
			IDPRINTF(pl,
			    ("%s: status CTIO complete\n", isp->isp_name));
		} else {
			/*
			 * Final CTIO completed. Release DMA resources and
			 * notify platform dependent layers.
			 */
			IDPRINTF(pl,
			    ("%s: data CTIO complete\n", isp->isp_name));
			ISP_DMAFREE(isp, xs, ct->ct_reserved);
		}
		(void) isp_async(isp, ISPASYNC_TARGET_ACTION, ct);
		/*
		 * The platform layer will destroy the handle if appropriate.
		 */
	}
}
#endif


text:
                {{game.notification.title}}

                {{game.notification.description}}


text:
.webos-list .webos-text-entry input {
	width: 100%;
	font-family: 'Ubuntu Mono', monospace;
}


text:
{% extends 'navbar.html' %}

{% set active_page = 'categories' %}

{% block content %}

            Categories

        <form method="POST" id="add_form">
            {{ add_form.csrf_token }}

{{ add_form.add_category.label }}

            {{ add_form.add_category }}
            {% for error in add_form.add_category.errors %}
                [{{ error }}]
            {% endfor %}
            {{ add_form.add_button(class_="btn btn-default") }}
        </form>

Here are the post categories, arranged in alphabetical order.

            {%- for column in categories|slice(2) %}

            {%- for category in column %}

{{ category.display_name }}

            {%- endfor %}

            {%- endfor %}

{% endblock %}

{% block footer %}
{% endblock %}


text:
package iht.views.application

import iht.views.ViewTestHelper
import iht.views.html.application.iht_kickout_final_application

class IhtKickoutFinalApplicationViewTest extends ViewTestHelper{

  lazy val ihtRef = "ABCABC"
  lazy val ihtKickoutFinalApplicationView: iht_kickout_final_application = app.injector.instanceOf[iht_kickout_final_application]

 def ihtKickOutFinalApplicationView = {
    implicit val request = createFakeRequest()
    val view = ihtKickoutFinalApplicationView(ihtRef).toString()
    asDocument(view)
  }

  "IhtKickoutFinalApplication View" must {

    "have no message keys in html" in {
      noMessageKeysShouldBePresent(ihtKickOutFinalApplicationView.toString)
    }

    "have the correct title and browser title" in {
      val view = ihtKickOutFinalApplicationView.toString

      titleShouldBeCorrect(view.toString, messagesApi("page.iht.application.kickout.final.browserTitle"))
      browserTitleShouldBeCorrect(view, messagesApi("page.iht.application.kickout.final.browserTitle"))
    }

    "have correct guidance" in {
      val view = ihtKickOutFinalApplicationView.toString

      messagesShouldBePresent(view, messagesApi("page.iht.application.kickout.final.getCopy.title"))
      messagesShouldBePresent(view, messagesApi("page.iht.application.kickout.final.getCopy.guidance1"))
      messagesShouldBePresent(view, messagesApi("page.iht.application.kickout.final.getCopy.guidance2.youShould"))
      ihtKickOutFinalApplicationView.getElementsByClass("panel").first.text() mustBe
        (messagesApi("page.iht.application.kickout.final.getCopy.guidance2.youShould") + " " +
          messagesApi("page.iht.application.kickout.final.getCopy.guidance2.saveAndPrint") +
          ".")
      messagesShouldBePresent(view, messagesApi("page.iht.application.kickout.final.getCopy.guidance3"))
      messagesShouldBePresent(view, messagesApi("page.iht.application.kickout.final.guidance.onFinish"))
    }

    "have save and print link with correct text " in {
      val view = ihtKickOutFinalApplicationView
      val returnButton = view.getElementById("save-and-print")
      returnButton.text() mustBe messagesApi("page.iht.application.kickout.final.getCopy.guidance2.saveAndPrint")
      returnButton.attr("href") mustBe
        iht.controllers.application.pdf.routes.PDFController.onPreSubmissionPDF.url
    }

    "have return link with correct text " in {
      val view = ihtKickOutFinalApplicationView

      val returnButton = view.getElementById("return-button")
      returnButton.text() mustBe messagesApi("iht.estateReport.returnToEstateOverview")
      returnButton.attr("href") mustBe
        iht.controllers.application.routes.EstateOverviewController.onPageLoadWithIhtRef(ihtRef).url
    }

    "have finish and delete button " in {
      val view = ihtKickOutFinalApplicationView

      val finishButton = view.getElementById("finish")
      finishButton.attr("value") mustBe messagesApi("iht.finishAndDeleteThisEstateReport")
    }
  }

}


text:
// Copyright 2019 Google LLC
//
// 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.

package com.google.firebase.segmentation;

import androidx.annotation.NonNull;
import com.google.firebase.FirebaseException;

/** The class for all Exceptions thrown by {@link FirebaseSegmentation}. */
public class SetCustomInstallationIdException extends FirebaseException {

  public enum Status {
    UNKNOWN(0),

    /** Error in Firebase SDK. */
    CLIENT_ERROR(1),

    /** Error when calling Firebase segmentation backend. */
    BACKEND_ERROR(2),

    /** The given custom installation is already tied to another Firebase installation. */
    DUPLICATED_CUSTOM_INSTALLATION_ID(3);

    private final int value;

    Status(int value) {
      this.value = value;
    }
  }

  @NonNull private final Status status;

  SetCustomInstallationIdException(@NonNull Status status) {
    this.status = status;
  }

  SetCustomInstallationIdException(@NonNull Status status, @NonNull String message) {
    super(message);
    this.status = status;
  }

  SetCustomInstallationIdException(
      @NonNull Status status, @NonNull String message, Throwable cause) {
    super(message, cause);
    this.status = status;
  }

  /**
   * Gets the status code for the operation that failed.
   *
   * @return the code for the SetCustomInstallationIdException
   */
  @NonNull
  public Status getStatus() {
    return status;
  }
}


text:
"""
https://leetcode.com/problems/generate-parentheses/

https://leetcode.com/submissions/detail/145650277/
"""

class Solution:
    def generateParenthesis(self, n):
        """
        :type n: int
        :rtype: List[str]
        """
        ans = []

        def recurse(curStr, lefts, rights, limit):
            if lefts == limit and rights == limit:
                return ans.append(curStr)
            if lefts == limit:
                return recurse(curStr + ')', lefts, rights + 1, limit)
            recurse(curStr + '(', lefts + 1, rights, limit)
            if rights < lefts:
                recurse(curStr + ')', lefts, rights + 1, limit)
        recurse('', 0, 0, n)
        return ans

import unittest

class Test(unittest.TestCase):
    def test(self):
        solution = Solution()
        self.assertEqual(solution.generateParenthesis(3), [
            "((()))",
            "(()())",
            "(())()",
            "()(())",
            "()()()"
        ])

if __name__ == '__main__':
    unittest.main()


text:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#D8DEDE"
        android:gravity="center_vertical"
        android:orientation="horizontal" >

        <ImageView
            android:id="@+id/iv_appinfo_icon"
            android:layout_width="45dp"
            android:layout_height="45dp"
            android:paddingBottom="5dp"
            android:paddingTop="5dp"
            android:src="@drawable/ic_launcher" />

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="5dp"
            android:orientation="vertical"
            android:paddingBottom="5dp"
            android:paddingTop="5dp" >

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal" >

                <TextView
                    android:id="@+id/tv_appname"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:ellipsize="middle"
                    android:singleLine="true"
                    android:text="应用名称"
                    android:textSize="20sp" />

                <TextView
                    android:id="@+id/tv_appsize"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:ellipsize="start"
                    android:singleLine="true"
                    android:text="应用大小" />
            </LinearLayout>

            <TextView
                android:id="@+id/tv_appcategory"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="安装位置" />
        </LinearLayout>
    </LinearLayout>

    <View
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:background="@drawable/devide_line2" />

</LinearLayout>


text:
<?php if ($this->session->userdata('loggedin') == 1 && $this->session->userdata('user_role') == 'admin'){

?>

<!DOCTYPE html>

  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <title>BU JUPEB Portal | Admin</title>

  <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">

  <link rel="icon" href="<?php echo base_url(); ?>assets/bu logo.ico" type="image/x-icon">

  <link rel="stylesheet" href="<?php echo base_url(); ?>assets/bootstrap/css/bootstrap.min.css">

  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.5.0/css/font-awesome.min.css">

  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/ionicons/2.0.1/css/ionicons.min.css">

  <link rel="stylesheet" href="<?php echo base_url(); ?>assets/plugins/datatables/dataTables.bootstrap.css">

  <link rel="stylesheet" href="<?php echo base_url(); ?>assets/dist/css/AdminLTE.min.css">

  <link rel="stylesheet" href="<?php echo base_url(); ?>assets/dist/css/skins/skin-blue.min.css">

  <link href="<?php echo base_url(); ?>assets/css/bread.css" rel="stylesheet">

      Admin

      JUPEB Admin

        Toggle navigation

              <img src="<?php echo base_url(); ?>assets/dist/img/avatar.png" class="user-image" alt="User Image">

               <?php echo ($this->session->userdata('name')); ?>

                <img src="<?php echo base_url(); ?>assets/dist/img/avatar.png" class="img-circle" alt="User Image">

                  <?php echo ($this->session->userdata('name')); ?>
                  You are logged in as <?php echo ($this->session->userdata('user_role')); ?>

                  <a href="<?php echo base_url(); ?>Login/display_change_password" class="btn btn-default btn-flat">Change Password

                  <a href="<?php echo base_url(); ?>Login/sign_out" class="btn btn-default btn-flat">Sign out

          <img src="<?php echo base_url(); ?>assets/dist/img/avatar.png" class="img-circle" alt="User Image">

<?php echo ($this->session->userdata('name')); ?>

           Online

<?php echo $student_records; ?>

<a href="<?php echo base_url(); ?>Admin/manage_session"> Manage Session

           Manage Program

<a href="<?php echo base_url(); ?>Programs/add_programs">Add Programs

<a href="<?php echo base_url(); ?>Subjects/add_subjects">Add Subjects

<a href="<?php echo base_url(); ?>Subjects_Combination/combine_subjects">Manage Subject Combination

           Manage Students

<a href="<?php echo base_url(); ?>Students/add_students">Add Students

<a href="<?php echo base_url(); ?>Students/view_students">View & Edit Students Details

           Manage Studens' Grades

<a href="<?php echo base_url(); ?>Grades/manage_grades"> Manage Grades by Program

<a href="<?php echo base_url(); ?>Grades/manage_subjectgrades"> Manage Grades by Subject

<a href="<?php echo base_url(); ?>Reporting/reports"> Generate Reports

        <?php echo $page_title; ?>
        <?php echo $optional_description; ?>

      <?php $this->load->view($content_view); ?>

      ...The Future is Babcock

    Copyright © 2017 Babcock University. All rights reserved.

<?php } else {redirect(base_url().'Login');}


text:
package com.alipay.api.response;

import com.alipay.api.AlipayResponse;

/**
 * ALIPAY API: alipay.open.mini.safedomain.create response.
 *
 * @author auto create
 * @since 1.0, 2018-01-15 15:25:38
 */
public class AlipayOpenMiniSafedomainCreateResponse extends AlipayResponse {

	private static final long serialVersionUID = 2368788521175739388L;

}


text:
class ComplaintQuestionship < ActiveRecord::Base
  belongs_to :complaint
  belongs_to :question
end


text:
/*
 global QUnit
 */
sap.ui.define([
	'sap/ui/test/opaQunit'
], function (opaTest) {
	"use strict";

	QUnit.module("API Reference Journey Test");

	opaTest("Should start the app and see the landing page", function (Given, When, Then) {
		// Arrangements
		Given.iStartMyApp();
		// Assertions
		Then.onTheAppPage.iShouldSeeTheAppPage();
	});

	opaTest("Should navigate to API Reference Page", function (Given, When, Then) {
		// Action
		When.onTheAppPage.iPressTheApiMasterTabButton();
		// Assertions
		Then.onTheApiMasterPage.iShouldSeeTheApiMasterPage();
	});

	opaTest("Should see the tree filled with items", function (Given, When, Then) {
		Then.onTheApiMasterPage.iShouldSeeTheTreeFilled();
	});

	opaTest("Should Filter the tree", function (Given, When, Then) {
		When.onTheApiMasterPage.iSearchFor("sap.ui.base.o");
		Then.onTheApiMasterPage.iShouldSeeTheseItems(["sap.ui.base", "Object", "ObjectPool"]);
	});

	opaTest("Should select an item from the filtered tree", function (Given, When, Then) {
		Given.onTheApiMasterPage.iSearchFor("sap.ui.base.o");
		When.onTheApiMasterPage.iSelectATreeNode("Object");
		Then.onTheApiDetailPage.iShouldSeeTheApiDetailPage().
		and.iShouldSeeTheApiDetailObjectPage();
	});

	opaTest("Should see the details for the selected item (sap.ui.base.Object)", function (Given, When, Then) {
		Given.onTheApiMasterPage.iSearchFor("sap.ui.base.o");
		When.onTheApiMasterPage.iSelectATreeNode("Object");
		Then.onTheApiDetailPage.iShouldSeeTheCorrectTitleAndSubtitle("abstract class sap.ui.base.Object", "").
		and.iShouldSeeTheElementDetailsInHeaderContent().
		and.iShouldSeeTheseSections("Overview", "Constructor", "Methods").
		and.iShouldSeeTheCorrectSectionSelected("Overview");
	});

	opaTest("Should scroll to section via section buttons", function (Given, When, Then) {
		Given.onTheApiMasterPage.iSearchFor("sap.ui.base.o").
		and.iSelectATreeNode("Object");
		When.onTheApiDetailPage.iSelectASection("Constructor");
		Then.onTheApiDetailPage.iShouldSeeTheCorrectSectionSelected("Constructor");
		When.onTheApiDetailPage.iSelectASection("Methods").and.iSelectASection("Summary");
		Then.onTheApiDetailPage.iShouldSeeTheCorrectSectionSelected("Methods");
	});

	opaTest("Should scroll to section via link", function (Given, When, Then) {
		When.onTheApiDetailPage.iSelectALink("getInterface");
		Then.onTheApiDetailPage.iShouldSeeTheCorrectSectionSelected("Methods").
		and.iShouldSeeTheCorrectSubSectionOnTop("getInterface").and.iTeardownMyApp();
	});

});


text:
//------------------------------------------------------------------------------
// <auto-generated>
//     This code was generated from a template.
//
//     Manual changes to this file may cause unexpected behavior in your application.
//     Manual changes to this file will be overwritten if the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

namespace Data_Platform_Demos.SqlDatabase
{
    using System;
    using System.Data.Entity;
    using System.Data.Entity.Infrastructure;

    public partial class AdventureWorksProductsEntities : DbContext
    {
        public AdventureWorksProductsEntities()
            : base("name=AdventureWorksProductsEntities")
        {
        }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            throw new UnintentionalCodeFirstException();
        }

        public virtual DbSet<Culture> Cultures { get; set; }
        public virtual DbSet<Product> Products { get; set; }
        public virtual DbSet<ProductCategory> ProductCategories { get; set; }
        public virtual DbSet<ProductDescription> ProductDescriptions { get; set; }
        public virtual DbSet<ProductModel> ProductModels { get; set; }
        public virtual DbSet<ProductModelProductDescriptionCulture> ProductModelProductDescriptionCultures { get; set; }
        public virtual DbSet<ProductReview> ProductReviews { get; set; }
        public virtual DbSet<ProductSubcategory> ProductSubcategories { get; set; }
    }
}


text:
namespace Envoy {

INSTANTIATE_TEST_CASE_P(TestParameters, UdsUpstreamIntegrationTest,
                        testing::Combine(testing::ValuesIn(TestEnvironment::getIpVersionsForTest()),
#if defined(__linux__)
                                         testing::Values(false, true)
#else
                                         testing::Values(false)
#endif
                                             ));

TEST_P(UdsUpstreamIntegrationTest, RouterRequestAndResponseWithBodyNoBuffer) {
  testRouterRequestAndResponseWithBody(1024, 512, false);
}

TEST_P(UdsUpstreamIntegrationTest, RouterHeaderOnlyRequestAndResponse) {
  testRouterHeaderOnlyRequestAndResponse(true);
}

TEST_P(UdsUpstreamIntegrationTest, RouterUpstreamDisconnectBeforeResponseComplete) {
  testRouterUpstreamDisconnectBeforeResponseComplete();
}

TEST_P(UdsUpstreamIntegrationTest, RouterDownstreamDisconnectBeforeRequestComplete) {
  testRouterDownstreamDisconnectBeforeRequestComplete();
}

TEST_P(UdsUpstreamIntegrationTest, RouterDownstreamDisconnectBeforeResponseComplete) {
  testRouterDownstreamDisconnectBeforeResponseComplete();
}

INSTANTIATE_TEST_CASE_P(TestParameters, UdsListenerIntegrationTest,
                        testing::Combine(testing::ValuesIn(TestEnvironment::getIpVersionsForTest()),
#if defined(__linux__)
                                         testing::Values(false, true)
#else
                                         testing::Values(false)
#endif
                                             ));

void UdsListenerIntegrationTest::initialize() {
  config_helper_.addConfigModifier([&](envoy::config::bootstrap::v2::Bootstrap& bootstrap) -> void {
    auto* admin_addr = bootstrap.mutable_admin()->mutable_address();
    admin_addr->clear_socket_address();
    admin_addr->mutable_pipe()->set_path(getAdminSocketName());

    auto* listeners = bootstrap.mutable_static_resources()->mutable_listeners();
    RELEASE_ASSERT(listeners->size() > 0);
    auto filter_chains = listeners->Get(0).filter_chains();
    listeners->Clear();
    auto* listener = listeners->Add();
    listener->set_name("listener_0");
    listener->mutable_address()->mutable_pipe()->set_path(getListenerSocketName());
    *(listener->mutable_filter_chains()) = filter_chains;
  });
  HttpIntegrationTest::initialize();
}

HttpIntegrationTest::ConnectionCreationFunction UdsListenerIntegrationTest::createConnectionFn() {
  return [&]() -> Network::ClientConnectionPtr {
    Network::ClientConnectionPtr conn(dispatcher_->createClientConnection(
        Network::Utility::resolveUrl(fmt::format("unix://{}", getListenerSocketName())),
        Network::Address::InstanceConstSharedPtr(), Network::Test::createRawBufferSocket(),
        nullptr));
    conn->enableHalfClose(enable_half_close_);
    return conn;
  };
}

TEST_P(UdsListenerIntegrationTest, RouterRequestAndResponseWithBodyNoBuffer) {
  ConnectionCreationFunction creator = createConnectionFn();
  testRouterRequestAndResponseWithBody(1024, 512, false, &creator);
}

TEST_P(UdsListenerIntegrationTest, RouterHeaderOnlyRequestAndResponse) {
  ConnectionCreationFunction creator = createConnectionFn();
  testRouterHeaderOnlyRequestAndResponse(true, &creator);
}

TEST_P(UdsListenerIntegrationTest, RouterListenerDisconnectBeforeResponseComplete) {
  ConnectionCreationFunction creator = createConnectionFn();
  testRouterUpstreamDisconnectBeforeResponseComplete(&creator);
}

TEST_P(UdsListenerIntegrationTest, RouterDownstreamDisconnectBeforeRequestComplete) {
  ConnectionCreationFunction creator = createConnectionFn();
  testRouterDownstreamDisconnectBeforeRequestComplete(&creator);
}

// TODO(htuch): This is disabled due to
// https://github.com/envoyproxy/envoy/issues/2829.
TEST_P(UdsListenerIntegrationTest, DISABLED_RouterDownstreamDisconnectBeforeResponseComplete) {
  ConnectionCreationFunction creator = createConnectionFn();
  testRouterDownstreamDisconnectBeforeResponseComplete(&creator);
}

} // namespace Envoy