Home | History | Annotate | Download | only in smbsrv
      1 /*
      2  * CDDL HEADER START
      3  *
      4  * The contents of this file are subject to the terms of the
      5  * Common Development and Distribution License (the "License").
      6  * You may not use this file except in compliance with the License.
      7  *
      8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
      9  * or http://www.opensolaris.org/os/licensing.
     10  * See the License for the specific language governing permissions
     11  * and limitations under the License.
     12  *
     13  * When distributing Covered Code, include this CDDL HEADER in each
     14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
     15  * If applicable, add the following below this CDDL HEADER, with the
     16  * fields enclosed by brackets "[]" replaced with your own identifying
     17  * information: Portions Copyright [yyyy] [name of copyright owner]
     18  *
     19  * CDDL HEADER END
     20  */
     21 /*
     22  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
     23  * Use is subject to license terms.
     24  */
     25 
     26 #pragma ident	"%Z%%M%	%I%	%E% SMI"
     27 
     28 #include <smbsrv/string.h>
     29 #include <smbsrv/codepage.h>
     30 #include <smbsrv/oem.h>
     31 
     32 static unsigned int smb_cpid = NO_OF_OEM_CP_INDS;
     33 static unsigned int telnet_cpid = NO_OF_OEM_CP_INDS;
     34 
     35 /*
     36  * oem_get_smb_cpid
     37  *
     38  * This function returns the cpid for current smb codepage.
     39  */
     40 unsigned int
     41 oem_get_smb_cpid(void)
     42 {
     43 	return (smb_cpid);
     44 }
     45 
     46 /*
     47  * oem_get_telnet_cpid
     48  *
     49  * This function returns the cpid for current telnet codepage.
     50  */
     51 unsigned int
     52 oem_get_telnet_cpid(void)
     53 {
     54 	return (telnet_cpid);
     55 }
     56 
     57 /*
     58  * oem_current_language
     59  *
     60  * This function will return the current language setting.
     61  * The current language is stored in env "codepage.oem.language".
     62  * If the env does not exist, "None Selected" will be returned.
     63  */
     64 char *
     65 oem_current_language()
     66 {
     67 #ifdef PBSHORTCUT
     68 	char *p = getenv("codepage.oem.language");
     69 
     70 	if (p)
     71 		return (p);
     72 #endif
     73 	return ("None Selected");
     74 }
     75 
     76 
     77 /*
     78  * oem_language_set
     79  *
     80  * This function will set the oem language and correct
     81  * env variables.
     82  */
     83 int
     84 oem_language_set(char *lang_name)
     85 {
     86 	int i;
     87 	language *lang_table = oem_get_lang_table();
     88 
     89 	for (i = 0; i < NO_OF_LANGUAGES; i++) {
     90 		if (utf8_strcasecmp(lang_name, lang_table[i].language) == 0) {
     91 			unsigned int oldSmbIndex = smb_cpid;
     92 			unsigned int oldTelnetIndex = telnet_cpid;
     93 			if (oem_codepage_init(lang_table[i].smbIndex) < 0 ||
     94 			    oem_codepage_init(lang_table[i].telnetIndex) < 0) {
     95 				oem_codepage_free(lang_table[i].smbIndex);
     96 				oem_codepage_free(lang_table[i].telnetIndex);
     97 				(void) oem_codepage_init(oem_default_smb_cpid);
     98 				(void) oem_codepage_init(
     99 				    oem_default_telnet_cpid);
    100 				smb_cpid = oem_default_smb_cpid;
    101 				telnet_cpid = oem_default_telnet_cpid;
    102 #ifdef PBSHORTCUT
    103 				setenv("codepage.oem.language",
    104 				    oem_default_language);
    105 #endif
    106 			} else {
    107 				smb_cpid = lang_table[i].smbIndex;
    108 				telnet_cpid = lang_table[i].telnetIndex;
    109 #ifdef PBSHORTCUT
    110 				setenv("codepage.oem.language",
    111 				    lang_table[i].language);
    112 #endif
    113 			}
    114 #ifdef PBSHORTCUT
    115 			saveenv();
    116 #endif
    117 
    118 			if (oldSmbIndex < NO_OF_OEM_CP_INDS)
    119 				oem_codepage_free(oldSmbIndex);
    120 			if (oldTelnetIndex < NO_OF_OEM_CP_INDS)
    121 				oem_codepage_free(oldTelnetIndex);
    122 			return (0);
    123 		}
    124 	}
    125 
    126 	return (-1);
    127 }
    128