1 # ===================================================================== 2 # aspellTinyMCE.awk: RPC I/O function for rpclib/aspellTinyMCE. 3 # 4 # Copyright (c) 2007,2008,2009,2010 Carlo Strozzi 5 # 6 # This program is free software; you can redistribute it and/or modify 7 # it under the terms of the GNU General Public License as published by 8 # the Free Software Foundation; version 2 dated June, 1991. 9 # 10 # This program is distributed in the hope that it will be useful, 11 # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 # GNU General Public License for more details. 14 # 15 # You should have received a copy of the GNU General Public License 16 # along with this program; if not, write to the Free Software 17 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 18 # 19 # ===================================================================== 20 21 # ===================================================================== 22 # void _userproc(int mode) 23 # ===================================================================== 24 25 function _userproc(mode, value,out,i,j,a,b) { 26 27 if (mode == _O_REQUEST) { # request. 28 29 # Output file is mandatory! 30 if ((out=_rcget("TNS_ASPELL_DATA")) !~ /^\//) 31 return(_sys("csaExit.fault 0041 TNS_ASPELL_DATA")) 32 33 # target group 34 value = _request("1",1) 35 36 # group must not be null and it may not contain the 37 # unescaped ``.'' character. 38 39 if (value != _NULL && value !~ /\./) 40 _rcset("cgi.group",unixify(value)) 41 42 # mandatory "id" field. 43 if ((value=_request("id",1)) ~ /^mce_editor_0\|[0-9]+$/) 44 _rcset("cgi.aspell.id",value) 45 46 # optional "lang" field. Only accept languages in the 47 # format specified by ISO-639 and ISO-3166. 48 if ((value=_request("lang",1)) ~ /^[a-z]+([-_][a-zA-Z]+)?$/) 49 _rcset("cgi.aspell.lang",value) 50 51 # mandatory "cmd" field. 52 if ((value=_request("cmd",1)) == "spell" || value == "suggest") 53 _rcset("cgi.aspell.cmd",value) 54 55 # Optional "check" field. Note that this may contain enything so 56 # it must be written to a file and passed to the actual apell-checker 57 # as-is. 58 59 print _request("check",1) > out 60 61 # The following test is necessary since the address could, 62 # at least in theory, have been set to any string by the 63 # remote user, due to how it is handled to cope with stunnel(8) 64 # and the lack of transproxy support in kernel 2.4.x. 65 66 if (_isipaddr(ENVIRON["REMOTE_ADDR"]) == _TRUE) 67 value = ENVIRON["REMOTE_ADDR"] 68 else value = "0.0.0.0" 69 70 _rcset("REMOTE_ADDR",value) 71 } 72 73 else { # response 74 75 out = _rcget("tpl.include.tw.page") 76 77 if (out !~ /^\/\.*[a-zA-Z0-9]/) 78 return(_sys("csaExit.fault 0041 out")) 79 80 printf("",\ 81 _rcget("cgi.aspell.id"),_rcget("cgi.aspell.cmd")) > out 82 83 # read aspell(1) output. 84 85 value = _rcget("cgi.aspell.cmd") 86 87 i = j = 1 88 89 while (split(_TBLS[1,i++],a," ")) { 90 91 if (a[1] != "&") continue # only read non-matches. 92 93 if (value == "spell") { # spell mode. 94 if (++j > 1) printf("+") > out 95 printf("%s",_uriencode(a[2])) > out 96 } 97 98 else { # suggest mode. 99 100 split(_TBLS[1,i-1],b,/[:,] /) 101 102 while (b[++j] != "") { 103 if (j > 2) printf("+") > out 104 printf("%s",_uriencode(b[j])) > out 105 } 106 107 break 108 } 109 } 110 111 printf("") > out 112 113 close(out) 114 115 # generic template conditionals. 116 117 ifsections() 118 } 119 } 120 121 # EOF