forked from python-ldap/python-ldap
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathberval.c
More file actions
51 lines (44 loc) · 1.13 KB
/
berval.c
File metadata and controls
51 lines (44 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/* See https://www.python-ldap.org/ for details. */
#include "common.h"
#include "berval.h"
/*
* Copies out the data from a berval, and returns it as a new Python object,
* Returns None if the berval pointer is NULL.
*
* Note that this function is not the exact inverse of LDAPberval_from_object
* with regards to the NULL/None conversion.
*
* Returns a new Python object on success, or NULL on failure.
*/
PyObject *
LDAPberval_to_object(const struct berval *bv)
{
PyObject *ret = NULL;
if (!bv) {
ret = Py_None;
Py_INCREF(ret);
}
else {
ret = PyBytes_FromStringAndSize(bv->bv_val, bv->bv_len);
}
return ret;
}
/*
* Same as LDAPberval_to_object, but returns a Unicode PyObject.
* Use when the value is known to be text (for instance a distinguishedName).
*
* Returns a new Python object on success, or NULL on failure.
*/
PyObject *
LDAPberval_to_unicode_object(const struct berval *bv)
{
PyObject *ret = NULL;
if (!bv) {
ret = Py_None;
Py_INCREF(ret);
}
else {
ret = PyUnicode_FromStringAndSize(bv->bv_val, bv->bv_len);
}
return ret;
}