diff --git a/ChangeLog b/ChangeLog index bab9c8ba7..f6d775207 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,1121 @@ +===================== 2020-06-22 Version 5.3.5 Released ===================== + +===================== Changes Since Version 5.3.4 =========================== + +commit d8e36aeb0c7b0ba08911454d724d3a69a7766810 +Author: Daniel-Constantin Mierla +Date: Mon Jun 22 11:46:19 2020 +0200 + + Makefile.defs: version set to 5.3.5 + +commit 089708b310b94171fa12084fa0eca9f98854b7f6 +Author: Daniel-Constantin Mierla +Date: Mon Jun 22 11:44:58 2020 +0200 + + pkg/kamailio: updated version to 5.3.5 for rpms and alpine specs + +commit 12386b2f4cc33f3ee0ea366ddcf48b124d2265aa +Author: Victor Seva +Date: Tue Jun 9 12:02:43 2020 +0200 + + sqlops: export sql_pvquery to KEMI + + (cherry picked from commit 3b2a0a849e60a6bf0bc9d8054568c954010d7aa6) + +commit 3a0e46df3c456cb7d5fc090caf5108fc62a8e9e8 +Author: Victor Seva +Date: Thu Jun 11 10:48:29 2020 +0200 + + avpops: export functions to KEMI + + * avp_check + * avp_copy + + (cherry picked from commit adf7fb2613c4117ea0a76463d2df55e14579da9f) + +commit 21e697728dc0b40cbd094c5d1c9de61eeeba5aea +Author: Victor Seva +Date: Mon Jun 22 09:19:57 2020 +0200 + + pkg/kamailio/deb: version set 5.3.5 + +commit 12b4bf66d3380f1e48023987db3d137f5be31e21 +Author: Kamailio Dev +Date: Mon Jun 22 08:31:46 2020 +0200 + + modules: readme files regenerated - modules ... [skip ci] + +commit d232e2e48b1b668270dcab419638adeffa5cf0b2 +Author: Daniel-Constantin Mierla +Date: Mon Jun 22 08:22:55 2020 +0200 + + uac: docs - updated examples to use avps with string names + + - the recommended format instead of interger ids + + (cherry picked from commit 295e9a23df952bc98c2a2803d796e358363b2e22) + +commit 0e9ccf0783570b3dabea1e97fddb234457d084b7 +Author: Kamailio Dev +Date: Sun Jun 21 19:46:43 2020 +0200 + + modules: readme files regenerated - modules ... [skip ci] + +commit 68290f9f48d3b7b7998c5831a0f11ebfa20e73a5 +Author: Daniel-Constantin Mierla +Date: Sun Jun 21 19:31:07 2020 +0200 + + db_mysql: docs - proper location for opt_ssl_mode in params section + + - reported by Juha Henianen + + (cherry picked from commit 56536708c5537c7443aa7a777fad0dc941e1bc71) + +commit 681cb57e66f74634b2c8d32fa989f2c7314cc412 +Author: Kamailio Dev +Date: Fri Jun 19 15:31:22 2020 +0200 + + modules: readme files regenerated - modules ... [skip ci] + +commit a6f117620f97fd8dd22e160938d6d322cce955bd +Author: Kristian F. Høgh +Date: Fri Jun 19 11:22:20 2020 +0200 + + registrar: expires_range should not make expires < min_expires + + (cherry picked from commit c753932ebfa055d923c92b916937eec99cd14d23) + +commit 9dff6197dcae5c4051194753382f95c5edaa379e +Author: Daniel-Constantin Mierla +Date: Thu Jun 18 10:31:38 2020 +0200 + + pv: use SIP_REQUEST/SIP_REPLY for value of $mt + + (cherry picked from commit 7e402da261e1ced56019037d3dce9e72b5b2b0ea) + +commit 0f90c016a4591bc2768731bd583235aea1348455 +Author: Daniel-Constantin Mierla +Date: Mon Jun 15 09:09:20 2020 +0200 + + db_mysql: use MARIADB_BASE_VERSION macro to check for MariaDB library + + (cherry picked from commit c5acc58863acb133748ad9f2f8a963ab714af871) + +commit 0a5f69e88d7d035a0966cbbe9c79b60163130c71 +Author: Daniel-Constantin Mierla +Date: Sun Jun 14 12:16:29 2020 +0200 + + db_mysql: note that libmariadbclient does not support ssl mode option + + (cherry picked from commit ae900a668aff4a472d6f1f7de5cf6277b5881ce9) + +commit 88b1b6d164fbb1b487a9c0a441673e63d2928c43 +Author: Daniel-Constantin Mierla +Date: Sun Jun 14 12:14:40 2020 +0200 + + db_mysql: mariadb client library does not support ssl mode option + + (cherry picked from commit 5b727447df9f5476c2ef818a8926f62525d0c349) + +commit 0fc0b643c655211ca0dfe12d560d1a8f9de284e6 +Author: Daniel-Constantin Mierla +Date: Sun Jun 14 11:31:59 2020 +0200 + + db_mysql: docs for opt_ssl_mode parameter + + (cherry picked from commit f012c525264ed05fec2acb4b3924d4b9a1cd3ab9) + +commit 31c6199d2204629240980b29cec861679493ce77 +Author: Daniel-Constantin Mierla +Date: Sun Jun 14 11:18:15 2020 +0200 + + db_mysql: new parameter opt_ssl_mode - allow controling ssl mode + + - can disable or enforce use of ssl + - some combinations of libmysqlclient and libssl1.1 can result in + crashing when ssl/tls is used, even on 127.0.0.1, this param can be used + to disable it + + (cherry picked from commit 260e25e15c4aa68533ee560bd8fcbdd5ee7b7d6f) + +commit 40549e34f81065f59b5f18cdda5c6ef74c3c9e0d +Author: Victor Seva +Date: Tue Jun 16 09:31:55 2020 +0200 + + sca: clang format code + + (cherry picked from commit cf3c0132cc81b2d8db05a6a9a26d7110a021ce23) + +commit 7bf0fc433008f4a0e0bd1e7eb7583fb989df973c +Author: Victor Seva +Date: Sat Mar 7 11:57:40 2020 +0100 + + core: remove compiler warnings [-Wstring-plus-int] + + > core/parser/parse_fline.c:241:17: warning: adding 'int' to a string does not append to the string [-Wstring-plus-int] + > SIP_VERSION+1, SIP_VERSION_LEN-1)) { + > ~~~~~~~~~~~^~ + > + > core/parser/parse_fline.c:241:17: note: use array indexing to silence this warning + > SIP_VERSION+1, SIP_VERSION_LEN-1)) { + > ^ + > & [ ] + > core/parser/parse_fline.c:247:18: warning: adding 'int' to a string does not append to the string [-Wstring-plus-int] + > HTTP_VERSION+1, HTTP_VERSION_LEN-1)) { + > ~~~~~~~~~~~~^~ + > + > core/parser/parse_fline.c:247:18: note: use array indexing to silence this warning + > HTTP_VERSION+1, HTTP_VERSION_LEN-1)) { + > ^ + > & [ ] + > + > 2 warnings generated. + + (cherry picked from commit f2959f422bb8171241728f5148d4b21c9cc2c681) + +commit 1797a30ec4a8aebab323a08f832d16d74958b765 +Author: Victor Seva +Date: Sat Mar 7 11:35:55 2020 +0100 + + core: remove compiler warnings [-Wstring-plus-int] + + > core/parser/parse_fline.c:93:34: warning: adding 'int' to a string does not append to the string [-Wstring-plus-int] + > strncasecmp( tmp+1, SIP_VERSION+1, SIP_VERSION_LEN-1)==0 && + > ~~~~~~~~~~~^~ + > + > core/parser/parse_fline.c:121:9: warning: adding 'int' to a string does not append to the string [-Wstring-plus-int] + > } else IFISMETHOD( INVITE, 'I' ) + > ^~~~~~~~~~~~~~~~~~~~~~~~~ + > + > core/parser/msg_parser.h:131:35: note: expanded from macro 'IFISMETHOD' + > strncasecmp( tmp+1, #methodname +1, methodname##_LEN-1)==0 && \ + > ~~~~~~~~~~~~^~ + + (cherry picked from commit 2b070a622fa3c78d929580fda3c7952963c4066b) + +commit f8b099436b654515ef75c61acb1abb0fea53b62d +Author: Kamailio Dev +Date: Thu Jun 11 16:04:43 2020 +0200 + + modules: readme files regenerated - modules ... [skip ci] + +commit bfa58cdebc84aeca8220eb9d583b597706907a1d +Author: Daniel-Constantin Mierla +Date: Thu Jun 11 15:50:09 2020 +0200 + + sipdump: make month in the file name from 1 to 12 + + - tm_mon is from 0-11 + - backport of 97593d20875d26c38511f564fd7071bf79baa56b + +commit 3dbf54f8f1994693a028a41d8d81d4cc7d9748d9 +Author: Daniel-Constantin Mierla +Date: Thu Jun 11 15:48:26 2020 +0200 + + kamctl: regenerated the schema + +commit 588b41f114ea1d14c59f6f1ab0cab65a0d01a227 +Author: Daniel-Constantin Mierla +Date: Thu Jun 11 15:19:19 2020 +0200 + + siputils: cotact ops - more debug info and coherence in log messages + + - use lowercase always at the start, the message is prefixed anyhow + + (cherry picked from commit 3f156be2e5e2c06a6716e709a246e57c51661012) + +commit 367a4f69fe179e52a1ef95780be1bf8284d80ede +Author: Daniel-Constantin Mierla +Date: Thu Jun 11 14:07:35 2020 +0200 + + siputils: contact ops - clang format code + + (cherry picked from commit 5754539602bb6806f829a9ceee73630953fdaa81) + +commit c0097b69c78919262be2c9c4babb462bc9354e15 +Author: Daniel-Constantin Mierla +Date: Thu Jun 11 13:27:22 2020 +0200 + + siputils: contact ops - removed old defines set on for very long time + + - bits of formatting code and comments + + (cherry picked from commit 2b8b2904399478984d3983ce447c98832419570a) + +commit ed1fb65f4e8b63e66c3c80d6382a2d98046265ff +Author: Daniel-Constantin Mierla +Date: Tue Jun 9 10:53:22 2020 +0200 + + app_python: check if f_code field in frame is set before using in log message + + (cherry picked from commit b02c247023ea3ea0ef9753efdb04aff7d5d3bbb4) + +commit ba3b6235cea86e3119392c5834e26a3fe224e42f +Author: Daniel-Constantin Mierla +Date: Tue Jun 9 10:49:22 2020 +0200 + + app_python3: use safer function PyBytes_AsString() instead of macro + + - check if f_code filed in frame is set before using in log message + - GH #2335 + + (cherry picked from commit e680dd6ed672e63012e960c68c0030e3f188654b) + +commit c09e2190a6e308e3446625afaaed5e9841883476 +Author: Daniel-Constantin Mierla +Date: Fri Jun 5 09:47:32 2020 +0200 + + topos: allow 183 without contact header + + - some UAs do not add it, even it can create the session for PRACK, + which requires it + + (cherry picked from commit 785326cdfbee849a8436e7c07003ff0539d259cd) + +commit be50e55355f1e33297121e0a7ac4c28fc4235e70 +Author: Daniel-Constantin Mierla +Date: Wed Jun 3 12:45:05 2020 +0200 + + core: tcp - log details of the exiting tcp connection on insert failure + + (cherry picked from commit 4deb51419ab66931459709fe44acd3e7a0acc18d) + +commit 69dca2b460b7802eed50072e3672a20a249b8851 +Author: Daniel-Constantin Mierla +Date: Wed Jun 3 08:55:57 2020 +0200 + + core: io_wait.h - typedef fd_map_t, more details in log when is a fd conflict + + (cherry picked from commit 50af00c7ef7037b6e55a3d3254a38935532bb0fa) + +commit c8f98ff7b7f734d0daa765cdb0332ea1952a97c7 +Author: Daniel-Constantin Mierla +Date: Wed Jun 3 08:36:07 2020 +0200 + + erlang: renamed global io_h to clt_io_h + + - tcp core also uses a glibal io_h + + (cherry picked from commit b6abc7618af7b8b3470e76aae7a0fd5ba0869949) + +commit dd59a3ac58253242257a8660310bb68274432ee3 +Author: Daniel-Constantin Mierla +Date: Wed Jun 3 08:33:01 2020 +0200 + + ctl: renamed global io_h to clt_io_h + + - tcp core also uses a glibal io_h + + (cherry picked from commit 19b3deb88afe5d787ca366885c660e66f17c3409) + +commit b80ed7c5220dda8ff73a8db48617d92b104b7482 +Author: Daniel-Constantin Mierla +Date: Sun May 31 09:29:39 2020 +0200 + + pv: removed commented code for retcode var - exported from core + + (cherry picked from commit f658a7a8263efd4b0ed5816959741380a964221d) + +commit a886c67b9d2047960aaa78154be1faaa259175d4 +Author: Torrey Searle +Date: Fri May 29 09:30:56 2020 +0200 + + misc: examples/kemi - fixes to the python script + + remove dependency on Router.Logger + remove ; + fix comment ref exit() + + (cherry picked from commit df2fa2c5589bd5f651e814e32e2edf00c23ffebc) + +commit 7b241198698db2ee483be13ab87d4d5bb37c7d85 +Author: Daniel-Constantin Mierla +Date: Tue May 26 15:05:15 2020 +0200 + + tls: better log messages when failing to create ssl ctx + + (cherry picked from commit d2906da97d2429bfdff089203f933de2d282a86d) + +commit 1f1b0517ddcb11c51e7211a902c2ca7eb338ef49 +Author: Daniel-Constantin Mierla +Date: Tue May 26 14:56:47 2020 +0200 + + tls: Makefile - option to link against libssl static libs + + (cherry picked from commit 3e7278f28c43b830a197e2f7b212ec6f06e5acbf) + +commit be5ded1ec663ba8b364e0bafaac1a07de1e656f5 +Author: Daniel-Constantin Mierla +Date: Tue May 26 09:24:17 2020 +0200 + + core: async task logging on no callback + + (cherry picked from commit 8893e6f2b30577b065f11a406faf5c5935714f78) + +commit f53ad6d78d77d160682e151b92cba4dc8a0c2fba +Author: Daniel-Constantin Mierla +Date: Mon May 25 11:06:24 2020 +0200 + + doc/docbook: added entities for kamctl and kamcli + + (cherry picked from commit 80e46395a3a937a5c5691c438db11bc059be6b38) + +commit 553438bf0df14ff7b2c450c3e73f909005260f3e +Author: Daniel-Constantin Mierla +Date: Sun May 24 15:43:28 2020 +0200 + + lib/srdb1: schema - added id auto-increment column to matrix + + - coherence across all tables + + (cherry picked from commit 740840ebe9538c1a3e6e3a49d82d437602b9d91a) + +commit 915c8a0d45710148ca781b3389e8397d6d7ff098 +Author: Daniel-Constantin Mierla +Date: Tue May 19 14:23:01 2020 +0200 + + core: kemi - functions to test http methods + + (cherry picked from commit f2458a66ae46a74b83fe2a3f3886f6015249a960) + +commit fed572ae474ca95eb35f712a4173451a8f98d825 +Author: Daniel-Constantin Mierla +Date: Mon May 18 11:28:20 2020 +0200 + + core: kemi - added KSR.is_KDQM() + + (cherry picked from commit 17d3040365400d14d251247c9c3319fc003f2cb2) + +commit b50e0041c0d485d82434381f66c1f6d21a2d003a +Author: Daniel-Constantin Mierla +Date: Mon May 18 08:29:09 2020 +0200 + + core: kemi - added missing is_MESSAGE() + + - GH #2331 + + (cherry picked from commit 8db5a12f7fab1a1fc7d50c87bbf1aee325b067c2) + +commit ac73bd096869a1cb13ba3145ad45a76838d023a9 +Author: Daniel-Constantin Mierla +Date: Sun May 17 10:01:18 2020 +0200 + + uid_uri_db: use file specific include guard + + (cherry picked from commit 7749069cd05b9619ee32237773097441e241bac4) + +commit a27d7da420ca0713201ca5f55ed79749d9ce213c +Author: Daniel-Constantin Mierla +Date: Sun May 17 10:01:00 2020 +0200 + + auth_diameter: use file specific include guard + + (cherry picked from commit 9053c70fe7e147b784c53a57014796282701c74d) + +commit 83f20f6b0e8a3e4a6c6b5351526f67b63f10da3e +Author: Daniel-Constantin Mierla +Date: Sun May 17 10:00:28 2020 +0200 + + acc_diameter: use file specific include guard + + (cherry picked from commit 3d73e8cb9f7431383c5a4ce798e2610f37ff92dc) + +commit 3a288421dbbffca9952200533668a653d6a4c170 +Author: Daniel-Constantin Mierla +Date: Sat May 16 15:21:43 2020 +0200 + + websocket: use signature macro instead of offsetting inside server hdr define + + - pass rcv info structure by address + - remove function name from logs + + (cherry picked from commit c0e687d820f9bbf2b6b1ef6892e5b34c30f25a63) + +commit 34eafd03b97c857682f9177ec4d7d1f983ff5bf2 +Author: Daniel-Constantin Mierla +Date: Sat May 16 15:20:45 2020 +0200 + + core: define macro for signature to be used for server and user-agent + + (cherry picked from commit d26ccdea61230bfc7720a2523c7b6dd8d2692d6d) + +commit 749dcc5b6d03889609685957538dc90bccce5703 +Author: Daniel-Constantin Mierla +Date: Fri May 15 16:51:50 2020 +0200 + + rr: updates for outboud module api + + (cherry picked from commit 6aca846dce4b797a66aaa865fb5a1e81f7806b4c) + +commit 8ca76f01711e59fd1567bfcbd785cb0b7b8b3942 +Author: Daniel-Constantin Mierla +Date: Fri May 15 16:51:41 2020 +0200 + + path: updates for outboud module api + + (cherry picked from commit 97c7081df94eaabd8e48b084671ea831b5ec9024) + +commit 40e3773f28faf392475b142f54f301d7c0ec6f6e +Author: Daniel-Constantin Mierla +Date: Fri May 15 16:49:17 2020 +0200 + + outbound: pass recv info struct by address + + - fix performance inefficiency for passing large structs by value + + (cherry picked from commit 56ea88ef9a0628d7ca644f31840101ffe573e5c3) + +commit 88935e040472ac0b5633173dfcd97251c09fa5c2 +Author: Daniel-Constantin Mierla +Date: Thu May 14 21:21:51 2020 +0200 + + pua_reginfo: free xml doc in case of error + + - a few whitespacing fixes + + (cherry picked from commit 7ae675bd90b4420ebaa17768c97aa09219f53116) + +commit 129986178fb1e11e1e3132155445c16f7ba8ac78 +Author: Daniel-Constantin Mierla +Date: Thu May 14 21:15:51 2020 +0200 + + evapi: cast to void* when printing logs with pointer value + + (cherry picked from commit 4ad790f697554332ea590793d3ec56e13437e82f) + +commit 4f9f7160511a5f9301e2fb5764d857f58eb8f95b +Author: Daniel-Constantin Mierla +Date: Thu May 14 20:37:09 2020 +0200 + + tm: safety checks for branch request len + + (cherry picked from commit c45913497f222c67bcccdbc8724b25bb083c556f) + +commit c90fb35fbd5091e929f8b3b5064d8fe9ef674487 +Author: Daniel-Constantin Mierla +Date: Wed May 13 18:35:56 2020 +0200 + + misc: examples/kemi - small typo in lua example + + (cherry picked from commit c1d3fdb31871078b666278a933dbab20a0a8dca3) + +commit c27cad6e743083b56c38f8eaf87ddc43e68b5068 +Author: Daniel-Constantin Mierla +Date: Tue May 12 19:52:52 2020 +0200 + + core: explicit cast to (void*) for %p format printing + + - c standard required that for a defined value and in some cases the + code analysers complain, especially when reading the value via + socket/file descriptor + + (cherry picked from commit 730f65c06d0b8436e4a9cd0c1a62d2433819dc45) + +commit f1af2147c506b3c01c80dcc66d294481530fd957 +Author: Daniel-Constantin Mierla +Date: Tue May 12 18:01:15 2020 +0200 + + imc: reserve last char in global buffer for ending zero + + (cherry picked from commit 702630b484ac6f7c017829c24294ce7552f1682a) + +commit a6a7e9b57edef5794a96299ce77c27db5667e4b4 +Author: Daniel-Constantin Mierla +Date: Sat May 9 13:53:19 2020 +0200 + + regex: leave enough space in buffers for parenthesis and -ending + + (cherry picked from commit 9cae069832c8f37ebf9e686b3fbcab5d63652755) + +commit ea06c83da7a2d592b856c01c6677692d1311e3f9 +Author: Daniel-Constantin Mierla +Date: Sat May 9 11:00:20 2020 +0200 + + core: udp server - add sockaddr_storage to ensure enough size for sockaddr_union + + - safety check that from addr len is matching expected size for listen + socket + - rename local variables to suggest better their purpose + + (cherry picked from commit d13f863e74c6c0275264e588f1dca206cf099587) + +commit ffc82295b14980283b88cac4793a3331788f413b +Author: Daniel-Constantin Mierla +Date: Fri May 8 21:28:01 2020 +0200 + + core: safer truncation of hostname using memcpy + + (cherry picked from commit aac577a4655ebf09d5cbef3e1a49f72d25ea57d7) + +commit c4471752e9f5b75b553676e7a0c8e783c2608a6a +Author: Daniel-Constantin Mierla +Date: Fri May 8 18:01:13 2020 +0200 + + sipdump: safety check for local socket pointer + + - use generic address is not set + + (cherry picked from commit 3e969a5b4d9a75d082f7d59b0fa1dc6362391675) + +commit 6db082b757ef4552c254ba9974ed29fb8dd1a53c +Author: Daniel-Constantin Mierla +Date: Fri May 8 13:54:49 2020 +0200 + + core: events - increased SREV_CB_LIST_SIZE + + - there can be several modules registering for these core callbacks + + (cherry picked from commit fc7b0d65a227a176f79459c86844668bcd519148) + +commit 7307b51b439f2d1fde1cc959c9eabc786eb1558c +Author: Daniel-Constantin Mierla +Date: Wed May 6 17:13:16 2020 +0200 + + htable: use localtime_r() for a safer multi-thread usage + + (cherry picked from commit a6a4046757c2cac79455aa4a2d2ac632faa5e379) + +commit 51ba498700c239d1721534d01da65fa90e95d069 +Author: Daniel-Constantin Mierla +Date: Wed May 6 17:03:45 2020 +0200 + + pv: use localtime_r() for a safer multi-thread usage + + (cherry picked from commit 14645b550cf9500e6a6e4a7d2ed8749e9aa174dc) + +commit 3b0cbc3002280b21e0e77769276eeaf1a7a3af6c +Author: Kamailio Dev +Date: Thu Jun 11 13:01:33 2020 +0200 + + modules: readme files regenerated - modules ... [skip ci] + +commit 8b0cd13f0dc08f9f4ecb0d9b716d651ff23ae2f3 +Author: Henning Westerholt +Date: Thu Jun 11 10:45:00 2020 +0000 + + ims_charging: fix errors in docs, add missing parameters + + (cherry picked from commit d4f3d0e705f38c61c842c5f6a367a9768e592965) + +commit 7453e9198ac3149e09cb04416f06e7303f32dd3c +Author: Henning Westerholt +Date: Wed Jun 10 15:36:48 2020 +0000 + + cdp: better compatiblity with certain Diameter servers + + - better compatiblity with certain Diameter servers + - some Diameter servers do not include Supported-Vendor-Id AVP in their reply + - assume in this case that the server will support our proposed applications + + (cherry picked from commit 1a462ed4cffddd5f691b33adb859c286a0c074df) + +commit 386669407ec3a04c00ca43ddcce256c61b86a867 +Author: Henning Westerholt +Date: Wed Jun 10 15:31:13 2020 +0000 + + ims_charging: initialize ro_forced_peer variable + + (cherry picked from commit 7cae3e5e0df27bf3481cbf0680bf86902359a97c) + +commit 5284b907357aa0dab0aa8eb655eeac81a7af60e9 +Author: Henning Westerholt +Date: Wed Jun 10 11:50:51 2020 +0000 + + ims_charging: fix missing line-breaks for log messages + + (cherry picked from commit 508786fcdbbc120215b3e7dd90d92ab40c3b1e4e) + +commit ccf7347e9f756b36e5baa65d93dab520098d3993 +Author: Henning Westerholt +Date: Wed Jun 10 11:35:37 2020 +0000 + + cdp: add missing line-breaks for log messages + + (cherry picked from commit 32a0d8073eb1b7f01190d305d318b43268811be8) + +commit 249d558c0e3ae0c0e24d508d2e7a9c2853078a8f +Author: Sergey Safarov +Date: Tue Jun 9 14:02:50 2020 +0300 + + pkg/docker: updated alpine docker packaging submodule + +commit ef221027a448d77337225e376362b26b2618f050 +Author: Daniel-Constantin Mierla +Date: Wed Jun 3 21:46:20 2020 +0200 + + pdb: use memcpy() for PDB_BUFTOSHORT macro + + - related to GH #2345 + + (cherry picked from commit be57be33d0e48d412ddab9801ee4d6d906329d70) + +commit 88676c2f083c2d7e52ae6b42f5cbe83f64357865 +Author: Federico Cabiddu +Date: Mon Jun 1 07:29:07 2020 +0200 + + dispatcher: don't reset load table when adding/removing a destination or reloading the list + + (cherry picked from commit 4099a6caf856c9af4d7d89aec73db143efbcd40b) + +commit ac47ce9019616ffda2d206f42fbecb142a5fc55d +Author: Daniel-Constantin Mierla +Date: Tue May 19 13:43:10 2020 +0200 + + dispatcher: sync on load management operations + + - use locks to increment/decrement call load and get least loaded dst + - GH #2322 + + (cherry picked from commit d14833d9d1ad6cc92c65e279b7dd89b3b922f129) + +commit 0dd7f9e939c2cc54b338a1432847622f7c4e385f +Author: Kamailio Dev +Date: Fri Jun 5 19:31:20 2020 +0200 + + modules: readme files regenerated - modules ... [skip ci] + +commit 1b27855539f42f5dece0232c90ee0857ca012ebd +Author: Henning Westerholt +Date: Fri Jun 5 17:29:17 2020 +0000 + + siptrace: extend docs that force_send_socket parameter is only used for HEP mode + +commit 16a94677a5aeaa499eaf09eab4cd057a720b3200 +Author: Kamailio Dev +Date: Fri Jun 5 14:31:20 2020 +0200 + + modules: readme files regenerated - modules ... [skip ci] + +commit dd9b9df93f33819f64831ea7f4a801a2b1b6c50b +Author: Victor Seva +Date: Wed Jun 3 13:22:21 2020 +0200 + + cnxcc: don't terminate non confirmed calls + + * non confirmed calls can't be terminated via dialog.terminate_dlg() API + * set call.max_amount to 0 to terminate the call if gets confirmed + + fix #2346 + + (cherry picked from commit ca0fc18e1cfad86ed6b7530d6c520b680e5d6a4f) + +commit c1b9bf212829f89702fd34cf62c493060d7c5616 +Author: Victor Seva +Date: Tue Jun 2 19:12:31 2020 +0200 + + cnxcc: minor changes + + * use [PKG|SHM]_MEM_ERROR + * use memset and avoid initialization per field + * init variables + * use localtime_r() for a safer multi-thread usage + * replaced deprecated STR_PARAM with PARAM_STR + * clean includes + * clang-format + + (cherry picked from commit e98457faf2098ca2f16a831a4a68d2a26e301b0a) + +commit fca18567f458fd3860a63ab37a9e7e2fe89f0019 +Author: Jose Luis Verdeguer +Date: Thu Dec 19 17:58:45 2019 +0100 + + cnxcc: updated readme file [skip ci] + + (cherry picked from commit cea7fa14b0aefc647d28eb1bf56faaec89d90d67) + +commit daecf0490c144a6f3fd5c66c53a86f33b6295681 +Author: Daniel-Constantin Mierla +Date: Mon Nov 18 18:29:05 2019 +0100 + + cnxcc: use snprintf() instead of sprintf() + + (cherry picked from commit 05bd956a9980ffc8938cdbce6bab3af5086350dd) + +commit a41dcf3259d72dfecf4cd34638d885734dc7a5ea +Author: Kamailio Dev +Date: Fri Jun 5 12:31:49 2020 +0200 + + modules: readme files regenerated - modules ... [skip ci] + +commit 0f733090f69f88a153040e0051057bfd3a9a8404 +Author: Henning Westerholt +Date: Fri Jun 5 09:25:04 2020 +0000 + + siptrace: fix regression introduced from 4e9a760123c for siptrace(), sip_trace_mode() + + - fix regression introduced from 4e9a760123c for siptrace(), sip_trace_mode() + - it was not working properly without destination uri in non-HEP mode + + (cherry picked from commit 21338195e74b09ccca29d6479e698417ed34cd42) + +commit 05a6f13c40249e0d658016652ae46b8512149857 +Author: Henning Westerholt +Date: Fri Jun 5 10:29:10 2020 +0000 + + siptrace: manual backport of 75e6e370ceb7, improve documentation for siptrace and DB setup + +commit a35a2f3d3f9d2a371ebb2e5c0da67dec24906b77 +Author: Victor Seva +Date: Fri Oct 18 09:59:27 2019 +0200 + + pkg/kamailio/deb: update [skip ci] + + * define User and Group + + Thanks @sergey-safarov + + (cherry picked from commit 0436af5abd8b73e17f65020c74943f0f3b72ba0d) + +commit ed2b91a57f648334a72aa18b9538230caaba7829 +Author: Victor Seva +Date: Fri Oct 18 09:47:07 2019 +0200 + + pkg/kamailio/deb: update /var/run -> /run [skip ci] + + * introduced on Debian since 7 Wheezy, on Ubuntu since 11.10 Oneiric + + (cherry picked from commit ac21d494253eddd085197e2862c3206efff8233a) + +commit 5be2234db7992309d128e6b999771fb298c01fd5 +Author: Sergey Safarov +Date: Sat May 23 22:24:25 2020 +0300 + + pkg/kamailio/obs: packaged xhttp_prom (prometheus) + + (cherry picked from commit 3e77c574c340941f36ca8f9081a77c5b476f8c8c) + +commit be32a0896187b385cb9f708abaf72089e5c35adb +Author: Daniel-Constantin Mierla +Date: Mon May 4 20:05:26 2020 +0200 + + rtpmanage: enable hadling of PRACK requests + + - they can have SDP + - use more compact bitwise match for method types + + (cherry picked from commit de77beffb436e783031a6aa71c1887848cb2cc73) + +commit fc28a14203f59c62d2c745ffd294a5091bf8cb26 +Author: Sergey Safarov +Date: Sun Apr 12 19:03:52 2020 +0300 + + pkg/kamailio: fixed python3 deps for RHEL 6 + + (cherry picked from commit 5f31a56acd25f892e6275e6ac786677f2eb2be0c) + +commit 957335591e589cde0ae3127b6d2e50c092708e0e +Author: Daniel-Constantin Mierla +Date: Sun Mar 29 14:17:19 2020 +0200 + + lib/srdb1/schema: removed kamailio-extensions.xml file + + - file didn't have any content itself, tried to include an inexistent + extra.xml, which generated an warning for 'make dbschema' + + (cherry picked from commit 367a865e7f0c9cd67fda9176add1ca3c0dad2d46) + +commit cc31c71e56f8feeeab45532f8fa954991817ed6d +Author: Henning Westerholt +Date: Sun Feb 23 21:45:48 2020 +0100 + + core: better debug logging in mk_action function + + (cherry picked from commit 10b96696b82d2e70c15f3e4bc52097f0a5062499) + +commit 99c3ddecd7887abed5ab087decdd9ff3712ff545 +Author: Daniel-Constantin Mierla +Date: Mon Apr 27 10:47:48 2020 +0200 + + pdb: covert byte-by-byte from buffer to short-int to avoid unalignment compile warning + + - GH #2298 + + (cherry picked from commit 86ebb4eef482b37a3bb8bf033caa4d87fd8aeb87) + +commit 2396526ca13f3373d41d727119326fd9a41b7eb7 +Author: Henning Westerholt +Date: Sun Mar 29 11:27:07 2020 +0200 + + lib/srdb1: fix warning about wrong namespace in version.xml + + (cherry picked from commit d4311f3dfa3fc6c3836e8573fb12bc2ae4b6c264) + +commit 11f64c9562c71b45497901be6b606ba86546126e +Author: Aleksandar Yosifov +Date: Thu May 7 12:49:20 2020 +0300 + + ims_usrloc_scscf: extend and fix log messages + + (cherry picked from commit b2487d95f61b46033eb2825c5f54d5f19ca1e878) + +commit ebd35b33f3afe9aa1b1858f07b672370267f532c +Author: Aleksandar Yosifov +Date: Tue Apr 21 13:55:36 2020 +0300 + + ims_registrar_scscf: fix aor generation in lookup() + + - Generate AoR in lookup() from parsed uri user and + host. Skipping all user's and host's parameters. + + (cherry picked from commit e53b25f89a14aba93d3c48a1b2f983114db1760c) + +commit 702ec6fb87ede0fe20e621b1e4a8eead057b0fcc +Author: Aleksandar Yosifov +Date: Wed Mar 11 17:56:09 2020 +0200 + + ims_registrar_scscf: fix multiple contacts in NOTIFY + + - Prevent multiple contacts for NOTIFY message in + Message body tag after + RE-REGISTRATION procedure. + + (cherry picked from commit fa8b7941c4d14625beadd4943d89e898543c7377) + +commit a91e7fdc9128b59c2084cab1a0e7c0ecbaa791ca +Author: Daniel-Constantin Mierla +Date: Thu Feb 13 10:25:51 2020 +0100 + + xmlrpc: Makefile - use pkg-config if xml2-config is not found + + - GH #2199 + + (cherry picked from commit 994a8dfc070d84b5dad28fa873d8759280c910f2) + +commit 81eb48d0627e9b677114fdce8e0890bf4f4c9e62 +Author: Daniel-Constantin Mierla +Date: Thu Feb 13 10:25:51 2020 +0100 + + xhttp_pi: Makefile - use pkg-config if xml2-config is not found + + - GH #2199 + + (cherry picked from commit fe173b2af121b2d6388fea3632037a0ea2999988) + +commit 5cd1c93c452dc37ee96b2cf9959ac3c7902d4921 +Author: Daniel-Constantin Mierla +Date: Thu Feb 13 10:25:51 2020 +0100 + + xcap_server: Makefile - use pkg-config if xml2-config is not found + + - GH #2199 + + (cherry picked from commit 169ccce5e3cb302352b1e4d5ac0a0dc58eb552cb) + +commit 40c925ae5cd7726d5730486999671cd26db7a21d +Author: Daniel-Constantin Mierla +Date: Thu Feb 13 10:25:51 2020 +0100 + + rls: Makefile - use pkg-config if xml2-config is not found + + - GH #2199 + + (cherry picked from commit fbfe21f54c7fd845bf9c99c4091980b1ee4d61d5) + +commit 31097600fa8ee6867e6c6dccdb9537066561c942 +Author: Daniel-Constantin Mierla +Date: Thu Feb 13 10:25:51 2020 +0100 + + pua_xmpp: Makefile - use pkg-config if xml2-config is not found + + - GH #2199 + + (cherry picked from commit d40a924bd698ddf365b4db52cba2ab45f7d7a6e2) + +commit ef5a8bcc8bc986e1658dc863f4eaecfd21deceb4 +Author: Daniel-Constantin Mierla +Date: Thu Feb 13 10:25:51 2020 +0100 + + pua_usrloc: Makefile - use pkg-config if xml2-config is not found + + - GH #2199 + + (cherry picked from commit 20d9453cd3259e8afa1de92a7dba1d25f5f43fe4) + +commit ac699321c417232a0444d84b7e0c147915d8c5c8 +Author: Daniel-Constantin Mierla +Date: Thu Feb 13 10:25:51 2020 +0100 + + pua_reginfo: Makefile - use pkg-config if xml2-config is not found + + - GH #2199 + + (cherry picked from commit 7f6648a8586fdfd5a1fdba05556333095bc25777) + +commit 74b7f6bca2e286a151a093d5b1f4d26cffa6b942 +Author: Daniel-Constantin Mierla +Date: Thu Feb 13 10:25:51 2020 +0100 + + pua_dialoginfo: Makefile - use pkg-config if xml2-config is not found + + - GH #2199 + + (cherry picked from commit b4842e81e3aa861739c996ff795b6d7261202b66) + +commit 016747536accc3fd32654b0197735dab8d19a526 +Author: Daniel-Constantin Mierla +Date: Thu Feb 13 10:25:51 2020 +0100 + + pua_bla: Makefile - use pkg-config if xml2-config is not found + + - GH #2199 + + (cherry picked from commit e00ce6016afd5c0fba084a19a45fb13353e7f6f4) + +commit f05809a2a1aaf2e599646f18ffd42bf97c9efa9b +Author: Daniel-Constantin Mierla +Date: Thu Feb 13 10:25:51 2020 +0100 + + pua: Makefile - use pkg-config if xml2-config is not found + + - GH #2199 + + (cherry picked from commit 4f43047172260e1a524700a866693f99ea11383b) + +commit 9e01d1bc26443b7fe95ce8bc894ba5b8ed1151a4 +Author: Daniel-Constantin Mierla +Date: Thu Feb 13 10:25:51 2020 +0100 + + presence_conference: Makefile - use pkg-config if xml2-config is not found + + - GH #2199 + + (cherry picked from commit 8e9e1fdeacc4c1b2b0cd67f1b36d73737dacd015) + +commit 65228082e4cddec5377632e50fbf09ab0f0a1b0b +Author: Daniel-Constantin Mierla +Date: Thu Feb 13 10:25:51 2020 +0100 + + lost: Makefile - use pkg-config if xml2-config is not found + + - GH #2199 + + (cherry picked from commit 8d7c0f80083351de98b99d2505170b740974080a) + +commit 44442227e6477f52ed06287827ac81817f2bcd50 +Author: Daniel-Constantin Mierla +Date: Thu Feb 13 10:25:50 2020 +0100 + + ims_registrar_scscf: Makefile - use pkg-config if xml2-config is not found + + - GH #2199 + + (cherry picked from commit ff92622c3b4c6224f75318ba9e39c9b4389bff1e) + +commit d2076d22d30f1ad71a69c178d6f5ff42d55f9fc9 +Author: Daniel-Constantin Mierla +Date: Thu Feb 13 10:25:50 2020 +0100 + + ims_registrar_pcscf: Makefile - use pkg-config if xml2-config is not found + + - GH #2199 + + (cherry picked from commit 29573bbdb09412c9cbfe839f0c80b7dd7fe77804) + +commit dad9ce4a79efa93bb0541bc610ab4061e8ae25f3 +Author: Daniel-Constantin Mierla +Date: Thu Feb 13 10:25:50 2020 +0100 + + ims_isc: Makefile - use pkg-config if xml2-config is not found + + - GH #2199 + + (cherry picked from commit 71e67531194aa867b8f3f32b72d07e1bd4ad7dff) + +commit 457d46778bd8b88ffb319779cdc3b967f182d949 +Author: Daniel-Constantin Mierla +Date: Thu Feb 13 10:25:50 2020 +0100 + + ims_icscf: Makefile - use pkg-config if xml2-config is not found + + - GH #2199 + + (cherry picked from commit 80f2eb33a967ede3e70fef572dc9b42172ad067c) + +commit c3ec851cae8609660372b28f6c4eba1b632964f6 +Author: Daniel-Constantin Mierla +Date: Thu Feb 13 10:25:50 2020 +0100 + + ims_auth: Makefile - use pkg-config if xml2-config is not found + + - GH #2199 + + (cherry picked from commit 4d3496fb82df1d249a78365e0c50b4ec13989261) + +commit 863882cc2b4980a3215bbb5310720fb13cf4f2f8 +Author: Daniel-Constantin Mierla +Date: Thu Feb 13 10:25:50 2020 +0100 + + cplc: Makefile - use pkg-config if xml2-config is not found + + - GH #2199 + + (cherry picked from commit f05a46dc79de45c6cb958b845b9f2d85452c4f37) + +commit 9708c4b553692747603923fa8562f3731140413d +Author: Daniel-Constantin Mierla +Date: Thu Feb 13 10:25:50 2020 +0100 + + cdp: Makefile - use pkg-config if xml2-config is not found + + - GH #2199 + + (cherry picked from commit 2749962b8354be1731ab68a0ae4aa0fac4f944e1) + +commit c81c26637bd9a4869cb446c6f70f21cf04cd79aa +Author: Daniel-Constantin Mierla +Date: Thu Feb 13 10:08:58 2020 +0100 + + lib/ims: Makefile - try to use pkg-config if xml2-config is not found + + - GH #2199 + + (cherry picked from commit 58deac2e7fd62afca409b17903deb951493b213a) + +commit 2012b6ff81c87be6c05cdf25f4f2a9b812a5dae7 +Author: Daniel-Constantin Mierla +Date: Wed Feb 12 20:56:05 2020 +0100 + + xmlops: Makefile - try to use pkg-config if xml2-config is not found + + - GH #2199 + + (cherry picked from commit 64d37971d2d3fbd87176fe71ae19adca7f47a6ea) + +commit 39fce673e50a52dbb0b1c8c786c98b15e8bdfeb7 +Author: Victor Seva +Date: Tue May 5 14:20:07 2020 +0200 + + ndb_redis: redis_cmd() check reply type to detect command errors + + fix #2300 + + (cherry picked from commit d00b14704805d728f5a845a6af900eff1ed372ac) + +commit f977da4c7058a62919557eba3f6edcd5faa61cda +Author: Daniel-Constantin Mierla +Date: Thu May 7 08:19:36 2020 +0200 + + kamctl: regenerated db schema for secfilter + + (cherry picked from commit 59c49af039f468466b0d853a4ceab8fe7f566215) + +commit 221175ff31bfead160ef9f3bc8ac613a107f98cf +Author: Daniel-Constantin Mierla +Date: Thu May 7 08:19:05 2020 +0200 + + srdb1: default value set to 0 for number types + + (cherry picked from commit b0f1486f8a656922aac02020c9e3141639f2ecb9) + +commit ac1b7f30b4cdc6d48d77f19421822300bcaa34be +Author: Daniel-Constantin Mierla +Date: Wed May 6 17:15:36 2020 +0200 + + pua: use file name specific include guard + + (cherry picked from commit 076649793bfdbdc4f03f96961f23997c87ce4268) + + ===================== 2020-05-06 Version 5.3.4 Released ===================== ===================== Changes Since Version 5.3.3 =========================== diff --git a/doc/docbook/entities.xml b/doc/docbook/entities.xml index b9d58c44e..0f54bc4ab 100644 --- a/doc/docbook/entities.xml +++ b/doc/docbook/entities.xml @@ -13,6 +13,8 @@ &kamwiki;"> + + diff --git a/misc/examples/kemi/kamailio-basic-kemi-lua.lua b/misc/examples/kemi/kamailio-basic-kemi-lua.lua index 49bcdb3c4..c35768991 100644 --- a/misc/examples/kemi/kamailio-basic-kemi-lua.lua +++ b/misc/examples/kemi/kamailio-basic-kemi-lua.lua @@ -240,7 +240,7 @@ function ksr_route_location() end --- IP authorization and user uthentication +-- IP authorization and user authentication function ksr_route_auth() if not KSR.is_REGISTER() then diff --git a/misc/examples/kemi/kamailio-basic-kemi-python.py b/misc/examples/kemi/kamailio-basic-kemi-python.py index 64e0cc43f..f73abfedc 100644 --- a/misc/examples/kemi/kamailio-basic-kemi-python.py +++ b/misc/examples/kemi/kamailio-basic-kemi-python.py @@ -7,12 +7,11 @@ ## Relevant remarks: ## * return code -255 is used to propagate the 'exit' behaviour to the ## parent route block function. The alternative is to use the native -## Python function os.exit() (or exit()) -- it throws an exception that +## Python function sys.exit() (or exit()) -- it throws an exception that ## is caught by Kamailio and previents the stop of the interpreter. import sys -import Router.Logger as Logger import KSR as KSR # global variables corresponding to defined values (e.g., flags) in kamailio.cfg @@ -28,56 +27,56 @@ FLB_NATSIPPING=7 # global function to instantiate a kamailio class object # -- executed when kamailio app_python module is initialized def mod_init(): - KSR.info("===== from Python mod init\n"); - # dumpObj(KSR); - return kamailio(); + KSR.info("===== from Python mod init\n") + # dumpObj(KSR) + return kamailio() # -- {start defining kamailio class} class kamailio: def __init__(self): - KSR.info('===== kamailio.__init__\n'); + KSR.info('===== kamailio.__init__\n') # executed when kamailio child processes are initialized def child_init(self, rank): - KSR.info('===== kamailio.child_init(%d)\n' % rank); - return 0; + KSR.info('===== kamailio.child_init(%d)\n' % rank) + return 0 # SIP request routing # -- equivalent of request_route{} def ksr_request_route(self, msg): - # KSR.info("===== request - from kamailio python script\n"); - # KSR.info("===== method [%s] r-uri [%s]\n" % (KSR.pv.get("$rm"),KSR.pv.get("$ru"))); + # KSR.info("===== request - from kamailio python script\n") + # KSR.info("===== method [%s] r-uri [%s]\n" % (KSR.pv.get("$rm"),KSR.pv.get("$ru"))) # per request initial checks if self.ksr_route_reqinit(msg)==-255 : - return 1; + return 1 # NAT detection if self.ksr_route_natdetect(msg)==-255 : - return 1; + return 1 # CANCEL processing if KSR.is_CANCEL() : if KSR.tm.t_check_trans()>0 : - self.ksr_route_relay(msg); - return 1; + self.ksr_route_relay(msg) + return 1 # handle requests within SIP dialogs if self.ksr_route_withindlg(msg)==-255 : - return 1; + return 1 # -- only initial requests (no To tag) # handle retransmissions if KSR.tmx.t_precheck_trans()>0 : - KSR.tm.t_check_trans(); - return 1; + KSR.tm.t_check_trans() + return 1 if KSR.tm.t_check_trans()==0 : - return 1; + return 1 # authentication if self.ksr_route_auth(msg)==-255 : @@ -85,9 +84,9 @@ class kamailio: # record routing for dialog forming requests (in case they are routed) # - remove preloaded route headers - KSR.hdr.remove("Route"); + KSR.hdr.remove("Route") if KSR.is_method_in("IS") : - KSR.rr.record_route(); + KSR.rr.record_route() # account only INVITEs @@ -97,24 +96,24 @@ class kamailio: # dispatch requests to foreign domains if self.ksr_route_sipout(msg)==-255 : - return 1; + return 1 # # requests for my local domains # handle registrations if self.ksr_route_registrar(msg)==-255 : - return 1; + return 1 if KSR.corex.has_ruri_user() < 0 : # request with no Username in RURI - KSR.sl.sl_send_reply(484,"Address Incomplete"); - return 1; + KSR.sl.sl_send_reply(484,"Address Incomplete") + return 1 # user location service - self.ksr_route_location(msg); + self.ksr_route_location(msg) - return 1; + return 1 # wrapper around tm relay function @@ -123,20 +122,20 @@ class kamailio: # - serial forking, RTP relaying handling, a.s.o. if KSR.is_method_in("IBSU") : if KSR.tm.t_is_set("branch_route")<0 : - KSR.tm.t_on_branch("ksr_branch_manage"); + KSR.tm.t_on_branch("ksr_branch_manage") if KSR.is_method_in("ISU") : if KSR.tm.t_is_set("onreply_route")<0 : - KSR.tm.t_on_reply("ksr_onreply_manage"); + KSR.tm.t_on_reply("ksr_onreply_manage") if KSR.is_INVITE() : if KSR.tm.t_is_set("failure_route")<0 : - KSR.tm.t_on_failure("ksr_failure_manage"); + KSR.tm.t_on_failure("ksr_failure_manage") if KSR.tm.t_relay()<0 : - KSR.sl.sl_reply_error(); + KSR.sl.sl_reply_error() - return -255; + return -255 # Per SIP request initial checks @@ -146,113 +145,113 @@ class kamailio: # ip is already blocked KSR.dbg("request from blocked IP - " + KSR.pv.get("$rm") + " from " + KSR.pv.get("$fu") + " (IP:" - + KSR.pv.get("$si") + ":" + str(KSR.pv.get("$sp")) + ")\n"); - return -255; + + KSR.pv.get("$si") + ":" + str(KSR.pv.get("$sp")) + ")\n") + return -255 if KSR.pike.pike_check_req()<0 : KSR.err("ALERT: pike blocking " + KSR.pv.get("$rm") + " from " + KSR.pv.get("$fu") + " (IP:" - + KSR.pv.get("$si") + ":" + str(KSR.pv.get("$sp")) + ")\n"); - KSR.pv.seti("$sht(ipban=>$si)", 1); - return -255; + + KSR.pv.get("$si") + ":" + str(KSR.pv.get("$sp")) + ")\n") + KSR.pv.seti("$sht(ipban=>$si)", 1) + return -255 if KSR.corex.has_user_agent() > 0 : ua = KSR.pv.gete("$ua") if (ua.find("friendly-scanner")!=-1 or ua.find("sipcli")!=-1) : - KSR.sl.sl_send_reply(200, "Processed"); - return -255; + KSR.sl.sl_send_reply(200, "Processed") + return -255 if KSR.maxfwd.process_maxfwd(10) < 0 : - KSR.sl.sl_send_reply(483,"Too Many Hops"); - return -255; + KSR.sl.sl_send_reply(483,"Too Many Hops") + return -255 if (KSR.is_OPTIONS() and KSR.is_myself_ruri() and KSR.corex.has_ruri_user() < 0) : - KSR.sl.sl_send_reply(200,"Keepalive"); - return -255; + KSR.sl.sl_send_reply(200,"Keepalive") + return -255 if KSR.sanity.sanity_check(1511, 7)<0 : KSR.err("Malformed SIP message from " - + KSR.pv.get("$si") + ":" + str(KSR.pv.get("$sp")) +"\n"); - return -255; + + KSR.pv.get("$si") + ":" + str(KSR.pv.get("$sp")) +"\n") + return -255 # Handle requests within SIP dialogs def ksr_route_withindlg(self, msg): if KSR.siputils.has_totag()<0 : - return 1; + return 1 # sequential request withing a dialog should # take the path determined by record-routing if KSR.rr.loose_route()>0 : if self.ksr_route_dlguri(msg)==-255 : - return -255; + return -255 if KSR.is_BYE() : # do accounting ... - KSR.setflag(FLT_ACC); + KSR.setflag(FLT_ACC) # ... even if the transaction fails - KSR.setflag(FLT_ACCFAILED); + KSR.setflag(FLT_ACCFAILED) elif KSR.is_ACK() : # ACK is forwarded statelessly if self.ksr_route_natmanage(msg)==-255 : - return -255; + return -255 elif KSR.is_NOTIFY() : # Add Record-Route for in-dialog NOTIFY as per RFC 6665. - KSR.rr.record_route(); + KSR.rr.record_route() - self.ksr_route_relay(msg); - return -255; + self.ksr_route_relay(msg) + return -255 if KSR.is_ACK() : if KSR.tm.t_check_trans() >0 : - # no loose-route, but stateful ACK; + # no loose-route, but stateful ACK # must be an ACK after a 487 # or e.g. 404 from upstream server - self.ksr_route_relay(msg); - return -255; + self.ksr_route_relay(msg) + return -255 else: # ACK without matching transaction ... ignore and discard - return -255; + return -255 - KSR.sl.sl_send_reply(404, "Not here"); - return -255; + KSR.sl.sl_send_reply(404, "Not here") + return -255 # Handle SIP registrations def ksr_route_registrar(self, msg): if not KSR.is_REGISTER() : - return 1; + return 1 if KSR.isflagset(FLT_NATS) : - KSR.setbflag(FLB_NATB); + KSR.setbflag(FLB_NATB) # do SIP NAT pinging - KSR.setbflag(FLB_NATSIPPING); + KSR.setbflag(FLB_NATSIPPING) if KSR.registrar.save("location", 0)<0 : - KSR.sl.sl_reply_error(); + KSR.sl.sl_reply_error() - return -255; + return -255 # User location service def ksr_route_location(self, msg): - rc = KSR.registrar.lookup("location"); + rc = KSR.registrar.lookup("location") if rc<0 : - KSR.tm.t_newtran(); + KSR.tm.t_newtran() if rc==-1 or rc==-3 : - KSR.sl.send_reply(404, "Not Found"); - return -255; + KSR.sl.send_reply(404, "Not Found") + return -255 elif rc==-2 : - KSR.sl.send_reply(405, "Method Not Allowed"); - return -255; + KSR.sl.send_reply(405, "Method Not Allowed") + return -255 # when routing via usrloc, log the missed calls also if KSR.is_INVITE() : - KSR.setflag(FLT_ACCMISSED); + KSR.setflag(FLT_ACCMISSED) - self.ksr_route_relay(msg); - return -255; + self.ksr_route_relay(msg) + return -255 @@ -262,39 +261,39 @@ class kamailio: if not KSR.is_REGISTER() : if KSR.permissions.allow_source_address(1)>0 : # source IP allowed - return 1; + return 1 if KSR.is_REGISTER() or KSR.is_myself_furi() : # authenticate requests if KSR.auth_db.auth_check(KSR.pv.get("$fd"), "subscriber", 1)<0 : - KSR.auth.auth_challenge(KSR.pv.get("$fd"), 0); - return -255; + KSR.auth.auth_challenge(KSR.pv.get("$fd"), 0) + return -255 # user authenticated - remove auth header if not KSR.is_method_in("RP") : - KSR.auth.consume_credentials(); + KSR.auth.consume_credentials() # if caller is not local subscriber, then check if it calls # a local destination, otherwise deny, not an open relay here if (not KSR.is_myself_furi()) and (not KSR.is_myself_ruri()) : - KSR.sl.sl_send_reply(403,"Not relaying"); - return -255; + KSR.sl.sl_send_reply(403,"Not relaying") + return -255 - return 1; + return 1 # Caller NAT detection def ksr_route_natdetect(self, msg): - KSR.force_rport(); + KSR.force_rport() if KSR.nathelper.nat_uac_test(19)>0 : if KSR.is_REGISTER() : - KSR.nathelper.fix_nated_register(); + KSR.nathelper.fix_nated_register() elif KSR.siputils.is_first_hop()>0 : - KSR.nathelper.set_contact_alias(); + KSR.nathelper.set_contact_alias() - KSR.setflag(FLT_NATS); + KSR.setflag(FLT_NATS) - return 1; + return 1 # RTPProxy control @@ -302,79 +301,79 @@ class kamailio: if KSR.siputils.is_request()>0 : if KSR.siputils.has_totag()>0 : if KSR.rr.check_route_param("nat=yes")>0 : - KSR.setbflag(FLB_NATB); + KSR.setbflag(FLB_NATB) if (not (KSR.isflagset(FLT_NATS) or KSR.isbflagset(FLB_NATB))) : - return 1; + return 1 - KSR.rtpproxy.rtpproxy_manage("co"); + KSR.rtpproxy.rtpproxy_manage("co") if KSR.siputils.is_request()>0 : if not KSR.siputils.has_totag() : if KSR.tmx.t_is_branch_route()>0 : - KSR.rr.add_rr_param(";nat=yes"); + KSR.rr.add_rr_param(";nat=yes") if KSR.siputils.is_reply()>0 : if KSR.isbflagset(FLB_NATB) : - KSR.nathelper.set_contact_alias(); + KSR.nathelper.set_contact_alias() - return 1; + return 1 # URI update for dialog requests def ksr_route_dlguri(self, msg): if not KSR.isdsturiset() : - KSR.nathelper.handle_ruri_alias(); + KSR.nathelper.handle_ruri_alias() - return 1; + return 1 # Routing to foreign domains def ksr_route_sipout(self, msg): if KSR.is_myself_ruri() : - return 1; + return 1 - KSR.hdr.append("P-Hint: outbound\r\n"); - self.ksr_route_relay(msg); - return -255; + KSR.hdr.append("P-Hint: outbound\r\n") + self.ksr_route_relay(msg) + return -255 # Manage outgoing branches # -- equivalent of branch_route[...]{} def ksr_branch_manage(self, msg): KSR.dbg("new branch ["+ str(KSR.pv.get("$T_branch_idx")) - + "] to "+ KSR.pv.get("$ru") + "\n"); - self.ksr_route_natmanage(msg); - return 1; + + "] to "+ KSR.pv.get("$ru") + "\n") + self.ksr_route_natmanage(msg) + return 1 # Manage incoming replies # -- equivalent of onreply_route[...]{} def ksr_onreply_manage(self, msg): - KSR.dbg("incoming reply\n"); - scode = KSR.pv.get("$rs"); + KSR.dbg("incoming reply\n") + scode = KSR.pv.get("$rs") if scode>100 and scode<299 : - self.ksr_route_natmanage(msg); + self.ksr_route_natmanage(msg) - return 1; + return 1 # Manage failure routing cases # -- equivalent of failure_route[...]{} def ksr_failure_manage(self, msg): - if self.ksr_route_natmanage(msg)==-255 : return 1; + if self.ksr_route_natmanage(msg)==-255 : return 1 if KSR.tm.t_is_canceled()>0 : - return 1; + return 1 - return 1; + return 1 # SIP response handling # -- equivalent of reply_route{} def ksr_reply_route(self, msg): - KSR.info("===== response - from kamailio python script\n"); - return 1; + KSR.info("===== response - from kamailio python script\n") + return 1 # -- {end defining kamailio class} @@ -383,6 +382,5 @@ class kamailio: # global helper function for debugging purposes def dumpObj(obj): for attr in dir(obj): - # KSR.info("obj.%s = %s\n" % (attr, getattr(obj, attr))); - Logger.LM_INFO("obj.%s = %s\n" % (attr, getattr(obj, attr))); + KSR.info("obj.%s = %s\n" % (attr, getattr(obj, attr))) diff --git a/pkg/kamailio/alpine/APKBUILD b/pkg/kamailio/alpine/APKBUILD index 0d421c624..1e211cb3d 100644 --- a/pkg/kamailio/alpine/APKBUILD +++ b/pkg/kamailio/alpine/APKBUILD @@ -4,7 +4,7 @@ # Maintainer: Nathan Angelacos pkgname=kamailio -pkgver=5.3.4 +pkgver=5.3.5 pkgrel=0 # If building from a git snapshot, specify the gitcommit diff --git a/pkg/kamailio/deb/bionic/changelog b/pkg/kamailio/deb/bionic/changelog index cca27d806..c2ec8fdaa 100644 --- a/pkg/kamailio/deb/bionic/changelog +++ b/pkg/kamailio/deb/bionic/changelog @@ -1,3 +1,9 @@ +kamailio (5.3.5) unstable; urgency=medium + + * version set 5.3.5 + + -- Victor Seva Mon, 22 Jun 2020 09:18:58 +0200 + kamailio (5.3.4) unstable; urgency=medium * version set 5.3.4 diff --git a/pkg/kamailio/deb/bionic/kamailio.default b/pkg/kamailio/deb/bionic/kamailio.default index 8b20fc003..81c89258d 100644 --- a/pkg/kamailio/deb/bionic/kamailio.default +++ b/pkg/kamailio/deb/bionic/kamailio.default @@ -11,6 +11,14 @@ # Group to run as #GROUP=kamailio +# On systemd, to change username or group please create drop-in +# /etc/systemd/system/kamailio.service.d/10-user_group.conf file, like +# ``` +# [Service] +# User=kamuser +# Group=kamgroup +# ``` + # Amount of shared and private memory to allocate # for the running Kamailio server (in Mb) #SHM_MEMORY=64 diff --git a/pkg/kamailio/deb/bionic/kamailio.init b/pkg/kamailio/deb/bionic/kamailio.init index 09ca0800c..45621c67a 100644 --- a/pkg/kamailio/deb/bionic/kamailio.init +++ b/pkg/kamailio/deb/bionic/kamailio.init @@ -18,7 +18,7 @@ PATH=/sbin:/bin:/usr/sbin:/usr/bin DAEMON=/usr/sbin/kamailio NAME=`basename "$0"` DESC="Kamailio SIP Server" -HOMEDIR=/var/run/$NAME +HOMEDIR=/run/$NAME PIDFILE=$HOMEDIR/$NAME.pid DEFAULTS=/etc/default/$NAME CFGFILE=/etc/$NAME/kamailio.cfg @@ -112,7 +112,7 @@ if test "$DUMP_CORE" = "yes" ; then # echo "$COREDIR/core.%e.sig%s.%p" > /proc/sys/kernel/core_pattern fi -# /var/run can be a tmpfs +# $HOMEDIR can be a tmpfs if [ ! -d $HOMEDIR ]; then mkdir -p $HOMEDIR chown ${USER}:${GROUP} $HOMEDIR diff --git a/pkg/kamailio/deb/bionic/kamailio.service b/pkg/kamailio/deb/bionic/kamailio.service index 4575fde61..5c697f635 100644 --- a/pkg/kamailio/deb/bionic/kamailio.service +++ b/pkg/kamailio/deb/bionic/kamailio.service @@ -5,19 +5,19 @@ After=network-online.target [Service] Type=forking +User=kamailio +Group=kamailio Environment='CFGFILE=/etc/kamailio/kamailio.cfg' Environment='SHM_MEMORY=64' Environment='PKG_MEMORY=8' -Environment='USER=kamailio' -Environment='GROUP=kamailio' EnvironmentFile=-/etc/default/kamailio EnvironmentFile=-/etc/default/kamailio.d/* # PIDFile requires a full absolute path -PIDFile=/var/run/kamailio/kamailio.pid +PIDFile=/run/kamailio/kamailio.pid # ExecStart requires a full absolute path -ExecStart=/usr/sbin/kamailio -P /var/run/kamailio/kamailio.pid -f $CFGFILE -m $SHM_MEMORY -M $PKG_MEMORY -u $USER -g $GROUP +ExecStart=/usr/sbin/kamailio -P /run/kamailio/kamailio.pid -f $CFGFILE -m $SHM_MEMORY -M $PKG_MEMORY Restart=on-failure -# /var/run/kamailio in tmpfs +# /run/kamailio in tmpfs RuntimeDirectory=kamailio RuntimeDirectoryMode=0750 diff --git a/pkg/kamailio/deb/buster/changelog b/pkg/kamailio/deb/buster/changelog index cca27d806..c2ec8fdaa 100644 --- a/pkg/kamailio/deb/buster/changelog +++ b/pkg/kamailio/deb/buster/changelog @@ -1,3 +1,9 @@ +kamailio (5.3.5) unstable; urgency=medium + + * version set 5.3.5 + + -- Victor Seva Mon, 22 Jun 2020 09:18:58 +0200 + kamailio (5.3.4) unstable; urgency=medium * version set 5.3.4 diff --git a/pkg/kamailio/deb/buster/kamailio.default b/pkg/kamailio/deb/buster/kamailio.default index 8b20fc003..81c89258d 100644 --- a/pkg/kamailio/deb/buster/kamailio.default +++ b/pkg/kamailio/deb/buster/kamailio.default @@ -11,6 +11,14 @@ # Group to run as #GROUP=kamailio +# On systemd, to change username or group please create drop-in +# /etc/systemd/system/kamailio.service.d/10-user_group.conf file, like +# ``` +# [Service] +# User=kamuser +# Group=kamgroup +# ``` + # Amount of shared and private memory to allocate # for the running Kamailio server (in Mb) #SHM_MEMORY=64 diff --git a/pkg/kamailio/deb/buster/kamailio.init b/pkg/kamailio/deb/buster/kamailio.init index 09ca0800c..45621c67a 100644 --- a/pkg/kamailio/deb/buster/kamailio.init +++ b/pkg/kamailio/deb/buster/kamailio.init @@ -18,7 +18,7 @@ PATH=/sbin:/bin:/usr/sbin:/usr/bin DAEMON=/usr/sbin/kamailio NAME=`basename "$0"` DESC="Kamailio SIP Server" -HOMEDIR=/var/run/$NAME +HOMEDIR=/run/$NAME PIDFILE=$HOMEDIR/$NAME.pid DEFAULTS=/etc/default/$NAME CFGFILE=/etc/$NAME/kamailio.cfg @@ -112,7 +112,7 @@ if test "$DUMP_CORE" = "yes" ; then # echo "$COREDIR/core.%e.sig%s.%p" > /proc/sys/kernel/core_pattern fi -# /var/run can be a tmpfs +# $HOMEDIR can be a tmpfs if [ ! -d $HOMEDIR ]; then mkdir -p $HOMEDIR chown ${USER}:${GROUP} $HOMEDIR diff --git a/pkg/kamailio/deb/buster/kamailio.service b/pkg/kamailio/deb/buster/kamailio.service index 4575fde61..5c697f635 100644 --- a/pkg/kamailio/deb/buster/kamailio.service +++ b/pkg/kamailio/deb/buster/kamailio.service @@ -5,19 +5,19 @@ After=network-online.target [Service] Type=forking +User=kamailio +Group=kamailio Environment='CFGFILE=/etc/kamailio/kamailio.cfg' Environment='SHM_MEMORY=64' Environment='PKG_MEMORY=8' -Environment='USER=kamailio' -Environment='GROUP=kamailio' EnvironmentFile=-/etc/default/kamailio EnvironmentFile=-/etc/default/kamailio.d/* # PIDFile requires a full absolute path -PIDFile=/var/run/kamailio/kamailio.pid +PIDFile=/run/kamailio/kamailio.pid # ExecStart requires a full absolute path -ExecStart=/usr/sbin/kamailio -P /var/run/kamailio/kamailio.pid -f $CFGFILE -m $SHM_MEMORY -M $PKG_MEMORY -u $USER -g $GROUP +ExecStart=/usr/sbin/kamailio -P /run/kamailio/kamailio.pid -f $CFGFILE -m $SHM_MEMORY -M $PKG_MEMORY Restart=on-failure -# /var/run/kamailio in tmpfs +# /run/kamailio in tmpfs RuntimeDirectory=kamailio RuntimeDirectoryMode=0750 diff --git a/pkg/kamailio/deb/debian/changelog b/pkg/kamailio/deb/debian/changelog index cca27d806..c2ec8fdaa 100644 --- a/pkg/kamailio/deb/debian/changelog +++ b/pkg/kamailio/deb/debian/changelog @@ -1,3 +1,9 @@ +kamailio (5.3.5) unstable; urgency=medium + + * version set 5.3.5 + + -- Victor Seva Mon, 22 Jun 2020 09:18:58 +0200 + kamailio (5.3.4) unstable; urgency=medium * version set 5.3.4 diff --git a/pkg/kamailio/deb/debian/kamailio.default b/pkg/kamailio/deb/debian/kamailio.default index 8b20fc003..81c89258d 100644 --- a/pkg/kamailio/deb/debian/kamailio.default +++ b/pkg/kamailio/deb/debian/kamailio.default @@ -11,6 +11,14 @@ # Group to run as #GROUP=kamailio +# On systemd, to change username or group please create drop-in +# /etc/systemd/system/kamailio.service.d/10-user_group.conf file, like +# ``` +# [Service] +# User=kamuser +# Group=kamgroup +# ``` + # Amount of shared and private memory to allocate # for the running Kamailio server (in Mb) #SHM_MEMORY=64 diff --git a/pkg/kamailio/deb/debian/kamailio.init b/pkg/kamailio/deb/debian/kamailio.init index 09ca0800c..45621c67a 100644 --- a/pkg/kamailio/deb/debian/kamailio.init +++ b/pkg/kamailio/deb/debian/kamailio.init @@ -18,7 +18,7 @@ PATH=/sbin:/bin:/usr/sbin:/usr/bin DAEMON=/usr/sbin/kamailio NAME=`basename "$0"` DESC="Kamailio SIP Server" -HOMEDIR=/var/run/$NAME +HOMEDIR=/run/$NAME PIDFILE=$HOMEDIR/$NAME.pid DEFAULTS=/etc/default/$NAME CFGFILE=/etc/$NAME/kamailio.cfg @@ -112,7 +112,7 @@ if test "$DUMP_CORE" = "yes" ; then # echo "$COREDIR/core.%e.sig%s.%p" > /proc/sys/kernel/core_pattern fi -# /var/run can be a tmpfs +# $HOMEDIR can be a tmpfs if [ ! -d $HOMEDIR ]; then mkdir -p $HOMEDIR chown ${USER}:${GROUP} $HOMEDIR diff --git a/pkg/kamailio/deb/debian/kamailio.service b/pkg/kamailio/deb/debian/kamailio.service index 4575fde61..5c697f635 100644 --- a/pkg/kamailio/deb/debian/kamailio.service +++ b/pkg/kamailio/deb/debian/kamailio.service @@ -5,19 +5,19 @@ After=network-online.target [Service] Type=forking +User=kamailio +Group=kamailio Environment='CFGFILE=/etc/kamailio/kamailio.cfg' Environment='SHM_MEMORY=64' Environment='PKG_MEMORY=8' -Environment='USER=kamailio' -Environment='GROUP=kamailio' EnvironmentFile=-/etc/default/kamailio EnvironmentFile=-/etc/default/kamailio.d/* # PIDFile requires a full absolute path -PIDFile=/var/run/kamailio/kamailio.pid +PIDFile=/run/kamailio/kamailio.pid # ExecStart requires a full absolute path -ExecStart=/usr/sbin/kamailio -P /var/run/kamailio/kamailio.pid -f $CFGFILE -m $SHM_MEMORY -M $PKG_MEMORY -u $USER -g $GROUP +ExecStart=/usr/sbin/kamailio -P /run/kamailio/kamailio.pid -f $CFGFILE -m $SHM_MEMORY -M $PKG_MEMORY Restart=on-failure -# /var/run/kamailio in tmpfs +# /run/kamailio in tmpfs RuntimeDirectory=kamailio RuntimeDirectoryMode=0750 diff --git a/pkg/kamailio/deb/jessie/changelog b/pkg/kamailio/deb/jessie/changelog index cca27d806..c2ec8fdaa 100644 --- a/pkg/kamailio/deb/jessie/changelog +++ b/pkg/kamailio/deb/jessie/changelog @@ -1,3 +1,9 @@ +kamailio (5.3.5) unstable; urgency=medium + + * version set 5.3.5 + + -- Victor Seva Mon, 22 Jun 2020 09:18:58 +0200 + kamailio (5.3.4) unstable; urgency=medium * version set 5.3.4 diff --git a/pkg/kamailio/deb/jessie/kamailio.default b/pkg/kamailio/deb/jessie/kamailio.default index 8b20fc003..81c89258d 100644 --- a/pkg/kamailio/deb/jessie/kamailio.default +++ b/pkg/kamailio/deb/jessie/kamailio.default @@ -11,6 +11,14 @@ # Group to run as #GROUP=kamailio +# On systemd, to change username or group please create drop-in +# /etc/systemd/system/kamailio.service.d/10-user_group.conf file, like +# ``` +# [Service] +# User=kamuser +# Group=kamgroup +# ``` + # Amount of shared and private memory to allocate # for the running Kamailio server (in Mb) #SHM_MEMORY=64 diff --git a/pkg/kamailio/deb/jessie/kamailio.init b/pkg/kamailio/deb/jessie/kamailio.init index 09ca0800c..45621c67a 100644 --- a/pkg/kamailio/deb/jessie/kamailio.init +++ b/pkg/kamailio/deb/jessie/kamailio.init @@ -18,7 +18,7 @@ PATH=/sbin:/bin:/usr/sbin:/usr/bin DAEMON=/usr/sbin/kamailio NAME=`basename "$0"` DESC="Kamailio SIP Server" -HOMEDIR=/var/run/$NAME +HOMEDIR=/run/$NAME PIDFILE=$HOMEDIR/$NAME.pid DEFAULTS=/etc/default/$NAME CFGFILE=/etc/$NAME/kamailio.cfg @@ -112,7 +112,7 @@ if test "$DUMP_CORE" = "yes" ; then # echo "$COREDIR/core.%e.sig%s.%p" > /proc/sys/kernel/core_pattern fi -# /var/run can be a tmpfs +# $HOMEDIR can be a tmpfs if [ ! -d $HOMEDIR ]; then mkdir -p $HOMEDIR chown ${USER}:${GROUP} $HOMEDIR diff --git a/pkg/kamailio/deb/jessie/kamailio.service b/pkg/kamailio/deb/jessie/kamailio.service index 4575fde61..5c697f635 100644 --- a/pkg/kamailio/deb/jessie/kamailio.service +++ b/pkg/kamailio/deb/jessie/kamailio.service @@ -5,19 +5,19 @@ After=network-online.target [Service] Type=forking +User=kamailio +Group=kamailio Environment='CFGFILE=/etc/kamailio/kamailio.cfg' Environment='SHM_MEMORY=64' Environment='PKG_MEMORY=8' -Environment='USER=kamailio' -Environment='GROUP=kamailio' EnvironmentFile=-/etc/default/kamailio EnvironmentFile=-/etc/default/kamailio.d/* # PIDFile requires a full absolute path -PIDFile=/var/run/kamailio/kamailio.pid +PIDFile=/run/kamailio/kamailio.pid # ExecStart requires a full absolute path -ExecStart=/usr/sbin/kamailio -P /var/run/kamailio/kamailio.pid -f $CFGFILE -m $SHM_MEMORY -M $PKG_MEMORY -u $USER -g $GROUP +ExecStart=/usr/sbin/kamailio -P /run/kamailio/kamailio.pid -f $CFGFILE -m $SHM_MEMORY -M $PKG_MEMORY Restart=on-failure -# /var/run/kamailio in tmpfs +# /run/kamailio in tmpfs RuntimeDirectory=kamailio RuntimeDirectoryMode=0750 diff --git a/pkg/kamailio/deb/precise/changelog b/pkg/kamailio/deb/precise/changelog index cca27d806..c2ec8fdaa 100644 --- a/pkg/kamailio/deb/precise/changelog +++ b/pkg/kamailio/deb/precise/changelog @@ -1,3 +1,9 @@ +kamailio (5.3.5) unstable; urgency=medium + + * version set 5.3.5 + + -- Victor Seva Mon, 22 Jun 2020 09:18:58 +0200 + kamailio (5.3.4) unstable; urgency=medium * version set 5.3.4 diff --git a/pkg/kamailio/deb/precise/kamailio.default b/pkg/kamailio/deb/precise/kamailio.default index 8b20fc003..81c89258d 100644 --- a/pkg/kamailio/deb/precise/kamailio.default +++ b/pkg/kamailio/deb/precise/kamailio.default @@ -11,6 +11,14 @@ # Group to run as #GROUP=kamailio +# On systemd, to change username or group please create drop-in +# /etc/systemd/system/kamailio.service.d/10-user_group.conf file, like +# ``` +# [Service] +# User=kamuser +# Group=kamgroup +# ``` + # Amount of shared and private memory to allocate # for the running Kamailio server (in Mb) #SHM_MEMORY=64 diff --git a/pkg/kamailio/deb/precise/kamailio.init b/pkg/kamailio/deb/precise/kamailio.init index 09ca0800c..45621c67a 100644 --- a/pkg/kamailio/deb/precise/kamailio.init +++ b/pkg/kamailio/deb/precise/kamailio.init @@ -18,7 +18,7 @@ PATH=/sbin:/bin:/usr/sbin:/usr/bin DAEMON=/usr/sbin/kamailio NAME=`basename "$0"` DESC="Kamailio SIP Server" -HOMEDIR=/var/run/$NAME +HOMEDIR=/run/$NAME PIDFILE=$HOMEDIR/$NAME.pid DEFAULTS=/etc/default/$NAME CFGFILE=/etc/$NAME/kamailio.cfg @@ -112,7 +112,7 @@ if test "$DUMP_CORE" = "yes" ; then # echo "$COREDIR/core.%e.sig%s.%p" > /proc/sys/kernel/core_pattern fi -# /var/run can be a tmpfs +# $HOMEDIR can be a tmpfs if [ ! -d $HOMEDIR ]; then mkdir -p $HOMEDIR chown ${USER}:${GROUP} $HOMEDIR diff --git a/pkg/kamailio/deb/sid/changelog b/pkg/kamailio/deb/sid/changelog index cca27d806..c2ec8fdaa 100644 --- a/pkg/kamailio/deb/sid/changelog +++ b/pkg/kamailio/deb/sid/changelog @@ -1,3 +1,9 @@ +kamailio (5.3.5) unstable; urgency=medium + + * version set 5.3.5 + + -- Victor Seva Mon, 22 Jun 2020 09:18:58 +0200 + kamailio (5.3.4) unstable; urgency=medium * version set 5.3.4 diff --git a/pkg/kamailio/deb/sid/kamailio.default b/pkg/kamailio/deb/sid/kamailio.default index 8b20fc003..81c89258d 100644 --- a/pkg/kamailio/deb/sid/kamailio.default +++ b/pkg/kamailio/deb/sid/kamailio.default @@ -11,6 +11,14 @@ # Group to run as #GROUP=kamailio +# On systemd, to change username or group please create drop-in +# /etc/systemd/system/kamailio.service.d/10-user_group.conf file, like +# ``` +# [Service] +# User=kamuser +# Group=kamgroup +# ``` + # Amount of shared and private memory to allocate # for the running Kamailio server (in Mb) #SHM_MEMORY=64 diff --git a/pkg/kamailio/deb/sid/kamailio.init b/pkg/kamailio/deb/sid/kamailio.init index 09ca0800c..45621c67a 100644 --- a/pkg/kamailio/deb/sid/kamailio.init +++ b/pkg/kamailio/deb/sid/kamailio.init @@ -18,7 +18,7 @@ PATH=/sbin:/bin:/usr/sbin:/usr/bin DAEMON=/usr/sbin/kamailio NAME=`basename "$0"` DESC="Kamailio SIP Server" -HOMEDIR=/var/run/$NAME +HOMEDIR=/run/$NAME PIDFILE=$HOMEDIR/$NAME.pid DEFAULTS=/etc/default/$NAME CFGFILE=/etc/$NAME/kamailio.cfg @@ -112,7 +112,7 @@ if test "$DUMP_CORE" = "yes" ; then # echo "$COREDIR/core.%e.sig%s.%p" > /proc/sys/kernel/core_pattern fi -# /var/run can be a tmpfs +# $HOMEDIR can be a tmpfs if [ ! -d $HOMEDIR ]; then mkdir -p $HOMEDIR chown ${USER}:${GROUP} $HOMEDIR diff --git a/pkg/kamailio/deb/sid/kamailio.service b/pkg/kamailio/deb/sid/kamailio.service index 4575fde61..5c697f635 100644 --- a/pkg/kamailio/deb/sid/kamailio.service +++ b/pkg/kamailio/deb/sid/kamailio.service @@ -5,19 +5,19 @@ After=network-online.target [Service] Type=forking +User=kamailio +Group=kamailio Environment='CFGFILE=/etc/kamailio/kamailio.cfg' Environment='SHM_MEMORY=64' Environment='PKG_MEMORY=8' -Environment='USER=kamailio' -Environment='GROUP=kamailio' EnvironmentFile=-/etc/default/kamailio EnvironmentFile=-/etc/default/kamailio.d/* # PIDFile requires a full absolute path -PIDFile=/var/run/kamailio/kamailio.pid +PIDFile=/run/kamailio/kamailio.pid # ExecStart requires a full absolute path -ExecStart=/usr/sbin/kamailio -P /var/run/kamailio/kamailio.pid -f $CFGFILE -m $SHM_MEMORY -M $PKG_MEMORY -u $USER -g $GROUP +ExecStart=/usr/sbin/kamailio -P /run/kamailio/kamailio.pid -f $CFGFILE -m $SHM_MEMORY -M $PKG_MEMORY Restart=on-failure -# /var/run/kamailio in tmpfs +# /run/kamailio in tmpfs RuntimeDirectory=kamailio RuntimeDirectoryMode=0750 diff --git a/pkg/kamailio/deb/stretch/changelog b/pkg/kamailio/deb/stretch/changelog index cca27d806..c2ec8fdaa 100644 --- a/pkg/kamailio/deb/stretch/changelog +++ b/pkg/kamailio/deb/stretch/changelog @@ -1,3 +1,9 @@ +kamailio (5.3.5) unstable; urgency=medium + + * version set 5.3.5 + + -- Victor Seva Mon, 22 Jun 2020 09:18:58 +0200 + kamailio (5.3.4) unstable; urgency=medium * version set 5.3.4 diff --git a/pkg/kamailio/deb/stretch/kamailio.default b/pkg/kamailio/deb/stretch/kamailio.default index 8b20fc003..81c89258d 100644 --- a/pkg/kamailio/deb/stretch/kamailio.default +++ b/pkg/kamailio/deb/stretch/kamailio.default @@ -11,6 +11,14 @@ # Group to run as #GROUP=kamailio +# On systemd, to change username or group please create drop-in +# /etc/systemd/system/kamailio.service.d/10-user_group.conf file, like +# ``` +# [Service] +# User=kamuser +# Group=kamgroup +# ``` + # Amount of shared and private memory to allocate # for the running Kamailio server (in Mb) #SHM_MEMORY=64 diff --git a/pkg/kamailio/deb/stretch/kamailio.init b/pkg/kamailio/deb/stretch/kamailio.init index 09ca0800c..45621c67a 100644 --- a/pkg/kamailio/deb/stretch/kamailio.init +++ b/pkg/kamailio/deb/stretch/kamailio.init @@ -18,7 +18,7 @@ PATH=/sbin:/bin:/usr/sbin:/usr/bin DAEMON=/usr/sbin/kamailio NAME=`basename "$0"` DESC="Kamailio SIP Server" -HOMEDIR=/var/run/$NAME +HOMEDIR=/run/$NAME PIDFILE=$HOMEDIR/$NAME.pid DEFAULTS=/etc/default/$NAME CFGFILE=/etc/$NAME/kamailio.cfg @@ -112,7 +112,7 @@ if test "$DUMP_CORE" = "yes" ; then # echo "$COREDIR/core.%e.sig%s.%p" > /proc/sys/kernel/core_pattern fi -# /var/run can be a tmpfs +# $HOMEDIR can be a tmpfs if [ ! -d $HOMEDIR ]; then mkdir -p $HOMEDIR chown ${USER}:${GROUP} $HOMEDIR diff --git a/pkg/kamailio/deb/stretch/kamailio.service b/pkg/kamailio/deb/stretch/kamailio.service index 4575fde61..5c697f635 100644 --- a/pkg/kamailio/deb/stretch/kamailio.service +++ b/pkg/kamailio/deb/stretch/kamailio.service @@ -5,19 +5,19 @@ After=network-online.target [Service] Type=forking +User=kamailio +Group=kamailio Environment='CFGFILE=/etc/kamailio/kamailio.cfg' Environment='SHM_MEMORY=64' Environment='PKG_MEMORY=8' -Environment='USER=kamailio' -Environment='GROUP=kamailio' EnvironmentFile=-/etc/default/kamailio EnvironmentFile=-/etc/default/kamailio.d/* # PIDFile requires a full absolute path -PIDFile=/var/run/kamailio/kamailio.pid +PIDFile=/run/kamailio/kamailio.pid # ExecStart requires a full absolute path -ExecStart=/usr/sbin/kamailio -P /var/run/kamailio/kamailio.pid -f $CFGFILE -m $SHM_MEMORY -M $PKG_MEMORY -u $USER -g $GROUP +ExecStart=/usr/sbin/kamailio -P /run/kamailio/kamailio.pid -f $CFGFILE -m $SHM_MEMORY -M $PKG_MEMORY Restart=on-failure -# /var/run/kamailio in tmpfs +# /run/kamailio in tmpfs RuntimeDirectory=kamailio RuntimeDirectoryMode=0750 diff --git a/pkg/kamailio/deb/trusty/changelog b/pkg/kamailio/deb/trusty/changelog index cca27d806..c2ec8fdaa 100644 --- a/pkg/kamailio/deb/trusty/changelog +++ b/pkg/kamailio/deb/trusty/changelog @@ -1,3 +1,9 @@ +kamailio (5.3.5) unstable; urgency=medium + + * version set 5.3.5 + + -- Victor Seva Mon, 22 Jun 2020 09:18:58 +0200 + kamailio (5.3.4) unstable; urgency=medium * version set 5.3.4 diff --git a/pkg/kamailio/deb/trusty/kamailio.default b/pkg/kamailio/deb/trusty/kamailio.default index 8b20fc003..81c89258d 100644 --- a/pkg/kamailio/deb/trusty/kamailio.default +++ b/pkg/kamailio/deb/trusty/kamailio.default @@ -11,6 +11,14 @@ # Group to run as #GROUP=kamailio +# On systemd, to change username or group please create drop-in +# /etc/systemd/system/kamailio.service.d/10-user_group.conf file, like +# ``` +# [Service] +# User=kamuser +# Group=kamgroup +# ``` + # Amount of shared and private memory to allocate # for the running Kamailio server (in Mb) #SHM_MEMORY=64 diff --git a/pkg/kamailio/deb/trusty/kamailio.init b/pkg/kamailio/deb/trusty/kamailio.init index 09ca0800c..45621c67a 100644 --- a/pkg/kamailio/deb/trusty/kamailio.init +++ b/pkg/kamailio/deb/trusty/kamailio.init @@ -18,7 +18,7 @@ PATH=/sbin:/bin:/usr/sbin:/usr/bin DAEMON=/usr/sbin/kamailio NAME=`basename "$0"` DESC="Kamailio SIP Server" -HOMEDIR=/var/run/$NAME +HOMEDIR=/run/$NAME PIDFILE=$HOMEDIR/$NAME.pid DEFAULTS=/etc/default/$NAME CFGFILE=/etc/$NAME/kamailio.cfg @@ -112,7 +112,7 @@ if test "$DUMP_CORE" = "yes" ; then # echo "$COREDIR/core.%e.sig%s.%p" > /proc/sys/kernel/core_pattern fi -# /var/run can be a tmpfs +# $HOMEDIR can be a tmpfs if [ ! -d $HOMEDIR ]; then mkdir -p $HOMEDIR chown ${USER}:${GROUP} $HOMEDIR diff --git a/pkg/kamailio/deb/wheezy/changelog b/pkg/kamailio/deb/wheezy/changelog index cca27d806..c2ec8fdaa 100644 --- a/pkg/kamailio/deb/wheezy/changelog +++ b/pkg/kamailio/deb/wheezy/changelog @@ -1,3 +1,9 @@ +kamailio (5.3.5) unstable; urgency=medium + + * version set 5.3.5 + + -- Victor Seva Mon, 22 Jun 2020 09:18:58 +0200 + kamailio (5.3.4) unstable; urgency=medium * version set 5.3.4 diff --git a/pkg/kamailio/deb/wheezy/kamailio.default b/pkg/kamailio/deb/wheezy/kamailio.default index 8b20fc003..81c89258d 100644 --- a/pkg/kamailio/deb/wheezy/kamailio.default +++ b/pkg/kamailio/deb/wheezy/kamailio.default @@ -11,6 +11,14 @@ # Group to run as #GROUP=kamailio +# On systemd, to change username or group please create drop-in +# /etc/systemd/system/kamailio.service.d/10-user_group.conf file, like +# ``` +# [Service] +# User=kamuser +# Group=kamgroup +# ``` + # Amount of shared and private memory to allocate # for the running Kamailio server (in Mb) #SHM_MEMORY=64 diff --git a/pkg/kamailio/deb/wheezy/kamailio.init b/pkg/kamailio/deb/wheezy/kamailio.init index 09ca0800c..45621c67a 100644 --- a/pkg/kamailio/deb/wheezy/kamailio.init +++ b/pkg/kamailio/deb/wheezy/kamailio.init @@ -18,7 +18,7 @@ PATH=/sbin:/bin:/usr/sbin:/usr/bin DAEMON=/usr/sbin/kamailio NAME=`basename "$0"` DESC="Kamailio SIP Server" -HOMEDIR=/var/run/$NAME +HOMEDIR=/run/$NAME PIDFILE=$HOMEDIR/$NAME.pid DEFAULTS=/etc/default/$NAME CFGFILE=/etc/$NAME/kamailio.cfg @@ -112,7 +112,7 @@ if test "$DUMP_CORE" = "yes" ; then # echo "$COREDIR/core.%e.sig%s.%p" > /proc/sys/kernel/core_pattern fi -# /var/run can be a tmpfs +# $HOMEDIR can be a tmpfs if [ ! -d $HOMEDIR ]; then mkdir -p $HOMEDIR chown ${USER}:${GROUP} $HOMEDIR diff --git a/pkg/kamailio/deb/xenial/changelog b/pkg/kamailio/deb/xenial/changelog index cca27d806..c2ec8fdaa 100644 --- a/pkg/kamailio/deb/xenial/changelog +++ b/pkg/kamailio/deb/xenial/changelog @@ -1,3 +1,9 @@ +kamailio (5.3.5) unstable; urgency=medium + + * version set 5.3.5 + + -- Victor Seva Mon, 22 Jun 2020 09:18:58 +0200 + kamailio (5.3.4) unstable; urgency=medium * version set 5.3.4 diff --git a/pkg/kamailio/deb/xenial/kamailio.default b/pkg/kamailio/deb/xenial/kamailio.default index 8b20fc003..81c89258d 100644 --- a/pkg/kamailio/deb/xenial/kamailio.default +++ b/pkg/kamailio/deb/xenial/kamailio.default @@ -11,6 +11,14 @@ # Group to run as #GROUP=kamailio +# On systemd, to change username or group please create drop-in +# /etc/systemd/system/kamailio.service.d/10-user_group.conf file, like +# ``` +# [Service] +# User=kamuser +# Group=kamgroup +# ``` + # Amount of shared and private memory to allocate # for the running Kamailio server (in Mb) #SHM_MEMORY=64 diff --git a/pkg/kamailio/deb/xenial/kamailio.init b/pkg/kamailio/deb/xenial/kamailio.init index 09ca0800c..45621c67a 100644 --- a/pkg/kamailio/deb/xenial/kamailio.init +++ b/pkg/kamailio/deb/xenial/kamailio.init @@ -18,7 +18,7 @@ PATH=/sbin:/bin:/usr/sbin:/usr/bin DAEMON=/usr/sbin/kamailio NAME=`basename "$0"` DESC="Kamailio SIP Server" -HOMEDIR=/var/run/$NAME +HOMEDIR=/run/$NAME PIDFILE=$HOMEDIR/$NAME.pid DEFAULTS=/etc/default/$NAME CFGFILE=/etc/$NAME/kamailio.cfg @@ -112,7 +112,7 @@ if test "$DUMP_CORE" = "yes" ; then # echo "$COREDIR/core.%e.sig%s.%p" > /proc/sys/kernel/core_pattern fi -# /var/run can be a tmpfs +# $HOMEDIR can be a tmpfs if [ ! -d $HOMEDIR ]; then mkdir -p $HOMEDIR chown ${USER}:${GROUP} $HOMEDIR diff --git a/pkg/kamailio/deb/xenial/kamailio.service b/pkg/kamailio/deb/xenial/kamailio.service index 4575fde61..5c697f635 100644 --- a/pkg/kamailio/deb/xenial/kamailio.service +++ b/pkg/kamailio/deb/xenial/kamailio.service @@ -5,19 +5,19 @@ After=network-online.target [Service] Type=forking +User=kamailio +Group=kamailio Environment='CFGFILE=/etc/kamailio/kamailio.cfg' Environment='SHM_MEMORY=64' Environment='PKG_MEMORY=8' -Environment='USER=kamailio' -Environment='GROUP=kamailio' EnvironmentFile=-/etc/default/kamailio EnvironmentFile=-/etc/default/kamailio.d/* # PIDFile requires a full absolute path -PIDFile=/var/run/kamailio/kamailio.pid +PIDFile=/run/kamailio/kamailio.pid # ExecStart requires a full absolute path -ExecStart=/usr/sbin/kamailio -P /var/run/kamailio/kamailio.pid -f $CFGFILE -m $SHM_MEMORY -M $PKG_MEMORY -u $USER -g $GROUP +ExecStart=/usr/sbin/kamailio -P /run/kamailio/kamailio.pid -f $CFGFILE -m $SHM_MEMORY -M $PKG_MEMORY Restart=on-failure -# /var/run/kamailio in tmpfs +# /run/kamailio in tmpfs RuntimeDirectory=kamailio RuntimeDirectoryMode=0750 diff --git a/pkg/kamailio/obs/kamailio.spec b/pkg/kamailio/obs/kamailio.spec index 76c08aa81..9ff0a975e 100644 --- a/pkg/kamailio/obs/kamailio.spec +++ b/pkg/kamailio/obs/kamailio.spec @@ -1,5 +1,5 @@ %define name kamailio -%define ver 5.3.4 +%define ver 5.3.5 %define rel dev1.0%{dist} %if 0%{?fedora} @@ -1109,6 +1109,10 @@ UUID module for Kamailio. %prep %setup -n %{name}-%{ver} +# python3 does not exist in RHEL 6 and similar dist. +%if 0%{?rhel} == 6 +sed -i -e 's/python3/python2/' utils/kamctl/dbtextdb/dbtextdb.py +%endif %build ln -s ../obs pkg/kamailio/%{dist_name}/%{dist_version} @@ -1145,6 +1149,7 @@ make every-module skip_modules="app_mono db_cassandra db_oracle iptrtpproxy \ %if %{with http_async_client} khttp_async \ %endif + kxhttp_prom \ %if %{with ims} kims \ %endif @@ -1232,6 +1237,7 @@ make install-modules-all skip_modules="app_mono db_cassandra db_oracle \ %if %{with http_async_client} khttp_async \ %endif + kxhttp_prom \ %if %{with ims} kims \ %endif diff --git a/src/Makefile.defs b/src/Makefile.defs index ea5545681..460a58998 100644 --- a/src/Makefile.defs +++ b/src/Makefile.defs @@ -106,7 +106,7 @@ INSTALL_FLAVOUR=$(FLAVOUR) # version number VERSION = 5 PATCHLEVEL = 3 -SUBLEVEL = 4 +SUBLEVEL = 5 EXTRAVERSION = # memory manager switcher diff --git a/src/core/async_task.c b/src/core/async_task.c index 870241b0d..1045e0ab4 100644 --- a/src/core/async_task.c +++ b/src/core/async_task.c @@ -277,9 +277,11 @@ int async_task_run(int idx) continue; } if(ptask->exec!=NULL) { - LM_DBG("task executed [%p] (%p/%p)\n", ptask, - ptask->exec, ptask->param); + LM_DBG("task executed [%p] (%p/%p)\n", (void*)ptask, + (void*)ptask->exec, (void*)ptask->param); ptask->exec(ptask->param); + } else { + LM_DBG("task with no callback function - ignoring\n"); } shm_free(ptask); } diff --git a/src/core/autover.h b/src/core/autover.h index 5687d8c4f..7be4bf24f 100644 --- a/src/core/autover.h +++ b/src/core/autover.h @@ -2,6 +2,6 @@ * DO NOT EDIT IT */ -#define REPO_VER "117ff9" -#define REPO_HASH "117ff9" +#define REPO_VER "9e70e8" +#define REPO_HASH "9e70e8" #define REPO_STATE "" diff --git a/src/core/config.h b/src/core/config.h index a891328eb..248779784 100644 --- a/src/core/config.h +++ b/src/core/config.h @@ -77,12 +77,15 @@ #define CONTENT_LENGTH "Content-Length: " #define CONTENT_LENGTH_LEN (sizeof(CONTENT_LENGTH)-1) -#define USER_AGENT "User-Agent: " NAME \ +#define SRVAPP_SIGNATURE NAME \ " (" VERSION " (" ARCH "/" OS_QUOTED "))" +#define SRVAPP_SIGNATURE_LEN (sizeof(SRVAPP_SIGNATURE)-1) + + +#define USER_AGENT "User-Agent: " SRVAPP_SIGNATURE #define USER_AGENT_LEN (sizeof(USER_AGENT)-1) -#define SERVER_HDR "Server: " NAME \ - " (" VERSION " (" ARCH "/" OS_QUOTED "))" +#define SERVER_HDR "Server: " SRVAPP_SIGNATURE #define SERVER_HDR_LEN (sizeof(SERVER_HDR)-1) #define MAX_WARNING_LEN 256 diff --git a/src/core/events.h b/src/core/events.h index 9c4c54a2e..239c26bf0 100644 --- a/src/core/events.h +++ b/src/core/events.h @@ -38,7 +38,7 @@ #define SREV_NET_DATA_RECV 14 #define SREV_NET_DATA_SEND 15 -#define SREV_CB_LIST_SIZE 3 +#define SREV_CB_LIST_SIZE 8 typedef struct sr_event_param { void *data; diff --git a/src/core/io_wait.h b/src/core/io_wait.h index 3112085a1..9177ae2aa 100644 --- a/src/core/io_wait.h +++ b/src/core/io_wait.h @@ -109,12 +109,12 @@ typedef int fd_type; /* maps a fd to some other structure; used in almost all cases * except epoll and maybe kqueue or /dev/poll */ -struct fd_map{ +typedef struct fd_map { int fd; /* fd no */ fd_type type; /* "data" type */ void* data; /* pointer to the corresponding structure */ short events; /* events we are interested int */ -}; +} fd_map_t; #ifdef HAVE_KQUEUE @@ -132,7 +132,7 @@ struct fd_map{ /* handler structure */ -struct io_wait_handler{ +typedef struct io_wait_handler { enum poll_types poll_method; int flags; struct fd_map* fd_hash; @@ -172,13 +172,12 @@ struct io_wait_handler{ fd_set master_wset; /* write set */ int max_fd_select; /* maximum select used fd */ #endif -}; - -typedef struct io_wait_handler io_wait_h; +} io_wait_h; /* get the corresponding fd_map structure pointer */ #define get_fd_map(h, fd) (&(h)->fd_hash[(fd)]) + /* remove a fd_map structure from the hash; the pointer must be returned * by get_fd_map or hash_fd_map*/ #define unhash_fd_map(pfm) \ @@ -321,7 +320,7 @@ inline static int io_watch_add( io_wait_h* h, h->fd_array[h->fd_no].events=(ev); /* useless for select */ \ h->fd_array[h->fd_no].revents=0; /* useless for select */ \ }while(0) - + #define set_fd_flags(f) \ do{ \ flags=fcntl(fd, F_GETFL); \ @@ -336,8 +335,7 @@ inline static int io_watch_add( io_wait_h* h, goto error; \ } \ }while(0) - - + struct fd_map* e; int flags; #ifdef HAVE_EPOLL @@ -353,7 +351,7 @@ inline static int io_watch_add( io_wait_h* h, int idx; int check_io; struct pollfd pf; - + check_io=0; /* set to 1 if we need to check for pre-existing queued io/data on the fd */ idx=-1; @@ -378,13 +376,13 @@ inline static int io_watch_add( io_wait_h* h, /* hash sanity check */ e=get_fd_map(h, fd); if (unlikely(e && (e->type!=0 /*F_NONE*/))){ - LM_ERR("trying to overwrite entry %d" - " watched for %x in the hash(%d, %d, %p) with (%d, %d, %p)\n", - fd, events, e->fd, e->type, e->data, fd, type, data); + LM_ERR("trying to overwrite entry %d watched for %x" + " in the hash %p (fd:%d, type:%d, data:%p) with (%d, %d, %p)\n", + fd, events, h, e->fd, e->type, e->data, fd, type, data); e=0; goto error; } - + if (unlikely((e=hash_fd_map(h, fd, events, type, data))==0)){ LM_ERR("failed to hash the fd %d\n", fd); goto error; diff --git a/src/core/ip_addr.h b/src/core/ip_addr.h index 0d26e7e75..253b5a33d 100644 --- a/src/core/ip_addr.h +++ b/src/core/ip_addr.h @@ -71,6 +71,7 @@ union sockaddr_union{ struct sockaddr s; struct sockaddr_in sin; struct sockaddr_in6 sin6; + struct sockaddr_storage sas; }; @@ -790,11 +791,14 @@ static inline struct hostent* ip_addr2he(str* name, struct ip_addr* ip) static char* p_aliases[1]; static char* p_addr[2]; static char address[16]; + int len; p_aliases[0]=0; /* no aliases*/ p_addr[1]=0; /* only one address*/ p_addr[0]=address; - strncpy(hostname, name->s, (name->len<256)?(name->len)+1:256); + len = (name->len<255)?name->len:255; + memcpy(hostname, name->s, len); + hostname[len] = '\0'; if (ip->len>16) return 0; memcpy(address, ip->u.addr, ip->len); diff --git a/src/core/kemi.c b/src/core/kemi.c index 7a9625415..6a4732e90 100644 --- a/src/core/kemi.c +++ b/src/core/kemi.c @@ -1025,6 +1025,57 @@ static int sr_kemi_core_is_method_prack(sip_msg_t *msg) return sr_kemi_core_is_method_type(msg, METHOD_PRACK); } + +/** + * + */ +static int sr_kemi_core_is_method_message(sip_msg_t *msg) +{ + return sr_kemi_core_is_method_type(msg, METHOD_MESSAGE); +} + + +/** + * + */ +static int sr_kemi_core_is_method_kdmq(sip_msg_t *msg) +{ + return sr_kemi_core_is_method_type(msg, METHOD_KDMQ); +} + + +/** + * + */ +static int sr_kemi_core_is_method_get(sip_msg_t *msg) +{ + return sr_kemi_core_is_method_type(msg, METHOD_GET); +} + +/** + * + */ +static int sr_kemi_core_is_method_post(sip_msg_t *msg) +{ + return sr_kemi_core_is_method_type(msg, METHOD_POST); +} + +/** + * + */ +static int sr_kemi_core_is_method_put(sip_msg_t *msg) +{ + return sr_kemi_core_is_method_type(msg, METHOD_PUT); +} + +/** + * + */ +static int sr_kemi_core_is_method_delete(sip_msg_t *msg) +{ + return sr_kemi_core_is_method_type(msg, METHOD_DELETE); +} + /** * */ @@ -1645,6 +1696,36 @@ static sr_kemi_t _sr_kemi_core[] = { { SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE } }, + { str_init(""), str_init("is_MESSAGE"), + SR_KEMIP_BOOL, sr_kemi_core_is_method_message, + { SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE, + SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE } + }, + { str_init(""), str_init("is_KDMQ"), + SR_KEMIP_BOOL, sr_kemi_core_is_method_kdmq, + { SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE, + SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE } + }, + { str_init(""), str_init("is_GET"), + SR_KEMIP_BOOL, sr_kemi_core_is_method_get, + { SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE, + SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE } + }, + { str_init(""), str_init("is_POST"), + SR_KEMIP_BOOL, sr_kemi_core_is_method_post, + { SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE, + SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE } + }, + { str_init(""), str_init("is_PUT"), + SR_KEMIP_BOOL, sr_kemi_core_is_method_put, + { SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE, + SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE } + }, + { str_init(""), str_init("is_DELETE"), + SR_KEMIP_BOOL, sr_kemi_core_is_method_delete, + { SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE, + SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE } + }, { str_init(""), str_init("is_UDP"), SR_KEMIP_BOOL, sr_kemi_core_is_proto_udp, { SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE, diff --git a/src/core/parser/msg_parser.h b/src/core/parser/msg_parser.h index 2aad6ecb8..8d242d283 100644 --- a/src/core/parser/msg_parser.h +++ b/src/core/parser/msg_parser.h @@ -128,7 +128,7 @@ typedef enum request_method { #define IFISMETHOD(methodname,firstchar) \ if ( (*tmp==(firstchar) || *tmp==((firstchar) | 32)) && \ - strncasecmp( tmp+1, #methodname +1, methodname##_LEN-1)==0 && \ + strncasecmp( tmp+1, &#methodname[1], methodname##_LEN-1)==0 && \ *(tmp+methodname##_LEN)==' ') { \ fl->type=SIP_REQUEST; \ fl->u.request.method.len=methodname##_LEN; \ diff --git a/src/core/parser/parse_fline.c b/src/core/parser/parse_fline.c index c535b49a4..5016a31d5 100644 --- a/src/core/parser/parse_fline.c +++ b/src/core/parser/parse_fline.c @@ -90,7 +90,7 @@ char* parse_first_line(char* buffer, unsigned int len, struct msg_start* fl) tmp=buffer; /* is it perhaps a reply, ie does it start with "SIP...." ? */ if ( (*tmp=='S' || *tmp=='s') && - strncasecmp( tmp+1, SIP_VERSION+1, SIP_VERSION_LEN-1)==0 && + strncasecmp( tmp+1, &SIP_VERSION[1], SIP_VERSION_LEN-1)==0 && (*(tmp+SIP_VERSION_LEN)==' ')) { fl->type=SIP_REPLY; fl->flags|=FLINE_FLAG_PROTO_SIP; @@ -98,7 +98,7 @@ char* parse_first_line(char* buffer, unsigned int len, struct msg_start* fl) tmp=buffer+SIP_VERSION_LEN; } else if (http_reply_parse != 0 && (*tmp=='H' || *tmp=='h')) { /* 'HTTP/1.' */ - if (strncasecmp( tmp+1, HTTP_VERSION+1, HTTP_VERSION_LEN-1)==0 && + if (strncasecmp( tmp+1, &HTTP_VERSION[1], HTTP_VERSION_LEN-1)==0 && /* [0|1] */ ((*(tmp+HTTP_VERSION_LEN)=='0') || (*(tmp+HTTP_VERSION_LEN)=='1')) && (*(tmp+HTTP_VERSION_LEN+1)==' ') ){ @@ -111,7 +111,7 @@ char* parse_first_line(char* buffer, unsigned int len, struct msg_start* fl) fl->u.reply.version.len=HTTP_VERSION_LEN+1 /*include last digit*/; tmp=buffer+HTTP_VERSION_LEN+1 /* last digit */; /* 'HTTP/2' */ - } else if (strncasecmp( tmp+1, HTTP2_VERSION+1, HTTP2_VERSION_LEN-1)==0 && + } else if (strncasecmp( tmp+1, &HTTP2_VERSION[1], HTTP2_VERSION_LEN-1)==0 && (*(tmp+HTTP2_VERSION_LEN)==' ')) { fl->type=SIP_REPLY; fl->flags|=FLINE_FLAG_PROTO_HTTP; @@ -238,13 +238,13 @@ char* parse_first_line(char* buffer, unsigned int len, struct msg_start* fl) && (fl->u.request.version.s[0]=='S' || fl->u.request.version.s[0]=='s') && !strncasecmp(fl->u.request.version.s+1, - SIP_VERSION+1, SIP_VERSION_LEN-1)) { + &SIP_VERSION[1], SIP_VERSION_LEN-1)) { fl->flags|=FLINE_FLAG_PROTO_SIP; } else if(fl->u.request.version.len >= HTTP_VERSION_LEN && (fl->u.request.version.s[0]=='H' || fl->u.request.version.s[0]=='h') && !strncasecmp(fl->u.request.version.s+1, - HTTP_VERSION+1, HTTP_VERSION_LEN-1)) { + &HTTP_VERSION[1], HTTP_VERSION_LEN-1)) { fl->flags|=FLINE_FLAG_PROTO_HTTP; } } diff --git a/src/core/route_struct.c b/src/core/route_struct.c index 063e1773a..51f48a0a6 100644 --- a/src/core/route_struct.c +++ b/src/core/route_struct.c @@ -125,8 +125,7 @@ struct action* mk_action(enum action_type type, int count, ...) for (i=0; icount; i++) { a->val[i].type = va_arg(args, int); a->val[i].u.data = va_arg(args, void *); - - DBG("ACTION_#%d #%d/%d: %d(%x)/ %p\n", a->type, i, a->count, a->val[i].type, a->val[i].type, a->val[i].u.data); + DBG("ACTION type%d, i/count %d/%d: type %d(%x)/ data %p\n", a->type, i, a->count, a->val[i].type, a->val[i].type, a->val[i].u.data); } va_end(args); diff --git a/src/core/tcp_main.c b/src/core/tcp_main.c index 1c9859f63..f23df907a 100644 --- a/src/core/tcp_main.c +++ b/src/core/tcp_main.c @@ -3668,7 +3668,7 @@ inline static int handle_tcp_child(struct tcp_child* tcp_c, int fd_i) _wbufq_non_empty(tcpconn) )){ if (unlikely(TICKS_GE(t, tcpconn->wbuf_q.wr_timeout))){ LM_DBG("wr. timeout on CONN_RELEASE for %p refcnt= %d\n", - tcpconn, atomic_get(&tcpconn->refcnt)); + (void*)tcpconn, atomic_get(&tcpconn->refcnt)); /* timeout */ if (unlikely(tcpconn->state==S_CONN_CONNECT)){ #ifdef USE_DST_BLACKLIST diff --git a/src/core/tcp_read.c b/src/core/tcp_read.c index afb124868..bc31df981 100644 --- a/src/core/tcp_read.c +++ b/src/core/tcp_read.c @@ -1732,7 +1732,7 @@ static ticks_t tcpconn_read_timeout(ticks_t t, struct timer_ln* tl, void* data) * idx - index in the fd_array (or -1 if not known) * return: -1 on error, or when we are not interested any more on reads * from this fd (e.g.: we are closing it ) - * 0 on EAGAIN or when by some other way it is known that no more + * 0 on EAGAIN or when by some other way it is known that no more * io events are queued on the fd (the receive buffer is empty). * Usefull to detect when there are no more io events queued for * sigio_rt, epoll_et, kqueue. @@ -1740,7 +1740,7 @@ static ticks_t tcpconn_read_timeout(ticks_t t, struct timer_ln* tl, void* data) * queued -- the receive buffer might still be non-empty) */ inline static int handle_io(struct fd_map* fm, short events, int idx) -{ +{ int ret; int n; int read_flags; @@ -1748,10 +1748,11 @@ inline static int handle_io(struct fd_map* fm, short events, int idx) int s; long resp; ticks_t t; - + fd_map_t *ee = NULL; + /* update the local config */ cfg_update(); - + switch(fm->type){ case F_TCPMAIN: again: @@ -1815,7 +1816,7 @@ repeat_1st_read: if (unlikely(read_flags & RD_CONN_REPEAT_READ)) goto repeat_1st_read; #endif /* USE_TLS */ - + /* must be before io_watch_add, io_watch_add might catch some * already existing events => might call handle_io and * handle_io might decide to del. the new connection => @@ -1828,13 +1829,25 @@ repeat_1st_read: local_timer_reinit(&con->timer); local_timer_add(&tcp_reader_ltimer, &con->timer, S_TO_TICKS(TCP_CHILD_TIMEOUT), t); - if (unlikely(io_watch_add(&io_w, s, POLLIN, F_TCPCONN, con)<0)){ + if (unlikely(io_watch_add(&io_w, s, POLLIN, F_TCPCONN, con)<0)) { LM_CRIT("io_watch_add failed for %p id %d fd %d, state %d, flags %x," " main fd %d, refcnt %d ([%s]:%u -> [%s]:%u)\n", con, con->id, con->fd, con->state, con->flags, con->s, atomic_get(&con->refcnt), ip_addr2a(&con->rcv.src_ip), con->rcv.src_port, ip_addr2a(&con->rcv.dst_ip), con->rcv.dst_port); + ee = get_fd_map(&io_w, s); + if(ee!=0 && ee->type==F_TCPCONN) { + tcp_connection_t *ec; + ec = (tcp_connection_t*)ee->data; + LM_CRIT("existing tcp con %p id %d fd %d, state %d, flags %x," + " main fd %d, refcnt %d ([%s]:%u -> [%s]:%u)\n", + ec, ec->id, ec->fd, ec->state, ec->flags, + ec->s, atomic_get(&ec->refcnt), + ip_addr2a(&ec->rcv.src_ip), ec->rcv.src_port, + ip_addr2a(&ec->rcv.dst_ip), ec->rcv.dst_port); + + } tcpconn_listrm(tcp_conn_lst, con, c_next, c_prev); local_timer_del(&tcp_reader_ltimer, &con->timer); goto con_error; diff --git a/src/core/udp_server.c b/src/core/udp_server.c index 2b874ab2e..b718895bd 100644 --- a/src/core/udp_server.c +++ b/src/core/udp_server.c @@ -428,9 +428,9 @@ int udp_rcv_loop() static char buf [BUF_SIZE+1]; #endif char *tmp; - union sockaddr_union* from; - unsigned int fromlen; - struct receive_info ri; + union sockaddr_union* fromaddr; + unsigned int fromaddrlen; + receive_info_t rcvi; sr_event_param_t evp = {0}; #define UDP_RCV_PRINTBUF_SIZE 512 #define UDP_RCV_PRINT_LEN 100 @@ -440,17 +440,18 @@ int udp_rcv_loop() int l; - from=(union sockaddr_union*) pkg_malloc(sizeof(union sockaddr_union)); - if (from==0){ + fromaddr=(union sockaddr_union*) pkg_malloc(sizeof(union sockaddr_union)); + if (fromaddr==0){ PKG_MEM_ERROR; goto error; } - memset(from, 0 , sizeof(union sockaddr_union)); - ri.bind_address=bind_address; /* this will not change, we do it only once*/ - ri.dst_port=bind_address->port_no; - ri.dst_ip=bind_address->address; - ri.proto=PROTO_UDP; - ri.proto_reserved1=ri.proto_reserved2=0; + memset(fromaddr, 0,sizeof(union sockaddr_union)); + memset(&rcvi, 0, sizeof(receive_info_t)); + /* these do not change, set only once*/ + rcvi.bind_address=bind_address; + rcvi.dst_port=bind_address->port_no; + rcvi.dst_ip=bind_address->address; + rcvi.proto=PROTO_UDP; /* initialize the config framework */ if (cfg_child_init()) goto error; @@ -463,9 +464,9 @@ int udp_rcv_loop() goto error; } #endif - fromlen=sockaddru_len(bind_address->su); - len=recvfrom(bind_address->socket, buf, BUF_SIZE, 0, &from->s, - &fromlen); + fromaddrlen=sizeof(union sockaddr_union); + len=recvfrom(bind_address->socket, buf, BUF_SIZE, 0, + (struct sockaddr*)fromaddr, &fromaddrlen); if (len==-1){ if (errno==EAGAIN){ LM_DBG("packet with bad checksum received\n"); @@ -476,6 +477,11 @@ int udp_rcv_loop() continue; /* goto skip;*/ else goto error; } + if(fromaddrlen != (unsigned int)sockaddru_len(bind_address->su)) { + LM_ERR("ignoring data - unexpected from addr len: %u != %u\n", + fromaddrlen, (unsigned int)sockaddru_len(bind_address->su)); + continue; + } /* we must 0-term the messages, receive_msg expects it */ buf[len]=0; /* no need to save the previous char */ @@ -498,16 +504,16 @@ int udp_rcv_loop() LM_DBG("received on udp socket: (%d/%d/%d) [[%.*s]]\n", j, i, len, j, printbuf); } - ri.src_su=*from; - su2ip_addr(&ri.src_ip, from); - ri.src_port=su_getport(from); + rcvi.src_su=*fromaddr; + su2ip_addr(&rcvi.src_ip, fromaddr); + rcvi.src_port=su_getport(fromaddr); if(unlikely(sr_event_enabled(SREV_NET_DGRAM_IN))) { void *sredp[3]; sredp[0] = (void*)buf; sredp[1] = (void*)(&len); - sredp[2] = (void*)(&ri); + sredp[2] = (void*)(&rcvi); evp.data = (void*)sredp; if(sr_event_exec(SREV_NET_DGRAM_IN, &evp)<0) { /* data handled by callback - continue to next packet */ @@ -517,8 +523,8 @@ int udp_rcv_loop() #ifndef NO_ZERO_CHECKS if (!unlikely(sr_event_enabled(SREV_STUN_IN)) || (unsigned char)*buf != 0x00) { if (len - - %entities; -]> - - - - - CUSTOM Extensions - - - - - - - diff --git a/src/lib/srdb1/schema/matrix.xml b/src/lib/srdb1/schema/matrix.xml index 748fd5cd8..9eb58f01f 100644 --- a/src/lib/srdb1/schema/matrix.xml +++ b/src/lib/srdb1/schema/matrix.xml @@ -21,6 +21,16 @@ + + id + unsigned int + &table_id_len; + + + int,auto + unique ID + + first int diff --git a/src/lib/srdb1/schema/secfilter.xml b/src/lib/srdb1/schema/secfilter.xml index 4edab34e6..0b3cbc887 100644 --- a/src/lib/srdb1/schema/secfilter.xml +++ b/src/lib/srdb1/schema/secfilter.xml @@ -37,14 +37,14 @@ action short - + 0 Action to do (0=blacklisted data, 1=whitelisted data, 2=blacklisted destination). type short - + 0 Type of data (0=user-agent, 1=country, 2=domain, 3=IP address, 4=user). diff --git a/src/lib/srdb1/schema/version.xml b/src/lib/srdb1/schema/version.xml index c18ea3b0c..14b3dd4be 100644 --- a/src/lib/srdb1/schema/version.xml +++ b/src/lib/srdb1/schema/version.xml @@ -6,7 +6,7 @@ ]> - +
> version1&MYSQL_TABLE_TYPE; diff --git a/src/modules/acc_diameter/diam_message.h b/src/modules/acc_diameter/diam_message.h index 9051f0f7a..7ca1caf27 100644 --- a/src/modules/acc_diameter/diam_message.h +++ b/src/modules/acc_diameter/diam_message.h @@ -26,8 +26,8 @@ * - Module: \ref acc */ -#ifndef _AAA_DIAMETER_MSG_H -#define _AAA_DIAMETER_MSG_H +#ifndef _ACC_DIAM_MESSAGE_H_ +#define _ACC_DIAM_MESSAGE_H_ #include "../../core/str.h" #include "../../core/mem/mem.h" diff --git a/src/modules/app_lua_sr/README b/src/modules/app_lua_sr/README index 77b82248d..8446e0d2f 100644 --- a/src/modules/app_lua_sr/README +++ b/src/modules/app_lua_sr/README @@ -10,7 +10,7 @@ Daniel-Constantin Mierla - Copyright 2010-2019 Daniel-Constantin Mierla (asipto.com) + Copyright © 2010-2019 Daniel-Constantin Mierla (asipto.com) __________________________________________________________________ Table of Contents @@ -138,7 +138,7 @@ Chapter 1. Admin Guide Note that 'sr', 'sr.hdr' and 'sr.pv' modules are always registered to Lua. - Default value is "null". + Default value is “null”. Example 1.2. Set register parameter ... diff --git a/src/modules/app_mono/README b/src/modules/app_mono/README index 52100a42a..45fa2028b 100644 --- a/src/modules/app_mono/README +++ b/src/modules/app_mono/README @@ -10,8 +10,6 @@ Daniel-Constantin Mierla -Edited by - Alex Balashov diff --git a/src/modules/app_perl/README b/src/modules/app_perl/README index b554b3b85..c6f42f585 100644 --- a/src/modules/app_perl/README +++ b/src/modules/app_perl/README @@ -1650,45 +1650,45 @@ Chapter 4. Frequently Asked Questions 4.1. - Are there known bugs in the Perl module? - - The Perl module does have a few shortcomings that may be regarded as - bugs. - * Missing module functions. Not all functions of other modules are - available for Perl access. The reason for this is a design property - of Kamailio. Making available more functions is work in progress. - * Perl and threads. Perl itself is, when compiled with the correct - parameters, thread safe; unfortunately, not all Perl modules are. - The DBI modules, especially (but not restricted to) DBI::ODBC are - known NOT to be thread safe. - Using DBI::ODBC -- and possibly other non-thread-safe Perl - extensions -- may result in erroneous behavior of Kamailio, - including (but not restricted to) server crashes and wrong routing. + Are there known bugs in the Perl module? + + The Perl module does have a few shortcomings that may be regarded as + bugs. + * Missing module functions. Not all functions of other modules are + available for Perl access. The reason for this is a design property + of Kamailio. Making available more functions is work in progress. + * Perl and threads. Perl itself is, when compiled with the correct + parameters, thread safe; unfortunately, not all Perl modules are. + The DBI modules, especially (but not restricted to) DBI::ODBC are + known NOT to be thread safe. + Using DBI::ODBC -- and possibly other non-thread-safe Perl + extensions -- may result in erroneous behavior of Kamailio, + including (but not restricted to) server crashes and wrong routing. 4.2. - Where can I find more about Kamailio? + Where can I find more about Kamailio? - Take a look at https://www.kamailio.org/. + Take a look at https://www.kamailio.org/. 4.3. - Where can I post a question about this module? + Where can I post a question about this module? - First at all check if your question was already answered on one of our - mailing lists: - * User Mailing List - - https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users - * Developer Mailing List - - https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-dev + First at all check if your question was already answered on one of our + mailing lists: + * User Mailing List - + https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users + * Developer Mailing List - + https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-dev - E-mails regarding any stable Kamailio release should be sent to - and e-mails regarding development - versions should be sent to . + E-mails regarding any stable Kamailio release should be sent to + and e-mails regarding development + versions should be sent to . 4.4. - How can I report a bug? + How can I report a bug? - Please follow the guidelines provided at: - https://github.com/kamailio/kamailio/issues. + Please follow the guidelines provided at: + https://github.com/kamailio/kamailio/issues. diff --git a/src/modules/app_python/apy_kemi.c b/src/modules/app_python/apy_kemi.c index 96fa2cf02..1661346d9 100644 --- a/src/modules/app_python/apy_kemi.c +++ b/src/modules/app_python/apy_kemi.c @@ -1806,9 +1806,9 @@ PyObject *sr_apy_kemi_exec_func(PyObject *self, PyObject *args, int idx) " took too long [%u us] (file:%s func:%s line:%d)\n", (ket->mname.len>0)?ket->mname.s:"", (ket->mname.len>0)?".":"", ket->fname.s, tdiff, - (pframe)?PyString_AsString(pframe->f_code->co_filename):"", - (pframe)?PyString_AsString(pframe->f_code->co_name):"", - (pframe)?PyCode_Addr2Line(pframe->f_code, pframe->f_lasti):0); + (pframe && pframe->f_code)?PyString_AsString(pframe->f_code->co_filename):"", + (pframe && pframe->f_code)?PyString_AsString(pframe->f_code->co_name):"", + (pframe && pframe->f_code)?PyCode_Addr2Line(pframe->f_code, pframe->f_lasti):0); } } diff --git a/src/modules/app_python3/apy_kemi.c b/src/modules/app_python3/apy_kemi.c index 7769046d2..4733ec1e1 100644 --- a/src/modules/app_python3/apy_kemi.c +++ b/src/modules/app_python3/apy_kemi.c @@ -1814,9 +1814,9 @@ PyObject *sr_apy_kemi_exec_func(PyObject *self, PyObject *args, int idx) " took too long [%u ms] (file:%s func:%s line:%d)\n", (ket->mname.len>0)?ket->mname.s:"", (ket->mname.len>0)?".":"", ket->fname.s, tdiff, - (pframe)?PyBytes_AS_STRING(pframe->f_code->co_filename):"", - (pframe)?PyBytes_AS_STRING(pframe->f_code->co_name):"", - (pframe)?PyCode_Addr2Line(pframe->f_code, pframe->f_lasti):0); + (pframe && pframe->f_code)?PyBytes_AsString(pframe->f_code->co_filename):"", + (pframe && pframe->f_code)?PyBytes_AsString(pframe->f_code->co_name):"", + (pframe && pframe->f_code)?PyCode_Addr2Line(pframe->f_code, pframe->f_lasti):0); } } diff --git a/src/modules/auth_diameter/diameter_msg.h b/src/modules/auth_diameter/diameter_msg.h index 7ab5a8c38..e8e7eea87 100644 --- a/src/modules/auth_diameter/diameter_msg.h +++ b/src/modules/auth_diameter/diameter_msg.h @@ -13,15 +13,15 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#ifndef _AAA_DIAMETER_MSG_H -#define _AAA_DIAMETER_MSG_H +#ifndef _AUTH_DIAM_MESSAGE_H_ +#define _AUTH_DIAM_MESSAGE_H_ #include "../../core/str.h" #include "../../core/mem/mem.h" diff --git a/src/modules/auth_radius/README b/src/modules/auth_radius/README index ff0a1ad86..4640043e9 100644 --- a/src/modules/auth_radius/README +++ b/src/modules/auth_radius/README @@ -22,8 +22,6 @@ Jan Janak -Edited by - Phil Lavin diff --git a/src/modules/avpops/avpops.c b/src/modules/avpops/avpops.c index 0805407cf..6e49933e8 100644 --- a/src/modules/avpops/avpops.c +++ b/src/modules/avpops/avpops.c @@ -30,6 +30,7 @@ #include "../../core/mem/mem.h" #include "../../core/parser/parse_hname2.h" #include "../../core/sr_module.h" +#include "../../core/kemi.h" #include "../../core/str.h" #include "../../core/dprint.h" #include "../../core/error.h" @@ -1064,3 +1065,164 @@ static int w_print_avps(struct sip_msg* msg, char* foo, char *bar) return ops_print_avp(); } +static int ki_check_avps(struct sip_msg* msg, str* param, str *check) +{ + struct fis_param *fparam, *fcheck; + regex_t* re = NULL; + int res; + + if((fparam = avpops_parse_pvar(param->s)) == NULL) + { + LM_ERR("unable to get pseudo-variable in param 1\n"); + return E_OUT_OF_MEM; + } + /* attr name is mandatory */ + if (fparam->u.sval->type==PVT_NULL) + { + LM_ERR("null pseudo-variable in param 1\n"); + pkg_free(fparam); + return E_UNSPEC; + } + + if((fcheck = avpops_parse_pvar(check->s)) == NULL) + { + LM_ERR("failed to parse checked value \n"); + pkg_free(fparam); + return E_UNSPEC; + } + /* if REGEXP op -> compile the expresion */ + if(fcheck->ops&AVPOPS_OP_RE) + { + if( (fcheck->opd&AVPOPS_VAL_STR) != 0 ) + { + if((re = (regex_t*) pkg_malloc(sizeof(regex_t))) == NULL) + { + PKG_MEM_ERROR; + pkg_free(fparam); + pkg_free(fcheck); + return E_OUT_OF_MEM; + } + LM_DBG("compiling regexp <%.*s>\n", fcheck->u.s.len, fcheck->u.s.s); + if (regcomp(re, fcheck->u.s.s,REG_EXTENDED|REG_ICASE|REG_NEWLINE)) + { + LM_ERR("bad re <%.*s>\n", fcheck->u.s.len, fcheck->u.s.s); + pkg_free(fparam); + pkg_free(re); + pkg_free(fcheck); + return E_BAD_RE; + } + fcheck->u.s.s = (char*)re; + } + } else if (fcheck->ops&AVPOPS_OP_FM) { + if (!( fcheck->opd&AVPOPS_VAL_PVAR || + (!(fcheck->opd&AVPOPS_VAL_PVAR) && fcheck->opd&AVPOPS_VAL_STR) ) ) + { + LM_ERR("fast_match operation requires string value or " + "avp name/alias (%d/%d)\n", fcheck->opd, fcheck->ops); + pkg_free(fparam); + pkg_free(fcheck); + return E_UNSPEC; + } + } + + res = ops_check_avp(msg, fparam, fcheck); + pkg_free(fparam); + pkg_free(fcheck); + if(re) pkg_free(re); + return res; +} + +static int ki_copy_avps(struct sip_msg* msg, str *name1, str *name2) +{ + struct fis_param *fname1, *fname2; + char *p = NULL; + int res; + + if((fname1 = avpops_parse_pvar(name1->s)) == NULL) + { + LM_ERR("unable to get pseudo-variable in param 1\n"); + return E_OUT_OF_MEM; + } + /* attr name is mandatory */ + if (fname1->u.sval->type != PVT_AVP) + { + LM_ERR("you must specify only AVP as parameter\n"); + pkg_free(fname1); + return E_UNSPEC; + } + + /* avp / flags */ + if ( (p=strchr(name2->s,'/')) != 0 ) + *(p++) = 0; + + if((fname2 = avpops_parse_pvar(name2->s)) == NULL) + { + LM_ERR("unable to get pseudo-variable in param 2\n"); + return E_OUT_OF_MEM; + } + /* attr name is mandatory */ + if (fname2->u.sval->type != PVT_AVP) + { + LM_ERR("you must specify only AVP as parameter\n"); + pkg_free(fname1); + pkg_free(fname2); + return E_UNSPEC; + } + + /* flags */ + for( ; p&&*p ; p++ ) + { + switch (*p) { + case 'g': + case 'G': + fname2->ops|=AVPOPS_FLAG_ALL; + break; + case 'd': + case 'D': + fname2->ops|=AVPOPS_FLAG_DELETE; + break; + case 'n': + case 'N': + fname2->ops|=AVPOPS_FLAG_CASTN; + break; + case 's': + case 'S': + fname2->ops|=AVPOPS_FLAG_CASTS; + break; + default: + LM_ERR("bad flag <%c>\n",*p); + pkg_free(fname1); + pkg_free(fname2); + return E_UNSPEC; + } + } + + res = ops_copy_avp( msg, fname1, fname2); + pkg_free(fname1); + pkg_free(fname2); + return res; +} + +/** + * + */ +/* clang-format off */ +static sr_kemi_t sr_kemi_rtpengine_exports[] = { + { str_init("avpops"), str_init("avp_check"), + SR_KEMIP_INT, ki_check_avps, + { SR_KEMIP_STR, SR_KEMIP_STR, SR_KEMIP_NONE, + SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE } + }, + { str_init("avpops"), str_init("avp_copy"), + SR_KEMIP_INT, ki_copy_avps, + { SR_KEMIP_STR, SR_KEMIP_STR, SR_KEMIP_NONE, + SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE } + }, + { {0, 0}, {0, 0}, 0, NULL, { 0, 0, 0, 0, 0, 0 } } +}; +/* clang-format on */ + +int mod_register(char *path, int *dlflags, void *p1, void *p2) { + sr_kemi_modules_add(sr_kemi_rtpengine_exports); + return 0; +} \ No newline at end of file diff --git a/src/modules/cdp/Makefile b/src/modules/cdp/Makefile index c1811297e..e2d0211f6 100644 --- a/src/modules/cdp/Makefile +++ b/src/modules/cdp/Makefile @@ -6,6 +6,12 @@ NAME=cdp.so ifeq ($(CROSS_COMPILE),) XML2CFG=$(shell which xml2-config) +ifeq ($(XML2CFG),) +XML2CFG=$(shell \ + if pkg-config --exists libxml-2.0; then \ + echo 'pkg-config libxml-2.0'; \ + fi) +endif endif ifneq ($(XML2CFG),) diff --git a/src/modules/cdp/acctstatemachine.c b/src/modules/cdp/acctstatemachine.c index 4e9272980..a0c5f26ad 100644 --- a/src/modules/cdp/acctstatemachine.c +++ b/src/modules/cdp/acctstatemachine.c @@ -40,7 +40,7 @@ void update_gsu_response_timers(cdp_cc_acc_session_t* session, AAAMessage* msg) AAA_AVP *mscc_avp = mscc_avp_list.head; while (mscc_avp != NULL ) { - LM_DBG("MSCC AVP code is [%i] and data length is [%i]", mscc_avp->code, mscc_avp->data.len); + LM_DBG("MSCC AVP code is [%i] and data length is [%i]\n", mscc_avp->code, mscc_avp->data.len); switch (mscc_avp->code) { case AVP_Granted_Service_Unit: y = AAAUngroupAVPS(mscc_avp->data); diff --git a/src/modules/cdp/peerstatemachine.c b/src/modules/cdp/peerstatemachine.c index 5d26605c7..b83654bf1 100644 --- a/src/modules/cdp/peerstatemachine.c +++ b/src/modules/cdp/peerstatemachine.c @@ -678,7 +678,8 @@ void add_peer_application(peer *p, int id, int vendor, app_type type) p->applications[p->applications_cnt].id = id; p->applications[p->applications_cnt].vendor = vendor; p->applications[p->applications_cnt].type = type; - LM_DBG("Application %i of maximum %i\n", p->applications_cnt, p->applications_max); + LM_DBG("Application number %i with id %d and vendor %d added, maximum %i\n", + p->applications_cnt, id, vendor, p->applications_max); p->applications_cnt++; } @@ -695,7 +696,7 @@ int count_Supported_Vendor_Id_AVPS(AAAMessage *msg) break; avp_vendor = AAAFindMatchingAVP(msg,avp_vendor->next,AVP_Supported_Vendor_Id,0,0); } - LM_DBG("Found %i Supported_Vendor AVPS", avp_vendor_cnt); + LM_DBG("Found %i Supported_Vendor AVPS\n", avp_vendor_cnt); return avp_vendor_cnt; } @@ -715,6 +716,12 @@ void save_peer_applications(peer *p,AAAMessage *msg) supported_vendor_id_avp_cnt = count_Supported_Vendor_Id_AVPS(msg); + if (supported_vendor_id_avp_cnt == 0) { + LM_INFO("No Supported-Vendor-Id AVP found, assuming compability with %d vendor(s) from our CER msg\n", + config->supported_vendors_cnt); + supported_vendor_id_avp_cnt = 1; + } + for(avp=msg->avpList.head;avp;avp = avp->next) switch (avp->code){ @@ -728,6 +735,8 @@ void save_peer_applications(peer *p,AAAMessage *msg) total_cnt+=2;/* wasteful, but let's skip decoding */ break; } + LM_DBG("Total count of applications is %d\n", total_cnt); + p->applications_cnt = 0; p->applications = shm_malloc(sizeof(app_config)*total_cnt); p->applications_max = total_cnt; @@ -745,7 +754,6 @@ void save_peer_applications(peer *p,AAAMessage *msg) add_peer_application(p,id,0,DP_AUTHORIZATION); avp_vendor = AAAFindMatchingAVP(msg,0,AVP_Supported_Vendor_Id,0,0); while (avp_vendor) { - vendor = get_4bytes(avp_vendor->data.s); LM_DBG("Found Supported Vendor for Application %i: %i\n", DP_AUTHORIZATION, vendor); add_peer_application(p,id,vendor,DP_AUTHORIZATION); diff --git a/src/modules/cdp/receiver.c b/src/modules/cdp/receiver.c index c33554457..5aed0a36f 100644 --- a/src/modules/cdp/receiver.c +++ b/src/modules/cdp/receiver.c @@ -396,7 +396,7 @@ again: *fd = *tmp; }else{ if(!cmsg) - LM_ERR("receive_fd: no descriptor passed, empty control message"); + LM_ERR("receive_fd: no descriptor passed, empty control message\n"); else LM_ERR("receive_fd: no descriptor passed, cmsg=%p," "len=%d\n", cmsg, (unsigned)cmsg->cmsg_len); @@ -768,7 +768,7 @@ int receive_loop(peer *original_peer) } LM_DBG("select_recv(): Send pipe says [%p] %d\n",msg,cnt); if (sp->tcp_socket<0){ - LM_ERR("select_recv(): got a signal to send something, but the connection was not opened"); + LM_ERR("select_recv(): got a signal to send something, but the connection was not opened\n"); } else { while( (cnt=write(sp->tcp_socket,msg->buf.s,msg->buf.len))==-1 ) { if (errno==EINTR) @@ -883,7 +883,7 @@ int peer_connect(peer *p) /* try to set the local socket used to connect to the peer */ if (p->src_addr.s && p->src_addr.len > 0) { - LM_DBG("peer_connect(): connetting to peer via src addr=%.*s",p->src_addr.len, p->src_addr.s); + LM_DBG("peer_connect(): connecting to peer via src addr=%.*s\n",p->src_addr.len, p->src_addr.s); memset (&hints, 0, sizeof(hints)); hints.ai_flags = AI_NUMERICHOST; hints.ai_socktype = SOCK_STREAM; diff --git a/src/modules/cdp/worker.c b/src/modules/cdp/worker.c index 30d7a1b0f..64ba70679 100644 --- a/src/modules/cdp/worker.c +++ b/src/modules/cdp/worker.c @@ -258,11 +258,11 @@ int put_task(peer *p, AAAMessage *msg) { length_percentage = num_tasks/tasks->max*100; if(length_percentage > workerq_length_threshold_percentage) { LM_WARN("Queue length has exceeded length threshold percentage" - " [%i] and is length [%i]", length_percentage, num_tasks); + " [%i] and is length [%i]\n", length_percentage, num_tasks); } } //int num_tasks = tasks->end - tasks->start; - //LM_ERR("Added task to task queue. Queue length [%i]", num_tasks); + //LM_ERR("Added task to task queue. Queue length [%i]\n", num_tasks); return 1; @@ -300,7 +300,7 @@ task_t take_task() { lock_release(tasks->lock); //int num_tasks = tasks->end - tasks->start; - //LM_ERR("Taken task from task queue. Queue length [%i]", num_tasks); + //LM_ERR("Taken task from task queue. Queue length [%i]\n", num_tasks); return t; diff --git a/src/modules/cdp_avp/README b/src/modules/cdp_avp/README index 4cff2f2ed..6466a28ae 100644 --- a/src/modules/cdp_avp/README +++ b/src/modules/cdp_avp/README @@ -8,8 +8,6 @@ Edited by Jason Penton -Edited by - Richard Good Copyright © 2006 FhG Fokus @@ -1658,28 +1656,28 @@ Chapter 3. Frequently Asked Questions 3.1. - Where can I find more about Kamailio? + Where can I find more about Kamailio? - Take a look at https://www.kamailio.org/. + Take a look at https://www.kamailio.org/. 3.2. - Where can I post a question about this module? + Where can I post a question about this module? - First at all check if your question was already answered on one of our - mailing lists: - * User Mailing List - - https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users - * Developer Mailing List - - https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-dev + First at all check if your question was already answered on one of our + mailing lists: + * User Mailing List - + https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users + * Developer Mailing List - + https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-dev - E-mails regarding any stable Kamailio release should be sent to - and e-mails regarding development - versions should be sent to . + E-mails regarding any stable Kamailio release should be sent to + and e-mails regarding development + versions should be sent to . 3.3. - How can I report a bug? + How can I report a bug? - Please follow the guidelines provided at: - https://github.com/kamailio/kamailio/issues. + Please follow the guidelines provided at: + https://github.com/kamailio/kamailio/issues. diff --git a/src/modules/cnxcc/README b/src/modules/cnxcc/README index d2e317de7..425a473f1 100644 --- a/src/modules/cnxcc/README +++ b/src/modules/cnxcc/README @@ -188,18 +188,32 @@ modparam("cnxcc", "credit_check_period", 1) Associates the call with a customer id and sets the max credit, connect cost, cost per second, initial pulse and final pulse. The discount is - calculated in pulses (30/6, 1/1, etc) and subtracted from the pool of + calculated in pulses (1/1, 60/1, etc) and subtracted from the pool of credit. The customer value can be provided as a string or a variable holding a - string. + string. This value identifies all calls from the same customer. + + The maxcredit (float) value is the maximum credit available for the + current call. + + The connect (float) value is the connect cost for the current call. + + The cps (float) value is the cost per second for the current call. + + The ipuse (integer) value is the initial pulse and establishes the + minimum time to be charged. For example, value 1 establishes a charge + per second and value 60 sets a charge per minute. If it is taken as + value 60, even if the duration is 5 seconds, 1 minute will be charged. - The maxcredit, connect and cps can be double (float) or integer values, - they have to be provided as static string values of variables holding - string values. + The fpulse (integer) value is the final pulse and establishes, from the + initial pulse, the time range to be charged. For example, the value 1 + establishes a charge per second, 5 sets a charge in blocks of 5 + seconds, 60 sets a full minute charge. - The ipulse and fpulse values are integer values, they can be also given - via variables holding integers. + 1/1 will make a charge per seconds for the entire call. 60/1 will make + a charge per seconds with the first full minute. 60/60 always perform a + full minute charge. Return code: * 1 - successful @@ -210,12 +224,15 @@ modparam("cnxcc", "credit_check_period", 1) ... cnxcc_set_max_credit("john-doe", "100", "3.0", "0.5", 60, 1); ... -$var(customer) = "john-doe-premium"; # customer id -$var(credit) = "100"; # max credit -$var(connect) = "3.0"; # connect const -$var(cps) = "0.5"; # cost per second -$var(initial_p) = 60; # initial pulse -$var(final_p) = 1; # final pulse +$var(customer) = "john-doe"; # customer id +$var(credit) = "100"; # max credit for all calls with the same + # customer id +$var(connect) = "3.0"; # connect cost or initial cost for the call +$var(cps) = "0.5"; # cost per second +$var(initial_p) = 60; # initial pulse (60 = the first minute will be + # charged even if the call is shorter) +$var(final_p) = 1; # final pulse (after the first minute, it will + # be charge in ranges of 1 second) cnxcc_set_max_credit("$var(customer)", "$var(credit)", "$var(connect)", "$var(cps)", "$var(initial_p)", "$var(final_p)"); ... diff --git a/src/modules/cnxcc/cnxcc.c b/src/modules/cnxcc/cnxcc.c index 3f0da8aff..eef1deea8 100644 --- a/src/modules/cnxcc/cnxcc.c +++ b/src/modules/cnxcc/cnxcc.c @@ -19,10 +19,8 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ -#include -#include + #include -#include #include "cnxcc.h" diff --git a/src/modules/cnxcc/cnxcc.h b/src/modules/cnxcc/cnxcc.h index 31fb84ee8..8c73dde2c 100644 --- a/src/modules/cnxcc/cnxcc.h +++ b/src/modules/cnxcc/cnxcc.h @@ -23,6 +23,8 @@ #ifndef _CNXCC_H #define _CNXCC_H +#include + #include "../../core/str.h" #define DATETIME_SIZE sizeof("0001-01-01 00:00:00") @@ -37,12 +39,12 @@ static inline unsigned int get_current_timestamp() static inline int timestamp2isodt(str *dest, unsigned int timestamp) { time_t tim; - struct tm *tmPtr; + struct tm tmPtr; tim = timestamp; - tmPtr = localtime(&tim); + localtime_r(&tim, &tmPtr); - strftime(dest->s, DATETIME_SIZE, "%Y-%m-%d %H:%M:%S", tmPtr); + strftime(dest->s, DATETIME_SIZE, "%Y-%m-%d %H:%M:%S", &tmPtr); dest->len = DATETIME_LENGTH; return 0; diff --git a/src/modules/cnxcc/cnxcc_mod.c b/src/modules/cnxcc/cnxcc_mod.c index 55d9bf00a..2a6b0f8cf 100644 --- a/src/modules/cnxcc/cnxcc_mod.c +++ b/src/modules/cnxcc/cnxcc_mod.c @@ -27,32 +27,28 @@ #include #include #include -#include #include #include "../../core/sr_module.h" +#include "../../core/mod_fix.h" #include "../../core/dprint.h" #include "../../core/error.h" #include "../../core/mem/mem.h" -#include "../../core/shm_init.h" #include "../../core/mem/shm_mem.h" -#include "../../core/pvar.h" -#include "../../core/locking.h" + #include "../../core/lock_ops.h" -#include "../../core/str_hash.h" #include "../../core/timer_proc.h" -#include "../../modules/tm/tm_load.h" #include "../../core/parser/parse_from.h" #include "../../core/parser/parse_to.h" #include "../../core/parser/parse_uri.h" #include "../../core/parser/parse_cseq.h" #include "../../core/parser/contact/parse_contact.h" #include "../../core/parser/contact/contact.h" -#include "../../core/parser/parse_rr.h" -#include "../../core/mod_fix.h" + +#include "../tm/tm_load.h" #include "../dialog/dlg_load.h" #include "../dialog/dlg_hash.h" -#include "../../core/fmsg.h" + #include "../../core/rpc.h" #include "../../core/rpc_lookup.h" #include "../../core/kemi.h" @@ -91,6 +87,8 @@ static int __init_hashtable(struct str_hash_table *ht); */ static int __shm_str_hash_alloc(struct str_hash_table *ht, int size); static void __free_credit_data_hash_entry(struct str_hash_entry *e); +static void __free_credit_data(credit_data_t *credit_data, hash_tables_t *hts, + struct str_hash_entry *cd_entry); /* * PV management functions @@ -123,6 +121,7 @@ static call_t *__alloc_new_call_by_money(credit_data_t *credit_data, double cost_per_second, int initial_pulse, int final_pulse); static void __notify_call_termination(sip_msg_t *msg); static void __free_call(call_t *call); +static void __delete_call(call_t *call, credit_data_t *credit_data); static int __has_to_tag(struct sip_msg *msg); static credit_data_t *__alloc_new_credit_data( str *client_id, credit_type_t type); @@ -170,7 +169,7 @@ static cmd_export_t cmds[] = { static param_export_t params[] = { {"dlg_flag", INT_PARAM, &_data.ctrl_flag }, {"credit_check_period", INT_PARAM, &_data.check_period }, - {"redis", STR_PARAM, &_data.redis_cnn_str.s }, + {"redis", PARAM_STR, &_data.redis_cnn_str }, { 0, 0, 0 } }; /* clang-format on */ @@ -262,9 +261,6 @@ static int __mod_init(void) return -1; } - if(_data.redis_cnn_str.s) - _data.redis_cnn_str.len = strlen(_data.redis_cnn_str.s); - _data.time.credit_data_by_client = shm_malloc(sizeof(struct str_hash_table)); _data.time.call_data_by_cid = shm_malloc(sizeof(struct str_hash_table)); @@ -284,15 +280,11 @@ static int __mod_init(void) memset(_data.channel.call_data_by_cid, 0, sizeof(struct str_hash_table)); _data.stats = (stats_t *)shm_malloc(sizeof(stats_t)); - if(!_data.stats) { - LM_ERR("Error allocating shared memory stats\n"); + SHM_MEM_ERROR; return -1; } - - _data.stats->active = 0; - _data.stats->dropped = 0; - _data.stats->total = 0; + memset(_data.stats, 0, sizeof(stats_t)); if(__init_hashtable(_data.time.credit_data_by_client) != 0) return -1; @@ -312,9 +304,7 @@ static int __mod_init(void) if(__init_hashtable(_data.channel.call_data_by_cid) != 0) return -1; - cnxcc_lock_init(_data.lock); - cnxcc_lock_init(_data.time.lock); cnxcc_lock_init(_data.money.lock); cnxcc_lock_init(_data.channel.lock); @@ -433,21 +423,22 @@ static int __child_init(int rank) static int __init_hashtable(struct str_hash_table *ht) { - if(__shm_str_hash_alloc(ht, HT_SIZE) != 0) { - LM_ERR("Error allocating shared memory hashtable\n"); + if(ht == NULL) + return -1; + + if(__shm_str_hash_alloc(ht, HT_SIZE) != 0) return -1; - } str_hash_init(ht); return 0; } static void __dialog_created_callback( - struct dlg_cell *cell, int type, struct dlg_cb_params *params) + struct dlg_cell *cell, int type, struct dlg_cb_params *_params) { struct sip_msg *msg = NULL; - msg = params->direction == SIP_REPLY ? params->rpl : params->req; + msg = _params->direction == SIP_REPLY ? _params->rpl : _params->req; if(msg == NULL) { LM_ERR("Error getting direction of SIP msg\n"); @@ -471,7 +462,7 @@ static void __dialog_created_callback( } static void __dialog_confirmed_callback( - struct dlg_cell *cell, int type, struct dlg_cb_params *params) + struct dlg_cell *cell, int type, struct dlg_cb_params *_params) { LM_DBG("Dialog confirmed for CID [%.*s]\n", cell->callid.len, cell->callid.s); @@ -480,7 +471,7 @@ static void __dialog_confirmed_callback( } static void __dialog_terminated_callback( - struct dlg_cell *cell, int type, struct dlg_cb_params *params) + struct dlg_cell *cell, int type, struct dlg_cb_params *_params) { LM_DBG("Dialog terminated for CID [%.*s]\n", cell->callid.len, cell->callid.s); @@ -621,7 +612,6 @@ static void __stop_billing(str *callid) LM_ERR("[%.*s] call pointer is null\n", callid->len, callid->s); return; } - if(hts == NULL) { LM_ERR("[%.*s] result hashtable pointer is null\n", callid->len, callid->s); @@ -629,13 +619,9 @@ static void __stop_billing(str *callid) } cnxcc_lock(hts->lock); - - /* - * Search credit_data by client_id - */ + // Search credit_data by client_id cd_entry = str_hash_get( hts->credit_data_by_client, call->client_id.s, call->client_id.len); - if(cd_entry == NULL) { LM_ERR("Credit data not found for CID [%.*s], client-ID [%.*s]\n", callid->len, callid->s, call->client_id.len, call->client_id.s); @@ -644,117 +630,24 @@ static void __stop_billing(str *callid) } credit_data = (credit_data_t *)cd_entry->u.p; - if(credit_data == NULL) { LM_ERR("[%.*s]: credit_data pointer is null\n", callid->len, callid->s); cnxcc_unlock(hts->lock); return; } - cnxcc_unlock(hts->lock); - /* - * Update calls statistics - */ - cnxcc_lock(_data.lock); - - _data.stats->active--; - _data.stats->total--; - - cnxcc_unlock(_data.lock); - - cnxcc_lock(credit_data->lock); - LM_DBG("Call [%.*s] of client-ID [%.*s], ended\n", callid->len, callid->s, call->client_id.len, call->client_id.s); + cnxcc_lock(credit_data->lock); + __delete_call(call, credit_data); - /* - * This call just ended and we need to remove it from the summ. - */ - if(call->confirmed) { - credit_data->concurrent_calls--; - credit_data->ended_calls_consumed_amount += call->consumed_amount; - - if(_data.redis) { - redis_incr_by_int(credit_data, "concurrent_calls", -1); - redis_incr_by_double(credit_data, "ended_calls_consumed_amount", - call->consumed_amount); - } - } - - credit_data->number_of_calls--; - - if(_data.redis) - redis_incr_by_int(credit_data, "number_of_calls", -1); - - if(credit_data->concurrent_calls < 0) { - LM_ERR("[BUG]: number of concurrent calls dropped to negative value: " - "%d\n", - credit_data->concurrent_calls); - } - - if(credit_data->number_of_calls < 0) { - LM_ERR("[BUG]: number of calls dropped to negative value: %d\n", - credit_data->number_of_calls); - } - - /* - * Remove (and free) the call from the list of calls of the current credit_data - */ - clist_rm(call, next, prev); - - /* return if credit_data is being deallocated. - * the call and the credit data will be freed by terminate_all_calls() - */ - if(credit_data->deallocating) { - return; - } - - __free_call(call); /* * In case there are no active calls for a certain client, we remove the client-id from the hash table. * This way, we can save memory for useful clients. - * */ if(credit_data->number_of_calls == 0) { - LM_DBG("Removing client [%.*s] and its calls from the list\n", - credit_data->call_list->client_id.len, - credit_data->call_list->client_id.s); - - credit_data->deallocating = 1; - cnxcc_lock(hts->lock); - - if(_data.redis) { - redis_clean_up_if_last(credit_data); - shm_free(credit_data->str_id); - } - - /* - * Remove the credit_data_t from the hash table - */ - str_hash_del(cd_entry); - - cnxcc_unlock(hts->lock); - - /* - * Free client_id in list's root - */ - shm_free(credit_data->call_list->client_id.s); - shm_free(credit_data->call_list); - - /* - * Release the lock since we are going to free the entry down below - */ - cnxcc_unlock(credit_data->lock); - - /* - * Free the whole entry - */ - __free_credit_data_hash_entry(cd_entry); - - /* - * return without releasing the acquired lock over credit_data. Why? Because we just freed it. - */ + __free_credit_data(credit_data, hts, cd_entry); return; } @@ -915,7 +808,7 @@ static void __start_billing( * Store from-tag value */ if(shm_str_dup(&call->sip_data.from_tag, &tags[0]) != 0) { - LM_ERR("No more pkg memory\n"); + SHM_MEM_ERROR; goto exit; } @@ -923,13 +816,13 @@ static void __start_billing( * Store to-tag value */ if(shm_str_dup(&call->sip_data.to_tag, &tags[1]) != 0) { - LM_ERR("No more pkg memory\n"); + SHM_MEM_ERROR; goto exit; } if(shm_str_dup(&call->sip_data.from_uri, from_uri) != 0 || shm_str_dup(&call->sip_data.to_uri, to_uri) != 0) { - LM_ERR("No more pkg memory\n"); + SHM_MEM_ERROR; goto exit; } @@ -947,6 +840,78 @@ exit: cnxcc_unlock(call->lock); } +static void __delete_call(call_t *call, credit_data_t *credit_data) +{ + // Update calls statistics + cnxcc_lock(_data.lock); + _data.stats->active--; + _data.stats->total--; + cnxcc_unlock(_data.lock); + + // This call just ended and we need to remove it from the summ. + if(call->confirmed) { + credit_data->concurrent_calls--; + credit_data->ended_calls_consumed_amount += call->consumed_amount; + + if(_data.redis) { + redis_incr_by_int(credit_data, "concurrent_calls", -1); + redis_incr_by_double(credit_data, "ended_calls_consumed_amount", + call->consumed_amount); + } + } + + credit_data->number_of_calls--; + + if(_data.redis) + redis_incr_by_int(credit_data, "number_of_calls", -1); + + if(credit_data->concurrent_calls < 0) { + LM_BUG("number of concurrent calls dropped to negative value: %d\n", + credit_data->concurrent_calls); + } + + if(credit_data->number_of_calls < 0) { + LM_BUG("number of calls dropped to negative value: %d\n", + credit_data->number_of_calls); + } + + // Remove (and free) the call from the list of calls of the current credit_data + clist_rm(call, next, prev); + __free_call(call); +} + +// must be called with lock held on credit_data +static void __free_credit_data(credit_data_t *credit_data, hash_tables_t *hts, + struct str_hash_entry *cd_entry) +{ + if(credit_data->deallocating) { + LM_DBG("deallocating, skip\n"); + return; + } + LM_DBG("Removing client [%.*s] and its calls from the list\n", + credit_data->call_list->client_id.len, + credit_data->call_list->client_id.s); + credit_data->deallocating = 1; + cnxcc_lock(hts->lock); + if(_data.redis) { + redis_clean_up_if_last(credit_data); + shm_free(credit_data->str_id); + } + // Remove the credit_data_t from the hash table + str_hash_del(cd_entry); + cnxcc_unlock(hts->lock); + + // Free client_id in list's root + shm_free(credit_data->call_list->client_id.s); + shm_free(credit_data->call_list); + + // Release the lock since we are going to free the entry down below + cnxcc_unlock(credit_data->lock); + + // Free the whole entry + __free_credit_data_hash_entry(cd_entry); +} + // must be called with lock held on credit_data /* terminate all calls and remove credit_data */ void terminate_all_calls(credit_data_t *credit_data) @@ -954,6 +919,7 @@ void terminate_all_calls(credit_data_t *credit_data) call_t *call = NULL, *tmp = NULL; struct str_hash_entry *cd_entry = NULL; hash_tables_t *hts = NULL; + unsigned int pending = 0; switch(credit_data->type) { case CREDIT_MONEY: @@ -975,57 +941,44 @@ void terminate_all_calls(credit_data_t *credit_data) credit_data->call_list->client_id.len); if(cd_entry == NULL) { - LM_WARN("credit data itme not found\n"); + LM_WARN("credit data item not found\n"); return; } + // tell __stop_billing() not to __free_credit_data credit_data->deallocating = 1; clist_foreach_safe(credit_data->call_list, call, tmp, next) { if(call->sip_data.callid.s != NULL) { - LM_DBG("Killing call with CID [%.*s]\n", call->sip_data.callid.len, - call->sip_data.callid.s); - - /* - * Update number of calls forced to end - */ - _data.stats->dropped++; - terminate_call(call); - __free_call(call); + if(call->confirmed) { + LM_DBG("Killing call with CID [%.*s]\n", + call->sip_data.callid.len, call->sip_data.callid.s); + + // Update number of calls forced to end + _data.stats->dropped++; + terminate_call(call); + // call memory will be cleaned by __stop_billing() when + // __dialog_terminated_callback() is triggered + } else { + LM_DBG("Non confirmed call with CID[%.*s], setting " + "max_amount:%f to 0\n", + call->sip_data.callid.len, call->sip_data.callid.s, + call->max_amount); + call->max_amount = 0; + pending = 1; + } } else { LM_WARN("invalid call structure %p\n", call); } } - cnxcc_lock(hts->lock); - - if(_data.redis) { - redis_clean_up_if_last(credit_data); - shm_free(credit_data->str_id); + credit_data->deallocating = 0; + if(!pending) { + __free_credit_data(credit_data, hts, cd_entry); + } else { + LM_DBG("credit data item left\n"); + cnxcc_unlock(credit_data->lock); } - - /* - * Remove the credit_data_t from the hash table - */ - str_hash_del(cd_entry); - - cnxcc_unlock(hts->lock); - - /* - * Free client_id in list's root - */ - shm_free(credit_data->call_list->client_id.s); - shm_free(credit_data->call_list); - - /* - * Release the lock since we are going to free the entry down below - */ - cnxcc_unlock(credit_data->lock); - - /* - * Free the whole entry - */ - __free_credit_data_hash_entry(cd_entry); } /* @@ -1089,9 +1042,10 @@ static int __shm_str_hash_alloc(struct str_hash_table *ht, int size) { ht->table = shm_malloc(sizeof(struct str_hash_head) * size); - if(!ht->table) + if(!ht->table) { + SHM_MEM_ERROR; return -1; - + } ht->size = size; return 0; } @@ -1110,7 +1064,7 @@ int terminate_call(call_t *call) call->dlg_h_entry); data = &call->sip_data; - if(faked_msg_init_with_dlg_info(&data->callid, &data->from_uri, + if(cnxcc_faked_msg_init_with_dlg_info(&data->callid, &data->from_uri, &data->from_tag, &data->to_uri, &data->to_tag, &dmsg) != 0) { LM_ERR("[%.*s]: error generating faked sip message\n", data->callid.len, @@ -1125,8 +1079,8 @@ int terminate_call(call_t *call) } if(!_dlgbinds.terminate_dlg(cell, NULL)) { - LM_DBG("dlg_end_dlg sent to call [%.*s]\n", call->sip_data.callid.len, - call->sip_data.callid.s); + LM_DBG("dlg_end_dlg sent to call [%.*s]\n", cell->callid.len, + cell->callid.s); if(_data.cs_route_number >= 0) __notify_call_termination(dmsg); @@ -1197,7 +1151,7 @@ static credit_data_t *__get_or_create_credit_data_entry( return (credit_data_t *)e->u.p; no_memory: - LM_ERR("No shared memory left\n"); + SHM_MEM_ERROR; return NULL; } @@ -1205,17 +1159,13 @@ static credit_data_t *__alloc_new_credit_data( str *client_id, credit_type_t type) { credit_data_t *credit_data = shm_malloc(sizeof(credit_data_t)); - ; - if(credit_data == NULL) goto no_memory; - memset(credit_data, 0, sizeof(credit_data_t)); cnxcc_lock_init(credit_data->lock); credit_data->call_list = shm_malloc(sizeof(call_t)); - if(credit_data->call_list == NULL) goto no_memory; @@ -1231,7 +1181,6 @@ static credit_data_t *__alloc_new_credit_data( if(_data.redis) { credit_data->str_id = shm_malloc(client_id->len + 1); - if(!credit_data->str_id) goto no_memory; @@ -1239,14 +1188,7 @@ static credit_data_t *__alloc_new_credit_data( snprintf(credit_data->str_id, client_id->len + 1, "%.*s", client_id->len, client_id->s); } - - credit_data->max_amount = 0; - credit_data->concurrent_calls = 0; - credit_data->consumed_amount = 0; - credit_data->ended_calls_consumed_amount = 0; - credit_data->number_of_calls = 0; credit_data->type = type; - credit_data->deallocating = 0; if(!_data.redis) return credit_data; @@ -1257,7 +1199,7 @@ static credit_data_t *__alloc_new_credit_data( return credit_data; no_memory: - LM_ERR("No shared memory left\n"); + SHM_MEM_ERROR; error: return NULL; } @@ -1277,9 +1219,10 @@ static call_t *__alloc_new_call_by_money(credit_data_t *credit_data, call = shm_malloc(sizeof(call_t)); if(call == NULL) { - LM_ERR("No shared memory left\n"); + SHM_MEM_ERROR; goto error; } + memset(call, 0, sizeof(call_t)); if((!msg->callid && parse_headers(msg, HDR_CALLID_F, 0) != 0) || shm_str_dup(&call->sip_data.callid, &msg->callid->body) != 0) { @@ -1287,16 +1230,6 @@ static call_t *__alloc_new_call_by_money(credit_data_t *credit_data, goto error; } - call->sip_data.to_uri.s = NULL; - call->sip_data.to_uri.len = 0; - call->sip_data.to_tag.s = NULL; - call->sip_data.to_tag.len = 0; - - call->sip_data.from_uri.s = NULL; - call->sip_data.from_uri.len = 0; - call->sip_data.from_tag.s = NULL; - call->sip_data.from_tag.len = 0; - call->consumed_amount = initial_pulse * cost_per_second; call->connect_amount = connect_cost; call->confirmed = FALSE; @@ -1356,6 +1289,7 @@ static call_t *__alloc_new_call_by_time( LM_ERR("No shared memory left\n"); goto error; } + memset(call, 0, sizeof(call_t)); if((!msg->callid && parse_headers(msg, HDR_CALLID_F, 0) != 0) || shm_str_dup(&call->sip_data.callid, &msg->callid->body) != 0) { @@ -1363,16 +1297,6 @@ static call_t *__alloc_new_call_by_time( goto error; } - call->sip_data.to_uri.s = NULL; - call->sip_data.to_uri.len = 0; - call->sip_data.to_tag.s = NULL; - call->sip_data.to_tag.len = 0; - - call->sip_data.from_uri.s = NULL; - call->sip_data.from_uri.len = 0; - call->sip_data.from_tag.s = NULL; - call->sip_data.from_tag.len = 0; - call->consumed_amount = 0; call->confirmed = FALSE; call->max_amount = max_secs; @@ -1423,9 +1347,10 @@ static call_t *alloc_new_call_by_channel( call = shm_malloc(sizeof(call_t)); if(call == NULL) { - LM_ERR("No shared memory left\n"); + SHM_MEM_ERROR; goto error; } + memset(call, 0, sizeof(call_t)); if((!msg->callid && parse_headers(msg, HDR_CALLID_F, 0) != 0) || shm_str_dup(&call->sip_data.callid, &msg->callid->body) != 0) { @@ -1433,16 +1358,6 @@ static call_t *alloc_new_call_by_channel( goto error; } - call->sip_data.to_uri.s = NULL; - call->sip_data.to_uri.len = 0; - call->sip_data.to_tag.s = NULL; - call->sip_data.to_tag.len = 0; - - call->sip_data.from_uri.s = NULL; - call->sip_data.from_uri.len = 0; - call->sip_data.from_tag.s = NULL; - call->sip_data.from_tag.len = 0; - call->consumed_amount = 0; call->confirmed = FALSE; call->max_amount = max_chan; @@ -1534,14 +1449,13 @@ static int __add_call_by_cid(str *cid, call_t *call, credit_type_t type) } e = shm_malloc(sizeof(struct str_hash_entry)); - if(e == NULL) { - LM_ERR("No shared memory left\n"); + SHM_MEM_ERROR; return -1; } if(shm_str_dup(&e->key, cid) != 0) { - LM_ERR("No shared memory left\n"); + SHM_MEM_ERROR; return -1; } @@ -1961,6 +1875,10 @@ static int __set_max_time(sip_msg_t *msg, char *pclient, char *pmaxsecs) static int ki_update_max_time(sip_msg_t *msg, str *sclient, int secs) { credit_data_t *credit_data = NULL; + struct str_hash_table *ht = NULL; + struct str_hash_entry *e = NULL; + double update_fraction = secs; + call_t *call = NULL, *tmp_call = NULL; set_ctrl_flag(msg); @@ -1985,12 +1903,7 @@ static int ki_update_max_time(sip_msg_t *msg, str *sclient, int secs) sclient->len, sclient->s, secs, msg->callid->body.len, msg->callid->body.s); - - struct str_hash_table *ht = NULL; - struct str_hash_entry *e = NULL; ht = _data.time.credit_data_by_client; - double update_fraction = secs; - call_t *call = NULL, *tmp_call = NULL; cnxcc_lock(_data.time.lock); e = str_hash_get(ht, sclient->s, sclient->len); diff --git a/src/modules/cnxcc/cnxcc_mod.h b/src/modules/cnxcc/cnxcc_mod.h index fa2bafcc5..6aa6a692b 100644 --- a/src/modules/cnxcc/cnxcc_mod.h +++ b/src/modules/cnxcc/cnxcc_mod.h @@ -25,7 +25,7 @@ #include "../../core/locking.h" #include "../../core/atomic_ops.h" #include "../../core/str_hash.h" -#include "../../core/parser/parse_rr.h" +#include "../../core/flags.h" #define str_shm_free_if_not_null(_var_) \ if(_var_.s != NULL) { \ @@ -35,7 +35,7 @@ } /*! - * \brief Init a cnxcc_lock + * \brief Init a cnxcc_lock * \param _entry locked entry */ #define cnxcc_lock_init(_entry) \ @@ -89,13 +89,15 @@ typedef struct stats unsigned int dropped; } stats_t; -typedef enum cnxpvtypes { +typedef enum cnxpvtypes +{ CNX_PV_ACTIVE = 1, CNX_PV_TOTAL, CNX_PV_DROPPED } cnxpvtypes_t; -typedef enum credit_type { +typedef enum credit_type +{ CREDIT_TIME, CREDIT_MONEY, CREDIT_CHANNEL @@ -212,7 +214,7 @@ typedef struct credit_data char *str_id; // flag to mark this instance in the process of being eliminated - int deallocating : 1; + unsigned int deallocating : 1; } credit_data_t; diff --git a/src/modules/cnxcc/cnxcc_redis.c b/src/modules/cnxcc/cnxcc_redis.c index 2b9d803ad..7483cf723 100644 --- a/src/modules/cnxcc/cnxcc_redis.c +++ b/src/modules/cnxcc/cnxcc_redis.c @@ -144,9 +144,18 @@ error: static struct redis *__alloc_redis(char *ip, int port, int db) { struct redis *redis = pkg_malloc(sizeof(struct redis)); + if(!redis) { + PKG_MEM_ERROR; + return NULL; + } int len = strlen(ip); redis->ip = pkg_malloc(len + 1); + if(!redis->ip) { + PKG_MEM_ERROR; + pkg_free(redis); + return NULL; + } strcpy(redis->ip, ip); redis->port = port; @@ -226,8 +235,7 @@ static struct redis *__redis_connect(struct redis *redis) static int __redis_select_db(redisContext *ctxt, int db) { - redisReply *rpl; - rpl = redisCommand(ctxt, "SELECT %d", db); + redisReply *rpl = redisCommand(ctxt, "SELECT %d", db); if(!rpl || rpl->type == REDIS_REPLY_ERROR) { if(!rpl) @@ -245,7 +253,7 @@ static int __redis_select_db(redisContext *ctxt, int db) static int __redis_exec( credit_data_t *credit_data, const char *cmd, redisReply **rpl) { - redisReply *rpl_aux; + redisReply *rpl_aux = NULL; char cmd_buffer[1024]; *rpl = redisCommand(_data.redis->ctxt, cmd); @@ -300,7 +308,7 @@ int redis_incr_by_double( int redis_get_double(credit_data_t *credit_data, const char *instruction, const char *key, double *value) { - str str_double = {0, 0}; + str str_double = STR_NULL; char buffer[128]; if(redis_get_str(credit_data, instruction, key, &str_double) < 0) @@ -389,6 +397,11 @@ int redis_get_str(credit_data_t *credit_data, const char *instruction, } value->s = pkg_malloc(rpl->len); + if(!value->s) { + PKG_MEM_ERROR; + freeReplyObject(rpl); + return -1; + } value->len = rpl->len; memcpy(value->s, rpl->str, rpl->len); @@ -516,7 +529,7 @@ int redis_insert_double_value( int redis_kill_list_member_exists(credit_data_t *credit_data) { - redisReply *rpl; + redisReply *rpl = NULL; int exists = 0; char cmd_buffer[1024]; @@ -552,7 +565,7 @@ static void __redis_subscribe_to_kill_list(struct redis *redis) int redis_publish_to_kill_list(credit_data_t *credit_data) { - redisReply *rpl; + redisReply *rpl = NULL; char cmd_buffer[1024]; snprintf(cmd_buffer, sizeof(cmd_buffer), "PUBLISH cnxcc:kill_list %s", credit_data->str_id); @@ -578,8 +591,8 @@ static void __async_disconnect_cb(const redisAsyncContext *c, int status) static void __subscription_cb(redisAsyncContext *c, void *r, void *privdata) { redisReply *reply = r; - str key; - credit_data_t *credit_data; + str key = STR_NULL; + credit_data_t *credit_data = NULL; if(reply == NULL) { LM_ERR("reply is NULL\n"); diff --git a/src/modules/cnxcc/cnxcc_rpc.c b/src/modules/cnxcc/cnxcc_rpc.c index 6c64d649c..5272f112f 100644 --- a/src/modules/cnxcc/cnxcc_rpc.c +++ b/src/modules/cnxcc/cnxcc_rpc.c @@ -22,18 +22,16 @@ #include -#include "../../core/rpc.h" -#include "../../core/rpc_lookup.h" - +#include "cnxcc_rpc.h" #include "cnxcc_mod.h" extern data_t _data; void rpc_kill_call(rpc_t *rpc, void *ctx) { - call_t *call; - hash_tables_t *hts; - str callid; + call_t *call = NULL; + hash_tables_t *hts = NULL; + str callid = STR_NULL; if(!rpc->scan(ctx, "S", &callid)) { LM_ERR("%s: error reading RPC param\n", __FUNCTION__); @@ -65,11 +63,12 @@ void rpc_kill_call(rpc_t *rpc, void *ctx) void rpc_check_client_stats(rpc_t *rpc, void *ctx) { - call_t *call, *tmp; + call_t *call = NULL, *tmp = NULL; int index = 0; - str client_id, rows; + str client_id = STR_NULL; + str rows = STR_NULL; char row_buffer[512]; - credit_data_t *credit_data; + credit_data_t *credit_data = NULL; if(!rpc->scan(ctx, "S", &client_id)) { LM_ERR("%s: error reading RPC param\n", __FUNCTION__); @@ -98,9 +97,7 @@ void rpc_check_client_stats(rpc_t *rpc, void *ctx) return; } - rows.len = 0; rows.s = pkg_malloc(10); - if(rows.s == NULL) goto nomem; @@ -137,7 +134,6 @@ void rpc_check_client_stats(rpc_t *rpc, void *ctx) row_len = strlen(row_buffer); rows.s = pkg_reallocxf(rows.s, rows.len + row_len); - if(rows.s == NULL) { cnxcc_unlock(credit_data->lock); goto nomem; @@ -161,14 +157,14 @@ void rpc_check_client_stats(rpc_t *rpc, void *ctx) return; nomem: - LM_ERR("No more pkg memory\n"); + PKG_MEM_ERROR; rpc->fault(ctx, 500, "No more memory\n"); } static int iterate_over_table( hash_tables_t *hts, str *result, credit_type_t type) { - struct str_hash_entry *h_entry, *tmp; + struct str_hash_entry *h_entry = NULL, *tmp = NULL; char row_buffer[512]; int index = 0; @@ -223,7 +219,6 @@ static int iterate_over_table( row_len = strlen(row_buffer); result->s = pkg_reallocxf(result->s, result->len + row_len); - if(result->s == NULL) { cnxcc_unlock(hts->lock); goto nomem; @@ -238,21 +233,18 @@ static int iterate_over_table( return 0; nomem: - LM_ERR("No more pkg memory\n"); + PKG_MEM_ERROR; return -1; } void rpc_active_clients(rpc_t *rpc, void *ctx) { - str rows; + str rows = STR_NULL; rows.s = pkg_malloc(10); - if(rows.s == NULL) goto nomem; - rows.len = 0; - iterate_over_table(&_data.time, &rows, CREDIT_TIME); iterate_over_table(&_data.money, &rows, CREDIT_MONEY); @@ -266,6 +258,6 @@ void rpc_active_clients(rpc_t *rpc, void *ctx) return; nomem: - LM_ERR("No more pkg memory\n"); + PKG_MEM_ERROR; rpc->fault(ctx, 500, "No more memory\n"); } diff --git a/src/modules/cnxcc/cnxcc_rpc.h b/src/modules/cnxcc/cnxcc_rpc.h index 1723cc28a..7b8b38554 100644 --- a/src/modules/cnxcc/cnxcc_rpc.h +++ b/src/modules/cnxcc/cnxcc_rpc.h @@ -23,6 +23,8 @@ #ifndef CNXCC_RPC_H_ #define CNXCC_RPC_H_ +#include "../../core/rpc.h" + void rpc_active_clients(rpc_t *rpc, void *ctx); void rpc_kill_call(rpc_t *rpc, void *ctx); void rpc_active_clients(rpc_t *rpc, void *ctx); diff --git a/src/modules/cnxcc/cnxcc_select.c b/src/modules/cnxcc/cnxcc_select.c index 7e83c80eb..02e35f65b 100644 --- a/src/modules/cnxcc/cnxcc_select.c +++ b/src/modules/cnxcc/cnxcc_select.c @@ -20,9 +20,9 @@ * */ -#include "../../core/select.h" -#include "../../core/select_buf.h" +#include "../../core/ut.h" +#include "cnxcc_select.h" #include "cnxcc_mod.h" extern data_t _data; diff --git a/src/modules/cnxcc/cnxcc_select.h b/src/modules/cnxcc/cnxcc_select.h index 1c87650ef..814c46d40 100644 --- a/src/modules/cnxcc/cnxcc_select.h +++ b/src/modules/cnxcc/cnxcc_select.h @@ -23,6 +23,9 @@ #ifndef CNXCC_SELECT_H_ #define CNXCC_SELECT_H_ +#include "../../core/str.h" +#include "../../core/select.h" + int sel_root(str *res, select_t *s, struct sip_msg *msg); int sel_channels(str *res, select_t *s, struct sip_msg *msg); int sel_channels_count(str *res, select_t *s, struct sip_msg *msg); diff --git a/src/modules/cnxcc/cnxcc_sip_msg_faker.c b/src/modules/cnxcc/cnxcc_sip_msg_faker.c index 7b601d537..7261b0b49 100644 --- a/src/modules/cnxcc/cnxcc_sip_msg_faker.c +++ b/src/modules/cnxcc/cnxcc_sip_msg_faker.c @@ -20,29 +20,30 @@ * */ +#include + #include "../../core/parser/msg_parser.h" #include "../../core/globals.h" -#include - #define FAKED_SIP_MSG_FORMAT \ "OPTIONS sip:you@kamailio.org SIP/2.0\r\nVia: SIP/2.0/UDP " \ "127.0.0.1\r\nFrom: <%.*s>;tag=%.*s\r\nTo: <%.*s>;tag=%.*s\r\nCall-ID: " \ "%.*s\r\nCSeq: 1 OPTIONS\r\nContent-Length: 0\r\n\r\n" #define FAKED_SIP_MSG_BUF_LEN 1024 -char _faked_sip_msg_buf[FAKED_SIP_MSG_BUF_LEN]; +static char _faked_sip_msg_buf[FAKED_SIP_MSG_BUF_LEN]; static struct sip_msg _faked_msg; -int faked_msg_init_with_dlg_info(str *callid, str *from_uri, str *from_tag, - str *to_uri, str *to_tag, struct sip_msg **msg) +int cnxcc_faked_msg_init_with_dlg_info(str *callid, str *from_uri, + str *from_tag, str *to_uri, str *to_tag, struct sip_msg **msg) { memset(_faked_sip_msg_buf, 0, FAKED_SIP_MSG_BUF_LEN); + memset(&_faked_msg, 0, sizeof(struct sip_msg)); - sprintf(_faked_sip_msg_buf, FAKED_SIP_MSG_FORMAT, from_uri->len, - from_uri->s, from_tag->len, from_tag->s, to_uri->len, to_uri->s, - to_tag->len, to_tag->s, callid->len, callid->s); + snprintf(_faked_sip_msg_buf, FAKED_SIP_MSG_BUF_LEN, FAKED_SIP_MSG_FORMAT, + from_uri->len, from_uri->s, from_tag->len, from_tag->s, to_uri->len, + to_uri->s, to_tag->len, to_tag->s, callid->len, callid->s); LM_DBG("fake msg:\n%s\n", _faked_sip_msg_buf); diff --git a/src/modules/cnxcc/cnxcc_sip_msg_faker.h b/src/modules/cnxcc/cnxcc_sip_msg_faker.h index b3e7abbbc..2b55bd1a5 100644 --- a/src/modules/cnxcc/cnxcc_sip_msg_faker.h +++ b/src/modules/cnxcc/cnxcc_sip_msg_faker.h @@ -22,7 +22,9 @@ #ifndef CNXCC_SIP_MSG_FAKER_H_ #define CNXCC_SIP_MSG_FAKER_H_ -int faked_msg_init_with_dlg_info(str *callid, str *from_uri, str *from_tag, - str *to_uri, str *to_tag, struct sip_msg **msg); +#include "../../core/str.h" + +int cnxcc_faked_msg_init_with_dlg_info(str *callid, str *from_uri, + str *from_tag, str *to_uri, str *to_tag, struct sip_msg **msg); #endif /* CNXCC_SIP_MSG_FAKER_H_ */ diff --git a/src/modules/cnxcc/doc/cnxcc_admin.xml b/src/modules/cnxcc/doc/cnxcc_admin.xml index 4284437a8..0c26cb0a5 100644 --- a/src/modules/cnxcc/doc/cnxcc_admin.xml +++ b/src/modules/cnxcc/doc/cnxcc_admin.xml @@ -128,21 +128,37 @@ modparam("cnxcc", "credit_check_period", 1) Associates the call with a customer id and sets the max credit, connect cost, cost per second, initial pulse and final pulse. The discount - is calculated in pulses (30/6, 1/1, etc) and subtracted from the pool + is calculated in pulses (1/1, 60/1, etc) and subtracted from the pool of credit. The customer value can be provided as a string or a variable holding - a string. + a string. This value identifies all calls from the same customer. + + + The maxcredit (float) value is the maximum credit available for the current call. + + + The connect (float) value is the connect cost for the current call. + + + The cps (float) value is the cost per second for the current call. + + + The ipuse (integer) value is the initial pulse and establishes the minimum + time to be charged. For example, value 1 establishes a charge per second + and value 60 sets a charge per minute. If it is taken as value 60, even + if the duration is 5 seconds, 1 minute will be charged. - The maxcredit, connect and cps can be double (float) or integer values, they - have to be provided as static string values of variables holding string - values. + The fpulse (integer) value is the final pulse and establishes, from the initial + pulse, the time range to be charged. For example, the value 1 establishes a charge + per second, 5 sets a charge in blocks of 5 seconds, 60 sets a full minute charge. - The ipulse and fpulse values are integer values, they can be also - given via variables holding integers. + 1/1 will make a charge per seconds for the entire call. 60/1 will make a + charge per seconds with the first full minute. 60/60 always perform + a full minute charge. Return code: @@ -173,12 +189,15 @@ modparam("cnxcc", "credit_check_period", 1) ... cnxcc_set_max_credit("john-doe", "100", "3.0", "0.5", 60, 1); ... -$var(customer) = "john-doe-premium"; # customer id -$var(credit) = "100"; # max credit -$var(connect) = "3.0"; # connect const -$var(cps) = "0.5"; # cost per second -$var(initial_p) = 60; # initial pulse -$var(final_p) = 1; # final pulse +$var(customer) = "john-doe"; # customer id +$var(credit) = "100"; # max credit for all calls with the same + # customer id +$var(connect) = "3.0"; # connect cost or initial cost for the call +$var(cps) = "0.5"; # cost per second +$var(initial_p) = 60; # initial pulse (60 = the first minute will be + # charged even if the call is shorter) +$var(final_p) = 1; # final pulse (after the first minute, it will + # be charge in ranges of 1 second) cnxcc_set_max_credit("$var(customer)", "$var(credit)", "$var(connect)", "$var(cps)", "$var(initial_p)", "$var(final_p)"); ... diff --git a/src/modules/cplc/Makefile b/src/modules/cplc/Makefile index 7304eee04..371c85beb 100644 --- a/src/modules/cplc/Makefile +++ b/src/modules/cplc/Makefile @@ -7,6 +7,12 @@ NAME=cplc.so ifeq ($(CROSS_COMPILE),) XML2CFG=$(shell which xml2-config) +ifeq ($(XML2CFG),) +XML2CFG=$(shell \ + if pkg-config --exists libxml-2.0; then \ + echo 'pkg-config libxml-2.0'; \ + fi) +endif endif ifneq ($(XML2CFG),) diff --git a/src/modules/ctl/io_listener.c b/src/modules/ctl/io_listener.c index 5d8a22e88..e8182ac62 100644 --- a/src/modules/ctl/io_listener.c +++ b/src/modules/ctl/io_listener.c @@ -13,8 +13,8 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ @@ -43,7 +43,7 @@ #include /* iovec */ #define IO_STREAM_CONN_TIMEOUT S_TO_TICKS(120) -#define IO_LISTEN_TIMEOUT 10 /* in s, how often the timer +#define IO_LISTEN_TIMEOUT 10 /* in s, how often the timer will be run */ #define IO_LISTEN_TX_TIMEOUT 10 /* ms */ @@ -86,16 +86,16 @@ typedef int (*send_ev_f)(void* send_h , struct iovec* v, size_t count); -static io_wait_h io_h; +static io_wait_h ctl_io_h; static int io_read_connections=0; static struct stream_connection stream_conn_lst; /* list head */ -static struct stream_connection* s_conn_new(int sock, +static struct stream_connection* s_conn_new(int sock, struct ctrl_socket* cs, union sockaddr_u* from) { struct stream_connection* s_c; - + s_c=ctl_malloc(sizeof(struct stream_connection)); if (s_c){ memset(s_c, 0, sizeof(struct stream_connection)); @@ -139,11 +139,11 @@ inline static int sendv_disc(struct send_handle* sh, struct iovec* v, char* p; char* end; int r; - + p=buf; end=p+DGRAM_BUF_SIZE; for (r=0; rend) + if ((p+v[r].iov_len)>end) goto error_overflow; memcpy(p, v[r].iov_base, v[r].iov_len); p+=v[r].iov_len; @@ -162,7 +162,7 @@ error_overflow: int sock_send_v(void *h, struct iovec* v, size_t count) { struct send_handle* sh; - + sh=(struct send_handle*)h; if (sh->type==S_CONNECTED) return tsend_dgram_ev(sh->fd, v, count, IO_LISTEN_TX_TIMEOUT); @@ -179,7 +179,7 @@ void io_listen_loop(int fd_no, struct ctrl_socket* cs_lst) int poll_method; struct ctrl_socket *cs; int type; - + clist_init(&stream_conn_lst, next, prev); type=F_T_RESERVED; #if 0 @@ -198,7 +198,7 @@ void io_listen_loop(int fd_no, struct ctrl_socket* cs_lst) poll_method = 0; /* make check for TCP poll method fail */ poll_err = NULL; #endif - + /* set an appropiate poll method */ if (poll_err || (poll_method==0)){ poll_method=choose_poll_method(); @@ -213,8 +213,8 @@ void io_listen_loop(int fd_no, struct ctrl_socket* cs_lst) LOG(L_INFO, "io_listen_loop: using %s io watch method (config)\n", poll_method_name(poll_method)); } - - if (init_io_wait(&io_h, max_fd_no, poll_method)<0) + + if (init_io_wait(&ctl_io_h, max_fd_no, poll_method)<0) goto error; /* add all the sockets we listen on for connections */ for (cs=cs_lst; cs; cs=cs->next){ @@ -239,12 +239,12 @@ void io_listen_loop(int fd_no, struct ctrl_socket* cs_lst) #endif case UNKNOWN_SOCK: LOG(L_CRIT, "BUG: io_listen_loop: bad control socket transport" - " %d\n", cs->transport); + " %d\n", cs->transport); goto error; } DBG("io_listen_loop: adding socket %d, type %d, transport" " %d (%s)\n", cs->fd, type, cs->transport, cs->name); - if (io_watch_add(&io_h, cs->fd, POLLIN, type, cs)<0){ + if (io_watch_add(&ctl_io_h, cs->fd, POLLIN, type, cs)<0){ LOG(L_CRIT, "ERROR: io_listen_loop: init: failed to add" "listen socket to the fd list\n"); goto error; @@ -255,56 +255,56 @@ void io_listen_loop(int fd_no, struct ctrl_socket* cs_lst) if (cfg_child_init()) goto error; /* main loop */ - switch(io_h.poll_method){ + switch(ctl_io_h.poll_method){ case POLL_POLL: while(1){ - io_wait_loop_poll(&io_h, IO_LISTEN_TIMEOUT, 0); + io_wait_loop_poll(&ctl_io_h, IO_LISTEN_TIMEOUT, 0); } break; #ifdef HAVE_SELECT case POLL_SELECT: while(1){ - io_wait_loop_select(&io_h, IO_LISTEN_TIMEOUT, 0); + io_wait_loop_select(&ctl_io_h, IO_LISTEN_TIMEOUT, 0); } break; #endif #ifdef HAVE_SIGIO_RT case POLL_SIGIO_RT: while(1){ - io_wait_loop_sigio_rt(&io_h, IO_LISTEN_TIMEOUT); + io_wait_loop_sigio_rt(&ctl_io_h, IO_LISTEN_TIMEOUT); } break; #endif #ifdef HAVE_EPOLL case POLL_EPOLL_LT: while(1){ - io_wait_loop_epoll(&io_h, IO_LISTEN_TIMEOUT, 0); + io_wait_loop_epoll(&ctl_io_h, IO_LISTEN_TIMEOUT, 0); } break; case POLL_EPOLL_ET: while(1){ - io_wait_loop_epoll(&io_h, IO_LISTEN_TIMEOUT, 1); + io_wait_loop_epoll(&ctl_io_h, IO_LISTEN_TIMEOUT, 1); } break; #endif #ifdef HAVE_KQUEUE case POLL_KQUEUE: while(1){ - io_wait_loop_kqueue(&io_h, IO_LISTEN_TIMEOUT, 0); + io_wait_loop_kqueue(&ctl_io_h, IO_LISTEN_TIMEOUT, 0); } break; #endif #ifdef HAVE_DEVPOLL case POLL_DEVPOLL: while(1){ - io_wait_loop_devpoll(&io_h, IO_LISTEN_TIMEOUT, 0); + io_wait_loop_devpoll(&ctl_io_h, IO_LISTEN_TIMEOUT, 0); } break; #endif default: LOG(L_CRIT, "BUG: io_listen_loop: no support for poll method " - " %s (%d)\n", - poll_method_name(io_h.poll_method), io_h.poll_method); + " %s (%d)\n", + poll_method_name(ctl_io_h.poll_method), ctl_io_h.poll_method); goto error; } /* should never reach this point under normal (non-error) circumstances */ @@ -316,12 +316,12 @@ error: /* handles an io event on one of the watched dgram connections * (it can read the whole packet) - * + * * params: cs - pointer to the control socket for which we have an io ev. * returns: handle_* return convention: * -1 on error, or when we are not interested any more on reads * from this fd (e.g.: we are closing it ) - * 0 on EAGAIN or when by some other way it is known that no more + * 0 on EAGAIN or when by some other way it is known that no more * io events are queued on the fd (the receive buffer is empty). * Usefull to detect when there are no more io events queued for * sigio_rt, epoll_et, kqueue. @@ -337,7 +337,7 @@ static int handle_ctrl_dgram(struct ctrl_socket* cs) int ret; struct send_handle sh; void* saved_state; - + saved_state=0; /* we get always a new datagram */ sh.fd=cs->fd; sh.type=S_DISCONNECTED; @@ -375,12 +375,12 @@ error: /* handles an new connect on one of the watched stream connections - * + * * params: cs - pointer to the control socket for which we have an io ev. * returns: handle_* return convention: * -1 on error, or when we are not interested any more on accepts * from this fd (e.g.: we are closing it ) - * 0 on EAGAIN or when by some other way it is known that no more + * 0 on EAGAIN or when by some other way it is known that no more * io events are queued on the fd (the receive buffer is empty). * Usefull to detect when there are no more io events queued for * sigio_rt, epoll_et, kqueue. @@ -395,7 +395,7 @@ static int handle_new_connect(struct ctrl_socket* cs) unsigned int from_len; int new_sock; struct stream_connection* s_conn; - + from_len=(cs->transport==UDP_SOCK)?sockaddru_len(cs->u.sa_in): sizeof(cs->u.sa_un); again: @@ -430,7 +430,7 @@ again: s_conn=s_conn_new(new_sock, cs, &from); if (s_conn){ s_conn_add(s_conn); - io_watch_add(&io_h, s_conn->fd, POLLIN, F_T_READ_STREAM, s_conn); + io_watch_add(&ctl_io_h, s_conn->fd, POLLIN, F_T_READ_STREAM, s_conn); }else{ LOG(L_ERR, "ERROR: io listen: handle_new_connect:" " s_conn_new failed\n"); @@ -449,14 +449,14 @@ error: /* handles a read event on one of the accepted connections - * + * * params: s_c - pointer to the stream_connection for which we have an io ev. - * idx - index in the fd_array -> pass this to io_watch_del for + * idx - index in the fd_array -> pass this to io_watch_del for * faster deletes * returns: handle_* return convention: * -1 on error, or when we are not interested any more on reads * from this fd (e.g.: we are closing it ) - * 0 on EAGAIN or when by some other way it is known that no more + * 0 on EAGAIN or when by some other way it is known that no more * io events are queued on the fd (the receive buffer is empty). * Usefull to detect when there are no more io events queued for * sigio_rt, epoll_et, kqueue. @@ -472,7 +472,7 @@ static int handle_stream_read(struct stream_connection* s_c, int idx) int bytes_processed; struct stream_req* r; struct send_handle sh; - + sh.fd=s_c->fd; sh.type=S_CONNECTED; sh.from_len=0; @@ -540,17 +540,17 @@ skip: /* everything went fine, we just have to read more */ s_c->expire=get_ticks_raw()+IO_STREAM_CONN_TIMEOUT; /* update timeout*/ return 1; - + no_read: /* false alarm */ return 0; close_connection: - io_watch_del(&io_h, s_c->fd, idx, IO_FD_CLOSING); + io_watch_del(&ctl_io_h, s_c->fd, idx, IO_FD_CLOSING); close(s_c->fd); s_conn_rm(s_c); return 0; error_read: - io_watch_del(&io_h, s_c->fd, idx, IO_FD_CLOSING); + io_watch_del(&ctl_io_h, s_c->fd, idx, IO_FD_CLOSING); close(s_c->fd); s_conn_rm(s_c); return -1; @@ -560,15 +560,15 @@ error_read: #ifdef USE_FIFO -/* handles a read event on one of the fifos - * +/* handles a read event on one of the fifos + * * params: s_c - pointer to the stream_connection for which we have an io ev. - * idx - index in the fd_array -> pass this to io_watch_del for + * idx - index in the fd_array -> pass this to io_watch_del for * faster deletes * returns: handle_* return convention: * -1 on error, or when we are not interested any more on reads * from this fd (e.g.: we are closing it ) - * 0 on EAGAIN or when by some other way it is known that no more + * 0 on EAGAIN or when by some other way it is known that no more * io events are queued on the fd (the receive buffer is empty). * Usefull to detect when there are no more io events queued for * sigio_rt, epoll_et, kqueue. @@ -585,7 +585,7 @@ static int handle_fifo_read(struct ctrl_socket* cs, int idx) struct stream_req* r; struct send_handle sh; struct stream_connection* sc; - + sh.fd=-1; sh.type=S_FIFO; sh.from_len=0; @@ -681,7 +681,7 @@ error: * params: fm - pointer to a fd hash entry * idx - index in the fd_array (or -1 if not known) * return: -1 on error - * 0 on EAGAIN or when by some other way it is known that no more + * 0 on EAGAIN or when by some other way it is known that no more * io events are queued on the fd (the receive buffer is empty). * Usefull to detect when there are no more io events queued for * sigio_rt, epoll_et, kqueue. @@ -731,7 +731,7 @@ void io_listen_who_rpc(rpc_t* rpc, void* ctx) struct ip_addr ip; int port; int i; - + i=0; /* check if called from another process */ if (stream_conn_lst.next==0){ @@ -757,7 +757,7 @@ void io_listen_who_rpc(rpc_t* rpc, void* ctx) case UNIXD_SOCK: #ifdef USE_FIFO case FIFO_SOCK: -#endif +#endif rpc->add(ctx, "ss", "", "" ); rpc->add(ctx, "ss", sc->parent->name, ""); break; @@ -765,7 +765,7 @@ void io_listen_who_rpc(rpc_t* rpc, void* ctx) rpc->add(ctx, "ssss", "", "", "", "", ""); } - + /* idle time * rpc->add(ctx, "d", TICKS_TO_MS(get_ticks_raw()- (sc->expire-IO_STREAM_CONN_TIMEOUT)));*/ diff --git a/src/modules/db_mysql/README b/src/modules/db_mysql/README index e78a7d1c8..739e3b7ca 100644 --- a/src/modules/db_mysql/README +++ b/src/modules/db_mysql/README @@ -31,6 +31,7 @@ Daniel-Constantin Mierla 3.4. auto_reconnect (integer) 3.5. insert_delayed (integer) 3.6. update_affected_found (integer) + 3.7. opt_ssl_mode (integer) 4. Functions 5. Installation @@ -44,9 +45,10 @@ Daniel-Constantin Mierla 1.4. Set auto_reconnect parameter 1.5. Set insert_delayed parameter 1.6. Set update_affected_found parameter - 1.7. Set a my.cnf group in db_url parameter - 1.8. Adding a kamailio group to my.cnf - 1.9. Using [client] and specific group + 1.7. Set opt_ssl_mode parameter + 1.8. Set a my.cnf group in db_url parameter + 1.9. Adding a kamailio group to my.cnf + 1.10. Using [client] and specific group Chapter 1. Admin Guide @@ -66,6 +68,7 @@ Chapter 1. Admin Guide 3.4. auto_reconnect (integer) 3.5. insert_delayed (integer) 3.6. update_affected_found (integer) + 3.7. opt_ssl_mode (integer) 4. Functions 5. Installation @@ -101,6 +104,7 @@ Chapter 1. Admin Guide 3.4. auto_reconnect (integer) 3.5. insert_delayed (integer) 3.6. update_affected_found (integer) + 3.7. opt_ssl_mode (integer) 3.1. ping_interval (integer) @@ -181,6 +185,30 @@ modparam("db_mysql", "insert_delayed", 1) modparam("db_mysql", "update_affected_found", 1) ... +3.7. opt_ssl_mode (integer) + + Control how the connection to MySQL server is done in regards to + SSL/TLS. If set to 1, SSL/TLS mode is disabled. + + The 'include/mysql.h' starting with MySQL 5.7.11 defines the values for + this option as enum: 'mysql_ssl_mode { SSL_MODE_DISABLED=1, + SSL_MODE_PREFERRED, SSL_MODE_REQUIRED, SSL_MODE_VERIFY_CA, + SSL_MODE_VERIFY_IDENTITY}'. + + Note: if the value of this parameter is 1, it enforces + SSL_MODE_DISABLED, any other value is passed to the mysql_options(), + not checking if it is defined. + + Note: this option is supported only by libmysqlclient, not by + libmariadbclient. + + Default value is 0 (0 - off). + + Example 1.7. Set opt_ssl_mode parameter +... +modparam("db_mysql", "opt_ssl_mode", 1) +... + 4. Functions No function exported to be used from configuration file. @@ -207,12 +235,12 @@ modparam("db_mysql", "update_affected_found", 1) * mysql://user:pass@[group]/db * mysql://[group]/db - Example 1.7. Set a my.cnf group in db_url parameter + Example 1.8. Set a my.cnf group in db_url parameter ... modparam("usrloc", "db_url", "mysql://[kamailio]/kamailio) ... - Example 1.8. Adding a kamailio group to my.cnf + Example 1.9. Adding a kamailio group to my.cnf ... [kamailio] socket = /path/to/mysql.sock @@ -226,7 +254,7 @@ default-character-set = utf8 both your specific group and the client group, then the value is taken from the last one. - Example 1.9. Using [client] and specific group + Example 1.10. Using [client] and specific group ... [client] socket = /var/run/mysql/mysqld.sock diff --git a/src/modules/db_mysql/db_mysql.c b/src/modules/db_mysql/db_mysql.c index da130f181..397372f5a 100644 --- a/src/modules/db_mysql/db_mysql.c +++ b/src/modules/db_mysql/db_mysql.c @@ -45,6 +45,7 @@ unsigned int my_server_timezone = 0; /* Use FROM_UNIXTIME() for date conversion unsigned long my_client_ver = 0; int db_mysql_unsigned_type = 0; +int db_mysql_opt_ssl_mode = 0; struct mysql_counters_h mysql_cnts_h; counter_def_t mysql_cnt_defs[] = { @@ -100,6 +101,7 @@ static param_export_t params[] = { {"insert_delayed", INT_PARAM, &db_mysql_insert_all_delayed}, {"update_affected_found", INT_PARAM, &db_mysql_update_affected_found}, {"unsigned_type", PARAM_INT, &db_mysql_unsigned_type}, + {"opt_ssl_mode", PARAM_INT, &db_mysql_opt_ssl_mode}, {0, 0, 0} }; diff --git a/src/modules/db_mysql/doc/db_mysql_admin.xml b/src/modules/db_mysql/doc/db_mysql_admin.xml index 69b81d33d..e0d1f2300 100644 --- a/src/modules/db_mysql/doc/db_mysql_admin.xml +++ b/src/modules/db_mysql/doc/db_mysql_admin.xml @@ -178,6 +178,39 @@ modparam("db_mysql", "insert_delayed", 1) ... modparam("db_mysql", "update_affected_found", 1) ... + + + +
+ <varname>opt_ssl_mode</varname> (integer) + + Control how the connection to MySQL server is done in regards to SSL/TLS. + If set to 1, SSL/TLS mode is disabled. + + + The 'include/mysql.h' starting with MySQL 5.7.11 defines the values for + this option as enum: 'mysql_ssl_mode { SSL_MODE_DISABLED=1, SSL_MODE_PREFERRED, + SSL_MODE_REQUIRED, SSL_MODE_VERIFY_CA, SSL_MODE_VERIFY_IDENTITY}'. + + + Note: if the value of this parameter is 1, it enforces SSL_MODE_DISABLED, + any other value is passed to the mysql_options(), not checking if it is + defined. + + + Note: this option is supported only by libmysqlclient, not by libmariadbclient. + + + + Default value is 0 (0 - off). + + + + Set <varname>opt_ssl_mode</varname> parameter + +... +modparam("db_mysql", "opt_ssl_mode", 1) +...
diff --git a/src/modules/db_mysql/km_my_con.c b/src/modules/db_mysql/km_my_con.c index bed21f92a..fb4f7dd5a 100644 --- a/src/modules/db_mysql/km_my_con.c +++ b/src/modules/db_mysql/km_my_con.c @@ -40,6 +40,8 @@ #include "../../core/ut.h" #include "db_mysql.h" +extern int db_mysql_opt_ssl_mode; + /*! \brief * Create a new connection structure, * open the MySQL connection and set reference count to 1 @@ -49,6 +51,7 @@ struct my_con* db_mysql_new_connection(const struct db_id* id) struct my_con* ptr; char *host, *grp, *egrp; unsigned int connection_flag = 0; + #if MYSQL_VERSION_ID > 50012 #if MYSQL_VERSION_ID > 80000 && ! defined MARIADB_BASE_VERSION bool rec; @@ -112,6 +115,27 @@ struct my_con* db_mysql_new_connection(const struct db_id* id) mysql_options(ptr->con, MYSQL_OPT_CONNECT_TIMEOUT, (const void*)&db_mysql_timeout_interval); mysql_options(ptr->con, MYSQL_OPT_READ_TIMEOUT, (const void*)&db_mysql_timeout_interval); mysql_options(ptr->con, MYSQL_OPT_WRITE_TIMEOUT, (const void*)&db_mysql_timeout_interval); +#if MYSQL_VERSION_ID > 50710 && !defined(MARIADB_BASE_VERSION) + if(db_mysql_opt_ssl_mode!=0) { + unsigned int optuint = 0; + if(db_mysql_opt_ssl_mode==1) { + if(db_mysql_opt_ssl_mode!=SSL_MODE_DISABLED) { + LM_WARN("ssl mode disabled is not 1 (value %u) - enforcing\n", + SSL_MODE_DISABLED); + } + optuint = SSL_MODE_DISABLED; + } else { + optuint = (unsigned int)db_mysql_opt_ssl_mode; + } + mysql_options(ptr->con, MYSQL_OPT_SSL_MODE, (const void*)&optuint); + } +#else + if(db_mysql_opt_ssl_mode!=0) { + LM_WARN("ssl mode not supported by mysql version (value %u) - ignoring\n", + (unsigned int)db_mysql_opt_ssl_mode); + } +#endif + #if MYSQL_VERSION_ID > 50012 /* set reconnect flag if enabled */ if (db_mysql_auto_reconnect) { diff --git a/src/modules/db_mysql/my_con.c b/src/modules/db_mysql/my_con.c index f64a90f0a..240546808 100644 --- a/src/modules/db_mysql/my_con.c +++ b/src/modules/db_mysql/my_con.c @@ -31,6 +31,7 @@ #include #include +extern int db_mysql_opt_ssl_mode; /* * Close the connection and release memory @@ -70,6 +71,26 @@ int my_con_connect(db_con_t* con) (const void*)&my_connect_to)) WARN("failed to set MYSQL_OPT_CONNECT_TIMEOUT\n"); } +#if MYSQL_VERSION_ID > 50710 && !defined(MARIADB_BASE_VERSION) + if(db_mysql_opt_ssl_mode!=0) { + unsigned int optuint = 0; + if(db_mysql_opt_ssl_mode==1) { + if(db_mysql_opt_ssl_mode!=SSL_MODE_DISABLED) { + LM_WARN("ssl mode disabled is not 1 (value %u) - enforcing\n", + SSL_MODE_DISABLED); + } + optuint = SSL_MODE_DISABLED; + } else { + optuint = (unsigned int)db_mysql_opt_ssl_mode; + } + mysql_options(mcon->con, MYSQL_OPT_SSL_MODE, (const void*)&optuint); + } +#else + if(db_mysql_opt_ssl_mode!=0) { + LM_WARN("ssl mode not supported by mysql version (value %u) - ignoring\n", + (unsigned int)db_mysql_opt_ssl_mode); + } +#endif #if MYSQL_VERSION_ID >= 40101 if ((my_client_ver >= 50025) || diff --git a/src/modules/dispatcher/dispatch.c b/src/modules/dispatcher/dispatch.c index aaa7b4a2d..d66a48e91 100644 --- a/src/modules/dispatcher/dispatch.c +++ b/src/modules/dispatcher/dispatch.c @@ -79,6 +79,22 @@ #define DS_ALG_RELWEIGHT 11 #define DS_ALG_PARALLEL 12 +/* increment call load */ +#define DS_LOAD_INC(dgrp, didx) do { \ + lock_get(&(dgrp)->lock); \ + (dgrp)->dlist[didx].dload++; \ + lock_release(&(dgrp)->lock); \ + } while(0) + +/* decrement call load */ +#define DS_LOAD_DEC(dgrp, didx) do { \ + lock_get(&(dgrp)->lock); \ + if(likely((dgrp)->dlist[didx].dload > 0)) { \ + (dgrp)->dlist[didx].dload--; \ + } \ + lock_release(&(dgrp)->lock); \ + } while(0) + static int _ds_table_version = DS_TABLE_VERSION; static ds_ht_t *_dsht_load = NULL; @@ -854,7 +870,7 @@ next_line: /* Update list - should it be sync'ed? */ _ds_list_nr = setn; *crt_idx = *next_idx; - ds_ht_clear_slots(_dsht_load); + ds_log_sets(); return 0; @@ -1102,7 +1118,6 @@ int ds_load_db(void) /* update data - should it be sync'ed? */ _ds_list_nr = setn; *crt_idx = *next_idx; - ds_ht_clear_slots(_dsht_load); ds_log_sets(); @@ -1506,6 +1521,7 @@ int ds_get_leastloaded(ds_set_t *dset) k = -1; t = 0x7fffffff; /* high load */ + lock_get(&dset->lock); \ for(j = 0; j < dset->nr; j++) { if(!ds_skip_dst(dset->dlist[j].flags) && (dset->dlist[j].attrs.maxload == 0 @@ -1517,6 +1533,7 @@ int ds_get_leastloaded(ds_set_t *dset) } } } + lock_release(&dset->lock); \ return k; } @@ -1538,7 +1555,7 @@ int ds_load_add(struct sip_msg *msg, ds_set_t *dset, int setid, int dst) msg->callid->body.s); return -1; } - dset->dlist[dst].dload++; + DS_LOAD_INC(dset, dst); return 0; } @@ -1591,23 +1608,24 @@ int ds_load_replace(struct sip_msg *msg, str *duid) break; } } + /* old destination has not been found: has been removed meanwhile? */ if(olddst == -1) { - ds_unlock_cell(_dsht_load, &msg->callid->body); - LM_ERR("old destination address not found for [%d, %.*s]\n", set, + LM_WARN("old destination address not found for [%d, %.*s]\n", set, it->duid.len, it->duid.s); - return -1; - } + } if(newdst == -1) { + /* new destination has not been found: has been removed meanwhile? */ ds_unlock_cell(_dsht_load, &msg->callid->body); LM_ERR("new destination address not found for [%d, %.*s]\n", set, duid->len, duid->s); - return -1; + return -2; } ds_unlock_cell(_dsht_load, &msg->callid->body); ds_del_cell(_dsht_load, &msg->callid->body); - if(idx->dlist[olddst].dload > 0) - idx->dlist[olddst].dload--; + + if(olddst != -1) + DS_LOAD_DEC(idx, olddst); if(ds_load_add(msg, idx, set, newdst) < 0) { LM_ERR("unable to replace destination load [%.*s / %.*s]\n", duid->len, @@ -1646,8 +1664,7 @@ int ds_load_remove_byid(int set, str *duid) return -1; } - if(idx->dlist[olddst].dload > 0) - idx->dlist[olddst].dload--; + DS_LOAD_DEC(idx, olddst); return 0; } @@ -2301,6 +2318,7 @@ int ds_manage_routes(sip_msg_t *msg, ds_select_state_t *rstate) int ds_update_dst(struct sip_msg *msg, int upos, int mode) { + int ret; socket_info_t *sock = NULL; sr_xavp_t *rxavp = NULL; sr_xavp_t *lxavp = NULL; @@ -2313,6 +2331,7 @@ int ds_update_dst(struct sip_msg *msg, int upos, int mode) } } +next_dst: rxavp = xavp_get(&ds_xavp_dst, NULL); if(rxavp == NULL || rxavp->val.type != SR_XTYPE_XAVP) { LM_DBG("no xavp with previous destination record\n"); @@ -2360,12 +2379,18 @@ int ds_update_dst(struct sip_msg *msg, int upos, int mode) return 1; } if(upos == DS_USE_NEXT) { - if(ds_load_replace(msg, &lxavp->val.v.s) < 0) { - LM_ERR("cannot update load distribution\n"); - return -1; + ret = ds_load_replace(msg, &lxavp->val.v.s); + switch(ret) { + case 0: + break; + case -2: + LM_ERR("cannot update load with %.*s, skipping dst.\n", lxavp->val.v.s.len, lxavp->val.v.s.s); + goto next_dst; + default: + LM_ERR("cannot update load distribution\n"); + return -1; } } - return 1; } @@ -2416,7 +2441,7 @@ int ds_add_dst(int group, str *address, int flags) _ds_list_nr = setn; *crt_idx = *next_idx; - ds_ht_clear_slots(_dsht_load); + ds_log_sets(); return 0; @@ -2471,7 +2496,7 @@ int ds_remove_dst(int group, str *address) _ds_list_nr = setn; *crt_idx = *next_idx; - ds_ht_clear_slots(_dsht_load); + ds_log_sets(); return 0; diff --git a/src/modules/dmq/README b/src/modules/dmq/README index d4ddcb864..c4c0dab8a 100644 --- a/src/modules/dmq/README +++ b/src/modules/dmq/README @@ -14,8 +14,6 @@ Edited by Marius Ovidiu Bucur -Edited by - Charles Chance Copyright © 2011 Marius Bucur diff --git a/src/modules/domainpolicy/README b/src/modules/domainpolicy/README index a943e10b9..4afc20a0f 100644 --- a/src/modules/domainpolicy/README +++ b/src/modules/domainpolicy/README @@ -14,8 +14,6 @@ Otmar Lendl -Edited by - Klaus Darilion diff --git a/src/modules/erlang/cnode.c b/src/modules/erlang/cnode.c index b3e789289..141fae71e 100644 --- a/src/modules/erlang/cnode.c +++ b/src/modules/erlang/cnode.c @@ -42,7 +42,7 @@ #define IO_LISTEN_TIMEOUT 10 #define CONNECT_TIMEOUT 500 /* ms */ -static io_wait_h io_h; +static io_wait_h erl_io_h; cnode_handler_t *enode = NULL; csockfd_handler_t *csocket_handler = NULL; @@ -177,7 +177,7 @@ int init_cnode_sockets(int cnode_id) LM_DBG("using %s as the I/O watch method (auto detected)\n", poll_method_name(poll_method)); - if (init_io_wait(&io_h,get_max_open_fds(),poll_method)) + if (init_io_wait(&erl_io_h,get_max_open_fds(),poll_method)) { LM_CRIT("init_io_wait failed\n"); return -1; @@ -195,7 +195,7 @@ int init_cnode_sockets(int cnode_id) return -1; } - if (io_watch_add(&io_h,phandler->sockfd,POLLIN,ERL_CSOCKFD_H,phandler)) { + if (io_watch_add(&erl_io_h,phandler->sockfd,POLLIN,ERL_CSOCKFD_H,phandler)) { LM_CRIT("io_watch_add failed\n"); return -1; } @@ -213,7 +213,7 @@ int init_cnode_sockets(int cnode_id) /* continue even failed to connect, connection can be established * from Erlang side too */ io_handler_del(phandler); - } else if (io_watch_add(&io_h,phandler->sockfd,POLLIN,ERL_CNODE_H,phandler)){ + } else if (io_watch_add(&erl_io_h,phandler->sockfd,POLLIN,ERL_CNODE_H,phandler)){ LM_CRIT("io_watch_add failed\n"); return -1; } @@ -231,7 +231,7 @@ int init_cnode_sockets(int cnode_id) return -1; } - if (io_watch_add(&io_h,phandler->sockfd,POLLIN,ERL_EPMD_H,phandler)){ + if (io_watch_add(&erl_io_h,phandler->sockfd,POLLIN,ERL_EPMD_H,phandler)){ LM_CRIT("io_watch_add failed\n"); return -1; } @@ -263,10 +263,10 @@ void cnode_main_loop(int cnode_id) enode_name = erlang_nodename.s?&erlang_nodename:&erlang_node_sname; /* main loop */ - switch(io_h.poll_method){ + switch(erl_io_h.poll_method){ case POLL_POLL: while(1){ - r = io_wait_loop_poll(&io_h, IO_LISTEN_TIMEOUT, 0); + r = io_wait_loop_poll(&erl_io_h, IO_LISTEN_TIMEOUT, 0); if(!r && enode_connect()) { LM_ERR("failed reconnect to %.*s\n",STR_FMT(enode_name)); } @@ -275,7 +275,7 @@ void cnode_main_loop(int cnode_id) #ifdef HAVE_SELECT case POLL_SELECT: while(1){ - r = io_wait_loop_select(&io_h, IO_LISTEN_TIMEOUT, 0); + r = io_wait_loop_select(&erl_io_h, IO_LISTEN_TIMEOUT, 0); if(!r && enode_connect()) { LM_ERR("failed reconnect to %.*s\n",STR_FMT(enode_name)); } @@ -285,7 +285,7 @@ void cnode_main_loop(int cnode_id) #ifdef HAVE_SIGIO_RT case POLL_SIGIO_RT: while(1){ - r = io_wait_loop_sigio_rt(&io_h, IO_LISTEN_TIMEOUT); + r = io_wait_loop_sigio_rt(&erl_io_h, IO_LISTEN_TIMEOUT); if(!r && enode_connect()) { LM_ERR("failed reconnect to %.*s\n",STR_FMT(enode_name)); } @@ -295,7 +295,7 @@ void cnode_main_loop(int cnode_id) #ifdef HAVE_EPOLL case POLL_EPOLL_LT: while(1){ - r = io_wait_loop_epoll(&io_h, IO_LISTEN_TIMEOUT, 0); + r = io_wait_loop_epoll(&erl_io_h, IO_LISTEN_TIMEOUT, 0); if(!r && enode_connect()) { LM_ERR("failed reconnect to %.*s\n",STR_FMT(enode_name)); } @@ -303,7 +303,7 @@ void cnode_main_loop(int cnode_id) break; case POLL_EPOLL_ET: while(1){ - r = io_wait_loop_epoll(&io_h, IO_LISTEN_TIMEOUT, 1); + r = io_wait_loop_epoll(&erl_io_h, IO_LISTEN_TIMEOUT, 1); if(!r && enode_connect()) { LM_ERR("failed reconnect to %.*s\n",STR_FMT(enode_name)); } @@ -313,7 +313,7 @@ void cnode_main_loop(int cnode_id) #ifdef HAVE_KQUEUE case POLL_KQUEUE: while(1){ - r = io_wait_loop_kqueue(&io_h, IO_LISTEN_TIMEOUT, 0); + r = io_wait_loop_kqueue(&erl_io_h, IO_LISTEN_TIMEOUT, 0); if(!r && enode_connect()) { LM_ERR("failed reconnect to %.*s\n",STR_FMT(enode_name)); } @@ -323,7 +323,7 @@ void cnode_main_loop(int cnode_id) #ifdef HAVE_DEVPOLL case POLL_DEVPOLL: while(1){ - r = io_wait_loop_devpoll(&io_h, IO_LISTEN_TIMEOUT, 0); + r = io_wait_loop_devpoll(&erl_io_h, IO_LISTEN_TIMEOUT, 0); if(!r && enode_connect()) { LM_ERR("failed reconnect to %.*s\n",STR_FMT(enode_name)); } @@ -332,8 +332,8 @@ void cnode_main_loop(int cnode_id) #endif default: LM_CRIT("BUG: io_listen_loop: no support for poll method " - " %s (%d)\n", poll_method_name(io_h.poll_method), - io_h.poll_method); + " %s (%d)\n", poll_method_name(erl_io_h.poll_method), + erl_io_h.poll_method); goto error; } @@ -362,7 +362,7 @@ int handle_io(struct fd_map* fm, short events, int idx) phandler = (handler_common_t*)fm->data; if (phandler->handle_f(phandler)) { - io_watch_del(&io_h,fm->fd,idx,IO_FD_CLOSING); + io_watch_del(&erl_io_h,fm->fd,idx,IO_FD_CLOSING); io_handler_del(phandler); if (fm->type == ERL_WORKER_H) { LM_CRIT("error on unix socket, not recoverable error -- aborting\n"); @@ -384,7 +384,7 @@ int handle_io(struct fd_map* fm, short events, int idx) return -1; } LM_DBG("add new handler type=%d\n",type); - if (io_watch_add(&io_h,phandler->new->sockfd,POLLIN,type,(void*)phandler->new)) { + if (io_watch_add(&erl_io_h,phandler->new->sockfd,POLLIN,type,(void*)phandler->new)) { LM_ERR("failed to add new handler\n"); return -1; } @@ -575,7 +575,7 @@ int enode_connect() { /* continue even failed to connect, connection can be established * from Erlang side too */ io_handler_del(phandler); - } else if (io_watch_add(&io_h,phandler->sockfd,POLLIN,ERL_CNODE_H,phandler)){ + } else if (io_watch_add(&erl_io_h,phandler->sockfd,POLLIN,ERL_CNODE_H,phandler)){ LM_CRIT("io_watch_add failed\n"); erl_close_socket(phandler->sockfd); io_handler_del(phandler); diff --git a/src/modules/evapi/evapi_dispatch.c b/src/modules/evapi/evapi_dispatch.c index b0e1e8386..655424f5d 100644 --- a/src/modules/evapi/evapi_dispatch.c +++ b/src/modules/evapi/evapi_dispatch.c @@ -606,7 +606,7 @@ void evapi_recv_notify(struct ev_loop *loop, struct ev_io *watcher, int revents) return; } - LM_DBG("received [%p] [%.*s] (%d)\n", emsg, + LM_DBG("received [%p] [%.*s] (%d)\n", (void*)emsg, emsg->data.len, emsg->data.s, emsg->data.len); evapi_dispatch_notify(emsg); shm_free(emsg); @@ -774,8 +774,8 @@ int _evapi_relay(str *evdata, str *ctag, int unicast) emsg->unicast = unicast; } - LM_DBG("sending [%p] [%.*s] (%d)\n", emsg, emsg->data.len, emsg->data.s, - emsg->data.len); + LM_DBG("sending [%p] [%.*s] (%d)\n", (void*)emsg, emsg->data.len, + emsg->data.s, emsg->data.len); if(_evapi_notify_sockets[1]!=-1) { len = write(_evapi_notify_sockets[1], &emsg, sizeof(evapi_msg_t*)); if(len<=0) { @@ -785,7 +785,7 @@ int _evapi_relay(str *evdata, str *ctag, int unicast) } } else { cfg_update(); - LM_DBG("dispatching [%p] [%.*s] (%d)\n", emsg, + LM_DBG("dispatching [%p] [%.*s] (%d)\n", (void*)emsg, emsg->data.len, emsg->data.s, emsg->data.len); if(evapi_dispatch_notify(emsg) == 0) { shm_free(emsg); @@ -855,7 +855,7 @@ int evapi_relay(str *event, str *data) LM_ERR("failed to pass the pointer to evapi dispatcher\n"); return -1; } - LM_DBG("sent [%p] [%.*s] (%d)\n", sbuf, sbuf->len, sbuf->s, sbuf->len); + LM_DBG("sent [%p] [%.*s] (%d)\n", (void*)sbuf, sbuf->len, sbuf->s, sbuf->len); return 0; } #endif diff --git a/src/modules/geoip/README b/src/modules/geoip/README index 1ab9a0be0..051fba60b 100644 --- a/src/modules/geoip/README +++ b/src/modules/geoip/README @@ -10,8 +10,6 @@ Daniel-Constantin Mierla -Edited by - Alex Balashov Evariste Systems LLC diff --git a/src/modules/htable/htable.c b/src/modules/htable/htable.c index 443502078..9288084fd 100644 --- a/src/modules/htable/htable.c +++ b/src/modules/htable/htable.c @@ -1246,7 +1246,7 @@ static void htable_rpc_get(rpc_t* rpc, void* c) { ht_cell_t *htc; /*!< One HT cell */ void* th; void* vh; - struct tm *_expire_t; + struct tm _expire_t; char expire_buf[RPC_DATE_BUF_LEN]="NEVER"; if (rpc->scan(c, "SS", &htname, &keyname) < 2) { @@ -1281,9 +1281,9 @@ static void htable_rpc_get(rpc_t* rpc, void* c) { } if (htc->expire) { - _expire_t = localtime(&htc->expire); + localtime_r(&htc->expire, &_expire_t); strftime(expire_buf, RPC_DATE_BUF_LEN - 1, - "%Y-%m-%d %H:%M:%S", _expire_t); + "%Y-%m-%d %H:%M:%S", &_expire_t); } if(htc->flags&AVP_VAL_STR) { diff --git a/src/modules/imc/imc_cmd.c b/src/modules/imc/imc_cmd.c index 757b17b34..bf68967d2 100644 --- a/src/modules/imc/imc_cmd.c +++ b/src/modules/imc/imc_cmd.c @@ -960,7 +960,8 @@ int imc_handle_members(struct sip_msg* msg, imc_cmd_t *cmd, } p = imc_body_buf; - left = sizeof(imc_body_buf); + imc_body_buf[IMC_BUF_SIZE - 1] = '\0'; + left = sizeof(imc_body_buf) - 1; memcpy(p, MEMBERS, sizeof(MEMBERS) - 1); p += sizeof(MEMBERS) - 1; @@ -975,22 +976,22 @@ int imc_handle_members(struct sip_msg* msg, imc_cmd_t *cmd, } if (imp->flags & IMC_MEMBER_OWNER) { - if (left < 1) goto overrun; + if (left < 2) goto overrun; *p++ = '*'; left--; } else if (imp->flags & IMC_MEMBER_ADMIN) { - if (left < 1) goto overrun; + if (left < 2) goto overrun; *p++ = '~'; left--; } name = format_uri(imp->uri); - if (left < name->len) goto overrun; + if (left < name->len + 1) goto overrun; strncpy(p, name->s, name->len); p += name->len; left -= name->len; - if (left < 1) goto overrun; + if (left < 2) goto overrun; *p++ = '\n'; left--; diff --git a/src/modules/ims_auth/Makefile b/src/modules/ims_auth/Makefile index 51ec0a7ca..ee6277e60 100644 --- a/src/modules/ims_auth/Makefile +++ b/src/modules/ims_auth/Makefile @@ -10,6 +10,12 @@ NAME=ims_auth.so ifeq ($(CROSS_COMPILE),) XML2CFG=$(shell which xml2-config) +ifeq ($(XML2CFG),) +XML2CFG=$(shell \ + if pkg-config --exists libxml-2.0; then \ + echo 'pkg-config libxml-2.0'; \ + fi) +endif endif ifneq ($(XML2CFG),) diff --git a/src/modules/ims_charging/README b/src/modules/ims_charging/README index d19574319..04d00ebb0 100644 --- a/src/modules/ims_charging/README +++ b/src/modules/ims_charging/README @@ -39,29 +39,33 @@ Carlos Ruiz Diaz 4. Parameters 4.1. hash_size(int) - 4.2. interim_update_credits(int) - 4.3. timer_buffer(int) - 4.4. ro_forced_peer(string) - 4.5. ro_auth_expiry(integer) - 4.6. ro_auth_expiry(integer) - 4.7. cdp_event_latency(integer) - 4.8. cdp_event_threshold(integer) - 4.9. cdp_event_latency_log(integer) - 4.10. single_ro_session_per_dialog(integer) - 4.11. origin_host(string) - 4.12. origin_realm(string) - 4.13. destination_host(string) - 4.14. destination_realm(string) - 4.15. service_context_id_root(string) - 4.16. service_context_id_ext(string) - 4.17. service_context_id_mnc(string) - 4.18. voice_service_identifier(string) - 4.19. voice_rating_group(string) - 4.20. video_service_identifier(string) - 4.21. video_rating_group(string) - 4.22. service_context_id_mcc(string) - 4.23. service_context_id_release(string) - 4.24. custom_user_avp (avp string) + 4.2. db_mode (int) + 4.3. db_url (string) + 4.4. interim_update_credits(int) + 4.5. timer_buffer(int) + 4.6. ro_forced_peer(string) + 4.7. ro_auth_expiry(integer) + 4.8. ro_auth_expiry(integer) + 4.9. cdp_event_latency(integer) + 4.10. cdp_event_threshold(integer) + 4.11. cdp_event_latency_log(integer) + 4.12. single_ro_session_per_dialog(integer) + 4.13. origin_host(string) + 4.14. origin_realm(string) + 4.15. destination_host(string) + 4.16. destination_realm(string) + 4.17. service_context_id_root(string) + 4.18. service_context_id_ext(string) + 4.19. service_context_id_mnc(string) + 4.20. voice_service_identifier(string) + 4.21. voice_rating_group(string) + 4.22. video_service_identifier(string) + 4.23. video_rating_group(string) + 4.24. service_context_id_mcc(string) + 4.25. service_context_id_release(string) + 4.26. custom_user_avp (avp string) + 4.27. vendor_specific_chargeinfo (int) + 4.28. vendor_specific_id (int) 5. Functions @@ -92,31 +96,35 @@ Carlos Ruiz Diaz List of Examples 1.1. hash_sizeparameter usage - 1.2. interim_update_creditsparameter usage - 1.3. timer_bufferparameter usage - 1.4. ro_forced_peerparameter usage - 1.5. ro_auth_expiryparameter usage - 1.6. ro_auth_expiryparameter usage - 1.7. cdp_event_latencyparameter usage - 1.8. cdp_event_thresholdparameter usage - 1.9. cdp_event_latency_logparameter usage - 1.10. single_ro_session_per_dialogparameter usage - 1.11. origin_hostparameter usage - 1.12. origin_realmparameter usage - 1.13. destination_hostparameter usage - 1.14. destination_realmparameter usage - 1.15. service_context_id_rootparameter usage - 1.16. service_context_id_extparameter usage - 1.17. service_context_id_mncparameter usage - 1.18. voice_service_identifierparameter usage - 1.19. voice_rating_groupparameter usage - 1.20. video_service_identifierparameter usage - 1.21. video_rating_groupparameter usage - 1.22. service_context_id_mccparameter usage - 1.23. service_context_id_releaseparameter usage - 1.24. custom_user_avpparameter usage - 1.25. Ro_CCR - 1.26. Ro_set_session_id_avp + 1.2. db_modeparameter usage + 1.3. db_urlparameter usage + 1.4. interim_update_creditsparameter usage + 1.5. timer_bufferparameter usage + 1.6. ro_forced_peerparameter usage + 1.7. ro_auth_expiryparameter usage + 1.8. ro_auth_expiryparameter usage + 1.9. cdp_event_latencyparameter usage + 1.10. cdp_event_thresholdparameter usage + 1.11. cdp_event_latency_logparameter usage + 1.12. single_ro_session_per_dialogparameter usage + 1.13. origin_hostparameter usage + 1.14. origin_realmparameter usage + 1.15. destination_hostparameter usage + 1.16. destination_realmparameter usage + 1.17. service_context_id_rootparameter usage + 1.18. service_context_id_extparameter usage + 1.19. service_context_id_mncparameter usage + 1.20. voice_service_identifierparameter usage + 1.21. voice_rating_groupparameter usage + 1.22. video_service_identifierparameter usage + 1.23. video_rating_groupparameter usage + 1.24. service_context_id_mccparameter usage + 1.25. service_context_id_releaseparameter usage + 1.26. custom_user_avpparameter usage + 1.27. vendor_specific_chargeinfoparameter usage + 1.28. vendor_specific_idparameter usage + 1.29. Ro_CCR + 1.30. Ro_set_session_id_avp Chapter 1. Admin Guide @@ -137,29 +145,33 @@ Chapter 1. Admin Guide 4. Parameters 4.1. hash_size(int) - 4.2. interim_update_credits(int) - 4.3. timer_buffer(int) - 4.4. ro_forced_peer(string) - 4.5. ro_auth_expiry(integer) - 4.6. ro_auth_expiry(integer) - 4.7. cdp_event_latency(integer) - 4.8. cdp_event_threshold(integer) - 4.9. cdp_event_latency_log(integer) - 4.10. single_ro_session_per_dialog(integer) - 4.11. origin_host(string) - 4.12. origin_realm(string) - 4.13. destination_host(string) - 4.14. destination_realm(string) - 4.15. service_context_id_root(string) - 4.16. service_context_id_ext(string) - 4.17. service_context_id_mnc(string) - 4.18. voice_service_identifier(string) - 4.19. voice_rating_group(string) - 4.20. video_service_identifier(string) - 4.21. video_rating_group(string) - 4.22. service_context_id_mcc(string) - 4.23. service_context_id_release(string) - 4.24. custom_user_avp (avp string) + 4.2. db_mode (int) + 4.3. db_url (string) + 4.4. interim_update_credits(int) + 4.5. timer_buffer(int) + 4.6. ro_forced_peer(string) + 4.7. ro_auth_expiry(integer) + 4.8. ro_auth_expiry(integer) + 4.9. cdp_event_latency(integer) + 4.10. cdp_event_threshold(integer) + 4.11. cdp_event_latency_log(integer) + 4.12. single_ro_session_per_dialog(integer) + 4.13. origin_host(string) + 4.14. origin_realm(string) + 4.15. destination_host(string) + 4.16. destination_realm(string) + 4.17. service_context_id_root(string) + 4.18. service_context_id_ext(string) + 4.19. service_context_id_mnc(string) + 4.20. voice_service_identifier(string) + 4.21. voice_rating_group(string) + 4.22. video_service_identifier(string) + 4.23. video_rating_group(string) + 4.24. service_context_id_mcc(string) + 4.25. service_context_id_release(string) + 4.26. custom_user_avp (avp string) + 4.27. vendor_specific_chargeinfo (int) + 4.28. vendor_specific_id (int) 5. Functions @@ -335,29 +347,33 @@ Chapter 1. Admin Guide 4. Parameters 4.1. hash_size(int) - 4.2. interim_update_credits(int) - 4.3. timer_buffer(int) - 4.4. ro_forced_peer(string) - 4.5. ro_auth_expiry(integer) - 4.6. ro_auth_expiry(integer) - 4.7. cdp_event_latency(integer) - 4.8. cdp_event_threshold(integer) - 4.9. cdp_event_latency_log(integer) - 4.10. single_ro_session_per_dialog(integer) - 4.11. origin_host(string) - 4.12. origin_realm(string) - 4.13. destination_host(string) - 4.14. destination_realm(string) - 4.15. service_context_id_root(string) - 4.16. service_context_id_ext(string) - 4.17. service_context_id_mnc(string) - 4.18. voice_service_identifier(string) - 4.19. voice_rating_group(string) - 4.20. video_service_identifier(string) - 4.21. video_rating_group(string) - 4.22. service_context_id_mcc(string) - 4.23. service_context_id_release(string) - 4.24. custom_user_avp (avp string) + 4.2. db_mode (int) + 4.3. db_url (string) + 4.4. interim_update_credits(int) + 4.5. timer_buffer(int) + 4.6. ro_forced_peer(string) + 4.7. ro_auth_expiry(integer) + 4.8. ro_auth_expiry(integer) + 4.9. cdp_event_latency(integer) + 4.10. cdp_event_threshold(integer) + 4.11. cdp_event_latency_log(integer) + 4.12. single_ro_session_per_dialog(integer) + 4.13. origin_host(string) + 4.14. origin_realm(string) + 4.15. destination_host(string) + 4.16. destination_realm(string) + 4.17. service_context_id_root(string) + 4.18. service_context_id_ext(string) + 4.19. service_context_id_mnc(string) + 4.20. voice_service_identifier(string) + 4.21. voice_rating_group(string) + 4.22. video_service_identifier(string) + 4.23. video_rating_group(string) + 4.24. service_context_id_mcc(string) + 4.25. service_context_id_release(string) + 4.26. custom_user_avp (avp string) + 4.27. vendor_specific_chargeinfo (int) + 4.28. vendor_specific_id (int) 4.1. hash_size(int) @@ -377,7 +393,30 @@ Chapter 1. Admin Guide modparam("ims_charging", "hash_size", 1024) ... -4.2. interim_update_credits(int) +4.2. db_mode (int) + + Should a database be used to store dialog information. + + Available database modes: 0 for no database, 1 for real-time mode and 2 + for shutdown mode. Mode 2 seems to be not fully implemented. + + Default value is 0 - no database is used. + + Example 1.2. db_modeparameter usage +... +modparam("ims_charging", "db_mode", 0) +... + +4.3. db_url (string) + + Default value is “mysql://kamailio:kamailiorw@localhost/kamailio” + + Example 1.3. db_urlparameter usage +... +modparam("ims_charging", "db_url", "dbdriver://username:password@dbhost/dbname") +... + +4.4. interim_update_credits(int) How much credit should be requested interim request? At the start of the call, we request the amount of seconds as per Command. For each @@ -385,24 +424,24 @@ modparam("ims_charging", "hash_size", 1024) Default value is 30. - Example 1.2. interim_update_creditsparameter usage + Example 1.4. interim_update_creditsparameter usage ... modparam("ims_charging", "interim_update_credits", 600) ... -4.3. timer_buffer(int) +4.5. timer_buffer(int) How many seconds before expiry of our credit should we request more credit? Default value is 8. - Example 1.3. timer_bufferparameter usage + Example 1.5. timer_bufferparameter usage ... modparam("ims_charging", "timer_buffer", 10) ... -4.4. ro_forced_peer(string) +4.6. ro_forced_peer(string) FQDN of Diameter Peer (OCS) to use for communication (CCR). If you use this, the routing defined in your diameter xml configuration file (CDP) @@ -411,48 +450,48 @@ modparam("ims_charging", "timer_buffer", 10) Default value is ''. - Example 1.4. ro_forced_peerparameter usage + Example 1.6. ro_forced_peerparameter usage ... modparam("ims_charging", "ro_forced_peer", "ocs.ims.smilecoms.com") ... -4.5. ro_auth_expiry(integer) +4.7. ro_auth_expiry(integer) This is the expiry length in seconds of the initiated Diameter sessions. Default value is 7200. - Example 1.5. ro_auth_expiryparameter usage + Example 1.7. ro_auth_expiryparameter usage ... modparam("ims_charging", "ro_auth_expiry", 14400) ... -4.6. ro_auth_expiry(integer) +4.8. ro_auth_expiry(integer) This is the expiry length in seconds of the initiated Diameter sessions. Default value is 7200. - Example 1.6. ro_auth_expiryparameter usage + Example 1.8. ro_auth_expiryparameter usage ... modparam("ims_charging", "ro_auth_expiry", 14400) ... -4.7. cdp_event_latency(integer) +4.9. cdp_event_latency(integer) This is a flag to determine whether or slow CDP responses should be reported in the log file. 1 is enabled and 0 is disabled. Default value is 1. - Example 1.7. cdp_event_latencyparameter usage + Example 1.9. cdp_event_latencyparameter usage ... modparam("ims_charging", "cdp_event_latency", 1) ... -4.8. cdp_event_threshold(integer) +4.10. cdp_event_threshold(integer) This time in milliseconds is the limit we should report a CDP response as slow. i.e. if a CDP response exceeds this limit it will be reported @@ -461,12 +500,12 @@ modparam("ims_charging", "cdp_event_latency", 1) Default value is 500. - Example 1.8. cdp_event_thresholdparameter usage + Example 1.10. cdp_event_thresholdparameter usage ... modparam("ims_charging", "cdp_event_threshold", 500) ... -4.9. cdp_event_latency_log(integer) +4.11. cdp_event_latency_log(integer) This time log level at which we should report slow CDP responses. 0 is ERROR, 1 is WARN, 2 is INFO and 3 is DEBUG. This is only relevant is @@ -474,12 +513,12 @@ modparam("ims_charging", "cdp_event_threshold", 500) Default value is 0. - Example 1.9. cdp_event_latency_logparameter usage + Example 1.11. cdp_event_latency_logparameter usage ... modparam("ims_charging", "cdp_event_latency_log", 1) ... -4.10. single_ro_session_per_dialog(integer) +4.12. single_ro_session_per_dialog(integer) This tells the module whether it should do a single ro session per dialog no matter how many times Ro_send_CCR is called from the config @@ -490,56 +529,56 @@ modparam("ims_charging", "cdp_event_latency_log", 1) Default value is 0. - Example 1.10. single_ro_session_per_dialogparameter usage + Example 1.12. single_ro_session_per_dialogparameter usage ... modparam("ims_charging", "single_ro_session_per_dialog", 1) ... -4.11. origin_host(string) +4.13. origin_host(string) Origin host to be used in Diameter messages to charging-server. - Default value is "scscf.ims.smilecoms.com". + Default value is "". - Example 1.11. origin_hostparameter usage + Example 1.13. origin_hostparameter usage ... modparam("ims_charging", "origin_host", "scscf.kamailio-ims.org") ... -4.12. origin_realm(string) +4.14. origin_realm(string) Origin Realm to be used in Diameter messages to charging-server. - Default value is "ims.smilecome.com". + Default value is "". - Example 1.12. origin_realmparameter usage + Example 1.14. origin_realmparameter usage ... modparam("ims_charging", "origin_realm", "kamailio-ims.org") ... -4.13. destination_host(string) +4.15. destination_host(string) Destination host to be used in Diameter messages to charging-server. - Default value is 5s. + Default value is "hss.ims.smilecoms.com". - Example 1.13. destination_hostparameter usage + Example 1.15. destination_hostparameter usage ... modparam("ims_charging", "destination_host", "ocs.kamailio-ims.org") ... -4.14. destination_realm(string) +4.16. destination_realm(string) Destination realm to be used in Diameter messages to charging-server. Default value is "ims.smilecoms.com". - Example 1.14. destination_realmparameter usage + Example 1.16. destination_realmparameter usage ... modparam("ims_charging", "destination_realm", "kamailio-ims.org") ... -4.15. service_context_id_root(string) +4.17. service_context_id_root(string) This defines a root-element of the Service-Context-Id AVP used in the diameter-message @@ -570,80 +609,80 @@ modparam("ims_charging", "destination_realm", "kamailio-ims.org") Default value is "32260@3gpp.org". - Example 1.15. service_context_id_rootparameter usage + Example 1.17. service_context_id_rootparameter usage ... modparam("ims_charging", "service_context_id_root", "calls@kamailio-ims.org") ... -4.16. service_context_id_ext(string) +4.18. service_context_id_ext(string) This defines the extension of the Service-Context-Id AVP used in the diameter-message. Default value is "ext". - Example 1.16. service_context_id_extparameter usage + Example 1.18. service_context_id_extparameter usage ... modparam("ims_charging", "service_context_id_ext", "ext2") ... -4.17. service_context_id_mnc(string) +4.19. service_context_id_mnc(string) This defines Mobile-Network-Code (MNC) of the Service-Context-Id AVP used in the diameter-message. Default value is "01". - Example 1.17. service_context_id_mncparameter usage + Example 1.19. service_context_id_mncparameter usage ... modparam("ims_charging", "service_context_id_mnc", "42") ... -4.18. voice_service_identifier(string) +4.20. voice_service_identifier(string) This defines the service identifier to be used for charging voice. Default value is "1000". - Example 1.18. voice_service_identifierparameter usage + Example 1.20. voice_service_identifierparameter usage ... modparam("ims_charging", "voice_service_identifier", "1000") ... -4.19. voice_rating_group(string) +4.21. voice_rating_group(string) This defines the rating group to be used for charging voice. Default value is "100". - Example 1.19. voice_rating_groupparameter usage + Example 1.21. voice_rating_groupparameter usage ... modparam("ims_charging", "voice_rating_group", "100") ... -4.20. video_service_identifier(string) +4.22. video_service_identifier(string) This defines the service identifier to be used for charging video. Default value is "1001". - Example 1.20. video_service_identifierparameter usage + Example 1.22. video_service_identifierparameter usage ... modparam("ims_charging", "video_service_identifier", "1000") ... -4.21. video_rating_group(string) +4.23. video_rating_group(string) This defines the rating group to be used for charging video. Default value is "200". - Example 1.21. video_rating_groupparameter usage + Example 1.23. video_rating_groupparameter usage ... modparam("ims_charging", "video_rating_group", "100") ... -4.22. service_context_id_mcc(string) +4.24. service_context_id_mcc(string) This defines Mobile-Country-Code (MCC) of the Service-Context-Id AVP used in the diameter-message. @@ -653,24 +692,24 @@ modparam("ims_charging", "video_rating_group", "100") Default value is "001". - Example 1.22. service_context_id_mccparameter usage + Example 1.24. service_context_id_mccparameter usage ... modparam("ims_charging", "service_context_id_mcc", "262") ... -4.23. service_context_id_release(string) +4.25. service_context_id_release(string) This defines Release of the Service-Context-Id AVP used in the diameter-message. Default value is "8" (Release 8). - Example 1.23. service_context_id_releaseparameter usage + Example 1.25. service_context_id_releaseparameter usage ... modparam("ims_charging", "service_context_id_release", "262") ... -4.24. custom_user_avp (avp string) +4.26. custom_user_avp (avp string) When this parameter is set and the contents of the AVP is not empty, the User-AVP in the Ro-Charging-Request will be based on the this @@ -682,11 +721,37 @@ modparam("ims_charging", "service_context_id_release", "262") Default value: if not set, P-Asserted-Identity with a fallback to the From-Header is used. - Example 1.24. custom_user_avpparameter usage + Example 1.26. custom_user_avpparameter usage ... modparam("ims_charging", "custom_user_avp", "$avp(from_user)") ... +4.27. vendor_specific_chargeinfo (int) + + This parameter can be used to activate or deactivate the addition of + Vendor-Specific-Termination-Clause and + Vendor-Specific-Termination-Reason AVPs to the requests. To activate + set this parameter to 1. + + Default value is "0" (deactivated). + + Example 1.27. vendor_specific_chargeinfoparameter usage +... +modparam("ims_charging", "vendor_specific_chargeinfo", 1) +... + +4.28. vendor_specific_id (int) + + To set the ID of the Vendor-Specific information, not implemented right + now. + + Default value is "10". + + Example 1.28. vendor_specific_idparameter usage +... +modparam("ims_charging", "vendor_specific_id", 10) +... + 5. Functions 5.1. Ro_CCR(route_name, direction, reservation_units, @@ -714,7 +779,7 @@ outgoing_trunk_id) This method is executed asynchronously. See example on how to retrieve return value. - Example 1.25. Ro_CCR + Example 1.29. Ro_CCR ... xlog("L_DBG","Sending initial CCR Request for call\n"); Ro_CCR("RO_ASYNC_TERM_REPLY", "term", 30, "1", "1"); @@ -750,7 +815,7 @@ n"); This function can be used from REQUEST_ROUTE or ONREPLY_ROUTE. - Example 1.26. Ro_set_session_id_avp + Example 1.30. Ro_set_session_id_avp ... Ro_set_session_id_avp(); xlog("L_DBG","Ro session AVP has been set: $avp(ro_session_id)\n"); diff --git a/src/modules/ims_charging/ccr.c b/src/modules/ims_charging/ccr.c index d15d0a43a..0c1d069b1 100644 --- a/src/modules/ims_charging/ccr.c +++ b/src/modules/ims_charging/ccr.c @@ -300,7 +300,7 @@ Ro_CCA_t *Ro_parse_CCA_avps(AAAMessage *cca) { mscc_avp_list_ptr = &mscc_avp_list; AAA_AVP *mscc_avp = mscc_avp_list_ptr->head; while (mscc_avp != NULL) { - LM_DBG("MSCC AVP code is [%i] and data length is [%i]", mscc_avp->code, mscc_avp->data.len); + LM_DBG("MSCC AVP code is [%i] and data length is [%i]\n", mscc_avp->code, mscc_avp->data.len); switch (mscc_avp->code) { AAA_AVP_LIST y; AAA_AVP *z; diff --git a/src/modules/ims_charging/dialog.c b/src/modules/ims_charging/dialog.c index fdbaafe66..a91ebdbe9 100644 --- a/src/modules/ims_charging/dialog.c +++ b/src/modules/ims_charging/dialog.c @@ -58,7 +58,7 @@ void dlg_answered(struct dlg_cell *dlg, int type, struct dlg_cb_params *_params) ro_session_lock(ro_session_table, ro_session_entry); if (session->active) { - LM_CRIT("Why the heck am i receiving a double confirmation of the dialog? Ignoring... "); + LM_CRIT("Why the heck am i receiving a double confirmation of the dialog? Ignoring...\n"); ro_session_unlock(ro_session_table, ro_session_entry); return; } else if (session->active < 0) { //session has already been terminated - we can't reactivate... @@ -152,7 +152,7 @@ void dlg_terminated(struct dlg_cell *dlg, int type, unsigned int termcode, char* s_reason = h->body; } } else if (_params->rpl) { - LM_DBG("Reply is [%d - %.*s]", _params->rpl->first_line.u.reply.statuscode, _params->rpl->first_line.u.reply.reason.len, _params->rpl->first_line.u.reply.reason.s); + LM_DBG("Reply is [%d - %.*s]\n", _params->rpl->first_line.u.reply.statuscode, _params->rpl->first_line.u.reply.reason.len, _params->rpl->first_line.u.reply.reason.s); } ro_session = (struct ro_session*)*_params->param; @@ -182,7 +182,7 @@ void dlg_terminated(struct dlg_cell *dlg, int type, unsigned int termcode, char* //If however, the call was never answered, then we can continue as normal ro_session_lock(ro_session_table, ro_session_entry); - LM_DBG("processing dlg_terminated in Ro and session [%.*s] has active = %d", ro_session->ro_session_id.len, ro_session->ro_session_id.s, ro_session->active); + LM_DBG("processing dlg_terminated in Ro and session [%.*s] has active = %d\n", ro_session->ro_session_id.len, ro_session->ro_session_id.s, ro_session->active); if ((!ro_session->active && (ro_session->start_time != 0)) || (ro_session->ccr_sent == 1)) { unref_ro_session(ro_session,1,0); LM_DBG("CCR already sent or Ro Session is not active, but may have been answered [%d]\n", (int)ro_session->start_time); diff --git a/src/modules/ims_charging/diameter_ro.c b/src/modules/ims_charging/diameter_ro.c index 52a3e1d1e..2be575a47 100644 --- a/src/modules/ims_charging/diameter_ro.c +++ b/src/modules/ims_charging/diameter_ro.c @@ -31,7 +31,7 @@ void RoChargingResponseHandler(AAAMessage *response, void *param) { LM_ERR("DBG:"M_NAME":RoChargingResponseHandler(): - Received unknown response for app %d command %d\n", response->applicationId, response->commandCode); - LM_ERR("Response is [%s]", response->buf.s); + LM_ERR("Response is [%s]\n", response->buf.s); return; } diff --git a/src/modules/ims_charging/doc/ims_charging_admin.xml b/src/modules/ims_charging/doc/ims_charging_admin.xml index 465044a12..92bf0e000 100644 --- a/src/modules/ims_charging/doc/ims_charging_admin.xml +++ b/src/modules/ims_charging/doc/ims_charging_admin.xml @@ -263,6 +263,45 @@ modparam("ims_charging", "hash_size", 1024) +
+ <varname>db_mode</varname> (int) + + Should a database be used to store dialog information. + + Available database modes: 0 for no database, 1 for real-time mode and + 2 for shutdown mode. Mode 2 seems to be not fully implemented. + + Default value is 0 - no database is used. + + + <varname>db_mode</varname>parameter usage + + +... +modparam("ims_charging", "db_mode", 0) +... + + +
+ +
+ <varname>db_url</varname> (string) + + + + Default value is &defaultdb; + + + <varname>db_url</varname>parameter usage + + +... +modparam("ims_charging", "db_url", "&exampledb;") +... + + +
+
<varname>interim_update_credits</varname>(int) @@ -453,8 +492,7 @@ modparam("ims_charging", "single_ro_session_per_dialog", 1) Origin host to be used in Diameter messages to charging-server. - Default value is - "scscf.ims.smilecoms.com". + Default value is "". <varname>origin_host</varname>parameter usage @@ -473,7 +511,7 @@ modparam("ims_charging", "origin_host", "scscf.kamailio-ims.org") Origin Realm to be used in Diameter messages to charging-server. - Default value is "ims.smilecome.com". + Default value is "". <varname>origin_realm</varname>parameter usage @@ -492,7 +530,7 @@ modparam("ims_charging", "origin_realm", "kamailio-ims.org") Destination host to be used in Diameter messages to charging-server. - Default value is 5s. + Default value is "hss.ims.smilecoms.com". <varname>destination_host</varname>parameter usage @@ -755,6 +793,48 @@ modparam("ims_charging", "custom_user_avp", "$avp(from_user)")
+ +
+ <varname>vendor_specific_chargeinfo</varname> (int) + + This parameter can be used to activate or deactivate the addition + of Vendor-Specific-Termination-Clause and Vendor-Specific-Termination-Reason + AVPs to the requests. To activate set this parameter to 1. + + Default value is "0" (deactivated). + + + <varname>vendor_specific_chargeinfo</varname>parameter + usage + + +... +modparam("ims_charging", "vendor_specific_chargeinfo", 1) +... + + +
+ +
+ <varname>vendor_specific_id</varname> (int) + + To set the ID of the Vendor-Specific information, not implemented right + now. + + Default value is "10". + + + <varname>vendor_specific_id</varname>parameter + usage + + +... +modparam("ims_charging", "vendor_specific_id", 10) +... + + +
+
diff --git a/src/modules/ims_charging/ims_charging_mod.c b/src/modules/ims_charging/ims_charging_mod.c index 5fabde671..150a52588 100644 --- a/src/modules/ims_charging/ims_charging_mod.c +++ b/src/modules/ims_charging/ims_charging_mod.c @@ -76,7 +76,7 @@ struct tm_binds tmb; /* Only used if we want to force the Ro peer usually this is configured at a stack level and the first request uses realm routing */ //char* rx_forced_peer_s = ""; -str ro_forced_peer; +str ro_forced_peer = str_init(""); int ro_auth_expiry = 7200; int cdp_event_latency = 1; /*flag: report slow processing of CDP callback events or not - default enabled */ int cdp_event_threshold = 500; /*time in ms above which we should report slow processing of CDP callback event - default 500ms*/ @@ -502,7 +502,7 @@ static int w_ro_ccr(struct sip_msg *msg, char* c_route_name, char* c_direction, if (msg->first_line.type != SIP_REQUEST) { - LM_ERR("Ro_CCR() called from SIP reply."); + LM_ERR("Ro_CCR() called from SIP reply.\n"); return RO_RETURN_ERROR;; } @@ -519,12 +519,12 @@ static int w_ro_ccr(struct sip_msg *msg, char* c_route_name, char* c_direction, if (dir == RO_ORIG_DIRECTION) { //get caller IMPU from asserted identity if ((identity = cscf_get_asserted_identity(msg, 0)).len == 0) { - LM_DBG("No P-Asserted-Identity hdr found. Using From hdr for asserted_identity"); + LM_DBG("No P-Asserted-Identity hdr found. Using From hdr for asserted_identity\n"); identity = dlg->from_uri; } //get caller contact from contact header - if not present then skip this if ((contact = cscf_get_contact(msg)).len == 0) { - LM_WARN("Can not get contact from message - will not get callbacks if this IMPU is removed to terminate call"); + LM_WARN("Can not get contact from message - will not get callbacks if this IMPU is removed to terminate call\n"); goto send_ccr; } @@ -532,7 +532,7 @@ static int w_ro_ccr(struct sip_msg *msg, char* c_route_name, char* c_direction, } else if (dir == RO_TERM_DIRECTION){ //get callee IMPU from called part id - if not present then skip this if ((identity = cscf_get_public_identity_from_called_party_id(msg, &h)).len == 0) { - LM_DBG("No P-Called-Identity hdr found - will not get callbacks if this IMPU is removed to terminate call"); + LM_DBG("No P-Called-Identity hdr found - will not get callbacks if this IMPU is removed to terminate call\n"); goto send_ccr; } //get callee contact from request URI diff --git a/src/modules/ims_charging/ims_ro.c b/src/modules/ims_charging/ims_ro.c index b78016b99..700178a0a 100644 --- a/src/modules/ims_charging/ims_ro.c +++ b/src/modules/ims_charging/ims_ro.c @@ -380,10 +380,10 @@ int get_sip_header_info(struct sip_msg * req, if (get_custom_user(req, asserted_id_uri) == -1) { if ((*asserted_id_uri = cscf_get_asserted_identity(req, 0)).len == 0) { - LM_DBG("No P-Asserted-Identity hdr found. Using From hdr"); + LM_DBG("No P-Asserted-Identity hdr found. Using From hdr\n"); if (!cscf_get_from_uri(req, asserted_id_uri)) { - LM_ERR("Error assigning P-Asserted-Identity using From hdr"); + LM_ERR("Error assigning P-Asserted-Identity using From hdr\n"); goto error; } } @@ -739,7 +739,7 @@ static void resume_on_interim_ccr(int is_timeout, void *param, AAAMessage *cca, } if (ro_cca_data->resultcode != 2001) { - LM_ERR("Got bad CCA result code [%d] - reservation failed", ro_cca_data->resultcode); + LM_ERR("Got bad CCA result code [%d] - reservation failed\n", ro_cca_data->resultcode); error_or_timeout = 1; goto error; } else { @@ -1073,7 +1073,7 @@ int Ro_Send_CCR(struct sip_msg *msg, struct dlg_cell *dlg, int dir, int reservat //getting asserted identity if (get_custom_user(msg, &asserted_identity) == -1) { if ((asserted_identity = cscf_get_asserted_identity(msg, 0)).len == 0) { - LM_DBG("No P-Asserted-Identity hdr found. Using From hdr for asserted_identity"); + LM_DBG("No P-Asserted-Identity hdr found. Using From hdr for asserted_identity\n"); asserted_identity = dlg->from_uri; if (asserted_identity.len > 0 && asserted_identity.s) { p=(char*)memchr(asserted_identity.s, ';',asserted_identity.len); @@ -1085,7 +1085,7 @@ int Ro_Send_CCR(struct sip_msg *msg, struct dlg_cell *dlg, int dir, int reservat //getting called asserted identity if ((called_asserted_identity = cscf_get_public_identity_from_called_party_id(msg, &h)).len == 0) { - LM_DBG("No P-Called-Identity hdr found. Using request URI for called_asserted_identity"); + LM_DBG("No P-Called-Identity hdr found. Using request URI for called_asserted_identity\n"); called_asserted_identity = cscf_get_public_identity_from_requri(msg); free_called_asserted_identity = 1; } @@ -1113,11 +1113,11 @@ int Ro_Send_CCR(struct sip_msg *msg, struct dlg_cell *dlg, int dir, int reservat str mac = {0, 0}; if (get_mac_avp_value(msg, &mac) != 0) - LM_DBG(RO_MAC_AVP_NAME" was not set. Using default."); + LM_DBG(RO_MAC_AVP_NAME" was not set. Using default.\n"); //by default we use voice service id and rate group //then we check SDP - if we find video then we use video service id and rate group - LM_DBG("Setting default SID to %d and RG to %d for voice", + LM_DBG("Setting default SID to %d and RG to %d for voice\n", voice_service_identifier, voice_rating_group); active_service_identifier = voice_service_identifier; active_rating_group = voice_rating_group; @@ -1141,7 +1141,7 @@ int Ro_Send_CCR(struct sip_msg *msg, struct dlg_cell *dlg, int dir, int reservat int intportA = atoi(msg_sdp_stream->port.s); if (intportA != 0 && strncasecmp(msg_sdp_stream->media.s, "video", 5) == 0) { - LM_DBG("This SDP has a video component and src ports not equal to 0 - so we set default SID to %d and RG to %d for video", + LM_DBG("This SDP has a video component and src ports not equal to 0 - so we set default SID to %d and RG to %d for video\n", video_service_identifier, video_rating_group); active_service_identifier = video_service_identifier; active_rating_group = video_rating_group; @@ -1342,7 +1342,7 @@ static void resume_on_initial_ccr(int is_timeout, void *param, AAAMessage *cca, if (fui_action == AVP_Final_Unit_Action_Redirect) { if (ro_cca_data->mscc->final_unit_action->redirect_server) { - LM_DBG("FUI with action: [%d]", ro_cca_data->mscc->final_unit_action->action); + LM_DBG("FUI with action: [%d]\n", ro_cca_data->mscc->final_unit_action->action); if (ro_cca_data->mscc->final_unit_action->action == AVP_Final_Unit_Action_Redirect) { LM_DBG("Have REDIRECT action with address type of [%d]\n", ro_cca_data->mscc->final_unit_action->redirect_server->address_type); @@ -1376,7 +1376,7 @@ static void resume_on_initial_ccr(int is_timeout, void *param, AAAMessage *cca, ro_cca_data->mscc->validity_time); if (ro_cca_data->mscc->granted_service_unit->cc_time <= 0) { - LM_DBG("got zero GSU.... reservation failed"); + LM_DBG("got zero GSU.... reservation failed\n"); error_code = RO_RETURN_FALSE; goto error1; } @@ -1482,7 +1482,7 @@ static int create_cca_return_code(int result) { if (result >= 0) break; - LM_ERR("Unknown result code: %d", result); + LM_ERR("Unknown result code: %d\n", result); avp_val.s.s = "??"; } diff --git a/src/modules/ims_charging/ro_db_handler.c b/src/modules/ims_charging/ro_db_handler.c index b9aa70474..59fed5478 100644 --- a/src/modules/ims_charging/ro_db_handler.c +++ b/src/modules/ims_charging/ro_db_handler.c @@ -125,7 +125,7 @@ dberror: } int load_ro_info_from_db(int hash_size, int fetch_num_rows) { - LM_WARN("not supported yet"); + LM_WARN("not supported yet\n"); return 0; } diff --git a/src/modules/ims_charging/ro_session_hash.c b/src/modules/ims_charging/ro_session_hash.c index e6ad04ac3..0d5740d94 100644 --- a/src/modules/ims_charging/ro_session_hash.c +++ b/src/modules/ims_charging/ro_session_hash.c @@ -22,7 +22,7 @@ struct ro_session_table *ro_session_table = 0; void link_ro_session(struct ro_session *ro_session, int n) { struct ro_session_entry *ro_session_entry; - LM_DBG("Linking Ro session [%.*s] into entries hash index [%d]", ro_session->ro_session_id.len, ro_session->ro_session_id.s, ro_session->h_entry); + LM_DBG("Linking Ro session [%.*s] into entries hash index [%d]\n", ro_session->ro_session_id.len, ro_session->ro_session_id.s, ro_session->h_entry); ro_session_entry = &(ro_session_table->entries[ro_session->h_entry]); @@ -197,7 +197,7 @@ void destroy_dlg_table(void) { struct ro_session* build_new_ro_session(int direction, int auth_appid, int auth_session_type, str *session_id, str *callid, str *asserted_identity, str* called_asserted_identity, str* mac, unsigned int dlg_h_entry, unsigned int dlg_h_id, unsigned int requested_secs, unsigned int validity_timeout, int active_rating_group, int active_service_identifier, str *incoming_trunk_id, str *outgoing_trunk_id, str *pani){ - LM_DBG("Building Ro Session **********"); + LM_DBG("Building Ro Session **********\n"); char *p; unsigned int len = /*session_id->len + */callid->len + asserted_identity->len + called_asserted_identity->len + mac->len + incoming_trunk_id->len + outgoing_trunk_id->len + pani->len + sizeof (struct ro_session); diff --git a/src/modules/ims_charging/ro_session_hash.h b/src/modules/ims_charging/ro_session_hash.h index 556d11d84..f74496cb2 100644 --- a/src/modules/ims_charging/ro_session_hash.h +++ b/src/modules/ims_charging/ro_session_hash.h @@ -109,7 +109,7 @@ extern struct ro_session_table *ro_session_table; * \param _entry locked entry */ #define ro_session_lock(_table, _entry) \ - { LM_DBG("LOCKING %d", (_entry)->lock_idx); lock_set_get( (_table)->locks, (_entry)->lock_idx); LM_DBG("LOCKED %d", (_entry)->lock_idx);} + { LM_DBG("LOCKING %d\n", (_entry)->lock_idx); lock_set_get( (_table)->locks, (_entry)->lock_idx); LM_DBG("LOCKED %d\n", (_entry)->lock_idx);} /*! @@ -118,7 +118,7 @@ extern struct ro_session_table *ro_session_table; * \param _entry locked entry */ #define ro_session_unlock(_table, _entry) \ - { LM_DBG("UNLOCKING %d", (_entry)->lock_idx); lock_set_release( (_table)->locks, (_entry)->lock_idx); LM_DBG("UNLOCKED %d", (_entry)->lock_idx); } + { LM_DBG("UNLOCKING %d\n", (_entry)->lock_idx); lock_set_release( (_table)->locks, (_entry)->lock_idx); LM_DBG("UNLOCKED %d\n", (_entry)->lock_idx); } /*! * \brief Reference an ro_session without locking diff --git a/src/modules/ims_charging/ro_timer.c b/src/modules/ims_charging/ro_timer.c index 38af8cbdc..80e498422 100644 --- a/src/modules/ims_charging/ro_timer.c +++ b/src/modules/ims_charging/ro_timer.c @@ -98,12 +98,12 @@ static inline void insert_ro_timer_unsafe(struct ro_tl *tl) { } LM_DBG("inserting %p for %d\n", tl, tl->timeout); - LM_DBG("BEFORE ptr [%p], ptr->next [%p], ptr->next->prev [%p]", ptr, ptr->next, ptr->next->prev); + LM_DBG("BEFORE ptr [%p], ptr->next [%p], ptr->next->prev [%p]\n", ptr, ptr->next, ptr->next->prev); tl->prev = ptr; tl->next = ptr->next; tl->prev->next = tl; tl->next->prev = tl; - LM_DBG("AFTER tl->prev [%p], tl->next [%p]", tl->prev, tl->next); + LM_DBG("AFTER tl->prev [%p], tl->next [%p]\n", tl->prev, tl->next); } /*! @@ -126,7 +126,7 @@ int insert_ro_timer(struct ro_tl *tl, int interval) { insert_ro_timer_unsafe(tl); - LM_DBG("TIMER inserted"); + LM_DBG("TIMER inserted\n"); lock_release(roi_timer->lock); return 0; @@ -249,7 +249,7 @@ static inline struct ro_tl* get_expired_ro_sessions(unsigned int time) { void ro_timer_routine(unsigned int ticks, void * attr) { struct ro_tl *tl, *ctl; - LM_DBG("getting expired ro-sessions"); + LM_DBG("getting expired ro-sessions\n"); tl = get_expired_ro_sessions(ticks); @@ -275,7 +275,7 @@ void resume_ro_session_ontimeout(struct interim_ccr *i_req, int timeout_or_error ro_session_entry = &(ro_session_table->entries[i_req->ro_session->h_entry]); ro_session_lock(ro_session_table, ro_session_entry); - LM_DBG("credit=%d credit_valid_for=%d", i_req->new_credit, i_req->credit_valid_for); + LM_DBG("credit=%d credit_valid_for=%d\n", i_req->new_credit, i_req->credit_valid_for); used_secs = rint((now - ((timeout_or_error==1 && i_req->ro_session->last_event_timestamp_backup>0)?i_req->ro_session->last_event_timestamp_backup : i_req->ro_session->last_event_timestamp)) / (float) 1000000); @@ -353,7 +353,7 @@ void resume_ro_session_ontimeout(struct interim_ccr *i_req, int timeout_or_error dlgb.lookup_terminate_dlg(i_req->ro_session->dlg_h_entry, i_req->ro_session->dlg_h_id, NULL); call_terminated = 1; } else { - LM_DBG("No more credit for user - letting call run out of money in [%i] seconds", whatsleft); + LM_DBG("No more credit for user - letting call run out of money in [%i] seconds\n", whatsleft); int ret = insert_ro_timer(&i_req->ro_session->ro_tl, whatsleft); if (ret != 0) { LM_CRIT("unable to insert timer for Ro Session [%.*s]\n", @@ -373,7 +373,7 @@ void resume_ro_session_ontimeout(struct interim_ccr *i_req, int timeout_or_error } shm_free(i_req); - LM_DBG("Exiting async ccr interim nicely"); + LM_DBG("Exiting async ccr interim nicely\n"); } /* this is the function called when a we need to request more funds/credit. We need to try and reserve more credit. @@ -392,14 +392,14 @@ void ro_session_ontimeout(struct ro_tl *tl) { LM_DBG("offset for ro_tl is [%lu] and ro_session id is [%.*s]\n", (unsigned long) (&((struct ro_session*) 0)->ro_tl), ro_session->ro_session_id.len, ro_session->ro_session_id.s); if (!ro_session) { - LM_ERR("Can't find a session. This is bad"); + LM_ERR("Can't find a session. This is bad\n"); return; } - LM_DBG("event-type=%d", ro_session->event_type); + LM_DBG("event-type=%d\n", ro_session->event_type); // if (!ro_session->active) { - // LM_ALERT("Looks like this session was terminated while requesting more units"); + // LM_ALERT("Looks like this session was terminated while requesting more units\n"); // goto exit; // return; // } @@ -438,7 +438,7 @@ void ro_session_ontimeout(struct ro_tl *tl) { ro_session->asserted_identity.len, ro_session->asserted_identity.s); - LM_DBG("Call session has been active for %i seconds. The last reserved secs was [%i] and the last event was [%i seconds] ago", + LM_DBG("Call session has been active for %i seconds. The last reserved secs was [%i] and the last event was [%i seconds] ago\n", (unsigned int) call_time, (unsigned int) ro_session->reserved_secs, (unsigned int) used_secs); diff --git a/src/modules/ims_dialog/README b/src/modules/ims_dialog/README index 4560f2569..ee1f86035 100644 --- a/src/modules/ims_dialog/README +++ b/src/modules/ims_dialog/README @@ -20,16 +20,10 @@ Edited by Bogdan-Andrei Iancu -Edited by - Carsten Bock -Edited by - Jason Penton -Edited by - Richard Good Copyright © 2006 Voice Sistem SRL @@ -1053,46 +1047,46 @@ Chapter 3. Frequently Asked Questions 3.1. - What happened with “use_tight_match” parameter? + What happened with “use_tight_match” parameter? - The parameter was removed with version 1.3 as the option of tight - matching became mandatory and not configurable. Now, the tight matching - is done all the time (when using DID matching). + The parameter was removed with version 1.3 as the option of tight + matching became mandatory and not configurable. Now, the tight matching + is done all the time (when using DID matching). 3.2. - Why is there a ims_dialog module and a dialog module? + Why is there a ims_dialog module and a dialog module? - The ims_dialog module addresses shortcomings in the initial dialog - module design. It makes some large changes to the API and therefore - must be introduced slowly. It is currently in the early development - stages. Eventually the ims_dialog module should replace the dialog - module. + The ims_dialog module addresses shortcomings in the initial dialog + module design. It makes some large changes to the API and therefore + must be introduced slowly. It is currently in the early development + stages. Eventually the ims_dialog module should replace the dialog + module. 3.3. - Where can I find more about Kamailio? + Where can I find more about Kamailio? - Take a look at https://www.kamailio.org/. + Take a look at https://www.kamailio.org/. 3.4. - Where can I post a question about this module? + Where can I post a question about this module? - First at all check if your question was already answered on one of our - mailing lists: - * User Mailing List - - https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users - * Developer Mailing List - - https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-dev + First at all check if your question was already answered on one of our + mailing lists: + * User Mailing List - + https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users + * Developer Mailing List - + https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-dev - E-mails regarding any stable Kamailio release should be sent to - and e-mails regarding development - versions should be sent to . + E-mails regarding any stable Kamailio release should be sent to + and e-mails regarding development + versions should be sent to . 3.5. - How can I report a bug? + How can I report a bug? - Please follow the guidelines provided at: - https://github.com/kamailio/kamailio/issues. + Please follow the guidelines provided at: + https://github.com/kamailio/kamailio/issues. diff --git a/src/modules/ims_icscf/Makefile b/src/modules/ims_icscf/Makefile index c1f08e2fa..ffc05f295 100644 --- a/src/modules/ims_icscf/Makefile +++ b/src/modules/ims_icscf/Makefile @@ -9,6 +9,12 @@ NAME=ims_icscf.so ifeq ($(CROSS_COMPILE),) XML2CFG=$(shell which xml2-config) +ifeq ($(XML2CFG),) +XML2CFG=$(shell \ + if pkg-config --exists libxml-2.0; then \ + echo 'pkg-config libxml-2.0'; \ + fi) +endif endif ifneq ($(XML2CFG),) diff --git a/src/modules/ims_isc/Makefile b/src/modules/ims_isc/Makefile index 9e8d0576d..d0244d001 100644 --- a/src/modules/ims_isc/Makefile +++ b/src/modules/ims_isc/Makefile @@ -9,6 +9,12 @@ NAME=ims_isc.so ifeq ($(CROSS_COMPILE),) XML2CFG=$(shell which xml2-config) +ifeq ($(XML2CFG),) +XML2CFG=$(shell \ + if pkg-config --exists libxml-2.0; then \ + echo 'pkg-config libxml-2.0'; \ + fi) +endif endif ifneq ($(XML2CFG),) diff --git a/src/modules/ims_registrar_pcscf/Makefile b/src/modules/ims_registrar_pcscf/Makefile index 4602c316f..cfa83b2ba 100644 --- a/src/modules/ims_registrar_pcscf/Makefile +++ b/src/modules/ims_registrar_pcscf/Makefile @@ -10,6 +10,12 @@ NAME=ims_registrar_pcscf.so ifeq ($(CROSS_COMPILE),) XML2CFG=$(shell which xml2-config) +ifeq ($(XML2CFG),) +XML2CFG=$(shell \ + if pkg-config --exists libxml-2.0; then \ + echo 'pkg-config libxml-2.0'; \ + fi) +endif endif ifneq ($(XML2CFG),) diff --git a/src/modules/ims_registrar_scscf/Makefile b/src/modules/ims_registrar_scscf/Makefile index 3549664ba..5a44343a8 100644 --- a/src/modules/ims_registrar_scscf/Makefile +++ b/src/modules/ims_registrar_scscf/Makefile @@ -10,6 +10,12 @@ NAME=ims_registrar_scscf.so ifeq ($(CROSS_COMPILE),) XML2CFG=$(shell which xml2-config) +ifeq ($(XML2CFG),) +XML2CFG=$(shell \ + if pkg-config --exists libxml-2.0; then \ + echo 'pkg-config libxml-2.0'; \ + fi) +endif endif ifneq ($(XML2CFG),) diff --git a/src/modules/ims_registrar_scscf/lookup.c b/src/modules/ims_registrar_scscf/lookup.c index 0e7b06cf6..640dbb970 100644 --- a/src/modules/ims_registrar_scscf/lookup.c +++ b/src/modules/ims_registrar_scscf/lookup.c @@ -61,13 +61,12 @@ */ int lookup(struct sip_msg* _m, udomain_t* _d, char* ue_type_c) { impurecord_t* r; - str aor; + str aor, tmp_aor; ucontact_t* ptr = 0; int res; int ret; str path_dst; flag_t old_bflags; - int i = 0; int ue_type; /*0=any, 1=3gpp, 2=sip */ impu_contact_t *impucontact; @@ -91,29 +90,35 @@ int lookup(struct sip_msg* _m, udomain_t* _d, char* ue_type_c) { ue_type=0; } - if (_m->new_uri.s) { - aor.s = pkg_malloc(_m->new_uri.len); - if (aor.s == NULL) { - LM_ERR("memory allocation failure\n"); - return -1; - } - memcpy(aor.s, _m->new_uri.s, _m->new_uri.len); - aor.len = _m->new_uri.len; - } else { - aor.s = pkg_malloc(_m->first_line.u.request.uri.len); - if (aor.s == NULL) { - LM_ERR("memory allocation failure\n"); - return -1; - } - memcpy(aor.s, _m->first_line.u.request.uri.s, _m->first_line.u.request.uri.len); - aor.len = _m->first_line.u.request.uri.len; - } - - for (i = 4; i < aor.len; i++) - if (aor.s[i] == ':' || aor.s[i] == ';' || aor.s[i] == '?') { - aor.len = i; - break; - } + if (parse_sip_msg_uri(_m) < 0) { + LM_ERR("Error while parsing the Request-URI\n"); + return -1; + } + + if (_m->new_uri.s) { + tmp_aor = _m->new_uri; + } else { + tmp_aor = _m->first_line.u.request.uri; + } + + aor.s = pkg_malloc(tmp_aor.len); + if (aor.s == NULL) { + LM_ERR("memory allocation failure\n"); + return -1; + } + + // build aor + // add 'sip:' or 'tel:' + memcpy(aor.s, tmp_aor.s, 4); + aor.len = 4; + // add user part + memcpy(aor.s + aor.len, _m->parsed_uri.user.s, _m->parsed_uri.user.len); + aor.len += _m->parsed_uri.user.len; + // add '@' + aor.s[aor.len++] = '@'; + // add host part + memcpy(aor.s + aor.len, _m->parsed_uri.host.s, _m->parsed_uri.host.len); + aor.len += _m->parsed_uri.host.len; LM_DBG("Looking for <%.*s>\n", aor.len, aor.s); diff --git a/src/modules/ims_registrar_scscf/registrar_notify.c b/src/modules/ims_registrar_scscf/registrar_notify.c index a40aa1d71..988ce155e 100644 --- a/src/modules/ims_registrar_scscf/registrar_notify.c +++ b/src/modules/ims_registrar_scscf/registrar_notify.c @@ -1385,6 +1385,77 @@ int contact_port_ip_match(str *c1, str *c2) { return 0; } +/*! + * \brief Extract ip and port from contact alias if exists + * \param contact contact string 1 + * \param port_ip extracted ip and port + * \return 0 on successfull, 1 failed + */ +static int extract_alias_ip_port(str* contact, str* port_ip) { + char* p, *port_s; + int tmp_len; + + port_ip->s = contact->s; + port_ip->len = contact->len; + + // if NULL -> alias is not present + if (port_ip->len > 6 && (p = _strnistr(port_ip->s, "alias=", port_ip->len)) != NULL) { + // strip all before 'alias=' and 'alias=' itself + // this is the length of 'IP~PORT~PROTO' string + port_ip->len -= (p - port_ip->s + 6); + // this is the IP's starting position + port_ip->s = p + 6; + + LM_DBG("alias->len=%d [%.*s]\n", port_ip->len, port_ip->len, port_ip->s); + + // find the firs '~' separates IP from PORT + // if NULL -> alias contains only IP + if ((p = memchr(port_ip->s, '~', port_ip->len))) { + // this is the temporary length of 'PORT~PROTO' string + tmp_len = port_ip->s + port_ip->len - p - 1; + // set PORT starting position + port_s = p + 1; + + LM_DBG("port~proto->len=%d [%.*s]\n", tmp_len, tmp_len, port_s); + + // find the second '~' separates PORT from PROTO + if ((p = memchr(port_s, '~', tmp_len))) { + // strip '~PROTO' string + tmp_len = (port_ip->len + port_ip->s - p); + + port_ip->len -= (port_ip->len + port_ip->s - p); + + LM_DBG("~proto->len=%d [%.*s]\n", tmp_len, tmp_len, p); + }else{ + LM_DBG("No alias proto in contact[%.*s]\n", contact->len, contact->s); + } + }else{ + LM_DBG("No alias port~proto in contact[%.*s]\n", contact->len, contact->s); + } + }else{ + LM_DBG("No alias in contact [%.*s]\n", contact->len, contact->s); + } + + return 0; +} + +/*! + * \brief Match the aliases of two contacts - compare only ip and port portion, without proto + * \param c1 contact string 1 + * \param c2 contact string 2 + * \return 1 on successfull match, 0 when they not match + */ +static int alias_port_ip_match(str *c1, str *c2) { + str ip_port1, ip_port2; + extract_alias_ip_port(c1, &ip_port1); + extract_alias_ip_port(c2, &ip_port2); + LM_DBG("Matching contact alias ip and port - comparing [%.*s] and [%.*s]\n", ip_port1.len, ip_port1.s, ip_port2.len, ip_port2.s); + if ((ip_port1.len == ip_port2.len) && !memcmp(ip_port1.s, ip_port2.s, ip_port1.len)) { + return 1; + } + return 0; +} + static str subs_terminated = {"terminated", 10}; static str subs_active = {"active;expires=", 15}; @@ -1671,12 +1742,12 @@ static void process_xml_for_contact(str* buf, str* pad, ucontact_t* ptr) { * @returns the str with the XML content * if its a new subscription we do things like subscribe to updates on IMPU, etc */ -str generate_reginfo_full(udomain_t* _t, str* impu_list, int num_impus, str *explit_dereg_contact, int num_explit_dereg_contact, unsigned int reginfo_version) { +str generate_reginfo_full(udomain_t* _t, str* impu_list, int num_impus, str *explit_dereg_contact, str* watcher_contact, int num_explit_dereg_contact, unsigned int reginfo_version) { str x = {0, 0}; str buf, pad; char bufc[MAX_REGINFO_SIZE], padc[MAX_REGINFO_SIZE]; impurecord_t *r; - int i, k, res; + int i, k, res, added_contacts; ucontact_t* ptr; buf.s = bufc; @@ -1760,11 +1831,32 @@ str generate_reginfo_full(udomain_t* _t, str* impu_list, int num_impus, str *exp } impucontact = r->linked_contacts.head; - while (impucontact) { + added_contacts = 0; + while (impucontact) { ptr = impucontact->contact; - process_xml_for_contact(&buf, &pad, ptr); + + // Prevent multiple contacts in Notify message body tags + // 1. Compare contact->contact IP and PORT with subscriber->watcher_contact IP and PORT + // 2. Compare contact->contact alias IP and PORT with subscriber->watcher_contact alias IP and PORT without PROTO + // This is because of IPv6 and IPv4 family + // When we have a case like: UE <--IPv6--> P-CSCF <--IPv4--> S-CSCF + // Then scscf contact->contact alias proto is 2(IPv6) but scscf subscriber->watcher_contact alias proto is 1(IPv4) + if(contact_port_ip_match(&ptr->c, watcher_contact) && alias_port_ip_match(&ptr->c, watcher_contact)){ + process_xml_for_contact(&buf, &pad, ptr); + ++added_contacts; + } impucontact = impucontact->next; - } + } + + // For pcscf or other AS subscriptions add all contacts + if(added_contacts == 0) { + impucontact = r->linked_contacts.head; + while (impucontact) { + ptr = impucontact->contact; + process_xml_for_contact(&buf, &pad, ptr); + impucontact = impucontact->next; + } + } STR_APPEND(buf, registration_e); @@ -1971,7 +2063,7 @@ void send_notification(reg_notification * n) { LM_DBG("Have a notification to send for the following IMPUs using domain [%.*s]\n", domain->name->len, domain->name->s); - content = generate_reginfo_full(domain, n->impus, n->num_impus, n->explit_dereg_contact, n->num_explit_dereg_contact, n->reginfo_s_version); + content = generate_reginfo_full(domain, n->impus, n->num_impus, n->explit_dereg_contact, &n->watcher_contact, n->num_explit_dereg_contact, n->reginfo_s_version); if (content.len > MAX_REGINFO_SIZE) { LM_ERR("content size (%d) exceeds MAX_REGINFO_SIZE (%d)!\n", content.len, MAX_REGINFO_SIZE); diff --git a/src/modules/ims_registrar_scscf/registrar_notify.h b/src/modules/ims_registrar_scscf/registrar_notify.h index 5491c43b5..76ed60807 100644 --- a/src/modules/ims_registrar_scscf/registrar_notify.h +++ b/src/modules/ims_registrar_scscf/registrar_notify.h @@ -135,7 +135,7 @@ int subscribe_reply(struct sip_msg *msg, int code, char *text, int *expires, str int event_reg(udomain_t* _d, impurecord_t* r_passed, int event_type, str *presentity_uri, str *watcher_contact, str *explit_dereg_contact, int num_explit_dereg_contact); -str generate_reginfo_full(udomain_t* _t, str* impu_list, int new_subscription, str *explit_dereg_contact, int num_explit_dereg_contact, unsigned int reginfo_version); +str generate_reginfo_full(udomain_t* _t, str* impu_list, int new_subscription, str *explit_dereg_contact, str* watcher_contact, int num_explit_dereg_contact, unsigned int reginfo_version); str get_reginfo_partial(impurecord_t *r, ucontact_t *c, int event_type, unsigned int reginfo_version); diff --git a/src/modules/ims_usrloc_pcscf/README b/src/modules/ims_usrloc_pcscf/README index c33652c9e..93efefc07 100644 --- a/src/modules/ims_usrloc_pcscf/README +++ b/src/modules/ims_usrloc_pcscf/README @@ -10,8 +10,6 @@ Richard Good Smile Communications -Edited by - Carsten Bock ng-voice GmbH @@ -234,28 +232,28 @@ Chapter 2. Frequently Asked Questions 2.1. - Where can I find more about Kamailio? + Where can I find more about Kamailio? - Take a look at https://www.kamailio.org/. + Take a look at https://www.kamailio.org/. 2.2. - Where can I post a question about this module? + Where can I post a question about this module? - First at all check if your question was already answered on one of our - mailing lists: - * User Mailing List - - https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users - * Developer Mailing List - - https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-dev + First at all check if your question was already answered on one of our + mailing lists: + * User Mailing List - + https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users + * Developer Mailing List - + https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-dev - E-mails regarding any stable Kamailio release should be sent to - and e-mails regarding development - versions should be sent to . + E-mails regarding any stable Kamailio release should be sent to + and e-mails regarding development + versions should be sent to . 2.3. - How can I report a bug? + How can I report a bug? - Please follow the guidelines provided at: - https://github.com/kamailio/kamailio/issues. + Please follow the guidelines provided at: + https://github.com/kamailio/kamailio/issues. diff --git a/src/modules/ims_usrloc_scscf/impurecord.c b/src/modules/ims_usrloc_scscf/impurecord.c index 67744bb5d..d7c7dde7c 100644 --- a/src/modules/ims_usrloc_scscf/impurecord.c +++ b/src/modules/ims_usrloc_scscf/impurecord.c @@ -385,8 +385,8 @@ static inline void process_impurecord(impurecord_t* _r) { s->watcher_contact.len, s->watcher_contact.s, s->presentity_uri.len, s->presentity_uri.s, (unsigned int) (s->expires - time(NULL))); sl = core_hash(&s->call_id, &s->to_tag, sub_dialog_hash_size); - LM_DBG("Hash size: <%i>", sub_dialog_hash_size); - LM_DBG("Searching sub dialog hash info with call_id: <%.*s> and ttag <%.*s> ftag <%.*s> and hash code <%i>", s->call_id.len, s->call_id.s, s->to_tag.len, s->to_tag.s, s->from_tag.len, s->from_tag.s, sl); + LM_DBG("Hash size: <%i>\n", sub_dialog_hash_size); + LM_DBG("Searching sub dialog hash info with call_id: <%.*s> and ttag <%.*s> ftag <%.*s> and hash code <%i>\n", s->call_id.len, s->call_id.s, s->to_tag.len, s->to_tag.s, s->from_tag.len, s->from_tag.s, sl); /* search the record in hash table */ lock_get(&sub_dialog_table[sl].lock); sub_dialog = pres_search_shtable(sub_dialog_table, s->call_id, s->to_tag, s->from_tag, sl); @@ -433,7 +433,7 @@ static inline void process_impurecord(impurecord_t* _r) { mustdeleteimpu = 0; hascontacts = 1; } else { - LM_WARN("Bogus state for contact [%.*s] - state: %d... ignoring", ptr->c.len, ptr->c.s, ptr->state); + LM_WARN("Bogus state for contact [%.*s] - state: %d... ignoring\n", ptr->c.len, ptr->c.s, ptr->state); mustdeleteimpu = 0; hascontacts = 1; } @@ -567,7 +567,7 @@ int insert_scontact(impurecord_t* _r, str* _contact, ucontact_info_t* _ci, ucont // /*DB?*/ if (db_mode == WRITE_THROUGH && db_insert_ucontact(_r, *_c) != 0) { - LM_ERR("error inserting contact into db"); + LM_ERR("error inserting contact into db\n"); return -1; } @@ -931,7 +931,7 @@ int update_impurecord(struct udomain* _d, str* public_identity, impurecord_t* im //make usre we have IMPU or enough data to find it... if (!impu_rec && (!public_identity || !public_identity->len || !public_identity->s)) { - LM_WARN("can't call update_impurecord with no details of IMPU..n"); + LM_WARN("can't call update_impurecord with no details of IMPU..\n"); return -1; } @@ -1040,7 +1040,7 @@ int update_impurecord(struct udomain* _d, str* public_identity, impurecord_t* im ref_subscription_unsafe(subs_ptr); (*_r)->s = subs_ptr; } else { - LM_DBG("new subscription is the same as the old one....not doing anything"); + LM_DBG("new subscription is the same as the old one....not doing anything\n"); //check that the service profile and associated impus are in the subscription, if not, add... /* if (compare_subscription(subs_ptr, *s) != 0) { unref_subscription((*_r)->s); //different subscription which we don't have lock on yet. @@ -1053,7 +1053,7 @@ int update_impurecord(struct udomain* _d, str* public_identity, impurecord_t* im run_ul_callbacks((*_r)->cbs, UL_IMPU_UPDATE, *_r, NULL); if (db_mode == WRITE_THROUGH && db_insert_impurecord(_d, &(*_r)->public_identity, (*_r)->reg_state, (*_r)->barring, &(*_r)->s, &(*_r)->ccf1, &(*_r)->ccf2, &(*_r)->ecf1, &(*_r)->ecf2, _r) != 0) { - LM_ERR("error inserting IMPU [%.*s] into db... continuing", (*_r)->public_identity.len, (*_r)->public_identity.s); + LM_ERR("error inserting IMPU [%.*s] into db... continuing\n", (*_r)->public_identity.len, (*_r)->public_identity.s); } if (subscription_locked) { @@ -1142,7 +1142,7 @@ int link_contact_to_impu(impurecord_t* impu, ucontact_t* contact, int write_to_d impu_contact_ptr = impu->linked_contacts.head; while (impu_contact_ptr) { if (impu_contact_ptr->contact->is_3gpp) { - LM_DBG("Found first 3GPP contact"); + LM_DBG("Found first 3GPP contact\n"); break; } impu_contact_ptr = impu_contact_ptr->next; @@ -1169,7 +1169,7 @@ int link_contact_to_impu(impurecord_t* impu, ucontact_t* contact, int write_to_d //a housekeeper thread do it locked = 1; } else { - LM_ERR("Could not get lock to remove link from of contact from impu...."); + LM_ERR("Could not get lock to remove link from of contact from impu...\n"); //TODO: we either need to wait and retry or we need to get another process to do this for us.... right now we will leak a contact. } if (locked == 1) { @@ -1205,7 +1205,7 @@ int link_contact_to_impu(impurecord_t* impu, ucontact_t* contact, int write_to_d //a housekeeper thread do it locked = 1; } else { - LM_ERR("Could not get lock to remove link from of contact from impu...."); + LM_ERR("Could not get lock to remove link from of contact from impu...\n"); //TODO: we either need to wait and retry or we need to get another process to do this for us.... right now we will leak a contact. } if (locked == 1) { @@ -1253,7 +1253,7 @@ int unlink_contact_from_impu(impurecord_t* impu, ucontact_t* contact, int write_ //a housekeeper thread do it locked = 1; } else { - LM_ERR("Could not get lock to remove link from of contact from impu...."); + LM_ERR("Could not get lock to remove link from of contact from impu...\n"); //TODO: we either need to wait and retry or we need to get another process to do this for us.... right now we will leak a contact. } if (locked == 1) { diff --git a/src/modules/ims_usrloc_scscf/subscribe.c b/src/modules/ims_usrloc_scscf/subscribe.c index d1b0a6dec..546ef4af1 100644 --- a/src/modules/ims_usrloc_scscf/subscribe.c +++ b/src/modules/ims_usrloc_scscf/subscribe.c @@ -288,7 +288,9 @@ int add_subscriber(impurecord_t* urec, if (!s) return -1; - LM_DBG("Adding new subscription to IMPU record list\n"); + LM_DBG("Adding new subscription p-uri[%.*s] w-contact[%.*s] to IMPU record [%.*s] list\n", + s->presentity_uri.len, s->presentity_uri.s, s->watcher_contact.len, s->watcher_contact.s, urec->public_identity.len, urec->public_identity.s); + s->next = 0; s->prev = urec->stail; if (urec->stail) urec->stail->next = s; diff --git a/src/modules/ims_usrloc_scscf/udomain.c b/src/modules/ims_usrloc_scscf/udomain.c index 361d5ba42..0379d27cb 100644 --- a/src/modules/ims_usrloc_scscf/udomain.c +++ b/src/modules/ims_usrloc_scscf/udomain.c @@ -332,7 +332,8 @@ void mem_timer_udomain(udomain_t* _d, int istart, int istep) { } } } else if (contact_ptr->state != CONTACT_DELETED) { - LM_DBG("expiring contact [%.*s].... setting to CONTACT_EXPIRE_PENDING_NOTIFY\n", contact_ptr->aor.len, contact_ptr->aor.s); + LM_DBG("expiring contact [%.*s](%.*s).... setting to CONTACT_EXPIRE_PENDING_NOTIFY\n", + contact_ptr->aor.len, contact_ptr->aor.s, contact_ptr->c.len, contact_ptr->c.s); contact_ptr->state = CONTACT_EXPIRE_PENDING_NOTIFY; ref_contact_unsafe(contact_ptr); expired_contacts[num_expired_contacts] = contact_ptr; @@ -399,11 +400,13 @@ void mem_timer_udomain(udomain_t* _d, int istart, int istep) { slot = expired_contacts[i]->sl; lock_contact_slot_i(slot); if (expired_contacts[i]->state != CONTACT_DELAYED_DELETE) { - LM_DBG("Setting contact state to CONTACT_DELETED for contact [%.*s]\n", expired_contacts[i]->aor.len, expired_contacts[i]->aor.s); + LM_DBG("Setting contact state to CONTACT_DELETED for contact [%.*s](%.*s)\n", + expired_contacts[i]->aor.len, expired_contacts[i]->aor.s, expired_contacts[i]->c.len, expired_contacts[i]->c.s); expired_contacts[i]->state = CONTACT_DELETED; unref_contact_unsafe(expired_contacts[i]); } else { - LM_DBG("deleting contact [%.*s]\n", expired_contacts[i]->aor.len, expired_contacts[i]->aor.s); + LM_DBG("deleting contact [%.*s](%.*s)\n", + expired_contacts[i]->aor.len, expired_contacts[i]->aor.s, expired_contacts[i]->c.len, expired_contacts[i]->c.s); delete_scontact(expired_contacts[i]); } unlock_contact_slot_i(slot); @@ -577,7 +580,7 @@ int insert_impurecord(struct udomain* _d, str* public_identity, str* private_ide /*DB?*/ if (db_mode == WRITE_THROUGH && db_insert_impurecord(_d, public_identity, reg_state, barring, s, ccf1, ccf2, ecf1, ecf2, _r) != 0) { - LM_ERR("error inserting contact into db"); + LM_ERR("error inserting contact into db\n"); goto error; } diff --git a/src/modules/jansson/README b/src/modules/jansson/README index b79a31ba8..a68d7f43f 100644 --- a/src/modules/jansson/README +++ b/src/modules/jansson/README @@ -10,8 +10,6 @@ Matthew Williams -Edited by - Carsten Bock diff --git a/src/modules/kemix/README b/src/modules/kemix/README index 1fa5a94af..4f5272e2c 100644 --- a/src/modules/kemix/README +++ b/src/modules/kemix/README @@ -10,7 +10,7 @@ Daniel-Constantin Mierla - Copyright 2019 asipto.com + Copyright © 2019 asipto.com __________________________________________________________________ Table of Contents diff --git a/src/modules/lost/Makefile b/src/modules/lost/Makefile index aad0522d1..3abcb0e45 100755 --- a/src/modules/lost/Makefile +++ b/src/modules/lost/Makefile @@ -10,6 +10,12 @@ NAME=lost.so ifeq ($(CROSS_COMPILE),) XML2CFG=$(shell which xml2-config) +ifeq ($(XML2CFG),) +XML2CFG=$(shell \ + if pkg-config --exists libxml-2.0; then \ + echo 'pkg-config libxml-2.0'; \ + fi) +endif endif ifneq ($(XML2CFG),) diff --git a/src/modules/mqueue/README b/src/modules/mqueue/README index 9bc250dfd..4ad5b6915 100644 --- a/src/modules/mqueue/README +++ b/src/modules/mqueue/README @@ -10,22 +10,16 @@ Elena-Ramona Modroiu -Edited by - Alex Balashov Evariste Systems -Edited by - Ovidiu Sas VoIP Embedded, Inc. -Edited by - Julien Chavanton diff --git a/src/modules/msrp/README b/src/modules/msrp/README index b55af6955..21335e35d 100644 --- a/src/modules/msrp/README +++ b/src/modules/msrp/README @@ -10,8 +10,6 @@ Daniel-Constantin Mierla -Edited by - Alex Balashov diff --git a/src/modules/mtree/README b/src/modules/mtree/README index 36d3fee75..9e401d79c 100644 --- a/src/modules/mtree/README +++ b/src/modules/mtree/README @@ -14,8 +14,6 @@ Juha Heinanen tutpro.com -Edited by - Juha Heinanen diff --git a/src/modules/ndb_redis/redis_client.c b/src/modules/ndb_redis/redis_client.c index a4531801b..acdc97876 100644 --- a/src/modules/ndb_redis/redis_client.c +++ b/src/modules/ndb_redis/redis_client.c @@ -953,6 +953,14 @@ int redisc_exec(str *srv, str *res, str *cmd, ...) goto error_exec; } } + + LM_DBG("rpl->rplRedis->type:%d\n", rpl->rplRedis->type); + if(rpl->rplRedis->type == REDIS_REPLY_ERROR) { + LM_ERR("Redis error:%.*s\n", + (int)rpl->rplRedis->len, rpl->rplRedis->str); + goto error_exec; + } + if (check_cluster_reply(rpl->rplRedis, &rsrv)) { LM_DBG("rsrv->ctxRedis = %p\n", rsrv->ctxRedis); if(rsrv->ctxRedis==NULL) @@ -987,6 +995,13 @@ int redisc_exec(str *srv, str *res, str *cmd, ...) goto error_exec; } } + + LM_DBG("rpl->rplRedis->type:%d\n", rpl->rplRedis->type); + if(rpl->rplRedis->type == REDIS_REPLY_ERROR) { + LM_ERR("Redis error:%.*s\n", + (int)rpl->rplRedis->len, rpl->rplRedis->str); + goto error_exec; + } } cmd->s[cmd->len] = c; rsrv->disable.consecutive_errors = 0; diff --git a/src/modules/outbound/api.h b/src/modules/outbound/api.h index 6e65e44e1..ae2b3b361 100644 --- a/src/modules/outbound/api.h +++ b/src/modules/outbound/api.h @@ -30,7 +30,7 @@ #include "../../core/str.h" #include "../../core/sr_module.h" -typedef int (*encode_flow_token_t)(str *, struct receive_info); +typedef int (*encode_flow_token_t)(str *, struct receive_info *); typedef int (*decode_flow_token_t)(struct sip_msg *, struct receive_info **, str); typedef int (*use_outbound_t)(struct sip_msg *); diff --git a/src/modules/outbound/outbound_mod.c b/src/modules/outbound/outbound_mod.c index 788376541..82d18a3ec 100644 --- a/src/modules/outbound/outbound_mod.c +++ b/src/modules/outbound/outbound_mod.c @@ -156,7 +156,7 @@ static void destroy(void) static unsigned char unenc_flow_token[UNENC_FLOW_TOKEN_MAX_LENGTH]; static unsigned char hmac_sha1[EVP_MAX_MD_SIZE]; -int encode_flow_token(str *flow_token, struct receive_info rcv) +int encode_flow_token(str *flow_token, struct receive_info *rcv) { int pos = FLOW_TOKEN_START_POS, i; @@ -168,19 +168,19 @@ int encode_flow_token(str *flow_token, struct receive_info rcv) /* Encode protocol information */ unenc_flow_token[pos++] = - (rcv.dst_ip.af == AF_INET6 ? 0x80 : 0x00) | rcv.proto; + (rcv->dst_ip.af == AF_INET6 ? 0x80 : 0x00) | rcv->proto; /* Encode destination address */ - for (i = 0; i < (rcv.dst_ip.af == AF_INET6 ? 16 : 4); i++) - unenc_flow_token[pos++] = rcv.dst_ip.u.addr[i]; - unenc_flow_token[pos++] = (rcv.dst_port >> 8) & 0xff; - unenc_flow_token[pos++] = rcv.dst_port & 0xff; + for (i = 0; i < (rcv->dst_ip.af == AF_INET6 ? 16 : 4); i++) + unenc_flow_token[pos++] = rcv->dst_ip.u.addr[i]; + unenc_flow_token[pos++] = (rcv->dst_port >> 8) & 0xff; + unenc_flow_token[pos++] = rcv->dst_port & 0xff; /* Encode source address */ - for (i = 0; i < (rcv.src_ip.af == AF_INET6 ? 16 : 4); i++) - unenc_flow_token[pos++] = rcv.src_ip.u.addr[i]; - unenc_flow_token[pos++] = (rcv.src_port >> 8) & 0xff; - unenc_flow_token[pos++] = rcv.src_port & 0xff; + for (i = 0; i < (rcv->src_ip.af == AF_INET6 ? 16 : 4); i++) + unenc_flow_token[pos++] = rcv->src_ip.u.addr[i]; + unenc_flow_token[pos++] = (rcv->src_port >> 8) & 0xff; + unenc_flow_token[pos++] = rcv->src_port & 0xff; /* HMAC-SHA1 the calculated flow-token, truncate to 80 bits, and prepend onto the flow-token */ diff --git a/src/modules/path/README b/src/modules/path/README index 4d6e7cba5..6cb156be0 100644 --- a/src/modules/path/README +++ b/src/modules/path/README @@ -8,8 +8,6 @@ Edited by Andreas Granig -Edited by - Richard Fuchs Copyright © 2006 Inode GmbH diff --git a/src/modules/path/path.c b/src/modules/path/path.c index f95d68ab7..1de9ef8b0 100644 --- a/src/modules/path/path.c +++ b/src/modules/path/path.c @@ -78,7 +78,7 @@ static int handleOutbound(sip_msg_t* _m, str *user, path_param_t *param) if (path_obb.use_outbound != NULL && path_obb.use_outbound(_m)) { struct via_body *via; - if (path_obb.encode_flow_token(user, _m->rcv) != 0) { + if (path_obb.encode_flow_token(user, &_m->rcv) != 0) { LM_ERR("encoding outbound flow-token\n"); return -1; } diff --git a/src/modules/pdb/README b/src/modules/pdb/README index 1857dbf2b..95d023bb3 100644 --- a/src/modules/pdb/README +++ b/src/modules/pdb/README @@ -7,8 +7,6 @@ Henning Westerholt 1&1 Internet AG -Edited by - Pawel Kuzak 1&1 Internet AG diff --git a/src/modules/pdb/pdb.c b/src/modules/pdb/pdb.c index b72ecf7f2..5fb1204e5 100644 --- a/src/modules/pdb/pdb.c +++ b/src/modules/pdb/pdb.c @@ -189,6 +189,8 @@ static int pdb_msg_format_send(struct pdb_msg *msg, } +/* two chars to short-int without caring of memory alignment in char buffer */ +#define PDB_BUFTOSHORT(_sv, _b, _n) memcpy(&(_sv), (char*)(_b) + (_n), sizeof(short int)) /*! * \return 1 if query for the number succeded and the avp with the corresponding carrier id was set, @@ -199,7 +201,7 @@ static int pdb_query(struct sip_msg *_msg, struct multiparam_t *_number, struct struct pdb_msg msg; struct timeval tstart, tnow; struct server_item_t *server; - short int carrierid, *_id; + short int carrierid, _id; short int _idv; char buf[sizeof(struct pdb_msg)]; size_t reqlen; @@ -345,8 +347,8 @@ static int pdb_query(struct sip_msg *_msg, struct multiparam_t *_number, struct case PDB_CODE_OK: msg.bdy.payload[sizeof(struct pdb_bdy) - 1] = '\0'; if (strcmp(msg.bdy.payload, number.s) == 0) { - _id = (short int *)&(msg.bdy.payload[reqlen]); /* make gcc happy */ - carrierid=ntohs(*_id); /* convert to host byte order */ + PDB_BUFTOSHORT(_id, msg.bdy.payload, reqlen); /* make gcc happy */ + carrierid=ntohs(_id); /* convert to host byte order */ goto found; } break; @@ -368,8 +370,8 @@ static int pdb_query(struct sip_msg *_msg, struct multiparam_t *_number, struct default: buf[sizeof(struct pdb_msg) - 1] = '\0'; if (strncmp(buf, number.s, number.len) == 0) { - _id = (short int *)&(buf[reqlen]); - carrierid=ntohs(*_id); /* convert to host byte order */ + PDB_BUFTOSHORT(_id, buf, reqlen); /* make gcc happy */ + carrierid=ntohs(_id); /* convert to host byte order */ goto found; } break; diff --git a/src/modules/permissions/README b/src/modules/permissions/README index 8452d58fa..0a95a2c33 100644 --- a/src/modules/permissions/README +++ b/src/modules/permissions/README @@ -6,16 +6,10 @@ Edited by Miklos Tirpak -Edited by - Bogdan-Andrei Iancu -Edited by - Juha Heinanen -Edited by - Emmanuel Schmidbauer Copyright © 2003 Miklos Tirpak diff --git a/src/modules/pipelimit/README b/src/modules/pipelimit/README index 3a1a3cc13..c98dd302a 100644 --- a/src/modules/pipelimit/README +++ b/src/modules/pipelimit/README @@ -8,8 +8,6 @@ Edited by Ovidiu Sas -Edited by - Daniel-Constantin Mierla Copyright © 2013 VoIPEmbedded Inc. diff --git a/src/modules/presence_conference/Makefile b/src/modules/presence_conference/Makefile index 3c85f88a5..6b668b9c4 100644 --- a/src/modules/presence_conference/Makefile +++ b/src/modules/presence_conference/Makefile @@ -7,6 +7,12 @@ NAME=presence_conference.so ifeq ($(CROSS_COMPILE),) XML2CFG=$(shell which xml2-config) +ifeq ($(XML2CFG),) +XML2CFG=$(shell \ + if pkg-config --exists libxml-2.0; then \ + echo 'pkg-config libxml-2.0'; \ + fi) +endif endif ifneq ($(XML2CFG),) diff --git a/src/modules/presence_dialoginfo/README b/src/modules/presence_dialoginfo/README index 70ffe87ae..e21ea7acc 100644 --- a/src/modules/presence_dialoginfo/README +++ b/src/modules/presence_dialoginfo/README @@ -13,8 +13,6 @@ Juha Heinanen -Edited by - Klaus Darilion diff --git a/src/modules/presence_profile/README b/src/modules/presence_profile/README index c5f670e8f..024a87e19 100644 --- a/src/modules/presence_profile/README +++ b/src/modules/presence_profile/README @@ -10,8 +10,6 @@ Mészáros Mihály -Edited by - Alex Balashov diff --git a/src/modules/pua/Makefile b/src/modules/pua/Makefile index bcfebce28..62e84ecc4 100644 --- a/src/modules/pua/Makefile +++ b/src/modules/pua/Makefile @@ -8,6 +8,12 @@ LIBS= ifeq ($(CROSS_COMPILE),) XML2CFG=$(shell which xml2-config) +ifeq ($(XML2CFG),) +XML2CFG=$(shell \ + if pkg-config --exists libxml-2.0; then \ + echo 'pkg-config libxml-2.0'; \ + fi) +endif endif ifneq ($(XML2CFG),) diff --git a/src/modules/pua/hash.h b/src/modules/pua/hash.h index cc73d3e76..454e4bb85 100644 --- a/src/modules/pua/hash.h +++ b/src/modules/pua/hash.h @@ -15,8 +15,8 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ diff --git a/src/modules/pua/pua.h b/src/modules/pua/pua.h index 57cc379eb..908f5b0cb 100644 --- a/src/modules/pua/pua.h +++ b/src/modules/pua/pua.h @@ -15,13 +15,13 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#ifndef PUBLISH_H -#define PUBLISH_H +#ifndef _PUA_H_ +#define _PUA_H_ #include "../../core/str.h" #include "../../lib/srdb1/db.h" diff --git a/src/modules/pua_bla/Makefile b/src/modules/pua_bla/Makefile index 80772eb05..d2fb431cc 100755 --- a/src/modules/pua_bla/Makefile +++ b/src/modules/pua_bla/Makefile @@ -7,6 +7,12 @@ NAME=pua_bla.so ifeq ($(CROSS_COMPILE),) XML2CFG=$(shell which xml2-config) +ifeq ($(XML2CFG),) +XML2CFG=$(shell \ + if pkg-config --exists libxml-2.0; then \ + echo 'pkg-config libxml-2.0'; \ + fi) +endif endif ifneq ($(XML2CFG),) diff --git a/src/modules/pua_dialoginfo/Makefile b/src/modules/pua_dialoginfo/Makefile index 6ab50b2f7..fb984267b 100644 --- a/src/modules/pua_dialoginfo/Makefile +++ b/src/modules/pua_dialoginfo/Makefile @@ -8,6 +8,12 @@ LIBS= ifeq ($(CROSS_COMPILE),) XML2CFG=$(shell which xml2-config) +ifeq ($(XML2CFG),) +XML2CFG=$(shell \ + if pkg-config --exists libxml-2.0; then \ + echo 'pkg-config libxml-2.0'; \ + fi) +endif endif ifneq ($(XML2CFG),) diff --git a/src/modules/pua_reginfo/Makefile b/src/modules/pua_reginfo/Makefile index f2b114c81..de79e2793 100644 --- a/src/modules/pua_reginfo/Makefile +++ b/src/modules/pua_reginfo/Makefile @@ -10,6 +10,12 @@ LIBS= ifeq ($(CROSS_COMPILE),) XML2CFG=$(shell which xml2-config) +ifeq ($(XML2CFG),) +XML2CFG=$(shell \ + if pkg-config --exists libxml-2.0; then \ + echo 'pkg-config libxml-2.0'; \ + fi) +endif endif ifneq ($(XML2CFG),) diff --git a/src/modules/pua_reginfo/usrloc_cb.c b/src/modules/pua_reginfo/usrloc_cb.c index f8a55480b..f12868012 100644 --- a/src/modules/pua_reginfo/usrloc_cb.c +++ b/src/modules/pua_reginfo/usrloc_cb.c @@ -16,8 +16,8 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ @@ -57,7 +57,7 @@ void pua_reginfo_update_self_op(int v) } str* build_reginfo_full(urecord_t * record, str uri, ucontact_t* c, int type) { - xmlDocPtr doc = NULL; + xmlDocPtr doc = NULL; xmlNodePtr root_node = NULL; xmlNodePtr registration_node = NULL; xmlNodePtr contact_node = NULL; @@ -78,11 +78,12 @@ str* build_reginfo_full(urecord_t * record, str uri, ucontact_t* c, int type) { root_node = xmlNewNode(NULL, BAD_CAST "reginfo"); if(root_node==0) { LM_ERR("Unable to create reginfo-XML-Element\n"); + xmlFreeDoc(doc); return NULL; } /* This is our Root-Element: */ - xmlDocSetRootElement(doc, root_node); - + xmlDocSetRootElement(doc, root_node); + xmlNewProp(root_node, BAD_CAST "xmlns", BAD_CAST "urn:ietf:params:xml:ns:reginfo"); /* we set the version to 0 but it should be set to the correct value in the pua module */ @@ -163,7 +164,7 @@ str* build_reginfo_full(urecord_t * record, str uri, ucontact_t* c, int type) { memset(buf, 0, sizeof(buf)); snprintf(buf, sizeof(buf), "%.*s", ptr->received.len, ptr->received.s); xmlNewProp(contact_node, BAD_CAST "received", BAD_CAST buf); - + /* path Attribute */ memset(buf, 0, sizeof(buf)); snprintf(buf, sizeof(buf), "%.*s", ptr->path.len, ptr->path.s); @@ -216,7 +217,7 @@ error: } if(doc) xmlFreeDoc(doc); return NULL; -} +} void reginfo_usrloc_cb(ucontact_t* c, int type, void* param) { str* body= NULL; @@ -240,7 +241,7 @@ void reginfo_usrloc_cb(ucontact_t* c, int type, void* param) { content_type.s = "application/reginfo+xml"; content_type.len = 23; - + /* Debug Output: */ LM_DBG("AOR: %.*s (%.*s)\n", c->aor->len, c->aor->s, c->domain->len, c->domain->s); if(type & UL_CONTACT_INSERT) LM_DBG("type= UL_CONTACT_INSERT\n"); @@ -292,7 +293,7 @@ void reginfo_usrloc_cb(ucontact_t* c, int type, void* param) { } uri.len = snprintf(uri.s, uri.len, "sip:%.*s", record->aor.len, record->aor.s); } - + /* Build the XML-Body: */ body = build_reginfo_full(record, uri, c, type); @@ -315,8 +316,8 @@ void reginfo_usrloc_cb(ucontact_t* c, int type, void* param) { publ.id.len = id_buf_len; publ.content_type = content_type; publ.expires = 3600; - - /* make UPDATE_TYPE, as if this "publish dialog" is not found + + /* make UPDATE_TYPE, as if this "publish dialog" is not found by pua it will fallback to INSERT_TYPE anyway */ publ.flag|= UPDATE_TYPE; publ.source_flag |= REGINFO_PUBLISH; @@ -328,7 +329,7 @@ void reginfo_usrloc_cb(ucontact_t* c, int type, void* param) { if(pua.send_publish(&publ) < 0) { LM_ERR("Error while sending publish\n"); - } + } error: if (uri.s) pkg_free(uri.s); if(body) { @@ -338,4 +339,4 @@ error: if(record) ul.release_urecord(record); return; -} +} diff --git a/src/modules/pua_usrloc/Makefile b/src/modules/pua_usrloc/Makefile index 08c19ebc6..8a1c90720 100644 --- a/src/modules/pua_usrloc/Makefile +++ b/src/modules/pua_usrloc/Makefile @@ -8,6 +8,12 @@ LIBS= ifeq ($(CROSS_COMPILE),) XML2CFG=$(shell which xml2-config) +ifeq ($(XML2CFG),) +XML2CFG=$(shell \ + if pkg-config --exists libxml-2.0; then \ + echo 'pkg-config libxml-2.0'; \ + fi) +endif endif ifneq ($(XML2CFG),) diff --git a/src/modules/pua_xmpp/Makefile b/src/modules/pua_xmpp/Makefile index 5cb2e71b9..598054f3f 100644 --- a/src/modules/pua_xmpp/Makefile +++ b/src/modules/pua_xmpp/Makefile @@ -8,6 +8,12 @@ LIBS= ifeq ($(CROSS_COMPILE),) XML2CFG=$(shell which xml2-config) +ifeq ($(XML2CFG),) +XML2CFG=$(shell \ + if pkg-config --exists libxml-2.0; then \ + echo 'pkg-config libxml-2.0'; \ + fi) +endif endif ifneq ($(XML2CFG),) diff --git a/src/modules/pv/pv.c b/src/modules/pv/pv.c index 310acf53d..d6a11b601 100644 --- a/src/modules/pv/pv.c +++ b/src/modules/pv/pv.c @@ -328,12 +328,6 @@ static pv_export_t mod_pvs[] = { {{"rb", (sizeof("rb")-1)}, /* */ PVT_MSG_BODY, pv_get_msg_body, 0, 0, 0, 0, 0}, - /* {{"rc", (sizeof("rc")-1)}, - PVT_OTHER, pv_get_return_code, 0, - 0, 0, 0, 0}, - {{"retcode", (sizeof("retcode")-1)}, - PVT_OTHER, pv_get_return_code, 0, - 0, 0, 0, 0}, */ {{"rd", (sizeof("rd")-1)}, /* */ PVT_RURI_DOMAIN, pv_get_ruri_attr, pv_set_ruri_host, 0, 0, pv_init_iname, 2}, diff --git a/src/modules/pv/pv_core.c b/src/modules/pv/pv_core.c index 9087fe01b..d4ae29bc9 100644 --- a/src/modules/pv/pv_core.c +++ b/src/modules/pv/pv_core.c @@ -188,9 +188,9 @@ int pv_get_msgtype(struct sip_msg *msg, pv_param_t *param, return -1; if(msg->first_line.type == SIP_REQUEST) - type = 1; + type = SIP_REQUEST; /* 1 */ else if(msg->first_line.type == SIP_REPLY) - type = 2; + type = SIP_REPLY; /* 2 */ return pv_get_uintval(msg, param, res, type); } diff --git a/src/modules/pv/pv_trans.c b/src/modules/pv/pv_trans.c index ea693bffd..dfc842aac 100644 --- a/src/modules/pv/pv_trans.c +++ b/src/modules/pv/pv_trans.c @@ -267,6 +267,7 @@ int tr_eval_string(struct sip_msg *msg, tr_param_t *tp, int subtype, pv_value_t v, w; time_t t; uint32_t sz1, sz2; + struct tm tmv; if(val==NULL || val->flags&PV_VAL_NULL) return -1; @@ -974,8 +975,8 @@ int tr_eval_string(struct sip_msg *msg, tr_param_t *tp, int subtype, memcpy(s, st.s, st.len); s[st.len] = '\0'; t = val->ri; - val->rs.len = strftime(_tr_buffer, TR_BUFFER_SIZE-1, s, - localtime(&t)); + localtime_r(&t, &tmv); + val->rs.len = strftime(_tr_buffer, TR_BUFFER_SIZE-1, s, &tmv); pkg_free(s); val->flags = PV_VAL_STR; val->rs.s = _tr_buffer; diff --git a/src/modules/ratelimit/README b/src/modules/ratelimit/README index 8848155a9..ecd6fce79 100644 --- a/src/modules/ratelimit/README +++ b/src/modules/ratelimit/README @@ -10,12 +10,8 @@ Edited by Ovidiu Sas -Edited by - Bogdan Vasile Harjoc -Edited by - Hendrik Scholz Copyright © 2006 Freenet Cityline GmbH diff --git a/src/modules/regex/regex_mod.c b/src/modules/regex/regex_mod.c index 880e1924f..475c3542e 100644 --- a/src/modules/regex/regex_mod.c +++ b/src/modules/regex/regex_mod.c @@ -275,7 +275,7 @@ static int load_pcres(int action) /* Read the file and extract the patterns */ memset(line, 0, FILE_MAX_LINE); i = -1; - while (fgets(line, FILE_MAX_LINE, f) != NULL) { + while (fgets(line, FILE_MAX_LINE-4, f) != NULL) { /* Ignore comments and lines starting by space, tab, CR, LF */ if(isspace(line[0]) || line[0]=='#') { @@ -306,7 +306,7 @@ static int load_pcres(int action) } /* Check if the patter size is too big (aprox) */ - if (strlen(patterns[i]) + strlen(line) >= group_max_size - 2) { + if (strlen(patterns[i]) + strlen(line) >= group_max_size - 4) { LM_ERR("pattern max file exceeded\n"); fclose(f); goto err; diff --git a/src/modules/registrar/sip_msg.c b/src/modules/registrar/sip_msg.c index 62bc0d9a8..8af14b23a 100644 --- a/src/modules/registrar/sip_msg.c +++ b/src/modules/registrar/sip_msg.c @@ -277,14 +277,17 @@ void calc_contact_expires(struct sip_msg* _m, param_t* _ep, int* _e, int novaria if ( *_e != 0 ) { - if (!novariation) { - *_e = randomize_expires( *_e, range ); - } - if (*_e < cfg_get(registrar, registrar_cfg, min_expires)) { *_e = cfg_get(registrar, registrar_cfg, min_expires); } + if (!novariation) { + *_e = randomize_expires( *_e, range ); + if (*_e < cfg_get(registrar, registrar_cfg, min_expires)) { + *_e = cfg_get(registrar, registrar_cfg, min_expires); + } + } + if (cfg_get(registrar, registrar_cfg, max_expires) && (*_e > cfg_get(registrar, registrar_cfg, max_expires))) { *_e = cfg_get(registrar, registrar_cfg, max_expires); } diff --git a/src/modules/rls/Makefile b/src/modules/rls/Makefile index b62be93d4..7c5b5b410 100644 --- a/src/modules/rls/Makefile +++ b/src/modules/rls/Makefile @@ -10,6 +10,12 @@ NAME=rls.so ifeq ($(CROSS_COMPILE),) XML2CFG=$(shell which xml2-config) +ifeq ($(XML2CFG),) +XML2CFG=$(shell \ + if pkg-config --exists libxml-2.0; then \ + echo 'pkg-config libxml-2.0'; \ + fi) +endif ifeq ($(OS), darwin) ICU_BUILDER = $(shell \ if pkg-config --exists icu-uc; then \ diff --git a/src/modules/rr/record.c b/src/modules/rr/record.c index 402e6d557..ee075b3e3 100644 --- a/src/modules/rr/record.c +++ b/src/modules/rr/record.c @@ -393,7 +393,7 @@ int record_route(struct sip_msg* _m, str *params) } } } else if (use_ob == 1) { - if (rr_obb.encode_flow_token(&user, _m->rcv) != 0) { + if (rr_obb.encode_flow_token(&user, &_m->rcv) != 0) { LM_ERR("encoding outbound flow-token\n"); return -1; } @@ -522,7 +522,7 @@ int record_route_preset(struct sip_msg* _m, str* _data) return -1; } } else if (use_ob == 1) { - if (rr_obb.encode_flow_token(&user, _m->rcv) != 0) { + if (rr_obb.encode_flow_token(&user, &_m->rcv) != 0) { LM_ERR("encoding outbound flow-token\n"); return -1; } @@ -773,7 +773,7 @@ int record_route_advertised_address(struct sip_msg* _m, str* _data) return -1; } } else if (use_ob == 1) { - if (rr_obb.encode_flow_token(&user, _m->rcv) != 0) { + if (rr_obb.encode_flow_token(&user, &_m->rcv) != 0) { LM_ERR("encoding outbound flow-token\n"); return -1; } diff --git a/src/modules/rtpengine/rtpengine.c b/src/modules/rtpengine/rtpengine.c index 8f3c28a67..8b72e5b67 100644 --- a/src/modules/rtpengine/rtpengine.c +++ b/src/modules/rtpengine/rtpengine.c @@ -3603,11 +3603,11 @@ rtpengine_manage(struct sip_msg *msg, const char *flags) method = get_cseq(msg)->method_id; - if (!(method==METHOD_INVITE || method==METHOD_ACK || method==METHOD_CANCEL - || method==METHOD_BYE || method==METHOD_UPDATE)) + if (!(method & (METHOD_INVITE|METHOD_ACK|METHOD_CANCEL|METHOD_BYE + |METHOD_UPDATE|METHOD_PRACK))) return -1; - if (method==METHOD_CANCEL || method==METHOD_BYE) + if (method & (METHOD_CANCEL|METHOD_BYE)) return rtpengine_delete(msg, flags); if (msg->msg_flags & FL_SDP_BODY) @@ -3616,7 +3616,7 @@ rtpengine_manage(struct sip_msg *msg, const char *flags) nosdp = parse_sdp(msg); if (msg->first_line.type == SIP_REQUEST) { - if(method==METHOD_ACK && nosdp==0) + if((method & (METHOD_ACK|METHOD_PRACK)) && nosdp==0) return rtpengine_offer_answer(msg, flags, OP_ANSWER, 0); if(method==METHOD_UPDATE && nosdp==0) return rtpengine_offer_answer(msg, flags, OP_OFFER, 0); @@ -3684,7 +3684,8 @@ rtpengine_answer1_f(struct sip_msg *msg, char *str1, char *str2) { if (msg->first_line.type == SIP_REQUEST) - if (msg->first_line.u.request.method_value != METHOD_ACK) + if (!(msg->first_line.u.request.method_value + & (METHOD_ACK | METHOD_PRACK))) return -1; return rtpengine_rtpp_set_wrap_fparam(msg, rtpengine_answer_wrap, str1, 2, OP_ANSWER); diff --git a/src/modules/sca/sca.c b/src/modules/sca/sca.c index dba9ff0bd..07dac3948 100644 --- a/src/modules/sca/sca.c +++ b/src/modules/sca/sca.c @@ -60,9 +60,9 @@ sca_mod *sca = NULL; /* * EXTERNAL API */ -db_func_t dbf; // db api +db_func_t dbf; // db api struct tm_binds tmb; // tm functions for sending messages -sl_api_t slb; // sl callback, function for getting to-tag +sl_api_t slb; // sl callback, function for getting to-tag /* * PROTOTYPES @@ -71,10 +71,10 @@ static int sca_mod_init(void); static int sca_child_init(int); static void sca_mod_destroy(void); static int sca_set_config(sca_mod *); -static int sca_call_info_update_0_f(sip_msg_t* msg, char*, char*); -static int sca_call_info_update_1_f(sip_msg_t* msg, char*, char*); -static int sca_call_info_update_2_f(sip_msg_t* msg, char*, char*); -static int sca_call_info_update_3_f(sip_msg_t* msg, char*, char*, char *); +static int sca_call_info_update_0_f(sip_msg_t *msg, char *, char *); +static int sca_call_info_update_1_f(sip_msg_t *msg, char *, char *); +static int sca_call_info_update_2_f(sip_msg_t *msg, char *, char *); +static int sca_call_info_update_3_f(sip_msg_t *msg, char *, char *, char *); int fixup_ciu(void **, int); int fixup_free_ciu(void **param, int param_no); @@ -84,16 +84,18 @@ int fixup_free_ciu(void **param, int param_no); static cmd_export_t cmds[] = { {"sca_handle_subscribe", (cmd_function)sca_handle_subscribe, 0, NULL, 0, REQUEST_ROUTE}, - {"sca_call_info_update", (cmd_function)sca_call_info_update_0_f, 0, NULL, 0, - REQUEST_ROUTE | FAILURE_ROUTE | ONREPLY_ROUTE}, + {"sca_call_info_update", (cmd_function)sca_call_info_update_0_f, 0, + NULL, 0, REQUEST_ROUTE | FAILURE_ROUTE | ONREPLY_ROUTE}, {"sca_call_info_update", (cmd_function)sca_call_info_update_1_f, 1, - fixup_ciu, fixup_free_ciu, REQUEST_ROUTE | FAILURE_ROUTE | ONREPLY_ROUTE}, + fixup_ciu, fixup_free_ciu, + REQUEST_ROUTE | FAILURE_ROUTE | ONREPLY_ROUTE}, {"sca_call_info_update", (cmd_function)sca_call_info_update_2_f, 2, - fixup_ciu, fixup_free_ciu, REQUEST_ROUTE | FAILURE_ROUTE | ONREPLY_ROUTE}, + fixup_ciu, fixup_free_ciu, + REQUEST_ROUTE | FAILURE_ROUTE | ONREPLY_ROUTE}, {"sca_call_info_update", (cmd_function)sca_call_info_update_3_f, 3, - fixup_ciu, fixup_free_ciu, REQUEST_ROUTE | FAILURE_ROUTE | ONREPLY_ROUTE}, - { 0, 0, 0, 0, 0, 0 } -}; + fixup_ciu, fixup_free_ciu, + REQUEST_ROUTE | FAILURE_ROUTE | ONREPLY_ROUTE}, + {0, 0, 0, 0, 0, 0}}; /* * EXPORTED RPC INTERFACE @@ -158,6 +160,7 @@ static param_export_t params[] = { /* * MODULE EXPORTS */ +/* clang-format off */ struct module_exports exports= { "sca", /* module name */ DEFAULT_DLFLAGS, /* dlopen flags */ @@ -170,6 +173,7 @@ struct module_exports exports= { sca_child_init, /* per-child init function */ sca_mod_destroy /* module destroy function */ }; +/* clang-format on */ static int sca_bind_sl(sca_mod *scam, sl_api_t *sl_api) { @@ -178,16 +182,17 @@ static int sca_bind_sl(sca_mod *scam, sl_api_t *sl_api) assert(scam != NULL); assert(sl_api != NULL); - if (sl_load_api(sl_api) != 0) { - LM_ERR("Failed to initialize required sl API. Check if the \"sl\" module is loaded.\n"); + if(sl_load_api(sl_api) != 0) { + LM_ERR("Failed to initialize required sl API. Check if the \"sl\" " + "module is loaded.\n"); return (-1); } scam->sl_api = sl_api; sl_cbe.type = SLCB_REPLY_READY; - sl_cbe.cbf = (sl_cbf_f) sca_call_info_sl_reply_cb; + sl_cbe.cbf = (sl_cbf_f)sca_call_info_sl_reply_cb; - if (scam->sl_api->register_cb(&sl_cbe) < 0) { + if(scam->sl_api->register_cb(&sl_cbe) < 0) { LM_ERR("Failed to register sl reply callback\n"); return (-1); } @@ -200,13 +205,14 @@ static int sca_bind_srdb1(sca_mod *scam, db_func_t *db_api) db1_con_t *db_con = NULL; int rc = -1; - if (db_bind_mod(scam->cfg->db_url, db_api) != 0) { - LM_ERR("Failed to initialize required DB API - %.*s\n", STR_FMT(scam->cfg->db_url)); + if(db_bind_mod(scam->cfg->db_url, db_api) != 0) { + LM_ERR("Failed to initialize required DB API - %.*s\n", + STR_FMT(scam->cfg->db_url)); goto done; } scam->db_api = db_api; - if (!DB_CAPABILITY((*db_api), DB_CAP_ALL)) { + if(!DB_CAPABILITY((*db_api), DB_CAP_ALL)) { LM_ERR("Selected database %.*s lacks required capabilities\n", STR_FMT(scam->cfg->db_url)); goto done; @@ -214,14 +220,15 @@ static int sca_bind_srdb1(sca_mod *scam, db_func_t *db_api) // ensure database exists and table schemas are correct db_con = db_api->init(scam->cfg->db_url); - if (db_con == NULL) { + if(db_con == NULL) { LM_ERR("sca_bind_srdb1: failed to connect to DB %.*s\n", STR_FMT(scam->cfg->db_url)); goto done; } - if (db_check_table_version(db_api, db_con, scam->cfg->subs_table, - SCA_DB_SUBSCRIPTIONS_TABLE_VERSION) < 0) { + if(db_check_table_version(db_api, db_con, scam->cfg->subs_table, + SCA_DB_SUBSCRIPTIONS_TABLE_VERSION) + < 0) { str tmp = *scam->cfg->subs_table; DB_TABLE_VERSION_ERROR(tmp); goto done; @@ -230,7 +237,8 @@ static int sca_bind_srdb1(sca_mod *scam, db_func_t *db_api) // DB and tables are OK, close DB handle. reopen in each child. rc = 0; - done: if (db_con != NULL) { +done: + if(db_con != NULL) { db_api->close(db_con); db_con = NULL; } @@ -240,36 +248,36 @@ static int sca_bind_srdb1(sca_mod *scam, db_func_t *db_api) static int sca_set_config(sca_mod *scam) { - scam->cfg = (sca_config *) shm_malloc(sizeof(sca_config)); - if (scam->cfg == NULL) { + scam->cfg = (sca_config *)shm_malloc(sizeof(sca_config)); + if(scam->cfg == NULL) { LM_ERR("Failed to shm_malloc module configuration\n"); return (-1); } memset(scam->cfg, 0, sizeof(sca_config)); - if (outbound_proxy.s) { + if(outbound_proxy.s) { scam->cfg->outbound_proxy = &outbound_proxy; } - if (!db_url.s || db_url.len <= 0) { + if(!db_url.s || db_url.len <= 0) { LM_ERR("sca_set_config: db_url must be set!\n"); return (-1); } scam->cfg->db_url = &db_url; - if (!db_subs_table.s || db_subs_table.len <= 0) { + if(!db_subs_table.s || db_subs_table.len <= 0) { LM_ERR("sca_set_config: subs_table must be set!\n"); return (-1); } scam->cfg->subs_table = &db_subs_table; - if (!db_state_table.s || db_state_table.len <= 0) { + if(!db_state_table.s || db_state_table.len <= 0) { LM_ERR("sca_set_config: state_table must be set!\n"); return (-1); } scam->cfg->state_table = &db_state_table; - if (hash_table_size > 0) { + if(hash_table_size > 0) { scam->cfg->hash_table_size = 1 << hash_table_size; } else { scam->cfg->hash_table_size = 512; @@ -285,7 +293,7 @@ static int sca_set_config(sca_mod *scam) } scam->cfg->onhold_bflag = onhold_bflag; - if (server_address.s) { + if(server_address.s) { scam->cfg->server_address = &server_address; } @@ -294,24 +302,26 @@ static int sca_set_config(sca_mod *scam) static int sca_child_init(int rank) { - if (rank == PROC_INIT || rank == PROC_TCP_MAIN) { + if(rank == PROC_INIT || rank == PROC_TCP_MAIN) { return (0); } - if (rank == PROC_MAIN) { - if (fork_dummy_timer(PROC_TIMER, "SCA DB SYNC PROCESS", 0, // we don't need sockets, just writing to DB - sca_subscription_db_update_timer, // timer cb - NULL, // parameter passed to callback - sca->cfg->db_update_interval) < 0) { + if(rank == PROC_MAIN) { + if(fork_dummy_timer(PROC_TIMER, "SCA DB SYNC PROCESS", + 0, // we don't need sockets, just writing to DB + sca_subscription_db_update_timer, // timer cb + NULL, // parameter passed to callback + sca->cfg->db_update_interval) + < 0) { LM_ERR("sca_child_init: failed to register subscription DB " - "sync timer process\n"); + "sync timer process\n"); return (-1); } return (0); } - if (sca->db_api == NULL || sca->db_api->init == NULL) { + if(sca->db_api == NULL || sca->db_api->init == NULL) { LM_CRIT("sca_child_init: DB API not loaded!\n"); return (-1); } @@ -321,45 +331,47 @@ static int sca_child_init(int rank) static int sca_mod_init(void) { - sca = (sca_mod *) shm_malloc(sizeof(sca_mod)); - if (sca == NULL) { + sca = (sca_mod *)shm_malloc(sizeof(sca_mod)); + if(sca == NULL) { LM_ERR("Failed to shm_malloc module object\n"); return (-1); } memset(sca, 0, sizeof(sca_mod)); - if (sca_set_config(sca) != 0) { + if(sca_set_config(sca) != 0) { LM_ERR("Failed to set configuration\n"); goto error; } - if (rpc_register_array(sca_rpc) != 0) { + if(rpc_register_array(sca_rpc) != 0) { LM_ERR("Failed to register RPC commands\n"); goto error; } - if (sca_bind_srdb1(sca, &dbf) != 0) { + if(sca_bind_srdb1(sca, &dbf) != 0) { LM_ERR("Failed to initialize required DB API\n"); goto error; } - if (load_tm_api(&tmb) != 0) { - LM_ERR("Failed to initialize required tm API. Check that the \"tm\" module is loaded before this module.\n"); + if(load_tm_api(&tmb) != 0) { + LM_ERR("Failed to initialize required tm API. Check that the \"tm\" " + "module is loaded before this module.\n"); goto error; } sca->tm_api = &tmb; - if (sca_bind_sl(sca, &slb) != 0) { - LM_ERR("Failed to initialize required sl API. Check that the \"sl\" module is loaded before this module.\n"); + if(sca_bind_sl(sca, &slb) != 0) { + LM_ERR("Failed to initialize required sl API. Check that the \"sl\" " + "module is loaded before this module.\n"); goto error; } - if (sca_hash_table_create(&sca->subscriptions, sca->cfg->hash_table_size) + if(sca_hash_table_create(&sca->subscriptions, sca->cfg->hash_table_size) != 0) { LM_ERR("Failed to create subscriptions hash table\n"); goto error; } - if (sca_hash_table_create(&sca->appearances, sca->cfg->hash_table_size) + if(sca_hash_table_create(&sca->appearances, sca->cfg->hash_table_size) != 0) { LM_ERR("Failed to create appearances hash table\n"); goto error; @@ -369,8 +381,8 @@ static int sca_mod_init(void) register_timer(sca_subscription_purge_expired, sca, sca->cfg->purge_expired_interval); - register_timer(sca_appearance_purge_stale, sca, - sca->cfg->purge_expired_interval); + register_timer( + sca_appearance_purge_stale, sca, sca->cfg->purge_expired_interval); // register separate timer process to write subscriptions to DB. // move to 3.3+ timer API (register_basic_timer) at some point. @@ -381,14 +393,15 @@ static int sca_mod_init(void) return (0); - error: if (sca != NULL) { - if (sca->cfg != NULL) { +error: + if(sca != NULL) { + if(sca->cfg != NULL) { shm_free(sca->cfg); } - if (sca->subscriptions != NULL) { + if(sca->subscriptions != NULL) { sca_hash_table_free(sca->subscriptions); } - if (sca->appearances != NULL) { + if(sca->appearances != NULL) { sca_hash_table_free(sca->appearances); } shm_free(sca); @@ -400,75 +413,73 @@ static int sca_mod_init(void) void sca_mod_destroy(void) { - if (sca == 0) + if(sca == 0) return; // write back to the DB to retain most current subscription info - if (sca_subscription_db_update() != 0) { - if (sca && sca->cfg && sca->cfg->db_url) { + if(sca_subscription_db_update() != 0) { + if(sca && sca->cfg && sca->cfg->db_url) { LM_ERR("sca_mod_destroy: failed to save current subscriptions \n" - "in DB %.*s", STR_FMT(sca->cfg->db_url)); + "in DB %.*s", + STR_FMT(sca->cfg->db_url)); } } sca_db_disconnect(); } -static int sca_call_info_update_0_f(sip_msg_t* msg, char* p1, char* p2) +static int sca_call_info_update_0_f(sip_msg_t *msg, char *p1, char *p2) { return sca_call_info_update(msg, SCA_CALL_INFO_SHARED_BOTH, NULL, NULL); } -static int sca_call_info_update_1_f(sip_msg_t* msg, char* p1, char* p2) +static int sca_call_info_update_1_f(sip_msg_t *msg, char *p1, char *p2) { int update_mask = SCA_CALL_INFO_SHARED_BOTH; - if (get_int_fparam(&update_mask, msg, (fparam_t *) p1) < 0) { + if(get_int_fparam(&update_mask, msg, (fparam_t *)p1) < 0) { LM_ERR("sca_call_info_update: argument 1: bad value " - "(integer expected)\n"); + "(integer expected)\n"); return (-1); } return sca_call_info_update(msg, update_mask, NULL, NULL); } -static int sca_call_info_update_2_f(sip_msg_t* msg, char* p1, char* p2) +static int sca_call_info_update_2_f(sip_msg_t *msg, char *p1, char *p2) { str uri_to = STR_NULL; int update_mask = SCA_CALL_INFO_SHARED_BOTH; - if (get_int_fparam(&update_mask, msg, (fparam_t *) p1) < 0) { + if(get_int_fparam(&update_mask, msg, (fparam_t *)p1) < 0) { LM_ERR("sca_call_info_update: argument 1: bad value " - "(integer expected)\n"); + "(integer expected)\n"); return (-1); } - if(get_str_fparam(&uri_to, msg, (gparam_p)p2)!=0) - { + if(get_str_fparam(&uri_to, msg, (gparam_p)p2) != 0) { LM_ERR("unable to get value from param pvar_to\n"); return -1; } return sca_call_info_update(msg, update_mask, &uri_to, NULL); } -static int sca_call_info_update_3_f(sip_msg_t* msg, - char* p1, char* p2, char * p3) +static int sca_call_info_update_3_f( + sip_msg_t *msg, char *p1, char *p2, char *p3) { str uri_to = STR_NULL; str uri_from = STR_NULL; int update_mask = SCA_CALL_INFO_SHARED_BOTH; - if (get_int_fparam(&update_mask, msg, (fparam_t *) p1) < 0) { + if(get_int_fparam(&update_mask, msg, (fparam_t *)p1) < 0) { LM_ERR("sca_call_info_update: argument 1: bad value " - "(integer expected)\n"); + "(integer expected)\n"); return (-1); } - if(get_str_fparam(&uri_to, msg, (gparam_p)p2)!=0) - { + if(get_str_fparam(&uri_to, msg, (gparam_p)p2) != 0) { LM_ERR("unable to get value from param pvar_to\n"); return -1; } - if(get_str_fparam(&uri_from, msg, (gparam_p)p3)!=0) - { + if(get_str_fparam(&uri_from, msg, (gparam_p)p3) != 0) { LM_ERR("unable to get value from param pvar_from\n"); return -1; } @@ -490,7 +501,7 @@ int ki_sca_call_info_update_turi(sip_msg_t *msg, int umask, str *sto) int fixup_ciu(void **param, int param_no) { - switch (param_no) { + switch(param_no) { case 1: return fixup_var_int_1(param, param_no); case 2: @@ -503,7 +514,7 @@ int fixup_ciu(void **param, int param_no) int fixup_free_ciu(void **param, int param_no) { - switch (param_no) { + switch(param_no) { case 1: return 0; case 2: diff --git a/src/modules/sca/sca.h b/src/modules/sca/sca.h index 04d3c1ea3..cceae17c0 100644 --- a/src/modules/sca/sca.h +++ b/src/modules/sca/sca.h @@ -27,7 +27,8 @@ #ifndef SCA_H #define SCA_H -struct _sca_config { +struct _sca_config +{ str *outbound_proxy; str *db_url; str *subs_table; @@ -42,7 +43,8 @@ struct _sca_config { }; typedef struct _sca_config sca_config; -struct _sca_mod { +struct _sca_mod +{ sca_config *cfg; sca_hash_table *subscriptions; sca_hash_table *appearances; diff --git a/src/modules/sca/sca_appearance.c b/src/modules/sca/sca_appearance.c index 9d948902a..78ee5d81c 100644 --- a/src/modules/sca/sca_appearance.c +++ b/src/modules/sca/sca_appearance.c @@ -37,7 +37,8 @@ const str SCA_APPEARANCE_STATE_STR_PROGRESSING = STR_STATIC_INIT("progressing"); const str SCA_APPEARANCE_STATE_STR_ALERTING = STR_STATIC_INIT("alerting"); const str SCA_APPEARANCE_STATE_STR_ACTIVE = STR_STATIC_INIT("active"); const str SCA_APPEARANCE_STATE_STR_HELD = STR_STATIC_INIT("held"); -const str SCA_APPEARANCE_STATE_STR_HELD_PRIVATE = STR_STATIC_INIT("held-private"); +const str SCA_APPEARANCE_STATE_STR_HELD_PRIVATE = + STR_STATIC_INIT("held-private"); const str SCA_APPEARANCE_STATE_STR_UNKNOWN = STR_STATIC_INIT("unknown"); // STR_ACTIVE is repeated, once for ACTIVE_PENDING, once for ACTIVE @@ -59,7 +60,7 @@ void sca_appearance_state_to_str(int state, str *state_str) { assert(state_str != NULL); - if (state >= SCA_APPEARANCE_STATE_NAME_COUNT || state < 0) { + if(state >= SCA_APPEARANCE_STATE_NAME_COUNT || state < 0) { state_str->len = SCA_APPEARANCE_STATE_STR_UNKNOWN.len; state_str->s = SCA_APPEARANCE_STATE_STR_UNKNOWN.s; @@ -76,12 +77,12 @@ int sca_appearance_state_from_str(str *state_str) assert(state_str != NULL); - for (state = 0; state < SCA_APPEARANCE_STATE_NAME_COUNT; state++) { - if (SCA_STR_EQ(state_str, state_names[state])) { + for(state = 0; state < SCA_APPEARANCE_STATE_NAME_COUNT; state++) { + if(SCA_STR_EQ(state_str, state_names[state])) { break; } } - if (state >= SCA_APPEARANCE_STATE_NAME_COUNT) { + if(state >= SCA_APPEARANCE_STATE_NAME_COUNT) { state = SCA_APPEARANCE_STATE_UNKNOWN; } @@ -95,16 +96,16 @@ sca_appearance *sca_appearance_create(int appearance_index, str *owner_uri) // we use multiple shm_malloc calls here because uri, owner, // dialog and callee are mutable. could also shm_malloc a big // block and divide it among the strs.... - new_appearance = (sca_appearance *) shm_malloc(sizeof(sca_appearance)); - if (new_appearance == NULL) { + new_appearance = (sca_appearance *)shm_malloc(sizeof(sca_appearance)); + if(new_appearance == NULL) { LM_ERR("Failed to shm_malloc new sca_appearance for %.*s, index %d\n", STR_FMT(owner_uri), appearance_index); goto error; } memset(new_appearance, 0, sizeof(sca_appearance)); - new_appearance->owner.s = (char *) shm_malloc(owner_uri->len); - if (new_appearance->owner.s == NULL) { + new_appearance->owner.s = (char *)shm_malloc(owner_uri->len); + if(new_appearance->owner.s == NULL) { LM_ERR("Failed to shm_malloc space for owner %.*s, index %d\n", STR_FMT(owner_uri), appearance_index); goto error; @@ -113,14 +114,15 @@ sca_appearance *sca_appearance_create(int appearance_index, str *owner_uri) new_appearance->index = appearance_index; new_appearance->times.ctime = time(NULL); - sca_appearance_update_state_unsafe(new_appearance, - SCA_APPEARANCE_STATE_IDLE); + sca_appearance_update_state_unsafe( + new_appearance, SCA_APPEARANCE_STATE_IDLE); new_appearance->next = NULL; return (new_appearance); - error: if (new_appearance != NULL) { - if (!SCA_STR_EMPTY(&new_appearance->owner)) { +error: + if(new_appearance != NULL) { + if(!SCA_STR_EMPTY(&new_appearance->owner)) { shm_free(new_appearance->owner.s); } shm_free(new_appearance); @@ -130,24 +132,24 @@ sca_appearance *sca_appearance_create(int appearance_index, str *owner_uri) void sca_appearance_free(sca_appearance *appearance) { - if (appearance != NULL) { - if (appearance->owner.s != NULL) { + if(appearance != NULL) { + if(appearance->owner.s != NULL) { shm_free(appearance->owner.s); } - if (appearance->uri.s != NULL) { + if(appearance->uri.s != NULL) { shm_free(appearance->uri.s); } - if (appearance->dialog.id.s != NULL) { + if(appearance->dialog.id.s != NULL) { shm_free(appearance->dialog.id.s); } - if (appearance->prev_owner.s != NULL) { + if(appearance->prev_owner.s != NULL) { shm_free(appearance->prev_owner.s); } - if (appearance->prev_callee.s != NULL) { + if(appearance->prev_callee.s != NULL) { shm_free(appearance->prev_callee.s); } - if (appearance->prev_dialog.id.s != NULL) { + if(appearance->prev_dialog.id.s != NULL) { shm_free(appearance->prev_dialog.id.s); } shm_free(appearance); @@ -170,9 +172,9 @@ static int sca_appearance_list_next_available_index_unsafe( assert(app_list != NULL); - for (app_cur = app_list->appearances; app_cur != NULL; + for(app_cur = app_list->appearances; app_cur != NULL; app_cur = app_cur->next, idx++) { - if (idx < app_cur->index) { + if(idx < app_cur->index) { break; } } @@ -186,15 +188,15 @@ static sca_appearance_list *sca_appearance_list_create(sca_mod *scam, str *aor) int len; len = sizeof(sca_appearance_list) + aor->len; - app_list = (sca_appearance_list *) shm_malloc(len); - if (app_list == NULL) { + app_list = (sca_appearance_list *)shm_malloc(len); + if(app_list == NULL) { LM_ERR("Failed to shm_malloc sca_appearance_list for %.*s\n", STR_FMT(aor)); return (NULL); } memset(app_list, 0, sizeof(sca_appearance_list)); len = sizeof(sca_appearance_list); - app_list->aor.s = (char *) app_list + len; + app_list->aor.s = (char *)app_list + len; SCA_STR_COPY(&app_list->aor, aor); return (app_list); @@ -206,8 +208,8 @@ sca_appearance_list *sca_appearance_list_for_line(sca_mod *scam, str *aor) return (NULL); } -void sca_appearance_list_insert_appearance(sca_appearance_list *app_list, - sca_appearance *app) +void sca_appearance_list_insert_appearance( + sca_appearance_list *app_list, sca_appearance *app) { sca_appearance **cur; @@ -216,8 +218,8 @@ void sca_appearance_list_insert_appearance(sca_appearance_list *app_list, app->appearance_list = app_list; - for (cur = &app_list->appearances; *cur != NULL; cur = &(*cur)->next) { - if (app->index < (*cur)->index) { + for(cur = &app_list->appearances; *cur != NULL; cur = &(*cur)->next) { + if(app->index < (*cur)->index) { break; } } @@ -225,8 +227,8 @@ void sca_appearance_list_insert_appearance(sca_appearance_list *app_list, *cur = app; } -sca_appearance *sca_appearance_list_unlink_index(sca_appearance_list *app_list, - int idx) +sca_appearance *sca_appearance_list_unlink_index( + sca_appearance_list *app_list, int idx) { sca_appearance *app = NULL; sca_appearance **cur; @@ -234,8 +236,8 @@ sca_appearance *sca_appearance_list_unlink_index(sca_appearance_list *app_list, assert(app_list != NULL); assert(idx > 0); - for (cur = &app_list->appearances; *cur != NULL; cur = &(*cur)->next) { - if ((*cur)->index == idx) { + for(cur = &app_list->appearances; *cur != NULL; cur = &(*cur)->next) { + if((*cur)->index == idx) { app = *cur; app->appearance_list = NULL; *cur = (*cur)->next; @@ -243,15 +245,15 @@ sca_appearance *sca_appearance_list_unlink_index(sca_appearance_list *app_list, } } - if (app == NULL) { + if(app == NULL) { LM_ERR("Tried to remove inactive %.*s appearance at index %d\n", STR_FMT(&app_list->aor), idx); } return (app); } -int sca_appearance_list_unlink_appearance(sca_appearance_list *app_list, - sca_appearance **app) +int sca_appearance_list_unlink_appearance( + sca_appearance_list *app_list, sca_appearance **app) { sca_appearance **cur; int rc = 0; @@ -259,8 +261,8 @@ int sca_appearance_list_unlink_appearance(sca_appearance_list *app_list, assert(app_list != NULL); assert(app != NULL && *app != NULL); - for (cur = &app_list->appearances; *cur != NULL; cur = &(*cur)->next) { - if (*cur == *app) { + for(cur = &app_list->appearances; *cur != NULL; cur = &(*cur)->next) { + if(*cur == *app) { *cur = (*cur)->next; (*app)->appearance_list = NULL; (*app)->next = NULL; @@ -272,44 +274,45 @@ int sca_appearance_list_unlink_appearance(sca_appearance_list *app_list, return (rc); } -int sca_appearance_list_aor_cmp(str *aor, void *cmp_value) { - sca_appearance_list *app_list = (sca_appearance_list *) cmp_value; +int sca_appearance_list_aor_cmp(str *aor, void *cmp_value) +{ + sca_appearance_list *app_list = (sca_appearance_list *)cmp_value; int cmp; - if ((cmp = aor->len - app_list->aor.len) != 0) { + if((cmp = aor->len - app_list->aor.len) != 0) { return (cmp); } return (memcmp(aor->s, app_list->aor.s, aor->len)); } -void sca_appearance_list_print(void *value) { - sca_appearance_list *app_list = (sca_appearance_list *) value; +void sca_appearance_list_print(void *value) +{ + sca_appearance_list *app_list = (sca_appearance_list *)value; sca_appearance *app; str state_str = STR_NULL; LM_INFO("Appearance state for AoR %.*s:\n", STR_FMT(&app_list->aor)); - for (app = app_list->appearances; app != NULL; app = app->next) { + for(app = app_list->appearances; app != NULL; app = app->next) { sca_appearance_state_to_str(app->state, &state_str); LM_INFO("index: %d, state: %.*s, uri: %.*s, owner: %.*s, " "callee: %.*s, dialog: %.*s;%.*s;%.*s\n", - app->index, STR_FMT(&state_str), - STR_FMT(&app->uri), STR_FMT(&app->owner), - STR_FMT(&app->callee), STR_FMT(&app->dialog.call_id), - STR_FMT(&app->dialog.from_tag), + app->index, STR_FMT(&state_str), STR_FMT(&app->uri), + STR_FMT(&app->owner), STR_FMT(&app->callee), + STR_FMT(&app->dialog.call_id), STR_FMT(&app->dialog.from_tag), STR_FMT(&app->dialog.to_tag)); } } void sca_appearance_list_free(void *value) { - sca_appearance_list *app_list = (sca_appearance_list *) value; + sca_appearance_list *app_list = (sca_appearance_list *)value; sca_appearance *app, *app_tmp; LM_DBG("Freeing appearance list for AoR %.*s\n", STR_FMT(&app_list->aor)); - for (app = app_list->appearances; app != NULL; app = app_tmp) { + for(app = app_list->appearances; app != NULL; app = app_tmp) { app_tmp = app->next; shm_free(app); } @@ -324,28 +327,31 @@ int sca_appearance_register(sca_mod *scam, str *aor) assert(scam != NULL); assert(aor != NULL); - if (sca_uri_is_shared_appearance(scam, aor)) { + if(sca_uri_is_shared_appearance(scam, aor)) { // we've already registered rc = 0; goto done; } app_list = sca_appearance_list_create(scam, aor); - if (app_list == NULL) { + if(app_list == NULL) { goto done; } - if (sca_hash_table_kv_insert(scam->appearances, aor, app_list, - sca_appearance_list_aor_cmp, sca_appearance_list_print, - sca_appearance_list_free) < 0) { + if(sca_hash_table_kv_insert(scam->appearances, aor, app_list, + sca_appearance_list_aor_cmp, sca_appearance_list_print, + sca_appearance_list_free) + < 0) { LM_ERR("sca_appearance_register: failed to insert appearance list " - "for %.*s\n", STR_FMT(aor)); + "for %.*s\n", + STR_FMT(aor)); goto done; } rc = 1; - done: return (rc); +done: + return (rc); } int sca_appearance_unregister(sca_mod *scam, str *aor) @@ -355,8 +361,8 @@ int sca_appearance_unregister(sca_mod *scam, str *aor) assert(scam != NULL); assert(aor != NULL); - if (sca_uri_is_shared_appearance(scam, aor)) { - if ((rc = sca_hash_table_kv_delete(scam->appearances, aor)) == 0) { + if(sca_uri_is_shared_appearance(scam, aor)) { + if((rc = sca_hash_table_kv_delete(scam->appearances, aor)) == 0) { rc = 1; LM_INFO("unregistered SCA AoR %.*s\n", STR_FMT(aor)); } @@ -376,22 +382,23 @@ sca_appearance *sca_appearance_seize_index_unsafe(sca_mod *scam, str *aor, slot = sca_hash_table_slot_for_index(scam->appearances, slot_idx); app_list = sca_hash_table_slot_kv_find_unsafe(slot, aor); - if (app_list == NULL) { + if(app_list == NULL) { LM_ERR("sca_appearance_seize_index_unsafe: no appearance list for " - "%.*s\n", STR_FMT(aor)); + "%.*s\n", + STR_FMT(aor)); goto done; } - if (app_idx <= 0) { + if(app_idx <= 0) { app_idx = sca_appearance_list_next_available_index_unsafe(app_list); } - for (app = app_list->appearances; app != NULL; app = app->next) { - if (app->index >= app_idx) { + for(app = app_list->appearances; app != NULL; app = app->next) { + if(app->index >= app_idx) { break; } } - if (app != NULL && app->index == app_idx) { + if(app != NULL && app->index == app_idx) { // attempt to seize in-use appearance-index error = SCA_APPEARANCE_ERR_INDEX_UNAVAILABLE; app = NULL; @@ -399,7 +406,7 @@ sca_appearance *sca_appearance_seize_index_unsafe(sca_mod *scam, str *aor, } app = sca_appearance_create(app_idx, owner_uri); - if (app == NULL) { + if(app == NULL) { LM_ERR("Failed to create new appearance for %.*s at index %d\n", STR_FMT(owner_uri), app_idx); error = SCA_APPEARANCE_ERR_MALLOC; @@ -409,14 +416,16 @@ sca_appearance *sca_appearance_seize_index_unsafe(sca_mod *scam, str *aor, sca_appearance_list_insert_appearance(app_list, app); error = SCA_APPEARANCE_OK; - done: if (seize_error) { +done: + if(seize_error) { *seize_error = error; } return (app); } -int sca_appearance_seize_index(sca_mod *scam, str *aor, int idx, str *owner_uri) { +int sca_appearance_seize_index(sca_mod *scam, str *aor, int idx, str *owner_uri) +{ sca_appearance *app; int slot_idx; int app_idx = -1; @@ -425,23 +434,23 @@ int sca_appearance_seize_index(sca_mod *scam, str *aor, int idx, str *owner_uri) slot_idx = sca_hash_table_index_for_key(scam->appearances, aor); sca_hash_table_lock_index(scam->appearances, slot_idx); - app = sca_appearance_seize_index_unsafe(scam, aor, owner_uri, idx, slot_idx, - &error); - if (app != NULL) { + app = sca_appearance_seize_index_unsafe( + scam, aor, owner_uri, idx, slot_idx, &error); + if(app != NULL) { app_idx = app->index; } sca_hash_table_unlock_index(scam->appearances, slot_idx); - if (error == SCA_APPEARANCE_ERR_INDEX_UNAVAILABLE) { + if(error == SCA_APPEARANCE_ERR_INDEX_UNAVAILABLE) { app_idx = SCA_APPEARANCE_INDEX_UNAVAILABLE; } return (app_idx); } -sca_appearance *sca_appearance_seize_next_available_unsafe(sca_mod *scam, - str *aor, str *owner_uri, int slot_idx) +sca_appearance *sca_appearance_seize_next_available_unsafe( + sca_mod *scam, str *aor, str *owner_uri, int slot_idx) { sca_appearance_list *app_list; sca_appearance *app = NULL; @@ -451,17 +460,17 @@ sca_appearance *sca_appearance_seize_next_available_unsafe(sca_mod *scam, slot = sca_hash_table_slot_for_index(scam->appearances, slot_idx); app_list = sca_hash_table_slot_kv_find_unsafe(slot, aor); - if (app_list == NULL) { + if(app_list == NULL) { app_list = sca_appearance_list_create(scam, aor); - if (app_list == NULL) { + if(app_list == NULL) { goto done; } - if (sca_hash_table_slot_kv_insert_unsafe(slot, app_list, - sca_appearance_list_aor_cmp, sca_appearance_list_print, - sca_appearance_list_free) < 0) { - LM_ERR("Failed to insert appearance list for %.*s\n", - STR_FMT(aor)); + if(sca_hash_table_slot_kv_insert_unsafe(slot, app_list, + sca_appearance_list_aor_cmp, sca_appearance_list_print, + sca_appearance_list_free) + < 0) { + LM_ERR("Failed to insert appearance list for %.*s\n", STR_FMT(aor)); goto done; } } @@ -471,7 +480,7 @@ sca_appearance *sca_appearance_seize_next_available_unsafe(sca_mod *scam, // XXX check idx > any configured max appearance index app = sca_appearance_create(idx, owner_uri); - if (app == NULL) { + if(app == NULL) { LM_ERR("Failed to create new appearance for %.*s at index %d\n", STR_FMT(owner_uri), idx); goto done; @@ -480,11 +489,12 @@ sca_appearance *sca_appearance_seize_next_available_unsafe(sca_mod *scam, sca_appearance_list_insert_appearance(app_list, app); - done: return (app); +done: + return (app); } -int sca_appearance_seize_next_available_index(sca_mod *scam, str *aor, - str *owner_uri) +int sca_appearance_seize_next_available_index( + sca_mod *scam, str *aor, str *owner_uri) { sca_appearance *app; int slot_idx; @@ -493,9 +503,9 @@ int sca_appearance_seize_next_available_index(sca_mod *scam, str *aor, slot_idx = sca_hash_table_index_for_key(scam->appearances, aor); sca_hash_table_lock_index(scam->appearances, slot_idx); - app = sca_appearance_seize_next_available_unsafe(scam, aor, owner_uri, - slot_idx); - if (app != NULL) { + app = sca_appearance_seize_next_available_unsafe( + scam, aor, owner_uri, slot_idx); + if(app != NULL) { idx = app->index; } @@ -517,25 +527,26 @@ int sca_appearance_update_owner_unsafe(sca_appearance *app, str *owner) assert(app != NULL); assert(owner != NULL); - if (!SCA_STR_EMPTY(&app->owner)) { - if (app->prev_owner.s != NULL) { + if(!SCA_STR_EMPTY(&app->owner)) { + if(app->prev_owner.s != NULL) { shm_free(app->prev_owner.s); } app->prev_owner.s = app->owner.s; app->prev_owner.len = app->owner.len; } - app->owner.s = (char *) shm_malloc(owner->len); - if (app->owner.s == NULL) { + app->owner.s = (char *)shm_malloc(owner->len); + if(app->owner.s == NULL) { LM_ERR("sca_appearance_update_owner_unsafe: shm_malloc for new " - "owner %.*s failed: out of memory\n", STR_FMT(owner)); + "owner %.*s failed: out of memory\n", + STR_FMT(owner)); goto error; } SCA_STR_COPY(&app->owner, owner); return (1); - error: +error: // restore owner app->owner.s = app->prev_owner.s; app->owner.len = app->prev_owner.len; @@ -549,25 +560,26 @@ int sca_appearance_update_callee_unsafe(sca_appearance *app, str *callee) assert(app != NULL); assert(callee != NULL); - if (!SCA_STR_EMPTY(&app->callee)) { - if (app->prev_callee.s != NULL) { + if(!SCA_STR_EMPTY(&app->callee)) { + if(app->prev_callee.s != NULL) { shm_free(app->prev_callee.s); } app->prev_callee.s = app->callee.s; app->prev_callee.len = app->callee.len; } - app->callee.s = (char *) shm_malloc(callee->len); - if (app->callee.s == NULL) { + app->callee.s = (char *)shm_malloc(callee->len); + if(app->callee.s == NULL) { LM_ERR("sca_appearance_update_owner_unsafe: shm_malloc for new " - "callee %.*s failed: out of memory\n", STR_FMT(callee)); + "callee %.*s failed: out of memory\n", + STR_FMT(callee)); goto error; } SCA_STR_COPY(&app->callee, callee); return (1); - error: +error: // restore callee app->callee.s = app->prev_callee.s; app->callee.len = app->prev_callee.len; @@ -575,8 +587,8 @@ int sca_appearance_update_callee_unsafe(sca_appearance *app, str *callee) return (-1); } -int sca_appearance_update_dialog_unsafe(sca_appearance *app, str *call_id, - str *from_tag, str *to_tag) +int sca_appearance_update_dialog_unsafe( + sca_appearance *app, str *call_id, str *from_tag, str *to_tag) { int len; @@ -584,8 +596,8 @@ int sca_appearance_update_dialog_unsafe(sca_appearance *app, str *call_id, assert(call_id != NULL); assert(from_tag != NULL); - if (!SCA_STR_EMPTY(&app->dialog.id)) { - if (app->prev_dialog.id.s != NULL) { + if(!SCA_STR_EMPTY(&app->dialog.id)) { + if(app->prev_dialog.id.s != NULL) { shm_free(app->prev_dialog.id.s); } app->prev_dialog.id.s = app->dialog.id.s; @@ -602,14 +614,14 @@ int sca_appearance_update_dialog_unsafe(sca_appearance *app, str *call_id, } len = call_id->len + from_tag->len; - if (!SCA_STR_EMPTY(to_tag)) { + if(!SCA_STR_EMPTY(to_tag)) { len += to_tag->len; } - app->dialog.id.s = (char *) shm_malloc(len); - if (app->dialog.id.s == NULL) { + app->dialog.id.s = (char *)shm_malloc(len); + if(app->dialog.id.s == NULL) { LM_ERR("sca_appearance_update_dialog_unsafe: shm_malloc new dialog " - "failed: out of memory\n"); + "failed: out of memory\n"); goto error; } SCA_STR_COPY(&app->dialog.id, call_id); @@ -626,7 +638,7 @@ int sca_appearance_update_dialog_unsafe(sca_appearance *app, str *call_id, return (1); - error: +error: // restore dialog app->prev_dialog.id.s = app->dialog.id.s; app->prev_dialog.id.len = app->dialog.id.len; @@ -651,12 +663,12 @@ int sca_appearance_update_unsafe(sca_appearance *app, int state, str *display, int rc = SCA_APPEARANCE_OK; int len; - if (state != SCA_APPEARANCE_STATE_UNKNOWN) { + if(state != SCA_APPEARANCE_STATE_UNKNOWN) { sca_appearance_update_state_unsafe(app, state); } - if (!SCA_STR_EMPTY(uri)) { - if (!SCA_STR_EMPTY(&app->uri)) { + if(!SCA_STR_EMPTY(uri)) { + if(!SCA_STR_EMPTY(&app->uri)) { // the uri str's s member is shm_malloc'd separately shm_free(app->uri.s); memset(&app->uri, 0, sizeof(str)); @@ -664,20 +676,20 @@ int sca_appearance_update_unsafe(sca_appearance *app, int state, str *display, // +2 for left & right carets surrounding URI len = uri->len + 2; - if (!SCA_STR_EMPTY(display)) { + if(!SCA_STR_EMPTY(display)) { // cheaper to scan string than shm_malloc 2x display? len += sca_uri_display_escapes_count(display); // +1 for space between display & uri len += display->len + 1; } - app->uri.s = (char *) shm_malloc(len); - if (app->uri.s == NULL) { + app->uri.s = (char *)shm_malloc(len); + if(app->uri.s == NULL) { LM_ERR("shm_malloc %d bytes returned NULL\n", uri->len); rc = SCA_APPEARANCE_ERR_MALLOC; goto done; } - if (!SCA_STR_EMPTY(display)) { + if(!SCA_STR_EMPTY(display)) { // copy escaped display information... app->uri.len = escape_common(app->uri.s, display->s, display->len); @@ -695,16 +707,16 @@ int sca_appearance_update_unsafe(sca_appearance *app, int state, str *display, app->uri.len++; } - if (!SCA_DIALOG_EMPTY(dialog)) { - if (!SCA_STR_EQ(&dialog->id, &app->dialog.id)) { - if (app->dialog.id.s != NULL) { + if(!SCA_DIALOG_EMPTY(dialog)) { + if(!SCA_STR_EQ(&dialog->id, &app->dialog.id)) { + if(app->dialog.id.s != NULL) { shm_free(app->dialog.id.s); } - app->dialog.id.s = (char *) shm_malloc(dialog->id.len); - if (app->dialog.id.s == NULL) { + app->dialog.id.s = (char *)shm_malloc(dialog->id.len); + if(app->dialog.id.s == NULL) { LM_ERR("sca_appearance_update_unsafe: shm_malloc dialog id " - "failed: out of shared memory\n"); + "failed: out of shared memory\n"); // XXX this seems bad enough to abort... return (-1); } @@ -716,9 +728,9 @@ int sca_appearance_update_unsafe(sca_appearance *app, int state, str *display, app->dialog.from_tag.s = app->dialog.id.s + dialog->call_id.len; app->dialog.from_tag.len = dialog->from_tag.len; - if (!SCA_STR_EMPTY(&dialog->to_tag)) { + if(!SCA_STR_EMPTY(&dialog->to_tag)) { app->dialog.to_tag.s = app->dialog.id.s + dialog->call_id.len - + dialog->from_tag.len; + + dialog->from_tag.len; app->dialog.to_tag.len = dialog->to_tag.len; } else { app->dialog.to_tag.s = NULL; @@ -728,39 +740,40 @@ int sca_appearance_update_unsafe(sca_appearance *app, int state, str *display, } // NOTE these two blocks could be condensed and inlined - if (!SCA_STR_EMPTY(owner)) { - if (!SCA_STR_EQ(&app->owner, owner)) { - if (app->owner.s != NULL) { + if(!SCA_STR_EMPTY(owner)) { + if(!SCA_STR_EQ(&app->owner, owner)) { + if(app->owner.s != NULL) { shm_free(app->owner.s); } - app->owner.s = (char *) shm_malloc(owner->len); - if (app->owner.s == NULL) { + app->owner.s = (char *)shm_malloc(owner->len); + if(app->owner.s == NULL) { LM_ERR("sca_appearance_update_unsafe: shm_malloc " - "appearance owner URI failed: out of shared memory\n"); + "appearance owner URI failed: out of shared memory\n"); return (-1); } SCA_STR_COPY(&app->owner, owner); } } - if (!SCA_STR_EMPTY(callee)) { - if (!SCA_STR_EQ(&app->callee, callee)) { - if (app->callee.s != NULL) { + if(!SCA_STR_EMPTY(callee)) { + if(!SCA_STR_EQ(&app->callee, callee)) { + if(app->callee.s != NULL) { shm_free(app->callee.s); } - app->callee.s = (char *) shm_malloc(callee->len); - if (app->callee.s == NULL) { + app->callee.s = (char *)shm_malloc(callee->len); + if(app->callee.s == NULL) { LM_ERR("sca_appearance_update_unsafe: shm_malloc " - "appearance callee URI failed: out of shared memory\n"); + "appearance callee URI failed: out of shared memory\n"); return (-1); } SCA_STR_COPY(&app->callee, callee); } } - done: return (rc); +done: + return (rc); } int sca_uri_is_shared_appearance(sca_mod *scam, str *aor) @@ -776,7 +789,7 @@ int sca_uri_is_shared_appearance(sca_mod *scam, str *aor) app_list = sca_hash_table_slot_kv_find_unsafe(slot, aor); sca_hash_table_unlock_index(scam->appearances, slot_idx); - if (app_list == NULL) { + if(app_list == NULL) { return (0); } @@ -789,7 +802,7 @@ int sca_uri_lock_shared_appearance(sca_mod *scam, str *aor) sca_appearance_list *app_list; int slot_idx; - if (SCA_STR_EMPTY(aor)) { + if(SCA_STR_EMPTY(aor)) { return (-1); } @@ -799,7 +812,7 @@ int sca_uri_lock_shared_appearance(sca_mod *scam, str *aor) sca_hash_table_lock_index(scam->appearances, slot_idx); app_list = sca_hash_table_slot_kv_find_unsafe(slot, aor); - if (app_list == NULL) { + if(app_list == NULL) { sca_hash_table_unlock_index(scam->appearances, slot_idx); slot_idx = -1; } @@ -814,7 +827,7 @@ int sca_uri_lock_if_shared_appearance(sca_mod *scam, str *aor, int *slot_idx) assert(slot_idx != NULL); - if (SCA_STR_EMPTY(aor)) { + if(SCA_STR_EMPTY(aor)) { *slot_idx = -1; return (0); } @@ -825,7 +838,7 @@ int sca_uri_lock_if_shared_appearance(sca_mod *scam, str *aor, int *slot_idx) sca_hash_table_lock_index(scam->appearances, *slot_idx); app_list = sca_hash_table_slot_kv_find_unsafe(slot, aor); - if (app_list == NULL) { + if(app_list == NULL) { sca_hash_table_unlock_index(scam->appearances, *slot_idx); *slot_idx = -1; @@ -849,25 +862,24 @@ int sca_appearance_state_for_index(sca_mod *scam, str *aor, int idx) sca_hash_table_lock_index(scam->appearances, slot_idx); app_list = sca_hash_table_slot_kv_find_unsafe(slot, aor); - if (app_list == NULL) { + if(app_list == NULL) { LM_DBG("%.*s has no in-use appearances\n", STR_FMT(aor)); goto done; } - for (app = app_list->appearances; app != NULL; app = app->next) { - if (app->index == idx) { + for(app = app_list->appearances; app != NULL; app = app->next) { + if(app->index == idx) { break; } } - if (app == NULL) { - LM_WARN("%.*s appearance-index %d is not in use\n", - STR_FMT(aor), idx); + if(app == NULL) { + LM_WARN("%.*s appearance-index %d is not in use\n", STR_FMT(aor), idx); goto done; } state = app->state; - done: +done: sca_hash_table_unlock_index(scam->appearances, slot_idx); return (state); @@ -892,36 +904,36 @@ int sca_appearance_update_index(sca_mod *scam, str *aor, int idx, int state, sca_appearance_state_to_str(state, &state_str); app_list = sca_hash_table_slot_kv_find_unsafe(slot, aor); - if (app_list == NULL) { + if(app_list == NULL) { LM_WARN("Cannot update %.*s index %d to state %.*s: %.*s has no " - "in-use appearances\n", STR_FMT(aor), idx, - STR_FMT(&state_str), STR_FMT(aor)); + "in-use appearances\n", + STR_FMT(aor), idx, STR_FMT(&state_str), STR_FMT(aor)); rc = SCA_APPEARANCE_ERR_NOT_IN_USE; goto done; } - for (app = app_list->appearances; app != NULL; app = app->next) { - if (app->index == idx) { + for(app = app_list->appearances; app != NULL; app = app->next) { + if(app->index == idx) { break; - } else if (idx == 0) { - if (SCA_STR_EQ(&dialog->id, &app->dialog.id)) { + } else if(idx == 0) { + if(SCA_STR_EQ(&dialog->id, &app->dialog.id)) { break; } } } - if (app == NULL) { + if(app == NULL) { LM_WARN("Cannot update %.*s index %d to %.*s: index %d not in use\n", STR_FMT(aor), idx, STR_FMT(&state_str), idx); rc = SCA_APPEARANCE_ERR_INDEX_INVALID; goto done; } - if (state != SCA_APPEARANCE_STATE_UNKNOWN && app->state != state) { + if(state != SCA_APPEARANCE_STATE_UNKNOWN && app->state != state) { sca_appearance_update_state_unsafe(app, state); } - if (!SCA_STR_EMPTY(uri)) { - if (!SCA_STR_EMPTY(&app->uri)) { + if(!SCA_STR_EMPTY(uri)) { + if(!SCA_STR_EMPTY(&app->uri)) { // the uri str's s member is shm_malloc'd separately shm_free(app->uri.s); memset(&app->uri, 0, sizeof(str)); @@ -929,22 +941,22 @@ int sca_appearance_update_index(sca_mod *scam, str *aor, int idx, int state, // +2 for left & right carets surrounding URI len = uri->len + 2; - if (!SCA_STR_EMPTY(display)) { + if(!SCA_STR_EMPTY(display)) { // cheaper to scan string than shm_malloc 2x display? len += sca_uri_display_escapes_count(display); // +1 for space between display & uri len += display->len + 1; } - app->uri.s = (char *) shm_malloc(len); - if (app->uri.s == NULL) { + app->uri.s = (char *)shm_malloc(len); + if(app->uri.s == NULL) { LM_ERR("Failed to update %.*s index %d uri to %.*s: " - "shm_malloc %d bytes returned NULL\n", + "shm_malloc %d bytes returned NULL\n", STR_FMT(aor), idx, STR_FMT(uri), uri->len); rc = SCA_APPEARANCE_ERR_MALLOC; goto done; } - if (!SCA_STR_EMPTY(display)) { + if(!SCA_STR_EMPTY(display)) { // copy escaped display information... app->uri.len = escape_common(app->uri.s, display->s, display->len); @@ -962,13 +974,13 @@ int sca_appearance_update_index(sca_mod *scam, str *aor, int idx, int state, app->uri.len++; } - if (!SCA_DIALOG_EMPTY(dialog)) { - if (!SCA_STR_EQ(&dialog->id, &app->dialog.id)) { - if (app->dialog.id.s != NULL) { + if(!SCA_DIALOG_EMPTY(dialog)) { + if(!SCA_STR_EQ(&dialog->id, &app->dialog.id)) { + if(app->dialog.id.s != NULL) { shm_free(app->dialog.id.s); } - app->dialog.id.s = (char *) shm_malloc(dialog->id.len); + app->dialog.id.s = (char *)shm_malloc(dialog->id.len); SCA_STR_COPY(&app->dialog.id, &dialog->id); app->dialog.call_id.s = app->dialog.id.s; @@ -977,9 +989,9 @@ int sca_appearance_update_index(sca_mod *scam, str *aor, int idx, int state, app->dialog.from_tag.s = app->dialog.id.s + dialog->call_id.len; app->dialog.from_tag.len = dialog->from_tag.len; - if (!SCA_STR_EMPTY(&dialog->to_tag)) { + if(!SCA_STR_EMPTY(&dialog->to_tag)) { app->dialog.to_tag.s = app->dialog.id.s + dialog->call_id.len - + dialog->from_tag.len; + + dialog->from_tag.len; app->dialog.to_tag.len = dialog->to_tag.len; } else { app->dialog.to_tag.s = NULL; @@ -990,7 +1002,7 @@ int sca_appearance_update_index(sca_mod *scam, str *aor, int idx, int state, rc = SCA_APPEARANCE_OK; - done: +done: sca_hash_table_unlock_index(scam->appearances, slot_idx); return (rc); @@ -1011,20 +1023,20 @@ int sca_appearance_release_index(sca_mod *scam, str *aor, int idx) sca_hash_table_lock_index(scam->appearances, slot_idx); app_list = NULL; - for (ent = slot->entries; ent != NULL; ent = ent->next) { - if (ent->compare(aor, ent->value) == 0) { - app_list = (sca_appearance_list *) ent->value; + for(ent = slot->entries; ent != NULL; ent = ent->next) { + if(ent->compare(aor, ent->value) == 0) { + app_list = (sca_appearance_list *)ent->value; break; } } - if (app_list == NULL) { + if(app_list == NULL) { LM_ERR("No appearances for %.*s\n", STR_FMT(aor)); rc = SCA_APPEARANCE_ERR_NOT_IN_USE; goto done; } app = sca_appearance_list_unlink_index(app_list, idx); - if (app == NULL) { + if(app == NULL) { LM_ERR("Failed to unlink %.*s appearance-index %d: invalid index\n", STR_FMT(aor), idx); rc = SCA_APPEARANCE_ERR_INDEX_INVALID; @@ -1034,13 +1046,14 @@ int sca_appearance_release_index(sca_mod *scam, str *aor, int idx) rc = SCA_APPEARANCE_OK; - done: +done: sca_hash_table_unlock_index(scam->appearances, slot_idx); return (rc); } -int sca_appearance_owner_release_all(str *aor, str *owner) { +int sca_appearance_owner_release_all(str *aor, str *owner) +{ sca_appearance_list *app_list = NULL; sca_appearance *app, **cur_app, **tmp_app; sca_hash_slot *slot; @@ -1051,26 +1064,25 @@ int sca_appearance_owner_release_all(str *aor, str *owner) { slot_idx = sca_uri_lock_shared_appearance(sca, aor); slot = sca_hash_table_slot_for_index(sca->appearances, slot_idx); - for (ent = slot->entries; ent != NULL; ent = ent->next) { - if (ent->compare(aor, ent->value) == 0) { - app_list = (sca_appearance_list *) ent->value; + for(ent = slot->entries; ent != NULL; ent = ent->next) { + if(ent->compare(aor, ent->value) == 0) { + app_list = (sca_appearance_list *)ent->value; break; } } released = 0; - if (app_list == NULL) { + if(app_list == NULL) { LM_DBG("sca_appearance_owner_release_all: No appearances for %.*s\n", STR_FMT(aor)); goto done; } - for (cur_app = &app_list->appearances; *cur_app != NULL; cur_app = - tmp_app) { + for(cur_app = &app_list->appearances; *cur_app != NULL; cur_app = tmp_app) { tmp_app = &(*cur_app)->next; - if (!SCA_STR_EQ(owner, &(*cur_app)->owner)) { + if(!SCA_STR_EQ(owner, &(*cur_app)->owner)) { continue; } @@ -1078,21 +1090,22 @@ int sca_appearance_owner_release_all(str *aor, str *owner) { *cur_app = (*cur_app)->next; tmp_app = cur_app; - if (app) { + if(app) { sca_appearance_free(app); released++; } } - done: if (slot_idx >= 0) { +done: + if(slot_idx >= 0) { sca_hash_table_unlock_index(sca->appearances, slot_idx); } return (released); } -sca_appearance *sca_appearance_for_index_unsafe(sca_mod *scam, str *aor, - int app_idx, int slot_idx) +sca_appearance *sca_appearance_for_index_unsafe( + sca_mod *scam, str *aor, int app_idx, int slot_idx) { sca_appearance_list *app_list; sca_appearance *app = NULL; @@ -1102,19 +1115,19 @@ sca_appearance *sca_appearance_for_index_unsafe(sca_mod *scam, str *aor, slot = sca_hash_table_slot_for_index(scam->appearances, slot_idx); app_list = NULL; - for (ent = slot->entries; ent != NULL; ent = ent->next) { - if (ent->compare(aor, ent->value) == 0) { - app_list = (sca_appearance_list *) ent->value; + for(ent = slot->entries; ent != NULL; ent = ent->next) { + if(ent->compare(aor, ent->value) == 0) { + app_list = (sca_appearance_list *)ent->value; break; } } - if (app_list == NULL) { + if(app_list == NULL) { LM_ERR("No appearances for %.*s\n", STR_FMT(aor)); return (NULL); } - for (app = app_list->appearances; app != NULL; app = app->next) { - if (app->index == app_idx) { + for(app = app_list->appearances; app != NULL; app = app->next) { + if(app->index == app_idx) { break; } } @@ -1122,8 +1135,8 @@ sca_appearance *sca_appearance_for_index_unsafe(sca_mod *scam, str *aor, return (app); } -sca_appearance *sca_appearance_for_dialog_unsafe(sca_mod *scam, str *aor, - sca_dialog *dialog, int slot_idx) +sca_appearance *sca_appearance_for_dialog_unsafe( + sca_mod *scam, str *aor, sca_dialog *dialog, int slot_idx) { sca_appearance_list *app_list; sca_appearance *app = NULL; @@ -1133,24 +1146,24 @@ sca_appearance *sca_appearance_for_dialog_unsafe(sca_mod *scam, str *aor, slot = sca_hash_table_slot_for_index(scam->appearances, slot_idx); app_list = NULL; - for (ent = slot->entries; ent != NULL; ent = ent->next) { - if (ent->compare(aor, ent->value) == 0) { - app_list = (sca_appearance_list *) ent->value; + for(ent = slot->entries; ent != NULL; ent = ent->next) { + if(ent->compare(aor, ent->value) == 0) { + app_list = (sca_appearance_list *)ent->value; break; } } - if (app_list == NULL) { + if(app_list == NULL) { LM_ERR("No appearances for %.*s\n", STR_FMT(aor)); return (NULL); } - for (app = app_list->appearances; app != NULL; app = app->next) { - if (SCA_STR_EQ(&app->dialog.call_id, &dialog->call_id) && - SCA_STR_EQ(&app->dialog.from_tag, &dialog->from_tag)) { + for(app = app_list->appearances; app != NULL; app = app->next) { + if(SCA_STR_EQ(&app->dialog.call_id, &dialog->call_id) + && SCA_STR_EQ(&app->dialog.from_tag, &dialog->from_tag)) { #ifdef notdef - if (!SCA_STR_EMPTY(&app->dialog.to_tag) && - !SCA_STR_EMPTY(&dialog->to_tag) && - !SCA_STR_EQ(&app->dialog.to_tag, &dialog->to_tag)) { + if(!SCA_STR_EMPTY(&app->dialog.to_tag) + && !SCA_STR_EMPTY(&dialog->to_tag) + && !SCA_STR_EQ(&app->dialog.to_tag, &dialog->to_tag)) { continue; } #endif // notdef @@ -1168,18 +1181,19 @@ sca_appearance *sca_appearance_for_tags_unsafe(sca_mod *scam, str *aor, char dlg_buf[1024]; dialog.id.s = dlg_buf; - if (sca_dialog_build_from_tags(&dialog, sizeof(dlg_buf), call_id, from_tag, - to_tag) < 0) { + if(sca_dialog_build_from_tags( + &dialog, sizeof(dlg_buf), call_id, from_tag, to_tag) + < 0) { LM_ERR("sca_appearance_for_tags_unsafe: failed to build dialog " - "from tags\n"); + "from tags\n"); return (NULL); } return (sca_appearance_for_dialog_unsafe(scam, aor, &dialog, slot_idx)); } -sca_appearance *sca_appearance_unlink_by_tags(sca_mod *scam, str *aor, - str *call_id, str *from_tag, str *to_tag) +sca_appearance *sca_appearance_unlink_by_tags( + sca_mod *scam, str *aor, str *call_id, str *from_tag, str *to_tag) { sca_appearance *app = NULL, *unl_app; int slot_idx = -1; @@ -1187,25 +1201,28 @@ sca_appearance *sca_appearance_unlink_by_tags(sca_mod *scam, str *aor, slot_idx = sca_hash_table_index_for_key(scam->appearances, aor); sca_hash_table_lock_index(scam->appearances, slot_idx); - app = sca_appearance_for_tags_unsafe(scam, aor, call_id, from_tag, to_tag, - slot_idx); - if (app == NULL) { + app = sca_appearance_for_tags_unsafe( + scam, aor, call_id, from_tag, to_tag, slot_idx); + if(app == NULL) { LM_ERR("sca_appearance_unlink_by_tags: no appearances found for %.*s " - "with dialog %.*s;%.*s;%.*s\n", STR_FMT(aor), - STR_FMT(call_id), STR_FMT(from_tag), STR_FMT(to_tag)); + "with dialog %.*s;%.*s;%.*s\n", + STR_FMT(aor), STR_FMT(call_id), STR_FMT(from_tag), + STR_FMT(to_tag)); goto done; } - unl_app = sca_appearance_list_unlink_index(app->appearance_list, - app->index); - if (unl_app == NULL || unl_app != app) { + unl_app = + sca_appearance_list_unlink_index(app->appearance_list, app->index); + if(unl_app == NULL || unl_app != app) { LM_ERR("sca_appearance_unlink_by_tags: failed to unlink %.*s " - "appearance-index %d\n", STR_FMT(aor), app->index); + "appearance-index %d\n", + STR_FMT(aor), app->index); app = NULL; goto done; } - done: if (slot_idx >= 0) { +done: + if(slot_idx >= 0) { sca_hash_table_unlock_index(scam->appearances, slot_idx); } @@ -1214,12 +1231,13 @@ sca_appearance *sca_appearance_unlink_by_tags(sca_mod *scam, str *aor, void sca_appearance_purge_stale(unsigned int ticks, void *param) { - struct notify_list { + struct notify_list + { struct notify_list *next; str aor; }; - sca_mod *scam = (sca_mod *) param; + sca_mod *scam = (sca_mod *)param; sca_hash_table *ht; sca_hash_entry *ent; sca_appearance_list *app_list; @@ -1237,36 +1255,36 @@ void sca_appearance_purge_stale(unsigned int ticks, void *param) now = time(NULL); ht = scam->appearances; - for (i = 0; i < ht->size; i++) { + for(i = 0; i < ht->size; i++) { sca_hash_table_lock_index(ht, i); - for (ent = ht->slots[i].entries; ent != NULL; ent = ent->next) { - app_list = (sca_appearance_list *) ent->value; - if (app_list == NULL) { + for(ent = ht->slots[i].entries; ent != NULL; ent = ent->next) { + app_list = (sca_appearance_list *)ent->value; + if(app_list == NULL) { continue; } unlinked = 0; - for (cur_app = &app_list->appearances; *cur_app != NULL; cur_app = - tmp_app) { + for(cur_app = &app_list->appearances; *cur_app != NULL; + cur_app = tmp_app) { tmp_app = &(*cur_app)->next; - switch ((*cur_app)->state) { - case SCA_APPEARANCE_STATE_ACTIVE_PENDING: - ttl = SCA_APPEARANCE_STATE_PENDING_TTL; - break; + switch((*cur_app)->state) { + case SCA_APPEARANCE_STATE_ACTIVE_PENDING: + ttl = SCA_APPEARANCE_STATE_PENDING_TTL; + break; - case SCA_APPEARANCE_STATE_SEIZED: - ttl = SCA_APPEARANCE_STATE_SEIZED_TTL; - break; + case SCA_APPEARANCE_STATE_SEIZED: + ttl = SCA_APPEARANCE_STATE_SEIZED_TTL; + break; - default: - // XXX for now just skip other appearances - ttl = now + 60; - break; + default: + // XXX for now just skip other appearances + ttl = now + 60; + break; } - if ((now - (*cur_app)->times.mtime) < ttl) { + if((now - (*cur_app)->times.mtime) < ttl) { continue; } @@ -1275,11 +1293,11 @@ void sca_appearance_purge_stale(unsigned int ticks, void *param) *cur_app = (*cur_app)->next; tmp_app = cur_app; - if (app) { + if(app) { sca_appearance_free(app); } - if (unlinked) { + if(unlinked) { // we've already added this AoR to the NOTIFY list continue; } @@ -1288,19 +1306,19 @@ void sca_appearance_purge_stale(unsigned int ticks, void *param) // can't notify while slot is locked. make a list of AoRs to // notify after unlocking. - tmp_nl = (struct notify_list *) pkg_malloc( + tmp_nl = (struct notify_list *)pkg_malloc( sizeof(struct notify_list)); - if (tmp_nl == NULL) { + if(tmp_nl == NULL) { LM_ERR("sca_appearance_purge_stale: failed to pkg_malloc " - "notify list entry for %.*s\n", + "notify list entry for %.*s\n", STR_FMT(&app_list->aor)); continue; } - tmp_nl->aor.s = (char *) pkg_malloc(app_list->aor.len); - if (tmp_nl->aor.s == NULL) { + tmp_nl->aor.s = (char *)pkg_malloc(app_list->aor.len); + if(tmp_nl->aor.s == NULL) { LM_ERR("sca_appearance_purge_stale: failed to pkg_malloc " - "space for copy of %.*s\n", + "space for copy of %.*s\n", STR_FMT(&app_list->aor)); pkg_free(tmp_nl); continue; @@ -1315,20 +1333,21 @@ void sca_appearance_purge_stale(unsigned int ticks, void *param) sca_hash_table_unlock_index(ht, i); - for (; notify_list != NULL; notify_list = tmp_nl) { + for(; notify_list != NULL; notify_list = tmp_nl) { tmp_nl = notify_list->next; LM_INFO("sca_appearance_purge_stale: notifying %.*s call-info " - "subscribers\n", STR_FMT(¬ify_list->aor)); + "subscribers\n", + STR_FMT(¬ify_list->aor)); - if (sca_notify_call_info_subscribers(scam, ¬ify_list->aor) < 0) { + if(sca_notify_call_info_subscribers(scam, ¬ify_list->aor) < 0) { LM_ERR("sca_appearance_purge_stale: failed to send " - "call-info NOTIFY %.*s subscribers\n", + "call-info NOTIFY %.*s subscribers\n", STR_FMT(¬ify_list->aor)); // fall through, free memory anyway } - if (notify_list->aor.s) { + if(notify_list->aor.s) { pkg_free(notify_list->aor.s); } pkg_free(notify_list); diff --git a/src/modules/sca/sca_appearance.h b/src/modules/sca/sca_appearance.h index 857949438..bd94e1404 100644 --- a/src/modules/sca/sca_appearance.h +++ b/src/modules/sca/sca_appearance.h @@ -24,7 +24,8 @@ #include "sca_dialog.h" -enum { +enum +{ SCA_APPEARANCE_STATE_IDLE = 0, SCA_APPEARANCE_STATE_SEIZED, SCA_APPEARANCE_STATE_PROGRESSING, @@ -36,17 +37,20 @@ enum { SCA_APPEARANCE_STATE_UNKNOWN = 0xff, }; -#define sca_appearance_is_held(app1) \ - ((app1) && ((app1)->state == SCA_APPEARANCE_STATE_HELD || \ - (app1)->state == SCA_APPEARANCE_STATE_HELD_PRIVATE)) +#define sca_appearance_is_held(app1) \ + ((app1) \ + && ((app1)->state == SCA_APPEARANCE_STATE_HELD \ + || (app1)->state == SCA_APPEARANCE_STATE_HELD_PRIVATE)) -enum { +enum +{ SCA_APPEARANCE_FLAG_DEFAULT = 0, SCA_APPEARANCE_FLAG_OWNER_PENDING = (1 << 0), SCA_APPEARANCE_FLAG_CALLEE_PENDING = (1 << 1), }; -enum { +enum +{ SCA_APPEARANCE_OK = 0, SCA_APPEARANCE_ERR_NOT_IN_USE = 0x1001, SCA_APPEARANCE_ERR_INDEX_INVALID = 0x1002, @@ -54,7 +58,7 @@ enum { SCA_APPEARANCE_ERR_MALLOC = 0x1008, SCA_APPEARANCE_ERR_UNKNOWN = 0x1f00, }; -#define SCA_APPEARANCE_INDEX_UNAVAILABLE -2 +#define SCA_APPEARANCE_INDEX_UNAVAILABLE -2 /* * maximum lifetime of an active, pending appearance. @@ -62,7 +66,8 @@ enum { * ACK. on receipt of the caller's ACK, we promote * the SCA callee's state to active. */ -enum { +enum +{ // Polycoms aggressively resubscribe line-seizes, give them time SCA_APPEARANCE_STATE_SEIZED_TTL = 120, @@ -82,7 +87,8 @@ extern const str SCA_APPEARANCE_STATE_STR_ACTIVE; extern const str SCA_APPEARANCE_STATE_STR_HELD; extern const str SCA_APPEARANCE_STATE_STR_HELD_PRIVATE; -struct _sca_appearance_times { +struct _sca_appearance_times +{ // time of appearance creation time_t ctime; @@ -95,7 +101,8 @@ struct _sca_appearance_times { typedef struct _sca_appearance_times sca_appearance_times; struct _sca_appearance_list; -struct _sca_appearance { +struct _sca_appearance +{ int index; int state; str uri; @@ -116,7 +123,8 @@ struct _sca_appearance { }; typedef struct _sca_appearance sca_appearance; -struct _sca_appearance_list { +struct _sca_appearance_list +{ str aor; int appearance_count; sca_appearance *appearances; @@ -126,38 +134,38 @@ typedef struct _sca_appearance_list sca_appearance_list; void sca_appearance_state_to_str(int, str *); int sca_appearance_state_from_str(str *); -sca_appearance *sca_appearance_seize_index_unsafe(sca_mod *, str *, str *, int, - int, int *); +sca_appearance *sca_appearance_seize_index_unsafe( + sca_mod *, str *, str *, int, int, int *); int sca_appearance_seize_index(sca_mod *, str *, int, str *); int sca_appearance_seize_next_available_index(sca_mod *, str *, str *); -sca_appearance *sca_appearance_seize_next_available_unsafe(sca_mod *, str *, - str *, int); +sca_appearance *sca_appearance_seize_next_available_unsafe( + sca_mod *, str *, str *, int); void sca_appearance_update_state_unsafe(sca_appearance *, int); int sca_appearance_update_owner_unsafe(sca_appearance *, str *); int sca_appearance_update_callee_unsafe(sca_appearance *, str *); int sca_appearance_update_dialog_unsafe(sca_appearance *, str *, str *, str *); -int sca_appearance_update_unsafe(sca_appearance *, int, str *, str *, - sca_dialog *, str *, str *); -int sca_appearance_update_index(sca_mod *, str *, int, int, str *, str *, - sca_dialog *); +int sca_appearance_update_unsafe( + sca_appearance *, int, str *, str *, sca_dialog *, str *, str *); +int sca_appearance_update_index( + sca_mod *, str *, int, int, str *, str *, sca_dialog *); int sca_appearance_release_index(sca_mod *, str *, int); int sca_appearance_owner_release_all(str *, str *); int sca_appearance_state_for_index(sca_mod *, str *, int); sca_appearance *sca_appearance_for_index_unsafe(sca_mod *, str *, int, int); -sca_appearance *sca_appearance_for_dialog_unsafe(sca_mod *, str *, sca_dialog *, - int); -sca_appearance *sca_appearance_for_tags_unsafe(sca_mod *, str *, str *, str *, - str *, int); +sca_appearance *sca_appearance_for_dialog_unsafe( + sca_mod *, str *, sca_dialog *, int); +sca_appearance *sca_appearance_for_tags_unsafe( + sca_mod *, str *, str *, str *, str *, int); int sca_appearance_register(sca_mod *, str *); int sca_appearance_unregister(sca_mod *, str *); -void sca_appearance_list_insert_appearance(sca_appearance_list *, - sca_appearance *); +void sca_appearance_list_insert_appearance( + sca_appearance_list *, sca_appearance *); sca_appearance *sca_appearance_list_unlink_index(sca_appearance_list *, int); -int sca_appearance_list_unlink_appearance(sca_appearance_list *, - sca_appearance **); -sca_appearance *sca_appearance_unlink_by_tags(sca_mod *, str *, str *, str *, - str *); +int sca_appearance_list_unlink_appearance( + sca_appearance_list *, sca_appearance **); +sca_appearance *sca_appearance_unlink_by_tags( + sca_mod *, str *, str *, str *, str *); sca_appearance *sca_appearance_create(int, str *); void sca_appearance_free(sca_appearance *); diff --git a/src/modules/sca/sca_call_info.c b/src/modules/sca/sca_call_info.c index 5592efd70..c443f238c 100644 --- a/src/modules/sca/sca_call_info.c +++ b/src/modules/sca/sca_call_info.c @@ -40,10 +40,10 @@ static int sca_call_info_domain_from_uri(str *uri, str *domain) assert(domain != NULL); domain->s = memchr(uri->s, '@', uri->len); - if (domain->s == NULL) { + if(domain->s == NULL) { // may be a sip:domain URI domain->s = memchr(uri->s, ':', uri->len); - if (domain->s == NULL) { + if(domain->s == NULL) { LM_ERR("Bad URI %.*s\n", STR_FMT(uri)); return (-1); } @@ -81,18 +81,18 @@ static int sca_call_info_header_length_for_appearance( assert(aor != NULL); // get length of stringified index, since conversion's destructive - (void) int2str(appearance->index, &len); + (void)int2str(appearance->index, &len); sca_appearance_state_to_str(appearance->state, &state_str); len += state_str.len; - if (!SCA_STR_EMPTY(&appearance->uri)) { + if(!SCA_STR_EMPTY(&appearance->uri)) { // +1 for ';', +1 for '=' between param name and value, +2 for quotes len += SCA_APPEARANCE_URI_STR.len + 1 + 1 + 2; len += appearance->uri.len; } - if (sca_call_info_domain_from_uri(aor, &domain) < 0) { + if(sca_call_info_domain_from_uri(aor, &domain) < 0) { return (-1); } len += domain.len; @@ -102,8 +102,8 @@ static int sca_call_info_header_length_for_appearance( return (len); } -static int sca_call_info_header_append_appearances(sca_mod *scam, - sca_subscription *sub, char *hdrbuf, int maxlen) +static int sca_call_info_header_append_appearances( + sca_mod *scam, sca_subscription *sub, char *hdrbuf, int maxlen) { sca_appearance_list *app_list; sca_appearance *app; @@ -114,26 +114,26 @@ static int sca_call_info_header_append_appearances(sca_mod *scam, int len = -1; int usedlen = -1; - slot_idx = sca_hash_table_index_for_key(scam->appearances, - &sub->target_aor); + slot_idx = + sca_hash_table_index_for_key(scam->appearances, &sub->target_aor); slot = sca_hash_table_slot_for_index(scam->appearances, slot_idx); sca_hash_table_lock_index(scam->appearances, slot_idx); app_list = sca_hash_table_slot_kv_find_unsafe(slot, &sub->target_aor); - if (app_list == NULL) { + if(app_list == NULL) { len = 0; goto done; } usedlen = 0; - for (app = app_list->appearances; app != NULL; app = app->next) { + for(app = app_list->appearances; app != NULL; app = app->next) { len = sca_call_info_header_length_for_appearance(app, &sub->target_aor); - if (len < 0) { + if(len < 0) { goto done; } - if ((maxlen - len) < 0) { + if((maxlen - len) < 0) { LM_ERR("Call-Info header for AoR %.*s is too long\n", STR_FMT(&sub->target_aor)); len = -1; @@ -143,7 +143,7 @@ static int sca_call_info_header_append_appearances(sca_mod *scam, memcpy(hdrbuf, "target_aor, &domain) < 0) { + if(sca_call_info_domain_from_uri(&sub->target_aor, &domain) < 0) { return (-1); } @@ -157,7 +157,7 @@ static int sca_call_info_header_append_appearances(sca_mod *scam, ">;appearance-index=%d;appearance-state=%s", app->index, state_str.s); - if (!SCA_STR_EMPTY(&app->uri)) { + if(!SCA_STR_EMPTY(&app->uri)) { hdrbuf[len] = ';'; len += 1; @@ -178,7 +178,7 @@ static int sca_call_info_header_append_appearances(sca_mod *scam, len += 1; } - if (app->next) { + if(app->next) { memcpy(hdrbuf + len, ",", 1); len++; } @@ -189,19 +189,19 @@ static int sca_call_info_header_append_appearances(sca_mod *scam, usedlen += len; } - done: +done: sca_hash_table_unlock_index(scam->appearances, slot_idx); return (usedlen); } -static int sca_call_info_build_idle_value(sca_mod *scam, str *aor, char *hdrbuf, - int maxlen) +static int sca_call_info_build_idle_value( + sca_mod *scam, str *aor, char *hdrbuf, int maxlen) { str idle_domain = STR_NULL; int len; - if (sca_call_info_domain_from_uri(aor, &idle_domain) < 0) { + if(sca_call_info_domain_from_uri(aor, &idle_domain) < 0) { LM_ERR("Failed to extract domain from %.*s for idle domain\n", STR_FMT(aor)); return (-1); @@ -211,7 +211,7 @@ static int sca_call_info_build_idle_value(sca_mod *scam, str *aor, char *hdrbuf, len = snprintf(hdrbuf, maxlen, ";%s=*;%s=%s%s", STR_FMT(&idle_domain), SCA_APPEARANCE_INDEX_STR.s, SCA_APPEARANCE_STATE_STR.s, SCA_APPEARANCE_STATE_STR_IDLE.s, CRLF); - if (len >= maxlen) { + if(len >= maxlen) { LM_ERR("Failed to add idle appearance: Call-Info header too long\n"); len = -1; // snprintf can also return negative. we catch that in the caller. @@ -220,8 +220,8 @@ static int sca_call_info_build_idle_value(sca_mod *scam, str *aor, char *hdrbuf, return (len); } -int sca_call_info_build_header(sca_mod *scam, sca_subscription *sub, - char *hdrbuf, int maxlen) +int sca_call_info_build_header( + sca_mod *scam, sca_subscription *sub, char *hdrbuf, int maxlen) { // we send one Call-Info header, appearances separated by commas int len; @@ -230,21 +230,21 @@ int sca_call_info_build_header(sca_mod *scam, sca_subscription *sub, // begin with "Call-Info: " memcpy(hdrbuf, SCA_CALL_INFO_HEADER_STR.s, SCA_CALL_INFO_HEADER_STR.len); - len = sca_call_info_header_append_appearances(scam, sub, hdrbuf + usedlen, - maxlen - usedlen); + len = sca_call_info_header_append_appearances( + scam, sub, hdrbuf + usedlen, maxlen - usedlen); usedlen += len; - if (usedlen > SCA_CALL_INFO_HEADER_STR.len) { + if(usedlen > SCA_CALL_INFO_HEADER_STR.len) { // we added an indexed appearance, append a comma memcpy(hdrbuf + usedlen, ",", 1); usedlen++; } // line-seize NOTIFYs will contain only the seized appearance index - if (sub->event != SCA_EVENT_TYPE_LINE_SEIZE) { + if(sub->event != SCA_EVENT_TYPE_LINE_SEIZE) { // if not all appearances in use, add *-index idle - len = sca_call_info_build_idle_value(scam, &sub->target_aor, - hdrbuf + usedlen, maxlen - usedlen); - if (len < 0 || len + usedlen >= maxlen) { + len = sca_call_info_build_idle_value( + scam, &sub->target_aor, hdrbuf + usedlen, maxlen - usedlen); + if(len < 0 || len + usedlen >= maxlen) { LM_ERR("Cannot build idle Call-Info value: buffer too small\n"); return (-1); } @@ -254,55 +254,54 @@ int sca_call_info_build_header(sca_mod *scam, sca_subscription *sub, return (usedlen); } -int sca_call_info_append_header_for_appearance_index(sca_subscription *sub, - int appearance_index, char *hdrbuf, int maxlen) +int sca_call_info_append_header_for_appearance_index( + sca_subscription *sub, int appearance_index, char *hdrbuf, int maxlen) { str domain = STR_NULL; char *app_index_p = NULL; - int len = 0, - idx_len; + int len = 0, idx_len; memcpy(hdrbuf, SCA_CALL_INFO_HEADER_STR.s, SCA_CALL_INFO_HEADER_STR.len); len += SCA_CALL_INFO_HEADER_STR.len; - if (len >= maxlen) { + if(len >= maxlen) { goto error; } memcpy(hdrbuf + len, "= maxlen) { + if(len >= maxlen) { goto error; } sca_call_info_domain_from_uri(&sub->target_aor, &domain); memcpy(hdrbuf + len, domain.s, domain.len); len += domain.len; - if (len >= maxlen) { + if(len >= maxlen) { goto error; } memcpy(hdrbuf + len, ">;appearance-index=", strlen(">;appearance-index=")); len += strlen(">;appearance-index="); - if (len >= maxlen) { + if(len >= maxlen) { goto error; } app_index_p = int2str(appearance_index, &idx_len); memcpy(hdrbuf + len, app_index_p, idx_len); len += idx_len; - if (len >= maxlen) { + if(len >= maxlen) { goto error; } memcpy(hdrbuf + len, CRLF, CRLF_LEN); len += CRLF_LEN; - if (len >= maxlen) { + if(len >= maxlen) { goto error; } return (len); - error: +error: LM_ERR("Failed to append Call-Info header for %.*s appearance index %d\n", STR_FMT(&sub->subscriber), appearance_index); return (-1); @@ -317,7 +316,7 @@ int sca_call_info_body_parse(str *hdr_body, sca_call_info *call_info) assert(call_info != NULL); - if (SCA_STR_EMPTY(hdr_body)) { + if(SCA_STR_EMPTY(hdr_body)) { LM_ERR("Call-Info header body is empty\n"); return (-1); } @@ -330,18 +329,19 @@ int sca_call_info_body_parse(str *hdr_body, sca_call_info *call_info) call_info->uri.len = 0; p = hdr_body->s; - if (memcmp(p, "len); - if (semi == NULL) { + if(semi == NULL) { LM_ERR("Bad Call-Info header body: missing ';' between uri and " - "%.*s\n", STR_FMT(&SCA_APPEARANCE_INDEX_STR)); + "%.*s\n", + STR_FMT(&SCA_APPEARANCE_INDEX_STR)); return (-1); } - if (*(semi - 1) != '>') { + if(*(semi - 1) != '>') { LM_ERR("Bad Call-Info header body: SCA URI missing '>' terminator\n"); return (-1); } @@ -351,7 +351,7 @@ int sca_call_info_body_parse(str *hdr_body, sca_call_info *call_info) p = semi; p++; - if (memcmp(p, SCA_APPEARANCE_INDEX_STR.s, SCA_APPEARANCE_INDEX_STR.len) + if(memcmp(p, SCA_APPEARANCE_INDEX_STR.s, SCA_APPEARANCE_INDEX_STR.len) != 0) { LM_ERR("Bad Call-Info header body: does not begin with %.*s\n", STR_FMT(&SCA_APPEARANCE_INDEX_STR)); @@ -359,7 +359,7 @@ int sca_call_info_body_parse(str *hdr_body, sca_call_info *call_info) } p += SCA_APPEARANCE_INDEX_STR.len; - if (*p != '=') { + if(*p != '=') { LM_ERR("Bad Call-Info header body: missing '=' after %.*s\n", STR_FMT(&SCA_APPEARANCE_INDEX_STR)); return (-1); @@ -368,26 +368,27 @@ int sca_call_info_body_parse(str *hdr_body, sca_call_info *call_info) p++; len = (hdr_body->s + hdr_body->len) - p; semi = memchr(p, ';', len); - if (semi != NULL) { + if(semi != NULL) { len = semi - p; } s.s = p; s.len = len; - if (str2int(&s, (unsigned int *) &call_info->index) != 0) { + if(str2int(&s, (unsigned int *)&call_info->index) != 0) { LM_ERR("Bad Call-Info header: failed to convert %.*s %.*s to an " - "integer\n", STR_FMT(&SCA_APPEARANCE_INDEX_STR), STR_FMT(&s)); + "integer\n", + STR_FMT(&SCA_APPEARANCE_INDEX_STR), STR_FMT(&s)); return (-1); } - if (semi == NULL) { + if(semi == NULL) { // Call-Info header only contained an appearance-index goto done; } // advance appearance-index value + semi-colon p += (len + 1); - if (memcmp(p, SCA_APPEARANCE_STATE_STR.s, SCA_APPEARANCE_STATE_STR.len) + if(memcmp(p, SCA_APPEARANCE_STATE_STR.s, SCA_APPEARANCE_STATE_STR.len) != 0) { LM_ERR("Bad Call-Info header: missing %.*s\n", STR_FMT(&SCA_APPEARANCE_STATE_STR)); @@ -395,44 +396,43 @@ int sca_call_info_body_parse(str *hdr_body, sca_call_info *call_info) } p += SCA_APPEARANCE_STATE_STR.len; - if (*p != '=') { + if(*p != '=') { LM_ERR("Bad Call-Info header body: missing '=' after %.*s\n", STR_FMT(&SCA_APPEARANCE_STATE_STR)); return (-1); - } p++; len = (hdr_body->s + hdr_body->len) - p; semi = memchr(p, ';', len); - if (semi != NULL) { + if(semi != NULL) { len = semi - p; } s.s = p; s.len = len; call_info->state = sca_appearance_state_from_str(&s); - if (call_info->state == SCA_APPEARANCE_STATE_UNKNOWN) { + if(call_info->state == SCA_APPEARANCE_STATE_UNKNOWN) { LM_ERR("Bad Call-Info header: unrecognized state \"%.*s\"\n", STR_FMT(&s)); return (-1); } - if (semi == NULL) { + if(semi == NULL) { // Call-Info header only had appearance-index & appearance-state goto done; } // advance length of state + semi-colon p += (len + 1); - if (memcmp(p, SCA_APPEARANCE_URI_STR.s, SCA_APPEARANCE_URI_STR.len) != 0) { + if(memcmp(p, SCA_APPEARANCE_URI_STR.s, SCA_APPEARANCE_URI_STR.len) != 0) { LM_ERR("Bad Call-Info header: missing %.*s\n", STR_FMT(&SCA_APPEARANCE_URI_STR)); return (-1); } p += SCA_APPEARANCE_URI_STR.len; - if (*p != '=') { + if(*p != '=') { LM_ERR("Bad Call-Info header: missing '=' after %.*s\n", STR_FMT(&SCA_APPEARANCE_URI_STR)); return (-1); @@ -442,13 +442,14 @@ int sca_call_info_body_parse(str *hdr_body, sca_call_info *call_info) call_info->uri.s = p; call_info->uri.len = (hdr_body->s + hdr_body->len) - p; - if (SCA_STR_EMPTY(&call_info->uri)) { + if(SCA_STR_EMPTY(&call_info->uri)) { LM_ERR("Bad Call-Info header: empty %.*s\n", STR_FMT(&SCA_APPEARANCE_URI_STR)); return (-1); } - done: return (0); +done: + return (0); } /* @@ -464,15 +465,15 @@ static int sca_call_info_header_remove(sip_msg_t *msg) int rc = 0; // all headers must be parsed before using del_lump - if (parse_headers(msg, HDR_EOH_F, 0) < 0) { + if(parse_headers(msg, HDR_EOH_F, 0) < 0) { LM_ERR("Failed to parse_headers\n"); return (-1); } - for (hdr = get_hdr(msg, HDR_CALLINFO_T); hdr; hdr = next_sibling_hdr(hdr)) { + for(hdr = get_hdr(msg, HDR_CALLINFO_T); hdr; hdr = next_sibling_hdr(hdr)) { // del_lump takes packet, offset, lump length, & hdr type - ci_hdr_lump = del_lump(msg, hdr->name.s - msg->buf, hdr->len, - HDR_CALLINFO_T); - if (ci_hdr_lump == NULL) { + ci_hdr_lump = + del_lump(msg, hdr->name.s - msg->buf, hdr->len, HDR_CALLINFO_T); + if(ci_hdr_lump == NULL) { LM_ERR("Failed to del_lump Call-Info header\n"); rc = -1; break; @@ -500,23 +501,24 @@ int sca_call_info_seize_held_call(sip_msg_t *msg, sca_call_info *call_info, int slot_idx = -1; int rc = -1; - LM_DBG( "From-AOR:%.*s To-AOR:%.*s From-URI:<%.*s> To-URI:<%.*s> " - "Contact: <%.*s> Call-Info: appearance-index=%d\n", - STR_FMT(from_aor), STR_FMT(to_aor),STR_FMT(&from->uri), + LM_DBG("From-AOR:%.*s To-AOR:%.*s From-URI:<%.*s> To-URI:<%.*s> " + "Contact: <%.*s> Call-Info: appearance-index=%d\n", + STR_FMT(from_aor), STR_FMT(to_aor), STR_FMT(&from->uri), STR_FMT(&to->uri), STR_FMT(contact_uri), call_info->index); slot_idx = sca_hash_table_index_for_key(sca->appearances, from_aor); sca_hash_table_lock_index(sca->appearances, slot_idx); - app = sca_appearance_for_index_unsafe(sca, from_aor, call_info->index, - slot_idx); - if (app == NULL) { + app = sca_appearance_for_index_unsafe( + sca, from_aor, call_info->index, slot_idx); + if(app == NULL) { LM_ERR("sca_call_info_seize_held_call: no active appearances for " - "%.*s\n", STR_FMT(from_aor)); + "%.*s\n", + STR_FMT(from_aor)); goto done; } - if (app->state == SCA_APPEARANCE_STATE_HELD_PRIVATE) { + if(app->state == SCA_APPEARANCE_STATE_HELD_PRIVATE) { // spec calls for "403 Forbidden" when non-owner tries to // seize a privately held call. if we get here, there's no // to-tag in the INVITE, meaning this isn't a reINVITE @@ -528,15 +530,16 @@ int sca_call_info_seize_held_call(sip_msg_t *msg, sca_call_info *call_info, goto done; } - LM_DBG("sca_call_info_seize_held_call: seizing %.*s index %d, callee %.*s\n", + LM_DBG("sca_call_info_seize_held_call: seizing %.*s index %d, callee " + "%.*s\n", STR_FMT(from_aor), app->index, STR_FMT(&app->callee)); // rewrite the RURI to use the callee in this SCA dialog - if (msg->new_uri.s) { + if(msg->new_uri.s) { // someone already rewrote the URI. shouldn't happen, but we have // to watch for it. log our overwriting of it. LM_DBG("SCA caller retrieving held call, but RURI was already " - "rewritten as %.*s. Overwriting with %.*s.\n", + "rewritten as %.*s. Overwriting with %.*s.\n", STR_FMT(&msg->new_uri), STR_FMT(&app->callee)); pkg_free(msg->new_uri.s); @@ -545,10 +548,11 @@ int sca_call_info_seize_held_call(sip_msg_t *msg, sca_call_info *call_info, } // msg->new_uri.s is free'd when transaction is torn down - msg->new_uri.s = (char *) pkg_malloc(app->callee.len); - if (msg->new_uri.s == NULL) { + msg->new_uri.s = (char *)pkg_malloc(app->callee.len); + if(msg->new_uri.s == NULL) { LM_ERR("sca_call_info_seize_held_call: pkg_malloc new RURI %.*s " - "failed\n", STR_FMT(&app->callee)); + "failed\n", + STR_FMT(&app->callee)); goto done; } SCA_STR_COPY(&msg->new_uri, &app->callee); @@ -556,10 +560,10 @@ int sca_call_info_seize_held_call(sip_msg_t *msg, sca_call_info *call_info, { int idx; - for (idx = 0; get_sip_branch(idx) != NULL; idx++) + for(idx = 0; get_sip_branch(idx) != NULL; idx++) ; - for (; idx >= 0; idx--) { + for(; idx >= 0; idx--) { drop_sip_branch(idx); } } @@ -576,39 +580,41 @@ int sca_call_info_seize_held_call(sip_msg_t *msg, sca_call_info *call_info, SCA_STR_COPY(&prev_totag, &app->dialog.to_tag); // pkg_malloc's replaces_hdr.s, which is free'd if added as lump - if (sca_dialog_create_replaces_header(&app->dialog, &replaces_hdr) < 0) { + if(sca_dialog_create_replaces_header(&app->dialog, &replaces_hdr) < 0) { LM_ERR("sca_call_info_seize_held_call: failed to create Replaces " - "header for %.*s from dialog %.*s\n", + "header for %.*s from dialog %.*s\n", STR_FMT(from_aor), STR_FMT(&app->dialog.id)); goto done; } // store the callee's username for lookup of the callee by AoR callee_aor.s = callee_buf; - if (sca_uri_build_aor(&callee_aor, sizeof(callee_buf), &app->callee, - from_aor) < 0) { + if(sca_uri_build_aor( + &callee_aor, sizeof(callee_buf), &app->callee, from_aor) + < 0) { LM_ERR("sca_call_info_seize_held_call: failed to create To AoR " - "from %.*s and %.*s\n", STR_FMT(&app->callee), - STR_FMT(from_aor)); + "from %.*s and %.*s\n", + STR_FMT(&app->callee), STR_FMT(from_aor)); pkg_free(replaces_hdr.s); goto done; } // all headers must be parsed before using lump functions - if (parse_headers(msg, HDR_EOH_F, 0) < 0) { + if(parse_headers(msg, HDR_EOH_F, 0) < 0) { LM_ERR("Failed to parse_headers\n"); goto done; } anchor = anchor_lump(msg, msg->eoh - msg->buf, 0, HDR_OTHER_T); - if (anchor == NULL) { + if(anchor == NULL) { LM_ERR("Failed to anchor lump\n"); goto done; } // append the Replaces header before the sdp body - if (insert_new_lump_before(anchor, replaces_hdr.s, replaces_hdr.len, - HDR_OTHER_T) == NULL) { + if(insert_new_lump_before( + anchor, replaces_hdr.s, replaces_hdr.len, HDR_OTHER_T) + == NULL) { LM_ERR("Failed to add Replaces header %.*s\n", STR_FMT(&replaces_hdr)); pkg_free(replaces_hdr.s); goto done; @@ -623,14 +629,15 @@ int sca_call_info_seize_held_call(sip_msg_t *msg, sca_call_info *call_info, // // if the reINVITE to seize the held line fails for some reason, // we restore the original owner and dialog. - if (sca_appearance_update_owner_unsafe(app, contact_uri) < 0) { + if(sca_appearance_update_owner_unsafe(app, contact_uri) < 0) { LM_ERR("sca_call_info_seize_held_call: failed to update owner\n"); pkg_free(replaces_hdr.s); goto done; } - if (sca_appearance_update_dialog_unsafe(app, &msg->callid->body, - &from->tag_value, &to->tag_value) < 0) { + if(sca_appearance_update_dialog_unsafe( + app, &msg->callid->body, &from->tag_value, &to->tag_value) + < 0) { LM_ERR("sca_call_info_seize_held_call: failed to update dialog\n"); goto done; } @@ -641,13 +648,13 @@ int sca_call_info_seize_held_call(sip_msg_t *msg, sca_call_info *call_info, sca_hash_table_unlock_index(sca->appearances, slot_idx); slot_idx = -1; - if (callee_aor.s != NULL && callee_aor.len > 0) { - if (sca_uri_lock_if_shared_appearance(sca, &callee_aor, &slot_idx)) { + if(callee_aor.s != NULL && callee_aor.len > 0) { + if(sca_uri_lock_if_shared_appearance(sca, &callee_aor, &slot_idx)) { app = sca_appearance_for_tags_unsafe(sca, &callee_aor, &prev_callid, &prev_totag, NULL, slot_idx); - if (app == NULL) { + if(app == NULL) { LM_ERR("sca_call_info_seize_held_call: failed to find " - "appearance of %.*s with dialog %.*s;%.*s\n", + "appearance of %.*s with dialog %.*s;%.*s\n", STR_FMT(&callee_aor), STR_FMT(&prev_callid), STR_FMT(&prev_totag)); goto done; @@ -655,15 +662,16 @@ int sca_call_info_seize_held_call(sip_msg_t *msg, sca_call_info *call_info, app->flags |= SCA_APPEARANCE_FLAG_CALLEE_PENDING; - if (sca_appearance_update_callee_unsafe(app, contact_uri) < 0) { + if(sca_appearance_update_callee_unsafe(app, contact_uri) < 0) { LM_ERR("sca_call_info_seize_held_call: " - "failed to update callee\n"); + "failed to update callee\n"); goto done; } - if (sca_appearance_update_dialog_unsafe(app, &msg->callid->body, - &to->tag_value, &from->tag_value) < 0) { + if(sca_appearance_update_dialog_unsafe(app, &msg->callid->body, + &to->tag_value, &from->tag_value) + < 0) { LM_ERR("sca_call_info_seize_held_call: " - "failed to update dialog\n"); + "failed to update dialog\n"); goto done; } } @@ -671,7 +679,8 @@ int sca_call_info_seize_held_call(sip_msg_t *msg, sca_call_info *call_info, rc = 1; - done: if (slot_idx >= 0) { +done: + if(slot_idx >= 0) { sca_hash_table_unlock_index(sca->appearances, slot_idx); } @@ -695,17 +704,18 @@ static int sca_call_info_uri_update(str *aor, sca_call_info *call_info, assert(call_info != NULL); LM_DBG("sca_call_info_uri_update for %.*s: From: <%.*s> To: <%.*s> " - "Contact: <%.*s> Call-ID: %.*s Call-Info: appearance-index=%d\n", + "Contact: <%.*s> Call-ID: %.*s Call-Info: appearance-index=%d\n", STR_FMT(aor), STR_FMT(&from->uri), STR_FMT(&to->uri), STR_FMT(contact_uri), STR_FMT(call_id), call_info->index); - if (!sca_uri_is_shared_appearance(sca, aor)) { + if(!sca_uri_is_shared_appearance(sca, aor)) { return (1); } dialog.id.s = dlg_buf; - if (sca_dialog_build_from_tags(&dialog, sizeof(dlg_buf), call_id, from_tag, - to_tag) < 0) { + if(sca_dialog_build_from_tags( + &dialog, sizeof(dlg_buf), call_id, from_tag, to_tag) + < 0) { LM_ERR("sca_call_info_uri_update: Failed to build dialog from tags\n"); return (-1); } @@ -714,57 +724,62 @@ static int sca_call_info_uri_update(str *aor, sca_call_info *call_info, sca_hash_table_lock_index(sca->appearances, slot_idx); app = sca_appearance_for_index_unsafe(sca, aor, call_info->index, slot_idx); - if (app == NULL) { + if(app == NULL) { LM_DBG("sca_call_info_uri_update: no appearance found for %.*s " - "index %d, looking up by dialog...\n", STR_FMT(aor), - call_info->index); + "index %d, looking up by dialog...\n", + STR_FMT(aor), call_info->index); app = sca_appearance_for_dialog_unsafe(sca, aor, &dialog, slot_idx); } - if (app != NULL) { + if(app != NULL) { LM_DBG("sca_call_info_uri_update: setting owner to %.*s\n", STR_FMT(contact_uri)); - if (sca_appearance_update_unsafe(app, call_info->state, - NULL, NULL, &dialog, contact_uri, NULL) < 0) { + if(sca_appearance_update_unsafe(app, call_info->state, NULL, NULL, + &dialog, contact_uri, NULL) + < 0) { sca_appearance_state_to_str(call_info->state, &state_str); LM_ERR("sca_call_info_uri_update: failed to update appearance " - "%.*s appearance-index %d with dialog id %.*s to " - "state %.*s\n", STR_FMT(&app->owner), app->index, - STR_FMT(&app->dialog.id), STR_FMT(&state_str)); + "%.*s appearance-index %d with dialog id %.*s to " + "state %.*s\n", + STR_FMT(&app->owner), app->index, STR_FMT(&app->dialog.id), + STR_FMT(&state_str)); goto done; } rc = 1; } else { - app = sca_appearance_seize_index_unsafe(sca, aor, contact_uri, - call_info->index, slot_idx, NULL); - if (app == NULL) { + app = sca_appearance_seize_index_unsafe( + sca, aor, contact_uri, call_info->index, slot_idx, NULL); + if(app == NULL) { LM_ERR("sca_call_info_uri_update: failed to seize index %d " - "for %.*s\n", call_info->index, STR_FMT(contact_uri)); + "for %.*s\n", + call_info->index, STR_FMT(contact_uri)); goto done; } LM_DBG("sca_call_info_uri_update: seized %d for %.*s: From: <%.*s> " - "To: <%.*s> Call-ID: <%.*s> Dialog: <%.*s>\n", app->index, - STR_FMT(&app->owner), STR_FMT(&from->uri), - STR_FMT(&to->uri), STR_FMT(call_id), - STR_FMT(&app->dialog.id)); - - if (sca_appearance_update_unsafe(app, - SCA_APPEARANCE_STATE_ACTIVE_PENDING, &from->display, &from->uri, - &dialog, contact_uri, &from->uri) < 0) { + "To: <%.*s> Call-ID: <%.*s> Dialog: <%.*s>\n", + app->index, STR_FMT(&app->owner), STR_FMT(&from->uri), + STR_FMT(&to->uri), STR_FMT(call_id), STR_FMT(&app->dialog.id)); + + if(sca_appearance_update_unsafe(app, + SCA_APPEARANCE_STATE_ACTIVE_PENDING, &from->display, + &from->uri, &dialog, contact_uri, &from->uri) + < 0) { sca_appearance_state_to_str(call_info->state, &state_str); LM_ERR("sca_call_info_uri_update: failed to update appearance " - "%.*s appearance-index %d with dialog id %.*s to " - "state %.*s\n", STR_FMT(&app->owner), app->index, - STR_FMT(&app->dialog.id), STR_FMT(&state_str)); + "%.*s appearance-index %d with dialog id %.*s to " + "state %.*s\n", + STR_FMT(&app->owner), app->index, STR_FMT(&app->dialog.id), + STR_FMT(&state_str)); goto done; } rc = 1; } - done: if (slot_idx >= 0) { +done: + if(slot_idx >= 0) { sca_hash_table_unlock_index(sca->appearances, slot_idx); } @@ -773,13 +788,14 @@ static int sca_call_info_uri_update(str *aor, sca_call_info *call_info, static int sca_call_info_is_line_seize_reinvite(sip_msg_t *msg, sca_call_info *call_info, struct to_body *from, struct to_body *to, - str *from_aor, str *to_aor) { + str *from_aor, str *to_aor) +{ str *ruri; str ruri_aor; int state; LM_DBG("For From-AOR %.*s To-AOR: %.*s: From: <%.*s> To: <%.*s> " - "Call-Info: appearance-index=%d\n", + "Call-Info: appearance-index=%d\n", STR_FMT(from_aor), STR_FMT(to_aor), STR_FMT(&from->uri), STR_FMT(&to->uri), call_info->index); @@ -788,32 +804,34 @@ static int sca_call_info_is_line_seize_reinvite(sip_msg_t *msg, // the above are SCA AoRs; // there is no to-tag; // a Call-Info header is present - if (SCA_CALL_INFO_EMPTY(call_info)) { + if(SCA_CALL_INFO_EMPTY(call_info)) { return (0); } - if (!SCA_STR_EMPTY(&to->tag_value)) { + if(!SCA_STR_EMPTY(&to->tag_value)) { return (0); } ruri = GET_RURI(msg); - if (sca_uri_extract_aor(ruri, &ruri_aor) < 0) { + if(sca_uri_extract_aor(ruri, &ruri_aor) < 0) { LM_ERR("sca_call_info_is_line_seize_reinvite: failed to extract " - "AoR from RURI %.*s\n", STR_FMT(ruri)); + "AoR from RURI %.*s\n", + STR_FMT(ruri)); return (0); } - if (!SCA_STR_EQ(from_aor, to_aor)) { + if(!SCA_STR_EQ(from_aor, to_aor)) { return (0); } state = sca_appearance_state_for_index(sca, from_aor, call_info->index); - if (state != SCA_APPEARANCE_STATE_HELD) { + if(state != SCA_APPEARANCE_STATE_HELD) { LM_DBG("sca_call_info_is_line_seize_reinvite: new INVITE to " - "%.*s from %.*s appearance-index %d (not seizing held line)\n", + "%.*s from %.*s appearance-index %d (not seizing held line)\n", STR_FMT(to_aor), STR_FMT(from_aor), call_info->index); return (0); } - LM_DBG("reINVITE to %.*s from %.*s appearance-index %d (seizing held line)\n", + LM_DBG("reINVITE to %.*s from %.*s appearance-index %d (seizing held " + "line)\n", STR_FMT(to_aor), STR_FMT(from_aor), call_info->index); return (1); @@ -831,32 +849,36 @@ static void sca_call_info_local_error_reply_handler(sip_msg_t *msg, int status) str contact_uri = STR_NULL; int rc; - if (sca_get_msg_from_header(msg, &from) < 0) { + if(sca_get_msg_from_header(msg, &from) < 0) { LM_ERR("sca_call_info_sl_reply_cb: failed to get From header from " - "request before stateless reply with %d\n", status); + "request before stateless reply with %d\n", + status); return; } - if (sca_uri_extract_aor(&from->uri, &aor) < 0) { + if(sca_uri_extract_aor(&from->uri, &aor) < 0) { LM_ERR("sca_call_info_sl_reply_cb: failed to extract AoR " - "from URI %.*s\n", STR_FMT(&from->uri)); + "from URI %.*s\n", + STR_FMT(&from->uri)); return; } - if (!sca_uri_is_shared_appearance(sca, &aor)) { + if(!sca_uri_is_shared_appearance(sca, &aor)) { // LM_DBG("sca_call_info_sl_reply_cb: ignoring non-shared appearance " // "%.*s\n", STR_FMT(&aor)); return; } - if (sca_get_msg_contact_uri(msg, &contact_uri) < 0) { + if(sca_get_msg_contact_uri(msg, &contact_uri) < 0) { LM_ERR("sca_call_info_sl_reply_cb: failed to get Contact from " - "request before stateless reply with %d\n", status); + "request before stateless reply with %d\n", + status); return; } - if (sca_get_msg_to_header(msg, &to) < 0) { + if(sca_get_msg_to_header(msg, &to) < 0) { LM_ERR("sca_call_info_sl_reply_cb: failed to get To header from " - "request before stateless reply with %d\n", status); + "request before stateless reply with %d\n", + status); return; } @@ -872,32 +894,33 @@ static void sca_call_info_local_error_reply_handler(sip_msg_t *msg, int status) rc = sca_subscription_terminate(sca, &aor, SCA_EVENT_TYPE_LINE_SEIZE, &contact_uri, SCA_SUBSCRIPTION_STATE_TERMINATED_NORESOURCE, SCA_SUBSCRIPTION_TERMINATE_OPT_DEFAULT); - if (rc < 0) { + if(rc < 0) { LM_ERR("sca_call_info_sl_reply_cb: failed to terminate " - "line-seize subscription for %.*s\n", STR_FMT(&contact_uri)); - } else if (rc == 0) { + "line-seize subscription for %.*s\n", + STR_FMT(&contact_uri)); + } else if(rc == 0) { // no line-seize subscription found app = sca_appearance_unlink_by_tags(sca, &aor, &msg->callid->body, &from->tag_value, &to->tag_value); - if (app) { + if(app) { sca_appearance_free(app); - if (sca_notify_call_info_subscribers(sca, &aor) < 0) { + if(sca_notify_call_info_subscribers(sca, &aor) < 0) { LM_ERR("sca_call_info_local_error_reply: failed to send " - "call-info NOTIFY to %.*s subscribers\n", + "call-info NOTIFY to %.*s subscribers\n", STR_FMT(&aor)); } } } } -void sca_call_info_response_ready_cb(struct cell *t, int type, - struct tmcb_params *params) +void sca_call_info_response_ready_cb( + struct cell *t, int type, struct tmcb_params *params) { - if (!(type & TMCB_RESPONSE_READY)) { + if(!(type & TMCB_RESPONSE_READY)) { return; } - if (params->code < 400) { + if(params->code < 400) { // non-error final response: 1xx, 2xx, 3xx return; } @@ -916,20 +939,22 @@ int sca_call_info_invite_request_handler(sip_msg_t *msg, int rc = -1; LM_DBG("For From-AOR %.*s To-AOR: %.*s: From: <%.*s> To: <%.*s> " - "Contact: <%.*s> Call-Info: appearance-index=%d\n", - STR_FMT(from_aor), STR_FMT(to_aor),STR_FMT(&from->uri), STR_FMT(&to->uri), - STR_FMT(contact_uri), call_info->index); + "Contact: <%.*s> Call-Info: appearance-index=%d\n", + STR_FMT(from_aor), STR_FMT(to_aor), STR_FMT(&from->uri), + STR_FMT(&to->uri), STR_FMT(contact_uri), call_info->index); // if we get here, one of the legs is an SCA endpoint. we want to know // when the e2e ACK comes in so we can notify other members of the group. - if (sca->tm_api->register_tmcb(msg, NULL, TMCB_E2EACK_IN, - sca_call_info_ack_cb, NULL, NULL) < 0) { + if(sca->tm_api->register_tmcb( + msg, NULL, TMCB_E2EACK_IN, sca_call_info_ack_cb, NULL, NULL) + < 0) { LM_ERR("sca_call_info_invite_request_handler: failed to register " - "callback for INVITE %.*s ACK\n", STR_FMT(from_aor)); + "callback for INVITE %.*s ACK\n", + STR_FMT(from_aor)); goto done; } - if (!SCA_CALL_INFO_IS_SHARED_CALLER(call_info)) { + if(!SCA_CALL_INFO_IS_SHARED_CALLER(call_info)) { // caller isn't SCA, no more to do. update callee in reply handler. rc = 1; goto done; @@ -938,49 +963,52 @@ int sca_call_info_invite_request_handler(sip_msg_t *msg, // register callback to handle error responses sent from script using // t_reply. TMCB_RESPONSE_READY will only be called from t_reply(), // so relayed responses from upstream UASs will not triggers this. - if (sca->tm_api->register_tmcb(msg, NULL, TMCB_RESPONSE_READY, - sca_call_info_response_ready_cb, NULL, NULL) < 0) { + if(sca->tm_api->register_tmcb(msg, NULL, TMCB_RESPONSE_READY, + sca_call_info_response_ready_cb, NULL, NULL) + < 0) { LM_ERR("sca_call_info_invite_request_handler: failed to register " - "callback for INVITE %.*s ACK\n", STR_FMT(from_aor)); + "callback for INVITE %.*s ACK\n", + STR_FMT(from_aor)); goto done; } - if (sca_call_is_held(msg)) { + if(sca_call_is_held(msg)) { state = SCA_APPEARANCE_STATE_HELD; - if (call_info->state == SCA_APPEARANCE_STATE_HELD_PRIVATE) { + if(call_info->state == SCA_APPEARANCE_STATE_HELD_PRIVATE) { state = SCA_APPEARANCE_STATE_HELD_PRIVATE; } else { state = SCA_APPEARANCE_STATE_HELD; } - } else if (!SCA_STR_EMPTY(&to->tag_value)) { + } else if(!SCA_STR_EMPTY(&to->tag_value)) { // this is a reINVITE from an SCA line that put the call on hold state = SCA_APPEARANCE_STATE_ACTIVE; - } else if (sca_call_info_is_line_seize_reinvite(msg, call_info, from, to, - from_aor, to_aor)) { - rc = sca_call_info_seize_held_call(msg, call_info, from, to, from_aor, - to_aor, contact_uri); - if (rc <= 0) { + } else if(sca_call_info_is_line_seize_reinvite( + msg, call_info, from, to, from_aor, to_aor)) { + rc = sca_call_info_seize_held_call( + msg, call_info, from, to, from_aor, to_aor, contact_uri); + if(rc <= 0) { goto done; } } // otherwise, this is an initial INVITE dialog.id.s = dlg_buf; - if (sca_dialog_build_from_tags(&dialog, sizeof(dlg_buf), &msg->callid->body, - &from->tag_value, &to->tag_value) < 0) { + if(sca_dialog_build_from_tags(&dialog, sizeof(dlg_buf), &msg->callid->body, + &from->tag_value, &to->tag_value) + < 0) { LM_ERR("Failed to build dialog from tags\n"); return (-1); } - if (sca_appearance_update_index(sca, from_aor, call_info->index, state, - NULL, NULL, &dialog) != SCA_APPEARANCE_OK) { + if(sca_appearance_update_index( + sca, from_aor, call_info->index, state, NULL, NULL, &dialog) + != SCA_APPEARANCE_OK) { sca_appearance_state_to_str(state, &state_str); LM_ERR("Failed to update %.*s appearance-index %d to %.*s\n", - STR_FMT(from_aor), call_info->index, - STR_FMT(&state_str)); + STR_FMT(from_aor), call_info->index, STR_FMT(&state_str)); } - if (sca_notify_call_info_subscribers(sca, from_aor) < 0) { + if(sca_notify_call_info_subscribers(sca, from_aor) < 0) { LM_ERR("Failed to call-info NOTIFY %.*s subscribers on INVITE\n", STR_FMT(from_aor)); goto done; @@ -988,7 +1016,8 @@ int sca_call_info_invite_request_handler(sip_msg_t *msg, rc = 1; - done: return (rc); +done: + return (rc); } int sca_call_info_invite_reply_18x_handler(sip_msg_t *msg, @@ -1003,78 +1032,81 @@ int sca_call_info_invite_reply_18x_handler(sip_msg_t *msg, int notify = 0; LM_DBG("For From-AOR %.*s To-AOR: %.*s: From: <%.*s> To: <%.*s> " - "Contact: <%.*s> Call-Info: appearance-index=%d", - STR_FMT(from_aor), STR_FMT(to_aor),STR_FMT(&from->uri), STR_FMT(&to->uri), - STR_FMT(contact_uri), call_info->index); + "Contact: <%.*s> Call-Info: appearance-index=%d", + STR_FMT(from_aor), STR_FMT(to_aor), STR_FMT(&from->uri), + STR_FMT(&to->uri), STR_FMT(contact_uri), call_info->index); - switch (msg->REPLY_STATUS) { - case 180: - case 183: - state = SCA_APPEARANCE_STATE_PROGRESSING; - break; + switch(msg->REPLY_STATUS) { + case 180: + case 183: + state = SCA_APPEARANCE_STATE_PROGRESSING; + break; - default: - goto done; + default: + goto done; } - if (!sca_uri_lock_if_shared_appearance(sca, from_aor, &slot_idx)) { + if(!sca_uri_lock_if_shared_appearance(sca, from_aor, &slot_idx)) { LM_DBG("sca_call_info_invite_reply_18x_handler: From-AoR %.*s is " - "not a shared appearance\n", STR_FMT(from_aor)); + "not a shared appearance\n", + STR_FMT(from_aor)); return (1); } app = sca_appearance_for_tags_unsafe(sca, from_aor, &msg->callid->body, &from->tag_value, &to->tag_value, slot_idx); - if (app == NULL) { + if(app == NULL) { goto done; } // clone appearance owner for subscription termination below - owner.s = (char *) pkg_malloc(app->owner.len); - if (owner.s == NULL) { + owner.s = (char *)pkg_malloc(app->owner.len); + if(owner.s == NULL) { LM_ERR("sca_call_info_invite_18x_reply_handler: failed to " - "pkg_malloc %d bytes to clone <%.*s>\n", + "pkg_malloc %d bytes to clone <%.*s>\n", app->owner.len, STR_FMT(&app->owner)); goto done; } SCA_STR_COPY(&owner, &app->owner); notify = (app->state != state); - if (notify) { + if(notify) { sca_appearance_update_state_unsafe(app, state); } rc = 1; - done: if (slot_idx >= 0) { +done: + if(slot_idx >= 0) { sca_hash_table_unlock_index(sca->appearances, slot_idx); } - if (rc > 0 && notify && owner.s != NULL) { - if (sca_subscription_terminate(sca, from_aor, SCA_EVENT_TYPE_LINE_SEIZE, - &owner, SCA_SUBSCRIPTION_STATE_TERMINATED_NORESOURCE, - SCA_SUBSCRIPTION_TERMINATE_OPT_UNSUBSCRIBE) < 0) { + if(rc > 0 && notify && owner.s != NULL) { + if(sca_subscription_terminate(sca, from_aor, SCA_EVENT_TYPE_LINE_SEIZE, + &owner, SCA_SUBSCRIPTION_STATE_TERMINATED_NORESOURCE, + SCA_SUBSCRIPTION_TERMINATE_OPT_UNSUBSCRIBE) + < 0) { LM_ERR("sca_call_info_invite_reply_18x_handler: " - "failed to terminate line-seize subscription for %.*s\n", + "failed to terminate line-seize subscription for %.*s\n", STR_FMT(&owner)); rc = -1; } - if (sca_notify_call_info_subscribers(sca, from_aor) < 0) { + if(sca_notify_call_info_subscribers(sca, from_aor) < 0) { LM_ERR("sca_call_info_invite_reply_18x_handler: " - "failed to NOTIFY %.*s call-info subscribers\n", + "failed to NOTIFY %.*s call-info subscribers\n", STR_FMT(from_aor)); rc = -1; } } - if (owner.s != NULL) { + if(owner.s != NULL) { pkg_free(owner.s); } return (rc); } -static int sca_call_info_insert_asserted_identity(sip_msg_t *msg, str *display, - int ua_type) +static int sca_call_info_insert_asserted_identity( + sip_msg_t *msg, str *display, int ua_type) { struct lump *anchor; str aor = STR_NULL; @@ -1083,33 +1115,33 @@ static int sca_call_info_insert_asserted_identity(sip_msg_t *msg, str *display, int rc = -1; anchor = anchor_lump(msg, msg->eoh - msg->buf, 0, HDR_OTHER_T); - if (anchor == NULL) { + if(anchor == NULL) { LM_ERR("Failed to anchor lump\n"); goto done; } - if (sca_create_canonical_aor_for_ua(msg, &aor, ua_type) < 0) { + if(sca_create_canonical_aor_for_ua(msg, &aor, ua_type) < 0) { LM_ERR("sca_call_info_insert_asserted_identity: failed to create " - "canonical AoR\n"); + "canonical AoR\n"); goto done; } -#define SCA_P_ASSERTED_IDENTITY_HDR_PREFIX "P-Asserted-Identity: " -#define SCA_P_ASSERTED_IDENTITY_HDR_PREFIX_LEN strlen("P-Asserted-Identity: ") +#define SCA_P_ASSERTED_IDENTITY_HDR_PREFIX "P-Asserted-Identity: " +#define SCA_P_ASSERTED_IDENTITY_HDR_PREFIX_LEN strlen("P-Asserted-Identity: ") len = SCA_P_ASSERTED_IDENTITY_HDR_PREFIX_LEN; len += display->len; // +1 for space, +1 for <, + 1 for > len += 1 + 1 + aor.len + 1 + CRLF_LEN; - hdr.s = (char *) pkg_malloc(len); - if (hdr.s == NULL) { + hdr.s = (char *)pkg_malloc(len); + if(hdr.s == NULL) { LM_ERR("insert_asserted_identity: pkg_malloc %d bytes failed\n", len); goto done; } memcpy(hdr.s, SCA_P_ASSERTED_IDENTITY_HDR_PREFIX, - SCA_P_ASSERTED_IDENTITY_HDR_PREFIX_LEN); + SCA_P_ASSERTED_IDENTITY_HDR_PREFIX_LEN); hdr.len = SCA_P_ASSERTED_IDENTITY_HDR_PREFIX_LEN; SCA_STR_APPEND(&hdr, display); @@ -1129,17 +1161,18 @@ static int sca_call_info_insert_asserted_identity(sip_msg_t *msg, str *display, hdr.len += CRLF_LEN; // append the PAI header before the sdp body - if (insert_new_lump_before(anchor, hdr.s, hdr.len, HDR_PAI_T) == NULL) { + if(insert_new_lump_before(anchor, hdr.s, hdr.len, HDR_PAI_T) == NULL) { LM_ERR("Failed to add PAI header %.*s\n", STR_FMT(&hdr)); goto done; } rc = 1; - done: if (aor.s != NULL) { +done: + if(aor.s != NULL) { pkg_free(aor.s); } - if (rc < 0 && hdr.s != NULL) { + if(rc < 0 && hdr.s != NULL) { pkg_free(hdr.s); } @@ -1162,22 +1195,23 @@ static int sca_call_info_invite_reply_200_handler(sip_msg_t *msg, int rc = -1; LM_DBG("For From-AOR %.*s To-AOR: %.*s: From: <%.*s> To: <%.*s> " - "Contact: <%.*s> Call-Info: appearance-index=%d\n", - STR_FMT(from_aor), STR_FMT(to_aor),STR_FMT(&from->uri), STR_FMT(&to->uri), - STR_FMT(contact_uri), call_info->index); + "Contact: <%.*s> Call-Info: appearance-index=%d\n", + STR_FMT(from_aor), STR_FMT(to_aor), STR_FMT(&from->uri), + STR_FMT(&to->uri), STR_FMT(contact_uri), call_info->index); - if (SCA_CALL_INFO_IS_SHARED_CALLEE(call_info) && - (!SCA_STR_EQ(from_aor, to_aor))) { - rc = sca_call_info_uri_update(to_aor, call_info, from, to, contact_uri, - &msg->callid->body); + if(SCA_CALL_INFO_IS_SHARED_CALLEE(call_info) + && (!SCA_STR_EQ(from_aor, to_aor))) { + rc = sca_call_info_uri_update( + to_aor, call_info, from, to, contact_uri, &msg->callid->body); } - if (!SCA_CALL_INFO_IS_SHARED_CALLER(call_info)) { + if(!SCA_CALL_INFO_IS_SHARED_CALLER(call_info)) { goto done; } - if (sca_call_info_insert_asserted_identity(msg, &to->display, - SCA_AOR_TYPE_UAS) < 0) { + if(sca_call_info_insert_asserted_identity( + msg, &to->display, SCA_AOR_TYPE_UAS) + < 0) { LM_WARN("sca_call_info_invite_reply_200_handler: failed to " "add P-Asserted-Identity header to response from %.*s\n", STR_FMT(contact_uri)); @@ -1197,29 +1231,31 @@ static int sca_call_info_invite_reply_200_handler(sip_msg_t *msg, app = sca_appearance_for_tags_unsafe(sca, from_aor, &msg->callid->body, &from->tag_value, NULL, slot_idx); - if (app == NULL) { + if(app == NULL) { // no SCA line is involved with this call rc = 1; goto done; } - if (!sca_appearance_is_held(app)) { + if(!sca_appearance_is_held(app)) { state = SCA_APPEARANCE_STATE_ACTIVE; } // if a Call-Info header is present, app-index goes to Contact dialog.id.s = dlg_buf; - if (sca_dialog_build_from_tags(&dialog, sizeof(dlg_buf), &msg->callid->body, - &from->tag_value, &to->tag_value) < 0) { + if(sca_dialog_build_from_tags(&dialog, sizeof(dlg_buf), &msg->callid->body, + &from->tag_value, &to->tag_value) + < 0) { LM_ERR("sca_call_info_invite_handler: failed to build sca_dialog " - "from tags\n"); + "from tags\n"); rc = -1; goto done; } - if (parse_uri(contact_uri->s, contact_uri->len, &c_uri) < 0) { + if(parse_uri(contact_uri->s, contact_uri->len, &c_uri) < 0) { LM_ERR("sca_call_info_invite_200_reply_handler: " - "parse_uri <%.*s> failed\n", STR_FMT(contact_uri)); + "parse_uri <%.*s> failed\n", + STR_FMT(contact_uri)); goto done; } @@ -1228,38 +1264,42 @@ static int sca_call_info_invite_reply_200_handler(sip_msg_t *msg, // INVITE for the call to sca_appearance_update_unsafe(). Otherwise its a // 200 reply for a reINVITE and the 'to_display' and 'app_uri_aor' are // already set to NULL and that won't change the appearance-uri. - if (!SCA_STR_EQ(from_aor, to_aor)) { + if(!SCA_STR_EQ(from_aor, to_aor)) { to_display = to->display; - if (sca_create_canonical_aor(msg, &app_uri_aor) < 0) { - LM_ERR( "sca_call_info_invite_200_reply_handler: " - "sca_create_canonical_aor failed\n" ); + if(sca_create_canonical_aor(msg, &app_uri_aor) < 0) { + LM_ERR("sca_call_info_invite_200_reply_handler: " + "sca_create_canonical_aor failed\n"); goto done; } } - if (sca_appearance_update_unsafe(app, state, &to_display, &app_uri_aor, - &dialog, NULL, contact_uri) < 0) { + if(sca_appearance_update_unsafe(app, state, &to_display, &app_uri_aor, + &dialog, NULL, contact_uri) + < 0) { sca_appearance_state_to_str(state, &state_str); LM_ERR("sca_call_info_invite_handler: failed to update appearance " - "%.*s appearance-index %d with dialog id %.*s to " - "state %.*s\n", STR_FMT(&app->owner), app->index, - STR_FMT(&app->dialog.id), STR_FMT(&state_str)); + "%.*s appearance-index %d with dialog id %.*s to " + "state %.*s\n", + STR_FMT(&app->owner), app->index, STR_FMT(&app->dialog.id), + STR_FMT(&state_str)); rc = -1; goto done; } rc = 1; - done: if (slot_idx >= 0) { +done: + if(slot_idx >= 0) { sca_hash_table_unlock_index(sca->appearances, slot_idx); } - if (app_uri_aor.s != NULL) { + if(app_uri_aor.s != NULL) { pkg_free(app_uri_aor.s); } - if (rc == 1) { - if (sca_notify_call_info_subscribers(sca, from_aor) < 0) { + if(rc == 1) { + if(sca_notify_call_info_subscribers(sca, from_aor) < 0) { LM_ERR("Failed to call-info NOTIFY %.*s subscribers on " - "200 OK reply to INVITE\n", STR_FMT(from_aor)); + "200 OK reply to INVITE\n", + STR_FMT(from_aor)); rc = -1; } } @@ -1281,25 +1321,26 @@ static int sca_call_info_invite_reply_error_handler(sip_msg_t *msg, // for a start, we just deal with the first case. sca_appearance *app; - if (msg->REPLY_STATUS == 487) { + if(msg->REPLY_STATUS == 487) { // reply status for a CANCEL'd INVITE return (1); } - if (sca_uri_is_shared_appearance(sca, from_aor)) { - app = sca_appearance_unlink_by_tags(sca, from_aor, &msg->callid->body, - &from->tag_value, NULL); - if (app == NULL) { + if(sca_uri_is_shared_appearance(sca, from_aor)) { + app = sca_appearance_unlink_by_tags( + sca, from_aor, &msg->callid->body, &from->tag_value, NULL); + if(app == NULL) { LM_ERR("sca_call_info_invite_reply_error_handler: failed to " - "look up dialog for failed INVITE %.*s from %.*s\n", + "look up dialog for failed INVITE %.*s from %.*s\n", STR_FMT(&to->uri), STR_FMT(from_aor)); return (-1); } sca_appearance_free(app); - if (sca_notify_call_info_subscribers(sca, from_aor) < 0) { + if(sca_notify_call_info_subscribers(sca, from_aor) < 0) { LM_ERR("Failed to call-info NOTIFY %.*s subscribers on " - "failed INVITE\n", STR_FMT(from_aor)); + "failed INVITE\n", + STR_FMT(from_aor)); return (-1); } } @@ -1315,22 +1356,23 @@ void sca_call_info_ack_from_handler(sip_msg_t *msg, str *from_aor, str *to_aor) int slot_idx = -1; int state = SCA_APPEARANCE_STATE_IDLE; - if (sca_get_msg_from_header(msg, &from) < 0) { + if(sca_get_msg_from_header(msg, &from) < 0) { LM_ERR("sca_call_info_ack_cb: failed to get From-header\n"); return; } - if (sca_get_msg_to_header(msg, &to) < 0) { + if(sca_get_msg_to_header(msg, &to) < 0) { LM_ERR("sca_call_info_ack_cb: failed to get To-header\n"); return; } - if (sca_uri_lock_if_shared_appearance(sca, from_aor, &slot_idx)) { + if(sca_uri_lock_if_shared_appearance(sca, from_aor, &slot_idx)) { app = sca_appearance_for_tags_unsafe(sca, from_aor, &msg->callid->body, &from->tag_value, NULL, slot_idx); - if (app == NULL) { + if(app == NULL) { LM_ERR("sca_call_info_ack_cb: No appearance for %.*s matching " - "call-id <%.*s> and from-tag <%.*s>\n", STR_FMT(from_aor), - STR_FMT(&msg->callid->body), STR_FMT(&from->tag_value)); + "call-id <%.*s> and from-tag <%.*s>\n", + STR_FMT(from_aor), STR_FMT(&msg->callid->body), + STR_FMT(&from->tag_value)); goto done; } @@ -1345,19 +1387,21 @@ void sca_call_info_ack_from_handler(sip_msg_t *msg, str *from_aor, str *to_aor) // false. instead, the ACK from the party placing the call on hold // includes the sendonly SDP. detect that here, and send NOTIFYs // as necessary. - if (sca_call_is_held(msg)) { + if(sca_call_is_held(msg)) { state = SCA_APPEARANCE_STATE_HELD; sca_appearance_update_state_unsafe(app, state); // can't send NOTIFYs until we unlock the slot below } } - done: if (slot_idx >= 0) { +done: + if(slot_idx >= 0) { sca_hash_table_unlock_index(sca->appearances, slot_idx); - if (state != SCA_APPEARANCE_STATE_IDLE) { - if (sca_notify_call_info_subscribers(sca, from_aor) < 0) { - LM_ERR("Failed to call-info NOTIFY %.*s subscribers on INVITE\n", + if(state != SCA_APPEARANCE_STATE_IDLE) { + if(sca_notify_call_info_subscribers(sca, from_aor) < 0) { + LM_ERR("Failed to call-info NOTIFY %.*s subscribers on " + "INVITE\n", STR_FMT(from_aor)); } } @@ -1373,19 +1417,19 @@ void sca_call_info_ack_cb(struct cell *t, int type, struct tmcb_params *params) str to_aor = STR_NULL; int slot_idx = -1; - if (!(type & TMCB_E2EACK_IN)) { + if(!(type & TMCB_E2EACK_IN)) { return; } - if (sca_create_canonical_aor(params->req, &from_aor) < 0) { + if(sca_create_canonical_aor(params->req, &from_aor) < 0) { return; } - if (sca_get_msg_to_header(params->req, &to) < 0) { + if(sca_get_msg_to_header(params->req, &to) < 0) { LM_ERR("sca_call_info_ack_cb: failed to get To-header\n"); goto done; } - if (sca_uri_extract_aor(&to->uri, &to_aor) < 0) { + if(sca_uri_extract_aor(&to->uri, &to_aor) < 0) { LM_ERR("sca_call_info_ack_cb: failed to extract To AoR from %.*s\n", STR_FMT(&to->uri)); goto done; @@ -1393,7 +1437,7 @@ void sca_call_info_ack_cb(struct cell *t, int type, struct tmcb_params *params) sca_call_info_ack_from_handler(params->req, &from_aor, &to_aor); - if (!sca_uri_lock_if_shared_appearance(sca, &to_aor, &slot_idx)) { + if(!sca_uri_lock_if_shared_appearance(sca, &to_aor, &slot_idx)) { LM_DBG("sca_call_info_ack_cb: %.*s is not a shared appearance\n", STR_FMT(&to_aor)); goto done; @@ -1402,73 +1446,75 @@ void sca_call_info_ack_cb(struct cell *t, int type, struct tmcb_params *params) // on ACK, ensure SCA callee state is promoted to ACTIVE. app = sca_appearance_for_tags_unsafe(sca, &to_aor, ¶ms->req->callid->body, &to->tag_value, NULL, slot_idx); - if (app && app->state == SCA_APPEARANCE_STATE_ACTIVE_PENDING) { + if(app && app->state == SCA_APPEARANCE_STATE_ACTIVE_PENDING) { LM_DBG("promoting %.*s appearance-index %d to active\n", STR_FMT(&to_aor), app->index); sca_appearance_update_state_unsafe(app, SCA_APPEARANCE_STATE_ACTIVE); } - if (slot_idx >= 0) { + if(slot_idx >= 0) { sca_hash_table_unlock_index(sca->appearances, slot_idx); } - if (sca_notify_call_info_subscribers(sca, &to_aor) < 0) { + if(sca_notify_call_info_subscribers(sca, &to_aor) < 0) { LM_ERR("sca_call_info_ack_cb: failed to call-info " - "NOTIFY %.*s subscribers\n", STR_FMT(&to_aor)); + "NOTIFY %.*s subscribers\n", + STR_FMT(&to_aor)); goto done; } - done: if (from_aor.s != NULL) { +done: + if(from_aor.s != NULL) { pkg_free(from_aor.s); } } -static int sca_call_info_invite_handler(sip_msg_t *msg, sca_call_info *call_info, - struct to_body *from, struct to_body *to, str *from_aor, str *to_aor, - str *contact_uri) +static int sca_call_info_invite_handler(sip_msg_t *msg, + sca_call_info *call_info, struct to_body *from, struct to_body *to, + str *from_aor, str *to_aor, str *contact_uri) { int rc = -1; - if (SCA_STR_EMPTY(contact_uri)) { + if(SCA_STR_EMPTY(contact_uri)) { LM_DBG("sca_call_info_invite_handler: Contact header is empty. " - "(From: %.*s To: %.*s)\n", STR_FMT(from_aor), - STR_FMT(to_aor)); + "(From: %.*s To: %.*s)\n", + STR_FMT(from_aor), STR_FMT(to_aor)); return (1); } - if (msg->first_line.type == SIP_REQUEST) { - rc = sca_call_info_invite_request_handler(msg, call_info, from, to, - from_aor, to_aor, contact_uri); + if(msg->first_line.type == SIP_REQUEST) { + rc = sca_call_info_invite_request_handler( + msg, call_info, from, to, from_aor, to_aor, contact_uri); } else { // XXX replace with dispatch table. - switch (msg->REPLY_STATUS) { - case 100: - rc = 1; - break; - - case 180: - case 183: - rc = sca_call_info_invite_reply_18x_handler(msg, call_info, from, - to, from_aor, to_aor, contact_uri); - break; - - case 200: - rc = sca_call_info_invite_reply_200_handler(msg, call_info, from, - to, from_aor, to_aor, contact_uri); - break; - - case 300: - case 301: - case 302: - // redirection (at least on Polycoms) does not cause caller to - // release its seized appearance. pass it through. - rc = 1; - break; + switch(msg->REPLY_STATUS) { + case 100: + rc = 1; + break; + + case 180: + case 183: + rc = sca_call_info_invite_reply_18x_handler(msg, call_info, + from, to, from_aor, to_aor, contact_uri); + break; + + case 200: + rc = sca_call_info_invite_reply_200_handler(msg, call_info, + from, to, from_aor, to_aor, contact_uri); + break; + + case 300: + case 301: + case 302: + // redirection (at least on Polycoms) does not cause caller to + // release its seized appearance. pass it through. + rc = 1; + break; - default: - rc = sca_call_info_invite_reply_error_handler(msg, call_info, from, - to, from_aor, to_aor, contact_uri); - break; + default: + rc = sca_call_info_invite_reply_error_handler(msg, call_info, + from, to, from_aor, to_aor, contact_uri); + break; } } @@ -1483,40 +1529,39 @@ static int sca_call_info_bye_handler(sip_msg_t *msg, sca_call_info *call_info, int slot_idx = -1; int rc = -1; - if (msg->first_line.type == SIP_REQUEST) { - if (SCA_CALL_INFO_IS_SHARED_CALLER(call_info)) { + if(msg->first_line.type == SIP_REQUEST) { + if(SCA_CALL_INFO_IS_SHARED_CALLER(call_info)) { slot_idx = sca_uri_lock_shared_appearance(sca, from_aor); - if (slot_idx < 0) { + if(slot_idx < 0) { LM_ERR("sca_call_info_bye_handler: failed to acquire " - "lock for %.*s, appearance-index %.d\n", + "lock for %.*s, appearance-index %.d\n", STR_FMT(from_aor), call_info->index); goto done; } - if (call_info->index != SCA_CALL_INFO_APPEARANCE_INDEX_ANY) { - app = sca_appearance_for_index_unsafe(sca, from_aor, - call_info->index, slot_idx); + if(call_info->index != SCA_CALL_INFO_APPEARANCE_INDEX_ANY) { + app = sca_appearance_for_index_unsafe( + sca, from_aor, call_info->index, slot_idx); } - if (app == NULL) { + if(app == NULL) { // try to find it by tags app = sca_appearance_for_tags_unsafe(sca, from_aor, &msg->callid->body, &from->tag_value, NULL, slot_idx); } - if (app == NULL) { + if(app == NULL) { LM_ERR("sca_call_info_bye_handler: %.*s " - "dialog leg %.*s;%.*s is not active\n", - STR_FMT(from_aor), - STR_FMT(&msg->callid->body), + "dialog leg %.*s;%.*s is not active\n", + STR_FMT(from_aor), STR_FMT(&msg->callid->body), STR_FMT(&from->tag_value)); goto done; } - if (SCA_STR_EQ(&app->dialog.call_id, &msg->callid->body)) { + if(SCA_STR_EQ(&app->dialog.call_id, &msg->callid->body)) { // XXX yes, duplicated below, too - if (!sca_appearance_list_unlink_appearance(app->appearance_list, - &app)) { + if(!sca_appearance_list_unlink_appearance( + app->appearance_list, &app)) { LM_ERR("sca_call_info_bye_handler: failed to unlink " - "%.*s appearance-index %d, owner %.*s\n", + "%.*s appearance-index %d, owner %.*s\n", STR_FMT(&app->owner), app->index, STR_FMT(&app->owner)); goto done; @@ -1526,21 +1571,22 @@ static int sca_call_info_bye_handler(sip_msg_t *msg, sca_call_info *call_info, sca_hash_table_unlock_index(sca->appearances, slot_idx); slot_idx = -1; - if (sca_notify_call_info_subscribers(sca, from_aor) < 0) { + if(sca_notify_call_info_subscribers(sca, from_aor) < 0) { LM_ERR("Failed to call-info NOTIFY %.*s subscribers " - "on BYE\n", STR_FMT(&to->uri)); + "on BYE\n", + STR_FMT(&to->uri)); goto done; } } } - if (slot_idx >= 0) { + if(slot_idx >= 0) { sca_hash_table_unlock_index(sca->appearances, slot_idx); slot_idx = -1; } - if (SCA_CALL_INFO_IS_SHARED_CALLEE(call_info)) { - if (!sca_uri_lock_if_shared_appearance(sca, to_aor, &slot_idx)) { + if(SCA_CALL_INFO_IS_SHARED_CALLEE(call_info)) { + if(!sca_uri_lock_if_shared_appearance(sca, to_aor, &slot_idx)) { LM_DBG("BYE from non-SCA %.*s to non-SCA %.*s\n", STR_FMT(from_aor), STR_FMT(to_aor)); rc = 1; @@ -1548,9 +1594,8 @@ static int sca_call_info_bye_handler(sip_msg_t *msg, sca_call_info *call_info, } app = sca_appearance_for_tags_unsafe(sca, to_aor, - &msg->callid->body, &to->tag_value, - NULL, slot_idx); - if (app == NULL) { + &msg->callid->body, &to->tag_value, NULL, slot_idx); + if(app == NULL) { LM_INFO("sca_call_info_bye_handler: no in-use callee " "appearance for BYE %.*s from %.*s, call-ID %.*s\n", STR_FMT(to_aor), STR_FMT(from_aor), @@ -1559,11 +1604,11 @@ static int sca_call_info_bye_handler(sip_msg_t *msg, sca_call_info *call_info, goto done; } - if (SCA_STR_EQ(&app->dialog.call_id, &msg->callid->body)) { - if (!sca_appearance_list_unlink_appearance(app->appearance_list, - &app)) { + if(SCA_STR_EQ(&app->dialog.call_id, &msg->callid->body)) { + if(!sca_appearance_list_unlink_appearance( + app->appearance_list, &app)) { LM_ERR("sca_call_info_bye_handler: failed to unlink " - "%.*s appearance-index %d, owner %.*s\n", + "%.*s appearance-index %d, owner %.*s\n", STR_FMT(&app->owner), app->index, STR_FMT(&app->owner)); goto done; @@ -1573,29 +1618,29 @@ static int sca_call_info_bye_handler(sip_msg_t *msg, sca_call_info *call_info, sca_hash_table_unlock_index(sca->appearances, slot_idx); slot_idx = -1; - if (sca_notify_call_info_subscribers(sca, to_aor) < 0) { + if(sca_notify_call_info_subscribers(sca, to_aor) < 0) { LM_ERR("Failed to call-info NOTIFY %.*s subscribers " - "on BYE\n", STR_FMT(to_aor)); + "on BYE\n", + STR_FMT(to_aor)); goto done; } } } } else { // this is just a backup to catch anything missed on the BYE request - if (SCA_CALL_INFO_IS_SHARED_CALLEE(call_info)) { + if(SCA_CALL_INFO_IS_SHARED_CALLEE(call_info)) { slot_idx = sca_hash_table_index_for_key(sca->appearances, to_aor); sca_hash_table_lock_index(sca->appearances, slot_idx); - app = sca_appearance_for_index_unsafe(sca, to_aor, call_info->index, - slot_idx); - if (app == NULL) { + app = sca_appearance_for_index_unsafe( + sca, to_aor, call_info->index, slot_idx); + if(app == NULL) { app = sca_appearance_for_tags_unsafe(sca, to_aor, - &msg->callid->body, &to->tag_value, - NULL, slot_idx); + &msg->callid->body, &to->tag_value, NULL, slot_idx); } - if (app == NULL) { + if(app == NULL) { LM_DBG("sca_call_info_bye_handler: no appearance found " - "for callee %.*s, call-ID %.*s\n", + "for callee %.*s, call-ID %.*s\n", STR_FMT(to_aor), STR_FMT(&msg->callid->body)); rc = 1; goto done; @@ -1605,11 +1650,11 @@ static int sca_call_info_bye_handler(sip_msg_t *msg, sca_call_info *call_info, "for callee %.*s, call-ID %.*s\n", STR_FMT(to_aor), STR_FMT(&msg->callid->body)); - if (SCA_STR_EQ(&app->dialog.call_id, &msg->callid->body)) { - if (!sca_appearance_list_unlink_appearance(app->appearance_list, - &app)) { + if(SCA_STR_EQ(&app->dialog.call_id, &msg->callid->body)) { + if(!sca_appearance_list_unlink_appearance( + app->appearance_list, &app)) { LM_ERR("sca_call_info_bye_handler: failed to unlink " - "%.*s appearance-index %d, owner %.*s\n", + "%.*s appearance-index %d, owner %.*s\n", STR_FMT(&app->owner), app->index, STR_FMT(&app->owner)); goto done; @@ -1619,9 +1664,10 @@ static int sca_call_info_bye_handler(sip_msg_t *msg, sca_call_info *call_info, sca_hash_table_unlock_index(sca->appearances, slot_idx); slot_idx = -1; - if (sca_notify_call_info_subscribers(sca, to_aor) < 0) { + if(sca_notify_call_info_subscribers(sca, to_aor) < 0) { LM_ERR("Failed to call-info NOTIFY %.*s subscribers " - "on BYE\n", STR_FMT(to_aor)); + "on BYE\n", + STR_FMT(to_aor)); goto done; } } @@ -1630,7 +1676,8 @@ static int sca_call_info_bye_handler(sip_msg_t *msg, sca_call_info *call_info, rc = 1; - done: if (slot_idx >= 0) { +done: + if(slot_idx >= 0) { sca_hash_table_unlock_index(sca->appearances, slot_idx); } @@ -1644,36 +1691,38 @@ static int sca_call_info_cancel_handler(sip_msg_t *msg, sca_appearance *app; int rc = 1; - if (msg->first_line.type != SIP_REQUEST) { + if(msg->first_line.type != SIP_REQUEST) { return (1); } // Polycom SCA CANCELs as of sip.ld 3.3.4 don't include Call-Info headers; // find appearance by dialog if Call-Info not present. // XXX also handle CANCEL w/ Call-Info header? Some UAs might send it - if (SCA_CALL_INFO_IS_SHARED_CALLER(call_info)) { - app = sca_appearance_unlink_by_tags(sca, from_aor, &msg->callid->body, - &from->tag_value, NULL); - if (app) { + if(SCA_CALL_INFO_IS_SHARED_CALLER(call_info)) { + app = sca_appearance_unlink_by_tags( + sca, from_aor, &msg->callid->body, &from->tag_value, NULL); + if(app) { sca_appearance_free(app); - if (sca_notify_call_info_subscribers(sca, from_aor) < 0) { - LM_ERR("Failed to call-info NOTIFY %.*s subscribers on CANCEL\n", + if(sca_notify_call_info_subscribers(sca, from_aor) < 0) { + LM_ERR("Failed to call-info NOTIFY %.*s subscribers on " + "CANCEL\n", STR_FMT(from_aor)); rc = -1; } } } - if (!SCA_STR_EMPTY(&to->tag_value) + if(!SCA_STR_EMPTY(&to->tag_value) && sca_uri_is_shared_appearance(sca, to_aor)) { - app = sca_appearance_unlink_by_tags(sca, to_aor, &msg->callid->body, - &to->tag_value, NULL); - if (app) { + app = sca_appearance_unlink_by_tags( + sca, to_aor, &msg->callid->body, &to->tag_value, NULL); + if(app) { sca_appearance_free(app); - if (sca_notify_call_info_subscribers(sca, to_aor) < 0) { - LM_ERR("Failed to call-info NOTIFY %.*s subscribers on CANCEL\n", + if(sca_notify_call_info_subscribers(sca, to_aor) < 0) { + LM_ERR("Failed to call-info NOTIFY %.*s subscribers on " + "CANCEL\n", STR_FMT(to_aor)); rc = -1; } @@ -1685,71 +1734,74 @@ static int sca_call_info_cancel_handler(sip_msg_t *msg, void sca_call_info_sl_reply_cb(void *cb_arg) { - sl_cbp_t *slcbp = (sl_cbp_t *) cb_arg; + sl_cbp_t *slcbp = (sl_cbp_t *)cb_arg; sip_msg_t *msg; struct to_body *from; struct to_body *to; str aor = STR_NULL; str contact_uri = STR_NULL; - if (slcbp == NULL) { + if(slcbp == NULL) { return; } - if (slcbp->type != SLCB_REPLY_READY) { + if(slcbp->type != SLCB_REPLY_READY) { return; } // for now, it appears we only need this during INVITEs... - if (slcbp->req->REQ_METHOD != METHOD_INVITE) { + if(slcbp->req->REQ_METHOD != METHOD_INVITE) { return; } // ...and even then only on error - if (slcbp->code < 400 || slcbp->code == 401 || slcbp->code == 407) { + if(slcbp->code < 400 || slcbp->code == 401 || slcbp->code == 407) { // LM_DBG("sca_call_info_sl_reply_cb: ignoring stateless reply with " // "status %d %.*s\n", slcbp->code, STR_FMT(slcbp->reason)); return; } msg = slcbp->req; - if (sca_get_msg_from_header(msg, &from) < 0) { + if(sca_get_msg_from_header(msg, &from) < 0) { LM_ERR("sca_call_info_sl_reply_cb: failed to get From header from " - "request before stateless reply with %d %.*s\n", + "request before stateless reply with %d %.*s\n", slcbp->code, STR_FMT(slcbp->reason)); return; } - if (sca_uri_extract_aor(&from->uri, &aor) < 0) { + if(sca_uri_extract_aor(&from->uri, &aor) < 0) { LM_ERR("sca_call_info_sl_reply_cb: failed to extract AoR " - "from URI %.*s\n", STR_FMT(&from->uri)); + "from URI %.*s\n", + STR_FMT(&from->uri)); return; } - if (!sca_uri_is_shared_appearance(sca, &aor)) { + if(!sca_uri_is_shared_appearance(sca, &aor)) { // LM_DBG("sca_call_info_sl_reply_cb: ignoring non-shared appearance " // "%.*s", STR_FMT(&aor)); return; } - if (sca_get_msg_contact_uri(msg, &contact_uri) < 0) { + if(sca_get_msg_contact_uri(msg, &contact_uri) < 0) { LM_ERR("sca_call_info_sl_reply_cb: failed to get Contact from " - "request before stateless reply with %d %.*s\n", + "request before stateless reply with %d %.*s\n", slcbp->code, STR_FMT(slcbp->reason)); return; } - if (sca_get_msg_to_header(msg, &to) < 0) { + if(sca_get_msg_to_header(msg, &to) < 0) { LM_ERR("sca_call_info_sl_reply_cb: failed to get To header from " - "request before stateless reply with %d %.*s\n", + "request before stateless reply with %d %.*s\n", slcbp->code, STR_FMT(slcbp->reason)); return; } - if (sca_subscription_terminate(sca, &aor, SCA_EVENT_TYPE_LINE_SEIZE, - &contact_uri, SCA_SUBSCRIPTION_STATE_TERMINATED_NORESOURCE, - SCA_SUBSCRIPTION_TERMINATE_OPT_DEFAULT) < 0) { + if(sca_subscription_terminate(sca, &aor, SCA_EVENT_TYPE_LINE_SEIZE, + &contact_uri, SCA_SUBSCRIPTION_STATE_TERMINATED_NORESOURCE, + SCA_SUBSCRIPTION_TERMINATE_OPT_DEFAULT) + < 0) { LM_ERR("sca_call_info_sl_reply_cb: failed to terminate " - "line-seize subscription for %.*s\n", STR_FMT(&contact_uri)); + "line-seize subscription for %.*s\n", + STR_FMT(&contact_uri)); return; } } @@ -1768,7 +1820,8 @@ static inline int sca_call_info_refer_handler(sip_msg_t *msg, return (1); } -struct sca_call_info_dispatch { +struct sca_call_info_dispatch +{ int method; int (*handler)(sip_msg_t *, sca_call_info *, struct to_body *, struct to_body *, str *, str *, str *); @@ -1782,12 +1835,12 @@ struct sca_call_info_dispatch call_info_dispatch[] = { {METHOD_REFER, sca_call_info_refer_handler}, }; -#define SCA_CALL_INFO_UPDATE_FLAG_DEFAULT 0 -#define SCA_CALL_INFO_UPDATE_FLAG_FROM_ALLOC (1 << 0) -#define SCA_CALL_INFO_UPDATE_FLAG_TO_ALLOC (1 << 1) +#define SCA_CALL_INFO_UPDATE_FLAG_DEFAULT 0 +#define SCA_CALL_INFO_UPDATE_FLAG_FROM_ALLOC (1 << 0) +#define SCA_CALL_INFO_UPDATE_FLAG_TO_ALLOC (1 << 1) -int sca_call_info_update(sip_msg_t *msg, int update_mask, str *uri_to, - str *uri_from) +int sca_call_info_update( + sip_msg_t *msg, int update_mask, str *uri_to, str *uri_from) { sca_call_info call_info; hdr_field_t *call_info_hdr; @@ -1807,102 +1860,100 @@ int sca_call_info_update(sip_msg_t *msg, int update_mask, str *uri_to, method = sca_get_msg_method(msg); n_dispatch = sizeof(call_info_dispatch) / sizeof(call_info_dispatch[0]); - for (i = 0; i < n_dispatch; i++) { - if (method == call_info_dispatch[i].method) { + for(i = 0; i < n_dispatch; i++) { + if(method == call_info_dispatch[i].method) { break; } } - if (i >= n_dispatch) { - if(msg->cseq==NULL && ((parse_headers(msg, HDR_CSEQ_F, 0)==-1) || - (msg->cseq==NULL))) - { + if(i >= n_dispatch) { + if(msg->cseq == NULL + && ((parse_headers(msg, HDR_CSEQ_F, 0) == -1) + || (msg->cseq == NULL))) { LM_ERR("no CSEQ header\n"); return (1); } LM_DBG("BUG: sca module does not support Call-Info headers " - "in %.*s requests\n", STR_FMT(&get_cseq(msg)->method)); + "in %.*s requests\n", + STR_FMT(&get_cseq(msg)->method)); return (1); } - if (parse_headers(msg, HDR_EOH_F, 0) < 0) { + if(parse_headers(msg, HDR_EOH_F, 0) < 0) { LM_ERR("header parsing failed: bad request\n"); return (-1); } - if (update_mask != SCA_CALL_INFO_SHARED_BOTH) { - switch (update_mask) { - case SCA_CALL_INFO_SHARED_NONE: - update_mask = SCA_CALL_INFO_SHARED_BOTH; - break; + if(update_mask != SCA_CALL_INFO_SHARED_BOTH) { + switch(update_mask) { + case SCA_CALL_INFO_SHARED_NONE: + update_mask = SCA_CALL_INFO_SHARED_BOTH; + break; - case SCA_CALL_INFO_SHARED_CALLER: - case SCA_CALL_INFO_SHARED_CALLEE: - break; + case SCA_CALL_INFO_SHARED_CALLER: + case SCA_CALL_INFO_SHARED_CALLEE: + break; - default: - LM_ERR("sca_call_info_update: argument 1: invalid value " - "(0, 1 or 2 expected)\n"); - return (-1); + default: + LM_ERR("sca_call_info_update: argument 1: invalid value " + "(0, 1 or 2 expected)\n"); + return (-1); } } memset(&call_info, 0, sizeof(sca_call_info)); call_info_hdr = get_hdr(msg, HDR_CALLINFO_T); - if (!SCA_HEADER_EMPTY(call_info_hdr)) { + if(!SCA_HEADER_EMPTY(call_info_hdr)) { // this needs to accomodate comma-separated appearance info - if (sca_call_info_body_parse(&call_info_hdr->body, &call_info) < 0) { + if(sca_call_info_body_parse(&call_info_hdr->body, &call_info) < 0) { LM_ERR("Bad Call-Info header body: %.*s\n", STR_FMT(&call_info_hdr->body)); return (-1); } } - if (uri_from != NULL) { - if(sca_build_to_body_from_uri(msg, &from, uri_from)<0){ + if(uri_from != NULL) { + if(sca_build_to_body_from_uri(msg, &from, uri_from) < 0) { LM_ERR("Bad From uri from param\n"); return (-1); } LM_DBG("from[%.*s] param\n", STR_FMT(uri_from)); to_body_flags |= SCA_CALL_INFO_UPDATE_FLAG_FROM_ALLOC; - if (sca_uri_extract_aor(&from->uri, &from_aor) < 0) { + if(sca_uri_extract_aor(&from->uri, &from_aor) < 0) { LM_ERR("Failed to extract AoR from From URI %.*s\n", STR_FMT(&from->uri)); goto done; } - } - else if (sca_get_msg_from_header(msg, &from) < 0) { + } else if(sca_get_msg_from_header(msg, &from) < 0) { LM_ERR("Bad From header\n"); return (-1); } - if (uri_to != NULL) { - if(sca_build_to_body_from_uri(msg, &to, uri_to)<0){ + if(uri_to != NULL) { + if(sca_build_to_body_from_uri(msg, &to, uri_to) < 0) { LM_ERR("Bad From uri to param\n"); goto done; } LM_DBG("to[%.*s] param\n", STR_FMT(uri_to)); to_body_flags |= SCA_CALL_INFO_UPDATE_FLAG_TO_ALLOC; - if (sca_uri_extract_aor(&to->uri, &to_aor) < 0) { + if(sca_uri_extract_aor(&to->uri, &to_aor) < 0) { LM_ERR("Failed to extract AoR from To URI %.*s\n", STR_FMT(&to->uri)); goto done; } - } - else if (sca_get_msg_to_header(msg, &to) < 0) { + } else if(sca_get_msg_to_header(msg, &to) < 0) { LM_ERR("Bad To header\n"); goto done; } memset(&c_uri, 0, sizeof(sip_uri_t)); rc = sca_get_msg_contact_uri(msg, &contact_uri); - if (rc > 0) { + if(rc > 0) { // Contact header in packet - if (parse_uri(contact_uri.s, contact_uri.len, &c_uri) < 0) { - LM_ERR("Failed to parse Contact URI %.*s\n", - STR_FMT(&contact_uri)); + if(parse_uri(contact_uri.s, contact_uri.len, &c_uri) < 0) { + LM_ERR("Failed to parse Contact URI %.*s\n", STR_FMT(&contact_uri)); rc = -1; goto done; } - } else if (rc < 0) { + } else if(rc < 0) { LM_ERR("Bad Contact\n"); goto done; } @@ -1910,109 +1961,110 @@ int sca_call_info_update(sip_msg_t *msg, int update_mask, str *uri_to, rc = -1; // reconcile mismatched Contact users and To/From URIs - if (msg->first_line.type == SIP_REQUEST) { - if (uri_from==NULL) { - if (sca_create_canonical_aor(msg, &from_aor) < 0) { + if(msg->first_line.type == SIP_REQUEST) { + if(uri_from == NULL) { + if(sca_create_canonical_aor(msg, &from_aor) < 0) { goto done; } aor_flags |= SCA_CALL_INFO_UPDATE_FLAG_FROM_ALLOC; } - if (uri_to==NULL) { - if (sca_uri_extract_aor(&to->uri, &to_aor) < 0) { + if(uri_to == NULL) { + if(sca_uri_extract_aor(&to->uri, &to_aor) < 0) { LM_ERR("Failed to extract AoR from To URI %.*s\n", STR_FMT(&to->uri)); goto done; } } } else { - if (uri_from==NULL) { - if (sca_uri_extract_aor(&from->uri, &from_aor) < 0) { + if(uri_from == NULL) { + if(sca_uri_extract_aor(&from->uri, &from_aor) < 0) { LM_ERR("Failed to extract AoR from From URI %.*s\n", STR_FMT(&from->uri)); goto done; } } - if (uri_to==NULL) { - if (sca_create_canonical_aor(msg, &to_aor) < 0) { + if(uri_to == NULL) { + if(sca_create_canonical_aor(msg, &to_aor) < 0) { goto done; } aor_flags |= SCA_CALL_INFO_UPDATE_FLAG_TO_ALLOC; } } - LM_DBG("to_aor[%.*s] from_aor[%.*s]\n", - STR_FMT(&to_aor), STR_FMT(&from_aor)); + LM_DBG("to_aor[%.*s] from_aor[%.*s]\n", STR_FMT(&to_aor), + STR_FMT(&from_aor)); // early check to see if we're dealing with any SCA endpoints - if (sca_uri_is_shared_appearance(sca, &from_aor)) { - if ((update_mask & SCA_CALL_INFO_SHARED_CALLER)) { + if(sca_uri_is_shared_appearance(sca, &from_aor)) { + if((update_mask & SCA_CALL_INFO_SHARED_CALLER)) { call_info.ua_shared |= SCA_CALL_INFO_SHARED_CALLER; } } - if (sca_uri_is_shared_appearance(sca, &to_aor)) { - if ((update_mask & SCA_CALL_INFO_SHARED_CALLEE)) { + if(sca_uri_is_shared_appearance(sca, &to_aor)) { + if((update_mask & SCA_CALL_INFO_SHARED_CALLEE)) { call_info.ua_shared |= SCA_CALL_INFO_SHARED_CALLEE; } } - if (call_info_hdr == NULL) { - if (SCA_CALL_INFO_IS_SHARED_CALLER(&call_info) && - msg->first_line.type == SIP_REQUEST) { - if (!sca_subscription_aor_has_subscribers(SCA_EVENT_TYPE_CALL_INFO, - &from_aor)) { + if(call_info_hdr == NULL) { + if(SCA_CALL_INFO_IS_SHARED_CALLER(&call_info) + && msg->first_line.type == SIP_REQUEST) { + if(!sca_subscription_aor_has_subscribers( + SCA_EVENT_TYPE_CALL_INFO, &from_aor)) { call_info.ua_shared &= ~SCA_CALL_INFO_SHARED_CALLER; sca_appearance_unregister(sca, &from_aor); } - } else if (SCA_CALL_INFO_IS_SHARED_CALLEE(&call_info) && - msg->first_line.type == SIP_REPLY) { - if (!sca_subscription_aor_has_subscribers(SCA_EVENT_TYPE_CALL_INFO, - &to_aor)) { + } else if(SCA_CALL_INFO_IS_SHARED_CALLEE(&call_info) + && msg->first_line.type == SIP_REPLY) { + if(!sca_subscription_aor_has_subscribers( + SCA_EVENT_TYPE_CALL_INFO, &to_aor)) { call_info.ua_shared &= ~SCA_CALL_INFO_SHARED_CALLEE; sca_appearance_unregister(sca, &to_aor); } } } - if (sca_call_info_header_remove(msg) < 0) { + if(sca_call_info_header_remove(msg) < 0) { LM_ERR("Failed to remove Call-Info header\n"); goto done; } - if (call_info.ua_shared == SCA_CALL_INFO_SHARED_NONE) { - LM_DBG("Neither %.*s nor %.*s are SCA AoRs\n", - STR_FMT(&from_aor), STR_FMT(&to_aor)); + if(call_info.ua_shared == SCA_CALL_INFO_SHARED_NONE) { + LM_DBG("Neither %.*s nor %.*s are SCA AoRs\n", STR_FMT(&from_aor), + STR_FMT(&to_aor)); goto done; } - LM_DBG( "Calling Dispatch Id: %d handler with From-AOR: %.*s To-AOR: %.*s " - "From-URI: <%.*s> To-URI: <%.*s> Contact-URI: <%.*s>\n", - i, STR_FMT(&from_aor), STR_FMT(&to_aor),STR_FMT(&from->uri), + LM_DBG("Calling Dispatch Id: %d handler with From-AOR: %.*s To-AOR: %.*s " + "From-URI: <%.*s> To-URI: <%.*s> Contact-URI: <%.*s>\n", + i, STR_FMT(&from_aor), STR_FMT(&to_aor), STR_FMT(&from->uri), STR_FMT(&to->uri), STR_FMT(&contact_uri)); - rc = call_info_dispatch[i].handler(msg, &call_info, from, to, &from_aor, - &to_aor, &contact_uri); - if (rc < 0) { + rc = call_info_dispatch[i].handler( + msg, &call_info, from, to, &from_aor, &to_aor, &contact_uri); + if(rc < 0) { LM_ERR("Failed to update Call-Info state for %.*s\n", STR_FMT(&contact_uri)); } - done: if ((aor_flags & SCA_CALL_INFO_UPDATE_FLAG_FROM_ALLOC)) { - if (from_aor.s != NULL) { +done: + if((aor_flags & SCA_CALL_INFO_UPDATE_FLAG_FROM_ALLOC)) { + if(from_aor.s != NULL) { pkg_free(from_aor.s); } } - if ((aor_flags & SCA_CALL_INFO_UPDATE_FLAG_TO_ALLOC)) { - if (to_aor.s != NULL) { + if((aor_flags & SCA_CALL_INFO_UPDATE_FLAG_TO_ALLOC)) { + if(to_aor.s != NULL) { pkg_free(to_aor.s); } } - if ((to_body_flags & SCA_CALL_INFO_UPDATE_FLAG_FROM_ALLOC)) { - if (from != NULL) { + if((to_body_flags & SCA_CALL_INFO_UPDATE_FLAG_FROM_ALLOC)) { + if(from != NULL) { free_to(from); } } - if ((to_body_flags & SCA_CALL_INFO_UPDATE_FLAG_TO_ALLOC)) { - if (to != NULL) { + if((to_body_flags & SCA_CALL_INFO_UPDATE_FLAG_TO_ALLOC)) { + if(to != NULL) { free_to(to); } } diff --git a/src/modules/sca/sca_call_info.h b/src/modules/sca/sca_call_info.h index f12bceb86..914f36f0b 100644 --- a/src/modules/sca/sca_call_info.h +++ b/src/modules/sca/sca_call_info.h @@ -24,9 +24,10 @@ #include "sca_subscribe.h" // pass to sca_notify_subscriber to include all appearances in Call-Info hdr -#define SCA_CALL_INFO_APPEARANCE_INDEX_ANY 0 +#define SCA_CALL_INFO_APPEARANCE_INDEX_ANY 0 -enum { +enum +{ SCA_CALL_INFO_SHARED_NONE = 0, SCA_CALL_INFO_SHARED_CALLER = (1 << 0), SCA_CALL_INFO_SHARED_CALLEE = (1 << 1), @@ -34,7 +35,8 @@ enum { #define SCA_CALL_INFO_SHARED_BOTH \ (SCA_CALL_INFO_SHARED_CALLER | SCA_CALL_INFO_SHARED_CALLEE) -struct _sca_call_info { +struct _sca_call_info +{ str sca_uri; int index; int state; @@ -44,28 +46,30 @@ struct _sca_call_info { }; typedef struct _sca_call_info sca_call_info; -#define SCA_CALL_INFO_EMPTY(ci1) \ - ((void*)(ci1) == NULL || \ - ((ci1)->index == SCA_CALL_INFO_APPEARANCE_INDEX_ANY && \ - (ci1)->state == SCA_APPEARANCE_STATE_UNKNOWN)) +#define SCA_CALL_INFO_EMPTY(ci1) \ + ((void *)(ci1) == NULL \ + || ((ci1)->index == SCA_CALL_INFO_APPEARANCE_INDEX_ANY \ + && (ci1)->state == SCA_APPEARANCE_STATE_UNKNOWN)) -#define SCA_CALL_INFO_IS_SHARED_CALLER(ci1) \ - (!SCA_CALL_INFO_EMPTY((ci1)) && \ - (((sca_call_info *)(ci1))->ua_shared & SCA_CALL_INFO_SHARED_CALLER)) +#define SCA_CALL_INFO_IS_SHARED_CALLER(ci1) \ + (!SCA_CALL_INFO_EMPTY((ci1)) \ + && (((sca_call_info *)(ci1))->ua_shared \ + & SCA_CALL_INFO_SHARED_CALLER)) -#define SCA_CALL_INFO_IS_SHARED_CALLEE(ci1) \ - (!SCA_CALL_INFO_EMPTY((ci1)) && \ - (((sca_call_info *)(ci1))->ua_shared & SCA_CALL_INFO_SHARED_CALLEE)) +#define SCA_CALL_INFO_IS_SHARED_CALLEE(ci1) \ + (!SCA_CALL_INFO_EMPTY((ci1)) \ + && (((sca_call_info *)(ci1))->ua_shared \ + & SCA_CALL_INFO_SHARED_CALLEE)) extern const str SCA_CALL_INFO_HEADER_STR; -int sca_call_info_update(sip_msg_t *, int, str*, str*); +int sca_call_info_update(sip_msg_t *, int, str *, str *); void sca_call_info_sl_reply_cb(void *); void sca_call_info_ack_cb(struct cell *, int, struct tmcb_params *); int sca_call_info_build_header(sca_mod *, sca_subscription *, char *, int); -int sca_call_info_append_header_for_appearance_index(sca_subscription *, int, - char *, int); +int sca_call_info_append_header_for_appearance_index( + sca_subscription *, int, char *, int); int sca_call_info_body_parse(str *, sca_call_info *); int sca_call_info_free(sca_call_info *); diff --git a/src/modules/sca/sca_common.h b/src/modules/sca/sca_common.h index acf967b85..5c4520a87 100644 --- a/src/modules/sca/sca_common.h +++ b/src/modules/sca/sca_common.h @@ -52,45 +52,43 @@ #define SCA_STRUCT_PTR_OFFSET(struct1, cast1, offset1) \ (cast1)(struct1) + (offset1) -#define SCA_STR_COPY(str1, str2) \ +#define SCA_STR_COPY(str1, str2) \ memcpy((str1)->s, (str2)->s, (str2)->len); \ (str1)->len = (str2)->len; -#define SCA_STR_APPEND(str1, str2) \ +#define SCA_STR_APPEND(str1, str2) \ memcpy((str1)->s + (str1)->len, (str2)->s, (str2)->len); \ (str1)->len += (str2)->len; -#define SCA_STR_APPEND_L(str1, str1_lim, s2, s2_len) \ - if ((str1)->len + (s2_len) >= (str1_lim)) { \ +#define SCA_STR_APPEND_L(str1, str1_lim, s2, s2_len) \ + if((str1)->len + (s2_len) >= (str1_lim)) { \ LM_ERR("Failed to append to str: too long\n"); \ - } else { \ - SCA_STR_APPEND((str1), (s2), (s2_len)); \ - (str1_lim) -= (s2_len); \ + } else { \ + SCA_STR_APPEND((str1), (s2), (s2_len)); \ + (str1_lim) -= (s2_len); \ } -#define SCA_STR_COPY_CSTR(str1, cstr1) \ +#define SCA_STR_COPY_CSTR(str1, cstr1) \ memcpy((str1)->s + (str1)->len, (cstr1), strlen((cstr1))); \ (str1)->len += strlen((cstr1)); -#define SCA_STR_APPEND_CSTR(str1, cstr1) \ - SCA_STR_COPY_CSTR((str1), (cstr1)) +#define SCA_STR_APPEND_CSTR(str1, cstr1) SCA_STR_COPY_CSTR((str1), (cstr1)) -#define SCA_STR_APPEND_CSTR_L(str1, str1_lim, cstr1) \ - if ((str1)->len + strlen(cstr1) >= (str1_lim)) { \ +#define SCA_STR_APPEND_CSTR_L(str1, str1_lim, cstr1) \ + if((str1)->len + strlen(cstr1) >= (str1_lim)) { \ LM_ERR("Failed to append to str: too long\n"); \ - } else { \ - SCA_STR_APPEND_CSTR((str1), (cstr1)); \ + } else { \ + SCA_STR_APPEND_CSTR((str1), (cstr1)); \ } // STR_EQ assumes we're not using str pointers, which is obnoxious -#define SCA_STR_EQ(str1, str2) \ - (((str1)->len == (str2)->len) && \ - memcmp((str1)->s, (str2)->s, (str1)->len) == 0) +#define SCA_STR_EQ(str1, str2) \ + (((str1)->len == (str2)->len) \ + && memcmp((str1)->s, (str2)->s, (str1)->len) == 0) #define SCA_STR_EMPTY(str1) \ ((str1) == NULL || ((str1)->s == NULL || (str1)->len <= 0)) -#define SCA_HEADER_EMPTY(hdr1) \ - ((hdr1) == NULL || SCA_STR_EMPTY(&(hdr1)->body)) +#define SCA_HEADER_EMPTY(hdr1) ((hdr1) == NULL || SCA_STR_EMPTY(&(hdr1)->body)) #endif // SCA_COMMON_H diff --git a/src/modules/sca/sca_db.c b/src/modules/sca/sca_db.c index ce40d9a04..2dc107b81 100644 --- a/src/modules/sca/sca_db.c +++ b/src/modules/sca/sca_db.c @@ -38,102 +38,103 @@ const str SCA_DB_NOTIFY_CSEQ_COL_NAME = STR_STATIC_INIT("notify_cseq"); const str SCA_DB_SUBSCRIBE_CSEQ_COL_NAME = STR_STATIC_INIT("subscribe_cseq"); const str SCA_DB_SERVER_ID_COL_NAME = STR_STATIC_INIT("server_id"); -void sca_db_subscriptions_get_value_for_column(int column, db_val_t *row_values, - void *column_value) +void sca_db_subscriptions_get_value_for_column( + int column, db_val_t *row_values, void *column_value) { assert(column_value != NULL); assert(row_values != NULL); assert(column >= 0 && column < SCA_DB_SUBS_BOUNDARY); - switch (column) { - case SCA_DB_SUBS_SUBSCRIBER_COL: - case SCA_DB_SUBS_AOR_COL: - case SCA_DB_SUBS_CALL_ID_COL: - case SCA_DB_SUBS_FROM_TAG_COL: - case SCA_DB_SUBS_TO_TAG_COL: - case SCA_DB_SUBS_RECORD_ROUTE_COL: - ((str *) column_value)->s = (char *) row_values[column].val.string_val; - ((str *) column_value)->len = strlen(((str *) column_value)->s); - break; - - case SCA_DB_SUBS_EXPIRES_COL: - *((time_t *) column_value) = row_values[column].val.time_val; - break; - - case SCA_DB_SUBS_EVENT_COL: - case SCA_DB_SUBS_STATE_COL: - case SCA_DB_SUBS_NOTIFY_CSEQ_COL: - case SCA_DB_SUBS_SUBSCRIBE_CSEQ_COL: - case SCA_DB_SUBS_SERVER_ID_COL: - *((int *) column_value) = row_values[column].val.int_val; - break; - - default: - column_value = NULL; + switch(column) { + case SCA_DB_SUBS_SUBSCRIBER_COL: + case SCA_DB_SUBS_AOR_COL: + case SCA_DB_SUBS_CALL_ID_COL: + case SCA_DB_SUBS_FROM_TAG_COL: + case SCA_DB_SUBS_TO_TAG_COL: + case SCA_DB_SUBS_RECORD_ROUTE_COL: + ((str *)column_value)->s = + (char *)row_values[column].val.string_val; + ((str *)column_value)->len = strlen(((str *)column_value)->s); + break; + + case SCA_DB_SUBS_EXPIRES_COL: + *((time_t *)column_value) = row_values[column].val.time_val; + break; + + case SCA_DB_SUBS_EVENT_COL: + case SCA_DB_SUBS_STATE_COL: + case SCA_DB_SUBS_NOTIFY_CSEQ_COL: + case SCA_DB_SUBS_SUBSCRIBE_CSEQ_COL: + case SCA_DB_SUBS_SERVER_ID_COL: + *((int *)column_value) = row_values[column].val.int_val; + break; + + default: + column_value = NULL; } } -void sca_db_subscriptions_set_value_for_column(int column, db_val_t *row_values, - void *column_value) +void sca_db_subscriptions_set_value_for_column( + int column, db_val_t *row_values, void *column_value) { assert(column >= 0 && column < SCA_DB_SUBS_BOUNDARY); assert(column_value != NULL); assert(row_values != NULL); - switch (column) { - case SCA_DB_SUBS_SUBSCRIBER_COL: - case SCA_DB_SUBS_AOR_COL: - case SCA_DB_SUBS_CALL_ID_COL: - case SCA_DB_SUBS_FROM_TAG_COL: - case SCA_DB_SUBS_TO_TAG_COL: - case SCA_DB_SUBS_RECORD_ROUTE_COL: - row_values[column].val.str_val = *((str *) column_value); - row_values[column].type = DB1_STR; - row_values[column].nul = 0; - break; - - case SCA_DB_SUBS_EXPIRES_COL: - row_values[column].val.int_val = (int) (*((time_t *) column_value)); - row_values[column].type = DB1_INT; - row_values[column].nul = 0; - break; - - case SCA_DB_SUBS_APP_IDX_COL: - // for now, don't save appearance index associated with subscriber - row_values[column].val.int_val = 0; - row_values[column].type = DB1_INT; - row_values[column].nul = 0; - break; - - default: - LM_WARN("sca_db_subscriptions_set_value_for_column: unrecognized " - "column index %d, treating as INT\n", column); - // fall through - - case SCA_DB_SUBS_EVENT_COL: - case SCA_DB_SUBS_STATE_COL: - case SCA_DB_SUBS_NOTIFY_CSEQ_COL: - case SCA_DB_SUBS_SUBSCRIBE_CSEQ_COL: - case SCA_DB_SUBS_SERVER_ID_COL: - row_values[column].val.int_val = *((int *) column_value); - row_values[column].type = DB1_INT; - row_values[column].nul = 0; - break; + switch(column) { + case SCA_DB_SUBS_SUBSCRIBER_COL: + case SCA_DB_SUBS_AOR_COL: + case SCA_DB_SUBS_CALL_ID_COL: + case SCA_DB_SUBS_FROM_TAG_COL: + case SCA_DB_SUBS_TO_TAG_COL: + case SCA_DB_SUBS_RECORD_ROUTE_COL: + row_values[column].val.str_val = *((str *)column_value); + row_values[column].type = DB1_STR; + row_values[column].nul = 0; + break; + + case SCA_DB_SUBS_EXPIRES_COL: + row_values[column].val.int_val = (int)(*((time_t *)column_value)); + row_values[column].type = DB1_INT; + row_values[column].nul = 0; + break; + + case SCA_DB_SUBS_APP_IDX_COL: + // for now, don't save appearance index associated with subscriber + row_values[column].val.int_val = 0; + row_values[column].type = DB1_INT; + row_values[column].nul = 0; + break; + + default: + LM_WARN("sca_db_subscriptions_set_value_for_column: unrecognized " + "column index %d, treating as INT\n", + column); + // fall through + + case SCA_DB_SUBS_EVENT_COL: + case SCA_DB_SUBS_STATE_COL: + case SCA_DB_SUBS_NOTIFY_CSEQ_COL: + case SCA_DB_SUBS_SUBSCRIBE_CSEQ_COL: + case SCA_DB_SUBS_SERVER_ID_COL: + row_values[column].val.int_val = *((int *)column_value); + row_values[column].type = DB1_INT; + row_values[column].nul = 0; + break; } } str **sca_db_subscriptions_columns(void) { - static str *subs_columns[] = {(str *) &SCA_DB_SUBSCRIBER_COL_NAME, - (str *) &SCA_DB_AOR_COL_NAME, (str *) &SCA_DB_EVENT_COL_NAME, - (str *) &SCA_DB_EXPIRES_COL_NAME, (str *) &SCA_DB_STATE_COL_NAME, - (str *) &SCA_DB_APP_IDX_COL_NAME, (str *) &SCA_DB_CALL_ID_COL_NAME, - (str *) &SCA_DB_FROM_TAG_COL_NAME, (str *) &SCA_DB_TO_TAG_COL_NAME, - (str *) &SCA_DB_RECORD_ROUTE_COL_NAME, - (str *) &SCA_DB_NOTIFY_CSEQ_COL_NAME, - (str *) &SCA_DB_SUBSCRIBE_CSEQ_COL_NAME, - (str *) &SCA_DB_SERVER_ID_COL_NAME, - NULL}; + static str *subs_columns[] = {(str *)&SCA_DB_SUBSCRIBER_COL_NAME, + (str *)&SCA_DB_AOR_COL_NAME, (str *)&SCA_DB_EVENT_COL_NAME, + (str *)&SCA_DB_EXPIRES_COL_NAME, (str *)&SCA_DB_STATE_COL_NAME, + (str *)&SCA_DB_APP_IDX_COL_NAME, (str *)&SCA_DB_CALL_ID_COL_NAME, + (str *)&SCA_DB_FROM_TAG_COL_NAME, (str *)&SCA_DB_TO_TAG_COL_NAME, + (str *)&SCA_DB_RECORD_ROUTE_COL_NAME, + (str *)&SCA_DB_NOTIFY_CSEQ_COL_NAME, + (str *)&SCA_DB_SUBSCRIBE_CSEQ_COL_NAME, + (str *)&SCA_DB_SERVER_ID_COL_NAME, NULL}; return (subs_columns); } @@ -143,7 +144,7 @@ db1_con_t *sca_db_get_connection(void) assert(sca && sca->cfg->db_url); assert(sca->db_api && sca->db_api->init); - if (sca_db_con == NULL) { + if(sca_db_con == NULL) { sca_db_con = sca->db_api->init(sca->cfg->db_url); // catch connection error in caller } @@ -151,8 +152,9 @@ db1_con_t *sca_db_get_connection(void) return (sca_db_con); } -void sca_db_disconnect(void) { - if (sca_db_con != NULL) { +void sca_db_disconnect(void) +{ + if(sca_db_con != NULL) { sca->db_api->close(sca_db_con); sca_db_con = NULL; } diff --git a/src/modules/sca/sca_db.h b/src/modules/sca/sca_db.h index 22f83492b..89e47fcf5 100644 --- a/src/modules/sca/sca_db.h +++ b/src/modules/sca/sca_db.h @@ -22,13 +22,14 @@ #include "../../lib/srdb1/db.h" -#define SCA_DB_SUBSCRIPTIONS_TABLE_VERSION 2 +#define SCA_DB_SUBSCRIPTIONS_TABLE_VERSION 2 -#define SCA_DB_SUBSCRIPTIONS_NUM_COLUMNS 13 +#define SCA_DB_SUBSCRIPTIONS_NUM_COLUMNS 13 -#define SCA_DB_DEFAULT_FETCH_ROW_COUNT 1000 +#define SCA_DB_DEFAULT_FETCH_ROW_COUNT 1000 -enum { +enum +{ SCA_DB_SUBS_SUBSCRIBER_COL = 0, SCA_DB_SUBS_AOR_COL = 1, SCA_DB_SUBS_EVENT_COL, @@ -46,25 +47,26 @@ enum { SCA_DB_SUBS_BOUNDARY, }; -enum { +enum +{ SCA_DB_FLAG_NONE = 0, SCA_DB_FLAG_INSERT = 1, SCA_DB_FLAG_UPDATE, SCA_DB_FLAG_DELETE, }; -#define SCA_DB_BIND_STR_VALUE(cv, ct, k, v, c) \ - ((db_key_t *)(k))[ (c) ] = (str *)(ct); \ - ((db_val_t *)(v))[ (c) ].type = DB1_STR; \ - ((db_val_t *)(v))[ (c) ].nul = 0; \ - ((db_val_t *)(v))[ (c) ].val.str_val = (str)(cv); \ +#define SCA_DB_BIND_STR_VALUE(cv, ct, k, v, c) \ + ((db_key_t *)(k))[(c)] = (str *)(ct); \ + ((db_val_t *)(v))[(c)].type = DB1_STR; \ + ((db_val_t *)(v))[(c)].nul = 0; \ + ((db_val_t *)(v))[(c)].val.str_val = (str)(cv); \ (c)++; -#define SCA_DB_BIND_INT_VALUE(cv, ct, k, v, c) \ - ((db_key_t *)(k))[ (c) ] = (str *)(ct); \ - ((db_val_t *)(v))[ (c) ].type = DB1_INT; \ - ((db_val_t *)(v))[ (c) ].nul = 0; \ - ((db_val_t *)(v))[ (c) ].val.int_val = (int)(cv); \ +#define SCA_DB_BIND_INT_VALUE(cv, ct, k, v, c) \ + ((db_key_t *)(k))[(c)] = (str *)(ct); \ + ((db_val_t *)(v))[(c)].type = DB1_INT; \ + ((db_val_t *)(v))[(c)].nul = 0; \ + ((db_val_t *)(v))[(c)].val.int_val = (int)(cv); \ (c)++; extern const str SCA_DB_SUBSCRIBER_COL_NAME; diff --git a/src/modules/sca/sca_dialog.c b/src/modules/sca/sca_dialog.c index a5e692404..1076caa35 100644 --- a/src/modules/sca/sca_dialog.c +++ b/src/modules/sca/sca_dialog.c @@ -32,15 +32,15 @@ int sca_dialog_build_from_tags(sca_dialog *dialog, int maxlen, str *call_id, assert(call_id != NULL); assert(from_tag != NULL); - LM_DBG( "From-Tag: %.*s To-Tag: %.*s CallId: %.*s\n", - STR_FMT(from_tag), STR_FMT(to_tag), STR_FMT(call_id)); + LM_DBG("From-Tag: %.*s To-Tag: %.*s CallId: %.*s\n", STR_FMT(from_tag), + STR_FMT(to_tag), STR_FMT(call_id)); len = call_id->len + from_tag->len; - if (!SCA_STR_EMPTY(to_tag)) { + if(!SCA_STR_EMPTY(to_tag)) { len += to_tag->len; } - if (len >= maxlen) { + if(len >= maxlen) { LM_ERR("sca_dialog_build_from_tags: tags too long\n"); return (-1); } @@ -53,7 +53,7 @@ int sca_dialog_build_from_tags(sca_dialog *dialog, int maxlen, str *call_id, dialog->from_tag.s = dialog->id.s + call_id->len; dialog->from_tag.len = from_tag->len; - if (!SCA_STR_EMPTY(to_tag)) { + if(!SCA_STR_EMPTY(to_tag)) { memcpy(dialog->id.s + call_id->len + from_tag->len, to_tag->s, to_tag->len); dialog->to_tag.s = dialog->id.s + call_id->len + from_tag->len; @@ -64,12 +64,12 @@ int sca_dialog_build_from_tags(sca_dialog *dialog, int maxlen, str *call_id, return (len); } -#define SCA_REPLACES_HDR_PREFIX "Replaces: " -#define SCA_REPLACES_HDR_PREFIX_LEN strlen(SCA_REPLACES_HDR_PREFIX) -#define SCA_REPLACES_TO_TAG "to-tag=" -#define SCA_REPLACES_TO_TAG_LEN strlen(SCA_REPLACES_TO_TAG) -#define SCA_REPLACES_FROM_TAG "from-tag=" -#define SCA_REPLACES_FROM_TAG_LEN strlen(SCA_REPLACES_FROM_TAG) +#define SCA_REPLACES_HDR_PREFIX "Replaces: " +#define SCA_REPLACES_HDR_PREFIX_LEN strlen(SCA_REPLACES_HDR_PREFIX) +#define SCA_REPLACES_TO_TAG "to-tag=" +#define SCA_REPLACES_TO_TAG_LEN strlen(SCA_REPLACES_TO_TAG) +#define SCA_REPLACES_FROM_TAG "from-tag=" +#define SCA_REPLACES_FROM_TAG_LEN strlen(SCA_REPLACES_FROM_TAG) int sca_dialog_create_replaces_header(sca_dialog *dlg, str *replaces_hdr) { @@ -77,12 +77,12 @@ int sca_dialog_create_replaces_header(sca_dialog *dlg, str *replaces_hdr) assert(replaces_hdr != NULL); - LM_DBG( "Called\n" ); + LM_DBG("Called\n"); - if (SCA_STR_EMPTY(&dlg->call_id) || SCA_STR_EMPTY(&dlg->from_tag) || - SCA_STR_EMPTY(&dlg->to_tag)) { + if(SCA_STR_EMPTY(&dlg->call_id) || SCA_STR_EMPTY(&dlg->from_tag) + || SCA_STR_EMPTY(&dlg->to_tag)) { LM_ERR("sca_dialog_create_replaces_header: dialog %.*s is not a " - "confirmed dialog, cannot build Replaces header\n", + "confirmed dialog, cannot build Replaces header\n", STR_FMT(&dlg->id)); return (-1); } @@ -91,11 +91,11 @@ int sca_dialog_create_replaces_header(sca_dialog *dlg, str *replaces_hdr) // +2 for semicolons separating tags, +2 for CRLF replaces_hdr->s = - pkg_malloc( - SCA_REPLACES_HDR_PREFIX_LEN + SCA_REPLACES_TO_TAG_LEN + SCA_REPLACES_FROM_TAG_LEN + dlg->id.len + 2 + 2); + pkg_malloc(SCA_REPLACES_HDR_PREFIX_LEN + SCA_REPLACES_TO_TAG_LEN + + SCA_REPLACES_FROM_TAG_LEN + dlg->id.len + 2 + 2); memcpy(replaces_hdr->s, SCA_REPLACES_HDR_PREFIX, - SCA_REPLACES_HDR_PREFIX_LEN); + SCA_REPLACES_HDR_PREFIX_LEN); len = SCA_REPLACES_HDR_PREFIX_LEN; memcpy(replaces_hdr->s + len, dlg->call_id.s, dlg->call_id.len); @@ -104,8 +104,7 @@ int sca_dialog_create_replaces_header(sca_dialog *dlg, str *replaces_hdr) memcpy(replaces_hdr->s + len, ";", strlen(";")); len += strlen(";"); - memcpy(replaces_hdr->s + len, SCA_REPLACES_TO_TAG, - SCA_REPLACES_TO_TAG_LEN); + memcpy(replaces_hdr->s + len, SCA_REPLACES_TO_TAG, SCA_REPLACES_TO_TAG_LEN); len += SCA_REPLACES_TO_TAG_LEN; memcpy(replaces_hdr->s + len, dlg->to_tag.s, dlg->to_tag.len); len += dlg->to_tag.len; @@ -114,7 +113,7 @@ int sca_dialog_create_replaces_header(sca_dialog *dlg, str *replaces_hdr) len += strlen(";"); memcpy(replaces_hdr->s + len, SCA_REPLACES_FROM_TAG, - SCA_REPLACES_FROM_TAG_LEN); + SCA_REPLACES_FROM_TAG_LEN); len += SCA_REPLACES_FROM_TAG_LEN; memcpy(replaces_hdr->s + len, dlg->from_tag.s, dlg->from_tag.len); len += dlg->from_tag.len; diff --git a/src/modules/sca/sca_dialog.h b/src/modules/sca/sca_dialog.h index 77bc6f328..d30895431 100644 --- a/src/modules/sca/sca_dialog.h +++ b/src/modules/sca/sca_dialog.h @@ -20,7 +20,8 @@ #ifndef SCA_DIALOG_H #define SCA_DIALOG_H -struct _sca_dialog { +struct _sca_dialog +{ str id; // call-id + from-tag + to-tag str call_id; str from_tag; @@ -31,10 +32,10 @@ struct _sca_dialog { }; typedef struct _sca_dialog sca_dialog; -#define SCA_DIALOG_EMPTY(d) \ - ((d) == NULL || (SCA_STR_EMPTY(&(d)->call_id) && \ - SCA_STR_EMPTY(&(d)->from_tag) && \ - SCA_STR_EMPTY(&(d)->to_tag))) +#define SCA_DIALOG_EMPTY(d) \ + ((d) == NULL \ + || (SCA_STR_EMPTY(&(d)->call_id) && SCA_STR_EMPTY(&(d)->from_tag) \ + && SCA_STR_EMPTY(&(d)->to_tag))) int sca_dialog_build_from_tags(sca_dialog *, int, str *, str *, str *); int sca_dialog_create_replaces_header(sca_dialog *, str *); diff --git a/src/modules/sca/sca_event.c b/src/modules/sca/sca_event.c index ac691b57b..5daa30143 100644 --- a/src/modules/sca/sca_event.c +++ b/src/modules/sca/sca_event.c @@ -28,13 +28,13 @@ int sca_event_from_str(str *event_str) { int event = SCA_EVENT_TYPE_UNKNOWN; - if (event_str == NULL || event_str->s == NULL) { + if(event_str == NULL || event_str->s == NULL) { return (SCA_EVENT_TYPE_UNKNOWN); } - if (STR_EQ(*event_str, SCA_EVENT_NAME_CALL_INFO)) { + if(STR_EQ(*event_str, SCA_EVENT_NAME_CALL_INFO)) { event = SCA_EVENT_TYPE_CALL_INFO; - } else if (STR_EQ(*event_str, SCA_EVENT_NAME_LINE_SEIZE)) { + } else if(STR_EQ(*event_str, SCA_EVENT_NAME_LINE_SEIZE)) { event = SCA_EVENT_TYPE_LINE_SEIZE; } @@ -43,15 +43,15 @@ int sca_event_from_str(str *event_str) char *sca_event_name_from_type(int event_type) { - switch (event_type) { - case SCA_EVENT_TYPE_CALL_INFO: - return (SCA_EVENT_NAME_CALL_INFO.s); + switch(event_type) { + case SCA_EVENT_TYPE_CALL_INFO: + return (SCA_EVENT_NAME_CALL_INFO.s); - case SCA_EVENT_TYPE_LINE_SEIZE: - return (SCA_EVENT_NAME_LINE_SEIZE.s); + case SCA_EVENT_TYPE_LINE_SEIZE: + return (SCA_EVENT_NAME_LINE_SEIZE.s); - default: - break; + default: + break; } return ("unknown"); @@ -63,7 +63,7 @@ int sca_event_append_header_for_type(int event_type, char *hdrbuf, int maxlen) len = snprintf(hdrbuf, maxlen, "Event: %s%s", sca_event_name_from_type(event_type), CRLF); - if (len >= maxlen) { + if(len >= maxlen) { LM_ERR("%s Event header too long\n", sca_event_name_from_type(event_type)); return (-1); diff --git a/src/modules/sca/sca_event.h b/src/modules/sca/sca_event.h index 0baae6b85..f03fe69ec 100644 --- a/src/modules/sca/sca_event.h +++ b/src/modules/sca/sca_event.h @@ -17,7 +17,8 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA. 02110-1301 USA */ -enum { +enum +{ SCA_EVENT_TYPE_UNKNOWN = -1, SCA_EVENT_TYPE_CALL_INFO = 1, SCA_EVENT_TYPE_LINE_SEIZE = 2, @@ -26,8 +27,7 @@ enum { extern str SCA_EVENT_NAME_CALL_INFO; extern str SCA_EVENT_NAME_LINE_SEIZE; -#define sca_ok_status_for_event(e1) \ - (e1) == SCA_EVENT_TYPE_CALL_INFO ? 202 : 200 +#define sca_ok_status_for_event(e1) (e1) == SCA_EVENT_TYPE_CALL_INFO ? 202 : 200 #define sca_ok_text_for_event(e1) \ (e1) == SCA_EVENT_TYPE_CALL_INFO ? "Accepted" : "OK" diff --git a/src/modules/sca/sca_hash.c b/src/modules/sca/sca_hash.c index ce7be7315..3e96bc2be 100644 --- a/src/modules/sca/sca_hash.c +++ b/src/modules/sca/sca_hash.c @@ -31,14 +31,14 @@ int sca_hash_table_create(sca_hash_table **ht, unsigned int size) assert(ht != NULL); *ht = shm_malloc(sizeof(sca_hash_table)); - if (*ht == NULL) { + if(*ht == NULL) { LM_ERR("Failed to shm_malloc space for hash table\n"); return (-1); } (*ht)->size = size; - (*ht)->slots = (sca_hash_slot *) shm_malloc(size * sizeof(sca_hash_slot)); - if ((*ht)->slots == NULL) { + (*ht)->slots = (sca_hash_slot *)shm_malloc(size * sizeof(sca_hash_slot)); + if((*ht)->slots == NULL) { LM_ERR("Failed to shm_malloc hash table slots\n"); shm_free(*ht); *ht = NULL; @@ -46,8 +46,8 @@ int sca_hash_table_create(sca_hash_table **ht, unsigned int size) } memset((*ht)->slots, 0, size * sizeof(sca_hash_slot)); - for (i = 0; i < (*ht)->size; i++) { - if (lock_init(&(*ht)->slots[i].lock) == NULL) { + for(i = 0; i < (*ht)->size; i++) { + if(lock_init(&(*ht)->slots[i].lock) == NULL) { LM_ERR("Failed to initialized lock in hash table slot %d\n", i); shm_free(*ht); *ht = NULL; @@ -69,8 +69,8 @@ int sca_hash_table_slot_kv_insert_unsafe(sca_hash_slot *slot, void *value, assert(value != NULL); assert(e_free != NULL); - new_entry = (sca_hash_entry *) shm_malloc(sizeof(sca_hash_entry)); - if (new_entry == NULL) { + new_entry = (sca_hash_entry *)shm_malloc(sizeof(sca_hash_entry)); + if(new_entry == NULL) { LM_ERR("Failed to shm_malloc new hash table entry for slot %p\n", slot); return (-1); } @@ -95,8 +95,8 @@ int sca_hash_table_slot_kv_insert(sca_hash_slot *slot, void *value, lock_get(&slot->lock); - rc = sca_hash_table_slot_kv_insert_unsafe(slot, value, e_compare, - e_description, e_free); + rc = sca_hash_table_slot_kv_insert_unsafe( + slot, value, e_compare, e_description, e_free); lock_release(&slot->lock); @@ -111,8 +111,8 @@ int sca_hash_table_index_kv_insert(sca_hash_table *ht, int slot_idx, assert(ht->slots != NULL); assert(slot_idx >= 0 && slot_idx < ht->size); - return (sca_hash_table_slot_kv_insert(&ht->slots[slot_idx], value, - e_compare, e_description, e_free)); + return (sca_hash_table_slot_kv_insert( + &ht->slots[slot_idx], value, e_compare, e_description, e_free)); } int sca_hash_table_kv_insert(sca_hash_table *ht, str *key, void *value, @@ -125,8 +125,8 @@ int sca_hash_table_kv_insert(sca_hash_table *ht, str *key, void *value, assert(ht != NULL && !SCA_STR_EMPTY(key) && value != NULL); hash_idx = sca_hash_table_index_for_key(ht, key); - rc = sca_hash_table_index_kv_insert(ht, hash_idx, value, e_compare, - e_description, e_free); + rc = sca_hash_table_index_kv_insert( + ht, hash_idx, value, e_compare, e_description, e_free); return (rc); } @@ -138,8 +138,8 @@ void *sca_hash_table_slot_kv_find_unsafe(sca_hash_slot *slot, str *key) assert(slot != NULL && !SCA_STR_EMPTY(key)); - for (e = slot->entries; e != NULL; e = e->next) { - if (e->compare(key, e->value) == 0) { + for(e = slot->entries; e != NULL; e = e->next) { + if(e->compare(key, e->value) == 0) { value = e->value; } } @@ -158,8 +158,8 @@ void *sca_hash_table_slot_kv_find(sca_hash_slot *slot, str *key) return (value); } -void *sca_hash_table_index_kv_find_unsafe(sca_hash_table *ht, int slot_idx, - str *key) +void *sca_hash_table_index_kv_find_unsafe( + sca_hash_table *ht, int slot_idx, str *key) { assert(ht != NULL && !SCA_STR_EMPTY(key)); assert(slot_idx >= 0 && slot_idx < ht->size); @@ -167,8 +167,7 @@ void *sca_hash_table_index_kv_find_unsafe(sca_hash_table *ht, int slot_idx, return (sca_hash_table_slot_kv_find_unsafe(&ht->slots[slot_idx], key)); } -void * -sca_hash_table_index_kv_find(sca_hash_table *ht, int slot_idx, str *key) +void *sca_hash_table_index_kv_find(sca_hash_table *ht, int slot_idx, str *key) { assert(ht != NULL && !SCA_STR_EMPTY(key)); assert(slot_idx >= 0 && slot_idx < ht->size); @@ -185,15 +184,15 @@ void *sca_hash_table_kv_find(sca_hash_table *ht, str *key) return (sca_hash_table_index_kv_find(ht, slot_idx, key)); } -sca_hash_entry *sca_hash_table_slot_kv_find_entry_unsafe(sca_hash_slot *slot, - str *key) +sca_hash_entry *sca_hash_table_slot_kv_find_entry_unsafe( + sca_hash_slot *slot, str *key) { sca_hash_entry *e = NULL; assert(slot != NULL && !SCA_STR_EMPTY(key)); - for (e = slot->entries; e != NULL; e = e->next) { - if (e->compare(key, e->value) == 0) { + for(e = slot->entries; e != NULL; e = e->next) { + if(e->compare(key, e->value) == 0) { break; } } @@ -220,16 +219,16 @@ void sca_hash_entry_free(sca_hash_entry *e) shm_free(e); } -sca_hash_entry *sca_hash_table_slot_unlink_entry_unsafe(sca_hash_slot *slot, - sca_hash_entry *e) +sca_hash_entry *sca_hash_table_slot_unlink_entry_unsafe( + sca_hash_slot *slot, sca_hash_entry *e) { sca_hash_entry **cur_e; assert(slot != NULL); assert(e != NULL); - for (cur_e = &slot->entries; *cur_e != NULL; cur_e = &(*cur_e)->next) { - if (*cur_e == e) { + for(cur_e = &slot->entries; *cur_e != NULL; cur_e = &(*cur_e)->next) { + if(*cur_e == e) { *cur_e = e->next; /* ensure any attempted traversal using this entry goes nowhere */ @@ -248,12 +247,12 @@ int sca_hash_table_slot_kv_delete_unsafe(sca_hash_slot *slot, str *key) sca_hash_entry *e; e = sca_hash_table_slot_kv_find_entry_unsafe(slot, key); - if (e == NULL) { + if(e == NULL) { return (-1); } e = sca_hash_table_slot_unlink_entry_unsafe(slot, e); - if (e) { + if(e) { e->free_entry(e->value); shm_free(e); } @@ -290,8 +289,8 @@ static void sca_hash_slot_print(sca_hash_slot *hs) { sca_hash_entry *e; - for (e = hs->entries; e != NULL; e = e->next) { - if (e->description != NULL) { + for(e = hs->entries; e != NULL; e = e->next) { + if(e->description != NULL) { e->description(e->value); } else { LM_DBG("0x%p\n", e->value); @@ -303,7 +302,7 @@ void sca_hash_table_print(sca_hash_table *ht) { unsigned int i; - for (i = 0; i < ht->size; i++) { + for(i = 0; i < ht->size; i++) { LM_DBG("SLOT %d:\n", i); sca_hash_slot_print(&ht->slots[i]); } @@ -314,18 +313,18 @@ void sca_hash_table_free(sca_hash_table *ht) sca_hash_entry *e, *e_tmp; unsigned int i; - if (ht == NULL) { + if(ht == NULL) { return; } - for (i = 0; i < ht->size; i++) { - if (ht->slots[i].entries == NULL) { + for(i = 0; i < ht->size; i++) { + if(ht->slots[i].entries == NULL) { continue; } sca_hash_table_lock_index(ht, i); - for (e = ht->slots[i].entries; e != NULL; e = e_tmp) { + for(e = ht->slots[i].entries; e != NULL; e = e_tmp) { e_tmp = e->next; e->free_entry(e->value); diff --git a/src/modules/sca/sca_hash.h b/src/modules/sca/sca_hash.h index 72e4bc354..15cbeb2c4 100644 --- a/src/modules/sca/sca_hash.h +++ b/src/modules/sca/sca_hash.h @@ -21,7 +21,8 @@ #define SCA_HASH_H struct _sca_hash_slot; -struct _sca_hash_entry { +struct _sca_hash_entry +{ void *value; int (*compare)(str *, void *); void (*description)(void *); @@ -31,13 +32,15 @@ struct _sca_hash_entry { }; typedef struct _sca_hash_entry sca_hash_entry; -struct _sca_hash_slot { +struct _sca_hash_slot +{ gen_lock_t lock; sca_hash_entry *entries; }; typedef struct _sca_hash_slot sca_hash_slot; -struct _sca_hash_table { +struct _sca_hash_table +{ unsigned int size; // power of two sca_hash_slot *slots; }; @@ -46,14 +49,13 @@ typedef struct _sca_hash_table sca_hash_table; #define sca_hash_table_index_for_key(ht1, str1) \ (get_hash1_raw((str1)->s, (str1)->len) & ((ht1)->size - 1)) -#define sca_hash_table_slot_for_index(ht1, idx1) \ - &(ht1)->slots[ (idx1) ] +#define sca_hash_table_slot_for_index(ht1, idx1) &(ht1)->slots[(idx1)] #define sca_hash_table_lock_index(ht1, idx1) \ - lock_get(&(ht1)->slots[ (idx1) ].lock) + lock_get(&(ht1)->slots[(idx1)].lock) #define sca_hash_table_unlock_index(ht1, idx1) \ - lock_release(&(ht1)->slots[ (idx1) ].lock) + lock_release(&(ht1)->slots[(idx1)].lock) // hash table operations int sca_hash_table_create(sca_hash_table **, unsigned int); @@ -77,9 +79,10 @@ void *sca_hash_table_index_kv_find_unsafe(sca_hash_table *, int, str *); void *sca_hash_table_index_kv_find(sca_hash_table *, int, str *); void *sca_hash_table_kv_find(sca_hash_table *, str *); -sca_hash_entry *sca_hash_table_slot_kv_find_entry_unsafe(sca_hash_slot *, str *); -sca_hash_entry *sca_hash_table_slot_unlink_entry_unsafe(sca_hash_slot *, - sca_hash_entry *); +sca_hash_entry *sca_hash_table_slot_kv_find_entry_unsafe( + sca_hash_slot *, str *); +sca_hash_entry *sca_hash_table_slot_unlink_entry_unsafe( + sca_hash_slot *, sca_hash_entry *); int sca_hash_table_slot_kv_delete(sca_hash_slot *, str *); int sca_hash_table_index_kv_delete(sca_hash_table *, int, str *); diff --git a/src/modules/sca/sca_notify.c b/src/modules/sca/sca_notify.c index a654fb9b0..133a3feed 100644 --- a/src/modules/sca/sca_notify.c +++ b/src/modules/sca/sca_notify.c @@ -32,24 +32,24 @@ const str SCA_METHOD_NOTIFY = STR_STATIC_INIT("NOTIFY"); -static void sca_notify_reply_cb(struct cell *t, int cb_type, - struct tmcb_params *cbp) +static void sca_notify_reply_cb( + struct cell *t, int cb_type, struct tmcb_params *cbp) { struct sip_msg *notify_reply = NULL; str to_aor = STR_NULL; str *contact_uri; - if (cbp == NULL) { + if(cbp == NULL) { LM_ERR("Empty parameters passed to NOTIFY callback!\n"); return; } - if ((notify_reply = cbp->rpl) == NULL) { + if((notify_reply = cbp->rpl) == NULL) { LM_ERR("Empty reply passed to NOTIFY callback!\n"); return; } contact_uri = &t->uac[0].uri; - if (notify_reply != FAKED_REPLY && REPLY_CLASS(notify_reply) == 2) { + if(notify_reply != FAKED_REPLY && REPLY_CLASS(notify_reply) == 2) { LM_DBG("NOTIFY %.*s returned %d\n", STR_FMT(contact_uri), notify_reply->REPLY_STATUS); return; @@ -61,30 +61,32 @@ static void sca_notify_reply_cb(struct cell *t, int cb_type, // possible the client will return 481 (no such transaction), but that's // still grounds for us to remove the subscription, since the dialog // we have associated with the subscription is no longer valid. - if (notify_reply == FAKED_REPLY) { + if(notify_reply == FAKED_REPLY) { LM_ERR("NOTIFY %.*s resulted in FAKED_REPLY from proxy: " - "failed to deliver NOTIFY to client\n", STR_FMT(contact_uri)); + "failed to deliver NOTIFY to client\n", + STR_FMT(contact_uri)); } else { LM_ERR("NOTIFY %.*s returned %d %.*s removing call-info " - "subscription for %.*s\n", STR_FMT(contact_uri), - notify_reply->REPLY_STATUS, + "subscription for %.*s\n", + STR_FMT(contact_uri), notify_reply->REPLY_STATUS, STR_FMT(¬ify_reply->first_line.u.reply.reason), STR_FMT(contact_uri)); } return; - if (sca_uri_extract_aor(&t->to, &to_aor) < 0) { + if(sca_uri_extract_aor(&t->to, &to_aor) < 0) { LM_ERR("Failed to extract AoR from %.*s\n", STR_FMT(&t->to)); return; } // t->to is the entire To header: "To: sip:....", so move to_aor.s ahead - if (memcmp(to_aor.s, "To: ", strlen("To: ")) == 0) { + if(memcmp(to_aor.s, "To: ", strlen("To: ")) == 0) { to_aor.s += strlen("To: "); to_aor.len -= strlen("To: "); } - if (sca_subscription_delete_subscriber_for_event(sca, contact_uri, - &SCA_EVENT_NAME_CALL_INFO, &to_aor) < 0) { + if(sca_subscription_delete_subscriber_for_event( + sca, contact_uri, &SCA_EVENT_NAME_CALL_INFO, &to_aor) + < 0) { LM_ERR("Failed to delete %.*s %.*s subscription\n", STR_FMT(contact_uri), STR_FMT(&SCA_EVENT_NAME_CALL_INFO)); } @@ -94,8 +96,8 @@ static dlg_t *sca_notify_dlg_for_subscription(sca_subscription *sub) { dlg_t *dlg = NULL; - dlg = (dlg_t *) pkg_malloc(sizeof(dlg_t)); - if (dlg == NULL) { + dlg = (dlg_t *)pkg_malloc(sizeof(dlg_t)); + if(dlg == NULL) { LM_ERR("pkg_malloc dlg_t for %.*s failed: out of memory\n", STR_FMT(&sub->subscriber)); goto error; @@ -117,10 +119,10 @@ static dlg_t *sca_notify_dlg_for_subscription(sca_subscription *sub) dlg->rem_uri = sub->target_aor; // restore route - if (!SCA_STR_EMPTY(&sub->rr)) { - if (parse_rr_body(sub->rr.s, sub->rr.len, &dlg->route_set) < 0) { + if(!SCA_STR_EMPTY(&sub->rr)) { + if(parse_rr_body(sub->rr.s, sub->rr.len, &dlg->route_set) < 0) { LM_ERR("sca_notify_dlg_for_subscription: failed to parse " - "%.*s subscription's Record-Route info\n", + "%.*s subscription's Record-Route info\n", STR_FMT(&sub->subscriber)); goto error; } @@ -133,35 +135,35 @@ static dlg_t *sca_notify_dlg_for_subscription(sca_subscription *sub) return (dlg); - error: if (dlg != NULL) { +error: + if(dlg != NULL) { pkg_free(dlg); } return (NULL); } -static int sca_notify_append_subscription_state_header(sca_subscription *sub, - char *hdrbuf, int maxlen) +static int sca_notify_append_subscription_state_header( + sca_subscription *sub, char *hdrbuf, int maxlen) { str state_str = STR_NULL; - int len, - total = 0; + int len, total = 0; int ttl = sub->expires - time(NULL); - if (ttl < 0) { + if(ttl < 0) { ttl = 0; } sca_subscription_state_to_str(sub->state, &state_str); len = snprintf(hdrbuf, maxlen, "Subscription-State: %s", state_str.s); - if (len >= maxlen) { + if(len >= maxlen) { goto error; } total += len; - if (ttl > 0) { + if(ttl > 0) { len = snprintf(hdrbuf + total, maxlen - total, ";expires=%d", ttl); - if (len >= maxlen) { + if(len >= maxlen) { goto error; } total += len; @@ -172,25 +174,24 @@ static int sca_notify_append_subscription_state_header(sca_subscription *sub, return (total); - error: +error: LM_ERR("Cannot append Subscription-State header: buffer too small\n"); return (-1); } -static int sca_notify_append_contact_header(sca_subscription *sub, char *hdrbuf, - int maxlen) +static int sca_notify_append_contact_header( + sca_subscription *sub, char *hdrbuf, int maxlen) { int len = strlen("Contact: "); str *orig = NULL; - if (sca->cfg->server_address != NULL) { + if(sca->cfg->server_address != NULL) { orig = sca->cfg->server_address; - } - else { + } else { orig = &sub->target_aor; } - if (len + orig->len + strlen(CRLF) >= maxlen) { + if(len + orig->len + strlen(CRLF) >= maxlen) { LM_ERR("Cannot append Contact header: buffer too small\n"); return (-1); } @@ -212,7 +213,7 @@ static int sca_notify_build_headers_from_info(str *hdrs, int max_hdrs_len, assert(hdrs != NULL); len = sca_notify_append_contact_header(sub, hdrs->s, max_hdrs_len); - if (len < 0) { + if(len < 0) { LM_ERR("Failed to add Contact header to %s NOTIFY for %.*s\n", sca_event_name_from_type(sub->event), STR_FMT(&sub->subscriber)); @@ -220,10 +221,11 @@ static int sca_notify_build_headers_from_info(str *hdrs, int max_hdrs_len, } hdrs->len = len; - if (app_idx == SCA_CALL_INFO_APPEARANCE_INDEX_ANY) { + if(app_idx == SCA_CALL_INFO_APPEARANCE_INDEX_ANY) { // add Call-Info header with appearance state - if ((len = sca_call_info_build_header(scam, sub, hdrs->s + hdrs->len, - max_hdrs_len - hdrs->len)) < 0) { + if((len = sca_call_info_build_header( + scam, sub, hdrs->s + hdrs->len, max_hdrs_len - hdrs->len)) + < 0) { LM_ERR("Failed to build Call-Info Headers for %s NOTIFY to %.*s\n", sca_event_name_from_type(sub->event), STR_FMT(&sub->subscriber)); @@ -231,18 +233,18 @@ static int sca_notify_build_headers_from_info(str *hdrs, int max_hdrs_len, } } else { // just add Call-Info header with single appearance index - len = sca_call_info_append_header_for_appearance_index(sub, app_idx, - hdrs->s + hdrs->len, max_hdrs_len - hdrs->len); - if (len < 0) { + len = sca_call_info_append_header_for_appearance_index( + sub, app_idx, hdrs->s + hdrs->len, max_hdrs_len - hdrs->len); + if(len < 0) { goto error; } } hdrs->len += len; - len = sca_event_append_header_for_type(sub->event, hdrs->s + hdrs->len, - max_hdrs_len - hdrs->len); - if (len < 0) { + len = sca_event_append_header_for_type( + sub->event, hdrs->s + hdrs->len, max_hdrs_len - hdrs->len); + if(len < 0) { LM_ERR("Failed to add Event header to %s NOTIFY for %.*s\n", sca_event_name_from_type(sub->event), STR_FMT(&sub->subscriber)); @@ -250,11 +252,12 @@ static int sca_notify_build_headers_from_info(str *hdrs, int max_hdrs_len, } hdrs->len += len; - len = sca_notify_append_subscription_state_header(sub, hdrs->s + hdrs->len, - max_hdrs_len - hdrs->len); - if (len < 0) { + len = sca_notify_append_subscription_state_header( + sub, hdrs->s + hdrs->len, max_hdrs_len - hdrs->len); + if(len < 0) { LM_ERR("Failed to add Subscription-State header to %s NOTIFY for " - "%.*s\n", sca_event_name_from_type(sub->event), + "%.*s\n", + sca_event_name_from_type(sub->event), STR_FMT(&sub->subscriber)); goto error; } @@ -262,11 +265,12 @@ static int sca_notify_build_headers_from_info(str *hdrs, int max_hdrs_len, return (hdrs->len); - error: return (-1); +error: + return (-1); } -static int sca_notify_subscriber_internal(sca_mod *scam, sca_subscription *sub, - str *headers) +static int sca_notify_subscriber_internal( + sca_mod *scam, sca_subscription *sub, str *headers) { uac_req_t request; dlg_t *dlg = NULL; @@ -274,12 +278,13 @@ static int sca_notify_subscriber_internal(sca_mod *scam, sca_subscription *sub, int rc = -1; sca_appearance_state_to_str(sub->state, &state_str); - LM_DBG("SCA: NOTIFYing subscriber '%.*s' of event '%s' with a state of '%.*s' to index '%d'\n", + LM_DBG("SCA: NOTIFYing subscriber '%.*s' of event '%s' with a state of " + "'%.*s' to index '%d'\n", STR_FMT(&sub->subscriber), sca_event_name_from_type(sub->event), STR_FMT(&state_str), sub->index); dlg = sca_notify_dlg_for_subscription(sub); - if (dlg == NULL) { + if(dlg == NULL) { LM_ERR("Failed to create dlg_t for %s NOTIFY to %.*s\n", sca_event_name_from_type(sub->event), STR_FMT(&sub->subscriber)); @@ -289,15 +294,16 @@ static int sca_notify_subscriber_internal(sca_mod *scam, sca_subscription *sub, set_uac_req(&request, (str *)&SCA_METHOD_NOTIFY, headers, NULL, dlg, TMCB_LOCAL_COMPLETED, sca_notify_reply_cb, scam); rc = scam->tm_api->t_request_within(&request); - if (rc < 0) { + if(rc < 0) { LM_ERR("Failed to send in-dialog %s NOTIFY to %.*s\n", sca_event_name_from_type(sub->event), STR_FMT(&sub->subscriber)); } // fall through, return rc from t_request_within - done: if (dlg != NULL) { - if (dlg->route_set != NULL) { +done: + if(dlg != NULL) { + if(dlg->route_set != NULL) { free_rr(&dlg->route_set); } @@ -307,7 +313,7 @@ static int sca_notify_subscriber_internal(sca_mod *scam, sca_subscription *sub, return (rc); } -#define SCA_HEADERS_MAX_LEN 4096 +#define SCA_HEADERS_MAX_LEN 4096 int sca_notify_subscriber(sca_mod *scam, sca_subscription *sub, int app_idx) { str headers = STR_NULL; @@ -316,8 +322,9 @@ int sca_notify_subscriber(sca_mod *scam, sca_subscription *sub, int app_idx) LM_DBG("NOTIFYing subscriber because of a SUBSCRIPTION request\n"); headers.s = hdrbuf; - if (sca_notify_build_headers_from_info(&headers, sizeof(hdrbuf), scam, sub, - app_idx) < 0) { + if(sca_notify_build_headers_from_info( + &headers, sizeof(hdrbuf), scam, sub, app_idx) + < 0) { LM_ERR("Failed to build NOTIFY headers\n"); return (-1); } @@ -344,13 +351,14 @@ int sca_notify_call_info_subscribers(sca_mod *scam, str *subscription_aor) assert(scam->subscriptions != NULL); assert(!SCA_STR_EMPTY(subscription_aor)); - LM_DBG("Notifying ALL subscribers of AOR %.*s due to a SUBSCRIBTION request\n", + LM_DBG("Notifying ALL subscribers of AOR %.*s due to a SUBSCRIBTION " + "request\n", STR_FMT(subscription_aor)); event_name = sca_event_name_from_type(SCA_EVENT_TYPE_CALL_INFO); - if (subscription_aor->len + strlen(event_name) >= sizeof(keybuf)) { - LM_ERR("Hash key %.*s + %s is too long\n", - STR_FMT(subscription_aor), event_name); + if(subscription_aor->len + strlen(event_name) >= sizeof(keybuf)) { + LM_ERR("Hash key %.*s + %s is too long\n", STR_FMT(subscription_aor), + event_name); return (-1); } hash_key.s = keybuf; @@ -362,17 +370,18 @@ int sca_notify_call_info_subscribers(sca_mod *scam, str *subscription_aor) sca_hash_table_lock_index(scam->subscriptions, slot_idx); - for (e = slot->entries; e != NULL; e = e->next) { - sub = (sca_subscription *) e->value; - if (!SCA_STR_EQ(subscription_aor, &sub->target_aor)) { + for(e = slot->entries; e != NULL; e = e->next) { + sub = (sca_subscription *)e->value; + if(!SCA_STR_EQ(subscription_aor, &sub->target_aor)) { continue; } - if (headers.len == 0) { + if(headers.len == 0) { headers.s = hdrbuf; - if (sca_notify_build_headers_from_info(&headers, sizeof(hdrbuf), - scam, sub, SCA_CALL_INFO_APPEARANCE_INDEX_ANY) < 0) { + if(sca_notify_build_headers_from_info(&headers, sizeof(hdrbuf), + scam, sub, SCA_CALL_INFO_APPEARANCE_INDEX_ANY) + < 0) { LM_ERR("Failed to build NOTIFY headers\n"); goto done; } @@ -381,13 +390,13 @@ int sca_notify_call_info_subscribers(sca_mod *scam, str *subscription_aor) // XXX would like this to be wrapped in one location sub->dialog.notify_cseq += 1; - if (sca_notify_subscriber_internal(scam, sub, &headers) < 0) { + if(sca_notify_subscriber_internal(scam, sub, &headers) < 0) { goto done; } } rc = 1; - done: +done: sca_hash_table_unlock_index(scam->subscriptions, slot_idx); return (rc); diff --git a/src/modules/sca/sca_reply.c b/src/modules/sca/sca_reply.c index a56fb9324..ad143d5e7 100644 --- a/src/modules/sca/sca_reply.c +++ b/src/modules/sca/sca_reply.c @@ -36,18 +36,18 @@ int sca_reply(sca_mod *scam, int status_code, char *status_msg, status_str.s = status_msg; status_str.len = strlen(status_msg); - if (extra_headers && extra_headers->len) { - if (add_lump_rpl(msg, extra_headers->s, extra_headers->len, - LUMP_RPL_HDR) == NULL) { - LM_ERR("sca_subscription_reply: failed to add Retry-After header\n"); + if(extra_headers && extra_headers->len) { + if(add_lump_rpl(msg, extra_headers->s, extra_headers->len, LUMP_RPL_HDR) + == NULL) { + LM_ERR("sca_subscription_reply: failed to add Retry-After " + "header\n"); return (-1); } } - if (scam->sl_api->freply(msg, status_code, &status_str) < 0) { - LM_ERR("Failed to send \"%d %s\" reply to %.*s", - status_code, status_msg, - get_from(msg)->body.len, get_from(msg)->body.s); + if(scam->sl_api->freply(msg, status_code, &status_str) < 0) { + LM_ERR("Failed to send \"%d %s\" reply to %.*s", status_code, + status_msg, get_from(msg)->body.len, get_from(msg)->body.s); return (-1); } diff --git a/src/modules/sca/sca_rpc.c b/src/modules/sca/sca_rpc.c index 6005aea3a..f1882fa87 100644 --- a/src/modules/sca/sca_rpc.c +++ b/src/modules/sca/sca_rpc.c @@ -33,40 +33,31 @@ #include "sca_subscribe.h" const char *sca_rpc_show_all_subscriptions_doc[] = { - "Show all shared call appearance subscriptions", - NULL}; + "Show all shared call appearance subscriptions", NULL}; const char *sca_rpc_subscription_count_doc[] = { - "Show count of call-info or line-seize subscriptions", - NULL}; + "Show count of call-info or line-seize subscriptions", NULL}; const char *sca_rpc_show_subscription_doc[] = { - "Show details of a single shared call appearance subscription", - NULL}; + "Show details of a single shared call appearance subscription", NULL}; const char *sca_rpc_show_subscribers_doc[] = { - "Show contact URIs for all call-info subscribers", - NULL}; + "Show contact URIs for all call-info subscribers", NULL}; const char *sca_rpc_deactivate_all_subscriptions_doc[] = { "Send NOTIFYs with Subscription-State: " - "terminated;reason=deactivated to all subscribers", + "terminated;reason=deactivated to all subscribers", NULL}; const char *sca_rpc_deactivate_subscription_doc[] = { "Send NOTIFY with Subscription-State: " - "terminated;reason=deactivated to a single subscriber", + "terminated;reason=deactivated to a single subscriber", NULL}; const char *sca_rpc_show_all_appearances_doc[] = { - "Show appearance state for all SCA accounts of record (AoR)", - NULL}; + "Show appearance state for all SCA accounts of record (AoR)", NULL}; const char *sca_rpc_show_appearance_doc[] = { - "Show appearance state for a single SCA account of record (AoR)", - NULL}; + "Show appearance state for a single SCA account of record (AoR)", NULL}; const char *sca_rpc_seize_appearance_doc[] = { - "Seize an appearance on an SCA line", - NULL}; + "Seize an appearance on an SCA line", NULL}; const char *sca_rpc_update_appearance_doc[] = { - "Update the state of a seized appearance on an SCA line", - NULL}; + "Update the state of a seized appearance on an SCA line", NULL}; const char *sca_rpc_release_appearance_doc[] = { - "Release a seized or active SCA appearance", - NULL}; + "Release a seized or active SCA appearance", NULL}; /* * Show all shared call appearance subscriptions @@ -82,42 +73,42 @@ void sca_rpc_show_all_subscriptions(rpc_t *rpc, void *ctx) int i; int rc = 0; - if ((ht = sca->subscriptions) == NULL) { + if((ht = sca->subscriptions) == NULL) { rpc->fault(ctx, 500, "Empty subscription table!"); return; } now = time(NULL); - for (i = 0; i < ht->size; i++) { + for(i = 0; i < ht->size; i++) { sca_hash_table_lock_index(ht, i); - for (ent = ht->slots[i].entries; ent != NULL; ent = ent->next) { - sub = (sca_subscription *) ent->value; + for(ent = ht->slots[i].entries; ent != NULL; ent = ent->next) { + sub = (sca_subscription *)ent->value; sca_subscription_state_to_str(sub->state, &sub_state); rc = parse_uri(sub->target_aor.s, sub->target_aor.len, &aor_uri); - if (rc >= 0) { - rc = parse_uri(sub->subscriber.s, sub->subscriber.len, - &sub_uri); + if(rc >= 0) { + rc = parse_uri( + sub->subscriber.s, sub->subscriber.len, &sub_uri); } - if (rc >= 0) { + if(rc >= 0) { rc = rpc->rpl_printf(ctx, "%.*s %.*s%s%.*s %s %ld %.*s", STR_FMT(&aor_uri.user), STR_FMT(&sub_uri.host), (sub_uri.port.len ? ":" : ""), STR_FMT(&sub_uri.port), sca_event_name_from_type(sub->event), - (long) (sub->expires - now), STR_FMT(&sub_state)); + (long)(sub->expires - now), STR_FMT(&sub_state)); } else { LM_ERR("sca_rpc_show_all_subscriptions: parse_uri %.*s " - "failed, dumping unparsed info\n", + "failed, dumping unparsed info\n", STR_FMT(&sub->target_aor)); rc = rpc->rpl_printf(ctx, "%.*s %.*s %s %ld %.*s", STR_FMT(&sub->target_aor), STR_FMT(&sub->subscriber), sca_event_name_from_type(sub->event), - (long) sub->expires, STR_FMT(&sub_state)); + (long)sub->expires, STR_FMT(&sub_state)); } - if (rc < 0) { + if(rc < 0) { // make sure we unlock below break; } @@ -125,7 +116,7 @@ void sca_rpc_show_all_subscriptions(rpc_t *rpc, void *ctx) sca_hash_table_unlock_index(ht, i); - if (rc < 0) { + if(rc < 0) { return; } } @@ -141,35 +132,35 @@ void sca_rpc_subscription_count(rpc_t *rpc, void *ctx) sca_subscription *sub; str event_name = STR_NULL; char *usage = "usage: sca.subscription_count " - "{call-info | line-seize}"; + "{call-info | line-seize}"; unsigned long sub_count = 0; int i; int event_type; - if ((ht = sca->subscriptions) == NULL) { + if((ht = sca->subscriptions) == NULL) { rpc->fault(ctx, 500, "Empty subscription table!"); return; } // AoR is required - if (rpc->scan(ctx, "S", &event_name) != 1) { + if(rpc->scan(ctx, "S", &event_name) != 1) { rpc->fault(ctx, 500, usage); return; } event_type = sca_event_from_str(&event_name); - if (event_type == SCA_EVENT_TYPE_UNKNOWN) { + if(event_type == SCA_EVENT_TYPE_UNKNOWN) { rpc->fault(ctx, 500, usage); return; } - for (i = 0; i < ht->size; i++) { + for(i = 0; i < ht->size; i++) { sca_hash_table_lock_index(ht, i); - for (ent = ht->slots[i].entries; ent != NULL; ent = ent->next) { - sub = (sca_subscription *) ent->value; + for(ent = ht->slots[i].entries; ent != NULL; ent = ent->next) { + sub = (sca_subscription *)ent->value; - if (event_type == sub->event) { + if(event_type == sub->event) { sub_count++; } } @@ -191,15 +182,15 @@ void sca_rpc_deactivate_all_subscriptions(rpc_t *rpc, void *ctx) int i; int rc = 0; - if ((ht = sca->subscriptions) == NULL) { + if((ht = sca->subscriptions) == NULL) { rpc->fault(ctx, 500, "Empty subscription table!"); } - for (i = 0; i < ht->size; i++) { + for(i = 0; i < ht->size; i++) { sca_hash_table_lock_index(ht, i); - for (ent = ht->slots[i].entries; ent != NULL; ent = ent->next) { - sub = (sca_subscription *) ent->value; + for(ent = ht->slots[i].entries; ent != NULL; ent = ent->next) { + sub = (sca_subscription *)ent->value; sub->state = SCA_SUBSCRIPTION_STATE_TERMINATED_DEACTIVATED; sub->expires = 0; sub->dialog.notify_cseq += 1; @@ -207,14 +198,14 @@ void sca_rpc_deactivate_all_subscriptions(rpc_t *rpc, void *ctx) rpc->rpl_printf(ctx, "Deactivating %s subscription from %.*s", sca_event_name_from_type(sub->event), STR_FMT(&sub->subscriber)); - if (rc < 0) { + if(rc < 0) { // make sure we unlock below break; } - rc = sca_notify_subscriber(sca, sub, - SCA_CALL_INFO_APPEARANCE_INDEX_ANY); - if (rc < 0) { + rc = sca_notify_subscriber( + sca, sub, SCA_CALL_INFO_APPEARANCE_INDEX_ANY); + if(rc < 0) { // make sure we unlock below break; } @@ -222,7 +213,7 @@ void sca_rpc_deactivate_all_subscriptions(rpc_t *rpc, void *ctx) sca_hash_table_unlock_index(ht, i); - if (rc < 0) { + if(rc < 0) { return; } } @@ -251,33 +242,32 @@ void sca_rpc_show_subscription(rpc_t *rpc, void *ctx) str event_name = STR_NULL; int event_type; int idx = -1; - int rc = 0, - opt_rc; + int rc = 0, opt_rc; char keybuf[1024]; char *usage = "usage: sca.show_subscription sip:user@domain " - "{call-info | line-seize} [sip:user@IP]"; + "{call-info | line-seize} [sip:user@IP]"; char *err_msg = NULL; int err_code = 0; // AoR is required - if (rpc->scan(ctx, "SS", &aor, &event_name) != 2) { + if(rpc->scan(ctx, "SS", &aor, &event_name) != 2) { rpc->fault(ctx, 500, usage); } event_type = sca_event_from_str(&event_name); - if (event_type == SCA_EVENT_TYPE_UNKNOWN) { + if(event_type == SCA_EVENT_TYPE_UNKNOWN) { err_code = 500; err_msg = usage; goto done; } - if ((ht = sca->subscriptions) == NULL) { + if((ht = sca->subscriptions) == NULL) { rpc->fault(ctx, 500, "Empty subscription table!"); return; } sub_key.s = keybuf; - if (aor.len + event_name.len >= sizeof(keybuf)) { + if(aor.len + event_name.len >= sizeof(keybuf)) { rpc->fault(ctx, 500, "AoR length + event name length: too long"); } SCA_STR_COPY(&sub_key, &aor); @@ -289,14 +279,14 @@ void sca_rpc_show_subscription(rpc_t *rpc, void *ctx) // Contact is optional opt_rc = rpc->scan(ctx, "*S", &contact); - for (ent = ht->slots[idx].entries; ent != NULL; ent = ent->next) { - sub = (sca_subscription *) ent->value; - if (ent->compare(&aor, &sub->target_aor) != 0) { + for(ent = ht->slots[idx].entries; ent != NULL; ent = ent->next) { + sub = (sca_subscription *)ent->value; + if(ent->compare(&aor, &sub->target_aor) != 0) { continue; } - if (opt_rc == 1) { - if (!SCA_STR_EQ(&contact, &sub->subscriber)) { + if(opt_rc == 1) { + if(!SCA_STR_EQ(&contact, &sub->subscriber)) { continue; } } @@ -305,17 +295,18 @@ void sca_rpc_show_subscription(rpc_t *rpc, void *ctx) sca_event_name_from_type(sub->event), STR_FMT(&sub->subscriber), sub->expires); - if (rc < 0) { + if(rc < 0) { // make sure we unlock below break; } } - done: if (ht && idx >= 0) { +done: + if(ht && idx >= 0) { sca_hash_table_unlock_index(ht, idx); } - if (err_code != 0) { + if(err_code != 0) { rpc->fault(ctx, err_code, err_msg); } } @@ -341,26 +332,28 @@ void sca_rpc_show_all_appearances(rpc_t *rpc, void *ctx) int i; int rc = 0; - if ((ht = sca->appearances) == NULL) { + if((ht = sca->appearances) == NULL) { return; } - for (i = 0; i < ht->size; i++) { + for(i = 0; i < ht->size; i++) { sca_hash_table_lock_index(ht, i); - for (ent = ht->slots[i].entries; ent != NULL; ent = ent->next) { - app_list = (sca_appearance_list *) ent->value; - for (app = app_list->appearances; app != NULL; app = app->next) { + for(ent = ht->slots[i].entries; ent != NULL; ent = ent->next) { + app_list = (sca_appearance_list *)ent->value; + for(app = app_list->appearances; app != NULL; app = app->next) { sca_appearance_state_to_str(app->state, &state_str); - rc = rpc->rpl_printf(ctx, "%.*s %d %.*s %ld %.*s %.*s " - "%.*s %.*s %.*s", STR_FMT(&app_list->aor), app->index, - STR_FMT(&state_str), (long) app->times.mtime, + rc = rpc->rpl_printf(ctx, + "%.*s %d %.*s %ld %.*s %.*s " + "%.*s %.*s %.*s", + STR_FMT(&app_list->aor), app->index, + STR_FMT(&state_str), (long)app->times.mtime, STR_FMT(&app->owner), STR_FMT(&app->callee), STR_FMT(&app->dialog.call_id), STR_FMT(&app->dialog.from_tag), STR_FMT(&app->dialog.to_tag)); - if (rc < 0) { + if(rc < 0) { // make sure we unlock below goto error; } @@ -372,7 +365,7 @@ void sca_rpc_show_all_appearances(rpc_t *rpc, void *ctx) return; - error: +error: sca_hash_table_unlock_index(ht, i); return; } @@ -396,13 +389,13 @@ void sca_rpc_seize_appearance(rpc_t *rpc, void *ctx) char *usage = "usage: sca.seize_appearance sip:user@domain"; // AoR & Contact are required - if (rpc->scan(ctx, "SS", &aor, &owner) != 2) { + if(rpc->scan(ctx, "SS", &aor, &owner) != 2) { rpc->fault(ctx, 500, usage); return; } app_idx = sca_appearance_seize_next_available_index(sca, &aor, &owner); - if (app_idx < 0) { + if(app_idx < 0) { rpc->fault(ctx, 500, "Failed to seize line"); return; } @@ -410,7 +403,7 @@ void sca_rpc_seize_appearance(rpc_t *rpc, void *ctx) rpc->rpl_printf(ctx, "Seized %.*s appearance-index %d for %.*s", STR_FMT(&aor), app_idx, STR_FMT(&owner)); - if (sca_notify_call_info_subscribers(sca, &aor) < 0) { + if(sca_notify_call_info_subscribers(sca, &aor) < 0) { rpc->fault(ctx, 500, "Failed to NOTIFY subscribers to %.*s", STR_FMT(&aor)); } @@ -423,38 +416,37 @@ void sca_rpc_update_appearance(rpc_t *rpc, void *ctx) { str aor = STR_NULL; str app_state_str = STR_NULL; - str app_uri = STR_NULL, - *app_uri_p = NULL; + str app_uri = STR_NULL, *app_uri_p = NULL; int app_idx; int app_state; int rc; char *usage = "Usage: sca.update_appearance " - "sip:user@domain appearance-index " - "appearance-state [appearance-uri]"; + "sip:user@domain appearance-index " + "appearance-state [appearance-uri]"; - if (rpc->scan(ctx, "SdS", &aor, &app_idx, &app_state_str) < 3) { + if(rpc->scan(ctx, "SdS", &aor, &app_idx, &app_state_str) < 3) { rpc->fault(ctx, 500, "%s", usage); return; } - if (rpc->scan(ctx, "*S", &app_uri) == 1) { + if(rpc->scan(ctx, "*S", &app_uri) == 1) { app_uri_p = &app_uri; } app_state = sca_appearance_state_from_str(&app_state_str); - if (app_state == SCA_APPEARANCE_STATE_UNKNOWN) { + if(app_state == SCA_APPEARANCE_STATE_UNKNOWN) { rpc->fault(ctx, 500, "%.*s: invalid state", STR_FMT(&app_state_str)); return; } - rc = sca_appearance_update_index(sca, &aor, app_idx, app_state, NULL, - app_uri_p, NULL); - if (rc != SCA_APPEARANCE_OK) { + rc = sca_appearance_update_index( + sca, &aor, app_idx, app_state, NULL, app_uri_p, NULL); + if(rc != SCA_APPEARANCE_OK) { rpc->fault(ctx, 500, "Failed to update %.*s appearance-index %d", STR_FMT(&aor), app_idx); return; } - if (sca_notify_call_info_subscribers(sca, &aor) < 0) { + if(sca_notify_call_info_subscribers(sca, &aor) < 0) { rpc->fault(ctx, 500, "Failed to NOTIFY subscribers to %.*s", STR_FMT(&aor)); } @@ -473,22 +465,22 @@ void sca_rpc_release_appearance(rpc_t *rpc, void *ctx) int idx = -1; int app_idx; char *usage = "usage: sca.release_appearance user@domain " - "appearance-index"; + "appearance-index"; char *err_msg = NULL; int err_code = 0; // AoR & appearance-index are required - if (rpc->scan(ctx, "Sd", &aor, &app_idx) != 2) { + if(rpc->scan(ctx, "Sd", &aor, &app_idx) != 2) { rpc->fault(ctx, 500, usage); return; } - if (app_idx <= 0) { + if(app_idx <= 0) { rpc->fault(ctx, 500, "appearance-index must be > 0"); return; } - if ((ht = sca->appearances) == NULL) { + if((ht = sca->appearances) == NULL) { rpc->fault(ctx, 500, "No active appearances"); return; } @@ -496,37 +488,38 @@ void sca_rpc_release_appearance(rpc_t *rpc, void *ctx) idx = sca_hash_table_index_for_key(ht, &aor); sca_hash_table_lock_index(ht, idx); - for (ent = ht->slots[idx].entries; ent != NULL; ent = ent->next) { - if (ent->compare(&aor, ent->value) == 0) { - app_list = (sca_appearance_list *) ent->value; + for(ent = ht->slots[idx].entries; ent != NULL; ent = ent->next) { + if(ent->compare(&aor, ent->value) == 0) { + app_list = (sca_appearance_list *)ent->value; break; } } - if (app_list == NULL) { + if(app_list == NULL) { rpc->fault(ctx, 500, "No appearances for %.*s", STR_FMT(&aor)); goto done; } app = sca_appearance_list_unlink_index(app_list, app_idx); - if (app == NULL) { + if(app == NULL) { rpc->fault(ctx, 500, "%.*s appearance index %d is not in use", STR_FMT(&aor), app_idx); goto done; } sca_appearance_free(app); - done: if (ht && idx >= 0) { +done: + if(ht && idx >= 0) { sca_hash_table_unlock_index(ht, idx); } - if (app != NULL) { - if (sca_notify_call_info_subscribers(sca, &aor) < 0) { + if(app != NULL) { + if(sca_notify_call_info_subscribers(sca, &aor) < 0) { rpc->fault(ctx, 500, "Failed to NOTIFY subscribers to %.*s", STR_FMT(&aor)); } } - if (err_code != 0) { + if(err_code != 0) { rpc->fault(ctx, err_code, err_msg); } } diff --git a/src/modules/sca/sca_subscribe.c b/src/modules/sca/sca_subscribe.c index 8040d49aa..dc33f0057 100644 --- a/src/modules/sca/sca_subscribe.c +++ b/src/modules/sca/sca_subscribe.c @@ -41,7 +41,8 @@ void sca_subscription_print(void *); const str SCA_METHOD_SUBSCRIBE = STR_STATIC_INIT("SUBSCRIBE"); -struct sca_sub_state_table { +struct sca_sub_state_table +{ int state; char *state_name; } state_table[] = { @@ -74,7 +75,7 @@ void sca_subscription_state_to_str(int state, str *state_str_out) void sca_subscription_purge_expired(unsigned int ticks, void *param) { - sca_mod *scam = (sca_mod *) param; + sca_mod *scam = (sca_mod *)param; sca_hash_table *ht; sca_hash_entry *ent, *ent_tmp; sca_subscription *sub; @@ -88,46 +89,48 @@ void sca_subscription_purge_expired(unsigned int ticks, void *param) LM_INFO("SCA: purging expired subscriptions\n"); ht = scam->subscriptions; - for (i = 0; i < ht->size; i++) { + for(i = 0; i < ht->size; i++) { sca_hash_table_lock_index(ht, i); - for (ent = ht->slots[i].entries; ent != NULL; ent = ent_tmp) { + for(ent = ht->slots[i].entries; ent != NULL; ent = ent_tmp) { ent_tmp = ent->next; - sub = (sca_subscription *) ent->value; - if (sub == NULL || sub->expires > now) { + sub = (sca_subscription *)ent->value; + if(sub == NULL || sub->expires > now) { continue; } - if (!SCA_SUBSCRIPTION_IS_TERMINATED(sub)) { + if(!SCA_SUBSCRIPTION_IS_TERMINATED(sub)) { sub->state = SCA_SUBSCRIPTION_STATE_TERMINATED_TIMEOUT; sub->expires = 0; sub->dialog.notify_cseq += 1; - if (sca_notify_subscriber(scam, sub, sub->index) < 0) { + if(sca_notify_subscriber(scam, sub, sub->index) < 0) { LM_ERR("Failed to send subscription expired " - "NOTIFY %s subscriber %.*s\n", + "NOTIFY %s subscriber %.*s\n", sca_event_name_from_type(sub->event), STR_FMT(&sub->subscriber)); // remove from subscribers list anyway } - if (sub->event == SCA_EVENT_TYPE_LINE_SEIZE) { + if(sub->event == SCA_EVENT_TYPE_LINE_SEIZE) { // only notify if the line is just seized - state = sca_appearance_state_for_index(sca, - &sub->target_aor, sub->index); - if (state == SCA_APPEARANCE_STATE_SEIZED) { - if (sca_appearance_release_index(sca, &sub->target_aor, - sub->index) < 0) { + state = sca_appearance_state_for_index( + sca, &sub->target_aor, sub->index); + if(state == SCA_APPEARANCE_STATE_SEIZED) { + if(sca_appearance_release_index( + sca, &sub->target_aor, sub->index) + < 0) { LM_ERR("Failed to release seized %.*s " - "appearance-index %d\n", + "appearance-index %d\n", STR_FMT(&sub->target_aor), sub->index); } - if (sca_notify_call_info_subscribers(sca, - &sub->target_aor) < 0) { + if(sca_notify_call_info_subscribers( + sca, &sub->target_aor) + < 0) { LM_ERR("SCA %s NOTIFY to all %.*s " - "subscribers failed\n", + "subscribers failed\n", sca_event_name_from_type(sub->event), STR_FMT(&sub->target_aor)); // fall through anyway. the state should propagate @@ -159,32 +162,32 @@ int sca_subscription_from_db_row_values(db_val_t *values, sca_subscription *sub) assert(sub != NULL); // XXX condense to loop with preprocessor macros when there's time - sca_db_subscriptions_get_value_for_column(SCA_DB_SUBS_SUBSCRIBER_COL, - values, &sub->subscriber); - sca_db_subscriptions_get_value_for_column(SCA_DB_SUBS_AOR_COL, values, - &sub->target_aor); - sca_db_subscriptions_get_value_for_column(SCA_DB_SUBS_EVENT_COL, values, - &sub->event); - sca_db_subscriptions_get_value_for_column(SCA_DB_SUBS_EXPIRES_COL, values, - &sub->expires); - sca_db_subscriptions_get_value_for_column(SCA_DB_SUBS_STATE_COL, values, - &sub->state); - sca_db_subscriptions_get_value_for_column(SCA_DB_SUBS_APP_IDX_COL, values, - &sub->index); - sca_db_subscriptions_get_value_for_column(SCA_DB_SUBS_CALL_ID_COL, values, - &sub->dialog.call_id); - sca_db_subscriptions_get_value_for_column(SCA_DB_SUBS_FROM_TAG_COL, values, - &sub->dialog.from_tag); - sca_db_subscriptions_get_value_for_column(SCA_DB_SUBS_TO_TAG_COL, values, - &sub->dialog.to_tag); - sca_db_subscriptions_get_value_for_column(SCA_DB_SUBS_RECORD_ROUTE_COL, - values, &sub->rr); - sca_db_subscriptions_get_value_for_column(SCA_DB_SUBS_NOTIFY_CSEQ_COL, - values, &sub->dialog.notify_cseq); + sca_db_subscriptions_get_value_for_column( + SCA_DB_SUBS_SUBSCRIBER_COL, values, &sub->subscriber); + sca_db_subscriptions_get_value_for_column( + SCA_DB_SUBS_AOR_COL, values, &sub->target_aor); + sca_db_subscriptions_get_value_for_column( + SCA_DB_SUBS_EVENT_COL, values, &sub->event); + sca_db_subscriptions_get_value_for_column( + SCA_DB_SUBS_EXPIRES_COL, values, &sub->expires); + sca_db_subscriptions_get_value_for_column( + SCA_DB_SUBS_STATE_COL, values, &sub->state); + sca_db_subscriptions_get_value_for_column( + SCA_DB_SUBS_APP_IDX_COL, values, &sub->index); + sca_db_subscriptions_get_value_for_column( + SCA_DB_SUBS_CALL_ID_COL, values, &sub->dialog.call_id); + sca_db_subscriptions_get_value_for_column( + SCA_DB_SUBS_FROM_TAG_COL, values, &sub->dialog.from_tag); + sca_db_subscriptions_get_value_for_column( + SCA_DB_SUBS_TO_TAG_COL, values, &sub->dialog.to_tag); + sca_db_subscriptions_get_value_for_column( + SCA_DB_SUBS_RECORD_ROUTE_COL, values, &sub->rr); + sca_db_subscriptions_get_value_for_column( + SCA_DB_SUBS_NOTIFY_CSEQ_COL, values, &sub->dialog.notify_cseq); sca_db_subscriptions_get_value_for_column(SCA_DB_SUBS_SUBSCRIBE_CSEQ_COL, values, &sub->dialog.subscribe_cseq); - sca_db_subscriptions_get_value_for_column(SCA_DB_SUBS_SERVER_ID_COL, - values, &sub->server_id); + sca_db_subscriptions_get_value_for_column( + SCA_DB_SUBS_SERVER_ID_COL, values, &sub->server_id); return (0); } @@ -196,35 +199,35 @@ int sca_subscription_to_db_row_values(sca_subscription *sub, db_val_t *values) assert(sub != NULL); assert(values != NULL); - sca_db_subscriptions_set_value_for_column(SCA_DB_SUBS_SUBSCRIBER_COL, - values, &sub->subscriber); - sca_db_subscriptions_set_value_for_column(SCA_DB_SUBS_AOR_COL, values, - &sub->target_aor); - sca_db_subscriptions_set_value_for_column(SCA_DB_SUBS_EVENT_COL, values, - &sub->event); - sca_db_subscriptions_set_value_for_column(SCA_DB_SUBS_EXPIRES_COL, values, - &sub->expires); - sca_db_subscriptions_set_value_for_column(SCA_DB_SUBS_STATE_COL, values, - &sub->state); - sca_db_subscriptions_set_value_for_column(SCA_DB_SUBS_APP_IDX_COL, values, - &sub->index); - sca_db_subscriptions_set_value_for_column(SCA_DB_SUBS_CALL_ID_COL, values, - &sub->dialog.call_id); - sca_db_subscriptions_set_value_for_column(SCA_DB_SUBS_FROM_TAG_COL, values, - &sub->dialog.from_tag); - sca_db_subscriptions_set_value_for_column(SCA_DB_SUBS_TO_TAG_COL, values, - &sub->dialog.to_tag); - sca_db_subscriptions_set_value_for_column(SCA_DB_SUBS_RECORD_ROUTE_COL, - values, &sub->rr); + sca_db_subscriptions_set_value_for_column( + SCA_DB_SUBS_SUBSCRIBER_COL, values, &sub->subscriber); + sca_db_subscriptions_set_value_for_column( + SCA_DB_SUBS_AOR_COL, values, &sub->target_aor); + sca_db_subscriptions_set_value_for_column( + SCA_DB_SUBS_EVENT_COL, values, &sub->event); + sca_db_subscriptions_set_value_for_column( + SCA_DB_SUBS_EXPIRES_COL, values, &sub->expires); + sca_db_subscriptions_set_value_for_column( + SCA_DB_SUBS_STATE_COL, values, &sub->state); + sca_db_subscriptions_set_value_for_column( + SCA_DB_SUBS_APP_IDX_COL, values, &sub->index); + sca_db_subscriptions_set_value_for_column( + SCA_DB_SUBS_CALL_ID_COL, values, &sub->dialog.call_id); + sca_db_subscriptions_set_value_for_column( + SCA_DB_SUBS_FROM_TAG_COL, values, &sub->dialog.from_tag); + sca_db_subscriptions_set_value_for_column( + SCA_DB_SUBS_TO_TAG_COL, values, &sub->dialog.to_tag); + sca_db_subscriptions_set_value_for_column( + SCA_DB_SUBS_RECORD_ROUTE_COL, values, &sub->rr); notify_cseq = sub->dialog.notify_cseq + 1; subscribe_cseq = sub->dialog.subscribe_cseq + 1; - sca_db_subscriptions_set_value_for_column(SCA_DB_SUBS_NOTIFY_CSEQ_COL, - values, ¬ify_cseq); - sca_db_subscriptions_set_value_for_column(SCA_DB_SUBS_SUBSCRIBE_CSEQ_COL, - values, &subscribe_cseq); - sca_db_subscriptions_set_value_for_column(SCA_DB_SUBS_SERVER_ID_COL, - values, &sub->server_id); + sca_db_subscriptions_set_value_for_column( + SCA_DB_SUBS_NOTIFY_CSEQ_COL, values, ¬ify_cseq); + sca_db_subscriptions_set_value_for_column( + SCA_DB_SUBS_SUBSCRIBE_CSEQ_COL, values, &subscribe_cseq); + sca_db_subscriptions_set_value_for_column( + SCA_DB_SUBS_SERVER_ID_COL, values, &sub->server_id); return (0); } @@ -250,71 +253,74 @@ int sca_subscriptions_restore_from_db(sca_mod *scam) time_t now = time(NULL); db_con = scam->db_api->init(scam->cfg->db_url); - if (db_con == NULL) { + if(db_con == NULL) { LM_ERR("sca_subscriptions_restore_from_db: failed to connect " - "to DB %.*s\n", STR_FMT(scam->cfg->db_url)); + "to DB %.*s\n", + STR_FMT(scam->cfg->db_url)); return (-1); } scam->db_api->use_table(db_con, scam->cfg->subs_table); column_names = sca_db_subscriptions_columns(); - if (column_names == NULL) { + if(column_names == NULL) { LM_ERR("sca_subscriptions_restore_from_db: failed to get " - "column names for SCA subscriptions table\n"); + "column names for SCA subscriptions table\n"); goto done; } - for (i = 0; i < SCA_DB_SUBSCRIPTIONS_NUM_COLUMNS; i++) { + for(i = 0; i < SCA_DB_SUBSCRIPTIONS_NUM_COLUMNS; i++) { result_columns[i] = column_names[i]; } - query_columns[q_count] = (str *) &SCA_DB_SERVER_ID_COL_NAME; + query_columns[q_count] = (str *)&SCA_DB_SERVER_ID_COL_NAME; query_ops[q_count] = OP_EQ; SCA_DB_BIND_INT_VALUE(server_id, &SCA_DB_SERVER_ID_COL_NAME, query_columns, - query_values, q_count); + query_values, q_count); rc = db_fetch_query(scam->db_api, SCA_DB_DEFAULT_FETCH_ROW_COUNT, db_con, query_columns, query_ops, query_values, result_columns, q_count, SCA_DB_SUBSCRIPTIONS_NUM_COLUMNS, 0, &result); - switch (rc) { - default: - case -1: - LM_ERR("sca_subscriptions_restore_from_db: query failed\n"); - goto done; + switch(rc) { + default: + case -1: + LM_ERR("sca_subscriptions_restore_from_db: query failed\n"); + goto done; - case 0: - LM_WARN("sca_subscriptions_restore_from_db: DB module does " - "not support fetch, query returning all values...\n"); - // fall through + case 0: + LM_WARN("sca_subscriptions_restore_from_db: DB module does " + "not support fetch, query returning all values...\n"); + // fall through - case 1: - break; + case 1: + break; } do { rows = RES_ROWS(result); num_rows = RES_ROW_N(result); - for (i = 0; i < num_rows; i++) { + for(i = 0; i < num_rows; i++) { memset(&sub, 0, sizeof(sca_subscription)); row_values = ROW_VALUES(rows + i); sub.expires = row_values[SCA_DB_SUBS_EXPIRES_COL].val.time_val; - if (sub.expires < now) { + if(sub.expires < now) { continue; } - if (sca_subscription_from_db_row_values(row_values, &sub) < 0) { + if(sca_subscription_from_db_row_values(row_values, &sub) < 0) { LM_ERR("sca_subscriptions_restore_from_db: skipping bad result " - "at index %d\n", i); + "at index %d\n", + i); continue; } - if (sca_subscription_copy_subscription_key(&sub, &sub_key) < 0) { + if(sca_subscription_copy_subscription_key(&sub, &sub_key) < 0) { LM_ERR("sca_subscriptions_restore_from_db: failed to copy " - "subscription key %.*s%s\n", STR_FMT(&sub.subscriber), + "subscription key %.*s%s\n", + STR_FMT(&sub.subscriber), sca_event_name_from_type(sub.event)); continue; } @@ -324,10 +330,11 @@ int sca_subscriptions_restore_from_db(sca_mod *scam) sca_hash_table_lock_index(sca->subscriptions, idx); - if (sca_subscription_save_unsafe(scam, &sub, idx, - SCA_SUBSCRIPTION_CREATE_OPT_RAW_EXPIRES) < 0) { + if(sca_subscription_save_unsafe( + scam, &sub, idx, SCA_SUBSCRIPTION_CREATE_OPT_RAW_EXPIRES) + < 0) { LM_ERR("sca_subscriptions_restore_from_db: failed to restore " - "%s subscription from %.*s to the hash table\n", + "%s subscription from %.*s to the hash table\n", sca_event_name_from_type(sub.event), STR_FMT(&sub.subscriber)); // fall through to unlock index @@ -335,28 +342,31 @@ int sca_subscriptions_restore_from_db(sca_mod *scam) sca_hash_table_unlock_index(sca->subscriptions, idx); } - } while (db_fetch_next(scam->db_api, SCA_DB_DEFAULT_FETCH_ROW_COUNT, db_con, - &result) == 1 && num_rows > 0); + } while(db_fetch_next(scam->db_api, SCA_DB_DEFAULT_FETCH_ROW_COUNT, db_con, + &result) + == 1 + && num_rows > 0); scam->db_api->free_result(db_con, result); // clear all records from table, let timer process repopulate it - if (scam->db_api->delete(db_con, NULL, NULL, NULL, 0) < 0) { + if(scam->db_api->delete(db_con, NULL, NULL, NULL, 0) < 0) { LM_ERR("sca_subscriptions_restore_from_db: failed to delete " - "records from table after restoring\n"); + "records from table after restoring\n"); goto done; } rc = 0; - done: scam->db_api->close(db_con); +done: + scam->db_api->close(db_con); db_con = NULL; return (rc); } -static int sca_subscription_db_update_subscriber(db1_con_t *db_con, - sca_subscription *sub) +static int sca_subscription_db_update_subscriber( + db1_con_t *db_con, sca_subscription *sub) { db_key_t query_columns[1]; db_val_t query_values[1]; @@ -388,11 +398,12 @@ static int sca_subscription_db_update_subscriber(db1_con_t *db_con, &SCA_DB_SUBSCRIBE_CSEQ_COL_NAME, update_columns, update_values, update_column_idx); - if (sca->db_api->update(db_con, query_columns, NULL, query_values, - update_columns, update_values, query_column_idx, update_column_idx) + if(sca->db_api->update(db_con, query_columns, NULL, query_values, + update_columns, update_values, query_column_idx, + update_column_idx) < 0) { LM_ERR("sca_subscription_db_update_subscriber: failed to update " - "%s subscriber %.*s in DB\n", + "%s subscriber %.*s in DB\n", sca_event_name_from_type(sub->event), STR_FMT(&sub->subscriber)); return (-1); @@ -404,8 +415,8 @@ static int sca_subscription_db_update_subscriber(db1_con_t *db_con, return (0); } -static int sca_subscription_db_insert_subscriber(db1_con_t *db_con, - sca_subscription *sub) +static int sca_subscription_db_insert_subscriber( + db1_con_t *db_con, sca_subscription *sub) { db_key_t insert_columns[SCA_DB_SUBSCRIPTIONS_NUM_COLUMNS]; db_val_t insert_values[SCA_DB_SUBSCRIPTIONS_NUM_COLUMNS]; @@ -416,29 +427,30 @@ static int sca_subscription_db_insert_subscriber(db1_con_t *db_con, assert(sub != NULL); column_names = sca_db_subscriptions_columns(); - if (column_names == NULL) { + if(column_names == NULL) { LM_ERR("sca_subscriptions_restore_from_db: failed to get " - "column names for SCA subscriptions table\n"); + "column names for SCA subscriptions table\n"); return (-1); } - for (i = 0; i < SCA_DB_SUBSCRIPTIONS_NUM_COLUMNS; i++) { + for(i = 0; i < SCA_DB_SUBSCRIPTIONS_NUM_COLUMNS; i++) { insert_columns[i] = column_names[i]; } // XXX array boundary checking - if (sca_subscription_to_db_row_values(sub, insert_values) != 0) { + if(sca_subscription_to_db_row_values(sub, insert_values) != 0) { LM_ERR("sca_subscription_db_insert_subscriber: failed to set " - "DB row values for INSERT of %s subscriber %.*s\n", + "DB row values for INSERT of %s subscriber %.*s\n", sca_event_name_from_type(sub->event), STR_FMT(&sub->subscriber)); return (-1); } - if (sca->db_api->insert(db_con, insert_columns, insert_values, - SCA_DB_SUBSCRIPTIONS_NUM_COLUMNS) < 0) { + if(sca->db_api->insert(db_con, insert_columns, insert_values, + SCA_DB_SUBSCRIPTIONS_NUM_COLUMNS) + < 0) { LM_ERR("sca_subscription_db_insert_subscriber: failed to insert " - "%s subscriber %.*s in DB subscription table\n", + "%s subscriber %.*s in DB subscription table\n", sca_event_name_from_type(sub->event), STR_FMT(&sub->subscriber)); return (-1); @@ -458,22 +470,24 @@ int sca_subscription_db_delete_expired(db1_con_t *db_con) time_t now = time(NULL); int kv_count = 0; - delete_columns[kv_count] = (str *) &SCA_DB_SERVER_ID_COL_NAME; + delete_columns[kv_count] = (str *)&SCA_DB_SERVER_ID_COL_NAME; delete_ops[kv_count] = OP_EQ; SCA_DB_BIND_INT_VALUE(server_id, &SCA_DB_SERVER_ID_COL_NAME, delete_columns, delete_values, kv_count); - delete_columns[kv_count] = (str *) &SCA_DB_EXPIRES_COL_NAME; + delete_columns[kv_count] = (str *)&SCA_DB_EXPIRES_COL_NAME; delete_ops[kv_count] = OP_LT; SCA_DB_BIND_INT_VALUE(now, &SCA_DB_EXPIRES_COL_NAME, delete_columns, delete_values, kv_count); - if (sca->db_api->delete(db_con, delete_columns, delete_ops, delete_values, - kv_count) < 0) { + if(sca->db_api->delete( + db_con, delete_columns, delete_ops, delete_values, kv_count) + < 0) { LM_ERR("sca_subscription_db_delete_expired: failed to delete " - "subscriptions expired before %ld\n", (long int)now); + "subscriptions expired before %ld\n", + (long int)now); return (-1); } @@ -491,48 +505,49 @@ int sca_subscription_db_update(void) time_t now = time(NULL); db_con = sca_db_get_connection(); - if (db_con == NULL) { + if(db_con == NULL) { LM_ERR("sca_subscription_db_update: failed to connect to DB %.*s\n", STR_FMT(sca->cfg->db_url)); goto done; } - if (sca->db_api->use_table(db_con, sca->cfg->subs_table) < 0) { + if(sca->db_api->use_table(db_con, sca->cfg->subs_table) < 0) { LM_ERR("sca_subscription_db_update: failed to in-use table " - "for DB %.*s\n", STR_FMT(sca->cfg->db_url)); + "for DB %.*s\n", + STR_FMT(sca->cfg->db_url)); goto done; } ht = sca->subscriptions; - for (i = 0; i < ht->size; i++) { + for(i = 0; i < ht->size; i++) { sca_hash_table_lock_index(ht, i); - for (entry = ht->slots[i].entries; entry != NULL; entry = entry->next) { - sub = (sca_subscription *) entry->value; + for(entry = ht->slots[i].entries; entry != NULL; entry = entry->next) { + sub = (sca_subscription *)entry->value; - if (sub == NULL || sub->expires < now) { + if(sub == NULL || sub->expires < now) { continue; } // we only do call-info subscriptions for now - if (sub->event != SCA_EVENT_TYPE_CALL_INFO) { + if(sub->event != SCA_EVENT_TYPE_CALL_INFO) { continue; } - if (SCA_SUBSCRIPTION_IS_TERMINATED(sub)) { + if(SCA_SUBSCRIPTION_IS_TERMINATED(sub)) { continue; } - if (sub->db_cmd_flag == SCA_DB_FLAG_INSERT) { - if (sca_subscription_db_insert_subscriber(db_con, sub) < 0) { + if(sub->db_cmd_flag == SCA_DB_FLAG_INSERT) { + if(sca_subscription_db_insert_subscriber(db_con, sub) < 0) { LM_ERR("sca_subscription_db_update: failed to insert " - "%s subscriber %.*s into subscription DB\n", + "%s subscriber %.*s into subscription DB\n", sca_event_name_from_type(sub->event), STR_FMT(&sub->subscriber)); } - } else if (sub->db_cmd_flag == SCA_DB_FLAG_UPDATE) { - if (sca_subscription_db_update_subscriber(db_con, sub) < 0) { + } else if(sub->db_cmd_flag == SCA_DB_FLAG_UPDATE) { + if(sca_subscription_db_update_subscriber(db_con, sub) < 0) { LM_ERR("sca_subscription_db_update: failed to insert " - "%s subscriber %.*s into subscription DB\n", + "%s subscriber %.*s into subscription DB\n", sca_event_name_from_type(sub->event), STR_FMT(&sub->subscriber)); } @@ -544,14 +559,16 @@ int sca_subscription_db_update(void) rc = sca_subscription_db_delete_expired(db_con); - done: return (rc); +done: + return (rc); } void sca_subscription_db_update_timer(unsigned int ticks, void *param) { - if (sca_subscription_db_update() != 0) { + if(sca_subscription_db_update() != 0) { LM_ERR("sca_subscription_db_update_timer: failed to update " - "subscriptions in DB %.*s\n", STR_FMT(sca->cfg->db_url)); + "subscriptions in DB %.*s\n", + STR_FMT(sca->cfg->db_url)); } } @@ -568,10 +585,11 @@ int sca_subscription_aor_has_subscribers(int event, str *aor) event_name = sca_event_name_from_type(event); len = aor->len + strlen(event_name); - sub_key.s = (char *) pkg_malloc(len); - if (sub_key.s == NULL) { + sub_key.s = (char *)pkg_malloc(len); + if(sub_key.s == NULL) { LM_ERR("Failed to pkg_malloc key to look up %s " - "subscription for %.*s\n", event_name, STR_FMT(aor)); + "subscription for %.*s\n", + event_name, STR_FMT(aor)); return (-1); } SCA_STR_COPY(&sub_key, aor); @@ -584,10 +602,10 @@ int sca_subscription_aor_has_subscribers(int event, str *aor) slot = sca_hash_table_slot_for_index(sca->subscriptions, slot_idx); sca_hash_table_lock_index(sca->subscriptions, slot_idx); - for (e = slot->entries; e != NULL; e = e->next) { - sub = (sca_subscription *) e->value; + for(e = slot->entries; e != NULL; e = e->next) { + sub = (sca_subscription *)e->value; - if (SCA_STR_EQ(&sub->target_aor, aor)) { + if(SCA_STR_EQ(&sub->target_aor, aor)) { subscribers = 1; break; } @@ -607,12 +625,12 @@ sca_subscription *sca_subscription_create(str *aor, int event, str *subscriber, len += sizeof(sca_subscription); len += sizeof(char) * (aor->len + subscriber->len); - if (!SCA_STR_EMPTY(rr)) { + if(!SCA_STR_EMPTY(rr)) { len += sizeof(char) * rr->len; } - sub = (sca_subscription *) shm_malloc(len); - if (sub == NULL) { + sub = (sca_subscription *)shm_malloc(len); + if(sub == NULL) { LM_ERR("Failed to create %s subscription for %.*s: out of memory\n", sca_event_name_from_type(event), STR_FMT(subscriber)); goto error; @@ -622,7 +640,7 @@ sca_subscription *sca_subscription_create(str *aor, int event, str *subscriber, sub->event = event; sub->state = SCA_SUBSCRIPTION_STATE_ACTIVE; sub->index = SCA_CALL_INFO_APPEARANCE_INDEX_ANY; - if (opts & SCA_SUBSCRIPTION_CREATE_OPT_RAW_EXPIRES) { + if(opts & SCA_SUBSCRIPTION_CREATE_OPT_RAW_EXPIRES) { sub->expires = expire_delta; } else { sub->expires = time(NULL) + expire_delta; @@ -633,16 +651,16 @@ sca_subscription *sca_subscription_create(str *aor, int event, str *subscriber, len = sizeof(sca_subscription); - sub->subscriber.s = (char *) sub + len; + sub->subscriber.s = (char *)sub + len; SCA_STR_COPY(&sub->subscriber, subscriber); len += subscriber->len; - sub->target_aor.s = (char *) sub + len; + sub->target_aor.s = (char *)sub + len; SCA_STR_COPY(&sub->target_aor, aor); len += aor->len; - if (!SCA_STR_EMPTY(rr)) { - sub->rr.s = (char *) sub + len; + if(!SCA_STR_EMPTY(rr)) { + sub->rr.s = (char *)sub + len; SCA_STR_COPY(&sub->rr, rr); len += rr->len; } @@ -654,10 +672,11 @@ sca_subscription *sca_subscription_create(str *aor, int event, str *subscriber, // dialog saved for this subscriber. this is likely to happen if the // subscriber goes off-line for some reason. len = sizeof(char) * (call_id->len + from_tag->len + to_tag->len); - sub->dialog.id.s = (char *) shm_malloc(len); - if (sub->dialog.id.s == NULL) { + sub->dialog.id.s = (char *)shm_malloc(len); + if(sub->dialog.id.s == NULL) { LM_ERR("Failed to shm_malloc space for %.*s %s subscription dialog: " - "out of memory\n", STR_FMT(&sub->subscriber), + "out of memory\n", + STR_FMT(&sub->subscriber), sca_event_name_from_type(sub->event)); goto error; } @@ -680,8 +699,9 @@ sca_subscription *sca_subscription_create(str *aor, int event, str *subscriber, return (sub); - error: if (sub != NULL) { - if (sub->dialog.id.s != NULL) { +error: + if(sub != NULL) { + if(sub->dialog.id.s != NULL) { shm_free(sub->dialog.id.s); } shm_free(sub); @@ -692,10 +712,10 @@ sca_subscription *sca_subscription_create(str *aor, int event, str *subscriber, int sca_subscription_subscriber_cmp(str *subscriber, void *cmp_value) { - sca_subscription *sub = (sca_subscription *) cmp_value; + sca_subscription *sub = (sca_subscription *)cmp_value; int cmp; - if ((cmp = subscriber->len - sub->subscriber.len) != 0) { + if((cmp = subscriber->len - sub->subscriber.len) != 0) { return (cmp); } @@ -704,17 +724,16 @@ int sca_subscription_subscriber_cmp(str *subscriber, void *cmp_value) void sca_subscription_free(void *value) { - sca_subscription *sub = (sca_subscription *) value; + sca_subscription *sub = (sca_subscription *)value; - if (sub == NULL) { + if(sub == NULL) { return; } LM_DBG("Freeing %s subscription from %.*s\n", - sca_event_name_from_type(sub->event), - STR_FMT(&sub->subscriber)); + sca_event_name_from_type(sub->event), STR_FMT(&sub->subscriber)); - if (!SCA_STR_EMPTY(&sub->dialog.id)) { + if(!SCA_STR_EMPTY(&sub->dialog.id)) { shm_free(sub->dialog.id.s); } @@ -723,28 +742,23 @@ void sca_subscription_free(void *value) void sca_subscription_print(void *value) { - sca_subscription *sub = (sca_subscription *) value; + sca_subscription *sub = (sca_subscription *)value; LM_DBG("%.*s %s (%d) %.*s, expires: %ld, index: %d, " - "dialog %.*s;%.*s;%.*s, record_route: %.*s, " - "notify_cseq: %d, subscribe_cseq: %d, server_id: %d\n", - STR_FMT(&sub->target_aor), - sca_event_name_from_type(sub->event), - sub->event, - STR_FMT(&sub->subscriber), - (long int)sub->expires, sub->index, - STR_FMT(&sub->dialog.call_id), - STR_FMT(&sub->dialog.from_tag), - STR_FMT(&sub->dialog.to_tag), + "dialog %.*s;%.*s;%.*s, record_route: %.*s, " + "notify_cseq: %d, subscribe_cseq: %d, server_id: %d\n", + STR_FMT(&sub->target_aor), sca_event_name_from_type(sub->event), + sub->event, STR_FMT(&sub->subscriber), (long int)sub->expires, + sub->index, STR_FMT(&sub->dialog.call_id), + STR_FMT(&sub->dialog.from_tag), STR_FMT(&sub->dialog.to_tag), SCA_STR_EMPTY(&sub->rr) ? 4 : sub->rr.len, SCA_STR_EMPTY(&sub->rr) ? "null" : sub->rr.s, - sub->dialog.notify_cseq, - sub->dialog.subscribe_cseq, + sub->dialog.notify_cseq, sub->dialog.subscribe_cseq, sub->server_id); } -int sca_subscription_save_unsafe(sca_mod *scam, sca_subscription *sub, - int save_idx, int opts) +int sca_subscription_save_unsafe( + sca_mod *scam, sca_subscription *sub, int save_idx, int opts) { sca_subscription *new_sub = NULL; sca_hash_slot *slot; @@ -756,16 +770,16 @@ int sca_subscription_save_unsafe(sca_mod *scam, sca_subscription *sub, &sub->subscriber, sub->dialog.notify_cseq, sub->dialog.subscribe_cseq, sub->expires, &sub->dialog.call_id, &sub->dialog.from_tag, &sub->dialog.to_tag, &sub->rr, opts); - if (new_sub == NULL) { + if(new_sub == NULL) { return (-1); } - if (sub->index != SCA_CALL_INFO_APPEARANCE_INDEX_ANY) { + if(sub->index != SCA_CALL_INFO_APPEARANCE_INDEX_ANY) { new_sub->index = sub->index; } - if (sca_appearance_register(scam, &sub->target_aor) < 0) { + if(sca_appearance_register(scam, &sub->target_aor) < 0) { LM_ERR("sca_subscription_save: sca_appearance_register failed, " - "still saving subscription from %.*s\n", + "still saving subscription from %.*s\n", STR_FMT(&sub->subscriber)); } @@ -773,7 +787,7 @@ int sca_subscription_save_unsafe(sca_mod *scam, sca_subscription *sub, rc = sca_hash_table_slot_kv_insert_unsafe(slot, new_sub, sca_subscription_subscriber_cmp, sca_subscription_print, sca_subscription_free); - if (rc < 0) { + if(rc < 0) { shm_free(new_sub); new_sub = NULL; } @@ -788,38 +802,40 @@ static int sca_subscription_update_unsafe(sca_mod *scam, int len; char *dlg_id_tmp; - if (sub_idx < 0 || sub_idx > scam->subscriptions->size) { + if(sub_idx < 0 || sub_idx > scam->subscriptions->size) { LM_ERR("Invalid hash table index %d\n", sub_idx); goto done; } // sanity checks first - if (saved_sub->event != update_sub->event) { + if(saved_sub->event != update_sub->event) { LM_ERR("Event mismatch for in-dialog SUBSCRIBE from %.*s: " - "%s != %s\n", STR_FMT(&update_sub->subscriber), + "%s != %s\n", + STR_FMT(&update_sub->subscriber), sca_event_name_from_type(saved_sub->event), sca_event_name_from_type(update_sub->event)); goto done; } - if (!STR_EQ(saved_sub->subscriber, update_sub->subscriber)) { + if(!STR_EQ(saved_sub->subscriber, update_sub->subscriber)) { LM_ERR("Contact mismatch for in-dialog SUBSCRIBE from %.*s: " - "%.*s != %.*s\n", STR_FMT(&update_sub->subscriber), + "%.*s != %.*s\n", + STR_FMT(&update_sub->subscriber), STR_FMT(&update_sub->subscriber), STR_FMT(&saved_sub->subscriber)); goto done; } - if (!STR_EQ(saved_sub->target_aor, update_sub->target_aor)) { + if(!STR_EQ(saved_sub->target_aor, update_sub->target_aor)) { LM_ERR("AoR mismatch for in-dialog SUBSCRIBE from %.*s: " - "%.*s != %.*s\n", STR_FMT(&update_sub->subscriber), + "%.*s != %.*s\n", + STR_FMT(&update_sub->subscriber), STR_FMT(&update_sub->target_aor), STR_FMT(&saved_sub->target_aor)); goto done; } - if (!STR_EQ(saved_sub->dialog.call_id, update_sub->dialog.call_id) || - !STR_EQ(saved_sub->dialog.from_tag, - update_sub->dialog.from_tag) || - !STR_EQ(saved_sub->dialog.to_tag, update_sub->dialog.to_tag)) { + if(!STR_EQ(saved_sub->dialog.call_id, update_sub->dialog.call_id) + || !STR_EQ(saved_sub->dialog.from_tag, update_sub->dialog.from_tag) + || !STR_EQ(saved_sub->dialog.to_tag, update_sub->dialog.to_tag)) { // mismatched dialog. we assume a subscriber can hold only one // subscription per event at any given time, so we replace the old // one with the new. @@ -827,14 +843,15 @@ static int sca_subscription_update_unsafe(sca_mod *scam, // this is allocated separately from the rest of the subscription len = sizeof(char *) - * (update_sub->dialog.call_id.len - + update_sub->dialog.from_tag.len - + update_sub->dialog.to_tag.len); + * (update_sub->dialog.call_id.len + + update_sub->dialog.from_tag.len + + update_sub->dialog.to_tag.len); - dlg_id_tmp = (char *) shm_malloc(len); - if (dlg_id_tmp == NULL) { + dlg_id_tmp = (char *)shm_malloc(len); + if(dlg_id_tmp == NULL) { LM_ERR("Failed to replace %.*s %s subscription dialog: " - "shm_malloc failed\n", STR_FMT(&update_sub->subscriber), + "shm_malloc failed\n", + STR_FMT(&update_sub->subscriber), sca_event_name_from_type(update_sub->event)); // XXX should remove subscription entirely here? } else { @@ -849,13 +866,13 @@ static int sca_subscription_update_unsafe(sca_mod *scam, saved_sub->dialog.call_id.s = saved_sub->dialog.id.s; saved_sub->dialog.call_id.len = update_sub->dialog.call_id.len; - saved_sub->dialog.from_tag.s = saved_sub->dialog.id.s - + update_sub->dialog.call_id.len; + saved_sub->dialog.from_tag.s = + saved_sub->dialog.id.s + update_sub->dialog.call_id.len; saved_sub->dialog.from_tag.len = update_sub->dialog.from_tag.len; saved_sub->dialog.to_tag.s = saved_sub->dialog.id.s - + update_sub->dialog.call_id.len - + update_sub->dialog.from_tag.len; + + update_sub->dialog.call_id.len + + update_sub->dialog.from_tag.len; saved_sub->dialog.to_tag.len = update_sub->dialog.to_tag.len; } } @@ -866,11 +883,11 @@ static int sca_subscription_update_unsafe(sca_mod *scam, saved_sub->expires = time(NULL) + update_sub->expires; // flag subscription for DB update only if we've already inserted - if (saved_sub->db_cmd_flag == SCA_DB_FLAG_NONE) { + if(saved_sub->db_cmd_flag == SCA_DB_FLAG_NONE) { saved_sub->db_cmd_flag = SCA_DB_FLAG_UPDATE; } - if (update_sub->index != SCA_CALL_INFO_APPEARANCE_INDEX_ANY) { + if(update_sub->index != SCA_CALL_INFO_APPEARANCE_INDEX_ANY) { saved_sub->index = update_sub->index; } @@ -878,11 +895,12 @@ static int sca_subscription_update_unsafe(sca_mod *scam, update_sub->dialog.notify_cseq = saved_sub->dialog.notify_cseq; // ensure we send the NOTIFY back through the same path as the SUBSCRIBE - if (SCA_STR_EMPTY(&update_sub->rr) && !SCA_STR_EMPTY(&saved_sub->rr)) { - update_sub->rr.s = (char *) pkg_malloc(saved_sub->rr.len); - if (update_sub->rr.s == NULL) { + if(SCA_STR_EMPTY(&update_sub->rr) && !SCA_STR_EMPTY(&saved_sub->rr)) { + update_sub->rr.s = (char *)pkg_malloc(saved_sub->rr.len); + if(update_sub->rr.s == NULL) { LM_ERR("sca_subscription_update_unsafe: pkg_malloc record-route " - "value %.*s failed\n", STR_FMT(&saved_sub->rr)); + "value %.*s failed\n", + STR_FMT(&saved_sub->rr)); goto done; } @@ -891,11 +909,12 @@ static int sca_subscription_update_unsafe(sca_mod *scam, rc = 1; - done: return (rc); +done: + return (rc); } -static int sca_subscription_copy_subscription_key(sca_subscription *sub, - str *key_out) +static int sca_subscription_copy_subscription_key( + sca_subscription *sub, str *key_out) { char *event_name; int len; @@ -907,8 +926,8 @@ static int sca_subscription_copy_subscription_key(sca_subscription *sub, event_name = sca_event_name_from_type(sub->event); len += strlen(event_name); - key_out->s = (char *) pkg_malloc(len); - if (key_out->s == NULL) { + key_out->s = (char *)pkg_malloc(len); + if(key_out->s == NULL) { LM_ERR("Failed to pkg_malloc space for subscription key\n"); return (-1); } @@ -919,8 +938,8 @@ static int sca_subscription_copy_subscription_key(sca_subscription *sub, return (key_out->len); } -int sca_subscription_delete_subscriber_for_event(sca_mod *scam, str *subscriber, - str *event, str *aor) +int sca_subscription_delete_subscriber_for_event( + sca_mod *scam, str *subscriber, str *event, str *aor) { sca_hash_slot *slot; sca_hash_entry *ent; @@ -932,9 +951,9 @@ int sca_subscription_delete_subscriber_for_event(sca_mod *scam, str *subscriber, len = aor->len; len += event->len; - if (len >= sizeof(skbuf)) { - LM_ERR("Subscription key %.*s%.*s: too long\n", - STR_FMT(aor), STR_FMT(event)); + if(len >= sizeof(skbuf)) { + LM_ERR("Subscription key %.*s%.*s: too long\n", STR_FMT(aor), + STR_FMT(event)); return (-1); } @@ -948,13 +967,13 @@ int sca_subscription_delete_subscriber_for_event(sca_mod *scam, str *subscriber, sca_hash_table_lock_index(scam->subscriptions, slot_idx); ent = sca_hash_table_slot_kv_find_entry_unsafe(slot, subscriber); - if (ent != NULL) { + if(ent != NULL) { ent = sca_hash_table_slot_unlink_entry_unsafe(slot, ent); } sca_hash_table_unlock_index(sca->subscriptions, slot_idx); - if (ent != NULL) { + if(ent != NULL) { sca_hash_entry_free(ent); } @@ -971,8 +990,7 @@ int sca_subscription_from_request(sca_mod *scam, sip_msg_t *msg, int event_type, struct to_body *to, *from; str contact_uri; str to_tag = STR_NULL; - unsigned int expires = 0, - max_expires; + unsigned int expires = 0, max_expires; unsigned int cseq; str *ruri = NULL; @@ -981,113 +999,112 @@ int sca_subscription_from_request(sca_mod *scam, sip_msg_t *msg, int event_type, memset(req_sub, 0, sizeof(sca_subscription)); // parse required info first - if (!SCA_HEADER_EMPTY(msg->expires)) { - if (parse_expires(msg->expires) < 0) { + if(!SCA_HEADER_EMPTY(msg->expires)) { + if(parse_expires(msg->expires) < 0) { LM_ERR("Failed to parse Expires header\n"); goto error; } - expires = ((exp_body_t *) msg->expires->parsed)->val; + expires = ((exp_body_t *)msg->expires->parsed)->val; } - switch (event_type) { - case SCA_EVENT_TYPE_CALL_INFO: - default: - max_expires = scam->cfg->call_info_max_expires; - break; + switch(event_type) { + case SCA_EVENT_TYPE_CALL_INFO: + default: + max_expires = scam->cfg->call_info_max_expires; + break; - case SCA_EVENT_TYPE_LINE_SEIZE: - max_expires = scam->cfg->line_seize_max_expires; - break; + case SCA_EVENT_TYPE_LINE_SEIZE: + max_expires = scam->cfg->line_seize_max_expires; + break; } - if (expires && expires > max_expires) { + if(expires && expires > max_expires) { expires = max_expires; } - if (SCA_HEADER_EMPTY(msg->to)) { + if(SCA_HEADER_EMPTY(msg->to)) { LM_ERR("Empty To header\n"); goto error; } - if (SCA_HEADER_EMPTY(msg->callid)) { + if(SCA_HEADER_EMPTY(msg->callid)) { LM_ERR("Empty Call-ID header\n"); goto error; } // XXX move to static inline function - if (SCA_HEADER_EMPTY(msg->cseq)) { + if(SCA_HEADER_EMPTY(msg->cseq)) { LM_ERR("Empty CSeq header\n"); goto error; } - if (str2int(&(get_cseq(msg)->number), &cseq) != 0) { - LM_ERR("Bad Cseq header: %.*s\n", - msg->cseq->body.len, msg->cseq->body.s); + if(str2int(&(get_cseq(msg)->number), &cseq) != 0) { + LM_ERR("Bad Cseq header: %.*s\n", msg->cseq->body.len, + msg->cseq->body.s); goto error; } - if (sca_get_msg_contact_uri(msg, &contact_uri) < 0) { + if(sca_get_msg_contact_uri(msg, &contact_uri) < 0) { // above logs error goto error; } - if (SCA_HEADER_EMPTY(msg->from)) { + if(SCA_HEADER_EMPTY(msg->from)) { LM_ERR("Empty From header\n"); goto error; } - if (parse_from_header(msg) < 0) { + if(parse_from_header(msg) < 0) { LM_ERR("Bad From header\n"); goto error; } - from = (struct to_body *) msg->from->parsed; - if (SCA_STR_EMPTY(&from->tag_value)) { + from = (struct to_body *)msg->from->parsed; + if(SCA_STR_EMPTY(&from->tag_value)) { LM_ERR("No from-tag in From header\n"); goto error; } - if ((to = (struct to_body *) msg->to->parsed) == NULL) { - parse_to(msg->to->body.s, msg->to->body.s + msg->to->body.len + 1, // end of buffer - &tmp_to); + if((to = (struct to_body *)msg->to->parsed) == NULL) { + parse_to(msg->to->body.s, + msg->to->body.s + msg->to->body.len + 1, // end of buffer + &tmp_to); - if (tmp_to.error != PARSE_OK) { + if(tmp_to.error != PARSE_OK) { LM_ERR("Bad To header\n"); goto error; } to = &tmp_to; } - if (parse_sip_msg_uri(msg) < 0) { + if(parse_sip_msg_uri(msg) < 0) { LM_ERR("Error while parsing the Request-URI\n"); goto error; } ruri = GET_RURI(msg); to_tag = to->tag_value; - if (to_tag.s == NULL) { + if(to_tag.s == NULL) { // XXX need hook to detect when we have a subscription and the // subscriber sends an out-of-dialog SUBSCRIBE, which indicates the // old subscription should be dumped & appropriate NOTIFYs sent. - if (scam->sl_api->get_reply_totag(msg, &to_tag) < 0) { + if(scam->sl_api->get_reply_totag(msg, &to_tag) < 0) { LM_ERR("Failed to generate to-tag for reply to SUBSCRIBE %.*s\n", STR_FMT(ruri)); goto error; } - if (!SCA_HEADER_EMPTY(msg->record_route)) { - if (print_rr_body(msg->record_route, &req_sub->rr, 0, NULL) < 0) { + if(!SCA_HEADER_EMPTY(msg->record_route)) { + if(print_rr_body(msg->record_route, &req_sub->rr, 0, NULL) < 0) { LM_ERR("Failed to parse Record-Route header %.*s in " - "SUBSCRIBE %.*s from %.*s\n", - STR_FMT(&msg->record_route->body), - STR_FMT(ruri), + "SUBSCRIBE %.*s from %.*s\n", + STR_FMT(&msg->record_route->body), STR_FMT(ruri), STR_FMT(&contact_uri)); goto error; } } - if (sca_uri_extract_aor(ruri, &req_sub->target_aor) < 0) { + if(sca_uri_extract_aor(ruri, &req_sub->target_aor) < 0) { LM_ERR("Failed to extract AoR from RURI %.*s\n", STR_FMT(ruri)); goto error; } - } - else { + } else { /* we are in-dialog */ req_sub->target_aor = to->uri; } @@ -1096,7 +1113,7 @@ int sca_subscription_from_request(sca_mod *scam, sip_msg_t *msg, int event_type, req_sub->event = event_type; req_sub->index = SCA_CALL_INFO_APPEARANCE_INDEX_ANY; req_sub->expires = expires; - if (req_sub->expires > 0) { + if(req_sub->expires > 0) { req_sub->state = SCA_SUBSCRIPTION_STATE_ACTIVE; expires += time(NULL); } else { @@ -1110,7 +1127,7 @@ int sca_subscription_from_request(sca_mod *scam, sip_msg_t *msg, int event_type, req_sub->dialog.from_tag = from->tag_value; req_sub->dialog.to_tag.s = pkg_malloc(to_tag.len); - if (req_sub->dialog.to_tag.s == NULL) { + if(req_sub->dialog.to_tag.s == NULL) { LM_ERR("Failed to pkg_malloc space for to-tag %.*s\n", STR_FMT(&to_tag)); goto error; @@ -1125,9 +1142,10 @@ int sca_subscription_from_request(sca_mod *scam, sip_msg_t *msg, int event_type, return (1); - error: free_to_params(&tmp_to); +error: + free_to_params(&tmp_to); - if (!SCA_STR_EMPTY(&req_sub->rr)) { + if(!SCA_STR_EMPTY(&req_sub->rr)) { pkg_free(req_sub->rr.s); req_sub->rr.s = NULL; } @@ -1151,37 +1169,39 @@ int ki_sca_handle_subscribe(sip_msg_t *msg) int rc = -1; int released = 0; - if (parse_headers(msg, HDR_EOH_F, 0) < 0) { + if(parse_headers(msg, HDR_EOH_F, 0) < 0) { LM_ERR("header parsing failed: bad request\n"); SCA_SUB_REPLY_ERROR(sca, 400, "Bad Request", msg); return (-1); } - if (!STR_EQ(REQ_LINE(msg).method, SCA_METHOD_SUBSCRIBE)) { + if(!STR_EQ(REQ_LINE(msg).method, SCA_METHOD_SUBSCRIBE)) { LM_ERR("bad request method %.*s\n", STR_FMT(&REQ_LINE(msg).method)); SCA_SUB_REPLY_ERROR(sca, 500, "Internal server error - config", msg); return (-1); } - if (SCA_HEADER_EMPTY(msg->event)) { + if(SCA_HEADER_EMPTY(msg->event)) { SCA_SUB_REPLY_ERROR(sca, 400, "Missing Event", msg); return (-1); } event_type = sca_event_from_str(&msg->event->body); - if (event_type == SCA_EVENT_TYPE_UNKNOWN) { + if(event_type == SCA_EVENT_TYPE_UNKNOWN) { SCA_SUB_REPLY_ERROR(sca, 400, "Bad Event", msg); return (-1); } - if (sca_subscription_from_request(sca, msg, event_type, &req_sub) < 0) { - SCA_SUB_REPLY_ERROR(sca, 400, "Bad Shared Call Appearance Request", - msg); + if(sca_subscription_from_request(sca, msg, event_type, &req_sub) < 0) { + SCA_SUB_REPLY_ERROR( + sca, 400, "Bad Shared Call Appearance Request", msg); return (-1); } - if (sca_subscription_copy_subscription_key(&req_sub, &sub_key) < 0) { - SCA_SUB_REPLY_ERROR(sca, 500, "Internal Server Error - " - "copy dialog id", msg); + if(sca_subscription_copy_subscription_key(&req_sub, &sub_key) < 0) { + SCA_SUB_REPLY_ERROR(sca, 500, + "Internal Server Error - " + "copy dialog id", + msg); goto done; } sca_subscription_print(&req_sub); @@ -1196,60 +1216,70 @@ int ki_sca_handle_subscribe(sip_msg_t *msg) // pkg_malloc'd in sca_subscription_copy_subscription_key above pkg_free(sub_key.s); - if (req_sub.event == SCA_EVENT_TYPE_LINE_SEIZE) { + if(req_sub.event == SCA_EVENT_TYPE_LINE_SEIZE) { call_info_hdr = get_hdr(msg, HDR_CALLINFO_T); - if (call_info_hdr) { - if (sca_call_info_body_parse(&call_info_hdr->body, &call_info) - < 0) { - SCA_SUB_REPLY_ERROR(sca, 400, "Bad Request - " - "Invalid Call-Info header", msg); + if(call_info_hdr) { + if(sca_call_info_body_parse(&call_info_hdr->body, &call_info) < 0) { + SCA_SUB_REPLY_ERROR(sca, 400, + "Bad Request - " + "Invalid Call-Info header", + msg); goto done; } req_sub.index = app_idx = call_info.index; } else { - SCA_SUB_REPLY_ERROR(sca, 400, "Bad Request - " - "missing Call-Info header", msg); + SCA_SUB_REPLY_ERROR(sca, 400, + "Bad Request - " + "missing Call-Info header", + msg); goto done; } } sca_hash_table_lock_index(sca->subscriptions, idx); - sub = sca_hash_table_index_kv_find_unsafe(sca->subscriptions, idx, - &req_sub.subscriber); + sub = sca_hash_table_index_kv_find_unsafe( + sca->subscriptions, idx, &req_sub.subscriber); - if (sub != NULL) { + if(sub != NULL) { // this will remove the subscription if expires == 0 - if (sca_subscription_update_unsafe(sca, sub, &req_sub, idx) < 0) { - SCA_SUB_REPLY_ERROR(sca, 500, "Internal Server Error - " - "update subscription", msg); + if(sca_subscription_update_unsafe(sca, sub, &req_sub, idx) < 0) { + SCA_SUB_REPLY_ERROR(sca, 500, + "Internal Server Error - " + "update subscription", + msg); goto done; } - if (req_sub.event == SCA_EVENT_TYPE_LINE_SEIZE) { - if (req_sub.expires == 0) { + if(req_sub.event == SCA_EVENT_TYPE_LINE_SEIZE) { + if(req_sub.expires == 0) { // release the seized appearance - if (call_info_hdr == NULL) { - SCA_SUB_REPLY_ERROR(sca, 400, "Bad Request - " - "missing Call-Info header", msg); + if(call_info_hdr == NULL) { + SCA_SUB_REPLY_ERROR(sca, 400, + "Bad Request - " + "missing Call-Info header", + msg); goto done; } - if (sca_appearance_release_index(sca, &req_sub.target_aor, - call_info.index) != SCA_APPEARANCE_OK) { - SCA_SUB_REPLY_ERROR(sca, 500, "Internal Server Error - " - "release seized line", msg); + if(sca_appearance_release_index( + sca, &req_sub.target_aor, call_info.index) + != SCA_APPEARANCE_OK) { + SCA_SUB_REPLY_ERROR(sca, 500, + "Internal Server Error - " + "release seized line", + msg); goto done; } - } else if (SCA_STR_EMPTY(to_tag)) { + } else if(SCA_STR_EMPTY(to_tag)) { // don't seize new index if this is a line-seize reSUBSCRIBE - app_idx = sca_appearance_seize_index(sca, &req_sub.target_aor, - app_idx, &req_sub.subscriber); - if (app_idx == SCA_APPEARANCE_INDEX_UNAVAILABLE) { - SCA_SUB_REPLY_ERROR(sca, 480, "Temporarily Unavailable", - msg); + app_idx = sca_appearance_seize_index( + sca, &req_sub.target_aor, app_idx, &req_sub.subscriber); + if(app_idx == SCA_APPEARANCE_INDEX_UNAVAILABLE) { + SCA_SUB_REPLY_ERROR( + sca, 480, "Temporarily Unavailable", msg); goto done; - } else if (app_idx < 0) { + } else if(app_idx < 0) { SCA_SUB_REPLY_ERROR(sca, 500, "Internal Server Error - seize appearance index", msg); @@ -1258,47 +1288,52 @@ int ki_sca_handle_subscribe(sip_msg_t *msg) req_sub.index = app_idx; } } else { - if (SCA_STR_EMPTY(to_tag)) { + if(SCA_STR_EMPTY(to_tag)) { // if the subscriber owns any active appearances, clear them. // we assume that an out-of-dialog SUBSCRIBE for a subscriber // with active appearances is indicative of a reboot. - released = sca_appearance_owner_release_all(&req_sub.target_aor, - &req_sub.subscriber); - if (released) { + released = sca_appearance_owner_release_all( + &req_sub.target_aor, &req_sub.subscriber); + if(released) { LM_INFO("sca_handle_subscribe: released %d appearances " - "for subscriber %.*s\n", released, - STR_FMT(&req_sub.subscriber)); + "for subscriber %.*s\n", + released, STR_FMT(&req_sub.subscriber)); } } } } else { // in-dialog request, but we didn't find it. - if (!SCA_STR_EMPTY(to_tag)) { - SCA_SUB_REPLY_ERROR(sca, 481, "Call Leg/Transaction Does Not Exist", - msg); + if(!SCA_STR_EMPTY(to_tag)) { + SCA_SUB_REPLY_ERROR( + sca, 481, "Call Leg/Transaction Does Not Exist", msg); goto done; } - if (req_sub.expires > 0) { - if (req_sub.event == SCA_EVENT_TYPE_LINE_SEIZE) { - app_idx = sca_appearance_seize_index(sca, &req_sub.target_aor, - app_idx, &req_sub.subscriber); - if (app_idx == SCA_APPEARANCE_INDEX_UNAVAILABLE) { - SCA_SUB_REPLY_ERROR(sca, 480, "Temporarily Unavailable", - msg); + if(req_sub.expires > 0) { + if(req_sub.event == SCA_EVENT_TYPE_LINE_SEIZE) { + app_idx = sca_appearance_seize_index( + sca, &req_sub.target_aor, app_idx, &req_sub.subscriber); + if(app_idx == SCA_APPEARANCE_INDEX_UNAVAILABLE) { + SCA_SUB_REPLY_ERROR( + sca, 480, "Temporarily Unavailable", msg); goto done; - } else if (app_idx < 0) { - SCA_SUB_REPLY_ERROR(sca, 500, "Internal Server Error - " - "seize appearance index", msg); + } else if(app_idx < 0) { + SCA_SUB_REPLY_ERROR(sca, 500, + "Internal Server Error - " + "seize appearance index", + msg); goto done; } req_sub.index = app_idx; } - if (sca_subscription_save_unsafe(sca, &req_sub, idx, - SCA_SUBSCRIPTION_CREATE_OPT_DEFAULT) < 0) { - SCA_SUB_REPLY_ERROR(sca, 500, "Internal Server Error - " - "save subscription", msg); + if(sca_subscription_save_unsafe( + sca, &req_sub, idx, SCA_SUBSCRIPTION_CREATE_OPT_DEFAULT) + < 0) { + SCA_SUB_REPLY_ERROR(sca, 500, + "Internal Server Error - " + "save subscription", + msg); goto done; } } else { @@ -1314,13 +1349,14 @@ int ki_sca_handle_subscribe(sip_msg_t *msg) status = sca_ok_status_for_event(event_type); status_text = sca_ok_text_for_event(event_type); - if (sca_subscription_reply(sca, status, status_text, event_type, - req_sub.expires, msg) < 0) { + if(sca_subscription_reply( + sca, status, status_text, event_type, req_sub.expires, msg) + < 0) { SCA_SUB_REPLY_ERROR(sca, 500, "Internal server error", msg); goto done; } - if (sca_notify_subscriber(sca, &req_sub, app_idx) < 0) { + if(sca_notify_subscriber(sca, &req_sub, app_idx) < 0) { LM_ERR("SCA %s SUBSCRIBE+NOTIFY for %.*s failed\n", sca_event_name_from_type(req_sub.event), STR_FMT(&req_sub.subscriber)); @@ -1329,8 +1365,8 @@ int ki_sca_handle_subscribe(sip_msg_t *msg) goto done; } - if (req_sub.event == SCA_EVENT_TYPE_LINE_SEIZE || released) { - if (sca_notify_call_info_subscribers(sca, &req_sub.target_aor) < 0) { + if(req_sub.event == SCA_EVENT_TYPE_LINE_SEIZE || released) { + if(sca_notify_call_info_subscribers(sca, &req_sub.target_aor) < 0) { LM_ERR("SCA %s NOTIFY to all %.*s subscribers failed\n", sca_event_name_from_type(req_sub.event), STR_FMT(&req_sub.target_aor)); @@ -1340,14 +1376,15 @@ int ki_sca_handle_subscribe(sip_msg_t *msg) rc = 1; - done: if (idx >= 0) { +done: + if(idx >= 0) { sca_hash_table_unlock_index(sca->subscriptions, idx); } - if (req_sub.dialog.to_tag.s != NULL) { + if(req_sub.dialog.to_tag.s != NULL) { pkg_free(req_sub.dialog.to_tag.s); } - if (req_sub.rr.s != NULL) { + if(req_sub.rr.s != NULL) { pkg_free(req_sub.rr.s); } @@ -1366,49 +1403,48 @@ int sca_subscription_reply(sca_mod *scam, int status_code, char *status_msg, char hdr_buf[1024]; int len; - if (event_type != SCA_EVENT_TYPE_CALL_INFO + if(event_type != SCA_EVENT_TYPE_CALL_INFO && event_type != SCA_EVENT_TYPE_LINE_SEIZE) { LM_ERR("sca_subscription_reply: unrecognized event type %d\n", event_type); return (-1); } - if (status_code < 300) { + if(status_code < 300) { // Add Event, Contact, Allow-Events and Expires headers extra_headers.s = hdr_buf; len = snprintf(extra_headers.s, sizeof(hdr_buf), "Event: %s%s", sca_event_name_from_type(event_type), CRLF); - if (len >= sizeof(hdr_buf) || len < 0) { + if(len >= sizeof(hdr_buf) || len < 0) { LM_ERR("sca_subscription_reply: extra headers too long\n"); return (-1); } extra_headers.len = len; SCA_STR_APPEND_CSTR(&extra_headers, "Contact: "); - if (sca->cfg->server_address != NULL) { - SCA_STR_APPEND( &extra_headers, sca->cfg->server_address); - } - else { - SCA_STR_APPEND( &extra_headers, &REQ_LINE( msg ).uri ); + if(sca->cfg->server_address != NULL) { + SCA_STR_APPEND(&extra_headers, sca->cfg->server_address); + } else { + SCA_STR_APPEND(&extra_headers, &REQ_LINE(msg).uri); } SCA_STR_APPEND_CSTR(&extra_headers, CRLF); - SCA_STR_COPY_CSTR(&extra_headers, - "Allow-Events: call-info, line-seize" CRLF); + SCA_STR_COPY_CSTR( + &extra_headers, "Allow-Events: call-info, line-seize" CRLF); len = snprintf(extra_headers.s + extra_headers.len, sizeof(hdr_buf) - extra_headers.len, "Expires: %d%s", expires, CRLF); - if (len >= (sizeof(hdr_buf) - extra_headers.len) || len < 0) { + if(len >= (sizeof(hdr_buf) - extra_headers.len) || len < 0) { LM_ERR("sca_subscription_reply: extra headers too long\n"); return (-1); } extra_headers.len += len; - } else if (status_code == 480) { + } else if(status_code == 480) { // tell loser of line-seize SUBSCRIBE race to try again shortly extra_headers.s = hdr_buf; - len = snprintf(extra_headers.s, sizeof(hdr_buf), "Retry-After: %d%s", 1, - CRLF); + len = snprintf( + extra_headers.s, sizeof(hdr_buf), "Retry-After: %d%s", 1, CRLF); extra_headers.len = len; } @@ -1432,17 +1468,18 @@ int sca_subscription_terminate(sca_mod *scam, str *aor, int event, int slot_idx; int len; - if (!(opts & SCA_SUBSCRIPTION_TERMINATE_OPT_UNSUBSCRIBE)) { + if(!(opts & SCA_SUBSCRIPTION_TERMINATE_OPT_UNSUBSCRIBE)) { LM_ERR("sca_subscription_terminate: invalid opts 0x%x\n", opts); return (-1); } event_name = sca_event_name_from_type(event); len = aor->len + strlen(event_name); - sub_key.s = (char *) pkg_malloc(len); - if (sub_key.s == NULL) { + sub_key.s = (char *)pkg_malloc(len); + if(sub_key.s == NULL) { LM_ERR("Failed to pkg_malloc key to look up %s " - "subscription for %.*s\n", event_name, STR_FMT(aor)); + "subscription for %.*s\n", + event_name, STR_FMT(aor)); return (-1); } SCA_STR_COPY(&sub_key, aor); @@ -1456,37 +1493,37 @@ int sca_subscription_terminate(sca_mod *scam, str *aor, int event, sca_hash_table_lock_index(scam->subscriptions, slot_idx); ent = sca_hash_table_slot_kv_find_entry_unsafe(slot, subscriber); - if (ent != NULL) { + if(ent != NULL) { ent = sca_hash_table_slot_unlink_entry_unsafe(slot, ent); } sca_hash_table_unlock_index(sca->subscriptions, slot_idx); - if (ent == NULL) { + if(ent == NULL) { LM_DBG("No %s subscription for %.*s\n", event_name, STR_FMT(subscriber)); return (0); } - sub = (sca_subscription *) ent->value; + sub = (sca_subscription *)ent->value; sub->expires = 0; sub->dialog.notify_cseq += 1; sub->state = termination_state; sca_subscription_print(sub); - if (sca_notify_subscriber(sca, sub, sub->index) < 0) { - LM_ERR("SCA %s NOTIFY to %.*s failed\n", - event_name, STR_FMT(&sub->subscriber)); + if(sca_notify_subscriber(sca, sub, sub->index) < 0) { + LM_ERR("SCA %s NOTIFY to %.*s failed\n", event_name, + STR_FMT(&sub->subscriber)); // fall through, we might be able to notify the others } - if ((opts & SCA_SUBSCRIPTION_TERMINATE_OPT_RELEASE_APPEARANCE) + if((opts & SCA_SUBSCRIPTION_TERMINATE_OPT_RELEASE_APPEARANCE) && sub->index != SCA_CALL_INFO_APPEARANCE_INDEX_ANY) { - if (sca_appearance_release_index(sca, &sub->target_aor, sub->index) + if(sca_appearance_release_index(sca, &sub->target_aor, sub->index) == SCA_APPEARANCE_OK) { - if (sca_notify_call_info_subscribers(sca, &sub->target_aor) < 0) { + if(sca_notify_call_info_subscribers(sca, &sub->target_aor) < 0) { LM_ERR("SCA %s NOTIFY to all %.*s subscribers failed\n", event_name, STR_FMT(&sub->target_aor)); // fall through, not much we can do about it @@ -1494,7 +1531,7 @@ int sca_subscription_terminate(sca_mod *scam, str *aor, int event, } } - if (ent) { + if(ent) { sca_hash_entry_free(ent); } diff --git a/src/modules/sca/sca_subscribe.h b/src/modules/sca/sca_subscribe.h index e91971756..e27883e43 100644 --- a/src/modules/sca/sca_subscribe.h +++ b/src/modules/sca/sca_subscribe.h @@ -23,7 +23,8 @@ #include "sca.h" #include "sca_dialog.h" -enum { +enum +{ SCA_SUBSCRIPTION_STATE_ACTIVE, SCA_SUBSCRIPTION_STATE_PENDING, SCA_SUBSCRIPTION_STATE_TERMINATED, @@ -35,45 +36,48 @@ enum { SCA_SUBSCRIPTION_STATE_TERMINATED_TIMEOUT, }; -struct _sca_subscription { +struct _sca_subscription +{ str subscriber; // contact: user@ip str target_aor; // account of record to watch: user@domain - int event; // "call-info", "line-seize" + int event; // "call-info", "line-seize" time_t expires; // expiration date of subscription - int state; // active, pending, terminated - int index; // seized appearance-index, line-seize only + int state; // active, pending, terminated + int index; // seized appearance-index, line-seize only sca_dialog dialog; // call-id, to- and from-tags, cseq str rr; // Record-Route header values int db_cmd_flag; // track whether to INSERT or UPDATE - int server_id; // server + int server_id; // server }; typedef struct _sca_subscription sca_subscription; -enum { +enum +{ SCA_SUBSCRIPTION_TERMINATE_OPT_UNSUBSCRIBE = (1 << 0), SCA_SUBSCRIPTION_TERMINATE_OPT_RELEASE_APPEARANCE = (1 << 1), }; -#define SCA_SUBSCRIPTION_TERMINATE_OPT_DEFAULT \ - (SCA_SUBSCRIPTION_TERMINATE_OPT_UNSUBSCRIBE | \ - SCA_SUBSCRIPTION_TERMINATE_OPT_RELEASE_APPEARANCE) +#define SCA_SUBSCRIPTION_TERMINATE_OPT_DEFAULT \ + (SCA_SUBSCRIPTION_TERMINATE_OPT_UNSUBSCRIBE \ + | SCA_SUBSCRIPTION_TERMINATE_OPT_RELEASE_APPEARANCE) -enum { +enum +{ SCA_SUBSCRIPTION_CREATE_OPT_DEFAULT = 0, SCA_SUBSCRIPTION_CREATE_OPT_RAW_EXPIRES = (1 << 0), }; extern const str SCA_METHOD_SUBSCRIBE; -#define SCA_SUBSCRIPTION_IS_TERMINATED(sub1) \ - ((sub1)->state >= SCA_SUBSCRIPTION_STATE_TERMINATED && \ - (sub1)->state <= SCA_SUBSCRIPTION_STATE_TERMINATED_TIMEOUT) +#define SCA_SUBSCRIPTION_IS_TERMINATED(sub1) \ + ((sub1)->state >= SCA_SUBSCRIPTION_STATE_TERMINATED \ + && (sub1)->state <= SCA_SUBSCRIPTION_STATE_TERMINATED_TIMEOUT) #define SCA_SUB_REPLY_ERROR(mod, scode, smsg, sreply) \ - sca_subscription_reply((mod), (scode), (smsg), \ - SCA_EVENT_TYPE_CALL_INFO, -1, (sreply)) + sca_subscription_reply( \ + (mod), (scode), (smsg), SCA_EVENT_TYPE_CALL_INFO, -1, (sreply)) int sca_handle_subscribe(sip_msg_t *, char *, char *); int sca_subscription_reply(sca_mod *, int, char *, int, int, sip_msg_t *); @@ -86,7 +90,8 @@ void sca_subscription_purge_expired(unsigned int, void *); void sca_subscription_state_to_str(int, str *); int sca_subscription_aor_has_subscribers(int, str *); -int sca_subscription_delete_subscriber_for_event(sca_mod *, str *, str *, str *); +int sca_subscription_delete_subscriber_for_event( + sca_mod *, str *, str *, str *); int sca_subscription_terminate(sca_mod *, str *, int, str *, int, int); int ki_sca_handle_subscribe(sip_msg_t *msg); diff --git a/src/modules/sca/sca_util.c b/src/modules/sca/sca_util.c index b586c8f59..4ab4c6ff9 100644 --- a/src/modules/sca/sca_util.c +++ b/src/modules/sca/sca_util.c @@ -29,7 +29,7 @@ int sca_get_msg_method(sip_msg_t *msg) { assert(msg != NULL); - if (msg->first_line.type == SIP_REQUEST) { + if(msg->first_line.type == SIP_REQUEST) { return (msg->REQ_METHOD); } @@ -43,7 +43,7 @@ int sca_get_msg_contact_uri(sip_msg_t *msg, str *contact_uri) assert(msg != NULL); assert(contact_uri != NULL); - if (SCA_HEADER_EMPTY(msg->contact)) { + if(SCA_HEADER_EMPTY(msg->contact)) { LM_DBG("Empty Contact header\n"); contact_uri->s = NULL; contact_uri->len = 0; @@ -51,24 +51,24 @@ int sca_get_msg_contact_uri(sip_msg_t *msg, str *contact_uri) return (0); } - if (parse_contact(msg->contact) < 0) { + if(parse_contact(msg->contact) < 0) { LM_ERR("Failed to parse Contact header: %.*s\n", STR_FMT(&msg->contact->body)); return (-1); } - if ((contact_body = (contact_body_t *) msg->contact->parsed) == NULL) { + if((contact_body = (contact_body_t *)msg->contact->parsed) == NULL) { LM_ERR("Invalid Contact header: %.*s\n", STR_FMT(&msg->contact->body)); return (-1); } - if (contact_body->star) { + if(contact_body->star) { LM_ERR("Invalid Contact header: SCA Contact must not be \"*\"\n"); return (-1); } - if (contact_body->contacts == NULL) { + if(contact_body->contacts == NULL) { LM_ERR("Invalid Contact header: parser found no contacts\n"); return (-1); } - if (contact_body->contacts->next) { + if(contact_body->contacts->next) { LM_ERR("Invalid Contact header: Contact may only contain one URI\n"); return (-1); } @@ -85,11 +85,11 @@ int sca_get_msg_cseq_number(sip_msg_t *msg) assert(msg != NULL); - if (SCA_HEADER_EMPTY(msg->cseq)) { + if(SCA_HEADER_EMPTY(msg->cseq)) { LM_ERR("Empty Cseq header\n"); return (-1); } - if (str2int(&(get_cseq(msg)->number), (unsigned int *) &cseq) != 0) { + if(str2int(&(get_cseq(msg)->number), (unsigned int *)&cseq) != 0) { LM_ERR("Bad Cseq header: %.*s\n", STR_FMT(&msg->cseq->body)); return (-1); } @@ -104,7 +104,7 @@ int sca_get_msg_cseq_method(sip_msg_t *msg) { assert(msg != NULL); - if (SCA_HEADER_EMPTY(msg->cseq)) { + if(SCA_HEADER_EMPTY(msg->cseq)) { LM_ERR("Empty Cseq header\n"); return (-1); } @@ -119,22 +119,22 @@ int sca_get_msg_from_header(sip_msg_t *msg, struct to_body **from) assert(msg != NULL); assert(from != NULL); - if (SCA_HEADER_EMPTY(msg->from)) { + if(SCA_HEADER_EMPTY(msg->from)) { LM_ERR("Empty From header\n"); return (-1); } - if (parse_from_header(msg) < 0) { + if(parse_from_header(msg) < 0) { LM_ERR("Bad From header\n"); return (-1); } f = get_from(msg); - if (SCA_STR_EMPTY(&f->tag_value)) { + if(SCA_STR_EMPTY(&f->tag_value)) { LM_ERR("Bad From header: no tag parameter\n"); return (-1); } // ensure the URI is parsed for future use - if (parse_uri(f->uri.s, f->uri.len, GET_FROM_PURI(msg)) < 0) { + if(parse_uri(f->uri.s, f->uri.len, GET_FROM_PURI(msg)) < 0) { LM_ERR("Failed to parse From URI %.*s\n", STR_FMT(&f->uri)); return (-1); } @@ -152,15 +152,16 @@ int sca_get_msg_to_header(sip_msg_t *msg, struct to_body **to) assert(msg != NULL); assert(to != NULL); - if (SCA_HEADER_EMPTY(msg->to)) { + if(SCA_HEADER_EMPTY(msg->to)) { LM_ERR("Empty To header\n"); return (-1); } t = get_to(msg); - if (t == NULL) { - parse_to(msg->to->body.s, msg->to->body.s + msg->to->body.len + 1, // end of buffer - &parsed_to); - if (parsed_to.error != PARSE_OK) { + if(t == NULL) { + parse_to(msg->to->body.s, + msg->to->body.s + msg->to->body.len + 1, // end of buffer + &parsed_to); + if(parsed_to.error != PARSE_OK) { LM_ERR("Bad To header\n"); return (-1); } @@ -168,7 +169,7 @@ int sca_get_msg_to_header(sip_msg_t *msg, struct to_body **to) } // ensure the URI is parsed for future use - if (parse_uri(t->uri.s, t->uri.len, GET_TO_PURI(msg)) < 0) { + if(parse_uri(t->uri.s, t->uri.len, GET_TO_PURI(msg)) < 0) { LM_ERR("Failed to parse To URI %.*s\n", STR_FMT(&t->uri)); return (-1); } @@ -190,14 +191,14 @@ int sca_build_to_body_from_uri(sip_msg_t *msg, struct to_body **body, str *uri) *body = pkg_malloc(sizeof(struct to_body)); if(*body == NULL) { LM_ERR("cannot allocate pkg memory\n"); - return(-1); + return (-1); } parse_to(uri->s, uri->s + uri->len + 1, *body); - if ((*body)->error != PARSE_OK) { + if((*body)->error != PARSE_OK) { LM_ERR("Bad uri value[%.*s]\n", STR_FMT(uri)); free_to(*body); - return(-1); + return (-1); } return (0); } @@ -205,24 +206,25 @@ int sca_build_to_body_from_uri(sip_msg_t *msg, struct to_body **body, str *uri) /* * count characters requiring escape as defined by escape_common */ -int sca_uri_display_escapes_count(str *display) { +int sca_uri_display_escapes_count(str *display) +{ int c = 0; int i; - if (SCA_STR_EMPTY(display)) { + if(SCA_STR_EMPTY(display)) { return (0); } - for (i = 0; i < display->len; i++) { - switch (display->s[i]) { - case '\'': - case '"': - case '\\': - case '\0': - c++; + for(i = 0; i < display->len; i++) { + switch(display->s[i]) { + case '\'': + case '"': + case '\\': + case '\0': + c++; - default: - break; + default: + break; } } @@ -235,7 +237,7 @@ int sca_uri_extract_aor(str *uri, str *aor) assert(aor != NULL); - if (uri == NULL) { + if(uri == NULL) { aor->s = NULL; aor->len = 0; return (-1); @@ -243,7 +245,7 @@ int sca_uri_extract_aor(str *uri, str *aor) aor->s = uri->s; semi = memchr(uri->s, ';', uri->len); - if (semi != NULL) { + if(semi != NULL) { aor->len = semi - uri->s; } else { aor->len = uri->len; @@ -262,12 +264,12 @@ int sca_uri_build_aor(str *aor, int maxlen, str *contact_uri, str *domain_uri) assert(contact_uri != NULL); assert(domain_uri != NULL); - if (contact_uri->len + domain_uri->len >= maxlen) { + if(contact_uri->len + domain_uri->len >= maxlen) { return (-1); } p = memchr(contact_uri->s, '@', contact_uri->len); - if (p == NULL) { + if(p == NULL) { // no username, by definition can't be an SCA line aor->s = NULL; aor->len = 0; @@ -275,10 +277,10 @@ int sca_uri_build_aor(str *aor, int maxlen, str *contact_uri, str *domain_uri) return (0); } dp = memchr(domain_uri->s, '@', domain_uri->len); - if (dp == NULL) { + if(dp == NULL) { // may be nameless URI dp = memchr(domain_uri->s, ':', domain_uri->len); - if (dp == NULL) { + if(dp == NULL) { // bad domain URI return (-1); } @@ -298,8 +300,8 @@ int sca_uri_build_aor(str *aor, int maxlen, str *contact_uri, str *domain_uri) return (aor->len); } -int sca_aor_create_from_info(str *aor, uri_type type, str *user, str *domain, - str *port) +int sca_aor_create_from_info( + str *aor, uri_type type, str *user, str *domain, str *port) { str scheme = STR_NULL; int len = 0; @@ -310,13 +312,13 @@ int sca_aor_create_from_info(str *aor, uri_type type, str *user, str *domain, // +1 for ':', +1 for '@' len = scheme.len + 1 + user->len + 1 + domain->len; - if (!SCA_STR_EMPTY(port)) { + if(!SCA_STR_EMPTY(port)) { // +1 for ':' len += 1 + port->len; } - aor->s = (char *) pkg_malloc(len); - if (aor->s == NULL) { + aor->s = (char *)pkg_malloc(len); + if(aor->s == NULL) { LM_ERR("sca_aor_create_from_info: pkg_malloc %d bytes failed\n", len); return (-1); } @@ -339,7 +341,7 @@ int sca_aor_create_from_info(str *aor, uri_type type, str *user, str *domain, SCA_STR_APPEND(aor, domain); len += domain->len; - if (!SCA_STR_EMPTY(port)) { + if(!SCA_STR_EMPTY(port)) { *(aor->s + len) = ':'; len += 1; @@ -363,59 +365,63 @@ int sca_create_canonical_aor_for_ua(sip_msg_t *msg, str *c_aor, int ua_opts) memset(c_aor, 0, sizeof(str)); - if ((ua_opts & SCA_AOR_TYPE_AUTO)) { - if (msg->first_line.type == SIP_REQUEST) { + if((ua_opts & SCA_AOR_TYPE_AUTO)) { + if(msg->first_line.type == SIP_REQUEST) { ua_opts = SCA_AOR_TYPE_UAC; } else { ua_opts = SCA_AOR_TYPE_UAS; } } - if ((ua_opts & SCA_AOR_TYPE_UAC)) { - if (sca_get_msg_from_header(msg, &tf) < 0) { + if((ua_opts & SCA_AOR_TYPE_UAC)) { + if(sca_get_msg_from_header(msg, &tf) < 0) { LM_ERR("sca_create_canonical_aor: failed to get From header\n"); goto done; } } else { - if (sca_get_msg_to_header(msg, &tf) < 0) { + if(sca_get_msg_to_header(msg, &tf) < 0) { LM_ERR("sca_create_canonical_aor: failed to get To header\n"); goto done; } } - if (sca_uri_extract_aor(&tf->uri, &tf_aor) < 0) { + if(sca_uri_extract_aor(&tf->uri, &tf_aor) < 0) { LM_ERR("sca_create_canonical_aor: failed to extract AoR from " - "URI <%.*s>\n", STR_FMT(&tf->uri)); + "URI <%.*s>\n", + STR_FMT(&tf->uri)); goto done; } memset(&c_uri, 0, sizeof(sip_uri_t)); - if ((rc = sca_get_msg_contact_uri(msg, &contact_uri)) < 0) { + if((rc = sca_get_msg_contact_uri(msg, &contact_uri)) < 0) { LM_ERR("sca_create_canonical_aor: failed to get contact URI from " - "Contact <%.*s>\n", STR_FMT(&msg->contact->body)); + "Contact <%.*s>\n", + STR_FMT(&msg->contact->body)); goto done; } - if (rc > 0) { - if (parse_uri(contact_uri.s, contact_uri.len, &c_uri) < 0) { + if(rc > 0) { + if(parse_uri(contact_uri.s, contact_uri.len, &c_uri) < 0) { LM_ERR("sca_create_canonical_aor: failed to parse Contact URI " - "<%.*s>\n", STR_FMT(&contact_uri)); + "<%.*s>\n", + STR_FMT(&contact_uri)); rc = -1; goto done; } } - if (SCA_STR_EMPTY(&c_uri.user) || - SCA_STR_EQ(&c_uri.user, &tf->parsed_uri.user)) { + if(SCA_STR_EMPTY(&c_uri.user) + || SCA_STR_EQ(&c_uri.user, &tf->parsed_uri.user)) { // empty contact header or Contact user matches To/From AoR - c_aor->s = (char *) pkg_malloc(tf_aor.len); + c_aor->s = (char *)pkg_malloc(tf_aor.len); c_aor->len = tf_aor.len; memcpy(c_aor->s, tf_aor.s, tf_aor.len); } else { // Contact user and To/From user mismatch - if (sca_aor_create_from_info(c_aor, c_uri.type, &c_uri.user, - &tf->parsed_uri.host, &tf->parsed_uri.port) < 0) { + if(sca_aor_create_from_info(c_aor, c_uri.type, &c_uri.user, + &tf->parsed_uri.host, &tf->parsed_uri.port) + < 0) { LM_ERR("sca_create_canonical_aor: failed to create AoR from " - "Contact <%.*s> and URI <%.*s>\n", + "Contact <%.*s> and URI <%.*s>\n", STR_FMT(&contact_uri), STR_FMT(&tf_aor)); goto done; } @@ -423,7 +429,8 @@ int sca_create_canonical_aor_for_ua(sip_msg_t *msg, str *c_aor, int ua_opts) rc = 1; - done: return (rc); +done: + return (rc); } int sca_create_canonical_aor(sip_msg_t *msg, str *c_aor) @@ -444,34 +451,36 @@ int sca_call_is_held(sip_msg_t *msg) int rc; if(sca->cfg->onhold_bflag >= 0) { - if (isbflagset(0, (flag_t)sca->cfg->onhold_bflag)==1) { + if(isbflagset(0, (flag_t)sca->cfg->onhold_bflag) == 1) { LM_DBG("onhold_bflag set, skip parse_sdp and set held\n"); - return ( 1 ); + return (1); } } rc = parse_sdp(msg); - if (rc < 0) { + if(rc < 0) { LM_ERR("sca_call_is_held: parse_sdp body failed\n"); return (0); - } else if (rc > 0) { + } else if(rc > 0) { LM_DBG("sca_call_is_held: parse_sdp returned %d, no SDP body\n", rc); return (0); } // Cf. modules_k/textops's exported is_audio_on_hold - for (n_sess = 0, session = get_sdp_session(msg, n_sess); session != NULL; + for(n_sess = 0, session = get_sdp_session(msg, n_sess); session != NULL; n_sess++, session = get_sdp_session(msg, n_sess)) { - for (n_str = 0, stream = get_sdp_stream(msg, n_sess, n_str); + for(n_str = 0, stream = get_sdp_stream(msg, n_sess, n_str); stream != NULL; n_str++, stream = get_sdp_stream(msg, n_sess, n_str)) { - if (stream->is_on_hold) { - LM_DBG("sca_call_is_held: parse_sdp detected stream is on hold\n"); + if(stream->is_on_hold) { + LM_DBG("sca_call_is_held: parse_sdp detected stream is on " + "hold\n"); is_held = 1; goto done; } } } - done: return (is_held); +done: + return (is_held); } diff --git a/src/modules/sca/sca_util.h b/src/modules/sca/sca_util.h index 9dcf705ec..c191083ed 100644 --- a/src/modules/sca/sca_util.h +++ b/src/modules/sca/sca_util.h @@ -22,7 +22,8 @@ #include "sca_common.h" -enum { +enum +{ SCA_AOR_TYPE_AUTO = (1 << 0), SCA_AOR_TYPE_UAC = (1 << 1), SCA_AOR_TYPE_UAS = (1 << 2), diff --git a/src/modules/sdpops/README b/src/modules/sdpops/README index 476ff7c41..9ea0e33ab 100644 --- a/src/modules/sdpops/README +++ b/src/modules/sdpops/README @@ -315,17 +315,17 @@ if(sdp_with_active_media("video")) contain the exact same number of "m=" lines as the request. - 6 Generating the Answer + 6 Generating the Answer - [...] + [...] - For each "m=" line in the offer, there MUST be a corresponding "m=" - line in the answer. The answer MUST contain exactly the same number of - "m=" lines as the offer. This allows for streams to be matched up based - on their order. This implies that if the offer contained zero "m=" - lines, the answer MUST contain zero "m=" lines. + For each "m=" line in the offer, there MUST be a corresponding "m=" + line in the answer. The answer MUST contain exactly the same number of + "m=" lines as the offer. This allows for streams to be matched up based + on their order. This implies that if the offer contained zero "m=" + lines, the answer MUST contain zero "m=" lines. - --RFC 3264 + --RFC 3264 So this may not work with all Endpoints, especially if they follow RFC 3264 precisely (e.g. JSSIP). diff --git a/src/modules/sipdump/sipdump_mod.c b/src/modules/sipdump/sipdump_mod.c index 3714eb39e..cb23274f8 100644 --- a/src/modules/sipdump/sipdump_mod.c +++ b/src/modules/sipdump/sipdump_mod.c @@ -337,8 +337,14 @@ int sipdump_msg_sent(sr_event_param_t *evp) sdi.tag.s = "snd"; sdi.tag.len = 3; - sdi.src_ip = evp->dst->send_sock->address_str; - sdi.src_port = (int)evp->dst->send_sock->port_no; + if(evp->dst->send_sock==NULL || evp->dst->send_sock->address_str.s==NULL) { + sdi.src_ip.len = 7; + sdi.src_ip.s = "0.0.0.0"; + sdi.src_port = 0; + } else { + sdi.src_ip = evp->dst->send_sock->address_str; + sdi.src_port = (int)evp->dst->send_sock->port_no; + } su2ip_addr(&ip, &evp->dst->to); sdi.dst_ip.len = ip_addr2sbufz(&ip, dstip_buf, IP_ADDR_MAX_STRZ_SIZE); sdi.dst_ip.s = dstip_buf; diff --git a/src/modules/sipdump/sipdump_write.c b/src/modules/sipdump/sipdump_write.c index 03ed711d8..c28e49482 100644 --- a/src/modules/sipdump/sipdump_write.c +++ b/src/modules/sipdump/sipdump_write.c @@ -201,7 +201,7 @@ static int sipdump_rotate_file(void) n = snprintf(_sipdump_fpath+_sipdump_fpath_prefix.len, SIPDUMP_FPATH_SIZE-_sipdump_fpath_prefix.len, "%d-%02d-%02d--%02d-%02d-%02d.data", - 1900+ti->tm_year, ti->tm_mon, ti->tm_mday, + 1900+ti->tm_year, ti->tm_mon+1, ti->tm_mday, ti->tm_hour, ti->tm_min, ti->tm_sec); LM_DBG("writing to file: %s (%d)\n", _sipdump_fpath, n); _sipdump_file = fopen( _sipdump_fpath, "w" ); diff --git a/src/modules/siptrace/README b/src/modules/siptrace/README index 5eab39eb2..65a3226c8 100644 --- a/src/modules/siptrace/README +++ b/src/modules/siptrace/README @@ -427,7 +427,8 @@ modparam("siptrace", "trace_delayed", 1) The local interface in the form of SIP URI from where to send the duplicated traffic. In the absence of this parameter Kamailio - automatically picks an interface. + automatically picks an interface. This parameter is only used for HEP + forwarding, not for SIP forwarding mode. Example 1.17. Set force_send_sock parameter ... @@ -472,8 +473,10 @@ modparam("siptrace", "auth_key", "spoihepuirthpeuia") Store or forward the current processed SIP message/transaction/dialog in database. It is stored in the form prior applying changes made to - it. Based on mode, one can trace the current message('m' - default), - the current transaction('t') or the current dialog('d'). + it. Based on mode, one can trace the current message('m'), the current + transaction('t') or the current dialog('d'). If no mode is given, it + falls back to the default mode - transaction tracking when trace_flag + is set, otherwise only the current message. Meaning of the parameters is as follows: * address - The address in form of SIP URI where to send a duplicate @@ -564,13 +567,13 @@ kamcmd siptrace.status check 6. Database setup - Before running Kamailio with siptrace, you have to setup the database - tables where the module will store the data. For that, if the table - were not created by the installation script or you choose to install - everything by yourself you can use the siptrace-create.sql SQL script - in the database directories in the kamailio/scripts folder as template. - You can also find the complete database documentation on the project - webpage, + Before running Kamailio with siptrace and activated trace_to_database + parameter, you have to setup the database tables where the module will + store the data. For that, if the table were not created by the + installation script or you choose to install everything by yourself you + can use the siptrace-create.sql SQL script in the database directories + in the kamailio/scripts folder as template. You can also find the + complete database documentation on the project webpage, https://www.kamailio.org/docs/db-tables/kamailio-db-devel.html. 7. Known issues diff --git a/src/modules/siptrace/doc/siptrace_admin.xml b/src/modules/siptrace/doc/siptrace_admin.xml index 6b3a1f49f..57c4b2a8a 100644 --- a/src/modules/siptrace/doc/siptrace_admin.xml +++ b/src/modules/siptrace/doc/siptrace_admin.xml @@ -455,7 +455,8 @@ modparam("siptrace", "trace_delayed", 1) The local interface in the form of SIP URI from where to send the duplicated traffic. In the absence of this parameter - &kamailio; automatically picks an interface. + &kamailio; automatically picks an interface. This parameter is + only used for HEP forwarding, not for SIP forwarding mode. Set <varname>force_send_sock</varname> parameter @@ -522,7 +523,9 @@ modparam("siptrace", "auth_key", "spoihepuirthpeuia") Store or forward the current processed SIP message/transaction/dialog in database. It is stored in the form prior applying changes made to it. Based on mode, one can trace - the current message('m' - default), the current transaction('t') or the current dialog('d'). + the current message('m'), the current transaction('t') or the current dialog('d'). + If no mode is given, it falls back to the default mode - transaction tracking when + trace_flag is set, otherwise only the current message. Meaning of the parameters is as follows: @@ -674,12 +677,12 @@ hlog("$hdr(P-MyID)", "Another one with a custom correlation ID");
Database setup - Before running &kamailio; with siptrace, you have to setup the database - tables where the module will store the data. For that, if the - table were not created by the installation script or you choose - to install everything by yourself you can use the siptrace-create.sql - SQL script in the database directories in the - kamailio/scripts folder as template. + Before running &kamailio; with siptrace and activated trace_to_database + parameter, you have to setup the database tables where the module will + store the data. For that, if the table were not created by the + installation script or you choose to install everything by yourself + you can use the siptrace-create.sql SQL script in + the database directories in the kamailio/scripts folder as template. You can also find the complete database documentation on the project webpage, &kamailiodbdocslink;. diff --git a/src/modules/siptrace/siptrace.c b/src/modules/siptrace/siptrace.c index e49946e52..161986d2c 100644 --- a/src/modules/siptrace/siptrace.c +++ b/src/modules/siptrace/siptrace.c @@ -534,7 +534,8 @@ static int sip_trace_store(siptrace_data_t *sto, dest_info_t *dst, trace_send_hep_duplicate( &sto->body, &sto->fromip, &sto->toip, dst, correlation_id_str); } else { - if(dst) { + /* sip_trace_mode() will not set a destination, uses duplicate_uri */ + if(dst || trace_to_database == 0) { trace_send_duplicate(sto->body.s, sto->body.len, dst); } } @@ -996,10 +997,13 @@ static int w_sip_trace3(sip_msg_t *msg, char *dest, char *correlation_id, char * dest_info_t dest_info; enum siptrace_type_t trace_type; - if (dest) { - if(fixup_get_svalue(msg, (gparam_t *)dest, &dup_uri_param_str) != 0) { - LM_ERR("unable to parse the dest URI string\n"); - return -1; + /* to support tracing to database without destination parameter - old mode */ + if (dest || trace_to_database == 0) { + if (dest) { + if(fixup_get_svalue(msg, (gparam_t *)dest, &dup_uri_param_str) != 0) { + LM_ERR("unable to parse the dest URI string\n"); + return -1; + } } if (dup_uri_param_str.s == 0 || (is_null_pv(dup_uri_param_str))) { diff --git a/src/modules/siputils/README b/src/modules/siputils/README index 390ef1b3c..74344a83c 100644 --- a/src/modules/siputils/README +++ b/src/modules/siputils/README @@ -32,12 +32,8 @@ Edited by Jan Janak -Edited by - Bogdan-Andrei Iancu -Edited by - Gabriel Vasile Copyright © 2008, 2005, 2003 1&1 Internet AG, FhG Fokus, Voice Sistem diff --git a/src/modules/siputils/contact_ops.c b/src/modules/siputils/contact_ops.c index bc48a8771..427bf3bb1 100644 --- a/src/modules/siputils/contact_ops.c +++ b/src/modules/siputils/contact_ops.c @@ -29,8 +29,6 @@ */ -#define STRICT_CHECK 1 - #include "contact_ops.h" #include "utils.h" #include "../../core/mem/mem.h" @@ -44,7 +42,7 @@ #include -int ki_encode_contact (sip_msg_t *msg, str *eprefix, str *eaddr) +int ki_encode_contact(sip_msg_t *msg, str *eprefix, str *eaddr) { contact_body_t *cb; contact_t *c; @@ -54,16 +52,17 @@ int ki_encode_contact (sip_msg_t *msg, str *eprefix, str *eaddr) char separator; /* - * I have a list of contacts in contact->parsed which is of type contact_body_t - * inside i have a contact->parsed->contact which is the head of the list of contacts - * inside it is a + * I have a list of contacts in contact->parsed which is of type + * contact_body_t inside i have a contact->parsed->contact which is + * the head of the list of contacts inside it is a * str uri; * struct contact *next; * I just have to visit each uri and encode each uri according to a scheme */ - if((msg->contact == NULL) && ((parse_headers(msg, HDR_CONTACT_F, 0) == -1) - || (msg->contact == NULL))) { + if((msg->contact == NULL) + && ((parse_headers(msg, HDR_CONTACT_F, 0) == -1) + || (msg->contact == NULL))) { LM_ERR("no Contact header present\n"); return -1; } @@ -88,34 +87,28 @@ int ki_encode_contact (sip_msg_t *msg, str *eprefix, str *eaddr) res = encode_uri(uri, eprefix->s, eaddr->s, separator, &newUri); if(res != 0) { - LM_ERR("failed encoding contact.Code %d\n", res); -#ifdef STRICT_CHECK + LM_ERR("failed encoding contact - return code %d\n", res); return res; -#endif } else if(patch(msg, uri.s, uri.len, newUri.s, newUri.len) < 0) { - LM_ERR("lumping failed in mangling port \n"); + LM_ERR("lumping failed in mangling port\n"); return -2; } -/* encoding next contacts too?*/ -#ifdef ENCODE_ALL_CONTACTS + /* encoding next contacts too? */ while(c->next != NULL) { c = c->next; uri = c->uri; res = encode_uri(uri, eprefix->s, eaddr->s, separator, &newUri); if(res != 0) { - LM_ERR("failed encode_uri.Code %d\n", res); -#ifdef STRICT_CHECK + LM_ERR("failed encode_uri - return code %d\n", res); return res; -#endif } else if(patch(msg, uri.s, uri.len, newUri.s, newUri.len) < 0) { - LM_ERR("lumping failed in mangling port \n"); + LM_ERR("lumping failed in mangling port\n"); return -3; } } /* while */ -#endif /* ENCODE_ALL_CONTACTS */ - } /* if c != NULL */ + } /* if c != NULL */ return 1; } @@ -147,40 +140,32 @@ int ki_decode_contact(sip_msg_t *msg) LM_DBG("[%.*s]\n", 75, msg->buf); separator = DEFAULT_SEPARATOR[0]; - if (contact_flds_separator != NULL) - if (strlen(contact_flds_separator)>=1) + if(contact_flds_separator != NULL) + if(strlen(contact_flds_separator) >= 1) separator = contact_flds_separator[0]; - if ((msg->new_uri.s == NULL) || (msg->new_uri.len == 0)) - { + if((msg->new_uri.s == NULL) || (msg->new_uri.len == 0)) { uri = msg->first_line.u.request.uri; - if (uri.s == NULL) + if(uri.s == NULL) return -1; - } - else - { + } else { uri = msg->new_uri; } - res = decode_uri (uri, separator, &newUri); + res = decode_uri(uri, separator, &newUri); - if (res == 0) + if(res == 0) LM_DBG("newuri.s=[%.*s]\n", newUri.len, newUri.s); - if (res != 0) - { - LM_ERR("failed decoding contact.Code %d\n", res); -#ifdef STRICT_CHECK + if(res != 0) { + LM_ERR("failed decoding contact [%.*s] - return code %d\n", + uri.len, uri.s, res); return res; -#endif - } - else - { + } else { /* we do not modify the original first line */ - if ((msg->new_uri.s == NULL) || (msg->new_uri.len == 0)) + if((msg->new_uri.s == NULL) || (msg->new_uri.len == 0)) msg->new_uri = newUri; - else - { + else { pkg_free(msg->new_uri.s); msg->new_uri = newUri; } @@ -202,25 +187,25 @@ int ki_decode_contact_header(sip_msg_t *msg) str newUri; char separator; int res; - str* ruri; + str *ruri; - if ((msg->contact == NULL)&&((parse_headers(msg,HDR_CONTACT_F,0) == -1) || - (msg->contact== NULL) )) - { + if((msg->contact == NULL) + && ((parse_headers(msg, HDR_CONTACT_F, 0) == -1) + || (msg->contact == NULL))) { LM_ERR("no Contact header present\n"); return -1; } separator = DEFAULT_SEPARATOR[0]; - if (contact_flds_separator != NULL) - if (strlen(contact_flds_separator)>=1) + if(contact_flds_separator != NULL) + if(strlen(contact_flds_separator) >= 1) separator = contact_flds_separator[0]; - LM_DBG("Using separator [%c]\n",separator); + LM_DBG("using separator [%c]\n", separator); ruri = GET_RURI(msg); - LM_DBG("New uri [%.*s]\n", ruri->len, ruri->s); + LM_DBG("new uri [%.*s]\n", ruri->len, ruri->s); ruri = &msg->first_line.u.request.uri; - LM_DBG("Initial uri [%.*s]\n", ruri->len, ruri->s); + LM_DBG("initial uri [%.*s]\n", ruri->len, ruri->s); if(msg->contact->parsed == NULL) { if(parse_contact(msg->contact) < 0 || msg->contact->parsed == NULL) { @@ -236,35 +221,34 @@ int ki_decode_contact_header(sip_msg_t *msg) uri = c->uri; res = decode_uri(uri, separator, &newUri); - LM_DBG("newuri.s=[%.*s]\n", newUri.len, newUri.s); if(res != 0) { - LM_ERR("failed decoding contact.Code %d\n", res); -#ifdef STRICT_CHECK + LM_ERR("failed decoding contact [%.*s] - return code %d\n", + uri.len, uri.s, res); return res; -#endif - } else if(patch(msg, uri.s, uri.len, newUri.s, newUri.len) < 0) { - LM_ERR("lumping failed in mangling port \n"); + } + LM_DBG("newuri.s=[%.*s]\n", newUri.len, newUri.s); + if(patch(msg, uri.s, uri.len, newUri.s, newUri.len) < 0) { + LM_ERR("lumping failed in mangling port\n"); return -2; } -#ifdef DECODE_ALL_CONTACTS while(c->next != NULL) { c = c->next; uri = c->uri; res = decode_uri(uri, separator, &newUri); if(res != 0) { - LM_ERR("failed decoding contact.Code %d\n", res); -#ifdef STRICT_CHECK + LM_ERR("failed decoding contact [%.*s] - return code %d\n", + uri.len, uri.s, res); return res; -#endif - } else if(patch(msg, uri.s, uri.len, newUri.s, newUri.len) < 0) { - LM_ERR("lumping failed in mangling port \n"); + } + LM_DBG("newuri.s=[%.*s]\n", newUri.len, newUri.s); + if(patch(msg, uri.s, uri.len, newUri.s, newUri.len) < 0) { + LM_ERR("lumping failed in mangling port\n"); return -3; } } // end while -#endif - } // if c!= NULL + } // if c!= NULL return 1; } @@ -276,52 +260,53 @@ int decode_contact_header(sip_msg_t *msg, char *unused1, char *unused2) } - int -encode2format (str uri, struct uri_format *format) +int encode2format(str uri, struct uri_format *format) { int foo; char *string, *pos, *start, *end; struct sip_uri sipUri; - if (uri.s == NULL) + if(uri.s == NULL) return -1; string = uri.s; - pos = memchr (string, '<', uri.len); - if (pos != NULL) /* we are only interested of chars inside <> */ + pos = memchr(string, '<', uri.len); + if(pos != NULL) /* we are only interested of chars inside <> */ { /* KD: I think this can be removed as the parsed contact removed <> already */ - start = memchr (string, ':', uri.len); - if (start == NULL) return -2; - if (start - pos < 4) return -3; + start = memchr(string, ':', uri.len); + if(start == NULL) + return -2; + if(start - pos < 4) + return -3; start = start - 3; - end = strchr (start, '>'); - if (end == NULL) - return -4; /* must be a match to < */ - } - else /* we do not have <> */ + end = strchr(start, '>'); + if(end == NULL) + return -4; /* must be a match to < */ + } else /* we do not have <> */ { - start = memchr (string, ':', uri.len); - if (start == NULL) + start = memchr(string, ':', uri.len); + if(start == NULL) return -5; - if (start - string < 3) + if(start - string < 3) return -6; - /* KD: FIXME: Looks like this code can not handle 'sips' URIs and discards all other URI parameters! */ + /* KD: FIXME: Looks like this code can not handle 'sips' + * URIs and discards all other URI parameters! */ start = start - 3; end = string + uri.len; } - memset(format,0,sizeof(struct uri_format)); - format->first = start - string + 4; /*sip: */ + memset(format, 0, sizeof(struct uri_format)); + format->first = start - string + 4; /*sip: */ format->second = end - string; /* --------------------------testing ------------------------------- */ - /* sip:gva@pass@10.0.0.1;;transport=udp>;expires=2 INCORECT BEHAVIOR OF parse_uri,myfunction works good */ - foo = parse_uri (start, end - start, &sipUri); - if (foo != 0) - { - LM_ERR("parse_uri failed on [%.*s].Code %d \n",uri.len,uri.s,foo); - LM_DBG("PARSING uri with parse uri not ok [%d]\n", foo); - return foo-10; + /* sip:gva@pass@10.0.0.1;;transport=udp>;expires=2 INCORECT BEHAVIOR OF + * parse_uri,myfunction works good */ + foo = parse_uri(start, end - start, &sipUri); + if(foo != 0) { + LM_ERR("parse_uri failed on [%.*s] - return code %d \n", + uri.len, uri.s, foo); + return foo - 10; } @@ -331,183 +316,203 @@ encode2format (str uri, struct uri_format *format) format->port = sipUri.port; format->protocol = sipUri.transport_val; - LM_DBG("First and second format [%d][%d] transport=[%.*s] transportval=[%.*s]\n", - format->first, format->second, - sipUri.transport.len, sipUri.transport.s, - sipUri.transport_val.len, sipUri.transport_val.s); + LM_DBG("first and second format [%d][%d] transport=[%.*s] " + "transportval=[%.*s]\n", + format->first, format->second, sipUri.transport.len, + sipUri.transport.s, sipUri.transport_val.len, + sipUri.transport_val.s); return 0; - } - int -encode_uri (str uri, char *encoding_prefix, char *public_ip,char separator, str * result) +int encode_uri(str uri, char *encoding_prefix, char *public_ip, char separator, + str *result) { struct uri_format format; char *pos; - int foo,res; + int foo, res; result->s = NULL; result->len = 0; - if (uri.len <= 1) - return -1; /* no contact or an invalid one */ - if (public_ip == NULL) - { + if(uri.len <= 1) + return -1; /* no contact or an invalid one */ + if(public_ip == NULL) { LM_ERR("invalid NULL value for public_ip parameter\n"); return -2; } - LM_DBG("Encoding request for [%.*s] with [%s]-[%s]\n", uri.len,uri.s, encoding_prefix, public_ip); + LM_DBG("encoding request for [%.*s] with [%s]-[%s]\n", uri.len, uri.s, + encoding_prefix, public_ip); - foo = encode2format (uri, &format); - if (foo < 0) - { - LM_ERR("unable to encode Contact URI [%.*s].Return code %d\n",uri.len,uri.s,foo); + foo = encode2format(uri, &format); + if(foo < 0) { + LM_ERR("unable to encode Contact URI [%.*s].Return code %d\n", uri.len, + uri.s, foo); return foo - 20; } - LM_DBG("user=%.*s ip=%.*s port=%.*s protocol=%.*s\n",format.username.len,format.username.s,format.ip.len,format.ip.s, - format.port.len,format.port.s,format.protocol.len,format.protocol.s); + LM_DBG("user=%.*s ip=%.*s port=%.*s protocol=%.*s\n", format.username.len, + format.username.s, format.ip.len, format.ip.s, format.port.len, + format.port.s, format.protocol.len, format.protocol.s); /* a complete uri would be sip:username@ip:port;transport=protocol goes to * sip:enc_pref*username*ip*port*protocol@public_ip */ - foo = 1; /*strlen(separator); */ - result->len = format.first + uri.len - format.second + //ar trebui sa sterg 1 - strlen (encoding_prefix) + foo + - format.username.len + foo + - format.password.len + foo + - format.ip.len + foo + format.port.len + foo + - format.protocol.len + 1 + strlen (public_ip); + foo = 1; /* strlen(separator); */ + result->len = format.first + uri.len - format.second + + strlen(encoding_prefix) + foo + format.username.len + foo + + format.password.len + foo + format.ip.len + foo + + format.port.len + foo + format.protocol.len + 1 + + strlen(public_ip); /* adding one comes from @ */ - result->s = pkg_malloc (result->len); + result->s = pkg_malloc(result->len); pos = result->s; - if (pos == NULL) - { - LM_DBG("Unable to alloc result [%d] end=[%d]\n", - result->len, format.second); + if(pos == NULL) { + LM_DBG("unable to alloc result [%d] end=[%d]\n", result->len, + format.second); LM_ERR("unable to alloc pkg memory\n"); return -3; } - LM_DBG("pass=[%d]i: allocated [%d], bytes.first=[%d] lengthsec=[%d]; adding [%d]->[%.*s]\n", - format.password.len, result->len, format.first, uri.len-format.second, format.first, format.first,uri.s); - - res = snprintf(pos,result->len,"%.*s%s%c%.*s%c%.*s%c%.*s%c%.*s%c%.*s@",format.first,uri.s,encoding_prefix,separator, - format.username.len,format.username.s,separator,format.password.len,format.password.s, - separator,format.ip.len,format.ip.s,separator,format.port.len,format.port.s,separator,format.protocol.len,format.protocol.s); - - if ((res < 0 )||(res>result->len)) - { + LM_DBG("pass=[%d]i: allocated [%d], bytes.first=[%d] lengthsec=[%d];" + " adding [%d]->[%.*s]\n", + format.password.len, result->len, format.first, + uri.len - format.second, format.first, format.first, uri.s); + + res = snprintf(pos, result->len, "%.*s%s%c%.*s%c%.*s%c%.*s%c%.*s%c%.*s@", + format.first, uri.s, encoding_prefix, separator, + format.username.len, format.username.s, separator, + format.password.len, format.password.s, separator, format.ip.len, + format.ip.s, separator, format.port.len, format.port.s, separator, + format.protocol.len, format.protocol.s); + + if((res < 0) || (res > result->len)) { LM_ERR("unable to construct new uri.\n"); - if (result->s != NULL) pkg_free(result->s); + if(result->s != NULL) + pkg_free(result->s); return -4; } - LM_DBG("res= %d\npos=%s\n",res,pos); - pos = pos + res ;/* overwriting the \0 from snprintf */ - memcpy (pos, public_ip, strlen (public_ip)); - pos = pos + strlen (public_ip); - memcpy (pos, uri.s + format.second, uri.len - format.second); + LM_DBG("res= %d\npos=%s\n", res, pos); + pos = pos + res; /* overwriting the \0 from snprintf */ + memcpy(pos, public_ip, strlen(public_ip)); + pos = pos + strlen(public_ip); + memcpy(pos, uri.s + format.second, uri.len - format.second); - LM_DBG("Adding [%.*s] => new uri [%.*s]\n", - uri.len - format.second, uri.s + format.second, - result->len, result->s); + LM_DBG("adding [%.*s] => new uri [%.*s]\n", uri.len - format.second, + uri.s + format.second, result->len, result->s); - /* Because called parse_uri format contains pointers to the inside of msg,must not deallocate */ + /* Because called parse_uri format contains pointers to the inside of msg, + * must not deallocate */ return 0; } - int -decode2format (str uri, char separator, struct uri_format *format) +int decode2format(str uri, char separator, struct uri_format *format) { - char *start, *end, *pos,*lastpos; + char *start, *end, *pos, *lastpos; str tmp; - enum {EX_PREFIX=0,EX_USER,EX_PASS,EX_IP,EX_PORT,EX_PROT,EX_FINAL} state; - - //memset (format, 0, sizeof ((struct uri_format))); - - if (uri.s == NULL) + enum { - LM_ERR("invalid parameter uri.It is NULL\n"); + EX_PREFIX = 0, + EX_USER, + EX_PASS, + EX_IP, + EX_PORT, + EX_PROT, + EX_FINAL + } state; + + if(uri.s == NULL) { + LM_ERR("invalid parameter uri - it is NULL\n"); return -1; } /* sip:enc_pref*username*password*ip*port*protocol@public_ip */ - start = memchr (uri.s, ':', uri.len); - if (start == NULL) - { - LM_ERR("invalid SIP uri.Missing :\n"); + start = memchr(uri.s, ':', uri.len); + if(start == NULL) { + LM_ERR("invalid SIP uri - missing :\n"); return -2; - } /* invalid uri */ - start = start + 1; /* jumping over sip: ATENTIE LA BUFFER OVERFLOW DACA E DOAR sip: */ + } /* invalid uri */ + start = start + 1; /* jumping over sip: */ format->first = start - uri.s; /* start */ - end = memchr(start,'@',uri.len-(start-uri.s)); - if (end == NULL) - { - LM_ERR("invalid SIP uri.Missing @\n"); - return -3;/* no host address found */ + end = memchr(start, '@', uri.len - (start - uri.s)); + if(end == NULL) { + LM_ERR("invalid SIP uri - missing @\n"); + return -3; /* no host address found */ } - LM_DBG("Decoding [%.*s]\n", (int)(long)(end-start), start); + LM_DBG("decoding [%.*s]\n", (int)(long)(end - start), start); state = EX_PREFIX; lastpos = start; - for (pos = start;pos0) tmp.s = lastpos; - else tmp.s = NULL; - switch (state) - { - case EX_PREFIX: state = EX_USER;break; - case EX_USER:format->username = tmp;state = EX_PASS;break; - case EX_PASS:format->password = tmp;state = EX_IP;break; - case EX_IP:format->ip = tmp;state = EX_PORT;break; - case EX_PORT:format->port = tmp;state = EX_PROT;break; - default: - { - /* this should not happen, we should find @ not separator */ - return -4; - break; - } + if(tmp.len > 0) + tmp.s = lastpos; + else + tmp.s = NULL; + switch(state) { + case EX_PREFIX: + state = EX_USER; + break; + case EX_USER: + format->username = tmp; + state = EX_PASS; + break; + case EX_PASS: + format->password = tmp; + state = EX_IP; + break; + case EX_IP: + format->ip = tmp; + state = EX_PORT; + break; + case EX_PORT: + format->port = tmp; + state = EX_PROT; + break; + default: { + /* this should not happen, we should find @ not separator */ + return -4; + break; + } } - lastpos = pos+1; - + lastpos = pos + 1; } } /* we must be in state EX_PROT and protocol is between lastpos and end@ */ - if (state != EX_PROT) return -6; + if(state != EX_PROT) { + LM_ERR("unexpected state %d\n", state); + return -6; + } format->protocol.len = end - lastpos; - if (format->protocol.len>0) format->protocol.s = lastpos; - else format->protocol.s = NULL; + if(format->protocol.len > 0) + format->protocol.s = lastpos; + else + format->protocol.s = NULL; /* I should check perhaps that after @ there is something */ - LM_DBG("username=[%.*s] password=[%.*s] ip=[%.*s] port=[%.*s] protocol=[%.*s]\n", - format->username.len,format->username.s, - format->password.len,format->password.s, - format->ip.len, format->ip.s, - format->port.len,format->port.s, - format->protocol.len,format->protocol.s); + LM_DBG("username=[%.*s] password=[%.*s] ip=[%.*s] port=[%.*s] " + "protocol=[%.*s]\n", + format->username.len, format->username.s, format->password.len, + format->password.s, format->ip.len, format->ip.s, format->port.len, + format->port.s, format->protocol.len, format->protocol.s); /* looking for the end of public ip */ - start = end;/*we are now at @ */ - for(pos = start;pos')) - { + start = end; /*we are now at @ */ + for(pos = start; pos < uri.s + uri.len; pos++) { + if((*pos == ';') || (*pos == '>')) { /* found end */ format->second = pos - uri.s; return 0; @@ -516,12 +521,10 @@ decode2format (str uri, char separator, struct uri_format *format) /* if we are here we did not find > or ; */ format->second = uri.len; return 0; - } - int -decode_uri (str uri, char separator, str * result) +int decode_uri(str uri, char separator, str *result) { char *pos; struct uri_format format; @@ -530,27 +533,23 @@ decode_uri (str uri, char separator, str * result) result->s = NULL; result->len = 0; - if ((uri.len <= 0) || (uri.s == NULL)) - { + if((uri.len <= 0) || (uri.s == NULL)) { LM_ERR("invalid value for uri\n"); return -1; } - foo = decode2format (uri, separator, &format); - if (foo < 0) - { - LM_ERR("failed to decode Contact uri .Error code %d\n",foo); + foo = decode2format(uri, separator, &format); + if(foo < 0) { + LM_ERR("failed to decode Contact uri .Error code %d\n", foo); return foo - 20; } /* sanity check */ - if (format.ip.len <= 0) - { + if(format.ip.len <= 0) { LM_ERR("unable to decode host address \n"); - return -2;/* should I quit or ignore ? */ + return -2; /* should I quit or ignore ? */ } - if ((format.password.len > 0) && (format.username.len <= 0)) - { + if((format.password.len > 0) && (format.username.len <= 0)) { LM_ERR("password decoded but no username available\n"); return -3; } @@ -558,20 +557,26 @@ decode_uri (str uri, char separator, str * result) /* a complete uri would be sip:username:password@ip:port;transport=protocol goes to * sip:enc_pref#username#password#ip#port#protocol@public_ip */ - result->len = format.first + (uri.len - format.second); /* not NULL terminated */ - if (format.username.len > 0) result->len += format.username.len + 1; //: or @ - if (format.password.len > 0) result->len += format.password.len + 1; //@ + result->len = + format.first + (uri.len - format.second); /* not NULL terminated */ + if(format.username.len > 0) + result->len += format.username.len + 1; //: or @ + if(format.password.len > 0) + result->len += format.password.len + 1; //@ - /* if (format.ip.len > 0) */ result->len += format.ip.len; + /* if (format.ip.len > 0) */ + result->len += format.ip.len; - if (format.port.len > 0) result->len += 1 + format.port.len; //: - if (format.protocol.len > 0) result->len += 1 + 10 + format.protocol.len; //;transport= - LM_DBG("Result size is [%d]. Original Uri size is [%d].\n", result->len, uri.len); + if(format.port.len > 0) + result->len += 1 + format.port.len; //: + if(format.protocol.len > 0) + result->len += 1 + 10 + format.protocol.len; //;transport= + LM_DBG("result size is [%d] - original Uri size is [%d].\n", result->len, + uri.len); /* adding one comes from * */ - result->s = pkg_malloc (result->len); - if (result->s == NULL) - { + result->s = pkg_malloc(result->len); + if(result->s == NULL) { LM_ERR("unable to allocate pkg memory\n"); return -4; } @@ -579,52 +584,47 @@ decode_uri (str uri, char separator, str * result) LM_DBG("Adding [%.*s]\n", format.first, uri.s); - memcpy (pos, uri.s, format.first); /* till sip: */ + memcpy(pos, uri.s, format.first); /* till sip: */ pos = pos + format.first; - if (format.username.len > 0) - { - memcpy (pos, format.username.s, format.username.len); + if(format.username.len > 0) { + memcpy(pos, format.username.s, format.username.len); pos = pos + format.username.len; - if (format.password.len > 0) - memcpy (pos, ":", 1); + if(format.password.len > 0) + memcpy(pos, ":", 1); else - memcpy (pos, "@", 1); + memcpy(pos, "@", 1); pos = pos + 1; } - if (format.password.len > 0) - { - memcpy (pos, format.password.s, format.password.len); + if(format.password.len > 0) { + memcpy(pos, format.password.s, format.password.len); pos = pos + format.password.len; - memcpy (pos, "@", 1); + memcpy(pos, "@", 1); pos = pos + 1; } /* if (format.ip.len > 0) */ - memcpy (pos, format.ip.s, format.ip.len); + memcpy(pos, format.ip.s, format.ip.len); pos = pos + format.ip.len; - if (format.port.len > 0) - { - memcpy (pos, ":", 1); + if(format.port.len > 0) { + memcpy(pos, ":", 1); pos = pos + 1; - memcpy (pos, format.port.s, format.port.len); + memcpy(pos, format.port.s, format.port.len); pos = pos + format.port.len; } - if (format.protocol.len > 0) - { - memcpy (pos, ";transport=", 11); + if(format.protocol.len > 0) { + memcpy(pos, ";transport=", 11); pos = pos + 11; - memcpy (pos, format.protocol.s, format.protocol.len); + memcpy(pos, format.protocol.s, format.protocol.len); pos = pos + format.protocol.len; } LM_DBG("Adding2 [%.*s]\n", uri.len - format.second, uri.s + format.second); - memcpy (pos, uri.s + format.second, uri.len - format.second); /* till end: */ + memcpy(pos, uri.s + format.second, uri.len - format.second); /* till end: */ - LM_DBG("New decoded uri [%.*s]\n", result->len,result->s); + LM_DBG("New decoded uri [%.*s]\n", result->len, result->s); return 0; } - diff --git a/src/modules/siputils/contact_ops.h b/src/modules/siputils/contact_ops.h index 939b80ac6..bacf42c17 100644 --- a/src/modules/siputils/contact_ops.h +++ b/src/modules/siputils/contact_ops.h @@ -36,14 +36,7 @@ #ifndef CONTACT_OPS_H #define CONTACT_OPS_H -/* if you want to parse all contacts not just de first one */ - - - -#include "../../core/parser/msg_parser.h" /* struct sip_msg */ - -#define ENCODE_ALL_CONTACTS 1 -#define DECODE_ALL_CONTACTS 1 +#include "../../core/parser/msg_parser.h" /* struct sip_msg */ #define DEFAULT_SEPARATOR "*" @@ -64,18 +57,19 @@ struct uri_format typedef struct uri_format contact_fields_t; -int ki_encode_contact (sip_msg_t *msg, str *eprefix, str *eaddr); +int ki_encode_contact(sip_msg_t *msg, str *eprefix, str *eaddr); int ki_decode_contact(sip_msg_t *msg); int ki_decode_contact_header(sip_msg_t *msg); -int encode_contact (struct sip_msg *msg, char *encoding_prefix,char *public_ip); -int decode_contact (struct sip_msg *msg, char *unused1,char *unused2); -int decode_contact_header (struct sip_msg *msg, char *unused1,char *unused2); +int encode_contact(struct sip_msg *msg, char *encoding_prefix, char *public_ip); +int decode_contact(struct sip_msg *msg, char *unused1, char *unused2); +int decode_contact_header(struct sip_msg *msg, char *unused1, char *unused2); -int encode2format (str uri, struct uri_format *format); -int decode2format (str uri, char separator, struct uri_format *format); +int encode2format(str uri, struct uri_format *format); +int decode2format(str uri, char separator, struct uri_format *format); -int encode_uri (str uri, char *encoding_prefix, char *public_ip,char separator, str * result); -int decode_uri (str uri, char separator, str * result); +int encode_uri(str uri, char *encoding_prefix, char *public_ip, char separator, + str *result); +int decode_uri(str uri, char separator, str *result); #endif diff --git a/src/modules/snmpstats/README b/src/modules/snmpstats/README index 464dd5e58..5308308e3 100644 --- a/src/modules/snmpstats/README +++ b/src/modules/snmpstats/README @@ -8,8 +8,6 @@ Edited by Jeffrey Magder -Edited by - Olle E. Johansson Copyright © 2006 SOMA Networks, Inc. diff --git a/src/modules/sqlops/sqlops.c b/src/modules/sqlops/sqlops.c index 3943b1b81..872755164 100644 --- a/src/modules/sqlops/sqlops.c +++ b/src/modules/sqlops/sqlops.c @@ -492,6 +492,60 @@ static int ki_sqlops_query(sip_msg_t *msg, str *scon, str *squery, str *sres) return sqlops_do_query(scon, squery, sres); } +static int ki_sqlops_pvquery(sip_msg_t *msg, str *scon, str *squery, str *sres) +{ + pv_elem_t *query = NULL; + pvname_list_t *pv_res = NULL; + pvname_list_t *pvl = NULL; + sql_con_t *con = NULL; + int i, res; + + if (scon == NULL || scon->s == NULL || scon->len<=0) { + LM_ERR("invalid connection name\n"); + return -1; + } + + con = sql_get_connection(scon); + if(con==NULL) { + LM_ERR("invalid connection [%.*s]\n", scon->len, scon->s); + return -1; + } + + if(pv_parse_format(squery, &query)<0) + { + LM_ERR("invalid query string [%s]\n", squery->s); + return -1; + } + + /* parse result variables into list of pv_spec_t's */ + pv_res = parse_pvname_list(sres, 0); + if(pv_res==NULL) + { + LM_ERR("invalid result parameter [%s]\n", sres->s); + pv_elem_free_all(query); + return -1; + } + /* check if all result variables are writable */ + pvl = pv_res; + i = 1; + while (pvl) { + if (pvl->sname.setf == NULL) + { + LM_ERR("result variable [%d] is read-only\n", i); + pv_elem_free_all(query); + free_pvname_list(pv_res); + return -1; + } + i++; + pvl = pvl->next; + } + res = sql_do_pvquery(msg, con, query, pv_res); + + pv_elem_free_all(query); + free_pvname_list(pv_res); + return res; +} + static int ki_sqlops_query_async(sip_msg_t *msg, str *scon, str *squery) { sql_con_t *con = NULL; @@ -561,6 +615,11 @@ static sr_kemi_t sr_kemi_sqlops_exports[] = { { SR_KEMIP_STR, SR_KEMIP_INT, SR_KEMIP_INT, SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE } }, + { str_init("sqlops"), str_init("sql_pvquery"), + SR_KEMIP_INT, ki_sqlops_pvquery, + { SR_KEMIP_STR, SR_KEMIP_STR, SR_KEMIP_STR, + SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE } + }, { str_init("sqlops"), str_init("sql_xquery"), SR_KEMIP_INT, sqlops_do_xquery, { SR_KEMIP_STR, SR_KEMIP_STR, SR_KEMIP_STR, diff --git a/src/modules/tls/Makefile b/src/modules/tls/Makefile index 224bbd81d..58c758c00 100644 --- a/src/modules/tls/Makefile +++ b/src/modules/tls/Makefile @@ -8,6 +8,13 @@ include ../../Makefile.defs auto_gen= NAME=tls.so +# set to yes when wanting to link with static libraries +LIBSSL_STATIC ?= no +# set to yes when wanting to link with static libraries compiled from source +LIBSSL_STATIC_SRCLIB ?= no +# set to the path of the folder with static libraries compiled from source +LIBSSL_STATIC_SRCPATH ?= /usr/local/src/openssl + ifeq ($(CROSS_COMPILE),) SSL_BUILDER=$(shell \ if pkg-config --exists libssl; then \ @@ -16,8 +23,21 @@ SSL_BUILDER=$(shell \ endif ifneq ($(SSL_BUILDER),) +ifneq ($(LIBSSL_STATIC),yes) DEFS += $(shell $(SSL_BUILDER) --cflags) LIBS += $(shell $(SSL_BUILDER) --libs) +else +ifneq ($(LIBSSL_STATIC_SRCLIB),yes) + ## when static libs (*.a) from packages are compiled with -fPIC + DEFS += $(shell $(SSL_BUILDER) --cflags) + LIBS += $(shell $(SSL_BUILDER) --libs-only-L) + LIBS += -l:libssl.a -l:libcrypto.a -l:libz.a -l:libdl.a +else + ## when linking against static libs compiled from sources + DEFS += -I$(LIBSSL_STATIC_SRCPATH)/include + LIBS += $(LIBSSL_STATIC_SRCPATH)/libssl.a $(LIBSSL_STATIC_SRCPATH)/libcrypto.a +endif # ifneq ($(LIBSSL_STATIC_SRCLIB),yes) +endif # ifneq ($(LIBSSL_STATIC),yes) else DEFS += -I$(LOCALBASE)/ssl/include LIBS += -L$(LOCALBASE)/lib -L$(LOCALBASE)/ssl/lib \ diff --git a/src/modules/tls/tls_domain.c b/src/modules/tls/tls_domain.c index ad59eed66..0f1ea60f5 100644 --- a/src/modules/tls/tls_domain.c +++ b/src/modules/tls/tls_domain.c @@ -1026,7 +1026,11 @@ static int ksr_tls_fix_domain(tls_domain_t* d, tls_domain_t* def) d->ctx[i] = SSL_CTX_new((SSL_METHOD*)ssl_methods[d->method - 1]); } if (d->ctx[i] == NULL) { - ERR("%s: Cannot create SSL context\n", tls_domain_str(d)); + unsigned long e = 0; + e = ERR_peek_last_error(); + ERR("%s: Cannot create SSL context [%d] (%lu: %s / %s)\n", + tls_domain_str(d), i, e, ERR_error_string(e, NULL), + ERR_reason_error_string(e)); return -1; } if(d->method>TLS_USE_TLSvRANGE) { @@ -1036,7 +1040,11 @@ static int ksr_tls_fix_domain(tls_domain_t* d, tls_domain_t* def) /* libssl >= 1.1.0 */ d->ctx[i] = SSL_CTX_new(sr_tls_methods[d->method - 1].TLSMethod); if (d->ctx[i] == NULL) { - ERR("%s: Cannot create SSL context\n", tls_domain_str(d)); + unsigned long e = 0; + e = ERR_peek_last_error(); + ERR("%s: Cannot create SSL context [%d] (%lu: %s / %s)\n", + tls_domain_str(d), i, e, ERR_error_string(e, NULL), + ERR_reason_error_string(e)); return -1; } if(d->method>TLS_USE_TLSvRANGE) { diff --git a/src/modules/tm/t_cancel.c b/src/modules/tm/t_cancel.c index d25b9d148..79c411d43 100644 --- a/src/modules/tm/t_cancel.c +++ b/src/modules/tm/t_cancel.c @@ -290,8 +290,12 @@ int cancel_branch( struct cell *t, int branch, , reason ); } - if (!cancel) { + if (!cancel || len<=0) { LM_ERR("attempt to build a CANCEL failed\n"); + if(cancel) { + shm_free(cancel); + cancel = NULL; + } /* remove BUSY_BUFFER -- mark cancel buffer as not used */ pcbuf=&crb->buffer; /* workaround for type punning warnings */ atomic_set_long(pcbuf, 0); @@ -497,8 +501,12 @@ unsigned int t_uac_cancel( str *headers, str *body, cancel->dst.proto = invite->dst.proto; //cancel->dst.proto_reserved1 = invite->dst.proto_reserved1; - if(!(buf = build_uac_cancel(headers,body,t_invite,0,&len, - &(cancel->dst)))){ + buf = build_uac_cancel(headers, body, t_invite, 0, &len, &(cancel->dst)); + if(!buf || len<=0) { + if(buf) { + shm_free(buf); + buf = NULL; + } ret=0; LM_ERR("attempt to build a CANCEL failed\n"); goto error1; diff --git a/src/modules/tm/t_fwd.c b/src/modules/tm/t_fwd.c index 83f22ebf0..edd73fade 100644 --- a/src/modules/tm/t_fwd.c +++ b/src/modules/tm/t_fwd.c @@ -474,8 +474,12 @@ static int prepare_new_uac( struct cell *t, struct sip_msg *i_req, } /* ... and build it now */ shbuf=build_req_buf_from_sip_req( i_req, &len, dst, BUILD_IN_SHM); - if (!shbuf) { + if (!shbuf || len<=0) { LM_ERR("could not build request\n"); + if(shbuf) { + shm_free(shbuf); + shbuf = NULL; + } ret=E_OUT_OF_MEM; goto error01; } @@ -883,7 +887,11 @@ static int add_uac_from_buf( struct cell *t, struct sip_msg *request, shbuf=print_uac_request_from_buf( t, request, branch, uri, &len, &t->uac[branch].request.dst, buf, buf_len); - if (!shbuf) { + if (!shbuf || len<=0) { + if(shbuf) { + shm_free(shbuf); + shbuf = NULL; + } ret=ser_error=E_OUT_OF_MEM; goto error; } @@ -1109,7 +1117,11 @@ int e2e_cancel_branch( struct sip_msg *cancel_msg, struct cell *t_cancel, CANCEL_LEN, &t_invite->to , 0 ); - if (unlikely(!shbuf)) { + if (unlikely(!shbuf) || len<=0) { + if(shbuf) { + shm_free(shbuf); + shbuf = NULL; + } LM_ERR("printing e2e cancel failed\n"); ret=ser_error=E_OUT_OF_MEM; goto error; diff --git a/src/modules/tm/t_msgbuilder.c b/src/modules/tm/t_msgbuilder.c index 75f0ab7fa..bd9952467 100644 --- a/src/modules/tm/t_msgbuilder.c +++ b/src/modules/tm/t_msgbuilder.c @@ -252,7 +252,7 @@ error: * * Can not be used to build other type of requests! */ -char *build_local_reparse(struct cell *Trans,unsigned int branch, +char *build_local_reparse(tm_cell_t *Trans,unsigned int branch, unsigned int *len, char *method, int method_len, str *to , struct cancel_reason *reason ) @@ -272,7 +272,7 @@ char *build_local_reparse(struct cell *Trans,unsigned int branch, invite_buf = Trans->uac[branch].request.buffer; invite_len = Trans->uac[branch].request.buffer_len; - if (!invite_buf || !invite_len) { + if (!invite_buf || invite_len<=0) { LM_ERR("INVITE is missing\n"); goto error; } diff --git a/src/modules/tm/t_reply.c b/src/modules/tm/t_reply.c index 77747d34c..c868e70a9 100644 --- a/src/modules/tm/t_reply.c +++ b/src/modules/tm/t_reply.c @@ -484,12 +484,16 @@ static int _reply_light( struct cell *trans, char* buf, unsigned int len, rb->rbtype=code; trans->uas.status = code; + if(len<=0) { + LM_ERR("invalid new buffer len\n"); + goto error3; + } buf_len = rb->buffer ? len : len + REPLY_OVERBUFFER_LEN; rb->buffer = (char*)shm_resize( rb->buffer, buf_len ); /* puts the reply's buffer to uas.response */ if (! rb->buffer ) { - LM_ERR("cannot allocate shmem buffer\n"); - goto error3; + LM_ERR("cannot allocate shmem buffer\n"); + goto error3; } update_local_tags(trans, bm, rb->buffer, buf); @@ -1951,6 +1955,10 @@ enum rps relay_reply( struct cell *t, struct sip_msg *p_msg, int branch, * larger messages are likely to follow and we will be * able to reuse the memory frag */ + if (res_len<=0) { + LM_ERR("invalid new buffer len\n"); + goto error03; + } uas_rb->buffer = (char*)shm_resize( uas_rb->buffer, res_len + (msg_status<200 ? REPLY_OVERBUFFER_LEN : 0)); if (!uas_rb->buffer) { diff --git a/src/modules/tm/uac.c b/src/modules/tm/uac.c index 82e7f5edf..7062df8fd 100644 --- a/src/modules/tm/uac.c +++ b/src/modules/tm/uac.c @@ -505,7 +505,7 @@ static inline int t_uac_prepare(uac_req_t *uac_r, buf = build_uac_req(uac_r->method, uac_r->headers, uac_r->body, uac_r->dialog, 0, new_cell, &buf_len, &dst); - if (!buf) { + if (!buf || buf_len<=0) { LM_ERR("Error while building message\n"); ret=E_OUT_OF_MEM; goto error1; @@ -749,19 +749,23 @@ struct retr_buf *local_ack_rb(sip_msg_t *rpl_2xx, struct cell *trans, struct dest_info dst; buf_len = (unsigned)sizeof(struct retr_buf); - if (! (buffer = build_dlg_ack(rpl_2xx, trans, branch, hdrs, body, - &buf_len, &dst))) { + buffer = build_dlg_ack(rpl_2xx, trans, branch, hdrs, body, + &buf_len, &dst); + if (!buffer || buf_len<=0) { + if(buffer) { + shm_free(buffer); + } return 0; - } else { - /* 'buffer' now points into a contiguous chunk of memory with enough - * room to hold both the retr. buffer and the string raw buffer: it - * points to the begining of the string buffer; we iterate back to get - * the begining of the space for the retr. buffer. */ - lack = &((struct retr_buf *)buffer)[-1]; - lack->buffer = buffer; - lack->buffer_len = buf_len; - lack->dst = dst; } + /* 'buffer' now points into a contiguous chunk of memory with enough + * room to hold both the retr. buffer and the string raw buffer: it + * points to the begining of the string buffer; we iterate back to get + * the begining of the space for the retr. buffer. */ + lack = &((struct retr_buf *)buffer)[-1]; + lack->buffer = buffer; + lack->buffer_len = buf_len; + lack->dst = dst; + /* TODO: need next 2? */ lack->rbtype = TYPE_LOCAL_ACK; diff --git a/src/modules/tmrec/README b/src/modules/tmrec/README index bcb8380ee..7da2a2e38 100644 --- a/src/modules/tmrec/README +++ b/src/modules/tmrec/README @@ -10,14 +10,10 @@ Daniel-Constantin Mierla -Edited by - Alex Balashov -Edited by - Richard Fuchs diff --git a/src/modules/topos/tps_storage.c b/src/modules/topos/tps_storage.c index 83d81172d..3bae45ec1 100644 --- a/src/modules/topos/tps_storage.c +++ b/src/modules/topos/tps_storage.c @@ -355,8 +355,7 @@ int tps_storage_link_msg(sip_msg_t *msg, tps_data_t *td, int dir) } if(msg->first_line.type==SIP_REPLY) { if(msg->first_line.u.reply.statuscode>=100 - && msg->first_line.u.reply.statuscode<200 - && msg->first_line.u.reply.statuscode!=183) { + && msg->first_line.u.reply.statuscode<200) { /* provisional response with no mandatory contact header */ return 0; } diff --git a/src/modules/uac/README b/src/modules/uac/README index caeb998e9..a65774af8 100644 --- a/src/modules/uac/README +++ b/src/modules/uac/README @@ -420,7 +420,7 @@ modparam("uac","credential","username:domain:password") Example 1.9. Set auth_realm_avp parameter ... -modparam("uac","auth_realm_avp","$avp(i:10)") +modparam("uac","auth_realm_avp","$avp(arealm)") ... 3.10. auth_username_avp (string) @@ -434,7 +434,7 @@ modparam("uac","auth_realm_avp","$avp(i:10)") Example 1.10. Set auth_username_avp parameter ... -modparam("uac","auth_username_avp","$avp(i:11)") +modparam("uac","auth_username_avp","$avp(auser)") ... 3.11. auth_password_avp (string) @@ -448,7 +448,7 @@ modparam("uac","auth_username_avp","$avp(i:11)") Example 1.11. Set auth_password_avp parameter ... -modparam("uac","auth_password_avp","$avp(i:12)") +modparam("uac","auth_password_avp","$avp(apasswd)") ... 3.12. reg_db_url (string) diff --git a/src/modules/uac/doc/uac_admin.xml b/src/modules/uac/doc/uac_admin.xml index 8ddf26ca0..e84501a9d 100644 --- a/src/modules/uac/doc/uac_admin.xml +++ b/src/modules/uac/doc/uac_admin.xml @@ -334,7 +334,7 @@ modparam("uac","credential","username:domain:password") Set <varname>auth_realm_avp</varname> parameter ... -modparam("uac","auth_realm_avp","$avp(i:10)") +modparam("uac","auth_realm_avp","$avp(arealm)") ... @@ -356,7 +356,7 @@ modparam("uac","auth_realm_avp","$avp(i:10)") Set <varname>auth_username_avp</varname> parameter ... -modparam("uac","auth_username_avp","$avp(i:11)") +modparam("uac","auth_username_avp","$avp(auser)") ... @@ -378,7 +378,7 @@ modparam("uac","auth_username_avp","$avp(i:11)") Set <varname>auth_password_avp</varname> parameter ... -modparam("uac","auth_password_avp","$avp(i:12)") +modparam("uac","auth_password_avp","$avp(apasswd)") ... diff --git a/src/modules/uid_uri_db/uid_uri_db_mod.h b/src/modules/uid_uri_db/uid_uri_db_mod.h index e4848ecd9..aa72a2aa5 100644 --- a/src/modules/uid_uri_db/uid_uri_db_mod.h +++ b/src/modules/uid_uri_db/uid_uri_db_mod.h @@ -27,8 +27,8 @@ */ -#ifndef URIDB_MOD_H -#define URIDB_MOD_H +#ifndef _UID_URI_DB_MOD_H_ +#define _UID_URI_DB_MOD_H_ #include "../../lib/srdb2/db.h" #include "../../core/str.h" diff --git a/src/modules/uri_db/README b/src/modules/uri_db/README index 589fba5b0..a4a19a8c1 100644 --- a/src/modules/uri_db/README +++ b/src/modules/uri_db/README @@ -8,8 +8,6 @@ Edited by Jan Janak -Edited by - Bogdan-Andrei Iancu Copyright © 2003 FhG FOKUS diff --git a/src/modules/websocket/websocket.c b/src/modules/websocket/websocket.c index 87cf4e3a5..5cef5d6b1 100644 --- a/src/modules/websocket/websocket.c +++ b/src/modules/websocket/websocket.c @@ -210,8 +210,8 @@ static int mod_init(void) } if(ws_ping_application_data.len < 1 || ws_ping_application_data.len > 125) { - ws_ping_application_data.s = DEFAULT_PING_APPLICATION_DATA + 8; - ws_ping_application_data.len = DEFAULT_PING_APPLICATION_DATA_LEN - 8; + ws_ping_application_data.s = DEFAULT_PING_APPLICATION_DATA; + ws_ping_application_data.len = DEFAULT_PING_APPLICATION_DATA_LEN; } if(ws_keepalive_mechanism != KEEPALIVE_MECHANISM_NONE) { diff --git a/src/modules/websocket/ws_conn.c b/src/modules/websocket/ws_conn.c index a4442ae0d..8570afa08 100644 --- a/src/modules/websocket/ws_conn.c +++ b/src/modules/websocket/ws_conn.c @@ -184,14 +184,14 @@ void wsconn_destroy(void) } } -int wsconn_add(struct receive_info rcv, unsigned int sub_protocol) +int wsconn_add(struct receive_info *rcv, unsigned int sub_protocol) { int cur_cons, max_cons; - int id = rcv.proto_reserved1; + int id = rcv->proto_reserved1; int id_hash = tcp_id_hash(id); ws_connection_t *wsc; - LM_DBG("wsconn_add id [%d]\n", id); + LM_DBG("connection id [%d]\n", id); /* Allocate and fill in new WebSocket connection */ wsc = shm_malloc(sizeof(ws_connection_t) + BUF_SIZE + 1); @@ -203,13 +203,13 @@ int wsconn_add(struct receive_info rcv, unsigned int sub_protocol) wsc->id = id; wsc->id_hash = id_hash; wsc->state = WS_S_OPEN; - wsc->rcv = rcv; + wsc->rcv = *rcv; wsc->sub_protocol = sub_protocol; wsc->run_event = 0; wsc->frag_buf.s = ((char *)wsc) + sizeof(ws_connection_t); atomic_set(&wsc->refcnt, 0); - LM_DBG("wsconn_add new wsc => [%p], ref => [%d]\n", wsc, + LM_DBG("new wsc => [%p], ref => [%d]\n", wsc, atomic_get(&wsc->refcnt)); WSCONN_LOCK; @@ -229,7 +229,7 @@ int wsconn_add(struct receive_info rcv, unsigned int sub_protocol) WSCONN_UNLOCK; - LM_DBG("wsconn_add added to conn_table wsc => [%p], ref => [%d]\n", wsc, + LM_DBG("added to conn_table wsc => [%p], ref => [%d]\n", wsc, atomic_get(&wsc->refcnt)); /* Update connection statistics */ diff --git a/src/modules/websocket/ws_conn.h b/src/modules/websocket/ws_conn.h index 9319238e4..f8aa93543 100644 --- a/src/modules/websocket/ws_conn.h +++ b/src/modules/websocket/ws_conn.h @@ -95,7 +95,7 @@ extern stat_var *ws_msrp_max_concurrent_connections; int wsconn_init(void); void wsconn_destroy(void); -int wsconn_add(struct receive_info rcv, unsigned int sub_protocol); +int wsconn_add(struct receive_info *rcv, unsigned int sub_protocol); int wsconn_rm(ws_connection_t *wsc, ws_conn_eventroute_t run_event_route); int wsconn_update(ws_connection_t *wsc); void wsconn_close_now(ws_connection_t *wsc); diff --git a/src/modules/websocket/ws_frame.h b/src/modules/websocket/ws_frame.h index d0f8d84ed..51a62e04c 100644 --- a/src/modules/websocket/ws_frame.h +++ b/src/modules/websocket/ws_frame.h @@ -49,8 +49,8 @@ extern int ws_keepalive_mechanism; #define DEFAULT_KEEPALIVE_TIMEOUT 180 /* seconds */ extern str ws_ping_application_data; -#define DEFAULT_PING_APPLICATION_DATA SERVER_HDR -#define DEFAULT_PING_APPLICATION_DATA_LEN SERVER_HDR_LEN +#define DEFAULT_PING_APPLICATION_DATA SRVAPP_SIGNATURE +#define DEFAULT_PING_APPLICATION_DATA_LEN SRVAPP_SIGNATURE_LEN extern stat_var *ws_failed_connections; extern stat_var *ws_local_closed_connections; diff --git a/src/modules/websocket/ws_handshake.c b/src/modules/websocket/ws_handshake.c index 58e6077bb..878c483f2 100644 --- a/src/modules/websocket/ws_handshake.c +++ b/src/modules/websocket/ws_handshake.c @@ -310,7 +310,7 @@ int ws_handle_handshake(struct sip_msg *msg) (unsigned char *)reply_key.s, base64_enc_len(SHA_DIGEST_LENGTH)); /* Add the connection to the WebSocket connection table */ - wsconn_add(msg->rcv, sub_protocol); + wsconn_add(&msg->rcv, sub_protocol); /* Make sure Kamailio core sends future messages on this connection directly to this module */ diff --git a/src/modules/xcap_server/Makefile b/src/modules/xcap_server/Makefile index d5684bdd9..24c31528a 100644 --- a/src/modules/xcap_server/Makefile +++ b/src/modules/xcap_server/Makefile @@ -10,6 +10,12 @@ NAME=xcap_server.so ifeq ($(CROSS_COMPILE),) XML2CFG=$(shell which xml2-config) +ifeq ($(XML2CFG),) +XML2CFG=$(shell \ + if pkg-config --exists libxml-2.0; then \ + echo 'pkg-config libxml-2.0'; \ + fi) +endif endif ifneq ($(XML2CFG),) diff --git a/src/modules/xhttp/README b/src/modules/xhttp/README index babbed954..a38599775 100644 --- a/src/modules/xhttp/README +++ b/src/modules/xhttp/README @@ -10,8 +10,6 @@ Daniel-Constantin Mierla -Edited by - Alex Balashov diff --git a/src/modules/xhttp_pi/Makefile b/src/modules/xhttp_pi/Makefile index 1b092231a..fb66a2b1f 100644 --- a/src/modules/xhttp_pi/Makefile +++ b/src/modules/xhttp_pi/Makefile @@ -9,6 +9,12 @@ LIBS += ifeq ($(CROSS_COMPILE),) XML2CFG=$(shell which xml2-config) +ifeq ($(XML2CFG),) +XML2CFG=$(shell \ + if pkg-config --exists libxml-2.0; then \ + echo 'pkg-config libxml-2.0'; \ + fi) +endif endif ifneq ($(XML2CFG),) diff --git a/src/modules/xhttp_prom/README b/src/modules/xhttp_prom/README index df07cbff4..a6c2e9586 100644 --- a/src/modules/xhttp_prom/README +++ b/src/modules/xhttp_prom/README @@ -14,7 +14,7 @@ Javier Gallart - Copyright 2019 www.sonoc.io + Copyright © 2019 www.sonoc.io __________________________________________________________________ Table of Contents @@ -296,7 +296,7 @@ modparam("xhttp_prom", "prom_gauge", "name=gg_third; label=method:handler;"); 4.5. prom_dispatch() 4.6. prom_check_uri() -4.1. prom_counter_reset(name, l0, l1, l2) +4.1. prom_counter_reset(name, l0, l1, l2) Get a counter based on its name and labels and reset its value to 0. Name parameter is mandatory. Values of labels are optional (from none @@ -325,7 +325,7 @@ prom_counter_reset("cnt01", "push", "192.168.0.1"); kamailio_cnt01 {method="push", IP="192.168.0.1"} 0 1234567890 ... -4.2. prom_gauge_reset(name, l0, l1, l2) +4.2. prom_gauge_reset(name, l0, l1, l2) Get a gauge based on its name and labels and reset its value to 0. Name parameter is mandatory. Values of labels are optional (from none up to @@ -352,7 +352,7 @@ prom_gauge_reset("cnt01", "push", "192.168.0.1"); kamailio_cnt01 {method="push", IP="192.168.0.1"} 0 1234567890 ... -4.3. prom_counter_inc(name, number, l0, l1, l2) +4.3. prom_counter_inc(name, number, l0, l1, l2) Get a counter identified by its name and labels and increase its value by a number. If counter does not exist it creates the counter, @@ -389,7 +389,7 @@ prom_counter_inc("cnt02", "15", "push", "192.168.0.1"); kamailio_cnt02 {method="push", IP="192.168.0.1"} 15 1234567890 ... -4.4. prom_gauge_set(name, number, l0, l1, l2) +4.4. prom_gauge_set(name, number, l0, l1, l2) Get a gauge identified by its name and labels and set its value to a number. If gauge does not exist it creates the gauge and assigns the @@ -426,7 +426,7 @@ prom_gauge_set("gg02", "2.8", "push", "192.168.0.1"); kamailio_gg02 {method="push", IP="192.168.0.1"} 2.8 1234567890 ... -4.5. prom_dispatch() +4.5. prom_dispatch() Handle the HTTP request and generate a response. @@ -526,7 +526,7 @@ kamailio_sl_sent_replies 15 1554839325427 kamailio_sl_xxx_replies 0 1554839325461 ... -4.6. prom_check_uri() +4.6. prom_check_uri() Check if path of HTTP URL equals /metrics. This avoids us to check hu variable from xHTTP module. diff --git a/src/modules/xmlops/Makefile b/src/modules/xmlops/Makefile index d31550301..1ac953920 100644 --- a/src/modules/xmlops/Makefile +++ b/src/modules/xmlops/Makefile @@ -9,20 +9,22 @@ NAME=xmlops.so LIBS= ifeq ($(CROSS_COMPILE),) -XML2CFG=$(shell which xml2-config) +PKGCFGTOOL=$(shell which xml2-config) +ifeq ($(PKGCFGTOOL),) +PKGCFGTOOL=$(shell \ + if pkg-config --exists libxml-2.0; then \ + echo 'pkg-config libxml-2.0'; \ + fi) +endif endif -ifneq ($(XML2CFG),) - - DEFS += $(shell $(XML2CFG) --cflags ) - LIBS += $(shell $(XML2CFG) --libs) - +ifneq ($(PKGCFGTOOL),) + DEFS += $(shell $(PKGCFGTOOL) --cflags ) + LIBS += $(shell $(PKGCFGTOOL) --libs) else - DEFS+=-I$(LOCALBASE)/include/libxml2 \ -I$(LOCALBASE)/include LIBS+=-L$(LOCALBASE)/lib -lxml2 - endif include ../../Makefile.modules diff --git a/src/modules/xmlrpc/Makefile b/src/modules/xmlrpc/Makefile index 358ab06b0..4573a815b 100644 --- a/src/modules/xmlrpc/Makefile +++ b/src/modules/xmlrpc/Makefile @@ -7,6 +7,12 @@ NAME=xmlrpc.so ifeq ($(CROSS_COMPILE),) XML2CFG=$(shell which xml2-config) +ifeq ($(XML2CFG),) +XML2CFG=$(shell \ + if pkg-config --exists libxml-2.0; then \ + echo 'pkg-config libxml-2.0'; \ + fi) +endif endif ifneq ($(XML2CFG),) diff --git a/utils/kamctl/db_berkeley/kamailio/matrix b/utils/kamctl/db_berkeley/kamailio/matrix index a2e07b3e0..3c06f2ec6 100644 --- a/utils/kamctl/db_berkeley/kamailio/matrix +++ b/utils/kamctl/db_berkeley/kamailio/matrix @@ -1,5 +1,5 @@ METADATA_COLUMNS -first(int) second(int) res(int) +id(int) first(int) second(int) res(int) METADATA_KEY METADATA_READONLY @@ -7,4 +7,4 @@ METADATA_READONLY METADATA_LOGFLAGS 0 METADATA_DEFAULTS -NIL|NIL|NIL +NIL|NIL|NIL|NIL diff --git a/utils/kamctl/db_berkeley/kamailio/secfilter b/utils/kamctl/db_berkeley/kamailio/secfilter index 38fbb9a05..b264e5b0a 100644 --- a/utils/kamctl/db_berkeley/kamailio/secfilter +++ b/utils/kamctl/db_berkeley/kamailio/secfilter @@ -7,4 +7,4 @@ METADATA_READONLY METADATA_LOGFLAGS 0 METADATA_DEFAULTS -NIL|''|''|'' +NIL|0|0|'' diff --git a/utils/kamctl/db_berkeley/kamailio/version b/utils/kamctl/db_berkeley/kamailio/version index 0dcb086f7..a7f5beeae 100644 --- a/utils/kamctl/db_berkeley/kamailio/version +++ b/utils/kamctl/db_berkeley/kamailio/version @@ -64,8 +64,6 @@ imc_members| imc_members|1 imc_rooms| imc_rooms|1 -METADATA_DEFAULTS -NIL|NIL|''|NIL|NIL|NULL|NULL|NULL|NULL|'2030-05-28 21:32:15'|1.0|'Default-Call-ID'|1|'2000-01-01 00:00:01'|0|0|''|NULL|NULL|NULL lcr_gw| lcr_gw|3 lcr_rule| diff --git a/utils/kamctl/db_redis/kamailio/matrix b/utils/kamctl/db_redis/kamailio/matrix index ddf335d53..46a702c70 100644 --- a/utils/kamctl/db_redis/kamailio/matrix +++ b/utils/kamctl/db_redis/kamailio/matrix @@ -1,2 +1,2 @@ -first/int,second/int,res/int, +id/int,first/int,second/int,res/int, 1 diff --git a/utils/kamctl/db_sqlite/matrix-create.sql b/utils/kamctl/db_sqlite/matrix-create.sql index 8f3f762ff..a6ab28a8c 100644 --- a/utils/kamctl/db_sqlite/matrix-create.sql +++ b/utils/kamctl/db_sqlite/matrix-create.sql @@ -1,4 +1,5 @@ CREATE TABLE matrix ( + id INTEGER PRIMARY KEY NOT NULL, first INTEGER NOT NULL, second SMALLINT NOT NULL, res INTEGER NOT NULL diff --git a/utils/kamctl/db_sqlite/secfilter-create.sql b/utils/kamctl/db_sqlite/secfilter-create.sql index 476ea46de..44e1f4e4c 100644 --- a/utils/kamctl/db_sqlite/secfilter-create.sql +++ b/utils/kamctl/db_sqlite/secfilter-create.sql @@ -1,7 +1,7 @@ CREATE TABLE secfilter ( id INTEGER PRIMARY KEY NOT NULL, - action SMALLINT DEFAULT '' NOT NULL, - type SMALLINT DEFAULT '' NOT NULL, + action SMALLINT DEFAULT 0 NOT NULL, + type SMALLINT DEFAULT 0 NOT NULL, data VARCHAR(64) DEFAULT '' NOT NULL ); diff --git a/utils/kamctl/dbtext/kamailio/matrix b/utils/kamctl/dbtext/kamailio/matrix index 5f86e1032..a791f2ce1 100644 --- a/utils/kamctl/dbtext/kamailio/matrix +++ b/utils/kamctl/dbtext/kamailio/matrix @@ -1 +1 @@ -first(int) second(int) res(int) +id(int,auto) first(int) second(int) res(int) diff --git a/utils/kamctl/mongodb/kamailio/matrix.json b/utils/kamctl/mongodb/kamailio/matrix.json index dfd33421d..92ec356b3 100644 --- a/utils/kamctl/mongodb/kamailio/matrix.json +++ b/utils/kamctl/mongodb/kamailio/matrix.json @@ -2,6 +2,11 @@ "name": "matrix", "version": 1, "columns": [ + "id": { + "type": "int", + "default": null, + "null": false + }, "first": { "type": "int", "default": null, diff --git a/utils/kamctl/mongodb/kamailio/secfilter.json b/utils/kamctl/mongodb/kamailio/secfilter.json index 1f7baf47f..7c433e929 100644 --- a/utils/kamctl/mongodb/kamailio/secfilter.json +++ b/utils/kamctl/mongodb/kamailio/secfilter.json @@ -9,12 +9,12 @@ }, "action": { "type": "int", - "default": "", + "default": 0, "null": false }, "type": { "type": "int", - "default": "", + "default": 0, "null": false }, "data": { diff --git a/utils/kamctl/mysql/matrix-create.sql b/utils/kamctl/mysql/matrix-create.sql index f0a50c86e..2b2751bf0 100644 --- a/utils/kamctl/mysql/matrix-create.sql +++ b/utils/kamctl/mysql/matrix-create.sql @@ -1,4 +1,5 @@ CREATE TABLE `matrix` ( + `id` INT(10) UNSIGNED AUTO_INCREMENT PRIMARY KEY NOT NULL, `first` INT(10) NOT NULL, `second` SMALLINT(10) NOT NULL, `res` INT(10) NOT NULL diff --git a/utils/kamctl/mysql/secfilter-create.sql b/utils/kamctl/mysql/secfilter-create.sql index 18a67c79b..9b35b8d57 100644 --- a/utils/kamctl/mysql/secfilter-create.sql +++ b/utils/kamctl/mysql/secfilter-create.sql @@ -1,7 +1,7 @@ CREATE TABLE `secfilter` ( `id` INT(10) UNSIGNED AUTO_INCREMENT PRIMARY KEY NOT NULL, - `action` SMALLINT DEFAULT '' NOT NULL, - `type` SMALLINT DEFAULT '' NOT NULL, + `action` SMALLINT DEFAULT 0 NOT NULL, + `type` SMALLINT DEFAULT 0 NOT NULL, `data` VARCHAR(64) DEFAULT '' NOT NULL ); diff --git a/utils/kamctl/oracle/matrix-create.sql b/utils/kamctl/oracle/matrix-create.sql index 95fc7bd86..165b05d35 100644 --- a/utils/kamctl/oracle/matrix-create.sql +++ b/utils/kamctl/oracle/matrix-create.sql @@ -1,4 +1,5 @@ CREATE TABLE matrix ( + id NUMBER(10) PRIMARY KEY, first NUMBER(10), second NUMBER(5), res NUMBER(10) diff --git a/utils/kamctl/oracle/secfilter-create.sql b/utils/kamctl/oracle/secfilter-create.sql index 684d1c44c..d98091552 100644 --- a/utils/kamctl/oracle/secfilter-create.sql +++ b/utils/kamctl/oracle/secfilter-create.sql @@ -1,7 +1,7 @@ CREATE TABLE secfilter ( id NUMBER(10) PRIMARY KEY, - action NUMBER(5) DEFAULT '', - type NUMBER(5) DEFAULT '', + action NUMBER(5) DEFAULT 0 NOT NULL, + type NUMBER(5) DEFAULT 0 NOT NULL, data VARCHAR2(64) DEFAULT '' ); diff --git a/utils/kamctl/postgres/matrix-create.sql b/utils/kamctl/postgres/matrix-create.sql index 8f3f762ff..c5cac48fb 100644 --- a/utils/kamctl/postgres/matrix-create.sql +++ b/utils/kamctl/postgres/matrix-create.sql @@ -1,4 +1,5 @@ CREATE TABLE matrix ( + id SERIAL PRIMARY KEY NOT NULL, first INTEGER NOT NULL, second SMALLINT NOT NULL, res INTEGER NOT NULL diff --git a/utils/kamctl/postgres/secfilter-create.sql b/utils/kamctl/postgres/secfilter-create.sql index 71badd4ec..ce048396f 100644 --- a/utils/kamctl/postgres/secfilter-create.sql +++ b/utils/kamctl/postgres/secfilter-create.sql @@ -1,7 +1,7 @@ CREATE TABLE secfilter ( id SERIAL PRIMARY KEY NOT NULL, - action SMALLINT DEFAULT '' NOT NULL, - type SMALLINT DEFAULT '' NOT NULL, + action SMALLINT DEFAULT 0 NOT NULL, + type SMALLINT DEFAULT 0 NOT NULL, data VARCHAR(64) DEFAULT '' NOT NULL ); diff --git a/utils/kamctl/xhttp_pi/matrix-mod b/utils/kamctl/xhttp_pi/matrix-mod index ee1a48ca6..808f3d861 100644 --- a/utils/kamctl/xhttp_pi/matrix-mod +++ b/utils/kamctl/xhttp_pi/matrix-mod @@ -4,6 +4,7 @@ matrix DB1_QUERY +
idupdatefirstsecondres @@ -18,4 +19,23 @@ res + update + matrix + DB1_UPDATE + + id= + + + first + second + res + + + delete + matrix + DB1_DELETE + + id= + + diff --git a/utils/kamctl/xhttp_pi/matrix-table b/utils/kamctl/xhttp_pi/matrix-table index 9d6d789d3..c87ae8f3c 100644 --- a/utils/kamctl/xhttp_pi/matrix-table +++ b/utils/kamctl/xhttp_pi/matrix-table @@ -2,6 +2,7 @@ matrix mysql + idDB1_INT firstDB1_INT secondDB1_INT resDB1_INT diff --git a/utils/kamctl/xhttp_pi/pi_framework.xml b/utils/kamctl/xhttp_pi/pi_framework.xml index 110feb200..1996f55a3 100644 --- a/utils/kamctl/xhttp_pi/pi_framework.xml +++ b/utils/kamctl/xhttp_pi/pi_framework.xml @@ -219,17 +219,6 @@ attrsDB1_STR descriptionDB1_STR - - - domainpolicy - mysql - idDB1_INT - ruleDB1_STR - typeDB1_STR - attDB1_STR - valDB1_STR - descriptionDB1_STR - domain @@ -250,6 +239,17 @@ valueDB1_STR last_modifiedDB1_DATETIME + + + domainpolicy + mysql + idDB1_INT + ruleDB1_STR + typeDB1_STR + attDB1_STR + valDB1_STR + descriptionDB1_STR + dr_gateways @@ -388,6 +388,7 @@ matrix mysql + idDB1_INT firstDB1_INT secondDB1_INT resDB1_INT @@ -2519,6 +2520,7 @@ matrix DB1_QUERY + idupdatefirstsecondres @@ -2533,6 +2535,25 @@ res + update + matrix + DB1_UPDATE + + id= + + + first + second + res + + + delete + matrix + DB1_DELETE + + id= + + mohqcalls