mirror of
https://github.com/openbsd/src.git
synced 2025-01-09 22:38:01 -08:00
add a new ber function ber_add_astring() that strdups the string and
sets the be_free flag (which is required in some cases). this will make it easier because it is done manually at some places in the code. discussed with dlg
This commit is contained in:
parent
b9314721c9
commit
af9bb98fed
@ -1,4 +1,4 @@
|
||||
.\" $OpenBSD: ber.3,v 1.4 2008/02/09 13:03:01 reyk Exp $
|
||||
.\" $OpenBSD: ber.3,v 1.5 2008/03/14 15:22:22 reyk Exp $
|
||||
.\"
|
||||
.\" Copyright (c) 2007 Reyk Floeter <reyk@vantronix.net>
|
||||
.\"
|
||||
@ -14,7 +14,7 @@
|
||||
.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
.\"
|
||||
.Dd $Mdocdate: February 9 2008 $
|
||||
.Dd $Mdocdate: March 14 2008 $
|
||||
.Dt BER 3
|
||||
.Os
|
||||
.Sh NAME
|
||||
@ -30,6 +30,7 @@
|
||||
.Nm ber_add_boolean ,
|
||||
.Nm ber_get_boolean ,
|
||||
.Nm ber_add_string ,
|
||||
.Nm ber_add_astring ,
|
||||
.Nm ber_get_string ,
|
||||
.Nm ber_add_nstring ,
|
||||
.Nm ber_add_bitstring ,
|
||||
@ -82,6 +83,8 @@
|
||||
.Ft "struct ber_element *"
|
||||
.Fn "ber_add_string" "struct ber_element *prev" "char *string"
|
||||
.Ft "struct ber_element *"
|
||||
.Fn "ber_add_astring" "struct ber_element *prev" "char *string"
|
||||
.Ft "struct ber_element *"
|
||||
.Fn "ber_add_nstring" "struct ber_element *prev" "char *string" "size_t size"
|
||||
.Ft "int"
|
||||
.Fn "ber_get_string" "struct ber_element *root" "char **charbuf"
|
||||
@ -152,6 +155,7 @@ using the
|
||||
.Fn ber_add_boolean ,
|
||||
.Fn ber_get_boolean ,
|
||||
.Fn ber_add_string ,
|
||||
.Fn ber_add_astring ,
|
||||
.Fn ber_get_string ,
|
||||
.Fn ber_add_nstring ,
|
||||
.Fn ber_add_bitstring ,
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $OpenBSD: ber.c,v 1.11 2008/03/12 17:48:27 reyk Exp $ */
|
||||
/* $OpenBSD: ber.c,v 1.12 2008/03/14 15:22:22 reyk Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2007 Reyk Floeter <reyk@vantronix.net>
|
||||
@ -233,6 +233,28 @@ ber_add_string(struct ber_element *prev, char *string)
|
||||
return elm;
|
||||
}
|
||||
|
||||
struct ber_element *
|
||||
ber_add_astring(struct ber_element *prev, const char *string)
|
||||
{
|
||||
struct ber_element *elm;
|
||||
char *str;
|
||||
|
||||
if ((elm = ber_get_element(BER_TYPE_OCTETSTRING)) == NULL)
|
||||
return NULL;
|
||||
if ((str = strdup(string)) == NULL) {
|
||||
ber_free_elements(elm);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
elm->be_val = str;
|
||||
elm->be_len = strlen(str); /* terminating '\0' not included */
|
||||
elm->be_free = 1; /* free string on cleanup */
|
||||
|
||||
ber_link_elements(prev, elm);
|
||||
|
||||
return elm;
|
||||
}
|
||||
|
||||
struct ber_element *
|
||||
ber_add_nstring(struct ber_element *prev, char *string, size_t len)
|
||||
{
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $OpenBSD: ber.h,v 1.4 2008/02/09 13:03:01 reyk Exp $ */
|
||||
/* $OpenBSD: ber.h,v 1.5 2008/03/14 15:22:22 reyk Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2007 Reyk Floeter <reyk@vantronix.net>
|
||||
@ -93,6 +93,7 @@ int ber_get_integer(struct ber_element *, long long *);
|
||||
struct ber_element *ber_add_boolean(struct ber_element *, int);
|
||||
int ber_get_boolean(struct ber_element *, int *);
|
||||
struct ber_element *ber_add_string(struct ber_element *, char *);
|
||||
struct ber_element *ber_add_astring(struct ber_element *, const char *);
|
||||
struct ber_element *ber_add_nstring(struct ber_element *, char *, size_t);
|
||||
int ber_get_string(struct ber_element *, char **);
|
||||
int ber_get_nstring(struct ber_element *, void **,
|
||||
|
Loading…
Reference in New Issue
Block a user