static void add_url(char *url) { static struct connection *tail; char *e; struct connection *conn = must_alloc(sizeof(struct connection)); /* Hack for BME files. */ e = strchr(url, ' '); if (e) *e = '\0'; conn->out = -1; conn->url = must_strdup(url); /* isolate the host from original url */ e = is_http(url); if (e) e = strchr(e, '/'); else e = strchr(url + 1, '/'); if (e) *e = '\0'; conn->host = must_strdup(url); if (comics) tail->next = conn; else comics = head = conn; tail = conn; ++n_comics; }
static int redirect(struct connection *conn, int status) { char *p = strstr(conn->buf, "Location:"); if (p) { char *e; for (p += 9; isspace(*p); ++p) ; e = strchr(p, '\n'); if (e) { while (isspace(*(e - 1))) --e; *e = '\0'; if (!conn->redirect_ok || verbose > 1) printf("WARNING: %s redirected to %s\n", conn->url, p); release_connection(conn); free(conn->url); if (is_http(p)) conn->url = strdup(p); else { /* Relative URL */ int len = strlen(conn->host) + strlen(p) + 2; conn->url = malloc(len); if (conn->url) sprintf(conn->url, "%s/%s", conn->host, p); } if (!conn->url) { printf("Out of memory\n"); return 1; } /* This will cause a bogus Multiple * Closes error if it fails. */ if (build_request(conn)) return fail_redirect(conn); return 0; } } printf("%s: %d with no new location\n", conn->host, status); return status; }
int build_request(struct connection *conn) { char *url, *host, *p; url = is_http(conn->url); if (!url) { #ifdef WANT_SSL printf("Only http/https supported\n"); #else printf("Only http supported\n"); #endif return 1; } p = strchr(url, '/'); if (p) { *p = '\0'; host = strdup(url); *p = '/'; url = p; } else { host = strdup(url); url = "/"; } if (!host) { printf("Out of memory\n"); return 1; } #ifdef REUSE_SOCKET if (CONN_OPEN) { if (hostcmp(conn->host, host)) { if (verbose) printf("New connection for %s\n", host); release_connection(conn); } else if (verbose) printf("Reuse connection for %s\n", conn->host); } #endif if (!get_buf(conn)) { free(host); return 1; } if (!CONN_OPEN) if (open_socket(conn, host)) { printf("Connection failed to %s\n", host); free(host); free_buf(conn); return 1; } if (proxy) snprintf(conn->buf, BUFSIZE, "%s http://%s/%s %s\r\n", method, host, url, http); else if (strchr(url, ' ')) { /* Some sites cannot handle spaces in the url. */ int n = sprintf(conn->buf, "%s ", method); char *in = url, *out = conn->buf + n; while (*in) if (*in == ' ') { *out++ = '%'; *out++ = '2'; *out++ = '0'; ++in; } else *out++ = *in++; sprintf(out, " %s\r\n", http); } else snprintf(conn->buf, BUFSIZE, "%s %s %s\r\n", method, url, http); add_full_header(conn, host); free(host); if (verbose > 1) printf("%s %s", proxy ? ">P" : ">", conn->buf); if (conn->referer) sprintf(conn->buf + strlen(conn->buf), "Referer: %.200s\r\n", conn->referer); strcat(conn->buf, "\r\n"); conn->curp = conn->buf; conn->length = strlen(conn->buf); return 0; }
glite_delegation_ctx *glite_delegation_new(const char *endpoint) { int ret; glite_delegation_ctx *ctx; ctx = calloc(sizeof(*ctx), 1); if(!ctx) return NULL; if( (! is_http(endpoint)) && (! is_https(endpoint)) && (! is_httpg(endpoint)) ) { char *error; char *sd_type = getenv(GLITE_DELEGATION_SD_ENV); if(!sd_type) sd_type = GLITE_DELEGATION_SD_TYPE; ctx->endpoint = glite_discover_endpoint(sd_type, endpoint, &error); if (!ctx->endpoint) { glite_delegation_set_error(ctx, "glite_delegation: service discovery error %s", error); free(error); return ctx; } } else { ctx->endpoint = strdup(endpoint); if (!ctx->endpoint) { glite_delegation_set_error(ctx, "glite_delegation: out of memory"); return ctx; } } ctx->soap = soap_new(); /* Register the CGSI plugin if secure communication is requested */ if (is_https(ctx->endpoint)) ret = soap_cgsi_init(ctx->soap, CGSI_OPT_DISABLE_NAME_CHECK | CGSI_OPT_SSL_COMPATIBLE); else if (is_httpg(ctx->endpoint)) ret = soap_cgsi_init(ctx->soap, CGSI_OPT_DISABLE_NAME_CHECK); else ret = 0; if (ret) { glite_delegation_set_error(ctx, "Failed to initialize the GSI plugin"); return ctx; } /* Namespace setup should happen after CGSI plugin initialization */ if ( soap_set_namespaces(ctx->soap, delegation_namespaces) ) { _fault_to_error(ctx, "Setting SOAP namespaces"); return ctx; } return ctx; }