Back to index

im-sdk  12.3.91
comp-client-descriptor.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_client_descriptor *
00012 iiimp_client_descriptor_new(
00013     IIIMP_data_s *   data_s,
00014     IIIMP_string *   type,
00015     IIIMP_string *   os_name,
00016     IIIMP_string *   arch,
00017     IIIMP_string *   version,
00018     IIIMP_string *   X_display_name,
00019     IIIMP_string *   X_server_vendor)
00020 {
00021     IIIMP_client_descriptor *      cd;
00022 
00023     cd = (IIIMP_client_descriptor *)malloc(sizeof (IIIMP_client_descriptor));
00024     if (NULL == cd) {
00025        data_s->status = IIIMP_DATA_MALLOC_ERROR;
00026        return NULL;
00027     }
00028 
00029     cd->nbyte = 0;
00030     if (NULL == type) {
00031        cd->nbyte += 4;
00032     } else {
00033        cd->nbyte += type->nbyte;
00034     }
00035     if (NULL == os_name) {
00036        cd->nbyte += 4;
00037     } else {
00038        cd->nbyte += os_name->nbyte;
00039     }
00040     if (NULL == arch) {
00041        cd->nbyte += 4;
00042     } else {
00043        cd->nbyte += arch->nbyte;
00044     }
00045     if (NULL == version) {
00046        cd->nbyte += 4;
00047     } else {
00048        cd->nbyte += version->nbyte;
00049     }
00050     if (NULL == X_display_name) {
00051        if (NULL != X_server_vendor) {
00052            cd->nbyte += 4;
00053        }
00054     } else {
00055        cd->nbyte += X_display_name->nbyte;
00056     }
00057     if (NULL == X_server_vendor) {
00058        if (NULL != X_display_name) {
00059            cd->nbyte += 4;
00060        }
00061     } else {
00062        cd->nbyte += X_server_vendor->nbyte;
00063     }
00064 
00065     cd->type = type;
00066     cd->os_name = os_name;
00067     cd->arch = arch;
00068     cd->version = version;
00069     cd->X_display_name = X_display_name;
00070     cd->X_server_vendor = X_server_vendor;
00071 
00072     return cd;
00073 }
00074 
00075 
00076 void
00077 iiimp_client_descriptor_delete(
00078     IIIMP_data_s *          data_s,
00079     IIIMP_client_descriptor *      cd)
00080 {
00081     if (NULL == cd) return;
00082     iiimp_string_delete(data_s, cd->type);
00083     iiimp_string_delete(data_s, cd->os_name);
00084     iiimp_string_delete(data_s, cd->arch);
00085     iiimp_string_delete(data_s, cd->version);
00086     iiimp_string_delete(data_s, cd->X_display_name);
00087     iiimp_string_delete(data_s, cd->X_server_vendor);
00088     free(cd);
00089     return;
00090 }
00091 
00092 
00093 void
00094 iiimp_client_descriptor_pack(
00095     IIIMP_data_s *          data_s,
00096     IIIMP_client_descriptor *      cd,
00097     size_t *                nbyte,
00098     uchar_t **                     ptr)
00099 {
00100     size_t    rest;
00101     uchar_t * p;
00102 
00103     rest = *nbyte;
00104     p = *ptr;
00105 
00106     iiimp_string_pack(data_s, cd->type, &rest, &p);
00107     iiimp_string_pack(data_s, cd->os_name, &rest, &p);
00108     iiimp_string_pack(data_s, cd->arch, &rest, &p);
00109     iiimp_string_pack(data_s, cd->version, &rest, &p);
00110 
00111     if (NULL != cd->X_display_name) {
00112        iiimp_string_pack(data_s, cd->X_display_name, &rest, &p);
00113     } else if (NULL != cd->X_server_vendor) {
00114        PUTU32(0, rest, p, data_s->byte_swap);
00115     }
00116     if (NULL != cd->X_server_vendor) {
00117        iiimp_string_pack(data_s, cd->X_server_vendor, &rest, &p);
00118     } else if (NULL != cd->X_display_name) {
00119        PUTU32(0, rest, p, data_s->byte_swap);
00120     }
00121 
00122     *nbyte = rest;
00123     *ptr = p;
00124 
00125     return;
00126 }
00127 
00128 
00129 IIIMP_client_descriptor *
00130 iiimp_client_descriptor_unpack(
00131     IIIMP_data_s *   data_s,
00132     size_t *         nbyte,
00133     const uchar_t ** ptr,
00134     size_t           nbyte_max)
00135 {
00136     IIIMP_client_descriptor *      cd;
00137     size_t                  rest;
00138     const uchar_t *         p;
00139 
00140     rest = nbyte_max;
00141     p = *ptr;
00142 
00143     if ((*nbyte < rest) || (rest < (4 + 4 + 4 + 4))) {
00144        data_s->status = IIIMP_DATA_INVALID;
00145        return NULL;
00146     }
00147 
00148     cd = (IIIMP_client_descriptor *)malloc(sizeof (IIIMP_client_descriptor));
00149     if (NULL == cd) {
00150        data_s->status = IIIMP_DATA_MALLOC_ERROR;
00151        return NULL;
00152     }
00153 
00154     cd->type = NULL;
00155     cd->os_name = NULL;
00156     cd->arch = NULL;
00157     cd->version = NULL;
00158     cd->X_display_name = NULL;
00159     cd->X_server_vendor = NULL;
00160 
00161     cd->type = iiimp_string_unpack(data_s, &rest, &p, rest);
00162     if (NULL == cd->type) {
00163        iiimp_client_descriptor_delete(data_s, cd);
00164        return NULL;
00165     }
00166     cd->os_name = iiimp_string_unpack(data_s, &rest, &p, rest);
00167     if (NULL == cd->os_name) {
00168        iiimp_client_descriptor_delete(data_s, cd);
00169        return NULL;
00170     }
00171     cd->arch = iiimp_string_unpack(data_s, &rest, &p, rest);
00172     if (NULL == cd->arch) {
00173        iiimp_client_descriptor_delete(data_s, cd);
00174        return NULL;
00175     }
00176     cd->version = iiimp_string_unpack(data_s, &rest, &p, rest);
00177     if (NULL == cd->version) {
00178        iiimp_client_descriptor_delete(data_s, cd);
00179        return NULL;
00180     }
00181     if (0 < rest) {
00182        cd->X_display_name = iiimp_string_unpack(data_s, &rest, &p, rest);
00183        if (NULL == cd->X_display_name) {
00184            iiimp_client_descriptor_delete(data_s, cd);
00185            return NULL;
00186        }
00187     }
00188     if (0 < rest) {
00189        cd->X_server_vendor = iiimp_string_unpack(data_s, &rest, &p, rest);
00190        if (NULL == cd->X_server_vendor) {
00191            iiimp_client_descriptor_delete(data_s, cd);
00192            return NULL;
00193        }
00194     }
00195 
00196     *nbyte -= (nbyte_max - rest);
00197     *ptr = p;
00198 
00199     return cd;
00200 }
00201 
00202 
00203 void
00204 iiimp_client_descriptor_print(
00205     IIIMP_data_s *          data_s,
00206     IIIMP_client_descriptor *      m)
00207 {
00208     if (NULL == m) return;
00209 
00210     (void)fprintf(data_s->print_fp, "\tApplication type=");
00211     iiimp_string_print(data_s, m->type);
00212     (void)fputc('\n', data_s->print_fp);
00213     (void)fprintf(data_s->print_fp, "\tOperating system name=");
00214     iiimp_string_print(data_s, m->os_name);
00215     (void)fputc('\n', data_s->print_fp);
00216     (void)fprintf(data_s->print_fp, "\tOperating system architecture=");
00217     iiimp_string_print(data_s, m->arch);
00218     (void)fputc('\n', data_s->print_fp);
00219     (void)fprintf(data_s->print_fp, "\tOperating system version=");
00220     iiimp_string_print(data_s, m->version);
00221     (void)fputc('\n', data_s->print_fp);
00222     (void)fprintf(data_s->print_fp, "\tX Display Name=");
00223     iiimp_string_print(data_s, m->X_display_name);
00224     (void)fputc('\n', data_s->print_fp);
00225     (void)fprintf(data_s->print_fp, "\tX Server Vendor=");
00226     iiimp_string_print(data_s, m->X_server_vendor);
00227     (void)fputc('\n', data_s->print_fp);
00228 }
00229 
00230 
00231 /* Local Variables: */
00232 /* c-file-style: "iiim-project" */
00233 /* End: */