1*12720SWyllys.Ingersoll@Sun.COM /* 2*12720SWyllys.Ingersoll@Sun.COM * CDDL HEADER START 3*12720SWyllys.Ingersoll@Sun.COM * 4*12720SWyllys.Ingersoll@Sun.COM * The contents of this file are subject to the terms of the 5*12720SWyllys.Ingersoll@Sun.COM * Common Development and Distribution License (the "License"). 6*12720SWyllys.Ingersoll@Sun.COM * You may not use this file except in compliance with the License. 7*12720SWyllys.Ingersoll@Sun.COM * 8*12720SWyllys.Ingersoll@Sun.COM * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9*12720SWyllys.Ingersoll@Sun.COM * or http://www.opensolaris.org/os/licensing. 10*12720SWyllys.Ingersoll@Sun.COM * See the License for the specific language governing permissions 11*12720SWyllys.Ingersoll@Sun.COM * and limitations under the License. 12*12720SWyllys.Ingersoll@Sun.COM * 13*12720SWyllys.Ingersoll@Sun.COM * When distributing Covered Code, include this CDDL HEADER in each 14*12720SWyllys.Ingersoll@Sun.COM * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15*12720SWyllys.Ingersoll@Sun.COM * If applicable, add the following below this CDDL HEADER, with the 16*12720SWyllys.Ingersoll@Sun.COM * fields enclosed by brackets "[]" replaced with your own identifying 17*12720SWyllys.Ingersoll@Sun.COM * information: Portions Copyright [yyyy] [name of copyright owner] 18*12720SWyllys.Ingersoll@Sun.COM * 19*12720SWyllys.Ingersoll@Sun.COM * CDDL HEADER END 20*12720SWyllys.Ingersoll@Sun.COM */ 21*12720SWyllys.Ingersoll@Sun.COM 22*12720SWyllys.Ingersoll@Sun.COM /* 23*12720SWyllys.Ingersoll@Sun.COM * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. 24*12720SWyllys.Ingersoll@Sun.COM */ 25*12720SWyllys.Ingersoll@Sun.COM 26*12720SWyllys.Ingersoll@Sun.COM /** 27*12720SWyllys.Ingersoll@Sun.COM * @file KMSAgentStringUtilities.h 28*12720SWyllys.Ingersoll@Sun.COM */ 29*12720SWyllys.Ingersoll@Sun.COM 30*12720SWyllys.Ingersoll@Sun.COM #ifndef KMSAgentStringUtilities_h 31*12720SWyllys.Ingersoll@Sun.COM #define KMSAgentStringUtilities_h 32*12720SWyllys.Ingersoll@Sun.COM 33*12720SWyllys.Ingersoll@Sun.COM #ifdef WIN32 34*12720SWyllys.Ingersoll@Sun.COM #pragma warning(disable: 4786) 35*12720SWyllys.Ingersoll@Sun.COM #endif 36*12720SWyllys.Ingersoll@Sun.COM 37*12720SWyllys.Ingersoll@Sun.COM #include <stdio.h> 38*12720SWyllys.Ingersoll@Sun.COM 39*12720SWyllys.Ingersoll@Sun.COM #include "SYSCommon.h" 40*12720SWyllys.Ingersoll@Sun.COM 41*12720SWyllys.Ingersoll@Sun.COM #ifdef __cplusplus 42*12720SWyllys.Ingersoll@Sun.COM extern "C" { 43*12720SWyllys.Ingersoll@Sun.COM #endif 44*12720SWyllys.Ingersoll@Sun.COM 45*12720SWyllys.Ingersoll@Sun.COM // 46*12720SWyllys.Ingersoll@Sun.COM // Functions for conversions between integers and strings. 47*12720SWyllys.Ingersoll@Sun.COM // 48*12720SWyllys.Ingersoll@Sun.COM 49*12720SWyllys.Ingersoll@Sun.COM /*---------------------------------------------------------------------------*/ 50*12720SWyllys.Ingersoll@Sun.COM /** 51*12720SWyllys.Ingersoll@Sun.COM * Converts a UTF8 string to an int64. 52*12720SWyllys.Ingersoll@Sun.COM * 53*12720SWyllys.Ingersoll@Sun.COM * @param i_sNumber: A string representation of the number to convert. 54*12720SWyllys.Ingersoll@Sun.COM * @return The integer the input string represented. 55*12720SWyllys.Ingersoll@Sun.COM */ 56*12720SWyllys.Ingersoll@Sun.COM /*---------------------------------------------------------------------------*/ 57*12720SWyllys.Ingersoll@Sun.COM int64 UTF8ToInt64( const char* i_sNumber ); 58*12720SWyllys.Ingersoll@Sun.COM 59*12720SWyllys.Ingersoll@Sun.COM /** 60*12720SWyllys.Ingersoll@Sun.COM * Formats an int64 into a UTF8 string. 61*12720SWyllys.Ingersoll@Sun.COM * 62*12720SWyllys.Ingersoll@Sun.COM * A note on padding: If i_bPad is true, the string will be padded to the 63*12720SWyllys.Ingersoll@Sun.COM * maximum size necessary to hold a an int64 representation. For decimal this 64*12720SWyllys.Ingersoll@Sun.COM * is 19, for hex it is 16. 65*12720SWyllys.Ingersoll@Sun.COM * 66*12720SWyllys.Ingersoll@Sun.COM * @param i_iNumber The number to format. 67*12720SWyllys.Ingersoll@Sun.COM * @param i_bPad If true, the string will be padded with zeroes. (See note above.) 68*12720SWyllys.Ingersoll@Sun.COM * @param i_bHex Indicates whether the string format should be a hexadecimal 69*12720SWyllys.Ingersoll@Sun.COM * representation of the integer (true) or a decimal representation (false). 70*12720SWyllys.Ingersoll@Sun.COM * @param o_psUTF8 the string representation of the integer 71*12720SWyllys.Ingersoll@Sun.COM * 72*12720SWyllys.Ingersoll@Sun.COM * @return void 73*12720SWyllys.Ingersoll@Sun.COM */ 74*12720SWyllys.Ingersoll@Sun.COM void Int64ToUTF8(char* const o_psUTF8, 75*12720SWyllys.Ingersoll@Sun.COM int64 i_iNumber, 76*12720SWyllys.Ingersoll@Sun.COM int i_bPad, 77*12720SWyllys.Ingersoll@Sun.COM int i_bHex ); 78*12720SWyllys.Ingersoll@Sun.COM 79*12720SWyllys.Ingersoll@Sun.COM // 80*12720SWyllys.Ingersoll@Sun.COM // Functions for converting between binary buffer and hex string 81*12720SWyllys.Ingersoll@Sun.COM // 82*12720SWyllys.Ingersoll@Sun.COM 83*12720SWyllys.Ingersoll@Sun.COM /*--------------------------------------------------------------------------*/ 84*12720SWyllys.Ingersoll@Sun.COM /** 85*12720SWyllys.Ingersoll@Sun.COM * Converts a UTF8 hex string to its binary representation. 86*12720SWyllys.Ingersoll@Sun.COM * 87*12720SWyllys.Ingersoll@Sun.COM * If o_pBinaryBuffer is null, the function will return the required size. 88*12720SWyllys.Ingersoll@Sun.COM * (The required size is always strlen(i_sHexString)/2.) 89*12720SWyllys.Ingersoll@Sun.COM * 90*12720SWyllys.Ingersoll@Sun.COM * @param i_sHexString: The hex string to convert. 91*12720SWyllys.Ingersoll@Sun.COM * @param o_pBinaryBuffer: The buffer in which to put the binary 92*12720SWyllys.Ingersoll@Sun.COM * representation of the hex string. If this is null, the function 93*12720SWyllys.Ingersoll@Sun.COM * returns the required size. 94*12720SWyllys.Ingersoll@Sun.COM * If this is not null, it must be large enough to hold binary conversion. 95*12720SWyllys.Ingersoll@Sun.COM * 96*12720SWyllys.Ingersoll@Sun.COM * @return The number of bytes put into o_pBinaryBuffer (or the number of bytes 97*12720SWyllys.Ingersoll@Sun.COM * required, if o_pBinaryBuffer was null). 98*12720SWyllys.Ingersoll@Sun.COM */ 99*12720SWyllys.Ingersoll@Sun.COM /*---------------------------------------------------------------------------*/ 100*12720SWyllys.Ingersoll@Sun.COM int ConvertUTF8HexStringToBinary( 101*12720SWyllys.Ingersoll@Sun.COM const char* i_sHexString, 102*12720SWyllys.Ingersoll@Sun.COM unsigned char* o_pBinaryBuffer); 103*12720SWyllys.Ingersoll@Sun.COM 104*12720SWyllys.Ingersoll@Sun.COM /** 105*12720SWyllys.Ingersoll@Sun.COM * Converts a binary buffer to its UTF8 hex string representation. 106*12720SWyllys.Ingersoll@Sun.COM * 107*12720SWyllys.Ingersoll@Sun.COM * @param i_pBinaryBuffer: The binary buffer to convert. 108*12720SWyllys.Ingersoll@Sun.COM * @param i_iBinaryBufferSize: The size of i_pBinaryBuffer; 109*12720SWyllys.Ingersoll@Sun.COM * @param o_sHexString The hex string representation of the 110*12720SWyllys.Ingersoll@Sun.COM * binary buffer which should be at least 111*12720SWyllys.Ingersoll@Sun.COM * (i_iBinaryBufferSize * 2) + 1 characters long 112*12720SWyllys.Ingersoll@Sun.COM */ 113*12720SWyllys.Ingersoll@Sun.COM void ConvertBinaryToUTF8HexString( 114*12720SWyllys.Ingersoll@Sun.COM char* const o_sHexString, 115*12720SWyllys.Ingersoll@Sun.COM const unsigned char* const i_pBinaryBuffer, 116*12720SWyllys.Ingersoll@Sun.COM int i_iBinaryBufferSize ); 117*12720SWyllys.Ingersoll@Sun.COM 118*12720SWyllys.Ingersoll@Sun.COM // 119*12720SWyllys.Ingersoll@Sun.COM // Functions for date strings 120*12720SWyllys.Ingersoll@Sun.COM // 121*12720SWyllys.Ingersoll@Sun.COM 122*12720SWyllys.Ingersoll@Sun.COM /** 123*12720SWyllys.Ingersoll@Sun.COM * populates o_psDateTimeISO8601UTC with a null terminated ISO 8601 124*12720SWyllys.Ingersoll@Sun.COM * formatted timestamp string from the current UTC time of the 125*12720SWyllys.Ingersoll@Sun.COM * system. The timestamp length will be restricted to i_iLength-1 126*12720SWyllys.Ingersoll@Sun.COM * characters. 127*12720SWyllys.Ingersoll@Sun.COM */ 128*12720SWyllys.Ingersoll@Sun.COM void GetCurrentDateTimeISO8601UTC(char* const o_psDateTimeISO8601UTC, 129*12720SWyllys.Ingersoll@Sun.COM int i_iLength); 130*12720SWyllys.Ingersoll@Sun.COM 131*12720SWyllys.Ingersoll@Sun.COM #ifdef __cplusplus 132*12720SWyllys.Ingersoll@Sun.COM } 133*12720SWyllys.Ingersoll@Sun.COM #endif 134*12720SWyllys.Ingersoll@Sun.COM 135*12720SWyllys.Ingersoll@Sun.COM #endif //KMSAgentStringUtilities_h 136