How to convert string to hash

I am working with ietf-alarms.yang data model. I defined my own alarm like this:

module thales-mcg-alarm {
    yang-version 1.1;
    namespace "";
    prefix "mcg-al";
    import ietf-alarms 		{ prefix al; }

    identity mcg-alarms {
       base al:alarm-type-id;
} // module thales-mcg-alarm

It translates to header file:

#ifndef mcg_al__ns
#define mcg_al__ns 1380531167
#define mcg_al__ns_id ""
#define mcg_al__ns_uri ""

#define mcg_al_mcg_alarms 215529530

I can convert hash to alarm name like this:

char* alarmStr = confd_hash2str(mcg_al_mcg_alarms);  // returns 'mcg_alarms'

But how can I do the opposite? How to convert alarm name to hash? The following does not work:

unsigned int hash = confd_str2hash("mcg_alarms");  // returns 0
hash = confd_str2hash("");  // returns 0

Did you load the schema using for example confd_load_schemas()? See the confd_lib_lib(3) man page for details.

Yes, I loaded the schema. Without schema loaded the API confd_hash2str() wouldn’t work. But it works fine.
I need the opposite: to convert string representation of identity ref to hash.

Should have hyphen instead of an underscore.
unsigned int hash = confd_str2hash("mcg-alarms");

Thanks a lot. Sometimes one doesn’t see simple things.

1 Like