diff options
author | Reyk Floeter <reyk@cvs.openbsd.org> | 2008-03-14 15:22:23 +0000 |
---|---|---|
committer | Reyk Floeter <reyk@cvs.openbsd.org> | 2008-03-14 15:22:23 +0000 |
commit | 39d6d7ce0df9a10343dccd65e71d0b58807c605d (patch) | |
tree | c751981f6e8217b9ffe69c3cd167f62255cdbff7 /usr.sbin | |
parent | 150cdec844fbeaf1b97117a06db02fb11842621f (diff) |
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
Diffstat (limited to 'usr.sbin')
-rw-r--r-- | usr.sbin/snmpd/ber.3 | 8 | ||||
-rw-r--r-- | usr.sbin/snmpd/ber.c | 24 | ||||
-rw-r--r-- | usr.sbin/snmpd/ber.h | 3 |
3 files changed, 31 insertions, 4 deletions
diff --git a/usr.sbin/snmpd/ber.3 b/usr.sbin/snmpd/ber.3 index 8c4a35c83b0..e275cd2fef8 100644 --- a/usr.sbin/snmpd/ber.3 +++ b/usr.sbin/snmpd/ber.3 @@ -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 , diff --git a/usr.sbin/snmpd/ber.c b/usr.sbin/snmpd/ber.c index ca77260f3c8..1b761c8eede 100644 --- a/usr.sbin/snmpd/ber.c +++ b/usr.sbin/snmpd/ber.c @@ -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> @@ -234,6 +234,28 @@ ber_add_string(struct ber_element *prev, char *string) } 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) { struct ber_element *elm; diff --git a/usr.sbin/snmpd/ber.h b/usr.sbin/snmpd/ber.h index d20f98bcbf4..cf6a182862a 100644 --- a/usr.sbin/snmpd/ber.h +++ b/usr.sbin/snmpd/ber.h @@ -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 **, |