VirtualBox

Ignore:
Timestamp:
Feb 20, 2008 11:54:09 AM (17 years ago)
Author:
vboxsync
Message:

XPCOM/IPC: Made IPC_AddName()/IPC_RemoveName(), IPC_DefineTarget() to return a failure when the name/target is already defined or when a non-existent name/target is requested for removal.

Location:
trunk/src/libs/xpcom18a4/ipc/ipcd/daemon/src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/libs/xpcom18a4/ipc/ipcd/daemon/src/ipcClient.cpp

    r1 r7029  
    9696}
    9797
    98 void
     98PRBool
    9999ipcClient::DelName(const char *name)
    100100{
    101101    LOG(("deleting client name: %s\n", name));
    102102
    103     mNames.FindAndDelete(name);
     103    return mNames.FindAndDelete(name);
    104104}
    105105
     
    115115}
    116116
    117 void
     117PRBool
    118118ipcClient::DelTarget(const nsID &target)
    119119{
     
    124124    //
    125125    if (!target.Equals(IPCM_TARGET))
    126         mTargets.FindAndDelete(target);
     126        return mTargets.FindAndDelete(target);
     127
     128    return PR_FALSE;
    127129}
    128130
     
    185187        }
    186188    }
    187  
     189
    188190    if (inFlags & PR_POLL_WRITE) {
    189191        LOG(("client socket is now writable\n"));
  • trunk/src/libs/xpcom18a4/ipc/ipcd/daemon/src/ipcClient.h

    r1 r7029  
    6565
    6666    void   AddName(const char *name);
    67     void  DelName(const char *name);
     67    PRBool DelName(const char *name);
    6868    PRBool HasName(const char *name) const { return mNames.Find(name) != NULL; }
    6969
    7070    void   AddTarget(const nsID &target);
    71     void  DelTarget(const nsID &target);
     71    PRBool DelTarget(const nsID &target);
    7272    PRBool HasTarget(const nsID &target) const { return mTargets.Find(target) != NULL; }
    7373
     
    9696    //
    9797    // returns:
    98     //   0             - to cancel client connection 
     98    //   0             - to cancel client connection
    9999    //   PR_POLL_READ  - to poll for a readable socket
    100100    //   PR_POLL_WRITE - to poll for a writable socket
     
    102102    //
    103103    // the socket is non-blocking.
    104     // 
     104    //
    105105    int Process(PRFileDesc *sockFD, int pollFlags);
    106106
     
    125125    // encoded in it.
    126126    PRUint32      mPID;
    127    
     127
    128128    // the hwnd of the client's message window.
    129129    HWND          mHwnd;
  • trunk/src/libs/xpcom18a4/ipc/ipcd/daemon/src/ipcCommandModule.cpp

    r1 r7029  
    6262
    6363        const ipcStringNode *node;
    64        
     64
    6565        for (node = nodes; node; node = node->mNext)
    6666            count++;
     
    8484
    8585        const ipcIDNode *node;
    86        
     86
    8787        for (node = nodes; node; node = node->mNext)
    8888            count++;
     
    133133        LOG(("got CLIENT_ADD_NAME\n"));
    134134
     135        PRInt32 status = IPCM_OK;
     136        PRUint32 requestIndex = IPCM_GetRequestIndex(rawMsg);
     137
    135138        ipcMessageCast<ipcmMessageClientAddName> msg(rawMsg);
    136139        const char *name = msg->Name();
    137         if (name)
    138             client->AddName(name);
    139 
    140         // TODO: send better status code (e.g., suppose name already defined for client)
    141         IPC_SendMsg(client, new ipcmMessageResult(IPCM_GetRequestIndex(rawMsg), IPCM_OK));
     140        if (name) {
     141            ipcClient *result = IPC_GetClientByName(msg->Name());
     142            if (result) {
     143                LOG(("  client with such name already exists (ID = %d)\n", result->ID()));
     144                status = IPCM_ERROR_ALREADY_EXISTS;
     145            }
     146            else
     147                client->AddName(name);
     148        }
     149        else
     150            status = IPCM_ERROR_INVALID_ARG;
     151
     152        IPC_SendMsg(client, new ipcmMessageResult(requestIndex, status));
    142153    }
    143154
     
    146157    {
    147158        LOG(("got CLIENT_DEL_NAME\n"));
     159
     160        PRInt32 status = IPCM_OK;
     161        PRUint32 requestIndex = IPCM_GetRequestIndex(rawMsg);
    148162
    149163        ipcMessageCast<ipcmMessageClientDelName> msg(rawMsg);
    150164        const char *name = msg->Name();
    151         if (name)
    152             client->DelName(name);
    153 
    154         // TODO: send better status code (e.g., suppose name not defined for client)
    155         IPC_SendMsg(client, new ipcmMessageResult(IPCM_GetRequestIndex(rawMsg), IPCM_OK));
     165        if (name) {
     166            if (!client->DelName(name)) {
     167                LOG(("  client doesn't have name '%s'\n", name));
     168                status = IPCM_ERROR_NO_SUCH_DATA;
     169            }
     170        }
     171        else
     172            status = IPCM_ERROR_INVALID_ARG;
     173
     174        IPC_SendMsg(client, new ipcmMessageResult(requestIndex, status));
    156175    }
    157176
     
    161180        LOG(("got CLIENT_ADD_TARGET\n"));
    162181
     182        PRInt32 status = IPCM_OK;
     183        PRUint32 requestIndex = IPCM_GetRequestIndex(rawMsg);
     184
    163185        ipcMessageCast<ipcmMessageClientAddTarget> msg(rawMsg);
    164         client->AddTarget(msg->Target());
    165 
    166         // TODO: send better status code (e.g., suppose target already defined for client)
    167         IPC_SendMsg(client, new ipcmMessageResult(IPCM_GetRequestIndex(rawMsg), IPCM_OK));
     186        if (client->HasTarget(msg->Target())) {
     187            LOG(("  target already defined for client\n"));
     188            status = IPCM_ERROR_ALREADY_EXISTS;
     189        }
     190        else
     191            client->AddTarget(msg->Target());
     192
     193        IPC_SendMsg(client, new ipcmMessageResult(requestIndex, status));
    168194    }
    169195
     
    173199        LOG(("got CLIENT_DEL_TARGET\n"));
    174200
     201        PRInt32 status = IPCM_OK;
     202        PRUint32 requestIndex = IPCM_GetRequestIndex(rawMsg);
     203
    175204        ipcMessageCast<ipcmMessageClientDelTarget> msg(rawMsg);
    176         client->DelTarget(msg->Target());
    177 
    178         // TODO: send better status code (e.g., suppose target not defined for client)
    179         IPC_SendMsg(client, new ipcmMessageResult(IPCM_GetRequestIndex(rawMsg), IPCM_OK));
     205        if (!client->DelTarget(msg->Target())) {
     206            LOG(("  client doesn't have the given target\n"));
     207            status = IPCM_ERROR_NO_SUCH_DATA;
     208        }
     209
     210        IPC_SendMsg(client, new ipcmMessageResult(requestIndex, status));
    180211    }
    181212
     
    222253        else {
    223254            LOG(("  client does not exist\n"));
    224             IPC_SendMsg(client, new ipcmMessageError(IPCM_ERROR_CLIENT_NOT_FOUND, msg->RequestIndex()));
     255            IPC_SendMsg(client, new ipcmMessageError(IPCM_ERROR_NO_CLIENT, msg->RequestIndex()));
    225256        }
    226257    }
     
    278309    type--;
    279310    if (type < 0 || type >= (int) (sizeof(handlers)/sizeof(handlers[0]))) {
    280         LOG(("unknown request -- ignoring message\n")); 
     311        LOG(("unknown request -- ignoring message\n"));
    281312        return;
    282313    }
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette