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