source: vanHelsing/trunk/clib/clibbac.cxx@ 1244

Last change on this file since 1244 was 773, checked in by hmueller, on Jul 3, 2009 at 5:19:08 PM

Clibbac now uses Python memory management

  • Property svn:mime-type set to text/x-cpp
File size: 1.5 KB
Line 
1#include "Python.h"
2#include "bacula.h"
3
4static PyObject *
5clibbac_bin_to_base64(PyObject *self, PyObject *args)
6{
7 char *binstr;
8 int compatible;
9 char *retbuf;
10 size_t retlen;
11 PyObject *result;
12
13 if (!PyArg_ParseTuple(args, "si", &binstr, &compatible))
14 return NULL;
15
16 retlen = strlen(binstr) * 2 + 2;
17
18 retbuf = (char *) PyMem_Malloc(retlen);
19 if (retbuf == NULL)
20 return NULL;
21
22 bin_to_base64(retbuf, retlen,
23 binstr, strlen(binstr), compatible);
24
25 result = Py_BuildValue("s", retbuf);
26 PyMem_Free(retbuf);
27
28 return result;
29}
30
31static PyObject *
32clibbac_hmac_md5(PyObject *self, PyObject *args)
33{
34 const char *challenge, *password;
35 char retbuf[20];
36
37 if (!PyArg_ParseTuple(args, "ss", &challenge, &password))
38 return NULL;
39 hmac_md5((u_int8_t*) challenge, strlen(challenge),
40 (u_int8_t*) password, strlen(password),
41 (u_int8_t*)retbuf);
42
43 return Py_BuildValue("s", retbuf);
44}
45
46static PyMethodDef BaculaMethods[] = {
47 {"bin_to_base64", clibbac_bin_to_base64, METH_VARARGS,
48 "Bacula's base64 algorythm"},
49 {"hmac_md5", clibbac_hmac_md5, METH_VARARGS,
50 "Bacula's hmac_md5 algorythm"},
51 {NULL, NULL, 0, NULL} /* Sentinel */
52};
53
54PyMODINIT_FUNC
55initclibbac(void)
56{
57 (void) Py_InitModule("clibbac", BaculaMethods);
58}
59
60int
61main(int argc, char *argv[])
62{
63 /* Pass argv[0] to the Python interpreter */
64 Py_SetProgramName(argv[0]);
65
66 /* Initialize the Python interpreter. Required. */
67 Py_Initialize();
68
69 /* Add a static module */
70 initclibbac();
71}
Note: See TracBrowser for help on using the repository browser.