void AP_Dialog_CollaborationShare::share(AccountHandler* pAccount, const std::vector<std::string>& vAcl)
{
	UT_DEBUGMSG(("AP_Dialog_CollaborationShare::_share()\n"));

	AbiCollabSessionManager* pManager = AbiCollabSessionManager::getManager();
	UT_return_if_fail(pManager);

	// determine which document to share
	XAP_Frame* pFrame = XAP_App::getApp()->getLastFocussedFrame();
	UT_return_if_fail(pFrame);

	PD_Document* pDoc = static_cast<PD_Document *>(pFrame->getCurrentDoc());
	UT_return_if_fail(pDoc);

	AbiCollab* pSession = NULL;
	if (!pManager->isInSession(pDoc))
	{
		UT_DEBUGMSG(("Sharing document...\n"));

		// FIXME: this can cause a race condition: the other side can already be
		// offered the session before we actually started it!
		
		// Tell the account handler that we start a new session, so
		// it set up things if needed. This call may just setup some stuff 
		// for a new session, or it might actually start a new session.
		bool b = pAccount->startSession(pDoc, m_vAcl, &pSession);
		if (!b)
		{
			XAP_App::getApp()->getLastFocussedFrame()->showMessageBox(
						"There was an error sharing this document!", 
						XAP_Dialog_MessageBox::b_O, XAP_Dialog_MessageBox::a_OK);
			return;
		}
		
		// start the session ourselves when the account handler did not...
		if (!pSession)
		{
			// ... and start the session!
			UT_UTF8String sSessionId("");
			// TODO: we could use/generate a proper descriptor when there is only
			// 1 account where we share this document over
			pSession = pManager->startSession(pDoc, sSessionId, pAccount, true, NULL, "");
		}
	}
	else
	{
		pSession = pManager->getSession(pDoc);
	}

	UT_return_if_fail(pSession);
	pManager->updateAcl(pSession, pAccount, vAcl);
}
예제 #2
0
  /*
  * This method invokes the target service method 
  */
  static axiom_node_t* AXIS2_CALL
    Axis2Service_invoke(axis2_svc_skeleton_t* /*pServiceSkeleton*/,
    const axutil_env_t* pEnv,
    axiom_node_t* pAxiomNode,
    axis2_msg_ctx_t* pMsgCtx)
  {
    if (pAxiomNode == NULL)
    {
      staff::LogError() << "AxiOM node is NULL\n";
      return NULL;
    }

    if (axiom_node_get_node_type(pAxiomNode, pEnv) != AXIOM_ELEMENT)
    {
      staff::LogError() << "Can't get AxiOM node type";
      return NULL;
    }

    axiom_element_t* pAxiomElement = (axiom_element_t*)axiom_node_get_data_element(pAxiomNode, pEnv);
    if (pAxiomElement == NULL)
    {
      staff::LogError() << "Can't get AxiOM node element\n";
      return NULL;
    }

    const axis2_char_t* szServiceName = reinterpret_cast<const axis2_char_t*>
        (axis2_msg_ctx_get_property_value(pMsgCtx, pEnv, "ServiceName"));
#ifndef WITHOUT_SECURITY
    const axis2_char_t* szSessionId = reinterpret_cast<const axis2_char_t*>
        (axis2_msg_ctx_get_property_value(pMsgCtx, pEnv, "SessionId"));
    const axis2_char_t* szInstanceId = reinterpret_cast<const axis2_char_t*>
        (axis2_msg_ctx_get_property_value(pMsgCtx, pEnv, "InstanceId"));
#endif

    if (szServiceName == NULL)
    {
      staff::LogError() << "Cannot process message: Failed to get service name.";
      return NULL;
    }

#ifndef WITHOUT_SECURITY
    if (szSessionId == NULL)
    {
      staff::LogError() << "Cannot process message: Failed to get session id.";
      return NULL;
    }

    if (szInstanceId == NULL)
    {
      staff::LogError() << "Cannot process message: Failed to get instance id.";
      return NULL;
    }
#endif

#ifdef _DEBUG
    staff::LogDebug1() << "Service name: [" << szServiceName << "]";
#ifndef WITHOUT_SECURITY
    staff::LogDebug1() << "Session id: [" << szSessionId << "]";
    staff::LogDebug1() << "Instance id: [" << szInstanceId << "]";
#endif

    {
      axiom_node_t* panBody = axiom_node_get_parent(pAxiomNode, pEnv);
      axiom_node_t* panEnv = axiom_node_get_parent(panBody, pEnv);

      staff::LogDebug2() << "request SOAP Envelope: \n" << staff::ColorTextBlue
                  << staff::DataObject(panEnv).ToString() << "\n" << staff::ColorDefault;
    }
#endif

    staff::Operation tOperation;
    staff::MessageContext tMessageContext(pEnv, pMsgCtx);

    std::string sServiceName(szServiceName);
#ifndef WITHOUT_SECURITY
    std::string sSessionId(szSessionId);
    std::string sInstanceId(szInstanceId);
#else
    static std::string sSessionId;
    static std::string sInstanceId;
#endif

    try
    {
      tOperation.SetRequest(pAxiomNode);
      tOperation.SetMessageContext(tMessageContext);

      if (axis2_msg_ctx_get_doing_rest(pMsgCtx, pEnv))
      {
        const axis2_char_t* szOperation = reinterpret_cast<const axis2_char_t*>
            (axis2_msg_ctx_get_property_value(pMsgCtx, pEnv, "Operation"));
        if (szOperation != NULL)
        {
          tOperation.SetName(szOperation);
        }
      }

      if (sServiceName == "StaffService")
      {
        staff::ServiceDispatcher::Inst().InvokeSelf(tOperation);
      }
      else
      {
        staff::ServiceWrapper* pServiceWrapper =
            staff::SharedContext::Inst().GetService(sServiceName);
        STAFF_ASSERT(pServiceWrapper, "Service [" + sServiceName + "] is not found: ");
        pServiceWrapper->Invoke(tOperation, sSessionId, sInstanceId);
      }
    }
    catch (const staff::SoapUserFaultException& rEx)
    {
      try
      {
        staff::DataObject tdoFault;
        tdoFault.FromString(rEx.GetFault());
        tOperation.SetUserFault(tdoFault);
      }
      catch (...)
      {
        tOperation.SetFault("server", "Invalid format of user soap fault",
                            "Failed to invoke service " + sServiceName
                            + "." + tOperation.GetName()
#ifndef WITHOUT_SECURITY
                            + "#" + sInstanceId + "(" + sSessionId + ")"
#endif
                            );
      }
    }
    catch (const staff::SoapFaultException& rEx)
    {
      tOperation.SetFault(rEx.GetCode(), rEx.GetString(), rEx.GetDetail());
    }
    catch (const std::exception& rEx)
    {
      tOperation.SetFault("server", rEx.what(), "Failed to invoke service " + sServiceName
                          + "." + tOperation.GetName()
#ifndef WITHOUT_SECURITY
                          + "#" + sInstanceId + "(" + sSessionId + ")"
#endif
                          );
    }
    catch (...)
    {
      tOperation.SetFault("server", "Unknown exception", "Failed to invoke service " + sServiceName
                          + "." + tOperation.GetName()
#ifndef WITHOUT_SECURITY
                          + "#" + sInstanceId + "(" + sSessionId + ")"
#endif
                          );
    }

    if (tOperation.IsFault())
    {
      staff::ScopedLock tLock(m_tFaultDetailsMutex);

      m_mFaultDetails[staff::Thread::GetCurrentId()] = tOperation.GetFaultDetail();
      staff::LogWarning() << "Fault: \n" << tOperation.GetFaultDescr() << "\n";
      AXIS2_ERROR_SET_MESSAGE(pEnv->error, static_cast<axis2_char_t*>(axutil_strdup(pEnv, tOperation.GetFaultString().c_str())));
      AXIS2_ERROR_SET_ERROR_NUMBER(pEnv->error, static_cast<axutil_error_codes_t>(AXUTIL_ERROR_MAX + 1));
      AXIS2_ERROR_SET_STATUS_CODE(pEnv->error, AXIS2_FAILURE);
      if (!m_bHttp200OnFault)
        return NULL;
    }

    if(!IsNeedReply(pMsgCtx, pEnv))
    {
      return NULL;
    }

    tOperation.PrepareResult();
    staff::DataObject& rResponse = tOperation.GetResponse();
    rResponse.SetOwner(false);

#ifdef _DEBUG
    staff::LogDebug2() << "Sending Response: \n" <<  staff::ColorTextBlue << rResponse.ToString() << "\n" << staff::ColorDefault;
#endif

    return rResponse;
  }