// // Misc tools // int process_inq(char *buffer, ibp_depotinfo_t *di) { char *bstate, *bstate2, *p, *key, *d; int err; memset(di, 0, sizeof(ibp_depotinfo_t)); p = tbx_stk_string_token(buffer, " ", &bstate, &err); while (err == 0) { key = tbx_stk_string_token(p, ":", &bstate2, &err); d = tbx_stk_string_token(NULL, ":", &bstate2, &err); if (strcmp(key, ST_VERSION) == 0) { di->majorVersion = atof(d); di->minorVersion = atof(tbx_stk_string_token(NULL, ":", &bstate2, &err)); } else if (strcmp(key, ST_DATAMOVERTYPE) == 0) { //*** I just skip this. IS it used??? *** } else if (strcmp(key, ST_RESOURCEID) == 0) { di->rid = atol(d); } else if (strcmp(key, ST_RESOURCETYPE) == 0) { di->type = atol(d); } else if (strcmp(key, ST_CONFIG_TOTAL_SZ) == 0) { di->TotalConfigured = atoll(d); } else if (strcmp(key, ST_SERVED_TOTAL_SZ) == 0) { di->TotalServed = atoll(d); } else if (strcmp(key, ST_USED_TOTAL_SZ) == 0) { di->TotalUsed = atoll(d); } else if (strcmp(key, ST_USED_HARD_SZ) == 0) { di->HardUsed = atoll(d); } else if (strcmp(key, ST_SERVED_HARD_SZ) == 0) { di->HardServed = atoll(d); } else if (strcmp(key, ST_CONFIG_HARD_SZ) == 0) { di->HardConfigured = atoll(d); } else if (strcmp(key, ST_ALLOC_TOTAL_SZ) == 0) { di->SoftAllocable = atoll(d); //** I have no idea what field this maps to.... } else if (strcmp(key, ST_ALLOC_HARD_SZ) == 0) { di->HardAllocable = atoll(d); } else if (strcmp(key, ST_DURATION) == 0) { di->Duration = atoll(d); } else if (strcmp(key, "RE") == 0) { err = 1; } else { log_printf(1, "process_inq: Unknown tag:%s key=%s data=%s\n", p, key, d); } p = tbx_stk_string_token(NULL, " ", &bstate, &err); } return(IBP_OK); }
char *change_hostport_cc(char *old_hostport, ibp_connect_context_t *cc) { char host[MAX_HOST_SIZE], new_hostport[MAX_HOST_SIZE]; char *hp2 = strdup(old_hostport); char *bstate; int fin, port; strncpy(host, tbx_stk_string_token(hp2, HP_HOSTPORT_SEPARATOR, &bstate, &fin), sizeof(host)-1); host[sizeof(host)-1] = '\0'; port = atoi(bstate); set_hostport(new_hostport, sizeof(new_hostport), host, port, cc); free(hp2); return(strdup(new_hostport)); }
int parse_cap(ibp_context_t *ic, ibp_cap_t *cap, char *host, int *port, char *key, char *typekey) { char *bstate; int finished = 0; int i, j, n, m; char rr[16]; host[MAX_HOST_SIZE-1] = '\0'; host[0] = '\0'; key[MAX_KEY_SIZE-1] = '\0'; key[0] = '\0'; typekey[MAX_KEY_SIZE-1] = '\0'; typekey[0] = '\0'; *port = -1; if (cap == NULL) return(1); char *temp = strdup(cap); char *ptr; tbx_stk_string_token(temp, "/", &bstate, &finished); //** gets the ibp:/ //log_printf(15, "1 ptr=%s\n", ptr); ptr = tbx_stk_string_token(NULL, ":", &bstate, &finished); //** This should be the hostname //log_printf(15, "2 ptr=%s\n", ptr); ptr = &(ptr[1]); //** Skip the extra "/" //log_printf(15, "3 ptr=%s\n", ptr); sscanf(tbx_stk_string_token(NULL, "/", &bstate, &finished), "%d", port); strncpy(host, ptr, MAX_HOST_SIZE-1); //** This should be the host name //log_printf(15, "ptr=%s host=%s ccmode=%d\n", ptr, host, ic->connection_mode); strncpy(key, tbx_stk_string_token(NULL, "/", &bstate, &finished), 255); strncpy(typekey, tbx_stk_string_token(NULL, "/", &bstate, &finished), 255); switch (ic->connection_mode) { case IBP_CMODE_RID: n = strlen(host); host[n] = '#'; n++; m = strlen(key); m = ((m+n) > MAX_HOST_SIZE-1) ? MAX_HOST_SIZE-1 - n : m; for (i=0; i<m; i++) { if (key[i] == '#') { host[i+n] = 0; break; } host[i+n] = key[i]; } break; case IBP_CMODE_ROUND_ROBIN: n = tbx_atomic_inc(ic->rr_count); n = n % ic->rr_size; snprintf(rr, sizeof(rr), "%d", n); n = strlen(host); host[n] = '#'; n++; for (j=0, i=n; (i<MAX_HOST_SIZE) && (rr[j] != '\0'); i++, j++) host[i] = rr[j]; if (i<1024) { host[i] = '\0'; } else { host[MAX_HOST_SIZE-1] = '\0'; } } free(temp); log_printf(14, "parse_cap: CAP=%s * parsed=[%s]:%d/%s/%s\n", cap, host, *port, key, typekey); if (finished == 1) log_printf(0, "parse_cap: Error parsing cap %s\n", cap); return(finished); }
host_portal_t *create_hportal(portal_context_t *hpc, void *connect_context, char *hostport, int min_conn, int max_conn, apr_time_t dt_connect) { host_portal_t *hp; log_printf(15, "create_hportal: hpc=%p\n", hpc); tbx_type_malloc_clear(hp, host_portal_t, 1); assert_result(apr_pool_create(&(hp->mpool), NULL), APR_SUCCESS); char host[sizeof(hp->host)]; int port; char *hp2 = strdup(hostport); char *bstate; int fin; host[0] = '\0'; strncpy(host, tbx_stk_string_token(hp2, HP_HOSTPORT_SEPARATOR, &bstate, &fin), sizeof(host)-1); host[sizeof(host)-1] = '\0'; port = atoi(bstate); free(hp2); log_printf(15, "create_hportal: hostport: %s host=%s port=%d min=%d max=%d dt=" TT "\n", hostport, host, port, min_conn, max_conn, dt_connect); strncpy(hp->host, host, sizeof(hp->host)-1); hp->host[sizeof(hp->host)-1] = '\0'; //** Check if we can resolve the host's IP address char in_addr[6]; if (tbx_dnsc_lookup(host, in_addr, NULL) != 0) { log_printf(1, "create_hportal: Can\'t resolve host address: %s:%d\n", host, port); hp->invalid_host = 0; // hp->invalid_host = 1; } else { hp->invalid_host = 0; } hp->port = port; snprintf(hp->skey, sizeof(hp->skey), "%s", hostport); hp->connect_context = hpc->fn->dup_connect_context(connect_context); hp->context = hpc; hp->min_conn = min_conn; hp->max_conn = max_conn; hp->dt_connect = dt_connect; hp->sleeping_conn = 0; hp->workload = 0; hp->executing_workload = 0; hp->cmds_processed = 0; hp->n_conn = 0; hp->conn_list = tbx_stack_new(); hp->closed_que = tbx_stack_new(); hp->que = tbx_stack_new(); hp->direct_list = tbx_stack_new(); hp->pause_until = 0; hp->stable_conn = max_conn; hp->closing_conn = 0; hp->failed_conn_attempts = 0; hp->successful_conn_attempts = 0; hp->abort_conn_attempts = hpc->abort_conn_attempts; apr_thread_mutex_create(&(hp->lock), APR_THREAD_MUTEX_DEFAULT, hp->mpool); apr_thread_cond_create(&(hp->cond), hp->mpool); return(hp); }