rpm  5.4.10
rpmlua.c
Go to the documentation of this file.
1 /*@-moduncon -mustmod -realcompare -sizeoftype @*/
2 #include "system.h"
3 
4 #ifdef WITH_LUA
5 #define _RPMIOB_INTERNAL
6 #include <rpmiotypes.h>
7 #include <rpmio.h>
8 #include <rpmmacro.h>
9 #include <rpmlog.h>
10 #include <rpmurl.h>
11 #include <rpmhook.h>
12 #include <rpmcb.h>
13 #include <argv.h>
14 #include <popt.h> /* XXX poptSaneFile test */
15 
16 #ifdef __cplusplus
17 extern "C" {
18 #endif
19 
20 #include <lauxlib.h>
21 #include <lualib.h>
22 
23 #ifdef WITH_SYCK
24 LUALIB_API int luaopen_syck(lua_State *L)
25  /*@modifies L @*/;
26 #endif /* WITH_SYCK */
27 #ifdef WITH_LUA_INTERNAL
28 #include <llocal.h>
29 #include <lposix.h>
30 #include <lrexlib.h>
31 #include <luuid.h>
32 #include <lwrs.h>
33 #ifdef USE_LUA_CRYPTO /* XXX external lua modules instead. */
34 #include <lcrypto.h>
35 #include <lxplib.h>
36 #endif
37 #ifdef USE_LUA_SOCKET /* XXX external lua modules instead. */
38 #include <luasocket.h>
39 #endif
40 #endif
41 
42 #ifdef __cplusplus
43 }
44 #endif
45 
46 #define _RPMLUA_INTERNAL
47 #include "rpmlua.h"
48 
49 #include "debug.h"
50 
51 /*@access rpmiob @*/
52 
53 #else /* WITH_LUA */
54 #include <rpmio.h>
55 #endif
56 
57 /*@unchecked@*/
58 int _rpmlua_debug = 0;
59 
60 /*@unchecked@*/ /*@only@*/ /*@null@*/
62 
63 /*@unchecked@*/ /*@only@*/ /*@null@*/
65 
66 #ifdef WITH_LUA
67 
68 /* XXX lua-5.2.0 retrofit destruction area. */
69 #if LUA_VERSION_NUM > 501
70 #define luaL_reg luaL_Reg
71 #define lua_strlen lua_rawlen
72 #define luaL_getn luaL_len
73 static int luaL_typerror(lua_State *L, int narg, const char *tname)
74 {
75  const char *msg = lua_pushfstring(L, "%s expected, got %s",
76  tname, luaL_typename(L, narg));
77  return luaL_argerror(L, narg, msg);
78 }
79 LUALIB_API void luaL_openlib (lua_State *L, const char *libname,
80  const luaL_Reg *l, int nup);
81 #define luaopen_posix luaopen_posix_c
82 
83 #define lua_open() luaL_newstate()
84 #endif
85 
86 #if !defined(HAVE_VSNPRINTF)
87 static inline int vsnprintf(char * buf, /*@unused@*/ size_t nb,
88  const char * fmt, va_list ap)
89 {
90  return vsprintf(buf, fmt, ap);
91 }
92 #endif
93 
94 #define INITSTATE(_lua, lua) \
95  rpmlua lua = _lua ? _lua : \
96  (globalLuaState ? globalLuaState : \
97  /*@-mods@*/ \
98  (globalLuaState = rpmluaNew()) \
99  /*@=mods@*/ \
100  )
101 
102 /*@only@*/ /*@unchecked@*/ /*@relnull@*/
103 static rpmlua globalLuaState;
104 
105 static int luaopen_rpm(lua_State *L)
106  /*@modifies L @*/;
107 static int rpm_print(lua_State *L)
108  /*@globals fileSystem @*/
109  /*@modifies L, fileSystem @*/;
110 
111 /*@unchecked@*/ /*@observer@*/
112 const char * rpmluaFiles = RPMLUAFILES;
113 
114 /*@unchecked@*/ /*@observer@*/
115 const char * rpmluaPath = "%{?_rpmhome}%{!?_rpmhome:" USRLIBRPM "}/lua/?.lua";
116 
118 {
119 /*@-globstate@*/
120  return globalLuaState;
121 /*@=globstate@*/
122 }
123 
124 static void rpmluaFini(void * _lua)
125  /*@globals globalLuaState @*/
126  /*@modifies globalLuaState @*/
127 {
128  rpmlua lua = (rpmlua) _lua;
129 
130  if (lua->L) lua_close(lua->L);
131  lua->L = NULL;
132  lua->printbuf = _free(lua->printbuf);
133 }
134 
135 static rpmlua rpmluaGetPool(/*@null@*/ rpmioPool pool)
136  /*@globals _rpmluaPool, fileSystem @*/
137  /*@modifies pool, _rpmluaPool, fileSystem @*/
138 {
139  rpmlua lua;
140 
141  if (_rpmluaPool == NULL) {
142  _rpmluaPool = rpmioNewPool("lua", sizeof(*lua), -1, _rpmlua_debug,
143  NULL, NULL, rpmluaFini);
144  pool = _rpmluaPool;
145  }
146  return (rpmlua) rpmioGetPool(pool, sizeof(*lua));
147 }
148 
149 void *rpmluaFree(rpmlua lua)
150 {
151  if (lua == NULL) lua = globalLuaState;
152  (void)rpmioFreePoolItem((rpmioItem)lua, __FUNCTION__, __FILE__, __LINE__);
153  if (lua == globalLuaState) globalLuaState = NULL;
154  return NULL;
155 }
156 
157 /*@-globs -mods@*/ /* XXX hide rpmGlobalMacroContext mods for now. */
158 rpmlua rpmluaNew(void)
159 {
160  rpmlua lua = rpmluaGetPool(_rpmluaPool);
161  lua_State *L = lua_open();
162  /*@-readonlytrans -nullassign @*/
163  /*@observer@*/ /*@unchecked@*/
164  static const luaL_reg lualibs[] = {
165  /* standard LUA libraries */
166  {"", luaopen_base},
167 /* XXX 5.1.4 internal has not */
168 #if defined(LUA_COLIBNAME) && LUA_VERSION_NUM > 501
169  {LUA_COLIBNAME, luaopen_coroutine},
170 #endif
171 #if defined(LUA_TABLIBNAME)
172  {LUA_TABLIBNAME, luaopen_table},
173 #endif
174 #if defined(LUA_IOLIBNAME)
175  {LUA_IOLIBNAME, luaopen_io},
176 #endif
177 #if defined(LUA_OSLIBNAME)
178  {LUA_OSLIBNAME, luaopen_os},
179 #endif
180 #if defined(LUA_STRLIBNAME)
181  {LUA_STRLIBNAME, luaopen_string},
182 #endif
183 #if defined(LUA_BITLIBNAME) /* XXX lua >= 5.2.0 only */
184  {LUA_BITLIBNAME, luaopen_bit32},
185 #endif
186 #if defined(LUA_MATHLIBNAME)
187  {LUA_MATHLIBNAME, luaopen_math},
188 #endif
189 #if defined(LUA_DBLIBNAME)
190  {LUA_DBLIBNAME, luaopen_debug},
191 #endif
192 #if defined(LUA_LOADLIBNAME)
193  {LUA_LOADLIBNAME, luaopen_package},
194 #endif
195 #ifdef WITH_SYCK
196  {"lsyck", luaopen_syck},
197 #endif /* WITH_SYCK */
198  /* local LUA libraries (RPM only) */
199 #ifdef WITH_LUA_INTERNAL
200  {"posix", luaopen_posix},
201  {"rex_posix", luaopen_rex_posix},
202  {"rex_pcre", luaopen_rex_pcre},
203  {"uuid", luaopen_uuid},
204  {"wrs", luaopen_wrs},
205 #ifdef USE_LUA_CRYPTO /* XXX external lua modules instead. */
206  {"crypto", luaopen_crypto},
207  {"lxp", luaopen_lxp},
208 #endif
209 #ifdef USE_LUA_SOCKET /* XXX external lua modules instead. */
210  {"socket", luaopen_socket_core},
211 #endif
212  {"local", luaopen_local},
213 #endif
214  {"rpm", luaopen_rpm},
215  {NULL, NULL},
216  };
217  /*@=readonlytrans =nullassign @*/
218  /*@observer@*/ /*@unchecked@*/
219  const luaL_reg *lib = lualibs;
220  char *path_buf;
221  char *path_next;
222  char *path;
223 
224  lua->L = L;
225  lua->pushsize = 0;
226  lua->storeprint = 0;
227  /* XXX TODO: use an rpmiob here. */
228  lua->printbufsize = 0;
229  lua->printbufused = 0;
230  lua->printbuf = NULL;
231 
232  for (; lib->name; lib++) {
233 /*@-noeffectuncon@*/
234  lua_pushcfunction(L, lib->func);
235  lua_pushstring(L, lib->name);
236  lua_call(L, 1, 0);
237 /*@=noeffectuncon@*/
238  }
239  { const char * _lua_path = rpmGetPath(rpmluaPath, NULL);
240  if (_lua_path != NULL) {
241  lua_pushliteral(L, "LUA_PATH");
242  lua_pushstring(L, _lua_path);
243  _lua_path = _free(_lua_path);
244  }
245  }
246 #if defined(LUA_GLOBALSINDEX)
247  lua_rawset(L, LUA_GLOBALSINDEX);
248 #else
249  lua_pushglobaltable(L);
250 #endif
251  lua_pushliteral(L, "print");
252  lua_pushcfunction(L, rpm_print);
253 #if defined(LUA_GLOBALSINDEX)
254  lua_rawset(L, LUA_GLOBALSINDEX);
255 #else
256  lua_pushglobaltable(L);
257 #endif
258  rpmluaSetData(lua, "lua", lua);
259 
260  /* load all standard RPM Lua script files */
261  path_buf = xstrdup(rpmluaFiles);
262  for (path = path_buf; path != NULL && *path != '\0'; path = path_next) {
263  const char **av;
264  struct stat st;
265  int ac, i;
266 
267  /* locate start of next path element */
268  path_next = strchr(path, ':');
269  if (path_next != NULL && *path_next == ':')
270  *path_next++ = '\0';
271  else
272  path_next = path + strlen(path);
273 
274  /* glob-expand the path element */
275  ac = 0;
276  av = NULL;
277  if ((i = rpmGlob(path, &ac, &av)) != 0)
278  continue;
279 
280  /* work-off each resulting file from the path element */
281  for (i = 0; i < ac; i++) {
282  const char *fn = av[i];
283  if (fn[0] == '@' /* attention */) {
284  fn++;
285 #if defined(RPM_VENDOR_OPENPKG) /* stick-with-rpm-file-sanity-checking */ || \
286  !defined(POPT_ERROR_BADCONFIG) /* XXX POPT 1.15 retrofit */
287  if (!rpmSecuritySaneFile(fn))
288 #else
289  if (!poptSaneFile(fn))
290 #endif
291  {
292  rpmlog(RPMLOG_WARNING, "existing RPM Lua script file \"%s\" considered INSECURE -- not loaded\n", fn);
293  /*@innercontinue@*/ continue;
294  }
295  }
296  if (Stat(fn, &st) != -1)
297  (void)rpmluaRunScriptFile(lua, fn);
298  av[i] = _free(av[i]);
299  }
300  av = _free(av);
301  }
302  path_buf = _free(path_buf);
303 
304  return ((rpmlua)rpmioLinkPoolItem((rpmioItem)lua, __FUNCTION__, __FILE__, __LINE__));
305 }
306 /*@=globs =mods@*/
307 
308 void rpmluaSetData(rpmlua _lua, const char *key, const void *data)
309 {
310  INITSTATE(_lua, lua);
311  lua_State *L = lua->L;
312  lua_pushliteral(L, "rpm_");
313  lua_pushstring(L, key);
314  lua_concat(L, 2);
315  if (data == NULL)
316  lua_pushnil(L);
317  else
318  lua_pushlightuserdata(L, (void *)data);
319  lua_rawset(L, LUA_REGISTRYINDEX);
320 }
321 
322 /*@null@*/
323 static void *getdata(lua_State *L, const char *key)
324  /*@modifies L @*/
325 {
326  void *ret = NULL;
327  lua_pushliteral(L, "rpm_");
328  lua_pushstring(L, key);
329  lua_concat(L, 2);
330  lua_rawget(L, LUA_REGISTRYINDEX);
331  if (lua_islightuserdata(L, -1))
332  ret = lua_touserdata(L, -1);
333  lua_pop(L, 1);
334  return ret;
335 }
336 
337 void *rpmluaGetData(rpmlua _lua, const char *key)
338 {
339  INITSTATE(_lua, lua);
340  return getdata(lua->L, key);
341 }
342 
343 void rpmluaSetPrintBuffer(rpmlua _lua, int flag)
344 {
345  INITSTATE(_lua, lua);
346  lua->storeprint = flag;
347  lua->printbuf = _free(lua->printbuf);
348  lua->printbufsize = 0;
349  lua->printbufused = 0;
350 }
351 
352 const char *rpmluaGetPrintBuffer(rpmlua _lua)
353 {
354  INITSTATE(_lua, lua);
355  return lua->printbuf;
356 }
357 
358 static int pushvar(lua_State *L, rpmluavType type, void *value)
359  /*@modifies L @*/
360 {
361  int ret = 0;
362  switch (type) {
363  case RPMLUAV_NIL:
364  lua_pushnil(L);
365  break;
366  case RPMLUAV_STRING:
367  lua_pushstring(L, *((char **)value));
368  break;
369  case RPMLUAV_NUMBER:
370  lua_pushnumber(L, *((double *)value));
371  break;
372  default:
373  ret = -1;
374  break;
375  }
376  return ret;
377 }
378 
379 void rpmluaSetVar(rpmlua _lua, rpmluav var)
380 {
381  INITSTATE(_lua, lua);
382  lua_State *L = lua->L;
383  if (var->listmode && lua->pushsize > 0) {
384  if (var->keyType != RPMLUAV_NUMBER || var->key.num == (double)0) {
385  var->keyType = RPMLUAV_NUMBER;
386  var->key.num = (double) luaL_getn(L, -1);
387  }
388  var->key.num++;
389  }
390  if (!var->listmode || lua->pushsize > 0) {
391 #if defined(LUA_GLOBALSINDEX)
392  if (lua->pushsize == 0)
393  lua_pushvalue(L, LUA_GLOBALSINDEX);
394 #endif
395  if (pushvar(L, var->keyType, &var->key) != -1) {
396  if (pushvar(L, var->valueType, &var->value) != -1)
397  lua_rawset(L, -3);
398  else
399  lua_pop(L, 1);
400  }
401  if (lua->pushsize == 0)
402  lua_pop(L, 1);
403  }
404 }
405 
406 static void popvar(lua_State *L, rpmluavType *type, void *value)
407  /*@modifies L, *type, *value @*/
408 {
409  switch (lua_type(L, -1)) {
410  case LUA_TSTRING:
411  *type = RPMLUAV_STRING;
412 /*@-observertrans -dependenttrans @*/
413  *((const char **)value) = lua_tostring(L, -1);
414 /*@=observertrans =dependenttrans @*/
415  break;
416  case LUA_TNUMBER:
417  *type = RPMLUAV_NUMBER;
418  *((double *)value) = lua_tonumber(L, -1);
419  break;
420  default:
421  *type = RPMLUAV_NIL;
422  *((void **)value) = NULL;
423  break;
424  }
425  lua_pop(L, 1);
426 }
427 
428 void rpmluaGetVar(rpmlua _lua, rpmluav var)
429 {
430  INITSTATE(_lua, lua);
431  lua_State *L = lua->L;
432  if (!var->listmode) {
433 #if defined(LUA_GLOBALSINDEX)
434  if (lua->pushsize == 0)
435  lua_pushvalue(L, LUA_GLOBALSINDEX);
436 #else
437  if (lua->pushsize == 0)
438  lua_pushglobaltable(L);
439 #endif
440  if (pushvar(L, var->keyType, &var->key) != -1) {
441  lua_rawget(L, -2);
442  popvar(L, &var->valueType, &var->value);
443  }
444  if (lua->pushsize == 0)
445  lua_pop(L, 1);
446  } else if (lua->pushsize > 0) {
447  (void) pushvar(L, var->keyType, &var->key);
448  if (lua_next(L, -2) != 0)
449  popvar(L, &var->valueType, &var->value);
450  }
451 }
452 
453 #define FINDKEY_RETURN 0
454 #define FINDKEY_CREATE 1
455 #define FINDKEY_REMOVE 2
456 static int findkey(lua_State *L, int oper, const char *key, va_list va)
457  /*@modifies L @*/
458 {
459  char buf[BUFSIZ];
460  const char *s, *e;
461  int ret = 0;
462  (void) vsnprintf(buf, sizeof(buf), key, va);
463  s = e = buf;
464 #if defined(LUA_GLOBALSINDEX)
465  lua_pushvalue(L, LUA_GLOBALSINDEX);
466 #else
467  lua_pushglobaltable(L);
468 #endif
469  for (;;) {
470  if (*e == '\0' || *e == '.') {
471  if (e != s) {
472  lua_pushlstring(L, s, e-s);
473  switch (oper) {
474  case FINDKEY_REMOVE:
475  if (*e == '\0') {
476  lua_pushnil(L);
477  lua_rawset(L, -3);
478  lua_pop(L, 1);
479  /*@switchbreak@*/ break;
480  }
481  /*@fallthrough@*/
482  case FINDKEY_RETURN:
483  lua_rawget(L, -2);
484  lua_remove(L, -2);
485  /*@switchbreak@*/ break;
486  case FINDKEY_CREATE:
487  lua_rawget(L, -2);
488  if (!lua_istable(L, -1)) {
489  lua_pop(L, 1);
490  lua_newtable(L);
491  lua_pushlstring(L, s, e-s);
492  lua_pushvalue(L, -2);
493  lua_rawset(L, -4);
494  }
495  lua_remove(L, -2);
496  /*@switchbreak@*/ break;
497  }
498  }
499  if (*e == '\0')
500  break;
501  if (!lua_istable(L, -1)) {
502  lua_pop(L, 1);
503  ret = -1;
504  break;
505  }
506  s = e+1;
507  }
508  e++;
509  }
510 
511  return ret;
512 }
513 
514 void rpmluaDelVar(rpmlua _lua, const char *key, ...)
515 {
516  INITSTATE(_lua, lua);
517  va_list va;
518  va_start(va, key);
519  (void) findkey(lua->L, FINDKEY_REMOVE, key, va);
520  va_end(va);
521 }
522 
523 int rpmluaVarExists(rpmlua _lua, const char *key, ...)
524 {
525  INITSTATE(_lua, lua);
526  lua_State *L = lua->L;
527  int ret = 0;
528  va_list va;
529  va_start(va, key);
530  if (findkey(L, FINDKEY_RETURN, key, va) == 0) {
531  if (!lua_isnil(L, -1))
532  ret = 1;
533  lua_pop(L, 1);
534  }
535  va_end(va);
536  return ret;
537 }
538 
539 void rpmluaPushTable(rpmlua _lua, const char *key, ...)
540 {
541  INITSTATE(_lua, lua);
542  va_list va;
543  va_start(va, key);
544  (void) findkey(lua->L, FINDKEY_CREATE, key, va);
545  lua->pushsize++;
546  va_end(va);
547 }
548 
549 void rpmluaPop(rpmlua _lua)
550 {
551  INITSTATE(_lua, lua);
552  assert(lua->pushsize > 0);
553  lua->pushsize--;
554  lua_pop(lua->L, 1);
555 }
556 
557 void *rpmluavFree(rpmluav var)
558 {
559  (void)rpmioFreePoolItem((rpmioItem)var, __FUNCTION__, __FILE__, __LINE__);
560  return NULL;
561 }
562 
563 static rpmluav rpmluavGetPool(/*@null@*/ rpmioPool pool)
564  /*@globals _rpmluavPool, fileSystem @*/
565  /*@modifies pool, _rpmluavPool, fileSystem @*/
566 {
567  rpmluav luav;
568 
569  if (_rpmluavPool == NULL) {
570  _rpmluavPool = rpmioNewPool("luav", sizeof(*luav), -1, _rpmlua_debug,
571  NULL, NULL, NULL);
572  pool = _rpmluavPool;
573  }
574  return (rpmluav) rpmioGetPool(pool, sizeof(*luav));
575 }
576 
577 rpmluav rpmluavNew(void)
578 {
579  rpmluav var = rpmluavGetPool(_rpmluavPool);
580  var->keyType = RPMLUAV_NIL;
581  var->valueType = RPMLUAV_NIL;
582  var->key.ptr = NULL;
583  var->value.ptr = NULL;
584  var->listmode = 0;
585  return ((rpmluav)rpmioLinkPoolItem((rpmioItem)var, __FUNCTION__, __FILE__, __LINE__));
586 }
587 
588 void rpmluavSetListMode(rpmluav var, int flag)
589 {
590  var->listmode = flag;
591  var->keyType = RPMLUAV_NIL;
592 }
593 
594 void rpmluavSetKey(rpmluav var, rpmluavType type, const void *value)
595 {
596  var->keyType = type;
597 /*@-assignexpose -temptrans @*/
598  switch (type) {
599  case RPMLUAV_NUMBER:
600  var->key.num = *((double *)value);
601  break;
602  case RPMLUAV_STRING:
603  var->key.str = (char *)value;
604  break;
605  default:
606  break;
607  }
608 /*@=assignexpose =temptrans @*/
609 }
610 
611 void rpmluavSetValue(rpmluav var, rpmluavType type, const void *value)
612 {
613  var->valueType = type;
614 /*@-assignexpose -temptrans @*/
615  switch (type) {
616  case RPMLUAV_NUMBER:
617  var->value.num = *((const double *)value);
618  break;
619  case RPMLUAV_STRING:
620  var->value.str = (const char *)value;
621  break;
622  default:
623  break;
624  }
625 /*@=assignexpose =temptrans @*/
626 }
627 
628 void rpmluavGetKey(rpmluav var, rpmluavType *type, void **value)
629 {
630  *type = var->keyType;
631 /*@-onlytrans@*/
632  switch (var->keyType) {
633  case RPMLUAV_NUMBER:
634  *((double **)value) = &var->key.num;
635  break;
636  case RPMLUAV_STRING:
637  *((const char **)value) = var->key.str;
638  break;
639  default:
640  break;
641  }
642 /*@=onlytrans@*/
643 }
644 
645 void rpmluavGetValue(rpmluav var, rpmluavType *type, void **value)
646 {
647  *type = var->valueType;
648 /*@-onlytrans@*/
649  switch (var->valueType) {
650  case RPMLUAV_NUMBER:
651  *((double **)value) = &var->value.num;
652  break;
653  case RPMLUAV_STRING:
654  *((const char **)value) = var->value.str;
655  break;
656  default:
657  break;
658  }
659 /*@=onlytrans@*/
660 }
661 
662 void rpmluavSetKeyNum(rpmluav var, double value)
663 {
664  rpmluavSetKey(var, RPMLUAV_NUMBER, &value);
665 }
666 
667 void rpmluavSetValueNum(rpmluav var, double value)
668 {
669  rpmluavSetValue(var, RPMLUAV_NUMBER, &value);
670 }
671 
672 double rpmluavGetKeyNum(rpmluav var)
673 {
674  rpmluavType type;
675  void *value;
676  rpmluavGetKey(var, &type, &value);
677  if (type == RPMLUAV_NUMBER)
678  return *((double *)value);
679  return (double) 0;
680 }
681 
682 double rpmluavGetValueNum(rpmluav var)
683 {
684  rpmluavType type;
685  void *value;
686  rpmluavGetValue(var, &type, &value);
687  if (type == RPMLUAV_NUMBER)
688  return *((double *)value);
689  return (double) 0;
690 }
691 
692 int rpmluavKeyIsNum(rpmluav var)
693 {
694  return (var->keyType == RPMLUAV_NUMBER) ? 1 : 0;
695 }
696 
697 int rpmluavValueIsNum(rpmluav var)
698 {
699  return (var->valueType == RPMLUAV_NUMBER) ? 1 : 0;
700 }
701 
702 int rpmluaCheckScript(rpmlua _lua, const char *script, const char *name)
703 {
704  INITSTATE(_lua, lua);
705  lua_State *L = lua->L;
706  int ret = 0;
707  if (name == NULL)
708  name = "<lua>";
709  if (luaL_loadbuffer(L, script, strlen(script), name) != 0) {
711  _("invalid syntax in Lua scriptlet: %s\n"),
712  lua_tostring(L, -1));
713  ret = -1;
714  }
715  lua_pop(L, 1); /* Error or chunk. */
716  return ret;
717 }
718 
719 int rpmluaRunScript(rpmlua _lua, const char *script, const char *name)
720 {
721  INITSTATE(_lua, lua);
722  lua_State *L = lua->L;
723  int ret = 0;
724  if (name == NULL)
725  name = "<lua>";
726  if (luaL_loadbuffer(L, script, strlen(script), name) != 0) {
727  rpmlog(RPMLOG_ERR, _("invalid syntax in Lua script: %s\n"),
728  lua_tostring(L, -1));
729  lua_pop(L, 1);
730  ret = -1;
731  } else if (lua_pcall(L, 0, 0, 0) != 0) {
732  rpmlog(RPMLOG_ERR, _("Lua script failed: %s\n"),
733  lua_tostring(L, -1));
734  lua_pop(L, 1);
735  ret = -1;
736  }
737  return ret;
738 }
739 
740 int rpmluaRunScriptFile(rpmlua _lua, const char *filename)
741 {
742  INITSTATE(_lua, lua);
743  lua_State *L = lua->L;
744  int ret = 0;
745  if (luaL_loadfile(L, filename) != 0) {
746  rpmlog(RPMLOG_ERR, _("invalid syntax in Lua file: %s\n"),
747  lua_tostring(L, -1));
748  lua_pop(L, 1);
749  ret = -1;
750  } else if (lua_pcall(L, 0, 0, 0) != 0) {
751  rpmlog(RPMLOG_ERR, _("Lua script failed: %s\n"),
752  lua_tostring(L, -1));
753  lua_pop(L, 1);
754  ret = -1;
755  }
756  return ret;
757 }
758 
759 /* From lua.c */
760 static int rpmluaReadline(lua_State *L, const char *prompt)
761  /*@globals fileSystem @*/
762  /*@modifies L, fileSystem @*/
763 {
764  static char buffer[1024];
765  if (prompt) {
766  (void) fputs(prompt, stdout);
767  (void) fflush(stdout);
768  }
769  if (fgets(buffer, (int)sizeof(buffer), stdin) == NULL) {
770  return 0; /* read fails */
771  } else {
772  lua_pushstring(L, buffer);
773  return 1;
774  }
775 }
776 
777 /* Based on lua.c */
778 static void _rpmluaInteractive(lua_State *L)
779  /*@globals fileSystem @*/
780  /*@modifies L, fileSystem @*/
781 {
782  (void) fputs("\n", stdout);
783  printf("RPM Interactive %s Interpreter\n", LUA_VERSION);
784  for (;;) {
785  int rc = 0;
786 
787  if (rpmluaReadline(L, "> ") == 0)
788  break;
789  if (lua_tostring(L, -1)[0] == '=') {
790 /*@-evalorder@*/
791  (void) lua_pushfstring(L, "print(%s)", lua_tostring(L, -1)+1);
792 /*@=evalorder@*/
793  lua_remove(L, -2);
794  }
795  for (;;) {
796 /*@-evalorder@*/
797  rc = luaL_loadbuffer(L, lua_tostring(L, -1),
798  lua_strlen(L, -1), "<lua>");
799 /*@=evalorder@*/
800  if (rc == LUA_ERRSYNTAX &&
801  strstr(lua_tostring(L, -1), "near `<eof>'") != NULL) {
802  if (rpmluaReadline(L, ">> ") == 0)
803  /*@innerbreak@*/ break;
804  lua_remove(L, -2); /* Remove error */
805  lua_concat(L, 2);
806  /*@innercontinue@*/ continue;
807  }
808  /*@innerbreak@*/ break;
809  }
810  if (rc == 0)
811  rc = lua_pcall(L, 0, 0, 0);
812  if (rc != 0) {
813 /*@-evalorderuncon@*/
814  fprintf(stderr, "%s\n", lua_tostring(L, -1));
815 /*@=evalorderuncon@*/
816  lua_pop(L, 1);
817  }
818  lua_pop(L, 1); /* Remove line */
819  }
820  (void) fputs("\n", stdout);
821 }
822 
823 /*@-mods@*/
824 void rpmluaInteractive(rpmlua _lua)
825 {
826  INITSTATE(_lua, lua);
827  _rpmluaInteractive(lua->L);
828 }
829 /*@=mods@*/
830 
831 /* ------------------------------------------------------------------ */
832 /* Lua API */
833 
834 static int rpm_macros(lua_State *L)
835  /*@modifies L @*/
836 {
837  const char ** av = NULL;
838  int ac = 0;
839  int i;
840 
841 /*@-modunconnomods@*/
842  lua_newtable(L);
843 /*@=modunconnomods@*/
844 
845 /*@-globs@*/
846  ac = rpmGetMacroEntries(NULL, NULL, -1, &av);
847 /*@=globs@*/
848 
849  if (av != NULL)
850  for (i = 0; i < ac; i++) {
851  char *n, *o, *b;
852 
853  /* Parse out "%name(opts)\tbody" into n/o/b strings. */
854  n = (char *) av[i];
855  b = strchr(n, '\t');
856 assert(b != NULL);
857  o = ((b > n && b[-1] == ')') ? strchr(n, '(') : NULL);
858  if (*n == '%') n++;
859  if (o != NULL && *o == '(') {
860  b[-1] = '\0';
861  o++;
862  o[-1] = '\0';
863  }
864  else
865  b[0] = '\0';
866  b++;
867 
868 /*@-modunconnomods@*/
869  lua_pushstring(L, n);
870  lua_newtable(L);
871  if (o) {
872  lua_pushstring(L, "opts");
873  lua_pushstring(L, o);
874  lua_settable(L, -3);
875  }
876  if (b) {
877  lua_pushstring(L, "body");
878  lua_pushstring(L, b);
879  lua_settable(L, -3);
880  }
881  lua_settable(L, -3);
882 /*@=modunconnomods@*/
883  }
884  av = argvFree(av);
885  return 1;
886 }
887 
888 static int rpm_expand(lua_State *L)
889  /*@globals rpmGlobalMacroContext, h_errno, internalState @*/
890  /*@modifies L, rpmGlobalMacroContext, internalState @*/
891 {
892  const char *str = luaL_checkstring(L, 1);
893  lua_pushstring(L, rpmExpand(str, NULL));
894  return 1;
895 }
896 
897 static int rpm_define(lua_State *L)
898  /*@globals rpmGlobalMacroContext, h_errno, internalState @*/
899  /*@modifies L, rpmGlobalMacroContext, internalState @*/
900 {
901  const char *str = luaL_checkstring(L, 1);
902  (void) rpmDefineMacro(NULL, str, 0);
903  return 0;
904 }
905 
906 static int rpm_undefine(lua_State *L)
907  /*@globals rpmGlobalMacroContext, internalState @*/
908  /*@modifies L, rpmGlobalMacroContext, internalState @*/
909 {
910  const char *str = luaL_checkstring(L, 1);
911  (void) rpmUndefineMacro(NULL, str);
912  return 0;
913 }
914 
915 static int rpm_interactive(lua_State *L)
916  /*@globals fileSystem @*/
917  /*@modifies L, fileSystem @*/
918 {
919  _rpmluaInteractive(L);
920  return 0;
921 }
922 
923 typedef struct rpmluaHookData_s {
924 /*@shared@*/
925  lua_State *L;
926  int funcRef;
927  int dataRef;
928 } * rpmluaHookData;
929 
930 static int rpmluaHookWrapper(rpmhookArgs args, void *data)
931  /*@*/
932 {
933  rpmluaHookData hookdata = (rpmluaHookData)data;
934  lua_State *L = hookdata->L;
935  int ret = 0;
936  int i;
937  lua_rawgeti(L, LUA_REGISTRYINDEX, hookdata->funcRef);
938  lua_newtable(L);
939  for (i = 0; i != args->argc; i++) {
940  switch (args->argt[i]) {
941  case 's':
942  lua_pushstring(L, args->argv[i].s);
943  lua_rawseti(L, -2, i+1);
944  /*@switchbreak@*/ break;
945  case 'i':
946  lua_pushnumber(L, (lua_Number)args->argv[i].i);
947  lua_rawseti(L, -2, i+1);
948  /*@switchbreak@*/ break;
949  case 'f':
950  lua_pushnumber(L, (lua_Number)args->argv[i].f);
951  lua_rawseti(L, -2, i+1);
952  /*@switchbreak@*/ break;
953  case 'p':
954  lua_pushlightuserdata(L, args->argv[i].p);
955  lua_rawseti(L, -2, i+1);
956  /*@switchbreak@*/ break;
957  default:
958  (void) luaL_error(L, "unsupported type '%c' as "
959  "a hook argument\n", args->argt[i]);
960  /*@switchbreak@*/ break;
961  }
962  }
963  if (lua_pcall(L, 1, 1, 0) != 0) {
964  rpmlog(RPMLOG_ERR, _("lua hook failed: %s\n"),
965  lua_tostring(L, -1));
966  lua_pop(L, 1);
967  } else {
968  if (lua_isnumber(L, -1))
969  ret = (int)lua_tonumber(L, -1);
970  lua_pop(L, 1);
971  }
972  return ret;
973 }
974 
975 static int rpm_register(lua_State *L)
976  /*@globals internalState @*/
977  /*@modifies L, internalState @*/
978 {
979  if (!lua_isstring(L, 1)) {
980  (void) luaL_argerror(L, 1, "hook name expected");
981  } else if (!lua_isfunction(L, 2)) {
982  (void) luaL_argerror(L, 2, "function expected");
983  } else {
984  rpmluaHookData hookdata = (rpmluaHookData)
985  lua_newuserdata(L, sizeof(struct rpmluaHookData_s));
986  lua_pushvalue(L, -1);
987  hookdata->dataRef = luaL_ref(L, LUA_REGISTRYINDEX);
988  lua_pushvalue(L, 2);
989  hookdata->funcRef = luaL_ref(L, LUA_REGISTRYINDEX);
990 /*@-temptrans@*/
991  hookdata->L = L;
992 /*@=temptrans@*/
993  rpmhookRegister(lua_tostring(L, 1), rpmluaHookWrapper, hookdata);
994  return 1;
995  }
996  return 0;
997 }
998 
999 static int rpm_unregister(lua_State *L)
1000  /*@modifies L @*/
1001 {
1002  if (!lua_isstring(L, 1)) {
1003  (void) luaL_argerror(L, 1, "hook name expected");
1004  } else if (!lua_islightuserdata(L, 2)) {
1005  (void) luaL_argerror(L, 2, "hook information expected");
1006  } else {
1007  rpmluaHookData hookdata = (rpmluaHookData)lua_touserdata(L, 2);
1008  luaL_unref(L, LUA_REGISTRYINDEX, hookdata->funcRef);
1009  luaL_unref(L, LUA_REGISTRYINDEX, hookdata->dataRef);
1010  rpmhookUnregister(lua_tostring(L, 1), rpmluaHookWrapper, hookdata);
1011  }
1012  return 0;
1013 }
1014 
1015 static int rpm_call(lua_State *L)
1016  /*@globals internalState @*/
1017  /*@modifies L, internalState @*/
1018 {
1019  if (!lua_isstring(L, 1)) {
1020  (void) luaL_argerror(L, 1, "hook name expected");
1021  } else {
1022  rpmhookArgs args = rpmhookArgsNew(lua_gettop(L)-1);
1023  const char *name = lua_tostring(L, 1);
1024  char *argt = (char *)xmalloc(args->argc+1);
1025  int i;
1026  for (i = 0; i != args->argc; i++) {
1027  switch (lua_type(L, i+1)) {
1028  case LUA_TNIL:
1029  argt[i] = 'p';
1030  args->argv[i].p = NULL;
1031  /*@switchbreak@*/ break;
1032  case LUA_TNUMBER: {
1033  float f = (float)lua_tonumber(L, i+1);
1034 /*@+relaxtypes@*/
1035  if (f == (int)f) {
1036  argt[i] = 'i';
1037  args->argv[i].i = (int)f;
1038  } else {
1039  argt[i] = 'f';
1040  args->argv[i].f = f;
1041  }
1042 /*@=relaxtypes@*/
1043  } /*@switchbreak@*/ break;
1044  case LUA_TSTRING:
1045  argt[i] = 's';
1046  args->argv[i].s = lua_tostring(L, i+1);
1047  /*@switchbreak@*/ break;
1048  case LUA_TUSERDATA:
1049  case LUA_TLIGHTUSERDATA:
1050  argt[i] = 'p';
1051  args->argv[i].p = lua_touserdata(L, i+1);
1052  /*@switchbreak@*/ break;
1053  default:
1054  (void) luaL_error(L, "unsupported Lua type passed to hook");
1055  argt[i] = 'p';
1056  args->argv[i].p = NULL;
1057  /*@switchbreak@*/ break;
1058  }
1059  }
1060 /*@-compdef -kepttrans -usereleased @*/
1061  args->argt = argt;
1062  rpmhookCallArgs(name, args);
1063  argt = _free(argt);
1064  (void) rpmhookArgsFree(args);
1065 /*@=compdef =kepttrans =usereleased @*/
1066  }
1067  return 0;
1068 }
1069 
1070 /* Based on luaB_print. */
1071 static int rpm_print (lua_State *L)
1072  /*@globals fileSystem @*/
1073  /*@modifies L, fileSystem @*/
1074 {
1075  rpmlua lua = (rpmlua)getdata(L, "lua");
1076  int n = lua_gettop(L); /* number of arguments */
1077  int i;
1078  if (!lua) return 0;
1079  lua_getglobal(L, "tostring");
1080  for (i = 1; i <= n; i++) {
1081  const char *s;
1082  lua_pushvalue(L, -1); /* function to be called */
1083  lua_pushvalue(L, i); /* value to print */
1084  lua_call(L, 1, 1);
1085  s = lua_tostring(L, -1); /* get result */
1086  if (s == NULL)
1087  return luaL_error(L, "`tostring' must return a string to `print'");
1088  if (lua->storeprint) {
1089  size_t sl = lua_strlen(L, -1);
1090  if ((size_t)(lua->printbufused+sl+1) > lua->printbufsize) {
1091  lua->printbufsize += sl+512;
1092  lua->printbuf = (char *) xrealloc(lua->printbuf, lua->printbufsize);
1093  }
1094  if (i > 1)
1095  lua->printbuf[lua->printbufused++] = '\t';
1096  memcpy(lua->printbuf+lua->printbufused, s, sl+1);
1097  lua->printbufused += sl;
1098  } else {
1099  if (i > 1)
1100  (void) fputs("\t", stdout);
1101  (void) fputs(s, stdout);
1102  }
1103  lua_pop(L, 1); /* pop result */
1104  }
1105  if (!lua->storeprint) {
1106  (void) fputs("\n", stdout);
1107  } else {
1108  if ((size_t)(lua->printbufused+1) > lua->printbufsize) {
1109  lua->printbufsize += 512;
1110  lua->printbuf = (char *) xrealloc(lua->printbuf, lua->printbufsize);
1111  }
1112  lua->printbuf[lua->printbufused] = '\0';
1113  }
1114  return 0;
1115 }
1116 
1117 static int rpm_source(lua_State *L)
1118  /*@globals fileSystem, internalState @*/
1119  /*@modifies L, fileSystem, internalState @*/
1120 {
1121  if (!lua_isstring(L, 1)) {
1122  (void)luaL_argerror(L, 1, "filename expected");
1123  } else {
1124  rpmlua lua = (rpmlua)getdata(L, "lua");
1125  const char *filename = lua_tostring(L, 1);
1126  (void)rpmluaRunScriptFile(lua, filename);
1127  }
1128  return 0;
1129 }
1130 
1131 extern int _max_load_depth; /* Maximum load nesting depth. */
1132 static int rpm_load(lua_State *L)
1133  /*@globals rpmGlobalMacroContext, fileSystem, internalState @*/
1134  /*@modifies L, rpmGlobalMacroContext, fileSystem, internalState @*/
1135 {
1136  if (!lua_isstring(L, 1)) {
1137  (void)luaL_argerror(L, 1, "filename expected");
1138  } else {
1139  const char *filename = lua_tostring(L, 1);
1140 /*@-globs@*/
1141  (void)rpmLoadMacroFile(NULL, filename, _max_load_depth);
1142 /*@=globs@*/
1143  }
1144  return 0;
1145 }
1146 
1147 static int rpm_verbose(lua_State *L)
1148  /*@globals internalState @*/
1149  /*@modifies L, internalState @*/
1150 {
1151  lua_pushboolean(L, rpmIsVerbose());
1152  return 1;
1153 }
1154 
1155 static int rpm_debug(lua_State *L)
1156  /*@globals internalState @*/
1157  /*@modifies L, internalState @*/
1158 {
1159  lua_pushboolean(L, rpmIsDebug());
1160  return 1;
1161 }
1162 
1163 static int rpm_slurp(lua_State *L)
1164  /*@globals fileSystem, internalState @*/
1165  /*@modifies L, fileSystem, internalState @*/
1166 {
1167  rpmiob iob = NULL;
1168  const char *fn;
1169  int rc;
1170 
1171  if (lua_isstring(L, 1))
1172  fn = lua_tostring(L, 1);
1173  else {
1174  (void)luaL_argerror(L, 1, "filename");
1175  return 0;
1176  }
1177 /*@-globs@*/
1178  rc = rpmiobSlurp(fn, &iob);
1179 /*@=globs@*/
1180  if (rc || iob == NULL) {
1181  (void)luaL_error(L, "failed to slurp data");
1182  return 0;
1183  }
1184  lua_pushlstring(L, (const char *)rpmiobStr(iob), rpmiobLen(iob));
1185  iob = rpmiobFree(iob);
1186  return 1;
1187 }
1188 
1189 static int rpm_sleep(lua_State *L)
1190  /*@globals fileSystem, internalState @*/
1191  /*@modifies L, fileSystem, internalState @*/
1192 {
1193  unsigned sec;
1194 
1195  if (lua_isnumber(L, 1))
1196  sec = (unsigned) lua_tonumber(L, 1);
1197  else {
1198  (void)luaL_argerror(L, 1, "seconds");
1199  return 0;
1200  }
1201  (void) sleep(sec);
1202  return 0;
1203 }
1204 
1205 static int rpm_realpath(lua_State *L)
1206  /*@globals fileSystem, internalState @*/
1207  /*@modifies L, fileSystem, internalState @*/
1208 {
1209  const char *pn;
1210  char rp_buf[PATH_MAX];
1211  char *rp = (char *) "";
1212 
1213  if (lua_isstring(L, 1))
1214  pn = lua_tostring(L, 1);
1215  else {
1216  (void)luaL_argerror(L, 1, "pathname");
1217  return 0;
1218  }
1219  if ((rp = Realpath(pn, rp_buf)) == NULL) {
1220  (void)luaL_error(L, "failed to resolve path via realpath(3): %s", strerror(errno));
1221  return 0;
1222  }
1223  lua_pushstring(L, (const char *)rp);
1224  return 1;
1225 }
1226 
1227 static int rpm_hostname(lua_State *L)
1228  /*@globals h_errno, internalState @*/
1229  /*@modifies L, h_errno, internalState @*/
1230 {
1231  char hostname[1024];
1232  struct hostent *hbn;
1233  char *h;
1234 
1235 /*@-multithreaded@*/
1236  (void)gethostname(hostname, sizeof(hostname));
1237  if ((hbn = gethostbyname(hostname)) != NULL)
1238  h = hbn->h_name;
1239  else
1240  h = hostname;
1241 /*@=multithreaded@*/
1242  lua_pushstring(L, (const char *)h);
1243  return 1;
1244 }
1245 
1246 /*@-readonlytrans -nullassign @*/
1247 /*@observer@*/ /*@unchecked@*/
1248 static const luaL_reg rpmlib[] = {
1249  {"macros", rpm_macros},
1250  {"expand", rpm_expand},
1251  {"define", rpm_define},
1252  {"undefine", rpm_undefine},
1253  {"register", rpm_register},
1254  {"unregister", rpm_unregister},
1255  {"call", rpm_call},
1256  {"interactive", rpm_interactive},
1257  {"source", rpm_source},
1258  {"load", rpm_load},
1259  {"verbose", rpm_verbose},
1260  {"debug", rpm_debug},
1261  {"slurp", rpm_slurp},
1262  {"sleep", rpm_sleep},
1263  {"realpath", rpm_realpath},
1264  {"hostname", rpm_hostname},
1265  {NULL, NULL}
1266 };
1267 /*@=readonlytrans =nullassign @*/
1268 
1269 static int luaopen_rpm(lua_State *L)
1270  /*@modifies L @*/
1271 {
1272 #if defined(LUA_GLOBALSINDEX)
1273  lua_pushvalue(L, LUA_GLOBALSINDEX);
1274 #else
1275  lua_pushglobaltable(L);
1276 #endif
1277  luaL_openlib(L, "rpm", rpmlib, 0);
1278  return 0;
1279 }
1280 #endif /* WITH_LUA */
1281 
1282 /*@=moduncon =mustmod =realcompare =sizeoftype @*/
#define RPMLUAFILES
Definition: config.h:1120
void rpmluavGetKey(rpmluav var, rpmluavType *type, void **value)
int rpmluaCheckScript(rpmlua _lua, const char *script, const char *name)
rpmhookArgs rpmhookArgsNew(int argc)
Definition: rpmhook.c:34
rpmhookArgs rpmhookArgsFree(rpmhookArgs args)
Definition: rpmhook.c:42
enum rpmluavType_e rpmluavType
const char * rpmluaPath
void rpmluavSetValueNum(rpmluav var, double value)
char * xstrdup(const char *str)
Definition: rpmmalloc.c:322
size_t rpmiobLen(rpmiob iob)
Return I/O buffer len.
Definition: rpmiob.c:123
void * rpmluavFree(rpmluav var)
char * rpmGetPath(const char *path,...)
Return (malloc&#39;ed) expanded, canonicalized, file path.
Definition: macro.c:3310
void rpmluaSetPrintBuffer(rpmlua _lua, int flag)
void rpmluaGetVar(rpmlua _lua, rpmluav var)
void rpmluavSetListMode(rpmluav var, int flag)
rpmioItem rpmioLinkPoolItem(rpmioItem item, const char *msg, const char *fn, unsigned ln)
Increment a pool item refcount.
Definition: rpmmalloc.c:166
int _max_load_depth
Definition: macro.c:166
void rpmhookUnregister(const char *name, rpmhookFunc func, void *data)
Definition: rpmhook.c:249
void rpmluavSetKey(rpmluav var, rpmluavType type, const void *value)
rpmlua rpmluaGetGlobalState(void)
int Stat(const char *path, struct stat *st)
stat(2) clone.
Definition: rpmrpc.c:1361
const char * s
Definition: rpmhook.h:6
void * rpmioFreePoolItem(rpmioItem item, const char *msg, const char *fn, unsigned ln)
Free a pool item.
Definition: rpmmalloc.c:187
int errno
void * rpmluaGetData(rpmlua _lua, const char *key)
rpmiob rpmiobFree(rpmiob iob)
Destroy a I/O buffer instance.
double rpmluavGetValueNum(rpmluav var)
static void rpmlog(int code, const char *fmt,...)
Definition: rpmlog.h:299
void rpmluavSetKeyNum(rpmluav var, double value)
int _rpmlua_debug
Definition: rpmlua.c:58
int i
Definition: rpmhook.h:7
void rpmluaPushTable(rpmlua _lua, const char *key,...)
void rpmluavSetValue(rpmluav var, rpmluavType type, const void *value)
int rpmiobSlurp(const char *fn, rpmiob *iobp)
Definition: rpmiob.c:130
Yet Another syslog(3) API clone.
int rpmGlob(const char *patterns, int *argcPtr, const char ***argvPtr)
Return URL path(s) from a (URL prefixed) pattern glob.
Definition: macro.c:2509
double rpmluavGetKeyNum(rpmluav var)
rpmioItem rpmioGetPool(rpmioPool pool, size_t size)
Get unused item from pool, or alloc a new item.
Definition: rpmmalloc.c:221
int rpmGetMacroEntries(MacroContext mc, void *_mire, int used, const char ***avp)
Return macro entries as string array.
Definition: macro.c:319
float f
Definition: rpmhook.h:8
ARGV_t argvFree(ARGV_t argv)
Destroy an argv array.
Definition: argv.c:44
struct rpmluav_s * rpmluav
Definition: rpmlua.h:54
const char * rpmluaGetPrintBuffer(rpmlua _lua)
int rpmDefineMacro(MacroContext mc, const char *macro, int level)
Define macro in context.
Definition: macro.c:2739
const char * rpmluaFiles
rpmluav rpmluavNew(void)
void * rpmluaFree(rpmlua lua)
char * rpmExpand(const char *arg,...)
Return (malloc&#39;ed) concatenated macro expansion(s).
Definition: macro.c:3117
void rpmluaInteractive(rpmlua _lua)
void rpmluaDelVar(rpmlua _lua, const char *key,...)
rpmlua rpmluaNew(void)
void * p
Definition: rpmhook.h:10
void rpmluaSetData(rpmlua _lua, const char *key, const void *data)
#define USRLIBRPM
Definition: config.h:1261
rpmioPool _rpmluaPool
Definition: rpmlua.c:61
char * rpmiobStr(rpmiob iob)
Return I/O buffer (as string).
Definition: rpmiob.c:113
#define L(CS)
Definition: fnmatch.c:155
const char * argt
Definition: rpmhook.h:15
static int vsnprintf(char *buf, int nb, const char *fmt, va_list ap)
Definition: rpmps.c:212
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:110
int rpmluaVarExists(rpmlua _lua, const char *key,...)
void rpmluaSetVar(rpmlua _lua, rpmluav var)
static void * _free(const void *p)
Wrapper to free(3), hides const compilation noise, permit NULL, return NULL.
Definition: rpmiotypes.h:647
struct rpmiob_s * rpmiob
Definition: rpmiotypes.h:57
int rpmluavKeyIsNum(rpmluav var)
int rpmSecuritySaneFile(const char *filename)
Check whether configuration file is moderately secure to load.
Definition: macro.c:2486
int rpmluavValueIsNum(rpmluav var)
#define rpmIsVerbose()
Definition: rpmcb.h:21
rpmhookArgv argv[1]
Definition: rpmhook.h:16
void rpmhookRegister(const char *name, rpmhookFunc func, void *data)
Definition: rpmhook.c:240
rpmioPool _rpmluavPool
Definition: rpmlua.c:64
struct rpmlua_s * rpmlua
Definition: rpmlua.h:53
void rpmhookCallArgs(const char *name, rpmhookArgs args)
Definition: rpmhook.c:282
int rpmluaRunScriptFile(rpmlua _lua, const char *filename)
static const char * name
#define rpmIsDebug()
Definition: rpmcb.h:23
#define _(Text)
Definition: system.h:30
void rpmluavGetValue(rpmluav var, rpmluavType *type, void **value)
#define xmalloc
Definition: system.h:33
int rpmLoadMacroFile(MacroContext mc, const char *fn, int nesting)
Load macro context from a macro file.
Definition: macro.c:2801
#define PATH_MAX
Definition: query.c:10
char * Realpath(const char *path, char *resolved_path)
realpath(3) clone.
Definition: rpmrpc.c:2330
#define xrealloc
Definition: system.h:36
int rpmluaRunScript(rpmlua _lua, const char *script, const char *name)
int rpmUndefineMacro(MacroContext mc, const char *macro)
Undefine macro in context.
Definition: macro.c:2753