Back to index

im-sdk  12.3.91
im-getimvalues.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_getimvalues_new(
00014     IIIMP_data_s *   data_s,
00015     IIIMP_card16     im_id,
00016     IIIMP_card16_list *     attr_list)
00017 {
00018     IIIMP_message *  m;
00019 
00020     REQUIRE_PROTOCOL_VERSION(data_s, 3);
00021 
00022     m = (IIIMP_message *)malloc(sizeof (IIIMP_message));
00023     if (NULL == m) {
00024        data_s->status = IIIMP_DATA_MALLOC_ERROR;
00025        return NULL;
00026     }
00027     m->opcode = IM_GETIMVALUES;
00028     m->im_id = im_id;
00029     m->ic_id = -1;
00030     m->v.getimvalues.attr_list = attr_list;
00031     return m;
00032 }
00033 
00034 
00035 
00036 void
00037 iiimp_getimvalues_delete(IIIMP_data_s * data_s, IIIMP_message * m)
00038 {
00039     if (NULL == m) return;
00040     iiimp_card16_list_delete(data_s, m->v.getimvalues.attr_list);
00041     free(m);
00042     return;
00043 }
00044 
00045 
00046 uchar_t *
00047 iiimp_getimvalues_pack(
00048     IIIMP_data_s *   data_s,
00049     IIIMP_card16     im_id,
00050     IIIMP_card16_list *     attr_list,
00051     size_t *         buf_size)
00052 {
00053     size_t           nbyte;
00054     int                     length;
00055     uchar_t *        buf;
00056     size_t           rest;
00057     uchar_t *        p;
00058 
00059     nbyte = 0;
00060     nbyte += 2;      /* input method id */
00061     nbyte += 2;      /* PAD(2) */
00062     nbyte += 4;      /* byte length of data_s-attribute */
00063     nbyte += attr_list->nbyte;
00064     nbyte += PAD(nbyte);
00065 
00066     length = (nbyte >> 2);
00067     *buf_size = (1 + 3 + nbyte);
00068 
00069     buf = (uchar_t *)malloc(1 + 3 + nbyte);
00070     if (NULL == buf) {
00071        data_s->status = IIIMP_DATA_MALLOC_ERROR;
00072        return NULL;
00073     }
00074 
00075     PUT_PACKET_HEADER(buf, IM_GETIMVALUES, length);
00076 
00077     rest = nbyte;
00078     p = (buf + 4);
00079 
00080     PUTU16(im_id, rest, p, data_s->byte_swap);
00081     PUTU16(0, rest, p, data_s->byte_swap);
00082     PUTU32(attr_list->nbyte, rest, p, data_s->byte_swap);
00083     iiimp_card16_list_pack(data_s, attr_list, &rest, &p);
00084     if (0 != rest) {
00085         PUT16(0, rest, p, data_s->byte_swap);
00086     }
00087 
00088     return buf;
00089 
00090 }
00091 
00092 
00093 IIIMP_message *
00094 iiimp_getimvalues_unpack(
00095     IIIMP_data_s *   data_s,
00096     IIIMP_card7             opcode,
00097     size_t *         nbyte,
00098     const uchar_t ** ptr)
00099 {
00100     IIIMP_message *         m;
00101     IIIMP_getimvalues_v *   v;
00102     size_t                  rest;
00103     const uchar_t *         p;
00104     int                            len;
00105     int                            pad;
00106 
00107     rest = *nbyte;
00108     p = *ptr;
00109 
00110     if (rest < (2 + 2 + 4)) {
00111        data_s->status = IIIMP_DATA_INVALID;
00112        return NULL;
00113     }
00114 
00115     m = (IIIMP_message *)malloc(sizeof (IIIMP_message));
00116     if (NULL == m) {
00117        data_s->status = IIIMP_DATA_MALLOC_ERROR;
00118        return NULL;
00119     }
00120     v = &(m->v.getimvalues);
00121 
00122     m->opcode = opcode;
00123 
00124     GETU16(m->im_id, rest, p, data_s->byte_swap);
00125     m->ic_id = -1;
00126     SKIP16(rest, p);
00127     GET32(len, rest, p, data_s->byte_swap);
00128     pad = PAD2(len);
00129 
00130     if ((len < 0) || (rest < (len + pad)) || (0 != (len & 0x01))) {
00131        iiimp_getimvalues_delete(data_s, m);
00132        data_s->status = IIIMP_DATA_INVALID;
00133        return NULL;
00134     }
00135 
00136     if (0 < len) {
00137        v->attr_list = iiimp_card16_list_unpack(data_s, &rest, &p, len);
00138        if (NULL == v->attr_list) {
00139            iiimp_getimvalues_delete(data_s, m);
00140            return NULL;
00141        }
00142     } else {
00143        v->attr_list = NULL;
00144     }
00145 
00146     *nbyte = (rest - len);
00147     *ptr = (p + len);
00148 
00149     return m;
00150 }
00151 
00152 
00153 void
00154 iiimp_getimvalues_print(
00155     IIIMP_data_s *   data_s,
00156     IIIMP_message *  m)
00157 {
00158     IIIMP_getimvalues_v *   v;
00159     int                            i;
00160     int                            id;
00161     int                            id_pre;
00162     int                            id_dyn;
00163 
00164     v = &(m->v.getimvalues);
00165     iiimp_message_header_print(data_s, m->opcode, m->im_id, -1);
00166 
00167     for (i = 0; i < v->attr_list->count; i++) {
00168        id = *(v->attr_list->ptr + i);
00169        if (0x1000 & id) {
00170            id_pre = id;
00171            id_dyn = 0;
00172        } else {
00173            id_pre = iiimp_attribute_id_search(data_s, id);
00174            id_dyn = id;
00175        }
00176        (void)fprintf(data_s->print_fp, "\t%s",
00177                     imattribute_id_string_get(id_pre));
00178        if (0 != id_dyn) {
00179            (void)fprintf(data_s->print_fp, " (dynamic=%d)", id_dyn);
00180        }
00181        (void)fputc('\n', data_s->print_fp);
00182     }
00183 }
00184 
00185 
00186 /* Local Variables: */
00187 /* c-file-style: "iiim-project" */
00188 /* End: */