All pastes #428718 Raw Edit

Someone

public text v1 · immutable
·published 2007-04-07 19:43 UTC
rendered paste body
SQLVHOST_BACKEND_GETVHOST(mod_postgresql_vhost_get_vhost) {
        plugin_data *p = p_d;
        int nFields;
        PGresult   *result;
        UNUSED(host);
        char *fValue;
        char *vhostID;
        char *vhostDIR;

        /* no host specified? */
        if (!con->uri.authority->used) return HANDLER_GO_ON;

        vhostDIR = (char *) g_hash_table_lookup(vhost_table, con->uri.authority->ptr);

        if (vhostDIR == NULL)
        {
                PGresult   *result;
                //g_hash_table_insert(person_table, contact, person);

                mod_postgresql_vhost_patch_connection(srv, con, p);

                if (!p->conf.conn) return HANDLER_GO_ON;

                /* TODO: Change to a stored proc to simiplify this */
                /* build and run SQL query */
                buffer_copy_string_buffer(p->tmp_buf, p->conf.postgresql_pre);
                if (p->conf.postgresql_post->used) {
                        buffer_append_string_buffer(p->tmp_buf, con->uri.authority);
                        buffer_append_string_buffer(p->tmp_buf, p->conf.postgresql_post);
                }
                result = PQexec(p->conf.conn, p->tmp_buf->ptr);
                // For Async requests. Database will block/slow down your daemon
                // result = PQsendQuery(p->conf.conn, p->tmp_buf->ptr);
                //
                if (result == NULL) {
                        log_error_write(srv, __FILE__, __LINE__, "s", "postgresql malloc failure");
                        return HANDLER_GO_ON;
                }
                if (PQresultStatus(result) != PGRES_TUPLES_OK)
                {
                        log_error_write(srv, __FILE__, __LINE__,  "ss", "PQerrorMessage :", PQerrorMessage(p->conf.conn));
                        PQclear(result);
                        // Fixme:
                        // Will test for bad connection in another place
                        //PQfinish(p->conf.conn);
                        return HANDLER_GO_ON;
                }
                // Fixme: We checked for tupels already, but will add more sanity
                nFields = PQnfields(result);
                if (PQntuples(result) < 1 || nFields < 1 ||
                        (fValue = PQgetvalue(result, 0, 0)) == NULL || !*fValue) {
                        /* no such virtual host */
                        PQclear(result);
                        return HANDLER_GO_ON;
                }
#ifdef WITH_DEBUGGING
                log_error_write(srv, __FILE__, __LINE__,  "ss", " PQgetvalue :",  PQgetvalue(result, 0, 0));
#endif
                buffer_copy_string(docroot, fValue);
                g_hash_table_insert(vhost_table, con->uri.authority->ptr , fValue);
                PQclear(result);
        }
        else
        {
                log_error_write(srv, __FILE__, __LINE__,  "ss", " The buffered docroot isssss :",  vhostDIR);
                buffer_copy_string(docroot, vhostDIR);
        }


        return 0;
}