Back to index

im-sdk  12.3.91
comp-ccdef.c
Go to the documentation of this file.
00001 #include <stdio.h>
00002 #include <stdlib.h>
00003 #include <string.h>
00004 #include <sys/types.h>
00005 
00006 #include <iiimp-data.h>
00007 
00008 #include "iiimp-dataP.h"
00009 
00010 
00011 IIIMP_ccdef *
00012 iiimp_ccdef_new(
00013     IIIMP_data_s *   data_s,
00014     IIIMP_string *   contents)
00015 {
00016     IIIMP_ccdef *    ccdef;
00017 
00018     ccdef = (IIIMP_ccdef *)malloc(sizeof (IIIMP_ccdef));
00019     if (NULL == ccdef) {
00020        data_s->status = IIIMP_DATA_MALLOC_ERROR;
00021        return NULL;
00022     }
00023 
00024     if (NULL == contents) {
00025        ccdef->nbyte = 4;
00026     } else {
00027        ccdef->nbyte = contents->nbyte;
00028     }
00029 
00030     ccdef->contents = contents;
00031 
00032     return ccdef;
00033 }
00034 
00035 
00036 void
00037 iiimp_ccdef_delete(IIIMP_data_s * data_s, IIIMP_ccdef * ccdef)
00038 {
00039     if (NULL == ccdef) return;
00040     iiimp_string_delete(data_s, ccdef->contents);
00041     free(ccdef);
00042     return;
00043 
00044 }
00045 
00046 
00047 void
00048 iiimp_ccdef_pack(
00049     IIIMP_data_s *   data_s,
00050     IIIMP_ccdef *    m,
00051     size_t *         nbyte,
00052     uchar_t **              ptr)
00053 {
00054     size_t           rest;
00055     uchar_t *        p;
00056 
00057     rest = *nbyte;
00058     p = *ptr;
00059 
00060     iiimp_string_pack(data_s, m->contents, &rest, &p);
00061 
00062     *nbyte = rest;
00063     *ptr = p;
00064 
00065     return;
00066 }
00067 
00068 
00069 IIIMP_ccdef *
00070 iiimp_ccdef_unpack(
00071     IIIMP_data_s *   data_s,
00072     size_t *         nbyte,
00073     const uchar_t ** ptr,
00074     size_t           nbyte_max)
00075 {
00076     IIIMP_ccdef *    ccdef;
00077     size_t           rest;
00078     const uchar_t *  p;
00079 
00080     rest = nbyte_max;
00081     p = *ptr;
00082 
00083     if ((*nbyte < rest) || (rest < (4 + 4 + 4 + 4))) {
00084        data_s->status = IIIMP_DATA_INVALID;
00085        return NULL;
00086     }
00087 
00088     ccdef = (IIIMP_ccdef *)malloc(sizeof (IIIMP_ccdef));
00089     if (NULL == ccdef) {
00090        data_s->status = IIIMP_DATA_MALLOC_ERROR;
00091        return NULL;
00092     }
00093 
00094     ccdef->contents = iiimp_string_unpack(data_s, &rest, &p, rest);
00095     if (NULL == ccdef->contents) {
00096        free(ccdef);
00097        return NULL;
00098     }
00099 
00100     *nbyte = rest;
00101     *ptr = p;
00102 
00103     return ccdef;
00104 }
00105 
00106 
00107 void
00108 iiimp_ccdef_print(
00109     IIIMP_data_s *   data_s,
00110     IIIMP_ccdef *    m)
00111 {
00112     if (NULL == m) return;
00113 
00114     iiimp_string_print(data_s, m->contents);
00115 }
00116 
00117 
00118 /* Local Variables: */
00119 /* c-file-style: "iiim-project" */
00120 /* End: */