summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/libfetch/common.c1
-rw-r--r--lib/libfetch/http.c80
-rw-r--r--lib/libgpio/gpio.c41
-rw-r--r--lib/libgpio/libgpio.h8
4 files changed, 121 insertions, 9 deletions
diff --git a/lib/libfetch/common.c b/lib/libfetch/common.c
index 7dc70b0..cd1ae92 100644
--- a/lib/libfetch/common.c
+++ b/lib/libfetch/common.c
@@ -918,6 +918,7 @@ fetch_ssl(conn_t *conn, const struct url *URL, int verbose)
}
SSL_load_error_strings();
+ OPENSSL_config(NULL);
conn->ssl_meth = SSLv23_client_method();
conn->ssl_ctx = SSL_CTX_new(conn->ssl_meth);
diff --git a/lib/libfetch/http.c b/lib/libfetch/http.c
index fe4e9de..cc3fa15 100644
--- a/lib/libfetch/http.c
+++ b/lib/libfetch/http.c
@@ -1370,12 +1370,51 @@ http_authorize(conn_t *conn, const char *hdr, http_auth_challenges_t *cs,
/*****************************************************************************
* Helper functions for connecting to a server or proxy
*/
+static int
+http_connect_tunnel(conn_t *conn, struct url *URL, struct url *purl, int isproxyauth)
+{
+ const char *p;
+ http_auth_challenges_t proxy_challenges;
+ init_http_auth_challenges(&proxy_challenges);
+ http_cmd(conn, "CONNECT %s:%d HTTP/1.1",
+ URL->host, URL->port);
+ http_cmd(conn, "Host: %s:%d",
+ URL->host, URL->port);
+ if (isproxyauth > 0)
+ {
+ http_auth_params_t aparams;
+ init_http_auth_params(&aparams);
+ if (*purl->user || *purl->pwd) {
+ aparams.user = strdup(purl->user);
+ aparams.password = strdup(purl->pwd);
+ } else if ((p = getenv("HTTP_PROXY_AUTH")) != NULL &&
+ *p != '\0') {
+ if (http_authfromenv(p, &aparams) < 0) {
+ http_seterr(HTTP_NEED_PROXY_AUTH);
+ return HTTP_PROTOCOL_ERROR;
+ }
+ } else if (fetch_netrc_auth(purl) == 0) {
+ aparams.user = strdup(purl->user);
+ aparams.password = strdup(purl->pwd);
+ }
+ else {
+ // No auth information found in system - exiting with warning.
+ warnx("Missing username and/or password set");
+ return HTTP_PROTOCOL_ERROR;
+ }
+ http_authorize(conn, "Proxy-Authorization",
+ &proxy_challenges, &aparams, purl);
+ clean_http_auth_params(&aparams);
+ }
+ http_cmd(conn, "");
+ return 0;
+}
/*
* Connect to the correct HTTP server or proxy.
*/
static conn_t *
-http_connect(struct url *URL, struct url *purl, const char *flags)
+http_connect(struct url *URL, struct url *purl, const char *flags, int isproxyauth)
{
struct url *curl;
conn_t *conn;
@@ -1407,13 +1446,17 @@ http_connect(struct url *URL, struct url *purl, const char *flags)
return (NULL);
init_http_headerbuf(&headerbuf);
if (strcasecmp(URL->scheme, SCHEME_HTTPS) == 0 && purl) {
- http_cmd(conn, "CONNECT %s:%d HTTP/1.1",
- URL->host, URL->port);
- http_cmd(conn, "Host: %s:%d",
- URL->host, URL->port);
- http_cmd(conn, "");
- if (http_get_reply(conn) != HTTP_OK) {
- http_seterr(conn->err);
+ if (http_connect_tunnel(conn, URL, purl, isproxyauth) > 0) {
+ fetch_syserr();
+ goto ouch;
+ }
+ /* Get replay from CONNECT Tunnel attempt */
+ int httpreply = http_get_reply(conn);
+ if (httpreply != HTTP_OK) {
+ http_seterr(httpreply);
+ /* If the error is a 407/HTTP_NEED_PROXY_AUTH */
+ if (httpreply == HTTP_NEED_PROXY_AUTH)
+ goto proxyauth;
goto ouch;
}
/* Read and discard the rest of the proxy response */
@@ -1453,6 +1496,15 @@ ouch:
fetch_close(conn);
errno = serrno;
return (NULL);
+proxyauth:
+ /* returning a "dummy" object with error
+ * set to 407/HTTP_NEED_PROXY_AUTH */
+ serrno = errno;
+ clean_http_headerbuf(&headerbuf);
+ fetch_close(conn);
+ errno = serrno;
+ conn->err = HTTP_NEED_PROXY_AUTH;
+ return (conn);
}
static struct url *
@@ -1601,9 +1653,19 @@ http_request_body(struct url *URL, const char *op, struct url_stat *us,
}
/* connect to server or proxy */
- if ((conn = http_connect(url, purl, flags)) == NULL)
+ /* Getting connection without proxy connection */
+ if ((conn = http_connect(url, purl, flags, 0)) == NULL)
goto ouch;
+ /* If returning object request proxy auth, rerun the connect with proxy auth */
+ if (conn->err == HTTP_NEED_PROXY_AUTH) {
+ /* Retry connection with proxy auth */
+ if ((conn = http_connect(url, purl, flags, 1)) == NULL) {
+ http_seterr(HTTP_NEED_PROXY_AUTH);
+ goto ouch;
+ }
+ }
+
/* append port number only if necessary */
host = url->host;
if (url->port != fetch_default_port(url->scheme)) {
diff --git a/lib/libgpio/gpio.c b/lib/libgpio/gpio.c
index 8170822..48642f5 100644
--- a/lib/libgpio/gpio.c
+++ b/lib/libgpio/gpio.c
@@ -276,3 +276,44 @@ gpio_pin_pulsate(gpio_handle_t handle, gpio_pin_t pin)
{
return (gpio_pin_set_flag(handle, pin, GPIO_PIN_PULSATE));
}
+
+int
+gpio_pin_pwm(gpio_handle_t handle, gpio_pin_t pin)
+{
+ return (gpio_pin_set_flag(handle, pin, GPIO_PIN_PWM));
+}
+
+int
+gpio_pwm_get(gpio_handle_t handle, gpio_pwm_t pwm, gpio_pin_t pin,
+ uint32_t reg, uint32_t *value)
+{
+ struct gpio_pwm_req pwmreq;
+
+ bzero(&pwmreq, sizeof(pwmreq));
+ pwmreq.gp_pwm = pwm;
+ pwmreq.gp_pwm_pin = pin;
+ pwmreq.gp_pwm_reg = reg;
+ if (ioctl(handle, GPIOPWMGET, &pwmreq) < 0)
+ return (-1);
+ *value = pwmreq.gp_pwm_value;
+
+ return (0);
+
+}
+
+int
+gpio_pwm_set(gpio_handle_t handle, gpio_pwm_t pwm, gpio_pin_t pin,
+ uint32_t reg, uint32_t value)
+{
+ struct gpio_pwm_req pwmreq;
+
+ bzero(&pwmreq, sizeof(pwmreq));
+ pwmreq.gp_pwm = pwm;
+ pwmreq.gp_pwm_pin = pin;
+ pwmreq.gp_pwm_reg = reg;
+ pwmreq.gp_pwm_value = value;
+ if (ioctl(handle, GPIOPWMSET, &pwmreq) < 0)
+ return (-1);
+
+ return (0);
+}
diff --git a/lib/libgpio/libgpio.h b/lib/libgpio/libgpio.h
index a832234..6cc258e 100644
--- a/lib/libgpio/libgpio.h
+++ b/lib/libgpio/libgpio.h
@@ -35,6 +35,7 @@ __BEGIN_DECLS
#define GPIO_INVALID_HANDLE -1
typedef int gpio_handle_t;
+typedef int32_t gpio_pwm_t;
typedef uint32_t gpio_pin_t;
/*
@@ -104,6 +105,13 @@ int gpio_pin_pulldown(gpio_handle_t, gpio_pin_t);
int gpio_pin_invin(gpio_handle_t, gpio_pin_t);
int gpio_pin_invout(gpio_handle_t, gpio_pin_t);
int gpio_pin_pulsate(gpio_handle_t, gpio_pin_t);
+int gpio_pin_pwm(gpio_handle_t, gpio_pin_t);
+
+/* PWM Settings. */
+int gpio_pwm_get(gpio_handle_t, gpio_pwm_t pwm, gpio_pin_t,
+ uint32_t, uint32_t *);
+int gpio_pwm_set(gpio_handle_t, gpio_pwm_t pwm, gpio_pin_t,
+ uint32_t, uint32_t);
__END_DECLS
OpenPOWER on IntegriCloud