dmake: do not set MAKEFLAGS=k
[unleashed/tickless.git] / usr / src / lib / libdhcputil / common / dhcp_symbol.c
blob76ad96c06d1dbe4eae8ea4d3bf686afed27876f0
1 /*
2 * CDDL HEADER START
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
19 * CDDL HEADER END
22 * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
26 #pragma ident "%Z%%M% %I% %E% SMI"
28 #include <stdlib.h>
29 #include <ctype.h>
30 #include <strings.h>
31 #include <limits.h>
32 #include <errno.h>
33 #include <dhcp_impl.h>
35 #include "dhcp_symbol.h"
38 * The following structure and table are used to define the attributes
39 * of a DHCP symbol category.
41 typedef struct dsym_cat {
42 char *dc_string; /* string value for the category */
43 int dc_minlen; /* min. chars of dc_string to match */
44 dsym_category_t dc_id; /* numerical value for the category */
45 boolean_t dc_dhcptab; /* valid for dhcptab use? */
46 ushort_t dc_min; /* minimum valid code */
47 ushort_t dc_max; /* maximum valid code */
48 } dsym_cat_t;
50 static dsym_cat_t cats[] = {
51 { "Extend", 6, DSYM_EXTEND, B_TRUE, DHCP_LAST_STD + 1,
52 DHCP_SITE_OPT - 1 },
53 { "Vendor=", 6, DSYM_VENDOR, B_TRUE, DHCP_FIRST_OPT,
54 DHCP_LAST_OPT },
55 { "Site", 4, DSYM_SITE, B_TRUE, DHCP_SITE_OPT, DHCP_LAST_OPT },
56 { "Standard", 8, DSYM_STANDARD, B_FALSE, DHCP_FIRST_OPT,
57 DHCP_LAST_STD },
58 { "Field", 5, DSYM_FIELD, B_FALSE, CD_PACKET_START,
59 CD_PACKET_END },
60 { "Internal", 8, DSYM_INTERNAL, B_FALSE, CD_INTRNL_START,
61 CD_INTRNL_END }
65 * The following structure and table are used to define the attributes
66 * of a DHCP symbol type.
68 typedef struct dsym_type {
69 char *dt_string; /* string value for the type */
70 dsym_cdtype_t dt_id; /* numerical value for the type */
71 boolean_t dt_dhcptab; /* valid for dhcptab use? */
72 } dsym_type_t;
74 static dsym_type_t types[] = {
75 { "ASCII", DSYM_ASCII, B_TRUE },
76 { "OCTET", DSYM_OCTET, B_TRUE },
77 { "IP", DSYM_IP, B_TRUE },
78 { "NUMBER", DSYM_NUMBER, B_TRUE },
79 { "BOOL", DSYM_BOOL, B_TRUE },
80 { "INCLUDE", DSYM_INCLUDE, B_FALSE },
81 { "UNUMBER8", DSYM_UNUMBER8, B_TRUE },
82 { "UNUMBER16", DSYM_UNUMBER16, B_TRUE },
83 { "UNUMBER24", DSYM_UNUMBER24, B_TRUE },
84 { "UNUMBER32", DSYM_UNUMBER32, B_TRUE },
85 { "UNUMBER64", DSYM_UNUMBER64, B_TRUE },
86 { "SNUMBER8", DSYM_SNUMBER8, B_TRUE },
87 { "SNUMBER16", DSYM_SNUMBER16, B_TRUE },
88 { "SNUMBER32", DSYM_SNUMBER32, B_TRUE },
89 { "SNUMBER64", DSYM_SNUMBER64, B_TRUE },
90 { "IPV6", DSYM_IPV6, B_TRUE },
91 { "DUID", DSYM_DUID, B_TRUE },
92 { "DOMAIN", DSYM_DOMAIN, B_TRUE }
96 * symbol delimiters and constants
98 #define DSYM_CLASS_DEL " \t\n"
99 #define DSYM_FIELD_DEL ","
100 #define DSYM_VENDOR_DEL '='
101 #define DSYM_QUOTE '"'
104 * dsym_trim(): trims all whitespace from either side of a string
106 * input: char **: a pointer to a string to trim of whitespace.
107 * output: none
110 static void
111 dsym_trim(char **str)
114 char *tmpstr = *str;
117 * Trim all whitespace from the front of the string.
119 while (*tmpstr != '\0' && isspace(*tmpstr)) {
120 tmpstr++;
124 * Move the str pointer to first non-whitespace char.
126 *str = tmpstr;
129 * Check case where the string is nothing but whitespace.
131 if (*tmpstr == '\0') {
134 * Trim all whitespace from the end of the string.
136 tmpstr = *str + strlen(*str) - 1;
137 while (tmpstr >= *str && isspace(*tmpstr)) {
138 tmpstr--;
142 * terminate after last non-whitespace char.
144 *(tmpstr+1) = '\0';
149 * dsym_get_token(): strtok_r() like routine, except consecutive delimiters
150 * result in an empty string
152 * note: original string is modified
154 * input: char *: string in which to search for tokens
155 * char *: list of possible token delimiter characters
156 * char **: location for next call to routine
157 * boolean_t: should delimiters be ignored if within quoted string?
158 * output: char *: token, or NULL if no more tokens
161 static char *
162 dsym_get_token(char *str, char *dels, char **lasts, boolean_t quote_support)
165 char *ptr = str;
166 char *del;
167 boolean_t found = B_FALSE;
168 boolean_t in_quote = B_FALSE;
171 * If incoming string has no tokens return a NULL
172 * pointer to signify no more tokens.
174 if (*ptr == '\0') {
175 return (NULL);
179 * Loop until either a token has been identified or until end
180 * of string has been reached.
182 while (!found && *ptr != '\0') {
185 * If pointer currently lies within a quoted string,
186 * then do not check for the delimiter.
188 if (!in_quote) {
189 for (del = dels; !found && *del != '\0'; del++) {
190 if (*del == *ptr) {
191 *ptr++ = '\0';
192 found = B_TRUE;
198 * If the pointer is pointing at a delimiter, then
199 * check to see if it points to at a quote and update
200 * the state appropriately.
202 if (!found) {
203 if (quote_support && *ptr == DSYM_QUOTE) {
204 in_quote = !in_quote;
206 ptr++;
210 *lasts = ptr;
212 return (str);
216 * dsym_get_long(): given a numeric string, returns its long value
218 * input: const char *: the numeric string
219 * long *: the return location for the long value
220 * output: DSYM_SUCCESS, DSYM_VALUE_OUT_OF_RANGE or DSYM_SYNTAX_ERROR
223 static dsym_errcode_t
224 dsym_get_long(const char *str, long *val)
227 int ret = DSYM_SUCCESS;
228 int i;
230 for (i = 0; str[i] != '\0'; i++) {
231 if (!isdigit(str[i])) {
232 return (DSYM_SYNTAX_ERROR);
236 errno = 0;
237 *val = strtol(str, NULL, 10);
238 if (errno != 0) {
239 ret = DSYM_VALUE_OUT_OF_RANGE;
242 return (ret);
246 * dsym_free_classes(): frees the classes allocated by dsym_parse_classes()
248 * input: dhcp_classes_t *: pointer to structure containing classes to free
249 * output: none
252 void
253 dsym_free_classes(dhcp_classes_t *classes)
256 int i;
258 if (classes->dc_names == NULL) {
259 return;
262 for (i = 0; i < classes->dc_cnt; i++) {
263 free(classes->dc_names[i]);
266 free(classes->dc_names);
267 classes->dc_names = NULL;
268 classes->dc_cnt = 0;
272 * dsym_parse_classes(): given a "Vendor" class string, builds and returns
273 * the list of vendor classes
275 * input: char *: the "Vendor" class string
276 * dhcp_classes_t *: pointer to the classes structure
277 * output: DSYM_SUCCESS, DSYM_INVALID_CAT, DSYM_EXCEEDS_MAX_CLASS_SIZE,
278 * DSYM_EXCEEDS_CLASS_SIZE, DSYM_SYNTAX_ERROR, or DSYM_NO_MEMORY
281 static dsym_errcode_t
282 dsym_parse_classes(char *ptr, dhcp_classes_t *classes_ret)
285 char **classes = NULL;
286 char *cp;
287 int len;
288 int ret = DSYM_SUCCESS;
289 int i;
291 while (*ptr != '\0') {
292 if (*ptr == DSYM_VENDOR_DEL) {
293 ptr++;
294 break;
296 ptr++;
299 if (*ptr == '\0') {
300 return (DSYM_INVALID_CAT);
303 if (strlen(ptr) > DSYM_MAX_CLASS_SIZE) {
304 return (DSYM_EXCEEDS_MAX_CLASS_SIZE);
307 dsym_trim(&ptr);
308 classes_ret->dc_cnt = 0;
309 for (i = 0; ret == DSYM_SUCCESS; i++) {
310 cp = dsym_get_token(ptr, DSYM_CLASS_DEL, &ptr, B_TRUE);
311 if (cp == NULL) {
312 break;
315 len = strlen(cp);
317 if (len == 0) {
318 continue;
319 } else if (len > DSYM_CLASS_SIZE) {
320 ret = DSYM_EXCEEDS_CLASS_SIZE;
321 continue;
324 if (cp[0] == DSYM_QUOTE && cp[len-1] != DSYM_QUOTE) {
325 ret = DSYM_SYNTAX_ERROR;
326 continue;
329 /* Strip off the quotes */
330 if (cp[0] == DSYM_QUOTE) {
331 cp[len-1] = '\0';
332 cp++;
335 classes = reallocarray(classes_ret->dc_names,
336 classes_ret->dc_cnt + 1, sizeof (char **));
337 if (classes == NULL ||
338 (classes[classes_ret->dc_cnt] = strdup(cp))
339 == NULL) {
340 ret = DSYM_NO_MEMORY;
341 continue;
343 classes_ret->dc_names = classes;
344 classes_ret->dc_cnt++;
347 if (ret != DSYM_SUCCESS) {
348 dsym_free_classes(classes_ret);
351 return (ret);
355 * dsym_get_cat_by_name(): given a category field, returns the pointer to its
356 * entry in the internal category table.
358 * input: const char *: the category name
359 * dsym_cat_t *: the return location for the pointer to the table entry
360 * boolean_t: case-sensitive name compare
361 * output: int: DSYM_SUCCESS or DSYM_INVALID_CAT
364 static dsym_errcode_t
365 dsym_get_cat_by_name(const char *cat, dsym_cat_t **entry, boolean_t cs)
368 dsym_cat_t *entryp = NULL;
369 int ret = DSYM_SUCCESS;
370 int cnt = sizeof (cats) / sizeof (dsym_cat_t);
371 int result;
372 int len;
373 int i;
375 for (i = 0; i < cnt; i++) {
377 len = cats[i].dc_minlen;
378 if (cs) {
379 result = strncmp(cat, cats[i].dc_string, len);
380 } else {
381 result = strncasecmp(cat, cats[i].dc_string, len);
384 if (result == 0) {
385 entryp = &cats[i];
386 break;
390 if (entryp != NULL) {
392 * Special code required for the Vendor category, because we
393 * allow whitespace between the keyword and the delimiter.
394 * If there is no delimiter, then this is an illegal category.
396 const char *ptr = cat + entryp->dc_minlen;
397 if (entryp->dc_id == DSYM_VENDOR) {
398 while (*ptr != '\0' && isspace(*ptr)) {
399 ptr++;
401 if (*ptr != DSYM_VENDOR_DEL) {
402 ret = DSYM_INVALID_CAT;
404 } else {
405 if (*ptr != '\0') {
406 ret = DSYM_INVALID_CAT;
409 } else {
410 ret = DSYM_INVALID_CAT;
413 if (ret == DSYM_SUCCESS) {
414 *entry = entryp;
417 return (ret);
421 * dsym_parse_cat(): given a category field, returns the category value
422 * Note: The category must be a valid dhcptab category.
424 * input: const char *: a category field
425 * dsym_category_t *: the return location for the category value
426 * output: int: DSYM_SUCCESS or DSYM_INVALID_CAT
429 static dsym_errcode_t
430 dsym_parse_cat(const char *field, dsym_category_t *cat)
433 dsym_cat_t *entry;
434 int ret;
436 ret = dsym_get_cat_by_name(field, &entry, B_TRUE);
437 if (ret == DSYM_SUCCESS) {
439 * Since this routine is meant to be used to parse dhcptab
440 * symbol definitions, only a subset of the DHCP categories
441 * are valid in this context.
443 if (entry->dc_dhcptab) {
444 *cat = entry->dc_id;
445 } else {
446 ret = DSYM_INVALID_CAT;
450 return (ret);
454 * dsym_parse_intrange(): given a DHCP integer field, returns the value
456 * input: const char *: a DHCP code field
457 * int *: the return location for the value
458 * int: the minimum valid value
459 * int: the maximum valid value
460 * output: int: DSYM_SUCCESS, DSYM_SYNTAX_ERROR, or DSYM_VALUE_OUT_OF_RANGE
463 static dsym_errcode_t
464 dsym_parse_intrange(const char *field, int *intval, int min, int max)
467 int ret;
468 long longval;
470 ret = dsym_get_long(field, &longval);
471 if (ret == DSYM_SUCCESS) {
472 if (longval < min || longval > max) {
473 ret = DSYM_VALUE_OUT_OF_RANGE;
474 } else {
475 *intval = (int)longval;
478 return (ret);
482 * dsym_validate_code(): given a symbol category and code, validates
483 * that the code is valid for the category
485 * input: dsym_category_t: the symbol category
486 * uint16_t: the symbol code
487 * output: DSYM_SUCCESS, DSYM_INVALID_CAT or DSYM_CODE_OUT_OF_RANGE
490 static dsym_errcode_t
491 dsym_validate_code(dsym_category_t cat, ushort_t code)
494 int cnt = sizeof (cats) / sizeof (dsym_cat_t);
495 int i;
498 * Find the category entry from the internal table.
500 for (i = 0; i < cnt; i++) {
501 dsym_cat_t *entry;
502 if (cat == cats[i].dc_id) {
503 entry = &cats[i];
504 if (code < entry->dc_min || code > entry->dc_max) {
505 return (DSYM_CODE_OUT_OF_RANGE);
507 return (DSYM_SUCCESS);
511 return (DSYM_INVALID_CAT);
515 * dsym_validate_granularity(): given a symbol type, validates
516 * that the granularity is valid for the type
518 * input: dsym_cdtype_t: the symbol type
519 * uchar_t: the symbol granularity
520 * output: DSYM_SUCCESS or DSYM_VALUE_OUT_OF_RANGE
523 static dsym_errcode_t
524 dsym_validate_granularity(dsym_cdtype_t type, uchar_t gran)
527 * We only need to check for a 0 with non-boolean types, as
528 * anything else is already validated by the ranges passed to
529 * dsym_parse_intrange() in dsym_parse_field().
531 if (gran == 0 && type != DSYM_BOOL) {
532 return (DSYM_VALUE_OUT_OF_RANGE);
534 return (DSYM_SUCCESS);
538 * dsym_get_type_by_name(): given a type field, returns the pointer to its
539 * entry in the internal type table.
541 * input: const char *: the type name
542 * dsym_type_t *: the return location for the pointer to the table entry
543 * boolean_t: case-sensitive name compare
544 * output: int: DSYM_SUCCESS or DSYM_INVALID_TYPE
547 static dsym_errcode_t
548 dsym_get_type_by_name(const char *type, dsym_type_t **entry, boolean_t cs)
550 int cnt = sizeof (types) / sizeof (dsym_type_t);
551 int result;
552 int i;
554 for (i = 0; i < cnt; i++) {
556 if (cs) {
557 result = strcmp(type, types[i].dt_string);
558 } else {
559 result = strcasecmp(type, types[i].dt_string);
562 if (result == 0) {
563 *entry = &types[i];
564 return (DSYM_SUCCESS);
568 return (DSYM_INVALID_TYPE);
572 * dsym_parse_type(): given a DHCP type string, returns the type id
574 * input: char *: a DHCP type string
575 * dsym_cdtype_t *: the return location for the type id
576 * output: int: DSYM_SUCCESS or DSYM_INVALID_TYPE
579 static dsym_errcode_t
580 dsym_parse_type(char *field, dsym_cdtype_t *type)
583 dsym_type_t *entry;
584 int ret;
586 ret = dsym_get_type_by_name(field, &entry, B_TRUE);
587 if (ret == DSYM_SUCCESS) {
589 * Since this routine is meant to be used to parse dhcptab
590 * symbol definitions, only a subset of the DHCP type
591 * are valid in this context.
593 if (entry->dt_dhcptab) {
594 *type = entry->dt_id;
595 } else {
596 ret = DSYM_INVALID_TYPE;
600 return (ret);
604 * dsym_free_fields(): frees an array of fields allocated by
605 * dsym_init_parser().
607 * input: char **: array of fields to free
608 * output: none
611 void
612 dsym_free_fields(char **fields)
614 int i;
615 if (fields != NULL) {
616 for (i = 0; i < DSYM_NUM_FIELDS; i++) {
617 free(fields[i]);
619 free(fields);
624 * dsym_close_parser(): free up all resources associated with the parser
626 * input: char **: the fields allocated by dsym_init_parser()
627 * dhcp_symbol_t *: the structure populated by dsym_init_parser()
628 * output: none
631 void
632 dsym_close_parser(char **fields, dhcp_symbol_t *sym)
634 dsym_free_fields(fields);
635 dsym_free_classes(&sym->ds_classes);
639 * dsym_init_parser(): initializes the structures used to parse a symbol
640 * value.
642 * input: const char *: the symbol name
643 * const char *: the symbol value in dhcptab format
644 * char ***: the return location for the symbol fields
645 * dhcp_symbol_t *: the structure which eventually will
646 * be the repository for the parsed symbol data
647 * output: int: DSYM_SUCCESS, DYSM_NO_MEMORY, DSYM_NULL_FIELD or
648 * DSYM_TOO_MANY_FIELDS
651 dsym_errcode_t
652 dsym_init_parser(const char *name, const char *value, char ***fields_ret,
653 dhcp_symbol_t *sym)
656 int ret = DSYM_SUCCESS;
657 char *cp;
658 char *next;
659 char *field;
660 char **fields;
661 int i;
664 * Initialize the symbol structure.
666 sym->ds_category = 0;
667 sym->ds_code = 0;
668 (void) strlcpy(sym->ds_name, name, DSYM_MAX_SYM_LEN);
669 sym->ds_type = 0;
670 sym->ds_gran = 0;
671 sym->ds_max = 0;
672 sym->ds_classes.dc_names = NULL;
673 sym->ds_classes.dc_cnt = 0;
675 if ((cp = strdup(value)) == NULL ||
676 (fields = calloc(DSYM_NUM_FIELDS, sizeof (char *))) == NULL) {
677 ret = DSYM_NO_MEMORY;
680 next = cp;
681 for (i = 0; ret == DSYM_SUCCESS && i < DSYM_NUM_FIELDS; i++) {
683 field = dsym_get_token(next, DSYM_FIELD_DEL, &next,
684 B_FALSE);
686 if (field == NULL) {
687 ret = DSYM_NULL_FIELD;
688 continue;
691 dsym_trim(&field);
693 if (strlen(field) == 0) {
694 ret = DSYM_NULL_FIELD;
695 continue;
698 if ((fields[i] = strdup(field)) == NULL) {
699 ret = DSYM_NO_MEMORY;
700 continue;
704 if (ret == DSYM_SUCCESS &&
705 dsym_get_token(next, DSYM_FIELD_DEL, &next, B_FALSE) != NULL) {
706 ret = DSYM_TOO_MANY_FIELDS;
709 if (ret != DSYM_SUCCESS) {
710 dsym_free_fields(fields);
711 } else {
712 *fields_ret = fields;
715 free(cp);
716 return (ret);
720 * dsym_parse_field(): parses the specified symbol field.
722 * input: int: the field number to be parsed.
723 * char **: symbol fields initialized by dsym_init_parser()
724 * dhcp_symbol_t *: the structure which will be the repository
725 * for the parsed field
726 * output: int: DSYM_SUCCESS, DSYM_SYNTAX_ERROR, DSYM_CODE_OUT_OF_RANGE,
727 * DSYM_INVALID_CAT, DSYM_INVALID_TYPE, DSYM_EXCEEDS_CLASS_SIZE,
728 * DSYM_EXCEEDS_MAX_CLASS_SIZE, DSYM_NO_MEMORY,
729 * DSYM_INVALID_FIELD_NUM, DSYM_VALUE_OUT_OF_RANGE
732 dsym_errcode_t
733 dsym_parse_field(int field_num, char **fields, dhcp_symbol_t *sym)
736 int ret = DSYM_SUCCESS;
737 int intval;
739 switch (field_num) {
741 case DSYM_CAT_FIELD:
742 ret = dsym_parse_cat(fields[field_num], &sym->ds_category);
743 if (ret == DSYM_SUCCESS && sym->ds_category == DSYM_VENDOR) {
744 ret = dsym_parse_classes(fields[field_num],
745 &sym->ds_classes);
747 break;
749 case DSYM_CODE_FIELD:
750 ret = dsym_parse_intrange(fields[field_num], &intval, 0,
751 USHRT_MAX);
752 if (ret == DSYM_SUCCESS) {
753 sym->ds_code = (ushort_t)intval;
754 ret = dsym_validate_code(sym->ds_category,
755 sym->ds_code);
757 break;
759 case DSYM_TYPE_FIELD:
760 ret = dsym_parse_type(fields[field_num], &sym->ds_type);
761 break;
763 case DSYM_GRAN_FIELD:
764 ret = dsym_parse_intrange(fields[field_num], &intval, 0,
765 UCHAR_MAX);
766 if (ret == DSYM_SUCCESS) {
767 sym->ds_gran = (uchar_t)intval;
768 ret = dsym_validate_granularity(sym->ds_type,
769 sym->ds_gran);
771 break;
773 case DSYM_MAX_FIELD:
774 ret = dsym_parse_intrange(fields[field_num], &intval, 0,
775 UCHAR_MAX);
776 if (ret == DSYM_SUCCESS) {
777 sym->ds_max = (uchar_t)intval;
779 break;
780 default:
781 ret = DSYM_INVALID_FIELD_NUM;
784 return (ret);
788 * dsym_parser(): parses a DHCP symbol value
790 * input: char **: symbol fields initialized by dsym_init_parser()
791 * dhcp_symbol_t *: the structure which will be the repository
792 * for the parsed field
793 * int *: last field processed
794 * boolean_t: parse all fields even though errors occur?
795 * output: int: DSYM_SUCCESS, DSYM_SYNTAX_ERROR, DSYM_CODE_OUT_OF_RANGE,
796 * DSYM_INVALID_CAT, DSYM_INVALID_TYPE, DSYM_EXCEEDS_CLASS_SIZE,
797 * DSYM_EXCEEDS_MAX_CLASS_SIZE, DSYM_NO_MEMORY
798 * DSYM_INVALID_FIELD_NUM, DSYM_VALUE_OUT_OF_RANGE
801 dsym_errcode_t
802 dsym_parser(char **fields, dhcp_symbol_t *sym, int *lastField,
803 boolean_t bestEffort)
806 int ret = DSYM_SUCCESS;
807 int tret = DSYM_SUCCESS;
808 int i;
810 *lastField = -1;
811 for (i = DSYM_FIRST_FIELD;
812 tret == DSYM_SUCCESS && i < DSYM_NUM_FIELDS; i++) {
814 tret = dsym_parse_field(i, fields, sym);
815 if (tret != DSYM_SUCCESS) {
816 if (ret == DSYM_SUCCESS) {
817 ret = tret;
819 if (bestEffort) {
820 *lastField = i;
821 tret = DSYM_SUCCESS;
826 if (*lastField == -1) {
827 *lastField = i - 1;
830 return (ret);
834 * dsym_get_cat_id(): given a category string, return the associated id.
836 * input: const char *: the category name
837 * dsym_category_t *: the return location for the id
838 * boolean_t: case-sensitive name compare
839 * output: int: DSYM_SUCCESS or DSYM_INVALID_CAT
842 dsym_errcode_t
843 dsym_get_cat_id(const char *cat, dsym_category_t *id, boolean_t cs)
846 dsym_cat_t *entry;
847 int ret;
849 ret = dsym_get_cat_by_name(cat, &entry, cs);
850 if (ret == DSYM_SUCCESS) {
851 *id = entry->dc_id;
854 return (ret);
858 * dsym_get_code_ranges(): given a category field, returns its valid code
859 * ranges.
861 * input: const char *: the category name
862 * ushort *: return location for the minimum code value.
863 * ushort *: return location for the maximum code value.
864 * boolean_t: case-sensitive name compare
865 * output: int: DSYM_SUCCESS or DSYM_INVALID_CAT
868 dsym_errcode_t
869 dsym_get_code_ranges(const char *cat, ushort_t *min, ushort_t *max,
870 boolean_t cs)
873 dsym_cat_t *entry;
874 int ret;
876 ret = dsym_get_cat_by_name(cat, &entry, cs);
877 if (ret == DSYM_SUCCESS) {
878 *min = entry->dc_min;
879 *max = entry->dc_max;
882 return (ret);
886 * dsym_get_type_id(): given a type string, return the associated type id.
888 * input: const char *: the type name
889 * dsym_cdtype_t *: the return location for the id
890 * boolean_t: case-sensitive name compare
891 * output: int: DSYM_SUCCESS or DSYM_INVALID_TYPE
894 dsym_errcode_t
895 dsym_get_type_id(const char *type, dsym_cdtype_t *id, boolean_t cs)
898 dsym_type_t *entry;
899 int ret;
901 ret = dsym_get_type_by_name(type, &entry, cs);
902 if (ret == DSYM_SUCCESS) {
903 *id = entry->dt_id;
906 return (ret);