MCPcopy Create free account
hub / github.com/apache/httpd / make_server_id

Function make_server_id

modules/proxy/mod_proxy_balancer.c:753–796  ·  view source on GitHub ↗

* Compute an ID for a vhost based on what makes it selected by requests. * The second and more Host(s)/IP(s):port(s), and the ServerAlias(es) are * optional (see make_servers_ids() below). */

Source from the content-addressed store, hash-verified

751 * optional (see make_servers_ids() below).
752 */
753 static const char *make_server_id(server_rec *s, apr_pool_t *p, int full)
754{
755 apr_md5_ctx_t md5_ctx;
756 unsigned char md5[APR_MD5_DIGESTSIZE];
757 char id[2 * APR_MD5_DIGESTSIZE + 1];
758 char host_ip[64]; /* for any IPv[46] string */
759 server_addr_rec *sar;
760 int i;
761
762 apr_md5_init(&md5_ctx);
763 for (sar = s->addrs; sar; sar = sar->next) {
764 host_ip[0] = '\0';
765 apr_sockaddr_ip_getbuf(host_ip, sizeof host_ip, sar->host_addr);
766 apr_md5_update(&md5_ctx, (void *)sar->virthost, strlen(sar->virthost));
767 apr_md5_update(&md5_ctx, (void *)host_ip, strlen(host_ip));
768 apr_md5_update(&md5_ctx, (void *)&sar->host_port,
769 sizeof(sar->host_port));
770 if (!full) {
771 break;
772 }
773 }
774 if (s->server_hostname) {
775 apr_md5_update(&md5_ctx, (void *)s->server_hostname,
776 strlen(s->server_hostname));
777 }
778 if (full) {
779 if (s->names) {
780 for (i = 0; i < s->names->nelts; ++i) {
781 const char *name = APR_ARRAY_IDX(s->names, i, char *);
782 apr_md5_update(&md5_ctx, (void *)name, strlen(name));
783 }
784 }
785 if (s->wild_names) {
786 for (i = 0; i < s->wild_names->nelts; ++i) {
787 const char *name = APR_ARRAY_IDX(s->wild_names, i, char *);
788 apr_md5_update(&md5_ctx, (void *)name, strlen(name));
789 }
790 }
791 }
792 apr_md5_final(md5, &md5_ctx);
793 ap_bin2hex(md5, APR_MD5_DIGESTSIZE, id);
794
795 return apr_pstrmemdup(p, id, sizeof(id) - 1);
796}
797
798/*
799 * First try to compute an unique ID for each vhost with minimal criteria,

Callers 1

make_servers_idsFunction · 0.85

Calls 1

ap_bin2hexFunction · 0.85

Tested by

no test coverage detected