2 * IR toolkit for tcl/tk
4 * See the file LICENSE for details.
5 * Sebastian Hammer, Adam Dickmeiss
8 * Revision 1.4 1996-05-29 06:37:42 adam
9 * Function ir_tcl_get_grs_r enhanced so that specific elements can be
12 * Revision 1.3 1996/03/05 09:21:01 adam
13 * Bug fix: memory used by GRS records wasn't freed.
14 * Rewrote some of the error handling code - the connection is always
15 * closed before failback is called.
16 * If failback is defined the send APDU methods (init, search, ...) will
17 * return OK but invoke failback (as is the case if the write operation
19 * Bug fix: ref_count in assoc object could grow if fraction of PDU was
22 * Revision 1.2 1995/09/20 11:37:01 adam
23 * Configure searches for tk4.1 and tk7.5.
26 * Revision 1.1 1995/08/29 15:38:34 adam
27 * Added grs.c. new version.
38 void ir_tcl_grs_del (IrTcl_GRS_Record **grs_record)
40 struct GRS_Record_entry *e;
45 e = (*grs_record)->entries;
46 for (i = 0; i < (*grs_record)->noTags; i++, e++)
50 case Z_StringOrNumeric_numeric:
57 case Z_ElementData_octets:
58 free (e->tagData.octets.buf);
60 case Z_ElementData_numeric:
62 case Z_ElementData_date:
63 free (e->tagData.str);
65 case Z_ElementData_ext:
67 case Z_ElementData_string:
68 free (e->tagData.str);
70 case Z_ElementData_trueOrFalse:
71 case Z_ElementData_oid:
72 case Z_ElementData_intUnit:
73 case Z_ElementData_elementNotThere:
74 case Z_ElementData_elementEmpty:
75 case Z_ElementData_noDataRequested:
76 case Z_ElementData_diagnostic:
78 case Z_ElementData_subtree:
79 ir_tcl_grs_del (&e->tagData.sub);
83 free ((*grs_record)->entries);
88 void ir_tcl_grs_mk (Z_GenericRecord *r, IrTcl_GRS_Record **grs_record)
91 struct GRS_Record_entry *e;
96 *grs_record = ir_tcl_malloc (sizeof(**grs_record));
97 if (!((*grs_record)->noTags = r->num_elements))
99 (*grs_record)->entries = NULL;
102 e = (*grs_record)->entries = ir_tcl_malloc (r->num_elements *
104 for (i = 0; i < r->num_elements; i++, e++)
110 e->tagType = *t->tagType;
113 e->tagWhich = t->tagValue->which;
114 if (t->tagValue->which == Z_StringOrNumeric_numeric)
115 e->tagVal.num = *t->tagValue->u.numeric;
117 ir_tcl_strdup (NULL, &e->tagVal.str, t->tagValue->u.string);
118 e->dataWhich = t->content->which;
120 switch (t->content->which)
122 case Z_ElementData_octets:
123 e->tagData.octets.len = t->content->u.octets->len;
124 e->tagData.octets.buf = ir_tcl_malloc (t->content->u.octets->len);
125 memcpy (e->tagData.octets.buf, t->content->u.octets->buf,
126 t->content->u.octets->len);
128 case Z_ElementData_numeric:
129 e->tagData.num = *t->content->u.numeric;
131 case Z_ElementData_date:
132 ir_tcl_strdup (NULL, &e->tagData.str, t->content->u.string);
134 case Z_ElementData_ext:
136 case Z_ElementData_string:
137 ir_tcl_strdup (NULL, &e->tagData.str, t->content->u.string);
139 case Z_ElementData_trueOrFalse:
140 e->tagData.bool = *t->content->u.trueOrFalse;
142 case Z_ElementData_oid:
144 case Z_ElementData_intUnit:
146 case Z_ElementData_elementNotThere:
147 case Z_ElementData_elementEmpty:
148 case Z_ElementData_noDataRequested:
150 case Z_ElementData_diagnostic:
152 case Z_ElementData_subtree:
153 ir_tcl_grs_mk (t->content->u.subtree, &e->tagData.sub);
159 static int ir_tcl_get_grs_r (Tcl_Interp *interp, IrTcl_GRS_Record *grs_record,
160 int argc, char **argv, int argno)
162 static char tmpbuf[32];
164 struct GRS_Record_entry *e = grs_record->entries;
166 for (i = 0; i<grs_record->noTags; i++, e++)
173 const char *cp0 = argv[argno];
174 const char *cp1 = strchr (cp0, '.');
176 if (!cp1 || cp1-cp0 < 1)
180 if (atoi(cp0) == e->tagType)
182 if (e->tagWhich == Z_StringOrNumeric_numeric)
184 if (atoi (cp1+1) == e->tagVal.num)
189 if (!strcmp (cp1+1, e->tagVal.str))
197 Tcl_AppendResult (interp, "{ ", NULL);
198 sprintf (tmpbuf, "%d", e->tagType);
199 Tcl_AppendElement (interp, tmpbuf);
201 if (e->tagWhich == Z_StringOrNumeric_numeric)
203 Tcl_AppendResult (interp, " numeric ", NULL);
204 sprintf (tmpbuf, "%d", e->tagVal.num);
205 Tcl_AppendElement (interp, tmpbuf);
209 Tcl_AppendResult (interp, " string ", NULL);
210 Tcl_AppendElement (interp, e->tagVal.str);
212 switch (e->dataWhich)
214 case Z_ElementData_octets:
215 Tcl_AppendResult (interp, " octets {} ", NULL);
217 case Z_ElementData_numeric:
218 Tcl_AppendResult (interp, " numeric ", NULL);
219 sprintf (tmpbuf, "%d", e->tagData.num);
220 Tcl_AppendElement (interp, tmpbuf);
222 case Z_ElementData_date:
223 Tcl_AppendResult (interp, " date {} ", NULL);
225 case Z_ElementData_ext:
226 Tcl_AppendResult (interp, " ext {} ", NULL);
228 case Z_ElementData_string:
229 Tcl_AppendResult (interp, " string ", NULL);
230 Tcl_AppendElement (interp, e->tagData.str);
232 case Z_ElementData_trueOrFalse:
233 Tcl_AppendResult (interp, " bool ",
234 e->tagData.bool ? "1" : "0", " ", NULL);
236 case Z_ElementData_oid:
237 Tcl_AppendResult (interp, " oid {} ", NULL);
239 case Z_ElementData_intUnit:
240 Tcl_AppendResult (interp, " intUnit {} ", NULL);
242 case Z_ElementData_elementNotThere:
243 Tcl_AppendResult (interp, " notThere {} ", NULL);
245 case Z_ElementData_elementEmpty:
246 Tcl_AppendResult (interp, " empty {} ", NULL);
248 case Z_ElementData_noDataRequested:
249 Tcl_AppendResult (interp, " notRequested {} ", NULL);
251 case Z_ElementData_diagnostic:
252 Tcl_AppendResult (interp, " diagnostic {} ", NULL);
254 case Z_ElementData_subtree:
255 Tcl_AppendResult (interp, " subtree { ", NULL);
256 ir_tcl_get_grs_r (interp, e->tagData.sub, argc, argv, argno+1);
257 Tcl_AppendResult (interp, " } ", NULL);
260 Tcl_AppendResult (interp, " } ", NULL);
265 int ir_tcl_get_grs (Tcl_Interp *interp, IrTcl_GRS_Record *grs_record,
266 int argc, char **argv)
268 return ir_tcl_get_grs_r (interp, grs_record, argc, argv, 3);