diff --git a/src/server/distrend.c b/src/server/distrend.c --- a/src/server/distrend.c +++ b/src/server/distrend.c @@ -85,6 +85,10 @@ int distrend_do_config(int argc, char *a int distrend_config_free(struct distrend_config *config); int distrend_handle_request(struct distrend_listens *listens, struct distrend_client *client, struct distren_request *req, void *reqdata, struct general_info *geninfo); +/** + client request handlers + */ +int distrend_handle_version(struct general_info *geninfo, struct distrend_client *client, size_t req_len, void *req_data); /* **************XML Functions**************** */ void update_general_info(struct general_info *geninfo); @@ -170,6 +174,8 @@ int main(int argc, char *argv[]) } } + distrend_listen_handler_add(general_info.config->listens, DISTREN_REQUEST_VERSION, &distrend_handle_version); + int slaveKey = 0; // Remotio should set me on a per-slave basis /* Main Loop */ general_info.config->die = 0; @@ -219,51 +225,46 @@ int main(int argc, char *argv[]) /* ********************** Functions ************************* */ -int distrend_handle_request(struct distrend_listens *listens, struct distrend_client *client, struct distren_request *req, void *reqdata, struct general_info *geninfo) +int distrend_handle_version(struct general_info *geninfo, struct distrend_client *client, size_t req_len, void *req_data) { - size_t counter; char *tmp_str; char fixedbuf[32]; - /* for response requests... if that makes any less sense ;-) */ struct distren_request *newreq; - fprintf(stderr, "I can haz data %d bytes long:", req->len); - for(counter = 0; counter < req->len; counter ++) - fputc(((char *)reqdata)[counter], stderr); - fputc('\n', stderr); - - switch(req->type) + if(client->state != DISTREND_CLIENT_PREVERSION) + { + distrend_send_disconnect(geninfo->config->listens, client, "You have already sent the VERSION command."); + } + if(strlen(PACKAGE_STRING) == req_len + && !strncmp(PACKAGE_STRING, req_data, req_len)) { - case DISTREN_REQUEST_VERSION: - if(strlen(PACKAGE_STRING) == req->len - && !strncmp(PACKAGE_STRING, reqdata, req->len)) - { - /** - The client and I claim to be of the same version of distren :-D - Now we will mark the client as valid. - */ - - } - else - { - /** - The client claims to be of a different version of distren. - Now we will just send a disconnect packet and disconnect the client. - */ - strncpy(fixedbuf, reqdata, 31); - fixedbuf[31] = '\0'; - if(req->len < 31) - fixedbuf[req->len] = '\0'; + /** + The client and I claim to be of the same version of distren :-D + Now we will mark the client as valid. + + We won't increment his time to live, though, because it shouldn't take + him that long to auth. + */ + client->state = DISTREND_CLIENT_PREAUTH; - _distren_asprintf(&tmp_str, "You have tried to connect to a %s server when your client claims to be running %s. Bye ;-)\n", PACKAGE_STRING, fixedbuf); - distrend_send_disconnect(listens, client, tmp_str); - } + distren_request_new(&newreq, strlen(PACKAGE_STRING), DISTREN_REQUEST_VERSION); + distrend_client_write_request(geninfo->config->listens, client, newreq, PACKAGE_STRING); + distren_request_free(newreq); + } + else + { + /** + The client claims to be of a different version of distren. + Now we will just send a disconnect packet and disconnect the client. + */ + strncpy(fixedbuf, req_data, 31); + fixedbuf[31] = '\0'; + if(req_len < 31) + fixedbuf[req_len] = '\0'; - distren_request_new(&newreq, strlen(VERSION), DISTREN_REQUEST_VERSION); - distrend_client_write_request(listens, client, newreq, VERSION); - distren_request_free(newreq); - break; + _distren_asprintf(&tmp_str, "You have tried to connect to a %s server when your client claims to be running %s. Bye ;-)\n", PACKAGE_STRING, fixedbuf); + distrend_send_disconnect(geninfo->config->listens, client, tmp_str); } return 0;