Back to index

im-sdk  12.3.91
im-seticvalues.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_seticvalues_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_SETICVALUES;
00025     m->im_id = im_id;
00026     m->ic_id = ic_id;
00027     m->v.seticvalues.attr_list = attr_list;
00028     return m;
00029 }
00030 
00031 
00032 void
00033 iiimp_seticvalues_delete(IIIMP_data_s * data_s, IIIMP_message * m)
00034 {
00035     if (NULL == m) return;
00036     iiimp_icattribute_list_delete(data_s, m->v.seticvalues.attr_list);
00037     free(m);
00038     return;
00039 }
00040 
00041 
00042 uchar_t *
00043 iiimp_seticvalues_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 += 2;      /* PAD(2) */
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_SETICVALUES, 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     PUTU16(0, rest, p, data_s->byte_swap);
00087 
00088     return buf;
00089 }
00090 
00091 
00092 IIIMP_message *
00093 iiimp_seticvalues_unpack(
00094     IIIMP_data_s *   data_s,
00095     IIIMP_card7             opcode,
00096     size_t *         nbyte,
00097     const uchar_t ** ptr)
00098 {
00099     IIIMP_message *         m;
00100     IIIMP_seticvalues_v *   v;
00101     size_t                  rest;
00102     const uchar_t *         p;
00103     int                            len;
00104 
00105     rest = *nbyte;
00106     p = *ptr;
00107 
00108     if (rest < (2 + 2 + 4)) {
00109        data_s->status = IIIMP_DATA_INVALID;
00110        return NULL;
00111     }
00112 
00113     m = (IIIMP_message *)malloc(sizeof (IIIMP_message));
00114     if (NULL == m) {
00115        data_s->status = IIIMP_DATA_MALLOC_ERROR;
00116        return NULL;
00117     }
00118     v = &(m->v.seticvalues);
00119 
00120     m->opcode = opcode;
00121 
00122     GETU16(m->im_id, rest, p, data_s->byte_swap);
00123     GETU16(m->ic_id, rest, p, data_s->byte_swap);
00124 
00125     GETU16(len, rest, p, data_s->byte_swap);
00126     if ((len < 0) || (rest < (len + 2)) || (0 != (len & 0x03))) {
00127        free(m);
00128        data_s->status = IIIMP_DATA_INVALID;
00129        return NULL;
00130     }
00131 
00132     if (0 < len) {
00133        v->attr_list = iiimp_icattribute_list_unpack(data_s, &rest, &p, len);
00134        if (NULL == v->attr_list) {
00135            free(m);
00136            return NULL;
00137        }
00138     } else {
00139        v->attr_list = NULL;
00140     }
00141 
00142     *nbyte = (rest - 2);
00143     *ptr = (p + 2);
00144 
00145     return m;
00146 }
00147 
00148 
00149 void
00150 iiimp_seticvalues_print(
00151     IIIMP_data_s *   data_s,
00152     IIIMP_message *  m)
00153 {
00154     iiimp_message_header_print(data_s, m->opcode, m->im_id, m->ic_id);
00155     iiimp_icattribute_list_print(data_s, m->v.seticvalues.attr_list);
00156 }
00157 
00158 
00159 /* Local Variables: */
00160 /* c-file-style: "iiim-project" */
00161 /* End: */