📄 nmuser.c
字号:
conf = (NMConference *) nm_request_get_data(request); nm_conference_list_remove(user, conf); } else if (strcmp("joinconf", cmd) == 0) { GSList *list = NULL, *node; conf = nm_request_get_data(request); locate = nm_locate_field(NM_A_FA_CONTACT_LIST, fields); if (locate && locate->ptr_value != 0) { field = (NMField *) locate->ptr_value; while ((field = nm_locate_field(NM_A_SZ_DN, field))) { if (field && field->ptr_value != 0) { if (nm_utf8_str_equal (nm_user_record_get_dn(user->user_record), (const char *) field->ptr_value)) { field++; continue; } user_record = nm_find_user_record(user, (const char *) field->ptr_value); if (user_record == NULL) { list = g_slist_append(list, g_strdup((char *) field->ptr_value)); } else { nm_conference_add_participant(conf, user_record); } } field++; } if (list != NULL) { done = FALSE; nm_request_set_user_define(request, list); nm_request_add_ref(request); for (node = list; node; node = node->next) { nm_send_get_details(user, (const char *) node->data, _handle_multiple_get_details_joinconf_cb, request); } } } } else if (strcmp("getdetails", cmd) == 0) { locate = nm_locate_field(NM_A_FA_RESULTS, fields); while (locate && locate->ptr_value != 0) { user_record = nm_create_user_record_from_fields(locate); if (user_record) { NMUserRecord *tmp; tmp = nm_find_user_record(user, nm_user_record_get_dn(user_record)); if (tmp) { /* Update the existing user record */ nm_user_record_copy(tmp, user_record); nm_release_user_record(user_record); user_record = tmp; } else { nm_user_add_user_record(user, user_record); nm_release_user_record(user_record); } /* Response data is new user record */ nm_request_set_data(request, (gpointer) user_record); } locate = nm_locate_field(NM_A_FA_RESULTS, locate+1); } } else if (strcmp("createfolder", cmd) == 0) { _update_contact_list(user, fields); } else if (strcmp("createcontact", cmd) == 0) { _update_contact_list(user, fields); locate = nm_locate_field(NM_A_SZ_OBJECT_ID, (NMField *) fields->ptr_value); if (locate) { NMContact *new_contact = nm_folder_find_item_by_object_id(user->root_folder, atoi((char *)locate->ptr_value)); if (new_contact) { /* Add the contact to our cache */ nm_user_add_contact(user, new_contact); /* Set the contact as the response data */ nm_request_set_data(request, (gpointer) new_contact); } } } else if (strcmp("deletecontact", cmd) == 0) { _update_contact_list(user, fields); } else if (strcmp("movecontact", cmd) == 0) { _update_contact_list(user, fields); } else if (strcmp("getstatus", cmd) == 0) { locate = nm_locate_field(NM_A_SZ_STATUS, fields); if (locate) { nm_user_record_set_status((NMUserRecord *) nm_request_get_data(request), atoi((char *) locate->ptr_value), NULL); } } else if (strcmp("updateitem", cmd) == 0) { /* Nothing extra to do here */ } else if (strcmp("createblock", cmd) == 0) { if ((locate = nm_locate_field(NM_A_BLOCKING_DENY_LIST, fields))) { if (locate->ptr_value) { user->deny_list = g_slist_append(user->deny_list, g_strdup((char *)locate->ptr_value)); } } else if ((locate = nm_locate_field(NM_A_BLOCKING_ALLOW_LIST, fields))) { if (locate->ptr_value) { user->allow_list = g_slist_append(user->allow_list, g_strdup((char *)locate->ptr_value)); } } } else if (strcmp("updateblocks", cmd) == 0) { /* nothing to do here */ } else { /* Nothing to do, just print debug message */ purple_debug(PURPLE_DEBUG_INFO, "novell", "nm_call_handler(): Unknown request command, %s\n", cmd); } } if (done && (cb = nm_request_get_callback(request))) { cb(user, ret_code, nm_request_get_data(request), nm_request_get_user_define(request)); } return rc;}static NMERR_Tnm_process_response(NMUser * user){ NMERR_T rc = NM_OK; NMField *fields = NULL; NMField *field = NULL; NMConn *conn = user->conn; NMRequest *req = NULL; rc = nm_read_header(conn); if (rc == NM_OK) { rc = nm_read_fields(conn, -1, &fields); } if (rc == NM_OK) { field = nm_locate_field(NM_A_SZ_TRANSACTION_ID, fields); if (field != NULL && field->ptr_value != 0) { req = nm_conn_find_request(conn, atoi((char *) field->ptr_value)); if (req != NULL) { rc = nm_call_handler(user, req, fields); nm_conn_remove_request_item(conn, req); } } } if (fields) nm_free_fields(&fields); return rc;}/* * Some utility functions...haven't figured out where * they belong yet. */gbooleannm_utf8_str_equal(gconstpointer str1, gconstpointer str2){ return (purple_utf8_strcasecmp(str1, str2) == 0);}char *nm_typed_to_dotted(const char *typed){ unsigned i = 0, j = 0; char *dotted; if (typed == NULL) return NULL; dotted = g_new0(char, strlen(typed)); do { /* replace comma with a dot */ if (j != 0) { dotted[j] = '.'; j++; } /* skip the type */ while (typed[i] != '\0' && typed[i] != '=') i++; /* verify that we aren't running off the end */ if (typed[i] == '\0') { dotted[j] = '\0'; break; } i++; /* copy the object name to context */ while (typed[i] != '\0' && typed[i] != ',') { dotted[j] = typed[i]; j++; i++; } } while (typed[i] != '\0'); return dotted;}const char *nm_error_to_string(NMERR_T err){ static char *unknown_msg = NULL; g_free(unknown_msg); unknown_msg = NULL; switch (err) { case NMERR_BAD_PARM: return _("Required parameters not passed in"); case NMERR_TCP_WRITE: return _("Unable to write to network"); case NMERR_TCP_READ: return _("Unable to read from network"); case NMERR_PROTOCOL: return _("Error communicating with server"); case NMERR_CONFERENCE_NOT_FOUND: case NMERR_CONFERENCE_NOT_FOUND_2: return _("Conference not found"); case NMERR_CONFERENCE_NOT_INSTANTIATED: return _("Conference does not exist"); case NMERR_DUPLICATE_FOLDER: case NMERR_FOLDER_EXISTS: return _("A folder with that name already exists"); case NMERR_NOT_SUPPORTED: return _("Not supported"); case NMERR_PASSWORD_EXPIRED: case NMERR_PASSWORD_EXPIRED_2: return _("Password has expired"); case NMERR_PASSWORD_INVALID: return _("Incorrect password"); case NMERR_USER_NOT_FOUND: return _("User not found"); case NMERR_USER_DISABLED: return _("Account has been disabled"); case NMERR_DIRECTORY_FAILURE: return _("The server could not access the directory"); case NMERR_ADMIN_LOCKED: return _("Your system administrator has disabled this operation"); case NMERR_SERVER_BUSY: return _("The server is unavailable; try again later"); case NMERR_DUPLICATE_CONTACT: return _("Cannot add a contact to the same folder twice"); case NMERR_USER_NOT_ALLOWED: return _("Cannot add yourself"); case NMERR_MASTER_ARCHIVE_MISSING: return _("Master archive is misconfigured"); case NMERR_AUTHENTICATION_FAILED: case NMERR_CREDENTIALS_MISSING: return _("Incorrect screen name or password"); case NMERR_HOST_NOT_FOUND: return _("Could not recognize the host of the screen name you entered"); case NMERR_ACCESS_DENIED: return _("Your account has been disabled because too many incorrect passwords were entered"); case NMERR_DUPLICATE_PARTICIPANT: return _("You cannot add the same person twice to a conversation"); case NMERR_TOO_MANY_CONTACTS: case NMERR_TOO_MANY_FOLDERS: return _("You have reached your limit for the number of contacts allowed"); case NMERR_OBJECT_NOT_FOUND: return _("You have entered an incorrect screen name"); case NMERR_DIRECTORY_UPDATE: return _("An error occurred while updating the directory"); case NMERR_SERVER_PROTOCOL: return _("Incompatible protocol version"); case NMERR_USER_BLOCKED: return _("The user has blocked you"); case NMERR_EVAL_CONNECTION_LIMIT: return _("This evaluation version does not allow more than ten users to log in at one time"); case NMERR_CONVERSATION_INVITE: return _("The user is either offline or you are blocked"); default: unknown_msg = g_strdup_printf (_("Unknown error: 0x%X"), err); return unknown_msg; }}static void_update_contact_list(NMUser * user, NMField * fields){ NMField *list, *cursor, *locate; gint objid1; NMContact *contact; NMFolder *folder; gpointer item; if (user == NULL || fields == NULL) return; /* Is it wrapped in a RESULTS array? */ if (strcmp(fields->tag, NM_A_FA_RESULTS) == 0) { list = (NMField *) fields->ptr_value; } else { list = fields; } /* Update the cached contact list */ cursor = (NMField *) list->ptr_value; while (cursor->tag != NULL) { if ((g_ascii_strcasecmp(cursor->tag, NM_A_FA_CONTACT) == 0) || (g_ascii_strcasecmp(cursor->tag, NM_A_FA_FOLDER) == 0)) { locate = nm_locate_field(NM_A_SZ_OBJECT_ID, (NMField *) cursor->ptr_value); if (locate != NULL && locate->ptr_value != 0) { objid1 = atoi((char *) locate->ptr_value); item = nm_folder_find_item_by_object_id(user->root_folder, objid1); if (item != NULL) { if (cursor->method == NMFIELD_METHOD_ADD) { if (g_ascii_strcasecmp(cursor->tag, NM_A_FA_CONTACT) == 0) { contact = (NMContact *) item; nm_contact_update_list_properties(contact, cursor); } else if (g_ascii_strcasecmp(cursor->tag, NM_A_FA_FOLDER) == 0) { folder = (NMFolder *) item; nm_folder_update_list_properties(folder, cursor); } } else if (cursor->method == NMFIELD_METHOD_DELETE) { if (g_ascii_strcasecmp(cursor->tag, NM_A_FA_CONTACT) == 0) { contact = (NMContact *) item; folder = nm_find_folder_by_id(user, nm_contact_get_parent_id (contact)); if (folder) { nm_folder_remove_contact(folder, contact); } } else if (g_ascii_strcasecmp(cursor->tag, NM_A_FA_FOLDER) == 0) { /* TODO: write nm_folder_remove_folder */ /* ignoring for now, should not be a big deal *//* folder = (NMFolder *) item;*//* nm_folder_remove_folder(user->root_folder, folder);*/ } } } else { if (cursor->method == NMFIELD_METHOD_ADD) { /* Not found, so we need to add it */ if (g_ascii_strcasecmp(cursor->tag, NM_A_FA_CONTACT) == 0) { const char *dn = NULL; locate = nm_locate_field(NM_A_SZ_DN, (NMField *) cursor->ptr_value); if (locate != NULL && locate->ptr_value != 0) { dn = (const char *) locate->ptr_value; if (dn != NULL) { contact = nm_create_contact_from_fields(cursor); if (contact) { nm_folder_add_contact_to_list(user-> root_folder, contact); nm_release_contact(contact); } } } } else if (g_ascii_strcasecmp(cursor->tag, NM_A_FA_FOLDER) == 0) { folder = nm_create_folder_from_fields(cursor); nm_folder_add_folder_to_list(user->root_folder, folder); nm_release_folder(folder); } } } } } cursor++; }}static char *nm_rtfize_text(char *text){ GString *gstr = NULL; unsigned char *pch; char *uni_str = NULL, *rtf = NULL; int bytes; gunichar uc; gstr = g_string_sized_new(strlen(text)*2); pch = (unsigned char *)text; while (*pch) { if ((*pch) <= 0x7F) { switch (*pch) { case '{': case '}': case '\\': gstr = g_string_append_c(gstr, '\\'); gstr = g_string_append_c(gstr, *pch); break; case '\n': gstr = g_string_append(gstr, "\\par "); break; default: gstr = g_string_append_c(gstr, *pch); break; } pch++; } else { /* convert the utf-8 character to ucs-4 for rtf encoding */ if(*pch <= 0xDF) { uc = ((((gunichar)pch[0]) & 0x001F) << 6) | (((gunichar)pch[1]) & 0x003F); bytes = 2; } else if(*pch <= 0xEF) { uc = ((((gunichar)pch[0]) & 0x000F) << 12) | ((((gunichar)pch[1]) & 0x003F) << 6) | (((gunichar)pch[2]) & 0x003F); bytes = 3; } else if (*pch <= 0xF7) { uc = ((((gunichar)pch[0]) & 0x0007) << 18) | ((((gunichar)pch[1]) & 0x003F) << 12) | ((((gunichar)pch[2]) & 0x003F) << 6) | (((gunichar)pch[3]) & 0x003F); bytes = 4; } else if (*pch <= 0xFB) { uc = ((((gunichar)pch[0]) & 0x0003) << 24) | ((((gunichar)pch[1]) & 0x003F) << 18) | ((((gunichar)pch[2]) & 0x003F) << 12) | ((((gunichar)pch[3]) & 0x003F) << 6) | (((gunichar)pch[4]) & 0x003F); bytes = 5; } else if (*pch <= 0xFD) { uc = ((((gunichar)pch[0]) & 0x0001) << 30) | ((((gunichar)pch[1]) & 0x003F) << 24) | ((((gunichar)pch[2]) & 0x003F) << 18) | ((((gunichar)pch[3]) & 0x003F) << 12) | ((((gunichar)pch[4]) & 0x003F) << 6) | (((gunichar)pch[5]) & 0x003F); bytes = 6; } else { /* should never happen ... bogus utf-8! */ purple_debug_info("novell", "bogus utf-8 lead byte: 0x%X\n", pch[0]); uc = 0x003F; bytes = 1; } uni_str = g_strdup_printf("\\u%d?", uc); purple_debug_info("novell", "unicode escaped char %s\n", uni_str); gstr = g_string_append(gstr, uni_str); pch += bytes; g_free(uni_str); } } rtf = g_strdup_printf(RTF_TEMPLATE, gstr->str); g_string_free(gstr, TRUE); return rtf;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -