Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
General
GeneralPortable MacsHardwareNetworking
Applications
Mac ApplicationsEudoraFirefox / MozillaInternet ExplorerOutlook ExpressMS OfficeEntourageExcelPowerPointWordVirtual PCMedia PlayerOther MS Products
Programming
Mac ProgrammingCodeWarriorPerl
Country Specific
Australian Mac GroupUK Mac Group

Mac Forum / Programming / Mac Programming / June 2007



Tip: Looking for answers? Try searching our database.

Howto extract proxy from .pac script?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Andrei Korostelev - 12 Jun 2007 09:49 GMT
Hi all,

I have a path to the .pac file received using SystemConfiguration
Framework API. This .pac file allows selecting the appropriate proxy
server for a given URL.

The question is: is it any C/C++ API to extract proxy from this .pac
file for a given URL?
Andrei Korostelev - 13 Jun 2007 20:58 GMT
> Hi all,
>
[quoted text clipped - 4 lines]
> The question is: is it any C/C++ API to extract proxy from this .pac
> file for a given URL?

I solved the problem by using the Mozilla JavaScript engine
(SpiderMonkey). It took me a while to build it, adapt for my purposes
and embed into the app. Still puzzling whether a native API (aka
Carbon) exist to do the same routine job.
Simon Slavin - 15 Jun 2007 13:51 GMT
On 12/06/2007, Andrei Korostelev wrote in message
<1181638163.399421.159930@a26g2000pre.googlegroups.com>:

> I have a path to the .pac file received using SystemConfiguration
> Framework API. This .pac file allows selecting the appropriate proxy
> server for a given URL.
>
> The question is: is it any C/C++ API to extract proxy from this .pac
> file for a given URL?

A .pac file is a JavaScript program.  It can, in theory, use any
JavaScript programming techniques it wants.  Take a look at one in a text
editor and you'll see what they look like.  Not only are they programs but
they can react to their environment by examining environment information.
So you have two options:

A) Write a JavaScript interpreter.
B) Let the .pac program run in the environment it's intended for, then see
what it did.

Simon.
Signature

http://www.hearsay.demon.co.uk

Patrick Machielse - 16 Jun 2007 14:46 GMT
> On 12/06/2007, Andrei Korostelev wrote in message
>  
[quoted text clipped - 10 lines]
> B) Let the .pac program run in the environment it's intended for, then see
> what it did.

Some ancient info available here:

<http://wp.netscape.com/eng/mozilla/2.0/relnotes/demo/proxy-live.html>

You might be able to use the following technique to execute the pac file
functions from a Cocoa program:

<http://will.thimbleby.net/script/>

patrick
Heath Raftery - 18 Jun 2007 03:01 GMT
> I have a path to the .pac file received using SystemConfiguration
> Framework API. This .pac file allows selecting the appropriate proxy
> server for a given URL.
>
> The question is: is it any C/C++ API to extract proxy from this .pac
> file for a given URL?

You need a full blown JavaScript interpreter - .pac files can use any
valid JavaScript, even though they often just do "if url is local,
return no proxy, else return this proxy". In my proxy server,
Authoxy, I used SpiderMonkey to do this. Fortunately, Authoxy is now
open source[1] (and I contributed some work back to the SpiderMonkey
team), so you'll welcome to benefit from what I've already done.

However, until Patrick posted in this thread, I was unaware of the
Cocoa interface. If I had the choice, I'd probably try to use that,
if I already had access to the Cocoa frameworks.

[1] http://sourceforge.net/projects/authoxy-panther/

Signature

*--------------------------------------------------------*

| ^Nothing is foolproof to a sufficiently talented fool^ |
|    Heath Raftery, HRSoftWorks          _\|/_           |
*______________________________________m_('.')_m_________*
Andrei Korostelev - 18 Jun 2007 09:20 GMT
> > I have a path to the .pac file received using SystemConfiguration
> > Framework API. This .pac file allows selecting the appropriate proxy
[quoted text clipped - 21 lines]
> |    Heath Raftery, HRSoftWorks          _\|/_           |
> *______________________________________m_('.')_m_________*

