/****************************************************************************** * Function: static int OpenLcxDb () * * Parameters: none * * Return Value: 0: ok * -1: error * * errno Values: * * Purpose: Opens the Ce-private Lcx database * *****************************************************************************/ int DtMail::Session::OpenLcxDb (void) { time_t time1 = 0; time_t time2 = 0; while (MyProcess == True) { /* if time out, return */ if (time(&time2) == (time_t)-1) return -1; if (time1 == 0) time1 = time2; else if (time2 - time1 >= (time_t)30) return -1; } if (MyFirst == True) { MyProcess = True; if (_DtLcxOpenAllDbs(&MyDb) == 0 && _DtXlateGetXlateEnv(MyDb,MyPlatform,&ExecVer,&CompVer) != 0) { _DtLcxCloseDb(&MyDb); MyDb = NULL; } MyFirst = False; MyProcess = False; } return (MyDb == NULL ? -1 : 0 ); }
int find_CDE_locale_name() { UserEnv *uenv = &userEnv; _DtXlateDb db = NULL; int ret = NoError; char plat[_DtPLATFORM_MAX_LEN]; int execver; int compver; static bool first = True; if (first) { uenv->CDE_locale = NULL; ret = _DtLcxOpenAllDbs(&db); if (ret == NoError) ret = _DtXlateGetXlateEnv(db, plat, &execver, &compver); if (ret == NoError) ret = _DtLcxXlateOpToStd(db, plat, compver, DtLCX_OPER_SETLOCALE, uenv->locale, &uenv->CDE_locale, NULL, NULL, NULL); if (ret == NoError) ret = _DtLcxCloseDb(&db); first = False; } return ret; }
Boolean info_lib::define_info_base( char* base_name, char* base_desc, char* spec_file_path ) { //MESSAGE(cerr, "define_info_base()"); //debug(cerr, base_name); //debug(cerr, base_desc); //debug(cerr, spec_file_path); char new_db_path[PATHSIZ]; char f_name[PATHSIZ]; char base_uid[UIDSIZ]; strcpy(new_db_path, form("%s/%s", info_lib_path, base_name)); strcpy(base_uid, unique_id()); g_mode_8_3 = 1; info_base* base = get_info_base(base_name) ; /* no checking here. DDK assures unique base name case if ( base == 0 ) { */ ////////////////////////// // check info base path ////////////////////////// if ( check_and_create_dir(new_db_path) == false ) { throw(stringException(form("bad base bath %s", new_db_path))); } ////////////////////////// // remove any old files ////////////////////////// strcpy(f_name, form("%s.%s", base_name, DATA_FILE_SUFFIX)); if ( exist_file(f_name, new_db_path) == true ) del_file(f_name, new_db_path); strcpy(f_name, form("%s.%s", base_name, INDEX_FILE_SUFFIX)); if ( exist_file(f_name, new_db_path) == true ) del_file(f_name, new_db_path); strcpy(f_name, form("%s.%s", base_name, SCHEMA_FILE_SUFFIX)); if ( exist_file(f_name, new_db_path) == true ) del_file(f_name, new_db_path); f_obj_dict -> init_a_base(spec_file_path, new_db_path, base_name); const char* lang; if ((lang = getenv("LC_ALL")) == NULL) if ((lang = getenv("LC_CTYPE")) == NULL) if ((lang = getenv("LANG")) == NULL) lang = "C"; #ifdef DtinfoClient _DtXlateDb db = NULL; char* std_locale = NULL; if (_DtLcxOpenAllDbs(&db) == 0) { char platform[_DtPLATFORM_MAX_LEN + 1]; int execver, compver; if (_DtXlateGetXlateEnv(db, platform, &execver, &compver) == 0) { _DtLcxXlateOpToStd(db, platform, compver, DtLCX_OPER_SETLOCALE, lang, &std_locale, NULL, NULL, NULL); } _DtLcxCloseDb(&db); db = NULL; } #endif base = new info_base(*f_obj_dict, set_nm_list, list_nm_list, new_db_path, base_name, base_desc, base_uid, #ifdef DtinfoClient std_locale ? std_locale : lang, #else lang, #endif mm_version(MAJOR, MINOR) ); info_base_list.insert_as_tail(new dlist_void_ptr_cell(base)); /*************************************/ // add the base name and description // to the names file /*************************************/ char* lib_nm = form("%s/%s", info_lib_path, MAP_FILE_8_3); fstream nm_out(lib_nm, ios::app, open_file_prot()); if ( !nm_out ) { MESSAGE(cerr, form("can't open %s/%s for append", info_lib_path, MAP_FILE_8_3) ); throw(streamException(nm_out.rdstate())); } if ( bytes(nm_out) == 0 ) { char* lib_entry = form("%s\t%s\n", info_lib_name, unique_id()); if ( !(nm_out << lib_entry) ) { MESSAGE(cerr, form("write %s.%s failed", info_lib_path, MAP_FILE_8_3)); throw(streamException(nm_out.rdstate())); } } char* base_entry = form("%s\t%s\t%s\t%s\t%d\t%d\n", base_name, base_desc, base_uid, #ifdef DtinfoClient std_locale ? std_locale: lang, #else lang, #endif MAJOR, MINOR ); #ifdef DtinfoClient if (std_locale) free(std_locale); #endif if ( !(nm_out << base_entry) ) { MESSAGE(cerr, form("write %s.%s failed", info_lib_path, MAP_FILE_8_3)); throw(streamException(nm_out.rdstate())); } nm_out.close(); if ( nm_out.fail() ) { MESSAGE(cerr, form("close %s.%s failed", info_lib_path, MAP_FILE_8_3)); throw(streamException(nm_out.rdstate())); } //} //MESSAGE(cerr, "define() done"); return true; }
static char * formatMessage(char ** addrs, const char * subject, const char * body) { char * msg; int size = 0; int line; char ** to; int isAllASCII; char hdr_buf[1024]; _DtXlateDb db = NULL; char plat[_DtPLATFORM_MAX_LEN]; int execver; int compver; int body_len; char digest[16]; char mime_type[64]; char tmpbuf[20]; char *ret_locale = NULL; char *ret_lang = NULL; char *ret_codeset = NULL; char default_charset[64]; char *NewBuf = NULL; unsigned long _len = 0; Encoding enc; /* Figure out how big we need the buffer to be. */ for (to = addrs; *to; to++) { size += strlen(*to); size += 2; /* Leave room for the , */ } size += strlen(subject); size += strlen(body); /* We will need space for the header names, a blank line, and other general formatting things. We could be exact, but 1024 is more than enough and give us some spare. */ size += 1024; msg = (char *)malloc(size); strcpy(msg, "To: "); line = 4; for (to = addrs; *to; to++) { strcat(msg, *to); if (*(to + 1) != NULL) { strcat(msg, ", "); line += strlen(*to); if (line > 72) { strcat(msg, "\n "); line = 0; } } } strcat(msg, "\nSubject: "); /* Encode the body of the message */ /* 1) Open Lcx data bases */ if ((_DtLcxOpenAllDbs(&db) == 0) && (_DtXlateGetXlateEnv(db,plat,&execver,&compver) != 0)) { _DtLcxCloseDb(&db); strcat(msg, subject); if (msg[strlen(msg) - 1] == '\n') { msg[strlen(msg) - 1] = 0; } strcat(msg, "\nMime-Version: 1.0\n"); strcat(msg, "Content-Type: text/plain;charset=us-ascii\n\n"); strcat(msg, body); } else { body_len = strlen(body); hdr_buf[0]='\0'; strcpy(mime_type,"text/plain"); rfc1522cpy(hdr_buf,subject); strcat(hdr_buf,"Mime-Version: 1.0\n"); isAllASCII= CvtStr((char *)NULL,(void *)body,(unsigned long)body_len,(void**)&NewBuf, &_len, CURRENT_TO_INTERNET); enc = getEncodingType(body,body_len,FALSE); /* * Here is an ugly adjustment again. If mime_type is text/plain and if * ret_codeset is ISO-2022-JP/KR/TW/CN, we have to always use * enc = MIME_7BIT * This means if the user inputs UDC/VDC into the e-mail body, * fold7 may convert it to the string with MSB-on character and * dtmail passes it to sendmail as if I had all 7bit chars. */ getCharSet(default_charset); DtXlateOpToStdLocale(DtLCX_OPER_MIME, default_charset, &ret_locale, &ret_lang, &ret_codeset); if ( !strncasecmp( mime_type, "text/plain", 10 ) && ( !strncasecmp( ret_codeset, "ISO-2022-JP", 11 ) || !strncasecmp( ret_codeset, "ISO-2022-KR", 11 ) || !strncasecmp( ret_codeset, "ISO-2022-TW", 11 ) || !strncasecmp( ret_codeset, "ISO-2022-CN", 11 ) ) ) enc = MIME_7BIT; memset(digest,0,sizeof(digest)); md5PlainText(body,body_len,digest); writeContentHeaders(hdr_buf,mime_type,enc,(char *)digest,isAllASCII); strcat(hdr_buf,"\n"); strcat(hdr_buf,"Content-Length: "); if (( NewBuf != NULL) && ( _len != 0)) { sprintf(tmpbuf,"%ld",_len); strcat(hdr_buf,tmpbuf); strcat(hdr_buf,"\n"); strcat(msg,hdr_buf); strncat(msg,NewBuf,_len); strcat(hdr_buf,"\n"); } else { sprintf(tmpbuf,"%d",body_len); strcat(hdr_buf,tmpbuf); strcat(hdr_buf,"\n"); strcat(msg,hdr_buf); strcat(msg,body); } } return(msg); }