Exemplo n.º 1
0
nitf_PluginRegistry_retrieveCompConstructor(nitf_PluginRegistry * reg,
                                            const char *ident,
                                            int *hadError,
                                            nitf_Error * error)
{

    /*  We get back a pair from the hash table  */
    nitf_Pair *pair;

    /*  No error has occurred (yet)  */
    *hadError = 0;

    if (!nitf_HashTable_exists(reg->compressionHandlers, ident))
    {
        *hadError = 1;
        nitf_Error_init(error, "Compression handlers not set", NRT_CTXT,
        		        NRT_ERR_COMPRESSION);
        return NULL;
    }
    pair = nitf_HashTable_find(reg->compressionHandlers, ident);

    /*  If nothing is there, we don't have a handler, plain and simple  */
    if (!pair)
    {
        nitf_Error_initf(error, NRT_CTXT, NRT_ERR_COMPRESSION,
        		         "Don't have a handler for '%s'",
        		         ident);
        return NULL;
    }

    return (NITF_PLUGIN_COMPRESSION_CONSTRUCT_FUNCTION) pair->data;
}
Exemplo n.º 2
0
nitf_PluginRegistry_retrieveTREHandler(nitf_PluginRegistry * reg,
                                       const char *treIdent,
                                       int *hadError,
                                       nitf_Error * error)
{
    nitf_TREHandler* theHandler;
    /*  We get back a pair from the hash table  */
    nitf_Pair *pair;
    /*  We are trying to find tre_main  */
    NITF_PLUGIN_TRE_HANDLER_FUNCTION treMain = NULL;

    /*  No error has occurred (yet)  */
    *hadError = 0;

    if (!nitf_HashTable_exists(reg->treHandlers, treIdent))
    {
        return NULL;
    }
    /*  Lookup the pair from the hash table, by the tre_id  */
    pair = nitf_HashTable_find(reg->treHandlers, treIdent);

    /*  If nothing is there, we dont have a handler, plain and simple  */
    if (!pair)
        return NULL;

    /*  If something is, get its DLL part  */
    treMain = (NITF_PLUGIN_TRE_HANDLER_FUNCTION) pair->data;

    theHandler = (*treMain)(error);
    if (!theHandler)
    {
        *hadError = 1;
    }
    return theHandler;
}
Exemplo n.º 3
0
void findInExtensions(nitf_Extensions* ext)
{
    /*  These iterators are for going through the image segments  */
    nitf_ListIterator  iter;
    nitf_ListIterator  end;
    nitf_List* list;
    assert( ext );

    list = nitf_Extensions_get(ext, "ACFTB");
    if (list)
    {
        /*  Set the iterator to traverse the list of image segments  */
        iter = nitf_List_begin(list);
        /*  And set this one to the end, so we'll know when we're done!  */
        end  = nitf_List_end(list);

        /*  While we are not done...  */
        while ( nitf_ListIterator_notEqualTo(&iter, &end) )
        {
            nitf_TRE* tre;

            printf("Found ACFTB instance\n");

            /*  Get the image segment as its proper object  */
            tre = (nitf_TRE*)nitf_ListIterator_get(&iter);
            if ( nitf_HashTable_exists( tre->hash, "raw_data" ) )
            {
                printf("Your plugin for ACFTB was not loaded so the data is contained in the RAW section\n");
            }
            else
            {
                nitf_Pair* mission = nitf_HashTable_find( tre->hash,
                                     "ACMSNID" );
                if (! mission )
                {
                    printf("Error: no Mission ID available\n");
                    nitf_HashTable_print( tre->hash );

                }


                else
                {
                    nitf_Field* field = (nitf_Field*)mission->data;

                    printf("Mission ID: [%.*s]\n", field->length, field->raw);
                }
            }

            /*  Increment the iterator so we can continue  */
            nitf_ListIterator_increment(&iter);
        }
    }
    else
    {
        printf("No ACFTB\n");
    }

}
Exemplo n.º 4
0
NITFPRIV(NITF_BOOL) insertCreator(nitf_DLL* dso, 
                                  nitf_HashTable* hash,
                                  const char* ident,
                                  const char* suffix,
                                  nitf_Error* error)
{
    /*  We are trying to find tre_main  */
    NITF_DLL_FUNCTION_PTR dsoMain = NULL;

    /*  Get the name of the handler  */
    char name[NITF_MAX_PATH];
    char* p = NULL;

    if (!nitf_DLL_isValid(dso))
    {
        nitf_Error_initf(error,
                         NITF_CTXT,
                         NITF_ERR_INVALID_PARAMETER,
                         "DSO is not valid for [%s]",
                         ident);

    }

    memset(name, 0, NITF_MAX_PATH);
    NITF_SNPRINTF(name, NITF_MAX_PATH, "%s%s", ident, suffix);

    nitf_Utils_replace(name, ' ', '_');

    /*  No error has occurred (yet)  */
#if NITF_DEBUG_PLUGIN_REG
    printf("Loading function [%s] in dso at [%p]\n", name, dso);
#endif

    /*  Retrieve the main  */
    dsoMain = nitf_DLL_retrieve(dso, name, error);

    if (!dsoMain)
    {
        /*  If it didnt work, we are done  */
        return NITF_FAILURE;
    }

#if NITF_DEBUG_PLUGIN_REG
    if (nitf_HashTable_exists(hash, ident))
    {
        printf("Warning, overriding [%s] hook", ident);
        
    }
#endif
    
    return nitf_HashTable_insert(hash, ident, dsoMain, error);

}
Exemplo n.º 5
0
nitf_PluginRegistry_registerTREHandler(NITF_PLUGIN_INIT_FUNCTION init,
                                       NITF_PLUGIN_TRE_HANDLER_FUNCTION handle,
                                       nitf_Error * error)
{

    nitf_PluginRegistry* reg = nitf_PluginRegistry_getInstance(error);

    const char** ident;
    int i = 1;
    int ok = 1;
    if (!reg)
    {
        return NITF_FAILURE;
    }
    if ( (ident = (*init)(error)) == NULL)
    {
        return NITF_FAILURE;
    }

    if (!ident[0] || (strcmp(ident[0], NITF_PLUGIN_TRE_KEY) != 0))
    {
        nitf_Error_initf(error,
                         NITF_CTXT,
                         NITF_ERR_INVALID_OBJECT,
                         "Expected a TRE identity");
        return NITF_FAILURE;
    }

    for (; ident[i] != NULL; ++i)
    {
#ifdef NITF_DEBUG_PLUGIN_REG
        if (nitf_HashTable_exists(reg->treHandlers, ident[i]))
        {
            printf("Warning, static handler overriding [%s] hook\n", ident[i]);
        }
#endif
        ok &= nitf_HashTable_insert(reg->treHandlers, ident[i], (NITF_DATA*)handle, error);
    }

    return ok;

}
Exemplo n.º 6
0
NITFPRIV(NITF_BOOL) defaultSetField(nitf_TRE * tre,
                                    const char *tag,
                                    NITF_DATA * data,
                                    size_t dataLength, nitf_Error * error)
{
	nitf_Field* field = NULL;

	if (strcmp(tag, NITF_TRE_RAW))
	{
        nitf_Error_initf(error, NITF_CTXT, NITF_ERR_INVALID_PARAMETER, "Invalid param [%s]", tag);
        return NITF_FAILURE;
	}

	field = nitf_Field_construct(dataLength, NITF_BINARY, error);
    if (!field)
        return NITF_FAILURE;

    /* TODO -- likely inefficient, since we end up copying the raw data here */
    if (!nitf_Field_setRawData(field, (NITF_DATA *) data, dataLength, error))
        return NITF_FAILURE;

	if (nitf_HashTable_exists(((nitf_TREPrivateData*)tre->priv)->hash, tag))
	{
        nitf_Field* oldValue;
        nitf_Pair* pair = nitf_HashTable_find(
                ((nitf_TREPrivateData*)tre->priv)->hash, tag);
        oldValue = (nitf_Field*)pair->data;
        nitf_Field_destruct(&oldValue);
        pair->data = field;
        return NITF_SUCCESS;
	}

	/* reset the lengths in two places */
	((nitf_TREPrivateData*)tre->priv)->length = dataLength;
	((nitf_TREPrivateData*)tre->priv)->description[0].data_count = dataLength;

	return nitf_HashTable_insert(((nitf_TREPrivateData*)tre->priv)->hash,
	        tag, field, error);
}
Exemplo n.º 7
0
nitf_PluginRegistry_internalTREHandlerExists(nitf_PluginRegistry* reg,
                                             const char* ident)
{
    return nitf_HashTable_exists(reg->treHandlers, ident);
}
Exemplo n.º 8
0
NITFAPI(NITF_BOOL) nitf_TREUtils_setValue(nitf_TRE * tre,
                                          const char *tag,
                                          NITF_DATA * data,
                                          size_t dataLength, 
                                          nitf_Error * error)
{
    nitf_Pair *pair;
    nitf_Field *field = NULL;
    nitf_TRECursor cursor;
    NITF_BOOL done = 0;
    NITF_BOOL status = 1;
    nitf_FieldType type = NITF_BCS_A;

    /* used temporarily for storing the length */
    int length;

    /* get out if TRE is null */
    if (!tre)
    {
        nitf_Error_init(error, "setValue -> invalid tre object",
                NITF_CTXT, NITF_ERR_INVALID_PARAMETER);
        return NITF_FAILURE;
    }

    /* If the field already exists, get it and modify it */
    if (nitf_HashTable_exists(((nitf_TREPrivateData*)tre->priv)->hash, tag))
    {
        pair = nitf_HashTable_find(
                ((nitf_TREPrivateData*)tre->priv)->hash, tag);
        field = (nitf_Field *) pair->data;

        if (!field)
        {
            nitf_Error_initf(error, NITF_CTXT, NITF_ERR_INVALID_PARAMETER,
                    "setValue -> invalid field object: %s", tag);
            return NITF_FAILURE;
        }

        /* check to see if the data passed in is too large or too small */
        if ((dataLength > field->length && !field->resizable) || dataLength < 1)
        {
            nitf_Error_initf(error, NITF_CTXT, NITF_ERR_INVALID_PARAMETER,
                    "setValue -> invalid dataLength for field: %s", tag);
            return NITF_FAILURE;
        }

        if (!nitf_Field_setRawData
            (field, (NITF_DATA *) data, dataLength, error))
        {
            return NITF_FAILURE;
        }
#ifdef NITF_DEBUG
        fprintf(stdout, "Setting (and filling) Field [%s] to TRE [%s]\n",
                tag, tre->tag);
#endif

        /* Now we need to fill our data */
        if (!nitf_TREUtils_fillData(tre,
                                    ((nitf_TREPrivateData*)tre->priv)->description,
                                    error))
            return NITF_FAILURE;

    }
    /* it doesn't exist in the hash yet, so we need to find it */
    else
    {

        cursor = nitf_TRECursor_begin(tre);
        while (!nitf_TRECursor_isDone(&cursor) && !done && status)
        {
            if (nitf_TRECursor_iterate(&cursor, error) == NITF_SUCCESS)
            {
                /* we found it */
                if (strcmp(tag, cursor.tag_str) == 0)
                {
                    if (cursor.desc_ptr->data_type == NITF_BCS_A)
                    {
                        type = NITF_BCS_A;
                    }
                    else if (cursor.desc_ptr->data_type == NITF_BCS_N)
                    {
                        type = NITF_BCS_N;
                    }
                    else if (cursor.desc_ptr->data_type == NITF_BINARY)
                    {
                        type = NITF_BINARY;
                    }
                    else
                    {
                        /* bad type */
                        nitf_Error_init(error,
                                "setValue -> invalid data type",
                                NITF_CTXT,
                                NITF_ERR_INVALID_PARAMETER);
                        return NITF_FAILURE;
                    }

                    length = cursor.length;
                    /* check to see if we should gobble the rest */
                    if (length == NITF_TRE_GOBBLE)
                    {
                        length = dataLength;
                    }

                    /* construct the field */
                    field = nitf_Field_construct(length, type, error);

                    /* now, set the data */
                    nitf_Field_setRawData(field, (NITF_DATA *) data,
                            dataLength, error);

#ifdef NITF_DEBUG
                    fprintf(stdout, "Adding (and filling) Field [%s] to TRE [%s]\n",
                            cursor.tag_str, tre->tag);
#endif

                    /* add to the hash */
                    nitf_HashTable_insert(
                            ((nitf_TREPrivateData*)tre->priv)->hash,
                            cursor.tag_str, field, error);


                    /* Now we need to fill our data */
                    if (!nitf_TREUtils_fillData(tre, ((nitf_TREPrivateData*)tre->priv)->description, error))
                        return NITF_FAILURE;

                    done = 1; /* set, so we break out of loop */
                }
            }
        }
        /* did we find it? */
        if (!done)
        {
            nitf_Error_initf(error, NITF_CTXT, NITF_ERR_UNK,
                    "Unable to find tag, '%s', in TRE hash for TRE '%s'",
                    tag, tre->tag);
            status = 0;
        }
        nitf_TRECursor_cleanup(&cursor);
    }
    return status;

}
Exemplo n.º 9
0
bool nitf::HashTable::exists(const std::string& key)
{
    return nitf_HashTable_exists(getNative(), key.c_str());
}