Permalink
Browse files

type implementiert

  • Loading branch information...
1 parent e3a1730 commit a28f999918e1ad5fd45d914a7498fbd3d1d88534 Robert A committed Jun 7, 2009
Showing with 45 additions and 2 deletions.
  1. +45 −2 duoit.c
View
47 duoit.c
@@ -15,7 +15,8 @@
#define DPORT "3020" // the default port for data transfering
#define BACKLOG 10 // how many pending connections queue will hold
#define PATHLENGTH 256 //default pathlength for pwd-command - may be dynamically increased later
-
+#define IMGAGE 1 //type image/binary
+#define ASCII 2 //type ascii
//struct for command and parameter pointers
typedef struct {
char *command;
@@ -28,6 +29,7 @@ typedef struct usr {
int dsocket;
int dport;
int passv;
+ int type;
char *pwd;
int pwd_len;
struct usr *next;
@@ -109,6 +111,7 @@ int ini_user_list(int newfd, usr **user) {
(*user)->dsocket = 0;
(*user)->dport = get_port(newfd);
(*user)->passv = 0;
+ (*user)->type = 1;
(*user)->pwd = calloc(1, PATHLENGTH);
(*user)->pwd_len = PATHLENGTH;
(*user)->next = NULL;
@@ -130,6 +133,7 @@ int append_user(int newfd, usr *user){
user->dsocket = 0;
user->dport = get_port(newfd);
user->passv = 0;
+ user->type = 1;
user->pwd = calloc(1, PATHLENGTH);
user->pwd_len = PATHLENGTH;
user->next = NULL;
@@ -316,8 +320,43 @@ int user_command(instruc *instruction, usr *user) {
}
/*
+ * sets the mode of file transfer
+ */
+int set_user_type(instruc *instruction, usr *user) {
+ int i = 0;
+
+ if (!instruction->params) {
+ send_message(user->csocket, "501 Syntax error in parameters or arguments.");
+ return 1;
+ }
+ //demand one parameter - make its chars upper-case
+ while(instruction->params[i] != '\0') {
+ i++;
+ }
+ if (format_command(instruction->params, i)) {
+ send_message(user->csocket, "501 Syntax error in parameters or arguments.");
+ return 1;
+ }
+
+ if (((i==1) && instruction->params[0] == 'A') || !strcmp(instruction->params, "ASCII")) {
+ //ascii type demanded
+ user->type = 2;
+ send_message(user->csocket, "200 Type set to A");
+ return 0;
+ } else if (((i==1) && (instruction->params[0] == 'I' || instruction->params[0] == 'B')) \
+ || !strcmp(instruction->params, "IMAGE") || !strcmp(instruction->params, "BINARY")) {
+ //binary type demanded
+ user->type = 1;
+ send_message(user->csocket, "200 Type set to I");
+ return 0;
+ }
+
+ send_message(user->csocket, "501 Syntax error in parameters or arguments.");
+ return 1;
+}
+
+/*
* quits the connection with client
- * TODO: usr struct freigeben
*/
int quit_command(instruc *instruction, usr *user, fd_set *master, usr **head) {
@@ -410,6 +449,10 @@ int dispatch(usr *user, char *received, int received_len, fd_set *master, usr **
if (user_command(&instruction, user)) {
return 1;
}
+ } else if (!strcmp(instruction.command, "TYPE")) {
+ if (set_user_type(&instruction, user)) {
+ return 1;
+ }
} else if (!strcmp(instruction.command, "QUIT")) {
quit_command(&instruction, user, master, head);
} else {

0 comments on commit a28f999

Please sign in to comment.