Ignore:
Timestamp:
Aug 20, 2008, 2:29:02 PM (17 years ago)
Author:
Yuri Dario
Message:

Handle automatic reconnection, fixes for return codes.

Location:
branches/client-1.5/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/client-1.5/src/ndpsmb.c

    r147 r150  
    856856            pfsa->cUnitAvail = 123456;
    857857            pfsa->cbSector = 2048;
     858            rc = (rc == 7 ? ERROR_BAD_DEV_TYPE : ERROR_ACCESS_DENIED);
    858859            return rc;
    859860        }
     
    913914                free(pConn);
    914915                pConn = NULL;
     916                rc = (rc == 7 ? ERROR_BAD_DEV_TYPE : ERROR_INVALID_PARAMETER);
    915917        }
    916918
     
    944946// -------------------------------------------------------------
    945947
     948/*
     949 * NdpQueryPathInfo is the most important  function :) netdrive always calls
     950 * the function before every operation to find out the path status: does it exist, is it a file, does a
     951 *  parent directory exist, etc.
     952 * Plugin must return one of the following error codes:
     953 * NO_ERROR - path exists and the path information have been successfully retrieved.
     954 * ERROR_FILE_NOT_FOUND - all but the last component of the path exist and the
     955 *    path without the last component is a directory. dir1_ok\dir2_ok\does_not_exist.
     956 *    the wildcard can not exist, so the plugin returns FILE_NOT_FOUND, if the parent
     957 *    directory exist.
     958 * ERROR_PATH_NOT_FOUND - any of not last path components does not exist, or all
     959 *    but the last component exist and is a file: \dir_ok\dir2_ok\file_ok\non_existing.
     960 * ERROR_REM_NOT_LIST - resource is temporarily unavailable for some reasons.
     961 * Any other error codes means an internal plugin error, not related to the status
     962 * of the path queried.
     963 */
    946964int APIENTRY NdpQueryPathInfo (HCONNECTION conn, void *plist, char *szPath)
    947965{
     
    954972        int retry = 0;
    955973
    956         do
    957           {
    958974                log("NdpQueryPathInfo in <%s>, retry = %d\n", szPath, retry);
     975       
     976                // is wildcard is specified, we suppose parent dir exist, so exit immediately
     977                if (ph->fsphStrChr(szPath, '*') || ph->fsphStrChr(szPath, '?'))
     978                {
     979                        return ERROR_FILE_NOT_FOUND;
     980                }
     981
    959982
    960983                do {
    961 
    962                         if (ph->fsphStrChr(szPath, '*') || ph->fsphStrChr(szPath, '?'))
    963                         {
    964                                 rc = ERROR_FILE_NOT_FOUND;
    965                                 break;
    966                         }
    967984
    968985                        rc = pathparser(pRes, pConn, szPath, path);
     
    9921009                        if (rc)
    9931010                        {
     1011                                // remote server not available for first time?
     1012                                if (rc == ERROR_REM_NOT_LIST && retry == 0)
     1013                                {
     1014                                    // free current cli resources
     1015                                    smbwrp_disconnect( pRes, pConn->cli);
     1016                                    // reconnect
     1017                                    smbwrp_connect( pRes, &pConn->cli);
     1018                                    // try file list again
     1019                                    rc = smbwrp_getattr( &pRes->srv, pConn->cli, &finfo);
     1020                                    log("NdpQueryPathInfo remote connection lost, retry rc = %d\n", rc);
     1021                                }
    9941022                                switch (rc)
    9951023                                {
     
    9991027                                        case ERROR_ACCESS_DENIED:
    10001028                                        case ERROR_INVALID_PARAMETER:
     1029                                        case ERROR_REM_NOT_LIST:
    10011030                                        break;
    10021031                                        default :
     
    10051034                                        }
    10061035                                }
    1007                                 rc =rc ? rc : ERROR_INVALID_PARAMETER;
    10081036                        }
    10091037                        else
     
    10221050                                        if (rc)
    10231051                                        {       
    1024                                                 rc = rc ? ERROR_PATH_NOT_FOUND : ERROR_INVALID_PARAMETER;
     1052                                            log("NdpQueryPathInfo upper path in <%s>, retry = %d\n",  finfo.fname, retry);
     1053                                            rc = rc ? ERROR_PATH_NOT_FOUND : ERROR_INVALID_PARAMETER;
    10251054                                        }
    10261055                                }
     
    10281057                } while (0);
    10291058                log("NdpQueryPathInfo <%s> (%s) %d\n", szPath, path, rc);
    1030                 retry = rc && !retry;
    1031 
    1032         } while (retry);
    1033        
     1059
    10341060        return rc;
    10351061}
     
    10961122                }
    10971123                rc = smbwrp_filelist( &pRes->srv, pConn->cli, &state);
     1124                // we need to handle reconnection also here, because NdpQueryPathInfo
     1125                // could be called with '*' and exit then immediately (without calling libsmb)
     1126                if (rc == ERROR_REM_NOT_LIST)
     1127                {
     1128                    // free current cli resources
     1129                    smbwrp_disconnect( pRes, pConn->cli);
     1130                    // reconnect
     1131                    smbwrp_connect( pRes, &pConn->cli);
     1132                    // try file list again next loop
     1133                    rc = smbwrp_filelist( &pRes->srv, pConn->cli, &state);
     1134                    log("NdpFindStart remote connection lost, retry rc = %d\n", rc);
     1135                }
    10981136
    10991137        log("NdpFindStart <%s> (%s) cnt %d %d\n", szPath, path, count, rc);
  • branches/client-1.5/src/smbwrp.c

    r147 r150  
     1
    12#include "includes.h"
    23
     
    9596        if (cli->fd == -1)
    9697        {
    97                 return ENOTCONN;
     98                return maperror( ENOTCONN);
    9899        }
    99100        return maperror(cli_errno(cli));
     
    495496
    496497        debuglocal(4," tconx ok. cli caps %08x\n", c->capabilities);
    497 
     498       
    498499        // save cli_state pointer
    499500        *cli = c;
Note: See TracChangeset for help on using the changeset viewer.