int process_response(struct server_attr *attr) { switch (attr->resp.code) { case RESP_LS: process_ls(attr); break; case RESP_CD: process_cd(attr); break; case RESP_PWD: process_pwd(attr); break; case RESP_MKDIR: /* Success */ break; case RESP_RM: break; case RESP_DOWNLOAD: process_download(attr); break; case RESP_UPLOAD: process_upload(attr); break; case RESP_LS_ERR: /* Print error message just */ case RESP_CD_ERR: case RESP_MKDIR_ERR: case RESP_RM_ERR: case RESP_DOWNLOAD_ERR: case RESP_UPLOAD_ERR: printf("%s\n", attr->data); break; case RESP_EXIT: return RESP_EXIT; /* Receive exit confirm */ break; default: err_exit(0, "UNKNOWN RESPONSE: (%#X)", attr->resp.code); } return 0; }
char *my_lcd(int fd, FILE *fp, char *param, char **pwds) { char *d; if (!(param = get_path(fd, fp, param)) || !strcmp(param, ESYNTAX) || !strcmp(param, ENOTTAKEN)) return (param); d = cd_init(fd, fp, param, pwds); if (!d || !strcmp(d, EBADSEQ)) return (d); if (d[0] != '/') { param = d; d = malloc(sizeof(*d) * (strlen(param) + strlen(pwds[CURRENT]) + 2)); if (!d) return (alloc_err(fd, fp, 0)); strcpy(d, pwds[CURRENT]); if (strcmp(d + strlen(d) - 10, "Anonymous/")) strcat(d, "/"); strcat(d, param); free(param); } return (process_cd(fd, fp, d, pwds)); }