tags:

views:

220

answers:

2

I am currently using libproxy to get the proxy information (if any) on RedHat and Debian Linux. It doesn't work all that well, but it's the only way I know I can use to get the proxy information from my code. I need to stop using the lib since in most cases it doesn't recognize the proxy. Is there any way to acquire the proxy information? What i mean is, is there a file (or group of files) i can read, or an env variable or an API or system call that i can use to get the information? Gnome based code is OK, KDE might help as well but i am looking for something more generic. The code is C.

Now, before anyone asks, I don't want to use libproxy anymore. Period. I don't want to start investigating why it doesn't work. I don't really want to know whether there is a new version of that lib. I know it might work, I just don't want to use it. i can't use it (just because). So please don't point me that way.

Code is appreciated.

thanks.

+2  A: 

In linux, the "global proxy setting" is typically just environment variables that are usually set in /etc/profile. You can examine those variables to see what proxy is set.

The variables are:

  • http_proxy - the proxy for HTTP connections
  • ftp_proxy - the proxy for FTP connections

Using the Network Proxy Preferences tool under Gnome saves information in the GConf database. The path to the keys are /system/http_proxy and /system/proxy. You can read about the detail in those trees at this page.

You can access the GConf database using the library API. Note that GConf is based on GObject. To examine the contents of this tree using the command line, try the following:

gconftool-2 -R /system/http_proxy

This will provide a "name = value" listing of the tree, which may be usable in your application. Note that this requires a system() call, so it's not recommended for a deployed application, but it might help you get started.

jheddings
These are only valid for command line tools, IMHO.
Amit
@Amit, What do you mean?
wonderer
Amit
@Amit there are many desktop apps that will also look for the presence of those variables.
jheddings
@jhheddings: Syntaptic/Songbird/Firefox doesn't.
Amit
I wasn't implying that all do, just that it is valid for more than command line apps.
jheddings
@jhheddings: I know how to get the env. variables, but how do you probe the gconf information? is there a way to read that? show i read into ~/.gconf?
wonderer
@wonderer I updated my answer with a pointer to the GConf library API.
jheddings
OK, so basically i need to add support for GTK2?
wonderer
You wouldn't need full support for the GTK, just the GLib and GObject parts. Depending on your application, you could also `system()` out and use the command line tools (updated answer again).
jheddings
+1  A: 

GNOME has its own place to store the Proxy settings, and I am sure KDE or any other DE has its own place too. May be you can look for any mention of where Proxy settings should be store in the Linux Standard Base. That could hint you a standard of doing it irrespective of Distro or DE.

DE -> Desktop Environment

Amit
Thanks. That is one the first places I checked (Linux Standard Base). No information there...
wonderer