blob: e32ecefc4a0e2c2b3aa1774d132c7b0d93acdc3d [file] [log] [blame]
Lev Walkinf15320b2004-06-03 03:38:44 +00001/*-
Lev Walkin2c34aad2005-03-10 11:50:24 +00002 * Copyright (c) 2003, 2004, 2005 Lev Walkin <vlm@lionet.info>.
3 * All rights reserved.
Lev Walkinf15320b2004-06-03 03:38:44 +00004 * Redistribution and modifications are permitted subject to BSD license.
5 */
6#ifndef _OBJECT_IDENTIFIER_H_
7#define _OBJECT_IDENTIFIER_H_
8
Lev Walkin8e8078a2004-09-26 13:10:40 +00009#include <asn_application.h>
Lev Walkin3256d6f2004-10-21 11:22:12 +000010#include <asn_codecs_prim.h>
Lev Walkinf15320b2004-06-03 03:38:44 +000011
Lev Walkin8e8078a2004-09-26 13:10:40 +000012typedef ASN__PRIMITIVE_TYPE_t OBJECT_IDENTIFIER_t;
Lev Walkinf15320b2004-06-03 03:38:44 +000013
Lev Walkin5e033762004-09-29 13:26:15 +000014extern asn_TYPE_descriptor_t asn_DEF_OBJECT_IDENTIFIER;
Lev Walkinf15320b2004-06-03 03:38:44 +000015
Lev Walkinf15320b2004-06-03 03:38:44 +000016asn_struct_print_f OBJECT_IDENTIFIER_print;
Lev Walkina9cc46e2004-09-22 16:06:28 +000017asn_constr_check_f OBJECT_IDENTIFIER_constraint;
18der_type_encoder_f OBJECT_IDENTIFIER_encode_der;
Lev Walkin92302252004-10-23 10:16:51 +000019xer_type_decoder_f OBJECT_IDENTIFIER_decode_xer;
Lev Walkina9cc46e2004-09-22 16:06:28 +000020xer_type_encoder_f OBJECT_IDENTIFIER_encode_xer;
Lev Walkinf15320b2004-06-03 03:38:44 +000021
22/**********************************
23 * Some handy conversion routines *
24 **********************************/
25
26/*
Lev Walkinf15320b2004-06-03 03:38:44 +000027 * This function fills an (_arcs) array with OBJECT IDENTIFIER arcs
Lev Walkin29a044b2004-06-14 07:24:36 +000028 * up to specified (_arc_slots) elements.
Lev Walkinf15320b2004-06-03 03:38:44 +000029 *
30 * EXAMPLE:
31 * void print_arcs(OBJECT_IDENTIFIER_t *oid) {
32 * unsigned long fixed_arcs[10]; // Try with fixed space first
33 * unsigned long *arcs = fixed_arcs;
Lev Walkin29a044b2004-06-14 07:24:36 +000034 * int arc_type_size = sizeof(fixed_arcs[0]); // sizeof(long)
35 * int arc_slots = sizeof(fixed_arcs)/sizeof(fixed_arcs[0]); // 10
Lev Walkinf15320b2004-06-03 03:38:44 +000036 * int count; // Real number of arcs.
37 * int i;
38 *
Lev Walkin29a044b2004-06-14 07:24:36 +000039 * count = OBJECT_IDENTIFIER_get_arcs(oid, arcs,
40 * arc_type_size, arc_slots);
Lev Walkinf15320b2004-06-03 03:38:44 +000041 * // If necessary, reallocate arcs array and try again.
Lev Walkin29a044b2004-06-14 07:24:36 +000042 * if(count > arc_slots) {
43 * arc_slots = count;
44 * arcs = malloc(arc_type_size * arc_slots);
Lev Walkinf15320b2004-06-03 03:38:44 +000045 * if(!arcs) return;
Lev Walkin29a044b2004-06-14 07:24:36 +000046 * count = OBJECT_IDENTIFIER_get_arcs(oid, arcs,
47 * arc_type_size, arc_slots);
48 * assert(count == arc_slots);
Lev Walkinf15320b2004-06-03 03:38:44 +000049 * }
50 *
51 * // Print the contents of the arcs array.
52 * for(i = 0; i < count; i++)
53 * printf("%d\n", arcs[i]);
54 *
55 * // Avoid memory leak.
56 * if(arcs != fixed_arcs) free(arcs);
57 * }
58 *
59 * RETURN VALUES:
60 * -1/EINVAL: Invalid arguments (oid is missing)
61 * -1/ERANGE: One or more arcs have value out of array cell type range.
62 * >=0: Number of arcs contained in the OBJECT IDENTIFIER
Lev Walkin92302252004-10-23 10:16:51 +000063 *
64 * WARNING: The function always returns the real number of arcs,
65 * even if there is no sufficient (_arc_slots) provided.
Lev Walkinf15320b2004-06-03 03:38:44 +000066 */
Lev Walkin29a044b2004-06-14 07:24:36 +000067int OBJECT_IDENTIFIER_get_arcs(OBJECT_IDENTIFIER_t *_oid,
Lev Walkin0787ff02004-06-17 23:43:39 +000068 void *_arcs, /* i.e., unsigned int arcs[N] */
69 unsigned int _arc_type_size, /* i.e., sizeof(arcs[0]) */
70 unsigned int _arc_slots /* i.e., N */);
Lev Walkinf15320b2004-06-03 03:38:44 +000071
72/*
73 * This functions initializes the OBJECT IDENTIFIER object with
74 * the given set of arcs.
75 * The minimum of two arcs must be present; some restrictions apply.
76 * RETURN VALUES:
77 * -1/EINVAL: Invalid arguments
78 * -1/ERANGE: The first two arcs do not conform to ASN.1 restrictions.
79 * -1/ENOMEM: Memory allocation failed
80 * 0: The object was initialized with new arcs.
81 */
Lev Walkin0787ff02004-06-17 23:43:39 +000082int OBJECT_IDENTIFIER_set_arcs(OBJECT_IDENTIFIER_t *_oid,
83 void *_arcs, /* i.e., unsigned int arcs[N] */
84 unsigned int _arc_type_size, /* i.e., sizeof(arcs[0]) */
85 unsigned int _arc_slots /* i.e., N */);
Lev Walkinf15320b2004-06-03 03:38:44 +000086
87/*
Lev Walkin92302252004-10-23 10:16:51 +000088 * Print the specified OBJECT IDENTIFIER arc.
89 */
90int OBJECT_IDENTIFIER_print_arc(uint8_t *arcbuf, int arclen,
91 int add, /* Arbitrary offset, required to process the first two arcs */
92 asn_app_consume_bytes_f *cb, void *app_key);
93
94/* Same as above, but returns the number of written digits, instead of 0 */
95ssize_t OBJECT_IDENTIFIER__dump_arc(uint8_t *arcbuf, int arclen, int add,
96 asn_app_consume_bytes_f *cb, void *app_key);
97
98/*
99 * Parse the OBJECT IDENTIFIER textual representation ("1.3.6.1.4.1.9363").
100 * No arc can exceed the (0..signed_long_max) range (typically, 0..2G if L32).
101 * This function is not specific to OBJECT IDENTIFIER, it may be used to parse
102 * the RELATIVE-OID data, or any other data consisting of dot-separated
103 * series of numeric values.
104 *
105 * If (oid_txt_length == -1), the strlen() will be invoked to determine the
106 * size of the (oid_text) string.
107 *
108 * After return, the optional (oid_text_end) is set to the character after
109 * the last parsed one. (oid_text_end) is never less than (oid_text).
110 *
111 * RETURN VALUES:
112 * -1: Parse error.
113 * >= 0: Number of arcs contained in the OBJECT IDENTIFIER.
114 *
115 * WARNING: The function always returns the real number of arcs,
116 * even if there is no sufficient (_arc_slots) provided.
Lev Walkinb9c91022005-03-10 11:32:57 +0000117 * This is useful for (_arc_slots) value estimation.
Lev Walkin92302252004-10-23 10:16:51 +0000118 */
119int OBJECT_IDENTIFIER_parse_arcs(const char *oid_text, ssize_t oid_txt_length,
Lev Walkin2c34aad2005-03-10 11:50:24 +0000120 long arcs[], unsigned int arcs_slots, const char **oid_text_end);
Lev Walkin92302252004-10-23 10:16:51 +0000121
122/*
Lev Walkinf15320b2004-06-03 03:38:44 +0000123 * Internal functions.
Lev Walkin0787ff02004-06-17 23:43:39 +0000124 * Used by RELATIVE-OID implementation in particular.
Lev Walkinf15320b2004-06-03 03:38:44 +0000125 */
Lev Walkin29a044b2004-06-14 07:24:36 +0000126int OBJECT_IDENTIFIER_get_single_arc(uint8_t *arcbuf, unsigned int arclen,
127 signed int add, void *value, unsigned int value_size);
Lev Walkin0787ff02004-06-17 23:43:39 +0000128int OBJECT_IDENTIFIER_set_single_arc(uint8_t *arcbuf,
129 void *arcval, unsigned int arcval_size, int _prepared_order);
Lev Walkinf15320b2004-06-03 03:38:44 +0000130
131#endif /* _OBJECT_IDENTIFIER_H_ */