add packaging
[platform/upstream/libnl1.git] / src / nl-list-caches.c
1 /*
2  * nl-list-caches.c     List registered cache types
3  *
4  *      This library is free software; you can redistribute it and/or
5  *      modify it under the terms of the GNU Lesser General Public
6  *      License as published by the Free Software Foundation version 2.1
7  *      of the License.
8  *
9  * Copyright (c) 2003-2006 Thomas Graf <tgraf@suug.ch>
10  */
11
12 #include "utils.h"
13
14 static void print_usage(void)
15 {
16         fprintf(stderr, "Usage: nl-list-caches\n");
17         exit(1);
18 }
19
20 static char *id_attr_list(struct nl_object_ops *ops, char *buf, size_t len)
21 {
22         if (ops->oo_attrs2str != NULL)
23                 return ops->oo_attrs2str(ops->oo_id_attrs, buf, len);
24         else {
25                 memset(buf, 0, len);
26                 return buf;
27         }
28 }
29
30 static void print(struct nl_cache_ops *ops, void *arg)
31 {
32         char buf[64];
33
34         printf("%s:\n" \
35                "    hdrsize: %d bytes\n" \
36                "    protocol: %s\n" \
37                "    request-update: %s\n" \
38                "    msg-parser: %s\n",
39                ops->co_name, ops->co_hdrsize,
40                nl_nlfamily2str(ops->co_protocol, buf, sizeof(buf)),
41                ops->co_request_update ? "yes" : "no",
42                ops->co_msg_parser ? "yes" : "no");
43
44         if (ops->co_obj_ops) {
45                 struct nl_object_ops *obj_ops = ops->co_obj_ops;
46                 const char *dump_names[NL_DUMP_MAX+1] = {
47                         "brief",
48                         "detailed",
49                         "stats",
50                         "xml",
51                         "env",
52                         "events"
53                 };
54                 int i;
55
56                 printf("    cacheable object:\n" \
57                        "        name: %s:\n" \
58                        "        size: %zu bytes\n" \
59                        "        constructor: %s\n" \
60                        "        free-data: %s\n" \
61                        "        clone: %s\n" \
62                        "        compare: %s\n" \
63                        "        id attributes: %s\n" \
64                        "        dump: ",
65                        obj_ops->oo_name, obj_ops->oo_size,
66                        obj_ops->oo_constructor ? "yes" : "no",
67                        obj_ops->oo_free_data ? "yes" : "no",
68                        obj_ops->oo_clone ? "yes" : "no",
69                        obj_ops->oo_compare ? "yes" : "no",
70                        id_attr_list(obj_ops, buf, sizeof(buf)));
71
72                 for (i = 0; i <= NL_DUMP_MAX; i++)
73                         if (obj_ops->oo_dump[i])
74                                 printf("%s%s",
75                                 i == 0 ? "" : ", ",
76                                 dump_names[i]);
77
78                 printf("\n");
79         }
80
81         if (ops->co_genl) {
82                 struct genl_ops *genl_ops = ops->co_genl;
83
84                 printf("    genl:\n" \
85                        "        name: %s\n" \
86                        "        family: %d\n" \
87                        "        id: %d\n",
88                        genl_ops->o_name, genl_ops->o_family, genl_ops->o_id);
89
90                 if (genl_ops->o_ncmds) {
91                         int i;
92
93                         printf("        cmds:\n");
94
95                         for (i = 0; i < genl_ops->o_ncmds; i++) {
96                                 struct genl_cmd *cmd = &genl_ops->o_cmds[i];
97
98                                 printf("            %s:\n"
99                                        "                id: %d\n" \
100                                        "                maxattr: %d\n" \
101                                        "                msg-parser: %s\n" \
102                                        "                attr-policy: %s\n",
103                                        cmd->c_name, cmd->c_id, cmd->c_maxattr,
104                                        cmd->c_msg_parser ? "yes" : "no",
105                                        cmd->c_attr_policy ? "yes" : "no");
106                         }
107                 }
108         }
109 }
110
111 int main(int argc, char *argv[])
112 {
113         if (argc > 1 && !strcasecmp(argv[1], "-h"))
114                 print_usage();
115
116         nl_cache_ops_foreach(print, NULL);
117
118         return 0;
119 }