This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

problem with http error

Help for those learning Tcl or writing their own scripts.
Post Reply
m
mikele
Voice
Posts: 1
Joined: Wed Mar 14, 2007 3:13 pm

problem with http error

Post by mikele »

Hi,
I have here a script which display the status of the user

Code: Select all

proc web:read {nick host hand chan arg} {
global url

if {[llength $arg] == 0} { set statususer [split $nick]

} else {
   set statususer [split $arg]
}
   ::http::config -useragent "Mozilla/4.75 (X11; U; FreeBSD 6.1; i586; Nav)"
   set http [::http::data [::http::geturl $url$statususer]]
...

it works fine, but if in the $statususer a"[" or "]" it will call an error
Tcl error [web:read]: Illegal characters in URL path

simple question, how can I teach the bot to ignore this error ?
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

First off, this script is buggy. It uses list-commands on untrusted string sources, which is a very, very bad idea. Secondly, the composition of the url used with ::http::geturl does'nt make much sense to me; it's an external string(?) concatenated with a list (from either split:ing $nick or $arg).

split should not be used as an escaping-function; it only servers the purpose of converting a string into a list.

It would also be helpful with some information to which http-package/library you are using. My guess would be that you're using tcl's http-package version 2.x. However, I have not been able to find that error-message in any of the versions I have available.

But to your question, if you don't wish to solve this problem, but just make your bot ignore it, find which command causes the error, and enclose it in a catch-statement (see manpage for catch on how to do this).
NML_375
User avatar
rosc2112
Revered One
Posts: 1454
Joined: Sun Feb 19, 2006 8:36 pm
Location: Northeast Pennsylvania

Post by rosc2112 »

Some chars are not valid in url's, so you'd have to convert them to hex strings. For example, in the steamid script I made, I use:

Code: Select all

# This is a global var, outside of any procs:

set sidmap {
"\ " +  : %3A  \\ %5C%5C  \[ %5B  \] %5D  \# %23  \" %22    \' %27  ! %21  @ %40
$ %24  \( %28  \) %29  ~  %7E  `  %60  %  %25   ^   %5E  \& %26  = %3D  + %2B
| %7C  \{ %7B  \} %7D  /  %2F  \? %3F  ,  %2C   <   %3C   > %3E  ; %3B
}
and then within procs to use the sidmap:

Code: Select all

 set url [string map -nocase $::sidmap $url]
That's the basic idea, mine's slightly different (I use split on the input and then join within the set url part..)
Post Reply