(file) Return to socketcomm.c CVS log (file) (dir) Up to [Pegasus] / pegasus / src / Pegasus / ProviderManager2 / CMPIR

File: [Pegasus] / pegasus / src / Pegasus / ProviderManager2 / CMPIR / socketcomm.c (download)
Revision: 1.6, Mon Oct 23 22:47:53 2006 UTC (17 years, 8 months ago) by dave.sudlik
Branch: MAIN
CVS Tags: TASK-PEP286_PRIVILEGE_SEPARATION-root, TASK-PEP286_PRIVILEGE_SEPARATION-branch, TASK-PEP267_SLPReregistrationSupport-merging_out_from_trunk, TASK-Bug2102_RCMPIWindows-root, TASK-Bug2102_RCMPIWindows-merged_out_to_branch, TASK-Bug2102_RCMPIWindows-merged_out_from_trunk, TASK-Bug2102_RCMPIWindows-merged_in_to_trunk, TASK-Bug2102_RCMPIWindows-merged_in_from_branch, TASK-Bug2102Final-root, TASK-Bug2102Final-merged_out_to_branch, TASK-Bug2102Final-merged_out_from_trunk, TASK-Bug2102Final-merged_in_to_trunk, TASK-Bug2102Final-merged_in_from_branch, TASK-Bug2021_RCMPIonWindows-root, TASK-Bug2021_RCMPIonWindows-merged_out_to_branch, TASK-Bug2021_RCMPIonWindows-merged_out_from_trunk, TASK-Bug2021_RCMPIonWindows-merged_in_to_trunk, TASK-Bug2021_RCMPIonWindows-merged_in_from_branch, TASK-BUG7240-root, TASK-BUG7240-branch, RELEASE_2_6_3-RC2, RELEASE_2_6_3-RC1, RELEASE_2_6_3, RELEASE_2_6_2-RC1, RELEASE_2_6_2, RELEASE_2_6_1-RC1, RELEASE_2_6_1, RELEASE_2_6_0-RC1, RELEASE_2_6_0-FC, RELEASE_2_6_0, RELEASE_2_6-root, RELEASE_2_6-branch-clean, RELEASE_2_6-branch, PEP286_PRIVILEGE_SEPARATION_ROOT, PEP286_PRIVILEGE_SEPARATION_CODE_FREEZE, PEP286_PRIVILEGE_SEPARATION_BRANCH, PEP286_PRIVILEGE_SEPARATION_1
Branch point for: TASK-Bug2102_RCMPIWindows-branch, TASK-Bug2102Final-branch, TASK-Bug2021_RCMPIonWindows-branch
Changes since 1.5: +11 -7 lines
BUG#: 5690
TITLE: Implementation of missing functionality in Remote CMPI

DESCRIPTION: committing approved fix

//%2006////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development
// Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems.
// Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L.P.;
// IBM Corp.; EMC Corporation, The Open Group.
// Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.;
// IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.
// Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;
// EMC Corporation; VERITAS Software Corporation; The Open Group.
// Copyright (c) 2006 Hewlett-Packard Development Company, L.P.; IBM Corp.;
// EMC Corporation; Symantec Corporation; The Open Group.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
// ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
// "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
// LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
// ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//==============================================================================
//
//%/////////////////////////////////////////////////////////////////////////////

/*!
  \file socketcomm.c
  \brief Socket-based communication layer common functionality.

  This module provides common functionality for the socket based communication
  layers. This comprises the serialization of entities not supported by
  the serialization module, such as contexts and properties for instance,
  as well as dispatching MI and MB calls respectively.

  \author Frank Scheffler
*/

#include <stdio.h>
#include <stdlib.h>
#include <Pegasus/Provider/CMPI/cmpimacs.h>
#include <Pegasus/Provider/CMPI/cmpidt.h>
#include <Pegasus/Provider/CMPI/cmpift.h>
#include "socketcomm.h"
#include "serialization.h"
#include "debug.h"


char * RCMPI_CTX_ID = "RCMPI_CTX_ID";


/****************************************************************************/

void socketcomm_copy_args ( CMPIArgs * src, CMPIArgs * dst )
{
	unsigned int i,arg_count;

	TRACE_NORMAL(("Copying CMPIArgs."));

	arg_count = CMGetArgCount ( src, NULL );

	TRACE_INFO(("arg count: %d", arg_count ));

	for ( i = 0; i < arg_count; i++ ) {

		CMPIString * argName;
		CMPIData data = CMGetArgAt ( src, i, &argName, NULL );

		TRACE_INFO(("arg:\nname: %s\ntype: 0x%x\nstate: 0x%x.",
			    CMGetCharsPtr ( argName, NULL ),
			    data.type, data.state ));

		if ( data.state & CMPI_nullValue ) {
			CMAddArg ( dst,
				   CMGetCharsPtr ( argName, NULL ),
				   NULL,
				   CMPI_null );
		} else CMAddArg ( dst,
				  CMGetCharsPtr ( argName, NULL ),
				  &data.value,
				  data.type );
	}
}


