CK_RV printArg(Value *ptr,int arg_number)
printArg(Value *ptr,int arg_number)
CK_RV printArg(Value *ptr,int arg_number){    ArgType type = ptr->type & ArgMask;    CK_INFO *info;    CK_SLOT_INFO    *slotInfo;    CK_TOKEN_INFO   *tokenInfo;    CK_SESSION_INFO *sessionInfo;    CK_ATTRIBUTE    *attribute;    CK_MECHANISM    *mechanism;    CK_MECHANISM_INFO    *mechanismInfo;    CK_C_INITIALIZE_ARGS *initArgs;    CK_FUNCTION_LIST *functionList;    CK_RV ckrv = CKR_OK;    ConstType constType;    if (arg_number) {	printf("Arg %d: \n",arg_number);    }    if (ptr->arraySize > 1) {	Value element;	int i;	int elementSize = ptr->size/ptr->arraySize;	char *dp = (char *)ptr->data;	/* build a temporary Value to hold a single element */	element.type = type;	element.constType = ptr->constType;	element.size = elementSize;	element.filename = ptr->filename;	element.reference = 1;	element.arraySize = 1;	for (i=0; i < ptr->arraySize; i++) {	    printf(" -----[ %d ] -----\n", i);	    element.data = (void *) &dp[i*elementSize];	    (void) printArg(&element, 0);	}	return ckrv;    }    if (ptr->data == NULL) {	printf(" NULL ptr to a %s\n", valueString[type]);	return ckrv;    }    switch (type) {    case ArgNone:	printf(" None\n");	break;    case ArgULong:	printf(" %lu (0x%lx)\n", *((CK_ULONG *)ptr->data),			*((CK_ULONG *)ptr->data));	if (ptr->constType != ConstNone) {	    printf(" ");	    printConst(*(CK_ULONG *)ptr->data,ptr->constType,1);	}	break;    case ArgVar:	printf(" Variable.....error\n");	ckrv = CKR_ARGUMENTS_BAD;	break;    case ArgUTF8:	printf(" %s\n",(char *)ptr->data);	break;    case ArgChar:	printDump(ptr->data,ptr->size);	break;    case ArgInfo:#define VERSION(x) (x).major, (x).minor	info = (CK_INFO *)ptr->data;	printf(" Cryptoki Version: %d.%02d\n",		VERSION(info->cryptokiVersion));	printf(" Manufacturer ID: ");	printChars(info->manufacturerID,sizeof(info->manufacturerID));	printFlags(" Flags: ", info->flags, ConstInfoFlags);	printf(" Library Description: ");	printChars(info->libraryDescription,sizeof(info->libraryDescription));	printf(" Library Version: %d.%02d\n",		VERSION(info->libraryVersion));	break;    case ArgSlotInfo:	slotInfo = (CK_SLOT_INFO *)ptr->data;	printf(" Slot Description: ");	printChars(slotInfo->slotDescription,sizeof(slotInfo->slotDescription));	printf(" Manufacturer ID: ");	printChars(slotInfo->manufacturerID,sizeof(slotInfo->manufacturerID));	printFlags(" Flags: ", slotInfo->flags, ConstSlotFlags);	printf(" Hardware Version: %d.%02d\n",		VERSION(slotInfo->hardwareVersion));	printf(" Firmware Version: %d.%02d\n",		VERSION(slotInfo->firmwareVersion));	break;    case ArgTokenInfo:	tokenInfo = (CK_TOKEN_INFO *)ptr->data;	printf(" Label: %s\n",tokenInfo->label);	printf(" Manufacturer ID: ");	printChars(tokenInfo->manufacturerID,sizeof(tokenInfo->manufacturerID));	printf(" Model: ");	printChars(tokenInfo->model,sizeof(tokenInfo->model));	printf(" Serial Number: ");	printChars(tokenInfo->serialNumber,sizeof(tokenInfo->serialNumber));	printFlags(" Flags: ", tokenInfo->flags, ConstTokenFlags);	printf(" Max Session Count: %lu\n",tokenInfo->ulMaxSessionCount);	printf(" Session Count: %lu\n",tokenInfo->ulSessionCount);	printf(" RW Session Count: %lu\n",tokenInfo->ulMaxRwSessionCount);	printf(" Max Pin Length : %lu\n",tokenInfo->ulMaxPinLen);	printf(" Min Pin Length : %lu\n",tokenInfo->ulMinPinLen);	printf(" Total Public Memory: %lu\n",		tokenInfo->ulTotalPublicMemory);	printf(" Free Public Memory: %lu\n",		tokenInfo->ulFreePublicMemory);	printf(" Total Private Memory: %lu\n",		tokenInfo->ulTotalPrivateMemory);	printf(" Free Private Memory: %lu\n",		tokenInfo->ulFreePrivateMemory);	printf(" Hardware Version: %d.%02d\n",		VERSION(tokenInfo->hardwareVersion));	printf(" Firmware Version: %d.%02d\n",		VERSION(tokenInfo->firmwareVersion));	printf(" UTC Time: %s\n",tokenInfo->utcTime);	break;    case ArgSessionInfo:	sessionInfo = (CK_SESSION_INFO *)ptr->data;	printf(" SlotID: 0x%08lx\n", sessionInfo->slotID);	printf(" State: ");	printConst(sessionInfo->state, ConstSessionState, 1);	printFlags(" Flags: ", sessionInfo->flags, ConstSessionFlags);	printf(" Device error: %lu 0x%08lx\n",sessionInfo->ulDeviceError,			sessionInfo->ulDeviceError);	break;    case ArgAttribute:	attribute = (CK_ATTRIBUTE *)ptr->data;	printf(" Attribute Type: ");	printConst(attribute->type, ConstAttribute, 1);	printf(" Attribute Data: ");	if (attribute->pValue == NULL) {	    printf("NULL\n");	    printf("Attribute Len: %lu\n",attribute->ulValueLen);	} else {	    constType = getConstFromAttribute(attribute->type);	    if (constType != ConstNone) {		CK_ULONG value = (constType == ConstBool) ?		    *(CK_BBOOL *)attribute->pValue :		    *(CK_ULONG *)attribute->pValue;		printConst(value, constType, 1);	    } else {		printf("\n");		printDump(attribute->pValue, attribute->ulValueLen);	    }	}	break;    case ArgMechanism:	mechanism = (CK_MECHANISM *)ptr->data;	printf(" Mechanism Type: ");	printConst(mechanism->mechanism, ConstMechanism, 1);	printf(" Mechanism Data:\n");	printDump(mechanism->pParameter, mechanism->ulParameterLen);	break;    case ArgMechanismInfo:	mechanismInfo = (CK_MECHANISM_INFO *)ptr->data;	printf(" Minimum Key Size: %ld\n",mechanismInfo->ulMinKeySize);	printf(" Maximum Key Size: %ld\n",mechanismInfo->ulMaxKeySize);	printFlags(" Flags: ", mechanismInfo->flags, ConstMechanismFlags);	break;    case ArgInitializeArgs:	initArgs = (CK_C_INITIALIZE_ARGS *)ptr->data;	printFlags(" Flags: ", initArgs->flags, ConstInitializeFlags);    case ArgFunctionList:	functionList = (CK_FUNCTION_LIST *)ptr->data;	printf(" Version: %d.%02d\n", VERSION(functionList->version));#ifdef notdef#undef CK_NEED_ARG_LIST#define CK_PKCS11_FUNCTION_INFO(func) \	printf(" %s: 0x%08lx\n", #func, (unsigned long) functionList->func );#include "pkcs11f.h"#undef CK_NEED_ARG_LIST#undef CK_PKCS11_FUNCTION_INFO#endif    default:	ckrv = CKR_ARGUMENTS_BAD;	break;    }    return ckrv;}