Back to index

im-sdk  12.3.91
im-geticvalues-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_geticvalues_reply_new(
00013     IIIMP_data_s *   data_s,
00014     IIIMP_card16     im_id,
00015     IIIMP_card16     ic_id,
00016     IIIMP_icattribute *     attr_list)
00017 {
00018     IIIMP_message *  m;
00019     m = (IIIMP_message *)malloc(sizeof (IIIMP_message));
00020     if (NULL == m) {
00021        data_s->status = IIIMP_DATA_MALLOC_ERROR;
00022        return NULL;
00023     }
00024     m->opcode = IM_GETICVALUES_REPLY;
00025     m->im_id = im_id;
00026     m->ic_id = ic_id;
00027     m->v.geticvalues_reply.attr_list = attr_list;
00028     return m;
00029 }
00030 
00031 
00032 void
00033 iiimp_geticvalues_reply_delete(IIIMP_data_s * data_s, IIIMP_message * m)
00034 {
00035     if (NULL == m) return;
00036     iiimp_icattribute_list_delete(data_s, m->v.geticvalues_reply.attr_list);
00037     free(m);
00038     return;
00039 }
00040 
00041 
00042 uchar_t *
00043 iiimp_geticvalues_reply_pack(
00044     IIIMP_data_s *   data_s,
00045     IIIMP_card16     im_id,
00046     IIIMP_card16     ic_id,
00047     IIIMP_icattribute *     attr_list,
00048     size_t *         buf_size)
00049 {
00050     size_t           nbyte;
00051     int                     length;
00052     uchar_t *        buf;
00053     size_t           rest;
00054     uchar_t *        p;
00055     size_t           attr_list_nbyte;
00056     IIIMP_icattribute *     a;
00057 
00058     nbyte = 0;
00059     nbyte += 2;                    /* input method id */
00060     nbyte += 2;                    /* input context id */
00061     nbyte += 2;                    /* byte length of ic-attribute */
00062     for (attr_list_nbyte = 0, a = attr_list; NULL != a; a = a->next) {
00063        attr_list_nbyte += a->nbyte;
00064     }
00065     nbyte += attr_list_nbyte;      /* ic-attributes */
00066     nbyte += PAD(nbyte);
00067 
00068     length = (nbyte >> 2);
00069     *buf_size = (1 + 3 + nbyte);
00070 
00071     buf = (uchar_t *)malloc(1 + 3 + nbyte);
00072     if (NULL == buf) {
00073        data_s->status = IIIMP_DATA_MALLOC_ERROR;
00074        return NULL;
00075     }
00076 
00077     PUT_PACKET_HEADER(buf, IM_GETICVALUES_REPLY, length);
00078 
00079     rest = nbyte;
00080     p = (buf + 4);
00081 
00082     PUTU16(im_id, rest, p, data_s->byte_swap);
00083     PUTU16(ic_id, rest, p, data_s->byte_swap);
00084     PUTU16(attr_list_nbyte, rest, p, data_s->byte_swap);
00085     iiimp_icattribute_list_pack(data_s, attr_list, &rest, &p);
00086     while (0 < rest) {
00087        PUTU16(0, rest, p, data_s->byte_swap);
00088     }
00089 
00090     return buf;
00091 }
00092 
00093 
00094 IIIMP_message *
00095 iiimp_geticvalues_reply_unpack(
00096     IIIMP_data_s *   data_s,
00097     IIIMP_card7             opcode,
00098     size_t *         nbyte,
00099     const uchar_t ** ptr)
00100 {
00101     IIIMP_message *         m;
00102     IIIMP_geticvalues_reply_v *    v;
00103     size_t                  rest;
00104     const uchar_t *         p;
00105     int                            len;
00106     int                            pad;
00107 
00108     rest = *nbyte;
00109     p = *ptr;
00110 
00111     if (rest < (2 + 2 + 2 + 2)) {
00112        data_s->status = IIIMP_DATA_INVALID;
00113        return NULL;
00114     }
00115 
00116     m = (IIIMP_message *)malloc(sizeof (IIIMP_message));
00117     if (NULL == m) {
00118        data_s->status = IIIMP_DATA_MALLOC_ERROR;
00119        return NULL;
00120     }
00121     v = &(m->v.geticvalues_reply);
00122 
00123     m->opcode = opcode;
00124 
00125     GETU16(m->im_id, rest, p, data_s->byte_swap);
00126     GETU16(m->ic_id, rest, p, data_s->byte_swap);
00127     GET16(len, rest, p, data_s->byte_swap);
00128 
00129     pad = PAD(len);
00130 
00131     if ((len < 0) || (rest < (len + pad)) || (0 != (len & 0x01))) {
00132        free(m);
00133        data_s->status = IIIMP_DATA_INVALID;
00134        return NULL;
00135     }
00136 
00137     if (0 < len) {
00138        v->attr_list = iiimp_icattribute_list_unpack(data_s, &rest, &p, len);
00139        if (NULL == v->attr_list) {
00140            free(m);
00141            return NULL;
00142        }
00143     } else {
00144        v->attr_list = NULL;
00145     }
00146 
00147     *nbyte = (rest - pad);
00148     *ptr = (p + pad);
00149 
00150     return m;
00151 }
00152 
00153 
00154 void
00155 iiimp_geticvalues_reply_print(
00156     IIIMP_data_s *   data_s,
00157     IIIMP_message *  m)
00158 {
00159     iiimp_message_header_print(data_s, m->opcode, m->im_id, m->ic_id);
00160     iiimp_icattribute_list_print(data_s, m->v.geticvalues_reply.attr_list);
00161 }
00162 
00163 
00164 /* Local Variables: */
00165 /* c-file-style: "iiim-project" */
00166 /* End: */