Thanks to everybody. As I already noticed above, I solved the probvlem
by using JavaScript inpetrpreter from SpiderMonkey. Works fine both in
Mac and in Win.  What I was looking for is a dedicated API in Mac OS X
to do the same. Carbon is the highest possible API layer I can use, so
Cocoa does not seem right choice. Nevertheless, thanks for you
autoproxy link, Heath.
Michael Ash - 18 Jun 2007 15:51 GMT
> Thanks to everybody. As I already noticed above, I solved the probvlem
> by using JavaScript inpetrpreter from SpiderMonkey. Works fine both in
> Mac and in Win.  What I was looking for is a dedicated API in Mac OS X
> to do the same. Carbon is the highest possible API layer I can use, so
> Cocoa does not seem right choice.

May I ask why? In most situations where Carbon can be used, there is no
penalty for using a little Cocoa too. (Indeed, Carbon itself uses a little
Cocoa.)

Signature

Michael Ash
Rogue Amoeba Software

Andrei Korostelev - 18 Jun 2007 18:54 GMT
> > Thanks to everybody. As I already noticed above, I solved the probvlem
> > by using JavaScript inpetrpreter from SpiderMonkey. Works fine both in
[quoted text clipped - 9 lines]
> Michael Ash
> Rogue Amoeba Software

Hm, I did not know that I can call Cocoa code from Carbon. It seems
that it is possible http://developer.apple.com/documentation/Cocoa/Conceptual/CarbonCocoaDoc/index.html
Michael Ash - 18 Jun 2007 21:40 GMT
>> > Thanks to everybody. As I already noticed above, I solved the probvlem
>> > by using JavaScript inpetrpreter from SpiderMonkey. Works fine both in
[quoted text clipped - 8 lines]
> Hm, I did not know that I can call Cocoa code from Carbon. It seems
> that it is possible http://developer.apple.com/documentation/Cocoa/Conceptual/CarbonCocoaDoc/index.html

They're just libraries. You're not calling Cocoa "from Carbon", you're
just calling it from your app. The question is whether you can mix the
two.

I'm not an expert on the subject but I believe that as long as you're on
10.2 or better*, the only real issue with mixing them is that you can't
insert controls or views from one framework into windows from another**.
In other words, everything inside a WindowRef must be Carbon, and
everything inside an NSWindow must be Cocoa. Aside from that, you can mix
and match at will. Just be aware that you need to initialize Cocoa before
you can start calling into it, and you'll need to provite autorelease
pools. The document you found sesems to cover all of this, so you should
be set.

* In case anyone is curious what was wrong on 10.1, the two frameworks
used totally different event dispatching methods which did not intermingle
at all. If you were in an application with a Cocoa event loop and you
registered some Carbon event handlers, they would not be called, and vice
versa. This was fixed on 10.2 and works fine now.

** Apple is able to do this, witness the limited Carbon support for WebKit
which ends up putting a WebView inside a Carbon window. However, their
techniques for this are Evil, and private, and you shouldn't even think
about attempting to duplicate this.

Signature

Michael Ash
Rogue Amoeba Software

Ben Artin - 19 Jun 2007 06:42 GMT
> * In case anyone is curious what was wrong on 10.1, the two frameworks
> used totally different event dispatching methods which did not intermingle
> at all. If you were in an application with a Cocoa event loop and you
> registered some Carbon event handlers, they would not be called, and vice
> versa. This was fixed on 10.2 and works fine now.

Having used this, I think that saying that it works fine now is a bit of a
stretch. More like, you can beat it into submission if you try hard enough and
your use case is not too complex.

Ben

Signature

If this message helped you, consider buying an item
from my wish list: <http://artins.org/ben/wishlist>

I changed my name: <http://periodic-kingdom.org/People/NameChange.php>

Andrei Korostelev - 19 Jun 2007 08:24 GMT
> >> > Thanks to everybody. As I already noticed above, I solved the probvlem
> >> > by using JavaScript inpetrpreter from SpiderMonkey. Works fine both in
[quoted text clipped - 37 lines]
> Michael Ash
> Rogue Amoeba Software

Thanks. We use Qt, so UI is not an issue.

--Andrei
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.