GW2GetFileType
File type IDs are mapped to file types supported by the Glasswall Engine. This API provides the formal name of the file type in string format given a file type ID number.
- C++
- C#
- Java
- Python
- JavaScript
#include "glasswall.core2.api.h"
int GW2GetFileType(
Session session,
size_t fileId,
size_t *bufferLength,
char **outputBuffer);
Parameters
session The ID of the session as returned by GW2OpenSession
fileId An integer representing the file type ID
bufferLength An output parameter which is populated with size in bytes of the memory pointed to by outputBuffer.
outputBuffer A string pointer output parameter which is populated with the formal name of the file type associated with the supplied file ID, eg. "BMP Image". The memory used by this pointer does not need to be freed by the user.
Returns
Returns an integer indicating whether the function call was successful. Negative numbers indicate a failure. See the Return Types table for an explanation of the return codes. If successful the outputBuffer is populated with the formal name associated with the file type.
Example
#include "glasswall.core2.api.h"
#include "filetype.h" // ft_t enum which includes ft_bmp
char *outbuf = NULL;
size_t buflen = 0;
if (GW2OpenSession() < 0)
/* Error opening session */
else
{
int status = GW2GetFileType(session, ft_bmp, &buflen, &outbuf);
/* In this example outbuf will point to the string "BMP Image". */
if (GW2CloseSession() < 0)
/* Error closing session */
}
Synopsis
public int GW2GetFileType(
int session,
uint fileID,
ref UIntPtr bufferLength,
out IntPtr outputBuffer)
Returns
Returns an integer GW2_RetStatus enum value. Negative numbers indicate a failure. If successful, the output buffer is
populated with the formal name of the file type.
Example
using glasswall_core2;
...
Glasswall glasswall = new Glasswall(); // Instance of the Glasswall wrapper
int session = glasswall.OpenSession();
int returnStatus = glasswall.GW2GetFileType(session, 22, ref bufferLength, out buffer);
if (bufferLength >= 0)
{
byte[] msgArray = glasswall.CreateArrayFromBuffer(buffer, bufferLength);
// Formal name for file type ID 22 now stored in a byte array
}
if (glasswall.CloseSession(session))
{
// Error Handling
}
Synopsis
import com.glasswall.core2javabridge.*;
public String GW2GetFileTypeString(int session, int fileId) throws GlasswallException
Note
This functionality previously required two separate function calls to retrieve the file type data. This has now been streamlined to return the settings as a String. The two original functions have been deprecated.
Returns
The GW2GetFileTypeString function returns a String representation of a filetype ID.
A GlasswallException exception will be thrown if session is invalid, or if the file type could not be retrieved.
Synopsis - Deprecated Functions
import com.glasswall.core2javabridge.*;
(Deprecated)
public int GW2GetFileType(int session, int fileId) throws GlasswallException
public byte[] GetFileTypeBuffer(int session) throws GlasswallException
Description - Deprecated Functions
The GW2GetFileType function outputs a representation of fileId for the session specified by session, to the internal FileType Buffer. Retrieve this data through use of the GetFileTypeBuffer function.
Returns - Deprecated Functions
The GW2GetFileType function returns a GW2_RetStatus enumeration converted to int. The value will be negative if an error occurred. 0 indicates success. Refer to the API Overview/Return types for details.
The GetFileTypeBuffer function returns a UTF-8 encoded byte[] containing a representation of a filetype ID. This will be null if GW2GetFileType has not been called.
A GlasswallException exception will be thrown if session is invalid, or if the file type could not be retrieved.
Synopsis
Retrieve information about a file type based on its identifier.
def get_file_type_info(self, file_type: Union[str, int]):
""" Retrieve information about a file type based on its identifier.
Args:
file_type (Union[str, int]): The file type identifier. This can be either a string representing a file
extension (e.g. 'bmp') or an integer corresponding to a file type (e.g. 29).
Returns:
- file_type_info (Union[int, str]): Depending on the input 'file_type':
- If `file_type` is a string (e.g. 'bmp'):
- If the file type is recognised, returns an integer corresponding to that file type.
- If the file type is not recognised, returns 0.
- If `file_type` is an integer (e.g. 29):
- If the integer corresponds to a recognised file type, returns a more detailed string description
of the file type (e.g. 'BMP Image').
- If the integer does not match any recognised file type, returns an empty string.
"""
Returns
Returns an integer or string depending on the input 'file_type'. This value is either an integer of a recognised file type, a detailed string description of a recognised file type or if the input 'file_type' was not recognised, 0 or an empty string.
Synopsis
This function places a pointer to a description of a specified fileID in a specified location.
/**
*
* @param {number} session The ID of the session.
* @param {number} fileID The ID of the file type.
* @param {number} bufferLength The length of the buffer.
* @param {string} outputBuffer The location of the output buffer.
*/
GW2GetFileType(
session,
fileID,
bufferLength,
outputBuffer)
Returns
Returns an integer GW2_RetStatus enum value. Negative numbers indicate a failure. If successful, the output buffer is populated with the formal name of the file type.
Example
const ref = require('ref-napi');
...
function buffer_to_string(buffer, buffer_size) {
if (!buffer.isNull() && ref.deref(buffer_size) > 0) {
return Buffer.from(ref.reinterpret(ref.deref(buffer), ref.deref(buffer_size), 0)).toString();
}
else {
return "";
}
}
...
output_file_buffer = ref.alloc(ref.refType(ref.types.CString));
output_buffer_size = ref.alloc(ref.types.size_t, 0);
return_status = gw.GW2GetFileType(session_id, 22, output_buffer_size, output_file_buffer);
let error_description = buffer_to_string(output_file_buffer, output_buffer_size);
...