int _tmain(int argc, _TCHAR* argv[]) { WSADATA ws; WSAStartup(MAKEWORD(2, 2), &ws);; struct proxy *prox; prox = proxy_create(); assert(prox); proxy_set(prox, "192.168.79.1", 1080, "test", "0"); proxy_connect(prox, "113.108.16.44", 25); proxy_recv_line(prox, buff, 512); return 0; }
static int soxy_hook_close(struct tracy_event *e) { long ret; proxy_t * proxy; if(e->child->pre_syscall) { proxy = proxy_find(e, e->args.a0); if(proxy != NULL) { if(proxy->map != NULL) { /* assume it doesn't fail. */ tracy_munmap(e->child, &ret, proxy->map, 0x1000); proxy->map = NULL; } free(proxy); proxy_set(e, e->args.a0, NULL); } } return 0; }
static int soxy_hook_socket(struct tracy_event *e) { proxy_t * proxy; if (e->child->pre_syscall) { cproxy(e->child->custom)->boe = e->args.a0; cproxy(e->child->custom)->ba = e->args.a1; } else { if (cproxy(e->child->custom)->boe == AF_INET && cproxy(e->child->custom)->ba == SOCK_STREAM) { fprintf(stderr, "We found a relevant fd\n"); proxy = (proxy_t *) calloc(1, sizeof(proxy_t)); if(proxy == NULL) { fprintf(stderr, "soxy_hook_socket: calloc failed\n"); return -1; } proxy_set(e, e->args.return_code, proxy); } } return TRACY_HOOK_CONTINUE; }
static void apteryx__set (Apteryx__Server_Service *service, const Apteryx__Set *set, Apteryx__OKResult_Closure closure, void *closure_data) { Apteryx__OKResult result = APTERYX__OKRESULT__INIT; const char *path = NULL; const char *value = NULL; result.result = 0; int validation_result = 0; int validation_lock = 0; int proxy_result = 0; bool db_result = false; int i; /* Check parameters */ if (set == NULL || set->n_sets == 0 || set->sets == NULL) { ERROR ("SET: Invalid parameters.\n"); result.result = -EINVAL; closure (&result, closure_data); INC_COUNTER (counters.set_invalid); return; } INC_COUNTER (counters.set); /* Debug */ for (i=0; apteryx_debug && i<set->n_sets; i++) { DEBUG ("SET: %s = %s\n", set->sets[i]->path, set->sets[i]->value); } /* Proxy first */ for (i=0; i<set->n_sets; i++) { path = set->sets[i]->path; value = set->sets[i]->value; if (value && value[0] == '\0') value = NULL; proxy_result = proxy_set (path, value, set->ts); if (proxy_result == 0) { /* Result success */ DEBUG ("SET: %s = %s proxied\n", path, value); /* Mark the set as processed */ notify_watchers (set->sets[i]->path); free (set->sets[i]->path); set->sets[i]->path = NULL; } else if (proxy_result < 0) { result.result = proxy_result; goto exit; } } /* Validate */ for (i=0; i<set->n_sets; i++) { path = set->sets[i]->path; if (!path) continue; value = set->sets[i]->value; if (value && value[0] == '\0') value = NULL; /* Validate new data */ validation_result = validate_set (path, value); if (validation_result != 0) validation_lock++; if (validation_result < 0) { DEBUG ("SET: %s = %s refused by validate\n", path, value); result.result = validation_result; goto exit; } } /* Set in the database */ pthread_rwlock_wrlock (&db_lock); for (i=0; i<set->n_sets; i++) { path = set->sets[i]->path; if (!path) continue; value = set->sets[i]->value; if (value && value[0] == '\0') value = NULL; /* Add/Delete to/from database */ if (value) db_result = db_add_no_lock (path, (unsigned char*)value, strlen (value) + 1, set->ts); else db_result = db_delete_no_lock (path, set->ts); if (!db_result) { DEBUG ("SET: %s = %s refused by DB\n", path, value); result.result = -EBUSY; pthread_rwlock_unlock (&db_lock); goto exit; } } pthread_rwlock_unlock (&db_lock); /* Set succeeded */ result.result = 0; exit: /* Return result and notify watchers */ if (validation_result >= 0 && result.result == 0) { /* Notify watchers */ for (i=0; i<set->n_sets; i++) { if (set->sets[i]->path) notify_watchers (set->sets[i]->path); } } /* Return result */ closure (&result, closure_data); /* Release validation lock - this is a sensitive value */ while (validation_lock) { DEBUG("SET: unlocking mutex\n"); pthread_mutex_unlock (&validating); validation_lock--; } return; }