rpm  5.4.15
rpmasn.c
Go to the documentation of this file.
1 
5 #include "system.h"
6 
7 #if defined(HAVE_LIBTASN1_H)
8 #include <libtasn1.h>
9 #endif
10 
11 #include <rpmiotypes.h>
12 #include <rpmio.h> /* for *Pool methods */
13 #include <rpmlog.h>
14 #include <rpmurl.h>
15 #define _RPMASN_INTERNAL
16 #include <rpmasn.h>
17 
18 #include "debug.h"
19 
20 /*@unchecked@*/
21 int _rpmasn_debug = 0;
22 
23 /*@-mustmod@*/ /* XXX splint on crack */
24 static void rpmasnFini(void * _asn)
25  /*@globals fileSystem @*/
26  /*@modifies *_asn, fileSystem @*/
27 {
28  rpmasn asn = (rpmasn) _asn;
29 
30 #if defined(WITH_LIBTASN1)
31  asn1_delete_structure(&asn->tree);
32  asn->tree = ASN1_TYPE_EMPTY;
33 #endif
34 
35  asn->fn = _free(asn->fn);
36 }
37 /*@=mustmod@*/
38 
39 /*@unchecked@*/ /*@only@*/ /*@null@*/
41 
42 static rpmasn rpmasnGetPool(/*@null@*/ rpmioPool pool)
43  /*@globals _rpmasnPool, fileSystem @*/
44  /*@modifies pool, _rpmasnPool, fileSystem @*/
45 {
46  rpmasn asn;
47 
48  if (_rpmasnPool == NULL) {
49  _rpmasnPool = rpmioNewPool("asn", sizeof(*asn), -1, _rpmasn_debug,
50  NULL, NULL, rpmasnFini);
51  pool = _rpmasnPool;
52  }
53  return (rpmasn) rpmioGetPool(pool, sizeof(*asn));
54 }
55 
56 rpmasn rpmasnNew(const char * fn, int flags)
57 {
58  rpmasn asn = rpmasnGetPool(_rpmasnPool);
59 
60  if (fn)
61  asn->fn = xstrdup(fn);
62 
63 #if defined(WITH_LIBTASN1)
64  asn->tree = ASN1_TYPE_EMPTY;
65  int xx = asn1_parser2tree(fn, &asn->tree, asn->error);
66  (void)xx;
67  /* XXX errors. */
68 #endif
69 
70  return rpmasnLink(asn);
71 }
72 
73 #ifdef NOTYET
74 const char * rpmasnFile(rpmasn asn, const char *fn)
75 {
76  const char * t = NULL;
77 
78 if (_rpmasn_debug)
79 fprintf(stderr, "--> rpmasnFile(%p, %s)\n", asn, (fn ? fn : "(nil)"));
80 
81 #if defined(WITH_LIBTASN1)
82 #endif
83 
84  if (t == NULL) t = "";
85  t = xstrdup(t);
86 
87 if (_rpmasn_debug)
88 fprintf(stderr, "<-- rpmasnFile(%p, %s) %s\n", asn, (fn ? fn : "(nil)"), t);
89  return t;
90 }
91 
92 const char * rpmasnBuffer(rpmasn asn, const char * b, size_t nb)
93 {
94  const char * t = NULL;
95 
96 if (_rpmasn_debug)
97 fprintf(stderr, "--> rpmasnBuffer(%p, %p[%d])\n", asn, b, (int)nb);
98  if (nb == 0) nb = strlen(b);
99 
100 #if defined(WITH_LIBTASN1)
101 #endif
102 
103  if (t == NULL) t = "";
104  t = xstrdup(t);
105 
106 if (_rpmasn_debug)
107 fprintf(stderr, "<-- rpmasnBuffer(%p, %p[%d]) %s\n", asn, b, (int)nb, t);
108  return t;
109 }
110 #endif /* NOTYET */
const bson * b
Definition: bson.h:280
int _rpmasn_debug
Definition: rpmasn.c:21
char * xstrdup(const char *str)
Definition: rpmmalloc.c:321
rpmioPool _rpmasnPool
Definition: rpmasn.c:40
Yet Another syslog(3) API clone.
static void rpmasnFini(void *_asn)
Definition: rpmasn.c:24
rpmioItem rpmioGetPool(rpmioPool pool, size_t size)
Get unused item from pool, or alloc a new item.
Definition: rpmmalloc.c:220
const char const bson int mongo_write_concern int flags
Definition: mongo.h:485
rpmioPool rpmioNewPool(const char *name, size_t size, int limit, int flags, char *(*dbg)(void *item), void(*init)(void *item), void(*fini)(void *item))
Create a memory pool.
Definition: rpmmalloc.c:109
static void * _free(const void *p)
Wrapper to free(3), hides const compilation noise, permit NULL, return NULL.
Definition: rpmiotypes.h:756
rpmasn rpmasnNew(const char *fn, int flags)
Create and load a ASN.1 wrapper.
Definition: rpmasn.c:56
static rpmasn rpmasnGetPool(rpmioPool pool)
Definition: rpmasn.c:42
struct rpmasn_s * rpmasn
Definition: rpmasn.h:15
rpmasn rpmasnLink(rpmasn asn)
Reference a ASN.1 wrapper instance.