Back to index

im-sdk  12.3.91
im-getimvalues-reply.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 
00010 
00011 IIIMP_message *
00012 iiimp_getimvalues_reply_new(
00013     IIIMP_data_s *   data_s,
00014     IIIMP_card16     im_id,
00015     IIIMP_imattribute *     attr_list)
00016 {
00017     IIIMP_message *  m;
00018     m = (IIIMP_message *)malloc(sizeof (IIIMP_message));
00019     if (NULL == m) {
00020        data_s->status = IIIMP_DATA_MALLOC_ERROR;
00021        return NULL;
00022     }
00023     m->opcode = IM_GETIMVALUES_REPLY;
00024     m->im_id = im_id;
00025     m->ic_id = -1;
00026     m->v.getimvalues_reply.attr_list = attr_list;
00027     return m;
00028 }
00029 
00030 
00031 
00032 void
00033 iiimp_getimvalues_reply_delete(IIIMP_data_s * data_s, IIIMP_message * m)
00034 {
00035     if (NULL == m) return;
00036     iiimp_imattribute_list_delete(data_s, m->v.getimvalues_reply.attr_list);
00037     free(m);
00038     return;
00039 }
00040 
00041 
00042 uchar_t *
00043 iiimp_getimvalues_reply_pack(
00044     IIIMP_data_s *   data_s,
00045     IIIMP_card16     im_id,
00046     IIIMP_imattribute *     attr_list,
00047     size_t *         buf_size)
00048 {
00049     size_t           nbyte;
00050     int                     length;
00051     uchar_t *        buf;
00052     size_t           rest;
00053     uchar_t *        p;
00054     size_t           attr_list_nbyte;
00055     IIIMP_imattribute *     a;
00056 
00057     nbyte = 0;
00058     nbyte += 2;                    /* input method id */
00059     nbyte += 2;                    /* PAD(2) */
00060     nbyte += 4;                    /* byte length of data_s-attribute */
00061     for (attr_list_nbyte = 0, a = attr_list; NULL != a; a = a->next) {
00062        attr_list_nbyte += a->nbyte;
00063     }
00064     nbyte += attr_list_nbyte;      /* data_s-attributes */
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_REPLY, 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_imattribute_list_pack(data_s, attr_list, &rest, &p);
00084 
00085     return buf;
00086 }
00087 
00088 
00089 IIIMP_message *
00090 iiimp_getimvalues_reply_unpack(
00091     IIIMP_data_s *   data_s,
00092     IIIMP_card7             opcode,
00093     size_t *         nbyte,
00094     const uchar_t ** ptr)
00095 {
00096     IIIMP_message *         m;
00097     IIIMP_getimvalues_reply_v *    v;
00098     size_t                  rest;
00099     const uchar_t *         p;
00100     int                            len;
00101 
00102     rest = *nbyte;
00103     p = *ptr;
00104 
00105     if (rest < (2 + 2 + 4)) {
00106        data_s->status = IIIMP_DATA_INVALID;
00107        return NULL;
00108     }
00109 
00110     m = (IIIMP_message *)malloc(sizeof (IIIMP_message));
00111     if (NULL == m) {
00112        data_s->status = IIIMP_DATA_MALLOC_ERROR;
00113        return NULL;
00114     }
00115     v = &(m->v.getimvalues_reply);
00116 
00117     m->opcode = opcode;
00118     v->attr_list = NULL;
00119 
00120     GETU16(m->im_id, rest, p, data_s->byte_swap);
00121     m->ic_id = -1;
00122     SKIP16(rest, p);
00123 
00124     GET32(len, rest, p, data_s->byte_swap);
00125     if ((len < 0) || (rest < len) || (0 != (len & 0x03))) {
00126        iiimp_getimvalues_reply_delete(data_s, m);
00127        data_s->status = IIIMP_DATA_INVALID;
00128        return NULL;
00129     }
00130 
00131     if (0 < len) {
00132        v->attr_list = iiimp_imattribute_list_unpack(data_s, &rest, &p, len);
00133        if (NULL == v->attr_list) {
00134            iiimp_getimvalues_reply_delete(data_s, m);
00135            return NULL;
00136        }
00137     } else {
00138        v->attr_list = NULL;
00139     }
00140 
00141     *nbyte = rest;
00142     *ptr = p;
00143 
00144     return m;
00145 }
00146 
00147 
00148 void
00149 iiimp_getimvalues_reply_print(
00150     IIIMP_data_s *   data_s,
00151     IIIMP_message *  m)
00152 {
00153     iiimp_message_header_print(data_s, m->opcode, m->im_id, -1);
00154     iiimp_imattribute_list_print(data_s, m->v.getimvalues_reply.attr_list);
00155 }
00156 
00157 
00158 /* Local Variables: */
00159 /* c-file-style: "iiim-project" */
00160 /* End: */