├── COPYING ├── README.MD └── qtalk_opensource ├── .gitignore ├── COPYING ├── Makefile ├── Makefile.in ├── Makefile.win32 ├── README.md ├── asn1 └── XmppAddr.asn1 ├── autogen.sh ├── build.sh ├── config.status ├── configure ├── configure.ac ├── configure.bat ├── contrib └── extract_translations │ ├── README │ ├── extract_translations.erl │ └── prepare-translation.sh ├── doc ├── Makefile ├── api │ ├── Makefile │ ├── overview.edoc │ └── process-one.css ├── contributed_modules.tex ├── dev.html ├── dev.tex ├── discorus.png ├── features.aux ├── features.html ├── features.out ├── features.pdf ├── features.tex ├── flow.dot ├── guide.html ├── guide.pdf ├── guide.tex ├── introduction.tex ├── logo.png ├── msrl-dit-deep.png ├── msrl-dit-flat.png ├── msrl-roster-deep.png ├── msrl-roster-flat.png ├── version.aux ├── version.tex ├── webadmmain.png ├── webadmmainru.png └── yozhikheader.png ├── ejabberd.init ├── ejabberd.init.template ├── ejabberd.yml.example ├── ejabberdctl.cfg.example ├── ejabberdctl.example ├── ejabberdctl.template ├── examples ├── extauth │ └── check_pass_null.pl ├── mtr │ ├── ejabberd │ ├── ejabberd-netbsd.sh │ └── ejabberd.cfg └── transport-configs │ ├── configs │ ├── aim-transport.xml │ ├── ile.xml │ ├── jabber-gg-transport.xml │ ├── jit.xml │ ├── msn-transport.xml │ └── yahoo-transport-2.xml │ └── init-scripts │ ├── aim-transport │ ├── ile │ ├── jabber-gg-transport │ ├── jit │ ├── msn-transport │ └── yahoo-transport-2 ├── include ├── ELDAPv3.hrl ├── XmppAddr.hrl ├── adhoc.hrl ├── ejabberd.hrl ├── ejabberd_commands.hrl ├── ejabberd_config.hrl ├── ejabberd_ctl.hrl ├── ejabberd_http.hrl ├── ejabberd_web_admin.hrl ├── eldap.hrl ├── http_bind.hrl ├── http_req.hrl ├── jlib.hrl ├── logger.hrl ├── message_pb.hrl ├── mod_muc_room.hrl ├── mod_privacy.hrl ├── mod_proxy65.hrl ├── mod_roster.hrl ├── ns.hrl ├── pubsub.hrl └── qunar_ejabberd_extend.hrl ├── inetrc ├── install-sh ├── m4 └── erlang-extra.m4 ├── priv └── msgs │ ├── ca.msg │ ├── ca.po │ ├── cs.msg │ ├── cs.po │ ├── de.msg │ ├── de.po │ ├── ejabberd.pot │ ├── el.msg │ ├── el.po │ ├── eo.msg │ ├── eo.po │ ├── es.msg │ ├── es.po │ ├── fr.msg │ ├── fr.po │ ├── gl.msg │ ├── gl.po │ ├── he.msg │ ├── he.po │ ├── id.msg │ ├── id.po │ ├── it.msg │ ├── it.po │ ├── ja.msg │ ├── ja.po │ ├── nl.msg │ ├── nl.po │ ├── no.msg │ ├── no.po │ ├── pl.msg │ ├── pl.po │ ├── pt-br.msg │ ├── pt-br.po │ ├── pt.msg │ ├── pt.po │ ├── ru.msg │ ├── ru.po │ ├── sk.msg │ ├── sk.po │ ├── sv.msg │ ├── sv.po │ ├── th.msg │ ├── th.po │ ├── tr.msg │ ├── tr.po │ ├── uk.msg │ ├── uk.po │ ├── vi.msg │ ├── vi.po │ ├── wa.msg │ ├── wa.po │ ├── zh.msg │ └── zh.po ├── rebar ├── rebar.config.script ├── rel ├── files │ ├── erl │ └── install_upgrade.escript └── reltool.config.script ├── scripts ├── .gitignore └── ejb_http_server │ ├── bin │ └── ejb_http_server │ ├── config │ ├── ejb_http_server.config │ └── lager.config │ ├── deps │ └── .keep │ ├── doc │ └── .keep │ ├── ebin │ └── .keep │ ├── include │ ├── ejb_http_server.hrl │ ├── http_req.hrl │ └── logger.hrl │ ├── priv │ └── .keep │ ├── rebar │ ├── rebar.config │ └── src │ ├── domain_search_vcard.erl │ ├── ejb_cache.erl │ ├── ejb_http_day_check.erl │ ├── ejb_http_server.app.src │ ├── ejb_http_server.erl │ ├── ejb_http_server_app.erl │ ├── ejb_http_server_config.erl │ ├── ejb_http_server_env.erl │ ├── ejb_http_server_sup.erl │ ├── ejb_http_server_sys_stat.erl │ ├── ejb_monitor.erl │ ├── ejb_odbc_query.erl │ ├── ejb_public.erl │ ├── ejb_server.erl │ ├── ejb_update_cache.erl │ ├── handle_department.erl │ ├── http_add_muc_user.erl │ ├── http_check_auth.erl │ ├── http_check_auth_v2.erl │ ├── http_check_user_status.erl │ ├── http_client.erl │ ├── http_client_sup.erl │ ├── http_create_muc.erl │ ├── http_del_muc_user.erl │ ├── http_destory_muc.erl │ ├── http_get_adjacentmsg.erl │ ├── http_get_blur_user.erl │ ├── http_get_dump_url.erl │ ├── http_get_exact_user_status.erl │ ├── http_get_history.erl │ ├── http_get_increment_mucs.erl │ ├── http_get_increment_users.erl │ ├── http_get_invite_info.erl │ ├── http_get_msg_backup.erl │ ├── http_get_msgs.erl │ ├── http_get_muc_backup_msg.erl │ ├── http_get_muc_config.erl │ ├── http_get_muc_history.erl │ ├── http_get_muc_history2.erl │ ├── http_get_muc_history3.erl │ ├── http_get_muc_history_v2.erl │ ├── http_get_muc_msg.erl │ ├── http_get_muc_users.erl │ ├── http_get_muc_vcard.erl │ ├── http_get_person_config.erl │ ├── http_get_rbts_sub.erl │ ├── http_get_recent_contacts.erl │ ├── http_get_user_muc_last.erl │ ├── http_get_user_nick.erl │ ├── http_get_user_profile.erl │ ├── http_get_user_status.erl │ ├── http_get_vcard_info.erl │ ├── http_getdeps.erl │ ├── http_gethistory.erl │ ├── http_getmsgs.erl │ ├── http_getmuchistory.erl │ ├── http_getmucmsg.erl │ ├── http_getmucvcard.erl │ ├── http_getonlineuser.erl │ ├── http_getonlineuser2.erl │ ├── http_getrbtinfo.erl │ ├── http_getservertime.erl │ ├── http_getsuoxie.erl │ ├── http_getusers.erl │ ├── http_getuserstatus.erl │ ├── http_getvcardinfo.erl │ ├── http_healthcheck.erl │ ├── http_log_dump_url.erl │ ├── http_qmonitor.erl │ ├── http_rbtReg.erl │ ├── http_recommend_rbts.erl │ ├── http_registeruser.erl │ ├── http_search_rbts.erl │ ├── http_send_rbt_msg.erl │ ├── http_send_warn_msg.erl │ ├── http_sendall.erl │ ├── http_senddep.erl │ ├── http_sendmessage.erl │ ├── http_set_muc_config.erl │ ├── http_set_person_config.erl │ ├── http_set_person_mackey.erl │ ├── http_set_user_profile.erl │ ├── http_setblacklist.erl │ ├── http_setmackey.erl │ ├── http_setmucvcard.erl │ ├── http_setrbtinfo.erl │ ├── http_setvcardinfo.erl │ ├── http_setwhitelist.erl │ ├── http_subscription.erl │ ├── http_utils.erl │ ├── http_wlan_send_message.erl │ ├── iplimit_util.erl │ ├── memory_free.erl │ ├── mod_time.erl │ ├── pg_odbc.erl │ ├── pg_odbc_sup.erl │ ├── randoms.erl │ ├── redis_link.erl │ ├── redis_link_sup.erl │ ├── str.erl │ ├── transfer_node_rpc.erl │ ├── transfer_odbc.erl │ └── transfer_odbc_sup.erl ├── sql ├── mssql2000.sql ├── mssql2005.sql ├── mssql2012.sql ├── mysql.sql └── pg.sql ├── src ├── ELDAPv3.asn1db ├── ELDAPv3.erl ├── XmppAddr.asn1db ├── XmppAddr.erl ├── acl.erl ├── adhoc.erl ├── asy_sql.erl ├── clear_expire_muc.erl ├── cyrsasl.erl ├── cyrsasl_anonymous.erl ├── cyrsasl_digest.erl ├── cyrsasl_plain.erl ├── cyrsasl_scram.erl ├── easy_cluster.erl ├── ejabberd.app.src ├── ejabberd.app.src.in ├── ejabberd.erl ├── ejabberd_admin.erl ├── ejabberd_app.erl ├── ejabberd_auth.erl ├── ejabberd_auth_anonymous.erl ├── ejabberd_auth_external.erl ├── ejabberd_auth_internal.erl ├── ejabberd_auth_ldap.erl ├── ejabberd_auth_odbc.erl ├── ejabberd_auth_pam.erl ├── ejabberd_auth_riak.erl ├── ejabberd_c2s.erl ├── ejabberd_c2s_config.erl ├── ejabberd_captcha.erl ├── ejabberd_commands.erl ├── ejabberd_config.erl ├── ejabberd_ctl.erl ├── ejabberd_encode_protobuf.erl ├── ejabberd_frontend_socket.erl ├── ejabberd_hooks.erl ├── ejabberd_http.erl ├── ejabberd_http_bind.erl ├── ejabberd_http_poll.erl ├── ejabberd_ldap_server.erl ├── ejabberd_ldap_sup.erl ├── ejabberd_listener.erl ├── ejabberd_local.erl ├── ejabberd_logger.erl ├── ejabberd_node_groups.erl ├── ejabberd_odbc.erl ├── ejabberd_odbc_sup.erl ├── ejabberd_piefxis.erl ├── ejabberd_public.erl ├── ejabberd_rdbms.erl ├── ejabberd_receiver.erl ├── ejabberd_regexp.erl ├── ejabberd_riak.erl ├── ejabberd_riak_sup.erl ├── ejabberd_router.erl ├── ejabberd_s2s.erl ├── ejabberd_s2s_in.erl ├── ejabberd_s2s_out.erl ├── ejabberd_service.erl ├── ejabberd_sm.erl ├── ejabberd_sm_v2.erl ├── ejabberd_sm_v3.erl ├── ejabberd_socket.erl ├── ejabberd_stun.erl ├── ejabberd_sup.erl ├── ejabberd_system_monitor.erl ├── ejabberd_tmp_sup.erl ├── ejabberd_update.erl ├── ejabberd_web.erl ├── ejabberd_web_admin.erl ├── ejabberd_wlan_c2s.erl ├── ejabberd_wlan_protobuf_c2s.erl ├── ejabberd_xml2pb_iq.erl ├── ejabberd_xml2pb_message.erl ├── ejabberd_xml2pb_presence.erl ├── ejabberd_xml2pb_public.erl ├── ejabberd_xmlrpc.erl ├── ejd2odbc.erl ├── eldap.erl ├── eldap_filter.erl ├── eldap_filter_yecc.erl ├── eldap_filter_yecc.yrl ├── eldap_pool.erl ├── eldap_utils.erl ├── extauth.erl ├── gen_iq_handler.erl ├── gen_mod.erl ├── gen_pubsub_node.erl ├── gen_pubsub_nodetree.erl ├── http_add_muc_user.erl ├── http_client.erl ├── http_cmd.erl ├── http_create_muc.erl ├── http_del_muc_user.erl ├── http_destroy_muc.erl ├── http_get_adjacentmsg.erl ├── http_get_increment_users.erl ├── http_get_muc_info.erl ├── http_get_user_status.erl ├── http_healthcheck.erl ├── http_management.erl ├── http_muc_session.erl ├── http_muc_vcard_presence.erl ├── http_qmonitor.erl ├── http_registeruser.erl ├── http_send_rbt_msg.erl ├── http_send_warn_msg.erl ├── http_sendall.erl ├── http_senddep.erl ├── http_sendmessage.erl ├── http_setblacklist.erl ├── http_setrbtinfo.erl ├── http_setwhitelist.erl ├── http_utils.erl ├── http_wlan_send_msg.erl ├── idna.erl ├── iplimit_util.erl ├── jd2ejd.erl ├── jlib.erl ├── make_muc_pic.erl ├── management_cmd.erl ├── memory_free.erl ├── mod_adhoc.erl ├── mod_announce.erl ├── mod_asy_sql.erl ├── mod_blocking.erl ├── mod_caps.erl ├── mod_carboncopy.erl ├── mod_configure.erl ├── mod_configure2.erl ├── mod_cowboy.erl ├── mod_day_check.erl ├── mod_disco.erl ├── mod_dispose_muc_not_alive_iq.erl ├── mod_echo.erl ├── mod_extend_iq.erl ├── mod_friend.erl ├── mod_hash.erl ├── mod_hash_nodes.erl ├── mod_hash_user.erl ├── mod_http_bind.erl ├── mod_http_client.erl ├── mod_http_cmd.erl ├── mod_http_fileserver.erl ├── mod_http_get.erl ├── mod_ip_blacklist.erl ├── mod_irc.erl ├── mod_irc_connection.erl ├── mod_last.erl ├── mod_log_chat.erl ├── mod_mnesia_monitor.erl ├── mod_monitor.erl ├── mod_msg_id_queue.erl ├── mod_muc.erl ├── mod_muc_log.erl ├── mod_muc_room.erl ├── mod_muc_subscribe.erl ├── mod_offline.erl ├── mod_ping.erl ├── mod_pres_counter.erl ├── mod_privacy.erl ├── mod_private.erl ├── mod_proxy65.erl ├── mod_proxy65_lib.erl ├── mod_proxy65_service.erl ├── mod_proxy65_sm.erl ├── mod_proxy65_stream.erl ├── mod_pubsub.erl ├── mod_pubsub_odbc.erl ├── mod_recent_contact.erl ├── mod_recv_msg_limit.erl ├── mod_redis.erl ├── mod_register.erl ├── mod_register_web.erl ├── mod_roster.erl ├── mod_service_log.erl ├── mod_shared_roster.erl ├── mod_shared_roster_ldap.erl ├── mod_sic.erl ├── mod_sip.erl ├── mod_sip_proxy.erl ├── mod_sip_registrar.erl ├── mod_stats.erl ├── mod_time.erl ├── mod_update.erl ├── mod_update_v2.erl ├── mod_user_relation.erl ├── mod_vcard.erl ├── mod_vcard_ldap.erl ├── mod_vcard_xupdate.erl ├── mod_version.erl ├── msg_id_queue.erl ├── node.template ├── node_buddy.erl ├── node_club.erl ├── node_dag.erl ├── node_dispatch.erl ├── node_flat.erl ├── node_flat_odbc.erl ├── node_hometree.erl ├── node_hometree_odbc.erl ├── node_mb.erl ├── node_pep.erl ├── node_pep_odbc.erl ├── node_private.erl ├── node_public.erl ├── nodetree_dag.erl ├── nodetree_tree.erl ├── nodetree_tree_odbc.erl ├── nodetree_virtual.erl ├── odbc_queries.erl ├── pubsub_db_odbc.erl ├── pubsub_index.erl ├── pubsub_subscription.erl ├── pubsub_subscription_odbc.erl ├── randoms.erl ├── readmark.erl ├── redis_link.erl ├── revoke.erl ├── scram.erl ├── shaper.erl ├── str.erl ├── subscribe_msg.erl ├── subscribe_msg_sup.erl ├── subscription.erl ├── sync_ets_cache.erl ├── table_handle.erl ├── tea_crypto.erl ├── translate.erl ├── user_relation.erl ├── uuid.erl └── win32_dns.erl ├── test ├── README ├── ejabberd_SUITE.erl ├── ejabberd_SUITE_data │ ├── cert.pem │ ├── ejabberd.cfg │ ├── ejabberd.ldif │ ├── ejabberd.yml │ └── extauth.py ├── ldap_srv.erl ├── suite.erl └── suite.hrl ├── tools ├── captcha.sh ├── configure.erl ├── ejabberdctl.bc ├── jhbtest.pl ├── xmpp_codec.erl ├── xmpp_codec.hrl └── xmpp_codec.spec ├── vars.config ├── vars.config.in └── win32 ├── CheckReqs.ini ├── CheckReqs1.ini ├── CheckReqs1H.ini ├── CheckService.ini ├── CheckUser.ini ├── CheckUserH.ini ├── ejabberd.cfg ├── ejabberd.ico ├── ejabberd.nsi ├── ejabberd_header.bmp ├── ejabberd_intro.bmp └── inetrc /README.MD: -------------------------------------------------------------------------------- 1 | *我们的目标是让企业化部署更加简单明了,聊天,服务器就是要放家里才放心!* 2 | 3 | ##### 我们的一键部署 4 | - 如果您觉得编译源码和下载其他组件太麻烦了的话,这里还有更简单的一键部署版本![一键部署](https://github.com/may-liu/qtalkonekey)欢迎使用。 5 | 6 | ##### 我们的官网 7 | https://im.qunar.com 8 | 9 | 欢迎大家在上头留言或者在线聊天! 10 | 迫于资源的问题,目前的版本还不够自动化。会尽快放出一键部署包。。。 11 | 12 | 13 | ##### 关于QTalk 14 | 15 | - 开源的企业级办公云平台,基于IM,目前是 Qunar(去哪儿网) 内部使用的通信软件。 16 | 17 | - 基于erlang开发。 18 | 19 | - 开源的代码部分会在代码审核组审核完成后提交到github。 20 | 21 | ##### 为什么要弄这个? 22 | 23 | - 在办公环境中,需要天天跟同事、跟OA打交道。 24 | 25 | - 这其中最让人恼火的就是办公环境掉链子、复杂难用、只能在特定地域完成(比如OA只能在办公室里审批)然后导致办公成本提升。 26 | 27 | - 为此我们自己做了一个基于IM云服务的办公系统。 28 | 29 | - 在Qunar内部使用了1年,经过了各种摧残,逐步完善中。 30 | 31 | ##### 我们的心愿 32 | 33 | - 希望随着它的不断壮大,可以帮助更多的人和企业! 34 | -------------------------------------------------------------------------------- /qtalk_opensource/.gitignore: -------------------------------------------------------------------------------- 1 | # kdiff3 ignore 2 | *.orig 3 | 4 | # maven ignore 5 | target/ 6 | 7 | # eclipse ignore 8 | .settings/ 9 | .project 10 | .classpath 11 | 12 | # idea ignore 13 | .idea/ 14 | *.ipr 15 | *.iml 16 | *.iws 17 | 18 | # temp ignore 19 | *.log 20 | *.cache 21 | *.diff 22 | *.patch 23 | *.tmp 24 | 25 | # system ignore 26 | .DS_Store 27 | Thumbs.db 28 | 29 | # package ignore (optional) 30 | # *.jar 31 | # *.war 32 | # *.zip 33 | # *.tar 34 | # *.tar.gz -------------------------------------------------------------------------------- /qtalk_opensource/README.md: -------------------------------------------------------------------------------- 1 | ejabberd - High-Performance Enterprise Instant Messaging Server 2 | --------------------------------------------------------------- 3 | 4 | Quickstart guide 5 | ================ 6 | 7 | 8 | 0. Requirements 9 | --------------- 10 | 11 | To compile ejabberd you need: 12 | 13 | - GNU Make 14 | - GCC 15 | - Libexpat 1.95 or higher 16 | - Libyaml 0.1.4 or higher 17 | - Erlang/OTP R15B or higher. 18 | - OpenSSL 0.9.8 or higher, for STARTTLS, SASL and SSL encryption. 19 | - Zlib 1.2.3 or higher, for Stream Compression support 20 | (XEP-0138). Optional. 21 | - PAM library. Optional. For Pluggable Authentication Modules (PAM). 22 | - GNU Iconv 1.8 or higher, for the IRC Transport 23 | (mod_irc). Optional. Not needed on systems with GNU Libc. 24 | - ImageMagick's Convert program. Optional. For CAPTCHA challenges. 25 | 26 | 27 | 1. Compile and install on *nix systems 28 | -------------------------------------- 29 | 30 | To compile ejabberd execute the commands: 31 | 32 | ./configure 33 | make 34 | 35 | To install ejabberd, run this command with system administrator rights 36 | (root user): 37 | 38 | sudo make install 39 | 40 | These commands will: 41 | 42 | - Install the configuration files in `/etc/ejabberd/` 43 | - Install ejabberd binary, header and runtime files in `/lib/ejabberd/` 44 | - Install the administration script: `/sbin/ejabberdctl` 45 | - Install ejabberd documentation in `/share/doc/ejabberd/` 46 | - Create a spool directory: `/var/lib/ejabberd/` 47 | - Create a directory for log files: `/var/log/ejabberd/` 48 | 49 | 50 | 2. Start ejabberd 51 | ----------------- 52 | 53 | You can use the `ejabberdctl` command line administration script to 54 | start and stop ejabberd. For example: 55 | 56 | ejabberdctl start 57 | 58 | 59 | For detailed information please refer to the [ejabberd Installation and 60 | Operation Guide][1]. 61 | 62 | [1]: http://www.process-one.net/docs/ejabberd/guide_en.html 63 | -------------------------------------------------------------------------------- /qtalk_opensource/asn1/XmppAddr.asn1: -------------------------------------------------------------------------------- 1 | XmppAddr { iso(1) identified-organization(3) 2 | dod(6) internet(1) security(5) mechanisms(5) pkix(7) 3 | id-on(8) id-on-xmppAddr(5) } 4 | 5 | DEFINITIONS EXPLICIT TAGS ::= 6 | BEGIN 7 | 8 | id-on-xmppAddr OBJECT IDENTIFIER ::= { iso(1) identified-organization(3) 9 | dod(6) internet(1) security(5) mechanisms(5) pkix(7) 10 | id-on(8) 5 } 11 | 12 | XmppAddr ::= UTF8String 13 | 14 | END 15 | -------------------------------------------------------------------------------- /qtalk_opensource/autogen.sh: -------------------------------------------------------------------------------- 1 | # generate a new autoconf 2 | aclocal -I m4 3 | autoconf -f 4 | -------------------------------------------------------------------------------- /qtalk_opensource/configure.bat: -------------------------------------------------------------------------------- 1 | 2 | @if "x%1"=="x--help" goto usage 3 | 4 | @set arg=dynamic 5 | @if "x%1"=="x--static" set arg=static 6 | 7 | @echo Configuring for %arg% build... 8 | 9 | erlc configure.erl 10 | erl -s configure -env arg %arg% -noshell 11 | 12 | @goto end 13 | 14 | :usage 15 | @echo Usage: configure.bat 16 | @echo or configure.bat --static 17 | @echo or configure.bat --help 18 | 19 | :end 20 | 21 | -------------------------------------------------------------------------------- /qtalk_opensource/contrib/extract_translations/README: -------------------------------------------------------------------------------- 1 | extract_translations - auxiliary tool that extracts lines to be translated 2 | from ejabberd source tree. 3 | 4 | Building: 5 | erlc extract_translations.erl 6 | 7 | Invoking 1: 8 | erl -noinput -s extract_translations -extra dirname message_file 9 | 10 | where dirname is the directory "src" in ejabberd's source tree root, 11 | message_file is a file with translated messages (src/msgs/*.msg). 12 | 13 | Result is a list of messages from source files which aren't contained in 14 | message file. 15 | 16 | Invoking 2: 17 | erl -noinput -s extract_translations -extra -unused dirname message_file 18 | 19 | Result is a list of messages from message file which aren't in source 20 | files anymore. 21 | 22 | -------------------------------------------------------------------------------- /qtalk_opensource/doc/Makefile: -------------------------------------------------------------------------------- 1 | # $Id$ 2 | 3 | SHELL = /bin/bash 4 | 5 | CONTRIBUTED_MODULES = "" 6 | #ifeq ($(shell ls mod_http_bind.tex),mod_http_bind.tex) 7 | # CONTRIBUTED_MODULES += "\\n\\setboolean{modhttpbind}{true}" 8 | #endif 9 | 10 | 11 | all: release pdf html 12 | 13 | release: 14 | @echo "Notes for the releaser:" 15 | @echo "* Do not forget to add a link to the release notes in guide.tex" 16 | @echo "* Do not forget to update the version number in ebin/ejabberd.app!" 17 | @echo "* Do not forget to update the features in introduction.tex (including \new{} and \improved{} tags)." 18 | @echo "Press any key to continue" 19 | ##@read foo 20 | @echo "% ejabberd version (automatically generated)." > version.tex 21 | @echo "\newcommand{\version}{"`sed '/vsn/!d;s/\(.*\)"\(.*\)"\(.*\)/\2/' ../ebin/ejabberd.app`"}" >> version.tex 22 | @echo -n "% Contributed modules (automatically generated)." > contributed_modules.tex 23 | @echo -e "$(CONTRIBUTED_MODULES)" >> contributed_modules.tex 24 | 25 | html: guide.html dev.html features.html 26 | 27 | pdf: guide.pdf features.pdf 28 | 29 | clean: 30 | rm -f *.aux 31 | rm -f *.haux 32 | rm -f *.htoc 33 | rm -f *.idx 34 | rm -f *.ilg 35 | rm -f *.ind 36 | rm -f *.log 37 | rm -f *.out 38 | rm -f *.pdf 39 | rm -f *.toc 40 | [ ! -f contributed_modules.tex ] || rm contributed_modules.tex 41 | 42 | distclean: clean 43 | rm -f *.html 44 | 45 | guide.html: guide.tex 46 | hevea -fix -pedantic guide.tex 47 | 48 | dev.html: dev.tex 49 | hevea -fix -pedantic dev.tex 50 | 51 | features.html: features.tex 52 | hevea -fix -pedantic features.tex 53 | 54 | guide.pdf: guide.tex 55 | pdflatex guide.tex 56 | pdflatex guide.tex 57 | pdflatex guide.tex 58 | makeindex guide.idx 59 | pdflatex guide.tex 60 | 61 | features.pdf: features.tex 62 | pdflatex features.tex 63 | -------------------------------------------------------------------------------- /qtalk_opensource/doc/api/Makefile: -------------------------------------------------------------------------------- 1 | APPNAME = ejabberd 2 | VSN = $(shell sed '/vsn/!d;s/\(.*\)"\(.*\)"\(.*\)/\2/' ../../src/ejabberd.app) 3 | 4 | DOCDIR=. 5 | SRCDIR=../../src 6 | 7 | .PHONY = all 8 | 9 | all: docs 10 | 11 | clean: 12 | rm -f *.html 13 | rm edoc-info 14 | rm erlang.png 15 | 16 | docs: 17 | erl -noshell -run edoc_run application \ 18 | "'$(APPNAME)'" '"$(SRCDIR)"' '[{dir,"$(DOCDIR)"},{packages, false},{todo,true},{private,true},{def,{vsn,"$(VSN)"}},{stylesheet,"process-one.css"},{overview,"$(DOCDIR)/overview.edoc"}]' -s init stop 19 | -------------------------------------------------------------------------------- /qtalk_opensource/doc/api/overview.edoc: -------------------------------------------------------------------------------- 1 | @author Mickael Remond 2 | [http://www.process-one.net/] 3 | @copyright 2013 ProcessOne 4 | @version {@vsn}, {@date} {@time} 5 | @title ejabberd Development API Documentation 6 | 7 | @doc 8 | == Introduction == 9 | 10 | TODO: Insert content from Jerome documentation. 11 | -------------------------------------------------------------------------------- /qtalk_opensource/doc/api/process-one.css: -------------------------------------------------------------------------------- 1 | html, body { 2 | font-family: Verdana, sans-serif; 3 | color: #000; 4 | background-color: #fff; 5 | } 6 | 7 | h1 { 8 | color: #4a5389; 9 | border-bottom: solid 1px #000; 10 | } 11 | 12 | h2 { 13 | font-size: 24px; 14 | text-align: right; 15 | color: #4a5389; 16 | border-bottom: 1px solid #000; 17 | } 18 | 19 | h3 { 20 | font-size: 18px; 21 | color: #900; 22 | } 23 | 24 | h4 { 25 | font-size: 14px; 26 | color: #000; 27 | } 28 | 29 | a[href] { 30 | color: #4a5389; 31 | } 32 | 33 | a[href]:hover { 34 | background-color: #ecefff; 35 | } 36 | 37 | p, li, dd { 38 | text-align: justify; 39 | } 40 | 41 | li { 42 | margin-top: 0.3em; 43 | } 44 | 45 | li:first-child { 46 | margin-top: 0px; 47 | } 48 | 49 | blockquote { 50 | color: #555; 51 | } 52 | 53 | caption { 54 | font-style: italic; 55 | color: #009; 56 | text-align: left; 57 | margin-left: 20px; 58 | } 59 | 60 | table[border="1"] { 61 | border-collapse: collapse; 62 | margin-bottom: 1em; 63 | } 64 | 65 | table[border="1"] td { 66 | border: 1px solid #ddd; 67 | } 68 | 69 | pre, tt, code { 70 | color: #461b7e; 71 | } 72 | 73 | pre { 74 | margin:1ex 2ex; 75 | border:1px dashed lightgrey; 76 | background-color:#f9f9f9; 77 | padding:0.5ex; 78 | } 79 | 80 | pre em { 81 | font-style: normal; 82 | font-weight: bold; 83 | } 84 | 85 | dt { 86 | margin:0ex 2ex; 87 | font-weight:bold; 88 | } 89 | 90 | dd { 91 | margin:0ex 0ex 1ex 4ex; 92 | } 93 | -------------------------------------------------------------------------------- /qtalk_opensource/doc/contributed_modules.tex: -------------------------------------------------------------------------------- 1 | % Contributed modules (automatically generated). 2 | -------------------------------------------------------------------------------- /qtalk_opensource/doc/discorus.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/may-liu/qtalk/f5431e5a7123975e9656e7ab239e674ce33713cd/qtalk_opensource/doc/discorus.png -------------------------------------------------------------------------------- /qtalk_opensource/doc/features.aux: -------------------------------------------------------------------------------- 1 | \relax 2 | \providecommand\HyperFirstAtBeginDocument{\AtBeginDocument} 3 | \HyperFirstAtBeginDocument{\ifx\hyper@anchor\@undefined 4 | \global\let\oldcontentsline\contentsline 5 | \gdef\contentsline#1#2#3#4{\oldcontentsline{#1}{#2}{#3}} 6 | \global\let\oldnewlabel\newlabel 7 | \gdef\newlabel#1#2{\newlabelxx{#1}#2} 8 | \gdef\newlabelxx#1#2#3#4#5#6{\oldnewlabel{#1}{{#2}{#3}}} 9 | \AtEndDocument{\ifx\hyper@anchor\@undefined 10 | \let\contentsline\oldcontentsline 11 | \let\newlabel\oldnewlabel 12 | \fi} 13 | \fi} 14 | \global\let\hyper@last\relax 15 | \gdef\HyperFirstAtBeginDocument#1{#1} 16 | \providecommand\HyField@AuxAddToFields[1]{} 17 | \newlabel{titlepage}{{}{1}{\relax }{Doc-Start}{}} 18 | \newlabel{intro}{{}{2}{\relax }{Doc-Start}{}} 19 | \@writefile{toc}{\contentsline {section}{Key Features}{3}{section*.1}} 20 | \newlabel{keyfeatures}{{}{3}{Key Features\relax }{section*.1}{}} 21 | \@writefile{toc}{\contentsline {section}{Additional Features}{4}{section*.2}} 22 | \newlabel{addfeatures}{{}{4}{Additional Features\relax }{section*.2}{}} 23 | -------------------------------------------------------------------------------- /qtalk_opensource/doc/features.out: -------------------------------------------------------------------------------- 1 | \BOOKMARK [1][-]{section*.1}{\376\377\000K\000e\000y\000\040\000F\000e\000a\000t\000u\000r\000e\000s}{}% 1 2 | \BOOKMARK [1][-]{section*.2}{\376\377\000A\000d\000d\000i\000t\000i\000o\000n\000a\000l\000\040\000F\000e\000a\000t\000u\000r\000e\000s}{}% 2 3 | -------------------------------------------------------------------------------- /qtalk_opensource/doc/features.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/may-liu/qtalk/f5431e5a7123975e9656e7ab239e674ce33713cd/qtalk_opensource/doc/features.pdf -------------------------------------------------------------------------------- /qtalk_opensource/doc/flow.dot: -------------------------------------------------------------------------------- 1 | digraph messages { 2 | //concentrate=true; 3 | subgraph clusterclients { 4 | client1 [shape = box]; 5 | client2 [shape = box]; 6 | client3 [shape = box]; 7 | 8 | style = dashed; 9 | label = "Clients"; 10 | } 11 | 12 | subgraph clusternode1 { 13 | subgraph clusterc2s1 { 14 | c2s11; 15 | c2s12; 16 | style = invis; 17 | } 18 | subgraph clusterservices1 { 19 | service11; 20 | service12; 21 | service13; 22 | style = invis; 23 | } 24 | //subgraph clusters2s1 { 25 | //s2s11; 26 | //s2s12; 27 | //style = invis; 28 | //} 29 | c2s11 -> auth1; 30 | c2s12 -> auth1; 31 | auth1 -> c2s11; 32 | auth1 -> c2s12; 33 | c2s11 -> sm1; 34 | c2s11 -> router1; 35 | c2s12 -> sm1; 36 | c2s12 -> router1; 37 | router1 -> local1; 38 | router1 -> service11; 39 | router1 -> service12; 40 | router1 -> service13; 41 | router1 -> s2s11; 42 | router1 -> s2s12; 43 | service11 -> router1; 44 | service12 -> router1; 45 | service13 -> router1; 46 | s2s11 -> router1; 47 | s2s12 -> router1; 48 | local1 -> sm1; 49 | sm1 -> c2s11; 50 | sm1 -> c2s12; 51 | 52 | style = dashed; 53 | label = "Node1"; 54 | } 55 | 56 | subgraph clusternode2 { 57 | c2s2 -> auth2; 58 | auth2 -> c2s2; 59 | c2s2 -> sm2; 60 | c2s2 -> router2; 61 | router2 -> local2; 62 | router2 -> service21; 63 | router2 -> s2s21; 64 | service21 -> router2; 65 | s2s21 -> router2; 66 | local2 -> sm2; 67 | sm2 -> c2s2; 68 | 69 | style = dashed; 70 | label = "Node2"; 71 | } 72 | 73 | 74 | 75 | subgraph clusterservers { 76 | server1 [shape = box]; 77 | server2 [shape = box]; 78 | server3 [shape = box]; 79 | 80 | style = dashed; 81 | label = "Servers"; 82 | } 83 | 84 | 85 | client1 -> c2s11; 86 | client2 -> c2s12; 87 | client3 -> c2s2; 88 | c2s11 -> client1 [constraint=false]; 89 | c2s12 -> client2 [constraint=false]; 90 | c2s2 -> client3 [constraint=false]; 91 | 92 | s2s11 -> server1 [minlen = 2]; 93 | s2s12 -> server2 [minlen = 2]; 94 | s2s21 -> server3 [minlen = 2]; 95 | server1 -> s2s11 [constraint=false]; 96 | server2 -> s2s12 [constraint=false]; 97 | server3 -> s2s21 [constraint=false]; 98 | 99 | router1 -> router2; 100 | router2 -> router1; 101 | sm1 -> sm2; 102 | sm2 -> sm1; 103 | 104 | label = "Data Flows"; 105 | } 106 | -------------------------------------------------------------------------------- /qtalk_opensource/doc/guide.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/may-liu/qtalk/f5431e5a7123975e9656e7ab239e674ce33713cd/qtalk_opensource/doc/guide.pdf -------------------------------------------------------------------------------- /qtalk_opensource/doc/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/may-liu/qtalk/f5431e5a7123975e9656e7ab239e674ce33713cd/qtalk_opensource/doc/logo.png -------------------------------------------------------------------------------- /qtalk_opensource/doc/msrl-dit-deep.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/may-liu/qtalk/f5431e5a7123975e9656e7ab239e674ce33713cd/qtalk_opensource/doc/msrl-dit-deep.png -------------------------------------------------------------------------------- /qtalk_opensource/doc/msrl-dit-flat.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/may-liu/qtalk/f5431e5a7123975e9656e7ab239e674ce33713cd/qtalk_opensource/doc/msrl-dit-flat.png -------------------------------------------------------------------------------- /qtalk_opensource/doc/msrl-roster-deep.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/may-liu/qtalk/f5431e5a7123975e9656e7ab239e674ce33713cd/qtalk_opensource/doc/msrl-roster-deep.png -------------------------------------------------------------------------------- /qtalk_opensource/doc/msrl-roster-flat.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/may-liu/qtalk/f5431e5a7123975e9656e7ab239e674ce33713cd/qtalk_opensource/doc/msrl-roster-flat.png -------------------------------------------------------------------------------- /qtalk_opensource/doc/version.aux: -------------------------------------------------------------------------------- 1 | \relax 2 | \@setckpt{version}{ 3 | \setcounter{page}{1} 4 | \setcounter{equation}{0} 5 | \setcounter{enumi}{0} 6 | \setcounter{enumii}{0} 7 | \setcounter{enumiii}{0} 8 | \setcounter{enumiv}{0} 9 | \setcounter{footnote}{0} 10 | \setcounter{mpfootnote}{0} 11 | \setcounter{part}{0} 12 | \setcounter{section}{0} 13 | \setcounter{subsection}{0} 14 | \setcounter{subsubsection}{0} 15 | \setcounter{paragraph}{0} 16 | \setcounter{subparagraph}{0} 17 | \setcounter{figure}{0} 18 | \setcounter{table}{0} 19 | \setcounter{cuttingdepth}{0} 20 | \setcounter{Item}{0} 21 | \setcounter{Hfootnote}{0} 22 | \setcounter{bookmark@seq@number}{0} 23 | } 24 | -------------------------------------------------------------------------------- /qtalk_opensource/doc/version.tex: -------------------------------------------------------------------------------- 1 | % ejabberd version (automatically generated). 2 | \newcommand{\version}{14.07} 3 | -------------------------------------------------------------------------------- /qtalk_opensource/doc/webadmmain.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/may-liu/qtalk/f5431e5a7123975e9656e7ab239e674ce33713cd/qtalk_opensource/doc/webadmmain.png -------------------------------------------------------------------------------- /qtalk_opensource/doc/webadmmainru.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/may-liu/qtalk/f5431e5a7123975e9656e7ab239e674ce33713cd/qtalk_opensource/doc/webadmmainru.png -------------------------------------------------------------------------------- /qtalk_opensource/doc/yozhikheader.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/may-liu/qtalk/f5431e5a7123975e9656e7ab239e674ce33713cd/qtalk_opensource/doc/yozhikheader.png -------------------------------------------------------------------------------- /qtalk_opensource/ejabberd.init: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | 3 | ### BEGIN INIT INFO 4 | # Provides: ejabberd 5 | # Required-Start: $remote_fs $network $named $time 6 | # Required-Stop: $remote_fs $network $named $time 7 | # Default-Start: 2 3 4 5 8 | # Default-Stop: 0 1 6 9 | # Short-Description: Starts ejabberd jabber server 10 | # Description: Starts ejabberd jabber server, an XMPP 11 | # compliant server written in Erlang. 12 | ### END INIT INFO 13 | 14 | # chkconfig: 2345 90 10 15 | # description: ejabberd XMPP server 16 | 17 | set -o errexit 18 | 19 | DIR=/home/q/ejabberd.14.07.1/sbin 20 | CTL="$DIR"/ejabberdctl 21 | USER=root 22 | 23 | test -x "$CTL" || { 24 | echo "ERROR: ejabberd not found: $DIR" 25 | exit 1 26 | } 27 | grep ^"$USER": /etc/passwd >/dev/null || { 28 | echo "ERROR: System user not found: $USER" 29 | exit 2 30 | } 31 | 32 | export PATH="${PATH:+$PATH:}/usr/sbin:/sbin" 33 | 34 | case "$1" in 35 | start) 36 | test -x "$CTL" || exit 0 37 | echo "Starting ejabberd..." 38 | su - $USER -c "$CTL start" 39 | su - $USER -c "$CTL started" 40 | echo "done." 41 | ;; 42 | stop) 43 | test -x "$CTL" || exit 0 44 | echo "Stopping ejabberd..." 45 | su - $USER -c "$CTL stop" 46 | su - $USER -c "$CTL stopped" 47 | echo "done." 48 | ;; 49 | status) 50 | test -x "$CTL" || exit 0 51 | echo "Getting ejabberd status..." 52 | su - $USER -c "$CTL status" 53 | ;; 54 | force-reload|restart) 55 | "$0" stop 56 | "$0" start 57 | ;; 58 | *) 59 | echo "Usage: $0 {start|stop|restart|force-reload|status}" 60 | exit 1 61 | esac 62 | 63 | exit 0 64 | -------------------------------------------------------------------------------- /qtalk_opensource/ejabberd.init.template: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | 3 | ### BEGIN INIT INFO 4 | # Provides: ejabberd 5 | # Required-Start: $remote_fs $network $named $time 6 | # Required-Stop: $remote_fs $network $named $time 7 | # Default-Start: 2 3 4 5 8 | # Default-Stop: 0 1 6 9 | # Short-Description: Starts ejabberd jabber server 10 | # Description: Starts ejabberd jabber server, an XMPP 11 | # compliant server written in Erlang. 12 | ### END INIT INFO 13 | 14 | # chkconfig: 2345 90 10 15 | # description: ejabberd XMPP server 16 | 17 | set -o errexit 18 | 19 | DIR=@ctlscriptpath@ 20 | CTL="$DIR"/ejabberdctl 21 | USER=@installuser@ 22 | 23 | test -x "$CTL" || { 24 | echo "ERROR: ejabberd not found: $DIR" 25 | exit 1 26 | } 27 | grep ^"$USER": /etc/passwd >/dev/null || { 28 | echo "ERROR: System user not found: $USER" 29 | exit 2 30 | } 31 | 32 | export PATH="${PATH:+$PATH:}/usr/sbin:/sbin" 33 | 34 | case "$1" in 35 | start) 36 | test -x "$CTL" || exit 0 37 | echo "Starting ejabberd..." 38 | su - $USER -c "$CTL start" 39 | su - $USER -c "$CTL started" 40 | echo "done." 41 | ;; 42 | stop) 43 | test -x "$CTL" || exit 0 44 | echo "Stopping ejabberd..." 45 | su - $USER -c "$CTL stop" 46 | su - $USER -c "$CTL stopped" 47 | echo "done." 48 | ;; 49 | status) 50 | test -x "$CTL" || exit 0 51 | echo "Getting ejabberd status..." 52 | su - $USER -c "$CTL status" 53 | ;; 54 | force-reload|restart) 55 | "$0" stop 56 | "$0" start 57 | ;; 58 | *) 59 | echo "Usage: $0 {start|stop|restart|force-reload|status}" 60 | exit 1 61 | esac 62 | 63 | exit 0 64 | -------------------------------------------------------------------------------- /qtalk_opensource/examples/extauth/check_pass_null.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | 3 | use Unix::Syslog qw(:macros :subs); 4 | 5 | my $domain = $ARGV[0] || "example.com"; 6 | 7 | while(1) 8 | { 9 | # my $rin = '',$rout; 10 | # vec($rin,fileno(STDIN),1) = 1; 11 | # $ein = $rin; 12 | # my $nfound = select($rout=$rin,undef,undef,undef); 13 | 14 | my $buf = ""; 15 | syslog LOG_INFO,"waiting for packet"; 16 | my $nread = sysread STDIN,$buf,2; 17 | do { syslog LOG_INFO,"port closed"; exit; } unless $nread == 2; 18 | my $len = unpack "n",$buf; 19 | my $nread = sysread STDIN,$buf,$len; 20 | 21 | my ($op,$user,$host,$password) = split /:/,$buf; 22 | #$user =~ s/\./\//og; 23 | my $jid = "$user\@$domain"; 24 | my $result; 25 | 26 | syslog(LOG_INFO,"request (%s)", $op); 27 | 28 | SWITCH: 29 | { 30 | $op eq 'auth' and do 31 | { 32 | $result = 1; 33 | },last SWITCH; 34 | 35 | $op eq 'setpass' and do 36 | { 37 | $result = 1; 38 | },last SWITCH; 39 | 40 | $op eq 'isuser' and do 41 | { 42 | # password is null. Return 1 if the user $user\@$domain exitst. 43 | $result = 1; 44 | },last SWITCH; 45 | 46 | $op eq 'tryregister' and do 47 | { 48 | $result = 1; 49 | },last SWITCH; 50 | 51 | $op eq 'removeuser' and do 52 | { 53 | # password is null. Return 1 if the user $user\@$domain exitst. 54 | $result = 1; 55 | },last SWITCH; 56 | 57 | $op eq 'removeuser3' and do 58 | { 59 | $result = 1; 60 | },last SWITCH; 61 | }; 62 | my $out = pack "nn",2,$result ? 1 : 0; 63 | syswrite STDOUT,$out; 64 | } 65 | 66 | closelog; 67 | -------------------------------------------------------------------------------- /qtalk_opensource/examples/mtr/ejabberd: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # PROVIDE: ejabberd 4 | # REQUIRE: DAEMON 5 | # KEYWORD: shutdown 6 | # 7 | 8 | HOME=/usr/pkg/jabber D=/usr/pkg/jabber/ejabberd export HOME 9 | 10 | name="ejabberd" 11 | rcvar=$name 12 | 13 | if [ -r /etc/rc.conf ] 14 | then 15 | . /etc/rc.conf 16 | else 17 | eval ${rcvar}=YES 18 | fi 19 | 20 | # $flags from environment overrides ${rcvar}_flags 21 | if [ -n "${flags}" ] 22 | then 23 | eval ${rcvar}_flags="${flags}" 24 | fi 25 | 26 | checkyesno() 27 | { 28 | eval _value=\$${1} 29 | case $_value in 30 | [Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]|[Oo][Nn]|1) return 0 ;; 31 | [Nn][Oo]|[Ff][Aa][Ll][Ss][Ee]|[Oo][Ff][Ff]|0) return 1 ;; 32 | *) 33 | echo "\$${1} is not set properly." 34 | return 1 35 | ;; 36 | esac 37 | } 38 | 39 | cmd=${1:-start} 40 | case ${cmd} in 41 | force*) 42 | cmd=${cmd#force} 43 | eval ${rcvar}=YES 44 | ;; 45 | esac 46 | 47 | if checkyesno ${rcvar} 48 | then 49 | else 50 | exit 0 51 | fi 52 | 53 | case ${cmd} in 54 | start) 55 | if [ -x $D/src ]; then 56 | echo "Starting ${name}." 57 | cd $D/src 58 | ERL_MAX_PORTS=32000 export ERL_MAX_PORTS 59 | ulimit -n $ERL_MAX_PORTS 60 | su jabber -c "/usr/pkg/bin/erl -sname ejabberd -s ejabberd -heart -detached -sasl sasl_error_logger '{file, \"ejabberd-sasl.log\"}' &" \ 61 | 1>/dev/null 2>&1 62 | fi 63 | ;; 64 | stop) 65 | echo "rpc:call('ejabberd@`hostname -s`', init, stop, [])." | \ 66 | su jabber -c "/usr/pkg/bin/erl -sname ejabberdstop" 67 | ;; 68 | restart) 69 | echo "rpc:call('ejabberd@`hostname -s`', init, restart, [])." | \ 70 | su jabber -c "/usr/pkg/bin/erl -sname ejabberdrestart" 71 | ;; 72 | *) 73 | echo "Usage: $0 {start|stop|restart}" 74 | exit 1 75 | esac 76 | -------------------------------------------------------------------------------- /qtalk_opensource/examples/mtr/ejabberd-netbsd.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | echo '1. fetch, compile, and install erlang' 4 | 5 | if [ ! pkg_info erlang 1>/dev/null 2>&1 ]; then 6 | cd /usr/pkgsrc/lang/erlang 7 | make fetch-list|sh 8 | make 9 | make install 10 | fi 11 | if pkg_info erlang | grep -q erlang-9.1nb1; then 12 | else 13 | echo "erlang-9.1nb1 not installed" 1>&2 14 | exit 1 15 | fi 16 | 17 | 18 | echo '2. install crypt_drv.so' 19 | 20 | if [ ! -d /usr/pkg/lib/erlang/lib/crypto-1.1.2.1/priv/lib ] ; then 21 | mkdir -p /usr/pkg/lib/erlang/lib/crypto-1.1.2.1/priv/lib 22 | fi 23 | if [ ! -f /usr/pkg/lib/erlang/lib/crypto-1.1.2.1/priv/lib/crypto_drv.so ]; then 24 | cp work/otp*/lib/crypto/priv/*/*/crypto_drv.so \ 25 | /usr/pkg/lib/erlang/lib/crypto-1.1.2.1/priv/lib 26 | fi 27 | 28 | 29 | echo '3. compile and install elibcrypto.so' 30 | 31 | if [ ! -f /usr/pkg/lib/erlang/lib/crypto-1.1.2.1/priv/lib/elibcrypto.so ]; then 32 | cd /usr/pkgsrc/lang/erlang/work/otp_src_R9B-1/lib/crypto/c_src 33 | ld -r -u CRYPTO_set_mem_functions -u MD5 -u MD5_Init -u MD5_Update \ 34 | -u MD5_Final -u SHA1 -u SHA1_Init -u SHA1_Update -u SHA1_Final \ 35 | -u des_set_key -u des_ncbc_encrypt -u des_ede3_cbc_encrypt \ 36 | -L/usr/lib -lcrypto -o ../priv/obj/i386--netbsdelf/elibcrypto.o 37 | cc -shared \ 38 | -L/usr/pkgsrc/lang/erlang/work/otp_src_R9B-1/lib/erl_interface/obj/i386--netbsdelf \ 39 | -o ../priv/obj/i386--netbsdelf/elibcrypto.so \ 40 | ../priv/obj/i386--netbsdelf/elibcrypto.o -L/usr/lib -lcrypto 41 | cp ../priv/obj/i386--netbsdelf/elibcrypto.so \ 42 | /usr/pkg/lib/erlang/lib/crypto-1.1.2.1/priv/lib 43 | fi 44 | 45 | 46 | echo '4. compile and install ssl_esock' 47 | 48 | if [ ! -f /usr/pkg/lib/erlang/lib/ssl-2.3.5/priv/bin/ssl_esock ]; then 49 | cd /usr/pkg/lib/erlang/lib/ssl-2.3.5/priv/obj/ 50 | make 51 | fi 52 | 53 | 54 | echo '5. initial ejabberd configuration' 55 | 56 | cd /usr/pkg/jabber/ejabberd/src 57 | ./configure 58 | 59 | 60 | echo '6. edit ejabberd Makefiles' 61 | 62 | for M in Makefile mod_*/Makefile; do 63 | if [ ! -f $M.orig ]; then 64 | mv $M $M.orig 65 | sed -e s%/usr/local%/usr/pkg%g < $M.orig > $M 66 | fi 67 | done 68 | 69 | 70 | echo '7. compile ejabberd' 71 | 72 | gmake 73 | for A in mod_irc mod_muc mod_pubsub; do 74 | (cd $A; gmake) 75 | done 76 | 77 | 78 | echo '' 79 | echo 'now edit ejabberd.cfg' 80 | echo '' 81 | echo 'to start ejabberd: erl -sname ejabberd -s ejabberd' 82 | -------------------------------------------------------------------------------- /qtalk_opensource/examples/mtr/ejabberd.cfg: -------------------------------------------------------------------------------- 1 | % jabber.dbc.mtview.ca.us 2 | 3 | override_acls. 4 | 5 | {acl, admin, {user, "mrose", "jabber.dbc.mtview.ca.us"}}. 6 | 7 | 8 | {access, announce, [{allow, admin}, 9 | {deny, all}]}. 10 | {access, c2s, [{deny, blocked}, 11 | {allow, all}]}. 12 | {access, c2s_shaper, [{none, admin}, 13 | {normal, all}]}. 14 | {access, configure, [{allow, admin}, 15 | {deny, all}]}. 16 | {access, disco_admin, [{allow, admin}, 17 | {deny, all}]}. 18 | {access, muc_admin, [{allow, admin}, 19 | {deny, all}]}. 20 | {access, register, [{deny, all}]}. 21 | {access, s2s_shaper, [{fast, all}]}. 22 | 23 | 24 | {auth_method, internal}. 25 | {host, "jabber.dbc.mtview.ca.us"}. 26 | {outgoing_s2s_port, 5269}. 27 | {shaper, normal, {maxrate, 1000}}. 28 | {shaper, fast, {maxrate, 50000}}. 29 | {welcome_message, none}. 30 | 31 | 32 | {listen, [{5222, ejabberd_c2s, 33 | [{access, c2s}, 34 | {shaper, c2s_shaper}]}, 35 | {5223, ejabberd_c2s, 36 | [{access, c2s}, 37 | {shaper, c2s_shaper}, 38 | {ssl, [{certfile, "/etc/openssl/certs/ejabberd.pem"}]}]}, 39 | {5269, ejabberd_s2s_in, 40 | [{shaper, s2s_shaper}]}]}. 41 | 42 | 43 | {modules, [ 44 | {mod_register, []}, 45 | {mod_roster, []}, 46 | {mod_privacy, []}, 47 | {mod_configure, []}, 48 | {mod_disco, []}, 49 | {mod_stats, []}, 50 | {mod_vcard, []}, 51 | {mod_offline, []}, 52 | {mod_echo, [{host, "echo.jabber.dbc.mtview.ca.us"}]}, 53 | {mod_private, []}, 54 | % {mod_irc, []}, 55 | {mod_muc, []}, 56 | {mod_pubsub, []}, 57 | {mod_time, []}, 58 | {mod_last, []}, 59 | {mod_version, []} 60 | ]}. 61 | 62 | 63 | 64 | % Local Variables: 65 | % mode: erlang 66 | % End: 67 | -------------------------------------------------------------------------------- /qtalk_opensource/examples/transport-configs/configs/aim-transport.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 9 | 10 | 11 | 12 | 13 | %d: [%t] (%h): %s 14 | /var/log/jabber/aim-transport-error.log 15 | 16 | 17 | 18 | 19 | record 20 | %d %h %s 21 | /var/log/jabber/aim-transport-record.log 22 | 23 | 24 | 28 | 29 | 30 | 31 | 32 | /usr/local/lib/jabber/libjabberdxdbfile.so 33 | 34 | 35 | /var/spool/jabber 36 | 37 | 38 | 39 | 43 | 44 | 45 | 46 | 47 | 48 | AIM/ICQ Transport 49 | This is the AIM/ICQ Transport. 50 | EMAIL@ADDRESS.COM 51 | http://aim-transport.jabberstudio.org/ 52 | 53 | cp1252 54 | 55 | 56 | 57 | /usr/local/lib/jabber/aim-transport.so 58 | 59 | 60 | 61 | 65 | 66 | 67 | 68 | 69 | 127.0.0.1 70 | 5233 71 | SECRET 72 | 73 | 74 | 75 | /var/run/jabber/aim-transport.pid 76 | 77 | 78 | -------------------------------------------------------------------------------- /qtalk_opensource/examples/transport-configs/configs/yahoo-transport-2.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 9 | 10 | 11 | 12 | 13 | %d: [%t] (%h): %s 14 | /var/log/jabber/yahoo-transport-2-error.log 15 | 16 | 17 | 18 | 22 | 23 | 24 | 25 | 26 | /usr/local/lib/jabber/libjabberdxdbfile.so 27 | 28 | 29 | /var/spool/jabber 30 | 31 | 32 | 33 | 37 | 38 | 39 | 40 | 41 | 42 | Yahoo! Transport 43 | vCard not implemented in current version 44 | This is the Yahoo! transport. 45 | EMAIL@ADDRESS.COM 46 | http://yahoo-transport-2.jabberstudio.org/ 47 | 48 | Fill in your YAHOO! Messenger username and password to register on this transport. 49 | scs.msg.yahoo.com 50 | 5050 51 | 57 | CP1252 58 | 62 | 63 | 64 | 65 | 66 | /usr/local/lib/jabber/yahoo-transport-2.so 67 | 68 | 69 | 70 | 74 | 75 | 76 | 77 | 78 | 127.0.0.1 79 | 5236 80 | SECRET 81 | 82 | 83 | 84 | /var/run/jabber/yahoo-transport-2.pid 85 | 86 | 87 | -------------------------------------------------------------------------------- /qtalk_opensource/examples/transport-configs/init-scripts/aim-transport: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | ######################################################### 3 | # 4 | # aim-transport -- script to start aim-transport. 5 | # 6 | ######################################################### 7 | 8 | DAEMON=/usr/local/sbin/jabberd-aim-transport 9 | CONF=/etc/jabber/aim-transport.xml 10 | NAME=jabberd-aim-transport 11 | HOME=/etc/jabber/ 12 | USER=ejabberd 13 | 14 | ######################################################### 15 | 16 | if [ "`/usr/bin/whoami`" != "$USER" ]; then 17 | 18 | echo "You need to be" $USER "user to run this script." 19 | exit 1 20 | fi 21 | 22 | case "$1" in 23 | debug) 24 | test -f $DAEMON -a -f $CONF || exit 0 25 | echo "Starting $NAME in debugging mode." 26 | $DAEMON -D -H $HOME -c $CONF & 27 | ;; 28 | start) 29 | test -f $DAEMON -a -f $CONF || exit 0 30 | echo "Starting $NAME." 31 | $DAEMON -H $HOME -c $CONF & 32 | ;; 33 | stop) 34 | echo "Stopping $NAME." 35 | killall $NAME & 36 | ;; 37 | restart|reload) 38 | $0 stop 39 | sleep 3 40 | $0 start 41 | ;; 42 | *) 43 | echo "Usage: $0 {debug|start|stop|restart}" 44 | exit 1 45 | esac 46 | -------------------------------------------------------------------------------- /qtalk_opensource/examples/transport-configs/init-scripts/ile: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | ######################################################### 3 | # 4 | # ile -- script to start ILE. 5 | # 6 | ######################################################### 7 | 8 | DAEMON=/usr/local/sbin/ile.pl 9 | NAME=ile.pl 10 | CONF=/etc/jabber/ile.xml 11 | USER=ejabberd 12 | 13 | ######################################################### 14 | 15 | if [ "`/usr/bin/whoami`" != "$USER" ]; then 16 | 17 | echo "You need to be" $USER "user to run this script." 18 | exit 1 19 | fi 20 | 21 | case "$1" in 22 | debug) 23 | echo "Not implemented yet. Starting in normal mode" 24 | $0 start 25 | ;; 26 | start) 27 | test -f $DAEMON || exit 0 28 | echo "Starting $NAME." 29 | $DAEMON $CONF & 30 | ;; 31 | stop) 32 | echo "Stopping $NAME." 33 | killall $NAME & 34 | ;; 35 | restart|reload) 36 | $0 stop 37 | sleep 3 38 | $0 start 39 | ;; 40 | *) 41 | echo "Usage: $0 {debug|start|stop|status|restart}" 42 | exit 1 43 | esac 44 | -------------------------------------------------------------------------------- /qtalk_opensource/examples/transport-configs/init-scripts/jabber-gg-transport: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | ######################################################### 3 | # 4 | # jabber-gg-transport -- script to start jabber-gg-transport. 5 | # 6 | ######################################################### 7 | 8 | DAEMON=/usr/local/sbin/jggtrans 9 | CONF=/etc/jabber/jabber-gg-transport.xml 10 | NAME=jggtrans 11 | HOME=/etc/jabber/ 12 | USER=ejabberd 13 | 14 | ######################################################### 15 | 16 | if [ "`/usr/bin/whoami`" != "$USER" ]; then 17 | 18 | echo "You need to be" $USER "user to run this script." 19 | exit 1 20 | fi 21 | 22 | case "$1" in 23 | debug) 24 | test -f $DAEMON -a -f $CONF || exit 0 25 | echo "Starting $NAME in debugging mode." 26 | $DAEMON -D -H $HOME -c $CONF & 27 | ;; 28 | start) 29 | test -f $DAEMON -a -f $CONF || exit 0 30 | echo "Starting $NAME." 31 | $DAEMON $CONF & 32 | ;; 33 | stop) 34 | echo "Stopping $NAME." 35 | killall $NAME & 36 | rm /var/run/jabber/jabber-gg-transport.pid 37 | ;; 38 | 39 | restart|reload) 40 | $0 stop 41 | sleep 3 42 | $0 start 43 | ;; 44 | *) 45 | echo "Usage: $0 {debug|start|stop|restart}" 46 | exit 1 47 | esac 48 | -------------------------------------------------------------------------------- /qtalk_opensource/examples/transport-configs/init-scripts/jit: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | ######################################################### 3 | # 4 | # jit -- script to start JIT. 5 | # 6 | ######################################################### 7 | 8 | DAEMON=/usr/local/sbin/wpjabber-jit 9 | CONF=/etc/jabber/jit.xml 10 | NAME=wpjabber-jit 11 | HOME=/etc/jabber/ 12 | USER=ejabberd 13 | 14 | ######################################################### 15 | 16 | if [ "`/usr/bin/whoami`" != "$USER" ]; then 17 | 18 | echo "You need to be" $USER "user to run this script." 19 | exit 1 20 | fi 21 | 22 | case "$1" in 23 | debug) 24 | test -f $DAEMON -a -f $CONF || exit 0 25 | echo "Starting $NAME in debugging mode." 26 | $DAEMON -D -H $HOME -c $CONF & 27 | ;; 28 | start) 29 | test -f $DAEMON -a -f $CONF || exit 0 30 | echo "Starting $NAME." 31 | $DAEMON -H $HOME -c $CONF & 32 | ;; 33 | stop) 34 | echo "Stopping $NAME." 35 | killall $NAME & 36 | ;; 37 | restart|reload) 38 | $0 stop 39 | sleep 3 40 | $0 start 41 | ;; 42 | *) 43 | echo "Usage: $0 {debug|start|stop|restart}" 44 | exit 1 45 | esac 46 | -------------------------------------------------------------------------------- /qtalk_opensource/examples/transport-configs/init-scripts/msn-transport: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | ######################################################### 3 | # 4 | # msn-transport -- script to start MSN Transport. 5 | # 6 | ######################################################### 7 | 8 | DAEMON=/usr/local/sbin/jabberd-msn-transport 9 | CONF=/etc/jabber/msn-transport.xml 10 | NAME=jabberd-msn-transport 11 | HOME=/etc/jabber/ 12 | USER=ejabberd 13 | 14 | ######################################################### 15 | 16 | if [ "`/usr/bin/whoami`" != "$USER" ]; then 17 | 18 | echo "You need to be" $USER "user to run this script." 19 | exit 1 20 | fi 21 | 22 | case "$1" in 23 | strace) 24 | test -f $DAEMON -a -f $CONF || exit 0 25 | echo "Starting $NAME in strace mode." 26 | strace -o /opt/ejabberd/var/log/jabber/strace.log $DAEMON -H $HOME -c $CONF & 27 | ;; 28 | debug) 29 | test -f $DAEMON -a -f $CONF || exit 0 30 | echo "Starting $NAME in debugging mode." 31 | $DAEMON -D -H $HOME -c $CONF & 32 | ;; 33 | start) 34 | test -f $DAEMON -a -f $CONF || exit 0 35 | echo "Starting $NAME." 36 | $DAEMON -H $HOME -c $CONF & 37 | ;; 38 | stop) 39 | echo "Stopping $NAME." 40 | killall $NAME & 41 | ;; 42 | restart|reload) 43 | $0 stop 44 | sleep 3 45 | $0 start 46 | ;; 47 | *) 48 | echo "Usage: $0 {debug|start|stop|restart}" 49 | exit 1 50 | esac 51 | -------------------------------------------------------------------------------- /qtalk_opensource/examples/transport-configs/init-scripts/yahoo-transport-2: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | ############################################################## 3 | # 4 | # yahoo-transport-2 -- script to start Yahoo-transport-2. 5 | # 6 | ############################################################# 7 | 8 | DAEMON=/usr/local/sbin/jabberd-yahoo-transport-2 9 | CONF=/etc/jabber/yahoo-transport-2.xml 10 | NAME=jabberd-yahoo-transport-2 11 | HOME=/etc/jabber/ 12 | USER=ejabberd 13 | 14 | ############################################################# 15 | 16 | if [ "`/usr/bin/whoami`" != "$USER" ]; then 17 | 18 | echo "You need to be" $USER "user to run this script." 19 | exit 1 20 | fi 21 | 22 | case "$1" in 23 | debug) 24 | test -f $DAEMON -a -f $CONF || exit 0 25 | echo "Starting $NAME in debugging mode." 26 | $DAEMON -D -H $HOME -c $CONF & 27 | ;; 28 | start) 29 | test -f $DAEMON -a -f $CONF || exit 0 30 | echo "Starting $NAME." 31 | $DAEMON -H $HOME -c $CONF & 32 | ;; 33 | stop) 34 | echo "Stopping $NAME." 35 | killall $NAME & 36 | ;; 37 | restart|reload) 38 | $0 stop 39 | sleep 3 40 | $0 start 41 | ;; 42 | *) 43 | echo "Usage: $0 {debug|start|stop|restart}" 44 | exit 1 45 | esac 46 | -------------------------------------------------------------------------------- /qtalk_opensource/include/ELDAPv3.hrl: -------------------------------------------------------------------------------- 1 | %% Generated by the Erlang ASN.1 compiler version:2.0.1 2 | %% Purpose: Erlang record definitions for each named and unnamed 3 | %% SEQUENCE and SET, and macro definitions for each value 4 | %% definition,in module ELDAPv3 5 | 6 | 7 | 8 | -record('LDAPMessage',{ 9 | messageID, protocolOp, controls = asn1_NOVALUE}). 10 | 11 | -record('AttributeValueAssertion',{ 12 | attributeDesc, assertionValue}). 13 | 14 | -record('Attribute',{ 15 | type, vals}). 16 | 17 | -record('LDAPResult',{ 18 | resultCode, matchedDN, errorMessage, referral = asn1_NOVALUE}). 19 | 20 | -record('Control',{ 21 | controlType, criticality = asn1_DEFAULT, controlValue = asn1_NOVALUE}). 22 | 23 | -record('BindRequest',{ 24 | version, name, authentication}). 25 | 26 | -record('SaslCredentials',{ 27 | mechanism, credentials = asn1_NOVALUE}). 28 | 29 | -record('BindResponse',{ 30 | resultCode, matchedDN, errorMessage, referral = asn1_NOVALUE, serverSaslCreds = asn1_NOVALUE}). 31 | 32 | -record('SearchRequest',{ 33 | baseObject, scope, derefAliases, sizeLimit, timeLimit, typesOnly, filter, attributes}). 34 | 35 | -record('SubstringFilter',{ 36 | type, substrings}). 37 | 38 | -record('MatchingRuleAssertion',{ 39 | matchingRule = asn1_NOVALUE, type = asn1_NOVALUE, matchValue, dnAttributes = asn1_DEFAULT}). 40 | 41 | -record('SearchResultEntry',{ 42 | objectName, attributes}). 43 | 44 | -record('PartialAttributeList_SEQOF',{ 45 | type, vals}). 46 | 47 | -record('ModifyRequest',{ 48 | object, modification}). 49 | 50 | -record('ModifyRequest_modification_SEQOF',{ 51 | operation, modification}). 52 | 53 | -record('AttributeTypeAndValues',{ 54 | type, vals}). 55 | 56 | -record('AddRequest',{ 57 | entry, attributes}). 58 | 59 | -record('AttributeList_SEQOF',{ 60 | type, vals}). 61 | 62 | -record('ModifyDNRequest',{ 63 | entry, newrdn, deleteoldrdn, newSuperior = asn1_NOVALUE}). 64 | 65 | -record('CompareRequest',{ 66 | entry, ava}). 67 | 68 | -record('ExtendedRequest',{ 69 | requestName, requestValue = asn1_NOVALUE}). 70 | 71 | -record('ExtendedResponse',{ 72 | resultCode, matchedDN, errorMessage, referral = asn1_NOVALUE, responseName = asn1_NOVALUE, response = asn1_NOVALUE}). 73 | 74 | -record('PasswdModifyRequestValue',{ 75 | userIdentity = asn1_NOVALUE, oldPasswd = asn1_NOVALUE, newPasswd = asn1_NOVALUE}). 76 | 77 | -record('PasswdModifyResponseValue',{ 78 | genPasswd = asn1_NOVALUE}). 79 | 80 | -define('maxInt', 2147483647). 81 | -define('passwdModifyOID', [49,46,51,46,54,46,49,46,52,46,49,46,52,50,48,51,46,49,46,49,49,46,49]). 82 | -------------------------------------------------------------------------------- /qtalk_opensource/include/XmppAddr.hrl: -------------------------------------------------------------------------------- 1 | %% Generated by the Erlang ASN.1 compiler version:3.0.4 2 | %% Purpose: Erlang record definitions for each named and unnamed 3 | %% SEQUENCE and SET, and macro definitions for each value 4 | %% definition,in module XmppAddr 5 | 6 | 7 | 8 | -ifndef(_XMPPADDR_HRL_). 9 | -define(_XMPPADDR_HRL_, true). 10 | 11 | -define('id-on-xmppAddr', {1,3,6,1,5,5,7,8,5}). 12 | -endif. %% _XMPPADDR_HRL_ 13 | -------------------------------------------------------------------------------- /qtalk_opensource/include/adhoc.hrl: -------------------------------------------------------------------------------- 1 | %%%---------------------------------------------------------------------- 2 | %%% 3 | %%% ejabberd, Copyright (C) 2002-2014 ProcessOne 4 | %%% 5 | %%% This program is free software; you can redistribute it and/or 6 | %%% modify it under the terms of the GNU General Public License as 7 | %%% published by the Free Software Foundation; either version 2 of the 8 | %%% License, or (at your option) any later version. 9 | %%% 10 | %%% This program is distributed in the hope that it will be useful, 11 | %%% but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | %%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | %%% General Public License for more details. 14 | %%% 15 | %%% You should have received a copy of the GNU General Public License along 16 | %%% with this program; if not, write to the Free Software Foundation, Inc., 17 | %%% 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 18 | %%% 19 | %%%---------------------------------------------------------------------- 20 | 21 | -record(adhoc_request, 22 | { 23 | lang = <<"">> :: binary(), 24 | node = <<"">> :: binary(), 25 | sessionid = <<"">> :: binary(), 26 | action = <<"">> :: binary(), 27 | xdata = false :: false | xmlel(), 28 | others = [] :: [xmlel()] 29 | }). 30 | 31 | -record(adhoc_response, 32 | { 33 | lang = <<"">> :: binary(), 34 | node = <<"">> :: binary(), 35 | sessionid = <<"">> :: binary(), 36 | status :: atom(), 37 | defaultaction = <<"">> :: binary(), 38 | actions = [] :: [binary()], 39 | notes = [] :: [{binary(), binary()}], 40 | elements = [] :: [xmlel()] 41 | }). 42 | 43 | -type adhoc_request() :: #adhoc_request{}. 44 | -type adhoc_response() :: #adhoc_response{}. 45 | -------------------------------------------------------------------------------- /qtalk_opensource/include/ejabberd.hrl: -------------------------------------------------------------------------------- 1 | %%%---------------------------------------------------------------------- 2 | %%% 3 | %%% ejabberd, Copyright (C) 2002-2014 ProcessOne 4 | %%% 5 | %%% This program is free software; you can redistribute it and/or 6 | %%% modify it under the terms of the GNU General Public License as 7 | %%% published by the Free Software Foundation; either version 2 of the 8 | %%% License, or (at your option) any later version. 9 | %%% 10 | %%% This program is distributed in the hope that it will be useful, 11 | %%% but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | %%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | %%% General Public License for more details. 14 | %%% 15 | %%% You should have received a copy of the GNU General Public License along 16 | %%% with this program; if not, write to the Free Software Foundation, Inc., 17 | %%% 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 18 | %%% 19 | %%%---------------------------------------------------------------------- 20 | 21 | %% This macro returns a string of the ejabberd version running, e.g. "2.3.4" 22 | %% If the ejabberd application description isn't loaded, returns atom: undefined 23 | -define(VERSION, ejabberd_config:get_version()). 24 | 25 | -define(MYHOSTS, ejabberd_config:get_myhosts()). 26 | 27 | -define(MYNAME, hd(ejabberd_config:get_myhosts())). 28 | 29 | -define(MYLANG, ejabberd_config:get_mylang()). 30 | 31 | -define(MSGS_DIR, filename:join(["priv", "msgs"])). 32 | 33 | -define(CONFIG_PATH, <<"ejabberd.cfg">>). 34 | 35 | -define(LOG_PATH, <<"ejabberd.log">>). 36 | 37 | -define(EJABBERD_URI, <<"http://www.process-one.net/en/ejabberd/">>). 38 | 39 | -define(S2STIMEOUT, 600000). 40 | 41 | %%-define(DBGFSM, true). 42 | 43 | -record(scram, 44 | {storedkey = <<"">>, 45 | serverkey = <<"">>, 46 | salt = <<"">>, 47 | iterationcount = 0 :: integer()}). 48 | 49 | -type scram() :: #scram{}. 50 | 51 | -define(SCRAM_DEFAULT_ITERATION_COUNT, 4096). 52 | -------------------------------------------------------------------------------- /qtalk_opensource/include/ejabberd_config.hrl: -------------------------------------------------------------------------------- 1 | %%%---------------------------------------------------------------------- 2 | %%% 3 | %%% ejabberd, Copyright (C) 2002-2014 ProcessOne 4 | %%% 5 | %%% This program is free software; you can redistribute it and/or 6 | %%% modify it under the terms of the GNU General Public License as 7 | %%% published by the Free Software Foundation; either version 2 of the 8 | %%% License, or (at your option) any later version. 9 | %%% 10 | %%% This program is distributed in the hope that it will be useful, 11 | %%% but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | %%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | %%% General Public License for more details. 14 | %%% 15 | %%% You should have received a copy of the GNU General Public License along 16 | %%% with this program; if not, write to the Free Software Foundation, Inc., 17 | %%% 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 18 | %%% 19 | %%%---------------------------------------------------------------------- 20 | 21 | -record(local_config, {key :: any(), value :: any()}). 22 | 23 | -type local_config() :: #local_config{}. 24 | 25 | -record(state, 26 | {opts = [] :: [acl:acl() | local_config()], 27 | hosts = [] :: [binary()], 28 | override_local = false :: boolean(), 29 | override_global = false :: boolean(), 30 | override_acls = false :: boolean()}). 31 | -------------------------------------------------------------------------------- /qtalk_opensource/include/ejabberd_ctl.hrl: -------------------------------------------------------------------------------- 1 | %%%---------------------------------------------------------------------- 2 | %%% 3 | %%% ejabberd, Copyright (C) 2002-2014 ProcessOne 4 | %%% 5 | %%% This program is free software; you can redistribute it and/or 6 | %%% modify it under the terms of the GNU General Public License as 7 | %%% published by the Free Software Foundation; either version 2 of the 8 | %%% License, or (at your option) any later version. 9 | %%% 10 | %%% This program is distributed in the hope that it will be useful, 11 | %%% but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | %%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | %%% General Public License for more details. 14 | %%% 15 | %%% You should have received a copy of the GNU General Public License along 16 | %%% with this program; if not, write to the Free Software Foundation, Inc., 17 | %%% 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 18 | %%% 19 | %%%---------------------------------------------------------------------- 20 | 21 | -define(STATUS_SUCCESS, 0). 22 | 23 | -define(STATUS_ERROR, 1). 24 | 25 | -define(STATUS_USAGE, 2). 26 | 27 | -define(STATUS_BADRPC, 3). 28 | -------------------------------------------------------------------------------- /qtalk_opensource/include/ejabberd_http.hrl: -------------------------------------------------------------------------------- 1 | %%%---------------------------------------------------------------------- 2 | %%% 3 | %%% ejabberd, Copyright (C) 2002-2014 ProcessOne 4 | %%% 5 | %%% This program is free software; you can redistribute it and/or 6 | %%% modify it under the terms of the GNU General Public License as 7 | %%% published by the Free Software Foundation; either version 2 of the 8 | %%% License, or (at your option) any later version. 9 | %%% 10 | %%% This program is distributed in the hope that it will be useful, 11 | %%% but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | %%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | %%% General Public License for more details. 14 | %%% 15 | %%% You should have received a copy of the GNU General Public License along 16 | %%% with this program; if not, write to the Free Software Foundation, Inc., 17 | %%% 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 18 | %%% 19 | %%%---------------------------------------------------------------------- 20 | 21 | -record(request, 22 | {method, % :: method(), 23 | path = [] :: [binary()], 24 | q = [] :: [{binary() | nokey, binary()}], 25 | us = {<<>>, <<>>} :: {binary(), binary()}, 26 | auth :: {binary(), binary()} | 27 | {auth_jid, {binary(), binary()}, jlib:jid()}, 28 | lang = <<"">> :: binary(), 29 | data = <<"">> :: binary(), 30 | ip :: {inet:ip_address(), inet:port_number()}, 31 | host = <<"">> :: binary(), 32 | port = 5280 :: inet:port_number(), 33 | tp = http, % :: protocol(), 34 | headers = [] :: [{atom() | binary(), binary()}]}). 35 | 36 | -------------------------------------------------------------------------------- /qtalk_opensource/include/http_bind.hrl: -------------------------------------------------------------------------------- 1 | %%%---------------------------------------------------------------------- 2 | %%% 3 | %%% ejabberd, Copyright (C) 2002-2014 ProcessOne 4 | %%% 5 | %%% This program is free software; you can redistribute it and/or 6 | %%% modify it under the terms of the GNU General Public License as 7 | %%% published by the Free Software Foundation; either version 2 of the 8 | %%% License, or (at your option) any later version. 9 | %%% 10 | %%% This program is distributed in the hope that it will be useful, 11 | %%% but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | %%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | %%% General Public License for more details. 14 | %%% 15 | %%% You should have received a copy of the GNU General Public License along 16 | %%% with this program; if not, write to the Free Software Foundation, Inc., 17 | %%% 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 18 | %%% 19 | %%%---------------------------------------------------------------------- 20 | 21 | -define(CT_XML, 22 | {<<"Content-Type">>, <<"text/xml; charset=utf-8">>}). 23 | 24 | -define(CT_PLAIN, 25 | {<<"Content-Type">>, <<"text/plain">>}). 26 | 27 | -define(AC_ALLOW_ORIGIN, 28 | {<<"Access-Control-Allow-Origin">>, <<"*">>}). 29 | 30 | -define(AC_ALLOW_METHODS, 31 | {<<"Access-Control-Allow-Methods">>, 32 | <<"GET, POST, OPTIONS">>}). 33 | 34 | -define(AC_ALLOW_HEADERS, 35 | {<<"Access-Control-Allow-Headers">>, 36 | <<"Content-Type">>}). 37 | 38 | -define(AC_MAX_AGE, 39 | {<<"Access-Control-Max-Age">>, <<"86400">>}). 40 | 41 | -define(OPTIONS_HEADER, 42 | [?CT_PLAIN, ?AC_ALLOW_ORIGIN, ?AC_ALLOW_METHODS, 43 | ?AC_ALLOW_HEADERS, ?AC_MAX_AGE]). 44 | 45 | -define(HEADER, 46 | [?CT_XML, ?AC_ALLOW_ORIGIN, ?AC_ALLOW_HEADERS]). 47 | -------------------------------------------------------------------------------- /qtalk_opensource/include/http_req.hrl: -------------------------------------------------------------------------------- 1 | -record(http_req, { 2 | %% Transport. 3 | socket = undefined :: any(), 4 | transport = undefined :: undefined | module(), 5 | connection = keepalive :: keepalive | close, 6 | 7 | %% Request. 8 | pid = undefined :: pid(), 9 | method = <<"GET">> :: binary(), 10 | version = 'HTTP/1.1' :: cowboy:http_version(), 11 | peer = undefined :: undefined | {inet:ip_address(), inet:port_number()}, 12 | host = undefined :: undefined | binary(), 13 | host_info = undefined :: undefined | cowboy_router:tokens(), 14 | port = undefined :: undefined | inet:port_number(), 15 | path = undefined :: binary(), 16 | path_info = undefined :: undefined | cowboy_router:tokens(), 17 | qs = undefined :: binary(), 18 | qs_vals = undefined :: undefined | list({binary(), binary() | true}), 19 | bindings = undefined :: undefined | cowboy_router:bindings(), 20 | headers = [] :: cowboy:http_headers(), 21 | p_headers = [] :: [any()], 22 | cookies = undefined :: undefined | [{binary(), binary()}], 23 | meta = [] :: [{atom(), any()}], 24 | 25 | %% Request body. 26 | body_state, 27 | buffer = <<>> :: binary(), 28 | multipart = undefined :: undefined | {binary(), binary()}, 29 | 30 | %% Response. 31 | resp_compress = false :: boolean(), 32 | resp_state = waiting :: locked | waiting | waiting_stream 33 | | chunks | stream | done, 34 | resp_headers = [] :: cowboy:http_headers(), 35 | resp_body, 36 | 37 | %% Functions. 38 | onresponse = undefined :: undefined | already_called 39 | | cowboy:onresponse_fun() 40 | }). 41 | -------------------------------------------------------------------------------- /qtalk_opensource/include/logger.hrl: -------------------------------------------------------------------------------- 1 | %%%---------------------------------------------------------------------- 2 | %%% 3 | %%% ejabberd, Copyright (C) 2002-2014 ProcessOne 4 | %%% 5 | %%% This program is free software; you can redistribute it and/or 6 | %%% modify it under the terms of the GNU General Public License as 7 | %%% published by the Free Software Foundation; either version 2 of the 8 | %%% License, or (at your option) any later version. 9 | %%% 10 | %%% This program is distributed in the hope that it will be useful, 11 | %%% but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | %%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | %%% General Public License for more details. 14 | %%% 15 | %%% You should have received a copy of the GNU General Public License along 16 | %%% with this program; if not, write to the Free Software Foundation, Inc., 17 | %%% 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 18 | %%% 19 | %%%---------------------------------------------------------------------- 20 | -define(PRINT(Format, Args), io:format(Format, Args)). 21 | 22 | -ifdef(LAGER). 23 | -compile([{parse_transform, lager_transform}]). 24 | 25 | -define(DEBUG(Format, Args), 26 | lager:debug(Format, Args)). 27 | 28 | -define(INFO_MSG(Format, Args), 29 | lager:info(Format, Args)). 30 | 31 | -define(WARNING_MSG(Format, Args), 32 | lager:warning(Format, Args)). 33 | 34 | -define(ERROR_MSG(Format, Args), 35 | lager:error(Format, Args)). 36 | 37 | -define(CRITICAL_MSG(Format, Args), 38 | lager:critical(Format, Args)). 39 | 40 | -else. 41 | 42 | -define(DEBUG(Format, Args), 43 | p1_logger:debug_msg(?MODULE, ?LINE, Format, Args)). 44 | 45 | -define(INFO_MSG(Format, Args), 46 | p1_logger:info_msg(?MODULE, ?LINE, Format, Args)). 47 | 48 | -define(WARNING_MSG(Format, Args), 49 | p1_logger:warning_msg(?MODULE, ?LINE, Format, Args)). 50 | 51 | -define(ERROR_MSG(Format, Args), 52 | p1_logger:error_msg(?MODULE, ?LINE, Format, Args)). 53 | 54 | -define(CRITICAL_MSG(Format, Args), 55 | p1_logger:critical_msg(?MODULE, ?LINE, Format, Args)). 56 | -endif. 57 | -------------------------------------------------------------------------------- /qtalk_opensource/include/mod_privacy.hrl: -------------------------------------------------------------------------------- 1 | %%%---------------------------------------------------------------------- 2 | %%% 3 | %%% ejabberd, Copyright (C) 2002-2014 ProcessOne 4 | %%% 5 | %%% This program is free software; you can redistribute it and/or 6 | %%% modify it under the terms of the GNU General Public License as 7 | %%% published by the Free Software Foundation; either version 2 of the 8 | %%% License, or (at your option) any later version. 9 | %%% 10 | %%% This program is distributed in the hope that it will be useful, 11 | %%% but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | %%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | %%% General Public License for more details. 14 | %%% 15 | %%% You should have received a copy of the GNU General Public License along 16 | %%% with this program; if not, write to the Free Software Foundation, Inc., 17 | %%% 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 18 | %%% 19 | %%%---------------------------------------------------------------------- 20 | 21 | -record(privacy, {us = {<<"">>, <<"">>} :: {binary(), binary()}, 22 | default = none :: none | binary(), 23 | lists = [] :: [{binary(), [listitem()]}]}). 24 | 25 | -record(listitem, {type = none :: none | jid | group | subscription, 26 | value = none :: none | both | from | to | ljid() | binary(), 27 | action = allow :: allow | deny, 28 | order = 0 :: integer(), 29 | match_all = false :: boolean(), 30 | match_iq = false :: boolean(), 31 | match_message = false :: boolean(), 32 | match_presence_in = false :: boolean(), 33 | match_presence_out = false :: boolean()}). 34 | 35 | -type listitem() :: #listitem{}. 36 | 37 | -record(userlist, {name = none :: none | binary(), 38 | list = [] :: [listitem()], 39 | needdb = false :: boolean()}). 40 | 41 | -type userlist() :: #userlist{}. 42 | 43 | -export_type([userlist/0]). 44 | -------------------------------------------------------------------------------- /qtalk_opensource/include/mod_proxy65.hrl: -------------------------------------------------------------------------------- 1 | %%%---------------------------------------------------------------------- 2 | %%% RFC 1928 constants. 3 | %%% 4 | %%% 5 | %%% ejabberd, Copyright (C) 2002-2014 ProcessOne 6 | %%% 7 | %%% This program is free software; you can redistribute it and/or 8 | %%% modify it under the terms of the GNU General Public License as 9 | %%% published by the Free Software Foundation; either version 2 of the 10 | %%% License, or (at your option) any later version. 11 | %%% 12 | %%% This program is distributed in the hope that it will be useful, 13 | %%% but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | %%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | %%% General Public License for more details. 16 | %%% 17 | %%% You should have received a copy of the GNU General Public License along 18 | %%% with this program; if not, write to the Free Software Foundation, Inc., 19 | %%% 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 20 | %%% 21 | %%%---------------------------------------------------------------------- 22 | 23 | %% Version 24 | -define(VERSION_5, 5). 25 | 26 | %% Authentication methods 27 | -define(AUTH_ANONYMOUS, 0). 28 | 29 | -define(AUTH_GSSAPI, 1). 30 | 31 | -define(AUTH_PLAIN, 2). 32 | 33 | %% Address Type 34 | -define(AUTH_NO_METHODS, 255). 35 | 36 | -define(ATYP_IPV4, 1). 37 | 38 | -define(ATYP_DOMAINNAME, 3). 39 | 40 | -define(ATYP_IPV6, 4). 41 | 42 | %% Commands 43 | -define(CMD_CONNECT, 1). 44 | 45 | -define(CMD_BIND, 2). 46 | 47 | -define(CMD_UDP, 3). 48 | 49 | %% RFC 1928 replies 50 | -define(SUCCESS, 0). 51 | 52 | -define(ERR_GENERAL_FAILURE, 1). 53 | 54 | -define(ERR_NOT_ALLOWED, 2). 55 | 56 | -define(ERR_NETWORK_UNREACHABLE, 3). 57 | 58 | -define(ERR_HOST_UNREACHABLE, 4). 59 | 60 | -define(ERR_CONNECTION_REFUSED, 5). 61 | 62 | -define(ERR_TTL_EXPIRED, 6). 63 | 64 | -define(ERR_COMMAND_NOT_SUPPORTED, 7). 65 | 66 | -define(ERR_ADDRESS_TYPE_NOT_SUPPORTED, 8). 67 | 68 | %% RFC 1928 defined timeout. 69 | -define(SOCKS5_REPLY_TIMEOUT, 10000). 70 | 71 | -record(s5_request, {rsv = 0 :: integer(), 72 | cmd = connect :: connect | udp, 73 | sha1 = <<"">> :: binary()}). 74 | -------------------------------------------------------------------------------- /qtalk_opensource/include/mod_roster.hrl: -------------------------------------------------------------------------------- 1 | %%%---------------------------------------------------------------------- 2 | %%% 3 | %%% ejabberd, Copyright (C) 2002-2014 ProcessOne 4 | %%% 5 | %%% This program is free software; you can redistribute it and/or 6 | %%% modify it under the terms of the GNU General Public License as 7 | %%% published by the Free Software Foundation; either version 2 of the 8 | %%% License, or (at your option) any later version. 9 | %%% 10 | %%% This program is distributed in the hope that it will be useful, 11 | %%% but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | %%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | %%% General Public License for more details. 14 | %%% 15 | %%% You should have received a copy of the GNU General Public License along 16 | %%% with this program; if not, write to the Free Software Foundation, Inc., 17 | %%% 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 18 | %%% 19 | %%%---------------------------------------------------------------------- 20 | 21 | -record(roster, 22 | { 23 | usj = {<<>>, <<>>, {<<>>, <<>>, <<>>}} :: {binary(), binary(), ljid()} | '_', 24 | us = {<<>>, <<>>} :: {binary(), binary()} | '_', 25 | jid = {<<>>, <<>>, <<>>} :: ljid(), 26 | name = <<>> :: binary() | '_', 27 | subscription = none :: subscription() | '_', 28 | ask = none :: ask() | '_', 29 | groups = [] :: [binary()] | '_', 30 | askmessage = <<"">> :: binary() | '_', 31 | xs = [] :: [xmlel()] | '_' 32 | }). 33 | 34 | -record(roster_version, 35 | { 36 | us = {<<>>, <<>>} :: {binary(), binary()}, 37 | version = <<>> :: binary() 38 | }). 39 | 40 | -type ask() :: none | in | out | both | subscribe | unsubscribe. 41 | -type subscription() :: none | both | from | to | remove. 42 | -------------------------------------------------------------------------------- /qtalk_opensource/include/qunar_ejabberd_extend.hrl: -------------------------------------------------------------------------------- 1 | -record(mac_sub_users,{user,key}). 2 | -record(department_users,{dep1,dep2,dep3,dep4,dep5,user}). 3 | -record(mac_push_notice,{user}). 4 | -record(muc_online_room, 5 | {name_host = {<<"">>, <<"">>} :: {binary(), binary()} | '$1' |{'_', binary()} | '_', pid = self() :: pid() | '$2' | '_' | '$1'}). 6 | 7 | -record(vcard_version, {user,version,url}). 8 | -------------------------------------------------------------------------------- /qtalk_opensource/inetrc: -------------------------------------------------------------------------------- 1 | {lookup,["file","native"]}. 2 | {host,{127,0,0,1}, ["localhost","hostalias"]}. 3 | {file, resolv, "/etc/resolv.conf"}. 4 | -------------------------------------------------------------------------------- /qtalk_opensource/m4/erlang-extra.m4: -------------------------------------------------------------------------------- 1 | dnl erlang-extra.m4 2 | 3 | AC_DEFUN([ERLANG_SUBST_LIB_VER], 4 | [AC_ERLANG_CHECK_LIB([$1]) 5 | ERLANG_LIB_VER_SUBST="$ERLANG_LIB_VER_SUBST -e 's,[@]ERLANG_LIB_VER_$1[@],\$(ERLANG_LIB_VER_$1),g'" 6 | AC_SUBST([ERLANG_LIB_VER_SUBST]) 7 | ]) # ERLANG_SUBST_LIB_VER 8 | 9 | AC_DEFUN([ERLANG_VERSION_CHECK], 10 | [ AC_MSG_CHECKING([Erlang/OTP version]) 11 | cat > conftest.erl < 16 | ERTS = erlang:system_info(version), 17 | RequiredMin = "$1", 18 | RequiredMax = "$2", 19 | Status = 20 | case {string:tokens(RequiredMin, " "), 21 | string:tokens(RequiredMax, " ")} of 22 | {[[MinStr | _]], [[MaxStr | _]]} -> 23 | case check(ERTS, {MinStr, MaxStr}) of 24 | less -> 25 | list_to_binary([[ERTS, " found, ", RequiredMin, " required"]]); 26 | greater -> 27 | list_to_binary([[ERTS, " found, ", RequiredMax, " or earlier required"]]); 28 | ok -> 29 | <<"ok">> 30 | end; 31 | _ -> 32 | list_to_binary([[ERTS, " found, ", RequiredMin, " required"]]) 33 | end, 34 | file:write_file("conftest.out", Status), 35 | halt(). 36 | 37 | check(CurStr, {MinStr, MaxStr}) -> 38 | Cur = parse(CurStr), 39 | Min = parse(MinStr), 40 | Max = parse(MaxStr), 41 | case {less_or_equal(Min, Cur), less_or_equal(Cur, Max)} of 42 | {false, true} -> less; 43 | {true, true} -> ok; 44 | {true, false} -> greater 45 | end. 46 | 47 | parse(Version) -> 48 | lists:map(fun(A) -> {Int,[[]]} = string:to_integer(A), Int end, 49 | string:tokens(Version, ".")). 50 | 51 | less_or_equal([[]], [[]]) -> 52 | true; 53 | less_or_equal([[]], _Any) -> 54 | true; 55 | less_or_equal(_Any, [[]]) -> 56 | false; 57 | less_or_equal([[Left| Rl]], [[Right| Rr]]) -> 58 | case {Left < Right, Left == Right} of 59 | {true, _} -> 60 | true; 61 | {false, false} -> 62 | false; 63 | {false, true} -> 64 | less_or_equal(Rl, Rr) 65 | end. 66 | 67 | EOF 68 | 69 | $ERLC conftest.erl || AC_MSG_ERROR(["Could not compile Erlang/OTP version check program using '$ERLC'"]) 70 | 71 | if ! $ERL -s conftest -noshell -o ! -f conftest.out ; then 72 | AC_MSG_ERROR(["Could not run Erlang/OTP version check program using '$ERL'"]) 73 | fi 74 | 75 | if test "x`cat conftest.out`" != "xok"; then 76 | AC_MSG_RESULT([failed]) 77 | X="`cat conftest.out`" 78 | if test "[$3]" == "warn"; then 79 | AC_MSG_WARN([$X]) 80 | else 81 | AC_MSG_FAILURE([$X]) 82 | fi 83 | else 84 | AC_MSG_RESULT([ok]) 85 | fi 86 | ]) dnl ERLANG_VERSION_CHECK 87 | -------------------------------------------------------------------------------- /qtalk_opensource/rebar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/may-liu/qtalk/f5431e5a7123975e9656e7ab239e674ce33713cd/qtalk_opensource/rebar -------------------------------------------------------------------------------- /qtalk_opensource/rel/files/erl: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | ## This script replaces the default "erl" in erts-VSN/bin. This is necessary 4 | ## as escript depends on erl and in turn, erl depends on having access to a 5 | ## bootscript (start.boot). Note that this script is ONLY invoked as a side-effect 6 | ## of running escript -- the embedded node bypasses erl and uses erlexec directly 7 | ## (as it should). 8 | ## 9 | ## Note that this script makes the assumption that there is a start_clean.boot 10 | ## file available in $ROOTDIR/release/VSN. 11 | 12 | # Determine the abspath of where this script is executing from. 13 | ERTS_BIN_DIR=$(cd ${0%/*} && pwd) 14 | 15 | # Now determine the root directory -- this script runs from erts-VSN/bin, 16 | # so we simply need to strip off two dirs from the end of the ERTS_BIN_DIR 17 | # path. 18 | ROOTDIR=${ERTS_BIN_DIR%/*/*} 19 | 20 | # Parse out release and erts info 21 | START_ERL=`cat $ROOTDIR/releases/start_erl.data` 22 | ERTS_VSN=${START_ERL% *} 23 | APP_VSN=${START_ERL#* } 24 | 25 | BINDIR=$ROOTDIR/erts-$ERTS_VSN/bin 26 | EMU=beam 27 | PROGNAME=`echo $0 | sed 's/.*\\///'` 28 | CMD="$BINDIR/erlexec" 29 | export EMU 30 | export ROOTDIR 31 | export BINDIR 32 | export PROGNAME 33 | 34 | exec $CMD -boot $ROOTDIR/releases/$APP_VSN/start_clean ${1+"$@"} 35 | -------------------------------------------------------------------------------- /qtalk_opensource/rel/files/install_upgrade.escript: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env escript 2 | %%! -noshell -noinput 3 | %% -*- mode: erlang;erlang-indent-level: 4;indent-tabs-mode: nil -*- 4 | %% ex: ft=erlang ts=4 sw=4 et 5 | 6 | -define(TIMEOUT, 60000). 7 | -define(INFO(Fmt,Args), io:format(Fmt,Args)). 8 | 9 | main([NodeName, Cookie, ReleasePackage]) -> 10 | TargetNode = start_distribution(NodeName, Cookie), 11 | {ok, Vsn} = rpc:call(TargetNode, release_handler, unpack_release, 12 | [ReleasePackage], ?TIMEOUT), 13 | ?INFO("Unpacked Release ~p~n", [Vsn]), 14 | {ok, OtherVsn, Desc} = rpc:call(TargetNode, release_handler, 15 | check_install_release, [Vsn], ?TIMEOUT), 16 | {ok, OtherVsn, Desc} = rpc:call(TargetNode, release_handler, 17 | install_release, [Vsn], ?TIMEOUT), 18 | ?INFO("Installed Release ~p~n", [Vsn]), 19 | ok = rpc:call(TargetNode, release_handler, make_permanent, [Vsn], ?TIMEOUT), 20 | ?INFO("Made Release ~p Permanent~n", [Vsn]); 21 | main(_) -> 22 | init:stop(1). 23 | 24 | start_distribution(NodeName, Cookie) -> 25 | MyNode = make_script_node(NodeName), 26 | {ok, _Pid} = net_kernel:start([MyNode, shortnames]), 27 | erlang:set_cookie(node(), list_to_atom(Cookie)), 28 | TargetNode = make_target_node(NodeName), 29 | case {net_kernel:hidden_connect_node(TargetNode), 30 | net_adm:ping(TargetNode)} of 31 | {true, pong} -> 32 | ok; 33 | {_, pang} -> 34 | io:format("Node ~p not responding to pings.\n", [TargetNode]), 35 | init:stop(1) 36 | end, 37 | TargetNode. 38 | 39 | make_target_node(Node) -> 40 | [_, Host] = string:tokens(atom_to_list(node()), "@"), 41 | list_to_atom(lists:concat([Node, "@", Host])). 42 | 43 | make_script_node(Node) -> 44 | list_to_atom(lists:concat([Node, "_upgrader_", os:getpid()])). 45 | -------------------------------------------------------------------------------- /qtalk_opensource/scripts/.gitignore: -------------------------------------------------------------------------------- 1 | # kdiff3 ignore 2 | *.orig 3 | 4 | # maven ignore 5 | target/ 6 | 7 | # eclipse ignore 8 | .settings/ 9 | .project 10 | .classpath 11 | 12 | # idea ignore 13 | .idea/ 14 | *.ipr 15 | *.iml 16 | *.iws 17 | 18 | # temp ignore 19 | *.log 20 | *.cache 21 | *.diff 22 | *.patch 23 | *.tmp 24 | 25 | # system ignore 26 | .DS_Store 27 | Thumbs.db 28 | 29 | # package ignore (optional) 30 | # *.jar 31 | # *.war 32 | # *.zip 33 | # *.tar 34 | # *.tar.gz -------------------------------------------------------------------------------- /qtalk_opensource/scripts/ejb_http_server/bin/ejb_http_server: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | #eja_sname="ejb_http_server" 4 | #eja_id="ejb_http_server" 5 | #eja_conf="" 6 | #eja_erlang_opt="-config config/lager -config config/ejb_http_server" 7 | #TODO 8 | LOCAL_NODE=`hostname`; 9 | ERL=erl 10 | NAME=-name 11 | NODE=ejb_http_server@$LOCAL_NODE 12 | ERL_OPTS="" 13 | EBIN_PATH="-pa ../ebin -pa ../deps/*/ebin" 14 | TEST_NODE=test@$LOCAL_NODE 15 | 16 | restart() 17 | { 18 | if is_running; then 19 | echo "ejb_http_server is restarting..." 20 | stop 21 | start 22 | else 23 | echo "ejb_http_server is stopped" 24 | exit 1 25 | fi 26 | } 27 | 28 | start() 29 | { 30 | if is_running; then 31 | echo "ejb_http_server is already started" 32 | exit 1 33 | else 34 | echo "ejb_http_server is starting..." 35 | #yaws --sname "${eja_sname}" --id "${eja_id}" --heart --daemon --conf "${eja_conf}" --erlarg "${eja_erlang_opt}" 36 | sudo $ERL $NAME $NODE -detached $EBIN_PATH -s ejb_http_server -smp enable -hidden -config ../config/lager -config ../config/ejb_http_server 37 | fi 38 | 39 | sleep 3 40 | 41 | if is_running; then 42 | echo "ejahttp start successfully" 43 | else 44 | echo "ejahttp start failed" 45 | fi 46 | } 47 | 48 | debug() 49 | { 50 | if is_running; then 51 | sudo $ERL $NAME TEST_NODE -remsh $NODE 52 | else 53 | echo "ejb_http_server is stop" 54 | exit 1 55 | fi 56 | } 57 | 58 | stop() 59 | { 60 | if is_running; then 61 | PID=`ps auxww |grep -w beam |grep "name $NODE" |awk '{print $2}'` 62 | if [ -n $PID ]; then 63 | kill -9 $PID 64 | fi 65 | echo "ejahttp is stopping..." 66 | else 67 | echo "ejahttp is stopped" 68 | exit 1; 69 | fi 70 | 71 | sleep 2 72 | 73 | if is_running; then 74 | echo "ejahttp stop failed" 75 | else 76 | echo "ejahttp stop successfully" 77 | fi 78 | } 79 | 80 | status() 81 | { 82 | if is_running; then 83 | yaws_status 84 | else 85 | echo "ejahttp is stopped" 86 | fi 87 | } 88 | 89 | is_running() 90 | { 91 | PID=`ps auxww |grep -w beam |grep "name $NODE" |awk '{print $2}'` 92 | if [ -z "$PID" ]; then 93 | return 1 94 | else 95 | return 0 96 | fi 97 | } 98 | 99 | help() 100 | { 101 | echo "Usage: $0 {start|restart|stop|status}" 102 | } 103 | 104 | case $1 in 105 | 'start') 106 | start 107 | ;; 108 | 'stop') 109 | stop 110 | ;; 111 | 'restart') 112 | stop && start 113 | ;; 114 | 'debug') 115 | debug 116 | ;; 117 | 'status') 118 | status 119 | ;; 120 | 'help') 121 | help 122 | ;; 123 | *) 124 | help 125 | exit 1 126 | esac 127 | -------------------------------------------------------------------------------- /qtalk_opensource/scripts/ejb_http_server/config/lager.config: -------------------------------------------------------------------------------- 1 | [{lager, [ 2 | {log_root, "./log"}, 3 | {handlers, [ 4 | {lager_console_backend, debug}, 5 | {lager_file_backend, [{file, "error.log"}, {level, error},{size, 1048576000}, {date, "$D0"}, {count, 60}]}, 6 | {lager_file_backend, [{file, "console.log"}, {level, debug},{size, 1048576000}, {date, "$D0"}, {count, 60}]}]}]} 7 | ]. 8 | -------------------------------------------------------------------------------- /qtalk_opensource/scripts/ejb_http_server/deps/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/may-liu/qtalk/f5431e5a7123975e9656e7ab239e674ce33713cd/qtalk_opensource/scripts/ejb_http_server/deps/.keep -------------------------------------------------------------------------------- /qtalk_opensource/scripts/ejb_http_server/doc/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/may-liu/qtalk/f5431e5a7123975e9656e7ab239e674ce33713cd/qtalk_opensource/scripts/ejb_http_server/doc/.keep -------------------------------------------------------------------------------- /qtalk_opensource/scripts/ejb_http_server/ebin/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/may-liu/qtalk/f5431e5a7123975e9656e7ab239e674ce33713cd/qtalk_opensource/scripts/ejb_http_server/ebin/.keep -------------------------------------------------------------------------------- /qtalk_opensource/scripts/ejb_http_server/include/ejb_http_server.hrl: -------------------------------------------------------------------------------- 1 | -record(user_status, {user ,status}). 2 | -record(online_status, {user ,status}). 3 | -record(cache_info, {name ,cache}). 4 | -record(vcard_version, {user,version,name,url,gender = <<"0">>}). 5 | -record(user_profile, {user,version,mood}). 6 | -record(muc_vcard, {muc_name,show_name,muc_desc,muc_title,muc_pic,version}). 7 | -record(rbt_info, {name,url,body,version}). 8 | -record(user_rbts, {user,rbt}). 9 | -record(iplimit, {ip,user}). 10 | -record(ejabberd_config, {key,val}). 11 | -record(domain_to_url, {domain,url}). 12 | -record(user_version,{user,name,version,hire_flag,fp,sp,type,dept}). 13 | 14 | 15 | -------------------------------------------------------------------------------- /qtalk_opensource/scripts/ejb_http_server/include/http_req.hrl: -------------------------------------------------------------------------------- 1 | -record(http_req, { 2 | %% Transport. 3 | socket = undefined :: any(), 4 | transport = undefined :: undefined | module(), 5 | connection = keepalive :: keepalive | close, 6 | 7 | %% Request. 8 | pid = undefined :: pid(), 9 | method = <<"GET">> :: binary(), 10 | version = 'HTTP/1.1' :: cowboy:http_version(), 11 | peer = undefined :: undefined | {inet:ip_address(), inet:port_number()}, 12 | host = undefined :: undefined | binary(), 13 | host_info = undefined :: undefined | cowboy_router:tokens(), 14 | port = undefined :: undefined | inet:port_number(), 15 | path = undefined :: binary(), 16 | path_info = undefined :: undefined | cowboy_router:tokens(), 17 | qs = undefined :: binary(), 18 | qs_vals = undefined :: undefined | list({binary(), binary() | true}), 19 | bindings = undefined :: undefined | cowboy_router:bindings(), 20 | headers = [] :: cowboy:http_headers(), 21 | p_headers = [] :: [any()], 22 | cookies = undefined :: undefined | [{binary(), binary()}], 23 | meta = [] :: [{atom(), any()}], 24 | 25 | %% Request body. 26 | body_state, 27 | buffer = <<>> :: binary(), 28 | multipart = undefined :: undefined | {binary(), binary()}, 29 | 30 | %% Response. 31 | resp_compress = false :: boolean(), 32 | resp_state = waiting :: locked | waiting | waiting_stream 33 | | chunks | stream | done, 34 | resp_headers = [] :: cowboy:http_headers(), 35 | resp_body, 36 | 37 | %% Functions. 38 | onresponse = undefined :: undefined | already_called 39 | | cowboy:onresponse_fun() 40 | }). 41 | -------------------------------------------------------------------------------- /qtalk_opensource/scripts/ejb_http_server/include/logger.hrl: -------------------------------------------------------------------------------- 1 | -define(DEBUG(Format, Args), 2 | lager:debug(Format, Args)). 3 | 4 | -define(INFO_MSG(Format, Args), 5 | lager:info(Format, Args)). 6 | 7 | -define(WARNING_MSG(Format, Args), 8 | lager:warning(Format, Args)). 9 | 10 | -define(ERROR(Format, Args), 11 | lager:error(Format, Args)). 12 | 13 | -define(CRITICAL_MSG(Format, Args), 14 | lager:critical(Format, Args)). 15 | -------------------------------------------------------------------------------- /qtalk_opensource/scripts/ejb_http_server/priv/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/may-liu/qtalk/f5431e5a7123975e9656e7ab239e674ce33713cd/qtalk_opensource/scripts/ejb_http_server/priv/.keep -------------------------------------------------------------------------------- /qtalk_opensource/scripts/ejb_http_server/rebar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/may-liu/qtalk/f5431e5a7123975e9656e7ab239e674ce33713cd/qtalk_opensource/scripts/ejb_http_server/rebar -------------------------------------------------------------------------------- /qtalk_opensource/scripts/ejb_http_server/rebar.config: -------------------------------------------------------------------------------- 1 | % -*- mode: erlang -*- 2 | 3 | {erl_opts,[{parse_transform,lager_transform}]}. 4 | {lib_dirs, ["deps"]}. 5 | {deps, [ 6 | {lager, ".*", {git, "https://github.com/basho/lager.git", {branch, "master"}}}, 7 | {eredis,".*",{git,"https://github.com/mkurkov/eredis.git",{branch, "sentinel"}}}, 8 | {p1_pgsql, ".*", {git, "https://github.com/processone/pgsql.git", {branch, "master"}}}, 9 | {cowboy, "1.0.1", {git, "https://github.com/ninenines/cowboy.git", "1.0.1"}}, 10 | {rfc4627_jsonrpc, ".*", {git, "https://github.com/tonyg/erlang-rfc4627"}}, 11 | {recon, ".*", {git, "https://github.com/ferd/recon.git", {branch, "master"}}}, 12 | {p1_xml, ".*", {git, "git://github.com/processone/xml"}} 13 | ]}. 14 | 15 | -------------------------------------------------------------------------------- /qtalk_opensource/scripts/ejb_http_server/src/ejb_http_server.app.src: -------------------------------------------------------------------------------- 1 | % -*- mode: erlang -*- 2 | {application, ejb_http_server, 3 | [ 4 | {description, ""}, 5 | {vsn, "1"}, 6 | {registered, [ejb_http_server]}, 7 | {applications, [ 8 | kernel, 9 | stdlib 10 | ]}, 11 | {mod, {ejb_http_server_app,[]}}, 12 | {env, []}]}. 13 | -------------------------------------------------------------------------------- /qtalk_opensource/scripts/ejb_http_server/src/ejb_http_server.erl: -------------------------------------------------------------------------------- 1 | -module(ejb_http_server). 2 | 3 | -include("logger.hrl"). 4 | 5 | -export([start/0]). 6 | 7 | start() -> 8 | lager:start(), 9 | application:start(inets), 10 | application:start(crypto), 11 | application:start(cowlib), 12 | application:start(ranch), 13 | application:start(cowboy), 14 | application:start(p1_xml), 15 | application:start(ejb_http_server), 16 | gen_server:cast(whereis(ejb_server),start_cowboy), 17 | ok. 18 | -------------------------------------------------------------------------------- /qtalk_opensource/scripts/ejb_http_server/src/ejb_http_server_app.erl: -------------------------------------------------------------------------------- 1 | -module(ejb_http_server_app). 2 | 3 | -behaviour(application). 4 | 5 | -include("ejb_http_server.hrl"). 6 | %% Application callbacks 7 | -export([start/2, stop/1]). 8 | 9 | %% =================================================================== 10 | %% Application callbacks 11 | %% =================================================================== 12 | 13 | start(_StartType, _StartArgs) -> 14 | ejb_http_server_sup:start_link(). 15 | 16 | stop(_State) -> 17 | ok. 18 | 19 | -------------------------------------------------------------------------------- /qtalk_opensource/scripts/ejb_http_server/src/ejb_http_server_config.erl: -------------------------------------------------------------------------------- 1 | -module(ejb_http_server_config). 2 | 3 | -export([reload_conf/2]). 4 | 5 | %%-------------------------------------------------------------------- 6 | %% @date 2015-09 7 | %% 重新读取配置文件 8 | %%-------------------------------------------------------------------- 9 | 10 | reload_conf(File, App) -> 11 | {ok, [Config]} = file:consult(File), 12 | lists:foldl(fun({A, C}, Acc) when A =:= App -> 13 | R = set_env(App, C), 14 | [{A, R}|Acc]; 15 | (_, Acc) -> 16 | Acc 17 | end, [], Config). 18 | 19 | %%-------------------------------------------------------------------- 20 | %% @date 2015-09 21 | %% 设置环境参数 22 | %%-------------------------------------------------------------------- 23 | set_env(App, C) -> 24 | lists:foldl(fun({K, V}, Acc) -> 25 | application:set_env(App, K, V), 26 | [K|Acc] 27 | end, [], C). 28 | -------------------------------------------------------------------------------- /qtalk_opensource/scripts/ejb_http_server/src/ejb_http_server_env.erl: -------------------------------------------------------------------------------- 1 | -module(ejb_http_server_env). 2 | 3 | -include("ejb_http_server.hrl"). 4 | 5 | -export([get_env/1, get_env/2, get_env/3, get_env/4]). 6 | 7 | -define(DEFAULT_APP, ejb_http_server). 8 | 9 | get_env(Key) -> 10 | get_env(Key, undefined). 11 | 12 | get_env(Key, Default) -> 13 | get_env(?DEFAULT_APP, Key, Default). 14 | 15 | get_env(App, Key, Default) -> 16 | get_env(App, Key, fun(X) -> 17 | X 18 | end, 19 | Default). 20 | 21 | get_env(App, Key, Fun, Default) -> 22 | case application:get_env(App, Key) of 23 | {ok, Value} -> 24 | Fun(Value); 25 | undefined -> 26 | Default 27 | end. 28 | -------------------------------------------------------------------------------- /qtalk_opensource/scripts/ejb_http_server/src/ejb_http_server_sys_stat.erl: -------------------------------------------------------------------------------- 1 | -module(ejb_http_server_sys_stat). 2 | 3 | -include("logger.hrl"). 4 | 5 | -export([ 6 | port_stat/0, 7 | msg_queue_stat/0, 8 | memory_stat/0 9 | ]). 10 | 11 | -define(MB, (1024 * 1024)). 12 | 13 | port_stat() -> 14 | UdpNum = length(recon:udp()), 15 | TcpNum = length(recon:tcp()), 16 | SctpNum = length(recon:sctp()), 17 | FileNum = length(recon:files()), 18 | PortNum = erlang:system_info(port_count), 19 | ProcessNum = erlang:system_info(process_count), 20 | 21 | [{<<"udp_num">>, UdpNum}, {<<"tcp_num">>, TcpNum}, {<<"sctp_num">>, SctpNum}, {<<"file_num">>, FileNum}, {<<"port_num">>, PortNum}, {<<"process_count">>, ProcessNum}]. 22 | 23 | msg_queue_stat() -> 24 | [{Pid, MsgNum, Attr}] = recon:proc_count(message_queue_len, 1), 25 | 26 | ?DEBUG("the process(~p) message_queue num is ~p, and the attr is ~p~n", [Pid, MsgNum, Attr]), 27 | [{<<"max_msg_queue">>, MsgNum}]. 28 | 29 | memory_stat() -> 30 | UsedNum = recon_alloc:memory(used) / ?MB, 31 | AllocatedNum = recon_alloc:memory(allocated) / ?MB, 32 | 33 | [{<<"memory_used">>, UsedNum}, {<<"memory_allocated">>, AllocatedNum}]. 34 | -------------------------------------------------------------------------------- /qtalk_opensource/scripts/ejb_http_server/src/http_add_muc_user.erl: -------------------------------------------------------------------------------- 1 | %% Feel free to use, reuse and abuse the code in this file. 2 | 3 | -module(http_add_muc_user). 4 | 5 | -export([init/3]). 6 | -export([handle/2]). 7 | -export([terminate/3]). 8 | 9 | -include("logger.hrl"). 10 | -include("http_req.hrl"). 11 | -include("ejb_http_server.hrl"). 12 | 13 | init(_Transport, Req, []) -> 14 | {ok, Req, undefined}. 15 | 16 | handle(Req, State) -> 17 | {Method, _} = cowboy_req:method(Req), 18 | case Method of 19 | <<"GET">> -> 20 | {Host,_} = cowboy_req:host(Req), 21 | {ok, Req1} = get_echo(Method,Host,Req), 22 | {ok, Req1, State}; 23 | <<"POST">> -> 24 | HasBody = cowboy_req:has_body(Req), 25 | {ok, Req1} = post_echo(Method, HasBody, Req), 26 | {ok, Req1, State}; 27 | _ -> 28 | {ok,Req1} = echo(undefined, Req), 29 | {ok, Req1, State} 30 | end. 31 | 32 | get_echo(<<"GET">>,_,Req) -> 33 | cowboy_req:reply(200, [ 34 | {<<"content-type">>, <<"text/json; charset=utf-8">>} 35 | ], <<"No GET method">>, Req). 36 | 37 | post_echo(<<"POST">>, true, Req) -> 38 | {ok, Body, _} = cowboy_req:body(Req), 39 | Ret = 40 | case iplimit_util:check_muc_ip_limit(Req,Body) of 41 | true -> 42 | http_create_muc(Body); 43 | _ -> 44 | http_utils:gen_result(false, <<"3">>, <<"">>,<<"ip is limited">>) 45 | end, 46 | cowboy_req:reply(200, [ {<<"content-type">>, <<"text/json; charset=utf-8">>}], Ret, Req); 47 | post_echo(<<"POST">>, false, Req) -> 48 | cowboy_req:reply(400, [], <<"Missing Post body.">>, Req); 49 | post_echo(_, _, Req) -> 50 | cowboy_req:reply(405, Req). 51 | 52 | 53 | echo(undefined, Req) -> 54 | cowboy_req:reply(400, [], <<"Missing parameter.">>, Req); 55 | echo(Echo, Req) -> 56 | cowboy_req:reply(200, [ 57 | {<<"content-type">>, <<"text/json; charset=utf-8">>} 58 | ], Echo, Req). 59 | 60 | terminate(_Reason, _Req, _State) -> 61 | ok. 62 | 63 | http_create_muc(Body) -> 64 | Url1 = 65 | case catch ets:lookup(ejabberd_config,<<"http_server">>) of 66 | [Http_server] when is_record(Http_server,ejabberd_config) -> 67 | Http_server#ejabberd_config.val; 68 | _ -> 69 | "http://127.0.0.1:10050/" 70 | end, 71 | Url = Url1 ++ "add_muc_user", 72 | Header = [], 73 | Type = "application/json", 74 | HTTPOptions = [], 75 | Options = [], 76 | case http_client:http_post(Url,Header,Type,Body,HTTPOptions,Options) of 77 | {ok, {_Status,_Headers, Rslt}} -> 78 | Rslt; 79 | _ -> 80 | http_utils:gen_result(false, <<"1">>, <<"">>,<<"create_muc failed">>) 81 | end. 82 | -------------------------------------------------------------------------------- /qtalk_opensource/scripts/ejb_http_server/src/http_check_user_status.erl: -------------------------------------------------------------------------------- 1 | %% Feel free to use, reuse and abuse the code in this file. 2 | 3 | -module(http_check_user_status). 4 | 5 | -export([init/3]). 6 | -export([handle/2]). 7 | -export([terminate/3]). 8 | 9 | -include("logger.hrl"). 10 | -include("http_req.hrl"). 11 | -include("ejb_http_server.hrl"). 12 | 13 | init(_Transport, Req, []) -> 14 | {ok, Req, undefined}. 15 | 16 | handle(Req, State) -> 17 | catch ejb_monitor:monitor_count(<<"http_check_user_status_domain">>,1), 18 | handle(Req, State, true). 19 | 20 | handle(Req, State, false) -> 21 | Req_Res = Req#http_req{resp_compress = true}, 22 | Res = http_utils:gen_result(false, <<"3">>, <<"ip is limited">>), 23 | {ok, NewReq} = cowboy_req:reply(200, [ 24 | {<<"content-type">>, <<"text/plain; charset=utf-8">>} 25 | ], Res, Req_Res), 26 | {ok, NewReq, State}; 27 | handle(Req, State, _) -> 28 | {Method, _} = cowboy_req:method(Req), 29 | case Method of 30 | <<"GET">> -> 31 | {Host,_} = cowboy_req:host(Req), 32 | {ok, Req1} = get_echo(Method,Host,Req), 33 | {ok, Req1, State}; 34 | <<"POST">> -> 35 | HasBody = cowboy_req:has_body(Req), 36 | {ok, Req1} = post_echo(Method, HasBody, Req), 37 | {ok, Req1, State}; 38 | _ -> 39 | {ok,Req1} = echo(undefined, Req), 40 | {ok, Req1, State} 41 | end. 42 | 43 | get_echo(<<"GET">>,_,Req) -> 44 | cowboy_req:reply(200, [ 45 | {<<"content-type">>, <<"text/json; charset=utf-8">>} 46 | ], <<"No GET method">>, Req). 47 | 48 | post_echo(<<"POST">>, true, Req) -> 49 | {ok, Body, _} = cowboy_req:body(Req), 50 | Url1 = 51 | case catch ets:lookup(ejabberd_config,<<"http_server">>) of 52 | [Http_server] when is_record(Http_server,ejabberd_config) -> 53 | Http_server#ejabberd_config.val; 54 | _ -> 55 | "http://127.0.0.1/" 56 | end, 57 | Url = Url1 ++ "get_user_status", 58 | Header = [], 59 | Type = "application/json", 60 | HTTPOptions = [], 61 | Options = [], 62 | Ret = 63 | case http_client:http_post(Url,Header,Type,Body,HTTPOptions,Options) of 64 | {ok, {_Status,_Headers, Rslt}} -> 65 | Rslt; 66 | _ -> 67 | rfc4627:encode({obj,[{"data",<<"Send Message Error">>}]}) 68 | end, 69 | cowboy_req:reply(200, [ {<<"content-type">>, <<"text/json; charset=utf-8">>}], Ret, Req); 70 | post_echo(<<"POST">>, false, Req) -> 71 | cowboy_req:reply(400, [], <<"Missing Post body.">>, Req); 72 | post_echo(_, _, Req) -> 73 | cowboy_req:reply(405, Req). 74 | 75 | echo(undefined, Req) -> 76 | cowboy_req:reply(400, [], <<"Missing parameter.">>, Req); 77 | echo(Echo, Req) -> 78 | cowboy_req:reply(200, [ 79 | {<<"content-type">>, <<"text/json; charset=utf-8">>} 80 | ], Echo, Req). 81 | 82 | terminate(_Reason, _Req, _State) -> 83 | ok. 84 | 85 | -------------------------------------------------------------------------------- /qtalk_opensource/scripts/ejb_http_server/src/http_client_sup.erl: -------------------------------------------------------------------------------- 1 | -module(http_client_sup). 2 | 3 | %% Callback Functions 4 | -export([init/1]). 5 | 6 | %% API 7 | -export([start_link/1, 8 | add_pid/1, 9 | remove_pid/1, 10 | get_pids/0, 11 | get_random_pid/0]). 12 | 13 | -define(SERVER, ?MODULE). 14 | -define(DEFAULT_POOL_SIZE, 10). 15 | 16 | start_link(Opts) -> 17 | ets:new(http_client_pid, [named_table, bag, public]), 18 | supervisor:start_link({local, ?SERVER}, ?MODULE, [Opts]). 19 | 20 | init([Opts]) -> 21 | PoolSize = proplists:get_value(poolsize, Opts, ?DEFAULT_POOL_SIZE), 22 | {ok, 23 | {{one_for_one, PoolSize * 10, 1}, 24 | lists:map(fun (I) -> 25 | {I, 26 | {http_client, start_link, 27 | [[{<<"seq">>,I}|Opts]]}, 28 | transient, 2000, worker, [http_client]} 29 | end, 30 | lists:seq(1, PoolSize))}}. 31 | 32 | get_pids() -> 33 | case ets:tab2list(http_client_pid) of 34 | [] -> 35 | []; 36 | Rs when is_list(Rs) -> 37 | lists:map(fun({Pid}) -> 38 | Pid 39 | end,Rs); 40 | _ -> 41 | [] 42 | end. 43 | 44 | get_random_pid() -> 45 | case get_pids() of 46 | [] -> undefined; 47 | Pids -> lists:nth(erlang:phash(os:timestamp(), length(Pids)), Pids) 48 | end. 49 | 50 | add_pid(Pid) -> 51 | ets:insert(http_client_pid, {Pid}). 52 | 53 | remove_pid(Pid) -> 54 | ets:delete_object(http_client_pid, {Pid}). 55 | -------------------------------------------------------------------------------- /qtalk_opensource/scripts/ejb_http_server/src/http_del_muc_user.erl: -------------------------------------------------------------------------------- 1 | %% Feel free to use, reuse and abuse the code in this file. 2 | 3 | -module(http_del_muc_user). 4 | 5 | -export([init/3]). 6 | -export([handle/2]). 7 | -export([terminate/3]). 8 | 9 | -include("logger.hrl"). 10 | -include("http_req.hrl"). 11 | -include("ejb_http_server.hrl"). 12 | 13 | init(_Transport, Req, []) -> 14 | {ok, Req, undefined}. 15 | 16 | handle(Req, State) -> 17 | {Method, _} = cowboy_req:method(Req), 18 | case Method of 19 | <<"GET">> -> 20 | {Host,_} = cowboy_req:host(Req), 21 | {ok, Req1} = get_echo(Method,Host,Req), 22 | {ok, Req1, State}; 23 | <<"POST">> -> 24 | HasBody = cowboy_req:has_body(Req), 25 | {ok, Req1} = post_echo(Method, HasBody, Req), 26 | {ok, Req1, State}; 27 | _ -> 28 | {ok,Req1} = echo(undefined, Req), 29 | {ok, Req1, State} 30 | end. 31 | 32 | get_echo(<<"GET">>,_,Req) -> 33 | cowboy_req:reply(200, [ 34 | {<<"content-type">>, <<"text/json; charset=utf-8">>} 35 | ], <<"No GET method">>, Req). 36 | 37 | post_echo(<<"POST">>, true, Req) -> 38 | {ok, Body, _} = cowboy_req:body(Req), 39 | Ret = 40 | case iplimit_util:check_muc_ip_limit(Req,Body) of 41 | true -> 42 | http_create_muc(Body); 43 | _ -> 44 | http_utils:gen_result(false, <<"3">>, <<"">>,<<"ip is limited">>) 45 | end, 46 | cowboy_req:reply(200, [ {<<"content-type">>, <<"text/json; charset=utf-8">>}], Ret, Req); 47 | post_echo(<<"POST">>, false, Req) -> 48 | cowboy_req:reply(400, [], <<"Missing Post body.">>, Req); 49 | post_echo(_, _, Req) -> 50 | cowboy_req:reply(405, Req). 51 | 52 | 53 | echo(undefined, Req) -> 54 | cowboy_req:reply(400, [], <<"Missing parameter.">>, Req); 55 | echo(Echo, Req) -> 56 | cowboy_req:reply(200, [ 57 | {<<"content-type">>, <<"text/json; charset=utf-8">>} 58 | ], Echo, Req). 59 | 60 | terminate(_Reason, _Req, _State) -> 61 | ok. 62 | 63 | http_create_muc(Body) -> 64 | Url1 = 65 | case catch ets:lookup(ejabberd_config,<<"http_server">>) of 66 | [Http_server] when is_record(Http_server,ejabberd_config) -> 67 | Http_server#ejabberd_config.val; 68 | _ -> 69 | "http://127.0.0.1:10050/" 70 | end, 71 | Url = Url1 ++ "del_muc_user", 72 | Header = [], 73 | Type = "application/json", 74 | HTTPOptions = [], 75 | Options = [], 76 | case http_client:http_post(Url,Header,Type,Body,HTTPOptions,Options) of 77 | {ok, {_Status,_Headers, Rslt}} -> 78 | Rslt; 79 | _ -> 80 | http_utils:gen_result(false, <<"1">>, <<"">>,<<"create_muc failed">>) 81 | end. 82 | -------------------------------------------------------------------------------- /qtalk_opensource/scripts/ejb_http_server/src/http_destory_muc.erl: -------------------------------------------------------------------------------- 1 | %% Feel free to use, reuse and abuse the code in this file. 2 | 3 | -module(http_destory_muc). 4 | 5 | -export([init/3]). 6 | -export([handle/2]). 7 | -export([terminate/3]). 8 | 9 | -include("logger.hrl"). 10 | -include("http_req.hrl"). 11 | -include("ejb_http_server.hrl"). 12 | 13 | init(_Transport, Req, []) -> 14 | {ok, Req, undefined}. 15 | 16 | handle(Req, State) -> 17 | {Method, _} = cowboy_req:method(Req), 18 | case Method of 19 | <<"GET">> -> 20 | {Host,_} = cowboy_req:host(Req), 21 | {ok, Req1} = get_echo(Method,Host,Req), 22 | {ok, Req1, State}; 23 | <<"POST">> -> 24 | HasBody = cowboy_req:has_body(Req), 25 | {ok, Req1} = post_echo(Method, HasBody, Req), 26 | {ok, Req1, State}; 27 | _ -> 28 | {ok,Req1} = echo(undefined, Req), 29 | {ok, Req1, State} 30 | end. 31 | 32 | get_echo(<<"GET">>,_,Req) -> 33 | cowboy_req:reply(200, [ 34 | {<<"content-type">>, <<"text/json; charset=utf-8">>} 35 | ], <<"No GET method">>, Req). 36 | 37 | post_echo(<<"POST">>, true, Req) -> 38 | {ok, Body, _} = cowboy_req:body(Req), 39 | Ret = 40 | case iplimit_util:check_muc_ip_limit(Req,Body) of 41 | true -> 42 | http_create_muc(Body); 43 | _ -> 44 | http_utils:gen_result(false, <<"3">>, <<"">>,<<"ip is limited">>) 45 | end, 46 | cowboy_req:reply(200, [ {<<"content-type">>, <<"text/json; charset=utf-8">>}], Ret, Req); 47 | post_echo(<<"POST">>, false, Req) -> 48 | cowboy_req:reply(400, [], <<"Missing Post body.">>, Req); 49 | post_echo(_, _, Req) -> 50 | cowboy_req:reply(405, Req). 51 | 52 | 53 | echo(undefined, Req) -> 54 | cowboy_req:reply(400, [], <<"Missing parameter.">>, Req); 55 | echo(Echo, Req) -> 56 | cowboy_req:reply(200, [ 57 | {<<"content-type">>, <<"text/json; charset=utf-8">>} 58 | ], Echo, Req). 59 | 60 | terminate(_Reason, _Req, _State) -> 61 | ok. 62 | 63 | http_create_muc(Body) -> 64 | Url1 = 65 | case catch ets:lookup(ejabberd_config,<<"http_server">>) of 66 | [Http_server] when is_record(Http_server,ejabberd_config) -> 67 | Http_server#ejabberd_config.val; 68 | _ -> 69 | "http://127.0.0.1:10050/" 70 | end, 71 | Url = Url1 ++ "destroy_muc", 72 | Header = [], 73 | Type = "application/json", 74 | HTTPOptions = [], 75 | Options = [], 76 | case http_client:http_post(Url,Header,Type,Body,HTTPOptions,Options) of 77 | {ok, {_Status,_Headers, Rslt}} -> 78 | Rslt; 79 | _ -> 80 | http_utils:gen_result(false, <<"1">>, <<"">>,<<"create_muc failed">>) 81 | end. 82 | -------------------------------------------------------------------------------- /qtalk_opensource/scripts/ejb_http_server/src/http_get_dump_url.erl: -------------------------------------------------------------------------------- 1 | %% Feel free to use, reuse and abuse the code in this file. 2 | -module(http_get_dump_url). 3 | 4 | -export([init/3]). 5 | -export([handle/2]). 6 | -export([terminate/3]). 7 | 8 | -include("logger.hrl"). 9 | -include("ejb_http_server.hrl"). 10 | 11 | init(_Transport, Req, []) -> 12 | {ok, Req, undefined}. 13 | 14 | handle(Req, State) -> 15 | {Method, _ } = cowboy_req:method(Req), 16 | catch ejb_monitor:monitor_count(<<"http_get_dump_url">>,1), 17 | case Method of 18 | <<"GET">> -> 19 | {Host,_} = cowboy_req:host(Req), 20 | {ok, Req1} = get_echo(Method,Host,Req), 21 | {ok, Req1, State}; 22 | <<"POST">> -> 23 | HasBody = cowboy_req:has_body(Req), 24 | {ok, Req2} = post_echo(Method, HasBody, Req), 25 | {ok, Req2, State}; 26 | _ -> 27 | {ok,Req3} = echo(undefined, Req), 28 | {ok, Req3, State} 29 | end. 30 | 31 | get_echo(<<"GET">>,_,Req) -> 32 | cowboy_req:reply(200, [ 33 | {<<"content-type">>, <<"text/plain; charset=utf-8">>} 34 | ], <<"No GET method">>, Req). 35 | 36 | post_echo(<<"POST">>, true, Req) -> 37 | {ok, Body, _} = cowboy_req:body(Req), 38 | case rfc4627:decode(Body) of 39 | {ok,{obj,Args},[]} -> 40 | Rslt = get_dump_url(Args), 41 | cowboy_req:reply(200, [{<<"content-type">>, <<"text/json; charset=utf-8">>}], Rslt, Req); 42 | _ -> 43 | Rslt = <<"Body parse error">>, 44 | cowboy_req:reply(200,[{<<"content-type">>, <<"text/json; charset=utf-8">>}],Rslt, Req) 45 | end; 46 | post_echo(<<"POST">>, false, Req) -> 47 | cowboy_req:reply(400, [], <<"Missing Post body.">>, Req); 48 | post_echo(_, _, Req) -> 49 | cowboy_req:reply(405, Req). 50 | 51 | echo(undefined, Req) -> 52 | cowboy_req:reply(400, [], <<"Missing parameter.">>, Req); 53 | echo(Echo, Req) -> 54 | cowboy_req:reply(200, [ 55 | {<<"content-type">>, <<"text/plain; charset=utf-8">>} 56 | ], Echo, Req). 57 | 58 | terminate(_Reason, _Req, _State) -> 59 | ok. 60 | 61 | get_dump_url(Args) -> 62 | Start_time = integer_to_binary(proplists:get_value("start_time",Args)+3600*8), 63 | End_time = integer_to_binary(proplists:get_value("end_time",Args)+3600*8), 64 | Ret = 65 | case catch pg_odbc:sql_query(<<"ejb_http_server">>, 66 | [<<"select user_name,dump_url from win_dump_url where extract(epoch from date_trunc('second', dump_time)) > ">>, 67 | Start_time,<<" and extract(epoch from date_trunc('second', dump_time)) < ">>,End_time ,<<";">>]) of 68 | {selected,_,Res} when is_list(Res) -> 69 | lists:flatmap(fun([User,Url]) -> 70 | [{obj,[{"user",User},{"dump_url",Url}]}] end,Res); 71 | A -> 72 | ?DEBUG("A ~p ~n",[A]), 73 | [] 74 | end, 75 | ?DEBUG("Ret ~p ~n",[Ret]), 76 | http_utils:gen_result(true, 0, <<"">>,Ret). 77 | 78 | -------------------------------------------------------------------------------- /qtalk_opensource/scripts/ejb_http_server/src/http_get_increment_mucs.erl: -------------------------------------------------------------------------------- 1 | %% Feel free to use, reuse and abuse the code in this file. 2 | 3 | -module(http_get_increment_mucs). 4 | 5 | -export([init/3]). 6 | -export([handle/2]). 7 | -export([terminate/3]). 8 | 9 | -include("logger.hrl"). 10 | -include("ejb_http_server.hrl"). 11 | 12 | init(_Transport, Req, []) -> 13 | {ok, Req, undefined}. 14 | 15 | handle(Req, State) -> 16 | {Method, _} = cowboy_req:method(Req), 17 | case Method of 18 | <<"GET">> -> 19 | {Host,_} = cowboy_req:host(Req), 20 | {ok, Req2} = get_echo(Method,Host,Req), 21 | {ok, Req2, State}; 22 | <<"POST">> -> 23 | HasBody = cowboy_req:has_body(Req), 24 | {ok, Req2} = post_echo(Method, HasBody, Req), 25 | {ok, Req2, State}; 26 | _ -> 27 | {ok,Req2} = echo(undefined, Req), 28 | {ok, Req2, State} 29 | end. 30 | 31 | get_echo(<<"GET">>,_,Req) -> 32 | cowboy_req:reply(200, [ 33 | {<<"content-type">>, <<"text/plain; charset=utf-8">>} 34 | ], <<"No GET method">>, Req). 35 | 36 | post_echo(<<"POST">>, true, Req) -> 37 | {ok, Body, _} = cowboy_req:body(Req), 38 | case rfc4627:decode(Body) of 39 | {ok,{obj,Json},[]} -> 40 | Rslt = 41 | % case http_utils:verify_user_key_pv1(Req) of 42 | case true of 43 | true -> 44 | {User,_} = cowboy_req:qs_val(<<"u">>, Req), 45 | Ret = get_increment_mucs(User,Json), 46 | http_utils:gen_result(true, 0, <<"">>,Ret); 47 | _ -> 48 | http_utils:gen_result(false, 1, <<"Tkey check error">>,<<"">>) 49 | end, 50 | cowboy_req:reply(200, [{<<"content-type">>, <<"text/json; charset=utf-8">>}], Rslt, Req); 51 | _ -> 52 | Rslt = <<"Body parse error">>, 53 | cowboy_req:reply(200,[{<<"content-type">>, <<"text/json; charset=utf-8">>}], http_utils:gen_result(false, 2, <<"">>,Rslt), Req) 54 | end; 55 | post_echo(<<"POST">>, false, Req) -> 56 | cowboy_req:reply(400, [], <<"Missing Post body.">>, Req); 57 | post_echo(_, _, Req) -> 58 | cowboy_req:reply(405, Req). 59 | 60 | 61 | echo(undefined, Req) -> 62 | cowboy_req:reply(400, [], <<"Missing parameter.">>, Req); 63 | echo(Echo, Req) -> 64 | cowboy_req:reply(200, [ 65 | {<<"content-type">>, <<"text/plain; charset=utf-8">>} 66 | ], Echo, Req). 67 | 68 | terminate(_Reason, _Req, _State) -> 69 | ok. 70 | 71 | 72 | get_increment_mucs(User,Args) -> 73 | case proplists:get_value("u",Args) of 74 | User -> 75 | T = proplists:get_value("t",Args,<<"0">>), 76 | case catch ejb_odbc_query:get_user_register_mucs_by_version(User,T) of 77 | {selected, _,Res} when is_list(Res) -> 78 | lists:flatmap(fun([M,D,V,F]) -> 79 | [{obj,[{"M",M},{"D",D},{"T",V},{"F",F}]}] end,Res); 80 | _ -> 81 | [] 82 | end; 83 | _ -> 84 | [] 85 | end. 86 | 87 | 88 | -------------------------------------------------------------------------------- /qtalk_opensource/scripts/ejb_http_server/src/http_get_muc_users.erl: -------------------------------------------------------------------------------- 1 | %% Feel free to use, reuse and abuse the code in this file. 2 | 3 | -module(http_get_muc_users). 4 | 5 | -export([init/3]). 6 | -export([handle/2]). 7 | -export([terminate/3]). 8 | 9 | -include("logger.hrl"). 10 | -include("ejb_http_server.hrl"). 11 | 12 | init(_Transport, Req, []) -> 13 | {ok, Req, undefined}. 14 | 15 | handle(Req, State) -> 16 | {Method, _ } = cowboy_req:method(Req), 17 | catch ejb_monitor:monitor_count(<<"http_get_muc_vcard_domain">>,1), 18 | case Method of 19 | <<"GET">> -> 20 | {Host,_} = cowboy_req:host(Req), 21 | {ok, Req1} = get_echo(Method,Host,Req), 22 | {ok, Req1, State}; 23 | <<"POST">> -> 24 | HasBody = cowboy_req:has_body(Req), 25 | {ok, Req2} = post_echo(Method, HasBody, Req), 26 | {ok, Req2, State}; 27 | _ -> 28 | {ok,Req3} = echo(undefined, Req), 29 | {ok, Req3, State} 30 | end. 31 | 32 | get_echo(<<"GET">>,_,Req) -> 33 | cowboy_req:reply(200, [ 34 | {<<"content-type">>, <<"text/plain; charset=utf-8">>} 35 | ], <<"No GET method">>, Req). 36 | 37 | post_echo(<<"POST">>, true, Req) -> 38 | {ok, Body, _} = cowboy_req:body(Req), 39 | case rfc4627:decode(Body) of 40 | {ok,Json,[]} -> 41 | Rslt = 42 | case http_utils:verify_user_key_pv1(Req) of 43 | true -> 44 | get_muc_users(Json); 45 | false -> 46 | case catch http_utils:verify_muc_acess_limit(Req) of 47 | true -> 48 | get_muc_users(Json); 49 | _ -> 50 | http_utils:gen_result(false, 1, <<"Tkey check error">>,<<"">>) 51 | end 52 | end, 53 | cowboy_req:reply(200, [{<<"content-type">>, <<"text/json; charset=utf-8">>}], Rslt, Req); 54 | _ -> 55 | Rslt = <<"Body parse error">>, 56 | cowboy_req:reply(200,[{<<"content-type">>, <<"text/json; charset=utf-8">>}],Rslt, Req) 57 | end; 58 | post_echo(<<"POST">>, false, Req) -> 59 | cowboy_req:reply(400, [], <<"Missing Post body.">>, Req); 60 | post_echo(_, _, Req) -> 61 | cowboy_req:reply(405, Req). 62 | 63 | echo(undefined, Req) -> 64 | cowboy_req:reply(400, [], <<"Missing parameter.">>, Req); 65 | echo(Echo, Req) -> 66 | cowboy_req:reply(200, [ 67 | {<<"content-type">>, <<"text/plain; charset=utf-8">>} 68 | ], Echo, Req). 69 | 70 | terminate(_Reason, _Req, _State) -> 71 | ok. 72 | 73 | get_muc_users(Json) -> 74 | {obj,Args} = Json, 75 | Muc = proplists:get_value("muc",Args), 76 | Ret = 77 | case catch pg_odbc:sql_query(<<"ejb_http_server">>, 78 | [<<"select username from muc_room_users where muc_name = '">>,Muc,<<"'">>]) of 79 | {selected,_,Res} when is_list(Res) -> 80 | lists:map(fun(U) -> 81 | User = list_to_binary(U), 82 | Nick = ejb_public:get_user_nick(User), 83 | {obj,[{"U",User},{"N",Nick}]} end,Res); 84 | _ -> 85 | [] 86 | end, 87 | http_utils:gen_result(true, 0, <<"">>,Ret). 88 | 89 | 90 | -------------------------------------------------------------------------------- /qtalk_opensource/scripts/ejb_http_server/src/http_getdeps.erl: -------------------------------------------------------------------------------- 1 | %% Feel free to use, reuse and abuse the code in this file. 2 | 3 | -module(http_getdeps). 4 | 5 | -export([init/3]). 6 | -export([handle/2]). 7 | -export([terminate/3]). 8 | 9 | -include("ejb_http_server.hrl"). 10 | -include("logger.hrl"). 11 | -include("http_req.hrl"). 12 | 13 | init(_Transport, Req, []) -> 14 | {ok, Req, undefined}. 15 | 16 | handle(Req, State) -> 17 | {Method, _} = cowboy_req:method(Req), 18 | catch ejb_monitor:monitor_count(<<"http_get_deps">>,1), 19 | case Method of 20 | <<"GET">> -> 21 | {Method, _} = cowboy_req:method(Req), 22 | {Host,_} = cowboy_req:host(Req), 23 | {ok, Req2} = get_echo(Method,Host,Req), 24 | {ok, cowboy_req:compact(Req2), State}; 25 | _ -> 26 | {ok,Req2} = echo(undefined, Req), 27 | {ok, Req2, State} 28 | end. 29 | 30 | get_echo(<<"GET">>,Host,Req) -> 31 | Req_compress = Req#http_req{resp_compress = true}, 32 | Rslt = 33 | %case http_utils:verify_user_key(Req) of 34 | case true of 35 | true -> 36 | get_departments(); 37 | _ -> 38 | [] 39 | end, 40 | cowboy_req:reply(200, [ 41 | {<<"content-type">>, <<"text/plain; charset=utf-8">>} 42 | ], Rslt, Req_compress); 43 | get_echo(<<"Get">>,_,Req) -> 44 | cowboy_req:reply(405, Req). 45 | 46 | echo(undefined, Req) -> 47 | cowboy_req:reply(400, [], <<"Missing parameter.">>, Req); 48 | echo(Echo, Req) -> 49 | cowboy_req:reply(200, [ 50 | {<<"content-type">>, <<"text/plain; charset=utf-8">>} 51 | ], Echo, Req). 52 | 53 | terminate(_Reason, _Req, _State) -> 54 | ok. 55 | 56 | get_departments() -> 57 | case ets:lookup(cache_info,<<"json_tree_depts">>) of 58 | [Json_tree_depts] when is_record(Json_tree_depts,cache_info) -> 59 | Json_tree_depts#cache_info.cache; 60 | _ -> 61 | [] 62 | end. 63 | -------------------------------------------------------------------------------- /qtalk_opensource/scripts/ejb_http_server/src/http_getonlineuser.erl: -------------------------------------------------------------------------------- 1 | %% Feel free to use, reuse and abuse the code in this file. 2 | 3 | -module(http_getonlineuser). 4 | 5 | -export([init/3]). 6 | -export([handle/2]). 7 | -export([terminate/3]). 8 | 9 | -include("logger.hrl"). 10 | -include("http_req.hrl"). 11 | -include("ejb_http_server.hrl"). 12 | 13 | init(_Transport, Req, []) -> 14 | {ok, Req, undefined}. 15 | 16 | handle(Req, State) -> 17 | {Method, Req} = cowboy_req:method(Req), 18 | catch ejb_monitor:monitor_count(<<"http_get_online_user">>,1), 19 | case Method of 20 | <<"GET">> -> 21 | {Host,_} = cowboy_req:host(Req), 22 | {ok, Req2} = get_echo(Method,Host,Req), 23 | {ok, Req2, State}; 24 | _ -> 25 | {ok,Req2} = echo(undefined, Req), 26 | {ok, Req2, State} 27 | end. 28 | 29 | get_echo(<<"GET">>,Host,Req) -> 30 | Req_compress = Req#http_req{resp_compress = true}, 31 | case http_utils:check_version(Req) of 32 | false -> 33 | Rslt = 34 | case catch ets:lookup(cache_info,<<"online1">>) of 35 | [Online] when is_record(Online,cache_info) -> 36 | Online#cache_info.cache; 37 | _ -> 38 | [] 39 | end, 40 | cowboy_req:reply(200, [ 41 | {<<"content-type">>, <<"text/json; charset=utf-8">>} 42 | ], Rslt, Req_compress); 43 | true -> 44 | Rslt = 45 | case http_utils:verify_user_key(Req) of 46 | true -> 47 | case catch ets:lookup(cache_info,<<"online1">>) of 48 | [Online] when is_record(Online,cache_info) -> 49 | Online#cache_info.cache; 50 | _ -> 51 | [] 52 | end; 53 | false -> 54 | [] 55 | end, 56 | cowboy_req:reply(200, [{<<"content-type">>, <<"text/json; charset=utf-8">>}], Rslt, Req_compress) 57 | end; 58 | get_echo(<<"Get">>,_,Req) -> 59 | cowboy_req:reply(405, Req). 60 | 61 | echo(undefined, Req) -> 62 | cowboy_req:reply(400, [], <<"Missing parameter.">>, Req); 63 | echo(Echo, Req) -> 64 | cowboy_req:reply(200, [ 65 | {<<"content-type">>, <<"text/json; charset=utf-8">>} 66 | ], Echo, Req). 67 | 68 | terminate(_Reason, _Req, _State) -> 69 | ok. 70 | -------------------------------------------------------------------------------- /qtalk_opensource/scripts/ejb_http_server/src/http_getonlineuser2.erl: -------------------------------------------------------------------------------- 1 | %% Feel free to use, reuse and abuse the code in this file. 2 | 3 | -module(http_getonlineuser2). 4 | 5 | -export([init/3]). 6 | -export([handle/2]). 7 | -export([terminate/3]). 8 | 9 | -include("logger.hrl"). 10 | -include("http_req.hrl"). 11 | -include("ejb_http_server.hrl"). 12 | 13 | init(_Transport, Req, []) -> 14 | {ok, Req, undefined}. 15 | 16 | handle(Req, State) -> 17 | {Method, _} = cowboy_req:method(Req), 18 | catch ejb_monitor:monitor_count(<<"http_get_online_users">>,1), 19 | case Method of 20 | <<"GET">> -> 21 | {Host,_} = cowboy_req:host(Req), 22 | {ok, Req2} = get_echo(Method,Host,Req), 23 | {ok, Req2, State}; 24 | _ -> 25 | {ok,Req2} = echo(undefined, Req), 26 | {ok, Req2, State} 27 | end. 28 | 29 | get_echo(<<"GET">>,Host,Req) -> 30 | Req_compress = Req#http_req{resp_compress = true}, 31 | case http_utils:check_version(Req) of 32 | false -> 33 | Rslt = 34 | case catch ets:lookup(cache_info,<<"online2">>) of 35 | [Online] when is_record(Online,cache_info) -> 36 | Online#cache_info.cache; 37 | _ -> 38 | [] 39 | end, 40 | cowboy_req:reply(200, [ 41 | {<<"content-type">>, <<"text/json; charset=utf-8">>} 42 | ], Rslt, Req_compress); 43 | true -> 44 | Rslt = 45 | case http_utils:verify_user_key(Req) of 46 | true -> 47 | case catch ets:lookup(cache_info,<<"online2">>) of 48 | [Online] when is_record(Online,cache_info) -> 49 | Online#cache_info.cache; 50 | _ -> 51 | [] 52 | end; 53 | _ -> 54 | %% http_utils:gen_result(false, <<"-1">>, <<"Not found Mac_Key">>) 55 | [] 56 | end, 57 | cowboy_req:reply(200, [{<<"content-type">>, <<"text/json; charset=utf-8">>}], Rslt, Req_compress) 58 | end; 59 | get_echo(<<"Get">>,_,Req) -> 60 | cowboy_req:reply(405, Req). 61 | 62 | echo(undefined, Req) -> 63 | cowboy_req:reply(400, [], <<"Missing parameter.">>, Req); 64 | echo(Echo, Req) -> 65 | cowboy_req:reply(200, [ 66 | {<<"content-type">>, <<"text/json; charset=utf-8">>} 67 | ], Echo, Req). 68 | 69 | terminate(_Reason, _Req, _State) -> 70 | ok. 71 | -------------------------------------------------------------------------------- /qtalk_opensource/scripts/ejb_http_server/src/http_getservertime.erl: -------------------------------------------------------------------------------- 1 | %% Feel free to use, reuse and abuse the code in this file. 2 | 3 | -module(http_getservertime). 4 | 5 | -export([init/3]). 6 | -export([handle/2]). 7 | -export([terminate/3]). 8 | 9 | -include("logger.hrl"). 10 | 11 | init(_Transport, Req, []) -> 12 | {ok, Req, undefined}. 13 | 14 | handle(Req, State) -> 15 | {Method, _} = cowboy_req:method(Req), 16 | catch ejb_monitor:monitor_count(<<"http_get_server_time">>,1), 17 | case Method of 18 | <<"GET">> -> 19 | {Host,_} = cowboy_req:host(Req), 20 | {ok, Req2} = get_echo(Method,Host,Req), 21 | {ok, Req2, State}; 22 | <<"POST">> -> 23 | HasBody = cowboy_req:has_body(Req), 24 | {ok, Req2} = post_echo(Method, HasBody, Req), 25 | {ok, Req2, State}; 26 | _ -> 27 | {ok,Req2} = echo(undefined, Req), 28 | {ok, Req2, State} 29 | end. 30 | 31 | get_echo(<<"GET">>,Host,Req) -> 32 | case http_utils:check_version(Req) of 33 | false -> 34 | Rslt = integer_to_binary(mod_time:get_timestamp()), 35 | cowboy_req:reply(200, [ 36 | {<<"content-type">>, <<"text/plain; charset=utf-8">>} 37 | ], Rslt, Req); 38 | true -> 39 | Res = 40 | case http_utils:verify_user_key(Req) of 41 | true -> 42 | integer_to_binary(mod_time:get_timestamp()); 43 | _ -> 44 | http_utils:gen_result(false, <<"-1">>, <<"Not found Mac_Key">>) 45 | end, 46 | cowboy_req:reply(200, [ 47 | {<<"content-type">>, <<"text/plain; charset=utf-8">>} 48 | ], Res, Req) 49 | end; 50 | get_echo(<<"Get">>,_,Req) -> 51 | cowboy_req:reply(405, Req). 52 | 53 | echo(undefined, Req) -> 54 | cowboy_req:reply(400, [], <<"Missing parameter.">>, Req); 55 | echo(Echo, Req) -> 56 | cowboy_req:reply(200, [ 57 | {<<"content-type">>, <<"text/plain; charset=utf-8">>} 58 | ], Echo, Req). 59 | 60 | 61 | post_echo(<<"POST">>, true, Req) -> 62 | {ok, _, _} = cowboy_req:body_qs(Req), 63 | {Host,_ } = cowboy_req:host(Req), 64 | case http_utils:check_version(Req) of 65 | false -> 66 | Rslt = integer_to_binary(mod_time:get_timestamp()), 67 | echo(Rslt,Req); 68 | true -> 69 | Rslt = 70 | case http_utils:verify_user_key(Req) of 71 | true -> 72 | integer_to_binary(mod_time:get_timestamp()); 73 | _ -> 74 | http_utils:gen_result(false, <<"-1">>, <<"Not found Mac_Key">>) 75 | end, 76 | echo(Rslt, Req) 77 | end; 78 | post_echo(<<"POST">>, false, Req) -> 79 | cowboy_req:reply(400, [], <<"Missing Post body.">>, Req); 80 | post_echo(_, _, Req) -> 81 | cowboy_req:reply(405, Req). 82 | 83 | terminate(_Reason, _Req, _State) -> 84 | ok. 85 | 86 | 87 | -------------------------------------------------------------------------------- /qtalk_opensource/scripts/ejb_http_server/src/http_getsuoxie.erl: -------------------------------------------------------------------------------- 1 | %% Feel free to use, reuse and abuse the code in this file. 2 | 3 | -module(http_getsuoxie). 4 | 5 | -export([init/3]). 6 | -export([handle/2]). 7 | -export([terminate/3]). 8 | 9 | -include("logger.hrl"). 10 | -include("http_req.hrl"). 11 | -include("ejb_http_server.hrl"). 12 | 13 | init(_Transport, Req, []) -> 14 | {ok, Req, undefined}. 15 | 16 | handle(Req, State) -> 17 | {Method, _} = cowboy_req:method(Req), 18 | catch ejb_monitor:monitor_count(<<"http_get_suoxie">>,1), 19 | case Method of 20 | <<"GET">> -> 21 | {Host,_} = cowboy_req:host(Req), 22 | {ok, Req2} = get_echo(Method,Host,Req), 23 | {ok, Req2, State}; 24 | _ -> 25 | {ok,Req2} = echo(undefined, Req), 26 | {ok, Req2, State} 27 | end. 28 | 29 | get_echo(<<"GET">>,Host,Req) -> 30 | Req_compress = Req#http_req{resp_compress = true}, 31 | case http_utils:check_version(Req) of 32 | false -> 33 | Rslt = 34 | case ets:lookup(cache_info,<<"abbreviates">>) of 35 | [Cache_info] when is_record(Cache_info,cache_info) -> 36 | Cache_info#cache_info.cache; 37 | _ -> 38 | [] 39 | end, 40 | cowboy_req:reply(200, [ 41 | {<<"content-type">>, <<"text/plain; charset=utf-8">>} 42 | ], Rslt, Req_compress); 43 | true -> 44 | Rslt = 45 | case http_utils:verify_user_key(Req) of 46 | true -> 47 | case ets:lookup(cache_info,<<"abbreviates">>) of 48 | [Cache_info] when is_record(Cache_info,cache_info) -> 49 | Cache_info#cache_info.cache; 50 | _ -> 51 | [] 52 | end; 53 | _ -> 54 | [] 55 | end, 56 | 57 | cowboy_req:reply(200, [ 58 | {<<"content-type">>, <<"text/plain; charset=utf-8">>} 59 | ],Rslt, Req_compress) 60 | end; 61 | get_echo(<<"Get">>,_,Req) -> 62 | cowboy_req:reply(405, Req). 63 | 64 | echo(undefined, Req) -> 65 | cowboy_req:reply(400, [], <<"Missing parameter.">>, Req); 66 | echo(Echo, Req) -> 67 | cowboy_req:reply(200, [ 68 | {<<"content-type">>, <<"text/plain; charset=utf-8">>} 69 | ], Echo, Req). 70 | 71 | terminate(_Reason, _Req, _State) -> 72 | ok. 73 | 74 | 75 | -------------------------------------------------------------------------------- /qtalk_opensource/scripts/ejb_http_server/src/http_getusers.erl: -------------------------------------------------------------------------------- 1 | -module(http_getusers). 2 | 3 | -export([init/3]). 4 | -export([handle/2]). 5 | -export([terminate/3]). 6 | 7 | -include("ejb_http_server.hrl"). 8 | -include("logger.hrl"). 9 | -include("http_req.hrl"). 10 | 11 | init(_Transport, Req, []) -> 12 | {ok, Req, undefined}. 13 | 14 | handle(Req, State) -> 15 | {Method, _} = cowboy_req:method(Req), 16 | catch ejb_monitor:monitor_count(<<"http_get_users">>,1), 17 | case Method of 18 | <<"GET">> -> 19 | {Host,_} = cowboy_req:host(Req), 20 | {ok, Req2} = get_echo(Method,Host,Req), 21 | {ok, Req2, State}; 22 | <<"POST">> -> 23 | HasBody = cowboy_req:has_body(Req), 24 | {ok, Req2} = post_echo(Method, HasBody, Req), 25 | {ok, Req2, State}; 26 | _ -> 27 | {ok,Req2} = echo(undefined, Req), 28 | {ok, Req2, State} 29 | end. 30 | 31 | get_echo(<<"GET">>,Host,Req) -> 32 | Req_compress = Req#http_req{resp_compress = true}, 33 | Res = 34 | case http_utils:verify_user_key(Req) of 35 | true -> 36 | get_department(); 37 | _ -> 38 | %% http_utils:gen_result(false, <<"-1">>, <<"Not found Mac_Key">>) 39 | [] 40 | end, 41 | cowboy_req:reply(200, [ 42 | {<<"content-type">>, <<"text/plain; charset=utf-8">>} 43 | ], Res, Req_compress); 44 | get_echo(<<"Get">>,_,Req) -> 45 | cowboy_req:reply(405, Req). 46 | 47 | echo(undefined, Req) -> 48 | cowboy_req:reply(400, [], <<"Missing parameter.">>, Req); 49 | echo(Echo, Req) -> 50 | cowboy_req:reply(200, [ 51 | {<<"content-type">>, <<"text/plain; charset=utf-8">>} 52 | ], Echo, Req). 53 | 54 | post_echo(<<"POST">>, true, Req) -> 55 | {ok, _, _} = cowboy_req:body_qs(Req), 56 | {Host,_} = cowboy_req:host(Req), 57 | Req_compress = Req#http_req{resp_compress = true}, 58 | case http_utils:check_version(Req) of 59 | false -> 60 | Res = get_department(), 61 | echo(Res,Req); 62 | true -> 63 | Res = 64 | case http_utils:verify_user_key(Req) of 65 | true -> 66 | get_department(); 67 | _ -> 68 | [] 69 | end, 70 | echo(Res, Req_compress) 71 | end; 72 | post_echo(<<"POST">>, false, Req) -> 73 | cowboy_req:reply(400, [], <<"Missing Post body.">>, Req); 74 | post_echo(_, _, Req) -> 75 | cowboy_req:reply(405, Req). 76 | 77 | terminate(_Reason, _Req, _State) -> 78 | ok. 79 | 80 | get_department() -> 81 | case ets:lookup(cache_info,<<"list_depts">>) of 82 | [] -> 83 | []; 84 | [Cache_info] when is_record(Cache_info,cache_info) -> 85 | Cache_info#cache_info.cache; 86 | _ -> 87 | [] 88 | end. 89 | 90 | -------------------------------------------------------------------------------- /qtalk_opensource/scripts/ejb_http_server/src/http_healthcheck.erl: -------------------------------------------------------------------------------- 1 | %% Feel free to use, reuse and abuse the code in this file. 2 | 3 | -module(http_healthcheck). 4 | 5 | -export([init/3]). 6 | -export([handle/2]). 7 | -export([terminate/3]). 8 | -include("logger.hrl"). 9 | 10 | init(_Transport, Req, []) -> 11 | {ok, Req, undefined}. 12 | 13 | handle(Req, State) -> 14 | {Method, _} = cowboy_req:method(Req), 15 | case Method of 16 | <<"GET">> -> 17 | {ok, Req1} = get_echo(Method,Req), 18 | {ok, Req1, State}; 19 | _ -> 20 | {ok,Req1} = echo(undefined, Req), 21 | {ok, Req1, State} 22 | end. 23 | 24 | get_echo(<<"GET">>,Req) -> 25 | cowboy_req:reply(200, [], [], Req); 26 | get_echo(<<"Get">>,Req) -> 27 | cowboy_req:reply(405, Req). 28 | 29 | echo(undefined, Req) -> 30 | cowboy_req:reply(400, [], <<"Missing parameter.">>, Req); 31 | echo(Echo, Req) -> 32 | cowboy_req:reply(200, [ 33 | {<<"content-type">>, <<"text/plain; charset=utf-8">>} 34 | ], Echo, Req). 35 | 36 | terminate(_Reason, _Req, _State) -> 37 | ok. 38 | 39 | -------------------------------------------------------------------------------- /qtalk_opensource/scripts/ejb_http_server/src/http_log_dump_url.erl: -------------------------------------------------------------------------------- 1 | %% Feel free to use, reuse and abuse the code in this file. 2 | -module(http_log_dump_url). 3 | 4 | -export([init/3]). 5 | -export([handle/2]). 6 | -export([terminate/3]). 7 | 8 | -include("logger.hrl"). 9 | -include("ejb_http_server.hrl"). 10 | 11 | init(_Transport, Req, []) -> 12 | {ok, Req, undefined}. 13 | 14 | handle(Req, State) -> 15 | {Method, _ } = cowboy_req:method(Req), 16 | catch ejb_monitor:monitor_count(<<"http_log_dump_url">>,1), 17 | case Method of 18 | <<"GET">> -> 19 | {Host,_} = cowboy_req:host(Req), 20 | {ok, Req1} = get_echo(Method,Host,Req), 21 | {ok, Req1, State}; 22 | <<"POST">> -> 23 | HasBody = cowboy_req:has_body(Req), 24 | {ok, Req2} = post_echo(Method, HasBody, Req), 25 | {ok, Req2, State}; 26 | _ -> 27 | {ok,Req3} = echo(undefined, Req), 28 | {ok, Req3, State} 29 | end. 30 | 31 | get_echo(<<"GET">>,_,Req) -> 32 | cowboy_req:reply(200, [ 33 | {<<"content-type">>, <<"text/plain; charset=utf-8">>} 34 | ], <<"No GET method">>, Req). 35 | 36 | post_echo(<<"POST">>, true, Req) -> 37 | {ok, Body, _} = cowboy_req:body(Req), 38 | case rfc4627:decode(Body) of 39 | {ok,Json,[]} -> 40 | Rslt = 41 | %%case http_utils:verify_user_key(Req) of 42 | case true of 43 | true -> 44 | log_dump_url(Json); 45 | false -> 46 | http_utils:gen_result(false, 1, <<"Tkey check error">>,<<"">>) 47 | end, 48 | cowboy_req:reply(200, [{<<"content-type">>, <<"text/json; charset=utf-8">>}], Rslt, Req); 49 | _ -> 50 | Rslt = <<"Body parse error">>, 51 | cowboy_req:reply(200,[{<<"content-type">>, <<"text/json; charset=utf-8">>}],Rslt, Req) 52 | end; 53 | post_echo(<<"POST">>, false, Req) -> 54 | cowboy_req:reply(400, [], <<"Missing Post body.">>, Req); 55 | post_echo(_, _, Req) -> 56 | cowboy_req:reply(405, Req). 57 | 58 | echo(undefined, Req) -> 59 | cowboy_req:reply(400, [], <<"Missing parameter.">>, Req); 60 | echo(Echo, Req) -> 61 | cowboy_req:reply(200, [ 62 | {<<"content-type">>, <<"text/plain; charset=utf-8">>} 63 | ], Echo, Req). 64 | 65 | terminate(_Reason, _Req, _State) -> 66 | ok. 67 | 68 | log_dump_url(Json) -> 69 | lists:foreach(fun({obj,Args}) -> 70 | Url = proplists:get_value("url",Args), 71 | User = proplists:get_value("user",Args), 72 | pg_odbc:sql_query(<<"ejb_http_server">>, 73 | [<<"insert into win_dump_url(user_name,dump_url) values ('">>,User,<<"','">>,Url,<<"');">>]) 74 | end,Json), 75 | http_utils:gen_result(true, 0, <<"">>,<<"Log dump_url sucess.">>). 76 | 77 | -------------------------------------------------------------------------------- /qtalk_opensource/scripts/ejb_http_server/src/http_qmonitor.erl: -------------------------------------------------------------------------------- 1 | -module(http_qmonitor). 2 | 3 | -export([init/3]). 4 | -export([handle/2]). 5 | -export([terminate/3]). 6 | 7 | -include("ejb_http_server.hrl"). 8 | -include("logger.hrl"). 9 | 10 | init(_Transport, Req, []) -> 11 | {ok, Req, undefined}. 12 | 13 | handle(Req, State) -> 14 | {Method, _} = cowboy_req:method(Req), 15 | case Method of 16 | <<"GET">> -> 17 | {Host,_} = cowboy_req:host(Req), 18 | {ok, Req2} = get_echo(Method,Host,Req), 19 | {ok, Req2, State}; 20 | <<"POST">> -> 21 | HasBody = cowboy_req:has_body(Req), 22 | {ok, Req2} = post_echo(Method, HasBody, Req), 23 | {ok, Req2, State}; 24 | _ -> 25 | {ok,Req2} = echo(undefined, Req), 26 | {ok, Req2, State} 27 | end. 28 | 29 | get_echo(<<"GET">>,Host,Req) -> 30 | Rslt = 31 | case ets:lookup(cache_info,<<"monitor_info">>) of 32 | [Monitor_info] when is_record(Monitor_info,cache_info) -> 33 | Monitor_info#cache_info.cache; 34 | _ -> 35 | [] 36 | end, 37 | cowboy_req:reply(200, [ 38 | {<<"content-type">>, <<"text/plain; charset=utf-8">>} 39 | ], Rslt, Req); 40 | 41 | get_echo(<<"Get">>,_,Req) -> 42 | cowboy_req:reply(405, Req). 43 | 44 | echo(undefined, Req) -> 45 | cowboy_req:reply(400, [], <<"Missing parameter.">>, Req); 46 | echo(Echo, Req) -> 47 | cowboy_req:reply(200, [ 48 | {<<"content-type">>, <<"text/plain; charset=utf-8">>} 49 | ], Echo, Req). 50 | 51 | post_echo(_, _, Req) -> 52 | cowboy_req:reply(405, Req). 53 | 54 | terminate(_Reason, _Req, _State) -> 55 | ok. 56 | 57 | 58 | -------------------------------------------------------------------------------- /qtalk_opensource/scripts/ejb_http_server/src/http_recommend_rbts.erl: -------------------------------------------------------------------------------- 1 | %% Feel free to use, reuse and abuse the code in this file. 2 | 3 | -module(http_recommend_rbts). 4 | -export([init/3]). 5 | -export([handle/2]). 6 | -export([terminate/3]). 7 | 8 | -include("ejb_http_server.hrl"). 9 | -include("logger.hrl"). 10 | 11 | init(_Transport, Req, []) -> 12 | {ok, Req, undefined}. 13 | 14 | handle(Req, State) -> 15 | {Method, _ } = cowboy_req:method(Req), 16 | catch ejb_monitor:monitor_count(<<"http_recommend_rbts">>,1), 17 | case Method of 18 | <<"GET">> -> 19 | {ok, Req1} = echo(<<"No Get Method!">>,Req), 20 | {ok, Req1, State}; 21 | <<"POST">> -> 22 | HasBody = cowboy_req:has_body(Req), 23 | {ok, Req1} = post_echo(Method, HasBody, Req), 24 | {ok, Req1, State}; 25 | _ -> 26 | {ok,Req1} = echo(undefined, Req), 27 | {ok, Req1, State} 28 | end. 29 | post_echo(<<"POST">>,true,Req) -> 30 | {ok, PBody, _} = cowboy_req:body(Req), 31 | Header = cowboy_req:get(headers,Req), 32 | Body = 33 | case catch proplists:get_value(<<"content-encoding">>,Header) of 34 | <<"gzip">> -> 35 | zlib:gunzip(PBody); 36 | _ -> 37 | PBody 38 | end, 39 | case rfc4627:decode(Body) of 40 | {ok,{obj,Args},[]} -> 41 | Type = proplists:get_value("type",Args), 42 | Res = case Type of 43 | 1 -> 44 | get_recommend_rbts(<<"ejb_http_server">>,Args); 45 | _ -> 46 | http_utils:gen_result(true, <<"0">>,<<"">>,[]) 47 | end, 48 | cowboy_req:reply(200, [{<<"content-type">>, <<"text/json; charset=utf-8">>}], Res, Req); 49 | _ -> 50 | cowboy_req:reply(200, [{<<"content-type">>, <<"text/json; charset=utf-8">>}], 51 | http_utils:gen_result(false, <<"-1">>,<<"Json format error.">>,<<"">>), Req) 52 | end; 53 | post_echo(<<"POST">>, false, Req) -> 54 | cowboy_req:reply(400, [], http_utils:gen_result(false, <<"-1">>,<<"Missing Post body.">>,<<"">>), Req); 55 | post_echo(_, _, Req) -> 56 | cowboy_req:reply(405, Req). 57 | 58 | 59 | echo(undefined, Req) -> 60 | cowboy_req:reply(400, [], http_utils:gen_result(false, <<"-1">>,<<"Missing Post body.">>,<<"">>), Req); 61 | echo(Echo, Req) -> 62 | cowboy_req:reply(200, [ 63 | {<<"content-type">>, <<"text/plain; charset=utf-8">>} 64 | ], http_utils:gen_result(true, <<"0">>,Echo,<<"">>), Req). 65 | 66 | terminate(_Reason, _Req, _State) -> 67 | ok. 68 | 69 | get_recommend_rbts(LServer,Json) -> 70 | Res = 71 | case catch pg_odbc:sql_query(LServer, 72 | [<<"select en_name,rbt_body,rbt_version from robot_info where recommend = 1;">>] ) of 73 | {selected, _ , SRes} when is_list(SRes) -> 74 | lists:map(fun([En,Body,Ve]) -> 75 | {obj,[{"rbt_name",En},{"rbt_body",Body},{"rbt_ver",http_utils:to_integer(Ve)}]} end,SRes); 76 | _ -> 77 | [] 78 | end, 79 | http_utils:gen_result(true, <<"0">>,<<"">>,Res). 80 | 81 | -------------------------------------------------------------------------------- /qtalk_opensource/scripts/ejb_http_server/src/memory_free.erl: -------------------------------------------------------------------------------- 1 | -module(memory_free). 2 | 3 | -export([find_max_memory_process/1,memory_free/1]). 4 | 5 | -include("logger.hrl"). 6 | 7 | 8 | find_max_memory_process(Num) -> 9 | ProcessL = processes() -- [self()], 10 | AttrName = memory, 11 | F = fun(Pid, L) -> 12 | case process_info(Pid, [AttrName, registered_name, current_function, initial_call]) of 13 | [Attr, Name, Init, Cur] -> 14 | Info = {Attr, [{pid, Pid}, Name, Init, Cur]}, 15 | [Info | L]; 16 | undefined -> 17 | L 18 | end end, 19 | ProInfoL = lists:foldl(F, [], ProcessL), 20 | CompF = fun({A, _},{B, _}) -> A > B end, 21 | ProInfoSortL = lists:usort(CompF, ProInfoL), 22 | lists:sublist(ProInfoSortL, Num). 23 | 24 | memory_free(Num) -> 25 | L = find_max_memory_process(Num), 26 | lists:foreach(fun({_,Info}) -> 27 | Pid = proplists:get_value(pid,Info), 28 | erlang:garbage_collect(Pid), 29 | ?DEBUG("Pid ~p ~n",[Pid]) end,L). 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /qtalk_opensource/scripts/ejb_http_server/src/mod_time.erl: -------------------------------------------------------------------------------- 1 | -module(mod_time). 2 | 3 | -export([get_timestamp/0,datetime_to_timestamp/1,timestamp_to_datetime/1,get_month_first_day/1,get_datetime_before_day/2]). 4 | -export([get_timestamp_of_end_day/1,get_timestamp_of_start_day/1,timestamp_to_datetime_utc1/1,deal_timestamp/1,get_exact_timestamp/0]). 5 | 6 | -define(DAY_TIMESTAMP,86400). 7 | 8 | -include("logger.hrl"). 9 | 10 | get_timestamp() -> 11 | {MegaSecs, Secs,_MicroSec} = os:timestamp(), 12 | MegaSecs * 1000000 + Secs. 13 | 14 | get_exact_timestamp() -> 15 | {MegaSecs, Secs,MicroSec} = os:timestamp(), 16 | 1000000000 * MegaSecs + Secs * 1000 + MicroSec div 1000. 17 | 18 | deal_timestamp(Time) -> 19 | {MegaSecs, Secs,_MicroSec} = Time, 20 | MegaSecs * 1000000 + Secs. 21 | %%UTC+8:use {{1970,1,1}, {8,0,0},not use {{1970,1,1}, {0,0,0} 22 | datetime_to_timestamp(DateTime) -> 23 | calendar:datetime_to_gregorian_seconds(DateTime) - 24 | calendar:datetime_to_gregorian_seconds({{1970,1,1}, {8,0,0}}). 25 | 26 | %%UTC+8:use {{1970,1,1}, {8,0,0},not use {{1970,1,1}, {0,0,0} 27 | timestamp_to_datetime(Timestamp) -> 28 | calendar:gregorian_seconds_to_datetime(Timestamp + 29 | calendar:datetime_to_gregorian_seconds({{1970,1,1}, {8,0,0}})). 30 | 31 | timestamp_to_datetime_utc1(Timestamp) -> 32 | calendar:gregorian_seconds_to_datetime(Timestamp + 33 | calendar:datetime_to_gregorian_seconds({{1970,1,1}, {0,0,0}})). 34 | 35 | get_month_first_day(Timestamp) -> 36 | case mod_time:timestamp_to_datetime(Timestamp) of 37 | {{Year,Month,_Day},{_,_,_}} -> 38 | mod_time:datetime_to_timestamp({{Year,Month,1},{0,0,0}}); 39 | _ -> 40 | 0 41 | end. 42 | 43 | get_datetime_before_day(Timestamp,Day) -> 44 | Timestamp - ?DAY_TIMESTAMP * Day. 45 | 46 | get_timestamp_of_end_day(Timestamp) -> 47 | case mod_time:timestamp_to_datetime(Timestamp) of 48 | {{Year,Month,Day},{_,_,_}} -> 49 | datetime_to_timestamp({{Year,Month,Day},{23,59,59}}); 50 | _ -> 51 | 0 52 | end. 53 | 54 | get_timestamp_of_start_day(Timestamp) -> 55 | case mod_time:timestamp_to_datetime(Timestamp) of 56 | {{Year,Month,Day},{_,_,_}} -> 57 | datetime_to_timestamp({{Year,Month,Day},{0,0,0}}); 58 | _ -> 59 | 0 60 | end. 61 | -------------------------------------------------------------------------------- /qtalk_opensource/scripts/ejb_http_server/src/pg_odbc_sup.erl: -------------------------------------------------------------------------------- 1 | %%%---------------------------------------------------------------------- 2 | %%% File : pg_odbc_sup.erl 3 | %%%---------------------------------------------------------------------- 4 | 5 | -module(pg_odbc_sup). 6 | 7 | %% API 8 | -export([start_link/1, init/1]). 9 | 10 | -export([add_pid/2, remove_pid/2, 11 | get_pids/1, get_random_pid/1, transform_options/1]). 12 | 13 | -define(DEFAULT_POOL_SIZE, 25). 14 | -define(PGSQL_PORT, 5432). 15 | 16 | start_link(Options) -> 17 | ets:new(odbc_pid, [named_table, bag, public]), 18 | supervisor:start_link({local,?MODULE}, ?MODULE, [Options]). 19 | 20 | init([Options]) -> 21 | PoolSize = proplists:get_value(pool_size, Options, ?DEFAULT_POOL_SIZE), 22 | {ok, 23 | {{one_for_one, PoolSize * 10, 1}, 24 | lists:map(fun (I) -> 25 | {I, 26 | {pg_odbc, start_link, 27 | [Options]}, 28 | transient, 2000, worker, [?MODULE]} 29 | end, 30 | lists:seq(1, PoolSize))}}. 31 | 32 | get_pids(Host) -> 33 | case ets:tab2list(odbc_pid) of 34 | [] -> 35 | []; 36 | Rs when is_list(Rs) -> 37 | lists:foldl(fun({H, Pid}, Acc) when H =:= Host -> 38 | [Pid|Acc]; 39 | (_, Acc) -> 40 | Acc 41 | end, [], Rs); 42 | _ -> 43 | [] 44 | end. 45 | 46 | get_random_pid(Host) -> 47 | case get_pids(Host) of 48 | [] -> undefined; 49 | Pids -> lists:nth(erlang:phash(os:timestamp(), length(Pids)), Pids) 50 | end. 51 | 52 | add_pid(Host, Pid) -> 53 | ets:insert(odbc_pid,{Host, Pid}). 54 | 55 | remove_pid(Host, Pid) -> 56 | ets:delete_object(odbc_pid,{Host, Pid}). 57 | 58 | transform_options(Opts) -> 59 | lists:foldl(fun transform_options/2, [], Opts). 60 | 61 | transform_options({odbc_server, {Type, Server, Port, DB, User, Pass}}, Opts) -> 62 | [{odbc_type, Type}, 63 | {odbc_server, Server}, 64 | {odbc_port, Port}, 65 | {odbc_database, DB}, 66 | {odbc_username, User}, 67 | {odbc_password, Pass}|Opts]; 68 | 69 | transform_options({odbc_server, {pgsql, Server, DB, User, Pass}}, Opts) -> 70 | transform_options({odbc_server, {pgsql, Server, ?PGSQL_PORT, DB, User, Pass}}, Opts); 71 | transform_options(Opt, Opts) -> 72 | [Opt|Opts]. 73 | -------------------------------------------------------------------------------- /qtalk_opensource/scripts/ejb_http_server/src/randoms.erl: -------------------------------------------------------------------------------- 1 | -module(randoms). 2 | 3 | -author('alexey@process-one.net'). 4 | 5 | -export([get_string/0, integer_to_binary/1, integer_to_binary/2]). 6 | 7 | -export([start/0, init/0]). 8 | 9 | start() -> 10 | register(random_generator, spawn(randoms, init, [])). 11 | 12 | init() -> 13 | {A1, A2, A3} = now(), random:seed(A1, A2, A3), loop(). 14 | 15 | loop() -> 16 | receive 17 | {From, get_random, N} -> 18 | From ! {random, random:uniform(N)}, loop(); 19 | _ -> loop() 20 | end. 21 | 22 | get_string() -> 23 | random_generator ! {self(), get_random, 65536 * 65536}, 24 | receive 25 | {random, R} -> randoms:integer_to_binary(R) 26 | end. 27 | 28 | integer_to_binary(I) -> 29 | list_to_binary(integer_to_list(I)). 30 | 31 | integer_to_binary(I, Base) -> 32 | list_to_binary(erlang:integer_to_list(I, Base)). 33 | 34 | -------------------------------------------------------------------------------- /qtalk_opensource/scripts/ejb_http_server/src/redis_link_sup.erl: -------------------------------------------------------------------------------- 1 | -module(redis_link_sup). 2 | 3 | -include("logger.hrl"). 4 | 5 | -author('liufannana@sina.com'). 6 | 7 | %% Callback Functions 8 | -export([ 9 | start_link/1, 10 | init/1 11 | ]). 12 | 13 | %% APIs 14 | -export([ 15 | add_pid/2, 16 | remove_pid/2, 17 | get_pids/1, 18 | get_random_pid/1 19 | ]). 20 | 21 | -define(SERVER, ?MODULE). 22 | -define(DEFAULT_POOL_SIZE, 40). 23 | -define(DEFAULT_TABLES, []). 24 | 25 | start_link(Opts) -> 26 | ets:new(redis_pid, [named_table, bag, public]), 27 | supervisor:start_link({local, ?SERVER}, ?MODULE, [Opts]). 28 | 29 | init([Opts]) -> 30 | StartMode = proplists:get_value(start_mode, Opts, ?DEFAULT_TABLES), 31 | PoolSize = proplists:get_value(pool_size, Opts, ?DEFAULT_POOL_SIZE), 32 | RedisTabs = proplists:get_value(tables, Opts, ?DEFAULT_TABLES), 33 | case StartMode of 34 | 1 -> 35 | Redis_sentinel_hosts = parse_sentinel_host(proplists:get_value(sentinel_hosts, Opts, "")), 36 | eredis_sentinel:start_link(Redis_sentinel_hosts); 37 | _ -> 38 | ok 39 | end, 40 | 41 | ChildSpec = lists:flatmap(fun (I) -> 42 | lists:map(fun(Tab) -> 43 | {I*100+Tab, 44 | {redis_link, start_link, 45 | [list_to_atom(lists:flatten(io_lib:format("~p:~p", [I, Tab]))),Tab,Opts]}, 46 | transient, 2000, worker, [redis_link]} 47 | end,RedisTabs) 48 | end, 49 | lists:seq(1, PoolSize)), 50 | {ok, 51 | {{one_for_one, PoolSize * 10, 1}, ChildSpec}}. 52 | 53 | get_pids(Table) -> 54 | case ets:tab2list(redis_pid) of 55 | [] -> 56 | []; 57 | Rs when is_list(Rs) -> 58 | lists:foldl(fun({Tab, Pid}, Acc) when Tab =:= Table-> 59 | [Pid|Acc]; 60 | (_, Acc) -> 61 | Acc 62 | end, [], Rs); 63 | _ -> 64 | [] 65 | end. 66 | 67 | get_random_pid(Table) -> 68 | case get_pids(Table) of 69 | [] -> undefined; 70 | Pids -> lists:nth(erlang:phash(os:timestamp(), length(Pids)), Pids) 71 | end. 72 | 73 | add_pid(Table, Pid) -> 74 | ets:insert(redis_pid,{Table, Pid}). 75 | 76 | remove_pid(Table, Pid) -> 77 | ets:delete_object(redis_pid,{Table, Pid}). 78 | 79 | parse_sentinel_host(Configure) -> 80 | lists:map(fun(Sentinel) -> 81 | [Host,Port] = string:tokens(Sentinel,":"), 82 | {Host,list_to_integer(Port)} end,Configure). 83 | -------------------------------------------------------------------------------- /qtalk_opensource/scripts/ejb_http_server/src/transfer_node_rpc.erl: -------------------------------------------------------------------------------- 1 | -module(transfer_node_rpc). 2 | 3 | -include("logger.hrl"). 4 | 5 | -export([call_ejabberd_node/4]). 6 | 7 | call_ejabberd_node(Server,Module,Function,Args) -> 8 | Hidden_nodes = nodes([hidden]), 9 | Ejabberd_nodes = 10 | lists:filter(fun(Node) -> 11 | str:str(list_to_binary(atom_to_list(Node)),<<"ejabberd">>) =/= 0 end,Hidden_nodes), 12 | ?DEBUG("Ejabberd_nodes ~p ~n",[Ejabberd_nodes]), 13 | case Ejabberd_nodes of 14 | [] -> 15 | {false,<<"no found ejabberd node">>}; 16 | _ -> 17 | Node = lists:nth(1,Ejabberd_nodes), 18 | case catch rpc:call(Node,'sync_ets_cache','send_sync_nodes_notcie',[Server,Module,Function,Args]) of 19 | {badrpc, Reason} -> 20 | ?DEBUG("Reasion ~p ~n",[Reason]), 21 | {false,Reason}; 22 | Res -> 23 | ?DEBUG("Reasion ~p ~n",[Res]), 24 | {true,Res} 25 | end 26 | end. 27 | 28 | 29 | -------------------------------------------------------------------------------- /qtalk_opensource/scripts/ejb_http_server/src/transfer_odbc.erl: -------------------------------------------------------------------------------- 1 | -module(transfer_odbc). 2 | 3 | -export([start_link/1]). 4 | -export([init/1, handle_call/3, handle_cast/2, handle_info/2, 5 | terminate/2,code_change/3]). 6 | -export([sync_sql/2,async_sql/2]). 7 | 8 | -behaviour(gen_server). 9 | 10 | -define(SERVER, ?MODULE). 11 | -define(HOST, <<"ejb_http_server">>). 12 | -include("logger.hrl"). 13 | 14 | -record(state, {host,pid}). 15 | 16 | start_link(Opts) -> 17 | gen_server:start_link(?MODULE, [?HOST,Opts], []). 18 | 19 | init([Host,_Opts]) -> 20 | transfer_odbc_sup:add_pid(Host,self()), 21 | {ok, #state{host = Host,pid = self()}}. 22 | 23 | handle_call({sync_sql,Host,Sql}, _From, State) -> 24 | Ret = do_run_sql(Host,Sql), 25 | {reply, Ret, State}; 26 | handle_call(Msg, _From, State) -> 27 | {reply, {ok, Msg}, State}. 28 | 29 | handle_cast({sql,Host,Sql},State) -> 30 | do_run_sql(Host,Sql), 31 | {noreply,State}; 32 | handle_cast(stop, State) -> 33 | transfer_odbc_sup:remove_pid(State#state.host,self()), 34 | {stop, normal, State}. 35 | 36 | handle_info(_From,State) -> 37 | {noreply,State}. 38 | 39 | terminate(_Reason, State) -> 40 | transfer_odbc_sup:remove_pid(State#state.host,self()), 41 | {ok,State}. 42 | 43 | code_change(_OldVsn, State, _Extra) -> 44 | {ok, State}. 45 | 46 | %%异步sql 47 | async_sql(Host,Sql) -> 48 | Spid = transfer_odbc_sup:get_random_pid(Host), 49 | gen_server:cast(Spid, {sql,Host,Sql}). 50 | 51 | %%同步sql 52 | sync_sql(Host,Sql) -> 53 | Spid = transfer_odbc_sup:get_random_pid(Host), 54 | gen_server:call(Spid, {sync_sql,Host,Sql}). 55 | 56 | do_run_sql(Host,Sql) -> 57 | pg_odbc:sql_query(Host,Sql). 58 | -------------------------------------------------------------------------------- /qtalk_opensource/scripts/ejb_http_server/src/transfer_odbc_sup.erl: -------------------------------------------------------------------------------- 1 | %%%---------------------------------------------------------------------- 2 | %%% File : transfer_odbc_sup.erl 3 | %%%---------------------------------------------------------------------- 4 | 5 | -module(transfer_odbc_sup). 6 | 7 | %% API 8 | -export([start_link/1, init/1]). 9 | 10 | -export([add_pid/2, remove_pid/2,get_pids/1, get_random_pid/1]). 11 | 12 | -define(DEFAULT_POOL_SIZE, 10). 13 | 14 | start_link(Options) -> 15 | ets:new(transfer_odbc_pid, [named_table, bag, public]), 16 | supervisor:start_link({local,?MODULE}, ?MODULE, [Options]). 17 | 18 | init([Options]) -> 19 | PoolSize = proplists:get_value(pool_size, Options, ?DEFAULT_POOL_SIZE), 20 | {ok, 21 | {{one_for_one, PoolSize * 10, 1}, 22 | lists:map(fun (I) -> 23 | {I, 24 | {transfer_odbc, start_link, 25 | [Options]}, 26 | transient, 2000, worker, [?MODULE]} 27 | end, 28 | lists:seq(1, PoolSize))}}. 29 | 30 | get_pids(Host) -> 31 | case ets:tab2list(transfer_odbc_pid) of 32 | [] -> 33 | []; 34 | Rs when is_list(Rs) -> 35 | lists:foldl(fun({H, Pid}, Acc) when H =:= Host -> 36 | [Pid|Acc]; 37 | (_, Acc) -> 38 | Acc 39 | end, [], Rs); 40 | _ -> 41 | [] 42 | end. 43 | 44 | get_random_pid(Host) -> 45 | case get_pids(Host) of 46 | [] -> undefined; 47 | Pids -> lists:nth(erlang:phash(os:timestamp(), length(Pids)), Pids) 48 | end. 49 | 50 | add_pid(Host, Pid) -> 51 | ets:insert(transfer_odbc_pid,{Host, Pid}). 52 | 53 | remove_pid(Host, Pid) -> 54 | ets:delete_object(transfer_odbc_pid,{Host, Pid}). 55 | 56 | -------------------------------------------------------------------------------- /qtalk_opensource/sql/pg.sql: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/may-liu/qtalk/f5431e5a7123975e9656e7ab239e674ce33713cd/qtalk_opensource/sql/pg.sql -------------------------------------------------------------------------------- /qtalk_opensource/src/ELDAPv3.asn1db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/may-liu/qtalk/f5431e5a7123975e9656e7ab239e674ce33713cd/qtalk_opensource/src/ELDAPv3.asn1db -------------------------------------------------------------------------------- /qtalk_opensource/src/XmppAddr.asn1db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/may-liu/qtalk/f5431e5a7123975e9656e7ab239e674ce33713cd/qtalk_opensource/src/XmppAddr.asn1db -------------------------------------------------------------------------------- /qtalk_opensource/src/cyrsasl_anonymous.erl: -------------------------------------------------------------------------------- 1 | %%%---------------------------------------------------------------------- 2 | %%% File : cyrsasl_anonymous.erl 3 | %%% Author : Magnus Henoch 4 | %%% Purpose : ANONYMOUS SASL mechanism 5 | %%% See http://www.ietf.org/internet-drafts/draft-ietf-sasl-anon-05.txt 6 | %%% Created : 23 Aug 2005 by Magnus Henoch 7 | %%% 8 | %%% 9 | %%% ejabberd, Copyright (C) 2002-2014 ProcessOne 10 | %%% 11 | %%% This program is free software; you can redistribute it and/or 12 | %%% modify it under the terms of the GNU General Public License as 13 | %%% published by the Free Software Foundation; either version 2 of the 14 | %%% License, or (at your option) any later version. 15 | %%% 16 | %%% This program is distributed in the hope that it will be useful, 17 | %%% but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | %%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 19 | %%% General Public License for more details. 20 | %%% 21 | %%% You should have received a copy of the GNU General Public License along 22 | %%% with this program; if not, write to the Free Software Foundation, Inc., 23 | %%% 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 24 | %%% 25 | %%%---------------------------------------------------------------------- 26 | 27 | -module(cyrsasl_anonymous). 28 | 29 | -export([start/1, stop/0, mech_new/4, mech_step/2]). 30 | 31 | -behaviour(cyrsasl). 32 | 33 | -record(state, {server = <<"">> :: binary()}). 34 | 35 | start(_Opts) -> 36 | cyrsasl:register_mechanism(<<"ANONYMOUS">>, ?MODULE, plain), 37 | ok. 38 | 39 | stop() -> ok. 40 | 41 | mech_new(Host, _GetPassword, _CheckPassword, _CheckPasswordDigest) -> 42 | {ok, #state{server = Host}}. 43 | 44 | mech_step(#state{server = Server}, _ClientIn) -> 45 | User = iolist_to_binary([randoms:get_string() 46 | | [jlib:integer_to_binary(X) 47 | || X <- tuple_to_list(now())]]), 48 | case ejabberd_auth:is_user_exists(User, Server) of 49 | true -> {error, <<"not-authorized">>}; 50 | false -> {ok, [{username, User}, {auth_module, ejabberd_auth_anonymous}]} 51 | end. 52 | -------------------------------------------------------------------------------- /qtalk_opensource/src/easy_cluster.erl: -------------------------------------------------------------------------------- 1 | -module(easy_cluster). 2 | 3 | -export([test_node/1,join/1,join_as_master/1,sync_node/1]). 4 | 5 | test_node(NodeName) -> 6 | case net_adm:ping(NodeName) of 'pong' -> 7 | io:format("server is reachable.~n"); 8 | _ -> 9 | io:format("server could NOT be reached.~n") 10 | end. 11 | 12 | join(NodeName) -> 13 | mnesia:stop(), 14 | mnesia:delete_schema([node()]), 15 | mnesia:start(), 16 | mnesia:change_config(extra_db_nodes, [NodeName]), 17 | mnesia:change_table_copy_type(schema, node(), disc_copies), 18 | application:stop(ejabberd), 19 | application:start(ejabberd). 20 | 21 | join_as_master(NodeName) -> 22 | application:stop(ejabberd), 23 | mnesia:stop(), 24 | mnesia:delete_schema([node()]), 25 | mnesia:start(), 26 | mnesia:change_config(extra_db_nodes, [NodeName]), 27 | mnesia:change_table_copy_type(schema, node(), disc_copies), 28 | easy_cluster:sync_node(NodeName), 29 | application:start(ejabberd). 30 | 31 | sync_node(NodeName) -> 32 | [{Tb, mnesia:add_table_copy(Tb, node(), Type)} 33 | || {Tb, [{NodeName, Type}]} <- [{T, mnesia:table_info(T, where_to_commit)} 34 | || T <- mnesia:system_info(tables)]]. 35 | -------------------------------------------------------------------------------- /qtalk_opensource/src/ejabberd.app.src: -------------------------------------------------------------------------------- 1 | %% $Id$ 2 | 3 | {application, ejabberd, 4 | [{description, "ejabberd"}, 5 | {vsn, "14.07"}, 6 | {modules, []}, 7 | {registered, []}, 8 | {applications, [kernel, stdlib]}, 9 | {env, []}, 10 | {mod, {ejabberd_app, []}}]}. 11 | 12 | 13 | %% Local Variables: 14 | %% mode: erlang 15 | %% End: 16 | %% vim: set filetype=erlang tabstop=8: 17 | -------------------------------------------------------------------------------- /qtalk_opensource/src/ejabberd.app.src.in: -------------------------------------------------------------------------------- 1 | %% $Id$ 2 | 3 | {application, ejabberd, 4 | [{description, "@PACKAGE_NAME@"}, 5 | {vsn, "@PACKAGE_VERSION@"}, 6 | {modules, []}, 7 | {registered, []}, 8 | {applications, [kernel, stdlib]}, 9 | {env, []}, 10 | {mod, {ejabberd_app, []}}]}. 11 | 12 | 13 | %% Local Variables: 14 | %% mode: erlang 15 | %% End: 16 | %% vim: set filetype=erlang tabstop=8: 17 | -------------------------------------------------------------------------------- /qtalk_opensource/src/ejabberd_c2s_config.erl: -------------------------------------------------------------------------------- 1 | %%%---------------------------------------------------------------------- 2 | %%% File : ejabberd_c2s_config.erl 3 | %%% Author : Mickael Remond 4 | %%% Purpose : Functions for c2s interactions from other client 5 | %%% connector modules 6 | %%% Created : 2 Nov 2007 by Mickael Remond 7 | %%% 8 | %%% 9 | %%% ejabberd, Copyright (C) 2002-2014 ProcessOne 10 | %%% 11 | %%% This program is free software; you can redistribute it and/or 12 | %%% modify it under the terms of the GNU General Public License as 13 | %%% published by the Free Software Foundation; either version 2 of the 14 | %%% License, or (at your option) any later version. 15 | %%% 16 | %%% This program is distributed in the hope that it will be useful, 17 | %%% but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | %%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 19 | %%% General Public License for more details. 20 | %%% 21 | %%% You should have received a copy of the GNU General Public License along 22 | %%% with this program; if not, write to the Free Software Foundation, Inc., 23 | %%% 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 24 | %%% 25 | %%%---------------------------------------------------------------------- 26 | 27 | -module(ejabberd_c2s_config). 28 | 29 | -author('mremond@process-one.net'). 30 | 31 | -export([get_c2s_limits/0]). 32 | 33 | %% Get first c2s configuration limitations to apply it to other c2s 34 | %% connectors. 35 | get_c2s_limits() -> 36 | case ejabberd_config:get_option(listen, fun(V) -> V end) of 37 | undefined -> []; 38 | C2SFirstListen -> 39 | case lists:keysearch(ejabberd_c2s, 2, C2SFirstListen) of 40 | false -> []; 41 | {value, {_Port, ejabberd_c2s, Opts}} -> 42 | select_opts_values(Opts) 43 | end 44 | end. 45 | %% Only get access, shaper and max_stanza_size values 46 | 47 | select_opts_values(Opts) -> 48 | select_opts_values(Opts, []). 49 | 50 | select_opts_values([], SelectedValues) -> 51 | SelectedValues; 52 | select_opts_values([{access, Value} | Opts], 53 | SelectedValues) -> 54 | select_opts_values(Opts, 55 | [{access, Value} | SelectedValues]); 56 | select_opts_values([{shaper, Value} | Opts], 57 | SelectedValues) -> 58 | select_opts_values(Opts, 59 | [{shaper, Value} | SelectedValues]); 60 | select_opts_values([{max_stanza_size, Value} | Opts], 61 | SelectedValues) -> 62 | select_opts_values(Opts, 63 | [{max_stanza_size, Value} | SelectedValues]); 64 | select_opts_values([_Opt | Opts], SelectedValues) -> 65 | select_opts_values(Opts, SelectedValues). 66 | -------------------------------------------------------------------------------- /qtalk_opensource/src/ejabberd_ldap_sup.erl: -------------------------------------------------------------------------------- 1 | -module(ejabberd_ldap_sup). 2 | 3 | %% API 4 | -export([start_link/1, init/1]). 5 | 6 | -export([add_pid/1, remove_pid/1, 7 | get_pids/0, get_random_pid/0]). 8 | 9 | -export([ 10 | login/2, 11 | get_dep/0]). 12 | 13 | -define(POOLSIZE, 5). 14 | 15 | start_link(Option) -> 16 | ets:new(ldap_server_pid, [named_table, bag, public]), 17 | supervisor:start_link({local,?MODULE}, ?MODULE, [Option]). 18 | 19 | 20 | init([Option]) -> 21 | PoolSize = proplists:get_value("poolsize", Option, ?POOLSIZE), 22 | {ok, 23 | {{one_for_one, 1000, 1}, lists:map(fun(I) -> 24 | {I, 25 | {ejabberd_ldap_server, start_link, [Option]}, 26 | transient, 27 | 2000, 28 | worker, 29 | [?MODULE]} end, lists:seq(1, PoolSize)) 30 | }}. 31 | 32 | get_pids() -> 33 | case ets:tab2list(ldap_server_pid) of 34 | [] -> 35 | []; 36 | Pids when is_list(Pids) -> 37 | Pids; 38 | _ -> 39 | [] 40 | end. 41 | 42 | get_random_pid() -> 43 | case get_pids() of 44 | [] -> undefined; 45 | Pids -> {Pid} = lists:nth(erlang:phash(os:timestamp(), length(Pids)), Pids), Pid 46 | end. 47 | 48 | add_pid(Pid) -> 49 | ets:insert(ldap_server_pid,{Pid}). 50 | 51 | remove_pid(Pid) -> 52 | ets:delete_object(ldap_server_pid,{Pid}). 53 | 54 | login(User, Passwd) -> 55 | case get_random_pid() of 56 | undefined -> error; 57 | Pid -> 58 | ejabberd_ldap_server:login(Pid, User, Passwd) 59 | end. 60 | 61 | %% ejabberd_ldap_sup:get_dep(). 62 | get_dep() -> 63 | case get_random_pid() of 64 | undefined -> []; 65 | Pid -> 66 | ejabberd_ldap_server:get_dep(Pid) 67 | end. 68 | -------------------------------------------------------------------------------- /qtalk_opensource/src/ejabberd_stun.erl: -------------------------------------------------------------------------------- 1 | %%%------------------------------------------------------------------- 2 | %%% @author Evgeny Khramtsov 3 | %%% @copyright (C) 2014, Evgeny Khramtsov 4 | %%% @doc 5 | %%% 6 | %%% @end 7 | %%% Created : 8 May 2014 by Evgeny Khramtsov 8 | %%%------------------------------------------------------------------- 9 | -module(ejabberd_stun). 10 | 11 | %% API 12 | -export([tcp_init/2, udp_init/2, udp_recv/5, start/2, socket_type/0]). 13 | 14 | -include("ejabberd.hrl"). 15 | -include("logger.hrl"). 16 | 17 | %%%=================================================================== 18 | %%% API 19 | %%%=================================================================== 20 | tcp_init(Socket, Opts) -> 21 | ejabberd:start_app(p1_stun), 22 | stun:tcp_init(Socket, prepare_turn_opts(Opts)). 23 | 24 | udp_init(Socket, Opts) -> 25 | ejabberd:start_app(p1_stun), 26 | stun:udp_init(Socket, prepare_turn_opts(Opts)). 27 | 28 | udp_recv(Socket, Addr, Port, Packet, Opts) -> 29 | stun:udp_recv(Socket, Addr, Port, Packet, Opts). 30 | 31 | start(Opaque, Opts) -> 32 | stun:start(Opaque, Opts). 33 | 34 | socket_type() -> 35 | raw. 36 | 37 | %%%=================================================================== 38 | %%% Internal functions 39 | %%%=================================================================== 40 | prepare_turn_opts(Opts) -> 41 | UseTurn = proplists:get_bool(use_turn, Opts), 42 | prepare_turn_opts(Opts, UseTurn). 43 | 44 | prepare_turn_opts(Opts, _UseTurn = false) -> 45 | Opts; 46 | prepare_turn_opts(Opts, _UseTurn = true) -> 47 | NumberOfMyHosts = length(?MYHOSTS), 48 | case proplists:get_value(turn_ip, Opts) of 49 | undefined -> 50 | ?WARNING_MSG("option 'turn_ip' is undefined, " 51 | "more likely the TURN relay won't be working " 52 | "properly", []); 53 | _ -> 54 | ok 55 | end, 56 | AuthFun = fun ejabberd_auth:get_password_s/2, 57 | Shaper = gen_mod:get_opt(shaper, Opts, 58 | fun(S) when is_atom(S) -> S end, 59 | none), 60 | AuthType = gen_mod:get_opt(auth_type, Opts, 61 | fun(anonymous) -> anonymous; 62 | (user) -> user 63 | end, user), 64 | Realm = case gen_mod:get_opt(auth_realm, Opts, fun iolist_to_binary/1) of 65 | undefined when AuthType == user -> 66 | if NumberOfMyHosts > 1 -> 67 | ?WARNING_MSG("you have several virtual " 68 | "hosts configured, but option " 69 | "'auth_realm' is undefined and " 70 | "'auth_type' is set to 'user', " 71 | "more likely the TURN relay won't " 72 | "be working properly. Using ~s as " 73 | "a fallback", [?MYNAME]); 74 | true -> 75 | ok 76 | end, 77 | [{auth_realm, ?MYNAME}]; 78 | _ -> 79 | [] 80 | end, 81 | MaxRate = shaper:get_max_rate(Shaper), 82 | Realm ++ [{auth_fun, AuthFun},{shaper, MaxRate} | 83 | lists:keydelete(shaper, 1, Opts)]. 84 | -------------------------------------------------------------------------------- /qtalk_opensource/src/ejabberd_tmp_sup.erl: -------------------------------------------------------------------------------- 1 | %%%---------------------------------------------------------------------- 2 | %%% File : ejabberd_tmp_sup.erl 3 | %%% Author : Alexey Shchepin 4 | %%% Purpose : Supervisor for temporary processess 5 | %%% Created : 18 Jul 2003 by Alexey Shchepin 6 | %%% 7 | %%% 8 | %%% ejabberd, Copyright (C) 2002-2014 ProcessOne 9 | %%% 10 | %%% This program is free software; you can redistribute it and/or 11 | %%% modify it under the terms of the GNU General Public License as 12 | %%% published by the Free Software Foundation; either version 2 of the 13 | %%% License, or (at your option) any later version. 14 | %%% 15 | %%% This program is distributed in the hope that it will be useful, 16 | %%% but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | %%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 18 | %%% General Public License for more details. 19 | %%% 20 | %%% You should have received a copy of the GNU General Public License along 21 | %%% with this program; if not, write to the Free Software Foundation, Inc., 22 | %%% 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 23 | %%% 24 | %%%---------------------------------------------------------------------- 25 | 26 | -module(ejabberd_tmp_sup). 27 | 28 | -author('alexey@process-one.net'). 29 | 30 | -export([start_link/2, init/1]). 31 | -include("logger.hrl"). 32 | 33 | start_link(Name, Module) -> 34 | %% ?DEBUG("name ~p,MOduel ~p ~n",[Name,Modele]), 35 | supervisor:start_link({local, Name}, ?MODULE, Module). 36 | 37 | init(Module) -> 38 | {ok, 39 | {{simple_one_for_one, 10, 1}, 40 | [{undefined, {Module, start_link, []}, temporary, 41 | brutal_kill, worker, [Module]}]}}. 42 | -------------------------------------------------------------------------------- /qtalk_opensource/src/http_client.erl: -------------------------------------------------------------------------------- 1 | -module(http_client). 2 | 3 | -export([start_link/2]). 4 | -export([init/1, handle_call/3, handle_cast/2, handle_info/2, 5 | terminate/2,code_change/3]). 6 | -export([http_post/7,http_get/5]). 7 | -export([stop/1]). 8 | -behaviour(gen_server). 9 | 10 | -define(SERVER, ?MODULE). 11 | -include("ejabberd.hrl"). 12 | -include("logger.hrl"). 13 | 14 | -record(state, {host,pid,profile}). 15 | 16 | start_link(Host,Opts) -> 17 | gen_server:start_link(?MODULE, [Host,Opts], []). 18 | 19 | init([Host,Opts]) -> 20 | mod_http_client:add_pid(Host,self()), 21 | Seq = proplists:get_value(<<"seq">>,Opts), 22 | Profile = "http_client_" ++ integer_to_list(Seq), 23 | Pid = 24 | case erlang:whereis(list_to_atom("httpc_"++ Profile)) of 25 | P when is_pid(P) -> 26 | P; 27 | _ -> 28 | {ok, P} = inets:start(httpc, [{profile, list_to_atom(Profile)}]), 29 | P 30 | end, 31 | {ok, #state{host = Host,pid = Pid,profile = list_to_atom(Profile)}}. 32 | %%同步 33 | handle_call({http_post,Url, Header, Type, Body, HTTPOptions, Options}, _From, State) -> 34 | Method = post, 35 | Profile = State#state.profile, 36 | Return = httpc:request(Method, {Url, Header, Type, Body}, HTTPOptions, Options, Profile), 37 | {reply, Return, State}; 38 | handle_call({http_get,Url, Header, HTTPOptions, Options}, _From, State) -> 39 | Method = get, 40 | Profile = State#state.profile, 41 | Return = httpc:request(Method, {Url, Header}, HTTPOptions, Options, Profile), 42 | {reply, Return, State}; 43 | handle_call(Msg, _From, State) -> 44 | {reply, {ok, Msg}, State}. 45 | 46 | handle_cast(stop, State) -> 47 | ?DEBUG("Stop Pid ~p ~n",[self()]), 48 | inets:stop(httpc, State#state.pid), 49 | mod_http_client:remove_pid(State#state.host,self()), 50 | {stop, normal, State}. 51 | 52 | handle_info(_From,State) -> 53 | {noreply,State}. 54 | 55 | terminate(_Reason, State) -> 56 | {ok,State}. 57 | 58 | code_change(_OldVsn, State, _Extra) -> 59 | {ok, State}. 60 | 61 | stop(Name) -> 62 | gen_server:cast(Name, stop). 63 | 64 | http_post(Host,Url, Header, Type, Body, HTTPOptions, Options) -> 65 | Http_client_pid = mod_http_client:get_random_pid(Host), 66 | gen_server:call(Http_client_pid, {http_post,Url, Header, Type, Body, HTTPOptions, Options}). 67 | 68 | http_get(Host,Url,Header, HTTPOptions, Options) -> 69 | Http_client_pid = mod_http_client:get_random_pid(Host), 70 | gen_server:call(Http_client_pid, {http_get,Url, Header, HTTPOptions, Options}). 71 | 72 | -------------------------------------------------------------------------------- /qtalk_opensource/src/http_cmd.erl: -------------------------------------------------------------------------------- 1 | %zr% Feel free to use, reuse and abuse the code in this file. 2 | 3 | %% @private 4 | -module(http_cmd). 5 | 6 | %% API. 7 | -export([start/2]). 8 | -export([stop/1]). 9 | %% API. 10 | -include("logger.hrl"). 11 | 12 | start(_Type, Args) -> 13 | Dispatch = cowboy_router:compile([ 14 | {'_', [ 15 | {"/setuserkey",http_setmackey,[]}, 16 | {"/sendmessage",http_sendmessage,[]}, 17 | {"/send_warn_msg",http_send_warn_msg,[]}, 18 | {"/sendnotice",http_sendall,[]}, 19 | {"/senddeprt",http_senddep,[]}, 20 | {"/management_cmd",http_management,[]}, 21 | {"/qmonitor.jsp",http_qmonitor,[]}, 22 | {"/send_rbt_msg",http_send_rbt_msg,[]}, 23 | {"/wlan_send_msg",http_wlan_send_msg,[]}, 24 | {"/get_user_status",http_get_user_status,[]}, 25 | {"/send_muc_presence",http_muc_vcard_presence,[]}, 26 | {"/answer_http",http_answer_http,[]}, 27 | {"/create_muc",http_create_muc,[]}, 28 | {"/add_muc_user",http_add_muc_user,[]}, 29 | {"/del_muc_user",http_del_muc_user,[]}, 30 | {"/destroy_muc",http_destroy_muc,[]}, 31 | {"/get_muc_info",http_get_muc_info,[]}, 32 | {"/registeruser", http_registeruser, []} 33 | ]} 34 | ]), 35 | cowboy:stop_listener(http), 36 | Http_port = gen_mod:get_opt(http_port, Args, fun(A) -> A end, 10050), 37 | {ok,_ } = cowboy:start_http(http, 200, [{port,Http_port}], [ 38 | {env, [{dispatch, Dispatch},{max_connections, infinity}]} 39 | ]). 40 | 41 | stop(_State) -> 42 | ok. 43 | -------------------------------------------------------------------------------- /qtalk_opensource/src/http_healthcheck.erl: -------------------------------------------------------------------------------- 1 | %% Feel free to use, reuse and abuse the code in this file. 2 | 3 | -module(http_healthcheck). 4 | 5 | -export([init/3]). 6 | -export([handle/2]). 7 | -export([terminate/3]). 8 | -include("ejabberd.hrl"). 9 | -include("logger.hrl"). 10 | -include("http_req.hrl"). 11 | 12 | -record(monitor_rec,{key,count,value,time}). 13 | 14 | init(_Transport, Req, []) -> 15 | {ok, Req, undefined}. 16 | 17 | handle(Req, State) -> 18 | {Method, Req2} = cowboy_req:method(Req), 19 | case Method of 20 | <<"GET">> -> 21 | {ok, Req4} = get_echo(Method,<<"pidgin">>,Req2), 22 | {ok, Req4, State}; 23 | _ -> 24 | {ok,Req3} = echo(undefined, Req2), 25 | {ok, Req3, State} 26 | end. 27 | 28 | get_echo(<<"GET">>,Client_type,Req) -> 29 | if Client_type == <<"pidgin">>; Client_type == <<"qtalk">> -> 30 | cowboy_req:reply(200, [ 31 | ], [], Req); 32 | true -> 33 | Res2 = "Not found Client Type", 34 | cowboy_req:reply(200, [ 35 | {<<"content-type">>, <<"text/plain; charset=utf-8">>} 36 | ], Res2, Req) 37 | end; 38 | get_echo(<<"Get">>,_,Req) -> 39 | cowboy_req:reply(405, Req). 40 | 41 | echo(undefined, Req) -> 42 | cowboy_req:reply(400, [], <<"Missing parameter.">>, Req); 43 | echo(Echo, Req) -> 44 | cowboy_req:reply(200, [ 45 | {<<"content-type">>, <<"text/plain; charset=utf-8">>} 46 | ], Echo, Req). 47 | 48 | terminate(_Reason, _Req, _State) -> 49 | ok. 50 | 51 | -------------------------------------------------------------------------------- /qtalk_opensource/src/http_qmonitor.erl: -------------------------------------------------------------------------------- 1 | %% Feel free to use, reuse and abuse the code in this file. 2 | 3 | -module(http_qmonitor). 4 | 5 | -export([init/3]). 6 | -export([handle/2]). 7 | -export([terminate/3]). 8 | -include("ejabberd.hrl"). 9 | -include("logger.hrl"). 10 | -include("http_req.hrl"). 11 | 12 | -record(monitor_rec,{key,count,time}). 13 | -record(monitor_val,{key,value}). 14 | 15 | init(_Transport, Req, []) -> 16 | {ok, Req, undefined}. 17 | 18 | handle(Req, State) -> 19 | {Method, Req2} = cowboy_req:method(Req), 20 | case Method of 21 | <<"GET">> -> 22 | {ok, Req4} = get_echo(Method,<<"pidgin">>,Req2), 23 | {ok, Req4, State}; 24 | _ -> 25 | {ok,Req3} = echo(undefined, Req2), 26 | {ok, Req3, State} 27 | end. 28 | 29 | get_echo(<<"GET">>,Client_type,Req) -> 30 | if Client_type == <<"pidgin">>; Client_type == <<"qtalk">> -> 31 | Res = get_monitor_info(), 32 | cowboy_req:reply(200, [ 33 | {<<"content-type">>, <<"text/plain; charset=utf-8">>} 34 | ], Res, Req); 35 | true -> 36 | Res2 = "Not found Client Type", 37 | cowboy_req:reply(200, [ 38 | {<<"content-type">>, <<"text/plain; charset=utf-8">>} 39 | ], Res2, Req) 40 | end; 41 | get_echo(<<"Get">>,_,Req) -> 42 | cowboy_req:reply(405, Req). 43 | 44 | echo(undefined, Req) -> 45 | cowboy_req:reply(400, [], <<"Missing parameter.">>, Req); 46 | echo(Echo, Req) -> 47 | cowboy_req:reply(200, [ 48 | {<<"content-type">>, <<"text/plain; charset=utf-8">>} 49 | ], Echo, Req). 50 | 51 | terminate(_Reason, _Req, _State) -> 52 | ok. 53 | 54 | 55 | get_monitor_info() -> 56 | Monitor_sum = ets:tab2list(monitor_sum), 57 | Monitor_info = 58 | case Monitor_sum of 59 | [] -> 60 | <<"user_login_Count=0\nuser_login_Time=0\n">>; 61 | _ -> 62 | list_to_binary(lists:flatmap(fun(M) -> 63 | case erlang:is_record(M,monitor_rec) of 64 | true -> 65 | lists:concat([binary_to_list(M#monitor_rec.key),"_Count=",M#monitor_rec.count,"\n", 66 | binary_to_list(M#monitor_rec.key),"_Time=",io_lib:format("~p",[M#monitor_rec.time]),"\n"]); 67 | false -> 68 | lists:concat([binary_to_list(M#monitor_val.key),"=",M#monitor_val.value,"\n" ]) 69 | end end,Monitor_sum)) 70 | end, 71 | [{Pid, MsgNum, Attr}] = recon:proc_count(message_queue_len, 1), 72 | ?INFO_MSG("the process(~p) message_queue num is ~p, and the attr is ~p~n", [Pid, MsgNum, Attr]), 73 | NewMsgNum = integer_to_binary(MsgNum), 74 | <<"max_msg_queue=", NewMsgNum/binary,"\n", Monitor_info/binary>>. 75 | 76 | -------------------------------------------------------------------------------- /qtalk_opensource/src/iplimit_util.erl: -------------------------------------------------------------------------------- 1 | -module(iplimit_util). 2 | 3 | -export([ 4 | create_ets/0, 5 | update_iplimit/1, 6 | check_ip/1, 7 | insert_ip_limit_num/2, 8 | check_ip_limit_num/1 9 | ]). 10 | 11 | -include("ejabberd.hrl"). 12 | -include("logger.hrl"). 13 | -include("http_req.hrl"). 14 | 15 | create_ets() -> 16 | ?DEBUG("create ets iplimit~n", []), 17 | catch ets:new(iplimit, [set, named_table, public, {keypos, 1},{write_concurrency, true}, {read_concurrency, true}]), 18 | catch ets:new(ip_limit_num, [set, named_table, public, {keypos, 1},{write_concurrency, true}, {read_concurrency, true}]). 19 | 20 | update_iplimit(Server) -> 21 | ets:delete_all_objects(iplimit), 22 | case catch odbc_queries:get_iplimit(jlib:nameprep(Server)) of 23 | {selected,[<<"ip">>],SRes} 24 | when is_list(SRes) -> 25 | lists:foreach(fun([IP]) -> 26 | ets:insert(iplimit,{IP}) end,SRes); 27 | _ -> 28 | ok 29 | end. 30 | 31 | check_ip_limit_num(IP) -> 32 | case ets:lookup(ip_limit_num,IP) of 33 | [{_,Num,_}] when Num > 3 -> 34 | false; 35 | _ -> 36 | true 37 | end. 38 | 39 | insert_ip_limit_num(IP,Timestamp) -> 40 | case ets:lookup(ip_limit_num,IP) of 41 | [{_,Num,Time}] -> 42 | N1 = Time / 60, 43 | N2 = Timestamp / 60, 44 | if N1 == N2 -> 45 | ets:insert(ip_limit_num,{IP,Num+1,Timestamp}); 46 | true -> 47 | ets:insert(ip_limit_num,{IP,0,Timestamp}) 48 | end; 49 | [] -> 50 | ets:insert(ip_limit_num,{IP,1,Timestamp}) 51 | end. 52 | 53 | %%-------------------------------------------------------------------- 54 | %% @date 2015-06-02 55 | %% 该函数取出HTTP Headers中的X-Real_IP字段,然后查看该IP是否存在于配 56 | %% 置中,存在返回true,否则返回false 57 | %% 我们需要在ejabberd.yml中添加如下配置: 58 | %% limited_ips: 59 | %% - "192.168.168.1" 60 | %% - "192.168.168.2" 61 | %% 或者 62 | %% limited_ips: all 63 | %% 64 | %% 如果没有配置,则允许所有用户访问 65 | %% 我们可以通过该函数来判断访问来源的有效性 66 | %%-------------------------------------------------------------------- 67 | 68 | check_ip(Req) -> 69 | LimitedIPs = ets:tab2list(iplimit), 70 | {Headers, _} = cowboy_req:headers(Req), 71 | IP = proplists:get_value(<<"x-real-ip">>, Headers), 72 | ?DEBUG("the x-real-ip is ~p~n", [IP]), 73 | check_ip(IP, LimitedIPs). 74 | 75 | check_ip(_IP, []) -> 76 | true; 77 | check_ip(undefined, _) -> 78 | false; 79 | check_ip(IP, LimitedIPs) -> 80 | lists:member({IP}, LimitedIPs). 81 | 82 | -------------------------------------------------------------------------------- /qtalk_opensource/src/memory_free.erl: -------------------------------------------------------------------------------- 1 | -module(memory_free). 2 | 3 | -export([find_max_memory_process/1,memory_free/1]). 4 | 5 | -include("logger.hrl"). 6 | 7 | 8 | find_max_memory_process(Num) -> 9 | ProcessL = processes() -- [self()], 10 | AttrName = memory, 11 | F = fun(Pid, L) -> 12 | case process_info(Pid, [AttrName, registered_name, current_function, initial_call]) of 13 | [Attr, Name, Init, Cur] -> 14 | Info = {Attr, [{pid, Pid}, Name, Init, Cur]}, 15 | [Info | L]; 16 | undefined -> 17 | L 18 | end end, 19 | ProInfoL = lists:foldl(F, [], ProcessL), 20 | CompF = fun({A, _},{B, _}) -> A > B end, 21 | ProInfoSortL = lists:usort(CompF, ProInfoL), 22 | lists:sublist(ProInfoSortL, Num). 23 | 24 | memory_free(Num) -> 25 | L = find_max_memory_process(Num), 26 | lists:foreach(fun({_,Info}) -> 27 | Pid = proplists:get_value(pid,Info), 28 | erlang:garbage_collect(Pid), 29 | ?DEBUG("Pid ~p ~n",[Pid]) end,L). 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /qtalk_opensource/src/mod_asy_sql.erl: -------------------------------------------------------------------------------- 1 | -module(mod_asy_sql). 2 | 3 | -behaviour(gen_mod). 4 | 5 | -define(PROCNAME, mod_asy_sql). 6 | -define(SERVER, ?MODULE). 7 | 8 | -define(DEFAULT_POOL_SIZE, 35). 9 | 10 | -include("ejabberd.hrl"). 11 | -include("logger.hrl"). 12 | -export([start/2,stop/1]). 13 | -export([start_link/2,init/1]). 14 | -export([add_pid/2, remove_pid/2, get_pids/1, get_random_pid/1]). 15 | 16 | start(Host, Opts)-> 17 | Proc = get_proc_name(Host), 18 | catch ets:new(asy_sql_pid, [named_table, bag, public]), 19 | ChildSpec = {Proc,{?MODULE, start_link,[Host,Opts]}, permanent, infinity,supervisor,[Proc]}, 20 | {ok, _Pid} = supervisor:start_child(ejabberd_sup, ChildSpec). 21 | 22 | start_link(Host,Opts) -> 23 | case supervisor:start_link({local, ?SERVER}, ?MODULE, [Host,Opts]) of 24 | {ok, Pid} -> 25 | {ok, Pid}; 26 | {error, Reason} -> 27 | ?INFO_MSG("Supervisor ~p start error ,reason ~p. ~n",[?MODULE,Reason]) 28 | end. 29 | 30 | init([Host,Opts]) -> 31 | PoolSize = gen_mod:get_opt(pool_size, Opts, fun(A) -> A end, ?DEFAULT_POOL_SIZE), 32 | {ok, 33 | {{one_for_one, ?DEFAULT_POOL_SIZE * 10, 1}, 34 | lists:map(fun (I) -> 35 | {I, 36 | {asy_sql, start_link, 37 | [Host, 20 * 1000]}, 38 | transient, 2000, worker, [?MODULE]} 39 | end, 40 | lists:seq(1, PoolSize))}}. 41 | 42 | get_pids(Host) -> 43 | case ets:lookup(asy_sql_pid,Host) of 44 | [] -> 45 | []; 46 | Rs when is_list(Rs) -> 47 | lists:flatmap(fun(B) -> 48 | [element(2,B)] 49 | end,Rs); 50 | _ -> 51 | [] 52 | end. 53 | 54 | get_random_pid(Host) -> 55 | case get_pids(Host) of 56 | [] -> none; 57 | Pids -> lists:nth(erlang:phash(os:timestamp(), length(Pids)), Pids) 58 | end. 59 | 60 | add_pid(Host,Pid) -> 61 | ets:insert(asy_sql_pid,{Host,Pid}). 62 | 63 | remove_pid(Host,Pid) -> 64 | ets:delete_object(asy_sql_pid,{Host,Pid}). 65 | 66 | stop_child() -> 67 | lists:foreach(fun({_,Pid}) -> 68 | gen_server:cast(Pid, stop) end,ets:tab2list(asy_sql_pid)). 69 | 70 | stop(Host) -> 71 | Proc = get_proc_name(Host), 72 | supervisor:terminate_child(ejabberd_sup, Proc), 73 | supervisor:delete_child(ejabberd_sup, Proc), 74 | stop_child(), 75 | catch ets:delete(asy_sql_pid). 76 | 77 | get_proc_name(Host) -> 78 | gen_mod:get_module_proc(Host, ?PROCNAME). 79 | -------------------------------------------------------------------------------- /qtalk_opensource/src/mod_cowboy.erl: -------------------------------------------------------------------------------- 1 | -module(mod_cowboy). 2 | 3 | -export([start_link/1]). 4 | -export([init/1, handle_call/3, handle_cast/2, handle_info/2, 5 | terminate/2,code_change/3]). 6 | -behaviour(gen_server). 7 | 8 | -define(SERVER, ?MODULE). 9 | -include("ejabberd.hrl"). 10 | 11 | -record(state, {info}). 12 | 13 | start_link(Info) -> 14 | gen_server:start_link(?MODULE, [], [Info]). 15 | 16 | init(Info) -> 17 | {ok, #state{info = ok}, 0}. 18 | 19 | handle_call(Msg, _From, State) -> 20 | {reply, {ok, Msg}, State}. 21 | 22 | handle_cast(stop, State) -> 23 | {stop, normal, State}. 24 | 25 | handle_info(timeout, State) -> 26 | cowboy_app:start(1,2), 27 | {noreply,State}. 28 | 29 | terminate(_Reason, State) -> 30 | {ok,State}. 31 | 32 | code_change(_OldVsn, State, _Extra) -> 33 | {ok, State}. 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /qtalk_opensource/src/mod_friend.erl: -------------------------------------------------------------------------------- 1 | -module(mod_friend). 2 | 3 | -behaviour(gen_mod). 4 | -behaviour(supervisor). 5 | 6 | -export([start/2,stop/1]). 7 | -export([start_link/2,init/1]). 8 | 9 | -include("ejabberd.hrl"). 10 | -include("logger.hrl"). 11 | 12 | -record(state,{server}). 13 | -record(user_friends,{user,friends,unfriends}). 14 | 15 | %%==================================================================== 16 | %% API 17 | %%==================================================================== 18 | %%-------------------------------------------------------------------- 19 | %% Function: start_link() -> {ok,Pid} | ignore | {error,Error} 20 | %% Description: Starts the server 21 | %%-------------------------------------------------------------------- 22 | 23 | start(Host, Opts)-> 24 | Proc = get_proc_name(Host), 25 | ChildSpec = {Proc,{?MODULE, start_link,[Host,Opts]}, permanent, infinity,supervisor,[Proc]}, 26 | {ok, _Pid} = supervisor:start_child(ejabberd_sup, ChildSpec). 27 | 28 | stop(Host) -> 29 | Proc = get_proc_name(Host), 30 | supervisor:terminate_child(ejabberd_sup, Proc), 31 | supervisor:delete_child(ejabberd_sup, Proc), 32 | ok. 33 | 34 | start_link(Host,Opts) -> 35 | supervisor:start_link({local, ?MODULE}, ?MODULE, [Host,Opts]). 36 | %% supervisor:start_link({local, ?MODULE}, ?MODULE, [Host,Opts], []). 37 | 38 | %%==================================================================== 39 | %% gen_server callbacks 40 | %%==================================================================== 41 | 42 | %%-------------------------------------------------------------------- 43 | %% Function: init(Args) -> {ok, State} | 44 | %% {ok, State, Timeout} | 45 | %% ignore | 46 | %% {stop, Reason} 47 | %% Description: Initiates the server 48 | %%-------------------------------------------------------------------- 49 | 50 | init([Host,Opts]) -> 51 | Recv_msg_limit = {recv_msg_limit,{mod_recv_msg_limit,start_link,[Host,Opts]},permanent, infinity,supervisor,[recv_msg_limit]}, 52 | User_Relationship = {mod_user_relation,{mod_user_relation,start_link,[Host,Opts]},permanent, infinity,supervisor,[mod_user_relation]}, 53 | 54 | {ok, {{rest_for_one, 5, 10}, [Recv_msg_limit,User_Relationship]}}. 55 | 56 | get_proc_name(Host) -> 57 | gen_mod:get_module_proc(Host, ?MODULE). 58 | -------------------------------------------------------------------------------- /qtalk_opensource/src/mod_hash.erl: -------------------------------------------------------------------------------- 1 | -module(mod_hash). 2 | 3 | -behaviour(gen_mod). 4 | -behaviour(supervisor). 5 | 6 | -export([start/2,stop/1]). 7 | -export([start_link/2,init/1]). 8 | 9 | -include("ejabberd.hrl"). 10 | -include("logger.hrl"). 11 | 12 | start(Host, Opts)-> 13 | Proc = get_proc_name(Host), 14 | catch ets:new(hash_user_pid,[set, named_table, public, {keypos, 1},{write_concurrency, true}, {read_concurrency, true}]), 15 | catch ets:new(friend_opts, [set, named_table, public, {keypos, 2},{write_concurrency, true}, {read_concurrency, true}]), 16 | catch ets:new(user_friends, [set, named_table, public, {keypos, 2},{write_concurrency, true}, {read_concurrency, true}]), 17 | catch ets:new(recv_msg_limit, [set, named_table, public, {keypos, 2},{write_concurrency, true}, {read_concurrency, true}]), 18 | ChildSpec = {Proc,{?MODULE, start_link,[Host,Opts]}, permanent, infinity,supervisor,[Proc]}, 19 | {ok, _Pid} = supervisor:start_child(ejabberd_sup, ChildSpec). 20 | %% catch mod_hash_nodes:send_mnesia_update(Host,10) 21 | 22 | stop(Host) -> 23 | Proc = get_proc_name(Host), 24 | supervisor:terminate_child(ejabberd_sup, Proc), 25 | supervisor:delete_child(ejabberd_sup, Proc), 26 | ok. 27 | 28 | start_link(Host,Opts) -> 29 | supervisor:start_link({local, ?MODULE}, ?MODULE, [Host,Opts]). 30 | 31 | init([Host,Opts]) -> 32 | Hash_nodes = {mod_hash_nodes,{mod_hash_nodes,start_link,[Host,Opts]},permanent, infinity,worker,[mod_hash_nodes]}, 33 | Hash_users = {mod_hash_user, {mod_hash_user,start_link,[Host,Opts]},permanent, infinity,worker,[mod_hash_user]}, 34 | 35 | {ok, {{rest_for_one, 5, 10}, [Hash_nodes,Hash_users]}}. 36 | 37 | get_proc_name(Host) -> 38 | gen_mod:get_module_proc(Host, ?MODULE). 39 | -------------------------------------------------------------------------------- /qtalk_opensource/src/mod_http_client.erl: -------------------------------------------------------------------------------- 1 | -module(mod_http_client). 2 | 3 | -behaviour(gen_mod). 4 | 5 | -define(PROCNAME, mod_http_client). 6 | -define(SERVER, ?MODULE). 7 | 8 | -include("ejabberd.hrl"). 9 | -include("logger.hrl"). 10 | -export([start/2,stop/1]). 11 | -export([start_link/2,init/1]). 12 | -export([add_pid/2, remove_pid/2,get_pids/1, get_random_pid/1]). 13 | 14 | -define(DEFAULT_POOL_SIZE, 65). 15 | 16 | start(Host, Opts)-> 17 | ets:new(http_client_pid, [named_table, bag, public]), 18 | ChildSpec = {?MODULE,{?MODULE, start_link,[Host,Opts]}, permanent, infinity,supervisor,[?MODULE]}, 19 | {ok, _Pid} = supervisor:start_child(ejabberd_sup, ChildSpec). 20 | 21 | start_link(Host,Opts) -> 22 | case supervisor:start_link({local, ?SERVER}, ?MODULE, [Host,Opts]) of 23 | {ok, Pid} -> 24 | {ok, Pid}; 25 | {error, Reason} -> 26 | ?INFO_MSG("Supervisor ~p start error,reason: ~p . ~n",[?MODULE,Reason]) 27 | end. 28 | 29 | init([Host,Opts]) -> 30 | PoolSize = gen_mod:get_opt(pool_size, Opts, fun(A) -> A end, ?DEFAULT_POOL_SIZE), 31 | {ok, 32 | {{one_for_one, ?DEFAULT_POOL_SIZE * 10, 1}, 33 | lists:map(fun (I) -> 34 | {I, 35 | {http_client, start_link, 36 | [Host, Opts ++ [{<<"seq">>,I}]]}, 37 | transient, 2000, worker, [?MODULE]} 38 | end, 39 | lists:seq(1, PoolSize))}}. 40 | 41 | get_pids(Host) -> 42 | case ets:lookup(http_client_pid,Host) of 43 | [] -> 44 | []; 45 | Rs when is_list(Rs) -> 46 | lists:flatmap(fun(B) -> 47 | [element(2,B)] 48 | end,Rs); 49 | _ -> 50 | [] 51 | end. 52 | 53 | get_random_pid(Host) -> 54 | case get_pids(Host) of 55 | [] -> 56 | none; 57 | Pids -> 58 | lists:nth(erlang:phash(os:timestamp(), length(Pids)), Pids) 59 | end. 60 | 61 | add_pid(Host,Pid) -> 62 | ets:insert(http_client_pid,{Host,Pid}). 63 | 64 | remove_pid(Host,Pid) -> 65 | ets:delete_object(http_client_pid,{Host,Pid}). 66 | 67 | stop_child() -> 68 | lists:foreach(fun({_,Pid}) -> 69 | gen_server:cast(Pid, stop) end,ets:tab2list(http_client_pid)). 70 | 71 | stop(Host) -> 72 | supervisor:terminate_child(ejabberd_sup, ?MODULE), 73 | supervisor:delete_child(ejabberd_sup, ?MODULE), 74 | stop_child(), 75 | catch ets:delete(http_client_pid). 76 | 77 | 78 | -------------------------------------------------------------------------------- /qtalk_opensource/src/mod_http_cmd.erl: -------------------------------------------------------------------------------- 1 | -module(mod_http_cmd). 2 | 3 | -behaviour(gen_mod). 4 | 5 | -define(PROCNAME, mod_http_cmd). 6 | -define(SERVER, ?MODULE). 7 | 8 | -include("ejabberd.hrl"). 9 | -include("logger.hrl"). 10 | -export([start/2,stop/1]). 11 | -export([start_link/1,init/1]). 12 | 13 | start(Host, Opts)-> 14 | %% rpc 调用频繁失败时调用,不建议打开改模块,该接口不宜暴露 15 | Proc = get_proc_name(Host), 16 | ChildSpec = {Proc,{?MODULE, start_link,[Opts]}, permanent, infinity,supervisor,[Proc]}, 17 | {ok, _Pid} = supervisor:start_child(ejabberd_sup, ChildSpec). 18 | 19 | start_link(Opts) -> 20 | case supervisor:start_link({local, ?SERVER}, ?MODULE, [Opts]) of 21 | {ok, Pid} -> 22 | {ok, Pid}; 23 | {error, Reason} -> 24 | ?DEBUG(" supervisor start error ~p ",[Reason]) 25 | end. 26 | 27 | init([Opts]) -> 28 | Http_get = {mod_http_get, {mod_http_get,start_link, [Opts]}, permanent, brutal_kill, worker, [mod_http_get]}, 29 | {ok, {{one_for_one, 10, 1},[Http_get]}}. 30 | 31 | stop(Host) -> 32 | Proc = get_proc_name(Host), 33 | supervisor:terminate_child(ejabberd_sup, Proc), 34 | supervisor:delete_child(ejabberd_sup, Proc), 35 | ok. 36 | 37 | get_proc_name(Host) -> 38 | gen_mod:get_module_proc(Host, ?PROCNAME). 39 | 40 | -------------------------------------------------------------------------------- /qtalk_opensource/src/mod_http_get.erl: -------------------------------------------------------------------------------- 1 | -module(mod_http_get). 2 | 3 | -export([start_link/1]). 4 | -export([init/1, handle_call/3, handle_cast/2, handle_info/2, 5 | terminate/2,code_change/3]). 6 | -behaviour(gen_server). 7 | 8 | -define(SERVER, ?MODULE). 9 | -include("ejabberd.hrl"). 10 | -include("logger.hrl"). 11 | 12 | -record(state, {info}). 13 | 14 | start_link(Info) -> 15 | gen_server:start_link(?MODULE, [Info], [Info]). 16 | 17 | init([Info]) -> 18 | {ok, #state{info = Info}, 0}. 19 | 20 | handle_call(Msg, _From, State) -> 21 | {reply, {ok, Msg}, State}. 22 | 23 | handle_cast(stop, State) -> 24 | {stop, normal, State}. 25 | 26 | handle_info(timeout,State = #state{info = Opts} ) -> 27 | http_cmd:start(1,Opts), 28 | {noreply,State}. 29 | 30 | terminate(_Reason, State) -> 31 | {ok,State}. 32 | 33 | code_change(_OldVsn, State, _Extra) -> 34 | {ok, State}. 35 | 36 | -------------------------------------------------------------------------------- /qtalk_opensource/src/mod_log_chat.erl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/may-liu/qtalk/f5431e5a7123975e9656e7ab239e674ce33713cd/qtalk_opensource/src/mod_log_chat.erl -------------------------------------------------------------------------------- /qtalk_opensource/src/mod_mnesia_monitor.erl: -------------------------------------------------------------------------------- 1 | -module(mod_mnesia_monitor). 2 | 3 | -behaviour(gen_server). 4 | -behaviour(gen_mod). 5 | 6 | -export([start/2,stop/1,start_link/2,init/1]). 7 | 8 | -export([handle_call/3, handle_cast/2, 9 | handle_info/2, terminate/2, code_change/3]). 10 | 11 | -include("ejabberd.hrl"). 12 | -include("logger.hrl"). 13 | 14 | -define(SERVER, ?MODULE). 15 | 16 | -record(state,{}). 17 | 18 | start(Host,Opts) -> 19 | Proc = get_proc_name(Host), 20 | ChildSpec = {Proc,{?MODULE, start_link, [Host,Opts]}, temporary,1000,worker,[?MODULE]}, 21 | {ok,_Pid} = supervisor:start_child(ejabberd_sup, ChildSpec). 22 | 23 | stop(Host) -> 24 | Proc = get_proc_name(Host), 25 | supervisor:terminate_child(ejabberd_sup, Proc), 26 | supervisor:delete_child(ejabberd_sup, Proc). 27 | 28 | start_link(Server,Opts) -> 29 | gen_server:start_link({local, get_proc_name(Server)}, ?MODULE, [Server,Opts], []). 30 | 31 | init([_Server,_Opts]) -> 32 | {ok, _} = mnesia:subscribe(system), 33 | {ok, #state{}}. 34 | 35 | 36 | handle_call(_Request, _From, State) -> 37 | {reply, ignored, State}. 38 | 39 | handle_cast(_Msg, State) -> 40 | {noreply, State}. 41 | 42 | handle_info({mnesia_system_event, 43 | {inconsistent_database, running_partitioned_network, Node}},State) -> 44 | catch mnesia:change_config(extra_db_nodes,['ejabberd@l-ejab1.vc.cn5']), 45 | {noreply, State}; 46 | handle_info({mnesia_system_event, 47 | {inconsistent_database, starting_partitioned_network, Node}},State) -> 48 | catch mnesia:change_config(extra_db_nodes,['ejabberd@l-ejab1.vc.cn5']), 49 | {noreply, State}; 50 | handle_info({mnesia_system_event, 51 | Info},State) -> 52 | ?ERROR_MSG("catch mnesia_system_event ~p ~n",[Info]), 53 | {noreply, State}; 54 | handle_info(_Info, State) -> 55 | {noreply, State}. 56 | 57 | code_change(_OldVsn, State, _Extra) -> 58 | {ok, State}. 59 | 60 | terminate(_Reason, _State) -> 61 | ok. 62 | 63 | get_proc_name(Host) -> 64 | gen_mod:get_module_proc(Host, ?MODULE). 65 | 66 | -------------------------------------------------------------------------------- /qtalk_opensource/src/mod_msg_id_queue.erl: -------------------------------------------------------------------------------- 1 | -module(mod_msg_id_queue). 2 | 3 | -behaviour(gen_mod). 4 | 5 | -define(PROCNAME, mod_msg_id_queue). 6 | -define(SERVER, ?MODULE). 7 | 8 | -include("ejabberd.hrl"). 9 | -include("logger.hrl"). 10 | -export([start/2,stop/1]). 11 | -export([start_link/2,init/1]). 12 | -export([add_pid/2, remove_pid/2,get_pids/1, get_random_pid/1,get_pid_by_id/2]). 13 | 14 | -define(DEFAULT_POOL_SIZE, 20). 15 | 16 | start(Host, Opts)-> 17 | catch ets:new(msg_id_queue_pid, [named_table, bag, public]), 18 | Proc = get_proc_name(Host), 19 | ChildSpec = {Proc,{?MODULE, start_link,[Host,Opts]}, permanent, infinity,supervisor,[Proc]}, 20 | {ok, _Pid} = supervisor:start_child(ejabberd_sup, ChildSpec). 21 | 22 | start_link(Host,Opts) -> 23 | case supervisor:start_link({local, ?SERVER}, ?MODULE, [Host,Opts]) of 24 | {ok, Pid} -> 25 | {ok, Pid}; 26 | {error, Reason} -> 27 | ?INFO_MSG("Supervisor ~p start error,reason: ~p . ~n",[?MODULE,Reason]) 28 | end. 29 | 30 | init([Host,Opts]) -> 31 | PoolSize = gen_mod:get_opt(pool_size, Opts, fun(A) -> A end, ?DEFAULT_POOL_SIZE), 32 | {ok, 33 | {{one_for_one, ?DEFAULT_POOL_SIZE * 10, 1}, 34 | lists:map(fun (I) -> 35 | {I, 36 | {msg_id_queue, start_link, 37 | [Host, Opts]}, 38 | transient, 2000, worker, [?MODULE]} 39 | end, 40 | lists:seq(1, PoolSize))}}. 41 | 42 | get_pids(Host) -> 43 | case ets:lookup(msg_id_queue_pid,Host) of 44 | [] -> 45 | []; 46 | Rs when is_list(Rs) -> 47 | lists:flatmap(fun(B) -> 48 | [element(2,B)] 49 | end,Rs); 50 | _ -> 51 | [] 52 | end. 53 | 54 | get_random_pid(Host) -> 55 | case get_pids(Host) of 56 | [] -> none; 57 | Pids -> lists:nth(erlang:phash(os:timestamp(), length(Pids)), Pids) 58 | end. 59 | 60 | get_pid_by_id(Host,ID) -> 61 | case get_pids(Host) of 62 | [] -> none; 63 | Pids -> lists:nth(erlang:phash(ID, length(Pids)), Pids) 64 | end. 65 | 66 | add_pid(Host,Pid) -> 67 | ets:insert(msg_id_queue_pid,{Host,Pid}). 68 | 69 | remove_pid(Host,Pid) -> 70 | ets:delete_object(msg_id_queue_pid,{Host,Pid}). 71 | 72 | 73 | stop_child() -> 74 | lists:foreach(fun({_,Pid}) -> 75 | gen_server:cast(Pid, stop) end,ets:tab2list(msg_id_queue_pid)). 76 | 77 | stop(Host) -> 78 | Proc = get_proc_name(Host), 79 | supervisor:terminate_child(ejabberd_sup, Proc), 80 | supervisor:delete_child(ejabberd_sup, Proc), 81 | stop_child(), 82 | catch ets:delete(msg_id_queue_pid). 83 | 84 | get_proc_name(Host) -> 85 | gen_mod:get_module_proc(Host, ?PROCNAME). 86 | 87 | -------------------------------------------------------------------------------- /qtalk_opensource/src/mod_muc_subscribe.erl: -------------------------------------------------------------------------------- 1 | -module(mod_muc_subscribe). 2 | 3 | -behaviour(gen_mod). 4 | 5 | -define(PROCNAME, mod_muc_subscribe). 6 | -define(SERVER, ?MODULE). 7 | 8 | -define(DEFAULT_POOL_SIZE, 9). 9 | 10 | -include("ejabberd.hrl"). 11 | -include("logger.hrl"). 12 | -export([start/2,stop/1]). 13 | -export([start_link/2,init/1]). 14 | -export([add_pid/2, remove_pid/2,get_pids/1, get_random_pid/1]). 15 | 16 | start(Host, Opts)-> 17 | Proc = get_proc_name(Host), 18 | catch ets:new(subscribe_msg_pid, [named_table, bag, public]), 19 | ChildSpec = {Proc,{?MODULE, start_link,[Host,Opts]}, permanent, infinity,supervisor,[Proc]}, 20 | {ok, _Pid} = supervisor:start_child(ejabberd_sup, ChildSpec). 21 | 22 | start_link(Host,Opts) -> 23 | case supervisor:start_link({local, ?SERVER}, ?MODULE, [Host,Opts]) of 24 | {ok, Pid} -> 25 | {ok, Pid}; 26 | {error, Reason} -> 27 | ?DEBUG(" supervisor ~p start error ~p ",[?MODULE,Reason]) 28 | end. 29 | 30 | init([Host,Opts]) -> 31 | PoolSize = gen_mod:get_opt(pool_size, Opts, fun(A) -> A end, ?DEFAULT_POOL_SIZE), 32 | {ok, 33 | {{one_for_one, ?DEFAULT_POOL_SIZE * 10, 1}, 34 | lists:map(fun (I) -> 35 | {I, 36 | {subscribe_msg, start_link, 37 | [Host, 50 * 1000]}, 38 | transient, 2000, worker, [?MODULE]} 39 | end, 40 | lists:seq(1, PoolSize))}}. 41 | 42 | get_pids(Host) -> 43 | case ets:lookup(subscribe_msg_pid,Host) of 44 | [] -> 45 | []; 46 | Rs when is_list(Rs) -> 47 | lists:flatmap(fun(B) -> 48 | [element(2,B)] 49 | end,Rs); 50 | _ -> 51 | [] 52 | end. 53 | 54 | get_random_pid(Host) -> 55 | case get_pids(Host) of 56 | [] -> none; 57 | Pids -> lists:nth(erlang:phash(os:timestamp(), length(Pids)), Pids) 58 | end. 59 | 60 | add_pid(Host,Pid) -> 61 | ets:insert(subscribe_msg_pid,{Host,Pid}). 62 | 63 | remove_pid(Host,Pid) -> 64 | ets:delete_object(subscribe_msg_pid,{Host,Pid}). 65 | 66 | stop_child() -> 67 | lists:foreach(fun({_,Pid}) -> 68 | gen_server:cast(Pid, stop) end,ets:tab2list(subscribe_msg_pid)). 69 | 70 | stop(Host) -> 71 | Proc = get_proc_name(Host), 72 | supervisor:terminate_child(ejabberd_sup, Proc), 73 | supervisor:delete_child(ejabberd_sup, Proc), 74 | stop_child(), 75 | catch ets:delete(subscribe_msg_pid). 76 | 77 | get_proc_name(Host) -> 78 | gen_mod:get_module_proc(Host, ?PROCNAME). 79 | 80 | -------------------------------------------------------------------------------- /qtalk_opensource/src/mod_proxy65_lib.erl: -------------------------------------------------------------------------------- 1 | %%%---------------------------------------------------------------------- 2 | %%% File : mod_proxy65_lib.erl 3 | %%% Author : Evgeniy Khramtsov 4 | %%% Purpose : SOCKS5 parsing library. 5 | %%% Created : 12 Oct 2006 by Evgeniy Khramtsov 6 | %%% 7 | %%% 8 | %%% ejabberd, Copyright (C) 2002-2014 ProcessOne 9 | %%% 10 | %%% This program is free software; you can redistribute it and/or 11 | %%% modify it under the terms of the GNU General Public License as 12 | %%% published by the Free Software Foundation; either version 2 of the 13 | %%% License, or (at your option) any later version. 14 | %%% 15 | %%% This program is distributed in the hope that it will be useful, 16 | %%% but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | %%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 18 | %%% General Public License for more details. 19 | %%% 20 | %%% You should have received a copy of the GNU General Public License along 21 | %%% with this program; if not, write to the Free Software Foundation, Inc., 22 | %%% 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 23 | %%% 24 | %%%---------------------------------------------------------------------- 25 | 26 | -module(mod_proxy65_lib). 27 | 28 | -author('xram@jabber.ru'). 29 | 30 | -include("mod_proxy65.hrl"). 31 | 32 | -export([unpack_init_message/1, unpack_auth_request/1, 33 | unpack_request/1, make_init_reply/1, make_auth_reply/1, 34 | make_reply/1, make_error_reply/1, make_error_reply/2]). 35 | 36 | unpack_init_message(<<(?VERSION_5), N, 37 | AuthMethodList:N/binary>>) 38 | when N > 0, N < 256 -> 39 | {ok, binary_to_list(AuthMethodList)}; 40 | unpack_init_message(_) -> error. 41 | 42 | unpack_auth_request(<<1, ULen, User:ULen/binary, PLen, 43 | Pass:PLen/binary>>) 44 | when ULen < 256, PLen < 256 -> 45 | {(User), (Pass)}; 46 | unpack_auth_request(_) -> error. 47 | 48 | unpack_request(<<(?VERSION_5), CMD, RSV, 49 | (?ATYP_DOMAINNAME), 40, SHA1:40/binary, 0, 0>>) 50 | when CMD == (?CMD_CONNECT); CMD == (?CMD_UDP) -> 51 | Command = if CMD == (?CMD_CONNECT) -> connect; 52 | CMD == (?CMD_UDP) -> udp 53 | end, 54 | #s5_request{cmd = Command, rsv = RSV, sha1 = (SHA1)}; 55 | unpack_request(_) -> error. 56 | 57 | make_init_reply(Method) -> [?VERSION_5, Method]. 58 | 59 | make_auth_reply(true) -> [1, ?SUCCESS]; 60 | make_auth_reply(false) -> [1, ?ERR_NOT_ALLOWED]. 61 | 62 | make_reply(#s5_request{rsv = RSV, sha1 = SHA1}) -> 63 | [?VERSION_5, ?SUCCESS, RSV, ?ATYP_DOMAINNAME, 64 | byte_size(SHA1), SHA1, 0, 0]. 65 | 66 | make_error_reply(Request) -> 67 | make_error_reply(Request, ?ERR_NOT_ALLOWED). 68 | 69 | make_error_reply(#s5_request{rsv = RSV, sha1 = SHA1}, 70 | Reason) -> 71 | [?VERSION_5, Reason, RSV, ?ATYP_DOMAINNAME, 72 | byte_size(SHA1), SHA1, 0, 0]. 73 | -------------------------------------------------------------------------------- /qtalk_opensource/src/msg_id_queue.erl: -------------------------------------------------------------------------------- 1 | -module(msg_id_queue). 2 | 3 | -behaviour(gen_server). 4 | -export([start_link/2,init/1]). 5 | 6 | -export([handle_call/3, handle_cast/2, 7 | handle_info/2, terminate/2, code_change/3,queue_in/2]). 8 | 9 | -include("ejabberd.hrl"). 10 | -include("logger.hrl"). 11 | 12 | -define(SERVER, ?MODULE). 13 | -define(MAXSIZE, 300). 14 | 15 | -record(state,{server,msg_queue,max_size,queue_in_timer}). 16 | 17 | start_link(Host,Opts) -> 18 | gen_server:start_link(?MODULE, [Host,Opts], []). 19 | 20 | init([Server,_Opts]) -> 21 | mod_msg_id_queue:add_pid(Server,self()), 22 | Timer_Tref = 23 | erlang:start_timer(5000,self(),update_queue), 24 | {ok, #state{server = Server,max_size = ?MAXSIZE,queue_in_timer = Timer_Tref,msg_queue = queue:new()}}. 25 | 26 | handle_call(stop, _From, State=#state{queue_in_timer = Timer_Tref}) -> 27 | {ok, cancel} = timer:cancel(Timer_Tref), 28 | {stop, normal, stopped, State}; 29 | handle_call(_Request, _From, State) -> 30 | {reply, ignored, State}. 31 | 32 | handle_cast({in, Msg}, State = #state{max_size=Max,msg_queue=OldQueue}) -> 33 | Queue = 34 | case queue:member(Msg,OldQueue) of 35 | true -> 36 | ?INFO_MSG("ID [~p] is already in queue. ~n",[Msg]), 37 | OldQueue; 38 | _ -> 39 | case Max =< queue:len(OldQueue) of 40 | true -> 41 | Q1 = queue:liat(OldQueue), 42 | queue:in(Msg, Q1); 43 | _ -> 44 | queue:in(Msg,OldQueue) 45 | end 46 | end, 47 | 48 | {noreply, State#state{msg_queue = Queue}}; 49 | handle_cast(_Msg, State) -> 50 | {noreply, State}. 51 | 52 | handle_info({timeout, TimerRef, update_queue},State=#state{server = Server,msg_queue = Queue}) -> 53 | case erlang:read_timer(TimerRef) of 54 | false -> 55 | do_update_msg_id(Server,Queue), 56 | New_Timer_Tref = erlang:start_timer(5000,self(),update_queue), 57 | NewQueue = queue:new(), 58 | NewState = State#state{queue_in_timer = New_Timer_Tref,msg_queue = NewQueue}, 59 | {noreply, NewState}; 60 | _ -> 61 | do_update_msg_id(Server,Queue), 62 | NewQueue = queue:new(), 63 | NewState = State#state{msg_queue = NewQueue}, 64 | {noreply, NewState} 65 | end; 66 | handle_info(_Info, State) -> 67 | {noreply, State}. 68 | 69 | terminate(_Reason, State=#state{server = Host}) -> 70 | mod_msg_id_queue:remove_pid(Host,self()), 71 | ok. 72 | 73 | code_change(_OldVsn, State, _Extra) -> 74 | {ok, State}. 75 | 76 | get_proc_name(Host) -> 77 | gen_mod:get_module_proc(Host, ?MODULE). 78 | 79 | do_update_msg_id(Host,Queue) -> 80 | IDs = queue:to_list(Queue), 81 | case IDs of 82 | [] -> 83 | ok; 84 | _ -> 85 | catch asy_sql:update_readmark_by_id(Host,IDs) 86 | end. 87 | 88 | queue_in(Msg,Host) -> 89 | gen_server:cast(mod_msg_id_queue:get_pid_by_id(Host,Msg), {in, Msg}). 90 | -------------------------------------------------------------------------------- /qtalk_opensource/src/pubsub_index.erl: -------------------------------------------------------------------------------- 1 | %%% ==================================================================== 2 | %%% ``The contents of this file are subject to the Erlang Public License, 3 | %%% Version 1.1, (the "License"); you may not use this file except in 4 | %%% compliance with the License. You should have received a copy of the 5 | %%% Erlang Public License along with this software. If not, it can be 6 | %%% retrieved via the world wide web at http://www.erlang.org/. 7 | %%% 8 | %%% 9 | %%% Software distributed under the License is distributed on an "AS IS" 10 | %%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See 11 | %%% the License for the specific language governing rights and limitations 12 | %%% under the License. 13 | %%% 14 | %%% 15 | %%% The Initial Developer of the Original Code is ProcessOne. 16 | %%% Portions created by ProcessOne are Copyright 2006-2014, ProcessOne 17 | %%% All Rights Reserved.'' 18 | %%% This software is copyright 2006-2014, ProcessOne. 19 | %%% 20 | %%% 21 | %%% @copyright 2006-2014 ProcessOne 22 | %%% @author Christophe Romain 23 | %%% [http://www.process-one.net/] 24 | %%% @version {@vsn}, {@date} {@time} 25 | %%% @end 26 | %%% ==================================================================== 27 | 28 | %% important note: 29 | %% new/1 and free/2 MUST be called inside a transaction bloc 30 | 31 | -module(pubsub_index). 32 | 33 | -author('christophe.romain@process-one.net'). 34 | 35 | -include("pubsub.hrl"). 36 | 37 | -export([init/3, new/1, free/2]). 38 | 39 | init(_Host, _ServerHost, _Opts) -> 40 | mnesia:create_table(pubsub_index, 41 | [{disc_copies, [node()]}, 42 | {attributes, record_info(fields, pubsub_index)}]). 43 | 44 | new(Index) -> 45 | case mnesia:read({pubsub_index, Index}) of 46 | [I] -> 47 | case I#pubsub_index.free of 48 | [] -> 49 | Id = I#pubsub_index.last + 1, 50 | mnesia:write(I#pubsub_index{last = Id}), 51 | Id; 52 | [Id | Free] -> 53 | mnesia:write(I#pubsub_index{free = Free}), Id 54 | end; 55 | _ -> 56 | mnesia:write(#pubsub_index{index = Index, last = 1, 57 | free = []}), 58 | 1 59 | end. 60 | 61 | free(Index, Id) -> 62 | case mnesia:read({pubsub_index, Index}) of 63 | [I] -> 64 | Free = I#pubsub_index.free, 65 | mnesia:write(I#pubsub_index{free = [Id | Free]}); 66 | _ -> ok 67 | end. 68 | -------------------------------------------------------------------------------- /qtalk_opensource/src/randoms.erl: -------------------------------------------------------------------------------- 1 | %%%---------------------------------------------------------------------- 2 | %%% File : randoms.erl 3 | %%% Author : Alexey Shchepin 4 | %%% Purpose : Random generation number wrapper 5 | %%% Created : 13 Dec 2002 by Alexey Shchepin 6 | %%% 7 | %%% 8 | %%% ejabberd, Copyright (C) 2002-2014 ProcessOne 9 | %%% 10 | %%% This program is free software; you can redistribute it and/or 11 | %%% modify it under the terms of the GNU General Public License as 12 | %%% published by the Free Software Foundation; either version 2 of the 13 | %%% License, or (at your option) any later version. 14 | %%% 15 | %%% This program is distributed in the hope that it will be useful, 16 | %%% but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | %%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 18 | %%% General Public License for more details. 19 | %%% 20 | %%% You should have received a copy of the GNU General Public License along 21 | %%% with this program; if not, write to the Free Software Foundation, Inc., 22 | %%% 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 23 | %%% 24 | %%%---------------------------------------------------------------------- 25 | 26 | -module(randoms). 27 | 28 | -author('alexey@process-one.net'). 29 | 30 | -export([get_string/0]). 31 | 32 | -export([start/0, init/0]). 33 | 34 | start() -> 35 | register(random_generator, spawn(randoms, init, [])). 36 | 37 | init() -> 38 | {A1, A2, A3} = os:timestamp(), random:seed(A1, A2, A3), loop(). 39 | 40 | loop() -> 41 | receive 42 | {From, get_random, N} -> 43 | From ! {random, random:uniform(N)}, loop(); 44 | _ -> loop() 45 | end. 46 | 47 | get_string() -> 48 | random_generator ! {self(), get_random, 65536 * 65536}, 49 | receive 50 | {random, R} -> jlib:integer_to_binary(R) 51 | end. 52 | -------------------------------------------------------------------------------- /qtalk_opensource/src/subscribe_msg_sup.erl: -------------------------------------------------------------------------------- 1 | %%%---------------------------------------------------------------------- 2 | %%% File : ejabberd_odbc_sup.erl 3 | %%% Author : Alexey Shchepin 4 | %%% Purpose : ODBC connections supervisor 5 | %%% Created : 22 Dec 2004 by Alexey Shchepin 6 | %%% 7 | %%% 8 | %%% ejabberd, Copyright (C) 2002-2014 ProcessOne 9 | %%% 10 | %%% This program is free software; you can redistribute it and/or 11 | %%% modify it under the terms of the GNU General Public License as 12 | %%% published by the Free Software Foundation; either version 2 of the 13 | %%% License, or (at your option) any later version. 14 | %%% 15 | %%% This program is distributed in the hope that it will be useful, 16 | %%% but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | %%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 18 | %%% General Public License for more details. 19 | %%% 20 | %%% You should have received a copy of the GNU General Public License along 21 | %%% with this program; if not, write to the Free Software Foundation, Inc., 22 | %%% 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 23 | %%% 24 | %%%---------------------------------------------------------------------- 25 | 26 | -module(subscribe_msg_sup). 27 | 28 | %% API 29 | -export([start_link/1, init/1, add_pid/2, remove_pid/2, 30 | get_pids/1, get_random_pid/1]). 31 | 32 | -include("ejabberd.hrl"). 33 | -include("logger.hrl"). 34 | 35 | -define(DEFAULT_POOL_SIZE, 8). 36 | 37 | -define(DEFAULT_START_INTERVAL, 30). 38 | 39 | -define(CONNECT_TIMEOUT, 500). 40 | 41 | start_link(Opts) -> 42 | Servers = ejabberd_config:get_myhosts(), 43 | Host = lists:nth(1,Servers), 44 | ets:new(subscribe_msg_pid, [named_table, bag, public]), 45 | supervisor:start_link({local, 46 | gen_mod:get_module_proc(Host, ?MODULE)}, 47 | ?MODULE, [Host,Opts]). 48 | 49 | init([Host,Opts]) -> 50 | PoolSize = ?DEFAULT_POOL_SIZE, 51 | StartInterval = ?DEFAULT_START_INTERVAL, 52 | {ok, 53 | {{one_for_one, ?DEFAULT_POOL_SIZE * 10, 1}, 54 | lists:map(fun (I) -> 55 | {I, 56 | {subscribe_msg, start_link, 57 | [Host, StartInterval * 1000]}, 58 | transient, 2000, worker, [?MODULE]} 59 | end, 60 | lists:seq(1, PoolSize))}}. 61 | 62 | get_pids(Host) -> 63 | case ets:lookup(subscribe_msg_pid,Host) of 64 | [] -> 65 | []; 66 | Rs when is_list(Rs) -> 67 | lists:flatmap(fun(B) -> 68 | [element(2,B)] 69 | end,Rs); 70 | _ -> 71 | [] 72 | end. 73 | 74 | get_random_pid(Host) -> 75 | case get_pids(Host) of 76 | [] -> none; 77 | Pids -> lists:nth(erlang:phash(os:timestamp(), length(Pids)), Pids) 78 | end. 79 | 80 | add_pid(Host,Pid) -> 81 | ets:insert(subscribe_msg_pid,{Host,Pid}). 82 | 83 | remove_pid(Host,Pid) -> 84 | ets:delete_object(subscribe_msg_pid,{Host,Pid}). 85 | 86 | -------------------------------------------------------------------------------- /qtalk_opensource/src/sync_ets_cache.erl: -------------------------------------------------------------------------------- 1 | -module(sync_ets_cache). 2 | 3 | -export([send_sync_node_notcie/5,send_sync_nodes_notcie/4,send_async_node_notcie/5]). 4 | 5 | -include("logger.hrl"). 6 | 7 | 8 | send_sync_nodes_notcie(Server,Module,Function,Args) -> 9 | Nodes = [node()] ++ nodes() , 10 | lists:map(fun(Node) -> 11 | send_sync_node_notcie(Server,Node,Module,Function,Args) 12 | end,Nodes). 13 | 14 | send_sync_node_notcie(Server,Node,Module,Function,Args) -> 15 | case catch rpc:call(Node,Module,Function,Args) of 16 | {badrpc, Reason} -> 17 | {Node,{error,Reason}}; 18 | Res -> 19 | {Node,{sucess,Res}} 20 | end. 21 | 22 | 23 | 24 | send_async_node_notcie(Server,Node,Module,Function,Args) -> 25 | case catch rpc:async_call(Node,Module,Function,Args) of 26 | {badrpc, Reason} -> 27 | {Node,{error,Reason}}; 28 | Res -> 29 | {Node,{sucess,Res}} 30 | end. 31 | -------------------------------------------------------------------------------- /qtalk_opensource/src/tea_crypto.erl: -------------------------------------------------------------------------------- 1 | -module(tea_crypto). 2 | -export([encrypt/2,decrypt/2]). 3 | -define(DELTA,16#9e3779b9). 4 | -define(MAX,16#FFFFFFFF). 5 | 6 | encrypt(V, K) when erlang:is_binary(K) and erlang:is_binary(V) and 7 | (erlang:size(K) == 16) -> 8 | encrypt(V, K, <<>>); 9 | encrypt(_, _) -> 10 | erlang:error(badarg). 11 | 12 | encrypt(<>, K, Acc) -> 13 | R = do_encrypt(V, K), 14 | encrypt(Rest, K, <>); 15 | encrypt(V, _K, Acc) -> 16 | <>. 17 | 18 | do_encrypt(V,K) when erlang:is_binary(K) and erlang:is_binary(V) and 19 | (erlang:size(V) == 8) and (erlang:size(K) == 16)-> 20 | <> = V, 21 | <> = K, 22 | encrypt_compute(0,V0,V1,K0,K1,K2,K3,0); 23 | do_encrypt(_,_) -> 24 | erlang:error(badarg). 25 | 26 | encrypt_compute(32,V0,V1,_K0,_K1,_K2,_K3,_Sum)-> 27 | <>; 28 | encrypt_compute(I,V0,V1,K0,K1,K2,K3,Sum)-> 29 | Sum1 = Sum + ?DELTA, 30 | V1K0 = V1 bsl 4 + K0, 31 | V1Sum = V1 + Sum1, 32 | V1K1 = (V1 bsr 5) + K1, 33 | NewV0 = (V0 + ((V1K0 bxor V1Sum) bxor V1K1) ) band ?MAX, 34 | V0K2 = NewV0 bsl 4 + K2, 35 | V0Sum = NewV0 + Sum1, 36 | V0K3 = (NewV0 bsr 5) + K3 , 37 | NewV1 = (V1 +((V0K2 bxor V0Sum) bxor V0K3)) band ?MAX, 38 | encrypt_compute(I + 1,NewV0,NewV1,K0,K1,K2,K3,Sum1). 39 | 40 | decrypt(V, K) when erlang:is_binary(K) and erlang:is_binary(V) and 41 | (erlang:size(K) == 16) -> 42 | decrypt(V, K, <<>>); 43 | decrypt(_, _) -> 44 | erlang:error(badarg). 45 | 46 | decrypt(<>, K, Acc) -> 47 | R = do_decrypt(V, K), 48 | decrypt(Rest, K, <>); 49 | decrypt(V, _K, Acc) -> 50 | <>. 51 | 52 | do_decrypt(V,K) when erlang:is_binary(K) and erlang:is_binary(V) and 53 | (erlang:size(V) == 8) and (erlang:size(K) == 16)-> 54 | <> = V, 55 | <> = K, 56 | decrypt_compute(0,V0,V1,K0,K1,K2,K3,16#c6ef3720); 57 | do_decrypt(_,_) -> 58 | erlang:error(badarg). 59 | 60 | decrypt_compute(32,V0,V1,_K0,_K1,_K2,_K3,_Sum)-> 61 | <>; 62 | decrypt_compute(I,V0,V1,K0,K1,K2,K3,Sum)-> 63 | V0K2 = V0 bsl 4 + K2, 64 | V0Sum = V0 + Sum, 65 | V0K3 = (V0 bsr 5) + K3 , 66 | NewV1 = (V1 - (((V0K2 bxor V0Sum) bxor V0K3) band ?MAX)) band ?MAX, 67 | 68 | V1K0 = NewV1 bsl 4 + K0, 69 | V1Sum = NewV1 + Sum, 70 | V1K1 = (NewV1 bsr 5) + K1, 71 | NewV0 = (V0 - (((V1K0 bxor V1Sum) bxor V1K1) band ?MAX)) band ?MAX, 72 | Sum1 = Sum - ?DELTA, 73 | decrypt_compute(I + 1,NewV0,NewV1,K0,K1,K2,K3,Sum1). 74 | -------------------------------------------------------------------------------- /qtalk_opensource/test/README: -------------------------------------------------------------------------------- 1 | You need MySQL, PostgreSQL and Riak up and running. 2 | MySQL should be accepting TCP connections on localhost:3306. 3 | PostgreSQL should be accepting TCP connections on localhost:5432. 4 | Riak should be accepting TCP connections on localhost:8087. 5 | MySQL and PostgreSQL should grant full access to user 'ejabberd_test' with 6 | password 'ejabberd_test' on database 'ejabberd_test'. 7 | Riak should be configured with leveldb as a database backend and -pz 8 | should be pointed to the directory with ejabberd BEAM files. 9 | 10 | Here is a quick setup example: 11 | 12 | ------------------ 13 | PostgreSQL 14 | ------------------ 15 | $ psql template1 16 | template1=# CREATE USER ejabberd_test WITH PASSWORD 'ejabberd_test'; 17 | template1=# CREATE DATABASE ejabberd_test; 18 | template1=# GRANT ALL PRIVILEGES ON DATABASE ejabberd_test TO ejabberd_test; 19 | 20 | ------------------- 21 | MySQL 22 | ------------------- 23 | $ mysql 24 | mysql> CREATE USER 'ejabberd_test'@'localhost' IDENTIFIED BY 'ejabberd_test'; 25 | mysql> CREATE DATABASE ejabberd_test; 26 | mysql> GRANT ALL ON ejabberd_test.* TO 'ejabberd_test'@'localhost'; 27 | 28 | ------------------- 29 | Riak 30 | ------------------- 31 | $ cat /etc/riak/vm.args 32 | ... 33 | ## Map/Reduce path 34 | -pz /path/to/ejabberd/ebin 35 | ... 36 | 37 | For version < 2.x: 38 | 39 | $ cat /etc/riak/app.config: 40 | ... 41 | {riak_kv, [ 42 | {storage_backend, riak_kv_eleveldb_backend}, 43 | ... 44 | 45 | For version >= 2.x: 46 | 47 | $ cat /etc/riak/riak.conf: 48 | ... 49 | storage_backend = leveldb 50 | ... 51 | -------------------------------------------------------------------------------- /qtalk_opensource/test/ejabberd_SUITE_data/ejabberd.ldif: -------------------------------------------------------------------------------- 1 | dn: dc=localhost 2 | dc: localhost 3 | objectclass: dcObject 4 | 5 | dn: cn=admin,dc=localhost 6 | cn: admin 7 | objectclass: organizationalRole 8 | 9 | dn: ou=users,dc=localhost 10 | ou: users 11 | objectClass: organizationalUnit 12 | 13 | dn: uid=test_single,ou=users,dc=localhost 14 | uid: test_single 15 | mail: test_single@localhost 16 | objectClass: person 17 | jpegPhoto:: /9g= 18 | cn: Test Single 19 | password: password 20 | 21 | dn: uid=test_master,ou=users,dc=localhost 22 | uid: test_master 23 | mail: test_master@localhost 24 | objectClass: person 25 | jpegPhoto:: /9g= 26 | cn: Test Master 27 | password: password 28 | 29 | dn: uid=test_slave,ou=users,dc=localhost 30 | uid: test_slave 31 | mail: test_slave@localhost 32 | objectClass: person 33 | jpegPhoto:: /9g= 34 | cn: Test Slave 35 | password: password 36 | -------------------------------------------------------------------------------- /qtalk_opensource/test/ejabberd_SUITE_data/extauth.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import struct 3 | 4 | def read(): 5 | (pkt_size,) = struct.unpack('>H', sys.stdin.read(2)) 6 | pkt = sys.stdin.read(pkt_size).split(':') 7 | cmd = pkt[0] 8 | args_num = len(pkt) - 1 9 | if cmd == 'auth' and args_num == 3: 10 | write(True) 11 | elif cmd == 'isuser' and args_num == 2: 12 | write(True) 13 | elif cmd == 'setpass' and args_num == 3: 14 | write(True) 15 | elif cmd == 'tryregister' and args_num == 3: 16 | write(True) 17 | elif cmd == 'removeuser' and args_num == 2: 18 | write(True) 19 | elif cmd == 'removeuser3' and args_num == 3: 20 | write(True) 21 | else: 22 | write(False) 23 | read() 24 | 25 | def write(result): 26 | if result: 27 | sys.stdout.write('\x00\x02\x00\x01') 28 | else: 29 | sys.stdout.write('\x00\x02\x00\x00') 30 | sys.stdout.flush() 31 | 32 | if __name__ == "__main__": 33 | try: 34 | read() 35 | except struct.error: 36 | pass 37 | -------------------------------------------------------------------------------- /qtalk_opensource/test/suite.hrl: -------------------------------------------------------------------------------- 1 | -include_lib("common_test/include/ct.hrl"). 2 | -include_lib("p1_xml/include/xml.hrl"). 3 | -include("ns.hrl"). 4 | -include("ejabberd.hrl"). 5 | -include("mod_proxy65.hrl"). 6 | -include("xmpp_codec.hrl"). 7 | 8 | -define(STREAM_HEADER, 9 | <<"">>). 13 | 14 | -define(STREAM_TRAILER, <<"">>). 15 | 16 | -define(PUBSUB(Node), <<(?NS_PUBSUB)/binary, "#", Node>>). 17 | 18 | -define(EJABBERD_CT_URI, <<"http://www.process-one.net/en/ejabberd_ct/">>). 19 | 20 | -define(recv2(P1, P2), 21 | (fun() -> 22 | case {R1 = recv(), R2 = recv()} of 23 | {P1, P2} -> {R1, R2}; 24 | {P2, P1} -> {R2, R1} 25 | end 26 | end)()). 27 | 28 | -define(recv3(P1, P2, P3), 29 | (fun() -> 30 | case R3 = recv() of 31 | P1 -> insert(R3, 1, ?recv2(P2, P3)); 32 | P2 -> insert(R3, 2, ?recv2(P1, P3)); 33 | P3 -> insert(R3, 3, ?recv2(P1, P2)) 34 | end 35 | end)()). 36 | 37 | -define(recv4(P1, P2, P3, P4), 38 | (fun() -> 39 | case R4 = recv() of 40 | P1 -> insert(R4, 1, ?recv3(P2, P3, P4)); 41 | P2 -> insert(R4, 2, ?recv3(P1, P3, P4)); 42 | P3 -> insert(R4, 3, ?recv3(P1, P2, P4)); 43 | P4 -> insert(R4, 4, ?recv3(P1, P2, P3)) 44 | end 45 | end)()). 46 | 47 | -define(recv5(P1, P2, P3, P4, P5), 48 | (fun() -> 49 | case R5 = recv() of 50 | P1 -> insert(R5, 1, ?recv4(P2, P3, P4, P5)); 51 | P2 -> insert(R5, 2, ?recv4(P1, P3, P4, P5)); 52 | P3 -> insert(R5, 3, ?recv4(P1, P2, P4, P5)); 53 | P4 -> insert(R5, 4, ?recv4(P1, P2, P3, P5)); 54 | P5 -> insert(R5, 5, ?recv4(P1, P2, P3, P4)) 55 | end 56 | end)()). 57 | 58 | -define(COMMON_VHOST, <<"localhost">>). 59 | -define(MNESIA_VHOST, <<"mnesia.localhost">>). 60 | -define(MYSQL_VHOST, <<"mysql.localhost">>). 61 | -define(PGSQL_VHOST, <<"pgsql.localhost">>). 62 | -define(LDAP_VHOST, <<"ldap.localhost">>). 63 | -define(EXTAUTH_VHOST, <<"extauth.localhost">>). 64 | -define(RIAK_VHOST, <<"riak.localhost">>). 65 | 66 | insert(Val, N, Tuple) -> 67 | L = tuple_to_list(Tuple), 68 | {H, T} = lists:split(N-1, L), 69 | list_to_tuple(H ++ [Val|T]). 70 | -------------------------------------------------------------------------------- /qtalk_opensource/tools/captcha.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | INPUT=$1 4 | 5 | if test -n ${BASH_VERSION:-''} ; then 6 | get_random () 7 | { 8 | R=$RANDOM 9 | } 10 | else 11 | for n in `od -A n -t u2 -N 48 /dev/urandom`; do RL="$RL$n "; done 12 | get_random () 13 | { 14 | R=${RL%% *} 15 | RL=${RL#* } 16 | } 17 | fi 18 | 19 | get_random 20 | WAVE1_AMPLITUDE=$((2 + $R % 5)) 21 | get_random 22 | WAVE1_LENGTH=$((50 + $R % 25)) 23 | get_random 24 | WAVE2_AMPLITUDE=$((2 + $R % 5)) 25 | get_random 26 | WAVE2_LENGTH=$((50 + $R % 25)) 27 | get_random 28 | WAVE3_AMPLITUDE=$((2 + $R % 5)) 29 | get_random 30 | WAVE3_LENGTH=$((50 + $R % 25)) 31 | get_random 32 | W1_LINE_START_Y=$((10 + $R % 40)) 33 | get_random 34 | W1_LINE_STOP_Y=$((10 + $R % 40)) 35 | get_random 36 | W2_LINE_START_Y=$((10 + $R % 40)) 37 | get_random 38 | W2_LINE_STOP_Y=$((10 + $R % 40)) 39 | get_random 40 | W3_LINE_START_Y=$((10 + $R % 40)) 41 | get_random 42 | W3_LINE_STOP_Y=$((10 + $R % 40)) 43 | 44 | get_random 45 | B1_LINE_START_Y=$(($R % 40)) 46 | get_random 47 | B1_LINE_STOP_Y=$(($R % 40)) 48 | get_random 49 | B2_LINE_START_Y=$(($R % 40)) 50 | get_random 51 | B2_LINE_STOP_Y=$(($R % 40)) 52 | #B3_LINE_START_Y=$(($R % 40)) 53 | #B3_LINE_STOP_Y=$(($R % 40)) 54 | 55 | get_random 56 | B1_LINE_START_X=$(($R % 20)) 57 | get_random 58 | B1_LINE_STOP_X=$((100 + $R % 40)) 59 | get_random 60 | B2_LINE_START_X=$(($R % 20)) 61 | get_random 62 | B2_LINE_STOP_X=$((100 + $R % 40)) 63 | #B3_LINE_START_X=$(($R % 20)) 64 | #B3_LINE_STOP_X=$((100 + $R % 40)) 65 | 66 | get_random 67 | ROLL_X=$(($R % 40)) 68 | 69 | convert -size 180x60 xc:none -pointsize 40 \ 70 | \( -clone 0 -fill white \ 71 | -stroke black -strokewidth 4 -annotate +0+40 "$INPUT" \ 72 | -stroke white -strokewidth 2 -annotate +0+40 "$INPUT" \ 73 | -roll +$ROLL_X+0 \ 74 | -wave "$WAVE1_AMPLITUDE"x"$WAVE1_LENGTH" \ 75 | -roll -$ROLL_X+0 \) \ 76 | \( -clone 0 -stroke black \ 77 | -strokewidth 1 -draw \ 78 | "line $B1_LINE_START_X,$B1_LINE_START_Y $B1_LINE_STOP_X,$B1_LINE_STOP_Y" \ 79 | -strokewidth 1 -draw \ 80 | "line $B2_LINE_START_X,$B2_LINE_START_Y $B2_LINE_STOP_X,$B2_LINE_STOP_Y" \ 81 | -wave "$WAVE2_AMPLITUDE"x"$WAVE2_LENGTH" \) \ 82 | \( -clone 0 -stroke white \ 83 | -strokewidth 2 -draw "line 0,$W1_LINE_START_Y 140,$W1_LINE_STOP_Y" \ 84 | -strokewidth 2 -draw "line 0,$W2_LINE_START_Y 140,$W2_LINE_STOP_Y" \ 85 | -strokewidth 2 -draw "line 0,$W3_LINE_START_Y 140,$W3_LINE_STOP_Y" \ 86 | -wave "$WAVE3_AMPLITUDE"x"$WAVE3_LENGTH" \) \ 87 | -flatten -crop 140x60 +repage -quality 90 -depth 8 png:- 88 | -------------------------------------------------------------------------------- /qtalk_opensource/vars.config: -------------------------------------------------------------------------------- 1 | %%%------------------------------------------------------------------- 2 | %%% @author Evgeniy Khramtsov 3 | %%% @copyright (C) 2013, Evgeniy Khramtsov 4 | %%% @doc 5 | %%% 6 | %%% @end 7 | %%% Created : 8 May 2013 by Evgeniy Khramtsov 8 | %%%------------------------------------------------------------------- 9 | %% Macros 10 | {roster_gateway_workaround, false}. 11 | {transient_supervisors, false}. 12 | {full_xml, true}. 13 | {nif, false}. 14 | {db_type, generic}. 15 | {debug, true}. 16 | {hipe, false}. 17 | 18 | %% Ad-hoc directories with source files 19 | {tools, false}. 20 | 21 | %% Dependencies 22 | {odbc, true}. 23 | {mysql, false}. 24 | {pgsql, false}. 25 | {pam, false}. 26 | {zlib, true}. 27 | {riak, false}. 28 | {json, false}. 29 | {http, false}. 30 | {lager, true}. 31 | {iconv, true}. 32 | 33 | %% Version 34 | {vsn, "14.07"}. 35 | 36 | %% Variables for overlay template files 37 | 38 | %% Platform-specific installation paths 39 | {release, true}. 40 | {release_dir, "${SCRIPT_DIR%/*}"}. 41 | {sysconfdir, "{{release_dir}}/etc"}. 42 | {installuser, ""}. 43 | {erl, "{{release_dir}}/{{erts_vsn}}/bin/erl"}. 44 | {localstatedir, "{{release_dir}}/var"}. 45 | {libdir, "{{release_dir}}/lib"}. 46 | {docdir, "{{release_dir}}/doc"}. 47 | 48 | %% Local Variables: 49 | %% mode: erlang 50 | %% End: 51 | %% vim: set filetype=erlang tabstop=8: 52 | -------------------------------------------------------------------------------- /qtalk_opensource/vars.config.in: -------------------------------------------------------------------------------- 1 | %%%------------------------------------------------------------------- 2 | %%% @author Evgeniy Khramtsov 3 | %%% @copyright (C) 2013, Evgeniy Khramtsov 4 | %%% @doc 5 | %%% 6 | %%% @end 7 | %%% Created : 8 May 2013 by Evgeniy Khramtsov 8 | %%%------------------------------------------------------------------- 9 | %% Macros 10 | {roster_gateway_workaround, @roster_gateway_workaround@}. 11 | {transient_supervisors, @transient_supervisors@}. 12 | {full_xml, @full_xml@}. 13 | {nif, @nif@}. 14 | {db_type, @db_type@}. 15 | {debug, @debug@}. 16 | {hipe, @hipe@}. 17 | 18 | %% Ad-hoc directories with source files 19 | {tools, @tools@}. 20 | 21 | %% Dependencies 22 | {odbc, @odbc@}. 23 | {mysql, @mysql@}. 24 | {pgsql, @pgsql@}. 25 | {pam, @pam@}. 26 | {zlib, @zlib@}. 27 | {riak, @riak@}. 28 | {json, @json@}. 29 | {http, @http@}. 30 | {lager, @lager@}. 31 | {iconv, @iconv@}. 32 | 33 | %% Version 34 | {vsn, "@PACKAGE_VERSION@"}. 35 | 36 | %% Variables for overlay template files 37 | 38 | %% Platform-specific installation paths 39 | {release, true}. 40 | {release_dir, "${SCRIPT_DIR%/*}"}. 41 | {sysconfdir, "{{release_dir}}/etc"}. 42 | {installuser, "@INSTALLUSER@"}. 43 | {erl, "{{release_dir}}/{{erts_vsn}}/bin/erl"}. 44 | {localstatedir, "{{release_dir}}/var"}. 45 | {libdir, "{{release_dir}}/lib"}. 46 | {docdir, "{{release_dir}}/doc"}. 47 | 48 | %% Local Variables: 49 | %% mode: erlang 50 | %% End: 51 | %% vim: set filetype=erlang tabstop=8: 52 | -------------------------------------------------------------------------------- /qtalk_opensource/win32/CheckReqs.ini: -------------------------------------------------------------------------------- 1 | [Settings] 2 | NumFields=2 3 | 4 | [Field 1] 5 | Type=label 6 | Left=0 7 | Right=-1 8 | Top=10 9 | Bottom=70 10 | Text="Erlang OTP R10B-7 (version 5.4.9) or newer is required to install Ejabberd.\r\n\r\nIt is not found on your computer.\r\n\r\nPlease install Erlang OTP R10B-7 or newer before installing Ejabberd.\r\n\r\nIts installer can be downloaded from" 11 | 12 | [Field 2] 13 | Type=link 14 | Left=0 15 | Right=-1 16 | Top=74 17 | Bottom=88 18 | State=http://www.erlang.org/download.html 19 | Text=http://www.erlang.org/download.html 20 | 21 | -------------------------------------------------------------------------------- /qtalk_opensource/win32/CheckReqs1.ini: -------------------------------------------------------------------------------- 1 | [Settings] 2 | NumFields=3 3 | 4 | [Field 1] 5 | Type=label 6 | Left=0 7 | Right=-1 8 | Top=10 9 | Bottom=70 10 | Text="OpenSLL 0.9.7i or newer is not found on your computer.\r\n\r\nTo use SSL and TLS encryption you need an SSL certificate. You can create a selfsigned certificate with OpenSSL.\r\n\r\nOpenSLL installer can be downloaded from" 11 | 12 | [Field 2] 13 | Type=link 14 | Left=0 15 | Right=-1 16 | Top=74 17 | Bottom=88 18 | State=http://www.slproweb.com/products/Win32OpenSSL.html 19 | Text=http://www.slproweb.com/products/Win32OpenSSL.html 20 | 21 | [Field 3] 22 | Type=label 23 | Left=0 24 | Right=-1 25 | Top=93 26 | Bottom=-10 27 | Text="If you want to continue installing Ejabberd anyway, click Next." 28 | 29 | -------------------------------------------------------------------------------- /qtalk_opensource/win32/CheckReqs1H.ini: -------------------------------------------------------------------------------- 1 | [Settings] 2 | NumFields=3 3 | 4 | [Field 1] 5 | Type=label 6 | Left=0 7 | Right=-1 8 | Top=10 9 | Bottom=70 10 | Text="OpenSLL 0.9.7i or newer is not found on your computer.\r\n\r\nTo use SSL and TLS encryption you need an SSL certificate. You can create a selfsigned certificate with OpenSSL.\r\n\r\nOpenSLL installer can be downloaded from" 11 | 12 | [Field 2] 13 | Type=link 14 | Left=0 15 | Right=-1 16 | Top=74 17 | Bottom=88 18 | State=http://www.slproweb.com/products/Win32OpenSSL.html 19 | Text=http://www.slproweb.com/products/Win32OpenSSL.html 20 | 21 | [Field 3] 22 | Type=checkbox 23 | Left=0 24 | Right=-1 25 | Top=93 26 | Bottom=105 27 | Text="I want to continue installing Ejabberd anyway" 28 | State=0 29 | Flags=NOTIFY 30 | -------------------------------------------------------------------------------- /qtalk_opensource/win32/CheckService.ini: -------------------------------------------------------------------------------- 1 | [Settings] 2 | NumFields=2 3 | 4 | [Field 1] 5 | Type=label 6 | Left=0 7 | Right=-1 8 | Top=10 9 | Bottom=50 10 | Text="You are installing Ejabberd as Administrator.\r\n\r\nEjabberd will be installed as a Windows service." 11 | 12 | [Field 2] 13 | Type=checkbox 14 | Left=0 15 | Right=-1 16 | Top=50 17 | Bottom=62 18 | Text="Configure ejabberd service to start automatically" 19 | State=1 20 | -------------------------------------------------------------------------------- /qtalk_opensource/win32/CheckUser.ini: -------------------------------------------------------------------------------- 1 | [Settings] 2 | NumFields=1 3 | 4 | [Field 1] 5 | Type=label 6 | Left=0 7 | Right=-1 8 | Top=10 9 | Bottom=-10 10 | Text="Administrator privileges are recommended for Ejabberd install.\r\n\r\nOtherwise installing Ejabberd as a service will be impossible.\r\n\r\nIf you want to continue installing Ejabberd anyway, click Next." 11 | 12 | -------------------------------------------------------------------------------- /qtalk_opensource/win32/CheckUserH.ini: -------------------------------------------------------------------------------- 1 | [Settings] 2 | NumFields=2 3 | 4 | [Field 1] 5 | Type=label 6 | Left=0 7 | Right=-1 8 | Top=10 9 | Bottom=50 10 | Text="Administrator privileges are recommended for Ejabberd install.\r\n\r\nOtherwise installing Ejabberd as a service will be impossible." 11 | 12 | [Field 2] 13 | Type=checkbox 14 | Left=0 15 | Right=-1 16 | Top=50 17 | Bottom=62 18 | Text="I want to continue installing Ejabberd anyway" 19 | State=0 20 | Flags=NOTIFY 21 | -------------------------------------------------------------------------------- /qtalk_opensource/win32/ejabberd.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/may-liu/qtalk/f5431e5a7123975e9656e7ab239e674ce33713cd/qtalk_opensource/win32/ejabberd.ico -------------------------------------------------------------------------------- /qtalk_opensource/win32/ejabberd_header.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/may-liu/qtalk/f5431e5a7123975e9656e7ab239e674ce33713cd/qtalk_opensource/win32/ejabberd_header.bmp -------------------------------------------------------------------------------- /qtalk_opensource/win32/ejabberd_intro.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/may-liu/qtalk/f5431e5a7123975e9656e7ab239e674ce33713cd/qtalk_opensource/win32/ejabberd_intro.bmp -------------------------------------------------------------------------------- /qtalk_opensource/win32/inetrc: -------------------------------------------------------------------------------- 1 | {registry, win32}. 2 | --------------------------------------------------------------------------------