ptr-string.h (2114B)
1/* 2 * Licensed to the Apache Software Foundation (ASF) under one 3 * or more contributor license agreements. See the NOTICE file 4 * distributed with this work for additional information 5 * regarding copyright ownership. The ASF licenses this file 6 * to you under the Apache License, Version 2.0 (the 7 * "License"); you may not use this file except in compliance 8 * with the License. You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, 13 * software distributed under the License is distributed on an 14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 * KIND, either express or implied. See the License for the 16 * specific language governing permissions and limitations 17 * under the License. 18 */ 19 20#ifndef GUAC_RDP_PLUGINS_PTR_STRING_H 21#define GUAC_RDP_PLUGINS_PTR_STRING_H 22 23#include <guacamole/client.h> 24 25/** 26 * The maximum number of bytes required to represent a pointer printed using 27 * printf()'s "%p". This will be the size of the hex prefix ("0x"), null 28 * terminator, plus two bytes for every byte required by a pointer. 29 */ 30#define GUAC_RDP_PTR_STRING_LENGTH (sizeof("0x") + (sizeof(void*) * 2)) 31 32/** 33 * Converts the given string back into a void pointer. The string MUST have 34 * been produced via guac_rdp_ptr_to_string(). 35 * 36 * @param str 37 * The string to convert back to a pointer. 38 * 39 * @return 40 * The pointer value of the given string, as originally passed to 41 * guac_rdp_ptr_to_string(). 42 */ 43void* guac_rdp_string_to_ptr(const char* str); 44 45/** 46 * Converts a void pointer into a string representation, safe for use with 47 * parts of the FreeRDP API which provide only for passing arbitrary strings, 48 * despite being within the same memory area. 49 * 50 * @param data 51 * The void pointer to convert to a string. 52 * 53 * @param str 54 * The buffer in which the string representation of the given void pointer 55 * should be stored. This buffer must have at least 56 * GUAC_RDP_PTR_STRING_LENGTH bytes available. 57 */ 58void guac_rdp_ptr_to_string(void* data, char* str); 59 60#endif 61