//! Copies array contents into CMPIResult objects.
/*!
  Since results from remote providers cannot be sent as CMPIResult directly,
  they are serialized using arrays, which can be transferred to the result
  using this method.

  \param array the source array.
  \param result the destination result.
 */
void socketcomm_array2result ( CMPIArray * array, CONST CMPIResult * result )
{
	TRACE_VERBOSE(("entered function."));
        CMPIStatus rc;
	if ( array != NULL && result != NULL ) {

		CMPICount size = CMGetArrayCount ( array, NULL );
		CMPICount i;

		TRACE_NORMAL(("Transferring %d array elements to CMPIResult.",
			      size));

		for ( i = 0; i < size; i++ ) {

			CMPIData data = CMGetArrayElementAt ( array, i, NULL );

			if ( data.type == CMPI_instance ) {

				TRACE_INFO(("transferring instance."));
				// EmbeddedObjects or EmbeddedInstances returned
				// from MethodProviders can not use CMReturnInstance
				// because it is not supported, return
				// these type of data with CMReturnData.
				rc = CMReturnInstance ( result, data.value.inst );
				if( rc.rc  == CMPI_RC_ERR_NOT_SUPPORTED )
				{
				    CMReturnData ( result, &data.value, data.type );
				}
			} else if ( data.type == CMPI_ref ) {

				TRACE_INFO(("transferring object path."));
				CMReturnObjectPath ( result, data.value.ref );
			} else {

				TRACE_INFO(("transferring CMPIData."));
				CMReturnData ( result,
					       &data.value,
					       data.type );
			}
		}
	}

	TRACE_VERBOSE(("leaving function."));
}

/****************************************************************************/

void socketcomm_serialize_props ( int socket,
				  const struct BinarySerializerFT * sft,
				  char ** props )
{
	unsigned long int i = 0;

	if ( props != NULL ) {

		while ( props[i] ) i++;
		sft->serialize_UINT32 ( socket, i );

		while ( i ) sft->serialize_string ( socket, props[--i] );

	} else sft->serialize_UINT32 ( socket, i );
}


char ** socketcomm_deserialize_props ( int socket,
				       const struct BinarySerializerFT * sft,
				       CONST CMPIBroker * broker )
{
	int i;
	char ** r = NULL;

	i = sft->deserialize_UINT32 ( socket );

	if ( i > 0 ) {

		r =  (char **) calloc ( i + 1, sizeof ( char * ) );
		while ( i )
			r[--i] = sft->deserialize_string ( socket, broker );
	}

	return r;
}


void socketcomm_serialize_context ( int socket,
				    const struct BinarySerializerFT * sft,
				    CONST CMPIContext * ctx )
{
	unsigned int size = CMGetContextEntryCount ( ctx, NULL ), i;

	TRACE_NORMAL(("serializing context with %d entries", size ));

	sft->serialize_UINT32 ( socket, size );

	for ( i = 0; i < size; i++ ) {
		CMPIString * entryName;
		CMPIData entry = CMGetContextEntryAt ( ctx,
						       i,
						       &entryName,
						       NULL );

		TRACE_INFO(("serializing entry(%d): %s",
			    i, CMGetCharsPtr ( entryName, NULL ) ));

		sft->serialize_CMPIString ( socket, entryName );
		sft->serialize_CMPIData ( socket, entry );
	}
}


void socketcomm_deserialize_context ( int socket,
				      const struct BinarySerializerFT * sft,
				      CONST CMPIBroker * broker,
				      CONST CMPIContext * ctx )
{
	unsigned int size;

	size = sft->deserialize_UINT32 ( socket );

	TRACE_NORMAL(("deserializing context with %d entries", size ));

	while ( size-- ) {
		CMPIString * entryName =
			sft->deserialize_CMPIString ( socket, broker );
		CMPIData entry =
			sft->deserialize_CMPIData ( socket, broker );
		CMPIType type =
			( entry.state & CMPI_nullValue )?
			CMPI_null: entry.type;

		TRACE_INFO(("adding entryName: %s", CMGetCharsPtr ( entryName, NULL ) ));

		CMAddContextEntry ( ctx,
				    CMGetCharsPtr ( entryName, NULL ),
				    &entry.value,
				    type );
	}
}


/*** Local Variables:  ***/
/*** mode: C           ***/
/*** c-basic-offset: 8 ***/
/*** End:              ***/

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2