コード例 #1
0
AJ_Status AJ_BusHandleBusMessage(AJ_Message* msg)
{
    AJ_Status status = AJ_OK;
    char* name;
    char* oldOwner;
    char* newOwner;
    AJ_Message reply;

    AJ_InfoPrintf(("AJ_BusHandleBusMessage(msg=0x%p)\n", msg));

    /*
     * Check we actually have a message to handle
     */
    if (!msg->hdr) {
        return AJ_OK;
    }

    switch (msg->msgId) {
    case AJ_METHOD_PING:
        AJ_InfoPrintf(("AJ_BusHandleBusMessage(): AJ_METHOD_PING\n"));
        status = AJ_MarshalReplyMsg(msg, &reply);
        break;

    case AJ_METHOD_GET_MACHINE_ID:
        AJ_InfoPrintf(("AJ_BusHandleBusMessage(): AJ_METHOD_GET_MACHINE_ID\n"));
        status = HandleGetMachineId(msg, &reply);
        break;

    case AJ_METHOD_INTROSPECT:
        AJ_InfoPrintf(("AJ_BusHandleBusMessage(): AJ_METHOD_INTROSPECT\n"));
        status = AJ_HandleIntrospectRequest(msg, &reply);
        break;

    case AJ_METHOD_EXCHANGE_GUIDS:
        AJ_InfoPrintf(("AJ_BusHandleBusMessage(): AJ_METHOD_EXCHANGE_GUIDS\n"));
        status = AJ_PeerHandleExchangeGUIDs(msg, &reply);
        break;

    case AJ_METHOD_GEN_SESSION_KEY:
        AJ_InfoPrintf(("AJ_BusHandleBusMessage(): AJ_METHOD_GEN_SESSION_KEY\n"));
        status = AJ_PeerHandleGenSessionKey(msg, &reply);
        break;

    case AJ_METHOD_EXCHANGE_GROUP_KEYS:
        AJ_InfoPrintf(("AJ_BusHandleBusMessage(): AJ_METHOD_EXCHANGE_GROUP_KEYS\n"));
        status = AJ_PeerHandleExchangeGroupKeys(msg, &reply);
        break;

    case AJ_METHOD_AUTH_CHALLENGE:
        AJ_InfoPrintf(("AJ_BusHandleBusMessage(): AJ_METHOD_AUTH_CHALLENGE\n"));
        status = AJ_PeerHandleAuthChallenge(msg, &reply);
        break;

    case AJ_REPLY_ID(AJ_METHOD_EXCHANGE_GUIDS):
        AJ_InfoPrintf(("AJ_BusHandleBusMessage(): AJ_REPLY_ID(AJ_METHOD_EXCHANGE_GUIDS)\n"));
        status = AJ_PeerHandleExchangeGUIDsReply(msg);
        break;

    case AJ_REPLY_ID(AJ_METHOD_AUTH_CHALLENGE):
        AJ_InfoPrintf(("AJ_BusHandleBusMessage(): AJ_REPLY_ID(AJ_METHOD_AUTH_CHALLENGE)\n"));
        status = AJ_PeerHandleAuthChallengeReply(msg);
        break;

    case AJ_REPLY_ID(AJ_METHOD_GEN_SESSION_KEY):
        AJ_InfoPrintf(("AJ_BusHandleBusMessage(): AJ_REPLY_ID(AJ_METHOD_GEN_SESSION_KEY)\n"));
        status = AJ_PeerHandleGenSessionKeyReply(msg);
        break;

    case AJ_REPLY_ID(AJ_METHOD_EXCHANGE_GROUP_KEYS):
        AJ_InfoPrintf(("AJ_BusHandleBusMessage(): AJ_REPLY_ID(AJ_METHOD_EXCHANGE_GROUP_KEYS)\n"));
        status = AJ_PeerHandleExchangeGroupKeysReply(msg);
        break;

    case AJ_REPLY_ID(AJ_METHOD_CANCEL_SESSIONLESS):
        AJ_InfoPrintf(("AJ_BusHandleBusMessage(): AJ_REPLY_ID(AJ_METHOD_CANCEL_SESSIONLESS)\n"));
        // handle return code here
        status = AJ_OK;
        break;

    case AJ_SIGNAL_SESSION_JOINED:
    case AJ_SIGNAL_NAME_ACQUIRED:
        AJ_InfoPrintf(("AJ_BusHandleBusMessage(): AJ_SIGNAL_{SESSION_JOINED|NAME_ACQUIRED}\n"));
        // nothing to do here
        status = AJ_OK;
        break;

    case AJ_REPLY_ID(AJ_METHOD_ADD_MATCH):
    case AJ_REPLY_ID(AJ_METHOD_REMOVE_MATCH):
    case AJ_REPLY_ID(AJ_METHOD_CANCEL_ADVERTISE):
    case AJ_REPLY_ID(AJ_METHOD_ADVERTISE_NAME):
        AJ_InfoPrintf(("AJ_BusHandleBusMessage(): AJ_REPLY_ID(AJ_METHOD_{ADD_MATCH|CANCEL_ADVERTISE|ADVERTISE_NAME})\n"));
        if (msg->hdr->msgType == AJ_MSG_ERROR) {
            status = AJ_ERR_FAILURE;
        }
        break;

    case AJ_SIGNAL_NAME_OWNER_CHANGED:
        AJ_InfoPrintf(("AJ_BusHandleBusMessage(): AJ_SIGNAL_NAME_OWNER_CHANGED)\n"));
        AJ_UnmarshalArgs(msg, "sss", &name, &oldOwner, &newOwner);
        if (newOwner && oldOwner && newOwner[0] == '\0') {
            AJ_GUID_DeleteNameMapping(oldOwner);
        }
        /*
         * Reset so the application can handle this too
         */
        status = AJ_ResetArgs(msg);
        break;

    default:
        AJ_InfoPrintf(("AJ_BusHandleBusMessage(): default\n"));
        if (msg->hdr->msgType == AJ_MSG_METHOD_CALL) {
            status = AJ_MarshalErrorMsg(msg, &reply, AJ_ErrRejected);
        }
        break;
    }
    if ((status == AJ_OK) && (msg->hdr->msgType == AJ_MSG_METHOD_CALL)) {
        status = AJ_DeliverMsg(&reply);
    }
    return status;
}
コード例 #2
0
ファイル: aj_bus.c プロジェクト: durake/core-ajtcl
AJ_Status AJ_BusHandleBusMessage(AJ_Message* msg)
{
    AJ_Status status = AJ_OK;
    AJ_BusAttachment* bus = msg->bus;
    char* languageTag;
    AJ_Message reply;

    AJ_InfoPrintf(("AJ_BusHandleBusMessage(msg=0x%p)\n", msg));
    memset(&reply, 0, sizeof(AJ_Message));
    /*
     * Check we actually have a message to handle
     */
    if (!msg->hdr) {
        return AJ_OK;
    }

    switch (msg->msgId) {
    case AJ_METHOD_PING:
        AJ_InfoPrintf(("AJ_BusHandleBusMessage(): AJ_METHOD_PING\n"));
        status = AJ_MarshalReplyMsg(msg, &reply);
        break;

    case AJ_METHOD_GET_MACHINE_ID:
        AJ_InfoPrintf(("AJ_BusHandleBusMessage(): AJ_METHOD_GET_MACHINE_ID\n"));
        status = HandleGetMachineId(msg, &reply);
        break;

    case AJ_METHOD_INTROSPECT:
        AJ_InfoPrintf(("AJ_BusHandleBusMessage(): AJ_METHOD_INTROSPECT\n"));
        status = AJ_HandleIntrospectRequest(msg, &reply, NULL);
        break;

    case AJ_METHOD_GET_DESCRIPTION_LANG:
        AJ_InfoPrintf(("AJ_BusHandleBusMessage(): AJ_METHOD_GET_DESCRIPTION_LANG\n"));
        status = AJ_HandleGetDescriptionLanguages(msg, &reply);
        break;

    case AJ_METHOD_INTROSPECT_WITH_DESC:
        AJ_InfoPrintf(("AJ_BusHandleBusMessage(): AJ_METHOD_INTROSPECT_WITH_DESC\n"));
        AJ_UnmarshalArgs(msg, "s", &languageTag);
        status = AJ_HandleIntrospectRequest(msg, &reply, languageTag);
        break;

    case AJ_METHOD_EXCHANGE_GUIDS:
        AJ_InfoPrintf(("AJ_BusHandleBusMessage(): AJ_METHOD_EXCHANGE_GUIDS\n"));
        status = AJ_PeerHandleExchangeGUIDs(msg, &reply);
        break;

    case AJ_METHOD_GEN_SESSION_KEY:
        AJ_InfoPrintf(("AJ_BusHandleBusMessage(): AJ_METHOD_GEN_SESSION_KEY\n"));
        status = AJ_PeerHandleGenSessionKey(msg, &reply);
        break;

    case AJ_METHOD_EXCHANGE_GROUP_KEYS:
        AJ_InfoPrintf(("AJ_BusHandleBusMessage(): AJ_METHOD_EXCHANGE_GROUP_KEYS\n"));
        status = AJ_PeerHandleExchangeGroupKeys(msg, &reply);
        break;

    case AJ_METHOD_EXCHANGE_SUITES:
        AJ_InfoPrintf(("AJ_BusHandleBusMessage(): AJ_METHOD_EXCHANGE_SUITES\n"));
        status = AJ_PeerHandleExchangeSuites(msg, &reply);
        break;

    case AJ_METHOD_KEY_EXCHANGE:
        AJ_InfoPrintf(("AJ_BusHandleBusMessage(): AJ_METHOD_KEY_EXCHANGE\n"));
        status = AJ_PeerHandleKeyExchange(msg, &reply);
        break;

    case AJ_METHOD_KEY_AUTHENTICATION:
        AJ_InfoPrintf(("AJ_BusHandleBusMessage(): AJ_METHOD_KEY_AUTHENTICATION\n"));
        status = AJ_PeerHandleKeyAuthentication(msg, &reply);
        break;

    case AJ_REPLY_ID(AJ_METHOD_EXCHANGE_GUIDS):
        AJ_InfoPrintf(("AJ_BusHandleBusMessage(): AJ_REPLY_ID(AJ_METHOD_EXCHANGE_GUIDS)\n"));
        status = AJ_PeerHandleExchangeGUIDsReply(msg);
        break;

    case AJ_REPLY_ID(AJ_METHOD_EXCHANGE_SUITES):
        AJ_InfoPrintf(("AJ_BusHandleBusMessage(): AJ_REPLY_ID(AJ_METHOD_EXCHANGE_SUITES)\n"));
        status = AJ_PeerHandleExchangeSuitesReply(msg);
        break;

    case AJ_REPLY_ID(AJ_METHOD_KEY_EXCHANGE):
        AJ_InfoPrintf(("AJ_BusHandleBusMessage(): AJ_REPLY_ID(AJ_METHOD_KEY_EXCHANGE)\n"));
        status = AJ_PeerHandleKeyExchangeReply(msg);
        break;

    case AJ_REPLY_ID(AJ_METHOD_KEY_AUTHENTICATION):
        AJ_InfoPrintf(("AJ_BusHandleBusMessage(): AJ_REPLY_ID(AJ_METHOD_KEY_AUTHENTICATION)\n"));
        status = AJ_PeerHandleKeyAuthenticationReply(msg);
        break;

    case AJ_REPLY_ID(AJ_METHOD_GEN_SESSION_KEY):
        AJ_InfoPrintf(("AJ_BusHandleBusMessage(): AJ_REPLY_ID(AJ_METHOD_GEN_SESSION_KEY)\n"));
        status = AJ_PeerHandleGenSessionKeyReply(msg);
        break;

    case AJ_REPLY_ID(AJ_METHOD_EXCHANGE_GROUP_KEYS):
        AJ_InfoPrintf(("AJ_BusHandleBusMessage(): AJ_REPLY_ID(AJ_METHOD_EXCHANGE_GROUP_KEYS)\n"));
        status = AJ_PeerHandleExchangeGroupKeysReply(msg);
        break;

    case AJ_REPLY_ID(AJ_METHOD_CANCEL_SESSIONLESS):
        AJ_InfoPrintf(("AJ_BusHandleBusMessage(): AJ_REPLY_ID(AJ_METHOD_CANCEL_SESSIONLESS)\n"));
        // handle return code here
        status = AJ_OK;
        break;

    case AJ_SIGNAL_SESSION_JOINED:
    case AJ_SIGNAL_NAME_ACQUIRED:
        AJ_InfoPrintf(("AJ_BusHandleBusMessage(): AJ_SIGNAL_{SESSION_JOINED|NAME_ACQUIRED}\n"));
        // nothing to do here
        status = AJ_OK;
        break;

    case AJ_REPLY_ID(AJ_METHOD_CANCEL_ADVERTISE):
    case AJ_REPLY_ID(AJ_METHOD_ADVERTISE_NAME):
        AJ_InfoPrintf(("AJ_BusHandleBusMessage(): AJ_REPLY_ID(AJ_METHOD_{CANCEL_ADVERTISE|ADVERTISE_NAME})\n"));
        if (msg->hdr->msgType == AJ_MSG_ERROR) {
            status = AJ_ERR_FAILURE;
        }
        break;

    case AJ_METHOD_ABOUT_GET_PROP:
        return AJ_AboutHandleGetProp(msg);

    case AJ_METHOD_ABOUT_GET_ABOUT_DATA:
        status = AJ_AboutHandleGetAboutData(msg, &reply);
        break;

    case AJ_METHOD_ABOUT_GET_OBJECT_DESCRIPTION:
        status = AJ_AboutHandleGetObjectDescription(msg, &reply);
        break;

    case AJ_METHOD_ABOUT_ICON_GET_PROP:
        return AJ_AboutIconHandleGetProp(msg);

    case AJ_METHOD_ABOUT_ICON_GET_URL:
        status = AJ_AboutIconHandleGetURL(msg, &reply);
        break;

    case AJ_METHOD_ABOUT_ICON_GET_CONTENT:
        status = AJ_AboutIconHandleGetContent(msg, &reply);
        break;

#ifdef ANNOUNCE_BASED_DISCOVERY
    case AJ_SIGNAL_ABOUT_ANNOUNCE:
        status = AJ_AboutHandleAnnounce(msg, NULL, NULL, NULL, NULL);
        break;
#endif

    default:
        AJ_InfoPrintf(("AJ_BusHandleBusMessage(): default\n"));
        if (msg->hdr->msgType == AJ_MSG_METHOD_CALL) {
            status = AJ_MarshalErrorMsg(msg, &reply, AJ_ErrRejected);
        }
        break;
    }
    if ((status == AJ_OK) && (msg->hdr->msgType == AJ_MSG_METHOD_CALL)) {
        status = AJ_DeliverMsg(&reply);
    }
    /*
     * Check if there is anything to announce
     */
    if (status == AJ_OK) {
        AJ_AboutAnnounce(bus);
    }
    return status;
}