Back to index

im-sdk  12.3.91
data-util.c
Go to the documentation of this file.
00001 #include <stdlib.h>
00002 #include <string.h>
00003 
00004 #include <iiimp.h>
00005 
00006 #include "input-method.h"
00007 
00008 
00009 IIIMF_status
00010 iiimf_data_string_ascii_new(
00011     IIIMP_data_s *   data_s,
00012     const char *     ptr,
00013     IIIMP_string **  ret)
00014 {
00015     IIIMP_string *   str;
00016     IIIMP_card16 *   p;
00017     size_t           len;
00018     size_t           nbyte;
00019     int                     i;
00020 
00021     len = strlen(ptr);
00022     nbyte = ((sizeof (IIIMP_card16)) * len);
00023 
00024     p = (IIIMP_card16 *)malloc(nbyte);
00025     if (NULL == p) return IIIMF_STATUS_MALLOC;
00026 
00027     for (i = 0; i < len; i++) {
00028        *(p + i) = *(ptr + i);
00029     }
00030 
00031     str = iiimp_string_new(data_s, len, p);
00032     free(p);
00033 
00034     if (NULL == str) {
00035        return IIIMF_STATUS_FAIL;
00036     }
00037 
00038     *ret = str;
00039     return IIIMF_STATUS_SUCCESS;
00040 }
00041 
00042 
00043 IIIMF_status
00044 iiimf_data_im_connect(IIIMF_im * im, IIIMP_message ** message_ret)
00045 {
00046     IIIMF_status     status;
00047     IIIMP_message *  message;
00048     IIIMP_string *   user_name;
00049     IIIMP_string *   auth;
00050     int                     len;
00051     char *           user;
00052     char *           password;
00053     int                     user_name_len;
00054     int                     node_len;
00055     char *           p;
00056 
00057     if (IIIMF_ROLE_CLIENT != im->role) return IIIMF_STATUS_ROLE;
00058 
00059     status = iiimf_role_data_client_auth_password(im, &password);
00060     if (IIIMF_STATUS_SUCCESS != status) return status;
00061 
00062     user_name_len = strlen(im->role_data.client->user_name);
00063     node_len = strlen(im->role_data.client->node);
00064 
00065     len = (user_name_len + 1 + node_len + 1 + strlen(password));
00066     user = (char *)malloc(len + 1);
00067     if (NULL == user) {
00068        free(password);
00069        return IIIMF_STATUS_MALLOC;
00070     }
00071 
00072     p = user;
00073     (void)strcpy(p, im->role_data.client->user_name);
00074     p += user_name_len;
00075     *p = '@';
00076     p += 1;
00077     (void)strcpy(p, im->role_data.client->node);
00078     p += node_len;
00079     *p = '#';
00080     p += 1;
00081     (void)strcpy(p, password);
00082 
00083     free(password);
00084 
00085     status = iiimf_data_string_ascii_new(im->data_s, user, &user_name);
00086     free(user);
00087     if (IIIMF_STATUS_SUCCESS != status) {
00088        return status;
00089     }
00090 
00091     auth = NULL;
00092 
00093     message = iiimp_connect_new(im->data_s, user_name, auth);
00094 
00095     if (NULL == message) {
00096        iiimp_string_delete(im->data_s, user_name);
00097        return IIIMF_STATUS_FAIL;
00098     }
00099 
00100     *message_ret = message;
00101 
00102     return IIIMF_STATUS_SUCCESS;
00103 }
00104 
00105 
00106 IIIMF_status
00107 iiimf_data_client_descriptor(IIIMF_im * im, IIIMP_client_descriptor ** data_ret)
00108 {
00109     IIIMP_data_s *          data_s;
00110     IIIMF_status            s_type;
00111     IIIMF_status            s_os_n;
00112     IIIMF_status            s_os_a;
00113     IIIMF_status            s_os_v;
00114     IIIMF_status            s_X_dn;
00115     IIIMF_status            s_X_sv;
00116     IIIMP_client_descriptor *      data;
00117     IIIMP_string *          type;
00118     IIIMP_string *          os_name;
00119     IIIMP_string *          os_arch;
00120     IIIMP_string *          os_ver;
00121     IIIMP_string *          X_display_name;
00122     IIIMP_string *          X_server_vendor;
00123     IIIMF_role_data_client *       cl;
00124 
00125     if (1 != im->role) return IIIMF_STATUS_ROLE;
00126 
00127     data = NULL;
00128 
00129     s_X_dn = IIIMF_STATUS_SUCCESS;
00130     s_X_sv = IIIMF_STATUS_SUCCESS;
00131     X_display_name = NULL;
00132     X_server_vendor = NULL;
00133 
00134     cl = im->role_data.client;
00135 
00136     data_s = im->data_s;
00137 
00138     s_type = iiimf_data_string_ascii_new(data_s, cl->type, &type);
00139     s_os_n = iiimf_data_string_ascii_new(data_s, cl->os_name, &os_name);
00140     s_os_a = iiimf_data_string_ascii_new(data_s, cl->os_arch, &os_arch);
00141     s_os_v = iiimf_data_string_ascii_new(data_s, cl->os_version, &os_ver);
00142     if ((NULL != cl->X_display_name) && (NULL != cl->X_server_vendor)) {
00143        s_X_dn = iiimf_data_string_ascii_new(data_s,
00144                                         cl->X_display_name,
00145                                         &X_display_name);
00146        s_X_sv = iiimf_data_string_ascii_new(data_s,
00147                                         cl->X_server_vendor,
00148                                         &X_server_vendor);
00149     }
00150 
00151     data = iiimp_client_descriptor_new(im->data_s,
00152                                    type, os_name, os_arch, os_ver,
00153                                    X_display_name, X_server_vendor);
00154 
00155     if ((IIIMF_STATUS_SUCCESS != s_type) ||
00156        (IIIMF_STATUS_SUCCESS != s_os_n) ||
00157        (IIIMF_STATUS_SUCCESS != s_os_a) ||
00158        (IIIMF_STATUS_SUCCESS != s_os_v) ||
00159        (IIIMF_STATUS_SUCCESS != s_X_dn) ||
00160        (IIIMF_STATUS_SUCCESS != s_X_sv) ||
00161        (NULL == data)) {
00162        iiimp_string_delete(data_s, type);
00163        iiimp_string_delete(data_s, os_name);
00164        iiimp_string_delete(data_s, os_arch);
00165        iiimp_string_delete(data_s, os_ver);
00166        iiimp_string_delete(data_s, X_display_name);
00167        iiimp_string_delete(data_s, X_server_vendor);
00168        return IIIMF_STATUS_FAIL;
00169     }
00170 
00171     *data_ret = data;
00172 
00173     return IIIMF_STATUS_SUCCESS;
00174 }
00175 
00176 
00177 /* Local Variables: */
00178 /* c-file-style: "iiim-project" */
00179 /* End: */