void CreateDiscussionsHandler::handleIqID( const IQ& iq, int context )
	{
		json::jobject jobj;
		if (iq.m_subtype != gloox::IQ::Result)
		{
			universal_resource error_desc;
			ELOG("app")->error(WCOOL(L"创建讨论组时服务端返回错误。") + boost::shared_ptr<gloox::Tag>(iq.tag())->xml());
			error_desc = XL("biz.CreateDiscussions.fail");

			callback_(true, error_desc, jobj);
		}else{
			if(iq.findExtension(kExtUser_iq_filter_creatediscussions))
			{
				boost::shared_ptr<gloox::Tag> tag(iq.findExtension(kExtUser_iq_filter_creatediscussions)->tag());
				if (tag)
				{
					gloox::Tag* tag2 = tag->findChild("item");
					if (tag)
					{
						jobj["session_id"] = gWrapInterface::instance().append_discussions_domain(tag2->findAttribute("id"));
						jobj["group_name"] = tag2->findAttribute("topic");

						callback_(false,XL(""),jobj);
						return;
					}
				}
			}
			ELOG("app")->error(WCOOL(L"创建讨论组时服务端返回的数据格式错误。") + boost::shared_ptr<gloox::Tag>(iq.tag())->xml());
			callback_(true, XL("biz.CreateDiscussions.fail"), jobj);
		}
	}
void TestInitiator::send( IQ& iq, IqHandler*, int ctx )
{
  m_result = false;
  iq.setFrom( JID( "self" ) );
  Tag* t = iq.tag();
  std::string expected;

//   printf( "TestInitiator: test %d: %s\n", m_test, t->xml().c_str() );

  switch( m_test )
  {
    case 1:
    {
      expected = "<iq to='foo@bar' from='self' id='id' type='set'><jingle xmlns='" + XMLNS_JINGLE + "' action='session-initiate' initiator='notself' sid='somesid'/></iq>";
      if( t->xml() == expected )
        m_result = true;
      else
        fprintf( stderr, "Jingle::Session test %d\nHave:     %s\nExpected: %s\n", m_test, t->xml().c_str(), expected.c_str() );
      res->sm()->handleIq( iq );
      break;
    }
  }

  delete t;
}
	bool CreateDiscussionsHandler::handleIq( const IQ& iq )
	{
		if(iq.findExtension(kExtUser_iq_filter_creatediscussions))
		{
			boost::shared_ptr<gloox::Tag> tag(iq.findExtension(kExtUser_iq_filter_creatediscussions)->tag());
			if (tag)
			{
				gloox::Tag* tag2 = tag->findChild("item");
				if (tag2)
				{
					json::jobject jobj;
					jobj["type"] = "add";
					json::jobject group;
					group["session_id"] = gWrapInterface::instance().append_discussions_domain(tag2->findAttribute("id"));
					group["group_name"] =  tag2->findAttribute("topic");
					jobj["group_info"].arr_push(group);
					gWrapInterface::instance().discussions_list_change(jobj);
					return true;
				}
			}
		}

		ELOG("app")->error(WCOOL(L"创建讨论组时服务端返回的数据格式错误。") + boost::shared_ptr<gloox::Tag>(iq.tag())->xml());
		return false;
	}
