Deleted Added
full compact
ng_parse.c (54249) ng_parse.c (58011)
1
2/*
3 * ng_parse.c
4 *
5 * Copyright (c) 1999 Whistle Communications, Inc.
6 * All rights reserved.
7 *
8 * Subject to the following obligations and disclaimer of warranty, use and

--- 23 unchanged lines hidden (view full) ---

32 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
33 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
34 * THIS SOFTWARE, EVEN IF WHISTLE COMMUNICATIONS IS ADVISED OF THE POSSIBILITY
35 * OF SUCH DAMAGE.
36 *
37 * Author: Archie Cobbs <archie@whistle.com>
38 *
39 * $Whistle: ng_parse.c,v 1.3 1999/11/29 01:43:48 archie Exp $
1
2/*
3 * ng_parse.c
4 *
5 * Copyright (c) 1999 Whistle Communications, Inc.
6 * All rights reserved.
7 *
8 * Subject to the following obligations and disclaimer of warranty, use and

--- 23 unchanged lines hidden (view full) ---

32 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
33 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
34 * THIS SOFTWARE, EVEN IF WHISTLE COMMUNICATIONS IS ADVISED OF THE POSSIBILITY
35 * OF SUCH DAMAGE.
36 *
37 * Author: Archie Cobbs <archie@whistle.com>
38 *
39 * $Whistle: ng_parse.c,v 1.3 1999/11/29 01:43:48 archie Exp $
40 * $FreeBSD: head/sys/netgraph/ng_parse.c 54249 1999-12-07 05:50:48Z julian $
40 * $FreeBSD: head/sys/netgraph/ng_parse.c 58011 2000-03-13 18:50:38Z archie $
41 */
42
43#include <sys/types.h>
44#include <sys/param.h>
45#include <sys/systm.h>
46#include <sys/errno.h>
47#include <sys/malloc.h>
48#include <sys/ctype.h>

--- 594 unchanged lines hidden (view full) ---

