Compilation of C application file for performing transactions

Hello,
I would like to know how to create our own application file using C language for performing read and write opeartions in confd for a database. What kind of data has to be used for implementing read and write in confd (i.e., configuration or operational data)? After writing the C application file for read and write operations for my database, what is the command/procedure by which i could compile and execute the C file? please help me to proceed with this. Thanks in advance!

ConfD is delivered with examples - see the directory examples.confd in your ConfD installation - that are aimed to show ConfD concepts from basic to more advanced ones. Your purpose, i.e. a C application that reads and updates configuration managed by ConfD, is probably best exemplified by intro/12-c_maapi - MAAPI is the ConfD interface that enables exactly that; but so as to understands the concepts, you may want to look at more basic ones before. And you definitely should accompany that by going through the user guide, in particular the chapter “The Management Agent API”.

Thank You very much sir. I’ll go through the chapter and example in confD as you have mentioned above.

Hello Sir,
After we have read through the intro/12-c_maapi directory for creating our own C application file and executing it, we have written the C code for our database and tried to execute it by initiating the interaction with confd using the command “make all start”,but we have encountered with some errors as follows:
movie2.c: In function ‘cnct’:
movie2.c:38:40: error: ‘pass’ undeclared (first use in this function); did you mean ‘puts’?
if (maapi_authenticate(sock, user, pass, &groups[0], 10) == 1) {
^~
puts
movie2.c:38:40: note: each undeclared identifier is reported only once for each function it appears in
In file included from movie2.c:3:0:
movie2.c:43:31: error: ‘srcip’ undeclared (first use in this function)
&srcip, CONFD_PROTO_TCP);
^
…/include/confd_maapi.h:223:56: note: in definition of macro ‘maapi_start_user_session’
maapi_start_user_session3(s, user, ctx, groups, n, addr, 0, prot,
^~
movie2.c:42:51: warning: passing argument 4 of ‘maapi_start_user_session3’ from incompatible pointer type [-Wincompatible-pointer-types]
maapi_start_user_session(sock, user, context, groups, i,
^
…/include/confd_maapi.h:223:45: note: in definition of macro ‘maapi_start_user_session’
maapi_start_user_session3(s, user, ctx, groups, n, addr, 0, prot,
^~~~
…/include/confd_maapi.h:230:12: note: expected ‘const char *’ but argument is of type ‘char *’
extern int maapi_start_user_session3(int sock,
^~~~~~~~~
movie2.c: In function ‘readwrite’:
movie2.c:61:12: warning: implicit declaration of function ‘strtok’ [-Wimplicit-function-declaration]
if((tok= strtok(ibuf, DELIM)) == NULL) {
^~~~
movie2.c:61:10: warning: assignment makes pointer from integer without a cast [-Wint-conversion]
if((tok= strtok(ibuf, DELIM)) == NULL) {
^
movie2.c:67:13: warning: implicit declaration of function ‘strcmp’ [-Wimplicit-function-declaration]
if(strcmp(tok, “get”)==0) {
^~~~
movie2.c:77:23: warning: passing argument 1 of ‘confd_pp_value’ from incompatible pointer type [-Wincompatible-pointer-types]
confd_pp_value(&id,&mc.keys[0]); // key of the table
^
In file included from movie2.c:2:0:
…/include/confd_lib.h:1075:12: note: expected ‘char *’ but argument is of type ‘int *’
extern int confd_pp_value(char *buf, int bufsiz, const confd_value_t *v);
^~~~~~
movie2.c:77:27: warning: passing argument 2 of ‘confd_pp_value’ makes integer from pointer without a cast [-Wint-conversion]
confd_pp_value(&id,&mc.keys[0]); // key of the table
^
In file included from movie2.c:2:0:
…/include/confd_lib.h:1075:12: note: expected ‘int’ but argument is of type ‘confd_value_t * {aka struct confd_value *}’
extern int confd_pp_value(char *buf, int bufsiz, const confd_value_t *v);
^~~~~~
movie2.c:77:8: error: too few arguments to function ‘confd_pp_value’
confd_pp_value(&id,&mc.keys[0]); // key of the table
^~~~~~
In file included from movie2.c:2:0:
…/include/confd_lib.h:1075:12: note: declared here
extern int confd_pp_value(char *buf, int bufsiz, const confd_value_t *v);
^~~~~~
movie2.c:79:52: warning: passing argument 4 of ‘maapi_get_str_elem’ makes integer from pointer without a cast [-Wint-conversion]
maapi_get_str_elem(sock, th, f_name, “/movie/actors/actor{%x}/ first_name”, &mc.keys[0]);
^~~~~~~~~~~~~~~
In file included from movie2.c:3:0:
…/include/confd_maapi.h:463:12: note: expected ‘int’ but argument is of type ‘char *’
extern int maapi_get_str_elem(int sock, int thandle, char *buf, int n,
^~~~~~~~
movie2.c:79:93: warning: passing argument 5 of ‘maapi_get_str_elem’ from incompatible pointer type [-Wincompatible-pointer-types]
tr_elem(sock, th, f_name, “/movie/actors/actor{%x}/ first_name”, &mc.keys[0]);
^
In file included from movie2.c:3:0:
…/include/confd_maapi.h:463:12: note: expected ‘const char *’ but argument is of type ‘confd_value_t * {aka struct confd_value *}’
extern int maapi_get_str_elem(int sock, int thandle, char *buf, int n,
^~~~~~~~
movie2.c:80:45: warning: passing argument 4 of ‘maapi_get_str_elem’ makes integer from pointer without a cast [-Wint-conversion]
maapi_get_str_elem(sock, th, l_name, “/movie/actors/actor{%x}/ last_name”, &mc.keys[0]);
^~~~~~~~~~~~~~
In file included from movie2.c:3:0:
…/include/confd_maapi.h:463:12: note: expected ‘int’ but argument is of type ‘char *’
extern int maapi_get_str_elem(int sock, int thandle, char *buf, int n,
^~~~~~~~
movie2.c:80:85: warning: passing argument 5 of ‘maapi_get_str_elem’ from incompatible pointer type [-Wincompatible-pointer-types]
str_elem(sock, th, l_name, “/movie/actors/actor{%x}/ last_name”, &mc.keys[0]);
^
In file included from movie2.c:3:0:
…/include/confd_maapi.h:463:12: note: expected ‘const char *’ but argument is of type ‘confd_value_t * {aka struct confd_value *}’
extern int maapi_get_str_elem(int sock, int thandle, char *buf, int n,
^~~~~~~~
movie2.c:81:44: warning: passing argument 4 of ‘maapi_get_str_elem’ makes integer from pointer without a cast [-Wint-conversion]
maapi_get_str_elem(sock, th, l_upd, “/movie/actors/actor{%x}/ last_update”, &mc.keys[0]);
^~~~~~~~~~~~~~
In file included from movie2.c:3:0:
…/include/confd_maapi.h:463:12: note: expected ‘int’ but argument is of type ‘char *’
extern int maapi_get_str_elem(int sock, int thandle, char *buf, int n,
^~~~~~~~
movie2.c:81:86: warning: passing argument 5 of ‘maapi_get_str_elem’ from incompatible pointer type [-Wincompatible-pointer-types]
tr_elem(sock, th, l_upd, “/movie/actors/actor{%x}/ last_update”, &mc.keys[0]);
^
In file included from movie2.c:3:0:
…/include/confd_maapi.h:463:12: note: expected ‘const char *’ but argument is of type ‘confd_value_t * {aka struct confd_value *}’
extern int maapi_get_str_elem(int sock, int thandle, char *buf, int n,
^~~~~~~~
movie2.c: In function ‘main’:
movie2.c:96:17: warning: implicit declaration of function ‘getopt’; did you mean ‘getw’? [-Wimplicit-function-declaration]
while ((c = getopt(argc, argv, “rc”)) != -1) {
^~~~
getw
At top level:
movie2.c:9:20: warning: ‘groups’ defined but not used [-Wunused-variable]
static const char *groups[] = {“rahini”};
^~~~
…/src/confd/build/include.mk:121: recipe for target ‘movie2.o’ failed
make: * [movie2.o] Error 1

How to resolve this sir? Could you please help us to make it out?
Following are attachments of c, yang, xml files:

C file:
image
image
image


image

yang file:
image
image
XML file:
image

These are basic C errors. You have so many basic errors such as missing variable declarations, or improper data types (The compiler output is very clear). This is not a C language forum. The focus is mainly on the API use and for those errors related to the ConfD APIs, I suggest you read the ConfD user guide and the man pages for specific APIs such as maapi. Research maapi_get_str_elem in the ConfD user guide. Do the same thing for every API you use until you understand how it should be used.

I also highly recommend you get the ConfD kickstart guide and listen to training videos on tail-f.com.

sorry sir and thank you for suggesting other way to reach out the error


After corrected some basic errors in the C file, an another error is generated.
The error is attached above. Can anyone help us by saying what this error actually is and how we can resolve it? thanks in advance!

Do you correctly call maapi_start_user_session (see maapi example, fucntion uopdate_start_log).

I think maapi_start_user_session is correctly called.
here is a portion of code that has maapi_start_user_session part:

if (maapi_authenticate(sock, user, pass, groupsa, 10) == 1) {
    int i = 0;
    while (groups[i])
      i++;
    maapi_start_user_session(sock, user, context, groups, i,
                             &ip, CONFD_PROTO_TCP);
    }

how could we resolve the “No user session” error?

Can you check the return value of maapi_start_user_session()? Does it fail? What does it say?
Double check the arguments values.

Also, just in case you didn’t see this in the user guide, it is not possible to create new user sessions until ConfD has reached start phase 2 unless the context is set to “system”.

Please check devel.log if maapi_start_user_session can be seen there and what is the result.