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

Last change on this file since 772 was 772, checked in by hmueller, on Jul 1, 2009 at 5:15:41 PM
  • Property svn:mime-type set to text/x-cpp
File size: 1.6 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// TODO replace malloc by python mem handler
19 retbuf = (char *) malloc(retlen);
20 if (retbuf == NULL)
21 return NULL;
22
23 bin_to_base64(retbuf, retlen,
24 binstr, strlen(binstr), compatible);
25
26 result = Py_BuildValue("s", retbuf);
27 free(retbuf);
28
29 return result;
30}
31
32static PyObject *
33clibbac_hmac_md5(PyObject *self, PyObject *args)
34{
35 const char *challenge, *password;
36 char retbuf[20];
37
38 if (!PyArg_ParseTuple(args, "ss", &challenge, &password))
39 return NULL;
40 hmac_md5((u_int8_t*) challenge, strlen(challenge),
41 (u_int8_t*) password, strlen(password),
42 (u_int8_t*)retbuf);
43
44 return Py_BuildValue("s", retbuf);
45}
46
47static PyMethodDef BaculaMethods[] = {
48 {"bin_to_base64", clibbac_bin_to_base64, METH_VARARGS,
49 "Bacula's base64 algorythm"},
50 {"hmac_md5", clibbac_hmac_md5, METH_VARARGS,
51 "Bacula's hmac_md5 algorythm"},
52 {NULL, NULL, 0, NULL} /* Sentinel */
53};
54
55PyMODINIT_FUNC
56initclibbac(void)
57{
58 (void) Py_InitModule("clibbac", BaculaMethods);
59}
60
61int
62main(int argc, char *argv[])
63{
64 /* Pass argv[0] to the Python interpreter */
65 Py_SetProgramName(argv[0]);
66
67 /* Initialize the Python interpreter. Required. */
68 Py_Initialize();
69
70 /* Add a static module */
71 initclibbac();
72}
Note: See TracBrowser for help on using the repository browser.