643 FIXED BUFFER STRING TYPE
644 ************************************************************************/
645
646static int
647ng_fixedstring_parse(const struct ng_parse_type *type,
648 const char *s, int *off, const u_char *const start,
649 u_char *const buf, int *buflen)
650{
41 */
42
43#include <sys/types.h>
44#include <sys/param.h>
45#include <sys/systm.h>
46#include <sys/errno.h>
47#include <sys/malloc.h>
48#include <sys/ctype.h>

--- 594 unchanged lines hidden (view full) ---

643 FIXED BUFFER STRING TYPE
644 ************************************************************************/
645
646static int
647ng_fixedstring_parse(const struct ng_parse_type *type,
648 const char *s, int *off, const u_char *const start,
649 u_char *const buf, int *buflen)
650{
651 const struct ng_parse_fixedsstring_info *const fi = type->info;
651 const struct ng_parse_fixedstring_info *const fi = type->info;
652 char *sval;
653 int len;
654
655 if ((sval = ng_get_string_token(s, off, &len)) == NULL)
656 return (EINVAL);
657 if (strlen(sval) + 1 > fi->bufSize)
658 return (E2BIG);
659 *off += len;

--- 4 unchanged lines hidden (view full) ---

664 *buflen = fi->bufSize;
665 return (0);
666}
667
668static int
669ng_fixedstring_unparse(const struct ng_parse_type *type,
670 const u_char *data, int *off, char *cbuf, int cbuflen)
671{
652 char *sval;
653 int len;
654
655 if ((sval = ng_get_string_token(s, off, &len)) == NULL)
656 return (EINVAL);
657 if (strlen(sval) + 1 > fi->bufSize)
658 return (E2BIG);
659 *off += len;

--- 4 unchanged lines hidden (view full) ---

664 *buflen = fi->bufSize;
665 return (0);
666}
667
668static int
669ng_fixedstring_unparse(const struct ng_parse_type *type,
670 const u_char *data, int *off, char *cbuf, int cbuflen)
671{
672 const struct ng_parse_fixedsstring_info *const fi = type->info;
672 const struct ng_parse_fixedstring_info *const fi = type->info;
673 int error, temp = *off;
674
675 if ((error = ng_string_unparse(type, data, &temp, cbuf, cbuflen)) != 0)
676 return (error);
677 *off += fi->bufSize;
678 return (0);
679}
680
681static int
682ng_fixedstring_getDefault(const struct ng_parse_type *type,
683 const u_char *const start, u_char *buf, int *buflen)
684{
673 int error, temp = *off;
674
675 if ((error = ng_string_unparse(type, data, &temp, cbuf, cbuflen)) != 0)
676 return (error);
677 *off += fi->bufSize;
678 return (0);
679}
680
681static int
682ng_fixedstring_getDefault(const struct ng_parse_type *type,
683 const u_char *const start, u_char *buf, int *buflen)
684{
685 const struct ng_parse_fixedsstring_info *const fi = type->info;
685 const struct ng_parse_fixedstring_info *const fi = type->info;
686
687 if (*buflen < fi->bufSize)
688 return (ERANGE);
689 bzero(buf, fi->bufSize);
690 *buflen = fi->bufSize;
691 return (0);
692}
693
694const struct ng_parse_type ng_parse_fixedstring_type = {
695 NULL,
696 NULL,
697 NULL,
698 ng_fixedstring_parse,
699 ng_fixedstring_unparse,
700 ng_fixedstring_getDefault,
701 NULL
702};
703
686
687 if (*buflen < fi->bufSize)
688 return (ERANGE);
689 bzero(buf, fi->bufSize);
690 *buflen = fi->bufSize;
691 return (0);
692}
693
694const struct ng_parse_type ng_parse_fixedstring_type = {
695 NULL,
696 NULL,
697 NULL,
698 ng_fixedstring_parse,
699 ng_fixedstring_unparse,
700 ng_fixedstring_getDefault,
701 NULL
702};
703
704const struct ng_parse_fixedsstring_info ng_parse_nodebuf_info = {
704const struct ng_parse_fixedstring_info ng_parse_nodebuf_info = {
705 NG_NODELEN + 1
706};
707const struct ng_parse_type ng_parse_nodebuf_type = {
708 &ng_parse_fixedstring_type,
709 &ng_parse_nodebuf_info
710};
711
705 NG_NODELEN + 1
706};
707const struct ng_parse_type ng_parse_nodebuf_type = {
708 &ng_parse_fixedstring_type,
709 &ng_parse_nodebuf_info
710};
711
712const struct ng_parse_fixedsstring_info ng_parse_hookbuf_info = {
712const struct ng_parse_fixedstring_info ng_parse_hookbuf_info = {
713 NG_HOOKLEN + 1
714};
715const struct ng_parse_type ng_parse_hookbuf_type = {
716 &ng_parse_fixedstring_type,
717 &ng_parse_hookbuf_info
718};
719
713 NG_HOOKLEN + 1
714};
715const struct ng_parse_type ng_parse_hookbuf_type = {
716 &ng_parse_fixedstring_type,
717 &ng_parse_hookbuf_info
718};
719
720const struct ng_parse_fixedsstring_info ng_parse_pathbuf_info = {
720const struct ng_parse_fixedstring_info ng_parse_pathbuf_info = {
721 NG_PATHLEN + 1
722};
723const struct ng_parse_type ng_parse_pathbuf_type = {
724 &ng_parse_fixedstring_type,
725 &ng_parse_pathbuf_info
726};
727
721 NG_PATHLEN + 1
722};
723const struct ng_parse_type ng_parse_pathbuf_type = {
724 &ng_parse_fixedstring_type,
725 &ng_parse_pathbuf_info
726};
727
728const struct ng_parse_fixedsstring_info ng_parse_typebuf_info = {
728const struct ng_parse_fixedstring_info ng_parse_typebuf_info = {
729 NG_TYPELEN + 1
730};
731const struct ng_parse_type ng_parse_typebuf_type = {
732 &ng_parse_fixedstring_type,
733 &ng_parse_typebuf_info
734};
735
729 NG_TYPELEN + 1
730};
731const struct ng_parse_type ng_parse_typebuf_type = {
732 &ng_parse_fixedstring_type,
733 &ng_parse_typebuf_info
734};
735
736const struct ng_parse_fixedsstring_info ng_parse_cmdbuf_info = {
736const struct ng_parse_fixedstring_info ng_parse_cmdbuf_info = {
737 NG_CMDSTRLEN + 1
738};
739const struct ng_parse_type ng_parse_cmdbuf_type = {
740 &ng_parse_fixedstring_type,
741 &ng_parse_cmdbuf_info
742};
743
744/************************************************************************

--- 859 unchanged lines hidden ---
737 NG_CMDSTRLEN + 1
738};
739const struct ng_parse_type ng_parse_cmdbuf_type = {
740 &ng_parse_fixedstring_type,
741 &ng_parse_cmdbuf_info
742};
743
744/************************************************************************

--- 859 unchanged lines hidden ---