Beispiel #4
0
bool GlooxRegisterHandler::handleIq(const IQ &iq) {
	Tag *iqTag = iq.tag();
	if (!iqTag) return true;

	bool ret = handleIq(iqTag);
	delete iqTag;
	return ret;
}
	/*
	 <iq type=’result’from=’[email protected]’ to=’[email protected]’>
	 <queryxmlns=’groups:share:file:delete’>
	 <item id=‘2’ />
	 </query>
	 </iq>
	*/
	void InviteIntoGroupsHandler::handleIqID( const IQ& iq, int context )
	{
		json::jobject jobj;
		if (iq.m_subtype != gloox::IQ::Result)
		{
			const Error* e = iq.error();
			if (!e)
			{
				ELOG("app")->error(WCOOL(L"邀请加入群时,服务器返回未知错误类型!") + boost::shared_ptr<gloox::Tag>(iq.tag())->xml());
				callback_(true,XL("biz.InviteIntoGroups.fail"));
				return;
			}

			if ( e->error() == StanzaErrorBadRequest)
			{
				ELOG("app")->error(WCOOL(L"邀请加入群时,请求协议错误!。"));
				callback_(true,XL("biz.crwod.iq_error.bad-request"));
			}
			else if (e->error() == StanzaErrorInternalServerError)
			{
				ELOG("app")->error(WCOOL(L"邀请加入群时,处理错误(服务器处理错误)。"));
				callback_(true,XL("biz.crwod.iq_error.internal-server-error"));
			}
			else if (e->error() == StanzaErrorConflict)
			{
				ELOG("app")->error(WCOOL(L"邀请加入群时,被邀请人已经在群里。"));
				callback_(true,XL("biz.crwod.iq_error.invite_conflict"));
			}
			else if (e->error() == StanzaErrorResourceConstraint)
			{
				ELOG("app")->error(WCOOL(L"邀请加入群时,群已经满员。"));
				callback_(true,XL("biz.crwod.iq_error.invite_resource-constraint"));
			}
			else if (e->error() == StanzaErrorNotAllowed)
			{
				ELOG("app")->error(WCOOL(L"邀请加入群时,邀请人不是管理员。"));
				callback_(true,XL("biz.crwod.iq_error.invite_not-allowed"));
			}else
			{
				ELOG("app")->error(WCOOL(L"邀请加入群时,服务器返回未知错误类型!") + boost::shared_ptr<gloox::Tag>(iq.tag())->xml());
				callback_(true,XL("biz.InviteIntoGroups.fail"));
			}
		}else{
			callback_(false,XL(""));
		}
	}
Beispiel #6
0
 void ClientBase::send( IQ& iq, IqHandler*, int )
 {
   Tag* tag = iq.tag();
   switch( m_test )
   {
     case 1:
     {
       break;
     }
   }
   delete tag;
 }
 void ClientBase::send( const IQ& iq, IqHandler*, int )
 {
   tag = iq.tag();
   if( !tag || tag->xml() != testValues[m_context][1] )
   {
     printf( "test failed: %s\n", testValues[m_context][0].c_str() );
     printf( "- %s\n", testValues[m_context][1].c_str() );
     if( tag )
       printf( "- %s\n", tag->xml().c_str() );
     ++failed;
   }
   delete tag;
 }
	void ChangeDiscussionsNameHandler::handleIqID( const IQ& iq, int context )
	{
		json::jobject jobj;
		if (iq.m_subtype != gloox::IQ::Result)
		{
			universal_resource error_desc;
			ELOG("app")->error(WCOOL(L"讨论组改名时服务端返回错误。") + boost::shared_ptr<gloox::Tag>(iq.tag())->xml());
			error_desc = XL("biz.ChangeDiscussionsName.fail");
			callback_(true, error_desc);
		}
		else
		{
			callback_(false, XL(""));
		}
	}
Beispiel #9
0
 void ClientBase::send( IQ& iq, IqHandler*, int )
 {
   Tag* tag = iq.tag();
   switch( m_test )
   {
     case 1:
     {
       Tag* si = tag->findChild( "si", "xmlns", XMLNS_SI );
       if( tag->findAttribute( "to" ) == to.full() && si && *(si->findChild( "file" )) == *t1
           && *(si->findChild( "feature" )) == *t2 && si->findAttribute( "mime-type" ) == "binary/octet-stream"
           && si->findAttribute( "profile" ) == g_profile )
         m_ok = true;
       break;
     }
   }
   delete tag;
 }
Beispiel #10
0
AdhocTag::AdhocTag(const IQ &stanza) : Tag("command") {
    m_from = stanza.from().full();
    m_id = stanza.id();
    xdata = NULL;
    Tag *iq = stanza.tag();
    Tag *command = iq->findChild("command");
    if (command) {
        const Tag::AttributeList & attributes = command->attributes();
        for (Tag::AttributeList::const_iterator it = attributes.begin(); it != attributes.end(); it++) {
            addAttribute(std::string((*it)->name()), std::string((*it)->value()));
        }
        Tag *x = command->findChildWithAttrib("xmlns","jabber:x:data");
        if (x) {
            xdata = x->clone();
            addChild(xdata);
        }
    }
    delete iq;
}
	void OrganizationShowHandller::handleIqID( const IQ& iq, int context )
	{
		json::jobject jobj = json::jobject();
		if (iq.m_subtype != gloox::IQ::Result)
		{
			universal_resource error_desc;
			ELOG("app")->error(WCOOL(L"组织结构树查看权限获取错误") + boost::shared_ptr<gloox::Tag>(iq.tag())->xml());
			error_desc = XL("biz.OrganizationShowHandller.fail");
			callback_(true, error_desc,jobj);
		}
		else
		{
			boost::shared_ptr<gloox::Tag> ptag(iq.findExtension(kExtUser_iq_filter_organization_show)->tag());
			if (ptag)
			{
				gloox::Tag* tag_basic_permission = ptag->findChild("basic_permissions");
				if (tag_basic_permission)
				{
					ConstTagList ptag_list = tag_basic_permission->findTagList("//permission");
					for (ConstTagList::iterator it = ptag_list.begin(); it != ptag_list.end(); ++it)
					{
						if ((*it)->findAttribute("name") == "show_organization")
						{
							if ((*it)->cdata() == "true")
							{
								jobj["is_show_organization"] = true;
							}
							else
							{
								jobj["is_show_organization"] = false;
							}
							callback_(false, XL(""),jobj);
						}
					}
				}
			}
		}
	}
