Topic: how to use the uci C api

Hello All,

Where can I find some examples  of using  uci  in C or C++. 
For instance if I want to collect the different lan interface names, how can I do this in C ?

Re: how to use the uci C api

I suggest you to check into the Lua UCI bindings, as they provide full UCI functions to Lua, and that the "Lua side" of it is understandable in C without prior Lua knowledge (package uci, file "lua/uci.c").

Hope it helps!

2x TP-Link TL-MR3020, 2x TP-Link TL-WR703N, 1x TP-Link TL-MR11U, 1x Hame MPR-L8

3 (edited by written_direcon 2012-11-15 17:14:59)

Re: how to use the uci C api

Compiling UCI as stand alone with an example using the C API
1. Compiling UCI as stand alone

cd ~
git clone git://nbd.name/uci.git ~/uci
cd ~/uci
cmake -DBUILD_LUA=off .
make install DESTDIR=$HOME

2. Example code using the UCI C API
~/uci/main.c

#include <stdio.h>
#include <string.h>
#include <uci.h>
#include <stdlib.h>

int main (int argc, char **argv)
{
  struct uci_context *c;
  struct uci_ptr p;
  char *a = strdup ("wireless.@wifi-iface[0].ssid");

  c = uci_alloc_context ();
  if (uci_lookup_ptr (c, &p, a, true) != UCI_OK)
    {
      uci_perror (c, "XXX");
      return 1;
    }

  printf("%s\n", p.o->v.string);
  uci_free_context (c);
  free (a);
  return 0;
}

3. Compile the example

cc -I$HOME/usr/include -L$HOME/usr/lib main.c -luci -o uci-test

4. Run the compiled example binary

export LD_LIBRARY_PATH=$HOME/usr/lib
./uci-test
XXX: Entry not found