1/* 2 * Part of Very Secure FTPd 3 * Licence: GPL v2 4 * Author: Chris Evans 5 * utility.c 6 */ 7 8#include "utility.h" 9#include "sysutil.h" 10#include "str.h" 11#include "defs.h" 12#include <stdarg.h> // Jiahao 13//#include <iconv.h> 14#include <stdlib.h> 15#include <stdio.h> 16#include <unistd.h> 17#include <string.h> 18#include <bcmnvram.h> 19#include "tunables.h" 20 21const char* NLS_NVRAM_U2C="asusnlsu2c"; // Jiahao 22const char* NLS_NVRAM_C2U="asusnlsc2u"; 23static char *xfr_buf=NULL; 24 25extern char *nvram_xfr(char *); 26 27//static int xfr_buf_init=0; 28char tmp[1024]; 29 30#define DIE_DEBUG 31 32void 33die(const char* p_text) 34{ 35#ifdef DIE_DEBUG 36 bug(p_text); 37#endif 38 vsf_sysutil_exit(1); 39} 40 41void 42die2(const char* p_text1, const char* p_text2) 43{ 44 struct mystr die_str = INIT_MYSTR; 45 str_alloc_text(&die_str, p_text1); 46 str_append_text(&die_str, p_text2); 47 die(str_getbuf(&die_str)); 48} 49 50void 51bug(const char* p_text) 52{ 53 /* Rats. Try and write the reason to the network for diagnostics */ 54 vsf_sysutil_activate_noblock(VSFTP_COMMAND_FD); 55 (void) vsf_sysutil_write_loop(VSFTP_COMMAND_FD, "500 OOPS: ", 10); 56 (void) vsf_sysutil_write_loop(VSFTP_COMMAND_FD, p_text, 57 vsf_sysutil_strlen(p_text)); 58 (void) vsf_sysutil_write_loop(VSFTP_COMMAND_FD, "\r\n", 2); 59 vsf_sysutil_exit(1); 60} 61 62void 63vsf_exit(const char* p_text) 64{ 65 (void) vsf_sysutil_write_loop(VSFTP_COMMAND_FD, p_text, 66 vsf_sysutil_strlen(p_text)); 67 vsf_sysutil_exit(0); 68} 69 70char * 71local2remote(const char *buf) 72{ 73 if (tunable_enable_iconv == 0) return NULL; 74 char *p; 75 76// if ((xfr_buf==NULL) && (xfr_buf_init==0)) 77// { 78 xfr_buf = (char *)malloc(2048); 79// if (xfr_buf!=NULL) 80// xfr_buf_init=1; 81// } 82 memset(tmp, 0, 1024); 83 sprintf(tmp, "%s%s_%s", NLS_NVRAM_U2C, tunable_remote_charset, buf); 84 if((p = (char *)nvram_xfr(tmp)) != NULL){ 85 strcpy(xfr_buf, p); 86 return xfr_buf; 87 } 88 else 89 return NULL; 90} 91 92char * 93remote2local(const char *buf) 94{ 95 if (tunable_enable_iconv == 0) return NULL; 96 char *p; 97 98// if ((xfr_buf==NULL) && (xfr_buf_init==0)) 99// { 100 xfr_buf = (char *)malloc(2048); 101// if (xfr_buf!=NULL) 102// xfr_buf_init=1; 103// } 104 memset(tmp, 0, 1024); 105 sprintf(tmp, "%s%s_%s", NLS_NVRAM_C2U, tunable_remote_charset, buf); 106 if((p = (char *)nvram_xfr(tmp)) != NULL){ 107 strcpy(xfr_buf, p); 108 return xfr_buf; 109 } 110 else 111 return NULL; 112} 113