const char* req_header(req_t* req, const char *name) { g_return_val_if_fail(req != NULL, NULL); return hl_find(req->headers, name); }
static net_fd openapp(const char *hostName, int port, unsigned short cto, unsigned short sto, unsigned short rto, int sbufsiz, int rbufsiz) { int s = 0; struct in_addr; net_fd appfd; struct hostent *host; host = hl_find(hostName); if (host == NULL) { WOLog(WO_ERR, "openapp(): host lookup failed for %s", hostName); return NULL_FD; } WOLog(WO_INFO, "attempting to connect to %s on port %d",host->h_name,port); s = socket(AF_INET, SOCK_STREAM, 0); if (s < 0) { char *errMsg = WA_errorDescription(WA_error()); WOLog(WO_ERR,"couldn't create socket to %s (%d): %s", host->h_name, port, errMsg); WA_freeErrorDescription(errMsg); return NULL_FD; } /* set send buffer size */ if (sbufsiz != 0) { if (setsockopt(s, SOL_SOCKET, SO_SNDBUF, (void *)&sbufsiz, sizeof(sbufsiz)) < 0) { char *errMsg = WA_errorDescription(WA_error()); WOLog(WO_WARN, "openapp(): error setting send buffer size to %d: %s", sbufsiz, errMsg); WA_freeErrorDescription(errMsg); } } /* set receive buffer size */ if (rbufsiz != 0) { if (setsockopt(s, SOL_SOCKET, SO_RCVBUF, (void *)&rbufsiz, sizeof(rbufsiz)) < 0) { char *errMsg = WA_errorDescription(WA_error()); WOLog(WO_WARN, "openapp(): error setting receive buffer size to %d: %s", rbufsiz, errMsg); WA_freeErrorDescription(errMsg); } } /* Set the socket to be non-blocking. */ if (setBlockingState(s, 1) == -1) { char *errMsg = WA_errorDescription(WA_error()); WOLog(WO_ERR,"openapp(): couldn't set socket to nonblocking"); WA_freeErrorDescription(errMsg); closeSocket(s); return NULL_FD; } /* attempt to connect */ if (nonBlockingConnectHostent(s, cto, host, port) < 0) { char *errMsg = WA_errorDescription(WA_error()); WOLog(WO_ERR,"couldn't connect to %s (%d): %s", host->h_name, port, errMsg); WA_freeErrorDescription(errMsg); closeSocket(s); return NULL_FD; } /* set up the buffer */ appfd = WOMALLOC(sizeof(netfd)); appfd->s = s; appfd->status = TR_OK; appfd->pos = 0; appfd->send_to = sto; appfd->recv_to = rto; appfd->count = 0; return appfd; }