Back to index

im-sdk  12.3.91
im-commit-string.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_commit_string_new(
00013     IIIMP_data_s *   data_s,
00014     IIIMP_card16     im_id,
00015     IIIMP_card16     ic_id,
00016     IIIMP_contents * contents)
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_COMMIT_STRING;
00025     m->im_id = im_id;
00026     m->ic_id = ic_id;
00027     m->v.commit_string.contents = contents;
00028     return m;
00029 }
00030 
00031 
00032 void
00033 iiimp_commit_string_delete(IIIMP_data_s * data_s, IIIMP_message * m)
00034 {
00035     if (NULL == m) return;
00036     iiimp_contents_delete(data_s, m->v.commit_string.contents);
00037     free(m);
00038     return;
00039 }
00040 
00041 
00042 uchar_t *
00043 iiimp_commit_string_pack(
00044     IIIMP_data_s *   data_s,
00045     IIIMP_card16     im_id,
00046     IIIMP_card16     ic_id,
00047     IIIMP_contents * contents,
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 
00056     nbyte = 0;
00057     nbyte += 2;      /* input method id */
00058     nbyte += 2;      /* input context id */
00059     nbyte += contents->nbyte;      /* forwarded string of text */
00060 
00061     length = (nbyte >> 2);
00062     *buf_size = (1 + 3 + nbyte);
00063 
00064     buf = (uchar_t *)malloc(1 + 3 + nbyte);
00065     if (NULL == buf) {
00066        data_s->status = IIIMP_DATA_MALLOC_ERROR;
00067        return NULL;
00068     }
00069 
00070     PUT_PACKET_HEADER(buf, IM_COMMIT_STRING, length);
00071 
00072     rest = nbyte;
00073     p = (buf + 4);
00074 
00075     PUTU16(im_id, rest, p, data_s->byte_swap);
00076     PUTU16(ic_id, rest, p, data_s->byte_swap);
00077     iiimp_contents_pack(data_s, contents, &rest, &p);
00078 
00079     return buf;
00080 }
00081 
00082 
00083 IIIMP_message *
00084 iiimp_commit_string_unpack(
00085     IIIMP_data_s *   data_s,
00086     IIIMP_card7             opcode,
00087     size_t *         nbyte,
00088     const uchar_t ** ptr)
00089 {
00090     IIIMP_message *  m;
00091     size_t           rest;
00092     const uchar_t *  p;
00093 
00094     rest = *nbyte;
00095     p = *ptr;
00096 
00097     if (rest < (2 + 2 + 4)) {
00098        data_s->status = IIIMP_DATA_INVALID;
00099        return NULL;
00100     }
00101 
00102     m = (IIIMP_message *)malloc(sizeof (IIIMP_message));
00103     if (NULL == m) {
00104        data_s->status = IIIMP_DATA_MALLOC_ERROR;
00105        return NULL;
00106     }
00107 
00108     m->opcode = opcode;
00109 
00110     GETU16(m->im_id, rest, p, data_s->byte_swap);
00111     GETU16(m->ic_id, rest, p, data_s->byte_swap);
00112 
00113     m->v.commit_string.contents =
00114        iiimp_contents_unpack(data_s, &rest, &p, rest);
00115     if (NULL == m->v.commit_string.contents) {
00116        free(m);
00117        return NULL;
00118     }
00119 
00120     *nbyte = rest;
00121     *ptr = p;
00122 
00123     return m;
00124 }
00125 
00126 
00127 void
00128 iiimp_commit_string_print(
00129     IIIMP_data_s *   data_s,
00130     IIIMP_message *  m)
00131 {
00132     iiimp_message_header_print(data_s, m->opcode, m->im_id, m->ic_id);
00133     iiimp_contents_print(data_s, m->v.commit_string.contents);
00134 }
00135 
00136 
00137 /* Local Variables: */
00138 /* c-file-style: "iiim-project" */
00139 /* End: */