static int elektraResolveFilename (Key * parentKey, ElektraResolveTempfile tmpFile) { int rc = 0; void * handle = elektraInvokeOpen ("resolver", 0, 0); if (!handle) { rc = -1; goto RESOLVE_FAILED; } ElektraResolved * resolved = NULL; typedef ElektraResolved * (*resolveFileFunc) (elektraNamespace, const char *, ElektraResolveTempfile, Key *); resolveFileFunc resolveFunc = *(resolveFileFunc *) elektraInvokeGetFunction (handle, "filename"); if (!resolveFunc) { rc = -1; goto RESOLVE_FAILED; } typedef void (*freeHandleFunc) (ElektraResolved *); freeHandleFunc freeHandle = *(freeHandleFunc *) elektraInvokeGetFunction (handle, "freeHandle"); if (!freeHandle) { rc = -1; goto RESOLVE_FAILED; } resolved = resolveFunc (keyGetNamespace (parentKey), keyString (parentKey), tmpFile, parentKey); if (!resolved) { rc = -1; goto RESOLVE_FAILED; } else { keySetString (parentKey, resolved->fullPath); freeHandle (resolved); } RESOLVE_FAILED: elektraInvokeClose (handle, 0); return rc; }
/** * @brief decodes Base64 encoded data by utilizing libinvoke. * @param input holds the Base64 encoded data string * @param output will be set to an allocated buffer holding the decoded data or NULL if the allocation failed. Must be freed by the caller on success. * @param outputLength will be set to the amount of decoded bytes. * @param errorKey will hold an error description if libinvoke fails. * @retval 1 on success * @retval -1 if the provided string has not been encoded with Base64 * @retval -2 if the output buffer allocation failed * @retval -3 if libinvoke reported an error (errorKey is being set). */ int CRYPTO_PLUGIN_FUNCTION (base64Decode) (Key * errorKey, const char * input, kdb_octet_t ** output, size_t * outputLength) { ElektraInvokeHandle * handle = elektraInvokeOpen ("base64", 0, errorKey); if (!handle) { return -3; } typedef int (*base64DecodeFunction) (const char * input, kdb_octet_t ** output, size_t * outputLength); base64DecodeFunction decodingFunction = *(base64DecodeFunction *) elektraInvokeGetFunction (handle, "base64Decode"); if (!decodingFunction) { elektraInvokeClose (handle, 0); return -3; } int result = decodingFunction (input, output, outputLength); elektraInvokeClose (handle, 0); return result; }
/** * @brief Encodes arbitrary data using the Base64 schema by utilizing libinvoke. * @param errorKey will hold an error description if libinvoke fails. * @param input holds the data to be encoded * @param inputLength tells how many bytes the input buffer is holding. * @param output points to an allocated string holding the Base64 encoded input data or NULL if the string can not be allocated. Must be * freed by the caller. * @retval 1 on success * @retval -1 if libinvoke reported an error (errorKey is being set). */ int CRYPTO_PLUGIN_FUNCTION (base64Encode) (Key * errorKey, const kdb_octet_t * input, const size_t inputLength, char ** output) { ElektraInvokeHandle * handle = elektraInvokeOpen ("base64", 0, errorKey); if (!handle) { return -1; } typedef char * (*base64EncodeFunction) (const kdb_octet_t * input, const size_t inputLength); base64EncodeFunction encodingFunction = *(base64EncodeFunction *) elektraInvokeGetFunction (handle, "base64Encode"); if (!encodingFunction) { elektraInvokeClose (handle, 0); return -1; } *output = encodingFunction (input, inputLength); elektraInvokeClose (handle, 0); return 1; }