Changeset 223 for trunk

Show
Ignore:
Timestamp:
08/07/08 20:49:09 (4 months ago)
Author:
zany
Message:

catch errors and let the user know

Location:
trunk
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • trunk/apps/obexftp.c

    r222 r223  
    7575 
    7676        case OBEXFTP_EV_ERR: 
     77                // OBEX_EV_REQDONE: obex_rsp=43  (SE user reject) 
    7778                fprintf(stderr, "failed: %s\n", msg); 
    7879                break; 
     
    261262                        fprintf(stderr, "Error opening obexftp-client\n"); 
    262263                        exit(1); 
    263                         //return FALSE; 
     264                        //return -1; 
    264265                } 
    265266                if (!use_conn) { 
     
    282283#endif 
    283284                if (ret >= 0) 
    284                         return TRUE; 
     285                        return ret; 
    285286                switch (errno) { 
    286287                 
     
    291292                case ECONNREFUSED: 
    292293                        perror("The user may have rejected the transfer"); 
    293                         return FALSE; 
     294                        return -errno; 
    294295 
    295296                case EHOSTDOWN: 
     
    311312        obexftp_close(cli); 
    312313        cli = NULL; 
    313         return FALSE; 
     314        return ret; 
    314315} 
    315316 
     
    318319{ 
    319320        if (cli != NULL) { 
    320                 return TRUE; 
     321                return 0; 
    321322        } 
    322323 
     
    326327                // we should free() the find_bt result at some point 
    327328        } 
    328         if (!cli_connect_uuid(use_uuid, use_uuid_len)) 
     329        if (cli_connect_uuid(use_uuid, use_uuid_len) < 0) 
    329330                exit(1); 
    330331 
    331         return TRUE; 
     332        return 0; 
    332333} 
    333334 
     
    347348        int rsp[10]; 
    348349         
    349         if (!cli_connect_uuid(uuid, uuid_len)) { 
     350        if (cli_connect_uuid(uuid, uuid_len) < 0) { 
    350351                printf("couldn't connect.\n"); 
    351352                return; 
     
    437438int main(int argc, char *argv[]) 
    438439{ 
    439         int verbose=0; 
     440        int verbose = 0; 
    440441        int most_recent_cmd = 0; 
    441442        char *output_file = NULL; 
    442443        char *move_src = NULL; 
     444        int ret = 0; 
    443445 
    444446        /* preset mode of operation depending on our name */ 
     
    614616                                optind++; 
    615617                        } 
    616                         if(cli_connect ()) { 
     618                        if (cli_connect() >= 0) { 
    617619                                /* List folder */ 
    618620                                stat_entry_t *ent; 
     
    636638                                optind++; 
    637639                        } 
    638                         if(cli_connect ()) { 
     640                        if (cli_connect() >= 0) { 
    639641                                /* List folder */ 
    640                                 (void) obexftp_list(cli, NULL, optarg); 
     642                                ret = obexftp_list(cli, NULL, optarg); 
    641643                        } 
    642644                        most_recent_cmd = c; 
     
    644646 
    645647                case 'c': 
    646                         if(cli_connect ()) { 
     648                        if (cli_connect() >= 0) { 
    647649                                /* Change dir */ 
    648                                 (void) obexftp_setpath(cli, optarg, 0); 
     650                                ret = obexftp_setpath(cli, optarg, 0); 
    649651                        } 
    650652                        most_recent_cmd = c; 
     
    652654 
    653655                case 'C': 
    654                         if(cli_connect ()) { 
     656                        if (cli_connect() >= 0) { 
    655657                                /* Change or Make dir */ 
    656                                 (void) obexftp_setpath(cli, optarg, 1); 
     658                                ret = obexftp_setpath(cli, optarg, 1); 
    657659                        } 
    658660                        most_recent_cmd = c; 
     
    665667                case 'g': 
    666668                case 'G': 
    667                         if(cli_connect ()) { 
     669                        if (cli_connect() >= 0) { 
    668670                                char *p; /* basename or output_file */ 
    669671                                if ((p = strrchr(optarg, '/')) != NULL) p++; 
     
    672674                                /* Get file */ 
    673675                                if (obexftp_get(cli, p, optarg) && c == 'G') 
    674                                         (void) obexftp_del(cli, optarg); 
     676                                        ret = obexftp_del(cli, optarg); 
    675677                                output_file = NULL; 
    676678                        } 
     
    679681 
    680682                case 'p': 
    681                         if(cli_connect ()) { 
     683                        if (cli_connect() >= 0) { 
    682684                                char *p; /* basename or output_file */ 
    683685                                if ((p = strrchr(optarg, '/')) != NULL) p++; 
     
    685687                                if (output_file) p = output_file; 
    686688                                /* Send file */ 
    687                                 (void) obexftp_put_file(cli, optarg, p); 
     689                                ret = obexftp_put_file(cli, optarg, p); 
    688690                                output_file = NULL; 
    689691                        } 
     
    692694 
    693695                case 'k': 
    694                         if(cli_connect ()) { 
     696                        if (cli_connect() >= 0) { 
    695697                                /* Delete file */ 
    696                                 (void) obexftp_del(cli, optarg); 
     698                                ret = obexftp_del(cli, optarg); 
    697699                        } 
    698700                        most_recent_cmd = c; 
     
    700702 
    701703                case 'X': 
    702                         if(cli_connect ()) { 
     704                        if (cli_connect() >= 0) { 
    703705                                /* Get capabilities */ 
    704                                 (void) obexftp_get_capability(cli, optarg, 0); 
     706                                ret = obexftp_get_capability(cli, optarg, 0); 
    705707                        } 
    706708                        most_recent_cmd = 'h'; // not really 
     
    716718 
    717719                case 'x': 
    718                         if(cli_connect ()) { 
     720                        if (cli_connect() >= 0) { 
    719721                                /* for S65 */ 
    720722                                (void) obexftp_disconnect (cli); 
     
    734736                                break; 
    735737                        } 
    736                         if(cli_connect ()) { 
     738                        if (cli_connect() >= 0) { 
    737739                                /* Rename a file */ 
    738                                 (void) obexftp_rename(cli, move_src, optarg); 
     740                                ret = obexftp_rename(cli, move_src, optarg); 
    739741                        } 
    740742                        move_src = NULL; 
     
    797799                                 argv[0]); 
    798800                } 
     801                if (ret < 0) 
     802                        printf("The operation failed with return code %d\n", -ret); 
    799803        } 
    800804 
     
    811815        cli_disconnect (); 
    812816 
    813         exit (0); 
    814  
    815 } 
     817        exit (-ret); 
     818 
     819} 
  • trunk/obexftp/client.c

    r219 r223  
    395395                cli->finished = TRUE; 
    396396                cli->success = FALSE; 
     397                DEBUG(2, "%s() OBEX_EV_LINKERR\n", __func__); 
    397398                break; 
    398399         
     
    434435                return 1; 
    435436        else 
    436                 return -1; 
     437                return - cli->obex_rsp; 
    437438} 
    438439 
  • trunk/obexftp/obexftp.h

    r194 r223  
    3333/** ObexFTP message callback events */ 
    3434enum { 
    35         OBEXFTP_EV_ERRMSG, 
     35        OBEXFTP_EV_ERRMSG, /* not used / internal error */ 
    3636 
    3737        OBEXFTP_EV_OK,