| 1 |
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ |
|---|
| 2 |
|
|---|
| 3 |
/* Cherokee |
|---|
| 4 |
* |
|---|
| 5 |
* Authors: |
|---|
| 6 |
* Alvaro Lopez Ortega <alvaro@alobbs.com> |
|---|
| 7 |
* |
|---|
| 8 |
* Copyright (C) 2001-2008 Alvaro Lopez Ortega |
|---|
| 9 |
* |
|---|
| 10 |
* This program is free software; you can redistribute it and/or |
|---|
| 11 |
* modify it under the terms of version 2 of the GNU General Public |
|---|
| 12 |
* License as published by the Free Software Foundation. |
|---|
| 13 |
* |
|---|
| 14 |
* This program is distributed in the hope that it will be useful, |
|---|
| 15 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 16 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 17 |
* GNU General Public License for more details. |
|---|
| 18 |
* |
|---|
| 19 |
* You should have received a copy of the GNU General Public License |
|---|
| 20 |
* along with this program; if not, write to the Free Software |
|---|
| 21 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
|---|
| 22 |
* USA |
|---|
| 23 |
*/ |
|---|
| 24 |
|
|---|
| 25 |
#include "common-internal.h" |
|---|
| 26 |
#include "proxy.h" |
|---|
| 27 |
#include "util.h" |
|---|
| 28 |
|
|---|
| 29 |
#define ENTRIES "proxy" |
|---|
| 30 |
#define PROXY_ENV_VAR "http_proxy" |
|---|
| 31 |
#define PROXY_PORT_DEFAULT 8080 |
|---|
| 32 |
|
|---|
| 33 |
|
|---|
| 34 |
static ret_t |
|---|
| 35 |
find_proxy_environment (cherokee_buffer_t *proxy, cuint_t *port) |
|---|
| 36 |
{ |
|---|
| 37 |
char *env; |
|---|
| 38 |
char *colon; |
|---|
| 39 |
|
|---|
| 40 |
env = getenv (PROXY_ENV_VAR); |
|---|
| 41 |
if (!env) return ret_not_found; |
|---|
| 42 |
|
|---|
| 43 |
colon = strrchr(env, ':'); |
|---|
| 44 |
if (colon) { |
|---|
| 45 |
cherokee_buffer_add (proxy, env, colon-env); |
|---|
| 46 |
*port = atoi(colon+1); |
|---|
| 47 |
} else { |
|---|
| 48 |
cherokee_buffer_add (proxy, env, strlen(env)); |
|---|
| 49 |
*port = PROXY_PORT_DEFAULT; |
|---|
| 50 |
} |
|---|
| 51 |
|
|---|
| 52 |
return ret_ok; |
|---|
| 53 |
} |
|---|
| 54 |
|
|---|
| 55 |
|
|---|
| 56 |
ret_t |
|---|
| 57 |
cget_find_proxy (cherokee_buffer_t *proxy, cuint_t *port) |
|---|
| 58 |
{ |
|---|
| 59 |
ret_t ret; |
|---|
| 60 |
|
|---|
| 61 |
ret = find_proxy_environment (proxy, port); |
|---|
| 62 |
if (ret == ret_ok) goto found; |
|---|
| 63 |
|
|---|
| 64 |
TRACE(ENTRIES, "Not found %s\n", ""); |
|---|
| 65 |
return ret_not_found; |
|---|
| 66 |
|
|---|
| 67 |
found: |
|---|
| 68 |
TRACE(ENTRIES, "proxy='%s' port=%d\n", proxy->buf, *port); |
|---|
| 69 |
return ret_ok; |
|---|
| 70 |
} |
|---|