Back to index

im-sdk  12.3.91
im-geticvalues.c
Go to the documentation of this file.
00001 #include <stdio.h>
00002 #include <stdlib.h>
00003 #include <sys/types.h>
00004 
00005 #include <iiimp-data.h>
00006 #include <iiimp-opcode.h>
00007 
00008 #include "iiimp-dataP.h"
00009 #include "print-misc.h"
00010 
00011 
00012 IIIMP_message *
00013 iiimp_geticvalues_new(
00014     IIIMP_data_s *   data_s,
00015     IIIMP_card16     im_id,
00016     IIIMP_card16     ic_id,
00017     IIIMP_card16_list *     attr_list)
00018 {
00019     IIIMP_message *  m;
00020     m = (IIIMP_message *)malloc(sizeof (IIIMP_message));
00021     if (NULL == m) {
00022        data_s->status = IIIMP_DATA_MALLOC_ERROR;
00023        return NULL;
00024     }
00025     m->opcode = IM_GETICVALUES;
00026     m->im_id = im_id;
00027     m->ic_id = ic_id;
00028     m->v.geticvalues.attr_list = attr_list;
00029     return m;
00030 }
00031 
00032 
00033 void
00034 iiimp_geticvalues_delete(IIIMP_data_s * data_s, IIIMP_message * m)
00035 {
00036     if (NULL == m) return;
00037     iiimp_card16_list_delete(data_s, m->v.geticvalues.attr_list);
00038     free(m);
00039     return;
00040 }
00041 
00042 
00043 uchar_t *
00044 iiimp_geticvalues_pack(
00045     IIIMP_data_s *   data_s,
00046     IIIMP_card16     im_id,
00047     IIIMP_card16     ic_id,
00048     IIIMP_card16_list *     attr_list,
00049     size_t *         buf_size)
00050 {
00051     size_t           nbyte;
00052     int                     length;
00053     uchar_t *        buf;
00054     size_t           rest;
00055     uchar_t *        p;
00056 
00057     nbyte = 0;
00058     nbyte += 2;                    /* input method id */
00059     nbyte += 2;                    /* input context id */
00060     nbyte += 2;                    /* byte length of ic-attribute */
00061     nbyte += attr_list->nbyte;     /* ic-attribute */
00062     nbyte += PAD(nbyte);
00063 
00064     length = (nbyte >> 2);
00065     *buf_size = (1 + 3 + nbyte);
00066 
00067     buf = (uchar_t *)malloc(1 + 3 + nbyte);
00068     if (NULL == buf) {
00069        data_s->status = IIIMP_DATA_MALLOC_ERROR;
00070        return NULL;
00071     }
00072 
00073     PUT_PACKET_HEADER(buf, IM_GETICVALUES, length);
00074 
00075     rest = nbyte;
00076     p = (buf + 4);
00077 
00078     PUTU16(im_id, rest, p, data_s->byte_swap);
00079     PUTU16(ic_id, rest, p, data_s->byte_swap);
00080     PUTU16(attr_list->nbyte, rest, p, data_s->byte_swap);
00081     iiimp_card16_list_pack(data_s, attr_list, &rest, &p);
00082     if (0 != rest) { 
00083         PUT16(0, rest, p, data_s->byte_swap); 
00084     }
00085 
00086     return buf;
00087 }
00088 
00089 
00090 IIIMP_message *
00091 iiimp_geticvalues_unpack(
00092     IIIMP_data_s *   data_s,
00093     IIIMP_card7             opcode,
00094     size_t *         nbyte,
00095     const uchar_t ** ptr)
00096 {
00097     IIIMP_message *         m;
00098     IIIMP_geticvalues_v *   v;
00099     size_t                  rest;
00100     const uchar_t *         p;
00101     int                            len;
00102     int                            pad;
00103 
00104     rest = *nbyte;
00105     p = *ptr;
00106 
00107     if (rest < (2 + 2 + 2 +2)) {
00108        data_s->status = IIIMP_DATA_INVALID;
00109        return NULL;
00110     }
00111 
00112     m = (IIIMP_message *)malloc(sizeof (IIIMP_message));
00113     if (NULL == m) {
00114        data_s->status = IIIMP_DATA_MALLOC_ERROR;
00115        return NULL;
00116     }
00117     v = &(m->v.geticvalues);
00118 
00119     m->opcode = opcode;
00120 
00121     GETU16(m->im_id, rest, p, data_s->byte_swap);
00122     GETU16(m->ic_id, rest, p, data_s->byte_swap);
00123 
00124     GET16(len, rest, p, data_s->byte_swap);
00125     pad = PAD2(2 + len);
00126 
00127     if ((len < 0) || (rest < (len + pad)) || (0 != (len & 0x01))) {
00128        free(m);
00129        data_s->status = IIIMP_DATA_INVALID;
00130        return NULL;
00131     }
00132 
00133     if (0 < len) {
00134        v->attr_list = iiimp_card16_list_unpack(data_s, &rest, &p, len);
00135        if (NULL == v->attr_list) {
00136            free(m);
00137            return NULL;
00138        }
00139     } else {
00140        v->attr_list = NULL;
00141     }
00142 
00143     *nbyte = (rest - pad);
00144     *ptr = (p + pad);
00145 
00146     return m;
00147 }
00148 
00149 
00150 void
00151 iiimp_geticvalues_print(
00152     IIIMP_data_s *   data_s,
00153     IIIMP_message *  m)
00154 {
00155     IIIMP_geticvalues_v *   v;
00156     int                            i;
00157 
00158     v = &(m->v.geticvalues);
00159     iiimp_message_header_print(data_s, m->opcode, m->im_id, m->ic_id);
00160     for (i = 0; i < v->attr_list->count; i++) {
00161        (void)fprintf(data_s->print_fp, "\t%s\n",
00162                     icattribute_id_string_get(*(v->attr_list->ptr + i)));
00163     }
00164 }
00165 
00166 
00167 /* Local Variables: */
00168 /* c-file-style: "iiim-project" */
00169 /* End: */