I am attempting to write a little CGI application with Dolphin. I am using
the CGI.cls file that Andy posted some time ago. I am using POST to submit the form, and I am trying to get the parameter string out of stdin. I was trying to use nextLine to get the string, however I am now wondering if CGI adds a cr to the string since my code does not seem to respond. I tried just using stdin contents but that raises a "bad file descriptor" error when it checks the size of the stream, and the comment implies that it cannot work for stdin. I don't want to liter the remote server with too many stuck programs, so I was hoping I could get some pointers. Could someone tell me how to get the string from a POST form submission? As a future enhancement to Dolphin it might be handy to include a simple CGISessionManager in the distribution image, it could get and parse the input. That would really make it easy to write CGI apps in Dolphin. Chris |
Chris,
> Could someone tell me how to get the string from a POST form submission? Quite a coincidence: I just started writing a Dolphin CGI yesterday. See the not-quite-fileIns (and not very well tested either) below. Blair, my CGI needs to make a COM connection to the outside, and that's failing, claiming that the class isn't registered. BUT, the class is registered, and the same expression works (across processes) from the IDE. My hunch is that this means it's either stripping or session manager related. Is there anything about the console session manager that would cause problems finding a class factory? Have a good one, Bill -- Wilhelm K. Schwab, Ph.D. [hidden email] String>>subStringsSeparatedBy:aCharacter #wks. ^( String with:aCharacter ) _separateSubStringsIn:self parse:aString "Assume the line is separated by $&, and then URL-encoded strings of the form key=value; answer a dictionary." | result | result := Dictionary new. ( aString subStringsSeparatedBy:$& ) do:[ :each | | in | in := ( self unescape:each ) readStream. result at:( in upTo:$= ) put:( in upToEnd ) ]. ^result unescape:aString "Answer the unescaped form of the string" " self unescape:'userUserName=ok%2C+try+this+as+a+user+name'. " | in out percent plus space done | percent := $%. plus := $+. space := Character space. in := aString readStream. out := String writeStream. [ in atEnd ] whileFalse:[ | c | done := false. c := in next. c == plus ifTrue:[ out nextPut:space. done := true. ]. c == percent ifTrue:[ | token codePoint | token := in next:2. codePoint := Integer fromString:'16r', token. out nextPut:( Character codePoint:codePoint ). done := true. ]. done ifFalse:[ out nextPut:c ]. ]. ^out contents |
Bill Schwab <[hidden email]> wrote in message
news:al4kkd$1mvhu0$[hidden email]... > Chris, > > > Could someone tell me how to get the string from a POST form submission? > > Quite a coincidence: I just started writing a Dolphin CGI yesterday. See > the not-quite-fileIns (and not very well tested either) below. > ... Actually my problem was on a more primitive level. I wanted to know how to get the string from stdin in order to parse it. However I figured that out and it seems to work. It turns out that my problem was with the mime headers. Also FYI it looks like Dolphin 5 has some unescaping code included, look at String<<unescapePercents. Thanks, Chris |
In reply to this post by Bill Schwab-2
"Bill Schwab" <[hidden email]> wrote in message
news:al4kkd$1mvhu0$[hidden email]... > Chris, > > > Could someone tell me how to get the string from a POST form submission? > > Quite a coincidence: I just started writing a Dolphin CGI yesterday. See > the not-quite-fileIns (and not very well tested either) below. > I can save you some testing. String>>subStrings: already works with character arguments, and there is already a method to unescape post strings: String>>unescapePercents. > Blair, my CGI needs to make a COM connection to the outside, and that's > failing, claiming that the class isn't registered. BUT, the class is > registered, and the same expression works (across processes) from the IDE. > My hunch is that this means it's either stripping or session manager > related. Is there anything about the console session manager that would > cause problems finding a class factory? > I can't think of any particular reason it wouldn't work, but I we haven't tried to build any console applications that use COM so you are a pioneer. Regards Blair |
"Blair McGlashan" <[hidden email]> wrote in message
news:al9qgk$1ohc5c$[hidden email]... > "Bill Schwab" <[hidden email]> wrote in message > news:al4kkd$1mvhu0$[hidden email]... > ... > > Blair, my CGI needs to make a COM connection to the outside, and that's > > failing, claiming that the class isn't registered. BUT, the class is > > registered, and the same expression works (across processes) from the IDE. > > My hunch is that this means it's either stripping or session manager > > related. Is there anything about the console session manager that would > > cause problems finding a class factory? > > > > I can't think of any particular reason it wouldn't work, but I we haven't > tried to build any console applications that use COM so you are a pioneer. But you are no longer the lone pioneer. I tried a quick test (see attached), and it works demonstrating that fundamentally COM should work in a console app, even for visual controls like the popup help control used in my example. Regards Blair ------------------------ | package | package := Package name: 'Hello World (Console COM)'. package paxVersion: 0; basicComment: ''. package imageStripperBytes: (ByteArray fromHexString: '21535442203120460F0D0004000000496D61676553747269707065720000000000000000520 000001900000048656C6C6F20576F726C642028436F6E736F6C6520434F4D29520000003B000 0004F626A65637420417274735C53616D706C65735C436F6E736F6C655C48656C6C6F20576F7 26C645C48656C6C6F434F4D436F6E736F6C652E6578659A00000000000000520000001900000 048656C6C6F20576F726C642028436F6E736F6C6520434F4D295200000018000000436F6D6D6 16E644C696E65434F4D48656C6C6F576F726C64EFBF250000000000000000000000000000000 000000000000000000000000000000000000000000000000000'). package classNames add: #CommandLineCOMHelloWorld; yourself. package binaryGlobalNames: (Set new yourself). package globalAliases: (Set new yourself). package allResourceNames: (Set new yourself). package setPrerequisites: (IdentitySet new add: '..\..\..\Dolphin\ActiveX\Automation\ActiveX Automation'; add: '..\..\..\Dolphin\Base\Dolphin'; add: '..\..\..\Dolphin\MVP\Base\Dolphin MVP Base'; yourself). package! "Class Definitions"! ConsoleSessionManager subclass: #CommandLineCOMHelloWorld instanceVariableNames: '' classVariableNames: '' poolDictionaries: '' classInstanceVariableNames: ''! "Global Aliases"! "Loose Methods"! "End of package definition"! "Source Globals"! "Classes"! CommandLineCOMHelloWorld guid: (GUID fromString: '{DE9FBA03-220E-4540-AC39-D788D28B5F5F}')! CommandLineCOMHelloWorld comment: ''! !CommandLineCOMHelloWorld categoriesForClass!Samples! ! !CommandLineCOMHelloWorld methodsFor! main | pdisp | pdisp := IDispatch createObject: 'Internet.HHCtrl.1'. "Fire off a method invocation via #doesNotUnderstand" pdisp TextPopup: 'Hello World' _: 'Microsoft Sans Serif,8,,italic' "Font face,point size,char set,format options" _: 2 _: 2 _: Color black asParameter _: Color white asParameter. "Let the message pump run a bit so the popup Window can be painted" SessionManager inputState pumpMessages. self stderr nextPutAll: 'Press <Enter> to exit:'; flush. self stdin nextLine! ! !CommandLineCOMHelloWorld categoriesFor: #main!operations-startup!public! ! "Binary Globals"! "Resources"! |
Hi Blair,
> But you are no longer the lone pioneer. I tried a quick test (see attached), > and it works demonstrating that fundamentally COM should work in a console > app, even for visual controls like the popup help control used in my > example. Thanks for checking on it. I'm fairly certain that I have it working too. The only caveat is that it's still technically possible for the console app to be talking to itself; class factories are a little too persistent for my own good at times, and I have so far only managed to get an interface pointer - I'd really need to move some data and look at the results, or set a breakpoint in the app, etc.. I know the Dolphin IDE client was crossing process boundaries though. More of a problem is that Apache isn't interested in giving my CGI app access to COM classes; if I can't solve that, there's no point in continuing. I _have_ managed to establish an Automation link to Word using PHP. But, before I rewrite my COM interfaces to be dispatch vs. vtable and build a dependence on PHP, it would probably make more sense to figure out CGIWrap or rig up something similar - I *think* PHP must be doing basically that itself or it would have the same problems. There would be long-term benefit in a clean solution, so I'll give it some more thought and take another run at it if I get any good ideas. Jerry Bell posted something about creating a new user for the script directory, but I haven't found a way to do that with Apache - suggestions are welcome :) For now it will very likely be easier to write my own web server for testing purposes, which is how this got started. Have a good one, Bill -- Wilhelm K. Schwab, Ph.D. [hidden email] |
Hi Bill,
> More of a problem is that Apache isn't interested in giving my CGI app > access to COM classes; FastCGI will allow you to run a number of separate long-running Dolphin processes behind Apache. Dolphinharbor is currently setup using Apache + mod_fastcgi and 5 Dolphin executables. There are some packages and samples at: http://www.dolphinharbor.org/dh/projects/fs/index.html Another option is mod_lisp. I have not used this myself, but it looks to be a simpler protocol than FastCGI. The Squeak Seaside code has a mod_lisp client implementation that could be ported to Dolphin at: http://www.beta4.com/seaside/ Hope this helps, Steve ========== Steve Waring [hidden email] http://www.dolphinharbor.org/dh/harbor/steve.html |
Steve,
Thanks for the reminder about FastCGI. I thought about trying sockets from a CGI, but have yet to race into it for fear of being stopped by either console app issues or permissions again. My other concern was the stability of winsock, but you would know by now if that were a big problem. How long does your server typically run between reboots? Do you feel hindered by not having access to Apache 2.x? <soapbox> It strikes me that the world would be better served by a brain-dead simple suexec or other way to tell a server to run only certain CGIs and as a specific user. My concern is that with all of the modules, FastCGI and WinCGI (where it exists), we're really just opening up more opportunities for hackers when we should be trying to make one securable way to generate dynamic content. </soapbox> Thanks! Bill -- Wilhelm K. Schwab, Ph.D. [hidden email] |
Steve,
Problem solved, at least for now. Your link to Pi3 did the trick - THANKS!!! It supports WinCGI, which I already have covered, and it runs under win2k, which my prior testing server seems unable to do. Have a good one, Bill -- Wilhelm K. Schwab, Ph.D. [hidden email] |
In reply to this post by Bill Schwab-2
Hi Bill,
> Thanks for the reminder about FastCGI. I thought about trying sockets from > a CGI, but have yet to race into it for fear of being stopped by either > console app issues or permissions again. My other concern was the stability > of winsock, but you would know by now if that were a big problem. How long > does your server typically run between reboots? Do you feel hindered by not > having access to Apache 2.x? > In short: stability=rock-solid! DolphinHarbor runs on an old NT 4 Workstation - 200Mhz Pentium Pro with 128MB of ram. Current uptime is over three weeks- the only time the hardware ever goes down is if we have a prolonged power outage overnight and my UPS gives out (happens every couple of months - I have a very large UPS, but the office is in the middle of nowhere and power quality isn't the greatest. The 'real' servers get the notification of power outages). I've never tracked the longest uptime for DH, but I'm sure it would be on the order of several months. Steve runs the Dolphin server software, to my knowledge we haven't had any crashes there in recent memory- perhaps a few very early on in DH's lifetime. I think he only restarts his stuff for configuration changes- he may want to add more details- he'll also be able to tell you in more detail what sort of loads his various servers generally handle- Steve? Anyway, I don't think you'd have any problems, and as demonstrated by the meager DH resources, you can run on pretty old hardware. ToGo apps rock! -Jerry Bell |
Free forum by Nabble | Edit this page |