Back to index

im-sdk  12.3.91
im-connect-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_connect_reply_new(
00013     IIIMP_data_s *   data_s,
00014     IIIMP_card16     im_id,
00015     IIIMP_string *   language_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_CONNECT_REPLY;
00024     m->im_id = im_id;
00025     m->ic_id = -1;
00026     m->v.connect_reply.language = language_list;
00027     return m;
00028 }
00029 
00030 
00031 void
00032 iiimp_connect_reply_delete(IIIMP_data_s * data_s, IIIMP_message * m)
00033 {
00034     if (NULL == m) return;
00035     iiimp_string_list_delete(data_s, m->v.connect_reply.language);
00036     free(m);
00037     return;
00038 }
00039 
00040 
00041 uchar_t *
00042 iiimp_connect_reply_pack(
00043     IIIMP_data_s *   data_s,
00044     IIIMP_card16     im_id,
00045     IIIMP_string *   language_list,
00046     size_t *         buf_size)
00047 {
00048     size_t           nbyte;
00049     int                     length;
00050     uchar_t *        buf;
00051     size_t           rest;
00052     uchar_t *        p;
00053     size_t           lang_nbyte;
00054     IIIMP_string *   l;
00055 
00056     nbyte = 0;
00057     nbyte += 2;      /* input method id */
00058     nbyte += 2;      /* byte length of list of language names */
00059     for (lang_nbyte = 0, l = language_list; NULL != l; l = l->next) {
00060        lang_nbyte += l->nbyte;
00061     }
00062     nbyte += lang_nbyte;    /* client auth protocol names */
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_CONNECT_REPLY, length);
00074 
00075     rest = nbyte;
00076     p = (buf + 4);
00077 
00078     PUTU16(im_id, rest, p, data_s->byte_swap);
00079     PUTU16(lang_nbyte, rest, p, data_s->byte_swap);
00080     iiimp_string_list_pack(data_s, language_list, &rest, &p);
00081 
00082     return buf;
00083 }
00084 
00085 
00086 IIIMP_message *
00087 iiimp_connect_reply_unpack(
00088     IIIMP_data_s *   data_s,
00089     IIIMP_card7             opcode,
00090     size_t *         nbyte,
00091     const uchar_t ** ptr)
00092 {
00093     IIIMP_message *         m;
00094     IIIMP_connect_reply_v * v;
00095     size_t                  rest;
00096     const uchar_t *         p;
00097     int                            len;
00098 
00099     rest = *nbyte;
00100     p = *ptr;
00101 
00102     if (rest < (2 + 2 + 4)) {
00103        data_s->status = IIIMP_DATA_INVALID;
00104        return NULL;
00105     }
00106 
00107     m = (IIIMP_message *)malloc(sizeof (IIIMP_message));
00108     if (NULL == m) {
00109        data_s->status = IIIMP_DATA_MALLOC_ERROR;
00110        return NULL;
00111     }
00112     v = &(m->v.connect_reply);
00113 
00114     m->opcode = opcode;
00115 
00116     GETU16(m->im_id, rest, p, data_s->byte_swap);
00117     m->ic_id = -1;
00118 
00119     GET16(len, rest, p, data_s->byte_swap);
00120 
00121     if ((len < 0) || (0 != (len & 0x03)) || (rest < len)) {
00122        data_s->status = IIIMP_DATA_INVALID;
00123        return NULL;
00124     }
00125 
00126     v->language = iiimp_string_list_unpack(data_s, &rest, &p, len);
00127     if (NULL == v->language) {
00128        free(m);
00129        return NULL;
00130     }
00131 
00132     *nbyte = 0;
00133     *ptr = p;
00134 
00135     return m;
00136 }
00137 
00138 
00139 void
00140 iiimp_connect_reply_print(
00141     IIIMP_data_s *   data_s,
00142     IIIMP_message *  m)
00143 {
00144     iiimp_message_header_print(data_s, m->opcode, m->im_id, -1);
00145     (void)fprintf(data_s->print_fp, "\tlanguage_list=(");
00146     iiimp_string_list_print(data_s, m->v.connect_reply.language);
00147     (void)fprintf(data_s->print_fp, ")\n");
00148 }
00149 
00150 
00151 /* Local Variables: */
00152 /* c-file-style: "iiim-project" */
00153 /* End: */