Construct hkeypath from string(xml path)

How I construct hkeypath from string(xml path) ?
I tried to use maapi_xpath2kpath. But I get following error:
TRACE MAAPI_XPATH2HKP DEBUG Operation not implemented - Unknown CDB operation

It depends a bit on what you want to do, can you explain in a little bit more detail.

I have never used the maapi function you mentioned, I have however used confd_format_keypath, which might be what you want.

Here is a code example of two different use cases:

confd_value_t wbuf;
CONFD_SET_STR(&wbuf, "www");
struct in_addr in;
inet_pton(AF_INET, "", &in);
n = confd_format_keypath(buf2, 255,
                         "servers", &wbuf, &in);
n = confd_format_keypath(buf2, 255, "/mtest");

I need a function that will take a string path and return a confd_hkeypath_t
confd_format_keypath returns a string

In other words I need a function that performs reverse of confd_pp_kpath()

Why do you need to produce a confd_hkeypath_t? Normally ConfD passes to you a keypath in hashed form; I’m not aware of any API call that requires you to pass a hashed keypath.

That said, there is one way I could see doing this. If you are writing application code using the CDB API, you could use cdb_cd using the string keypath to set the current working directory, then use cdb_getcwd_kpath to get the hashed keypath. MAAPI also has a similar pair of api calls that could be used to do this.

Hi Greg,

Using cdb_cd and cdb_getcwd_kpath solved my problem. Thank you very much.

I am using the following code in order to retrieve the enum key names:

struct confd_cs_node *node;
confd_hkeypath_t *kp;
confd_value_t newv;

cdb_get(rsock, &newv, path);
cdb_cd(rsock, path);
cdb_getcwd_kpath(rsock, &kp);
node = confd_find_cs_node(kp, kp->len);
confd_val2str(node->info.type, &newv, fieldValue, sizeof(fieldValue));

alext wrote:

cdb_cd(rsock, path);
cdb_getcwd_kpath(rsock, &kp);
node = confd_find_cs_node(kp, kp->len);

It seems you overlooked the confd_cs_node_cd() function. Using that, the code above becomes just (assuming that ‘path’ is an absolute path):

node = confd_cs_node_cd(NULL, path);

I.e. as greg wrote, you are never required to pass a hkeypath - confd_find_cs_node() is intended for the cases where a hkeypath is what you already have, e.g. iter() callback of cdb_diff_iterate(), or data provider callbacks.