Beispiel #12
0
void TestResponder::send( IQ& iq, IqHandler*, int ctx )
{
  m_result = false;
  iq.setFrom( remote_jid );
  Tag* t = iq.tag();
  std::string expected;

//   printf( "TestResponder: test %d: %s\n", m_test, t->xml().c_str() );
  switch( m_test )
  {
    case 1:
      break;
    case 2:
      expected = "<iq to='self' from='foo@bar' id='id' type='set'><jingle xmlns='" + XMLNS_JINGLE + "' action='session-accept' responder='self' sid='somesid'/></iq>";
      if( t->xml() == expected )
        m_result = true;
      else
        fprintf( stderr, "Jingle::Session test %d\nHave:     %s\nExpected: %s\n", m_test, t->xml().c_str(), expected.c_str() );
      ini->js()->handleIq( iq );
      break;
    case 3:
      expected = "<iq to='self' from='foo@bar' id='id' type='set'><jingle xmlns='" + XMLNS_JINGLE + "' action='session-terminate' sid='somesid'><reason><success/></reason></jingle></iq>";
      if( t->xml() == expected )
        m_result = true;
      else
        fprintf( stderr, "Jingle::Session test %d\nHave:     %s\nExpected: %s\n", m_test, t->xml().c_str(), expected.c_str() );
      ini->js()->handleIq( iq );
      break;
    case 4:
    case 5:
    {
      break;
    }
  }

  delete t;
}
	/*
	
	<iq type=’result’from=’groups.ruijie.com.cn’ to=’[email protected]/pc’>
	<query xmlns=’groups:list’>
	<item id=’112’ name=’吃货群’ icon=”icon_url”v=”false” alert=”1”/>
	<item id=’113’ name=’开心群’ icon=”icon_url”v=”false” alert=”0”/>
	…
	</query>
	</iq>
*/
	void GetGroupsListHandler::handleIqID( const IQ& iq, int context )
	{
		json::jobject jobj;
		if (iq.m_subtype != gloox::IQ::Result)
		{
			const Error* e = iq.error();
			if (!e)
			{
				callback_(true,XL("biz.GetGroupsList.fail"),jobj);
				return;
			}

			if ( e->error() == StanzaErrorBadRequest)
			{
				ELOG("app")->error(WCOOL(L"取群列表时,请求协议错误!。"));
				callback_(true,XL("biz.crwod.iq_error.bad-request"),jobj);
			}
			else if (e->error() == StanzaErrorInternalServerError)
			{
				ELOG("app")->error(WCOOL(L"取群列表时,处理错误(服务器处理错误)。"));
				callback_(true,XL("biz.crwod.iq_error.internal-server-error"),jobj);
			}
			else if (e->error() == StanzaErrorItemNotFound)
			{
				ELOG("app")->error(WCOOL(L"取群列表时,找不到此群。"));
				callback_(true,XL("biz.crwod.iq_error.item-not-found"),jobj);
			}else
			{
				ELOG("app")->error(WCOOL(L"取群列表时,服务器返回未知错误类型!") + boost::shared_ptr<gloox::Tag>(iq.tag())->xml());
				callback_(true,XL("biz.GetGroupsList.fail"),jobj);
			}

		}else{
			if(iq.findExtension(kExtUser_iq_filter_getgroupslist))
			{
				boost::shared_ptr<gloox::Tag> tag(iq.findExtension(kExtUser_iq_filter_getgroupslist)->tag());
				if (tag)
				{
					//循环取得item
					gloox::TagList items;
					items = tag->findChildren("item");
					TagList::const_iterator it = items.begin();
					for( ; it != items.end(); ++it )
					{
						json::jobject data;
						data["session_id"] = gWrapInterface::instance().append_groups_domain((*it)->findAttribute( "id" ));
						data["remark"] = (*it)->findAttribute( "remark" );
						data["name"] = (*it)->findAttribute( "name" );
						data["icon"]  = (*it)->findAttribute( "icon" );
						data["official"] = (*it)->findAttribute( "v" );
						data["alert"] = (*it)->findAttribute( "alert" );
						data["role"] = (*it)->findAttribute( "role" );
						data["quit"] = (*it)->findAttribute( "quit" );
						data["status"] = (*it)->findAttribute( "status" );
						data["dismiss"] = (*it)->findAttribute( "dismiss" );
						data["active"] = (*it)->findAttribute( "active" );
						data["category"] = (*it)->findAttribute( "category" );
						jobj.arr_push(data);
					}

					if (!callback_.empty())
					{
						callback_(false, XL(""), jobj);
					}

					return;
				}
			}

			ELOG("app")->error(WCOOL(L"取群列表时服务端返回的数据格式错误。") + boost::shared_ptr<gloox::Tag>(iq.tag())->xml());
			if (!callback_.empty())
			{
				universal_resource error_desc;
				error_desc = XL("biz.GetGroupsList.fail");
				callback_(true, error_desc, jobj);
			}
		}
	}
	void GetGroupsShareListHandler::handleIqID( const IQ& iq, int context )
	{
		json::jobject jobj,items,sets;
		if (iq.m_subtype != gloox::IQ::Result)
		{
			const Error* e = iq.error();
			if (!e)
			{
				callback_(true,XL("biz.GetGroupsShareList.fail"),jobj);
				return;
			}
			if ( e->error() == StanzaErrorBadRequest)
			{
				ELOG("app")->error(WCOOL(L"取群共享列表时,请求协议错误!。"));
				callback_(true,XL("biz.crwod.iq_error.bad-request"),jobj);
			}
			else if (e->error() == StanzaErrorInternalServerError)
			{
				ELOG("app")->error(WCOOL(L"取群共享列表时,处理错误(服务器处理错误)。"));
				callback_(true,XL("biz.crwod.iq_error.internal-server-error"),jobj);
			}
			else if (e->error() == StanzaErrorItemNotFound)
			{
				ELOG("app")->error(WCOOL(L"取群共享列表时,找不到此群。"));
				callback_(true,XL("biz.crwod.iq_error.item-not-found"),jobj);
			}else
			{
				ELOG("app")->error(WCOOL(L"取群共享列表时,服务器返回未知错误类型!") + boost::shared_ptr<gloox::Tag>(iq.tag())->xml());
				callback_(true,XL("biz.GetGroupsShareList.fail"),jobj);
			}

		}else{
			if(iq.findExtension(kExtUser_iq_filter_getgroupssharelist))
			{
				boost::shared_ptr<gloox::Tag> tag(iq.findExtension(kExtUser_iq_filter_getgroupssharelist)->tag());
				if (tag)
				{
					//循环取得item
					gloox::TagList item;
					item = tag->findChildren("item");
					TagList::const_iterator it = item.begin();

					gloox::Tag* setTag = tag->findChild("set");
					if (setTag)
					{
						if (setTag->findChild( "index" ))
						{
							sets["index"]= setTag->findChild( "index" )->findCData( "index" );
						}
						if (setTag->findChild( "max" ))
						{
							sets["max"]= setTag->findChild( "max" )->findCData( "max" );
						}
						if (setTag->findChild( "total" ))
						{
							sets["total"]= setTag->findChild( "total" )->findCData( "total" );
						}
					}
					
					jobj["set"]=sets;
					for( ; it != item.end(); ++it )
					{
						json::jobject data;
						
						data["id"] = (*it)->findAttribute( "id" );
						data["name"] = (*it)->findAttribute( "name" );
						data["size"]  = (*it)->findAttribute( "size" );
						data["owner_jid"] = (*it)->findAttribute( "owner_jid" );
						
						if ((*it)->findAttribute( "download_count" ).empty())
						{
							data["download_count"] = "0";
						}
						else
						{
							data["download_count"] = (*it)->findAttribute( "download_count" );
						}
						
						std::string timestamp = (*it)->findAttribute( "create_time" );
						data["timestamp"] = timestamp;
						if (!timestamp.empty())
						{
							boost::posix_time::ptime t = boost::posix_time::from_time_t(boost::lexical_cast<intmax_t>(timestamp)/1000);
							boost::posix_time::ptime local_time = boost::date_time::c_local_adjustor<boost::posix_time::ptime>::utc_to_local(t);
							data["create_time"] = epius::time_format(local_time);
						}
						else
						{
							data["create_time"] = "";
						}
						
						data["owner_name"] = (*it)->findAttribute( "owner_name" );
						data["uri"] = (*it)->findAttribute( "uri" );
						items.arr_push(data);
					}
					jobj["list"]=items;
					if (!callback_.empty())
					{
						callback_(false, XL(""), jobj);
					}

					return;
				}
			}

			ELOG("app")->error(WCOOL(L"取群共享列表时服务端返回的数据格式错误。") + boost::shared_ptr<gloox::Tag>(iq.tag())->xml());
			if (!callback_.empty())
			{
				universal_resource error_desc;
				error_desc = XL("biz.GetGroupsShareList.fail");
				callback_(true, error_desc, jobj);
			}
		}
	}
	void GroupsAdminManageMemberHandler::handleIqID( const IQ& iq, int context )
	{
		json::jobject jobj;
		if (iq.m_subtype != gloox::IQ::Result)
		{
			const Error* e = iq.error();
			if (!e)
			{
				callback_(true,XL("biz.GroupsAdminManageMember.fail"));
				return;
			}
			if ( e->error() == StanzaErrorBadRequest)
			{
				ELOG("app")->error(WCOOL(L"管理员审批成员加入时,请求协议错误!。"));
				callback_(true,XL("biz.crwod.iq_error.bad-request"));
			}
			else if (e->error() == StanzaErrorInternalServerError)
			{
				ELOG("app")->error(WCOOL(L"管理员审批成员加入时,处理错误(服务器处理错误)。"));
				callback_(true,XL("biz.crwod.iq_error.internal-server-error"));
			}
			else if (e->error() == StanzaErrorGone)
			{
				universal_resource err;
				err.res_key="biz.crwod.iq_error.answer_apply_gone";
				ELOG("app")->error(WCOOL(L"管理员审批成员加入时,消息已过期!"));
				callback_(false,err);
			}
			else if (e->error() == StanzaErrorForbidden)
			{
				ELOG("app")->error(WCOOL(L"管理员审批成员加入时,自己不是管理员"));
				callback_(true,XL("biz.crwod.iq_error.admin_forbidden"));
			}			
			else if (e->error() == StanzaErrorResourceConstraint)
			{
				ELOG("app")->error(WCOOL(L"管理员审批成员加入时,群成员已经满"));
				callback_(true,XL("biz.crwod.iq_error.admin_resource-constraint"));
			}
			else if (e->error() == StanzaErrorConflict)
			{
				universal_resource err;
				err.res_key="biz.crwod.iq_error.admin_Conflict";
				ELOG("app")->error(WCOOL(L"管理员审批成员加入时,该成员已加入群"));
				callback_(false,err);
			}
			else if (e->error() == StanzaErrorItemNotFound)
			{
				ELOG("app")->error(WCOOL(L"管理员审批成员加入时,找不到此群。"));
				callback_(true,XL("biz.crwod.iq_error.item-not-found"));
			}else
			{
				ELOG("app")->error(WCOOL(L"管理员审批成员加入时,服务器返回未知错误类型!") + boost::shared_ptr<gloox::Tag>(iq.tag())->xml());
				callback_(true,XL("biz.GroupsAdminManageMember.fail"));
			}

		}else{
			callback_(false,XL(""));		
		}
	}
/*
 <iq type=’result’ from=’[email protected]’ to=’[email protected]’>
  	<query xmlns=’groups:dismiss’>
  		<item name=’吃货群’ />
  </query>
  </iq>
*/
void GetGroupsRecentMessagesHandler::handleIqID( const IQ& iq, int context )
{
    json::jobject jobj;
    if (iq.m_subtype != gloox::IQ::Result)
    {
        universal_resource error_group;
        ELOG("app")->error(WCOOL(L"获取群最近消息时服务端返回错误。") + boost::shared_ptr<gloox::Tag>(iq.tag())->xml());
        error_group = XL("biz.GetGroupsRecentMessages.fail");
    }
}