Back to index

im-sdk  12.3.91
commit.c
Go to the documentation of this file.
00001 /*
00002   commit.c
00003 */
00004 
00005 #include <stdlib.h>
00006 #include "iiimcfint.h"
00007 
00008 IIIMF_status
00009 iiimcf_commit_string(
00010     IIIMCF_context_rec *pc,
00011     IIIMP_message *pmes
00012 )
00013 {
00014     IIIMF_status st;
00015     IIIMP_contents *pcon = pmes->v.commit_string.contents;
00016 
00017     ASSERT(pmes->opcode == IM_COMMIT_STRING);
00018 
00019     if (IIIMCF_IS_STATE_CHANGED(pc, IIIMCF_STATE_COMMIT_REQUIRED)) {
00020        /* In the same session, the server sends IM_COMMIT_STRING more than
00021           once.  We should simply concatenate the commit string.  */
00022        st = iiimcf_append_contents_to_text(&pc->committed_text, pcon);
00023        if (st != IIIMF_STATUS_SUCCESS) return st;
00024        IIIMCF_SET_STATE(pc, IIIMCF_CONTEXT_COMMITTED_TEXT_ENABLED);
00025     } else {
00026        /* First commit since the last session is initiated.  */
00027        st = iiimcf_convert_iiimp_contents_to_text(pcon, &pc->committed_text);
00028        if (st != IIIMF_STATUS_SUCCESS) return st;
00029        IIIMCF_SET_STATE(pc, IIIMCF_CONTEXT_COMMITTED_TEXT_ENABLED);
00030        IIIMCF_SET_STATE_CHANGE(pc, IIIMCF_STATE_COMMIT_REQUIRED);
00031        st = iiimcf_store_simple_event(pc, IIIMCF_EVENT_TYPE_UI_COMMIT);
00032     }
00033 
00034     return st;
00035 }
00036 
00037 IIIMF_status
00038 iiimcf_get_committed_text(
00039     IIIMCF_context context,
00040     IIIMCF_text *ptext
00041 )
00042 {
00043     IIIMCF_context_rec *pc = (IIIMCF_context_rec*) context;
00044 
00045     if (IIIMCF_IS_IC_INVALID(pc)) return IIIMF_STATUS_IC_INVALID;
00046     if ((!IIIMCF_IS_ENABLED(pc, IIIMCF_CONTEXT_COMMITTED_TEXT_ENABLED))
00047        || (!IIIMCF_IS_VALID_TEXT(&pc->committed_text)))
00048        return IIIMF_STATUS_NO_COMMITTED_TEXT;
00049 
00050     *ptext = &pc->committed_text;
00051 
00052     return IIIMF_STATUS_SUCCESS;
00053 }
00054 
00055 /* Local Variables: */
00056 /* c-file-style: "iiim-project" */
00057 /* End: */