00001
00002
00003
00004
00009 #if HAVE_CONFIG_H
00010 #include <config.h>
00011 #endif
00012
00013 #include "odr-priv.h"
00014
00015 int odr_sequence_begin(ODR o, void *p, int size, const char *name)
00016 {
00017 char **pp = (char**) p;
00018
00019 if (o->error)
00020 return 0;
00021 if (o->op->t_class < 0)
00022 {
00023 o->op->t_class = ODR_UNIVERSAL;
00024 o->op->t_tag = ODR_SEQUENCE;
00025 }
00026 if (o->direction == ODR_DECODE)
00027 *pp = 0;
00028 if (odr_constructed_begin(o, p, o->op->t_class, o->op->t_tag, name))
00029 {
00030 if (o->direction == ODR_DECODE && size)
00031 *pp = (char *)odr_malloc(o, size);
00032 return 1;
00033 }
00034 else
00035 return 0;
00036 }
00037
00038 int odr_set_begin(ODR o, void *p, int size, const char *name)
00039 {
00040 char **pp = (char**) p;
00041
00042 if (o->error)
00043 return 0;
00044 if (o->op->t_class < 0)
00045 {
00046 o->op->t_class = ODR_UNIVERSAL;
00047 o->op->t_tag = ODR_SET;
00048 }
00049 if (o->direction == ODR_DECODE)
00050 *pp = 0;
00051 if (odr_constructed_begin(o, p, o->op->t_class, o->op->t_tag, name))
00052 {
00053 if (o->direction == ODR_DECODE && size)
00054 *pp = (char *)odr_malloc(o, size);
00055 return 1;
00056 }
00057 else
00058 return 0;
00059 }
00060
00061 int odr_sequence_end(ODR o)
00062 {
00063 return odr_constructed_end(o);
00064 }
00065
00066 int odr_set_end(ODR o)
00067 {
00068 return odr_constructed_end(o);
00069 }
00070
00071 static int odr_sequence_more(ODR o)
00072 {
00073 return odr_constructed_more(o);
00074 }
00075
00076 static int odr_sequence_x (ODR o, Odr_fun type, void *p, int *num)
00077 {
00078 char ***pp = (char***) p;
00079 char **tmp = 0;
00080 int size = 0, i;
00081
00082 switch (o->direction)
00083 {
00084 case ODR_DECODE:
00085 *num = 0;
00086 *pp = (char **)odr_nullval();
00087 while (odr_sequence_more(o))
00088 {
00089
00090 if (*num * (int) sizeof(void*) >= size)
00091 {
00092
00093 tmp = (char **)odr_malloc(o, sizeof(void*) *
00094 (size += size ? size : 128));
00095 if (*num)
00096 {
00097 memcpy(tmp, *pp, *num * sizeof(void*));
00098
00099
00100
00101
00102 }
00103 *pp = tmp;
00104 }
00105 if (!(*type)(o, (*pp) + *num, 0, 0))
00106 return 0;
00107 (*num)++;
00108 }
00109 break;
00110 case ODR_ENCODE: case ODR_PRINT:
00111 for (i = 0; i < *num; i++)
00112 {
00113 if (!(*type)(o, *pp + i, 0, 0))
00114 return 0;
00115 }
00116 break;
00117 default:
00118 odr_seterror(o, OOTHER, 47);
00119 return 0;
00120 }
00121 return odr_sequence_end(o);
00122 }
00123
00124 int odr_set_of(ODR o, Odr_fun type, void *p, int *num, const char *name)
00125 {
00126 if (!odr_set_begin(o, p, 0, name)) {
00127 if (o->direction == ODR_DECODE)
00128 *num = 0;
00129 return 0;
00130 }
00131 return odr_sequence_x (o, type, p, num);
00132 }
00133
00134 int odr_sequence_of(ODR o, Odr_fun type, void *p, int *num,
00135 const char *name)
00136 {
00137 if (!odr_sequence_begin(o, p, 0, name)) {
00138 if (o->direction == ODR_DECODE)
00139 *num = 0;
00140 return 0;
00141 }
00142 return odr_sequence_x (o, type, p, num);
00143 }
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153