From fac22fad6c018807799a4849934a67229c28a27a Mon Sep 17 00:00:00 2001 From: "raveit65 (via Travis CI)" Date: Thu, 22 Feb 2024 18:58:56 +0000 Subject: Deploy mate-desktop/mate-user-share to github.com/mate-desktop/mate-user-share.git:gh-pages --- .../0.html | 1482 ++++++++++++++++++ .../1.html | 1038 +++++++++++++ .../2.html | 1272 ++++++++++++++++ .../3.html | 748 ++++++++++ .../4.html | 336 +++++ .../5.html | 1166 +++++++++++++++ .../index.html | 130 ++ .../stats.html | 99 ++ .../style.css | 149 ++ .../0.html | 1482 ++++++++++++++++++ .../1.html | 1038 +++++++++++++ .../2.html | 1272 ++++++++++++++++ .../3.html | 748 ++++++++++ .../4.html | 336 +++++ .../5.html | 1166 +++++++++++++++ .../index.html | 130 ++ .../stats.html | 99 ++ .../style.css | 149 ++ .../0.html | 1482 ++++++++++++++++++ .../1.html | 1038 +++++++++++++ .../2.html | 1272 ++++++++++++++++ .../3.html | 748 ++++++++++ .../4.html | 336 +++++ .../5.html | 1166 +++++++++++++++ .../index.html | 130 ++ .../stats.html | 99 ++ .../style.css | 149 ++ .../0.html | 1498 +++++++++++++++++++ .../1.html | 1054 +++++++++++++ .../2.html | 1288 ++++++++++++++++ .../3.html | 764 ++++++++++ .../4.html | 1182 +++++++++++++++ .../index.html | 143 ++ .../stats.html | 112 ++ .../style.css | 137 ++ .../0.html | 1498 +++++++++++++++++++ .../1.html | 1054 +++++++++++++ .../2.html | 1288 ++++++++++++++++ .../3.html | 764 ++++++++++ .../4.html | 1182 +++++++++++++++ .../index.html | 143 ++ .../stats.html | 112 ++ .../style.css | 137 ++ .../0.html | 1498 +++++++++++++++++++ .../1.html | 1054 +++++++++++++ .../2.html | 1288 ++++++++++++++++ .../3.html | 764 ++++++++++ .../4.html | 1182 +++++++++++++++ .../index.html | 141 ++ .../stats.html | 109 ++ .../style.css | 137 ++ .../0.html | 1498 +++++++++++++++++++ .../1.html | 1054 +++++++++++++ .../2.html | 1288 ++++++++++++++++ .../3.html | 764 ++++++++++ .../4.html | 1182 +++++++++++++++ .../index.html | 141 ++ .../stats.html | 109 ++ .../style.css | 137 ++ .../0.html | 1498 +++++++++++++++++++ .../1.html | 1054 +++++++++++++ .../2.html | 1288 ++++++++++++++++ .../3.html | 764 ++++++++++ .../4.html | 1182 +++++++++++++++ .../index.html | 141 ++ .../stats.html | 109 ++ .../style.css | 137 ++ .../0.html | 1498 +++++++++++++++++++ .../1.html | 1054 +++++++++++++ .../2.html | 1288 ++++++++++++++++ .../3.html | 764 ++++++++++ .../4.html | 1182 +++++++++++++++ .../index.html | 141 ++ .../stats.html | 109 ++ .../style.css | 137 ++ .../0.html | 1503 +++++++++++++++++++ .../1.html | 1059 +++++++++++++ .../2.html | 1293 ++++++++++++++++ .../3.html | 769 ++++++++++ .../4.html | 1187 +++++++++++++++ .../index.html | 141 ++ .../stats.html | 109 ++ .../style.css | 137 ++ .../0.html | 1505 +++++++++++++++++++ .../1.html | 1061 +++++++++++++ .../2.html | 1295 ++++++++++++++++ .../3.html | 771 ++++++++++ .../4.html | 1189 +++++++++++++++ .../index.html | 141 ++ .../stats.html | 109 ++ .../style.css | 137 ++ .../0.html | 1505 +++++++++++++++++++ .../1.html | 1061 +++++++++++++ .../2.html | 1295 ++++++++++++++++ .../3.html | 771 ++++++++++ .../4.html | 1189 +++++++++++++++ .../index.html | 141 ++ .../stats.html | 109 ++ .../style.css | 137 ++ .../0.html | 1505 +++++++++++++++++++ .../1.html | 1061 +++++++++++++ .../2.html | 1295 ++++++++++++++++ .../3.html | 771 ++++++++++ .../4.html | 1189 +++++++++++++++ .../index.html | 143 ++ .../stats.html | 109 ++ .../style.css | 137 ++ .../0.html | 1567 ++++++++++++++++++++ .../1.html | 1123 ++++++++++++++ .../2.html | 833 +++++++++++ .../3.html | 1251 ++++++++++++++++ .../index.html | 212 +++ .../stats.html | 170 +++ .../style.css | 177 +++ .../0.html | 1567 ++++++++++++++++++++ .../1.html | 1123 ++++++++++++++ .../2.html | 833 +++++++++++ .../3.html | 1251 ++++++++++++++++ .../index.html | 212 +++ .../stats.html | 170 +++ .../style.css | 177 +++ .../0.html | 1567 ++++++++++++++++++++ .../1.html | 1123 ++++++++++++++ .../2.html | 833 +++++++++++ .../3.html | 1251 ++++++++++++++++ .../index.html | 212 +++ .../stats.html | 170 +++ .../style.css | 177 +++ .../0.html | 1567 ++++++++++++++++++++ .../1.html | 1123 ++++++++++++++ .../2.html | 833 +++++++++++ .../3.html | 1251 ++++++++++++++++ .../index.html | 212 +++ .../stats.html | 170 +++ .../style.css | 177 +++ .../0.html | 501 +++++++ .../1.html | 1567 ++++++++++++++++++++ .../2.html | 1123 ++++++++++++++ .../3.html | 1357 +++++++++++++++++ .../4.html | 833 +++++++++++ .../5.html | 1251 ++++++++++++++++ .../index.html | 231 +++ .../stats.html | 174 +++ .../style.css | 177 +++ .../0.html | 501 +++++++ .../1.html | 1567 ++++++++++++++++++++ .../2.html | 1123 ++++++++++++++ .../3.html | 1357 +++++++++++++++++ .../4.html | 833 +++++++++++ .../5.html | 1251 ++++++++++++++++ .../index.html | 231 +++ .../stats.html | 174 +++ .../style.css | 177 +++ .../0.html | 501 +++++++ .../1.html | 365 +++++ .../10.html | 303 ++++ .../11.html | 833 +++++++++++ .../12.html | 421 ++++++ .../13.html | 443 ++++++ .../14.html | 1251 ++++++++++++++++ .../2.html | 1567 ++++++++++++++++++++ .../3.html | 1123 ++++++++++++++ .../4.html | 299 ++++ .../5.html | 413 ++++++ .../6.html | 567 +++++++ .../7.html | 297 ++++ .../8.html | 1357 +++++++++++++++++ .../9.html | 279 ++++ .../index.html | 325 ++++ .../stats.html | 186 +++ .../style.css | 177 +++ CNAME | 1 + index.html | 47 + 173 files changed, 127647 insertions(+) create mode 100644 2020-06-12-004111-9546-cppcheck@0ac8ecb990d2_master/0.html create mode 100644 2020-06-12-004111-9546-cppcheck@0ac8ecb990d2_master/1.html create mode 100644 2020-06-12-004111-9546-cppcheck@0ac8ecb990d2_master/2.html create mode 100644 2020-06-12-004111-9546-cppcheck@0ac8ecb990d2_master/3.html create mode 100644 2020-06-12-004111-9546-cppcheck@0ac8ecb990d2_master/4.html create mode 100644 2020-06-12-004111-9546-cppcheck@0ac8ecb990d2_master/5.html create mode 100644 2020-06-12-004111-9546-cppcheck@0ac8ecb990d2_master/index.html create mode 100644 2020-06-12-004111-9546-cppcheck@0ac8ecb990d2_master/stats.html create mode 100644 2020-06-12-004111-9546-cppcheck@0ac8ecb990d2_master/style.css create mode 100644 2020-06-22-164518-5655-cppcheck@b751b682733f_travis-ci/0.html create mode 100644 2020-06-22-164518-5655-cppcheck@b751b682733f_travis-ci/1.html create mode 100644 2020-06-22-164518-5655-cppcheck@b751b682733f_travis-ci/2.html create mode 100644 2020-06-22-164518-5655-cppcheck@b751b682733f_travis-ci/3.html create mode 100644 2020-06-22-164518-5655-cppcheck@b751b682733f_travis-ci/4.html create mode 100644 2020-06-22-164518-5655-cppcheck@b751b682733f_travis-ci/5.html create mode 100644 2020-06-22-164518-5655-cppcheck@b751b682733f_travis-ci/index.html create mode 100644 2020-06-22-164518-5655-cppcheck@b751b682733f_travis-ci/stats.html create mode 100644 2020-06-22-164518-5655-cppcheck@b751b682733f_travis-ci/style.css create mode 100644 2020-06-28-102155-0593-cppcheck@ceeb6e4bfa08_master/0.html create mode 100644 2020-06-28-102155-0593-cppcheck@ceeb6e4bfa08_master/1.html create mode 100644 2020-06-28-102155-0593-cppcheck@ceeb6e4bfa08_master/2.html create mode 100644 2020-06-28-102155-0593-cppcheck@ceeb6e4bfa08_master/3.html create mode 100644 2020-06-28-102155-0593-cppcheck@ceeb6e4bfa08_master/4.html create mode 100644 2020-06-28-102155-0593-cppcheck@ceeb6e4bfa08_master/5.html create mode 100644 2020-06-28-102155-0593-cppcheck@ceeb6e4bfa08_master/index.html create mode 100644 2020-06-28-102155-0593-cppcheck@ceeb6e4bfa08_master/stats.html create mode 100644 2020-06-28-102155-0593-cppcheck@ceeb6e4bfa08_master/style.css create mode 100644 2020-07-31-224753-9107-cppcheck@3fd04c35acf7_master/0.html create mode 100644 2020-07-31-224753-9107-cppcheck@3fd04c35acf7_master/1.html create mode 100644 2020-07-31-224753-9107-cppcheck@3fd04c35acf7_master/2.html create mode 100644 2020-07-31-224753-9107-cppcheck@3fd04c35acf7_master/3.html create mode 100644 2020-07-31-224753-9107-cppcheck@3fd04c35acf7_master/4.html create mode 100644 2020-07-31-224753-9107-cppcheck@3fd04c35acf7_master/index.html create mode 100644 2020-07-31-224753-9107-cppcheck@3fd04c35acf7_master/stats.html create mode 100644 2020-07-31-224753-9107-cppcheck@3fd04c35acf7_master/style.css create mode 100644 2020-12-09-195411-4024-cppcheck@258a71f02483_master/0.html create mode 100644 2020-12-09-195411-4024-cppcheck@258a71f02483_master/1.html create mode 100644 2020-12-09-195411-4024-cppcheck@258a71f02483_master/2.html create mode 100644 2020-12-09-195411-4024-cppcheck@258a71f02483_master/3.html create mode 100644 2020-12-09-195411-4024-cppcheck@258a71f02483_master/4.html create mode 100644 2020-12-09-195411-4024-cppcheck@258a71f02483_master/index.html create mode 100644 2020-12-09-195411-4024-cppcheck@258a71f02483_master/stats.html create mode 100644 2020-12-09-195411-4024-cppcheck@258a71f02483_master/style.css create mode 100644 2021-02-23-075223-9463-cppcheck@8c6c291142e4_master/0.html create mode 100644 2021-02-23-075223-9463-cppcheck@8c6c291142e4_master/1.html create mode 100644 2021-02-23-075223-9463-cppcheck@8c6c291142e4_master/2.html create mode 100644 2021-02-23-075223-9463-cppcheck@8c6c291142e4_master/3.html create mode 100644 2021-02-23-075223-9463-cppcheck@8c6c291142e4_master/4.html create mode 100644 2021-02-23-075223-9463-cppcheck@8c6c291142e4_master/index.html create mode 100644 2021-02-23-075223-9463-cppcheck@8c6c291142e4_master/stats.html create mode 100644 2021-02-23-075223-9463-cppcheck@8c6c291142e4_master/style.css create mode 100644 2021-03-09-235935-8562-cppcheck@52bc759bdcfd_master/0.html create mode 100644 2021-03-09-235935-8562-cppcheck@52bc759bdcfd_master/1.html create mode 100644 2021-03-09-235935-8562-cppcheck@52bc759bdcfd_master/2.html create mode 100644 2021-03-09-235935-8562-cppcheck@52bc759bdcfd_master/3.html create mode 100644 2021-03-09-235935-8562-cppcheck@52bc759bdcfd_master/4.html create mode 100644 2021-03-09-235935-8562-cppcheck@52bc759bdcfd_master/index.html create mode 100644 2021-03-09-235935-8562-cppcheck@52bc759bdcfd_master/stats.html create mode 100644 2021-03-09-235935-8562-cppcheck@52bc759bdcfd_master/style.css create mode 100644 2021-03-27-160708-9454-cppcheck@bc0bdef34681_master/0.html create mode 100644 2021-03-27-160708-9454-cppcheck@bc0bdef34681_master/1.html create mode 100644 2021-03-27-160708-9454-cppcheck@bc0bdef34681_master/2.html create mode 100644 2021-03-27-160708-9454-cppcheck@bc0bdef34681_master/3.html create mode 100644 2021-03-27-160708-9454-cppcheck@bc0bdef34681_master/4.html create mode 100644 2021-03-27-160708-9454-cppcheck@bc0bdef34681_master/index.html create mode 100644 2021-03-27-160708-9454-cppcheck@bc0bdef34681_master/stats.html create mode 100644 2021-03-27-160708-9454-cppcheck@bc0bdef34681_master/style.css create mode 100644 2021-04-25-143339-9886-cppcheck@cf2a18e177f2_master/0.html create mode 100644 2021-04-25-143339-9886-cppcheck@cf2a18e177f2_master/1.html create mode 100644 2021-04-25-143339-9886-cppcheck@cf2a18e177f2_master/2.html create mode 100644 2021-04-25-143339-9886-cppcheck@cf2a18e177f2_master/3.html create mode 100644 2021-04-25-143339-9886-cppcheck@cf2a18e177f2_master/4.html create mode 100644 2021-04-25-143339-9886-cppcheck@cf2a18e177f2_master/index.html create mode 100644 2021-04-25-143339-9886-cppcheck@cf2a18e177f2_master/stats.html create mode 100644 2021-04-25-143339-9886-cppcheck@cf2a18e177f2_master/style.css create mode 100644 2021-05-30-164325-0736-cppcheck@58f05a4efe60_master/0.html create mode 100644 2021-05-30-164325-0736-cppcheck@58f05a4efe60_master/1.html create mode 100644 2021-05-30-164325-0736-cppcheck@58f05a4efe60_master/2.html create mode 100644 2021-05-30-164325-0736-cppcheck@58f05a4efe60_master/3.html create mode 100644 2021-05-30-164325-0736-cppcheck@58f05a4efe60_master/4.html create mode 100644 2021-05-30-164325-0736-cppcheck@58f05a4efe60_master/index.html create mode 100644 2021-05-30-164325-0736-cppcheck@58f05a4efe60_master/stats.html create mode 100644 2021-05-30-164325-0736-cppcheck@58f05a4efe60_master/style.css create mode 100644 2021-06-25-153248-0614-cppcheck@198f334ccf4c_master/0.html create mode 100644 2021-06-25-153248-0614-cppcheck@198f334ccf4c_master/1.html create mode 100644 2021-06-25-153248-0614-cppcheck@198f334ccf4c_master/2.html create mode 100644 2021-06-25-153248-0614-cppcheck@198f334ccf4c_master/3.html create mode 100644 2021-06-25-153248-0614-cppcheck@198f334ccf4c_master/4.html create mode 100644 2021-06-25-153248-0614-cppcheck@198f334ccf4c_master/index.html create mode 100644 2021-06-25-153248-0614-cppcheck@198f334ccf4c_master/stats.html create mode 100644 2021-06-25-153248-0614-cppcheck@198f334ccf4c_master/style.css create mode 100644 2021-08-05-192303-3702-cppcheck@c6718ce23130_master/0.html create mode 100644 2021-08-05-192303-3702-cppcheck@c6718ce23130_master/1.html create mode 100644 2021-08-05-192303-3702-cppcheck@c6718ce23130_master/2.html create mode 100644 2021-08-05-192303-3702-cppcheck@c6718ce23130_master/3.html create mode 100644 2021-08-05-192303-3702-cppcheck@c6718ce23130_master/4.html create mode 100644 2021-08-05-192303-3702-cppcheck@c6718ce23130_master/index.html create mode 100644 2021-08-05-192303-3702-cppcheck@c6718ce23130_master/stats.html create mode 100644 2021-08-05-192303-3702-cppcheck@c6718ce23130_master/style.css create mode 100644 2022-02-13-194124-4467-cppcheck@b215c4400bb6_master/0.html create mode 100644 2022-02-13-194124-4467-cppcheck@b215c4400bb6_master/1.html create mode 100644 2022-02-13-194124-4467-cppcheck@b215c4400bb6_master/2.html create mode 100644 2022-02-13-194124-4467-cppcheck@b215c4400bb6_master/3.html create mode 100644 2022-02-13-194124-4467-cppcheck@b215c4400bb6_master/4.html create mode 100644 2022-02-13-194124-4467-cppcheck@b215c4400bb6_master/index.html create mode 100644 2022-02-13-194124-4467-cppcheck@b215c4400bb6_master/stats.html create mode 100644 2022-02-13-194124-4467-cppcheck@b215c4400bb6_master/style.css create mode 100644 2022-10-29-134846-0734-cppcheck@fcf648868871_master/0.html create mode 100644 2022-10-29-134846-0734-cppcheck@fcf648868871_master/1.html create mode 100644 2022-10-29-134846-0734-cppcheck@fcf648868871_master/2.html create mode 100644 2022-10-29-134846-0734-cppcheck@fcf648868871_master/3.html create mode 100644 2022-10-29-134846-0734-cppcheck@fcf648868871_master/index.html create mode 100644 2022-10-29-134846-0734-cppcheck@fcf648868871_master/stats.html create mode 100644 2022-10-29-134846-0734-cppcheck@fcf648868871_master/style.css create mode 100644 2022-10-30-110836-1803-cppcheck@3a4fb1c0ec7f_master/0.html create mode 100644 2022-10-30-110836-1803-cppcheck@3a4fb1c0ec7f_master/1.html create mode 100644 2022-10-30-110836-1803-cppcheck@3a4fb1c0ec7f_master/2.html create mode 100644 2022-10-30-110836-1803-cppcheck@3a4fb1c0ec7f_master/3.html create mode 100644 2022-10-30-110836-1803-cppcheck@3a4fb1c0ec7f_master/index.html create mode 100644 2022-10-30-110836-1803-cppcheck@3a4fb1c0ec7f_master/stats.html create mode 100644 2022-10-30-110836-1803-cppcheck@3a4fb1c0ec7f_master/style.css create mode 100644 2022-11-11-200849-3937-cppcheck@c9d02a6bbcbb_master/0.html create mode 100644 2022-11-11-200849-3937-cppcheck@c9d02a6bbcbb_master/1.html create mode 100644 2022-11-11-200849-3937-cppcheck@c9d02a6bbcbb_master/2.html create mode 100644 2022-11-11-200849-3937-cppcheck@c9d02a6bbcbb_master/3.html create mode 100644 2022-11-11-200849-3937-cppcheck@c9d02a6bbcbb_master/index.html create mode 100644 2022-11-11-200849-3937-cppcheck@c9d02a6bbcbb_master/stats.html create mode 100644 2022-11-11-200849-3937-cppcheck@c9d02a6bbcbb_master/style.css create mode 100644 2022-11-11-201040-0718-cppcheck@c9d02a6bbcbb_v1.27.0/0.html create mode 100644 2022-11-11-201040-0718-cppcheck@c9d02a6bbcbb_v1.27.0/1.html create mode 100644 2022-11-11-201040-0718-cppcheck@c9d02a6bbcbb_v1.27.0/2.html create mode 100644 2022-11-11-201040-0718-cppcheck@c9d02a6bbcbb_v1.27.0/3.html create mode 100644 2022-11-11-201040-0718-cppcheck@c9d02a6bbcbb_v1.27.0/index.html create mode 100644 2022-11-11-201040-0718-cppcheck@c9d02a6bbcbb_v1.27.0/stats.html create mode 100644 2022-11-11-201040-0718-cppcheck@c9d02a6bbcbb_v1.27.0/style.css create mode 100644 2023-09-10-082921-9712-cppcheck@2d4aba56e7bf_master/0.html create mode 100644 2023-09-10-082921-9712-cppcheck@2d4aba56e7bf_master/1.html create mode 100644 2023-09-10-082921-9712-cppcheck@2d4aba56e7bf_master/2.html create mode 100644 2023-09-10-082921-9712-cppcheck@2d4aba56e7bf_master/3.html create mode 100644 2023-09-10-082921-9712-cppcheck@2d4aba56e7bf_master/4.html create mode 100644 2023-09-10-082921-9712-cppcheck@2d4aba56e7bf_master/5.html create mode 100644 2023-09-10-082921-9712-cppcheck@2d4aba56e7bf_master/index.html create mode 100644 2023-09-10-082921-9712-cppcheck@2d4aba56e7bf_master/stats.html create mode 100644 2023-09-10-082921-9712-cppcheck@2d4aba56e7bf_master/style.css create mode 100644 2023-09-19-100425-2309-cppcheck@72f91230a146_master/0.html create mode 100644 2023-09-19-100425-2309-cppcheck@72f91230a146_master/1.html create mode 100644 2023-09-19-100425-2309-cppcheck@72f91230a146_master/2.html create mode 100644 2023-09-19-100425-2309-cppcheck@72f91230a146_master/3.html create mode 100644 2023-09-19-100425-2309-cppcheck@72f91230a146_master/4.html create mode 100644 2023-09-19-100425-2309-cppcheck@72f91230a146_master/5.html create mode 100644 2023-09-19-100425-2309-cppcheck@72f91230a146_master/index.html create mode 100644 2023-09-19-100425-2309-cppcheck@72f91230a146_master/stats.html create mode 100644 2023-09-19-100425-2309-cppcheck@72f91230a146_master/style.css create mode 100644 2024-02-22-185755-8058-cppcheck@00d9a360c0cc_v1.28.0/0.html create mode 100644 2024-02-22-185755-8058-cppcheck@00d9a360c0cc_v1.28.0/1.html create mode 100644 2024-02-22-185755-8058-cppcheck@00d9a360c0cc_v1.28.0/10.html create mode 100644 2024-02-22-185755-8058-cppcheck@00d9a360c0cc_v1.28.0/11.html create mode 100644 2024-02-22-185755-8058-cppcheck@00d9a360c0cc_v1.28.0/12.html create mode 100644 2024-02-22-185755-8058-cppcheck@00d9a360c0cc_v1.28.0/13.html create mode 100644 2024-02-22-185755-8058-cppcheck@00d9a360c0cc_v1.28.0/14.html create mode 100644 2024-02-22-185755-8058-cppcheck@00d9a360c0cc_v1.28.0/2.html create mode 100644 2024-02-22-185755-8058-cppcheck@00d9a360c0cc_v1.28.0/3.html create mode 100644 2024-02-22-185755-8058-cppcheck@00d9a360c0cc_v1.28.0/4.html create mode 100644 2024-02-22-185755-8058-cppcheck@00d9a360c0cc_v1.28.0/5.html create mode 100644 2024-02-22-185755-8058-cppcheck@00d9a360c0cc_v1.28.0/6.html create mode 100644 2024-02-22-185755-8058-cppcheck@00d9a360c0cc_v1.28.0/7.html create mode 100644 2024-02-22-185755-8058-cppcheck@00d9a360c0cc_v1.28.0/8.html create mode 100644 2024-02-22-185755-8058-cppcheck@00d9a360c0cc_v1.28.0/9.html create mode 100644 2024-02-22-185755-8058-cppcheck@00d9a360c0cc_v1.28.0/index.html create mode 100644 2024-02-22-185755-8058-cppcheck@00d9a360c0cc_v1.28.0/stats.html create mode 100644 2024-02-22-185755-8058-cppcheck@00d9a360c0cc_v1.28.0/style.css create mode 100644 CNAME create mode 100644 index.html diff --git a/2020-06-12-004111-9546-cppcheck@0ac8ecb990d2_master/0.html b/2020-06-12-004111-9546-cppcheck@0ac8ecb990d2_master/0.html new file mode 100644 index 0000000..cb65a79 --- /dev/null +++ b/2020-06-12-004111-9546-cppcheck@0ac8ecb990d2_master/0.html @@ -0,0 +1,1482 @@ + + + + + + Cppcheck - HTML report - mate-user-share + + + + + + + +
+
  1
+  2
+  3
+  4
+  5
+  6
+  7
+  8
+  9
+ 10
+ 11
+ 12
+ 13
+ 14
+ 15
+ 16
+ 17
+ 18
+ 19
+ 20
+ 21
+ 22
+ 23
+ 24
+ 25
+ 26
+ 27
+ 28
+ 29
+ 30
+ 31
+ 32
+ 33
+ 34
+ 35
+ 36
+ 37
+ 38
+ 39
+ 40
+ 41
+ 42
+ 43
+ 44
+ 45
+ 46
+ 47
+ 48
+ 49
+ 50
+ 51
+ 52
+ 53
+ 54
+ 55
+ 56
+ 57
+ 58
+ 59
+ 60
+ 61
+ 62
+ 63
+ 64
+ 65
+ 66
+ 67
+ 68
+ 69
+ 70
+ 71
+ 72
+ 73
+ 74
+ 75
+ 76
+ 77
+ 78
+ 79
+ 80
+ 81
+ 82
+ 83
+ 84
+ 85
+ 86
+ 87
+ 88
+ 89
+ 90
+ 91
+ 92
+ 93
+ 94
+ 95
+ 96
+ 97
+ 98
+ 99
+100
+101
+102
+103
+104
+105
+106
+107
+108
+109
+110
+111
+112
+113
+114
+115
+116
+117
+118
+119
+120
+121
+122
+123
+124
+125
+126
+127
+128
+129
+130
+131
+132
+133
+134
+135
+136
+137
+138
+139
+140
+141
+142
+143
+144
+145
+146
+147
+148
+149
+150
+151
+152
+153
+154
+155
+156
+157
+158
+159
+160
+161
+162
+163
+164
+165
+166
+167
+168
+169
+170
+171
+172
+173
+174
+175
+176
+177
+178
+179
+180
+181
+182
+183
+184
+185
+186
+187
+188
+189
+190
+191
+192
+193
+194
+195
+196
+197
+198
+199
+200
+201
+202
+203
+204
+205
+206
+207
+208
+209
+210
+211
+212
+213
+214
+215
+216
+217
+218
+219
+220
+221
+222
+223
+224
+225
+226
+227
+228
+229
+230
+231
+232
+233
+234
+235
+236
+237
+238
+239
+240
+241
+242
+243
+244
+245
+246
+247
+248
+249
+250
+251
+252
+253
+254
+255
+256
+257
+258
+259
+260
+261
+262
+263
+264
+265
+266
+267
+268
+269
+270
+271
+272
+273
+274
+275
+276
+277
+278
+279
+280
+281
+282
+283
+284
+285
+286
+287
+288
+289
+290
+291
+292
+293
+294
+295
+296
+297
+298
+299
+300
+301
+302
+303
+304
+305
+306
+307
+308
+309
+310
+311
+312
+313
+314
+315
+316
+317
+318
+319
+320
+321
+322
+323
+324
+325
+326
+327
+328
+329
+330
+331
+332
+333
+334
+335
+336
+337
+338
+339
+340
+341
+342
+343
+344
+345
+346
+347
+348
+349
+350
+351
+352
+353
+354
+355
+356
+357
+358
+359
+360
+361
+362
+363
+364
+365
+366
+367
+368
+369
+370
+371
+372
+373
+374
+375
+376
+377
+378
+379
+380
+381
+382
+383
+384
+385
+386
+387
+388
+389
+390
+391
+392
+393
+394
+395
+396
+397
+398
+399
+400
+401
+402
+403
+404
+405
+406
+407
+408
+409
+410
+411
+412
+413
+414
+415
+416
+417
+418
+419
+420
+421
+422
+423
+424
+425
+426
+427
+428
+429
+430
+431
+432
+433
+434
+435
+436
+437
+438
+439
+440
+441
+442
+443
+444
+445
+446
+447
+448
+449
+450
+451
+452
+453
+454
+455
+456
+457
+458
+459
+460
+461
+462
+463
+464
+465
+466
+467
+468
+469
+470
+471
+472
+473
+474
+475
+476
+477
+478
+479
+480
+481
+482
+483
+484
+485
+486
+487
+488
+489
+490
+491
+492
+493
+494
+495
+496
+497
+498
+499
+500
+501
+502
+503
+504
+505
+506
+507
+508
+509
+510
+511
+512
+513
+514
+515
+516
+517
+518
+519
+520
+521
+522
+523
+524
+525
+526
+527
+528
+529
+530
+531
+532
+533
+534
+535
+536
+537
+538
+539
+540
+541
+542
+543
+544
+545
+546
+547
+548
+549
+550
+551
+552
+553
+554
+555
+556
+557
+558
+559
+560
+561
+562
+563
+564
+565
+566
+567
+568
+569
+570
+571
+572
+573
+574
+575
+576
+577
+578
+579
+580
+581
+582
+583
+584
+585
+586
+587
+588
+589
+590
+591
+592
+593
+594
+595
+596
+597
+598
+599
+600
+601
+602
+603
+604
+605
+606
+607
+608
+609
+610
+611
+612
+613
+614
+615
+616
+617
+618
+619
+620
+621
+622
+623
+624
+625
+626
+627
+628
+629
+630
+631
+632
+633
+634
+635
+636
+637
+638
+639
+640
+641
+642
+643
+644
+645
+646
+647
+648
+649
+650
+651
+652
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
+
+/*
+ *  Copyright (C) 2004 Red Hat, Inc.
+ *
+ *  Caja is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU General Public License as
+ *  published by the Free Software Foundation; either version 2 of the
+ *  License, or (at your option) any later version.
+ *
+ *  Caja is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  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
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ *  Authors: Alexander Larsson <alexl@redhat.com>
+ *
+ */
+
+#include "config.h"
+
+#include <string.h>
+#include <stdio.h>
+
+#include <gtk/gtk.h>
+#include <glib/gi18n.h>
+#include <gio/gio.h>
+
+#include "user_share-private.h"
+
+#define REALM "Please log in as the user guest"
+#define USER "guest"
+#define GSETTINGS_SCHEMA "org.mate.FileSharing"
+#define GSETTINGS_KEY_FILE_SHARING_ENABLED "enabled"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_ENABLED "bluetooth-enabled"
+#define GSETTINGS_KEY_FILE_SHARING_REQUIRE_PASSWORD "require-password"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_ALLOW_WRITE "bluetooth-allow-write"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_REQUIRE_PAIRING "bluetooth-require-pairing"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED "bluetooth-obexpush-enabled"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_ACCEPT_FILES "bluetooth-accept-files"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_NOTIFY "bluetooth-notify"
+
+static GtkBuilder* builder;
+static GSettings* settings;<--- Shadowed declaration<--- Shadowed declaration<--- Shadowed declaration<--- Shadowed declaration<--- Shadowed declaration<--- Shadowed declaration<--- Shadowed declaration<--- Shadowed declaration<--- Shadowed declaration<--- Shadowed declaration
+
+
+static void
+write_out_password (const char *password)
+{
+    char *to_hash;
+    char *ascii_digest;
+    char *line;
+    char *filename;
+    FILE *file;
+
+    to_hash = g_strdup_printf ("%s:%s:%s", USER, REALM, password);
+    ascii_digest = g_compute_checksum_for_string (G_CHECKSUM_MD5, to_hash, strlen (to_hash));
+    g_free (to_hash);
+    line = g_strdup_printf ("%s:%s:%s\n", USER, REALM, ascii_digest);
+    g_free (ascii_digest);
+
+    filename = g_build_filename (g_get_user_config_dir (), "user-share", "passwd", NULL);
+
+    file = fopen (filename, "w");
+    if (file != NULL) {
+	fwrite (line, strlen (line), 1, file);
+	fclose (file);
+    }
+
+    g_free (filename);
+    g_free (line);
+}
+
+static void
+flush_password (void)
+{
+    GtkWidget *password_entry;
+    const char *password;
+
+    password_entry = GTK_WIDGET (gtk_builder_get_object (builder, "password_entry"));
+
+    if (g_object_get_data (G_OBJECT( password_entry), "user_edited")) {
+	password = gtk_entry_get_text (GTK_ENTRY (password_entry));
+	if (password != NULL && password[0] != 0)
+	    write_out_password (password);
+    }
+}
+
+
+static void
+update_ui (void)
+{
+    GSettings *settings;<--- Shadow variable
+    gboolean enabled;
+#ifdef HAVE_BLUETOOTH
+    gboolean bluetooth_enabled, bluetooth_write_enabled, require_pairing_enabled;
+    gboolean bluetooth_obexpush_enabled, bluetooth_obexpush_notify;
+#endif /* HAVE_BLUETOOTH */
+    char *str;
+    PasswordSetting password_setting;
+    AcceptSetting accept_setting;<--- Unused variable: accept_setting
+    GtkWidget *check;
+    GtkWidget *password_combo;
+    GtkWidget *password_entry;
+#ifdef HAVE_BLUETOOTH
+    GtkWidget *vbox_share_bluetooth;
+    GtkWidget *vbox_receive_bluetooth;
+    GtkWidget *bluetooth_check;
+    GtkWidget *allow_write_bluetooth_check;
+    GtkWidget *require_pairing_check;
+    GtkWidget *enable_obexpush_check;
+    GtkWidget *accept_obexpush_combo;
+    GtkWidget *notify_received_obexpush_check;
+#endif /* HAVE_BLUETOOTH */
+
+    settings = g_settings_new (GSETTINGS_SCHEMA);
+
+    enabled = g_settings_get_boolean (settings,
+				     FILE_SHARING_ENABLED);
+
+    str = g_settings_get_string (settings, FILE_SHARING_REQUIRE_PASSWORD);
+    password_setting = password_setting_from_string (str);
+    g_free (str);
+
+#ifdef HAVE_BLUETOOTH
+    bluetooth_enabled = g_settings_get_boolean (settings,
+    					       FILE_SHARING_BLUETOOTH_ENABLED);
+    bluetooth_write_enabled = g_settings_get_boolean (settings,
+						     FILE_SHARING_BLUETOOTH_ALLOW_WRITE);
+    require_pairing_enabled = g_settings_get_boolean (settings,
+    						     FILE_SHARING_BLUETOOTH_REQUIRE_PAIRING);
+    bluetooth_obexpush_enabled = g_settings_get_boolean (settings,
+    							FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED);
+    bluetooth_obexpush_notify = g_settings_get_boolean (settings,
+    						       FILE_SHARING_BLUETOOTH_OBEXPUSH_NOTIFY);
+
+    str = g_settings_get_string (settings, FILE_SHARING_BLUETOOTH_OBEXPUSH_ACCEPT_FILES);
+    accept_setting = accept_setting_from_string (str);
+    g_free (str);
+#endif /* HAVE_BLUETOOTH */
+
+    check = GTK_WIDGET (gtk_builder_get_object (builder, "enable_check"));
+    password_combo = GTK_WIDGET (gtk_builder_get_object (builder, "password_combo"));
+    password_entry = GTK_WIDGET (gtk_builder_get_object (builder, "password_entry"));
+#ifdef HAVE_BLUETOOTH
+    vbox_share_bluetooth = GTK_WIDGET (gtk_builder_get_object (builder, "vbox_share_bluetooth"));
+    vbox_receive_bluetooth = GTK_WIDGET (gtk_builder_get_object (builder, "vbox_receive_bluetooth"));
+    bluetooth_check = GTK_WIDGET (gtk_builder_get_object (builder, "enable_bluetooth_check"));
+    allow_write_bluetooth_check = GTK_WIDGET (gtk_builder_get_object (builder, "allow_write_bluetooth_check"));
+    require_pairing_check = GTK_WIDGET (gtk_builder_get_object (builder, "require_pairing_check"));
+    enable_obexpush_check = GTK_WIDGET (gtk_builder_get_object (builder, "enable_obexpush_check"));
+    accept_obexpush_combo = GTK_WIDGET (gtk_builder_get_object (builder, "accept_obexpush_combo"));
+    notify_received_obexpush_check = GTK_WIDGET (gtk_builder_get_object (builder, "notify_received_obexpush_check"));
+#endif /* HAVE_BLUETOOTH */
+
+    /* Network */
+    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (check), enabled);
+    gtk_widget_set_sensitive (password_combo, enabled);
+    gtk_widget_set_sensitive (password_entry, enabled && password_setting != PASSWORD_NEVER);
+
+    gtk_combo_box_set_active (GTK_COMBO_BOX (password_combo),
+			      password_setting);
+
+#ifdef HAVE_BLUETOOTH
+    /* Bluetooth ObexFTP */
+    gtk_widget_set_visible (vbox_share_bluetooth, TRUE);
+    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (bluetooth_check), bluetooth_enabled);
+    gtk_widget_set_sensitive (allow_write_bluetooth_check, bluetooth_enabled);
+    gtk_widget_set_sensitive (require_pairing_check, bluetooth_enabled);
+
+    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (allow_write_bluetooth_check),
+    				  bluetooth_write_enabled);
+    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (require_pairing_check),
+    				  require_pairing_enabled);
+
+    /* Bluetooth ObexPush */
+    gtk_widget_set_visible (vbox_receive_bluetooth, TRUE);
+    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (enable_obexpush_check), bluetooth_obexpush_enabled);
+    gtk_widget_set_sensitive (accept_obexpush_combo, bluetooth_obexpush_enabled);
+    gtk_widget_set_sensitive (notify_received_obexpush_check, bluetooth_obexpush_enabled);
+
+    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (notify_received_obexpush_check),
+    				  bluetooth_obexpush_notify);
+
+    gtk_combo_box_set_active (GTK_COMBO_BOX (accept_obexpush_combo),
+    			      accept_setting);
+#endif /* HAVE_BLUETOOTH */
+
+    g_object_unref (settings);
+}
+
+static void
+file_sharing_enabled_changed (GSettings *settings, gchar *key, gpointer data)
+{
+    update_ui ();
+}
+
+static void
+password_required_changed (GSettings *settings, gchar *key, gpointer data)
+{
+    update_ui ();
+}
+
+#ifdef HAVE_BLUETOOTH
+static void
+file_sharing_bluetooth_enabled_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	update_ui ();
+}
+
+static void
+file_sharing_bluetooth_allow_write_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	update_ui ();
+}
+
+static void
+file_sharing_bluetooth_require_pairing_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	update_ui ();
+}
+
+static void
+file_sharing_bluetooth_obexpush_enabled_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	update_ui ();
+}
+
+static void
+file_sharing_bluetooth_obexpush_accept_files_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	update_ui ();
+}
+
+static void
+file_sharing_bluetooth_obexpush_notify_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	update_ui ();
+}
+#endif /* HAVE_BLUETOOTH */
+
+static void
+password_combo_changed (GtkComboBox *combo_box)
+{
+    GSettings *settings;<--- Shadow variable
+    guint setting;
+
+    setting = gtk_combo_box_get_active (combo_box);
+
+    settings = g_settings_new (GSETTINGS_SCHEMA) ;
+
+    g_settings_set_string (settings,
+			     FILE_SHARING_REQUIRE_PASSWORD,
+			     password_string_from_setting (setting));
+    g_object_unref (settings);
+}
+
+static void
+launch_share (void)
+{
+	if (!g_spawn_command_line_async (USER_SHARE_PROGRAM, NULL))
+		g_warning ("Unable to start mate-user-share program");
+}
+
+#ifdef HAVE_BLUETOOTH
+static void
+enable_bluetooth_check_toggled (GtkWidget *check)
+{
+	GSettings *settings;<--- Shadow variable
+	gboolean enabled;
+
+	enabled = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check));
+
+	settings = g_settings_new (GSETTINGS_SCHEMA) ;
+
+	g_settings_set_boolean (settings,
+			       FILE_SHARING_BLUETOOTH_ENABLED,
+			       enabled);
+
+	g_object_unref (settings);
+
+	if (enabled != FALSE)
+		launch_share ();
+}
+#endif /* HAVE_BLUETOOTH */
+
+static void
+enable_check_toggled (GtkWidget *check)
+{
+	GSettings *settings;<--- Shadow variable
+	gboolean enabled;
+
+	enabled = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check));
+
+	settings = g_settings_new (GSETTINGS_SCHEMA);
+
+	g_settings_set_boolean (settings,
+			       FILE_SHARING_ENABLED,
+			       enabled);
+
+	g_object_unref (settings);
+
+	if (enabled != FALSE)
+		launch_share ();
+}
+
+static void
+password_entry_changed (GtkEditable *editable)
+{
+	g_object_set_data (G_OBJECT (editable),
+			   "user_edited", GINT_TO_POINTER (1));
+	flush_password ();
+}
+
+#ifdef HAVE_BLUETOOTH
+static void
+bluetooth_allow_write_check_toggled (GtkWidget *check)
+{
+	GSettings *settings;<--- Shadow variable
+	gboolean enabled;
+
+	enabled = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check));
+
+	settings = g_settings_new (GSETTINGS_SCHEMA) ;
+
+	g_settings_set_boolean (settings,
+			       FILE_SHARING_BLUETOOTH_ALLOW_WRITE,
+			       enabled);
+
+	g_object_unref (settings);
+}
+
+static void
+bluetooth_require_pairing_check_toggled (GtkWidget *check)
+{
+	GSettings *settings;<--- Shadow variable
+	gboolean enabled;
+
+	enabled = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check));
+
+	settings = g_settings_new (GSETTINGS_SCHEMA) ;
+
+	g_settings_set_boolean (settings,
+			       FILE_SHARING_BLUETOOTH_REQUIRE_PAIRING,
+			       enabled);
+
+	g_object_unref (settings);
+}
+
+static void
+enable_obexpush_check_toggled (GtkWidget *check)
+{
+	GSettings *settings;<--- Shadow variable
+	gboolean enabled;
+
+	enabled = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check));
+
+	settings = g_settings_new (GSETTINGS_SCHEMA) ;
+
+	g_settings_set_boolean (settings,
+			       FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED,
+			       enabled);
+
+	g_object_unref (settings);
+
+	if (enabled != FALSE)
+		launch_share ();
+}
+
+static void
+accept_obexpush_combo_changed (GtkComboBox *combo_box)
+{
+    GSettings *settings;<--- Shadow variable
+    guint setting;
+
+    setting = gtk_combo_box_get_active (combo_box);
+
+    settings = g_settings_new (GSETTINGS_SCHEMA) ;
+
+    g_settings_set_string (settings,
+			     FILE_SHARING_BLUETOOTH_OBEXPUSH_ACCEPT_FILES,
+			     accept_string_from_setting (setting));
+    g_object_unref (settings);
+}
+
+static void
+notify_received_obexpush_check_toggled (GtkWidget *check)
+{
+	GSettings *settings;<--- Shadow variable
+	gboolean enabled;
+
+	enabled = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check));
+
+	settings = g_settings_new (GSETTINGS_SCHEMA) ;
+
+	g_settings_set_boolean (settings,
+			       FILE_SHARING_BLUETOOTH_OBEXPUSH_NOTIFY,
+			       enabled);
+
+	g_object_unref (settings);
+}
+#endif /* HAVE_BLUETOOTH */
+
+static GtkWidget *
+error_dialog (const char *title,
+	      const char *reason,
+	      GtkWindow *parent)
+{
+	GtkWidget *error_dialog;
+
+	if (reason == NULL)
+		reason = _("No reason");
+
+	error_dialog =
+		gtk_message_dialog_new (parent,
+					GTK_DIALOG_MODAL,
+					GTK_MESSAGE_ERROR,
+					GTK_BUTTONS_OK,
+					"%s", title);
+	gtk_message_dialog_format_secondary_text
+		(GTK_MESSAGE_DIALOG (error_dialog), "%s", reason);
+
+	gtk_window_set_title (GTK_WINDOW (error_dialog), ""); /* as per HIG */
+	gtk_container_set_border_width (GTK_CONTAINER (error_dialog), 5);
+	gtk_dialog_set_default_response (GTK_DIALOG (error_dialog),
+					 GTK_RESPONSE_OK);
+	gtk_window_set_modal (GTK_WINDOW (error_dialog), TRUE);
+
+	return error_dialog;
+}
+
+static void
+help_button_clicked (GtkButton *button, GtkWidget *window)
+{
+	GError *error = NULL;
+
+	if (gtk_show_uri_on_window (GTK_WINDOW (window), "help:mate-user-share", gtk_get_current_event_time (), &error) == FALSE) {
+		GtkWidget *dialog;
+
+		dialog = error_dialog (_("Could not display the help contents."), error->message, GTK_WINDOW (window));
+		g_signal_connect (G_OBJECT (dialog), "response", G_CALLBACK
+				  (gtk_widget_destroy), error_dialog);
+		gtk_window_present (GTK_WINDOW (dialog));
+
+		g_error_free (error);
+	}
+}
+
+static GtkWidget *
+create_window (void)
+{
+    GError *error = NULL;
+    GSettings *settings;<--- Shadow variable
+    GtkWidget *check;
+    GtkWidget *password_combo;
+    GtkWidget *password_entry;
+#ifdef HAVE_BLUETOOTH
+    GtkWidget *bluetooth_check;
+    GtkWidget *bluetooth_allow_write_check;
+    GtkWidget *require_pairing_check;
+    GtkWidget *enable_obexpush_check;
+    GtkWidget *accept_obexpush_combo;
+    GtkWidget *notify_received_obexpush_check;
+#endif /* HAVE_BLUETOOTH */
+    GtkWidget *window;
+    GtkListStore *store;
+    GtkCellRenderer *cell;
+    GtkTreeIter iter;
+
+    builder = gtk_builder_new ();
+    gtk_builder_add_from_file (builder, DATADIR"file-share-properties.ui", &error);
+
+    if (error) {
+      GtkWidget *dialog;
+
+      dialog = error_dialog (_("Could not build interface."), error->message, NULL);
+      gtk_dialog_run (GTK_DIALOG (dialog));
+      gtk_widget_destroy (dialog);
+
+      g_error_free (error);
+      return NULL;
+    }
+
+    window = GTK_WIDGET (gtk_builder_get_object (builder, "user_share_dialog"));
+
+    settings = g_settings_new (GSETTINGS_SCHEMA);
+
+    check = GTK_WIDGET (gtk_builder_get_object (builder, "enable_check"));
+    password_combo = GTK_WIDGET (gtk_builder_get_object (builder, "password_combo"));
+    password_entry = GTK_WIDGET (gtk_builder_get_object (builder, "password_entry"));
+#ifdef HAVE_BLUETOOTH
+    bluetooth_check = GTK_WIDGET (gtk_builder_get_object (builder, "enable_bluetooth_check"));
+    bluetooth_allow_write_check = GTK_WIDGET (gtk_builder_get_object (builder, "allow_write_bluetooth_check"));
+    require_pairing_check = GTK_WIDGET (gtk_builder_get_object (builder, "require_pairing_check"));
+    enable_obexpush_check = GTK_WIDGET (gtk_builder_get_object (builder, "enable_obexpush_check"));
+    accept_obexpush_combo = GTK_WIDGET (gtk_builder_get_object (builder, "accept_obexpush_combo"));
+    notify_received_obexpush_check = GTK_WIDGET (gtk_builder_get_object (builder, "notify_received_obexpush_check"));
+#endif /* HAVE_BLUETOOTH */
+
+    store = gtk_list_store_new (1, G_TYPE_STRING);
+    gtk_combo_box_set_model (GTK_COMBO_BOX (password_combo),
+			     GTK_TREE_MODEL (store));
+    cell = gtk_cell_renderer_text_new ();
+    gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (password_combo), cell, TRUE);
+    gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (password_combo), cell,
+				    "text", 0,
+				    NULL);
+
+    /* Keep in same order as enum */
+    gtk_list_store_append (store, &iter);
+    gtk_list_store_set (store, &iter, 0,
+			_("Never"), -1);
+    gtk_list_store_append (store, &iter);
+    gtk_list_store_set (store, &iter, 0,
+			_("When writing files"), -1);
+    gtk_list_store_append (store, &iter);
+    gtk_list_store_set (store, &iter, 0,
+			_("Always"), -1);
+    g_object_unref (store);
+
+    /* We can't read the password from the text, just set it to something */
+    gtk_entry_set_text (GTK_ENTRY (password_entry), "none");
+    g_object_set_data (G_OBJECT (password_entry),
+		       "user_edited", GINT_TO_POINTER (0));
+    g_signal_connect (password_entry,
+		      "changed", G_CALLBACK (password_entry_changed), NULL);
+
+#ifdef HAVE_BLUETOOTH
+    /* Accept files combo */
+    store = gtk_list_store_new (1, G_TYPE_STRING);
+    gtk_combo_box_set_model (GTK_COMBO_BOX (accept_obexpush_combo),
+			     GTK_TREE_MODEL (store));
+    cell = gtk_cell_renderer_text_new ();
+    gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (accept_obexpush_combo), cell, TRUE);
+    gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (accept_obexpush_combo), cell,
+				    "text", 0,
+				    NULL);
+
+    /* Keep in same order as enum */
+    gtk_list_store_append (store, &iter);
+    gtk_list_store_set (store, &iter, 0,
+			_("Always"), -1);
+    gtk_list_store_append (store, &iter);
+    gtk_list_store_set (store, &iter, 0,
+			_("Only for set up devices"), -1);
+    //FIXME implement
+#if 0
+    gtk_list_store_append (store, &iter);
+    gtk_list_store_set (store, &iter, 0,
+    			_("Ask"), -1);
+#endif
+    g_object_unref (store);
+#endif /* HAVE_BLUETOOTH */
+
+    g_signal_connect (check,
+		      "toggled", G_CALLBACK (enable_check_toggled), NULL);
+    g_signal_connect (password_combo,
+		      "changed", G_CALLBACK (password_combo_changed), NULL);
+#ifdef HAVE_BLUETOOTH
+    g_signal_connect (bluetooth_check,
+    		      "toggled", G_CALLBACK (enable_bluetooth_check_toggled), NULL);
+    g_signal_connect (bluetooth_allow_write_check,
+    		      "toggled", G_CALLBACK (bluetooth_allow_write_check_toggled), NULL);
+    g_signal_connect (require_pairing_check,
+    		      "toggled", G_CALLBACK (bluetooth_require_pairing_check_toggled), NULL);
+    g_signal_connect (enable_obexpush_check,
+    		      "toggled", G_CALLBACK (enable_obexpush_check_toggled), NULL);
+    g_signal_connect (accept_obexpush_combo,
+    		      "changed", G_CALLBACK (accept_obexpush_combo_changed), NULL);
+    g_signal_connect (notify_received_obexpush_check,
+    		      "toggled", G_CALLBACK (notify_received_obexpush_check_toggled), NULL);
+#endif /* HAVE_BLUETOOTH */
+
+    g_signal_connect_swapped (GTK_WIDGET (gtk_builder_get_object (builder, "close_button")),
+                              "clicked", G_CALLBACK (gtk_widget_destroy), window);
+    g_signal_connect (GTK_WIDGET (gtk_builder_get_object (builder, "help_button")),
+		      "clicked", G_CALLBACK (help_button_clicked),
+		      gtk_builder_get_object (builder, "user_share_dialog"));
+
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_ENABLED,
+			     G_CALLBACK (file_sharing_enabled_changed), NULL);
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_REQUIRE_PASSWORD,
+			     G_CALLBACK (password_required_changed), NULL);
+#ifdef HAVE_BLUETOOTH
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_ENABLED,
+			     G_CALLBACK (file_sharing_bluetooth_enabled_changed), NULL);
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_ALLOW_WRITE,
+			     G_CALLBACK (file_sharing_bluetooth_allow_write_changed), NULL);
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_REQUIRE_PAIRING,
+			     G_CALLBACK (file_sharing_bluetooth_require_pairing_changed), NULL);
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED,
+			     G_CALLBACK (file_sharing_bluetooth_obexpush_enabled_changed), NULL);
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_ACCEPT_FILES,
+			     G_CALLBACK (file_sharing_bluetooth_obexpush_accept_files_changed), NULL);
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_NOTIFY,
+			     G_CALLBACK (file_sharing_bluetooth_obexpush_notify_changed), NULL);
+#endif /* HAVE_BLUETOOTH */
+
+    update_ui ();
+
+    return window;
+}
+
+static void
+activate (GtkApplication *app)
+{
+    GList *list;
+    GtkWidget *window;
+
+    list = gtk_application_get_windows (app);
+
+    if (list) {
+        gtk_window_present (GTK_WINDOW (list->data));
+    } else {
+        window = create_window ();
+        gtk_window_set_application (GTK_WINDOW (window), app);
+        gtk_widget_show (window);
+    }
+}
+
+int
+main (int argc, char *argv[])
+{
+    GtkApplication *app;
+    gint status;
+
+    bindtextdomain (GETTEXT_PACKAGE, MATELOCALEDIR);
+    bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
+    textdomain (GETTEXT_PACKAGE);
+
+    app = gtk_application_new ("org.mate.user-share.properties",
+                               G_APPLICATION_FLAGS_NONE);
+    g_signal_connect (app, "activate", G_CALLBACK (activate), NULL);
+
+    status = g_application_run (G_APPLICATION (app), argc, argv);
+
+    g_object_unref (app);
+
+    return status;
+}
+
+
+
+ + + diff --git a/2020-06-12-004111-9546-cppcheck@0ac8ecb990d2_master/1.html b/2020-06-12-004111-9546-cppcheck@0ac8ecb990d2_master/1.html new file mode 100644 index 0000000..0ccd444 --- /dev/null +++ b/2020-06-12-004111-9546-cppcheck@0ac8ecb990d2_master/1.html @@ -0,0 +1,1038 @@ + + + + + + Cppcheck - HTML report - mate-user-share + + + + + + + +
+
  1
+  2
+  3
+  4
+  5
+  6
+  7
+  8
+  9
+ 10
+ 11
+ 12
+ 13
+ 14
+ 15
+ 16
+ 17
+ 18
+ 19
+ 20
+ 21
+ 22
+ 23
+ 24
+ 25
+ 26
+ 27
+ 28
+ 29
+ 30
+ 31
+ 32
+ 33
+ 34
+ 35
+ 36
+ 37
+ 38
+ 39
+ 40
+ 41
+ 42
+ 43
+ 44
+ 45
+ 46
+ 47
+ 48
+ 49
+ 50
+ 51
+ 52
+ 53
+ 54
+ 55
+ 56
+ 57
+ 58
+ 59
+ 60
+ 61
+ 62
+ 63
+ 64
+ 65
+ 66
+ 67
+ 68
+ 69
+ 70
+ 71
+ 72
+ 73
+ 74
+ 75
+ 76
+ 77
+ 78
+ 79
+ 80
+ 81
+ 82
+ 83
+ 84
+ 85
+ 86
+ 87
+ 88
+ 89
+ 90
+ 91
+ 92
+ 93
+ 94
+ 95
+ 96
+ 97
+ 98
+ 99
+100
+101
+102
+103
+104
+105
+106
+107
+108
+109
+110
+111
+112
+113
+114
+115
+116
+117
+118
+119
+120
+121
+122
+123
+124
+125
+126
+127
+128
+129
+130
+131
+132
+133
+134
+135
+136
+137
+138
+139
+140
+141
+142
+143
+144
+145
+146
+147
+148
+149
+150
+151
+152
+153
+154
+155
+156
+157
+158
+159
+160
+161
+162
+163
+164
+165
+166
+167
+168
+169
+170
+171
+172
+173
+174
+175
+176
+177
+178
+179
+180
+181
+182
+183
+184
+185
+186
+187
+188
+189
+190
+191
+192
+193
+194
+195
+196
+197
+198
+199
+200
+201
+202
+203
+204
+205
+206
+207
+208
+209
+210
+211
+212
+213
+214
+215
+216
+217
+218
+219
+220
+221
+222
+223
+224
+225
+226
+227
+228
+229
+230
+231
+232
+233
+234
+235
+236
+237
+238
+239
+240
+241
+242
+243
+244
+245
+246
+247
+248
+249
+250
+251
+252
+253
+254
+255
+256
+257
+258
+259
+260
+261
+262
+263
+264
+265
+266
+267
+268
+269
+270
+271
+272
+273
+274
+275
+276
+277
+278
+279
+280
+281
+282
+283
+284
+285
+286
+287
+288
+289
+290
+291
+292
+293
+294
+295
+296
+297
+298
+299
+300
+301
+302
+303
+304
+305
+306
+307
+308
+309
+310
+311
+312
+313
+314
+315
+316
+317
+318
+319
+320
+321
+322
+323
+324
+325
+326
+327
+328
+329
+330
+331
+332
+333
+334
+335
+336
+337
+338
+339
+340
+341
+342
+343
+344
+345
+346
+347
+348
+349
+350
+351
+352
+353
+354
+355
+356
+357
+358
+359
+360
+361
+362
+363
+364
+365
+366
+367
+368
+369
+370
+371
+372
+373
+374
+375
+376
+377
+378
+379
+380
+381
+382
+383
+384
+385
+386
+387
+388
+389
+390
+391
+392
+393
+394
+395
+396
+397
+398
+399
+400
+401
+402
+403
+404
+405
+406
+407
+408
+409
+410
+411
+412
+413
+414
+415
+416
+417
+418
+419
+420
+421
+422
+423
+424
+425
+426
+427
+428
+429
+430
+431
+432
+433
+434
+435
+436
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
+
+/*
+ *  Copyright (C) 2004-2008 Red Hat, Inc.
+ *
+ *  Caja is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU General Public License as
+ *  published by the Free Software Foundation; either version 2 of the
+ *  License, or (at your option) any later version.
+ *
+ *  Caja is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  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
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ *  Authors: Alexander Larsson <alexl@redhat.com>
+ *
+ */
+
+#include "config.h"
+
+#include <glib.h>
+#include <glib/gi18n.h>
+#include <X11/Xlib.h>
+
+#include <gio/gio.h>
+
+#include <stdarg.h>
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <signal.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <sys/stat.h>
+
+#ifdef HAVE_SELINUX
+#include <selinux/selinux.h>
+#endif
+
+#include "user_share-common.h"
+#include "user_share-private.h"
+#include "http.h"
+
+/* From avahi-common/domain.h */
+#define AVAHI_LABEL_MAX 64
+
+#define GSETTINGS_SCHEMA "org.mate.FileSharing"
+
+static pid_t httpd_pid = 0;
+
+static int
+get_port (void)
+{
+	int sock;
+	struct sockaddr_in addr;
+	int reuse;
+	socklen_t len;
+
+	sock = socket (PF_INET, SOCK_STREAM, 0);
+	if (sock < 0) {
+		return -1;
+	}
+
+	memset (&addr, 0, sizeof (addr));
+	addr.sin_port = 0;
+	addr.sin_addr.s_addr = INADDR_ANY;
+	addr.sin_family = AF_INET;
+
+	reuse = 1;
+	setsockopt (sock, SOL_SOCKET, SO_REUSEADDR, &reuse, sizeof (reuse));
+	if (bind (sock, (struct sockaddr *)&addr, sizeof (addr)) == -1) {
+		close (sock);
+		return -1;
+	}
+
+	len = sizeof (addr);
+	if (getsockname (sock, (struct sockaddr *)&addr, &len) == -1) {
+		close (sock);
+		return -1;
+	}
+
+#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__APPLE__) || defined(__OpenBSD__)
+	/* XXX This exposes a potential race condition, but without this,
+	 * httpd will not start on the above listed platforms due to the fact
+	 * that SO_REUSEADDR is also needed when Apache binds to the listening
+	 * socket.  At this time, Apache does not support that socket option.
+	 */
+	close (sock);
+#endif
+	return ntohs (addr.sin_port);
+}
+
+static char *
+truncate_name (const char *name)
+{
+	const char *end;
+
+	end = g_utf8_find_prev_char (name, name + 64);<--- Assignment 'end=g_utf8_find_prev_char(name,name+64)', assigned value is 0
+	g_assert (end != NULL);<--- Assuming that condition 'end!=NULL' is not redundant
+	return g_strndup (name, end - name);<--- Null pointer subtraction
+}
+
+static char *
+get_share_name (void)
+{
+	static char *name = NULL;
+	const char *host_name;
+	char *str;
+
+	if (name == NULL) {
+		host_name = g_get_host_name ();
+		if (strcmp (host_name, "localhost") == 0) {
+			/* Translators: The %s will get filled in with the user name
+			   of the user, to form a genitive. If this is difficult to
+			   translate correctly so that it will work correctly in your
+			   language, you may use something equivalent to
+			   "Public files of %s", or leave out the %s altogether.
+			   In the latter case, please put "%.0s" somewhere in the string,
+			   which will match the user name string passed by the C code,
+			   but not put the user name in the final string. This is to
+			   avoid the warning that msgfmt might otherwise generate. */
+			name = g_strdup_printf (_("%s's public files"), g_get_user_name ());
+		} else {
+			/* Translators: This is similar to the string before, only it
+			   has the hostname in it too. */
+			name = g_strdup_printf (_("%s's public files on %s"),
+						g_get_user_name (),
+						host_name);
+		}
+
+	}
+	/* And truncate */
+	if (strlen (name) < AVAHI_LABEL_MAX)
+		return name;
+
+	str = truncate_name (name);
+	g_free (name);
+	name = str;
+
+	return name;
+}
+
+static void
+ensure_conf_dir (void)
+{
+	char *dirname;
+
+	dirname = g_build_filename (g_get_user_config_dir (), "user-share", NULL);
+	g_mkdir_with_parents (dirname, 0755);
+	g_free (dirname);
+}
+
+static void
+httpd_child_setup (gpointer user_data)
+{
+#ifdef HAVE_SELINUX
+	char *mycon;
+	/* If selinux is enabled, avoid transitioning to the httpd_t context,
+	   as this normally means you can't read the users homedir. */
+	if (is_selinux_enabled()) {
+		if (getcon (&mycon) < 0) {
+			abort ();
+		}
+		if (setexeccon (mycon) < 0)
+			abort ();
+		freecon (mycon);
+	}
+#endif
+}
+
+static const char *known_httpd_locations [] = {
+	HTTPD_PROGRAM,
+	"/usr/sbin/httpd",
+	"/usr/sbin/httpd2",
+	"/usr/sbin/apache2",
+	NULL
+};
+
+static char*
+get_httpd_program (void)
+{
+	int i;
+
+	for (i = 0; known_httpd_locations[i]; i++) {
+		if (known_httpd_locations[i][0] == '\0') {
+			/* empty string as first element, happens when
+			 * configured --with-httpd=auto */
+			continue;
+		}
+		if (g_file_test (known_httpd_locations[i], G_FILE_TEST_IS_EXECUTABLE)
+				&& ! g_file_test (known_httpd_locations[i], G_FILE_TEST_IS_DIR)) {
+			return g_strdup (known_httpd_locations[i]);
+		}
+	}
+	return NULL;
+}
+
+static const char *known_httpd_modules_locations [] = {
+	HTTPD_MODULES_PATH,
+	"/etc/httpd/modules",
+	"/usr/lib/apache2/modules",
+	NULL
+};
+
+static gchar*
+get_httpd_modules_path (void)
+{
+	int i;
+
+	for (i = 0; known_httpd_modules_locations[i]; i++) {
+		if (known_httpd_modules_locations[i][0] == '\0') {
+			/* empty string as first element, happens when
+			 * configured --with-httpd=auto */
+			continue;
+		}
+		if (g_file_test (known_httpd_modules_locations[i], G_FILE_TEST_IS_EXECUTABLE)
+				&& g_file_test (known_httpd_modules_locations[i], G_FILE_TEST_IS_DIR)) {
+			return g_strdup (known_httpd_modules_locations[i]);
+		}
+	}
+	return NULL;
+}
+
+static GRegex *version_regex = NULL;
+
+static char*
+get_httpd_config (const char *httpd_program)
+{
+	gchar *standard_output;
+	gchar *cmd_line;
+	GMatchInfo *match_info;
+	gchar *version_number = NULL;
+	gchar *config;
+
+	cmd_line = g_strdup_printf ("%s -v", httpd_program);
+	if (! g_spawn_command_line_sync (cmd_line, &standard_output, NULL, NULL, NULL)) {
+		g_free (cmd_line);
+		return NULL;
+	}
+	g_free (cmd_line);
+
+	if (version_regex == NULL) {
+		version_regex = g_regex_new ("\\d\\.\\d", 0, 0, NULL);
+	}
+
+	if (g_regex_match (version_regex, standard_output, 0, &match_info)) {
+		while (g_match_info_matches (match_info)) {
+			version_number = g_match_info_fetch (match_info, 0);
+			break;
+		}
+		g_match_info_free (match_info);
+		g_free (standard_output);
+	} else {
+		/* Failed to parse httpd version number */
+		g_warning ("Could not parse '%s' as a version for httpd", standard_output);
+		g_free (standard_output);
+		/* assume it is 2.2 */
+		version_number = g_strdup ("2.2");
+	}
+
+	config = g_strdup_printf (HTTPD_CONFIG_TEMPLATE, version_number);
+	g_free (version_number);
+
+	return config;
+}
+
+static gboolean
+spawn_httpd (int port, pid_t *pid_out)
+{
+	char *free1, *free2, *free3, *free4, *free5, *free6, *free7, *free8, *free9;
+	gboolean res;
+	char *argv[10];
+	char *env[10];
+	int i;
+	gint status;
+	char *pid_filename;
+	char *pidfile;
+	GError *error;
+	gboolean got_pidfile;
+	GSettings *settings;
+	char *str;
+	char *public_dir;
+
+	public_dir = lookup_public_dir ();
+	ensure_conf_dir ();
+
+	i = 0;
+	free1 = argv[i++] = get_httpd_program ();
+	if (argv[0] == NULL) {
+		fprintf (stderr, "error finding httpd server\n");
+		return FALSE;
+	}
+
+	argv[i++] = "-f";
+	free2 = argv[i++] = get_httpd_config (argv[0]);
+	argv[i++] = "-C";
+	free3 = argv[i++] = g_strdup_printf ("Listen %d", port);
+
+	settings = g_settings_new (GSETTINGS_SCHEMA);
+	str = g_settings_get_string (settings,
+				       FILE_SHARING_REQUIRE_PASSWORD);
+
+	if (str && strcmp (str, "never") == 0) {
+		/* Do nothing */
+	} else if (str && strcmp (str, "on_write") == 0){
+		argv[i++] = "-D";
+		argv[i++] = "RequirePasswordOnWrite";
+	} else {
+		/* always, or safe fallback */
+		argv[i++] = "-D";
+		argv[i++] = "RequirePasswordAlways";
+	}
+	g_free (str);
+	g_object_unref (settings);
+
+	argv[i] = NULL;
+
+	i = 0;
+	free4 = env[i++] = g_strdup_printf ("HOME=%s", g_get_home_dir());
+	free5 = env[i++] = g_strdup_printf ("XDG_PUBLICSHARE_DIR=%s", public_dir);
+	free6 = env[i++] = g_strdup_printf ("XDG_CONFIG_HOME=%s", g_get_user_config_dir ());
+	free7 = env[i++] = g_strdup_printf ("GUS_SHARE_NAME=%s", get_share_name ());
+	free8 = env[i++] = g_strdup_printf ("GUS_LOGIN_LABEL=%s", "Please log in as the user guest");
+	free9 = env[i++] = g_strdup_printf ("HTTP_MODULES_PATH=%s",get_httpd_modules_path ());
+	env[i++] = "LANG=C";
+	env[i] = NULL;
+
+	pid_filename = g_build_filename (g_get_user_config_dir (), "user-share", "pid", NULL);
+
+	/* Remove pid file before spawning to avoid races with child and old pidfile */
+	unlink (pid_filename);
+
+	error = NULL;
+	res = g_spawn_sync (g_get_home_dir(),
+			    argv, env, 0,
+			    httpd_child_setup, NULL,
+			    NULL, NULL,
+			    &status,
+			    &error);
+	g_free (free1);
+	g_free (free2);
+	g_free (free3);
+	g_free (free4);
+	g_free (free5);
+	g_free (free6);
+	g_free (free7);
+	g_free (free8);
+	g_free (free9);
+	g_free (public_dir);
+
+	if (!res) {
+		fprintf (stderr, "error spawning httpd: %s\n",
+			 error->message);
+		g_error_free (error);
+		g_free (pid_filename);
+		return FALSE;
+	}
+
+	if (status != 0) {
+		g_free (pid_filename);
+		return FALSE;
+	}
+
+	got_pidfile = FALSE;
+	error = NULL;
+	for (i = 0; i < 5; i++) {
+		if (error != NULL)
+			g_error_free (error);
+		error = NULL;
+		if (g_file_get_contents (pid_filename, &pidfile, NULL, &error)) {
+			got_pidfile = TRUE;
+			*pid_out = atoi (pidfile);
+			g_free (pidfile);
+			break;
+		}
+		sleep (1);
+	}
+
+	g_free (pid_filename);
+
+	if (!got_pidfile) {
+		fprintf (stderr, "error opening httpd pidfile: %s\n", error->message);
+		g_error_free (error);
+		return FALSE;
+	}
+	return TRUE;
+}
+
+static void
+kill_httpd (void)
+{
+	if (httpd_pid != 0) {
+		kill (httpd_pid, SIGTERM);
+
+		/* Allow child time to die, we can't waitpid, because its
+		   not a direct child */
+		sleep (1);
+	}
+	httpd_pid = 0;
+}
+
+void
+http_up (void)
+{
+	guint port;
+
+	port = get_port ();
+	if (!spawn_httpd (port, &httpd_pid)) {
+		fprintf (stderr, "spawning httpd failed\n");
+	}
+}
+
+void
+http_down (void)
+{
+	kill_httpd ();
+}
+
+gboolean
+http_init (void)
+{
+	return TRUE;
+}
+
+pid_t
+http_get_pid (void)
+{
+	return httpd_pid;
+}
+
+
+
+ + + diff --git a/2020-06-12-004111-9546-cppcheck@0ac8ecb990d2_master/2.html b/2020-06-12-004111-9546-cppcheck@0ac8ecb990d2_master/2.html new file mode 100644 index 0000000..d61baec --- /dev/null +++ b/2020-06-12-004111-9546-cppcheck@0ac8ecb990d2_master/2.html @@ -0,0 +1,1272 @@ + + + + + + Cppcheck - HTML report - mate-user-share + + + + + + + +
+
  1
+  2
+  3
+  4
+  5
+  6
+  7
+  8
+  9
+ 10
+ 11
+ 12
+ 13
+ 14
+ 15
+ 16
+ 17
+ 18
+ 19
+ 20
+ 21
+ 22
+ 23
+ 24
+ 25
+ 26
+ 27
+ 28
+ 29
+ 30
+ 31
+ 32
+ 33
+ 34
+ 35
+ 36
+ 37
+ 38
+ 39
+ 40
+ 41
+ 42
+ 43
+ 44
+ 45
+ 46
+ 47
+ 48
+ 49
+ 50
+ 51
+ 52
+ 53
+ 54
+ 55
+ 56
+ 57
+ 58
+ 59
+ 60
+ 61
+ 62
+ 63
+ 64
+ 65
+ 66
+ 67
+ 68
+ 69
+ 70
+ 71
+ 72
+ 73
+ 74
+ 75
+ 76
+ 77
+ 78
+ 79
+ 80
+ 81
+ 82
+ 83
+ 84
+ 85
+ 86
+ 87
+ 88
+ 89
+ 90
+ 91
+ 92
+ 93
+ 94
+ 95
+ 96
+ 97
+ 98
+ 99
+100
+101
+102
+103
+104
+105
+106
+107
+108
+109
+110
+111
+112
+113
+114
+115
+116
+117
+118
+119
+120
+121
+122
+123
+124
+125
+126
+127
+128
+129
+130
+131
+132
+133
+134
+135
+136
+137
+138
+139
+140
+141
+142
+143
+144
+145
+146
+147
+148
+149
+150
+151
+152
+153
+154
+155
+156
+157
+158
+159
+160
+161
+162
+163
+164
+165
+166
+167
+168
+169
+170
+171
+172
+173
+174
+175
+176
+177
+178
+179
+180
+181
+182
+183
+184
+185
+186
+187
+188
+189
+190
+191
+192
+193
+194
+195
+196
+197
+198
+199
+200
+201
+202
+203
+204
+205
+206
+207
+208
+209
+210
+211
+212
+213
+214
+215
+216
+217
+218
+219
+220
+221
+222
+223
+224
+225
+226
+227
+228
+229
+230
+231
+232
+233
+234
+235
+236
+237
+238
+239
+240
+241
+242
+243
+244
+245
+246
+247
+248
+249
+250
+251
+252
+253
+254
+255
+256
+257
+258
+259
+260
+261
+262
+263
+264
+265
+266
+267
+268
+269
+270
+271
+272
+273
+274
+275
+276
+277
+278
+279
+280
+281
+282
+283
+284
+285
+286
+287
+288
+289
+290
+291
+292
+293
+294
+295
+296
+297
+298
+299
+300
+301
+302
+303
+304
+305
+306
+307
+308
+309
+310
+311
+312
+313
+314
+315
+316
+317
+318
+319
+320
+321
+322
+323
+324
+325
+326
+327
+328
+329
+330
+331
+332
+333
+334
+335
+336
+337
+338
+339
+340
+341
+342
+343
+344
+345
+346
+347
+348
+349
+350
+351
+352
+353
+354
+355
+356
+357
+358
+359
+360
+361
+362
+363
+364
+365
+366
+367
+368
+369
+370
+371
+372
+373
+374
+375
+376
+377
+378
+379
+380
+381
+382
+383
+384
+385
+386
+387
+388
+389
+390
+391
+392
+393
+394
+395
+396
+397
+398
+399
+400
+401
+402
+403
+404
+405
+406
+407
+408
+409
+410
+411
+412
+413
+414
+415
+416
+417
+418
+419
+420
+421
+422
+423
+424
+425
+426
+427
+428
+429
+430
+431
+432
+433
+434
+435
+436
+437
+438
+439
+440
+441
+442
+443
+444
+445
+446
+447
+448
+449
+450
+451
+452
+453
+454
+455
+456
+457
+458
+459
+460
+461
+462
+463
+464
+465
+466
+467
+468
+469
+470
+471
+472
+473
+474
+475
+476
+477
+478
+479
+480
+481
+482
+483
+484
+485
+486
+487
+488
+489
+490
+491
+492
+493
+494
+495
+496
+497
+498
+499
+500
+501
+502
+503
+504
+505
+506
+507
+508
+509
+510
+511
+512
+513
+514
+515
+516
+517
+518
+519
+520
+521
+522
+523
+524
+525
+526
+527
+528
+529
+530
+531
+532
+533
+534
+535
+536
+537
+538
+539
+540
+541
+542
+543
+544
+545
+546
+547
+548
+549
+550
+551
+552
+553
+554
+555
+556
+557
+558
+559
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
+
+/*
+ *  Copyright (C) 2004-2008 Red Hat, Inc.
+ *
+ *  Caja is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU General Public License as
+ *  published by the Free Software Foundation; either version 2 of the
+ *  License, or (at your option) any later version.
+ *
+ *  Caja is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  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
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ *  Authors: Bastien Nocera <hadess@hadess.net>
+ *
+ */
+
+#include "config.h"
+
+#include <glib.h>
+#include <glib/gi18n.h>
+#include <gio/gio.h>
+#include <gdk/gdk.h>
+#include <gtk/gtk.h>
+#include <libnotify/notify.h>
+#include <dbus/dbus-glib.h>
+#include <dbus/dbus-glib-lowlevel.h>
+#include <canberra-gtk.h>
+
+#include <string.h>
+
+#include "marshal.h"
+#include "obexpush.h"
+#include "user_share-common.h"
+#include "user_share-private.h"
+
+#define DBUS_TYPE_G_STRING_VARIANT_HASHTABLE (dbus_g_type_get_map ("GHashTable", G_TYPE_STRING, G_TYPE_STRING))
+
+#define GSETTINGS_SCHEMA "org.mate.FileSharing"
+
+static DBusGConnection *connection = NULL;<--- Shadowed declaration
+static DBusGProxy *manager_proxy = NULL;
+static DBusGProxy *server_proxy = NULL;
+static AcceptSetting accept_setting = -1;
+static gboolean show_notifications = FALSE;
+
+static GtkStatusIcon *statusicon = NULL;
+static guint num_notifications = 0;
+
+static void
+hide_statusicon (void)
+{
+	num_notifications--;
+	if (num_notifications == 0)
+		gtk_status_icon_set_visible (statusicon, FALSE);
+}
+
+static void
+on_close_notification (NotifyNotification *notification)
+{
+	hide_statusicon ();
+	g_object_unref (notification);
+}
+
+static void
+notification_launch_action_on_file_cb (NotifyNotification *notification,
+				       const char *action,
+				       const char *file_uri)
+{
+	GdkScreen *screen;
+	GAppLaunchContext *ctx;
+	GTimeVal val;
+
+	g_assert (action != NULL);
+
+	g_get_current_time (&val);
+
+	ctx = G_APP_LAUNCH_CONTEXT (gdk_app_launch_context_new ());
+	screen = gdk_screen_get_default ();
+	gdk_app_launch_context_set_screen (GDK_APP_LAUNCH_CONTEXT (ctx), screen);
+	gdk_app_launch_context_set_timestamp (GDK_APP_LAUNCH_CONTEXT (ctx), val.tv_sec);
+
+	/* We launch the file viewer for the file */
+	if (g_str_equal (action, "display") != FALSE) {
+		if (g_app_info_launch_default_for_uri (file_uri, ctx, NULL) == FALSE) {
+			g_warning ("Failed to launch the file viewer\n");
+		}
+	}
+
+	/* we open the Downloads folder */
+	if (g_str_equal (action, "reveal") != FALSE) {
+		GFile *file;
+		GFile *parent;
+		gchar *parent_uri;
+
+		file = g_file_new_for_uri (file_uri);
+		parent = g_file_get_parent (file);
+		parent_uri = g_file_get_uri (parent);
+		g_object_unref (file);
+		g_object_unref (parent);
+
+		if (!g_app_info_launch_default_for_uri (parent_uri, ctx, NULL)) {
+			g_warning ("Failed to launch the file manager\n");
+		}
+
+		g_free (parent_uri);
+	}
+
+	notify_notification_close (notification, NULL);
+	/* No need to call hide_statusicon(), closing the notification
+	 * will call the close callback */
+}
+
+static void
+show_notification (const char *filename)
+{
+	char *file_uri, *notification_text, *display, *mime_type;
+	NotifyNotification *notification;
+	ca_context *ctx;
+	GAppInfo *app;
+
+	file_uri = g_filename_to_uri (filename, NULL, NULL);
+	if (file_uri == NULL) {
+		g_warning ("Could not make a filename from '%s'", filename);
+		return;
+	}
+
+	display = g_filename_display_basename (filename);
+	/* Translators: %s is the name of the filename received */
+	notification_text = g_strdup_printf(_("You received \"%s\" via Bluetooth"), display);
+	g_free (display);
+	notification = notify_notification_new (_("You received a file"),
+								 notification_text,
+								 "dialog-information");
+
+	notify_notification_set_timeout (notification, NOTIFY_EXPIRES_DEFAULT);
+
+	mime_type = g_content_type_guess (filename, NULL, 0, NULL);
+	app = g_app_info_get_default_for_type (mime_type, FALSE);
+	if (app != NULL) {
+		g_object_unref (app);
+		notify_notification_add_action (notification, "display", _("Open File"),
+						(NotifyActionCallback) notification_launch_action_on_file_cb,
+						g_strdup (file_uri), (GFreeFunc) g_free);
+	}
+	notify_notification_add_action (notification, "reveal", _("Reveal File"),
+					(NotifyActionCallback) notification_launch_action_on_file_cb,
+					g_strdup (file_uri), (GFreeFunc) g_free);
+
+	g_free (file_uri);
+
+	g_signal_connect (G_OBJECT (notification), "closed", G_CALLBACK (on_close_notification), notification);
+
+	if (!notify_notification_show (notification, NULL)) {
+		g_warning ("failed to send notification\n");
+	}
+	g_free (notification_text);
+
+	/* Now we do the audio notification */
+	ctx = ca_gtk_context_get ();
+	ca_context_play (ctx, 0,
+			 CA_PROP_EVENT_ID, "complete-download",
+			 CA_PROP_EVENT_DESCRIPTION, _("File reception complete"),
+			 NULL);
+}
+
+static void
+show_icon (void)
+{
+	if (statusicon == NULL) {
+		statusicon = gtk_status_icon_new_from_icon_name ("mate-obex-server");
+	} else {
+		gtk_status_icon_set_visible (statusicon, TRUE);
+	}
+	num_notifications++;
+}
+
+static gboolean
+device_is_authorised (const char *bdaddr)
+{
+	DBusGConnection *connection;<--- Shadow variable
+	DBusGProxy *manager;
+	GError *error = NULL;
+	GPtrArray *adapters;
+	gboolean retval = FALSE;
+	guint i;
+
+	connection = dbus_g_bus_get (DBUS_BUS_SYSTEM, NULL);
+	if (connection == NULL)
+		return FALSE;
+
+	manager = dbus_g_proxy_new_for_name (connection, "org.bluez",
+					     "/", "org.bluez.Manager");
+	if (manager == NULL) {
+		dbus_g_connection_unref (connection);
+		return FALSE;
+	}
+
+	if (dbus_g_proxy_call (manager, "ListAdapters", &error, G_TYPE_INVALID, dbus_g_type_get_collection ("GPtrArray", DBUS_TYPE_G_OBJECT_PATH), &adapters, G_TYPE_INVALID) == FALSE) {
+		g_object_unref (manager);
+		dbus_g_connection_unref (connection);
+		return FALSE;
+	}
+
+	for (i = 0; i < adapters->len; i++) {
+		DBusGProxy *adapter, *device;
+		char *device_path;
+		GHashTable *props;
+
+		g_debug ("checking adapter %s", (gchar *) g_ptr_array_index (adapters, i));
+
+		adapter = dbus_g_proxy_new_for_name (connection, "org.bluez",
+						    g_ptr_array_index (adapters, i), "org.bluez.Adapter");
+
+		if (dbus_g_proxy_call (adapter, "FindDevice", NULL,
+				       G_TYPE_STRING, bdaddr, G_TYPE_INVALID,
+				       DBUS_TYPE_G_OBJECT_PATH, &device_path, G_TYPE_INVALID) == FALSE)
+		{
+			g_object_unref (adapter);
+			continue;
+		}
+
+		device = dbus_g_proxy_new_for_name (connection, "org.bluez", device_path, "org.bluez.Device");
+
+		if (dbus_g_proxy_call (device, "GetProperties", NULL,
+				       G_TYPE_INVALID, dbus_g_type_get_map ("GHashTable", G_TYPE_STRING, G_TYPE_VALUE),
+				       &props, G_TYPE_INVALID) != FALSE)
+		{
+			GValue *value;
+			gboolean bonded;
+
+			value = g_hash_table_lookup (props, "Paired");
+			bonded = g_value_get_boolean (value);
+			g_message ("%s is %s", bdaddr, bonded ? "bonded" : "not bonded");
+
+			if (bonded) {
+				g_hash_table_destroy (props);
+				g_object_unref (device);
+				g_object_unref (adapter);
+				retval = TRUE;
+				break;
+			}
+		}
+		g_object_unref(adapter);
+	}
+
+	g_ptr_array_free (adapters, TRUE);
+
+	g_object_unref(manager);
+	dbus_g_connection_unref(connection);
+
+	return retval;
+}
+
+static void
+transfer_started_cb (DBusGProxy *session,
+		     const char *filename,
+		     const char *local_path,
+		     guint64 size,
+		     gpointer user_data)
+{
+	GHashTable *dict;
+	DBusGProxy *server = (DBusGProxy *) user_data;
+	GError *error = NULL;
+	gboolean authorise;
+
+	g_message ("transfer started on %s", local_path);
+	g_object_set_data_full (G_OBJECT (session), "filename", g_strdup (local_path), (GDestroyNotify) g_free);
+
+	show_icon ();
+
+	/* First transfer of the session */
+	if (g_object_get_data (G_OBJECT (session), "bdaddr") == NULL) {
+		const char *bdaddr;
+
+		if (dbus_g_proxy_call (server, "GetServerSessionInfo", &error,
+				       DBUS_TYPE_G_OBJECT_PATH, dbus_g_proxy_get_path (session), G_TYPE_INVALID,
+				       DBUS_TYPE_G_STRING_VARIANT_HASHTABLE, &dict, G_TYPE_INVALID) == FALSE) {
+			g_printerr ("Getting Server session info failed: %s\n",
+				    error->message);
+			g_error_free (error);
+			return;
+		}
+
+		bdaddr = g_hash_table_lookup (dict, "BluetoothAddress");
+		g_message ("transfer started for device %s", bdaddr);
+
+		g_object_set_data_full (G_OBJECT (session), "bdaddr", g_strdup (bdaddr), (GDestroyNotify) g_free);
+		/* Initial accept method is undefined, we do that lower down */
+		g_object_set_data (G_OBJECT (session), "accept-method", GINT_TO_POINTER (-1));
+		g_hash_table_destroy (dict);
+	}
+
+	/* Accept method changed */
+	if (GPOINTER_TO_INT (g_object_get_data (G_OBJECT (session), "accept-method")) != accept_setting) {
+		const char *bdaddr;
+
+		bdaddr = g_object_get_data (G_OBJECT (session), "bdaddr");
+
+		if (bdaddr == NULL) {
+			g_warning ("Couldn't get the Bluetooth address for the device, rejecting the transfer");
+			authorise = FALSE;
+		} else if (accept_setting == ACCEPT_ALWAYS) {
+			authorise = TRUE;
+		} else if (accept_setting == ACCEPT_BONDED) {
+			authorise = device_is_authorised (bdaddr);
+		} else {
+			//FIXME implement
+			g_warning ("\"Ask\" authorisation method not implemented");
+			authorise = FALSE;
+		}
+		g_object_set_data (G_OBJECT (session), "authorise", GINT_TO_POINTER (authorise));
+	}
+
+	g_message ("accept_setting: %d", accept_setting);
+
+	authorise = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (session), "authorise"));
+	if (authorise != FALSE) {
+		if (dbus_g_proxy_call (session, "Accept", &error, G_TYPE_INVALID, G_TYPE_INVALID) == FALSE) {
+			g_printerr ("Failed to accept file transfer: %s\n", error->message);
+			g_error_free (error);
+			return;
+		}
+		g_message ("authorised transfer");
+	} else {
+		if (dbus_g_proxy_call (session, "Reject", &error, G_TYPE_INVALID, G_TYPE_INVALID) == FALSE) {
+			g_printerr ("Failed to reject file transfer: %s\n", error->message);
+			g_error_free (error);
+			return;
+		}
+		g_message ("rejected transfer");
+		g_object_set_data (G_OBJECT (session), "filename", NULL);
+	}
+}
+
+static void
+transfer_completed_cb (DBusGProxy *session,
+		       gpointer user_data)
+{
+	GSettings *settings;
+	gboolean display_notify;
+	const char *filename;
+
+	filename = (const char *) g_object_get_data (G_OBJECT (session), "filename");
+
+	g_message ("file finish transfer: %s", filename);
+
+	if (filename == NULL)
+		return;
+
+	settings = g_settings_new (GSETTINGS_SCHEMA);
+	display_notify = g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_OBEXPUSH_NOTIFY);
+	g_object_unref (settings);
+
+	if (display_notify) {
+		show_notification (filename);
+	} else {
+		hide_statusicon ();
+	}
+	g_object_set_data (G_OBJECT (session), "filename", NULL);
+}
+
+static void
+cancelled_cb (DBusGProxy *session,
+	      gpointer user_data)
+{
+	//FIXME implement properly, we never actually finished the transfer
+	g_message ("transfered was cancelled by the sender");
+	transfer_completed_cb (session, user_data);
+	hide_statusicon ();
+}
+
+static void
+error_occurred_cb (DBusGProxy *session,
+		   const char *error_name,
+		   const char *error_message,
+		   gpointer user_data)
+{
+	//FIXME implement properly
+	g_message ("transfer error occurred: %s", error_message);
+	transfer_completed_cb (session, user_data);
+}
+
+static void
+session_created_cb (DBusGProxy *server, const char *session_path, gpointer user_data)
+{
+	DBusGProxy *session;
+
+	session = dbus_g_proxy_new_for_name (connection,
+					     "org.openobex",
+					     session_path,
+					     "org.openobex.ServerSession");
+
+	dbus_g_proxy_add_signal (session, "TransferStarted",
+				 G_TYPE_STRING, G_TYPE_STRING, G_TYPE_UINT64, G_TYPE_INVALID);
+	dbus_g_proxy_connect_signal(session, "TransferStarted",
+				    G_CALLBACK (transfer_started_cb), server, NULL);
+	dbus_g_proxy_add_signal (session, "TransferCompleted",
+				 G_TYPE_INVALID, G_TYPE_INVALID);
+	dbus_g_proxy_connect_signal(session, "TransferCompleted",
+				    G_CALLBACK (transfer_completed_cb), server, NULL);
+	dbus_g_proxy_add_signal (session, "Cancelled",
+				 G_TYPE_INVALID, G_TYPE_INVALID);
+	dbus_g_proxy_connect_signal(session, "Cancelled",
+				    G_CALLBACK (cancelled_cb), server, NULL);
+	dbus_g_proxy_add_signal (session, "ErrorOccurred",
+				 G_TYPE_INVALID, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INVALID);
+	dbus_g_proxy_connect_signal(session, "ErrorOccurred",
+				    G_CALLBACK (error_occurred_cb), server, NULL);
+}
+
+void
+obexpush_up (void)
+{
+	GError *err = NULL;
+	char *download_dir, *server;
+
+	server = NULL;
+	if (manager_proxy == NULL) {
+		manager_proxy = dbus_g_proxy_new_for_name (connection,
+							   "org.openobex",
+							   "/org/openobex",
+							   "org.openobex.Manager");
+		if (dbus_g_proxy_call (manager_proxy, "CreateBluetoothServer",
+				       &err, G_TYPE_STRING, "00:00:00:00:00:00", G_TYPE_STRING, "opp", G_TYPE_BOOLEAN, FALSE, G_TYPE_INVALID,
+				       DBUS_TYPE_G_OBJECT_PATH, &server, G_TYPE_INVALID) == FALSE) {
+			g_printerr ("Creating Bluetooth ObexPush server failed: %s\n",
+				    err->message);
+			g_error_free (err);
+			g_object_unref (manager_proxy);
+			manager_proxy = NULL;
+			return;
+		}
+	}
+
+	download_dir = lookup_download_dir ();
+
+	if (server_proxy == NULL) {
+		server_proxy = dbus_g_proxy_new_for_name (connection,
+							   "org.openobex",
+							   server,
+							   "org.openobex.Server");
+		g_free (server);
+
+		dbus_g_proxy_add_signal (server_proxy, "SessionCreated",
+					 DBUS_TYPE_G_OBJECT_PATH, G_TYPE_INVALID);
+		dbus_g_proxy_connect_signal(server_proxy, "SessionCreated",
+					    G_CALLBACK (session_created_cb), NULL, NULL);
+	}
+
+	if (dbus_g_proxy_call (server_proxy, "Start", &err,
+			   G_TYPE_STRING, download_dir, G_TYPE_BOOLEAN, TRUE, G_TYPE_BOOLEAN, FALSE, G_TYPE_INVALID,
+			   G_TYPE_INVALID) == FALSE) {
+		if (g_error_matches (err, DBUS_GERROR, DBUS_GERROR_REMOTE_EXCEPTION) != FALSE &&
+		    dbus_g_error_has_name (err, "org.openobex.Error.Started") != FALSE) {
+		    	g_error_free (err);
+		    	g_message ("already started, ignoring error");
+		    	g_free (download_dir);
+		    	return;
+		}
+		g_printerr ("Starting Bluetooth ObexPush server failed: %s\n",
+			    err->message);
+		g_error_free (err);
+		g_free (download_dir);
+		g_object_unref (server_proxy);
+		server_proxy = NULL;
+		g_object_unref (manager_proxy);
+		manager_proxy = NULL;
+		return;
+	}
+
+	g_free (download_dir);
+}
+
+static void
+obexpush_stop (gboolean stop_manager)
+{
+	GError *err = NULL;
+
+	if (server_proxy == NULL)
+		return;
+
+	if (dbus_g_proxy_call (server_proxy, "Close", &err, G_TYPE_INVALID, G_TYPE_INVALID) == FALSE) {
+		if (g_error_matches (err, DBUS_GERROR, DBUS_GERROR_REMOTE_EXCEPTION) == FALSE ||
+		    dbus_g_error_has_name (err, "org.openobex.Error.NotStarted") == FALSE) {
+			g_printerr ("Stopping Bluetooth ObexPush server failed: %s\n",
+				    err->message);
+			g_error_free (err);
+			return;
+		}
+		g_error_free (err);
+	}
+
+	if (stop_manager != FALSE) {
+		g_object_unref (server_proxy);
+		server_proxy = NULL;
+		g_object_unref (manager_proxy);
+		manager_proxy = NULL;
+	}
+
+	//FIXME stop all the notifications
+}
+
+void
+obexpush_down (void)
+{
+	obexpush_stop (TRUE);
+}
+
+void
+obexpush_restart (void)
+{
+	obexpush_stop (FALSE);
+	obexpush_up ();
+}
+
+gboolean
+obexpush_init (void)
+{
+	GError *err = NULL;
+
+	connection = dbus_g_bus_get (DBUS_BUS_SESSION, &err);
+	if (connection == NULL) {
+		g_printerr ("Connecting to session bus failed: %s\n",
+			    err->message);
+		g_error_free (err);
+		return FALSE;
+	}
+
+	dbus_g_object_register_marshaller (marshal_VOID__STRING_STRING_UINT64,
+					   G_TYPE_NONE,
+					   G_TYPE_STRING, G_TYPE_STRING, G_TYPE_UINT64, G_TYPE_INVALID);
+
+	if (!notify_init("mate-user-share")) {
+		g_warning("Unable to initialize the notification system\n");
+        }
+
+	dbus_connection_set_exit_on_disconnect (dbus_g_connection_get_connection (connection), FALSE);
+
+	return TRUE;
+}
+
+void
+obexpush_set_accept_files_policy (AcceptSetting setting)
+{
+	accept_setting = setting;
+}
+
+void
+obexpush_set_notify (gboolean enabled)
+{
+	show_notifications = enabled;
+}
+
+
+
+ + + diff --git a/2020-06-12-004111-9546-cppcheck@0ac8ecb990d2_master/3.html b/2020-06-12-004111-9546-cppcheck@0ac8ecb990d2_master/3.html new file mode 100644 index 0000000..f31a1bc --- /dev/null +++ b/2020-06-12-004111-9546-cppcheck@0ac8ecb990d2_master/3.html @@ -0,0 +1,748 @@ + + + + + + Cppcheck - HTML report - mate-user-share + + + + + + + +
+
  1
+  2
+  3
+  4
+  5
+  6
+  7
+  8
+  9
+ 10
+ 11
+ 12
+ 13
+ 14
+ 15
+ 16
+ 17
+ 18
+ 19
+ 20
+ 21
+ 22
+ 23
+ 24
+ 25
+ 26
+ 27
+ 28
+ 29
+ 30
+ 31
+ 32
+ 33
+ 34
+ 35
+ 36
+ 37
+ 38
+ 39
+ 40
+ 41
+ 42
+ 43
+ 44
+ 45
+ 46
+ 47
+ 48
+ 49
+ 50
+ 51
+ 52
+ 53
+ 54
+ 55
+ 56
+ 57
+ 58
+ 59
+ 60
+ 61
+ 62
+ 63
+ 64
+ 65
+ 66
+ 67
+ 68
+ 69
+ 70
+ 71
+ 72
+ 73
+ 74
+ 75
+ 76
+ 77
+ 78
+ 79
+ 80
+ 81
+ 82
+ 83
+ 84
+ 85
+ 86
+ 87
+ 88
+ 89
+ 90
+ 91
+ 92
+ 93
+ 94
+ 95
+ 96
+ 97
+ 98
+ 99
+100
+101
+102
+103
+104
+105
+106
+107
+108
+109
+110
+111
+112
+113
+114
+115
+116
+117
+118
+119
+120
+121
+122
+123
+124
+125
+126
+127
+128
+129
+130
+131
+132
+133
+134
+135
+136
+137
+138
+139
+140
+141
+142
+143
+144
+145
+146
+147
+148
+149
+150
+151
+152
+153
+154
+155
+156
+157
+158
+159
+160
+161
+162
+163
+164
+165
+166
+167
+168
+169
+170
+171
+172
+173
+174
+175
+176
+177
+178
+179
+180
+181
+182
+183
+184
+185
+186
+187
+188
+189
+190
+191
+192
+193
+194
+195
+196
+197
+198
+199
+200
+201
+202
+203
+204
+205
+206
+207
+208
+209
+210
+211
+212
+213
+214
+215
+216
+217
+218
+219
+220
+221
+222
+223
+224
+225
+226
+227
+228
+229
+230
+231
+232
+233
+234
+235
+236
+237
+238
+239
+240
+241
+242
+243
+244
+245
+246
+247
+248
+249
+250
+251
+252
+253
+254
+255
+256
+257
+258
+259
+260
+261
+262
+263
+264
+265
+266
+267
+268
+269
+270
+271
+272
+273
+274
+275
+276
+277
+278
+279
+280
+281
+282
+283
+284
+285
+286
+287
+288
+289
+290
+291
/* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 8; tab-width: 8 -*-
+ *
+ * Copyright (C) 2003 Novell, Inc.
+ * Copyright (C) 2003-2004 Red Hat, Inc.
+ * Copyright (C) 2005 William Jon McCann <mccann@jhu.edu>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * 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 Foundation, Inc., 51 Franklin St, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ *
+ */
+
+#include "config.h"
+
+#include <stdlib.h>
+#include <string.h>
+#include <glib/gi18n-lib.h>
+#include <gtk/gtk.h>
+#include <libcaja-extension/caja-menu-provider.h>
+#include <libcaja-extension/caja-location-widget-provider.h>
+
+#ifdef HAVE_BLUETOOTH
+#include <bluetooth-client.h>
+#endif
+
+#include "caja-share-bar.h"
+#include "user_share-common.h"
+
+#define CAJA_TYPE_USER_SHARE  (caja_user_share_get_type ())
+#define CAJA_USER_SHARE(o)    (G_TYPE_CHECK_INSTANCE_CAST ((o), CAJA_TYPE_USER_SHARE, CajaUserShare))
+#define CAJA_IS_USER_SHARE(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), CAJA_TYPE_USER_SHARE))
+
+typedef struct
+{
+        GObject              parent_slot;
+} CajaUserShare;
+
+typedef struct
+{
+        GObjectClass parent_slot;
+} CajaUserShareClass;
+
+static GType caja_user_share_get_type      (void);
+static void  caja_user_share_register_type (GTypeModule *module);
+
+static void
+launch_process (char **argv, GtkWindow *parent)
+{
+        GError *error;
+        GtkWidget *dialog;
+
+        error = NULL;
+        if (!g_spawn_async (NULL,
+                            argv, NULL,
+                            0,
+                            NULL, NULL,
+                            NULL,
+                            &error)) {
+
+
+                dialog = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL, GTK_MESSAGE_WARNING,
+						 GTK_BUTTONS_OK, _("Unable to launch the Personal File Sharing preferences"));
+
+                gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog), "%s", error->message);
+
+                gtk_dialog_run (GTK_DIALOG (dialog));
+                gtk_widget_destroy (dialog);
+
+                g_error_free (error);
+        }
+}
+
+static void
+launch_prefs_on_window (GtkWindow *window)
+{
+        char *argv [2];
+
+        argv [0] = g_build_filename (BINDIR, "mate-file-share-properties", NULL);
+        argv [1] = NULL;
+
+        launch_process (argv, window);
+
+        g_free (argv [0]);
+}
+
+static void
+bar_response_cb (CajaShareBar *bar,
+                 gint response,
+                 gpointer         data)
+{
+        if (response == CAJA_SHARE_BAR_RESPONSE_PREFERENCES) {
+                launch_prefs_on_window (GTK_WINDOW (data));
+        }
+}
+
+#ifdef HAVE_BLUETOOTH
+static void
+downloads_bar_set_from_bluetooth_status (GtkWidget *bar)
+{
+	BluetoothClient *client;
+	gboolean bt_powered;
+
+	client = g_object_get_data (G_OBJECT (bar), "bluetooth-client");
+	g_object_get (G_OBJECT (client),
+		      "default-adapter-powered", &bt_powered,
+		      NULL);
+	gtk_widget_set_visible (bar, bt_powered);
+}
+
+static void
+default_adapter_powered_cb (GObject    *gobject,
+			    GParamSpec *pspec,
+			    GtkWidget  *bar)
+{
+	downloads_bar_set_from_bluetooth_status (bar);
+}
+#endif /* HAVE_BLUETOOTH */
+
+static GtkWidget *
+caja_user_share_get_location_widget (CajaLocationWidgetProvider *iface,
+                                         const char                     *uri,
+                                         GtkWidget                      *window)
+{
+	GFile             *file;
+	GtkWidget         *bar;
+	guint              i;
+	gboolean           enable = FALSE;
+	GFile             *home;
+#ifdef HAVE_BLUETOOTH
+	const GUserDirectory special_dirs[] = { G_USER_DIRECTORY_PUBLIC_SHARE, G_USER_DIRECTORY_DOWNLOAD };
+
+	gboolean is_dir[] = { FALSE, FALSE };
+#else
+	const GUserDirectory special_dirs[] = { G_USER_DIRECTORY_PUBLIC_SHARE };
+
+	gboolean is_dir[] = { FALSE };
+#endif /* HAVE_BLUETOOTH */
+	file = g_file_new_for_uri (uri);
+	home = g_file_new_for_path (g_get_home_dir ());
+
+	/* We don't show anything in $HOME */
+	if (g_file_equal (home, file)) {
+		g_object_unref (home);
+		g_object_unref (file);
+		return NULL;
+	}
+
+	g_object_unref (home);
+
+	for (i = 0; i < G_N_ELEMENTS (special_dirs); i++) {
+		GFile *dir;
+		dir = lookup_dir_with_fallback (special_dirs[i]);
+		if (g_file_equal (dir, file)) {
+			enable = TRUE;
+			is_dir[i] = TRUE;
+		}
+		g_object_unref (dir);
+	}
+
+	g_object_unref (file);
+
+	if (enable == FALSE)
+		return NULL;
+
+	if (is_dir[0] != FALSE) {
+#ifdef HAVE_BLUETOOTH
+		if (is_dir[1] != FALSE) {
+			bar = caja_share_bar_new (_("May be used to share or receive files"));
+		} else {
+			bar = caja_share_bar_new (_("May be shared over the network or Bluetooth"));
+		}
+#else
+		bar = caja_share_bar_new (_("May be shared over the network"));
+#endif /* HAVE_BLUETOOTH */
+	} else {
+#ifdef HAVE_BLUETOOTH
+		BluetoothClient *client;
+
+		bar = caja_share_bar_new (_("May be used to receive files over Bluetooth"));
+
+		gtk_widget_set_no_show_all (bar, TRUE);
+		client = bluetooth_client_new ();
+		g_object_set_data_full (G_OBJECT (bar), "bluetooth-client", client, g_object_unref);
+		g_signal_connect (G_OBJECT (client), "notify::default-adapter-powered",
+				  G_CALLBACK (default_adapter_powered_cb), bar);
+		downloads_bar_set_from_bluetooth_status (bar);
+#endif /* HAVE_BLUETOOTH */
+	}
+
+	g_signal_connect (bar, "response",
+			  G_CALLBACK (bar_response_cb),
+			  window);
+
+	gtk_widget_show_all (bar);
+
+	return bar;
+}
+
+static void
+caja_user_share_location_widget_provider_iface_init (CajaLocationWidgetProviderIface *iface)
+{
+        iface->get_widget = caja_user_share_get_location_widget;
+}
+
+static void
+caja_user_share_instance_init (CajaUserShare *share)
+{
+
+}
+
+static void
+caja_user_share_class_init (CajaUserShareClass *klass)
+{
+
+}
+
+static GType share_type = 0;
+
+static GType
+caja_user_share_get_type (void)
+{
+        return share_type;
+}
+
+static void
+caja_user_share_register_type (GTypeModule *module)
+{
+        static const GTypeInfo info = {
+                sizeof (CajaUserShareClass),
+                (GBaseInitFunc) NULL,
+                (GBaseFinalizeFunc) NULL,
+                (GClassInitFunc) caja_user_share_class_init,
+                NULL,
+                NULL,
+                sizeof (CajaUserShare),
+                0,
+                (GInstanceInitFunc) caja_user_share_instance_init,
+        };
+
+        static const GInterfaceInfo location_widget_provider_iface_info = {
+                (GInterfaceInitFunc) caja_user_share_location_widget_provider_iface_init,
+                NULL,
+                NULL
+        };
+
+        share_type = g_type_module_register_type (module,
+                                                 G_TYPE_OBJECT,
+                                                 "CajaUserShare",
+                                                 &info, 0);
+
+        g_type_module_add_interface (module,
+                                     share_type,
+                                     CAJA_TYPE_LOCATION_WIDGET_PROVIDER,
+                                     &location_widget_provider_iface_info);
+}
+
+void
+caja_module_initialize (GTypeModule *module)
+{
+        caja_user_share_register_type (module);
+        bindtextdomain (GETTEXT_PACKAGE, MATELOCALEDIR);
+        bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
+}
+
+void
+caja_module_shutdown (void)
+{
+}
+
+void
+caja_module_list_types (const GType **types,
+                            int          *num_types)
+{
+        static GType type_list [1];
+
+        type_list[0] = CAJA_TYPE_USER_SHARE;
+
+        *types = type_list;
+        *num_types = 1;
+}
+
+
+
+ + + diff --git a/2020-06-12-004111-9546-cppcheck@0ac8ecb990d2_master/4.html b/2020-06-12-004111-9546-cppcheck@0ac8ecb990d2_master/4.html new file mode 100644 index 0000000..462c100 --- /dev/null +++ b/2020-06-12-004111-9546-cppcheck@0ac8ecb990d2_master/4.html @@ -0,0 +1,336 @@ + + + + + + Cppcheck - HTML report - mate-user-share + + + + + + + +
+
 1
+ 2
+ 3
+ 4
+ 5
+ 6
+ 7
+ 8
+ 9
+10
+11
+12
+13
+14
+15
+16
+17
+18
+19
+20
+21
+22
+23
+24
+25
+26
+27
+28
+29
+30
+31
+32
+33
+34
+35
+36
+37
+38
+39
+40
+41
+42
+43
+44
+45
+46
+47
+48
+49
+50
+51
+52
+53
+54
+55
+56
+57
+58
+59
+60
+61
+62
+63
+64
+65
+66
+67
+68
+69
+70
+71
+72
+73
+74
+75
+76
+77
+78
+79
+80
+81
+82
+83
+84
+85
+86
+87
+88
+89
+90
+91
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
+
+/*
+ *  Copyright (C) 2004-2009 Red Hat, Inc.
+ *
+ *  Caja is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU General Public License as
+ *  published by the Free Software Foundation; either version 2 of the
+ *  License, or (at your option) any later version.
+ *
+ *  Caja is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  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
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ *  Authors: Alexander Larsson <alexl@redhat.com>
+ *  Bastien Nocera <hadess@hadess.net>
+ *
+ */
+
+#include <string.h>
+
+#include "user_share-common.h"
+
+static char *
+lookup_special_dir (GUserDirectory directory,
+		    const char *name,
+		    gboolean create_dir)
+{
+	const char *special_dir;
+	char *dir;
+
+	special_dir = g_get_user_special_dir (directory);
+	if (special_dir != NULL && strcmp (special_dir, g_get_home_dir ()) != 0) {
+		if (create_dir != FALSE)
+			g_mkdir_with_parents (special_dir, 0755);
+		return g_strdup (special_dir);
+	}
+
+	dir = g_build_filename (g_get_home_dir (), name, NULL);
+	if (create_dir != FALSE)
+		g_mkdir_with_parents (dir, 0755);
+	return dir;
+}
+
+char *
+lookup_public_dir (void)
+{
+	return lookup_special_dir (G_USER_DIRECTORY_PUBLIC_SHARE,
+				   "Public",
+				   TRUE);
+}
+
+char *
+lookup_download_dir (void)
+{
+	return lookup_special_dir (G_USER_DIRECTORY_DOWNLOAD,
+				   "Downloads",
+				   TRUE);
+}
+
+GFile *
+lookup_dir_with_fallback (GUserDirectory directory)
+{
+	GFile *file;
+	char *path;
+	const char *name;
+
+	if (directory == G_USER_DIRECTORY_PUBLIC_SHARE)
+		name = "Public";
+	else if (directory == G_USER_DIRECTORY_DOWNLOAD)
+		name = "Downloads";
+	else
+		g_assert_not_reached ();
+
+	path = lookup_special_dir (directory,
+				   name,<--- Uninitialized variable: name
+				   FALSE);
+
+	if (path == NULL)
+		return NULL;
+
+	file = g_file_new_for_path (path);
+	g_free (path);
+
+	return file;
+}
+
+
+
+ + + diff --git a/2020-06-12-004111-9546-cppcheck@0ac8ecb990d2_master/5.html b/2020-06-12-004111-9546-cppcheck@0ac8ecb990d2_master/5.html new file mode 100644 index 0000000..5dde496 --- /dev/null +++ b/2020-06-12-004111-9546-cppcheck@0ac8ecb990d2_master/5.html @@ -0,0 +1,1166 @@ + + + + + + Cppcheck - HTML report - mate-user-share + + + + + + + +
+
  1
+  2
+  3
+  4
+  5
+  6
+  7
+  8
+  9
+ 10
+ 11
+ 12
+ 13
+ 14
+ 15
+ 16
+ 17
+ 18
+ 19
+ 20
+ 21
+ 22
+ 23
+ 24
+ 25
+ 26
+ 27
+ 28
+ 29
+ 30
+ 31
+ 32
+ 33
+ 34
+ 35
+ 36
+ 37
+ 38
+ 39
+ 40
+ 41
+ 42
+ 43
+ 44
+ 45
+ 46
+ 47
+ 48
+ 49
+ 50
+ 51
+ 52
+ 53
+ 54
+ 55
+ 56
+ 57
+ 58
+ 59
+ 60
+ 61
+ 62
+ 63
+ 64
+ 65
+ 66
+ 67
+ 68
+ 69
+ 70
+ 71
+ 72
+ 73
+ 74
+ 75
+ 76
+ 77
+ 78
+ 79
+ 80
+ 81
+ 82
+ 83
+ 84
+ 85
+ 86
+ 87
+ 88
+ 89
+ 90
+ 91
+ 92
+ 93
+ 94
+ 95
+ 96
+ 97
+ 98
+ 99
+100
+101
+102
+103
+104
+105
+106
+107
+108
+109
+110
+111
+112
+113
+114
+115
+116
+117
+118
+119
+120
+121
+122
+123
+124
+125
+126
+127
+128
+129
+130
+131
+132
+133
+134
+135
+136
+137
+138
+139
+140
+141
+142
+143
+144
+145
+146
+147
+148
+149
+150
+151
+152
+153
+154
+155
+156
+157
+158
+159
+160
+161
+162
+163
+164
+165
+166
+167
+168
+169
+170
+171
+172
+173
+174
+175
+176
+177
+178
+179
+180
+181
+182
+183
+184
+185
+186
+187
+188
+189
+190
+191
+192
+193
+194
+195
+196
+197
+198
+199
+200
+201
+202
+203
+204
+205
+206
+207
+208
+209
+210
+211
+212
+213
+214
+215
+216
+217
+218
+219
+220
+221
+222
+223
+224
+225
+226
+227
+228
+229
+230
+231
+232
+233
+234
+235
+236
+237
+238
+239
+240
+241
+242
+243
+244
+245
+246
+247
+248
+249
+250
+251
+252
+253
+254
+255
+256
+257
+258
+259
+260
+261
+262
+263
+264
+265
+266
+267
+268
+269
+270
+271
+272
+273
+274
+275
+276
+277
+278
+279
+280
+281
+282
+283
+284
+285
+286
+287
+288
+289
+290
+291
+292
+293
+294
+295
+296
+297
+298
+299
+300
+301
+302
+303
+304
+305
+306
+307
+308
+309
+310
+311
+312
+313
+314
+315
+316
+317
+318
+319
+320
+321
+322
+323
+324
+325
+326
+327
+328
+329
+330
+331
+332
+333
+334
+335
+336
+337
+338
+339
+340
+341
+342
+343
+344
+345
+346
+347
+348
+349
+350
+351
+352
+353
+354
+355
+356
+357
+358
+359
+360
+361
+362
+363
+364
+365
+366
+367
+368
+369
+370
+371
+372
+373
+374
+375
+376
+377
+378
+379
+380
+381
+382
+383
+384
+385
+386
+387
+388
+389
+390
+391
+392
+393
+394
+395
+396
+397
+398
+399
+400
+401
+402
+403
+404
+405
+406
+407
+408
+409
+410
+411
+412
+413
+414
+415
+416
+417
+418
+419
+420
+421
+422
+423
+424
+425
+426
+427
+428
+429
+430
+431
+432
+433
+434
+435
+436
+437
+438
+439
+440
+441
+442
+443
+444
+445
+446
+447
+448
+449
+450
+451
+452
+453
+454
+455
+456
+457
+458
+459
+460
+461
+462
+463
+464
+465
+466
+467
+468
+469
+470
+471
+472
+473
+474
+475
+476
+477
+478
+479
+480
+481
+482
+483
+484
+485
+486
+487
+488
+489
+490
+491
+492
+493
+494
+495
+496
+497
+498
+499
+500
+501
+502
+503
+504
+505
+506
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
+
+/*
+ *  Copyright (C) 2004-2008 Red Hat, Inc.
+ *
+ *  Caja is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU General Public License as
+ *  published by the Free Software Foundation; either version 2 of the
+ *  License, or (at your option) any later version.
+ *
+ *  Caja is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  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
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ *  Authors: Alexander Larsson <alexl@redhat.com>
+ *
+ */
+
+#include "config.h"
+
+#include <gdk/gdkx.h>
+#include <gtk/gtk.h>
+#include <glib/gi18n.h>
+#include <glib/gstdio.h>
+#include <gio/gio.h>
+#include <X11/Xlib.h>
+
+#include "user_share-private.h"
+#include "user_share-common.h"
+#include "http.h"
+
+#ifdef HAVE_BLUETOOTH
+#include <bluetooth-client.h>
+
+#include "obexftp.h"
+#include "obexpush.h"
+
+#endif /* HAVE_BLUETOOTH */
+
+#include <gio/gio.h>
+
+#include <stdarg.h>
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <signal.h>
+#include <unistd.h>
+
+static guint disabled_timeout_tag = 0;
+static GSettings* settings;<--- Shadowed declaration<--- Shadowed declaration<--- Shadowed declaration
+
+#define GSETTINGS_SCHEMA "org.mate.FileSharing"
+#define GSETTINGS_KEY_FILE_SHARING_ENABLED "enabled"
+#define GSETTINGS_KEY_FILE_SHARING_REQUIRE_PASSWORD "require-password"
+
+#ifdef HAVE_BLUETOOTH
+/* MATE Session */
+#define MATE_SESSION_DBUS_NAME      "org.gnome.SessionManager"
+#define MATE_SESSION_DBUS_OBJECT    "/org/gnome/SessionManager"
+#define MATE_SESSION_DBUS_INTERFACE "org.gnome.SessionManager"
+
+static GDBusProxy *session_proxy = NULL;
+static gboolean has_console = TRUE;
+
+static BluetoothClient *client = NULL;
+static gboolean bluetoothd_enabled = FALSE;
+
+#define OBEX_ENABLED (bluetoothd_enabled && has_console)
+
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_ENABLED "bluetooth-enabled"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_ALLOW_WRITE "bluetooth-allow-write"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_REQUIRE_PAIRING "bluetooth-require-pairing"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED "bluetooth-obexpush-enabled"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_ACCEPT_FILES "bluetooth-accept-files"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_NOTIFY "bluetooth-notify"
+
+
+static void
+obex_services_start (void)
+{
+	GSettings *settings;<--- Shadow variable
+
+	if (bluetoothd_enabled == FALSE ||
+	    has_console == FALSE)
+	    	return;
+
+	settings = g_settings_new(GSETTINGS_SCHEMA);
+
+	if (g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED) == TRUE) {
+	    obexpush_up ();
+	}
+	if (g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_ENABLED) == TRUE) {
+	    obexftp_up ();
+	}
+
+	g_object_unref (client);
+}
+
+static void
+obex_services_shutdown (void)
+{
+	obexpush_down ();
+	obexftp_down ();
+}
+
+static void
+session_properties_changed_cb (GDBusProxy      *session,
+			       GVariant        *changed,
+			       char           **invalidated,
+			       gpointer         user_data)
+{
+	GVariant *v;
+
+	v = g_variant_lookup_value (changed, "SessionIsActive", G_VARIANT_TYPE_BOOLEAN);
+	if (v) {
+		has_console = g_variant_get_boolean (v);
+		g_debug ("Received session is active change: now %s", has_console ? "active" : "inactive");
+
+		if (has_console)
+			obex_services_start ();
+		else
+			obex_services_shutdown ();
+
+		g_variant_unref (v);
+	}
+}
+
+static gboolean
+is_session_active (void)
+{
+	GVariant *variant;
+	gboolean is_session_active = FALSE;
+
+	variant = g_dbus_proxy_get_cached_property (session_proxy,
+						    "SessionIsActive");
+	if (variant) {
+		is_session_active = g_variant_get_boolean (variant);
+		g_variant_unref (variant);
+ 	}
+
+	return is_session_active;
+}
+
+static void
+session_init (void)
+{
+	GError *error = NULL;
+
+	session_proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION,
+						       G_DBUS_PROXY_FLAGS_NONE,
+						       NULL,
+						       MATE_SESSION_DBUS_NAME,
+						       MATE_SESSION_DBUS_OBJECT,
+						       MATE_SESSION_DBUS_INTERFACE,
+						       NULL,
+						       &error);
+	if (session_proxy == NULL) {
+		g_warning ("Failed to get session proxy: %s", error->message);
+		g_error_free (error);
+		return;
+	}
+	g_signal_connect (session_proxy, "g-properties-changed",
+			  G_CALLBACK (session_properties_changed_cb),
+			  NULL);
+	has_console = is_session_active ();
+}
+
+static void
+default_adapter_changed (GObject    *gobject,
+			 GParamSpec *pspec,
+			 gpointer    user_data)
+{
+	char *adapter;
+	gboolean adapter_powered;
+
+	g_object_get (G_OBJECT (client),
+		      "default-adapter", &adapter,
+		      "default-adapter-powered", &adapter_powered,
+		      NULL);
+	if (adapter != NULL && *adapter != '\0') {
+		bluetoothd_enabled = adapter_powered;
+	} else {
+		bluetoothd_enabled = FALSE;
+	}
+
+	/* Were we called as init, or as a callback */
+	if (gobject != NULL) {
+		if (bluetoothd_enabled != FALSE)
+			obex_services_start ();
+		else
+			obex_services_shutdown ();
+	}
+}
+
+static void
+bluez_init (void)
+{
+	client = bluetooth_client_new ();
+	default_adapter_changed (NULL, NULL, NULL);
+	g_signal_connect (G_OBJECT (client), "notify::default-adapter",
+			  G_CALLBACK (default_adapter_changed), NULL);
+	g_signal_connect (G_OBJECT (client), "notify::default-adapter-powered",
+			  G_CALLBACK (default_adapter_changed), NULL);
+}
+#endif /* HAVE_BLUETOOTH */
+
+static gboolean
+file_sharing_enabled (void)
+{
+	gboolean enabled = TRUE;
+	settings = g_settings_new (GSETTINGS_SCHEMA);
+
+#ifdef HAVE_BLUETOOTH
+	if (g_settings_get_boolean (settings, FILE_SHARING_ENABLED) == FALSE &&
+	    g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_ENABLED) == FALSE &&
+	    g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED) == FALSE)
+#else /* HAVE_BLUETOOTH */
+	if (g_settings_get_boolean (settings, FILE_SHARING_ENABLED) == FALSE)
+#endif /* HAVE_BLUETOOTH */
+		enabled = FALSE;
+
+	g_object_unref (settings);
+
+	return enabled;
+}
+
+static void
+migrate_old_configuration (void)
+{
+	const char *old_config_dir;
+	const char *new_config_dir;
+
+	old_config_dir = g_build_filename (g_get_home_dir (), ".mate2", "user-share", NULL);
+	new_config_dir = g_build_filename (g_get_user_config_dir (), "user-share", NULL);
+	if (g_file_test (old_config_dir, G_FILE_TEST_IS_DIR))
+		g_rename (old_config_dir, new_config_dir);
+
+}
+
+static void
+require_password_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	/* Need to restart to get new password setting */
+	if (http_get_pid () != 0) {
+		http_down ();
+		http_up ();
+	}
+}
+
+/* File sharing was disabled for some time, exit now */
+/* If we re-enable it in the ui, this will be restarted anyway */
+static gboolean
+disabled_timeout_callback (gpointer user_data)
+{
+	GSettings *settings = (GSettings *) user_data;<--- Shadow variable
+	http_down ();
+
+#ifdef HAVE_BLUETOOTH
+	if (g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_ENABLED) == FALSE &&
+	    g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED) == FALSE)
+		_exit (0);
+#else /* HAVE_BLUETOOTH */
+	if (g_settings_get_boolean (settings, FILE_SHARING_ENABLED) == FALSE)
+		_exit (0);
+#endif /* HAVE_BLUETOOTH */
+	return FALSE;
+}
+
+static void
+file_sharing_enabled_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	gboolean enabled;
+
+	if (disabled_timeout_tag != 0) {
+		g_source_remove (disabled_timeout_tag);
+		disabled_timeout_tag = 0;
+	}
+
+	enabled = g_settings_get_boolean (settings,
+					 FILE_SHARING_ENABLED);
+	if (enabled) {
+		if (http_get_pid () == 0) {
+			http_up ();
+		}
+	} else {
+		http_down ();
+		disabled_timeout_tag = g_timeout_add_seconds (3,
+							      (GSourceFunc)disabled_timeout_callback,
+							      settings);
+	}
+}
+
+#ifdef HAVE_BLUETOOTH
+static void
+file_sharing_bluetooth_allow_write_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	if (g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_ENABLED) != FALSE)
+		obexftp_restart ();
+}
+
+static void
+file_sharing_bluetooth_require_pairing_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	if (g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_ENABLED) != FALSE) {
+		/* We need to fully reset the session,
+		 * otherwise the new setting isn't taken into account */
+		obexftp_down ();
+		obexftp_up ();
+	}
+}
+
+static void
+file_sharing_bluetooth_enabled_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	if (g_settings_get_boolean (settings,
+				   FILE_SHARING_BLUETOOTH_ENABLED) == FALSE) {
+		obexftp_down ();
+		if (g_settings_get_boolean (settings, FILE_SHARING_ENABLED) == FALSE &&
+		    g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED) == FALSE) {
+			_exit (0);
+		}
+	} else if (OBEX_ENABLED) {
+		obexftp_up ();
+	}
+}
+
+static void
+file_sharing_bluetooth_obexpush_enabled_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	if (g_settings_get_boolean (settings,
+				   FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED) == FALSE) {
+		obexpush_down ();
+		if (g_settings_get_boolean (settings, FILE_SHARING_ENABLED) == FALSE &&
+		    g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_ENABLED) == FALSE) {
+			_exit (0);
+		}
+	} else if (OBEX_ENABLED) {
+		obexpush_up ();
+	}
+}
+
+static void
+file_sharing_bluetooth_obexpush_accept_files_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	AcceptSetting setting;
+	char *str;
+
+	str = g_settings_get_string (settings, FILE_SHARING_BLUETOOTH_OBEXPUSH_ACCEPT_FILES);
+	setting = accept_setting_from_string (str);
+	g_free (str);
+
+	obexpush_set_accept_files_policy (setting);
+}
+
+static void
+file_sharing_bluetooth_obexpush_notify_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	obexpush_set_notify (g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_OBEXPUSH_NOTIFY));
+}
+#endif /* HAVE_BLUETOOTH */
+
+static RETSIGTYPE
+cleanup_handler (int sig)
+{
+	http_down ();
+#ifdef HAVE_BLUETOOTH
+	obexftp_down ();
+	obexpush_down ();
+#endif /* HAVE_BLUETOOTH */
+	_exit (2);
+}
+
+static int
+x_io_error_handler (Display *xdisplay)
+{
+	http_down ();
+#ifdef HAVE_BLUETOOTH
+	obexftp_down ();
+#endif /* HAVE_BLUETOOTH */
+	_exit (2);
+}
+
+int
+main (int argc, char **argv)
+{
+	GSettings *settings;<--- Shadow variable
+	Display *xdisplay;
+	G_GNUC_UNUSED int x_fd;
+	Window selection_owner;
+	Atom xatom;
+
+	bindtextdomain (GETTEXT_PACKAGE, MATELOCALEDIR);
+	bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
+	textdomain (GETTEXT_PACKAGE);
+
+	gtk_init (&argc, &argv);
+
+	if (g_strcmp0 (g_get_real_name (), "root") == 0) {
+		g_warning ("mate-user-share cannot be started as root for security reasons.");
+		return 1;
+	}
+
+	signal (SIGPIPE, SIG_IGN);
+	signal (SIGINT, cleanup_handler);
+	signal (SIGHUP, cleanup_handler);
+	signal (SIGTERM, cleanup_handler);
+
+	xdisplay = GDK_DISPLAY_XDISPLAY (gdk_display_get_default ());
+	if (xdisplay == NULL) {
+		g_warning ("Can't open display");
+		return 1;
+	}
+
+	xatom = XInternAtom (xdisplay, "_MATE_USER_SHARE", FALSE);
+	selection_owner = XGetSelectionOwner (xdisplay, xatom);
+
+	if (selection_owner != None) {
+		/* There is an owner already, quit */
+		return 1;
+	}
+
+	selection_owner = XCreateSimpleWindow (xdisplay,
+					       RootWindow (xdisplay, 0),
+					       0, 0, 1, 1,
+					       0, 0, 0);
+	XSetSelectionOwner (xdisplay, xatom, selection_owner, CurrentTime);
+
+	if (XGetSelectionOwner (xdisplay, xatom) != selection_owner) {
+		/* Didn't get the selection */
+		return 1;
+	}
+
+	migrate_old_configuration ();
+
+	if (!file_sharing_enabled ())
+		return 1;
+
+	settings = g_settings_new (GSETTINGS_SCHEMA);
+
+	x_fd = ConnectionNumber (xdisplay);
+	XSetIOErrorHandler (x_io_error_handler);
+
+	if (http_init () == FALSE)
+		return 1;
+#ifdef HAVE_BLUETOOTH
+	if (obexftp_init () == FALSE)
+		return 1;
+	if (obexpush_init () == FALSE)
+		return 1;
+#endif /* HAVE_BLUETOOTH */
+
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_ENABLED,
+			     G_CALLBACK (file_sharing_enabled_changed), NULL);
+
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_REQUIRE_PASSWORD,
+			     G_CALLBACK (require_password_changed), NULL);
+
+#ifdef HAVE_BLUETOOTH
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_ENABLED,
+			     G_CALLBACK (file_sharing_bluetooth_enabled_changed), NULL);
+
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_ALLOW_WRITE,
+			     G_CALLBACK (file_sharing_bluetooth_allow_write_changed), NULL);
+
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_REQUIRE_PAIRING,
+			     G_CALLBACK (file_sharing_bluetooth_require_pairing_changed), NULL);
+
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED,
+			     G_CALLBACK (file_sharing_bluetooth_obexpush_enabled_changed), NULL);
+
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_ACCEPT_FILES,
+			     G_CALLBACK (file_sharing_bluetooth_obexpush_accept_files_changed), NULL);
+
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_NOTIFY,
+			     G_CALLBACK (file_sharing_bluetooth_obexpush_notify_changed), NULL);
+
+	bluez_init ();
+	session_init ();
+#endif /* HAVE_BLUETOOTH */
+
+	/* Initial setting */
+	file_sharing_enabled_changed (settings, NULL, NULL);
+#ifdef HAVE_BLUETOOTH
+	file_sharing_bluetooth_enabled_changed (settings, NULL, NULL);
+	file_sharing_bluetooth_obexpush_accept_files_changed (settings, NULL, NULL);
+	file_sharing_bluetooth_obexpush_notify_changed (settings, NULL, NULL);
+	file_sharing_bluetooth_obexpush_enabled_changed (settings, NULL, NULL);
+#endif /* HAVE_BLUETOOTH */
+
+	gtk_main ();
+
+	return 0;
+}
+
+
+
+ + + diff --git a/2020-06-12-004111-9546-cppcheck@0ac8ecb990d2_master/index.html b/2020-06-12-004111-9546-cppcheck@0ac8ecb990d2_master/index.html new file mode 100644 index 0000000..a691de5 --- /dev/null +++ b/2020-06-12-004111-9546-cppcheck@0ac8ecb990d2_master/index.html @@ -0,0 +1,130 @@ + + + + + + Cppcheck - HTML report - mate-user-share + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
LineIdCWESeverityMessage
missingIncludeinformationCppcheck cannot find all the include files (use --check-config for details)
src/file-share-properties.c
82variableScope398styleThe scope of the variable 'password' can be reduced.
97shadowVariable398styleLocal variable 'settings' shadows outer variable
105unusedVariable563styleUnused variable: accept_setting
249shadowVariable398styleLocal variable 'settings' shadows outer variable
273shadowVariable398styleLocal variable 'settings' shadows outer variable
294shadowVariable398styleLocal variable 'settings' shadows outer variable
323shadowVariable398styleLocal variable 'settings' shadows outer variable
340shadowVariable398styleLocal variable 'settings' shadows outer variable
357shadowVariable398styleLocal variable 'settings' shadows outer variable
377shadowVariable398styleLocal variable 'settings' shadows outer variable
393shadowVariable398styleLocal variable 'settings' shadows outer variable
457shadowVariable398styleLocal variable 'settings' shadows outer variable
620variableScope398styleThe scope of the variable 'window' can be reduced.
src/http.c
107nullPointerArithmeticRedundantCheck682warningEither the condition 'end!=NULL' is redundant or there is overflow in pointer subtraction.
114variableScope398styleThe scope of the variable 'host_name' can be reduced.
src/obexpush.c
187shadowVariable398styleLocal variable 'connection' shadows outer variable
src/share-extension.c
61variableScope398styleThe scope of the variable 'dialog' can be reduced.
src/user_share-common.c
81uninitvar908errorUninitialized variable: name
src/user_share.c
86shadowVariable398styleLocal variable 'settings' shadows outer variable
260shadowVariable398styleLocal variable 'settings' shadows outer variable
391shadowVariable398styleLocal variable 'settings' shadows outer variable
+
+ + + diff --git a/2020-06-12-004111-9546-cppcheck@0ac8ecb990d2_master/stats.html b/2020-06-12-004111-9546-cppcheck@0ac8ecb990d2_master/stats.html new file mode 100644 index 0000000..0990d84 --- /dev/null +++ b/2020-06-12-004111-9546-cppcheck@0ac8ecb990d2_master/stats.html @@ -0,0 +1,99 @@ + + + + + + Cppcheck - HTML report - mate-user-share + + + + + + + +
+

Top 10 files for error severity, total findings: 1
+   1  src/user_share-common.c
+

+

Top 10 files for warning severity, total findings: 1
+   1  src/http.c
+

+

Top 10 files for style severity, total findings: 19
+   13  src/file-share-properties.c
+   3   src/user_share.c
+   1   src/share-extension.c
+   1   src/obexpush.c
+   1   src/http.c
+

+ +
+ + + diff --git a/2020-06-12-004111-9546-cppcheck@0ac8ecb990d2_master/style.css b/2020-06-12-004111-9546-cppcheck@0ac8ecb990d2_master/style.css new file mode 100644 index 0000000..c39571c --- /dev/null +++ b/2020-06-12-004111-9546-cppcheck@0ac8ecb990d2_master/style.css @@ -0,0 +1,149 @@ + +body { + font: 13px Arial, Verdana, Sans-Serif; + margin: 0; + width: auto; +} + +h1 { + margin: 10px; +} + +#footer > p { + margin: 4px; +} + +.error { + background-color: #ffb7b7; +} + +.error2 { + background-color: #faa; + border: 1px dotted black; + display: inline-block; + margin-left: 4px; +} + +.inconclusive { + background-color: #B6B6B4; +} + +.inconclusive2 { + background-color: #B6B6B4; + border: 1px dotted black; + display: inline-block; + margin-left: 4px; +} + +div.verbose { + display: inline-block; + vertical-align: top; + cursor: help; +} + +div.verbose div.content { + display: none; + position: absolute; + padding: 10px; + margin: 4px; + max-width: 40%; + white-space: pre-wrap; + border: 1px solid black; + background-color: #FFFFCC; + cursor: auto; +} + +.highlight .hll { + padding: 1px; +} + +#header { + border-bottom: thin solid #aaa; +} + +#menu { + float: left; + margin-top: 5px; + text-align: left; + width: 150px; + /*height: 75%;*/ + position: fixed; + overflow: auto; + z-index: 1; +} + +#menu_index { + float: left; + margin-top: 5px; + padding-left: 5px; + text-align: left; + width: 300px; + /*height: 75%;*/ + position: fixed; + overflow: auto; + z-index: 1; +} + +#menu > a { + display: block; + margin-left: 10px; + font: 12px; + z-index: 1; +} + +#filename { + margin-left: 10px; + font: 12px; + z-index: 1; +} + +.highlighttable { + background-color:white; + z-index: 10; + position: relative; + margin: -10 px; +} + +#content { + background-color: white; + -webkit-box-sizing: content-box; + -moz-box-sizing: content-box; + box-sizing: content-box; + float: left; + margin: 5px; + margin-left: 10px; + padding: 0 10px 10px 10px; + width: 80%; + padding-left: 150px; +} + +#content_index { + background-color: white; + -webkit-box-sizing: content-box; + -moz-box-sizing: content-box; + box-sizing: content-box; + float: left; + margin: 5px; + margin-left: 10px; + padding: 0 10px 10px 10px; + width: 80%; + padding-left: 300px; +} + +.linenos { + border-right: thin solid #aaa; + color: lightgray; + padding-right: 6px; +} + +#footer { + border-top: thin solid #aaa; + clear: both; + font-size: 90%; + margin-top: 5px; +} + +#footer ul { + list-style-type: none; + padding-left: 0; +} diff --git a/2020-06-22-164518-5655-cppcheck@b751b682733f_travis-ci/0.html b/2020-06-22-164518-5655-cppcheck@b751b682733f_travis-ci/0.html new file mode 100644 index 0000000..cb65a79 --- /dev/null +++ b/2020-06-22-164518-5655-cppcheck@b751b682733f_travis-ci/0.html @@ -0,0 +1,1482 @@ + + + + + + Cppcheck - HTML report - mate-user-share + + + + + + + +
+
  1
+  2
+  3
+  4
+  5
+  6
+  7
+  8
+  9
+ 10
+ 11
+ 12
+ 13
+ 14
+ 15
+ 16
+ 17
+ 18
+ 19
+ 20
+ 21
+ 22
+ 23
+ 24
+ 25
+ 26
+ 27
+ 28
+ 29
+ 30
+ 31
+ 32
+ 33
+ 34
+ 35
+ 36
+ 37
+ 38
+ 39
+ 40
+ 41
+ 42
+ 43
+ 44
+ 45
+ 46
+ 47
+ 48
+ 49
+ 50
+ 51
+ 52
+ 53
+ 54
+ 55
+ 56
+ 57
+ 58
+ 59
+ 60
+ 61
+ 62
+ 63
+ 64
+ 65
+ 66
+ 67
+ 68
+ 69
+ 70
+ 71
+ 72
+ 73
+ 74
+ 75
+ 76
+ 77
+ 78
+ 79
+ 80
+ 81
+ 82
+ 83
+ 84
+ 85
+ 86
+ 87
+ 88
+ 89
+ 90
+ 91
+ 92
+ 93
+ 94
+ 95
+ 96
+ 97
+ 98
+ 99
+100
+101
+102
+103
+104
+105
+106
+107
+108
+109
+110
+111
+112
+113
+114
+115
+116
+117
+118
+119
+120
+121
+122
+123
+124
+125
+126
+127
+128
+129
+130
+131
+132
+133
+134
+135
+136
+137
+138
+139
+140
+141
+142
+143
+144
+145
+146
+147
+148
+149
+150
+151
+152
+153
+154
+155
+156
+157
+158
+159
+160
+161
+162
+163
+164
+165
+166
+167
+168
+169
+170
+171
+172
+173
+174
+175
+176
+177
+178
+179
+180
+181
+182
+183
+184
+185
+186
+187
+188
+189
+190
+191
+192
+193
+194
+195
+196
+197
+198
+199
+200
+201
+202
+203
+204
+205
+206
+207
+208
+209
+210
+211
+212
+213
+214
+215
+216
+217
+218
+219
+220
+221
+222
+223
+224
+225
+226
+227
+228
+229
+230
+231
+232
+233
+234
+235
+236
+237
+238
+239
+240
+241
+242
+243
+244
+245
+246
+247
+248
+249
+250
+251
+252
+253
+254
+255
+256
+257
+258
+259
+260
+261
+262
+263
+264
+265
+266
+267
+268
+269
+270
+271
+272
+273
+274
+275
+276
+277
+278
+279
+280
+281
+282
+283
+284
+285
+286
+287
+288
+289
+290
+291
+292
+293
+294
+295
+296
+297
+298
+299
+300
+301
+302
+303
+304
+305
+306
+307
+308
+309
+310
+311
+312
+313
+314
+315
+316
+317
+318
+319
+320
+321
+322
+323
+324
+325
+326
+327
+328
+329
+330
+331
+332
+333
+334
+335
+336
+337
+338
+339
+340
+341
+342
+343
+344
+345
+346
+347
+348
+349
+350
+351
+352
+353
+354
+355
+356
+357
+358
+359
+360
+361
+362
+363
+364
+365
+366
+367
+368
+369
+370
+371
+372
+373
+374
+375
+376
+377
+378
+379
+380
+381
+382
+383
+384
+385
+386
+387
+388
+389
+390
+391
+392
+393
+394
+395
+396
+397
+398
+399
+400
+401
+402
+403
+404
+405
+406
+407
+408
+409
+410
+411
+412
+413
+414
+415
+416
+417
+418
+419
+420
+421
+422
+423
+424
+425
+426
+427
+428
+429
+430
+431
+432
+433
+434
+435
+436
+437
+438
+439
+440
+441
+442
+443
+444
+445
+446
+447
+448
+449
+450
+451
+452
+453
+454
+455
+456
+457
+458
+459
+460
+461
+462
+463
+464
+465
+466
+467
+468
+469
+470
+471
+472
+473
+474
+475
+476
+477
+478
+479
+480
+481
+482
+483
+484
+485
+486
+487
+488
+489
+490
+491
+492
+493
+494
+495
+496
+497
+498
+499
+500
+501
+502
+503
+504
+505
+506
+507
+508
+509
+510
+511
+512
+513
+514
+515
+516
+517
+518
+519
+520
+521
+522
+523
+524
+525
+526
+527
+528
+529
+530
+531
+532
+533
+534
+535
+536
+537
+538
+539
+540
+541
+542
+543
+544
+545
+546
+547
+548
+549
+550
+551
+552
+553
+554
+555
+556
+557
+558
+559
+560
+561
+562
+563
+564
+565
+566
+567
+568
+569
+570
+571
+572
+573
+574
+575
+576
+577
+578
+579
+580
+581
+582
+583
+584
+585
+586
+587
+588
+589
+590
+591
+592
+593
+594
+595
+596
+597
+598
+599
+600
+601
+602
+603
+604
+605
+606
+607
+608
+609
+610
+611
+612
+613
+614
+615
+616
+617
+618
+619
+620
+621
+622
+623
+624
+625
+626
+627
+628
+629
+630
+631
+632
+633
+634
+635
+636
+637
+638
+639
+640
+641
+642
+643
+644
+645
+646
+647
+648
+649
+650
+651
+652
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
+
+/*
+ *  Copyright (C) 2004 Red Hat, Inc.
+ *
+ *  Caja is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU General Public License as
+ *  published by the Free Software Foundation; either version 2 of the
+ *  License, or (at your option) any later version.
+ *
+ *  Caja is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  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
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ *  Authors: Alexander Larsson <alexl@redhat.com>
+ *
+ */
+
+#include "config.h"
+
+#include <string.h>
+#include <stdio.h>
+
+#include <gtk/gtk.h>
+#include <glib/gi18n.h>
+#include <gio/gio.h>
+
+#include "user_share-private.h"
+
+#define REALM "Please log in as the user guest"
+#define USER "guest"
+#define GSETTINGS_SCHEMA "org.mate.FileSharing"
+#define GSETTINGS_KEY_FILE_SHARING_ENABLED "enabled"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_ENABLED "bluetooth-enabled"
+#define GSETTINGS_KEY_FILE_SHARING_REQUIRE_PASSWORD "require-password"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_ALLOW_WRITE "bluetooth-allow-write"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_REQUIRE_PAIRING "bluetooth-require-pairing"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED "bluetooth-obexpush-enabled"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_ACCEPT_FILES "bluetooth-accept-files"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_NOTIFY "bluetooth-notify"
+
+static GtkBuilder* builder;
+static GSettings* settings;<--- Shadowed declaration<--- Shadowed declaration<--- Shadowed declaration<--- Shadowed declaration<--- Shadowed declaration<--- Shadowed declaration<--- Shadowed declaration<--- Shadowed declaration<--- Shadowed declaration<--- Shadowed declaration
+
+
+static void
+write_out_password (const char *password)
+{
+    char *to_hash;
+    char *ascii_digest;
+    char *line;
+    char *filename;
+    FILE *file;
+
+    to_hash = g_strdup_printf ("%s:%s:%s", USER, REALM, password);
+    ascii_digest = g_compute_checksum_for_string (G_CHECKSUM_MD5, to_hash, strlen (to_hash));
+    g_free (to_hash);
+    line = g_strdup_printf ("%s:%s:%s\n", USER, REALM, ascii_digest);
+    g_free (ascii_digest);
+
+    filename = g_build_filename (g_get_user_config_dir (), "user-share", "passwd", NULL);
+
+    file = fopen (filename, "w");
+    if (file != NULL) {
+	fwrite (line, strlen (line), 1, file);
+	fclose (file);
+    }
+
+    g_free (filename);
+    g_free (line);
+}
+
+static void
+flush_password (void)
+{
+    GtkWidget *password_entry;
+    const char *password;
+
+    password_entry = GTK_WIDGET (gtk_builder_get_object (builder, "password_entry"));
+
+    if (g_object_get_data (G_OBJECT( password_entry), "user_edited")) {
+	password = gtk_entry_get_text (GTK_ENTRY (password_entry));
+	if (password != NULL && password[0] != 0)
+	    write_out_password (password);
+    }
+}
+
+
+static void
+update_ui (void)
+{
+    GSettings *settings;<--- Shadow variable
+    gboolean enabled;
+#ifdef HAVE_BLUETOOTH
+    gboolean bluetooth_enabled, bluetooth_write_enabled, require_pairing_enabled;
+    gboolean bluetooth_obexpush_enabled, bluetooth_obexpush_notify;
+#endif /* HAVE_BLUETOOTH */
+    char *str;
+    PasswordSetting password_setting;
+    AcceptSetting accept_setting;<--- Unused variable: accept_setting
+    GtkWidget *check;
+    GtkWidget *password_combo;
+    GtkWidget *password_entry;
+#ifdef HAVE_BLUETOOTH
+    GtkWidget *vbox_share_bluetooth;
+    GtkWidget *vbox_receive_bluetooth;
+    GtkWidget *bluetooth_check;
+    GtkWidget *allow_write_bluetooth_check;
+    GtkWidget *require_pairing_check;
+    GtkWidget *enable_obexpush_check;
+    GtkWidget *accept_obexpush_combo;
+    GtkWidget *notify_received_obexpush_check;
+#endif /* HAVE_BLUETOOTH */
+
+    settings = g_settings_new (GSETTINGS_SCHEMA);
+
+    enabled = g_settings_get_boolean (settings,
+				     FILE_SHARING_ENABLED);
+
+    str = g_settings_get_string (settings, FILE_SHARING_REQUIRE_PASSWORD);
+    password_setting = password_setting_from_string (str);
+    g_free (str);
+
+#ifdef HAVE_BLUETOOTH
+    bluetooth_enabled = g_settings_get_boolean (settings,
+    					       FILE_SHARING_BLUETOOTH_ENABLED);
+    bluetooth_write_enabled = g_settings_get_boolean (settings,
+						     FILE_SHARING_BLUETOOTH_ALLOW_WRITE);
+    require_pairing_enabled = g_settings_get_boolean (settings,
+    						     FILE_SHARING_BLUETOOTH_REQUIRE_PAIRING);
+    bluetooth_obexpush_enabled = g_settings_get_boolean (settings,
+    							FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED);
+    bluetooth_obexpush_notify = g_settings_get_boolean (settings,
+    						       FILE_SHARING_BLUETOOTH_OBEXPUSH_NOTIFY);
+
+    str = g_settings_get_string (settings, FILE_SHARING_BLUETOOTH_OBEXPUSH_ACCEPT_FILES);
+    accept_setting = accept_setting_from_string (str);
+    g_free (str);
+#endif /* HAVE_BLUETOOTH */
+
+    check = GTK_WIDGET (gtk_builder_get_object (builder, "enable_check"));
+    password_combo = GTK_WIDGET (gtk_builder_get_object (builder, "password_combo"));
+    password_entry = GTK_WIDGET (gtk_builder_get_object (builder, "password_entry"));
+#ifdef HAVE_BLUETOOTH
+    vbox_share_bluetooth = GTK_WIDGET (gtk_builder_get_object (builder, "vbox_share_bluetooth"));
+    vbox_receive_bluetooth = GTK_WIDGET (gtk_builder_get_object (builder, "vbox_receive_bluetooth"));
+    bluetooth_check = GTK_WIDGET (gtk_builder_get_object (builder, "enable_bluetooth_check"));
+    allow_write_bluetooth_check = GTK_WIDGET (gtk_builder_get_object (builder, "allow_write_bluetooth_check"));
+    require_pairing_check = GTK_WIDGET (gtk_builder_get_object (builder, "require_pairing_check"));
+    enable_obexpush_check = GTK_WIDGET (gtk_builder_get_object (builder, "enable_obexpush_check"));
+    accept_obexpush_combo = GTK_WIDGET (gtk_builder_get_object (builder, "accept_obexpush_combo"));
+    notify_received_obexpush_check = GTK_WIDGET (gtk_builder_get_object (builder, "notify_received_obexpush_check"));
+#endif /* HAVE_BLUETOOTH */
+
+    /* Network */
+    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (check), enabled);
+    gtk_widget_set_sensitive (password_combo, enabled);
+    gtk_widget_set_sensitive (password_entry, enabled && password_setting != PASSWORD_NEVER);
+
+    gtk_combo_box_set_active (GTK_COMBO_BOX (password_combo),
+			      password_setting);
+
+#ifdef HAVE_BLUETOOTH
+    /* Bluetooth ObexFTP */
+    gtk_widget_set_visible (vbox_share_bluetooth, TRUE);
+    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (bluetooth_check), bluetooth_enabled);
+    gtk_widget_set_sensitive (allow_write_bluetooth_check, bluetooth_enabled);
+    gtk_widget_set_sensitive (require_pairing_check, bluetooth_enabled);
+
+    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (allow_write_bluetooth_check),
+    				  bluetooth_write_enabled);
+    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (require_pairing_check),
+    				  require_pairing_enabled);
+
+    /* Bluetooth ObexPush */
+    gtk_widget_set_visible (vbox_receive_bluetooth, TRUE);
+    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (enable_obexpush_check), bluetooth_obexpush_enabled);
+    gtk_widget_set_sensitive (accept_obexpush_combo, bluetooth_obexpush_enabled);
+    gtk_widget_set_sensitive (notify_received_obexpush_check, bluetooth_obexpush_enabled);
+
+    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (notify_received_obexpush_check),
+    				  bluetooth_obexpush_notify);
+
+    gtk_combo_box_set_active (GTK_COMBO_BOX (accept_obexpush_combo),
+    			      accept_setting);
+#endif /* HAVE_BLUETOOTH */
+
+    g_object_unref (settings);
+}
+
+static void
+file_sharing_enabled_changed (GSettings *settings, gchar *key, gpointer data)
+{
+    update_ui ();
+}
+
+static void
+password_required_changed (GSettings *settings, gchar *key, gpointer data)
+{
+    update_ui ();
+}
+
+#ifdef HAVE_BLUETOOTH
+static void
+file_sharing_bluetooth_enabled_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	update_ui ();
+}
+
+static void
+file_sharing_bluetooth_allow_write_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	update_ui ();
+}
+
+static void
+file_sharing_bluetooth_require_pairing_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	update_ui ();
+}
+
+static void
+file_sharing_bluetooth_obexpush_enabled_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	update_ui ();
+}
+
+static void
+file_sharing_bluetooth_obexpush_accept_files_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	update_ui ();
+}
+
+static void
+file_sharing_bluetooth_obexpush_notify_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	update_ui ();
+}
+#endif /* HAVE_BLUETOOTH */
+
+static void
+password_combo_changed (GtkComboBox *combo_box)
+{
+    GSettings *settings;<--- Shadow variable
+    guint setting;
+
+    setting = gtk_combo_box_get_active (combo_box);
+
+    settings = g_settings_new (GSETTINGS_SCHEMA) ;
+
+    g_settings_set_string (settings,
+			     FILE_SHARING_REQUIRE_PASSWORD,
+			     password_string_from_setting (setting));
+    g_object_unref (settings);
+}
+
+static void
+launch_share (void)
+{
+	if (!g_spawn_command_line_async (USER_SHARE_PROGRAM, NULL))
+		g_warning ("Unable to start mate-user-share program");
+}
+
+#ifdef HAVE_BLUETOOTH
+static void
+enable_bluetooth_check_toggled (GtkWidget *check)
+{
+	GSettings *settings;<--- Shadow variable
+	gboolean enabled;
+
+	enabled = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check));
+
+	settings = g_settings_new (GSETTINGS_SCHEMA) ;
+
+	g_settings_set_boolean (settings,
+			       FILE_SHARING_BLUETOOTH_ENABLED,
+			       enabled);
+
+	g_object_unref (settings);
+
+	if (enabled != FALSE)
+		launch_share ();
+}
+#endif /* HAVE_BLUETOOTH */
+
+static void
+enable_check_toggled (GtkWidget *check)
+{
+	GSettings *settings;<--- Shadow variable
+	gboolean enabled;
+
+	enabled = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check));
+
+	settings = g_settings_new (GSETTINGS_SCHEMA);
+
+	g_settings_set_boolean (settings,
+			       FILE_SHARING_ENABLED,
+			       enabled);
+
+	g_object_unref (settings);
+
+	if (enabled != FALSE)
+		launch_share ();
+}
+
+static void
+password_entry_changed (GtkEditable *editable)
+{
+	g_object_set_data (G_OBJECT (editable),
+			   "user_edited", GINT_TO_POINTER (1));
+	flush_password ();
+}
+
+#ifdef HAVE_BLUETOOTH
+static void
+bluetooth_allow_write_check_toggled (GtkWidget *check)
+{
+	GSettings *settings;<--- Shadow variable
+	gboolean enabled;
+
+	enabled = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check));
+
+	settings = g_settings_new (GSETTINGS_SCHEMA) ;
+
+	g_settings_set_boolean (settings,
+			       FILE_SHARING_BLUETOOTH_ALLOW_WRITE,
+			       enabled);
+
+	g_object_unref (settings);
+}
+
+static void
+bluetooth_require_pairing_check_toggled (GtkWidget *check)
+{
+	GSettings *settings;<--- Shadow variable
+	gboolean enabled;
+
+	enabled = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check));
+
+	settings = g_settings_new (GSETTINGS_SCHEMA) ;
+
+	g_settings_set_boolean (settings,
+			       FILE_SHARING_BLUETOOTH_REQUIRE_PAIRING,
+			       enabled);
+
+	g_object_unref (settings);
+}
+
+static void
+enable_obexpush_check_toggled (GtkWidget *check)
+{
+	GSettings *settings;<--- Shadow variable
+	gboolean enabled;
+
+	enabled = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check));
+
+	settings = g_settings_new (GSETTINGS_SCHEMA) ;
+
+	g_settings_set_boolean (settings,
+			       FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED,
+			       enabled);
+
+	g_object_unref (settings);
+
+	if (enabled != FALSE)
+		launch_share ();
+}
+
+static void
+accept_obexpush_combo_changed (GtkComboBox *combo_box)
+{
+    GSettings *settings;<--- Shadow variable
+    guint setting;
+
+    setting = gtk_combo_box_get_active (combo_box);
+
+    settings = g_settings_new (GSETTINGS_SCHEMA) ;
+
+    g_settings_set_string (settings,
+			     FILE_SHARING_BLUETOOTH_OBEXPUSH_ACCEPT_FILES,
+			     accept_string_from_setting (setting));
+    g_object_unref (settings);
+}
+
+static void
+notify_received_obexpush_check_toggled (GtkWidget *check)
+{
+	GSettings *settings;<--- Shadow variable
+	gboolean enabled;
+
+	enabled = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check));
+
+	settings = g_settings_new (GSETTINGS_SCHEMA) ;
+
+	g_settings_set_boolean (settings,
+			       FILE_SHARING_BLUETOOTH_OBEXPUSH_NOTIFY,
+			       enabled);
+
+	g_object_unref (settings);
+}
+#endif /* HAVE_BLUETOOTH */
+
+static GtkWidget *
+error_dialog (const char *title,
+	      const char *reason,
+	      GtkWindow *parent)
+{
+	GtkWidget *error_dialog;
+
+	if (reason == NULL)
+		reason = _("No reason");
+
+	error_dialog =
+		gtk_message_dialog_new (parent,
+					GTK_DIALOG_MODAL,
+					GTK_MESSAGE_ERROR,
+					GTK_BUTTONS_OK,
+					"%s", title);
+	gtk_message_dialog_format_secondary_text
+		(GTK_MESSAGE_DIALOG (error_dialog), "%s", reason);
+
+	gtk_window_set_title (GTK_WINDOW (error_dialog), ""); /* as per HIG */
+	gtk_container_set_border_width (GTK_CONTAINER (error_dialog), 5);
+	gtk_dialog_set_default_response (GTK_DIALOG (error_dialog),
+					 GTK_RESPONSE_OK);
+	gtk_window_set_modal (GTK_WINDOW (error_dialog), TRUE);
+
+	return error_dialog;
+}
+
+static void
+help_button_clicked (GtkButton *button, GtkWidget *window)
+{
+	GError *error = NULL;
+
+	if (gtk_show_uri_on_window (GTK_WINDOW (window), "help:mate-user-share", gtk_get_current_event_time (), &error) == FALSE) {
+		GtkWidget *dialog;
+
+		dialog = error_dialog (_("Could not display the help contents."), error->message, GTK_WINDOW (window));
+		g_signal_connect (G_OBJECT (dialog), "response", G_CALLBACK
+				  (gtk_widget_destroy), error_dialog);
+		gtk_window_present (GTK_WINDOW (dialog));
+
+		g_error_free (error);
+	}
+}
+
+static GtkWidget *
+create_window (void)
+{
+    GError *error = NULL;
+    GSettings *settings;<--- Shadow variable
+    GtkWidget *check;
+    GtkWidget *password_combo;
+    GtkWidget *password_entry;
+#ifdef HAVE_BLUETOOTH
+    GtkWidget *bluetooth_check;
+    GtkWidget *bluetooth_allow_write_check;
+    GtkWidget *require_pairing_check;
+    GtkWidget *enable_obexpush_check;
+    GtkWidget *accept_obexpush_combo;
+    GtkWidget *notify_received_obexpush_check;
+#endif /* HAVE_BLUETOOTH */
+    GtkWidget *window;
+    GtkListStore *store;
+    GtkCellRenderer *cell;
+    GtkTreeIter iter;
+
+    builder = gtk_builder_new ();
+    gtk_builder_add_from_file (builder, DATADIR"file-share-properties.ui", &error);
+
+    if (error) {
+      GtkWidget *dialog;
+
+      dialog = error_dialog (_("Could not build interface."), error->message, NULL);
+      gtk_dialog_run (GTK_DIALOG (dialog));
+      gtk_widget_destroy (dialog);
+
+      g_error_free (error);
+      return NULL;
+    }
+
+    window = GTK_WIDGET (gtk_builder_get_object (builder, "user_share_dialog"));
+
+    settings = g_settings_new (GSETTINGS_SCHEMA);
+
+    check = GTK_WIDGET (gtk_builder_get_object (builder, "enable_check"));
+    password_combo = GTK_WIDGET (gtk_builder_get_object (builder, "password_combo"));
+    password_entry = GTK_WIDGET (gtk_builder_get_object (builder, "password_entry"));
+#ifdef HAVE_BLUETOOTH
+    bluetooth_check = GTK_WIDGET (gtk_builder_get_object (builder, "enable_bluetooth_check"));
+    bluetooth_allow_write_check = GTK_WIDGET (gtk_builder_get_object (builder, "allow_write_bluetooth_check"));
+    require_pairing_check = GTK_WIDGET (gtk_builder_get_object (builder, "require_pairing_check"));
+    enable_obexpush_check = GTK_WIDGET (gtk_builder_get_object (builder, "enable_obexpush_check"));
+    accept_obexpush_combo = GTK_WIDGET (gtk_builder_get_object (builder, "accept_obexpush_combo"));
+    notify_received_obexpush_check = GTK_WIDGET (gtk_builder_get_object (builder, "notify_received_obexpush_check"));
+#endif /* HAVE_BLUETOOTH */
+
+    store = gtk_list_store_new (1, G_TYPE_STRING);
+    gtk_combo_box_set_model (GTK_COMBO_BOX (password_combo),
+			     GTK_TREE_MODEL (store));
+    cell = gtk_cell_renderer_text_new ();
+    gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (password_combo), cell, TRUE);
+    gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (password_combo), cell,
+				    "text", 0,
+				    NULL);
+
+    /* Keep in same order as enum */
+    gtk_list_store_append (store, &iter);
+    gtk_list_store_set (store, &iter, 0,
+			_("Never"), -1);
+    gtk_list_store_append (store, &iter);
+    gtk_list_store_set (store, &iter, 0,
+			_("When writing files"), -1);
+    gtk_list_store_append (store, &iter);
+    gtk_list_store_set (store, &iter, 0,
+			_("Always"), -1);
+    g_object_unref (store);
+
+    /* We can't read the password from the text, just set it to something */
+    gtk_entry_set_text (GTK_ENTRY (password_entry), "none");
+    g_object_set_data (G_OBJECT (password_entry),
+		       "user_edited", GINT_TO_POINTER (0));
+    g_signal_connect (password_entry,
+		      "changed", G_CALLBACK (password_entry_changed), NULL);
+
+#ifdef HAVE_BLUETOOTH
+    /* Accept files combo */
+    store = gtk_list_store_new (1, G_TYPE_STRING);
+    gtk_combo_box_set_model (GTK_COMBO_BOX (accept_obexpush_combo),
+			     GTK_TREE_MODEL (store));
+    cell = gtk_cell_renderer_text_new ();
+    gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (accept_obexpush_combo), cell, TRUE);
+    gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (accept_obexpush_combo), cell,
+				    "text", 0,
+				    NULL);
+
+    /* Keep in same order as enum */
+    gtk_list_store_append (store, &iter);
+    gtk_list_store_set (store, &iter, 0,
+			_("Always"), -1);
+    gtk_list_store_append (store, &iter);
+    gtk_list_store_set (store, &iter, 0,
+			_("Only for set up devices"), -1);
+    //FIXME implement
+#if 0
+    gtk_list_store_append (store, &iter);
+    gtk_list_store_set (store, &iter, 0,
+    			_("Ask"), -1);
+#endif
+    g_object_unref (store);
+#endif /* HAVE_BLUETOOTH */
+
+    g_signal_connect (check,
+		      "toggled", G_CALLBACK (enable_check_toggled), NULL);
+    g_signal_connect (password_combo,
+		      "changed", G_CALLBACK (password_combo_changed), NULL);
+#ifdef HAVE_BLUETOOTH
+    g_signal_connect (bluetooth_check,
+    		      "toggled", G_CALLBACK (enable_bluetooth_check_toggled), NULL);
+    g_signal_connect (bluetooth_allow_write_check,
+    		      "toggled", G_CALLBACK (bluetooth_allow_write_check_toggled), NULL);
+    g_signal_connect (require_pairing_check,
+    		      "toggled", G_CALLBACK (bluetooth_require_pairing_check_toggled), NULL);
+    g_signal_connect (enable_obexpush_check,
+    		      "toggled", G_CALLBACK (enable_obexpush_check_toggled), NULL);
+    g_signal_connect (accept_obexpush_combo,
+    		      "changed", G_CALLBACK (accept_obexpush_combo_changed), NULL);
+    g_signal_connect (notify_received_obexpush_check,
+    		      "toggled", G_CALLBACK (notify_received_obexpush_check_toggled), NULL);
+#endif /* HAVE_BLUETOOTH */
+
+    g_signal_connect_swapped (GTK_WIDGET (gtk_builder_get_object (builder, "close_button")),
+                              "clicked", G_CALLBACK (gtk_widget_destroy), window);
+    g_signal_connect (GTK_WIDGET (gtk_builder_get_object (builder, "help_button")),
+		      "clicked", G_CALLBACK (help_button_clicked),
+		      gtk_builder_get_object (builder, "user_share_dialog"));
+
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_ENABLED,
+			     G_CALLBACK (file_sharing_enabled_changed), NULL);
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_REQUIRE_PASSWORD,
+			     G_CALLBACK (password_required_changed), NULL);
+#ifdef HAVE_BLUETOOTH
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_ENABLED,
+			     G_CALLBACK (file_sharing_bluetooth_enabled_changed), NULL);
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_ALLOW_WRITE,
+			     G_CALLBACK (file_sharing_bluetooth_allow_write_changed), NULL);
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_REQUIRE_PAIRING,
+			     G_CALLBACK (file_sharing_bluetooth_require_pairing_changed), NULL);
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED,
+			     G_CALLBACK (file_sharing_bluetooth_obexpush_enabled_changed), NULL);
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_ACCEPT_FILES,
+			     G_CALLBACK (file_sharing_bluetooth_obexpush_accept_files_changed), NULL);
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_NOTIFY,
+			     G_CALLBACK (file_sharing_bluetooth_obexpush_notify_changed), NULL);
+#endif /* HAVE_BLUETOOTH */
+
+    update_ui ();
+
+    return window;
+}
+
+static void
+activate (GtkApplication *app)
+{
+    GList *list;
+    GtkWidget *window;
+
+    list = gtk_application_get_windows (app);
+
+    if (list) {
+        gtk_window_present (GTK_WINDOW (list->data));
+    } else {
+        window = create_window ();
+        gtk_window_set_application (GTK_WINDOW (window), app);
+        gtk_widget_show (window);
+    }
+}
+
+int
+main (int argc, char *argv[])
+{
+    GtkApplication *app;
+    gint status;
+
+    bindtextdomain (GETTEXT_PACKAGE, MATELOCALEDIR);
+    bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
+    textdomain (GETTEXT_PACKAGE);
+
+    app = gtk_application_new ("org.mate.user-share.properties",
+                               G_APPLICATION_FLAGS_NONE);
+    g_signal_connect (app, "activate", G_CALLBACK (activate), NULL);
+
+    status = g_application_run (G_APPLICATION (app), argc, argv);
+
+    g_object_unref (app);
+
+    return status;
+}
+
+
+
+ + + diff --git a/2020-06-22-164518-5655-cppcheck@b751b682733f_travis-ci/1.html b/2020-06-22-164518-5655-cppcheck@b751b682733f_travis-ci/1.html new file mode 100644 index 0000000..0ccd444 --- /dev/null +++ b/2020-06-22-164518-5655-cppcheck@b751b682733f_travis-ci/1.html @@ -0,0 +1,1038 @@ + + + + + + Cppcheck - HTML report - mate-user-share + + + + + + + +
+
  1
+  2
+  3
+  4
+  5
+  6
+  7
+  8
+  9
+ 10
+ 11
+ 12
+ 13
+ 14
+ 15
+ 16
+ 17
+ 18
+ 19
+ 20
+ 21
+ 22
+ 23
+ 24
+ 25
+ 26
+ 27
+ 28
+ 29
+ 30
+ 31
+ 32
+ 33
+ 34
+ 35
+ 36
+ 37
+ 38
+ 39
+ 40
+ 41
+ 42
+ 43
+ 44
+ 45
+ 46
+ 47
+ 48
+ 49
+ 50
+ 51
+ 52
+ 53
+ 54
+ 55
+ 56
+ 57
+ 58
+ 59
+ 60
+ 61
+ 62
+ 63
+ 64
+ 65
+ 66
+ 67
+ 68
+ 69
+ 70
+ 71
+ 72
+ 73
+ 74
+ 75
+ 76
+ 77
+ 78
+ 79
+ 80
+ 81
+ 82
+ 83
+ 84
+ 85
+ 86
+ 87
+ 88
+ 89
+ 90
+ 91
+ 92
+ 93
+ 94
+ 95
+ 96
+ 97
+ 98
+ 99
+100
+101
+102
+103
+104
+105
+106
+107
+108
+109
+110
+111
+112
+113
+114
+115
+116
+117
+118
+119
+120
+121
+122
+123
+124
+125
+126
+127
+128
+129
+130
+131
+132
+133
+134
+135
+136
+137
+138
+139
+140
+141
+142
+143
+144
+145
+146
+147
+148
+149
+150
+151
+152
+153
+154
+155
+156
+157
+158
+159
+160
+161
+162
+163
+164
+165
+166
+167
+168
+169
+170
+171
+172
+173
+174
+175
+176
+177
+178
+179
+180
+181
+182
+183
+184
+185
+186
+187
+188
+189
+190
+191
+192
+193
+194
+195
+196
+197
+198
+199
+200
+201
+202
+203
+204
+205
+206
+207
+208
+209
+210
+211
+212
+213
+214
+215
+216
+217
+218
+219
+220
+221
+222
+223
+224
+225
+226
+227
+228
+229
+230
+231
+232
+233
+234
+235
+236
+237
+238
+239
+240
+241
+242
+243
+244
+245
+246
+247
+248
+249
+250
+251
+252
+253
+254
+255
+256
+257
+258
+259
+260
+261
+262
+263
+264
+265
+266
+267
+268
+269
+270
+271
+272
+273
+274
+275
+276
+277
+278
+279
+280
+281
+282
+283
+284
+285
+286
+287
+288
+289
+290
+291
+292
+293
+294
+295
+296
+297
+298
+299
+300
+301
+302
+303
+304
+305
+306
+307
+308
+309
+310
+311
+312
+313
+314
+315
+316
+317
+318
+319
+320
+321
+322
+323
+324
+325
+326
+327
+328
+329
+330
+331
+332
+333
+334
+335
+336
+337
+338
+339
+340
+341
+342
+343
+344
+345
+346
+347
+348
+349
+350
+351
+352
+353
+354
+355
+356
+357
+358
+359
+360
+361
+362
+363
+364
+365
+366
+367
+368
+369
+370
+371
+372
+373
+374
+375
+376
+377
+378
+379
+380
+381
+382
+383
+384
+385
+386
+387
+388
+389
+390
+391
+392
+393
+394
+395
+396
+397
+398
+399
+400
+401
+402
+403
+404
+405
+406
+407
+408
+409
+410
+411
+412
+413
+414
+415
+416
+417
+418
+419
+420
+421
+422
+423
+424
+425
+426
+427
+428
+429
+430
+431
+432
+433
+434
+435
+436
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
+
+/*
+ *  Copyright (C) 2004-2008 Red Hat, Inc.
+ *
+ *  Caja is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU General Public License as
+ *  published by the Free Software Foundation; either version 2 of the
+ *  License, or (at your option) any later version.
+ *
+ *  Caja is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  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
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ *  Authors: Alexander Larsson <alexl@redhat.com>
+ *
+ */
+
+#include "config.h"
+
+#include <glib.h>
+#include <glib/gi18n.h>
+#include <X11/Xlib.h>
+
+#include <gio/gio.h>
+
+#include <stdarg.h>
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <signal.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <sys/stat.h>
+
+#ifdef HAVE_SELINUX
+#include <selinux/selinux.h>
+#endif
+
+#include "user_share-common.h"
+#include "user_share-private.h"
+#include "http.h"
+
+/* From avahi-common/domain.h */
+#define AVAHI_LABEL_MAX 64
+
+#define GSETTINGS_SCHEMA "org.mate.FileSharing"
+
+static pid_t httpd_pid = 0;
+
+static int
+get_port (void)
+{
+	int sock;
+	struct sockaddr_in addr;
+	int reuse;
+	socklen_t len;
+
+	sock = socket (PF_INET, SOCK_STREAM, 0);
+	if (sock < 0) {
+		return -1;
+	}
+
+	memset (&addr, 0, sizeof (addr));
+	addr.sin_port = 0;
+	addr.sin_addr.s_addr = INADDR_ANY;
+	addr.sin_family = AF_INET;
+
+	reuse = 1;
+	setsockopt (sock, SOL_SOCKET, SO_REUSEADDR, &reuse, sizeof (reuse));
+	if (bind (sock, (struct sockaddr *)&addr, sizeof (addr)) == -1) {
+		close (sock);
+		return -1;
+	}
+
+	len = sizeof (addr);
+	if (getsockname (sock, (struct sockaddr *)&addr, &len) == -1) {
+		close (sock);
+		return -1;
+	}
+
+#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__APPLE__) || defined(__OpenBSD__)
+	/* XXX This exposes a potential race condition, but without this,
+	 * httpd will not start on the above listed platforms due to the fact
+	 * that SO_REUSEADDR is also needed when Apache binds to the listening
+	 * socket.  At this time, Apache does not support that socket option.
+	 */
+	close (sock);
+#endif
+	return ntohs (addr.sin_port);
+}
+
+static char *
+truncate_name (const char *name)
+{
+	const char *end;
+
+	end = g_utf8_find_prev_char (name, name + 64);<--- Assignment 'end=g_utf8_find_prev_char(name,name+64)', assigned value is 0
+	g_assert (end != NULL);<--- Assuming that condition 'end!=NULL' is not redundant
+	return g_strndup (name, end - name);<--- Null pointer subtraction
+}
+
+static char *
+get_share_name (void)
+{
+	static char *name = NULL;
+	const char *host_name;
+	char *str;
+
+	if (name == NULL) {
+		host_name = g_get_host_name ();
+		if (strcmp (host_name, "localhost") == 0) {
+			/* Translators: The %s will get filled in with the user name
+			   of the user, to form a genitive. If this is difficult to
+			   translate correctly so that it will work correctly in your
+			   language, you may use something equivalent to
+			   "Public files of %s", or leave out the %s altogether.
+			   In the latter case, please put "%.0s" somewhere in the string,
+			   which will match the user name string passed by the C code,
+			   but not put the user name in the final string. This is to
+			   avoid the warning that msgfmt might otherwise generate. */
+			name = g_strdup_printf (_("%s's public files"), g_get_user_name ());
+		} else {
+			/* Translators: This is similar to the string before, only it
+			   has the hostname in it too. */
+			name = g_strdup_printf (_("%s's public files on %s"),
+						g_get_user_name (),
+						host_name);
+		}
+
+	}
+	/* And truncate */
+	if (strlen (name) < AVAHI_LABEL_MAX)
+		return name;
+
+	str = truncate_name (name);
+	g_free (name);
+	name = str;
+
+	return name;
+}
+
+static void
+ensure_conf_dir (void)
+{
+	char *dirname;
+
+	dirname = g_build_filename (g_get_user_config_dir (), "user-share", NULL);
+	g_mkdir_with_parents (dirname, 0755);
+	g_free (dirname);
+}
+
+static void
+httpd_child_setup (gpointer user_data)
+{
+#ifdef HAVE_SELINUX
+	char *mycon;
+	/* If selinux is enabled, avoid transitioning to the httpd_t context,
+	   as this normally means you can't read the users homedir. */
+	if (is_selinux_enabled()) {
+		if (getcon (&mycon) < 0) {
+			abort ();
+		}
+		if (setexeccon (mycon) < 0)
+			abort ();
+		freecon (mycon);
+	}
+#endif
+}
+
+static const char *known_httpd_locations [] = {
+	HTTPD_PROGRAM,
+	"/usr/sbin/httpd",
+	"/usr/sbin/httpd2",
+	"/usr/sbin/apache2",
+	NULL
+};
+
+static char*
+get_httpd_program (void)
+{
+	int i;
+
+	for (i = 0; known_httpd_locations[i]; i++) {
+		if (known_httpd_locations[i][0] == '\0') {
+			/* empty string as first element, happens when
+			 * configured --with-httpd=auto */
+			continue;
+		}
+		if (g_file_test (known_httpd_locations[i], G_FILE_TEST_IS_EXECUTABLE)
+				&& ! g_file_test (known_httpd_locations[i], G_FILE_TEST_IS_DIR)) {
+			return g_strdup (known_httpd_locations[i]);
+		}
+	}
+	return NULL;
+}
+
+static const char *known_httpd_modules_locations [] = {
+	HTTPD_MODULES_PATH,
+	"/etc/httpd/modules",
+	"/usr/lib/apache2/modules",
+	NULL
+};
+
+static gchar*
+get_httpd_modules_path (void)
+{
+	int i;
+
+	for (i = 0; known_httpd_modules_locations[i]; i++) {
+		if (known_httpd_modules_locations[i][0] == '\0') {
+			/* empty string as first element, happens when
+			 * configured --with-httpd=auto */
+			continue;
+		}
+		if (g_file_test (known_httpd_modules_locations[i], G_FILE_TEST_IS_EXECUTABLE)
+				&& g_file_test (known_httpd_modules_locations[i], G_FILE_TEST_IS_DIR)) {
+			return g_strdup (known_httpd_modules_locations[i]);
+		}
+	}
+	return NULL;
+}
+
+static GRegex *version_regex = NULL;
+
+static char*
+get_httpd_config (const char *httpd_program)
+{
+	gchar *standard_output;
+	gchar *cmd_line;
+	GMatchInfo *match_info;
+	gchar *version_number = NULL;
+	gchar *config;
+
+	cmd_line = g_strdup_printf ("%s -v", httpd_program);
+	if (! g_spawn_command_line_sync (cmd_line, &standard_output, NULL, NULL, NULL)) {
+		g_free (cmd_line);
+		return NULL;
+	}
+	g_free (cmd_line);
+
+	if (version_regex == NULL) {
+		version_regex = g_regex_new ("\\d\\.\\d", 0, 0, NULL);
+	}
+
+	if (g_regex_match (version_regex, standard_output, 0, &match_info)) {
+		while (g_match_info_matches (match_info)) {
+			version_number = g_match_info_fetch (match_info, 0);
+			break;
+		}
+		g_match_info_free (match_info);
+		g_free (standard_output);
+	} else {
+		/* Failed to parse httpd version number */
+		g_warning ("Could not parse '%s' as a version for httpd", standard_output);
+		g_free (standard_output);
+		/* assume it is 2.2 */
+		version_number = g_strdup ("2.2");
+	}
+
+	config = g_strdup_printf (HTTPD_CONFIG_TEMPLATE, version_number);
+	g_free (version_number);
+
+	return config;
+}
+
+static gboolean
+spawn_httpd (int port, pid_t *pid_out)
+{
+	char *free1, *free2, *free3, *free4, *free5, *free6, *free7, *free8, *free9;
+	gboolean res;
+	char *argv[10];
+	char *env[10];
+	int i;
+	gint status;
+	char *pid_filename;
+	char *pidfile;
+	GError *error;
+	gboolean got_pidfile;
+	GSettings *settings;
+	char *str;
+	char *public_dir;
+
+	public_dir = lookup_public_dir ();
+	ensure_conf_dir ();
+
+	i = 0;
+	free1 = argv[i++] = get_httpd_program ();
+	if (argv[0] == NULL) {
+		fprintf (stderr, "error finding httpd server\n");
+		return FALSE;
+	}
+
+	argv[i++] = "-f";
+	free2 = argv[i++] = get_httpd_config (argv[0]);
+	argv[i++] = "-C";
+	free3 = argv[i++] = g_strdup_printf ("Listen %d", port);
+
+	settings = g_settings_new (GSETTINGS_SCHEMA);
+	str = g_settings_get_string (settings,
+				       FILE_SHARING_REQUIRE_PASSWORD);
+
+	if (str && strcmp (str, "never") == 0) {
+		/* Do nothing */
+	} else if (str && strcmp (str, "on_write") == 0){
+		argv[i++] = "-D";
+		argv[i++] = "RequirePasswordOnWrite";
+	} else {
+		/* always, or safe fallback */
+		argv[i++] = "-D";
+		argv[i++] = "RequirePasswordAlways";
+	}
+	g_free (str);
+	g_object_unref (settings);
+
+	argv[i] = NULL;
+
+	i = 0;
+	free4 = env[i++] = g_strdup_printf ("HOME=%s", g_get_home_dir());
+	free5 = env[i++] = g_strdup_printf ("XDG_PUBLICSHARE_DIR=%s", public_dir);
+	free6 = env[i++] = g_strdup_printf ("XDG_CONFIG_HOME=%s", g_get_user_config_dir ());
+	free7 = env[i++] = g_strdup_printf ("GUS_SHARE_NAME=%s", get_share_name ());
+	free8 = env[i++] = g_strdup_printf ("GUS_LOGIN_LABEL=%s", "Please log in as the user guest");
+	free9 = env[i++] = g_strdup_printf ("HTTP_MODULES_PATH=%s",get_httpd_modules_path ());
+	env[i++] = "LANG=C";
+	env[i] = NULL;
+
+	pid_filename = g_build_filename (g_get_user_config_dir (), "user-share", "pid", NULL);
+
+	/* Remove pid file before spawning to avoid races with child and old pidfile */
+	unlink (pid_filename);
+
+	error = NULL;
+	res = g_spawn_sync (g_get_home_dir(),
+			    argv, env, 0,
+			    httpd_child_setup, NULL,
+			    NULL, NULL,
+			    &status,
+			    &error);
+	g_free (free1);
+	g_free (free2);
+	g_free (free3);
+	g_free (free4);
+	g_free (free5);
+	g_free (free6);
+	g_free (free7);
+	g_free (free8);
+	g_free (free9);
+	g_free (public_dir);
+
+	if (!res) {
+		fprintf (stderr, "error spawning httpd: %s\n",
+			 error->message);
+		g_error_free (error);
+		g_free (pid_filename);
+		return FALSE;
+	}
+
+	if (status != 0) {
+		g_free (pid_filename);
+		return FALSE;
+	}
+
+	got_pidfile = FALSE;
+	error = NULL;
+	for (i = 0; i < 5; i++) {
+		if (error != NULL)
+			g_error_free (error);
+		error = NULL;
+		if (g_file_get_contents (pid_filename, &pidfile, NULL, &error)) {
+			got_pidfile = TRUE;
+			*pid_out = atoi (pidfile);
+			g_free (pidfile);
+			break;
+		}
+		sleep (1);
+	}
+
+	g_free (pid_filename);
+
+	if (!got_pidfile) {
+		fprintf (stderr, "error opening httpd pidfile: %s\n", error->message);
+		g_error_free (error);
+		return FALSE;
+	}
+	return TRUE;
+}
+
+static void
+kill_httpd (void)
+{
+	if (httpd_pid != 0) {
+		kill (httpd_pid, SIGTERM);
+
+		/* Allow child time to die, we can't waitpid, because its
+		   not a direct child */
+		sleep (1);
+	}
+	httpd_pid = 0;
+}
+
+void
+http_up (void)
+{
+	guint port;
+
+	port = get_port ();
+	if (!spawn_httpd (port, &httpd_pid)) {
+		fprintf (stderr, "spawning httpd failed\n");
+	}
+}
+
+void
+http_down (void)
+{
+	kill_httpd ();
+}
+
+gboolean
+http_init (void)
+{
+	return TRUE;
+}
+
+pid_t
+http_get_pid (void)
+{
+	return httpd_pid;
+}
+
+
+
+ + + diff --git a/2020-06-22-164518-5655-cppcheck@b751b682733f_travis-ci/2.html b/2020-06-22-164518-5655-cppcheck@b751b682733f_travis-ci/2.html new file mode 100644 index 0000000..d61baec --- /dev/null +++ b/2020-06-22-164518-5655-cppcheck@b751b682733f_travis-ci/2.html @@ -0,0 +1,1272 @@ + + + + + + Cppcheck - HTML report - mate-user-share + + + + + + + +
+
  1
+  2
+  3
+  4
+  5
+  6
+  7
+  8
+  9
+ 10
+ 11
+ 12
+ 13
+ 14
+ 15
+ 16
+ 17
+ 18
+ 19
+ 20
+ 21
+ 22
+ 23
+ 24
+ 25
+ 26
+ 27
+ 28
+ 29
+ 30
+ 31
+ 32
+ 33
+ 34
+ 35
+ 36
+ 37
+ 38
+ 39
+ 40
+ 41
+ 42
+ 43
+ 44
+ 45
+ 46
+ 47
+ 48
+ 49
+ 50
+ 51
+ 52
+ 53
+ 54
+ 55
+ 56
+ 57
+ 58
+ 59
+ 60
+ 61
+ 62
+ 63
+ 64
+ 65
+ 66
+ 67
+ 68
+ 69
+ 70
+ 71
+ 72
+ 73
+ 74
+ 75
+ 76
+ 77
+ 78
+ 79
+ 80
+ 81
+ 82
+ 83
+ 84
+ 85
+ 86
+ 87
+ 88
+ 89
+ 90
+ 91
+ 92
+ 93
+ 94
+ 95
+ 96
+ 97
+ 98
+ 99
+100
+101
+102
+103
+104
+105
+106
+107
+108
+109
+110
+111
+112
+113
+114
+115
+116
+117
+118
+119
+120
+121
+122
+123
+124
+125
+126
+127
+128
+129
+130
+131
+132
+133
+134
+135
+136
+137
+138
+139
+140
+141
+142
+143
+144
+145
+146
+147
+148
+149
+150
+151
+152
+153
+154
+155
+156
+157
+158
+159
+160
+161
+162
+163
+164
+165
+166
+167
+168
+169
+170
+171
+172
+173
+174
+175
+176
+177
+178
+179
+180
+181
+182
+183
+184
+185
+186
+187
+188
+189
+190
+191
+192
+193
+194
+195
+196
+197
+198
+199
+200
+201
+202
+203
+204
+205
+206
+207
+208
+209
+210
+211
+212
+213
+214
+215
+216
+217
+218
+219
+220
+221
+222
+223
+224
+225
+226
+227
+228
+229
+230
+231
+232
+233
+234
+235
+236
+237
+238
+239
+240
+241
+242
+243
+244
+245
+246
+247
+248
+249
+250
+251
+252
+253
+254
+255
+256
+257
+258
+259
+260
+261
+262
+263
+264
+265
+266
+267
+268
+269
+270
+271
+272
+273
+274
+275
+276
+277
+278
+279
+280
+281
+282
+283
+284
+285
+286
+287
+288
+289
+290
+291
+292
+293
+294
+295
+296
+297
+298
+299
+300
+301
+302
+303
+304
+305
+306
+307
+308
+309
+310
+311
+312
+313
+314
+315
+316
+317
+318
+319
+320
+321
+322
+323
+324
+325
+326
+327
+328
+329
+330
+331
+332
+333
+334
+335
+336
+337
+338
+339
+340
+341
+342
+343
+344
+345
+346
+347
+348
+349
+350
+351
+352
+353
+354
+355
+356
+357
+358
+359
+360
+361
+362
+363
+364
+365
+366
+367
+368
+369
+370
+371
+372
+373
+374
+375
+376
+377
+378
+379
+380
+381
+382
+383
+384
+385
+386
+387
+388
+389
+390
+391
+392
+393
+394
+395
+396
+397
+398
+399
+400
+401
+402
+403
+404
+405
+406
+407
+408
+409
+410
+411
+412
+413
+414
+415
+416
+417
+418
+419
+420
+421
+422
+423
+424
+425
+426
+427
+428
+429
+430
+431
+432
+433
+434
+435
+436
+437
+438
+439
+440
+441
+442
+443
+444
+445
+446
+447
+448
+449
+450
+451
+452
+453
+454
+455
+456
+457
+458
+459
+460
+461
+462
+463
+464
+465
+466
+467
+468
+469
+470
+471
+472
+473
+474
+475
+476
+477
+478
+479
+480
+481
+482
+483
+484
+485
+486
+487
+488
+489
+490
+491
+492
+493
+494
+495
+496
+497
+498
+499
+500
+501
+502
+503
+504
+505
+506
+507
+508
+509
+510
+511
+512
+513
+514
+515
+516
+517
+518
+519
+520
+521
+522
+523
+524
+525
+526
+527
+528
+529
+530
+531
+532
+533
+534
+535
+536
+537
+538
+539
+540
+541
+542
+543
+544
+545
+546
+547
+548
+549
+550
+551
+552
+553
+554
+555
+556
+557
+558
+559
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
+
+/*
+ *  Copyright (C) 2004-2008 Red Hat, Inc.
+ *
+ *  Caja is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU General Public License as
+ *  published by the Free Software Foundation; either version 2 of the
+ *  License, or (at your option) any later version.
+ *
+ *  Caja is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  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
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ *  Authors: Bastien Nocera <hadess@hadess.net>
+ *
+ */
+
+#include "config.h"
+
+#include <glib.h>
+#include <glib/gi18n.h>
+#include <gio/gio.h>
+#include <gdk/gdk.h>
+#include <gtk/gtk.h>
+#include <libnotify/notify.h>
+#include <dbus/dbus-glib.h>
+#include <dbus/dbus-glib-lowlevel.h>
+#include <canberra-gtk.h>
+
+#include <string.h>
+
+#include "marshal.h"
+#include "obexpush.h"
+#include "user_share-common.h"
+#include "user_share-private.h"
+
+#define DBUS_TYPE_G_STRING_VARIANT_HASHTABLE (dbus_g_type_get_map ("GHashTable", G_TYPE_STRING, G_TYPE_STRING))
+
+#define GSETTINGS_SCHEMA "org.mate.FileSharing"
+
+static DBusGConnection *connection = NULL;<--- Shadowed declaration
+static DBusGProxy *manager_proxy = NULL;
+static DBusGProxy *server_proxy = NULL;
+static AcceptSetting accept_setting = -1;
+static gboolean show_notifications = FALSE;
+
+static GtkStatusIcon *statusicon = NULL;
+static guint num_notifications = 0;
+
+static void
+hide_statusicon (void)
+{
+	num_notifications--;
+	if (num_notifications == 0)
+		gtk_status_icon_set_visible (statusicon, FALSE);
+}
+
+static void
+on_close_notification (NotifyNotification *notification)
+{
+	hide_statusicon ();
+	g_object_unref (notification);
+}
+
+static void
+notification_launch_action_on_file_cb (NotifyNotification *notification,
+				       const char *action,
+				       const char *file_uri)
+{
+	GdkScreen *screen;
+	GAppLaunchContext *ctx;
+	GTimeVal val;
+
+	g_assert (action != NULL);
+
+	g_get_current_time (&val);
+
+	ctx = G_APP_LAUNCH_CONTEXT (gdk_app_launch_context_new ());
+	screen = gdk_screen_get_default ();
+	gdk_app_launch_context_set_screen (GDK_APP_LAUNCH_CONTEXT (ctx), screen);
+	gdk_app_launch_context_set_timestamp (GDK_APP_LAUNCH_CONTEXT (ctx), val.tv_sec);
+
+	/* We launch the file viewer for the file */
+	if (g_str_equal (action, "display") != FALSE) {
+		if (g_app_info_launch_default_for_uri (file_uri, ctx, NULL) == FALSE) {
+			g_warning ("Failed to launch the file viewer\n");
+		}
+	}
+
+	/* we open the Downloads folder */
+	if (g_str_equal (action, "reveal") != FALSE) {
+		GFile *file;
+		GFile *parent;
+		gchar *parent_uri;
+
+		file = g_file_new_for_uri (file_uri);
+		parent = g_file_get_parent (file);
+		parent_uri = g_file_get_uri (parent);
+		g_object_unref (file);
+		g_object_unref (parent);
+
+		if (!g_app_info_launch_default_for_uri (parent_uri, ctx, NULL)) {
+			g_warning ("Failed to launch the file manager\n");
+		}
+
+		g_free (parent_uri);
+	}
+
+	notify_notification_close (notification, NULL);
+	/* No need to call hide_statusicon(), closing the notification
+	 * will call the close callback */
+}
+
+static void
+show_notification (const char *filename)
+{
+	char *file_uri, *notification_text, *display, *mime_type;
+	NotifyNotification *notification;
+	ca_context *ctx;
+	GAppInfo *app;
+
+	file_uri = g_filename_to_uri (filename, NULL, NULL);
+	if (file_uri == NULL) {
+		g_warning ("Could not make a filename from '%s'", filename);
+		return;
+	}
+
+	display = g_filename_display_basename (filename);
+	/* Translators: %s is the name of the filename received */
+	notification_text = g_strdup_printf(_("You received \"%s\" via Bluetooth"), display);
+	g_free (display);
+	notification = notify_notification_new (_("You received a file"),
+								 notification_text,
+								 "dialog-information");
+
+	notify_notification_set_timeout (notification, NOTIFY_EXPIRES_DEFAULT);
+
+	mime_type = g_content_type_guess (filename, NULL, 0, NULL);
+	app = g_app_info_get_default_for_type (mime_type, FALSE);
+	if (app != NULL) {
+		g_object_unref (app);
+		notify_notification_add_action (notification, "display", _("Open File"),
+						(NotifyActionCallback) notification_launch_action_on_file_cb,
+						g_strdup (file_uri), (GFreeFunc) g_free);
+	}
+	notify_notification_add_action (notification, "reveal", _("Reveal File"),
+					(NotifyActionCallback) notification_launch_action_on_file_cb,
+					g_strdup (file_uri), (GFreeFunc) g_free);
+
+	g_free (file_uri);
+
+	g_signal_connect (G_OBJECT (notification), "closed", G_CALLBACK (on_close_notification), notification);
+
+	if (!notify_notification_show (notification, NULL)) {
+		g_warning ("failed to send notification\n");
+	}
+	g_free (notification_text);
+
+	/* Now we do the audio notification */
+	ctx = ca_gtk_context_get ();
+	ca_context_play (ctx, 0,
+			 CA_PROP_EVENT_ID, "complete-download",
+			 CA_PROP_EVENT_DESCRIPTION, _("File reception complete"),
+			 NULL);
+}
+
+static void
+show_icon (void)
+{
+	if (statusicon == NULL) {
+		statusicon = gtk_status_icon_new_from_icon_name ("mate-obex-server");
+	} else {
+		gtk_status_icon_set_visible (statusicon, TRUE);
+	}
+	num_notifications++;
+}
+
+static gboolean
+device_is_authorised (const char *bdaddr)
+{
+	DBusGConnection *connection;<--- Shadow variable
+	DBusGProxy *manager;
+	GError *error = NULL;
+	GPtrArray *adapters;
+	gboolean retval = FALSE;
+	guint i;
+
+	connection = dbus_g_bus_get (DBUS_BUS_SYSTEM, NULL);
+	if (connection == NULL)
+		return FALSE;
+
+	manager = dbus_g_proxy_new_for_name (connection, "org.bluez",
+					     "/", "org.bluez.Manager");
+	if (manager == NULL) {
+		dbus_g_connection_unref (connection);
+		return FALSE;
+	}
+
+	if (dbus_g_proxy_call (manager, "ListAdapters", &error, G_TYPE_INVALID, dbus_g_type_get_collection ("GPtrArray", DBUS_TYPE_G_OBJECT_PATH), &adapters, G_TYPE_INVALID) == FALSE) {
+		g_object_unref (manager);
+		dbus_g_connection_unref (connection);
+		return FALSE;
+	}
+
+	for (i = 0; i < adapters->len; i++) {
+		DBusGProxy *adapter, *device;
+		char *device_path;
+		GHashTable *props;
+
+		g_debug ("checking adapter %s", (gchar *) g_ptr_array_index (adapters, i));
+
+		adapter = dbus_g_proxy_new_for_name (connection, "org.bluez",
+						    g_ptr_array_index (adapters, i), "org.bluez.Adapter");
+
+		if (dbus_g_proxy_call (adapter, "FindDevice", NULL,
+				       G_TYPE_STRING, bdaddr, G_TYPE_INVALID,
+				       DBUS_TYPE_G_OBJECT_PATH, &device_path, G_TYPE_INVALID) == FALSE)
+		{
+			g_object_unref (adapter);
+			continue;
+		}
+
+		device = dbus_g_proxy_new_for_name (connection, "org.bluez", device_path, "org.bluez.Device");
+
+		if (dbus_g_proxy_call (device, "GetProperties", NULL,
+				       G_TYPE_INVALID, dbus_g_type_get_map ("GHashTable", G_TYPE_STRING, G_TYPE_VALUE),
+				       &props, G_TYPE_INVALID) != FALSE)
+		{
+			GValue *value;
+			gboolean bonded;
+
+			value = g_hash_table_lookup (props, "Paired");
+			bonded = g_value_get_boolean (value);
+			g_message ("%s is %s", bdaddr, bonded ? "bonded" : "not bonded");
+
+			if (bonded) {
+				g_hash_table_destroy (props);
+				g_object_unref (device);
+				g_object_unref (adapter);
+				retval = TRUE;
+				break;
+			}
+		}
+		g_object_unref(adapter);
+	}
+
+	g_ptr_array_free (adapters, TRUE);
+
+	g_object_unref(manager);
+	dbus_g_connection_unref(connection);
+
+	return retval;
+}
+
+static void
+transfer_started_cb (DBusGProxy *session,
+		     const char *filename,
+		     const char *local_path,
+		     guint64 size,
+		     gpointer user_data)
+{
+	GHashTable *dict;
+	DBusGProxy *server = (DBusGProxy *) user_data;
+	GError *error = NULL;
+	gboolean authorise;
+
+	g_message ("transfer started on %s", local_path);
+	g_object_set_data_full (G_OBJECT (session), "filename", g_strdup (local_path), (GDestroyNotify) g_free);
+
+	show_icon ();
+
+	/* First transfer of the session */
+	if (g_object_get_data (G_OBJECT (session), "bdaddr") == NULL) {
+		const char *bdaddr;
+
+		if (dbus_g_proxy_call (server, "GetServerSessionInfo", &error,
+				       DBUS_TYPE_G_OBJECT_PATH, dbus_g_proxy_get_path (session), G_TYPE_INVALID,
+				       DBUS_TYPE_G_STRING_VARIANT_HASHTABLE, &dict, G_TYPE_INVALID) == FALSE) {
+			g_printerr ("Getting Server session info failed: %s\n",
+				    error->message);
+			g_error_free (error);
+			return;
+		}
+
+		bdaddr = g_hash_table_lookup (dict, "BluetoothAddress");
+		g_message ("transfer started for device %s", bdaddr);
+
+		g_object_set_data_full (G_OBJECT (session), "bdaddr", g_strdup (bdaddr), (GDestroyNotify) g_free);
+		/* Initial accept method is undefined, we do that lower down */
+		g_object_set_data (G_OBJECT (session), "accept-method", GINT_TO_POINTER (-1));
+		g_hash_table_destroy (dict);
+	}
+
+	/* Accept method changed */
+	if (GPOINTER_TO_INT (g_object_get_data (G_OBJECT (session), "accept-method")) != accept_setting) {
+		const char *bdaddr;
+
+		bdaddr = g_object_get_data (G_OBJECT (session), "bdaddr");
+
+		if (bdaddr == NULL) {
+			g_warning ("Couldn't get the Bluetooth address for the device, rejecting the transfer");
+			authorise = FALSE;
+		} else if (accept_setting == ACCEPT_ALWAYS) {
+			authorise = TRUE;
+		} else if (accept_setting == ACCEPT_BONDED) {
+			authorise = device_is_authorised (bdaddr);
+		} else {
+			//FIXME implement
+			g_warning ("\"Ask\" authorisation method not implemented");
+			authorise = FALSE;
+		}
+		g_object_set_data (G_OBJECT (session), "authorise", GINT_TO_POINTER (authorise));
+	}
+
+	g_message ("accept_setting: %d", accept_setting);
+
+	authorise = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (session), "authorise"));
+	if (authorise != FALSE) {
+		if (dbus_g_proxy_call (session, "Accept", &error, G_TYPE_INVALID, G_TYPE_INVALID) == FALSE) {
+			g_printerr ("Failed to accept file transfer: %s\n", error->message);
+			g_error_free (error);
+			return;
+		}
+		g_message ("authorised transfer");
+	} else {
+		if (dbus_g_proxy_call (session, "Reject", &error, G_TYPE_INVALID, G_TYPE_INVALID) == FALSE) {
+			g_printerr ("Failed to reject file transfer: %s\n", error->message);
+			g_error_free (error);
+			return;
+		}
+		g_message ("rejected transfer");
+		g_object_set_data (G_OBJECT (session), "filename", NULL);
+	}
+}
+
+static void
+transfer_completed_cb (DBusGProxy *session,
+		       gpointer user_data)
+{
+	GSettings *settings;
+	gboolean display_notify;
+	const char *filename;
+
+	filename = (const char *) g_object_get_data (G_OBJECT (session), "filename");
+
+	g_message ("file finish transfer: %s", filename);
+
+	if (filename == NULL)
+		return;
+
+	settings = g_settings_new (GSETTINGS_SCHEMA);
+	display_notify = g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_OBEXPUSH_NOTIFY);
+	g_object_unref (settings);
+
+	if (display_notify) {
+		show_notification (filename);
+	} else {
+		hide_statusicon ();
+	}
+	g_object_set_data (G_OBJECT (session), "filename", NULL);
+}
+
+static void
+cancelled_cb (DBusGProxy *session,
+	      gpointer user_data)
+{
+	//FIXME implement properly, we never actually finished the transfer
+	g_message ("transfered was cancelled by the sender");
+	transfer_completed_cb (session, user_data);
+	hide_statusicon ();
+}
+
+static void
+error_occurred_cb (DBusGProxy *session,
+		   const char *error_name,
+		   const char *error_message,
+		   gpointer user_data)
+{
+	//FIXME implement properly
+	g_message ("transfer error occurred: %s", error_message);
+	transfer_completed_cb (session, user_data);
+}
+
+static void
+session_created_cb (DBusGProxy *server, const char *session_path, gpointer user_data)
+{
+	DBusGProxy *session;
+
+	session = dbus_g_proxy_new_for_name (connection,
+					     "org.openobex",
+					     session_path,
+					     "org.openobex.ServerSession");
+
+	dbus_g_proxy_add_signal (session, "TransferStarted",
+				 G_TYPE_STRING, G_TYPE_STRING, G_TYPE_UINT64, G_TYPE_INVALID);
+	dbus_g_proxy_connect_signal(session, "TransferStarted",
+				    G_CALLBACK (transfer_started_cb), server, NULL);
+	dbus_g_proxy_add_signal (session, "TransferCompleted",
+				 G_TYPE_INVALID, G_TYPE_INVALID);
+	dbus_g_proxy_connect_signal(session, "TransferCompleted",
+				    G_CALLBACK (transfer_completed_cb), server, NULL);
+	dbus_g_proxy_add_signal (session, "Cancelled",
+				 G_TYPE_INVALID, G_TYPE_INVALID);
+	dbus_g_proxy_connect_signal(session, "Cancelled",
+				    G_CALLBACK (cancelled_cb), server, NULL);
+	dbus_g_proxy_add_signal (session, "ErrorOccurred",
+				 G_TYPE_INVALID, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INVALID);
+	dbus_g_proxy_connect_signal(session, "ErrorOccurred",
+				    G_CALLBACK (error_occurred_cb), server, NULL);
+}
+
+void
+obexpush_up (void)
+{
+	GError *err = NULL;
+	char *download_dir, *server;
+
+	server = NULL;
+	if (manager_proxy == NULL) {
+		manager_proxy = dbus_g_proxy_new_for_name (connection,
+							   "org.openobex",
+							   "/org/openobex",
+							   "org.openobex.Manager");
+		if (dbus_g_proxy_call (manager_proxy, "CreateBluetoothServer",
+				       &err, G_TYPE_STRING, "00:00:00:00:00:00", G_TYPE_STRING, "opp", G_TYPE_BOOLEAN, FALSE, G_TYPE_INVALID,
+				       DBUS_TYPE_G_OBJECT_PATH, &server, G_TYPE_INVALID) == FALSE) {
+			g_printerr ("Creating Bluetooth ObexPush server failed: %s\n",
+				    err->message);
+			g_error_free (err);
+			g_object_unref (manager_proxy);
+			manager_proxy = NULL;
+			return;
+		}
+	}
+
+	download_dir = lookup_download_dir ();
+
+	if (server_proxy == NULL) {
+		server_proxy = dbus_g_proxy_new_for_name (connection,
+							   "org.openobex",
+							   server,
+							   "org.openobex.Server");
+		g_free (server);
+
+		dbus_g_proxy_add_signal (server_proxy, "SessionCreated",
+					 DBUS_TYPE_G_OBJECT_PATH, G_TYPE_INVALID);
+		dbus_g_proxy_connect_signal(server_proxy, "SessionCreated",
+					    G_CALLBACK (session_created_cb), NULL, NULL);
+	}
+
+	if (dbus_g_proxy_call (server_proxy, "Start", &err,
+			   G_TYPE_STRING, download_dir, G_TYPE_BOOLEAN, TRUE, G_TYPE_BOOLEAN, FALSE, G_TYPE_INVALID,
+			   G_TYPE_INVALID) == FALSE) {
+		if (g_error_matches (err, DBUS_GERROR, DBUS_GERROR_REMOTE_EXCEPTION) != FALSE &&
+		    dbus_g_error_has_name (err, "org.openobex.Error.Started") != FALSE) {
+		    	g_error_free (err);
+		    	g_message ("already started, ignoring error");
+		    	g_free (download_dir);
+		    	return;
+		}
+		g_printerr ("Starting Bluetooth ObexPush server failed: %s\n",
+			    err->message);
+		g_error_free (err);
+		g_free (download_dir);
+		g_object_unref (server_proxy);
+		server_proxy = NULL;
+		g_object_unref (manager_proxy);
+		manager_proxy = NULL;
+		return;
+	}
+
+	g_free (download_dir);
+}
+
+static void
+obexpush_stop (gboolean stop_manager)
+{
+	GError *err = NULL;
+
+	if (server_proxy == NULL)
+		return;
+
+	if (dbus_g_proxy_call (server_proxy, "Close", &err, G_TYPE_INVALID, G_TYPE_INVALID) == FALSE) {
+		if (g_error_matches (err, DBUS_GERROR, DBUS_GERROR_REMOTE_EXCEPTION) == FALSE ||
+		    dbus_g_error_has_name (err, "org.openobex.Error.NotStarted") == FALSE) {
+			g_printerr ("Stopping Bluetooth ObexPush server failed: %s\n",
+				    err->message);
+			g_error_free (err);
+			return;
+		}
+		g_error_free (err);
+	}
+
+	if (stop_manager != FALSE) {
+		g_object_unref (server_proxy);
+		server_proxy = NULL;
+		g_object_unref (manager_proxy);
+		manager_proxy = NULL;
+	}
+
+	//FIXME stop all the notifications
+}
+
+void
+obexpush_down (void)
+{
+	obexpush_stop (TRUE);
+}
+
+void
+obexpush_restart (void)
+{
+	obexpush_stop (FALSE);
+	obexpush_up ();
+}
+
+gboolean
+obexpush_init (void)
+{
+	GError *err = NULL;
+
+	connection = dbus_g_bus_get (DBUS_BUS_SESSION, &err);
+	if (connection == NULL) {
+		g_printerr ("Connecting to session bus failed: %s\n",
+			    err->message);
+		g_error_free (err);
+		return FALSE;
+	}
+
+	dbus_g_object_register_marshaller (marshal_VOID__STRING_STRING_UINT64,
+					   G_TYPE_NONE,
+					   G_TYPE_STRING, G_TYPE_STRING, G_TYPE_UINT64, G_TYPE_INVALID);
+
+	if (!notify_init("mate-user-share")) {
+		g_warning("Unable to initialize the notification system\n");
+        }
+
+	dbus_connection_set_exit_on_disconnect (dbus_g_connection_get_connection (connection), FALSE);
+
+	return TRUE;
+}
+
+void
+obexpush_set_accept_files_policy (AcceptSetting setting)
+{
+	accept_setting = setting;
+}
+
+void
+obexpush_set_notify (gboolean enabled)
+{
+	show_notifications = enabled;
+}
+
+
+
+ + + diff --git a/2020-06-22-164518-5655-cppcheck@b751b682733f_travis-ci/3.html b/2020-06-22-164518-5655-cppcheck@b751b682733f_travis-ci/3.html new file mode 100644 index 0000000..f31a1bc --- /dev/null +++ b/2020-06-22-164518-5655-cppcheck@b751b682733f_travis-ci/3.html @@ -0,0 +1,748 @@ + + + + + + Cppcheck - HTML report - mate-user-share + + + + + + + +
+
  1
+  2
+  3
+  4
+  5
+  6
+  7
+  8
+  9
+ 10
+ 11
+ 12
+ 13
+ 14
+ 15
+ 16
+ 17
+ 18
+ 19
+ 20
+ 21
+ 22
+ 23
+ 24
+ 25
+ 26
+ 27
+ 28
+ 29
+ 30
+ 31
+ 32
+ 33
+ 34
+ 35
+ 36
+ 37
+ 38
+ 39
+ 40
+ 41
+ 42
+ 43
+ 44
+ 45
+ 46
+ 47
+ 48
+ 49
+ 50
+ 51
+ 52
+ 53
+ 54
+ 55
+ 56
+ 57
+ 58
+ 59
+ 60
+ 61
+ 62
+ 63
+ 64
+ 65
+ 66
+ 67
+ 68
+ 69
+ 70
+ 71
+ 72
+ 73
+ 74
+ 75
+ 76
+ 77
+ 78
+ 79
+ 80
+ 81
+ 82
+ 83
+ 84
+ 85
+ 86
+ 87
+ 88
+ 89
+ 90
+ 91
+ 92
+ 93
+ 94
+ 95
+ 96
+ 97
+ 98
+ 99
+100
+101
+102
+103
+104
+105
+106
+107
+108
+109
+110
+111
+112
+113
+114
+115
+116
+117
+118
+119
+120
+121
+122
+123
+124
+125
+126
+127
+128
+129
+130
+131
+132
+133
+134
+135
+136
+137
+138
+139
+140
+141
+142
+143
+144
+145
+146
+147
+148
+149
+150
+151
+152
+153
+154
+155
+156
+157
+158
+159
+160
+161
+162
+163
+164
+165
+166
+167
+168
+169
+170
+171
+172
+173
+174
+175
+176
+177
+178
+179
+180
+181
+182
+183
+184
+185
+186
+187
+188
+189
+190
+191
+192
+193
+194
+195
+196
+197
+198
+199
+200
+201
+202
+203
+204
+205
+206
+207
+208
+209
+210
+211
+212
+213
+214
+215
+216
+217
+218
+219
+220
+221
+222
+223
+224
+225
+226
+227
+228
+229
+230
+231
+232
+233
+234
+235
+236
+237
+238
+239
+240
+241
+242
+243
+244
+245
+246
+247
+248
+249
+250
+251
+252
+253
+254
+255
+256
+257
+258
+259
+260
+261
+262
+263
+264
+265
+266
+267
+268
+269
+270
+271
+272
+273
+274
+275
+276
+277
+278
+279
+280
+281
+282
+283
+284
+285
+286
+287
+288
+289
+290
+291
/* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 8; tab-width: 8 -*-
+ *
+ * Copyright (C) 2003 Novell, Inc.
+ * Copyright (C) 2003-2004 Red Hat, Inc.
+ * Copyright (C) 2005 William Jon McCann <mccann@jhu.edu>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * 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 Foundation, Inc., 51 Franklin St, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ *
+ */
+
+#include "config.h"
+
+#include <stdlib.h>
+#include <string.h>
+#include <glib/gi18n-lib.h>
+#include <gtk/gtk.h>
+#include <libcaja-extension/caja-menu-provider.h>
+#include <libcaja-extension/caja-location-widget-provider.h>
+
+#ifdef HAVE_BLUETOOTH
+#include <bluetooth-client.h>
+#endif
+
+#include "caja-share-bar.h"
+#include "user_share-common.h"
+
+#define CAJA_TYPE_USER_SHARE  (caja_user_share_get_type ())
+#define CAJA_USER_SHARE(o)    (G_TYPE_CHECK_INSTANCE_CAST ((o), CAJA_TYPE_USER_SHARE, CajaUserShare))
+#define CAJA_IS_USER_SHARE(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), CAJA_TYPE_USER_SHARE))
+
+typedef struct
+{
+        GObject              parent_slot;
+} CajaUserShare;
+
+typedef struct
+{
+        GObjectClass parent_slot;
+} CajaUserShareClass;
+
+static GType caja_user_share_get_type      (void);
+static void  caja_user_share_register_type (GTypeModule *module);
+
+static void
+launch_process (char **argv, GtkWindow *parent)
+{
+        GError *error;
+        GtkWidget *dialog;
+
+        error = NULL;
+        if (!g_spawn_async (NULL,
+                            argv, NULL,
+                            0,
+                            NULL, NULL,
+                            NULL,
+                            &error)) {
+
+
+                dialog = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL, GTK_MESSAGE_WARNING,
+						 GTK_BUTTONS_OK, _("Unable to launch the Personal File Sharing preferences"));
+
+                gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog), "%s", error->message);
+
+                gtk_dialog_run (GTK_DIALOG (dialog));
+                gtk_widget_destroy (dialog);
+
+                g_error_free (error);
+        }
+}
+
+static void
+launch_prefs_on_window (GtkWindow *window)
+{
+        char *argv [2];
+
+        argv [0] = g_build_filename (BINDIR, "mate-file-share-properties", NULL);
+        argv [1] = NULL;
+
+        launch_process (argv, window);
+
+        g_free (argv [0]);
+}
+
+static void
+bar_response_cb (CajaShareBar *bar,
+                 gint response,
+                 gpointer         data)
+{
+        if (response == CAJA_SHARE_BAR_RESPONSE_PREFERENCES) {
+                launch_prefs_on_window (GTK_WINDOW (data));
+        }
+}
+
+#ifdef HAVE_BLUETOOTH
+static void
+downloads_bar_set_from_bluetooth_status (GtkWidget *bar)
+{
+	BluetoothClient *client;
+	gboolean bt_powered;
+
+	client = g_object_get_data (G_OBJECT (bar), "bluetooth-client");
+	g_object_get (G_OBJECT (client),
+		      "default-adapter-powered", &bt_powered,
+		      NULL);
+	gtk_widget_set_visible (bar, bt_powered);
+}
+
+static void
+default_adapter_powered_cb (GObject    *gobject,
+			    GParamSpec *pspec,
+			    GtkWidget  *bar)
+{
+	downloads_bar_set_from_bluetooth_status (bar);
+}
+#endif /* HAVE_BLUETOOTH */
+
+static GtkWidget *
+caja_user_share_get_location_widget (CajaLocationWidgetProvider *iface,
+                                         const char                     *uri,
+                                         GtkWidget                      *window)
+{
+	GFile             *file;
+	GtkWidget         *bar;
+	guint              i;
+	gboolean           enable = FALSE;
+	GFile             *home;
+#ifdef HAVE_BLUETOOTH
+	const GUserDirectory special_dirs[] = { G_USER_DIRECTORY_PUBLIC_SHARE, G_USER_DIRECTORY_DOWNLOAD };
+
+	gboolean is_dir[] = { FALSE, FALSE };
+#else
+	const GUserDirectory special_dirs[] = { G_USER_DIRECTORY_PUBLIC_SHARE };
+
+	gboolean is_dir[] = { FALSE };
+#endif /* HAVE_BLUETOOTH */
+	file = g_file_new_for_uri (uri);
+	home = g_file_new_for_path (g_get_home_dir ());
+
+	/* We don't show anything in $HOME */
+	if (g_file_equal (home, file)) {
+		g_object_unref (home);
+		g_object_unref (file);
+		return NULL;
+	}
+
+	g_object_unref (home);
+
+	for (i = 0; i < G_N_ELEMENTS (special_dirs); i++) {
+		GFile *dir;
+		dir = lookup_dir_with_fallback (special_dirs[i]);
+		if (g_file_equal (dir, file)) {
+			enable = TRUE;
+			is_dir[i] = TRUE;
+		}
+		g_object_unref (dir);
+	}
+
+	g_object_unref (file);
+
+	if (enable == FALSE)
+		return NULL;
+
+	if (is_dir[0] != FALSE) {
+#ifdef HAVE_BLUETOOTH
+		if (is_dir[1] != FALSE) {
+			bar = caja_share_bar_new (_("May be used to share or receive files"));
+		} else {
+			bar = caja_share_bar_new (_("May be shared over the network or Bluetooth"));
+		}
+#else
+		bar = caja_share_bar_new (_("May be shared over the network"));
+#endif /* HAVE_BLUETOOTH */
+	} else {
+#ifdef HAVE_BLUETOOTH
+		BluetoothClient *client;
+
+		bar = caja_share_bar_new (_("May be used to receive files over Bluetooth"));
+
+		gtk_widget_set_no_show_all (bar, TRUE);
+		client = bluetooth_client_new ();
+		g_object_set_data_full (G_OBJECT (bar), "bluetooth-client", client, g_object_unref);
+		g_signal_connect (G_OBJECT (client), "notify::default-adapter-powered",
+				  G_CALLBACK (default_adapter_powered_cb), bar);
+		downloads_bar_set_from_bluetooth_status (bar);
+#endif /* HAVE_BLUETOOTH */
+	}
+
+	g_signal_connect (bar, "response",
+			  G_CALLBACK (bar_response_cb),
+			  window);
+
+	gtk_widget_show_all (bar);
+
+	return bar;
+}
+
+static void
+caja_user_share_location_widget_provider_iface_init (CajaLocationWidgetProviderIface *iface)
+{
+        iface->get_widget = caja_user_share_get_location_widget;
+}
+
+static void
+caja_user_share_instance_init (CajaUserShare *share)
+{
+
+}
+
+static void
+caja_user_share_class_init (CajaUserShareClass *klass)
+{
+
+}
+
+static GType share_type = 0;
+
+static GType
+caja_user_share_get_type (void)
+{
+        return share_type;
+}
+
+static void
+caja_user_share_register_type (GTypeModule *module)
+{
+        static const GTypeInfo info = {
+                sizeof (CajaUserShareClass),
+                (GBaseInitFunc) NULL,
+                (GBaseFinalizeFunc) NULL,
+                (GClassInitFunc) caja_user_share_class_init,
+                NULL,
+                NULL,
+                sizeof (CajaUserShare),
+                0,
+                (GInstanceInitFunc) caja_user_share_instance_init,
+        };
+
+        static const GInterfaceInfo location_widget_provider_iface_info = {
+                (GInterfaceInitFunc) caja_user_share_location_widget_provider_iface_init,
+                NULL,
+                NULL
+        };
+
+        share_type = g_type_module_register_type (module,
+                                                 G_TYPE_OBJECT,
+                                                 "CajaUserShare",
+                                                 &info, 0);
+
+        g_type_module_add_interface (module,
+                                     share_type,
+                                     CAJA_TYPE_LOCATION_WIDGET_PROVIDER,
+                                     &location_widget_provider_iface_info);
+}
+
+void
+caja_module_initialize (GTypeModule *module)
+{
+        caja_user_share_register_type (module);
+        bindtextdomain (GETTEXT_PACKAGE, MATELOCALEDIR);
+        bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
+}
+
+void
+caja_module_shutdown (void)
+{
+}
+
+void
+caja_module_list_types (const GType **types,
+                            int          *num_types)
+{
+        static GType type_list [1];
+
+        type_list[0] = CAJA_TYPE_USER_SHARE;
+
+        *types = type_list;
+        *num_types = 1;
+}
+
+
+
+ + + diff --git a/2020-06-22-164518-5655-cppcheck@b751b682733f_travis-ci/4.html b/2020-06-22-164518-5655-cppcheck@b751b682733f_travis-ci/4.html new file mode 100644 index 0000000..462c100 --- /dev/null +++ b/2020-06-22-164518-5655-cppcheck@b751b682733f_travis-ci/4.html @@ -0,0 +1,336 @@ + + + + + + Cppcheck - HTML report - mate-user-share + + + + + + + +
+
 1
+ 2
+ 3
+ 4
+ 5
+ 6
+ 7
+ 8
+ 9
+10
+11
+12
+13
+14
+15
+16
+17
+18
+19
+20
+21
+22
+23
+24
+25
+26
+27
+28
+29
+30
+31
+32
+33
+34
+35
+36
+37
+38
+39
+40
+41
+42
+43
+44
+45
+46
+47
+48
+49
+50
+51
+52
+53
+54
+55
+56
+57
+58
+59
+60
+61
+62
+63
+64
+65
+66
+67
+68
+69
+70
+71
+72
+73
+74
+75
+76
+77
+78
+79
+80
+81
+82
+83
+84
+85
+86
+87
+88
+89
+90
+91
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
+
+/*
+ *  Copyright (C) 2004-2009 Red Hat, Inc.
+ *
+ *  Caja is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU General Public License as
+ *  published by the Free Software Foundation; either version 2 of the
+ *  License, or (at your option) any later version.
+ *
+ *  Caja is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  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
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ *  Authors: Alexander Larsson <alexl@redhat.com>
+ *  Bastien Nocera <hadess@hadess.net>
+ *
+ */
+
+#include <string.h>
+
+#include "user_share-common.h"
+
+static char *
+lookup_special_dir (GUserDirectory directory,
+		    const char *name,
+		    gboolean create_dir)
+{
+	const char *special_dir;
+	char *dir;
+
+	special_dir = g_get_user_special_dir (directory);
+	if (special_dir != NULL && strcmp (special_dir, g_get_home_dir ()) != 0) {
+		if (create_dir != FALSE)
+			g_mkdir_with_parents (special_dir, 0755);
+		return g_strdup (special_dir);
+	}
+
+	dir = g_build_filename (g_get_home_dir (), name, NULL);
+	if (create_dir != FALSE)
+		g_mkdir_with_parents (dir, 0755);
+	return dir;
+}
+
+char *
+lookup_public_dir (void)
+{
+	return lookup_special_dir (G_USER_DIRECTORY_PUBLIC_SHARE,
+				   "Public",
+				   TRUE);
+}
+
+char *
+lookup_download_dir (void)
+{
+	return lookup_special_dir (G_USER_DIRECTORY_DOWNLOAD,
+				   "Downloads",
+				   TRUE);
+}
+
+GFile *
+lookup_dir_with_fallback (GUserDirectory directory)
+{
+	GFile *file;
+	char *path;
+	const char *name;
+
+	if (directory == G_USER_DIRECTORY_PUBLIC_SHARE)
+		name = "Public";
+	else if (directory == G_USER_DIRECTORY_DOWNLOAD)
+		name = "Downloads";
+	else
+		g_assert_not_reached ();
+
+	path = lookup_special_dir (directory,
+				   name,<--- Uninitialized variable: name
+				   FALSE);
+
+	if (path == NULL)
+		return NULL;
+
+	file = g_file_new_for_path (path);
+	g_free (path);
+
+	return file;
+}
+
+
+
+ + + diff --git a/2020-06-22-164518-5655-cppcheck@b751b682733f_travis-ci/5.html b/2020-06-22-164518-5655-cppcheck@b751b682733f_travis-ci/5.html new file mode 100644 index 0000000..5dde496 --- /dev/null +++ b/2020-06-22-164518-5655-cppcheck@b751b682733f_travis-ci/5.html @@ -0,0 +1,1166 @@ + + + + + + Cppcheck - HTML report - mate-user-share + + + + + + + +
+
  1
+  2
+  3
+  4
+  5
+  6
+  7
+  8
+  9
+ 10
+ 11
+ 12
+ 13
+ 14
+ 15
+ 16
+ 17
+ 18
+ 19
+ 20
+ 21
+ 22
+ 23
+ 24
+ 25
+ 26
+ 27
+ 28
+ 29
+ 30
+ 31
+ 32
+ 33
+ 34
+ 35
+ 36
+ 37
+ 38
+ 39
+ 40
+ 41
+ 42
+ 43
+ 44
+ 45
+ 46
+ 47
+ 48
+ 49
+ 50
+ 51
+ 52
+ 53
+ 54
+ 55
+ 56
+ 57
+ 58
+ 59
+ 60
+ 61
+ 62
+ 63
+ 64
+ 65
+ 66
+ 67
+ 68
+ 69
+ 70
+ 71
+ 72
+ 73
+ 74
+ 75
+ 76
+ 77
+ 78
+ 79
+ 80
+ 81
+ 82
+ 83
+ 84
+ 85
+ 86
+ 87
+ 88
+ 89
+ 90
+ 91
+ 92
+ 93
+ 94
+ 95
+ 96
+ 97
+ 98
+ 99
+100
+101
+102
+103
+104
+105
+106
+107
+108
+109
+110
+111
+112
+113
+114
+115
+116
+117
+118
+119
+120
+121
+122
+123
+124
+125
+126
+127
+128
+129
+130
+131
+132
+133
+134
+135
+136
+137
+138
+139
+140
+141
+142
+143
+144
+145
+146
+147
+148
+149
+150
+151
+152
+153
+154
+155
+156
+157
+158
+159
+160
+161
+162
+163
+164
+165
+166
+167
+168
+169
+170
+171
+172
+173
+174
+175
+176
+177
+178
+179
+180
+181
+182
+183
+184
+185
+186
+187
+188
+189
+190
+191
+192
+193
+194
+195
+196
+197
+198
+199
+200
+201
+202
+203
+204
+205
+206
+207
+208
+209
+210
+211
+212
+213
+214
+215
+216
+217
+218
+219
+220
+221
+222
+223
+224
+225
+226
+227
+228
+229
+230
+231
+232
+233
+234
+235
+236
+237
+238
+239
+240
+241
+242
+243
+244
+245
+246
+247
+248
+249
+250
+251
+252
+253
+254
+255
+256
+257
+258
+259
+260
+261
+262
+263
+264
+265
+266
+267
+268
+269
+270
+271
+272
+273
+274
+275
+276
+277
+278
+279
+280
+281
+282
+283
+284
+285
+286
+287
+288
+289
+290
+291
+292
+293
+294
+295
+296
+297
+298
+299
+300
+301
+302
+303
+304
+305
+306
+307
+308
+309
+310
+311
+312
+313
+314
+315
+316
+317
+318
+319
+320
+321
+322
+323
+324
+325
+326
+327
+328
+329
+330
+331
+332
+333
+334
+335
+336
+337
+338
+339
+340
+341
+342
+343
+344
+345
+346
+347
+348
+349
+350
+351
+352
+353
+354
+355
+356
+357
+358
+359
+360
+361
+362
+363
+364
+365
+366
+367
+368
+369
+370
+371
+372
+373
+374
+375
+376
+377
+378
+379
+380
+381
+382
+383
+384
+385
+386
+387
+388
+389
+390
+391
+392
+393
+394
+395
+396
+397
+398
+399
+400
+401
+402
+403
+404
+405
+406
+407
+408
+409
+410
+411
+412
+413
+414
+415
+416
+417
+418
+419
+420
+421
+422
+423
+424
+425
+426
+427
+428
+429
+430
+431
+432
+433
+434
+435
+436
+437
+438
+439
+440
+441
+442
+443
+444
+445
+446
+447
+448
+449
+450
+451
+452
+453
+454
+455
+456
+457
+458
+459
+460
+461
+462
+463
+464
+465
+466
+467
+468
+469
+470
+471
+472
+473
+474
+475
+476
+477
+478
+479
+480
+481
+482
+483
+484
+485
+486
+487
+488
+489
+490
+491
+492
+493
+494
+495
+496
+497
+498
+499
+500
+501
+502
+503
+504
+505
+506
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
+
+/*
+ *  Copyright (C) 2004-2008 Red Hat, Inc.
+ *
+ *  Caja is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU General Public License as
+ *  published by the Free Software Foundation; either version 2 of the
+ *  License, or (at your option) any later version.
+ *
+ *  Caja is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  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
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ *  Authors: Alexander Larsson <alexl@redhat.com>
+ *
+ */
+
+#include "config.h"
+
+#include <gdk/gdkx.h>
+#include <gtk/gtk.h>
+#include <glib/gi18n.h>
+#include <glib/gstdio.h>
+#include <gio/gio.h>
+#include <X11/Xlib.h>
+
+#include "user_share-private.h"
+#include "user_share-common.h"
+#include "http.h"
+
+#ifdef HAVE_BLUETOOTH
+#include <bluetooth-client.h>
+
+#include "obexftp.h"
+#include "obexpush.h"
+
+#endif /* HAVE_BLUETOOTH */
+
+#include <gio/gio.h>
+
+#include <stdarg.h>
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <signal.h>
+#include <unistd.h>
+
+static guint disabled_timeout_tag = 0;
+static GSettings* settings;<--- Shadowed declaration<--- Shadowed declaration<--- Shadowed declaration
+
+#define GSETTINGS_SCHEMA "org.mate.FileSharing"
+#define GSETTINGS_KEY_FILE_SHARING_ENABLED "enabled"
+#define GSETTINGS_KEY_FILE_SHARING_REQUIRE_PASSWORD "require-password"
+
+#ifdef HAVE_BLUETOOTH
+/* MATE Session */
+#define MATE_SESSION_DBUS_NAME      "org.gnome.SessionManager"
+#define MATE_SESSION_DBUS_OBJECT    "/org/gnome/SessionManager"
+#define MATE_SESSION_DBUS_INTERFACE "org.gnome.SessionManager"
+
+static GDBusProxy *session_proxy = NULL;
+static gboolean has_console = TRUE;
+
+static BluetoothClient *client = NULL;
+static gboolean bluetoothd_enabled = FALSE;
+
+#define OBEX_ENABLED (bluetoothd_enabled && has_console)
+
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_ENABLED "bluetooth-enabled"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_ALLOW_WRITE "bluetooth-allow-write"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_REQUIRE_PAIRING "bluetooth-require-pairing"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED "bluetooth-obexpush-enabled"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_ACCEPT_FILES "bluetooth-accept-files"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_NOTIFY "bluetooth-notify"
+
+
+static void
+obex_services_start (void)
+{
+	GSettings *settings;<--- Shadow variable
+
+	if (bluetoothd_enabled == FALSE ||
+	    has_console == FALSE)
+	    	return;
+
+	settings = g_settings_new(GSETTINGS_SCHEMA);
+
+	if (g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED) == TRUE) {
+	    obexpush_up ();
+	}
+	if (g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_ENABLED) == TRUE) {
+	    obexftp_up ();
+	}
+
+	g_object_unref (client);
+}
+
+static void
+obex_services_shutdown (void)
+{
+	obexpush_down ();
+	obexftp_down ();
+}
+
+static void
+session_properties_changed_cb (GDBusProxy      *session,
+			       GVariant        *changed,
+			       char           **invalidated,
+			       gpointer         user_data)
+{
+	GVariant *v;
+
+	v = g_variant_lookup_value (changed, "SessionIsActive", G_VARIANT_TYPE_BOOLEAN);
+	if (v) {
+		has_console = g_variant_get_boolean (v);
+		g_debug ("Received session is active change: now %s", has_console ? "active" : "inactive");
+
+		if (has_console)
+			obex_services_start ();
+		else
+			obex_services_shutdown ();
+
+		g_variant_unref (v);
+	}
+}
+
+static gboolean
+is_session_active (void)
+{
+	GVariant *variant;
+	gboolean is_session_active = FALSE;
+
+	variant = g_dbus_proxy_get_cached_property (session_proxy,
+						    "SessionIsActive");
+	if (variant) {
+		is_session_active = g_variant_get_boolean (variant);
+		g_variant_unref (variant);
+ 	}
+
+	return is_session_active;
+}
+
+static void
+session_init (void)
+{
+	GError *error = NULL;
+
+	session_proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION,
+						       G_DBUS_PROXY_FLAGS_NONE,
+						       NULL,
+						       MATE_SESSION_DBUS_NAME,
+						       MATE_SESSION_DBUS_OBJECT,
+						       MATE_SESSION_DBUS_INTERFACE,
+						       NULL,
+						       &error);
+	if (session_proxy == NULL) {
+		g_warning ("Failed to get session proxy: %s", error->message);
+		g_error_free (error);
+		return;
+	}
+	g_signal_connect (session_proxy, "g-properties-changed",
+			  G_CALLBACK (session_properties_changed_cb),
+			  NULL);
+	has_console = is_session_active ();
+}
+
+static void
+default_adapter_changed (GObject    *gobject,
+			 GParamSpec *pspec,
+			 gpointer    user_data)
+{
+	char *adapter;
+	gboolean adapter_powered;
+
+	g_object_get (G_OBJECT (client),
+		      "default-adapter", &adapter,
+		      "default-adapter-powered", &adapter_powered,
+		      NULL);
+	if (adapter != NULL && *adapter != '\0') {
+		bluetoothd_enabled = adapter_powered;
+	} else {
+		bluetoothd_enabled = FALSE;
+	}
+
+	/* Were we called as init, or as a callback */
+	if (gobject != NULL) {
+		if (bluetoothd_enabled != FALSE)
+			obex_services_start ();
+		else
+			obex_services_shutdown ();
+	}
+}
+
+static void
+bluez_init (void)
+{
+	client = bluetooth_client_new ();
+	default_adapter_changed (NULL, NULL, NULL);
+	g_signal_connect (G_OBJECT (client), "notify::default-adapter",
+			  G_CALLBACK (default_adapter_changed), NULL);
+	g_signal_connect (G_OBJECT (client), "notify::default-adapter-powered",
+			  G_CALLBACK (default_adapter_changed), NULL);
+}
+#endif /* HAVE_BLUETOOTH */
+
+static gboolean
+file_sharing_enabled (void)
+{
+	gboolean enabled = TRUE;
+	settings = g_settings_new (GSETTINGS_SCHEMA);
+
+#ifdef HAVE_BLUETOOTH
+	if (g_settings_get_boolean (settings, FILE_SHARING_ENABLED) == FALSE &&
+	    g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_ENABLED) == FALSE &&
+	    g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED) == FALSE)
+#else /* HAVE_BLUETOOTH */
+	if (g_settings_get_boolean (settings, FILE_SHARING_ENABLED) == FALSE)
+#endif /* HAVE_BLUETOOTH */
+		enabled = FALSE;
+
+	g_object_unref (settings);
+
+	return enabled;
+}
+
+static void
+migrate_old_configuration (void)
+{
+	const char *old_config_dir;
+	const char *new_config_dir;
+
+	old_config_dir = g_build_filename (g_get_home_dir (), ".mate2", "user-share", NULL);
+	new_config_dir = g_build_filename (g_get_user_config_dir (), "user-share", NULL);
+	if (g_file_test (old_config_dir, G_FILE_TEST_IS_DIR))
+		g_rename (old_config_dir, new_config_dir);
+
+}
+
+static void
+require_password_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	/* Need to restart to get new password setting */
+	if (http_get_pid () != 0) {
+		http_down ();
+		http_up ();
+	}
+}
+
+/* File sharing was disabled for some time, exit now */
+/* If we re-enable it in the ui, this will be restarted anyway */
+static gboolean
+disabled_timeout_callback (gpointer user_data)
+{
+	GSettings *settings = (GSettings *) user_data;<--- Shadow variable
+	http_down ();
+
+#ifdef HAVE_BLUETOOTH
+	if (g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_ENABLED) == FALSE &&
+	    g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED) == FALSE)
+		_exit (0);
+#else /* HAVE_BLUETOOTH */
+	if (g_settings_get_boolean (settings, FILE_SHARING_ENABLED) == FALSE)
+		_exit (0);
+#endif /* HAVE_BLUETOOTH */
+	return FALSE;
+}
+
+static void
+file_sharing_enabled_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	gboolean enabled;
+
+	if (disabled_timeout_tag != 0) {
+		g_source_remove (disabled_timeout_tag);
+		disabled_timeout_tag = 0;
+	}
+
+	enabled = g_settings_get_boolean (settings,
+					 FILE_SHARING_ENABLED);
+	if (enabled) {
+		if (http_get_pid () == 0) {
+			http_up ();
+		}
+	} else {
+		http_down ();
+		disabled_timeout_tag = g_timeout_add_seconds (3,
+							      (GSourceFunc)disabled_timeout_callback,
+							      settings);
+	}
+}
+
+#ifdef HAVE_BLUETOOTH
+static void
+file_sharing_bluetooth_allow_write_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	if (g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_ENABLED) != FALSE)
+		obexftp_restart ();
+}
+
+static void
+file_sharing_bluetooth_require_pairing_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	if (g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_ENABLED) != FALSE) {
+		/* We need to fully reset the session,
+		 * otherwise the new setting isn't taken into account */
+		obexftp_down ();
+		obexftp_up ();
+	}
+}
+
+static void
+file_sharing_bluetooth_enabled_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	if (g_settings_get_boolean (settings,
+				   FILE_SHARING_BLUETOOTH_ENABLED) == FALSE) {
+		obexftp_down ();
+		if (g_settings_get_boolean (settings, FILE_SHARING_ENABLED) == FALSE &&
+		    g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED) == FALSE) {
+			_exit (0);
+		}
+	} else if (OBEX_ENABLED) {
+		obexftp_up ();
+	}
+}
+
+static void
+file_sharing_bluetooth_obexpush_enabled_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	if (g_settings_get_boolean (settings,
+				   FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED) == FALSE) {
+		obexpush_down ();
+		if (g_settings_get_boolean (settings, FILE_SHARING_ENABLED) == FALSE &&
+		    g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_ENABLED) == FALSE) {
+			_exit (0);
+		}
+	} else if (OBEX_ENABLED) {
+		obexpush_up ();
+	}
+}
+
+static void
+file_sharing_bluetooth_obexpush_accept_files_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	AcceptSetting setting;
+	char *str;
+
+	str = g_settings_get_string (settings, FILE_SHARING_BLUETOOTH_OBEXPUSH_ACCEPT_FILES);
+	setting = accept_setting_from_string (str);
+	g_free (str);
+
+	obexpush_set_accept_files_policy (setting);
+}
+
+static void
+file_sharing_bluetooth_obexpush_notify_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	obexpush_set_notify (g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_OBEXPUSH_NOTIFY));
+}
+#endif /* HAVE_BLUETOOTH */
+
+static RETSIGTYPE
+cleanup_handler (int sig)
+{
+	http_down ();
+#ifdef HAVE_BLUETOOTH
+	obexftp_down ();
+	obexpush_down ();
+#endif /* HAVE_BLUETOOTH */
+	_exit (2);
+}
+
+static int
+x_io_error_handler (Display *xdisplay)
+{
+	http_down ();
+#ifdef HAVE_BLUETOOTH
+	obexftp_down ();
+#endif /* HAVE_BLUETOOTH */
+	_exit (2);
+}
+
+int
+main (int argc, char **argv)
+{
+	GSettings *settings;<--- Shadow variable
+	Display *xdisplay;
+	G_GNUC_UNUSED int x_fd;
+	Window selection_owner;
+	Atom xatom;
+
+	bindtextdomain (GETTEXT_PACKAGE, MATELOCALEDIR);
+	bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
+	textdomain (GETTEXT_PACKAGE);
+
+	gtk_init (&argc, &argv);
+
+	if (g_strcmp0 (g_get_real_name (), "root") == 0) {
+		g_warning ("mate-user-share cannot be started as root for security reasons.");
+		return 1;
+	}
+
+	signal (SIGPIPE, SIG_IGN);
+	signal (SIGINT, cleanup_handler);
+	signal (SIGHUP, cleanup_handler);
+	signal (SIGTERM, cleanup_handler);
+
+	xdisplay = GDK_DISPLAY_XDISPLAY (gdk_display_get_default ());
+	if (xdisplay == NULL) {
+		g_warning ("Can't open display");
+		return 1;
+	}
+
+	xatom = XInternAtom (xdisplay, "_MATE_USER_SHARE", FALSE);
+	selection_owner = XGetSelectionOwner (xdisplay, xatom);
+
+	if (selection_owner != None) {
+		/* There is an owner already, quit */
+		return 1;
+	}
+
+	selection_owner = XCreateSimpleWindow (xdisplay,
+					       RootWindow (xdisplay, 0),
+					       0, 0, 1, 1,
+					       0, 0, 0);
+	XSetSelectionOwner (xdisplay, xatom, selection_owner, CurrentTime);
+
+	if (XGetSelectionOwner (xdisplay, xatom) != selection_owner) {
+		/* Didn't get the selection */
+		return 1;
+	}
+
+	migrate_old_configuration ();
+
+	if (!file_sharing_enabled ())
+		return 1;
+
+	settings = g_settings_new (GSETTINGS_SCHEMA);
+
+	x_fd = ConnectionNumber (xdisplay);
+	XSetIOErrorHandler (x_io_error_handler);
+
+	if (http_init () == FALSE)
+		return 1;
+#ifdef HAVE_BLUETOOTH
+	if (obexftp_init () == FALSE)
+		return 1;
+	if (obexpush_init () == FALSE)
+		return 1;
+#endif /* HAVE_BLUETOOTH */
+
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_ENABLED,
+			     G_CALLBACK (file_sharing_enabled_changed), NULL);
+
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_REQUIRE_PASSWORD,
+			     G_CALLBACK (require_password_changed), NULL);
+
+#ifdef HAVE_BLUETOOTH
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_ENABLED,
+			     G_CALLBACK (file_sharing_bluetooth_enabled_changed), NULL);
+
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_ALLOW_WRITE,
+			     G_CALLBACK (file_sharing_bluetooth_allow_write_changed), NULL);
+
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_REQUIRE_PAIRING,
+			     G_CALLBACK (file_sharing_bluetooth_require_pairing_changed), NULL);
+
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED,
+			     G_CALLBACK (file_sharing_bluetooth_obexpush_enabled_changed), NULL);
+
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_ACCEPT_FILES,
+			     G_CALLBACK (file_sharing_bluetooth_obexpush_accept_files_changed), NULL);
+
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_NOTIFY,
+			     G_CALLBACK (file_sharing_bluetooth_obexpush_notify_changed), NULL);
+
+	bluez_init ();
+	session_init ();
+#endif /* HAVE_BLUETOOTH */
+
+	/* Initial setting */
+	file_sharing_enabled_changed (settings, NULL, NULL);
+#ifdef HAVE_BLUETOOTH
+	file_sharing_bluetooth_enabled_changed (settings, NULL, NULL);
+	file_sharing_bluetooth_obexpush_accept_files_changed (settings, NULL, NULL);
+	file_sharing_bluetooth_obexpush_notify_changed (settings, NULL, NULL);
+	file_sharing_bluetooth_obexpush_enabled_changed (settings, NULL, NULL);
+#endif /* HAVE_BLUETOOTH */
+
+	gtk_main ();
+
+	return 0;
+}
+
+
+
+ + + diff --git a/2020-06-22-164518-5655-cppcheck@b751b682733f_travis-ci/index.html b/2020-06-22-164518-5655-cppcheck@b751b682733f_travis-ci/index.html new file mode 100644 index 0000000..a691de5 --- /dev/null +++ b/2020-06-22-164518-5655-cppcheck@b751b682733f_travis-ci/index.html @@ -0,0 +1,130 @@ + + + + + + Cppcheck - HTML report - mate-user-share + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
LineIdCWESeverityMessage
missingIncludeinformationCppcheck cannot find all the include files (use --check-config for details)
src/file-share-properties.c
82variableScope398styleThe scope of the variable 'password' can be reduced.
97shadowVariable398styleLocal variable 'settings' shadows outer variable
105unusedVariable563styleUnused variable: accept_setting
249shadowVariable398styleLocal variable 'settings' shadows outer variable
273shadowVariable398styleLocal variable 'settings' shadows outer variable
294shadowVariable398styleLocal variable 'settings' shadows outer variable
323shadowVariable398styleLocal variable 'settings' shadows outer variable
340shadowVariable398styleLocal variable 'settings' shadows outer variable
357shadowVariable398styleLocal variable 'settings' shadows outer variable
377shadowVariable398styleLocal variable 'settings' shadows outer variable
393shadowVariable398styleLocal variable 'settings' shadows outer variable
457shadowVariable398styleLocal variable 'settings' shadows outer variable
620variableScope398styleThe scope of the variable 'window' can be reduced.
src/http.c
107nullPointerArithmeticRedundantCheck682warningEither the condition 'end!=NULL' is redundant or there is overflow in pointer subtraction.
114variableScope398styleThe scope of the variable 'host_name' can be reduced.
src/obexpush.c
187shadowVariable398styleLocal variable 'connection' shadows outer variable
src/share-extension.c
61variableScope398styleThe scope of the variable 'dialog' can be reduced.
src/user_share-common.c
81uninitvar908errorUninitialized variable: name
src/user_share.c
86shadowVariable398styleLocal variable 'settings' shadows outer variable
260shadowVariable398styleLocal variable 'settings' shadows outer variable
391shadowVariable398styleLocal variable 'settings' shadows outer variable
+
+ + + diff --git a/2020-06-22-164518-5655-cppcheck@b751b682733f_travis-ci/stats.html b/2020-06-22-164518-5655-cppcheck@b751b682733f_travis-ci/stats.html new file mode 100644 index 0000000..0990d84 --- /dev/null +++ b/2020-06-22-164518-5655-cppcheck@b751b682733f_travis-ci/stats.html @@ -0,0 +1,99 @@ + + + + + + Cppcheck - HTML report - mate-user-share + + + + + + + +
+

Top 10 files for error severity, total findings: 1
+   1  src/user_share-common.c
+

+

Top 10 files for warning severity, total findings: 1
+   1  src/http.c
+

+

Top 10 files for style severity, total findings: 19
+   13  src/file-share-properties.c
+   3   src/user_share.c
+   1   src/share-extension.c
+   1   src/obexpush.c
+   1   src/http.c
+

+ +
+ + + diff --git a/2020-06-22-164518-5655-cppcheck@b751b682733f_travis-ci/style.css b/2020-06-22-164518-5655-cppcheck@b751b682733f_travis-ci/style.css new file mode 100644 index 0000000..c39571c --- /dev/null +++ b/2020-06-22-164518-5655-cppcheck@b751b682733f_travis-ci/style.css @@ -0,0 +1,149 @@ + +body { + font: 13px Arial, Verdana, Sans-Serif; + margin: 0; + width: auto; +} + +h1 { + margin: 10px; +} + +#footer > p { + margin: 4px; +} + +.error { + background-color: #ffb7b7; +} + +.error2 { + background-color: #faa; + border: 1px dotted black; + display: inline-block; + margin-left: 4px; +} + +.inconclusive { + background-color: #B6B6B4; +} + +.inconclusive2 { + background-color: #B6B6B4; + border: 1px dotted black; + display: inline-block; + margin-left: 4px; +} + +div.verbose { + display: inline-block; + vertical-align: top; + cursor: help; +} + +div.verbose div.content { + display: none; + position: absolute; + padding: 10px; + margin: 4px; + max-width: 40%; + white-space: pre-wrap; + border: 1px solid black; + background-color: #FFFFCC; + cursor: auto; +} + +.highlight .hll { + padding: 1px; +} + +#header { + border-bottom: thin solid #aaa; +} + +#menu { + float: left; + margin-top: 5px; + text-align: left; + width: 150px; + /*height: 75%;*/ + position: fixed; + overflow: auto; + z-index: 1; +} + +#menu_index { + float: left; + margin-top: 5px; + padding-left: 5px; + text-align: left; + width: 300px; + /*height: 75%;*/ + position: fixed; + overflow: auto; + z-index: 1; +} + +#menu > a { + display: block; + margin-left: 10px; + font: 12px; + z-index: 1; +} + +#filename { + margin-left: 10px; + font: 12px; + z-index: 1; +} + +.highlighttable { + background-color:white; + z-index: 10; + position: relative; + margin: -10 px; +} + +#content { + background-color: white; + -webkit-box-sizing: content-box; + -moz-box-sizing: content-box; + box-sizing: content-box; + float: left; + margin: 5px; + margin-left: 10px; + padding: 0 10px 10px 10px; + width: 80%; + padding-left: 150px; +} + +#content_index { + background-color: white; + -webkit-box-sizing: content-box; + -moz-box-sizing: content-box; + box-sizing: content-box; + float: left; + margin: 5px; + margin-left: 10px; + padding: 0 10px 10px 10px; + width: 80%; + padding-left: 300px; +} + +.linenos { + border-right: thin solid #aaa; + color: lightgray; + padding-right: 6px; +} + +#footer { + border-top: thin solid #aaa; + clear: both; + font-size: 90%; + margin-top: 5px; +} + +#footer ul { + list-style-type: none; + padding-left: 0; +} diff --git a/2020-06-28-102155-0593-cppcheck@ceeb6e4bfa08_master/0.html b/2020-06-28-102155-0593-cppcheck@ceeb6e4bfa08_master/0.html new file mode 100644 index 0000000..cb65a79 --- /dev/null +++ b/2020-06-28-102155-0593-cppcheck@ceeb6e4bfa08_master/0.html @@ -0,0 +1,1482 @@ + + + + + + Cppcheck - HTML report - mate-user-share + + + + + + + +
+
  1
+  2
+  3
+  4
+  5
+  6
+  7
+  8
+  9
+ 10
+ 11
+ 12
+ 13
+ 14
+ 15
+ 16
+ 17
+ 18
+ 19
+ 20
+ 21
+ 22
+ 23
+ 24
+ 25
+ 26
+ 27
+ 28
+ 29
+ 30
+ 31
+ 32
+ 33
+ 34
+ 35
+ 36
+ 37
+ 38
+ 39
+ 40
+ 41
+ 42
+ 43
+ 44
+ 45
+ 46
+ 47
+ 48
+ 49
+ 50
+ 51
+ 52
+ 53
+ 54
+ 55
+ 56
+ 57
+ 58
+ 59
+ 60
+ 61
+ 62
+ 63
+ 64
+ 65
+ 66
+ 67
+ 68
+ 69
+ 70
+ 71
+ 72
+ 73
+ 74
+ 75
+ 76
+ 77
+ 78
+ 79
+ 80
+ 81
+ 82
+ 83
+ 84
+ 85
+ 86
+ 87
+ 88
+ 89
+ 90
+ 91
+ 92
+ 93
+ 94
+ 95
+ 96
+ 97
+ 98
+ 99
+100
+101
+102
+103
+104
+105
+106
+107
+108
+109
+110
+111
+112
+113
+114
+115
+116
+117
+118
+119
+120
+121
+122
+123
+124
+125
+126
+127
+128
+129
+130
+131
+132
+133
+134
+135
+136
+137
+138
+139
+140
+141
+142
+143
+144
+145
+146
+147
+148
+149
+150
+151
+152
+153
+154
+155
+156
+157
+158
+159
+160
+161
+162
+163
+164
+165
+166
+167
+168
+169
+170
+171
+172
+173
+174
+175
+176
+177
+178
+179
+180
+181
+182
+183
+184
+185
+186
+187
+188
+189
+190
+191
+192
+193
+194
+195
+196
+197
+198
+199
+200
+201
+202
+203
+204
+205
+206
+207
+208
+209
+210
+211
+212
+213
+214
+215
+216
+217
+218
+219
+220
+221
+222
+223
+224
+225
+226
+227
+228
+229
+230
+231
+232
+233
+234
+235
+236
+237
+238
+239
+240
+241
+242
+243
+244
+245
+246
+247
+248
+249
+250
+251
+252
+253
+254
+255
+256
+257
+258
+259
+260
+261
+262
+263
+264
+265
+266
+267
+268
+269
+270
+271
+272
+273
+274
+275
+276
+277
+278
+279
+280
+281
+282
+283
+284
+285
+286
+287
+288
+289
+290
+291
+292
+293
+294
+295
+296
+297
+298
+299
+300
+301
+302
+303
+304
+305
+306
+307
+308
+309
+310
+311
+312
+313
+314
+315
+316
+317
+318
+319
+320
+321
+322
+323
+324
+325
+326
+327
+328
+329
+330
+331
+332
+333
+334
+335
+336
+337
+338
+339
+340
+341
+342
+343
+344
+345
+346
+347
+348
+349
+350
+351
+352
+353
+354
+355
+356
+357
+358
+359
+360
+361
+362
+363
+364
+365
+366
+367
+368
+369
+370
+371
+372
+373
+374
+375
+376
+377
+378
+379
+380
+381
+382
+383
+384
+385
+386
+387
+388
+389
+390
+391
+392
+393
+394
+395
+396
+397
+398
+399
+400
+401
+402
+403
+404
+405
+406
+407
+408
+409
+410
+411
+412
+413
+414
+415
+416
+417
+418
+419
+420
+421
+422
+423
+424
+425
+426
+427
+428
+429
+430
+431
+432
+433
+434
+435
+436
+437
+438
+439
+440
+441
+442
+443
+444
+445
+446
+447
+448
+449
+450
+451
+452
+453
+454
+455
+456
+457
+458
+459
+460
+461
+462
+463
+464
+465
+466
+467
+468
+469
+470
+471
+472
+473
+474
+475
+476
+477
+478
+479
+480
+481
+482
+483
+484
+485
+486
+487
+488
+489
+490
+491
+492
+493
+494
+495
+496
+497
+498
+499
+500
+501
+502
+503
+504
+505
+506
+507
+508
+509
+510
+511
+512
+513
+514
+515
+516
+517
+518
+519
+520
+521
+522
+523
+524
+525
+526
+527
+528
+529
+530
+531
+532
+533
+534
+535
+536
+537
+538
+539
+540
+541
+542
+543
+544
+545
+546
+547
+548
+549
+550
+551
+552
+553
+554
+555
+556
+557
+558
+559
+560
+561
+562
+563
+564
+565
+566
+567
+568
+569
+570
+571
+572
+573
+574
+575
+576
+577
+578
+579
+580
+581
+582
+583
+584
+585
+586
+587
+588
+589
+590
+591
+592
+593
+594
+595
+596
+597
+598
+599
+600
+601
+602
+603
+604
+605
+606
+607
+608
+609
+610
+611
+612
+613
+614
+615
+616
+617
+618
+619
+620
+621
+622
+623
+624
+625
+626
+627
+628
+629
+630
+631
+632
+633
+634
+635
+636
+637
+638
+639
+640
+641
+642
+643
+644
+645
+646
+647
+648
+649
+650
+651
+652
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
+
+/*
+ *  Copyright (C) 2004 Red Hat, Inc.
+ *
+ *  Caja is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU General Public License as
+ *  published by the Free Software Foundation; either version 2 of the
+ *  License, or (at your option) any later version.
+ *
+ *  Caja is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  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
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ *  Authors: Alexander Larsson <alexl@redhat.com>
+ *
+ */
+
+#include "config.h"
+
+#include <string.h>
+#include <stdio.h>
+
+#include <gtk/gtk.h>
+#include <glib/gi18n.h>
+#include <gio/gio.h>
+
+#include "user_share-private.h"
+
+#define REALM "Please log in as the user guest"
+#define USER "guest"
+#define GSETTINGS_SCHEMA "org.mate.FileSharing"
+#define GSETTINGS_KEY_FILE_SHARING_ENABLED "enabled"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_ENABLED "bluetooth-enabled"
+#define GSETTINGS_KEY_FILE_SHARING_REQUIRE_PASSWORD "require-password"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_ALLOW_WRITE "bluetooth-allow-write"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_REQUIRE_PAIRING "bluetooth-require-pairing"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED "bluetooth-obexpush-enabled"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_ACCEPT_FILES "bluetooth-accept-files"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_NOTIFY "bluetooth-notify"
+
+static GtkBuilder* builder;
+static GSettings* settings;<--- Shadowed declaration<--- Shadowed declaration<--- Shadowed declaration<--- Shadowed declaration<--- Shadowed declaration<--- Shadowed declaration<--- Shadowed declaration<--- Shadowed declaration<--- Shadowed declaration<--- Shadowed declaration
+
+
+static void
+write_out_password (const char *password)
+{
+    char *to_hash;
+    char *ascii_digest;
+    char *line;
+    char *filename;
+    FILE *file;
+
+    to_hash = g_strdup_printf ("%s:%s:%s", USER, REALM, password);
+    ascii_digest = g_compute_checksum_for_string (G_CHECKSUM_MD5, to_hash, strlen (to_hash));
+    g_free (to_hash);
+    line = g_strdup_printf ("%s:%s:%s\n", USER, REALM, ascii_digest);
+    g_free (ascii_digest);
+
+    filename = g_build_filename (g_get_user_config_dir (), "user-share", "passwd", NULL);
+
+    file = fopen (filename, "w");
+    if (file != NULL) {
+	fwrite (line, strlen (line), 1, file);
+	fclose (file);
+    }
+
+    g_free (filename);
+    g_free (line);
+}
+
+static void
+flush_password (void)
+{
+    GtkWidget *password_entry;
+    const char *password;
+
+    password_entry = GTK_WIDGET (gtk_builder_get_object (builder, "password_entry"));
+
+    if (g_object_get_data (G_OBJECT( password_entry), "user_edited")) {
+	password = gtk_entry_get_text (GTK_ENTRY (password_entry));
+	if (password != NULL && password[0] != 0)
+	    write_out_password (password);
+    }
+}
+
+
+static void
+update_ui (void)
+{
+    GSettings *settings;<--- Shadow variable
+    gboolean enabled;
+#ifdef HAVE_BLUETOOTH
+    gboolean bluetooth_enabled, bluetooth_write_enabled, require_pairing_enabled;
+    gboolean bluetooth_obexpush_enabled, bluetooth_obexpush_notify;
+#endif /* HAVE_BLUETOOTH */
+    char *str;
+    PasswordSetting password_setting;
+    AcceptSetting accept_setting;<--- Unused variable: accept_setting
+    GtkWidget *check;
+    GtkWidget *password_combo;
+    GtkWidget *password_entry;
+#ifdef HAVE_BLUETOOTH
+    GtkWidget *vbox_share_bluetooth;
+    GtkWidget *vbox_receive_bluetooth;
+    GtkWidget *bluetooth_check;
+    GtkWidget *allow_write_bluetooth_check;
+    GtkWidget *require_pairing_check;
+    GtkWidget *enable_obexpush_check;
+    GtkWidget *accept_obexpush_combo;
+    GtkWidget *notify_received_obexpush_check;
+#endif /* HAVE_BLUETOOTH */
+
+    settings = g_settings_new (GSETTINGS_SCHEMA);
+
+    enabled = g_settings_get_boolean (settings,
+				     FILE_SHARING_ENABLED);
+
+    str = g_settings_get_string (settings, FILE_SHARING_REQUIRE_PASSWORD);
+    password_setting = password_setting_from_string (str);
+    g_free (str);
+
+#ifdef HAVE_BLUETOOTH
+    bluetooth_enabled = g_settings_get_boolean (settings,
+    					       FILE_SHARING_BLUETOOTH_ENABLED);
+    bluetooth_write_enabled = g_settings_get_boolean (settings,
+						     FILE_SHARING_BLUETOOTH_ALLOW_WRITE);
+    require_pairing_enabled = g_settings_get_boolean (settings,
+    						     FILE_SHARING_BLUETOOTH_REQUIRE_PAIRING);
+    bluetooth_obexpush_enabled = g_settings_get_boolean (settings,
+    							FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED);
+    bluetooth_obexpush_notify = g_settings_get_boolean (settings,
+    						       FILE_SHARING_BLUETOOTH_OBEXPUSH_NOTIFY);
+
+    str = g_settings_get_string (settings, FILE_SHARING_BLUETOOTH_OBEXPUSH_ACCEPT_FILES);
+    accept_setting = accept_setting_from_string (str);
+    g_free (str);
+#endif /* HAVE_BLUETOOTH */
+
+    check = GTK_WIDGET (gtk_builder_get_object (builder, "enable_check"));
+    password_combo = GTK_WIDGET (gtk_builder_get_object (builder, "password_combo"));
+    password_entry = GTK_WIDGET (gtk_builder_get_object (builder, "password_entry"));
+#ifdef HAVE_BLUETOOTH
+    vbox_share_bluetooth = GTK_WIDGET (gtk_builder_get_object (builder, "vbox_share_bluetooth"));
+    vbox_receive_bluetooth = GTK_WIDGET (gtk_builder_get_object (builder, "vbox_receive_bluetooth"));
+    bluetooth_check = GTK_WIDGET (gtk_builder_get_object (builder, "enable_bluetooth_check"));
+    allow_write_bluetooth_check = GTK_WIDGET (gtk_builder_get_object (builder, "allow_write_bluetooth_check"));
+    require_pairing_check = GTK_WIDGET (gtk_builder_get_object (builder, "require_pairing_check"));
+    enable_obexpush_check = GTK_WIDGET (gtk_builder_get_object (builder, "enable_obexpush_check"));
+    accept_obexpush_combo = GTK_WIDGET (gtk_builder_get_object (builder, "accept_obexpush_combo"));
+    notify_received_obexpush_check = GTK_WIDGET (gtk_builder_get_object (builder, "notify_received_obexpush_check"));
+#endif /* HAVE_BLUETOOTH */
+
+    /* Network */
+    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (check), enabled);
+    gtk_widget_set_sensitive (password_combo, enabled);
+    gtk_widget_set_sensitive (password_entry, enabled && password_setting != PASSWORD_NEVER);
+
+    gtk_combo_box_set_active (GTK_COMBO_BOX (password_combo),
+			      password_setting);
+
+#ifdef HAVE_BLUETOOTH
+    /* Bluetooth ObexFTP */
+    gtk_widget_set_visible (vbox_share_bluetooth, TRUE);
+    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (bluetooth_check), bluetooth_enabled);
+    gtk_widget_set_sensitive (allow_write_bluetooth_check, bluetooth_enabled);
+    gtk_widget_set_sensitive (require_pairing_check, bluetooth_enabled);
+
+    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (allow_write_bluetooth_check),
+    				  bluetooth_write_enabled);
+    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (require_pairing_check),
+    				  require_pairing_enabled);
+
+    /* Bluetooth ObexPush */
+    gtk_widget_set_visible (vbox_receive_bluetooth, TRUE);
+    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (enable_obexpush_check), bluetooth_obexpush_enabled);
+    gtk_widget_set_sensitive (accept_obexpush_combo, bluetooth_obexpush_enabled);
+    gtk_widget_set_sensitive (notify_received_obexpush_check, bluetooth_obexpush_enabled);
+
+    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (notify_received_obexpush_check),
+    				  bluetooth_obexpush_notify);
+
+    gtk_combo_box_set_active (GTK_COMBO_BOX (accept_obexpush_combo),
+    			      accept_setting);
+#endif /* HAVE_BLUETOOTH */
+
+    g_object_unref (settings);
+}
+
+static void
+file_sharing_enabled_changed (GSettings *settings, gchar *key, gpointer data)
+{
+    update_ui ();
+}
+
+static void
+password_required_changed (GSettings *settings, gchar *key, gpointer data)
+{
+    update_ui ();
+}
+
+#ifdef HAVE_BLUETOOTH
+static void
+file_sharing_bluetooth_enabled_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	update_ui ();
+}
+
+static void
+file_sharing_bluetooth_allow_write_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	update_ui ();
+}
+
+static void
+file_sharing_bluetooth_require_pairing_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	update_ui ();
+}
+
+static void
+file_sharing_bluetooth_obexpush_enabled_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	update_ui ();
+}
+
+static void
+file_sharing_bluetooth_obexpush_accept_files_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	update_ui ();
+}
+
+static void
+file_sharing_bluetooth_obexpush_notify_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	update_ui ();
+}
+#endif /* HAVE_BLUETOOTH */
+
+static void
+password_combo_changed (GtkComboBox *combo_box)
+{
+    GSettings *settings;<--- Shadow variable
+    guint setting;
+
+    setting = gtk_combo_box_get_active (combo_box);
+
+    settings = g_settings_new (GSETTINGS_SCHEMA) ;
+
+    g_settings_set_string (settings,
+			     FILE_SHARING_REQUIRE_PASSWORD,
+			     password_string_from_setting (setting));
+    g_object_unref (settings);
+}
+
+static void
+launch_share (void)
+{
+	if (!g_spawn_command_line_async (USER_SHARE_PROGRAM, NULL))
+		g_warning ("Unable to start mate-user-share program");
+}
+
+#ifdef HAVE_BLUETOOTH
+static void
+enable_bluetooth_check_toggled (GtkWidget *check)
+{
+	GSettings *settings;<--- Shadow variable
+	gboolean enabled;
+
+	enabled = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check));
+
+	settings = g_settings_new (GSETTINGS_SCHEMA) ;
+
+	g_settings_set_boolean (settings,
+			       FILE_SHARING_BLUETOOTH_ENABLED,
+			       enabled);
+
+	g_object_unref (settings);
+
+	if (enabled != FALSE)
+		launch_share ();
+}
+#endif /* HAVE_BLUETOOTH */
+
+static void
+enable_check_toggled (GtkWidget *check)
+{
+	GSettings *settings;<--- Shadow variable
+	gboolean enabled;
+
+	enabled = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check));
+
+	settings = g_settings_new (GSETTINGS_SCHEMA);
+
+	g_settings_set_boolean (settings,
+			       FILE_SHARING_ENABLED,
+			       enabled);
+
+	g_object_unref (settings);
+
+	if (enabled != FALSE)
+		launch_share ();
+}
+
+static void
+password_entry_changed (GtkEditable *editable)
+{
+	g_object_set_data (G_OBJECT (editable),
+			   "user_edited", GINT_TO_POINTER (1));
+	flush_password ();
+}
+
+#ifdef HAVE_BLUETOOTH
+static void
+bluetooth_allow_write_check_toggled (GtkWidget *check)
+{
+	GSettings *settings;<--- Shadow variable
+	gboolean enabled;
+
+	enabled = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check));
+
+	settings = g_settings_new (GSETTINGS_SCHEMA) ;
+
+	g_settings_set_boolean (settings,
+			       FILE_SHARING_BLUETOOTH_ALLOW_WRITE,
+			       enabled);
+
+	g_object_unref (settings);
+}
+
+static void
+bluetooth_require_pairing_check_toggled (GtkWidget *check)
+{
+	GSettings *settings;<--- Shadow variable
+	gboolean enabled;
+
+	enabled = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check));
+
+	settings = g_settings_new (GSETTINGS_SCHEMA) ;
+
+	g_settings_set_boolean (settings,
+			       FILE_SHARING_BLUETOOTH_REQUIRE_PAIRING,
+			       enabled);
+
+	g_object_unref (settings);
+}
+
+static void
+enable_obexpush_check_toggled (GtkWidget *check)
+{
+	GSettings *settings;<--- Shadow variable
+	gboolean enabled;
+
+	enabled = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check));
+
+	settings = g_settings_new (GSETTINGS_SCHEMA) ;
+
+	g_settings_set_boolean (settings,
+			       FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED,
+			       enabled);
+
+	g_object_unref (settings);
+
+	if (enabled != FALSE)
+		launch_share ();
+}
+
+static void
+accept_obexpush_combo_changed (GtkComboBox *combo_box)
+{
+    GSettings *settings;<--- Shadow variable
+    guint setting;
+
+    setting = gtk_combo_box_get_active (combo_box);
+
+    settings = g_settings_new (GSETTINGS_SCHEMA) ;
+
+    g_settings_set_string (settings,
+			     FILE_SHARING_BLUETOOTH_OBEXPUSH_ACCEPT_FILES,
+			     accept_string_from_setting (setting));
+    g_object_unref (settings);
+}
+
+static void
+notify_received_obexpush_check_toggled (GtkWidget *check)
+{
+	GSettings *settings;<--- Shadow variable
+	gboolean enabled;
+
+	enabled = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check));
+
+	settings = g_settings_new (GSETTINGS_SCHEMA) ;
+
+	g_settings_set_boolean (settings,
+			       FILE_SHARING_BLUETOOTH_OBEXPUSH_NOTIFY,
+			       enabled);
+
+	g_object_unref (settings);
+}
+#endif /* HAVE_BLUETOOTH */
+
+static GtkWidget *
+error_dialog (const char *title,
+	      const char *reason,
+	      GtkWindow *parent)
+{
+	GtkWidget *error_dialog;
+
+	if (reason == NULL)
+		reason = _("No reason");
+
+	error_dialog =
+		gtk_message_dialog_new (parent,
+					GTK_DIALOG_MODAL,
+					GTK_MESSAGE_ERROR,
+					GTK_BUTTONS_OK,
+					"%s", title);
+	gtk_message_dialog_format_secondary_text
+		(GTK_MESSAGE_DIALOG (error_dialog), "%s", reason);
+
+	gtk_window_set_title (GTK_WINDOW (error_dialog), ""); /* as per HIG */
+	gtk_container_set_border_width (GTK_CONTAINER (error_dialog), 5);
+	gtk_dialog_set_default_response (GTK_DIALOG (error_dialog),
+					 GTK_RESPONSE_OK);
+	gtk_window_set_modal (GTK_WINDOW (error_dialog), TRUE);
+
+	return error_dialog;
+}
+
+static void
+help_button_clicked (GtkButton *button, GtkWidget *window)
+{
+	GError *error = NULL;
+
+	if (gtk_show_uri_on_window (GTK_WINDOW (window), "help:mate-user-share", gtk_get_current_event_time (), &error) == FALSE) {
+		GtkWidget *dialog;
+
+		dialog = error_dialog (_("Could not display the help contents."), error->message, GTK_WINDOW (window));
+		g_signal_connect (G_OBJECT (dialog), "response", G_CALLBACK
+				  (gtk_widget_destroy), error_dialog);
+		gtk_window_present (GTK_WINDOW (dialog));
+
+		g_error_free (error);
+	}
+}
+
+static GtkWidget *
+create_window (void)
+{
+    GError *error = NULL;
+    GSettings *settings;<--- Shadow variable
+    GtkWidget *check;
+    GtkWidget *password_combo;
+    GtkWidget *password_entry;
+#ifdef HAVE_BLUETOOTH
+    GtkWidget *bluetooth_check;
+    GtkWidget *bluetooth_allow_write_check;
+    GtkWidget *require_pairing_check;
+    GtkWidget *enable_obexpush_check;
+    GtkWidget *accept_obexpush_combo;
+    GtkWidget *notify_received_obexpush_check;
+#endif /* HAVE_BLUETOOTH */
+    GtkWidget *window;
+    GtkListStore *store;
+    GtkCellRenderer *cell;
+    GtkTreeIter iter;
+
+    builder = gtk_builder_new ();
+    gtk_builder_add_from_file (builder, DATADIR"file-share-properties.ui", &error);
+
+    if (error) {
+      GtkWidget *dialog;
+
+      dialog = error_dialog (_("Could not build interface."), error->message, NULL);
+      gtk_dialog_run (GTK_DIALOG (dialog));
+      gtk_widget_destroy (dialog);
+
+      g_error_free (error);
+      return NULL;
+    }
+
+    window = GTK_WIDGET (gtk_builder_get_object (builder, "user_share_dialog"));
+
+    settings = g_settings_new (GSETTINGS_SCHEMA);
+
+    check = GTK_WIDGET (gtk_builder_get_object (builder, "enable_check"));
+    password_combo = GTK_WIDGET (gtk_builder_get_object (builder, "password_combo"));
+    password_entry = GTK_WIDGET (gtk_builder_get_object (builder, "password_entry"));
+#ifdef HAVE_BLUETOOTH
+    bluetooth_check = GTK_WIDGET (gtk_builder_get_object (builder, "enable_bluetooth_check"));
+    bluetooth_allow_write_check = GTK_WIDGET (gtk_builder_get_object (builder, "allow_write_bluetooth_check"));
+    require_pairing_check = GTK_WIDGET (gtk_builder_get_object (builder, "require_pairing_check"));
+    enable_obexpush_check = GTK_WIDGET (gtk_builder_get_object (builder, "enable_obexpush_check"));
+    accept_obexpush_combo = GTK_WIDGET (gtk_builder_get_object (builder, "accept_obexpush_combo"));
+    notify_received_obexpush_check = GTK_WIDGET (gtk_builder_get_object (builder, "notify_received_obexpush_check"));
+#endif /* HAVE_BLUETOOTH */
+
+    store = gtk_list_store_new (1, G_TYPE_STRING);
+    gtk_combo_box_set_model (GTK_COMBO_BOX (password_combo),
+			     GTK_TREE_MODEL (store));
+    cell = gtk_cell_renderer_text_new ();
+    gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (password_combo), cell, TRUE);
+    gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (password_combo), cell,
+				    "text", 0,
+				    NULL);
+
+    /* Keep in same order as enum */
+    gtk_list_store_append (store, &iter);
+    gtk_list_store_set (store, &iter, 0,
+			_("Never"), -1);
+    gtk_list_store_append (store, &iter);
+    gtk_list_store_set (store, &iter, 0,
+			_("When writing files"), -1);
+    gtk_list_store_append (store, &iter);
+    gtk_list_store_set (store, &iter, 0,
+			_("Always"), -1);
+    g_object_unref (store);
+
+    /* We can't read the password from the text, just set it to something */
+    gtk_entry_set_text (GTK_ENTRY (password_entry), "none");
+    g_object_set_data (G_OBJECT (password_entry),
+		       "user_edited", GINT_TO_POINTER (0));
+    g_signal_connect (password_entry,
+		      "changed", G_CALLBACK (password_entry_changed), NULL);
+
+#ifdef HAVE_BLUETOOTH
+    /* Accept files combo */
+    store = gtk_list_store_new (1, G_TYPE_STRING);
+    gtk_combo_box_set_model (GTK_COMBO_BOX (accept_obexpush_combo),
+			     GTK_TREE_MODEL (store));
+    cell = gtk_cell_renderer_text_new ();
+    gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (accept_obexpush_combo), cell, TRUE);
+    gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (accept_obexpush_combo), cell,
+				    "text", 0,
+				    NULL);
+
+    /* Keep in same order as enum */
+    gtk_list_store_append (store, &iter);
+    gtk_list_store_set (store, &iter, 0,
+			_("Always"), -1);
+    gtk_list_store_append (store, &iter);
+    gtk_list_store_set (store, &iter, 0,
+			_("Only for set up devices"), -1);
+    //FIXME implement
+#if 0
+    gtk_list_store_append (store, &iter);
+    gtk_list_store_set (store, &iter, 0,
+    			_("Ask"), -1);
+#endif
+    g_object_unref (store);
+#endif /* HAVE_BLUETOOTH */
+
+    g_signal_connect (check,
+		      "toggled", G_CALLBACK (enable_check_toggled), NULL);
+    g_signal_connect (password_combo,
+		      "changed", G_CALLBACK (password_combo_changed), NULL);
+#ifdef HAVE_BLUETOOTH
+    g_signal_connect (bluetooth_check,
+    		      "toggled", G_CALLBACK (enable_bluetooth_check_toggled), NULL);
+    g_signal_connect (bluetooth_allow_write_check,
+    		      "toggled", G_CALLBACK (bluetooth_allow_write_check_toggled), NULL);
+    g_signal_connect (require_pairing_check,
+    		      "toggled", G_CALLBACK (bluetooth_require_pairing_check_toggled), NULL);
+    g_signal_connect (enable_obexpush_check,
+    		      "toggled", G_CALLBACK (enable_obexpush_check_toggled), NULL);
+    g_signal_connect (accept_obexpush_combo,
+    		      "changed", G_CALLBACK (accept_obexpush_combo_changed), NULL);
+    g_signal_connect (notify_received_obexpush_check,
+    		      "toggled", G_CALLBACK (notify_received_obexpush_check_toggled), NULL);
+#endif /* HAVE_BLUETOOTH */
+
+    g_signal_connect_swapped (GTK_WIDGET (gtk_builder_get_object (builder, "close_button")),
+                              "clicked", G_CALLBACK (gtk_widget_destroy), window);
+    g_signal_connect (GTK_WIDGET (gtk_builder_get_object (builder, "help_button")),
+		      "clicked", G_CALLBACK (help_button_clicked),
+		      gtk_builder_get_object (builder, "user_share_dialog"));
+
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_ENABLED,
+			     G_CALLBACK (file_sharing_enabled_changed), NULL);
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_REQUIRE_PASSWORD,
+			     G_CALLBACK (password_required_changed), NULL);
+#ifdef HAVE_BLUETOOTH
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_ENABLED,
+			     G_CALLBACK (file_sharing_bluetooth_enabled_changed), NULL);
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_ALLOW_WRITE,
+			     G_CALLBACK (file_sharing_bluetooth_allow_write_changed), NULL);
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_REQUIRE_PAIRING,
+			     G_CALLBACK (file_sharing_bluetooth_require_pairing_changed), NULL);
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED,
+			     G_CALLBACK (file_sharing_bluetooth_obexpush_enabled_changed), NULL);
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_ACCEPT_FILES,
+			     G_CALLBACK (file_sharing_bluetooth_obexpush_accept_files_changed), NULL);
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_NOTIFY,
+			     G_CALLBACK (file_sharing_bluetooth_obexpush_notify_changed), NULL);
+#endif /* HAVE_BLUETOOTH */
+
+    update_ui ();
+
+    return window;
+}
+
+static void
+activate (GtkApplication *app)
+{
+    GList *list;
+    GtkWidget *window;
+
+    list = gtk_application_get_windows (app);
+
+    if (list) {
+        gtk_window_present (GTK_WINDOW (list->data));
+    } else {
+        window = create_window ();
+        gtk_window_set_application (GTK_WINDOW (window), app);
+        gtk_widget_show (window);
+    }
+}
+
+int
+main (int argc, char *argv[])
+{
+    GtkApplication *app;
+    gint status;
+
+    bindtextdomain (GETTEXT_PACKAGE, MATELOCALEDIR);
+    bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
+    textdomain (GETTEXT_PACKAGE);
+
+    app = gtk_application_new ("org.mate.user-share.properties",
+                               G_APPLICATION_FLAGS_NONE);
+    g_signal_connect (app, "activate", G_CALLBACK (activate), NULL);
+
+    status = g_application_run (G_APPLICATION (app), argc, argv);
+
+    g_object_unref (app);
+
+    return status;
+}
+
+
+
+ + + diff --git a/2020-06-28-102155-0593-cppcheck@ceeb6e4bfa08_master/1.html b/2020-06-28-102155-0593-cppcheck@ceeb6e4bfa08_master/1.html new file mode 100644 index 0000000..0ccd444 --- /dev/null +++ b/2020-06-28-102155-0593-cppcheck@ceeb6e4bfa08_master/1.html @@ -0,0 +1,1038 @@ + + + + + + Cppcheck - HTML report - mate-user-share + + + + + + + +
+
  1
+  2
+  3
+  4
+  5
+  6
+  7
+  8
+  9
+ 10
+ 11
+ 12
+ 13
+ 14
+ 15
+ 16
+ 17
+ 18
+ 19
+ 20
+ 21
+ 22
+ 23
+ 24
+ 25
+ 26
+ 27
+ 28
+ 29
+ 30
+ 31
+ 32
+ 33
+ 34
+ 35
+ 36
+ 37
+ 38
+ 39
+ 40
+ 41
+ 42
+ 43
+ 44
+ 45
+ 46
+ 47
+ 48
+ 49
+ 50
+ 51
+ 52
+ 53
+ 54
+ 55
+ 56
+ 57
+ 58
+ 59
+ 60
+ 61
+ 62
+ 63
+ 64
+ 65
+ 66
+ 67
+ 68
+ 69
+ 70
+ 71
+ 72
+ 73
+ 74
+ 75
+ 76
+ 77
+ 78
+ 79
+ 80
+ 81
+ 82
+ 83
+ 84
+ 85
+ 86
+ 87
+ 88
+ 89
+ 90
+ 91
+ 92
+ 93
+ 94
+ 95
+ 96
+ 97
+ 98
+ 99
+100
+101
+102
+103
+104
+105
+106
+107
+108
+109
+110
+111
+112
+113
+114
+115
+116
+117
+118
+119
+120
+121
+122
+123
+124
+125
+126
+127
+128
+129
+130
+131
+132
+133
+134
+135
+136
+137
+138
+139
+140
+141
+142
+143
+144
+145
+146
+147
+148
+149
+150
+151
+152
+153
+154
+155
+156
+157
+158
+159
+160
+161
+162
+163
+164
+165
+166
+167
+168
+169
+170
+171
+172
+173
+174
+175
+176
+177
+178
+179
+180
+181
+182
+183
+184
+185
+186
+187
+188
+189
+190
+191
+192
+193
+194
+195
+196
+197
+198
+199
+200
+201
+202
+203
+204
+205
+206
+207
+208
+209
+210
+211
+212
+213
+214
+215
+216
+217
+218
+219
+220
+221
+222
+223
+224
+225
+226
+227
+228
+229
+230
+231
+232
+233
+234
+235
+236
+237
+238
+239
+240
+241
+242
+243
+244
+245
+246
+247
+248
+249
+250
+251
+252
+253
+254
+255
+256
+257
+258
+259
+260
+261
+262
+263
+264
+265
+266
+267
+268
+269
+270
+271
+272
+273
+274
+275
+276
+277
+278
+279
+280
+281
+282
+283
+284
+285
+286
+287
+288
+289
+290
+291
+292
+293
+294
+295
+296
+297
+298
+299
+300
+301
+302
+303
+304
+305
+306
+307
+308
+309
+310
+311
+312
+313
+314
+315
+316
+317
+318
+319
+320
+321
+322
+323
+324
+325
+326
+327
+328
+329
+330
+331
+332
+333
+334
+335
+336
+337
+338
+339
+340
+341
+342
+343
+344
+345
+346
+347
+348
+349
+350
+351
+352
+353
+354
+355
+356
+357
+358
+359
+360
+361
+362
+363
+364
+365
+366
+367
+368
+369
+370
+371
+372
+373
+374
+375
+376
+377
+378
+379
+380
+381
+382
+383
+384
+385
+386
+387
+388
+389
+390
+391
+392
+393
+394
+395
+396
+397
+398
+399
+400
+401
+402
+403
+404
+405
+406
+407
+408
+409
+410
+411
+412
+413
+414
+415
+416
+417
+418
+419
+420
+421
+422
+423
+424
+425
+426
+427
+428
+429
+430
+431
+432
+433
+434
+435
+436
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
+
+/*
+ *  Copyright (C) 2004-2008 Red Hat, Inc.
+ *
+ *  Caja is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU General Public License as
+ *  published by the Free Software Foundation; either version 2 of the
+ *  License, or (at your option) any later version.
+ *
+ *  Caja is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  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
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ *  Authors: Alexander Larsson <alexl@redhat.com>
+ *
+ */
+
+#include "config.h"
+
+#include <glib.h>
+#include <glib/gi18n.h>
+#include <X11/Xlib.h>
+
+#include <gio/gio.h>
+
+#include <stdarg.h>
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <signal.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <sys/stat.h>
+
+#ifdef HAVE_SELINUX
+#include <selinux/selinux.h>
+#endif
+
+#include "user_share-common.h"
+#include "user_share-private.h"
+#include "http.h"
+
+/* From avahi-common/domain.h */
+#define AVAHI_LABEL_MAX 64
+
+#define GSETTINGS_SCHEMA "org.mate.FileSharing"
+
+static pid_t httpd_pid = 0;
+
+static int
+get_port (void)
+{
+	int sock;
+	struct sockaddr_in addr;
+	int reuse;
+	socklen_t len;
+
+	sock = socket (PF_INET, SOCK_STREAM, 0);
+	if (sock < 0) {
+		return -1;
+	}
+
+	memset (&addr, 0, sizeof (addr));
+	addr.sin_port = 0;
+	addr.sin_addr.s_addr = INADDR_ANY;
+	addr.sin_family = AF_INET;
+
+	reuse = 1;
+	setsockopt (sock, SOL_SOCKET, SO_REUSEADDR, &reuse, sizeof (reuse));
+	if (bind (sock, (struct sockaddr *)&addr, sizeof (addr)) == -1) {
+		close (sock);
+		return -1;
+	}
+
+	len = sizeof (addr);
+	if (getsockname (sock, (struct sockaddr *)&addr, &len) == -1) {
+		close (sock);
+		return -1;
+	}
+
+#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__APPLE__) || defined(__OpenBSD__)
+	/* XXX This exposes a potential race condition, but without this,
+	 * httpd will not start on the above listed platforms due to the fact
+	 * that SO_REUSEADDR is also needed when Apache binds to the listening
+	 * socket.  At this time, Apache does not support that socket option.
+	 */
+	close (sock);
+#endif
+	return ntohs (addr.sin_port);
+}
+
+static char *
+truncate_name (const char *name)
+{
+	const char *end;
+
+	end = g_utf8_find_prev_char (name, name + 64);<--- Assignment 'end=g_utf8_find_prev_char(name,name+64)', assigned value is 0
+	g_assert (end != NULL);<--- Assuming that condition 'end!=NULL' is not redundant
+	return g_strndup (name, end - name);<--- Null pointer subtraction
+}
+
+static char *
+get_share_name (void)
+{
+	static char *name = NULL;
+	const char *host_name;
+	char *str;
+
+	if (name == NULL) {
+		host_name = g_get_host_name ();
+		if (strcmp (host_name, "localhost") == 0) {
+			/* Translators: The %s will get filled in with the user name
+			   of the user, to form a genitive. If this is difficult to
+			   translate correctly so that it will work correctly in your
+			   language, you may use something equivalent to
+			   "Public files of %s", or leave out the %s altogether.
+			   In the latter case, please put "%.0s" somewhere in the string,
+			   which will match the user name string passed by the C code,
+			   but not put the user name in the final string. This is to
+			   avoid the warning that msgfmt might otherwise generate. */
+			name = g_strdup_printf (_("%s's public files"), g_get_user_name ());
+		} else {
+			/* Translators: This is similar to the string before, only it
+			   has the hostname in it too. */
+			name = g_strdup_printf (_("%s's public files on %s"),
+						g_get_user_name (),
+						host_name);
+		}
+
+	}
+	/* And truncate */
+	if (strlen (name) < AVAHI_LABEL_MAX)
+		return name;
+
+	str = truncate_name (name);
+	g_free (name);
+	name = str;
+
+	return name;
+}
+
+static void
+ensure_conf_dir (void)
+{
+	char *dirname;
+
+	dirname = g_build_filename (g_get_user_config_dir (), "user-share", NULL);
+	g_mkdir_with_parents (dirname, 0755);
+	g_free (dirname);
+}
+
+static void
+httpd_child_setup (gpointer user_data)
+{
+#ifdef HAVE_SELINUX
+	char *mycon;
+	/* If selinux is enabled, avoid transitioning to the httpd_t context,
+	   as this normally means you can't read the users homedir. */
+	if (is_selinux_enabled()) {
+		if (getcon (&mycon) < 0) {
+			abort ();
+		}
+		if (setexeccon (mycon) < 0)
+			abort ();
+		freecon (mycon);
+	}
+#endif
+}
+
+static const char *known_httpd_locations [] = {
+	HTTPD_PROGRAM,
+	"/usr/sbin/httpd",
+	"/usr/sbin/httpd2",
+	"/usr/sbin/apache2",
+	NULL
+};
+
+static char*
+get_httpd_program (void)
+{
+	int i;
+
+	for (i = 0; known_httpd_locations[i]; i++) {
+		if (known_httpd_locations[i][0] == '\0') {
+			/* empty string as first element, happens when
+			 * configured --with-httpd=auto */
+			continue;
+		}
+		if (g_file_test (known_httpd_locations[i], G_FILE_TEST_IS_EXECUTABLE)
+				&& ! g_file_test (known_httpd_locations[i], G_FILE_TEST_IS_DIR)) {
+			return g_strdup (known_httpd_locations[i]);
+		}
+	}
+	return NULL;
+}
+
+static const char *known_httpd_modules_locations [] = {
+	HTTPD_MODULES_PATH,
+	"/etc/httpd/modules",
+	"/usr/lib/apache2/modules",
+	NULL
+};
+
+static gchar*
+get_httpd_modules_path (void)
+{
+	int i;
+
+	for (i = 0; known_httpd_modules_locations[i]; i++) {
+		if (known_httpd_modules_locations[i][0] == '\0') {
+			/* empty string as first element, happens when
+			 * configured --with-httpd=auto */
+			continue;
+		}
+		if (g_file_test (known_httpd_modules_locations[i], G_FILE_TEST_IS_EXECUTABLE)
+				&& g_file_test (known_httpd_modules_locations[i], G_FILE_TEST_IS_DIR)) {
+			return g_strdup (known_httpd_modules_locations[i]);
+		}
+	}
+	return NULL;
+}
+
+static GRegex *version_regex = NULL;
+
+static char*
+get_httpd_config (const char *httpd_program)
+{
+	gchar *standard_output;
+	gchar *cmd_line;
+	GMatchInfo *match_info;
+	gchar *version_number = NULL;
+	gchar *config;
+
+	cmd_line = g_strdup_printf ("%s -v", httpd_program);
+	if (! g_spawn_command_line_sync (cmd_line, &standard_output, NULL, NULL, NULL)) {
+		g_free (cmd_line);
+		return NULL;
+	}
+	g_free (cmd_line);
+
+	if (version_regex == NULL) {
+		version_regex = g_regex_new ("\\d\\.\\d", 0, 0, NULL);
+	}
+
+	if (g_regex_match (version_regex, standard_output, 0, &match_info)) {
+		while (g_match_info_matches (match_info)) {
+			version_number = g_match_info_fetch (match_info, 0);
+			break;
+		}
+		g_match_info_free (match_info);
+		g_free (standard_output);
+	} else {
+		/* Failed to parse httpd version number */
+		g_warning ("Could not parse '%s' as a version for httpd", standard_output);
+		g_free (standard_output);
+		/* assume it is 2.2 */
+		version_number = g_strdup ("2.2");
+	}
+
+	config = g_strdup_printf (HTTPD_CONFIG_TEMPLATE, version_number);
+	g_free (version_number);
+
+	return config;
+}
+
+static gboolean
+spawn_httpd (int port, pid_t *pid_out)
+{
+	char *free1, *free2, *free3, *free4, *free5, *free6, *free7, *free8, *free9;
+	gboolean res;
+	char *argv[10];
+	char *env[10];
+	int i;
+	gint status;
+	char *pid_filename;
+	char *pidfile;
+	GError *error;
+	gboolean got_pidfile;
+	GSettings *settings;
+	char *str;
+	char *public_dir;
+
+	public_dir = lookup_public_dir ();
+	ensure_conf_dir ();
+
+	i = 0;
+	free1 = argv[i++] = get_httpd_program ();
+	if (argv[0] == NULL) {
+		fprintf (stderr, "error finding httpd server\n");
+		return FALSE;
+	}
+
+	argv[i++] = "-f";
+	free2 = argv[i++] = get_httpd_config (argv[0]);
+	argv[i++] = "-C";
+	free3 = argv[i++] = g_strdup_printf ("Listen %d", port);
+
+	settings = g_settings_new (GSETTINGS_SCHEMA);
+	str = g_settings_get_string (settings,
+				       FILE_SHARING_REQUIRE_PASSWORD);
+
+	if (str && strcmp (str, "never") == 0) {
+		/* Do nothing */
+	} else if (str && strcmp (str, "on_write") == 0){
+		argv[i++] = "-D";
+		argv[i++] = "RequirePasswordOnWrite";
+	} else {
+		/* always, or safe fallback */
+		argv[i++] = "-D";
+		argv[i++] = "RequirePasswordAlways";
+	}
+	g_free (str);
+	g_object_unref (settings);
+
+	argv[i] = NULL;
+
+	i = 0;
+	free4 = env[i++] = g_strdup_printf ("HOME=%s", g_get_home_dir());
+	free5 = env[i++] = g_strdup_printf ("XDG_PUBLICSHARE_DIR=%s", public_dir);
+	free6 = env[i++] = g_strdup_printf ("XDG_CONFIG_HOME=%s", g_get_user_config_dir ());
+	free7 = env[i++] = g_strdup_printf ("GUS_SHARE_NAME=%s", get_share_name ());
+	free8 = env[i++] = g_strdup_printf ("GUS_LOGIN_LABEL=%s", "Please log in as the user guest");
+	free9 = env[i++] = g_strdup_printf ("HTTP_MODULES_PATH=%s",get_httpd_modules_path ());
+	env[i++] = "LANG=C";
+	env[i] = NULL;
+
+	pid_filename = g_build_filename (g_get_user_config_dir (), "user-share", "pid", NULL);
+
+	/* Remove pid file before spawning to avoid races with child and old pidfile */
+	unlink (pid_filename);
+
+	error = NULL;
+	res = g_spawn_sync (g_get_home_dir(),
+			    argv, env, 0,
+			    httpd_child_setup, NULL,
+			    NULL, NULL,
+			    &status,
+			    &error);
+	g_free (free1);
+	g_free (free2);
+	g_free (free3);
+	g_free (free4);
+	g_free (free5);
+	g_free (free6);
+	g_free (free7);
+	g_free (free8);
+	g_free (free9);
+	g_free (public_dir);
+
+	if (!res) {
+		fprintf (stderr, "error spawning httpd: %s\n",
+			 error->message);
+		g_error_free (error);
+		g_free (pid_filename);
+		return FALSE;
+	}
+
+	if (status != 0) {
+		g_free (pid_filename);
+		return FALSE;
+	}
+
+	got_pidfile = FALSE;
+	error = NULL;
+	for (i = 0; i < 5; i++) {
+		if (error != NULL)
+			g_error_free (error);
+		error = NULL;
+		if (g_file_get_contents (pid_filename, &pidfile, NULL, &error)) {
+			got_pidfile = TRUE;
+			*pid_out = atoi (pidfile);
+			g_free (pidfile);
+			break;
+		}
+		sleep (1);
+	}
+
+	g_free (pid_filename);
+
+	if (!got_pidfile) {
+		fprintf (stderr, "error opening httpd pidfile: %s\n", error->message);
+		g_error_free (error);
+		return FALSE;
+	}
+	return TRUE;
+}
+
+static void
+kill_httpd (void)
+{
+	if (httpd_pid != 0) {
+		kill (httpd_pid, SIGTERM);
+
+		/* Allow child time to die, we can't waitpid, because its
+		   not a direct child */
+		sleep (1);
+	}
+	httpd_pid = 0;
+}
+
+void
+http_up (void)
+{
+	guint port;
+
+	port = get_port ();
+	if (!spawn_httpd (port, &httpd_pid)) {
+		fprintf (stderr, "spawning httpd failed\n");
+	}
+}
+
+void
+http_down (void)
+{
+	kill_httpd ();
+}
+
+gboolean
+http_init (void)
+{
+	return TRUE;
+}
+
+pid_t
+http_get_pid (void)
+{
+	return httpd_pid;
+}
+
+
+
+ + + diff --git a/2020-06-28-102155-0593-cppcheck@ceeb6e4bfa08_master/2.html b/2020-06-28-102155-0593-cppcheck@ceeb6e4bfa08_master/2.html new file mode 100644 index 0000000..d61baec --- /dev/null +++ b/2020-06-28-102155-0593-cppcheck@ceeb6e4bfa08_master/2.html @@ -0,0 +1,1272 @@ + + + + + + Cppcheck - HTML report - mate-user-share + + + + + + + +
+
  1
+  2
+  3
+  4
+  5
+  6
+  7
+  8
+  9
+ 10
+ 11
+ 12
+ 13
+ 14
+ 15
+ 16
+ 17
+ 18
+ 19
+ 20
+ 21
+ 22
+ 23
+ 24
+ 25
+ 26
+ 27
+ 28
+ 29
+ 30
+ 31
+ 32
+ 33
+ 34
+ 35
+ 36
+ 37
+ 38
+ 39
+ 40
+ 41
+ 42
+ 43
+ 44
+ 45
+ 46
+ 47
+ 48
+ 49
+ 50
+ 51
+ 52
+ 53
+ 54
+ 55
+ 56
+ 57
+ 58
+ 59
+ 60
+ 61
+ 62
+ 63
+ 64
+ 65
+ 66
+ 67
+ 68
+ 69
+ 70
+ 71
+ 72
+ 73
+ 74
+ 75
+ 76
+ 77
+ 78
+ 79
+ 80
+ 81
+ 82
+ 83
+ 84
+ 85
+ 86
+ 87
+ 88
+ 89
+ 90
+ 91
+ 92
+ 93
+ 94
+ 95
+ 96
+ 97
+ 98
+ 99
+100
+101
+102
+103
+104
+105
+106
+107
+108
+109
+110
+111
+112
+113
+114
+115
+116
+117
+118
+119
+120
+121
+122
+123
+124
+125
+126
+127
+128
+129
+130
+131
+132
+133
+134
+135
+136
+137
+138
+139
+140
+141
+142
+143
+144
+145
+146
+147
+148
+149
+150
+151
+152
+153
+154
+155
+156
+157
+158
+159
+160
+161
+162
+163
+164
+165
+166
+167
+168
+169
+170
+171
+172
+173
+174
+175
+176
+177
+178
+179
+180
+181
+182
+183
+184
+185
+186
+187
+188
+189
+190
+191
+192
+193
+194
+195
+196
+197
+198
+199
+200
+201
+202
+203
+204
+205
+206
+207
+208
+209
+210
+211
+212
+213
+214
+215
+216
+217
+218
+219
+220
+221
+222
+223
+224
+225
+226
+227
+228
+229
+230
+231
+232
+233
+234
+235
+236
+237
+238
+239
+240
+241
+242
+243
+244
+245
+246
+247
+248
+249
+250
+251
+252
+253
+254
+255
+256
+257
+258
+259
+260
+261
+262
+263
+264
+265
+266
+267
+268
+269
+270
+271
+272
+273
+274
+275
+276
+277
+278
+279
+280
+281
+282
+283
+284
+285
+286
+287
+288
+289
+290
+291
+292
+293
+294
+295
+296
+297
+298
+299
+300
+301
+302
+303
+304
+305
+306
+307
+308
+309
+310
+311
+312
+313
+314
+315
+316
+317
+318
+319
+320
+321
+322
+323
+324
+325
+326
+327
+328
+329
+330
+331
+332
+333
+334
+335
+336
+337
+338
+339
+340
+341
+342
+343
+344
+345
+346
+347
+348
+349
+350
+351
+352
+353
+354
+355
+356
+357
+358
+359
+360
+361
+362
+363
+364
+365
+366
+367
+368
+369
+370
+371
+372
+373
+374
+375
+376
+377
+378
+379
+380
+381
+382
+383
+384
+385
+386
+387
+388
+389
+390
+391
+392
+393
+394
+395
+396
+397
+398
+399
+400
+401
+402
+403
+404
+405
+406
+407
+408
+409
+410
+411
+412
+413
+414
+415
+416
+417
+418
+419
+420
+421
+422
+423
+424
+425
+426
+427
+428
+429
+430
+431
+432
+433
+434
+435
+436
+437
+438
+439
+440
+441
+442
+443
+444
+445
+446
+447
+448
+449
+450
+451
+452
+453
+454
+455
+456
+457
+458
+459
+460
+461
+462
+463
+464
+465
+466
+467
+468
+469
+470
+471
+472
+473
+474
+475
+476
+477
+478
+479
+480
+481
+482
+483
+484
+485
+486
+487
+488
+489
+490
+491
+492
+493
+494
+495
+496
+497
+498
+499
+500
+501
+502
+503
+504
+505
+506
+507
+508
+509
+510
+511
+512
+513
+514
+515
+516
+517
+518
+519
+520
+521
+522
+523
+524
+525
+526
+527
+528
+529
+530
+531
+532
+533
+534
+535
+536
+537
+538
+539
+540
+541
+542
+543
+544
+545
+546
+547
+548
+549
+550
+551
+552
+553
+554
+555
+556
+557
+558
+559
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
+
+/*
+ *  Copyright (C) 2004-2008 Red Hat, Inc.
+ *
+ *  Caja is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU General Public License as
+ *  published by the Free Software Foundation; either version 2 of the
+ *  License, or (at your option) any later version.
+ *
+ *  Caja is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  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
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ *  Authors: Bastien Nocera <hadess@hadess.net>
+ *
+ */
+
+#include "config.h"
+
+#include <glib.h>
+#include <glib/gi18n.h>
+#include <gio/gio.h>
+#include <gdk/gdk.h>
+#include <gtk/gtk.h>
+#include <libnotify/notify.h>
+#include <dbus/dbus-glib.h>
+#include <dbus/dbus-glib-lowlevel.h>
+#include <canberra-gtk.h>
+
+#include <string.h>
+
+#include "marshal.h"
+#include "obexpush.h"
+#include "user_share-common.h"
+#include "user_share-private.h"
+
+#define DBUS_TYPE_G_STRING_VARIANT_HASHTABLE (dbus_g_type_get_map ("GHashTable", G_TYPE_STRING, G_TYPE_STRING))
+
+#define GSETTINGS_SCHEMA "org.mate.FileSharing"
+
+static DBusGConnection *connection = NULL;<--- Shadowed declaration
+static DBusGProxy *manager_proxy = NULL;
+static DBusGProxy *server_proxy = NULL;
+static AcceptSetting accept_setting = -1;
+static gboolean show_notifications = FALSE;
+
+static GtkStatusIcon *statusicon = NULL;
+static guint num_notifications = 0;
+
+static void
+hide_statusicon (void)
+{
+	num_notifications--;
+	if (num_notifications == 0)
+		gtk_status_icon_set_visible (statusicon, FALSE);
+}
+
+static void
+on_close_notification (NotifyNotification *notification)
+{
+	hide_statusicon ();
+	g_object_unref (notification);
+}
+
+static void
+notification_launch_action_on_file_cb (NotifyNotification *notification,
+				       const char *action,
+				       const char *file_uri)
+{
+	GdkScreen *screen;
+	GAppLaunchContext *ctx;
+	GTimeVal val;
+
+	g_assert (action != NULL);
+
+	g_get_current_time (&val);
+
+	ctx = G_APP_LAUNCH_CONTEXT (gdk_app_launch_context_new ());
+	screen = gdk_screen_get_default ();
+	gdk_app_launch_context_set_screen (GDK_APP_LAUNCH_CONTEXT (ctx), screen);
+	gdk_app_launch_context_set_timestamp (GDK_APP_LAUNCH_CONTEXT (ctx), val.tv_sec);
+
+	/* We launch the file viewer for the file */
+	if (g_str_equal (action, "display") != FALSE) {
+		if (g_app_info_launch_default_for_uri (file_uri, ctx, NULL) == FALSE) {
+			g_warning ("Failed to launch the file viewer\n");
+		}
+	}
+
+	/* we open the Downloads folder */
+	if (g_str_equal (action, "reveal") != FALSE) {
+		GFile *file;
+		GFile *parent;
+		gchar *parent_uri;
+
+		file = g_file_new_for_uri (file_uri);
+		parent = g_file_get_parent (file);
+		parent_uri = g_file_get_uri (parent);
+		g_object_unref (file);
+		g_object_unref (parent);
+
+		if (!g_app_info_launch_default_for_uri (parent_uri, ctx, NULL)) {
+			g_warning ("Failed to launch the file manager\n");
+		}
+
+		g_free (parent_uri);
+	}
+
+	notify_notification_close (notification, NULL);
+	/* No need to call hide_statusicon(), closing the notification
+	 * will call the close callback */
+}
+
+static void
+show_notification (const char *filename)
+{
+	char *file_uri, *notification_text, *display, *mime_type;
+	NotifyNotification *notification;
+	ca_context *ctx;
+	GAppInfo *app;
+
+	file_uri = g_filename_to_uri (filename, NULL, NULL);
+	if (file_uri == NULL) {
+		g_warning ("Could not make a filename from '%s'", filename);
+		return;
+	}
+
+	display = g_filename_display_basename (filename);
+	/* Translators: %s is the name of the filename received */
+	notification_text = g_strdup_printf(_("You received \"%s\" via Bluetooth"), display);
+	g_free (display);
+	notification = notify_notification_new (_("You received a file"),
+								 notification_text,
+								 "dialog-information");
+
+	notify_notification_set_timeout (notification, NOTIFY_EXPIRES_DEFAULT);
+
+	mime_type = g_content_type_guess (filename, NULL, 0, NULL);
+	app = g_app_info_get_default_for_type (mime_type, FALSE);
+	if (app != NULL) {
+		g_object_unref (app);
+		notify_notification_add_action (notification, "display", _("Open File"),
+						(NotifyActionCallback) notification_launch_action_on_file_cb,
+						g_strdup (file_uri), (GFreeFunc) g_free);
+	}
+	notify_notification_add_action (notification, "reveal", _("Reveal File"),
+					(NotifyActionCallback) notification_launch_action_on_file_cb,
+					g_strdup (file_uri), (GFreeFunc) g_free);
+
+	g_free (file_uri);
+
+	g_signal_connect (G_OBJECT (notification), "closed", G_CALLBACK (on_close_notification), notification);
+
+	if (!notify_notification_show (notification, NULL)) {
+		g_warning ("failed to send notification\n");
+	}
+	g_free (notification_text);
+
+	/* Now we do the audio notification */
+	ctx = ca_gtk_context_get ();
+	ca_context_play (ctx, 0,
+			 CA_PROP_EVENT_ID, "complete-download",
+			 CA_PROP_EVENT_DESCRIPTION, _("File reception complete"),
+			 NULL);
+}
+
+static void
+show_icon (void)
+{
+	if (statusicon == NULL) {
+		statusicon = gtk_status_icon_new_from_icon_name ("mate-obex-server");
+	} else {
+		gtk_status_icon_set_visible (statusicon, TRUE);
+	}
+	num_notifications++;
+}
+
+static gboolean
+device_is_authorised (const char *bdaddr)
+{
+	DBusGConnection *connection;<--- Shadow variable
+	DBusGProxy *manager;
+	GError *error = NULL;
+	GPtrArray *adapters;
+	gboolean retval = FALSE;
+	guint i;
+
+	connection = dbus_g_bus_get (DBUS_BUS_SYSTEM, NULL);
+	if (connection == NULL)
+		return FALSE;
+
+	manager = dbus_g_proxy_new_for_name (connection, "org.bluez",
+					     "/", "org.bluez.Manager");
+	if (manager == NULL) {
+		dbus_g_connection_unref (connection);
+		return FALSE;
+	}
+
+	if (dbus_g_proxy_call (manager, "ListAdapters", &error, G_TYPE_INVALID, dbus_g_type_get_collection ("GPtrArray", DBUS_TYPE_G_OBJECT_PATH), &adapters, G_TYPE_INVALID) == FALSE) {
+		g_object_unref (manager);
+		dbus_g_connection_unref (connection);
+		return FALSE;
+	}
+
+	for (i = 0; i < adapters->len; i++) {
+		DBusGProxy *adapter, *device;
+		char *device_path;
+		GHashTable *props;
+
+		g_debug ("checking adapter %s", (gchar *) g_ptr_array_index (adapters, i));
+
+		adapter = dbus_g_proxy_new_for_name (connection, "org.bluez",
+						    g_ptr_array_index (adapters, i), "org.bluez.Adapter");
+
+		if (dbus_g_proxy_call (adapter, "FindDevice", NULL,
+				       G_TYPE_STRING, bdaddr, G_TYPE_INVALID,
+				       DBUS_TYPE_G_OBJECT_PATH, &device_path, G_TYPE_INVALID) == FALSE)
+		{
+			g_object_unref (adapter);
+			continue;
+		}
+
+		device = dbus_g_proxy_new_for_name (connection, "org.bluez", device_path, "org.bluez.Device");
+
+		if (dbus_g_proxy_call (device, "GetProperties", NULL,
+				       G_TYPE_INVALID, dbus_g_type_get_map ("GHashTable", G_TYPE_STRING, G_TYPE_VALUE),
+				       &props, G_TYPE_INVALID) != FALSE)
+		{
+			GValue *value;
+			gboolean bonded;
+
+			value = g_hash_table_lookup (props, "Paired");
+			bonded = g_value_get_boolean (value);
+			g_message ("%s is %s", bdaddr, bonded ? "bonded" : "not bonded");
+
+			if (bonded) {
+				g_hash_table_destroy (props);
+				g_object_unref (device);
+				g_object_unref (adapter);
+				retval = TRUE;
+				break;
+			}
+		}
+		g_object_unref(adapter);
+	}
+
+	g_ptr_array_free (adapters, TRUE);
+
+	g_object_unref(manager);
+	dbus_g_connection_unref(connection);
+
+	return retval;
+}
+
+static void
+transfer_started_cb (DBusGProxy *session,
+		     const char *filename,
+		     const char *local_path,
+		     guint64 size,
+		     gpointer user_data)
+{
+	GHashTable *dict;
+	DBusGProxy *server = (DBusGProxy *) user_data;
+	GError *error = NULL;
+	gboolean authorise;
+
+	g_message ("transfer started on %s", local_path);
+	g_object_set_data_full (G_OBJECT (session), "filename", g_strdup (local_path), (GDestroyNotify) g_free);
+
+	show_icon ();
+
+	/* First transfer of the session */
+	if (g_object_get_data (G_OBJECT (session), "bdaddr") == NULL) {
+		const char *bdaddr;
+
+		if (dbus_g_proxy_call (server, "GetServerSessionInfo", &error,
+				       DBUS_TYPE_G_OBJECT_PATH, dbus_g_proxy_get_path (session), G_TYPE_INVALID,
+				       DBUS_TYPE_G_STRING_VARIANT_HASHTABLE, &dict, G_TYPE_INVALID) == FALSE) {
+			g_printerr ("Getting Server session info failed: %s\n",
+				    error->message);
+			g_error_free (error);
+			return;
+		}
+
+		bdaddr = g_hash_table_lookup (dict, "BluetoothAddress");
+		g_message ("transfer started for device %s", bdaddr);
+
+		g_object_set_data_full (G_OBJECT (session), "bdaddr", g_strdup (bdaddr), (GDestroyNotify) g_free);
+		/* Initial accept method is undefined, we do that lower down */
+		g_object_set_data (G_OBJECT (session), "accept-method", GINT_TO_POINTER (-1));
+		g_hash_table_destroy (dict);
+	}
+
+	/* Accept method changed */
+	if (GPOINTER_TO_INT (g_object_get_data (G_OBJECT (session), "accept-method")) != accept_setting) {
+		const char *bdaddr;
+
+		bdaddr = g_object_get_data (G_OBJECT (session), "bdaddr");
+
+		if (bdaddr == NULL) {
+			g_warning ("Couldn't get the Bluetooth address for the device, rejecting the transfer");
+			authorise = FALSE;
+		} else if (accept_setting == ACCEPT_ALWAYS) {
+			authorise = TRUE;
+		} else if (accept_setting == ACCEPT_BONDED) {
+			authorise = device_is_authorised (bdaddr);
+		} else {
+			//FIXME implement
+			g_warning ("\"Ask\" authorisation method not implemented");
+			authorise = FALSE;
+		}
+		g_object_set_data (G_OBJECT (session), "authorise", GINT_TO_POINTER (authorise));
+	}
+
+	g_message ("accept_setting: %d", accept_setting);
+
+	authorise = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (session), "authorise"));
+	if (authorise != FALSE) {
+		if (dbus_g_proxy_call (session, "Accept", &error, G_TYPE_INVALID, G_TYPE_INVALID) == FALSE) {
+			g_printerr ("Failed to accept file transfer: %s\n", error->message);
+			g_error_free (error);
+			return;
+		}
+		g_message ("authorised transfer");
+	} else {
+		if (dbus_g_proxy_call (session, "Reject", &error, G_TYPE_INVALID, G_TYPE_INVALID) == FALSE) {
+			g_printerr ("Failed to reject file transfer: %s\n", error->message);
+			g_error_free (error);
+			return;
+		}
+		g_message ("rejected transfer");
+		g_object_set_data (G_OBJECT (session), "filename", NULL);
+	}
+}
+
+static void
+transfer_completed_cb (DBusGProxy *session,
+		       gpointer user_data)
+{
+	GSettings *settings;
+	gboolean display_notify;
+	const char *filename;
+
+	filename = (const char *) g_object_get_data (G_OBJECT (session), "filename");
+
+	g_message ("file finish transfer: %s", filename);
+
+	if (filename == NULL)
+		return;
+
+	settings = g_settings_new (GSETTINGS_SCHEMA);
+	display_notify = g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_OBEXPUSH_NOTIFY);
+	g_object_unref (settings);
+
+	if (display_notify) {
+		show_notification (filename);
+	} else {
+		hide_statusicon ();
+	}
+	g_object_set_data (G_OBJECT (session), "filename", NULL);
+}
+
+static void
+cancelled_cb (DBusGProxy *session,
+	      gpointer user_data)
+{
+	//FIXME implement properly, we never actually finished the transfer
+	g_message ("transfered was cancelled by the sender");
+	transfer_completed_cb (session, user_data);
+	hide_statusicon ();
+}
+
+static void
+error_occurred_cb (DBusGProxy *session,
+		   const char *error_name,
+		   const char *error_message,
+		   gpointer user_data)
+{
+	//FIXME implement properly
+	g_message ("transfer error occurred: %s", error_message);
+	transfer_completed_cb (session, user_data);
+}
+
+static void
+session_created_cb (DBusGProxy *server, const char *session_path, gpointer user_data)
+{
+	DBusGProxy *session;
+
+	session = dbus_g_proxy_new_for_name (connection,
+					     "org.openobex",
+					     session_path,
+					     "org.openobex.ServerSession");
+
+	dbus_g_proxy_add_signal (session, "TransferStarted",
+				 G_TYPE_STRING, G_TYPE_STRING, G_TYPE_UINT64, G_TYPE_INVALID);
+	dbus_g_proxy_connect_signal(session, "TransferStarted",
+				    G_CALLBACK (transfer_started_cb), server, NULL);
+	dbus_g_proxy_add_signal (session, "TransferCompleted",
+				 G_TYPE_INVALID, G_TYPE_INVALID);
+	dbus_g_proxy_connect_signal(session, "TransferCompleted",
+				    G_CALLBACK (transfer_completed_cb), server, NULL);
+	dbus_g_proxy_add_signal (session, "Cancelled",
+				 G_TYPE_INVALID, G_TYPE_INVALID);
+	dbus_g_proxy_connect_signal(session, "Cancelled",
+				    G_CALLBACK (cancelled_cb), server, NULL);
+	dbus_g_proxy_add_signal (session, "ErrorOccurred",
+				 G_TYPE_INVALID, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INVALID);
+	dbus_g_proxy_connect_signal(session, "ErrorOccurred",
+				    G_CALLBACK (error_occurred_cb), server, NULL);
+}
+
+void
+obexpush_up (void)
+{
+	GError *err = NULL;
+	char *download_dir, *server;
+
+	server = NULL;
+	if (manager_proxy == NULL) {
+		manager_proxy = dbus_g_proxy_new_for_name (connection,
+							   "org.openobex",
+							   "/org/openobex",
+							   "org.openobex.Manager");
+		if (dbus_g_proxy_call (manager_proxy, "CreateBluetoothServer",
+				       &err, G_TYPE_STRING, "00:00:00:00:00:00", G_TYPE_STRING, "opp", G_TYPE_BOOLEAN, FALSE, G_TYPE_INVALID,
+				       DBUS_TYPE_G_OBJECT_PATH, &server, G_TYPE_INVALID) == FALSE) {
+			g_printerr ("Creating Bluetooth ObexPush server failed: %s\n",
+				    err->message);
+			g_error_free (err);
+			g_object_unref (manager_proxy);
+			manager_proxy = NULL;
+			return;
+		}
+	}
+
+	download_dir = lookup_download_dir ();
+
+	if (server_proxy == NULL) {
+		server_proxy = dbus_g_proxy_new_for_name (connection,
+							   "org.openobex",
+							   server,
+							   "org.openobex.Server");
+		g_free (server);
+
+		dbus_g_proxy_add_signal (server_proxy, "SessionCreated",
+					 DBUS_TYPE_G_OBJECT_PATH, G_TYPE_INVALID);
+		dbus_g_proxy_connect_signal(server_proxy, "SessionCreated",
+					    G_CALLBACK (session_created_cb), NULL, NULL);
+	}
+
+	if (dbus_g_proxy_call (server_proxy, "Start", &err,
+			   G_TYPE_STRING, download_dir, G_TYPE_BOOLEAN, TRUE, G_TYPE_BOOLEAN, FALSE, G_TYPE_INVALID,
+			   G_TYPE_INVALID) == FALSE) {
+		if (g_error_matches (err, DBUS_GERROR, DBUS_GERROR_REMOTE_EXCEPTION) != FALSE &&
+		    dbus_g_error_has_name (err, "org.openobex.Error.Started") != FALSE) {
+		    	g_error_free (err);
+		    	g_message ("already started, ignoring error");
+		    	g_free (download_dir);
+		    	return;
+		}
+		g_printerr ("Starting Bluetooth ObexPush server failed: %s\n",
+			    err->message);
+		g_error_free (err);
+		g_free (download_dir);
+		g_object_unref (server_proxy);
+		server_proxy = NULL;
+		g_object_unref (manager_proxy);
+		manager_proxy = NULL;
+		return;
+	}
+
+	g_free (download_dir);
+}
+
+static void
+obexpush_stop (gboolean stop_manager)
+{
+	GError *err = NULL;
+
+	if (server_proxy == NULL)
+		return;
+
+	if (dbus_g_proxy_call (server_proxy, "Close", &err, G_TYPE_INVALID, G_TYPE_INVALID) == FALSE) {
+		if (g_error_matches (err, DBUS_GERROR, DBUS_GERROR_REMOTE_EXCEPTION) == FALSE ||
+		    dbus_g_error_has_name (err, "org.openobex.Error.NotStarted") == FALSE) {
+			g_printerr ("Stopping Bluetooth ObexPush server failed: %s\n",
+				    err->message);
+			g_error_free (err);
+			return;
+		}
+		g_error_free (err);
+	}
+
+	if (stop_manager != FALSE) {
+		g_object_unref (server_proxy);
+		server_proxy = NULL;
+		g_object_unref (manager_proxy);
+		manager_proxy = NULL;
+	}
+
+	//FIXME stop all the notifications
+}
+
+void
+obexpush_down (void)
+{
+	obexpush_stop (TRUE);
+}
+
+void
+obexpush_restart (void)
+{
+	obexpush_stop (FALSE);
+	obexpush_up ();
+}
+
+gboolean
+obexpush_init (void)
+{
+	GError *err = NULL;
+
+	connection = dbus_g_bus_get (DBUS_BUS_SESSION, &err);
+	if (connection == NULL) {
+		g_printerr ("Connecting to session bus failed: %s\n",
+			    err->message);
+		g_error_free (err);
+		return FALSE;
+	}
+
+	dbus_g_object_register_marshaller (marshal_VOID__STRING_STRING_UINT64,
+					   G_TYPE_NONE,
+					   G_TYPE_STRING, G_TYPE_STRING, G_TYPE_UINT64, G_TYPE_INVALID);
+
+	if (!notify_init("mate-user-share")) {
+		g_warning("Unable to initialize the notification system\n");
+        }
+
+	dbus_connection_set_exit_on_disconnect (dbus_g_connection_get_connection (connection), FALSE);
+
+	return TRUE;
+}
+
+void
+obexpush_set_accept_files_policy (AcceptSetting setting)
+{
+	accept_setting = setting;
+}
+
+void
+obexpush_set_notify (gboolean enabled)
+{
+	show_notifications = enabled;
+}
+
+
+
+ + + diff --git a/2020-06-28-102155-0593-cppcheck@ceeb6e4bfa08_master/3.html b/2020-06-28-102155-0593-cppcheck@ceeb6e4bfa08_master/3.html new file mode 100644 index 0000000..f31a1bc --- /dev/null +++ b/2020-06-28-102155-0593-cppcheck@ceeb6e4bfa08_master/3.html @@ -0,0 +1,748 @@ + + + + + + Cppcheck - HTML report - mate-user-share + + + + + + + +
+
  1
+  2
+  3
+  4
+  5
+  6
+  7
+  8
+  9
+ 10
+ 11
+ 12
+ 13
+ 14
+ 15
+ 16
+ 17
+ 18
+ 19
+ 20
+ 21
+ 22
+ 23
+ 24
+ 25
+ 26
+ 27
+ 28
+ 29
+ 30
+ 31
+ 32
+ 33
+ 34
+ 35
+ 36
+ 37
+ 38
+ 39
+ 40
+ 41
+ 42
+ 43
+ 44
+ 45
+ 46
+ 47
+ 48
+ 49
+ 50
+ 51
+ 52
+ 53
+ 54
+ 55
+ 56
+ 57
+ 58
+ 59
+ 60
+ 61
+ 62
+ 63
+ 64
+ 65
+ 66
+ 67
+ 68
+ 69
+ 70
+ 71
+ 72
+ 73
+ 74
+ 75
+ 76
+ 77
+ 78
+ 79
+ 80
+ 81
+ 82
+ 83
+ 84
+ 85
+ 86
+ 87
+ 88
+ 89
+ 90
+ 91
+ 92
+ 93
+ 94
+ 95
+ 96
+ 97
+ 98
+ 99
+100
+101
+102
+103
+104
+105
+106
+107
+108
+109
+110
+111
+112
+113
+114
+115
+116
+117
+118
+119
+120
+121
+122
+123
+124
+125
+126
+127
+128
+129
+130
+131
+132
+133
+134
+135
+136
+137
+138
+139
+140
+141
+142
+143
+144
+145
+146
+147
+148
+149
+150
+151
+152
+153
+154
+155
+156
+157
+158
+159
+160
+161
+162
+163
+164
+165
+166
+167
+168
+169
+170
+171
+172
+173
+174
+175
+176
+177
+178
+179
+180
+181
+182
+183
+184
+185
+186
+187
+188
+189
+190
+191
+192
+193
+194
+195
+196
+197
+198
+199
+200
+201
+202
+203
+204
+205
+206
+207
+208
+209
+210
+211
+212
+213
+214
+215
+216
+217
+218
+219
+220
+221
+222
+223
+224
+225
+226
+227
+228
+229
+230
+231
+232
+233
+234
+235
+236
+237
+238
+239
+240
+241
+242
+243
+244
+245
+246
+247
+248
+249
+250
+251
+252
+253
+254
+255
+256
+257
+258
+259
+260
+261
+262
+263
+264
+265
+266
+267
+268
+269
+270
+271
+272
+273
+274
+275
+276
+277
+278
+279
+280
+281
+282
+283
+284
+285
+286
+287
+288
+289
+290
+291
/* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 8; tab-width: 8 -*-
+ *
+ * Copyright (C) 2003 Novell, Inc.
+ * Copyright (C) 2003-2004 Red Hat, Inc.
+ * Copyright (C) 2005 William Jon McCann <mccann@jhu.edu>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * 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 Foundation, Inc., 51 Franklin St, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ *
+ */
+
+#include "config.h"
+
+#include <stdlib.h>
+#include <string.h>
+#include <glib/gi18n-lib.h>
+#include <gtk/gtk.h>
+#include <libcaja-extension/caja-menu-provider.h>
+#include <libcaja-extension/caja-location-widget-provider.h>
+
+#ifdef HAVE_BLUETOOTH
+#include <bluetooth-client.h>
+#endif
+
+#include "caja-share-bar.h"
+#include "user_share-common.h"
+
+#define CAJA_TYPE_USER_SHARE  (caja_user_share_get_type ())
+#define CAJA_USER_SHARE(o)    (G_TYPE_CHECK_INSTANCE_CAST ((o), CAJA_TYPE_USER_SHARE, CajaUserShare))
+#define CAJA_IS_USER_SHARE(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), CAJA_TYPE_USER_SHARE))
+
+typedef struct
+{
+        GObject              parent_slot;
+} CajaUserShare;
+
+typedef struct
+{
+        GObjectClass parent_slot;
+} CajaUserShareClass;
+
+static GType caja_user_share_get_type      (void);
+static void  caja_user_share_register_type (GTypeModule *module);
+
+static void
+launch_process (char **argv, GtkWindow *parent)
+{
+        GError *error;
+        GtkWidget *dialog;
+
+        error = NULL;
+        if (!g_spawn_async (NULL,
+                            argv, NULL,
+                            0,
+                            NULL, NULL,
+                            NULL,
+                            &error)) {
+
+
+                dialog = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL, GTK_MESSAGE_WARNING,
+						 GTK_BUTTONS_OK, _("Unable to launch the Personal File Sharing preferences"));
+
+                gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog), "%s", error->message);
+
+                gtk_dialog_run (GTK_DIALOG (dialog));
+                gtk_widget_destroy (dialog);
+
+                g_error_free (error);
+        }
+}
+
+static void
+launch_prefs_on_window (GtkWindow *window)
+{
+        char *argv [2];
+
+        argv [0] = g_build_filename (BINDIR, "mate-file-share-properties", NULL);
+        argv [1] = NULL;
+
+        launch_process (argv, window);
+
+        g_free (argv [0]);
+}
+
+static void
+bar_response_cb (CajaShareBar *bar,
+                 gint response,
+                 gpointer         data)
+{
+        if (response == CAJA_SHARE_BAR_RESPONSE_PREFERENCES) {
+                launch_prefs_on_window (GTK_WINDOW (data));
+        }
+}
+
+#ifdef HAVE_BLUETOOTH
+static void
+downloads_bar_set_from_bluetooth_status (GtkWidget *bar)
+{
+	BluetoothClient *client;
+	gboolean bt_powered;
+
+	client = g_object_get_data (G_OBJECT (bar), "bluetooth-client");
+	g_object_get (G_OBJECT (client),
+		      "default-adapter-powered", &bt_powered,
+		      NULL);
+	gtk_widget_set_visible (bar, bt_powered);
+}
+
+static void
+default_adapter_powered_cb (GObject    *gobject,
+			    GParamSpec *pspec,
+			    GtkWidget  *bar)
+{
+	downloads_bar_set_from_bluetooth_status (bar);
+}
+#endif /* HAVE_BLUETOOTH */
+
+static GtkWidget *
+caja_user_share_get_location_widget (CajaLocationWidgetProvider *iface,
+                                         const char                     *uri,
+                                         GtkWidget                      *window)
+{
+	GFile             *file;
+	GtkWidget         *bar;
+	guint              i;
+	gboolean           enable = FALSE;
+	GFile             *home;
+#ifdef HAVE_BLUETOOTH
+	const GUserDirectory special_dirs[] = { G_USER_DIRECTORY_PUBLIC_SHARE, G_USER_DIRECTORY_DOWNLOAD };
+
+	gboolean is_dir[] = { FALSE, FALSE };
+#else
+	const GUserDirectory special_dirs[] = { G_USER_DIRECTORY_PUBLIC_SHARE };
+
+	gboolean is_dir[] = { FALSE };
+#endif /* HAVE_BLUETOOTH */
+	file = g_file_new_for_uri (uri);
+	home = g_file_new_for_path (g_get_home_dir ());
+
+	/* We don't show anything in $HOME */
+	if (g_file_equal (home, file)) {
+		g_object_unref (home);
+		g_object_unref (file);
+		return NULL;
+	}
+
+	g_object_unref (home);
+
+	for (i = 0; i < G_N_ELEMENTS (special_dirs); i++) {
+		GFile *dir;
+		dir = lookup_dir_with_fallback (special_dirs[i]);
+		if (g_file_equal (dir, file)) {
+			enable = TRUE;
+			is_dir[i] = TRUE;
+		}
+		g_object_unref (dir);
+	}
+
+	g_object_unref (file);
+
+	if (enable == FALSE)
+		return NULL;
+
+	if (is_dir[0] != FALSE) {
+#ifdef HAVE_BLUETOOTH
+		if (is_dir[1] != FALSE) {
+			bar = caja_share_bar_new (_("May be used to share or receive files"));
+		} else {
+			bar = caja_share_bar_new (_("May be shared over the network or Bluetooth"));
+		}
+#else
+		bar = caja_share_bar_new (_("May be shared over the network"));
+#endif /* HAVE_BLUETOOTH */
+	} else {
+#ifdef HAVE_BLUETOOTH
+		BluetoothClient *client;
+
+		bar = caja_share_bar_new (_("May be used to receive files over Bluetooth"));
+
+		gtk_widget_set_no_show_all (bar, TRUE);
+		client = bluetooth_client_new ();
+		g_object_set_data_full (G_OBJECT (bar), "bluetooth-client", client, g_object_unref);
+		g_signal_connect (G_OBJECT (client), "notify::default-adapter-powered",
+				  G_CALLBACK (default_adapter_powered_cb), bar);
+		downloads_bar_set_from_bluetooth_status (bar);
+#endif /* HAVE_BLUETOOTH */
+	}
+
+	g_signal_connect (bar, "response",
+			  G_CALLBACK (bar_response_cb),
+			  window);
+
+	gtk_widget_show_all (bar);
+
+	return bar;
+}
+
+static void
+caja_user_share_location_widget_provider_iface_init (CajaLocationWidgetProviderIface *iface)
+{
+        iface->get_widget = caja_user_share_get_location_widget;
+}
+
+static void
+caja_user_share_instance_init (CajaUserShare *share)
+{
+
+}
+
+static void
+caja_user_share_class_init (CajaUserShareClass *klass)
+{
+
+}
+
+static GType share_type = 0;
+
+static GType
+caja_user_share_get_type (void)
+{
+        return share_type;
+}
+
+static void
+caja_user_share_register_type (GTypeModule *module)
+{
+        static const GTypeInfo info = {
+                sizeof (CajaUserShareClass),
+                (GBaseInitFunc) NULL,
+                (GBaseFinalizeFunc) NULL,
+                (GClassInitFunc) caja_user_share_class_init,
+                NULL,
+                NULL,
+                sizeof (CajaUserShare),
+                0,
+                (GInstanceInitFunc) caja_user_share_instance_init,
+        };
+
+        static const GInterfaceInfo location_widget_provider_iface_info = {
+                (GInterfaceInitFunc) caja_user_share_location_widget_provider_iface_init,
+                NULL,
+                NULL
+        };
+
+        share_type = g_type_module_register_type (module,
+                                                 G_TYPE_OBJECT,
+                                                 "CajaUserShare",
+                                                 &info, 0);
+
+        g_type_module_add_interface (module,
+                                     share_type,
+                                     CAJA_TYPE_LOCATION_WIDGET_PROVIDER,
+                                     &location_widget_provider_iface_info);
+}
+
+void
+caja_module_initialize (GTypeModule *module)
+{
+        caja_user_share_register_type (module);
+        bindtextdomain (GETTEXT_PACKAGE, MATELOCALEDIR);
+        bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
+}
+
+void
+caja_module_shutdown (void)
+{
+}
+
+void
+caja_module_list_types (const GType **types,
+                            int          *num_types)
+{
+        static GType type_list [1];
+
+        type_list[0] = CAJA_TYPE_USER_SHARE;
+
+        *types = type_list;
+        *num_types = 1;
+}
+
+
+
+ + + diff --git a/2020-06-28-102155-0593-cppcheck@ceeb6e4bfa08_master/4.html b/2020-06-28-102155-0593-cppcheck@ceeb6e4bfa08_master/4.html new file mode 100644 index 0000000..462c100 --- /dev/null +++ b/2020-06-28-102155-0593-cppcheck@ceeb6e4bfa08_master/4.html @@ -0,0 +1,336 @@ + + + + + + Cppcheck - HTML report - mate-user-share + + + + + + + +
+
 1
+ 2
+ 3
+ 4
+ 5
+ 6
+ 7
+ 8
+ 9
+10
+11
+12
+13
+14
+15
+16
+17
+18
+19
+20
+21
+22
+23
+24
+25
+26
+27
+28
+29
+30
+31
+32
+33
+34
+35
+36
+37
+38
+39
+40
+41
+42
+43
+44
+45
+46
+47
+48
+49
+50
+51
+52
+53
+54
+55
+56
+57
+58
+59
+60
+61
+62
+63
+64
+65
+66
+67
+68
+69
+70
+71
+72
+73
+74
+75
+76
+77
+78
+79
+80
+81
+82
+83
+84
+85
+86
+87
+88
+89
+90
+91
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
+
+/*
+ *  Copyright (C) 2004-2009 Red Hat, Inc.
+ *
+ *  Caja is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU General Public License as
+ *  published by the Free Software Foundation; either version 2 of the
+ *  License, or (at your option) any later version.
+ *
+ *  Caja is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  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
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ *  Authors: Alexander Larsson <alexl@redhat.com>
+ *  Bastien Nocera <hadess@hadess.net>
+ *
+ */
+
+#include <string.h>
+
+#include "user_share-common.h"
+
+static char *
+lookup_special_dir (GUserDirectory directory,
+		    const char *name,
+		    gboolean create_dir)
+{
+	const char *special_dir;
+	char *dir;
+
+	special_dir = g_get_user_special_dir (directory);
+	if (special_dir != NULL && strcmp (special_dir, g_get_home_dir ()) != 0) {
+		if (create_dir != FALSE)
+			g_mkdir_with_parents (special_dir, 0755);
+		return g_strdup (special_dir);
+	}
+
+	dir = g_build_filename (g_get_home_dir (), name, NULL);
+	if (create_dir != FALSE)
+		g_mkdir_with_parents (dir, 0755);
+	return dir;
+}
+
+char *
+lookup_public_dir (void)
+{
+	return lookup_special_dir (G_USER_DIRECTORY_PUBLIC_SHARE,
+				   "Public",
+				   TRUE);
+}
+
+char *
+lookup_download_dir (void)
+{
+	return lookup_special_dir (G_USER_DIRECTORY_DOWNLOAD,
+				   "Downloads",
+				   TRUE);
+}
+
+GFile *
+lookup_dir_with_fallback (GUserDirectory directory)
+{
+	GFile *file;
+	char *path;
+	const char *name;
+
+	if (directory == G_USER_DIRECTORY_PUBLIC_SHARE)
+		name = "Public";
+	else if (directory == G_USER_DIRECTORY_DOWNLOAD)
+		name = "Downloads";
+	else
+		g_assert_not_reached ();
+
+	path = lookup_special_dir (directory,
+				   name,<--- Uninitialized variable: name
+				   FALSE);
+
+	if (path == NULL)
+		return NULL;
+
+	file = g_file_new_for_path (path);
+	g_free (path);
+
+	return file;
+}
+
+
+
+ + + diff --git a/2020-06-28-102155-0593-cppcheck@ceeb6e4bfa08_master/5.html b/2020-06-28-102155-0593-cppcheck@ceeb6e4bfa08_master/5.html new file mode 100644 index 0000000..5dde496 --- /dev/null +++ b/2020-06-28-102155-0593-cppcheck@ceeb6e4bfa08_master/5.html @@ -0,0 +1,1166 @@ + + + + + + Cppcheck - HTML report - mate-user-share + + + + + + + +
+
  1
+  2
+  3
+  4
+  5
+  6
+  7
+  8
+  9
+ 10
+ 11
+ 12
+ 13
+ 14
+ 15
+ 16
+ 17
+ 18
+ 19
+ 20
+ 21
+ 22
+ 23
+ 24
+ 25
+ 26
+ 27
+ 28
+ 29
+ 30
+ 31
+ 32
+ 33
+ 34
+ 35
+ 36
+ 37
+ 38
+ 39
+ 40
+ 41
+ 42
+ 43
+ 44
+ 45
+ 46
+ 47
+ 48
+ 49
+ 50
+ 51
+ 52
+ 53
+ 54
+ 55
+ 56
+ 57
+ 58
+ 59
+ 60
+ 61
+ 62
+ 63
+ 64
+ 65
+ 66
+ 67
+ 68
+ 69
+ 70
+ 71
+ 72
+ 73
+ 74
+ 75
+ 76
+ 77
+ 78
+ 79
+ 80
+ 81
+ 82
+ 83
+ 84
+ 85
+ 86
+ 87
+ 88
+ 89
+ 90
+ 91
+ 92
+ 93
+ 94
+ 95
+ 96
+ 97
+ 98
+ 99
+100
+101
+102
+103
+104
+105
+106
+107
+108
+109
+110
+111
+112
+113
+114
+115
+116
+117
+118
+119
+120
+121
+122
+123
+124
+125
+126
+127
+128
+129
+130
+131
+132
+133
+134
+135
+136
+137
+138
+139
+140
+141
+142
+143
+144
+145
+146
+147
+148
+149
+150
+151
+152
+153
+154
+155
+156
+157
+158
+159
+160
+161
+162
+163
+164
+165
+166
+167
+168
+169
+170
+171
+172
+173
+174
+175
+176
+177
+178
+179
+180
+181
+182
+183
+184
+185
+186
+187
+188
+189
+190
+191
+192
+193
+194
+195
+196
+197
+198
+199
+200
+201
+202
+203
+204
+205
+206
+207
+208
+209
+210
+211
+212
+213
+214
+215
+216
+217
+218
+219
+220
+221
+222
+223
+224
+225
+226
+227
+228
+229
+230
+231
+232
+233
+234
+235
+236
+237
+238
+239
+240
+241
+242
+243
+244
+245
+246
+247
+248
+249
+250
+251
+252
+253
+254
+255
+256
+257
+258
+259
+260
+261
+262
+263
+264
+265
+266
+267
+268
+269
+270
+271
+272
+273
+274
+275
+276
+277
+278
+279
+280
+281
+282
+283
+284
+285
+286
+287
+288
+289
+290
+291
+292
+293
+294
+295
+296
+297
+298
+299
+300
+301
+302
+303
+304
+305
+306
+307
+308
+309
+310
+311
+312
+313
+314
+315
+316
+317
+318
+319
+320
+321
+322
+323
+324
+325
+326
+327
+328
+329
+330
+331
+332
+333
+334
+335
+336
+337
+338
+339
+340
+341
+342
+343
+344
+345
+346
+347
+348
+349
+350
+351
+352
+353
+354
+355
+356
+357
+358
+359
+360
+361
+362
+363
+364
+365
+366
+367
+368
+369
+370
+371
+372
+373
+374
+375
+376
+377
+378
+379
+380
+381
+382
+383
+384
+385
+386
+387
+388
+389
+390
+391
+392
+393
+394
+395
+396
+397
+398
+399
+400
+401
+402
+403
+404
+405
+406
+407
+408
+409
+410
+411
+412
+413
+414
+415
+416
+417
+418
+419
+420
+421
+422
+423
+424
+425
+426
+427
+428
+429
+430
+431
+432
+433
+434
+435
+436
+437
+438
+439
+440
+441
+442
+443
+444
+445
+446
+447
+448
+449
+450
+451
+452
+453
+454
+455
+456
+457
+458
+459
+460
+461
+462
+463
+464
+465
+466
+467
+468
+469
+470
+471
+472
+473
+474
+475
+476
+477
+478
+479
+480
+481
+482
+483
+484
+485
+486
+487
+488
+489
+490
+491
+492
+493
+494
+495
+496
+497
+498
+499
+500
+501
+502
+503
+504
+505
+506
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
+
+/*
+ *  Copyright (C) 2004-2008 Red Hat, Inc.
+ *
+ *  Caja is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU General Public License as
+ *  published by the Free Software Foundation; either version 2 of the
+ *  License, or (at your option) any later version.
+ *
+ *  Caja is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  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
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ *  Authors: Alexander Larsson <alexl@redhat.com>
+ *
+ */
+
+#include "config.h"
+
+#include <gdk/gdkx.h>
+#include <gtk/gtk.h>
+#include <glib/gi18n.h>
+#include <glib/gstdio.h>
+#include <gio/gio.h>
+#include <X11/Xlib.h>
+
+#include "user_share-private.h"
+#include "user_share-common.h"
+#include "http.h"
+
+#ifdef HAVE_BLUETOOTH
+#include <bluetooth-client.h>
+
+#include "obexftp.h"
+#include "obexpush.h"
+
+#endif /* HAVE_BLUETOOTH */
+
+#include <gio/gio.h>
+
+#include <stdarg.h>
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <signal.h>
+#include <unistd.h>
+
+static guint disabled_timeout_tag = 0;
+static GSettings* settings;<--- Shadowed declaration<--- Shadowed declaration<--- Shadowed declaration
+
+#define GSETTINGS_SCHEMA "org.mate.FileSharing"
+#define GSETTINGS_KEY_FILE_SHARING_ENABLED "enabled"
+#define GSETTINGS_KEY_FILE_SHARING_REQUIRE_PASSWORD "require-password"
+
+#ifdef HAVE_BLUETOOTH
+/* MATE Session */
+#define MATE_SESSION_DBUS_NAME      "org.gnome.SessionManager"
+#define MATE_SESSION_DBUS_OBJECT    "/org/gnome/SessionManager"
+#define MATE_SESSION_DBUS_INTERFACE "org.gnome.SessionManager"
+
+static GDBusProxy *session_proxy = NULL;
+static gboolean has_console = TRUE;
+
+static BluetoothClient *client = NULL;
+static gboolean bluetoothd_enabled = FALSE;
+
+#define OBEX_ENABLED (bluetoothd_enabled && has_console)
+
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_ENABLED "bluetooth-enabled"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_ALLOW_WRITE "bluetooth-allow-write"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_REQUIRE_PAIRING "bluetooth-require-pairing"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED "bluetooth-obexpush-enabled"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_ACCEPT_FILES "bluetooth-accept-files"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_NOTIFY "bluetooth-notify"
+
+
+static void
+obex_services_start (void)
+{
+	GSettings *settings;<--- Shadow variable
+
+	if (bluetoothd_enabled == FALSE ||
+	    has_console == FALSE)
+	    	return;
+
+	settings = g_settings_new(GSETTINGS_SCHEMA);
+
+	if (g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED) == TRUE) {
+	    obexpush_up ();
+	}
+	if (g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_ENABLED) == TRUE) {
+	    obexftp_up ();
+	}
+
+	g_object_unref (client);
+}
+
+static void
+obex_services_shutdown (void)
+{
+	obexpush_down ();
+	obexftp_down ();
+}
+
+static void
+session_properties_changed_cb (GDBusProxy      *session,
+			       GVariant        *changed,
+			       char           **invalidated,
+			       gpointer         user_data)
+{
+	GVariant *v;
+
+	v = g_variant_lookup_value (changed, "SessionIsActive", G_VARIANT_TYPE_BOOLEAN);
+	if (v) {
+		has_console = g_variant_get_boolean (v);
+		g_debug ("Received session is active change: now %s", has_console ? "active" : "inactive");
+
+		if (has_console)
+			obex_services_start ();
+		else
+			obex_services_shutdown ();
+
+		g_variant_unref (v);
+	}
+}
+
+static gboolean
+is_session_active (void)
+{
+	GVariant *variant;
+	gboolean is_session_active = FALSE;
+
+	variant = g_dbus_proxy_get_cached_property (session_proxy,
+						    "SessionIsActive");
+	if (variant) {
+		is_session_active = g_variant_get_boolean (variant);
+		g_variant_unref (variant);
+ 	}
+
+	return is_session_active;
+}
+
+static void
+session_init (void)
+{
+	GError *error = NULL;
+
+	session_proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION,
+						       G_DBUS_PROXY_FLAGS_NONE,
+						       NULL,
+						       MATE_SESSION_DBUS_NAME,
+						       MATE_SESSION_DBUS_OBJECT,
+						       MATE_SESSION_DBUS_INTERFACE,
+						       NULL,
+						       &error);
+	if (session_proxy == NULL) {
+		g_warning ("Failed to get session proxy: %s", error->message);
+		g_error_free (error);
+		return;
+	}
+	g_signal_connect (session_proxy, "g-properties-changed",
+			  G_CALLBACK (session_properties_changed_cb),
+			  NULL);
+	has_console = is_session_active ();
+}
+
+static void
+default_adapter_changed (GObject    *gobject,
+			 GParamSpec *pspec,
+			 gpointer    user_data)
+{
+	char *adapter;
+	gboolean adapter_powered;
+
+	g_object_get (G_OBJECT (client),
+		      "default-adapter", &adapter,
+		      "default-adapter-powered", &adapter_powered,
+		      NULL);
+	if (adapter != NULL && *adapter != '\0') {
+		bluetoothd_enabled = adapter_powered;
+	} else {
+		bluetoothd_enabled = FALSE;
+	}
+
+	/* Were we called as init, or as a callback */
+	if (gobject != NULL) {
+		if (bluetoothd_enabled != FALSE)
+			obex_services_start ();
+		else
+			obex_services_shutdown ();
+	}
+}
+
+static void
+bluez_init (void)
+{
+	client = bluetooth_client_new ();
+	default_adapter_changed (NULL, NULL, NULL);
+	g_signal_connect (G_OBJECT (client), "notify::default-adapter",
+			  G_CALLBACK (default_adapter_changed), NULL);
+	g_signal_connect (G_OBJECT (client), "notify::default-adapter-powered",
+			  G_CALLBACK (default_adapter_changed), NULL);
+}
+#endif /* HAVE_BLUETOOTH */
+
+static gboolean
+file_sharing_enabled (void)
+{
+	gboolean enabled = TRUE;
+	settings = g_settings_new (GSETTINGS_SCHEMA);
+
+#ifdef HAVE_BLUETOOTH
+	if (g_settings_get_boolean (settings, FILE_SHARING_ENABLED) == FALSE &&
+	    g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_ENABLED) == FALSE &&
+	    g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED) == FALSE)
+#else /* HAVE_BLUETOOTH */
+	if (g_settings_get_boolean (settings, FILE_SHARING_ENABLED) == FALSE)
+#endif /* HAVE_BLUETOOTH */
+		enabled = FALSE;
+
+	g_object_unref (settings);
+
+	return enabled;
+}
+
+static void
+migrate_old_configuration (void)
+{
+	const char *old_config_dir;
+	const char *new_config_dir;
+
+	old_config_dir = g_build_filename (g_get_home_dir (), ".mate2", "user-share", NULL);
+	new_config_dir = g_build_filename (g_get_user_config_dir (), "user-share", NULL);
+	if (g_file_test (old_config_dir, G_FILE_TEST_IS_DIR))
+		g_rename (old_config_dir, new_config_dir);
+
+}
+
+static void
+require_password_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	/* Need to restart to get new password setting */
+	if (http_get_pid () != 0) {
+		http_down ();
+		http_up ();
+	}
+}
+
+/* File sharing was disabled for some time, exit now */
+/* If we re-enable it in the ui, this will be restarted anyway */
+static gboolean
+disabled_timeout_callback (gpointer user_data)
+{
+	GSettings *settings = (GSettings *) user_data;<--- Shadow variable
+	http_down ();
+
+#ifdef HAVE_BLUETOOTH
+	if (g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_ENABLED) == FALSE &&
+	    g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED) == FALSE)
+		_exit (0);
+#else /* HAVE_BLUETOOTH */
+	if (g_settings_get_boolean (settings, FILE_SHARING_ENABLED) == FALSE)
+		_exit (0);
+#endif /* HAVE_BLUETOOTH */
+	return FALSE;
+}
+
+static void
+file_sharing_enabled_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	gboolean enabled;
+
+	if (disabled_timeout_tag != 0) {
+		g_source_remove (disabled_timeout_tag);
+		disabled_timeout_tag = 0;
+	}
+
+	enabled = g_settings_get_boolean (settings,
+					 FILE_SHARING_ENABLED);
+	if (enabled) {
+		if (http_get_pid () == 0) {
+			http_up ();
+		}
+	} else {
+		http_down ();
+		disabled_timeout_tag = g_timeout_add_seconds (3,
+							      (GSourceFunc)disabled_timeout_callback,
+							      settings);
+	}
+}
+
+#ifdef HAVE_BLUETOOTH
+static void
+file_sharing_bluetooth_allow_write_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	if (g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_ENABLED) != FALSE)
+		obexftp_restart ();
+}
+
+static void
+file_sharing_bluetooth_require_pairing_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	if (g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_ENABLED) != FALSE) {
+		/* We need to fully reset the session,
+		 * otherwise the new setting isn't taken into account */
+		obexftp_down ();
+		obexftp_up ();
+	}
+}
+
+static void
+file_sharing_bluetooth_enabled_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	if (g_settings_get_boolean (settings,
+				   FILE_SHARING_BLUETOOTH_ENABLED) == FALSE) {
+		obexftp_down ();
+		if (g_settings_get_boolean (settings, FILE_SHARING_ENABLED) == FALSE &&
+		    g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED) == FALSE) {
+			_exit (0);
+		}
+	} else if (OBEX_ENABLED) {
+		obexftp_up ();
+	}
+}
+
+static void
+file_sharing_bluetooth_obexpush_enabled_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	if (g_settings_get_boolean (settings,
+				   FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED) == FALSE) {
+		obexpush_down ();
+		if (g_settings_get_boolean (settings, FILE_SHARING_ENABLED) == FALSE &&
+		    g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_ENABLED) == FALSE) {
+			_exit (0);
+		}
+	} else if (OBEX_ENABLED) {
+		obexpush_up ();
+	}
+}
+
+static void
+file_sharing_bluetooth_obexpush_accept_files_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	AcceptSetting setting;
+	char *str;
+
+	str = g_settings_get_string (settings, FILE_SHARING_BLUETOOTH_OBEXPUSH_ACCEPT_FILES);
+	setting = accept_setting_from_string (str);
+	g_free (str);
+
+	obexpush_set_accept_files_policy (setting);
+}
+
+static void
+file_sharing_bluetooth_obexpush_notify_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	obexpush_set_notify (g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_OBEXPUSH_NOTIFY));
+}
+#endif /* HAVE_BLUETOOTH */
+
+static RETSIGTYPE
+cleanup_handler (int sig)
+{
+	http_down ();
+#ifdef HAVE_BLUETOOTH
+	obexftp_down ();
+	obexpush_down ();
+#endif /* HAVE_BLUETOOTH */
+	_exit (2);
+}
+
+static int
+x_io_error_handler (Display *xdisplay)
+{
+	http_down ();
+#ifdef HAVE_BLUETOOTH
+	obexftp_down ();
+#endif /* HAVE_BLUETOOTH */
+	_exit (2);
+}
+
+int
+main (int argc, char **argv)
+{
+	GSettings *settings;<--- Shadow variable
+	Display *xdisplay;
+	G_GNUC_UNUSED int x_fd;
+	Window selection_owner;
+	Atom xatom;
+
+	bindtextdomain (GETTEXT_PACKAGE, MATELOCALEDIR);
+	bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
+	textdomain (GETTEXT_PACKAGE);
+
+	gtk_init (&argc, &argv);
+
+	if (g_strcmp0 (g_get_real_name (), "root") == 0) {
+		g_warning ("mate-user-share cannot be started as root for security reasons.");
+		return 1;
+	}
+
+	signal (SIGPIPE, SIG_IGN);
+	signal (SIGINT, cleanup_handler);
+	signal (SIGHUP, cleanup_handler);
+	signal (SIGTERM, cleanup_handler);
+
+	xdisplay = GDK_DISPLAY_XDISPLAY (gdk_display_get_default ());
+	if (xdisplay == NULL) {
+		g_warning ("Can't open display");
+		return 1;
+	}
+
+	xatom = XInternAtom (xdisplay, "_MATE_USER_SHARE", FALSE);
+	selection_owner = XGetSelectionOwner (xdisplay, xatom);
+
+	if (selection_owner != None) {
+		/* There is an owner already, quit */
+		return 1;
+	}
+
+	selection_owner = XCreateSimpleWindow (xdisplay,
+					       RootWindow (xdisplay, 0),
+					       0, 0, 1, 1,
+					       0, 0, 0);
+	XSetSelectionOwner (xdisplay, xatom, selection_owner, CurrentTime);
+
+	if (XGetSelectionOwner (xdisplay, xatom) != selection_owner) {
+		/* Didn't get the selection */
+		return 1;
+	}
+
+	migrate_old_configuration ();
+
+	if (!file_sharing_enabled ())
+		return 1;
+
+	settings = g_settings_new (GSETTINGS_SCHEMA);
+
+	x_fd = ConnectionNumber (xdisplay);
+	XSetIOErrorHandler (x_io_error_handler);
+
+	if (http_init () == FALSE)
+		return 1;
+#ifdef HAVE_BLUETOOTH
+	if (obexftp_init () == FALSE)
+		return 1;
+	if (obexpush_init () == FALSE)
+		return 1;
+#endif /* HAVE_BLUETOOTH */
+
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_ENABLED,
+			     G_CALLBACK (file_sharing_enabled_changed), NULL);
+
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_REQUIRE_PASSWORD,
+			     G_CALLBACK (require_password_changed), NULL);
+
+#ifdef HAVE_BLUETOOTH
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_ENABLED,
+			     G_CALLBACK (file_sharing_bluetooth_enabled_changed), NULL);
+
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_ALLOW_WRITE,
+			     G_CALLBACK (file_sharing_bluetooth_allow_write_changed), NULL);
+
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_REQUIRE_PAIRING,
+			     G_CALLBACK (file_sharing_bluetooth_require_pairing_changed), NULL);
+
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED,
+			     G_CALLBACK (file_sharing_bluetooth_obexpush_enabled_changed), NULL);
+
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_ACCEPT_FILES,
+			     G_CALLBACK (file_sharing_bluetooth_obexpush_accept_files_changed), NULL);
+
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_NOTIFY,
+			     G_CALLBACK (file_sharing_bluetooth_obexpush_notify_changed), NULL);
+
+	bluez_init ();
+	session_init ();
+#endif /* HAVE_BLUETOOTH */
+
+	/* Initial setting */
+	file_sharing_enabled_changed (settings, NULL, NULL);
+#ifdef HAVE_BLUETOOTH
+	file_sharing_bluetooth_enabled_changed (settings, NULL, NULL);
+	file_sharing_bluetooth_obexpush_accept_files_changed (settings, NULL, NULL);
+	file_sharing_bluetooth_obexpush_notify_changed (settings, NULL, NULL);
+	file_sharing_bluetooth_obexpush_enabled_changed (settings, NULL, NULL);
+#endif /* HAVE_BLUETOOTH */
+
+	gtk_main ();
+
+	return 0;
+}
+
+
+
+ + + diff --git a/2020-06-28-102155-0593-cppcheck@ceeb6e4bfa08_master/index.html b/2020-06-28-102155-0593-cppcheck@ceeb6e4bfa08_master/index.html new file mode 100644 index 0000000..a691de5 --- /dev/null +++ b/2020-06-28-102155-0593-cppcheck@ceeb6e4bfa08_master/index.html @@ -0,0 +1,130 @@ + + + + + + Cppcheck - HTML report - mate-user-share + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
LineIdCWESeverityMessage
missingIncludeinformationCppcheck cannot find all the include files (use --check-config for details)
src/file-share-properties.c
82variableScope398styleThe scope of the variable 'password' can be reduced.
97shadowVariable398styleLocal variable 'settings' shadows outer variable
105unusedVariable563styleUnused variable: accept_setting
249shadowVariable398styleLocal variable 'settings' shadows outer variable
273shadowVariable398styleLocal variable 'settings' shadows outer variable
294shadowVariable398styleLocal variable 'settings' shadows outer variable
323shadowVariable398styleLocal variable 'settings' shadows outer variable
340shadowVariable398styleLocal variable 'settings' shadows outer variable
357shadowVariable398styleLocal variable 'settings' shadows outer variable
377shadowVariable398styleLocal variable 'settings' shadows outer variable
393shadowVariable398styleLocal variable 'settings' shadows outer variable
457shadowVariable398styleLocal variable 'settings' shadows outer variable
620variableScope398styleThe scope of the variable 'window' can be reduced.
src/http.c
107nullPointerArithmeticRedundantCheck682warningEither the condition 'end!=NULL' is redundant or there is overflow in pointer subtraction.
114variableScope398styleThe scope of the variable 'host_name' can be reduced.
src/obexpush.c
187shadowVariable398styleLocal variable 'connection' shadows outer variable
src/share-extension.c
61variableScope398styleThe scope of the variable 'dialog' can be reduced.
src/user_share-common.c
81uninitvar908errorUninitialized variable: name
src/user_share.c
86shadowVariable398styleLocal variable 'settings' shadows outer variable
260shadowVariable398styleLocal variable 'settings' shadows outer variable
391shadowVariable398styleLocal variable 'settings' shadows outer variable
+
+ + + diff --git a/2020-06-28-102155-0593-cppcheck@ceeb6e4bfa08_master/stats.html b/2020-06-28-102155-0593-cppcheck@ceeb6e4bfa08_master/stats.html new file mode 100644 index 0000000..0990d84 --- /dev/null +++ b/2020-06-28-102155-0593-cppcheck@ceeb6e4bfa08_master/stats.html @@ -0,0 +1,99 @@ + + + + + + Cppcheck - HTML report - mate-user-share + + + + + + + +
+

Top 10 files for error severity, total findings: 1
+   1  src/user_share-common.c
+

+

Top 10 files for warning severity, total findings: 1
+   1  src/http.c
+

+

Top 10 files for style severity, total findings: 19
+   13  src/file-share-properties.c
+   3   src/user_share.c
+   1   src/share-extension.c
+   1   src/obexpush.c
+   1   src/http.c
+

+ +
+ + + diff --git a/2020-06-28-102155-0593-cppcheck@ceeb6e4bfa08_master/style.css b/2020-06-28-102155-0593-cppcheck@ceeb6e4bfa08_master/style.css new file mode 100644 index 0000000..c39571c --- /dev/null +++ b/2020-06-28-102155-0593-cppcheck@ceeb6e4bfa08_master/style.css @@ -0,0 +1,149 @@ + +body { + font: 13px Arial, Verdana, Sans-Serif; + margin: 0; + width: auto; +} + +h1 { + margin: 10px; +} + +#footer > p { + margin: 4px; +} + +.error { + background-color: #ffb7b7; +} + +.error2 { + background-color: #faa; + border: 1px dotted black; + display: inline-block; + margin-left: 4px; +} + +.inconclusive { + background-color: #B6B6B4; +} + +.inconclusive2 { + background-color: #B6B6B4; + border: 1px dotted black; + display: inline-block; + margin-left: 4px; +} + +div.verbose { + display: inline-block; + vertical-align: top; + cursor: help; +} + +div.verbose div.content { + display: none; + position: absolute; + padding: 10px; + margin: 4px; + max-width: 40%; + white-space: pre-wrap; + border: 1px solid black; + background-color: #FFFFCC; + cursor: auto; +} + +.highlight .hll { + padding: 1px; +} + +#header { + border-bottom: thin solid #aaa; +} + +#menu { + float: left; + margin-top: 5px; + text-align: left; + width: 150px; + /*height: 75%;*/ + position: fixed; + overflow: auto; + z-index: 1; +} + +#menu_index { + float: left; + margin-top: 5px; + padding-left: 5px; + text-align: left; + width: 300px; + /*height: 75%;*/ + position: fixed; + overflow: auto; + z-index: 1; +} + +#menu > a { + display: block; + margin-left: 10px; + font: 12px; + z-index: 1; +} + +#filename { + margin-left: 10px; + font: 12px; + z-index: 1; +} + +.highlighttable { + background-color:white; + z-index: 10; + position: relative; + margin: -10 px; +} + +#content { + background-color: white; + -webkit-box-sizing: content-box; + -moz-box-sizing: content-box; + box-sizing: content-box; + float: left; + margin: 5px; + margin-left: 10px; + padding: 0 10px 10px 10px; + width: 80%; + padding-left: 150px; +} + +#content_index { + background-color: white; + -webkit-box-sizing: content-box; + -moz-box-sizing: content-box; + box-sizing: content-box; + float: left; + margin: 5px; + margin-left: 10px; + padding: 0 10px 10px 10px; + width: 80%; + padding-left: 300px; +} + +.linenos { + border-right: thin solid #aaa; + color: lightgray; + padding-right: 6px; +} + +#footer { + border-top: thin solid #aaa; + clear: both; + font-size: 90%; + margin-top: 5px; +} + +#footer ul { + list-style-type: none; + padding-left: 0; +} diff --git a/2020-07-31-224753-9107-cppcheck@3fd04c35acf7_master/0.html b/2020-07-31-224753-9107-cppcheck@3fd04c35acf7_master/0.html new file mode 100644 index 0000000..4fb9d6e --- /dev/null +++ b/2020-07-31-224753-9107-cppcheck@3fd04c35acf7_master/0.html @@ -0,0 +1,1498 @@ + + + + + + Cppcheck - HTML report - mate-user-share + + + + + + +
+ +
+
  1
+  2
+  3
+  4
+  5
+  6
+  7
+  8
+  9
+ 10
+ 11
+ 12
+ 13
+ 14
+ 15
+ 16
+ 17
+ 18
+ 19
+ 20
+ 21
+ 22
+ 23
+ 24
+ 25
+ 26
+ 27
+ 28
+ 29
+ 30
+ 31
+ 32
+ 33
+ 34
+ 35
+ 36
+ 37
+ 38
+ 39
+ 40
+ 41
+ 42
+ 43
+ 44
+ 45
+ 46
+ 47
+ 48
+ 49
+ 50
+ 51
+ 52
+ 53
+ 54
+ 55
+ 56
+ 57
+ 58
+ 59
+ 60
+ 61
+ 62
+ 63
+ 64
+ 65
+ 66
+ 67
+ 68
+ 69
+ 70
+ 71
+ 72
+ 73
+ 74
+ 75
+ 76
+ 77
+ 78
+ 79
+ 80
+ 81
+ 82
+ 83
+ 84
+ 85
+ 86
+ 87
+ 88
+ 89
+ 90
+ 91
+ 92
+ 93
+ 94
+ 95
+ 96
+ 97
+ 98
+ 99
+100
+101
+102
+103
+104
+105
+106
+107
+108
+109
+110
+111
+112
+113
+114
+115
+116
+117
+118
+119
+120
+121
+122
+123
+124
+125
+126
+127
+128
+129
+130
+131
+132
+133
+134
+135
+136
+137
+138
+139
+140
+141
+142
+143
+144
+145
+146
+147
+148
+149
+150
+151
+152
+153
+154
+155
+156
+157
+158
+159
+160
+161
+162
+163
+164
+165
+166
+167
+168
+169
+170
+171
+172
+173
+174
+175
+176
+177
+178
+179
+180
+181
+182
+183
+184
+185
+186
+187
+188
+189
+190
+191
+192
+193
+194
+195
+196
+197
+198
+199
+200
+201
+202
+203
+204
+205
+206
+207
+208
+209
+210
+211
+212
+213
+214
+215
+216
+217
+218
+219
+220
+221
+222
+223
+224
+225
+226
+227
+228
+229
+230
+231
+232
+233
+234
+235
+236
+237
+238
+239
+240
+241
+242
+243
+244
+245
+246
+247
+248
+249
+250
+251
+252
+253
+254
+255
+256
+257
+258
+259
+260
+261
+262
+263
+264
+265
+266
+267
+268
+269
+270
+271
+272
+273
+274
+275
+276
+277
+278
+279
+280
+281
+282
+283
+284
+285
+286
+287
+288
+289
+290
+291
+292
+293
+294
+295
+296
+297
+298
+299
+300
+301
+302
+303
+304
+305
+306
+307
+308
+309
+310
+311
+312
+313
+314
+315
+316
+317
+318
+319
+320
+321
+322
+323
+324
+325
+326
+327
+328
+329
+330
+331
+332
+333
+334
+335
+336
+337
+338
+339
+340
+341
+342
+343
+344
+345
+346
+347
+348
+349
+350
+351
+352
+353
+354
+355
+356
+357
+358
+359
+360
+361
+362
+363
+364
+365
+366
+367
+368
+369
+370
+371
+372
+373
+374
+375
+376
+377
+378
+379
+380
+381
+382
+383
+384
+385
+386
+387
+388
+389
+390
+391
+392
+393
+394
+395
+396
+397
+398
+399
+400
+401
+402
+403
+404
+405
+406
+407
+408
+409
+410
+411
+412
+413
+414
+415
+416
+417
+418
+419
+420
+421
+422
+423
+424
+425
+426
+427
+428
+429
+430
+431
+432
+433
+434
+435
+436
+437
+438
+439
+440
+441
+442
+443
+444
+445
+446
+447
+448
+449
+450
+451
+452
+453
+454
+455
+456
+457
+458
+459
+460
+461
+462
+463
+464
+465
+466
+467
+468
+469
+470
+471
+472
+473
+474
+475
+476
+477
+478
+479
+480
+481
+482
+483
+484
+485
+486
+487
+488
+489
+490
+491
+492
+493
+494
+495
+496
+497
+498
+499
+500
+501
+502
+503
+504
+505
+506
+507
+508
+509
+510
+511
+512
+513
+514
+515
+516
+517
+518
+519
+520
+521
+522
+523
+524
+525
+526
+527
+528
+529
+530
+531
+532
+533
+534
+535
+536
+537
+538
+539
+540
+541
+542
+543
+544
+545
+546
+547
+548
+549
+550
+551
+552
+553
+554
+555
+556
+557
+558
+559
+560
+561
+562
+563
+564
+565
+566
+567
+568
+569
+570
+571
+572
+573
+574
+575
+576
+577
+578
+579
+580
+581
+582
+583
+584
+585
+586
+587
+588
+589
+590
+591
+592
+593
+594
+595
+596
+597
+598
+599
+600
+601
+602
+603
+604
+605
+606
+607
+608
+609
+610
+611
+612
+613
+614
+615
+616
+617
+618
+619
+620
+621
+622
+623
+624
+625
+626
+627
+628
+629
+630
+631
+632
+633
+634
+635
+636
+637
+638
+639
+640
+641
+642
+643
+644
+645
+646
+647
+648
+649
+650
+651
+652
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
+
+/*
+ *  Copyright (C) 2004 Red Hat, Inc.
+ *
+ *  Caja is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU General Public License as
+ *  published by the Free Software Foundation; either version 2 of the
+ *  License, or (at your option) any later version.
+ *
+ *  Caja is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  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
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ *  Authors: Alexander Larsson <alexl@redhat.com>
+ *
+ */
+
+#include "config.h"
+
+#include <string.h>
+#include <stdio.h>
+
+#include <gtk/gtk.h>
+#include <glib/gi18n.h>
+#include <gio/gio.h>
+
+#include "user_share-private.h"
+
+#define REALM "Please log in as the user guest"
+#define USER "guest"
+#define GSETTINGS_SCHEMA "org.mate.FileSharing"
+#define GSETTINGS_KEY_FILE_SHARING_ENABLED "enabled"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_ENABLED "bluetooth-enabled"
+#define GSETTINGS_KEY_FILE_SHARING_REQUIRE_PASSWORD "require-password"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_ALLOW_WRITE "bluetooth-allow-write"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_REQUIRE_PAIRING "bluetooth-require-pairing"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED "bluetooth-obexpush-enabled"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_ACCEPT_FILES "bluetooth-accept-files"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_NOTIFY "bluetooth-notify"
+
+static GtkBuilder* builder;
+static GSettings* settings;<--- Shadowed declaration<--- Shadowed declaration<--- Shadowed declaration<--- Shadowed declaration<--- Shadowed declaration<--- Shadowed declaration<--- Shadowed declaration<--- Shadowed declaration<--- Shadowed declaration<--- Shadowed declaration
+
+
+static void
+write_out_password (const char *password)
+{
+    char *to_hash;
+    char *ascii_digest;
+    char *line;
+    char *filename;
+    FILE *file;
+
+    to_hash = g_strdup_printf ("%s:%s:%s", USER, REALM, password);
+    ascii_digest = g_compute_checksum_for_string (G_CHECKSUM_MD5, to_hash, strlen (to_hash));
+    g_free (to_hash);
+    line = g_strdup_printf ("%s:%s:%s\n", USER, REALM, ascii_digest);
+    g_free (ascii_digest);
+
+    filename = g_build_filename (g_get_user_config_dir (), "user-share", "passwd", NULL);
+
+    file = fopen (filename, "w");
+    if (file != NULL) {
+	fwrite (line, strlen (line), 1, file);
+	fclose (file);
+    }
+
+    g_free (filename);
+    g_free (line);
+}
+
+static void
+flush_password (void)
+{
+    GtkWidget *password_entry;
+    const char *password;
+
+    password_entry = GTK_WIDGET (gtk_builder_get_object (builder, "password_entry"));
+
+    if (g_object_get_data (G_OBJECT( password_entry), "user_edited")) {
+	password = gtk_entry_get_text (GTK_ENTRY (password_entry));
+	if (password != NULL && password[0] != 0)
+	    write_out_password (password);
+    }
+}
+
+
+static void
+update_ui (void)
+{
+    GSettings *settings;<--- Shadow variable
+    gboolean enabled;
+#ifdef HAVE_BLUETOOTH
+    gboolean bluetooth_enabled, bluetooth_write_enabled, require_pairing_enabled;
+    gboolean bluetooth_obexpush_enabled, bluetooth_obexpush_notify;
+#endif /* HAVE_BLUETOOTH */
+    char *str;
+    PasswordSetting password_setting;
+    AcceptSetting accept_setting;<--- Unused variable: accept_setting
+    GtkWidget *check;
+    GtkWidget *password_combo;
+    GtkWidget *password_entry;
+#ifdef HAVE_BLUETOOTH
+    GtkWidget *vbox_share_bluetooth;
+    GtkWidget *vbox_receive_bluetooth;
+    GtkWidget *bluetooth_check;
+    GtkWidget *allow_write_bluetooth_check;
+    GtkWidget *require_pairing_check;
+    GtkWidget *enable_obexpush_check;
+    GtkWidget *accept_obexpush_combo;
+    GtkWidget *notify_received_obexpush_check;
+#endif /* HAVE_BLUETOOTH */
+
+    settings = g_settings_new (GSETTINGS_SCHEMA);
+
+    enabled = g_settings_get_boolean (settings,
+				     FILE_SHARING_ENABLED);
+
+    str = g_settings_get_string (settings, FILE_SHARING_REQUIRE_PASSWORD);
+    password_setting = password_setting_from_string (str);
+    g_free (str);
+
+#ifdef HAVE_BLUETOOTH
+    bluetooth_enabled = g_settings_get_boolean (settings,
+    					       FILE_SHARING_BLUETOOTH_ENABLED);
+    bluetooth_write_enabled = g_settings_get_boolean (settings,
+						     FILE_SHARING_BLUETOOTH_ALLOW_WRITE);
+    require_pairing_enabled = g_settings_get_boolean (settings,
+    						     FILE_SHARING_BLUETOOTH_REQUIRE_PAIRING);
+    bluetooth_obexpush_enabled = g_settings_get_boolean (settings,
+    							FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED);
+    bluetooth_obexpush_notify = g_settings_get_boolean (settings,
+    						       FILE_SHARING_BLUETOOTH_OBEXPUSH_NOTIFY);
+
+    str = g_settings_get_string (settings, FILE_SHARING_BLUETOOTH_OBEXPUSH_ACCEPT_FILES);
+    accept_setting = accept_setting_from_string (str);
+    g_free (str);
+#endif /* HAVE_BLUETOOTH */
+
+    check = GTK_WIDGET (gtk_builder_get_object (builder, "enable_check"));
+    password_combo = GTK_WIDGET (gtk_builder_get_object (builder, "password_combo"));
+    password_entry = GTK_WIDGET (gtk_builder_get_object (builder, "password_entry"));
+#ifdef HAVE_BLUETOOTH
+    vbox_share_bluetooth = GTK_WIDGET (gtk_builder_get_object (builder, "vbox_share_bluetooth"));
+    vbox_receive_bluetooth = GTK_WIDGET (gtk_builder_get_object (builder, "vbox_receive_bluetooth"));
+    bluetooth_check = GTK_WIDGET (gtk_builder_get_object (builder, "enable_bluetooth_check"));
+    allow_write_bluetooth_check = GTK_WIDGET (gtk_builder_get_object (builder, "allow_write_bluetooth_check"));
+    require_pairing_check = GTK_WIDGET (gtk_builder_get_object (builder, "require_pairing_check"));
+    enable_obexpush_check = GTK_WIDGET (gtk_builder_get_object (builder, "enable_obexpush_check"));
+    accept_obexpush_combo = GTK_WIDGET (gtk_builder_get_object (builder, "accept_obexpush_combo"));
+    notify_received_obexpush_check = GTK_WIDGET (gtk_builder_get_object (builder, "notify_received_obexpush_check"));
+#endif /* HAVE_BLUETOOTH */
+
+    /* Network */
+    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (check), enabled);
+    gtk_widget_set_sensitive (password_combo, enabled);
+    gtk_widget_set_sensitive (password_entry, enabled && password_setting != PASSWORD_NEVER);
+
+    gtk_combo_box_set_active (GTK_COMBO_BOX (password_combo),
+			      password_setting);
+
+#ifdef HAVE_BLUETOOTH
+    /* Bluetooth ObexFTP */
+    gtk_widget_set_visible (vbox_share_bluetooth, TRUE);
+    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (bluetooth_check), bluetooth_enabled);
+    gtk_widget_set_sensitive (allow_write_bluetooth_check, bluetooth_enabled);
+    gtk_widget_set_sensitive (require_pairing_check, bluetooth_enabled);
+
+    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (allow_write_bluetooth_check),
+    				  bluetooth_write_enabled);
+    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (require_pairing_check),
+    				  require_pairing_enabled);
+
+    /* Bluetooth ObexPush */
+    gtk_widget_set_visible (vbox_receive_bluetooth, TRUE);
+    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (enable_obexpush_check), bluetooth_obexpush_enabled);
+    gtk_widget_set_sensitive (accept_obexpush_combo, bluetooth_obexpush_enabled);
+    gtk_widget_set_sensitive (notify_received_obexpush_check, bluetooth_obexpush_enabled);
+
+    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (notify_received_obexpush_check),
+    				  bluetooth_obexpush_notify);
+
+    gtk_combo_box_set_active (GTK_COMBO_BOX (accept_obexpush_combo),
+    			      accept_setting);
+#endif /* HAVE_BLUETOOTH */
+
+    g_object_unref (settings);
+}
+
+static void
+file_sharing_enabled_changed (GSettings *settings, gchar *key, gpointer data)
+{
+    update_ui ();
+}
+
+static void
+password_required_changed (GSettings *settings, gchar *key, gpointer data)
+{
+    update_ui ();
+}
+
+#ifdef HAVE_BLUETOOTH
+static void
+file_sharing_bluetooth_enabled_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	update_ui ();
+}
+
+static void
+file_sharing_bluetooth_allow_write_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	update_ui ();
+}
+
+static void
+file_sharing_bluetooth_require_pairing_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	update_ui ();
+}
+
+static void
+file_sharing_bluetooth_obexpush_enabled_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	update_ui ();
+}
+
+static void
+file_sharing_bluetooth_obexpush_accept_files_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	update_ui ();
+}
+
+static void
+file_sharing_bluetooth_obexpush_notify_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	update_ui ();
+}
+#endif /* HAVE_BLUETOOTH */
+
+static void
+password_combo_changed (GtkComboBox *combo_box)
+{
+    GSettings *settings;<--- Shadow variable
+    guint setting;
+
+    setting = gtk_combo_box_get_active (combo_box);
+
+    settings = g_settings_new (GSETTINGS_SCHEMA) ;
+
+    g_settings_set_string (settings,
+			     FILE_SHARING_REQUIRE_PASSWORD,
+			     password_string_from_setting (setting));
+    g_object_unref (settings);
+}
+
+static void
+launch_share (void)
+{
+	if (!g_spawn_command_line_async (USER_SHARE_PROGRAM, NULL))
+		g_warning ("Unable to start mate-user-share program");
+}
+
+#ifdef HAVE_BLUETOOTH
+static void
+enable_bluetooth_check_toggled (GtkWidget *check)
+{
+	GSettings *settings;<--- Shadow variable
+	gboolean enabled;
+
+	enabled = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check));
+
+	settings = g_settings_new (GSETTINGS_SCHEMA) ;
+
+	g_settings_set_boolean (settings,
+			       FILE_SHARING_BLUETOOTH_ENABLED,
+			       enabled);
+
+	g_object_unref (settings);
+
+	if (enabled != FALSE)
+		launch_share ();
+}
+#endif /* HAVE_BLUETOOTH */
+
+static void
+enable_check_toggled (GtkWidget *check)
+{
+	GSettings *settings;<--- Shadow variable
+	gboolean enabled;
+
+	enabled = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check));
+
+	settings = g_settings_new (GSETTINGS_SCHEMA);
+
+	g_settings_set_boolean (settings,
+			       FILE_SHARING_ENABLED,
+			       enabled);
+
+	g_object_unref (settings);
+
+	if (enabled != FALSE)
+		launch_share ();
+}
+
+static void
+password_entry_changed (GtkEditable *editable)
+{
+	g_object_set_data (G_OBJECT (editable),
+			   "user_edited", GINT_TO_POINTER (1));
+	flush_password ();
+}
+
+#ifdef HAVE_BLUETOOTH
+static void
+bluetooth_allow_write_check_toggled (GtkWidget *check)
+{
+	GSettings *settings;<--- Shadow variable
+	gboolean enabled;
+
+	enabled = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check));
+
+	settings = g_settings_new (GSETTINGS_SCHEMA) ;
+
+	g_settings_set_boolean (settings,
+			       FILE_SHARING_BLUETOOTH_ALLOW_WRITE,
+			       enabled);
+
+	g_object_unref (settings);
+}
+
+static void
+bluetooth_require_pairing_check_toggled (GtkWidget *check)
+{
+	GSettings *settings;<--- Shadow variable
+	gboolean enabled;
+
+	enabled = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check));
+
+	settings = g_settings_new (GSETTINGS_SCHEMA) ;
+
+	g_settings_set_boolean (settings,
+			       FILE_SHARING_BLUETOOTH_REQUIRE_PAIRING,
+			       enabled);
+
+	g_object_unref (settings);
+}
+
+static void
+enable_obexpush_check_toggled (GtkWidget *check)
+{
+	GSettings *settings;<--- Shadow variable
+	gboolean enabled;
+
+	enabled = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check));
+
+	settings = g_settings_new (GSETTINGS_SCHEMA) ;
+
+	g_settings_set_boolean (settings,
+			       FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED,
+			       enabled);
+
+	g_object_unref (settings);
+
+	if (enabled != FALSE)
+		launch_share ();
+}
+
+static void
+accept_obexpush_combo_changed (GtkComboBox *combo_box)
+{
+    GSettings *settings;<--- Shadow variable
+    guint setting;
+
+    setting = gtk_combo_box_get_active (combo_box);
+
+    settings = g_settings_new (GSETTINGS_SCHEMA) ;
+
+    g_settings_set_string (settings,
+			     FILE_SHARING_BLUETOOTH_OBEXPUSH_ACCEPT_FILES,
+			     accept_string_from_setting (setting));
+    g_object_unref (settings);
+}
+
+static void
+notify_received_obexpush_check_toggled (GtkWidget *check)
+{
+	GSettings *settings;<--- Shadow variable
+	gboolean enabled;
+
+	enabled = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check));
+
+	settings = g_settings_new (GSETTINGS_SCHEMA) ;
+
+	g_settings_set_boolean (settings,
+			       FILE_SHARING_BLUETOOTH_OBEXPUSH_NOTIFY,
+			       enabled);
+
+	g_object_unref (settings);
+}
+#endif /* HAVE_BLUETOOTH */
+
+static GtkWidget *
+error_dialog (const char *title,
+	      const char *reason,
+	      GtkWindow *parent)
+{
+	GtkWidget *error_dialog;
+
+	if (reason == NULL)
+		reason = _("No reason");
+
+	error_dialog =
+		gtk_message_dialog_new (parent,
+					GTK_DIALOG_MODAL,
+					GTK_MESSAGE_ERROR,
+					GTK_BUTTONS_OK,
+					"%s", title);
+	gtk_message_dialog_format_secondary_text
+		(GTK_MESSAGE_DIALOG (error_dialog), "%s", reason);
+
+	gtk_window_set_title (GTK_WINDOW (error_dialog), ""); /* as per HIG */
+	gtk_container_set_border_width (GTK_CONTAINER (error_dialog), 5);
+	gtk_dialog_set_default_response (GTK_DIALOG (error_dialog),
+					 GTK_RESPONSE_OK);
+	gtk_window_set_modal (GTK_WINDOW (error_dialog), TRUE);
+
+	return error_dialog;
+}
+
+static void
+help_button_clicked (GtkButton *button, GtkWidget *window)
+{
+	GError *error = NULL;
+
+	if (gtk_show_uri_on_window (GTK_WINDOW (window), "help:mate-user-share", gtk_get_current_event_time (), &error) == FALSE) {
+		GtkWidget *dialog;
+
+		dialog = error_dialog (_("Could not display the help contents."), error->message, GTK_WINDOW (window));
+		g_signal_connect (G_OBJECT (dialog), "response", G_CALLBACK
+				  (gtk_widget_destroy), error_dialog);
+		gtk_window_present (GTK_WINDOW (dialog));
+
+		g_error_free (error);
+	}
+}
+
+static GtkWidget *
+create_window (void)
+{
+    GError *error = NULL;
+    GSettings *settings;<--- Shadow variable
+    GtkWidget *check;
+    GtkWidget *password_combo;
+    GtkWidget *password_entry;
+#ifdef HAVE_BLUETOOTH
+    GtkWidget *bluetooth_check;
+    GtkWidget *bluetooth_allow_write_check;
+    GtkWidget *require_pairing_check;
+    GtkWidget *enable_obexpush_check;
+    GtkWidget *accept_obexpush_combo;
+    GtkWidget *notify_received_obexpush_check;
+#endif /* HAVE_BLUETOOTH */
+    GtkWidget *window;
+    GtkListStore *store;
+    GtkCellRenderer *cell;
+    GtkTreeIter iter;
+
+    builder = gtk_builder_new ();
+    gtk_builder_add_from_file (builder, DATADIR"file-share-properties.ui", &error);
+
+    if (error) {
+      GtkWidget *dialog;
+
+      dialog = error_dialog (_("Could not build interface."), error->message, NULL);
+      gtk_dialog_run (GTK_DIALOG (dialog));
+      gtk_widget_destroy (dialog);
+
+      g_error_free (error);
+      return NULL;
+    }
+
+    window = GTK_WIDGET (gtk_builder_get_object (builder, "user_share_dialog"));
+
+    settings = g_settings_new (GSETTINGS_SCHEMA);
+
+    check = GTK_WIDGET (gtk_builder_get_object (builder, "enable_check"));
+    password_combo = GTK_WIDGET (gtk_builder_get_object (builder, "password_combo"));
+    password_entry = GTK_WIDGET (gtk_builder_get_object (builder, "password_entry"));
+#ifdef HAVE_BLUETOOTH
+    bluetooth_check = GTK_WIDGET (gtk_builder_get_object (builder, "enable_bluetooth_check"));
+    bluetooth_allow_write_check = GTK_WIDGET (gtk_builder_get_object (builder, "allow_write_bluetooth_check"));
+    require_pairing_check = GTK_WIDGET (gtk_builder_get_object (builder, "require_pairing_check"));
+    enable_obexpush_check = GTK_WIDGET (gtk_builder_get_object (builder, "enable_obexpush_check"));
+    accept_obexpush_combo = GTK_WIDGET (gtk_builder_get_object (builder, "accept_obexpush_combo"));
+    notify_received_obexpush_check = GTK_WIDGET (gtk_builder_get_object (builder, "notify_received_obexpush_check"));
+#endif /* HAVE_BLUETOOTH */
+
+    store = gtk_list_store_new (1, G_TYPE_STRING);
+    gtk_combo_box_set_model (GTK_COMBO_BOX (password_combo),
+			     GTK_TREE_MODEL (store));
+    cell = gtk_cell_renderer_text_new ();
+    gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (password_combo), cell, TRUE);
+    gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (password_combo), cell,
+				    "text", 0,
+				    NULL);
+
+    /* Keep in same order as enum */
+    gtk_list_store_append (store, &iter);
+    gtk_list_store_set (store, &iter, 0,
+			_("Never"), -1);
+    gtk_list_store_append (store, &iter);
+    gtk_list_store_set (store, &iter, 0,
+			_("When writing files"), -1);
+    gtk_list_store_append (store, &iter);
+    gtk_list_store_set (store, &iter, 0,
+			_("Always"), -1);
+    g_object_unref (store);
+
+    /* We can't read the password from the text, just set it to something */
+    gtk_entry_set_text (GTK_ENTRY (password_entry), "none");
+    g_object_set_data (G_OBJECT (password_entry),
+		       "user_edited", GINT_TO_POINTER (0));
+    g_signal_connect (password_entry,
+		      "changed", G_CALLBACK (password_entry_changed), NULL);
+
+#ifdef HAVE_BLUETOOTH
+    /* Accept files combo */
+    store = gtk_list_store_new (1, G_TYPE_STRING);
+    gtk_combo_box_set_model (GTK_COMBO_BOX (accept_obexpush_combo),
+			     GTK_TREE_MODEL (store));
+    cell = gtk_cell_renderer_text_new ();
+    gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (accept_obexpush_combo), cell, TRUE);
+    gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (accept_obexpush_combo), cell,
+				    "text", 0,
+				    NULL);
+
+    /* Keep in same order as enum */
+    gtk_list_store_append (store, &iter);
+    gtk_list_store_set (store, &iter, 0,
+			_("Always"), -1);
+    gtk_list_store_append (store, &iter);
+    gtk_list_store_set (store, &iter, 0,
+			_("Only for set up devices"), -1);
+    //FIXME implement
+#if 0
+    gtk_list_store_append (store, &iter);
+    gtk_list_store_set (store, &iter, 0,
+    			_("Ask"), -1);
+#endif
+    g_object_unref (store);
+#endif /* HAVE_BLUETOOTH */
+
+    g_signal_connect (check,
+		      "toggled", G_CALLBACK (enable_check_toggled), NULL);
+    g_signal_connect (password_combo,
+		      "changed", G_CALLBACK (password_combo_changed), NULL);
+#ifdef HAVE_BLUETOOTH
+    g_signal_connect (bluetooth_check,
+    		      "toggled", G_CALLBACK (enable_bluetooth_check_toggled), NULL);
+    g_signal_connect (bluetooth_allow_write_check,
+    		      "toggled", G_CALLBACK (bluetooth_allow_write_check_toggled), NULL);
+    g_signal_connect (require_pairing_check,
+    		      "toggled", G_CALLBACK (bluetooth_require_pairing_check_toggled), NULL);
+    g_signal_connect (enable_obexpush_check,
+    		      "toggled", G_CALLBACK (enable_obexpush_check_toggled), NULL);
+    g_signal_connect (accept_obexpush_combo,
+    		      "changed", G_CALLBACK (accept_obexpush_combo_changed), NULL);
+    g_signal_connect (notify_received_obexpush_check,
+    		      "toggled", G_CALLBACK (notify_received_obexpush_check_toggled), NULL);
+#endif /* HAVE_BLUETOOTH */
+
+    g_signal_connect_swapped (GTK_WIDGET (gtk_builder_get_object (builder, "close_button")),
+                              "clicked", G_CALLBACK (gtk_widget_destroy), window);
+    g_signal_connect (GTK_WIDGET (gtk_builder_get_object (builder, "help_button")),
+		      "clicked", G_CALLBACK (help_button_clicked),
+		      gtk_builder_get_object (builder, "user_share_dialog"));
+
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_ENABLED,
+			     G_CALLBACK (file_sharing_enabled_changed), NULL);
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_REQUIRE_PASSWORD,
+			     G_CALLBACK (password_required_changed), NULL);
+#ifdef HAVE_BLUETOOTH
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_ENABLED,
+			     G_CALLBACK (file_sharing_bluetooth_enabled_changed), NULL);
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_ALLOW_WRITE,
+			     G_CALLBACK (file_sharing_bluetooth_allow_write_changed), NULL);
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_REQUIRE_PAIRING,
+			     G_CALLBACK (file_sharing_bluetooth_require_pairing_changed), NULL);
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED,
+			     G_CALLBACK (file_sharing_bluetooth_obexpush_enabled_changed), NULL);
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_ACCEPT_FILES,
+			     G_CALLBACK (file_sharing_bluetooth_obexpush_accept_files_changed), NULL);
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_NOTIFY,
+			     G_CALLBACK (file_sharing_bluetooth_obexpush_notify_changed), NULL);
+#endif /* HAVE_BLUETOOTH */
+
+    update_ui ();
+
+    return window;
+}
+
+static void
+activate (GtkApplication *app)
+{
+    GList *list;
+    GtkWidget *window;
+
+    list = gtk_application_get_windows (app);
+
+    if (list) {
+        gtk_window_present (GTK_WINDOW (list->data));
+    } else {
+        window = create_window ();
+        gtk_window_set_application (GTK_WINDOW (window), app);
+        gtk_widget_show (window);
+    }
+}
+
+int
+main (int argc, char *argv[])
+{
+    GtkApplication *app;
+    gint status;
+
+    bindtextdomain (GETTEXT_PACKAGE, MATELOCALEDIR);
+    bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
+    textdomain (GETTEXT_PACKAGE);
+
+    app = gtk_application_new ("org.mate.user-share.properties",
+                               G_APPLICATION_FLAGS_NONE);
+    g_signal_connect (app, "activate", G_CALLBACK (activate), NULL);
+
+    status = g_application_run (G_APPLICATION (app), argc, argv);
+
+    g_object_unref (app);
+
+    return status;
+}
+
+
+
+
+ + + diff --git a/2020-07-31-224753-9107-cppcheck@3fd04c35acf7_master/1.html b/2020-07-31-224753-9107-cppcheck@3fd04c35acf7_master/1.html new file mode 100644 index 0000000..273ae95 --- /dev/null +++ b/2020-07-31-224753-9107-cppcheck@3fd04c35acf7_master/1.html @@ -0,0 +1,1054 @@ + + + + + + Cppcheck - HTML report - mate-user-share + + + + + + +
+ +
+
  1
+  2
+  3
+  4
+  5
+  6
+  7
+  8
+  9
+ 10
+ 11
+ 12
+ 13
+ 14
+ 15
+ 16
+ 17
+ 18
+ 19
+ 20
+ 21
+ 22
+ 23
+ 24
+ 25
+ 26
+ 27
+ 28
+ 29
+ 30
+ 31
+ 32
+ 33
+ 34
+ 35
+ 36
+ 37
+ 38
+ 39
+ 40
+ 41
+ 42
+ 43
+ 44
+ 45
+ 46
+ 47
+ 48
+ 49
+ 50
+ 51
+ 52
+ 53
+ 54
+ 55
+ 56
+ 57
+ 58
+ 59
+ 60
+ 61
+ 62
+ 63
+ 64
+ 65
+ 66
+ 67
+ 68
+ 69
+ 70
+ 71
+ 72
+ 73
+ 74
+ 75
+ 76
+ 77
+ 78
+ 79
+ 80
+ 81
+ 82
+ 83
+ 84
+ 85
+ 86
+ 87
+ 88
+ 89
+ 90
+ 91
+ 92
+ 93
+ 94
+ 95
+ 96
+ 97
+ 98
+ 99
+100
+101
+102
+103
+104
+105
+106
+107
+108
+109
+110
+111
+112
+113
+114
+115
+116
+117
+118
+119
+120
+121
+122
+123
+124
+125
+126
+127
+128
+129
+130
+131
+132
+133
+134
+135
+136
+137
+138
+139
+140
+141
+142
+143
+144
+145
+146
+147
+148
+149
+150
+151
+152
+153
+154
+155
+156
+157
+158
+159
+160
+161
+162
+163
+164
+165
+166
+167
+168
+169
+170
+171
+172
+173
+174
+175
+176
+177
+178
+179
+180
+181
+182
+183
+184
+185
+186
+187
+188
+189
+190
+191
+192
+193
+194
+195
+196
+197
+198
+199
+200
+201
+202
+203
+204
+205
+206
+207
+208
+209
+210
+211
+212
+213
+214
+215
+216
+217
+218
+219
+220
+221
+222
+223
+224
+225
+226
+227
+228
+229
+230
+231
+232
+233
+234
+235
+236
+237
+238
+239
+240
+241
+242
+243
+244
+245
+246
+247
+248
+249
+250
+251
+252
+253
+254
+255
+256
+257
+258
+259
+260
+261
+262
+263
+264
+265
+266
+267
+268
+269
+270
+271
+272
+273
+274
+275
+276
+277
+278
+279
+280
+281
+282
+283
+284
+285
+286
+287
+288
+289
+290
+291
+292
+293
+294
+295
+296
+297
+298
+299
+300
+301
+302
+303
+304
+305
+306
+307
+308
+309
+310
+311
+312
+313
+314
+315
+316
+317
+318
+319
+320
+321
+322
+323
+324
+325
+326
+327
+328
+329
+330
+331
+332
+333
+334
+335
+336
+337
+338
+339
+340
+341
+342
+343
+344
+345
+346
+347
+348
+349
+350
+351
+352
+353
+354
+355
+356
+357
+358
+359
+360
+361
+362
+363
+364
+365
+366
+367
+368
+369
+370
+371
+372
+373
+374
+375
+376
+377
+378
+379
+380
+381
+382
+383
+384
+385
+386
+387
+388
+389
+390
+391
+392
+393
+394
+395
+396
+397
+398
+399
+400
+401
+402
+403
+404
+405
+406
+407
+408
+409
+410
+411
+412
+413
+414
+415
+416
+417
+418
+419
+420
+421
+422
+423
+424
+425
+426
+427
+428
+429
+430
+431
+432
+433
+434
+435
+436
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
+
+/*
+ *  Copyright (C) 2004-2008 Red Hat, Inc.
+ *
+ *  Caja is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU General Public License as
+ *  published by the Free Software Foundation; either version 2 of the
+ *  License, or (at your option) any later version.
+ *
+ *  Caja is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  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
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ *  Authors: Alexander Larsson <alexl@redhat.com>
+ *
+ */
+
+#include "config.h"
+
+#include <glib.h>
+#include <glib/gi18n.h>
+#include <X11/Xlib.h>
+
+#include <gio/gio.h>
+
+#include <stdarg.h>
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <signal.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <sys/stat.h>
+
+#ifdef HAVE_SELINUX
+#include <selinux/selinux.h>
+#endif
+
+#include "user_share-common.h"
+#include "user_share-private.h"
+#include "http.h"
+
+/* From avahi-common/domain.h */
+#define AVAHI_LABEL_MAX 64
+
+#define GSETTINGS_SCHEMA "org.mate.FileSharing"
+
+static pid_t httpd_pid = 0;
+
+static int
+get_port (void)
+{
+	int sock;
+	struct sockaddr_in addr;
+	int reuse;
+	socklen_t len;
+
+	sock = socket (PF_INET, SOCK_STREAM, 0);
+	if (sock < 0) {
+		return -1;
+	}
+
+	memset (&addr, 0, sizeof (addr));
+	addr.sin_port = 0;
+	addr.sin_addr.s_addr = INADDR_ANY;
+	addr.sin_family = AF_INET;
+
+	reuse = 1;
+	setsockopt (sock, SOL_SOCKET, SO_REUSEADDR, &reuse, sizeof (reuse));
+	if (bind (sock, (struct sockaddr *)&addr, sizeof (addr)) == -1) {
+		close (sock);
+		return -1;
+	}
+
+	len = sizeof (addr);
+	if (getsockname (sock, (struct sockaddr *)&addr, &len) == -1) {
+		close (sock);
+		return -1;
+	}
+
+#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__APPLE__) || defined(__OpenBSD__)
+	/* XXX This exposes a potential race condition, but without this,
+	 * httpd will not start on the above listed platforms due to the fact
+	 * that SO_REUSEADDR is also needed when Apache binds to the listening
+	 * socket.  At this time, Apache does not support that socket option.
+	 */
+	close (sock);
+#endif
+	return ntohs (addr.sin_port);
+}
+
+static char *
+truncate_name (const char *name)
+{
+	const char *end;
+
+	end = g_utf8_find_prev_char (name, name + 64);<--- Assignment 'end=g_utf8_find_prev_char(name,name+64)', assigned value is 0
+	g_assert (end != NULL);<--- Assuming that condition 'end!=NULL' is not redundant
+	return g_strndup (name, end - name);<--- Null pointer subtraction
+}
+
+static char *
+get_share_name (void)
+{
+	static char *name = NULL;
+	const char *host_name;
+	char *str;
+
+	if (name == NULL) {
+		host_name = g_get_host_name ();
+		if (strcmp (host_name, "localhost") == 0) {
+			/* Translators: The %s will get filled in with the user name
+			   of the user, to form a genitive. If this is difficult to
+			   translate correctly so that it will work correctly in your
+			   language, you may use something equivalent to
+			   "Public files of %s", or leave out the %s altogether.
+			   In the latter case, please put "%.0s" somewhere in the string,
+			   which will match the user name string passed by the C code,
+			   but not put the user name in the final string. This is to
+			   avoid the warning that msgfmt might otherwise generate. */
+			name = g_strdup_printf (_("%s's public files"), g_get_user_name ());
+		} else {
+			/* Translators: This is similar to the string before, only it
+			   has the hostname in it too. */
+			name = g_strdup_printf (_("%s's public files on %s"),
+						g_get_user_name (),
+						host_name);
+		}
+
+	}
+	/* And truncate */
+	if (strlen (name) < AVAHI_LABEL_MAX)
+		return name;
+
+	str = truncate_name (name);
+	g_free (name);
+	name = str;
+
+	return name;
+}
+
+static void
+ensure_conf_dir (void)
+{
+	char *dirname;
+
+	dirname = g_build_filename (g_get_user_config_dir (), "user-share", NULL);
+	g_mkdir_with_parents (dirname, 0755);
+	g_free (dirname);
+}
+
+static void
+httpd_child_setup (gpointer user_data)
+{
+#ifdef HAVE_SELINUX
+	char *mycon;
+	/* If selinux is enabled, avoid transitioning to the httpd_t context,
+	   as this normally means you can't read the users homedir. */
+	if (is_selinux_enabled()) {
+		if (getcon (&mycon) < 0) {
+			abort ();
+		}
+		if (setexeccon (mycon) < 0)
+			abort ();
+		freecon (mycon);
+	}
+#endif
+}
+
+static const char *known_httpd_locations [] = {
+	HTTPD_PROGRAM,
+	"/usr/sbin/httpd",
+	"/usr/sbin/httpd2",
+	"/usr/sbin/apache2",
+	NULL
+};
+
+static char*
+get_httpd_program (void)
+{
+	int i;
+
+	for (i = 0; known_httpd_locations[i]; i++) {
+		if (known_httpd_locations[i][0] == '\0') {
+			/* empty string as first element, happens when
+			 * configured --with-httpd=auto */
+			continue;
+		}
+		if (g_file_test (known_httpd_locations[i], G_FILE_TEST_IS_EXECUTABLE)
+				&& ! g_file_test (known_httpd_locations[i], G_FILE_TEST_IS_DIR)) {
+			return g_strdup (known_httpd_locations[i]);
+		}
+	}
+	return NULL;
+}
+
+static const char *known_httpd_modules_locations [] = {
+	HTTPD_MODULES_PATH,
+	"/etc/httpd/modules",
+	"/usr/lib/apache2/modules",
+	NULL
+};
+
+static gchar*
+get_httpd_modules_path (void)
+{
+	int i;
+
+	for (i = 0; known_httpd_modules_locations[i]; i++) {
+		if (known_httpd_modules_locations[i][0] == '\0') {
+			/* empty string as first element, happens when
+			 * configured --with-httpd=auto */
+			continue;
+		}
+		if (g_file_test (known_httpd_modules_locations[i], G_FILE_TEST_IS_EXECUTABLE)
+				&& g_file_test (known_httpd_modules_locations[i], G_FILE_TEST_IS_DIR)) {
+			return g_strdup (known_httpd_modules_locations[i]);
+		}
+	}
+	return NULL;
+}
+
+static GRegex *version_regex = NULL;
+
+static char*
+get_httpd_config (const char *httpd_program)
+{
+	gchar *standard_output;
+	gchar *cmd_line;
+	GMatchInfo *match_info;
+	gchar *version_number = NULL;
+	gchar *config;
+
+	cmd_line = g_strdup_printf ("%s -v", httpd_program);
+	if (! g_spawn_command_line_sync (cmd_line, &standard_output, NULL, NULL, NULL)) {
+		g_free (cmd_line);
+		return NULL;
+	}
+	g_free (cmd_line);
+
+	if (version_regex == NULL) {
+		version_regex = g_regex_new ("\\d\\.\\d", 0, 0, NULL);
+	}
+
+	if (g_regex_match (version_regex, standard_output, 0, &match_info)) {
+		while (g_match_info_matches (match_info)) {
+			version_number = g_match_info_fetch (match_info, 0);
+			break;
+		}
+		g_match_info_free (match_info);
+		g_free (standard_output);
+	} else {
+		/* Failed to parse httpd version number */
+		g_warning ("Could not parse '%s' as a version for httpd", standard_output);
+		g_free (standard_output);
+		/* assume it is 2.2 */
+		version_number = g_strdup ("2.2");
+	}
+
+	config = g_strdup_printf (HTTPD_CONFIG_TEMPLATE, version_number);
+	g_free (version_number);
+
+	return config;
+}
+
+static gboolean
+spawn_httpd (int port, pid_t *pid_out)
+{
+	char *free1, *free2, *free3, *free4, *free5, *free6, *free7, *free8, *free9;
+	gboolean res;
+	char *argv[10];
+	char *env[10];
+	int i;
+	gint status;
+	char *pid_filename;
+	char *pidfile;
+	GError *error;
+	gboolean got_pidfile;
+	GSettings *settings;
+	char *str;
+	char *public_dir;
+
+	public_dir = lookup_public_dir ();
+	ensure_conf_dir ();
+
+	i = 0;
+	free1 = argv[i++] = get_httpd_program ();
+	if (argv[0] == NULL) {
+		fprintf (stderr, "error finding httpd server\n");
+		return FALSE;
+	}
+
+	argv[i++] = "-f";
+	free2 = argv[i++] = get_httpd_config (argv[0]);
+	argv[i++] = "-C";
+	free3 = argv[i++] = g_strdup_printf ("Listen %d", port);
+
+	settings = g_settings_new (GSETTINGS_SCHEMA);
+	str = g_settings_get_string (settings,
+				       FILE_SHARING_REQUIRE_PASSWORD);
+
+	if (str && strcmp (str, "never") == 0) {
+		/* Do nothing */
+	} else if (str && strcmp (str, "on_write") == 0){
+		argv[i++] = "-D";
+		argv[i++] = "RequirePasswordOnWrite";
+	} else {
+		/* always, or safe fallback */
+		argv[i++] = "-D";
+		argv[i++] = "RequirePasswordAlways";
+	}
+	g_free (str);
+	g_object_unref (settings);
+
+	argv[i] = NULL;
+
+	i = 0;
+	free4 = env[i++] = g_strdup_printf ("HOME=%s", g_get_home_dir());
+	free5 = env[i++] = g_strdup_printf ("XDG_PUBLICSHARE_DIR=%s", public_dir);
+	free6 = env[i++] = g_strdup_printf ("XDG_CONFIG_HOME=%s", g_get_user_config_dir ());
+	free7 = env[i++] = g_strdup_printf ("GUS_SHARE_NAME=%s", get_share_name ());
+	free8 = env[i++] = g_strdup_printf ("GUS_LOGIN_LABEL=%s", "Please log in as the user guest");
+	free9 = env[i++] = g_strdup_printf ("HTTP_MODULES_PATH=%s",get_httpd_modules_path ());
+	env[i++] = "LANG=C";
+	env[i] = NULL;
+
+	pid_filename = g_build_filename (g_get_user_config_dir (), "user-share", "pid", NULL);
+
+	/* Remove pid file before spawning to avoid races with child and old pidfile */
+	unlink (pid_filename);
+
+	error = NULL;
+	res = g_spawn_sync (g_get_home_dir(),
+			    argv, env, 0,
+			    httpd_child_setup, NULL,
+			    NULL, NULL,
+			    &status,
+			    &error);
+	g_free (free1);
+	g_free (free2);
+	g_free (free3);
+	g_free (free4);
+	g_free (free5);
+	g_free (free6);
+	g_free (free7);
+	g_free (free8);
+	g_free (free9);
+	g_free (public_dir);
+
+	if (!res) {
+		fprintf (stderr, "error spawning httpd: %s\n",
+			 error->message);
+		g_error_free (error);
+		g_free (pid_filename);
+		return FALSE;
+	}
+
+	if (status != 0) {
+		g_free (pid_filename);
+		return FALSE;
+	}
+
+	got_pidfile = FALSE;
+	error = NULL;
+	for (i = 0; i < 5; i++) {
+		if (error != NULL)
+			g_error_free (error);
+		error = NULL;
+		if (g_file_get_contents (pid_filename, &pidfile, NULL, &error)) {
+			got_pidfile = TRUE;
+			*pid_out = atoi (pidfile);
+			g_free (pidfile);
+			break;
+		}
+		sleep (1);
+	}
+
+	g_free (pid_filename);
+
+	if (!got_pidfile) {
+		fprintf (stderr, "error opening httpd pidfile: %s\n", error->message);
+		g_error_free (error);
+		return FALSE;
+	}
+	return TRUE;
+}
+
+static void
+kill_httpd (void)
+{
+	if (httpd_pid != 0) {
+		kill (httpd_pid, SIGTERM);
+
+		/* Allow child time to die, we can't waitpid, because its
+		   not a direct child */
+		sleep (1);
+	}
+	httpd_pid = 0;
+}
+
+void
+http_up (void)
+{
+	guint port;
+
+	port = get_port ();
+	if (!spawn_httpd (port, &httpd_pid)) {
+		fprintf (stderr, "spawning httpd failed\n");
+	}
+}
+
+void
+http_down (void)
+{
+	kill_httpd ();
+}
+
+gboolean
+http_init (void)
+{
+	return TRUE;
+}
+
+pid_t
+http_get_pid (void)
+{
+	return httpd_pid;
+}
+
+
+
+
+ + + diff --git a/2020-07-31-224753-9107-cppcheck@3fd04c35acf7_master/2.html b/2020-07-31-224753-9107-cppcheck@3fd04c35acf7_master/2.html new file mode 100644 index 0000000..e964668 --- /dev/null +++ b/2020-07-31-224753-9107-cppcheck@3fd04c35acf7_master/2.html @@ -0,0 +1,1288 @@ + + + + + + Cppcheck - HTML report - mate-user-share + + + + + + +
+ +
+
  1
+  2
+  3
+  4
+  5
+  6
+  7
+  8
+  9
+ 10
+ 11
+ 12
+ 13
+ 14
+ 15
+ 16
+ 17
+ 18
+ 19
+ 20
+ 21
+ 22
+ 23
+ 24
+ 25
+ 26
+ 27
+ 28
+ 29
+ 30
+ 31
+ 32
+ 33
+ 34
+ 35
+ 36
+ 37
+ 38
+ 39
+ 40
+ 41
+ 42
+ 43
+ 44
+ 45
+ 46
+ 47
+ 48
+ 49
+ 50
+ 51
+ 52
+ 53
+ 54
+ 55
+ 56
+ 57
+ 58
+ 59
+ 60
+ 61
+ 62
+ 63
+ 64
+ 65
+ 66
+ 67
+ 68
+ 69
+ 70
+ 71
+ 72
+ 73
+ 74
+ 75
+ 76
+ 77
+ 78
+ 79
+ 80
+ 81
+ 82
+ 83
+ 84
+ 85
+ 86
+ 87
+ 88
+ 89
+ 90
+ 91
+ 92
+ 93
+ 94
+ 95
+ 96
+ 97
+ 98
+ 99
+100
+101
+102
+103
+104
+105
+106
+107
+108
+109
+110
+111
+112
+113
+114
+115
+116
+117
+118
+119
+120
+121
+122
+123
+124
+125
+126
+127
+128
+129
+130
+131
+132
+133
+134
+135
+136
+137
+138
+139
+140
+141
+142
+143
+144
+145
+146
+147
+148
+149
+150
+151
+152
+153
+154
+155
+156
+157
+158
+159
+160
+161
+162
+163
+164
+165
+166
+167
+168
+169
+170
+171
+172
+173
+174
+175
+176
+177
+178
+179
+180
+181
+182
+183
+184
+185
+186
+187
+188
+189
+190
+191
+192
+193
+194
+195
+196
+197
+198
+199
+200
+201
+202
+203
+204
+205
+206
+207
+208
+209
+210
+211
+212
+213
+214
+215
+216
+217
+218
+219
+220
+221
+222
+223
+224
+225
+226
+227
+228
+229
+230
+231
+232
+233
+234
+235
+236
+237
+238
+239
+240
+241
+242
+243
+244
+245
+246
+247
+248
+249
+250
+251
+252
+253
+254
+255
+256
+257
+258
+259
+260
+261
+262
+263
+264
+265
+266
+267
+268
+269
+270
+271
+272
+273
+274
+275
+276
+277
+278
+279
+280
+281
+282
+283
+284
+285
+286
+287
+288
+289
+290
+291
+292
+293
+294
+295
+296
+297
+298
+299
+300
+301
+302
+303
+304
+305
+306
+307
+308
+309
+310
+311
+312
+313
+314
+315
+316
+317
+318
+319
+320
+321
+322
+323
+324
+325
+326
+327
+328
+329
+330
+331
+332
+333
+334
+335
+336
+337
+338
+339
+340
+341
+342
+343
+344
+345
+346
+347
+348
+349
+350
+351
+352
+353
+354
+355
+356
+357
+358
+359
+360
+361
+362
+363
+364
+365
+366
+367
+368
+369
+370
+371
+372
+373
+374
+375
+376
+377
+378
+379
+380
+381
+382
+383
+384
+385
+386
+387
+388
+389
+390
+391
+392
+393
+394
+395
+396
+397
+398
+399
+400
+401
+402
+403
+404
+405
+406
+407
+408
+409
+410
+411
+412
+413
+414
+415
+416
+417
+418
+419
+420
+421
+422
+423
+424
+425
+426
+427
+428
+429
+430
+431
+432
+433
+434
+435
+436
+437
+438
+439
+440
+441
+442
+443
+444
+445
+446
+447
+448
+449
+450
+451
+452
+453
+454
+455
+456
+457
+458
+459
+460
+461
+462
+463
+464
+465
+466
+467
+468
+469
+470
+471
+472
+473
+474
+475
+476
+477
+478
+479
+480
+481
+482
+483
+484
+485
+486
+487
+488
+489
+490
+491
+492
+493
+494
+495
+496
+497
+498
+499
+500
+501
+502
+503
+504
+505
+506
+507
+508
+509
+510
+511
+512
+513
+514
+515
+516
+517
+518
+519
+520
+521
+522
+523
+524
+525
+526
+527
+528
+529
+530
+531
+532
+533
+534
+535
+536
+537
+538
+539
+540
+541
+542
+543
+544
+545
+546
+547
+548
+549
+550
+551
+552
+553
+554
+555
+556
+557
+558
+559
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
+
+/*
+ *  Copyright (C) 2004-2008 Red Hat, Inc.
+ *
+ *  Caja is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU General Public License as
+ *  published by the Free Software Foundation; either version 2 of the
+ *  License, or (at your option) any later version.
+ *
+ *  Caja is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  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
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ *  Authors: Bastien Nocera <hadess@hadess.net>
+ *
+ */
+
+#include "config.h"
+
+#include <glib.h>
+#include <glib/gi18n.h>
+#include <gio/gio.h>
+#include <gdk/gdk.h>
+#include <gtk/gtk.h>
+#include <libnotify/notify.h>
+#include <dbus/dbus-glib.h>
+#include <dbus/dbus-glib-lowlevel.h>
+#include <canberra-gtk.h>
+
+#include <string.h>
+
+#include "marshal.h"
+#include "obexpush.h"
+#include "user_share-common.h"
+#include "user_share-private.h"
+
+#define DBUS_TYPE_G_STRING_VARIANT_HASHTABLE (dbus_g_type_get_map ("GHashTable", G_TYPE_STRING, G_TYPE_STRING))
+
+#define GSETTINGS_SCHEMA "org.mate.FileSharing"
+
+static DBusGConnection *connection = NULL;<--- Shadowed declaration
+static DBusGProxy *manager_proxy = NULL;
+static DBusGProxy *server_proxy = NULL;
+static AcceptSetting accept_setting = -1;
+static gboolean show_notifications = FALSE;
+
+static GtkStatusIcon *statusicon = NULL;
+static guint num_notifications = 0;
+
+static void
+hide_statusicon (void)
+{
+	num_notifications--;
+	if (num_notifications == 0)
+		gtk_status_icon_set_visible (statusicon, FALSE);
+}
+
+static void
+on_close_notification (NotifyNotification *notification)
+{
+	hide_statusicon ();
+	g_object_unref (notification);
+}
+
+static void
+notification_launch_action_on_file_cb (NotifyNotification *notification,
+				       const char *action,
+				       const char *file_uri)
+{
+	GdkScreen *screen;
+	GAppLaunchContext *ctx;
+	GTimeVal val;
+
+	g_assert (action != NULL);
+
+	g_get_current_time (&val);
+
+	ctx = G_APP_LAUNCH_CONTEXT (gdk_app_launch_context_new ());
+	screen = gdk_screen_get_default ();
+	gdk_app_launch_context_set_screen (GDK_APP_LAUNCH_CONTEXT (ctx), screen);
+	gdk_app_launch_context_set_timestamp (GDK_APP_LAUNCH_CONTEXT (ctx), val.tv_sec);
+
+	/* We launch the file viewer for the file */
+	if (g_str_equal (action, "display") != FALSE) {
+		if (g_app_info_launch_default_for_uri (file_uri, ctx, NULL) == FALSE) {
+			g_warning ("Failed to launch the file viewer\n");
+		}
+	}
+
+	/* we open the Downloads folder */
+	if (g_str_equal (action, "reveal") != FALSE) {
+		GFile *file;
+		GFile *parent;
+		gchar *parent_uri;
+
+		file = g_file_new_for_uri (file_uri);
+		parent = g_file_get_parent (file);
+		parent_uri = g_file_get_uri (parent);
+		g_object_unref (file);
+		g_object_unref (parent);
+
+		if (!g_app_info_launch_default_for_uri (parent_uri, ctx, NULL)) {
+			g_warning ("Failed to launch the file manager\n");
+		}
+
+		g_free (parent_uri);
+	}
+
+	notify_notification_close (notification, NULL);
+	/* No need to call hide_statusicon(), closing the notification
+	 * will call the close callback */
+}
+
+static void
+show_notification (const char *filename)
+{
+	char *file_uri, *notification_text, *display, *mime_type;
+	NotifyNotification *notification;
+	ca_context *ctx;
+	GAppInfo *app;
+
+	file_uri = g_filename_to_uri (filename, NULL, NULL);
+	if (file_uri == NULL) {
+		g_warning ("Could not make a filename from '%s'", filename);
+		return;
+	}
+
+	display = g_filename_display_basename (filename);
+	/* Translators: %s is the name of the filename received */
+	notification_text = g_strdup_printf(_("You received \"%s\" via Bluetooth"), display);
+	g_free (display);
+	notification = notify_notification_new (_("You received a file"),
+								 notification_text,
+								 "dialog-information");
+
+	notify_notification_set_timeout (notification, NOTIFY_EXPIRES_DEFAULT);
+
+	mime_type = g_content_type_guess (filename, NULL, 0, NULL);
+	app = g_app_info_get_default_for_type (mime_type, FALSE);
+	if (app != NULL) {
+		g_object_unref (app);
+		notify_notification_add_action (notification, "display", _("Open File"),
+						(NotifyActionCallback) notification_launch_action_on_file_cb,
+						g_strdup (file_uri), (GFreeFunc) g_free);
+	}
+	notify_notification_add_action (notification, "reveal", _("Reveal File"),
+					(NotifyActionCallback) notification_launch_action_on_file_cb,
+					g_strdup (file_uri), (GFreeFunc) g_free);
+
+	g_free (file_uri);
+
+	g_signal_connect (G_OBJECT (notification), "closed", G_CALLBACK (on_close_notification), notification);
+
+	if (!notify_notification_show (notification, NULL)) {
+		g_warning ("failed to send notification\n");
+	}
+	g_free (notification_text);
+
+	/* Now we do the audio notification */
+	ctx = ca_gtk_context_get ();
+	ca_context_play (ctx, 0,
+			 CA_PROP_EVENT_ID, "complete-download",
+			 CA_PROP_EVENT_DESCRIPTION, _("File reception complete"),
+			 NULL);
+}
+
+static void
+show_icon (void)
+{
+	if (statusicon == NULL) {
+		statusicon = gtk_status_icon_new_from_icon_name ("mate-obex-server");
+	} else {
+		gtk_status_icon_set_visible (statusicon, TRUE);
+	}
+	num_notifications++;
+}
+
+static gboolean
+device_is_authorised (const char *bdaddr)
+{
+	DBusGConnection *connection;<--- Shadow variable
+	DBusGProxy *manager;
+	GError *error = NULL;
+	GPtrArray *adapters;
+	gboolean retval = FALSE;
+	guint i;
+
+	connection = dbus_g_bus_get (DBUS_BUS_SYSTEM, NULL);
+	if (connection == NULL)
+		return FALSE;
+
+	manager = dbus_g_proxy_new_for_name (connection, "org.bluez",
+					     "/", "org.bluez.Manager");
+	if (manager == NULL) {
+		dbus_g_connection_unref (connection);
+		return FALSE;
+	}
+
+	if (dbus_g_proxy_call (manager, "ListAdapters", &error, G_TYPE_INVALID, dbus_g_type_get_collection ("GPtrArray", DBUS_TYPE_G_OBJECT_PATH), &adapters, G_TYPE_INVALID) == FALSE) {
+		g_object_unref (manager);
+		dbus_g_connection_unref (connection);
+		return FALSE;
+	}
+
+	for (i = 0; i < adapters->len; i++) {
+		DBusGProxy *adapter, *device;
+		char *device_path;
+		GHashTable *props;
+
+		g_debug ("checking adapter %s", (gchar *) g_ptr_array_index (adapters, i));
+
+		adapter = dbus_g_proxy_new_for_name (connection, "org.bluez",
+						    g_ptr_array_index (adapters, i), "org.bluez.Adapter");
+
+		if (dbus_g_proxy_call (adapter, "FindDevice", NULL,
+				       G_TYPE_STRING, bdaddr, G_TYPE_INVALID,
+				       DBUS_TYPE_G_OBJECT_PATH, &device_path, G_TYPE_INVALID) == FALSE)
+		{
+			g_object_unref (adapter);
+			continue;
+		}
+
+		device = dbus_g_proxy_new_for_name (connection, "org.bluez", device_path, "org.bluez.Device");
+
+		if (dbus_g_proxy_call (device, "GetProperties", NULL,
+				       G_TYPE_INVALID, dbus_g_type_get_map ("GHashTable", G_TYPE_STRING, G_TYPE_VALUE),
+				       &props, G_TYPE_INVALID) != FALSE)
+		{
+			GValue *value;
+			gboolean bonded;
+
+			value = g_hash_table_lookup (props, "Paired");
+			bonded = g_value_get_boolean (value);
+			g_message ("%s is %s", bdaddr, bonded ? "bonded" : "not bonded");
+
+			if (bonded) {
+				g_hash_table_destroy (props);
+				g_object_unref (device);
+				g_object_unref (adapter);
+				retval = TRUE;
+				break;
+			}
+		}
+		g_object_unref(adapter);
+	}
+
+	g_ptr_array_free (adapters, TRUE);
+
+	g_object_unref(manager);
+	dbus_g_connection_unref(connection);
+
+	return retval;
+}
+
+static void
+transfer_started_cb (DBusGProxy *session,
+		     const char *filename,
+		     const char *local_path,
+		     guint64 size,
+		     gpointer user_data)
+{
+	GHashTable *dict;
+	DBusGProxy *server = (DBusGProxy *) user_data;
+	GError *error = NULL;
+	gboolean authorise;
+
+	g_message ("transfer started on %s", local_path);
+	g_object_set_data_full (G_OBJECT (session), "filename", g_strdup (local_path), (GDestroyNotify) g_free);
+
+	show_icon ();
+
+	/* First transfer of the session */
+	if (g_object_get_data (G_OBJECT (session), "bdaddr") == NULL) {
+		const char *bdaddr;
+
+		if (dbus_g_proxy_call (server, "GetServerSessionInfo", &error,
+				       DBUS_TYPE_G_OBJECT_PATH, dbus_g_proxy_get_path (session), G_TYPE_INVALID,
+				       DBUS_TYPE_G_STRING_VARIANT_HASHTABLE, &dict, G_TYPE_INVALID) == FALSE) {
+			g_printerr ("Getting Server session info failed: %s\n",
+				    error->message);
+			g_error_free (error);
+			return;
+		}
+
+		bdaddr = g_hash_table_lookup (dict, "BluetoothAddress");
+		g_message ("transfer started for device %s", bdaddr);
+
+		g_object_set_data_full (G_OBJECT (session), "bdaddr", g_strdup (bdaddr), (GDestroyNotify) g_free);
+		/* Initial accept method is undefined, we do that lower down */
+		g_object_set_data (G_OBJECT (session), "accept-method", GINT_TO_POINTER (-1));
+		g_hash_table_destroy (dict);
+	}
+
+	/* Accept method changed */
+	if (GPOINTER_TO_INT (g_object_get_data (G_OBJECT (session), "accept-method")) != accept_setting) {
+		const char *bdaddr;
+
+		bdaddr = g_object_get_data (G_OBJECT (session), "bdaddr");
+
+		if (bdaddr == NULL) {
+			g_warning ("Couldn't get the Bluetooth address for the device, rejecting the transfer");
+			authorise = FALSE;
+		} else if (accept_setting == ACCEPT_ALWAYS) {
+			authorise = TRUE;
+		} else if (accept_setting == ACCEPT_BONDED) {
+			authorise = device_is_authorised (bdaddr);
+		} else {
+			//FIXME implement
+			g_warning ("\"Ask\" authorisation method not implemented");
+			authorise = FALSE;
+		}
+		g_object_set_data (G_OBJECT (session), "authorise", GINT_TO_POINTER (authorise));
+	}
+
+	g_message ("accept_setting: %d", accept_setting);
+
+	authorise = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (session), "authorise"));
+	if (authorise != FALSE) {
+		if (dbus_g_proxy_call (session, "Accept", &error, G_TYPE_INVALID, G_TYPE_INVALID) == FALSE) {
+			g_printerr ("Failed to accept file transfer: %s\n", error->message);
+			g_error_free (error);
+			return;
+		}
+		g_message ("authorised transfer");
+	} else {
+		if (dbus_g_proxy_call (session, "Reject", &error, G_TYPE_INVALID, G_TYPE_INVALID) == FALSE) {
+			g_printerr ("Failed to reject file transfer: %s\n", error->message);
+			g_error_free (error);
+			return;
+		}
+		g_message ("rejected transfer");
+		g_object_set_data (G_OBJECT (session), "filename", NULL);
+	}
+}
+
+static void
+transfer_completed_cb (DBusGProxy *session,
+		       gpointer user_data)
+{
+	GSettings *settings;
+	gboolean display_notify;
+	const char *filename;
+
+	filename = (const char *) g_object_get_data (G_OBJECT (session), "filename");
+
+	g_message ("file finish transfer: %s", filename);
+
+	if (filename == NULL)
+		return;
+
+	settings = g_settings_new (GSETTINGS_SCHEMA);
+	display_notify = g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_OBEXPUSH_NOTIFY);
+	g_object_unref (settings);
+
+	if (display_notify) {
+		show_notification (filename);
+	} else {
+		hide_statusicon ();
+	}
+	g_object_set_data (G_OBJECT (session), "filename", NULL);
+}
+
+static void
+cancelled_cb (DBusGProxy *session,
+	      gpointer user_data)
+{
+	//FIXME implement properly, we never actually finished the transfer
+	g_message ("transfered was cancelled by the sender");
+	transfer_completed_cb (session, user_data);
+	hide_statusicon ();
+}
+
+static void
+error_occurred_cb (DBusGProxy *session,
+		   const char *error_name,
+		   const char *error_message,
+		   gpointer user_data)
+{
+	//FIXME implement properly
+	g_message ("transfer error occurred: %s", error_message);
+	transfer_completed_cb (session, user_data);
+}
+
+static void
+session_created_cb (DBusGProxy *server, const char *session_path, gpointer user_data)
+{
+	DBusGProxy *session;
+
+	session = dbus_g_proxy_new_for_name (connection,
+					     "org.openobex",
+					     session_path,
+					     "org.openobex.ServerSession");
+
+	dbus_g_proxy_add_signal (session, "TransferStarted",
+				 G_TYPE_STRING, G_TYPE_STRING, G_TYPE_UINT64, G_TYPE_INVALID);
+	dbus_g_proxy_connect_signal(session, "TransferStarted",
+				    G_CALLBACK (transfer_started_cb), server, NULL);
+	dbus_g_proxy_add_signal (session, "TransferCompleted",
+				 G_TYPE_INVALID, G_TYPE_INVALID);
+	dbus_g_proxy_connect_signal(session, "TransferCompleted",
+				    G_CALLBACK (transfer_completed_cb), server, NULL);
+	dbus_g_proxy_add_signal (session, "Cancelled",
+				 G_TYPE_INVALID, G_TYPE_INVALID);
+	dbus_g_proxy_connect_signal(session, "Cancelled",
+				    G_CALLBACK (cancelled_cb), server, NULL);
+	dbus_g_proxy_add_signal (session, "ErrorOccurred",
+				 G_TYPE_INVALID, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INVALID);
+	dbus_g_proxy_connect_signal(session, "ErrorOccurred",
+				    G_CALLBACK (error_occurred_cb), server, NULL);
+}
+
+void
+obexpush_up (void)
+{
+	GError *err = NULL;
+	char *download_dir, *server;
+
+	server = NULL;
+	if (manager_proxy == NULL) {
+		manager_proxy = dbus_g_proxy_new_for_name (connection,
+							   "org.openobex",
+							   "/org/openobex",
+							   "org.openobex.Manager");
+		if (dbus_g_proxy_call (manager_proxy, "CreateBluetoothServer",
+				       &err, G_TYPE_STRING, "00:00:00:00:00:00", G_TYPE_STRING, "opp", G_TYPE_BOOLEAN, FALSE, G_TYPE_INVALID,
+				       DBUS_TYPE_G_OBJECT_PATH, &server, G_TYPE_INVALID) == FALSE) {
+			g_printerr ("Creating Bluetooth ObexPush server failed: %s\n",
+				    err->message);
+			g_error_free (err);
+			g_object_unref (manager_proxy);
+			manager_proxy = NULL;
+			return;
+		}
+	}
+
+	download_dir = lookup_download_dir ();
+
+	if (server_proxy == NULL) {
+		server_proxy = dbus_g_proxy_new_for_name (connection,
+							   "org.openobex",
+							   server,
+							   "org.openobex.Server");
+		g_free (server);
+
+		dbus_g_proxy_add_signal (server_proxy, "SessionCreated",
+					 DBUS_TYPE_G_OBJECT_PATH, G_TYPE_INVALID);
+		dbus_g_proxy_connect_signal(server_proxy, "SessionCreated",
+					    G_CALLBACK (session_created_cb), NULL, NULL);
+	}
+
+	if (dbus_g_proxy_call (server_proxy, "Start", &err,
+			   G_TYPE_STRING, download_dir, G_TYPE_BOOLEAN, TRUE, G_TYPE_BOOLEAN, FALSE, G_TYPE_INVALID,
+			   G_TYPE_INVALID) == FALSE) {
+		if (g_error_matches (err, DBUS_GERROR, DBUS_GERROR_REMOTE_EXCEPTION) != FALSE &&
+		    dbus_g_error_has_name (err, "org.openobex.Error.Started") != FALSE) {
+		    	g_error_free (err);
+		    	g_message ("already started, ignoring error");
+		    	g_free (download_dir);
+		    	return;
+		}
+		g_printerr ("Starting Bluetooth ObexPush server failed: %s\n",
+			    err->message);
+		g_error_free (err);
+		g_free (download_dir);
+		g_object_unref (server_proxy);
+		server_proxy = NULL;
+		g_object_unref (manager_proxy);
+		manager_proxy = NULL;
+		return;
+	}
+
+	g_free (download_dir);
+}
+
+static void
+obexpush_stop (gboolean stop_manager)
+{
+	GError *err = NULL;
+
+	if (server_proxy == NULL)
+		return;
+
+	if (dbus_g_proxy_call (server_proxy, "Close", &err, G_TYPE_INVALID, G_TYPE_INVALID) == FALSE) {
+		if (g_error_matches (err, DBUS_GERROR, DBUS_GERROR_REMOTE_EXCEPTION) == FALSE ||
+		    dbus_g_error_has_name (err, "org.openobex.Error.NotStarted") == FALSE) {
+			g_printerr ("Stopping Bluetooth ObexPush server failed: %s\n",
+				    err->message);
+			g_error_free (err);
+			return;
+		}
+		g_error_free (err);
+	}
+
+	if (stop_manager != FALSE) {
+		g_object_unref (server_proxy);
+		server_proxy = NULL;
+		g_object_unref (manager_proxy);
+		manager_proxy = NULL;
+	}
+
+	//FIXME stop all the notifications
+}
+
+void
+obexpush_down (void)
+{
+	obexpush_stop (TRUE);
+}
+
+void
+obexpush_restart (void)
+{
+	obexpush_stop (FALSE);
+	obexpush_up ();
+}
+
+gboolean
+obexpush_init (void)
+{
+	GError *err = NULL;
+
+	connection = dbus_g_bus_get (DBUS_BUS_SESSION, &err);
+	if (connection == NULL) {
+		g_printerr ("Connecting to session bus failed: %s\n",
+			    err->message);
+		g_error_free (err);
+		return FALSE;
+	}
+
+	dbus_g_object_register_marshaller (marshal_VOID__STRING_STRING_UINT64,
+					   G_TYPE_NONE,
+					   G_TYPE_STRING, G_TYPE_STRING, G_TYPE_UINT64, G_TYPE_INVALID);
+
+	if (!notify_init("mate-user-share")) {
+		g_warning("Unable to initialize the notification system\n");
+        }
+
+	dbus_connection_set_exit_on_disconnect (dbus_g_connection_get_connection (connection), FALSE);
+
+	return TRUE;
+}
+
+void
+obexpush_set_accept_files_policy (AcceptSetting setting)
+{
+	accept_setting = setting;
+}
+
+void
+obexpush_set_notify (gboolean enabled)
+{
+	show_notifications = enabled;
+}
+
+
+
+
+ + + diff --git a/2020-07-31-224753-9107-cppcheck@3fd04c35acf7_master/3.html b/2020-07-31-224753-9107-cppcheck@3fd04c35acf7_master/3.html new file mode 100644 index 0000000..d1be6aa --- /dev/null +++ b/2020-07-31-224753-9107-cppcheck@3fd04c35acf7_master/3.html @@ -0,0 +1,764 @@ + + + + + + Cppcheck - HTML report - mate-user-share + + + + + + +
+ +
+
  1
+  2
+  3
+  4
+  5
+  6
+  7
+  8
+  9
+ 10
+ 11
+ 12
+ 13
+ 14
+ 15
+ 16
+ 17
+ 18
+ 19
+ 20
+ 21
+ 22
+ 23
+ 24
+ 25
+ 26
+ 27
+ 28
+ 29
+ 30
+ 31
+ 32
+ 33
+ 34
+ 35
+ 36
+ 37
+ 38
+ 39
+ 40
+ 41
+ 42
+ 43
+ 44
+ 45
+ 46
+ 47
+ 48
+ 49
+ 50
+ 51
+ 52
+ 53
+ 54
+ 55
+ 56
+ 57
+ 58
+ 59
+ 60
+ 61
+ 62
+ 63
+ 64
+ 65
+ 66
+ 67
+ 68
+ 69
+ 70
+ 71
+ 72
+ 73
+ 74
+ 75
+ 76
+ 77
+ 78
+ 79
+ 80
+ 81
+ 82
+ 83
+ 84
+ 85
+ 86
+ 87
+ 88
+ 89
+ 90
+ 91
+ 92
+ 93
+ 94
+ 95
+ 96
+ 97
+ 98
+ 99
+100
+101
+102
+103
+104
+105
+106
+107
+108
+109
+110
+111
+112
+113
+114
+115
+116
+117
+118
+119
+120
+121
+122
+123
+124
+125
+126
+127
+128
+129
+130
+131
+132
+133
+134
+135
+136
+137
+138
+139
+140
+141
+142
+143
+144
+145
+146
+147
+148
+149
+150
+151
+152
+153
+154
+155
+156
+157
+158
+159
+160
+161
+162
+163
+164
+165
+166
+167
+168
+169
+170
+171
+172
+173
+174
+175
+176
+177
+178
+179
+180
+181
+182
+183
+184
+185
+186
+187
+188
+189
+190
+191
+192
+193
+194
+195
+196
+197
+198
+199
+200
+201
+202
+203
+204
+205
+206
+207
+208
+209
+210
+211
+212
+213
+214
+215
+216
+217
+218
+219
+220
+221
+222
+223
+224
+225
+226
+227
+228
+229
+230
+231
+232
+233
+234
+235
+236
+237
+238
+239
+240
+241
+242
+243
+244
+245
+246
+247
+248
+249
+250
+251
+252
+253
+254
+255
+256
+257
+258
+259
+260
+261
+262
+263
+264
+265
+266
+267
+268
+269
+270
+271
+272
+273
+274
+275
+276
+277
+278
+279
+280
+281
+282
+283
+284
+285
+286
+287
+288
+289
+290
+291
/* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 8; tab-width: 8 -*-
+ *
+ * Copyright (C) 2003 Novell, Inc.
+ * Copyright (C) 2003-2004 Red Hat, Inc.
+ * Copyright (C) 2005 William Jon McCann <mccann@jhu.edu>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * 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 Foundation, Inc., 51 Franklin St, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ *
+ */
+
+#include "config.h"
+
+#include <stdlib.h>
+#include <string.h>
+#include <glib/gi18n-lib.h>
+#include <gtk/gtk.h>
+#include <libcaja-extension/caja-menu-provider.h>
+#include <libcaja-extension/caja-location-widget-provider.h>
+
+#ifdef HAVE_BLUETOOTH
+#include <bluetooth-client.h>
+#endif
+
+#include "caja-share-bar.h"
+#include "user_share-common.h"
+
+#define CAJA_TYPE_USER_SHARE  (caja_user_share_get_type ())
+#define CAJA_USER_SHARE(o)    (G_TYPE_CHECK_INSTANCE_CAST ((o), CAJA_TYPE_USER_SHARE, CajaUserShare))
+#define CAJA_IS_USER_SHARE(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), CAJA_TYPE_USER_SHARE))
+
+typedef struct
+{
+        GObject              parent_slot;
+} CajaUserShare;
+
+typedef struct
+{
+        GObjectClass parent_slot;
+} CajaUserShareClass;
+
+static GType caja_user_share_get_type      (void);
+static void  caja_user_share_register_type (GTypeModule *module);
+
+static void
+launch_process (char **argv, GtkWindow *parent)
+{
+        GError *error;
+        GtkWidget *dialog;
+
+        error = NULL;
+        if (!g_spawn_async (NULL,
+                            argv, NULL,
+                            0,
+                            NULL, NULL,
+                            NULL,
+                            &error)) {
+
+
+                dialog = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL, GTK_MESSAGE_WARNING,
+						 GTK_BUTTONS_OK, _("Unable to launch the Personal File Sharing preferences"));
+
+                gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog), "%s", error->message);
+
+                gtk_dialog_run (GTK_DIALOG (dialog));
+                gtk_widget_destroy (dialog);
+
+                g_error_free (error);
+        }
+}
+
+static void
+launch_prefs_on_window (GtkWindow *window)
+{
+        char *argv [2];
+
+        argv [0] = g_build_filename (BINDIR, "mate-file-share-properties", NULL);
+        argv [1] = NULL;
+
+        launch_process (argv, window);
+
+        g_free (argv [0]);
+}
+
+static void
+bar_response_cb (CajaShareBar *bar,
+                 gint response,
+                 gpointer         data)
+{
+        if (response == CAJA_SHARE_BAR_RESPONSE_PREFERENCES) {
+                launch_prefs_on_window (GTK_WINDOW (data));
+        }
+}
+
+#ifdef HAVE_BLUETOOTH
+static void
+downloads_bar_set_from_bluetooth_status (GtkWidget *bar)
+{
+	BluetoothClient *client;
+	gboolean bt_powered;
+
+	client = g_object_get_data (G_OBJECT (bar), "bluetooth-client");
+	g_object_get (G_OBJECT (client),
+		      "default-adapter-powered", &bt_powered,
+		      NULL);
+	gtk_widget_set_visible (bar, bt_powered);
+}
+
+static void
+default_adapter_powered_cb (GObject    *gobject,
+			    GParamSpec *pspec,
+			    GtkWidget  *bar)
+{
+	downloads_bar_set_from_bluetooth_status (bar);
+}
+#endif /* HAVE_BLUETOOTH */
+
+static GtkWidget *
+caja_user_share_get_location_widget (CajaLocationWidgetProvider *iface,
+                                         const char                     *uri,
+                                         GtkWidget                      *window)
+{
+	GFile             *file;
+	GtkWidget         *bar;
+	guint              i;
+	gboolean           enable = FALSE;
+	GFile             *home;
+#ifdef HAVE_BLUETOOTH
+	const GUserDirectory special_dirs[] = { G_USER_DIRECTORY_PUBLIC_SHARE, G_USER_DIRECTORY_DOWNLOAD };
+
+	gboolean is_dir[] = { FALSE, FALSE };
+#else
+	const GUserDirectory special_dirs[] = { G_USER_DIRECTORY_PUBLIC_SHARE };
+
+	gboolean is_dir[] = { FALSE };
+#endif /* HAVE_BLUETOOTH */
+	file = g_file_new_for_uri (uri);
+	home = g_file_new_for_path (g_get_home_dir ());
+
+	/* We don't show anything in $HOME */
+	if (g_file_equal (home, file)) {
+		g_object_unref (home);
+		g_object_unref (file);
+		return NULL;
+	}
+
+	g_object_unref (home);
+
+	for (i = 0; i < G_N_ELEMENTS (special_dirs); i++) {
+		GFile *dir;
+		dir = lookup_dir_with_fallback (special_dirs[i]);
+		if (g_file_equal (dir, file)) {
+			enable = TRUE;
+			is_dir[i] = TRUE;
+		}
+		g_object_unref (dir);
+	}
+
+	g_object_unref (file);
+
+	if (enable == FALSE)
+		return NULL;
+
+	if (is_dir[0] != FALSE) {
+#ifdef HAVE_BLUETOOTH
+		if (is_dir[1] != FALSE) {
+			bar = caja_share_bar_new (_("May be used to share or receive files"));
+		} else {
+			bar = caja_share_bar_new (_("May be shared over the network or Bluetooth"));
+		}
+#else
+		bar = caja_share_bar_new (_("May be shared over the network"));
+#endif /* HAVE_BLUETOOTH */
+	} else {
+#ifdef HAVE_BLUETOOTH
+		BluetoothClient *client;
+
+		bar = caja_share_bar_new (_("May be used to receive files over Bluetooth"));
+
+		gtk_widget_set_no_show_all (bar, TRUE);
+		client = bluetooth_client_new ();
+		g_object_set_data_full (G_OBJECT (bar), "bluetooth-client", client, g_object_unref);
+		g_signal_connect (G_OBJECT (client), "notify::default-adapter-powered",
+				  G_CALLBACK (default_adapter_powered_cb), bar);
+		downloads_bar_set_from_bluetooth_status (bar);
+#endif /* HAVE_BLUETOOTH */
+	}
+
+	g_signal_connect (bar, "response",
+			  G_CALLBACK (bar_response_cb),
+			  window);
+
+	gtk_widget_show_all (bar);
+
+	return bar;
+}
+
+static void
+caja_user_share_location_widget_provider_iface_init (CajaLocationWidgetProviderIface *iface)
+{
+        iface->get_widget = caja_user_share_get_location_widget;
+}
+
+static void
+caja_user_share_instance_init (CajaUserShare *share)
+{
+
+}
+
+static void
+caja_user_share_class_init (CajaUserShareClass *klass)
+{
+
+}
+
+static GType share_type = 0;
+
+static GType
+caja_user_share_get_type (void)
+{
+        return share_type;
+}
+
+static void
+caja_user_share_register_type (GTypeModule *module)
+{
+        static const GTypeInfo info = {
+                sizeof (CajaUserShareClass),
+                (GBaseInitFunc) NULL,
+                (GBaseFinalizeFunc) NULL,
+                (GClassInitFunc) caja_user_share_class_init,
+                NULL,
+                NULL,
+                sizeof (CajaUserShare),
+                0,
+                (GInstanceInitFunc) caja_user_share_instance_init,
+        };
+
+        static const GInterfaceInfo location_widget_provider_iface_info = {
+                (GInterfaceInitFunc) caja_user_share_location_widget_provider_iface_init,
+                NULL,
+                NULL
+        };
+
+        share_type = g_type_module_register_type (module,
+                                                 G_TYPE_OBJECT,
+                                                 "CajaUserShare",
+                                                 &info, 0);
+
+        g_type_module_add_interface (module,
+                                     share_type,
+                                     CAJA_TYPE_LOCATION_WIDGET_PROVIDER,
+                                     &location_widget_provider_iface_info);
+}
+
+void
+caja_module_initialize (GTypeModule *module)
+{
+        caja_user_share_register_type (module);
+        bindtextdomain (GETTEXT_PACKAGE, MATELOCALEDIR);
+        bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
+}
+
+void
+caja_module_shutdown (void)
+{
+}
+
+void
+caja_module_list_types (const GType **types,
+                            int          *num_types)
+{
+        static GType type_list [1];
+
+        type_list[0] = CAJA_TYPE_USER_SHARE;
+
+        *types = type_list;
+        *num_types = 1;
+}
+
+
+
+
+ + + diff --git a/2020-07-31-224753-9107-cppcheck@3fd04c35acf7_master/4.html b/2020-07-31-224753-9107-cppcheck@3fd04c35acf7_master/4.html new file mode 100644 index 0000000..2a8fd9a --- /dev/null +++ b/2020-07-31-224753-9107-cppcheck@3fd04c35acf7_master/4.html @@ -0,0 +1,1182 @@ + + + + + + Cppcheck - HTML report - mate-user-share + + + + + + +
+ +
+
  1
+  2
+  3
+  4
+  5
+  6
+  7
+  8
+  9
+ 10
+ 11
+ 12
+ 13
+ 14
+ 15
+ 16
+ 17
+ 18
+ 19
+ 20
+ 21
+ 22
+ 23
+ 24
+ 25
+ 26
+ 27
+ 28
+ 29
+ 30
+ 31
+ 32
+ 33
+ 34
+ 35
+ 36
+ 37
+ 38
+ 39
+ 40
+ 41
+ 42
+ 43
+ 44
+ 45
+ 46
+ 47
+ 48
+ 49
+ 50
+ 51
+ 52
+ 53
+ 54
+ 55
+ 56
+ 57
+ 58
+ 59
+ 60
+ 61
+ 62
+ 63
+ 64
+ 65
+ 66
+ 67
+ 68
+ 69
+ 70
+ 71
+ 72
+ 73
+ 74
+ 75
+ 76
+ 77
+ 78
+ 79
+ 80
+ 81
+ 82
+ 83
+ 84
+ 85
+ 86
+ 87
+ 88
+ 89
+ 90
+ 91
+ 92
+ 93
+ 94
+ 95
+ 96
+ 97
+ 98
+ 99
+100
+101
+102
+103
+104
+105
+106
+107
+108
+109
+110
+111
+112
+113
+114
+115
+116
+117
+118
+119
+120
+121
+122
+123
+124
+125
+126
+127
+128
+129
+130
+131
+132
+133
+134
+135
+136
+137
+138
+139
+140
+141
+142
+143
+144
+145
+146
+147
+148
+149
+150
+151
+152
+153
+154
+155
+156
+157
+158
+159
+160
+161
+162
+163
+164
+165
+166
+167
+168
+169
+170
+171
+172
+173
+174
+175
+176
+177
+178
+179
+180
+181
+182
+183
+184
+185
+186
+187
+188
+189
+190
+191
+192
+193
+194
+195
+196
+197
+198
+199
+200
+201
+202
+203
+204
+205
+206
+207
+208
+209
+210
+211
+212
+213
+214
+215
+216
+217
+218
+219
+220
+221
+222
+223
+224
+225
+226
+227
+228
+229
+230
+231
+232
+233
+234
+235
+236
+237
+238
+239
+240
+241
+242
+243
+244
+245
+246
+247
+248
+249
+250
+251
+252
+253
+254
+255
+256
+257
+258
+259
+260
+261
+262
+263
+264
+265
+266
+267
+268
+269
+270
+271
+272
+273
+274
+275
+276
+277
+278
+279
+280
+281
+282
+283
+284
+285
+286
+287
+288
+289
+290
+291
+292
+293
+294
+295
+296
+297
+298
+299
+300
+301
+302
+303
+304
+305
+306
+307
+308
+309
+310
+311
+312
+313
+314
+315
+316
+317
+318
+319
+320
+321
+322
+323
+324
+325
+326
+327
+328
+329
+330
+331
+332
+333
+334
+335
+336
+337
+338
+339
+340
+341
+342
+343
+344
+345
+346
+347
+348
+349
+350
+351
+352
+353
+354
+355
+356
+357
+358
+359
+360
+361
+362
+363
+364
+365
+366
+367
+368
+369
+370
+371
+372
+373
+374
+375
+376
+377
+378
+379
+380
+381
+382
+383
+384
+385
+386
+387
+388
+389
+390
+391
+392
+393
+394
+395
+396
+397
+398
+399
+400
+401
+402
+403
+404
+405
+406
+407
+408
+409
+410
+411
+412
+413
+414
+415
+416
+417
+418
+419
+420
+421
+422
+423
+424
+425
+426
+427
+428
+429
+430
+431
+432
+433
+434
+435
+436
+437
+438
+439
+440
+441
+442
+443
+444
+445
+446
+447
+448
+449
+450
+451
+452
+453
+454
+455
+456
+457
+458
+459
+460
+461
+462
+463
+464
+465
+466
+467
+468
+469
+470
+471
+472
+473
+474
+475
+476
+477
+478
+479
+480
+481
+482
+483
+484
+485
+486
+487
+488
+489
+490
+491
+492
+493
+494
+495
+496
+497
+498
+499
+500
+501
+502
+503
+504
+505
+506
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
+
+/*
+ *  Copyright (C) 2004-2008 Red Hat, Inc.
+ *
+ *  Caja is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU General Public License as
+ *  published by the Free Software Foundation; either version 2 of the
+ *  License, or (at your option) any later version.
+ *
+ *  Caja is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  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
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ *  Authors: Alexander Larsson <alexl@redhat.com>
+ *
+ */
+
+#include "config.h"
+
+#include <gdk/gdkx.h>
+#include <gtk/gtk.h>
+#include <glib/gi18n.h>
+#include <glib/gstdio.h>
+#include <gio/gio.h>
+#include <X11/Xlib.h>
+
+#include "user_share-private.h"
+#include "user_share-common.h"
+#include "http.h"
+
+#ifdef HAVE_BLUETOOTH
+#include <bluetooth-client.h>
+
+#include "obexftp.h"
+#include "obexpush.h"
+
+#endif /* HAVE_BLUETOOTH */
+
+#include <gio/gio.h>
+
+#include <stdarg.h>
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <signal.h>
+#include <unistd.h>
+
+static guint disabled_timeout_tag = 0;
+static GSettings* settings;<--- Shadowed declaration<--- Shadowed declaration<--- Shadowed declaration
+
+#define GSETTINGS_SCHEMA "org.mate.FileSharing"
+#define GSETTINGS_KEY_FILE_SHARING_ENABLED "enabled"
+#define GSETTINGS_KEY_FILE_SHARING_REQUIRE_PASSWORD "require-password"
+
+#ifdef HAVE_BLUETOOTH
+/* MATE Session */
+#define MATE_SESSION_DBUS_NAME      "org.gnome.SessionManager"
+#define MATE_SESSION_DBUS_OBJECT    "/org/gnome/SessionManager"
+#define MATE_SESSION_DBUS_INTERFACE "org.gnome.SessionManager"
+
+static GDBusProxy *session_proxy = NULL;
+static gboolean has_console = TRUE;
+
+static BluetoothClient *client = NULL;
+static gboolean bluetoothd_enabled = FALSE;
+
+#define OBEX_ENABLED (bluetoothd_enabled && has_console)
+
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_ENABLED "bluetooth-enabled"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_ALLOW_WRITE "bluetooth-allow-write"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_REQUIRE_PAIRING "bluetooth-require-pairing"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED "bluetooth-obexpush-enabled"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_ACCEPT_FILES "bluetooth-accept-files"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_NOTIFY "bluetooth-notify"
+
+
+static void
+obex_services_start (void)
+{
+	GSettings *settings;<--- Shadow variable
+
+	if (bluetoothd_enabled == FALSE ||
+	    has_console == FALSE)
+	    	return;
+
+	settings = g_settings_new(GSETTINGS_SCHEMA);
+
+	if (g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED) == TRUE) {
+	    obexpush_up ();
+	}
+	if (g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_ENABLED) == TRUE) {
+	    obexftp_up ();
+	}
+
+	g_object_unref (client);
+}
+
+static void
+obex_services_shutdown (void)
+{
+	obexpush_down ();
+	obexftp_down ();
+}
+
+static void
+session_properties_changed_cb (GDBusProxy      *session,
+			       GVariant        *changed,
+			       char           **invalidated,
+			       gpointer         user_data)
+{
+	GVariant *v;
+
+	v = g_variant_lookup_value (changed, "SessionIsActive", G_VARIANT_TYPE_BOOLEAN);
+	if (v) {
+		has_console = g_variant_get_boolean (v);
+		g_debug ("Received session is active change: now %s", has_console ? "active" : "inactive");
+
+		if (has_console)
+			obex_services_start ();
+		else
+			obex_services_shutdown ();
+
+		g_variant_unref (v);
+	}
+}
+
+static gboolean
+is_session_active (void)
+{
+	GVariant *variant;
+	gboolean is_session_active = FALSE;
+
+	variant = g_dbus_proxy_get_cached_property (session_proxy,
+						    "SessionIsActive");
+	if (variant) {
+		is_session_active = g_variant_get_boolean (variant);
+		g_variant_unref (variant);
+ 	}
+
+	return is_session_active;
+}
+
+static void
+session_init (void)
+{
+	GError *error = NULL;
+
+	session_proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION,
+						       G_DBUS_PROXY_FLAGS_NONE,
+						       NULL,
+						       MATE_SESSION_DBUS_NAME,
+						       MATE_SESSION_DBUS_OBJECT,
+						       MATE_SESSION_DBUS_INTERFACE,
+						       NULL,
+						       &error);
+	if (session_proxy == NULL) {
+		g_warning ("Failed to get session proxy: %s", error->message);
+		g_error_free (error);
+		return;
+	}
+	g_signal_connect (session_proxy, "g-properties-changed",
+			  G_CALLBACK (session_properties_changed_cb),
+			  NULL);
+	has_console = is_session_active ();
+}
+
+static void
+default_adapter_changed (GObject    *gobject,
+			 GParamSpec *pspec,
+			 gpointer    user_data)
+{
+	char *adapter;
+	gboolean adapter_powered;
+
+	g_object_get (G_OBJECT (client),
+		      "default-adapter", &adapter,
+		      "default-adapter-powered", &adapter_powered,
+		      NULL);
+	if (adapter != NULL && *adapter != '\0') {
+		bluetoothd_enabled = adapter_powered;
+	} else {
+		bluetoothd_enabled = FALSE;
+	}
+
+	/* Were we called as init, or as a callback */
+	if (gobject != NULL) {
+		if (bluetoothd_enabled != FALSE)
+			obex_services_start ();
+		else
+			obex_services_shutdown ();
+	}
+}
+
+static void
+bluez_init (void)
+{
+	client = bluetooth_client_new ();
+	default_adapter_changed (NULL, NULL, NULL);
+	g_signal_connect (G_OBJECT (client), "notify::default-adapter",
+			  G_CALLBACK (default_adapter_changed), NULL);
+	g_signal_connect (G_OBJECT (client), "notify::default-adapter-powered",
+			  G_CALLBACK (default_adapter_changed), NULL);
+}
+#endif /* HAVE_BLUETOOTH */
+
+static gboolean
+file_sharing_enabled (void)
+{
+	gboolean enabled = TRUE;
+	settings = g_settings_new (GSETTINGS_SCHEMA);
+
+#ifdef HAVE_BLUETOOTH
+	if (g_settings_get_boolean (settings, FILE_SHARING_ENABLED) == FALSE &&
+	    g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_ENABLED) == FALSE &&
+	    g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED) == FALSE)
+#else /* HAVE_BLUETOOTH */
+	if (g_settings_get_boolean (settings, FILE_SHARING_ENABLED) == FALSE)
+#endif /* HAVE_BLUETOOTH */
+		enabled = FALSE;
+
+	g_object_unref (settings);
+
+	return enabled;
+}
+
+static void
+migrate_old_configuration (void)
+{
+	const char *old_config_dir;
+	const char *new_config_dir;
+
+	old_config_dir = g_build_filename (g_get_home_dir (), ".mate2", "user-share", NULL);
+	new_config_dir = g_build_filename (g_get_user_config_dir (), "user-share", NULL);
+	if (g_file_test (old_config_dir, G_FILE_TEST_IS_DIR))
+		g_rename (old_config_dir, new_config_dir);
+
+}
+
+static void
+require_password_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	/* Need to restart to get new password setting */
+	if (http_get_pid () != 0) {
+		http_down ();
+		http_up ();
+	}
+}
+
+/* File sharing was disabled for some time, exit now */
+/* If we re-enable it in the ui, this will be restarted anyway */
+static gboolean
+disabled_timeout_callback (gpointer user_data)
+{
+	GSettings *settings = (GSettings *) user_data;<--- Shadow variable
+	http_down ();
+
+#ifdef HAVE_BLUETOOTH
+	if (g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_ENABLED) == FALSE &&
+	    g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED) == FALSE)
+		_exit (0);
+#else /* HAVE_BLUETOOTH */
+	if (g_settings_get_boolean (settings, FILE_SHARING_ENABLED) == FALSE)
+		_exit (0);
+#endif /* HAVE_BLUETOOTH */
+	return FALSE;
+}
+
+static void
+file_sharing_enabled_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	gboolean enabled;
+
+	if (disabled_timeout_tag != 0) {
+		g_source_remove (disabled_timeout_tag);
+		disabled_timeout_tag = 0;
+	}
+
+	enabled = g_settings_get_boolean (settings,
+					 FILE_SHARING_ENABLED);
+	if (enabled) {
+		if (http_get_pid () == 0) {
+			http_up ();
+		}
+	} else {
+		http_down ();
+		disabled_timeout_tag = g_timeout_add_seconds (3,
+							      (GSourceFunc)disabled_timeout_callback,
+							      settings);
+	}
+}
+
+#ifdef HAVE_BLUETOOTH
+static void
+file_sharing_bluetooth_allow_write_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	if (g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_ENABLED) != FALSE)
+		obexftp_restart ();
+}
+
+static void
+file_sharing_bluetooth_require_pairing_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	if (g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_ENABLED) != FALSE) {
+		/* We need to fully reset the session,
+		 * otherwise the new setting isn't taken into account */
+		obexftp_down ();
+		obexftp_up ();
+	}
+}
+
+static void
+file_sharing_bluetooth_enabled_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	if (g_settings_get_boolean (settings,
+				   FILE_SHARING_BLUETOOTH_ENABLED) == FALSE) {
+		obexftp_down ();
+		if (g_settings_get_boolean (settings, FILE_SHARING_ENABLED) == FALSE &&
+		    g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED) == FALSE) {
+			_exit (0);
+		}
+	} else if (OBEX_ENABLED) {
+		obexftp_up ();
+	}
+}
+
+static void
+file_sharing_bluetooth_obexpush_enabled_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	if (g_settings_get_boolean (settings,
+				   FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED) == FALSE) {
+		obexpush_down ();
+		if (g_settings_get_boolean (settings, FILE_SHARING_ENABLED) == FALSE &&
+		    g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_ENABLED) == FALSE) {
+			_exit (0);
+		}
+	} else if (OBEX_ENABLED) {
+		obexpush_up ();
+	}
+}
+
+static void
+file_sharing_bluetooth_obexpush_accept_files_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	AcceptSetting setting;
+	char *str;
+
+	str = g_settings_get_string (settings, FILE_SHARING_BLUETOOTH_OBEXPUSH_ACCEPT_FILES);
+	setting = accept_setting_from_string (str);
+	g_free (str);
+
+	obexpush_set_accept_files_policy (setting);
+}
+
+static void
+file_sharing_bluetooth_obexpush_notify_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	obexpush_set_notify (g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_OBEXPUSH_NOTIFY));
+}
+#endif /* HAVE_BLUETOOTH */
+
+static RETSIGTYPE
+cleanup_handler (int sig)
+{
+	http_down ();
+#ifdef HAVE_BLUETOOTH
+	obexftp_down ();
+	obexpush_down ();
+#endif /* HAVE_BLUETOOTH */
+	_exit (2);
+}
+
+static int
+x_io_error_handler (Display *xdisplay)
+{
+	http_down ();
+#ifdef HAVE_BLUETOOTH
+	obexftp_down ();
+#endif /* HAVE_BLUETOOTH */
+	_exit (2);
+}
+
+int
+main (int argc, char **argv)
+{
+	GSettings *settings;<--- Shadow variable
+	Display *xdisplay;
+	G_GNUC_UNUSED int x_fd;
+	Window selection_owner;
+	Atom xatom;
+
+	bindtextdomain (GETTEXT_PACKAGE, MATELOCALEDIR);
+	bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
+	textdomain (GETTEXT_PACKAGE);
+
+	gtk_init (&argc, &argv);
+
+	if (g_strcmp0 (g_get_real_name (), "root") == 0) {
+		g_warning ("mate-user-share cannot be started as root for security reasons.");
+		return 1;
+	}
+
+	signal (SIGPIPE, SIG_IGN);
+	signal (SIGINT, cleanup_handler);
+	signal (SIGHUP, cleanup_handler);
+	signal (SIGTERM, cleanup_handler);
+
+	xdisplay = GDK_DISPLAY_XDISPLAY (gdk_display_get_default ());
+	if (xdisplay == NULL) {
+		g_warning ("Can't open display");
+		return 1;
+	}
+
+	xatom = XInternAtom (xdisplay, "_MATE_USER_SHARE", FALSE);
+	selection_owner = XGetSelectionOwner (xdisplay, xatom);
+
+	if (selection_owner != None) {
+		/* There is an owner already, quit */
+		return 1;
+	}
+
+	selection_owner = XCreateSimpleWindow (xdisplay,
+					       RootWindow (xdisplay, 0),
+					       0, 0, 1, 1,
+					       0, 0, 0);
+	XSetSelectionOwner (xdisplay, xatom, selection_owner, CurrentTime);
+
+	if (XGetSelectionOwner (xdisplay, xatom) != selection_owner) {
+		/* Didn't get the selection */
+		return 1;
+	}
+
+	migrate_old_configuration ();
+
+	if (!file_sharing_enabled ())
+		return 1;
+
+	settings = g_settings_new (GSETTINGS_SCHEMA);
+
+	x_fd = ConnectionNumber (xdisplay);
+	XSetIOErrorHandler (x_io_error_handler);
+
+	if (http_init () == FALSE)
+		return 1;
+#ifdef HAVE_BLUETOOTH
+	if (obexftp_init () == FALSE)
+		return 1;
+	if (obexpush_init () == FALSE)
+		return 1;
+#endif /* HAVE_BLUETOOTH */
+
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_ENABLED,
+			     G_CALLBACK (file_sharing_enabled_changed), NULL);
+
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_REQUIRE_PASSWORD,
+			     G_CALLBACK (require_password_changed), NULL);
+
+#ifdef HAVE_BLUETOOTH
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_ENABLED,
+			     G_CALLBACK (file_sharing_bluetooth_enabled_changed), NULL);
+
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_ALLOW_WRITE,
+			     G_CALLBACK (file_sharing_bluetooth_allow_write_changed), NULL);
+
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_REQUIRE_PAIRING,
+			     G_CALLBACK (file_sharing_bluetooth_require_pairing_changed), NULL);
+
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED,
+			     G_CALLBACK (file_sharing_bluetooth_obexpush_enabled_changed), NULL);
+
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_ACCEPT_FILES,
+			     G_CALLBACK (file_sharing_bluetooth_obexpush_accept_files_changed), NULL);
+
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_NOTIFY,
+			     G_CALLBACK (file_sharing_bluetooth_obexpush_notify_changed), NULL);
+
+	bluez_init ();
+	session_init ();
+#endif /* HAVE_BLUETOOTH */
+
+	/* Initial setting */
+	file_sharing_enabled_changed (settings, NULL, NULL);
+#ifdef HAVE_BLUETOOTH
+	file_sharing_bluetooth_enabled_changed (settings, NULL, NULL);
+	file_sharing_bluetooth_obexpush_accept_files_changed (settings, NULL, NULL);
+	file_sharing_bluetooth_obexpush_notify_changed (settings, NULL, NULL);
+	file_sharing_bluetooth_obexpush_enabled_changed (settings, NULL, NULL);
+#endif /* HAVE_BLUETOOTH */
+
+	gtk_main ();
+
+	return 0;
+}
+
+
+
+
+ + + diff --git a/2020-07-31-224753-9107-cppcheck@3fd04c35acf7_master/index.html b/2020-07-31-224753-9107-cppcheck@3fd04c35acf7_master/index.html new file mode 100644 index 0000000..1170da5 --- /dev/null +++ b/2020-07-31-224753-9107-cppcheck@3fd04c35acf7_master/index.html @@ -0,0 +1,143 @@ + + + + + + Cppcheck - HTML report - mate-user-share + + + + + + +
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
LineIdCWESeverityMessage
missingIncludeinformationCppcheck cannot find all the include files (use --check-config for details)
src/file-share-properties.c
82variableScope398styleThe scope of the variable 'password' can be reduced.
97shadowVariable398styleLocal variable 'settings' shadows outer variable
105unusedVariable563styleUnused variable: accept_setting
249shadowVariable398styleLocal variable 'settings' shadows outer variable
273shadowVariable398styleLocal variable 'settings' shadows outer variable
294shadowVariable398styleLocal variable 'settings' shadows outer variable
323shadowVariable398styleLocal variable 'settings' shadows outer variable
340shadowVariable398styleLocal variable 'settings' shadows outer variable
357shadowVariable398styleLocal variable 'settings' shadows outer variable
377shadowVariable398styleLocal variable 'settings' shadows outer variable
393shadowVariable398styleLocal variable 'settings' shadows outer variable
457shadowVariable398styleLocal variable 'settings' shadows outer variable
620variableScope398styleThe scope of the variable 'window' can be reduced.
src/http.c
107nullPointerArithmeticRedundantCheck682warningEither the condition 'end!=NULL' is redundant or there is overflow in pointer subtraction.
114variableScope398styleThe scope of the variable 'host_name' can be reduced.
src/obexpush.c
187shadowVariable398styleLocal variable 'connection' shadows outer variable
src/share-extension.c
61variableScope398styleThe scope of the variable 'dialog' can be reduced.
src/user_share.c
86shadowVariable398styleLocal variable 'settings' shadows outer variable
260shadowVariable398styleLocal variable 'settings' shadows outer variable
391shadowVariable398styleLocal variable 'settings' shadows outer variable
+
+
+ + + diff --git a/2020-07-31-224753-9107-cppcheck@3fd04c35acf7_master/stats.html b/2020-07-31-224753-9107-cppcheck@3fd04c35acf7_master/stats.html new file mode 100644 index 0000000..0adff8f --- /dev/null +++ b/2020-07-31-224753-9107-cppcheck@3fd04c35acf7_master/stats.html @@ -0,0 +1,112 @@ + + + + + + Cppcheck - HTML report - mate-user-share + + + + + + +
+ +
+

Top 10 files for warning severity, total findings: 1
+   1  src/http.c
+

+

Top 10 files for style severity, total findings: 19
+   13  src/file-share-properties.c
+   3   src/user_share.c
+   1   src/share-extension.c
+   1   src/obexpush.c
+   1   src/http.c
+

+ +
+
+ + + diff --git a/2020-07-31-224753-9107-cppcheck@3fd04c35acf7_master/style.css b/2020-07-31-224753-9107-cppcheck@3fd04c35acf7_master/style.css new file mode 100644 index 0000000..07125f4 --- /dev/null +++ b/2020-07-31-224753-9107-cppcheck@3fd04c35acf7_master/style.css @@ -0,0 +1,137 @@ + +body { + font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif; + font-size: 13px; + line-height: 1.5; + margin: 0; + width: auto; +} + +h1 { + margin: 10px; +} + +.header { + border-bottom: thin solid #aaa; +} + +.footer { + border-top: thin solid #aaa; + font-size: 90%; + margin-top: 5px; +} + +.footer ul { + list-style-type: none; + padding-left: 0; +} + +.footer > p { + margin: 4px; +} + +.wrapper { + display: -webkit-box; + display: -ms-flexbox; + display: flex; + -webkit-box-pack: justify; + -ms-flex-pack: justify; + justify-content: space-between; +} + +#menu, +#menu_index { + text-align: left; + width: 350px; + height: 90vh; + min-height: 200px; + overflow: auto; + position: -webkit-sticky; + position: sticky; + top: 0; + padding: 0 15px 15px 15px; +} + +#menu > a { + display: block; + margin-left: 10px; + font-size: 12px; + z-index: 1; +} + +#content, +#content_index { + background-color: #fff; + -webkit-box-sizing: content-box; + -moz-box-sizing: content-box; + box-sizing: content-box; + padding: 0 15px 15px 15px; + width: calc(100% - 350px); + height: 100%; + overflow-x: auto; +} + +#filename { + margin-left: 10px; + font-size: 12px; + z-index: 1; +} + +.error { + background-color: #ffb7b7; +} + +.error2 { + background-color: #faa; + display: inline-block; + margin-left: 4px; +} + +.inconclusive { + background-color: #b6b6b4; +} + +.inconclusive2 { + background-color: #b6b6b4; + display: inline-block; + margin-left: 4px; +} + +.verbose { + display: inline-block; + vertical-align: top; + cursor: help; +} + +.verbose .content { + display: none; + position: absolute; + padding: 10px; + margin: 4px; + max-width: 40%; + white-space: pre-wrap; + border: 1px solid #000; + background-color: #ffffcc; + cursor: auto; +} + +.highlight .hll { + padding: 1px; +} + +.highlighttable { + background-color: #fff; + z-index: 10; + position: relative; + margin: -10px; +} + +.linenos { + border-right: thin solid #aaa; + color: #d3d3d3; + padding-right: 6px; +} + +.d-none { + display: none; +} diff --git a/2020-12-09-195411-4024-cppcheck@258a71f02483_master/0.html b/2020-12-09-195411-4024-cppcheck@258a71f02483_master/0.html new file mode 100644 index 0000000..5c4ead1 --- /dev/null +++ b/2020-12-09-195411-4024-cppcheck@258a71f02483_master/0.html @@ -0,0 +1,1498 @@ + + + + + + Cppcheck - HTML report - mate-user-share + + + + + + +
+ +
+
  1
+  2
+  3
+  4
+  5
+  6
+  7
+  8
+  9
+ 10
+ 11
+ 12
+ 13
+ 14
+ 15
+ 16
+ 17
+ 18
+ 19
+ 20
+ 21
+ 22
+ 23
+ 24
+ 25
+ 26
+ 27
+ 28
+ 29
+ 30
+ 31
+ 32
+ 33
+ 34
+ 35
+ 36
+ 37
+ 38
+ 39
+ 40
+ 41
+ 42
+ 43
+ 44
+ 45
+ 46
+ 47
+ 48
+ 49
+ 50
+ 51
+ 52
+ 53
+ 54
+ 55
+ 56
+ 57
+ 58
+ 59
+ 60
+ 61
+ 62
+ 63
+ 64
+ 65
+ 66
+ 67
+ 68
+ 69
+ 70
+ 71
+ 72
+ 73
+ 74
+ 75
+ 76
+ 77
+ 78
+ 79
+ 80
+ 81
+ 82
+ 83
+ 84
+ 85
+ 86
+ 87
+ 88
+ 89
+ 90
+ 91
+ 92
+ 93
+ 94
+ 95
+ 96
+ 97
+ 98
+ 99
+100
+101
+102
+103
+104
+105
+106
+107
+108
+109
+110
+111
+112
+113
+114
+115
+116
+117
+118
+119
+120
+121
+122
+123
+124
+125
+126
+127
+128
+129
+130
+131
+132
+133
+134
+135
+136
+137
+138
+139
+140
+141
+142
+143
+144
+145
+146
+147
+148
+149
+150
+151
+152
+153
+154
+155
+156
+157
+158
+159
+160
+161
+162
+163
+164
+165
+166
+167
+168
+169
+170
+171
+172
+173
+174
+175
+176
+177
+178
+179
+180
+181
+182
+183
+184
+185
+186
+187
+188
+189
+190
+191
+192
+193
+194
+195
+196
+197
+198
+199
+200
+201
+202
+203
+204
+205
+206
+207
+208
+209
+210
+211
+212
+213
+214
+215
+216
+217
+218
+219
+220
+221
+222
+223
+224
+225
+226
+227
+228
+229
+230
+231
+232
+233
+234
+235
+236
+237
+238
+239
+240
+241
+242
+243
+244
+245
+246
+247
+248
+249
+250
+251
+252
+253
+254
+255
+256
+257
+258
+259
+260
+261
+262
+263
+264
+265
+266
+267
+268
+269
+270
+271
+272
+273
+274
+275
+276
+277
+278
+279
+280
+281
+282
+283
+284
+285
+286
+287
+288
+289
+290
+291
+292
+293
+294
+295
+296
+297
+298
+299
+300
+301
+302
+303
+304
+305
+306
+307
+308
+309
+310
+311
+312
+313
+314
+315
+316
+317
+318
+319
+320
+321
+322
+323
+324
+325
+326
+327
+328
+329
+330
+331
+332
+333
+334
+335
+336
+337
+338
+339
+340
+341
+342
+343
+344
+345
+346
+347
+348
+349
+350
+351
+352
+353
+354
+355
+356
+357
+358
+359
+360
+361
+362
+363
+364
+365
+366
+367
+368
+369
+370
+371
+372
+373
+374
+375
+376
+377
+378
+379
+380
+381
+382
+383
+384
+385
+386
+387
+388
+389
+390
+391
+392
+393
+394
+395
+396
+397
+398
+399
+400
+401
+402
+403
+404
+405
+406
+407
+408
+409
+410
+411
+412
+413
+414
+415
+416
+417
+418
+419
+420
+421
+422
+423
+424
+425
+426
+427
+428
+429
+430
+431
+432
+433
+434
+435
+436
+437
+438
+439
+440
+441
+442
+443
+444
+445
+446
+447
+448
+449
+450
+451
+452
+453
+454
+455
+456
+457
+458
+459
+460
+461
+462
+463
+464
+465
+466
+467
+468
+469
+470
+471
+472
+473
+474
+475
+476
+477
+478
+479
+480
+481
+482
+483
+484
+485
+486
+487
+488
+489
+490
+491
+492
+493
+494
+495
+496
+497
+498
+499
+500
+501
+502
+503
+504
+505
+506
+507
+508
+509
+510
+511
+512
+513
+514
+515
+516
+517
+518
+519
+520
+521
+522
+523
+524
+525
+526
+527
+528
+529
+530
+531
+532
+533
+534
+535
+536
+537
+538
+539
+540
+541
+542
+543
+544
+545
+546
+547
+548
+549
+550
+551
+552
+553
+554
+555
+556
+557
+558
+559
+560
+561
+562
+563
+564
+565
+566
+567
+568
+569
+570
+571
+572
+573
+574
+575
+576
+577
+578
+579
+580
+581
+582
+583
+584
+585
+586
+587
+588
+589
+590
+591
+592
+593
+594
+595
+596
+597
+598
+599
+600
+601
+602
+603
+604
+605
+606
+607
+608
+609
+610
+611
+612
+613
+614
+615
+616
+617
+618
+619
+620
+621
+622
+623
+624
+625
+626
+627
+628
+629
+630
+631
+632
+633
+634
+635
+636
+637
+638
+639
+640
+641
+642
+643
+644
+645
+646
+647
+648
+649
+650
+651
+652
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
+
+/*
+ *  Copyright (C) 2004 Red Hat, Inc.
+ *
+ *  Caja is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU General Public License as
+ *  published by the Free Software Foundation; either version 2 of the
+ *  License, or (at your option) any later version.
+ *
+ *  Caja is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  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
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ *  Authors: Alexander Larsson <alexl@redhat.com>
+ *
+ */
+
+#include "config.h"
+
+#include <string.h>
+#include <stdio.h>
+
+#include <gtk/gtk.h>
+#include <glib/gi18n.h>
+#include <gio/gio.h>
+
+#include "user_share-private.h"
+
+#define REALM "Please log in as the user guest"
+#define USER "guest"
+#define GSETTINGS_SCHEMA "org.mate.FileSharing"
+#define GSETTINGS_KEY_FILE_SHARING_ENABLED "enabled"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_ENABLED "bluetooth-enabled"
+#define GSETTINGS_KEY_FILE_SHARING_REQUIRE_PASSWORD "require-password"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_ALLOW_WRITE "bluetooth-allow-write"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_REQUIRE_PAIRING "bluetooth-require-pairing"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED "bluetooth-obexpush-enabled"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_ACCEPT_FILES "bluetooth-accept-files"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_NOTIFY "bluetooth-notify"
+
+static GtkBuilder* builder;
+static GSettings* settings;<--- Shadowed declaration<--- Shadowed declaration<--- Shadowed declaration<--- Shadowed declaration<--- Shadowed declaration<--- Shadowed declaration<--- Shadowed declaration<--- Shadowed declaration<--- Shadowed declaration<--- Shadowed declaration
+
+
+static void
+write_out_password (const char *password)
+{
+    char *to_hash;
+    char *ascii_digest;
+    char *line;
+    char *filename;
+    FILE *file;
+
+    to_hash = g_strdup_printf ("%s:%s:%s", USER, REALM, password);
+    ascii_digest = g_compute_checksum_for_string (G_CHECKSUM_MD5, to_hash, strlen (to_hash));
+    g_free (to_hash);
+    line = g_strdup_printf ("%s:%s:%s\n", USER, REALM, ascii_digest);
+    g_free (ascii_digest);
+
+    filename = g_build_filename (g_get_user_config_dir (), "user-share", "passwd", NULL);
+
+    file = fopen (filename, "w");
+    if (file != NULL) {
+	fwrite (line, strlen (line), 1, file);
+	fclose (file);
+    }
+
+    g_free (filename);
+    g_free (line);
+}
+
+static void
+flush_password (void)
+{
+    GtkWidget *password_entry;
+    const char *password;
+
+    password_entry = GTK_WIDGET (gtk_builder_get_object (builder, "password_entry"));
+
+    if (g_object_get_data (G_OBJECT( password_entry), "user_edited")) {
+	password = gtk_entry_get_text (GTK_ENTRY (password_entry));
+	if (password != NULL && password[0] != 0)
+	    write_out_password (password);
+    }
+}
+
+
+static void
+update_ui (void)
+{
+    GSettings *settings;<--- Shadow variable
+    gboolean enabled;
+#ifdef HAVE_BLUETOOTH
+    gboolean bluetooth_enabled, bluetooth_write_enabled, require_pairing_enabled;
+    gboolean bluetooth_obexpush_enabled, bluetooth_obexpush_notify;
+#endif /* HAVE_BLUETOOTH */
+    char *str;
+    PasswordSetting password_setting;
+    AcceptSetting accept_setting;<--- Unused variable: accept_setting
+    GtkWidget *check;
+    GtkWidget *password_combo;
+    GtkWidget *password_entry;
+#ifdef HAVE_BLUETOOTH
+    GtkWidget *vbox_share_bluetooth;
+    GtkWidget *vbox_receive_bluetooth;
+    GtkWidget *bluetooth_check;
+    GtkWidget *allow_write_bluetooth_check;
+    GtkWidget *require_pairing_check;
+    GtkWidget *enable_obexpush_check;
+    GtkWidget *accept_obexpush_combo;
+    GtkWidget *notify_received_obexpush_check;
+#endif /* HAVE_BLUETOOTH */
+
+    settings = g_settings_new (GSETTINGS_SCHEMA);
+
+    enabled = g_settings_get_boolean (settings,
+				     FILE_SHARING_ENABLED);
+
+    str = g_settings_get_string (settings, FILE_SHARING_REQUIRE_PASSWORD);
+    password_setting = password_setting_from_string (str);
+    g_free (str);
+
+#ifdef HAVE_BLUETOOTH
+    bluetooth_enabled = g_settings_get_boolean (settings,
+    					       FILE_SHARING_BLUETOOTH_ENABLED);
+    bluetooth_write_enabled = g_settings_get_boolean (settings,
+						     FILE_SHARING_BLUETOOTH_ALLOW_WRITE);
+    require_pairing_enabled = g_settings_get_boolean (settings,
+    						     FILE_SHARING_BLUETOOTH_REQUIRE_PAIRING);
+    bluetooth_obexpush_enabled = g_settings_get_boolean (settings,
+    							FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED);
+    bluetooth_obexpush_notify = g_settings_get_boolean (settings,
+    						       FILE_SHARING_BLUETOOTH_OBEXPUSH_NOTIFY);
+
+    str = g_settings_get_string (settings, FILE_SHARING_BLUETOOTH_OBEXPUSH_ACCEPT_FILES);
+    accept_setting = accept_setting_from_string (str);
+    g_free (str);
+#endif /* HAVE_BLUETOOTH */
+
+    check = GTK_WIDGET (gtk_builder_get_object (builder, "enable_check"));
+    password_combo = GTK_WIDGET (gtk_builder_get_object (builder, "password_combo"));
+    password_entry = GTK_WIDGET (gtk_builder_get_object (builder, "password_entry"));
+#ifdef HAVE_BLUETOOTH
+    vbox_share_bluetooth = GTK_WIDGET (gtk_builder_get_object (builder, "vbox_share_bluetooth"));
+    vbox_receive_bluetooth = GTK_WIDGET (gtk_builder_get_object (builder, "vbox_receive_bluetooth"));
+    bluetooth_check = GTK_WIDGET (gtk_builder_get_object (builder, "enable_bluetooth_check"));
+    allow_write_bluetooth_check = GTK_WIDGET (gtk_builder_get_object (builder, "allow_write_bluetooth_check"));
+    require_pairing_check = GTK_WIDGET (gtk_builder_get_object (builder, "require_pairing_check"));
+    enable_obexpush_check = GTK_WIDGET (gtk_builder_get_object (builder, "enable_obexpush_check"));
+    accept_obexpush_combo = GTK_WIDGET (gtk_builder_get_object (builder, "accept_obexpush_combo"));
+    notify_received_obexpush_check = GTK_WIDGET (gtk_builder_get_object (builder, "notify_received_obexpush_check"));
+#endif /* HAVE_BLUETOOTH */
+
+    /* Network */
+    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (check), enabled);
+    gtk_widget_set_sensitive (password_combo, enabled);
+    gtk_widget_set_sensitive (password_entry, enabled && password_setting != PASSWORD_NEVER);
+
+    gtk_combo_box_set_active (GTK_COMBO_BOX (password_combo),
+			      password_setting);
+
+#ifdef HAVE_BLUETOOTH
+    /* Bluetooth ObexFTP */
+    gtk_widget_set_visible (vbox_share_bluetooth, TRUE);
+    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (bluetooth_check), bluetooth_enabled);
+    gtk_widget_set_sensitive (allow_write_bluetooth_check, bluetooth_enabled);
+    gtk_widget_set_sensitive (require_pairing_check, bluetooth_enabled);
+
+    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (allow_write_bluetooth_check),
+    				  bluetooth_write_enabled);
+    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (require_pairing_check),
+    				  require_pairing_enabled);
+
+    /* Bluetooth ObexPush */
+    gtk_widget_set_visible (vbox_receive_bluetooth, TRUE);
+    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (enable_obexpush_check), bluetooth_obexpush_enabled);
+    gtk_widget_set_sensitive (accept_obexpush_combo, bluetooth_obexpush_enabled);
+    gtk_widget_set_sensitive (notify_received_obexpush_check, bluetooth_obexpush_enabled);
+
+    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (notify_received_obexpush_check),
+    				  bluetooth_obexpush_notify);
+
+    gtk_combo_box_set_active (GTK_COMBO_BOX (accept_obexpush_combo),
+    			      accept_setting);
+#endif /* HAVE_BLUETOOTH */
+
+    g_object_unref (settings);
+}
+
+static void
+file_sharing_enabled_changed (GSettings *settings, gchar *key, gpointer data)
+{
+    update_ui ();
+}
+
+static void
+password_required_changed (GSettings *settings, gchar *key, gpointer data)
+{
+    update_ui ();
+}
+
+#ifdef HAVE_BLUETOOTH
+static void
+file_sharing_bluetooth_enabled_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	update_ui ();
+}
+
+static void
+file_sharing_bluetooth_allow_write_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	update_ui ();
+}
+
+static void
+file_sharing_bluetooth_require_pairing_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	update_ui ();
+}
+
+static void
+file_sharing_bluetooth_obexpush_enabled_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	update_ui ();
+}
+
+static void
+file_sharing_bluetooth_obexpush_accept_files_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	update_ui ();
+}
+
+static void
+file_sharing_bluetooth_obexpush_notify_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	update_ui ();
+}
+#endif /* HAVE_BLUETOOTH */
+
+static void
+password_combo_changed (GtkComboBox *combo_box)
+{
+    GSettings *settings;<--- Shadow variable
+    guint setting;
+
+    setting = gtk_combo_box_get_active (combo_box);
+
+    settings = g_settings_new (GSETTINGS_SCHEMA) ;
+
+    g_settings_set_string (settings,
+			     FILE_SHARING_REQUIRE_PASSWORD,
+			     password_string_from_setting (setting));
+    g_object_unref (settings);
+}
+
+static void
+launch_share (void)
+{
+	if (!g_spawn_command_line_async (USER_SHARE_PROGRAM, NULL))
+		g_warning ("Unable to start mate-user-share program");
+}
+
+#ifdef HAVE_BLUETOOTH
+static void
+enable_bluetooth_check_toggled (GtkWidget *check)
+{
+	GSettings *settings;<--- Shadow variable
+	gboolean enabled;
+
+	enabled = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check));
+
+	settings = g_settings_new (GSETTINGS_SCHEMA) ;
+
+	g_settings_set_boolean (settings,
+			       FILE_SHARING_BLUETOOTH_ENABLED,
+			       enabled);
+
+	g_object_unref (settings);
+
+	if (enabled != FALSE)
+		launch_share ();
+}
+#endif /* HAVE_BLUETOOTH */
+
+static void
+enable_check_toggled (GtkWidget *check)
+{
+	GSettings *settings;<--- Shadow variable
+	gboolean enabled;
+
+	enabled = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check));
+
+	settings = g_settings_new (GSETTINGS_SCHEMA);
+
+	g_settings_set_boolean (settings,
+			       FILE_SHARING_ENABLED,
+			       enabled);
+
+	g_object_unref (settings);
+
+	if (enabled != FALSE)
+		launch_share ();
+}
+
+static void
+password_entry_changed (GtkEditable *editable)
+{
+	g_object_set_data (G_OBJECT (editable),
+			   "user_edited", GINT_TO_POINTER (1));
+	flush_password ();
+}
+
+#ifdef HAVE_BLUETOOTH
+static void
+bluetooth_allow_write_check_toggled (GtkWidget *check)
+{
+	GSettings *settings;<--- Shadow variable
+	gboolean enabled;
+
+	enabled = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check));
+
+	settings = g_settings_new (GSETTINGS_SCHEMA) ;
+
+	g_settings_set_boolean (settings,
+			       FILE_SHARING_BLUETOOTH_ALLOW_WRITE,
+			       enabled);
+
+	g_object_unref (settings);
+}
+
+static void
+bluetooth_require_pairing_check_toggled (GtkWidget *check)
+{
+	GSettings *settings;<--- Shadow variable
+	gboolean enabled;
+
+	enabled = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check));
+
+	settings = g_settings_new (GSETTINGS_SCHEMA) ;
+
+	g_settings_set_boolean (settings,
+			       FILE_SHARING_BLUETOOTH_REQUIRE_PAIRING,
+			       enabled);
+
+	g_object_unref (settings);
+}
+
+static void
+enable_obexpush_check_toggled (GtkWidget *check)
+{
+	GSettings *settings;<--- Shadow variable
+	gboolean enabled;
+
+	enabled = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check));
+
+	settings = g_settings_new (GSETTINGS_SCHEMA) ;
+
+	g_settings_set_boolean (settings,
+			       FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED,
+			       enabled);
+
+	g_object_unref (settings);
+
+	if (enabled != FALSE)
+		launch_share ();
+}
+
+static void
+accept_obexpush_combo_changed (GtkComboBox *combo_box)
+{
+    GSettings *settings;<--- Shadow variable
+    guint setting;
+
+    setting = gtk_combo_box_get_active (combo_box);
+
+    settings = g_settings_new (GSETTINGS_SCHEMA) ;
+
+    g_settings_set_string (settings,
+			     FILE_SHARING_BLUETOOTH_OBEXPUSH_ACCEPT_FILES,
+			     accept_string_from_setting (setting));
+    g_object_unref (settings);
+}
+
+static void
+notify_received_obexpush_check_toggled (GtkWidget *check)
+{
+	GSettings *settings;<--- Shadow variable
+	gboolean enabled;
+
+	enabled = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check));
+
+	settings = g_settings_new (GSETTINGS_SCHEMA) ;
+
+	g_settings_set_boolean (settings,
+			       FILE_SHARING_BLUETOOTH_OBEXPUSH_NOTIFY,
+			       enabled);
+
+	g_object_unref (settings);
+}
+#endif /* HAVE_BLUETOOTH */
+
+static GtkWidget *
+error_dialog (const char *title,
+	      const char *reason,
+	      GtkWindow *parent)
+{
+	GtkWidget *error_dialog;
+
+	if (reason == NULL)
+		reason = _("No reason");
+
+	error_dialog =
+		gtk_message_dialog_new (parent,
+					GTK_DIALOG_MODAL,
+					GTK_MESSAGE_ERROR,
+					GTK_BUTTONS_OK,
+					"%s", title);
+	gtk_message_dialog_format_secondary_text
+		(GTK_MESSAGE_DIALOG (error_dialog), "%s", reason);
+
+	gtk_window_set_title (GTK_WINDOW (error_dialog), ""); /* as per HIG */
+	gtk_container_set_border_width (GTK_CONTAINER (error_dialog), 5);
+	gtk_dialog_set_default_response (GTK_DIALOG (error_dialog),
+					 GTK_RESPONSE_OK);
+	gtk_window_set_modal (GTK_WINDOW (error_dialog), TRUE);
+
+	return error_dialog;
+}
+
+static void
+help_button_clicked (GtkButton *button, GtkWidget *window)
+{
+	GError *error = NULL;
+
+	if (gtk_show_uri_on_window (GTK_WINDOW (window), "help:mate-user-share", gtk_get_current_event_time (), &error) == FALSE) {
+		GtkWidget *dialog;
+
+		dialog = error_dialog (_("Could not display the help contents."), error->message, GTK_WINDOW (window));
+		g_signal_connect (G_OBJECT (dialog), "response", G_CALLBACK
+				  (gtk_widget_destroy), error_dialog);
+		gtk_window_present (GTK_WINDOW (dialog));
+
+		g_error_free (error);
+	}
+}
+
+static GtkWidget *
+create_window (void)
+{
+    GError *error = NULL;
+    GSettings *settings;<--- Shadow variable
+    GtkWidget *check;
+    GtkWidget *password_combo;
+    GtkWidget *password_entry;
+#ifdef HAVE_BLUETOOTH
+    GtkWidget *bluetooth_check;
+    GtkWidget *bluetooth_allow_write_check;
+    GtkWidget *require_pairing_check;
+    GtkWidget *enable_obexpush_check;
+    GtkWidget *accept_obexpush_combo;
+    GtkWidget *notify_received_obexpush_check;
+#endif /* HAVE_BLUETOOTH */
+    GtkWidget *window;
+    GtkListStore *store;
+    GtkCellRenderer *cell;
+    GtkTreeIter iter;
+
+    builder = gtk_builder_new ();
+    gtk_builder_add_from_file (builder, DATADIR"file-share-properties.ui", &error);
+
+    if (error) {
+      GtkWidget *dialog;
+
+      dialog = error_dialog (_("Could not build interface."), error->message, NULL);
+      gtk_dialog_run (GTK_DIALOG (dialog));
+      gtk_widget_destroy (dialog);
+
+      g_error_free (error);
+      return NULL;
+    }
+
+    window = GTK_WIDGET (gtk_builder_get_object (builder, "user_share_dialog"));
+
+    settings = g_settings_new (GSETTINGS_SCHEMA);
+
+    check = GTK_WIDGET (gtk_builder_get_object (builder, "enable_check"));
+    password_combo = GTK_WIDGET (gtk_builder_get_object (builder, "password_combo"));
+    password_entry = GTK_WIDGET (gtk_builder_get_object (builder, "password_entry"));
+#ifdef HAVE_BLUETOOTH
+    bluetooth_check = GTK_WIDGET (gtk_builder_get_object (builder, "enable_bluetooth_check"));
+    bluetooth_allow_write_check = GTK_WIDGET (gtk_builder_get_object (builder, "allow_write_bluetooth_check"));
+    require_pairing_check = GTK_WIDGET (gtk_builder_get_object (builder, "require_pairing_check"));
+    enable_obexpush_check = GTK_WIDGET (gtk_builder_get_object (builder, "enable_obexpush_check"));
+    accept_obexpush_combo = GTK_WIDGET (gtk_builder_get_object (builder, "accept_obexpush_combo"));
+    notify_received_obexpush_check = GTK_WIDGET (gtk_builder_get_object (builder, "notify_received_obexpush_check"));
+#endif /* HAVE_BLUETOOTH */
+
+    store = gtk_list_store_new (1, G_TYPE_STRING);
+    gtk_combo_box_set_model (GTK_COMBO_BOX (password_combo),
+			     GTK_TREE_MODEL (store));
+    cell = gtk_cell_renderer_text_new ();
+    gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (password_combo), cell, TRUE);
+    gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (password_combo), cell,
+				    "text", 0,
+				    NULL);
+
+    /* Keep in same order as enum */
+    gtk_list_store_append (store, &iter);
+    gtk_list_store_set (store, &iter, 0,
+			_("Never"), -1);
+    gtk_list_store_append (store, &iter);
+    gtk_list_store_set (store, &iter, 0,
+			_("When writing files"), -1);
+    gtk_list_store_append (store, &iter);
+    gtk_list_store_set (store, &iter, 0,
+			_("Always"), -1);
+    g_object_unref (store);
+
+    /* We can't read the password from the text, just set it to something */
+    gtk_entry_set_text (GTK_ENTRY (password_entry), "none");
+    g_object_set_data (G_OBJECT (password_entry),
+		       "user_edited", GINT_TO_POINTER (0));
+    g_signal_connect (password_entry,
+		      "changed", G_CALLBACK (password_entry_changed), NULL);
+
+#ifdef HAVE_BLUETOOTH
+    /* Accept files combo */
+    store = gtk_list_store_new (1, G_TYPE_STRING);
+    gtk_combo_box_set_model (GTK_COMBO_BOX (accept_obexpush_combo),
+			     GTK_TREE_MODEL (store));
+    cell = gtk_cell_renderer_text_new ();
+    gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (accept_obexpush_combo), cell, TRUE);
+    gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (accept_obexpush_combo), cell,
+				    "text", 0,
+				    NULL);
+
+    /* Keep in same order as enum */
+    gtk_list_store_append (store, &iter);
+    gtk_list_store_set (store, &iter, 0,
+			_("Always"), -1);
+    gtk_list_store_append (store, &iter);
+    gtk_list_store_set (store, &iter, 0,
+			_("Only for set up devices"), -1);
+    //FIXME implement
+#if 0
+    gtk_list_store_append (store, &iter);
+    gtk_list_store_set (store, &iter, 0,
+    			_("Ask"), -1);
+#endif
+    g_object_unref (store);
+#endif /* HAVE_BLUETOOTH */
+
+    g_signal_connect (check,
+		      "toggled", G_CALLBACK (enable_check_toggled), NULL);
+    g_signal_connect (password_combo,
+		      "changed", G_CALLBACK (password_combo_changed), NULL);
+#ifdef HAVE_BLUETOOTH
+    g_signal_connect (bluetooth_check,
+    		      "toggled", G_CALLBACK (enable_bluetooth_check_toggled), NULL);
+    g_signal_connect (bluetooth_allow_write_check,
+    		      "toggled", G_CALLBACK (bluetooth_allow_write_check_toggled), NULL);
+    g_signal_connect (require_pairing_check,
+    		      "toggled", G_CALLBACK (bluetooth_require_pairing_check_toggled), NULL);
+    g_signal_connect (enable_obexpush_check,
+    		      "toggled", G_CALLBACK (enable_obexpush_check_toggled), NULL);
+    g_signal_connect (accept_obexpush_combo,
+    		      "changed", G_CALLBACK (accept_obexpush_combo_changed), NULL);
+    g_signal_connect (notify_received_obexpush_check,
+    		      "toggled", G_CALLBACK (notify_received_obexpush_check_toggled), NULL);
+#endif /* HAVE_BLUETOOTH */
+
+    g_signal_connect_swapped (GTK_WIDGET (gtk_builder_get_object (builder, "close_button")),
+                              "clicked", G_CALLBACK (gtk_widget_destroy), window);
+    g_signal_connect (GTK_WIDGET (gtk_builder_get_object (builder, "help_button")),
+		      "clicked", G_CALLBACK (help_button_clicked),
+		      gtk_builder_get_object (builder, "user_share_dialog"));
+
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_ENABLED,
+			     G_CALLBACK (file_sharing_enabled_changed), NULL);
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_REQUIRE_PASSWORD,
+			     G_CALLBACK (password_required_changed), NULL);
+#ifdef HAVE_BLUETOOTH
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_ENABLED,
+			     G_CALLBACK (file_sharing_bluetooth_enabled_changed), NULL);
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_ALLOW_WRITE,
+			     G_CALLBACK (file_sharing_bluetooth_allow_write_changed), NULL);
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_REQUIRE_PAIRING,
+			     G_CALLBACK (file_sharing_bluetooth_require_pairing_changed), NULL);
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED,
+			     G_CALLBACK (file_sharing_bluetooth_obexpush_enabled_changed), NULL);
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_ACCEPT_FILES,
+			     G_CALLBACK (file_sharing_bluetooth_obexpush_accept_files_changed), NULL);
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_NOTIFY,
+			     G_CALLBACK (file_sharing_bluetooth_obexpush_notify_changed), NULL);
+#endif /* HAVE_BLUETOOTH */
+
+    update_ui ();
+
+    return window;
+}
+
+static void
+activate (GtkApplication *app)
+{
+    GList *list;
+    GtkWidget *window;
+
+    list = gtk_application_get_windows (app);
+
+    if (list) {
+        gtk_window_present (GTK_WINDOW (list->data));
+    } else {
+        window = create_window ();
+        gtk_window_set_application (GTK_WINDOW (window), app);
+        gtk_widget_show (window);
+    }
+}
+
+int
+main (int argc, char *argv[])
+{
+    GtkApplication *app;
+    gint status;
+
+    bindtextdomain (GETTEXT_PACKAGE, MATELOCALEDIR);
+    bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
+    textdomain (GETTEXT_PACKAGE);
+
+    app = gtk_application_new ("org.mate.user-share.properties",
+                               G_APPLICATION_FLAGS_NONE);
+    g_signal_connect (app, "activate", G_CALLBACK (activate), NULL);
+
+    status = g_application_run (G_APPLICATION (app), argc, argv);
+
+    g_object_unref (app);
+
+    return status;
+}
+
+
+
+
+ + + diff --git a/2020-12-09-195411-4024-cppcheck@258a71f02483_master/1.html b/2020-12-09-195411-4024-cppcheck@258a71f02483_master/1.html new file mode 100644 index 0000000..fad9871 --- /dev/null +++ b/2020-12-09-195411-4024-cppcheck@258a71f02483_master/1.html @@ -0,0 +1,1054 @@ + + + + + + Cppcheck - HTML report - mate-user-share + + + + + + +
+ +
+
  1
+  2
+  3
+  4
+  5
+  6
+  7
+  8
+  9
+ 10
+ 11
+ 12
+ 13
+ 14
+ 15
+ 16
+ 17
+ 18
+ 19
+ 20
+ 21
+ 22
+ 23
+ 24
+ 25
+ 26
+ 27
+ 28
+ 29
+ 30
+ 31
+ 32
+ 33
+ 34
+ 35
+ 36
+ 37
+ 38
+ 39
+ 40
+ 41
+ 42
+ 43
+ 44
+ 45
+ 46
+ 47
+ 48
+ 49
+ 50
+ 51
+ 52
+ 53
+ 54
+ 55
+ 56
+ 57
+ 58
+ 59
+ 60
+ 61
+ 62
+ 63
+ 64
+ 65
+ 66
+ 67
+ 68
+ 69
+ 70
+ 71
+ 72
+ 73
+ 74
+ 75
+ 76
+ 77
+ 78
+ 79
+ 80
+ 81
+ 82
+ 83
+ 84
+ 85
+ 86
+ 87
+ 88
+ 89
+ 90
+ 91
+ 92
+ 93
+ 94
+ 95
+ 96
+ 97
+ 98
+ 99
+100
+101
+102
+103
+104
+105
+106
+107
+108
+109
+110
+111
+112
+113
+114
+115
+116
+117
+118
+119
+120
+121
+122
+123
+124
+125
+126
+127
+128
+129
+130
+131
+132
+133
+134
+135
+136
+137
+138
+139
+140
+141
+142
+143
+144
+145
+146
+147
+148
+149
+150
+151
+152
+153
+154
+155
+156
+157
+158
+159
+160
+161
+162
+163
+164
+165
+166
+167
+168
+169
+170
+171
+172
+173
+174
+175
+176
+177
+178
+179
+180
+181
+182
+183
+184
+185
+186
+187
+188
+189
+190
+191
+192
+193
+194
+195
+196
+197
+198
+199
+200
+201
+202
+203
+204
+205
+206
+207
+208
+209
+210
+211
+212
+213
+214
+215
+216
+217
+218
+219
+220
+221
+222
+223
+224
+225
+226
+227
+228
+229
+230
+231
+232
+233
+234
+235
+236
+237
+238
+239
+240
+241
+242
+243
+244
+245
+246
+247
+248
+249
+250
+251
+252
+253
+254
+255
+256
+257
+258
+259
+260
+261
+262
+263
+264
+265
+266
+267
+268
+269
+270
+271
+272
+273
+274
+275
+276
+277
+278
+279
+280
+281
+282
+283
+284
+285
+286
+287
+288
+289
+290
+291
+292
+293
+294
+295
+296
+297
+298
+299
+300
+301
+302
+303
+304
+305
+306
+307
+308
+309
+310
+311
+312
+313
+314
+315
+316
+317
+318
+319
+320
+321
+322
+323
+324
+325
+326
+327
+328
+329
+330
+331
+332
+333
+334
+335
+336
+337
+338
+339
+340
+341
+342
+343
+344
+345
+346
+347
+348
+349
+350
+351
+352
+353
+354
+355
+356
+357
+358
+359
+360
+361
+362
+363
+364
+365
+366
+367
+368
+369
+370
+371
+372
+373
+374
+375
+376
+377
+378
+379
+380
+381
+382
+383
+384
+385
+386
+387
+388
+389
+390
+391
+392
+393
+394
+395
+396
+397
+398
+399
+400
+401
+402
+403
+404
+405
+406
+407
+408
+409
+410
+411
+412
+413
+414
+415
+416
+417
+418
+419
+420
+421
+422
+423
+424
+425
+426
+427
+428
+429
+430
+431
+432
+433
+434
+435
+436
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
+
+/*
+ *  Copyright (C) 2004-2008 Red Hat, Inc.
+ *
+ *  Caja is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU General Public License as
+ *  published by the Free Software Foundation; either version 2 of the
+ *  License, or (at your option) any later version.
+ *
+ *  Caja is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  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
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ *  Authors: Alexander Larsson <alexl@redhat.com>
+ *
+ */
+
+#include "config.h"
+
+#include <glib.h>
+#include <glib/gi18n.h>
+#include <X11/Xlib.h>
+
+#include <gio/gio.h>
+
+#include <stdarg.h>
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <signal.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <sys/stat.h>
+
+#ifdef HAVE_SELINUX
+#include <selinux/selinux.h>
+#endif
+
+#include "user_share-common.h"
+#include "user_share-private.h"
+#include "http.h"
+
+/* From avahi-common/domain.h */
+#define AVAHI_LABEL_MAX 64
+
+#define GSETTINGS_SCHEMA "org.mate.FileSharing"
+
+static pid_t httpd_pid = 0;
+
+static int
+get_port (void)
+{
+	int sock;
+	struct sockaddr_in addr;
+	int reuse;
+	socklen_t len;
+
+	sock = socket (PF_INET, SOCK_STREAM, 0);
+	if (sock < 0) {
+		return -1;
+	}
+
+	memset (&addr, 0, sizeof (addr));
+	addr.sin_port = 0;
+	addr.sin_addr.s_addr = INADDR_ANY;
+	addr.sin_family = AF_INET;
+
+	reuse = 1;
+	setsockopt (sock, SOL_SOCKET, SO_REUSEADDR, &reuse, sizeof (reuse));
+	if (bind (sock, (struct sockaddr *)&addr, sizeof (addr)) == -1) {
+		close (sock);
+		return -1;
+	}
+
+	len = sizeof (addr);
+	if (getsockname (sock, (struct sockaddr *)&addr, &len) == -1) {
+		close (sock);
+		return -1;
+	}
+
+#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__APPLE__) || defined(__OpenBSD__)
+	/* XXX This exposes a potential race condition, but without this,
+	 * httpd will not start on the above listed platforms due to the fact
+	 * that SO_REUSEADDR is also needed when Apache binds to the listening
+	 * socket.  At this time, Apache does not support that socket option.
+	 */
+	close (sock);
+#endif
+	return ntohs (addr.sin_port);
+}
+
+static char *
+truncate_name (const char *name)
+{
+	const char *end;
+
+	end = g_utf8_find_prev_char (name, name + 64);<--- Assignment 'end=g_utf8_find_prev_char(name,name+64)', assigned value is 0
+	g_assert (end != NULL);<--- Assuming that condition 'end!=NULL' is not redundant
+	return g_strndup (name, end - name);<--- Null pointer subtraction
+}
+
+static char *
+get_share_name (void)
+{
+	static char *name = NULL;
+	const char *host_name;
+	char *str;
+
+	if (name == NULL) {
+		host_name = g_get_host_name ();
+		if (strcmp (host_name, "localhost") == 0) {
+			/* Translators: The %s will get filled in with the user name
+			   of the user, to form a genitive. If this is difficult to
+			   translate correctly so that it will work correctly in your
+			   language, you may use something equivalent to
+			   "Public files of %s", or leave out the %s altogether.
+			   In the latter case, please put "%.0s" somewhere in the string,
+			   which will match the user name string passed by the C code,
+			   but not put the user name in the final string. This is to
+			   avoid the warning that msgfmt might otherwise generate. */
+			name = g_strdup_printf (_("%s's public files"), g_get_user_name ());
+		} else {
+			/* Translators: This is similar to the string before, only it
+			   has the hostname in it too. */
+			name = g_strdup_printf (_("%s's public files on %s"),
+						g_get_user_name (),
+						host_name);
+		}
+
+	}
+	/* And truncate */
+	if (strlen (name) < AVAHI_LABEL_MAX)
+		return name;
+
+	str = truncate_name (name);
+	g_free (name);
+	name = str;
+
+	return name;
+}
+
+static void
+ensure_conf_dir (void)
+{
+	char *dirname;
+
+	dirname = g_build_filename (g_get_user_config_dir (), "user-share", NULL);
+	g_mkdir_with_parents (dirname, 0755);
+	g_free (dirname);
+}
+
+static void
+httpd_child_setup (gpointer user_data)
+{
+#ifdef HAVE_SELINUX
+	char *mycon;
+	/* If selinux is enabled, avoid transitioning to the httpd_t context,
+	   as this normally means you can't read the users homedir. */
+	if (is_selinux_enabled()) {
+		if (getcon (&mycon) < 0) {
+			abort ();
+		}
+		if (setexeccon (mycon) < 0)
+			abort ();
+		freecon (mycon);
+	}
+#endif
+}
+
+static const char *known_httpd_locations [] = {
+	HTTPD_PROGRAM,
+	"/usr/sbin/httpd",
+	"/usr/sbin/httpd2",
+	"/usr/sbin/apache2",
+	NULL
+};
+
+static char*
+get_httpd_program (void)
+{
+	int i;
+
+	for (i = 0; known_httpd_locations[i]; i++) {
+		if (known_httpd_locations[i][0] == '\0') {
+			/* empty string as first element, happens when
+			 * configured --with-httpd=auto */
+			continue;
+		}
+		if (g_file_test (known_httpd_locations[i], G_FILE_TEST_IS_EXECUTABLE)
+				&& ! g_file_test (known_httpd_locations[i], G_FILE_TEST_IS_DIR)) {
+			return g_strdup (known_httpd_locations[i]);
+		}
+	}
+	return NULL;
+}
+
+static const char *known_httpd_modules_locations [] = {
+	HTTPD_MODULES_PATH,
+	"/etc/httpd/modules",
+	"/usr/lib/apache2/modules",
+	NULL
+};
+
+static gchar*
+get_httpd_modules_path (void)
+{
+	int i;
+
+	for (i = 0; known_httpd_modules_locations[i]; i++) {
+		if (known_httpd_modules_locations[i][0] == '\0') {
+			/* empty string as first element, happens when
+			 * configured --with-httpd=auto */
+			continue;
+		}
+		if (g_file_test (known_httpd_modules_locations[i], G_FILE_TEST_IS_EXECUTABLE)
+				&& g_file_test (known_httpd_modules_locations[i], G_FILE_TEST_IS_DIR)) {
+			return g_strdup (known_httpd_modules_locations[i]);
+		}
+	}
+	return NULL;
+}
+
+static GRegex *version_regex = NULL;
+
+static char*
+get_httpd_config (const char *httpd_program)
+{
+	gchar *standard_output;
+	gchar *cmd_line;
+	GMatchInfo *match_info;
+	gchar *version_number = NULL;
+	gchar *config;
+
+	cmd_line = g_strdup_printf ("%s -v", httpd_program);
+	if (! g_spawn_command_line_sync (cmd_line, &standard_output, NULL, NULL, NULL)) {
+		g_free (cmd_line);
+		return NULL;
+	}
+	g_free (cmd_line);
+
+	if (version_regex == NULL) {
+		version_regex = g_regex_new ("\\d\\.\\d", 0, 0, NULL);
+	}
+
+	if (g_regex_match (version_regex, standard_output, 0, &match_info)) {
+		while (g_match_info_matches (match_info)) {
+			version_number = g_match_info_fetch (match_info, 0);
+			break;
+		}
+		g_match_info_free (match_info);
+		g_free (standard_output);
+	} else {
+		/* Failed to parse httpd version number */
+		g_warning ("Could not parse '%s' as a version for httpd", standard_output);
+		g_free (standard_output);
+		/* assume it is 2.2 */
+		version_number = g_strdup ("2.2");
+	}
+
+	config = g_strdup_printf (HTTPD_CONFIG_TEMPLATE, version_number);
+	g_free (version_number);
+
+	return config;
+}
+
+static gboolean
+spawn_httpd (int port, pid_t *pid_out)
+{
+	char *free1, *free2, *free3, *free4, *free5, *free6, *free7, *free8, *free9;
+	gboolean res;
+	char *argv[10];
+	char *env[10];
+	int i;
+	gint status;
+	char *pid_filename;
+	char *pidfile;
+	GError *error;
+	gboolean got_pidfile;
+	GSettings *settings;
+	char *str;
+	char *public_dir;
+
+	public_dir = lookup_public_dir ();
+	ensure_conf_dir ();
+
+	i = 0;
+	free1 = argv[i++] = get_httpd_program ();
+	if (argv[0] == NULL) {
+		fprintf (stderr, "error finding httpd server\n");
+		return FALSE;
+	}
+
+	argv[i++] = "-f";
+	free2 = argv[i++] = get_httpd_config (argv[0]);
+	argv[i++] = "-C";
+	free3 = argv[i++] = g_strdup_printf ("Listen %d", port);
+
+	settings = g_settings_new (GSETTINGS_SCHEMA);
+	str = g_settings_get_string (settings,
+				       FILE_SHARING_REQUIRE_PASSWORD);
+
+	if (str && strcmp (str, "never") == 0) {
+		/* Do nothing */
+	} else if (str && strcmp (str, "on_write") == 0){
+		argv[i++] = "-D";
+		argv[i++] = "RequirePasswordOnWrite";
+	} else {
+		/* always, or safe fallback */
+		argv[i++] = "-D";
+		argv[i++] = "RequirePasswordAlways";
+	}
+	g_free (str);
+	g_object_unref (settings);
+
+	argv[i] = NULL;
+
+	i = 0;
+	free4 = env[i++] = g_strdup_printf ("HOME=%s", g_get_home_dir());
+	free5 = env[i++] = g_strdup_printf ("XDG_PUBLICSHARE_DIR=%s", public_dir);
+	free6 = env[i++] = g_strdup_printf ("XDG_CONFIG_HOME=%s", g_get_user_config_dir ());
+	free7 = env[i++] = g_strdup_printf ("GUS_SHARE_NAME=%s", get_share_name ());
+	free8 = env[i++] = g_strdup_printf ("GUS_LOGIN_LABEL=%s", "Please log in as the user guest");
+	free9 = env[i++] = g_strdup_printf ("HTTP_MODULES_PATH=%s",get_httpd_modules_path ());
+	env[i++] = "LANG=C";
+	env[i] = NULL;
+
+	pid_filename = g_build_filename (g_get_user_config_dir (), "user-share", "pid", NULL);
+
+	/* Remove pid file before spawning to avoid races with child and old pidfile */
+	unlink (pid_filename);
+
+	error = NULL;
+	res = g_spawn_sync (g_get_home_dir(),
+			    argv, env, 0,
+			    httpd_child_setup, NULL,
+			    NULL, NULL,
+			    &status,
+			    &error);
+	g_free (free1);
+	g_free (free2);
+	g_free (free3);
+	g_free (free4);
+	g_free (free5);
+	g_free (free6);
+	g_free (free7);
+	g_free (free8);
+	g_free (free9);
+	g_free (public_dir);
+
+	if (!res) {
+		fprintf (stderr, "error spawning httpd: %s\n",
+			 error->message);
+		g_error_free (error);
+		g_free (pid_filename);
+		return FALSE;
+	}
+
+	if (status != 0) {
+		g_free (pid_filename);
+		return FALSE;
+	}
+
+	got_pidfile = FALSE;
+	error = NULL;
+	for (i = 0; i < 5; i++) {
+		if (error != NULL)
+			g_error_free (error);
+		error = NULL;
+		if (g_file_get_contents (pid_filename, &pidfile, NULL, &error)) {
+			got_pidfile = TRUE;
+			*pid_out = atoi (pidfile);
+			g_free (pidfile);
+			break;
+		}
+		sleep (1);
+	}
+
+	g_free (pid_filename);
+
+	if (!got_pidfile) {
+		fprintf (stderr, "error opening httpd pidfile: %s\n", error->message);
+		g_error_free (error);
+		return FALSE;
+	}
+	return TRUE;
+}
+
+static void
+kill_httpd (void)
+{
+	if (httpd_pid != 0) {
+		kill (httpd_pid, SIGTERM);
+
+		/* Allow child time to die, we can't waitpid, because its
+		   not a direct child */
+		sleep (1);
+	}
+	httpd_pid = 0;
+}
+
+void
+http_up (void)
+{
+	guint port;
+
+	port = get_port ();
+	if (!spawn_httpd (port, &httpd_pid)) {
+		fprintf (stderr, "spawning httpd failed\n");
+	}
+}
+
+void
+http_down (void)
+{
+	kill_httpd ();
+}
+
+gboolean
+http_init (void)
+{
+	return TRUE;
+}
+
+pid_t
+http_get_pid (void)
+{
+	return httpd_pid;
+}
+
+
+
+
+ + + diff --git a/2020-12-09-195411-4024-cppcheck@258a71f02483_master/2.html b/2020-12-09-195411-4024-cppcheck@258a71f02483_master/2.html new file mode 100644 index 0000000..76cbf20 --- /dev/null +++ b/2020-12-09-195411-4024-cppcheck@258a71f02483_master/2.html @@ -0,0 +1,1288 @@ + + + + + + Cppcheck - HTML report - mate-user-share + + + + + + +
+ +
+
  1
+  2
+  3
+  4
+  5
+  6
+  7
+  8
+  9
+ 10
+ 11
+ 12
+ 13
+ 14
+ 15
+ 16
+ 17
+ 18
+ 19
+ 20
+ 21
+ 22
+ 23
+ 24
+ 25
+ 26
+ 27
+ 28
+ 29
+ 30
+ 31
+ 32
+ 33
+ 34
+ 35
+ 36
+ 37
+ 38
+ 39
+ 40
+ 41
+ 42
+ 43
+ 44
+ 45
+ 46
+ 47
+ 48
+ 49
+ 50
+ 51
+ 52
+ 53
+ 54
+ 55
+ 56
+ 57
+ 58
+ 59
+ 60
+ 61
+ 62
+ 63
+ 64
+ 65
+ 66
+ 67
+ 68
+ 69
+ 70
+ 71
+ 72
+ 73
+ 74
+ 75
+ 76
+ 77
+ 78
+ 79
+ 80
+ 81
+ 82
+ 83
+ 84
+ 85
+ 86
+ 87
+ 88
+ 89
+ 90
+ 91
+ 92
+ 93
+ 94
+ 95
+ 96
+ 97
+ 98
+ 99
+100
+101
+102
+103
+104
+105
+106
+107
+108
+109
+110
+111
+112
+113
+114
+115
+116
+117
+118
+119
+120
+121
+122
+123
+124
+125
+126
+127
+128
+129
+130
+131
+132
+133
+134
+135
+136
+137
+138
+139
+140
+141
+142
+143
+144
+145
+146
+147
+148
+149
+150
+151
+152
+153
+154
+155
+156
+157
+158
+159
+160
+161
+162
+163
+164
+165
+166
+167
+168
+169
+170
+171
+172
+173
+174
+175
+176
+177
+178
+179
+180
+181
+182
+183
+184
+185
+186
+187
+188
+189
+190
+191
+192
+193
+194
+195
+196
+197
+198
+199
+200
+201
+202
+203
+204
+205
+206
+207
+208
+209
+210
+211
+212
+213
+214
+215
+216
+217
+218
+219
+220
+221
+222
+223
+224
+225
+226
+227
+228
+229
+230
+231
+232
+233
+234
+235
+236
+237
+238
+239
+240
+241
+242
+243
+244
+245
+246
+247
+248
+249
+250
+251
+252
+253
+254
+255
+256
+257
+258
+259
+260
+261
+262
+263
+264
+265
+266
+267
+268
+269
+270
+271
+272
+273
+274
+275
+276
+277
+278
+279
+280
+281
+282
+283
+284
+285
+286
+287
+288
+289
+290
+291
+292
+293
+294
+295
+296
+297
+298
+299
+300
+301
+302
+303
+304
+305
+306
+307
+308
+309
+310
+311
+312
+313
+314
+315
+316
+317
+318
+319
+320
+321
+322
+323
+324
+325
+326
+327
+328
+329
+330
+331
+332
+333
+334
+335
+336
+337
+338
+339
+340
+341
+342
+343
+344
+345
+346
+347
+348
+349
+350
+351
+352
+353
+354
+355
+356
+357
+358
+359
+360
+361
+362
+363
+364
+365
+366
+367
+368
+369
+370
+371
+372
+373
+374
+375
+376
+377
+378
+379
+380
+381
+382
+383
+384
+385
+386
+387
+388
+389
+390
+391
+392
+393
+394
+395
+396
+397
+398
+399
+400
+401
+402
+403
+404
+405
+406
+407
+408
+409
+410
+411
+412
+413
+414
+415
+416
+417
+418
+419
+420
+421
+422
+423
+424
+425
+426
+427
+428
+429
+430
+431
+432
+433
+434
+435
+436
+437
+438
+439
+440
+441
+442
+443
+444
+445
+446
+447
+448
+449
+450
+451
+452
+453
+454
+455
+456
+457
+458
+459
+460
+461
+462
+463
+464
+465
+466
+467
+468
+469
+470
+471
+472
+473
+474
+475
+476
+477
+478
+479
+480
+481
+482
+483
+484
+485
+486
+487
+488
+489
+490
+491
+492
+493
+494
+495
+496
+497
+498
+499
+500
+501
+502
+503
+504
+505
+506
+507
+508
+509
+510
+511
+512
+513
+514
+515
+516
+517
+518
+519
+520
+521
+522
+523
+524
+525
+526
+527
+528
+529
+530
+531
+532
+533
+534
+535
+536
+537
+538
+539
+540
+541
+542
+543
+544
+545
+546
+547
+548
+549
+550
+551
+552
+553
+554
+555
+556
+557
+558
+559
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
+
+/*
+ *  Copyright (C) 2004-2008 Red Hat, Inc.
+ *
+ *  Caja is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU General Public License as
+ *  published by the Free Software Foundation; either version 2 of the
+ *  License, or (at your option) any later version.
+ *
+ *  Caja is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  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
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ *  Authors: Bastien Nocera <hadess@hadess.net>
+ *
+ */
+
+#include "config.h"
+
+#include <glib.h>
+#include <glib/gi18n.h>
+#include <gio/gio.h>
+#include <gdk/gdk.h>
+#include <gtk/gtk.h>
+#include <libnotify/notify.h>
+#include <dbus/dbus-glib.h>
+#include <dbus/dbus-glib-lowlevel.h>
+#include <canberra-gtk.h>
+
+#include <string.h>
+
+#include "marshal.h"
+#include "obexpush.h"
+#include "user_share-common.h"
+#include "user_share-private.h"
+
+#define DBUS_TYPE_G_STRING_VARIANT_HASHTABLE (dbus_g_type_get_map ("GHashTable", G_TYPE_STRING, G_TYPE_STRING))
+
+#define GSETTINGS_SCHEMA "org.mate.FileSharing"
+
+static DBusGConnection *connection = NULL;<--- Shadowed declaration
+static DBusGProxy *manager_proxy = NULL;
+static DBusGProxy *server_proxy = NULL;
+static AcceptSetting accept_setting = -1;
+static gboolean show_notifications = FALSE;
+
+static GtkStatusIcon *statusicon = NULL;
+static guint num_notifications = 0;
+
+static void
+hide_statusicon (void)
+{
+	num_notifications--;
+	if (num_notifications == 0)
+		gtk_status_icon_set_visible (statusicon, FALSE);
+}
+
+static void
+on_close_notification (NotifyNotification *notification)
+{
+	hide_statusicon ();
+	g_object_unref (notification);
+}
+
+static void
+notification_launch_action_on_file_cb (NotifyNotification *notification,
+				       const char *action,
+				       const char *file_uri)
+{
+	GdkScreen *screen;
+	GAppLaunchContext *ctx;
+	GTimeVal val;
+
+	g_assert (action != NULL);
+
+	g_get_current_time (&val);
+
+	ctx = G_APP_LAUNCH_CONTEXT (gdk_app_launch_context_new ());
+	screen = gdk_screen_get_default ();
+	gdk_app_launch_context_set_screen (GDK_APP_LAUNCH_CONTEXT (ctx), screen);
+	gdk_app_launch_context_set_timestamp (GDK_APP_LAUNCH_CONTEXT (ctx), val.tv_sec);
+
+	/* We launch the file viewer for the file */
+	if (g_str_equal (action, "display") != FALSE) {
+		if (g_app_info_launch_default_for_uri (file_uri, ctx, NULL) == FALSE) {
+			g_warning ("Failed to launch the file viewer\n");
+		}
+	}
+
+	/* we open the Downloads folder */
+	if (g_str_equal (action, "reveal") != FALSE) {
+		GFile *file;
+		GFile *parent;
+		gchar *parent_uri;
+
+		file = g_file_new_for_uri (file_uri);
+		parent = g_file_get_parent (file);
+		parent_uri = g_file_get_uri (parent);
+		g_object_unref (file);
+		g_object_unref (parent);
+
+		if (!g_app_info_launch_default_for_uri (parent_uri, ctx, NULL)) {
+			g_warning ("Failed to launch the file manager\n");
+		}
+
+		g_free (parent_uri);
+	}
+
+	notify_notification_close (notification, NULL);
+	/* No need to call hide_statusicon(), closing the notification
+	 * will call the close callback */
+}
+
+static void
+show_notification (const char *filename)
+{
+	char *file_uri, *notification_text, *display, *mime_type;
+	NotifyNotification *notification;
+	ca_context *ctx;
+	GAppInfo *app;
+
+	file_uri = g_filename_to_uri (filename, NULL, NULL);
+	if (file_uri == NULL) {
+		g_warning ("Could not make a filename from '%s'", filename);
+		return;
+	}
+
+	display = g_filename_display_basename (filename);
+	/* Translators: %s is the name of the filename received */
+	notification_text = g_strdup_printf(_("You received \"%s\" via Bluetooth"), display);
+	g_free (display);
+	notification = notify_notification_new (_("You received a file"),
+								 notification_text,
+								 "dialog-information");
+
+	notify_notification_set_timeout (notification, NOTIFY_EXPIRES_DEFAULT);
+
+	mime_type = g_content_type_guess (filename, NULL, 0, NULL);
+	app = g_app_info_get_default_for_type (mime_type, FALSE);
+	if (app != NULL) {
+		g_object_unref (app);
+		notify_notification_add_action (notification, "display", _("Open File"),
+						(NotifyActionCallback) notification_launch_action_on_file_cb,
+						g_strdup (file_uri), (GFreeFunc) g_free);
+	}
+	notify_notification_add_action (notification, "reveal", _("Reveal File"),
+					(NotifyActionCallback) notification_launch_action_on_file_cb,
+					g_strdup (file_uri), (GFreeFunc) g_free);
+
+	g_free (file_uri);
+
+	g_signal_connect (G_OBJECT (notification), "closed", G_CALLBACK (on_close_notification), notification);
+
+	if (!notify_notification_show (notification, NULL)) {
+		g_warning ("failed to send notification\n");
+	}
+	g_free (notification_text);
+
+	/* Now we do the audio notification */
+	ctx = ca_gtk_context_get ();
+	ca_context_play (ctx, 0,
+			 CA_PROP_EVENT_ID, "complete-download",
+			 CA_PROP_EVENT_DESCRIPTION, _("File reception complete"),
+			 NULL);
+}
+
+static void
+show_icon (void)
+{
+	if (statusicon == NULL) {
+		statusicon = gtk_status_icon_new_from_icon_name ("mate-obex-server");
+	} else {
+		gtk_status_icon_set_visible (statusicon, TRUE);
+	}
+	num_notifications++;
+}
+
+static gboolean
+device_is_authorised (const char *bdaddr)
+{
+	DBusGConnection *connection;<--- Shadow variable
+	DBusGProxy *manager;
+	GError *error = NULL;
+	GPtrArray *adapters;
+	gboolean retval = FALSE;
+	guint i;
+
+	connection = dbus_g_bus_get (DBUS_BUS_SYSTEM, NULL);
+	if (connection == NULL)
+		return FALSE;
+
+	manager = dbus_g_proxy_new_for_name (connection, "org.bluez",
+					     "/", "org.bluez.Manager");
+	if (manager == NULL) {
+		dbus_g_connection_unref (connection);
+		return FALSE;
+	}
+
+	if (dbus_g_proxy_call (manager, "ListAdapters", &error, G_TYPE_INVALID, dbus_g_type_get_collection ("GPtrArray", DBUS_TYPE_G_OBJECT_PATH), &adapters, G_TYPE_INVALID) == FALSE) {
+		g_object_unref (manager);
+		dbus_g_connection_unref (connection);
+		return FALSE;
+	}
+
+	for (i = 0; i < adapters->len; i++) {
+		DBusGProxy *adapter, *device;
+		char *device_path;
+		GHashTable *props;
+
+		g_debug ("checking adapter %s", (gchar *) g_ptr_array_index (adapters, i));
+
+		adapter = dbus_g_proxy_new_for_name (connection, "org.bluez",
+						    g_ptr_array_index (adapters, i), "org.bluez.Adapter");
+
+		if (dbus_g_proxy_call (adapter, "FindDevice", NULL,
+				       G_TYPE_STRING, bdaddr, G_TYPE_INVALID,
+				       DBUS_TYPE_G_OBJECT_PATH, &device_path, G_TYPE_INVALID) == FALSE)
+		{
+			g_object_unref (adapter);
+			continue;
+		}
+
+		device = dbus_g_proxy_new_for_name (connection, "org.bluez", device_path, "org.bluez.Device");
+
+		if (dbus_g_proxy_call (device, "GetProperties", NULL,
+				       G_TYPE_INVALID, dbus_g_type_get_map ("GHashTable", G_TYPE_STRING, G_TYPE_VALUE),
+				       &props, G_TYPE_INVALID) != FALSE)
+		{
+			GValue *value;
+			gboolean bonded;
+
+			value = g_hash_table_lookup (props, "Paired");
+			bonded = g_value_get_boolean (value);
+			g_message ("%s is %s", bdaddr, bonded ? "bonded" : "not bonded");
+
+			if (bonded) {
+				g_hash_table_destroy (props);
+				g_object_unref (device);
+				g_object_unref (adapter);
+				retval = TRUE;
+				break;
+			}
+		}
+		g_object_unref(adapter);
+	}
+
+	g_ptr_array_free (adapters, TRUE);
+
+	g_object_unref(manager);
+	dbus_g_connection_unref(connection);
+
+	return retval;
+}
+
+static void
+transfer_started_cb (DBusGProxy *session,
+		     const char *filename,
+		     const char *local_path,
+		     guint64 size,
+		     gpointer user_data)
+{
+	GHashTable *dict;
+	DBusGProxy *server = (DBusGProxy *) user_data;
+	GError *error = NULL;
+	gboolean authorise;
+
+	g_message ("transfer started on %s", local_path);
+	g_object_set_data_full (G_OBJECT (session), "filename", g_strdup (local_path), (GDestroyNotify) g_free);
+
+	show_icon ();
+
+	/* First transfer of the session */
+	if (g_object_get_data (G_OBJECT (session), "bdaddr") == NULL) {
+		const char *bdaddr;
+
+		if (dbus_g_proxy_call (server, "GetServerSessionInfo", &error,
+				       DBUS_TYPE_G_OBJECT_PATH, dbus_g_proxy_get_path (session), G_TYPE_INVALID,
+				       DBUS_TYPE_G_STRING_VARIANT_HASHTABLE, &dict, G_TYPE_INVALID) == FALSE) {
+			g_printerr ("Getting Server session info failed: %s\n",
+				    error->message);
+			g_error_free (error);
+			return;
+		}
+
+		bdaddr = g_hash_table_lookup (dict, "BluetoothAddress");
+		g_message ("transfer started for device %s", bdaddr);
+
+		g_object_set_data_full (G_OBJECT (session), "bdaddr", g_strdup (bdaddr), (GDestroyNotify) g_free);
+		/* Initial accept method is undefined, we do that lower down */
+		g_object_set_data (G_OBJECT (session), "accept-method", GINT_TO_POINTER (-1));
+		g_hash_table_destroy (dict);
+	}
+
+	/* Accept method changed */
+	if (GPOINTER_TO_INT (g_object_get_data (G_OBJECT (session), "accept-method")) != accept_setting) {
+		const char *bdaddr;
+
+		bdaddr = g_object_get_data (G_OBJECT (session), "bdaddr");
+
+		if (bdaddr == NULL) {
+			g_warning ("Couldn't get the Bluetooth address for the device, rejecting the transfer");
+			authorise = FALSE;
+		} else if (accept_setting == ACCEPT_ALWAYS) {
+			authorise = TRUE;
+		} else if (accept_setting == ACCEPT_BONDED) {
+			authorise = device_is_authorised (bdaddr);
+		} else {
+			//FIXME implement
+			g_warning ("\"Ask\" authorisation method not implemented");
+			authorise = FALSE;
+		}
+		g_object_set_data (G_OBJECT (session), "authorise", GINT_TO_POINTER (authorise));
+	}
+
+	g_message ("accept_setting: %d", accept_setting);
+
+	authorise = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (session), "authorise"));
+	if (authorise != FALSE) {
+		if (dbus_g_proxy_call (session, "Accept", &error, G_TYPE_INVALID, G_TYPE_INVALID) == FALSE) {
+			g_printerr ("Failed to accept file transfer: %s\n", error->message);
+			g_error_free (error);
+			return;
+		}
+		g_message ("authorised transfer");
+	} else {
+		if (dbus_g_proxy_call (session, "Reject", &error, G_TYPE_INVALID, G_TYPE_INVALID) == FALSE) {
+			g_printerr ("Failed to reject file transfer: %s\n", error->message);
+			g_error_free (error);
+			return;
+		}
+		g_message ("rejected transfer");
+		g_object_set_data (G_OBJECT (session), "filename", NULL);
+	}
+}
+
+static void
+transfer_completed_cb (DBusGProxy *session,
+		       gpointer user_data)
+{
+	GSettings *settings;
+	gboolean display_notify;
+	const char *filename;
+
+	filename = (const char *) g_object_get_data (G_OBJECT (session), "filename");
+
+	g_message ("file finish transfer: %s", filename);
+
+	if (filename == NULL)
+		return;
+
+	settings = g_settings_new (GSETTINGS_SCHEMA);
+	display_notify = g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_OBEXPUSH_NOTIFY);
+	g_object_unref (settings);
+
+	if (display_notify) {
+		show_notification (filename);
+	} else {
+		hide_statusicon ();
+	}
+	g_object_set_data (G_OBJECT (session), "filename", NULL);
+}
+
+static void
+cancelled_cb (DBusGProxy *session,
+	      gpointer user_data)
+{
+	//FIXME implement properly, we never actually finished the transfer
+	g_message ("transfered was cancelled by the sender");
+	transfer_completed_cb (session, user_data);
+	hide_statusicon ();
+}
+
+static void
+error_occurred_cb (DBusGProxy *session,
+		   const char *error_name,
+		   const char *error_message,
+		   gpointer user_data)
+{
+	//FIXME implement properly
+	g_message ("transfer error occurred: %s", error_message);
+	transfer_completed_cb (session, user_data);
+}
+
+static void
+session_created_cb (DBusGProxy *server, const char *session_path, gpointer user_data)
+{
+	DBusGProxy *session;
+
+	session = dbus_g_proxy_new_for_name (connection,
+					     "org.openobex",
+					     session_path,
+					     "org.openobex.ServerSession");
+
+	dbus_g_proxy_add_signal (session, "TransferStarted",
+				 G_TYPE_STRING, G_TYPE_STRING, G_TYPE_UINT64, G_TYPE_INVALID);
+	dbus_g_proxy_connect_signal(session, "TransferStarted",
+				    G_CALLBACK (transfer_started_cb), server, NULL);
+	dbus_g_proxy_add_signal (session, "TransferCompleted",
+				 G_TYPE_INVALID, G_TYPE_INVALID);
+	dbus_g_proxy_connect_signal(session, "TransferCompleted",
+				    G_CALLBACK (transfer_completed_cb), server, NULL);
+	dbus_g_proxy_add_signal (session, "Cancelled",
+				 G_TYPE_INVALID, G_TYPE_INVALID);
+	dbus_g_proxy_connect_signal(session, "Cancelled",
+				    G_CALLBACK (cancelled_cb), server, NULL);
+	dbus_g_proxy_add_signal (session, "ErrorOccurred",
+				 G_TYPE_INVALID, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INVALID);
+	dbus_g_proxy_connect_signal(session, "ErrorOccurred",
+				    G_CALLBACK (error_occurred_cb), server, NULL);
+}
+
+void
+obexpush_up (void)
+{
+	GError *err = NULL;
+	char *download_dir, *server;
+
+	server = NULL;
+	if (manager_proxy == NULL) {
+		manager_proxy = dbus_g_proxy_new_for_name (connection,
+							   "org.openobex",
+							   "/org/openobex",
+							   "org.openobex.Manager");
+		if (dbus_g_proxy_call (manager_proxy, "CreateBluetoothServer",
+				       &err, G_TYPE_STRING, "00:00:00:00:00:00", G_TYPE_STRING, "opp", G_TYPE_BOOLEAN, FALSE, G_TYPE_INVALID,
+				       DBUS_TYPE_G_OBJECT_PATH, &server, G_TYPE_INVALID) == FALSE) {
+			g_printerr ("Creating Bluetooth ObexPush server failed: %s\n",
+				    err->message);
+			g_error_free (err);
+			g_object_unref (manager_proxy);
+			manager_proxy = NULL;
+			return;
+		}
+	}
+
+	download_dir = lookup_download_dir ();
+
+	if (server_proxy == NULL) {
+		server_proxy = dbus_g_proxy_new_for_name (connection,
+							   "org.openobex",
+							   server,
+							   "org.openobex.Server");
+		g_free (server);
+
+		dbus_g_proxy_add_signal (server_proxy, "SessionCreated",
+					 DBUS_TYPE_G_OBJECT_PATH, G_TYPE_INVALID);
+		dbus_g_proxy_connect_signal(server_proxy, "SessionCreated",
+					    G_CALLBACK (session_created_cb), NULL, NULL);
+	}
+
+	if (dbus_g_proxy_call (server_proxy, "Start", &err,
+			   G_TYPE_STRING, download_dir, G_TYPE_BOOLEAN, TRUE, G_TYPE_BOOLEAN, FALSE, G_TYPE_INVALID,
+			   G_TYPE_INVALID) == FALSE) {
+		if (g_error_matches (err, DBUS_GERROR, DBUS_GERROR_REMOTE_EXCEPTION) != FALSE &&
+		    dbus_g_error_has_name (err, "org.openobex.Error.Started") != FALSE) {
+		    	g_error_free (err);
+		    	g_message ("already started, ignoring error");
+		    	g_free (download_dir);
+		    	return;
+		}
+		g_printerr ("Starting Bluetooth ObexPush server failed: %s\n",
+			    err->message);
+		g_error_free (err);
+		g_free (download_dir);
+		g_object_unref (server_proxy);
+		server_proxy = NULL;
+		g_object_unref (manager_proxy);
+		manager_proxy = NULL;
+		return;
+	}
+
+	g_free (download_dir);
+}
+
+static void
+obexpush_stop (gboolean stop_manager)
+{
+	GError *err = NULL;
+
+	if (server_proxy == NULL)
+		return;
+
+	if (dbus_g_proxy_call (server_proxy, "Close", &err, G_TYPE_INVALID, G_TYPE_INVALID) == FALSE) {
+		if (g_error_matches (err, DBUS_GERROR, DBUS_GERROR_REMOTE_EXCEPTION) == FALSE ||
+		    dbus_g_error_has_name (err, "org.openobex.Error.NotStarted") == FALSE) {
+			g_printerr ("Stopping Bluetooth ObexPush server failed: %s\n",
+				    err->message);
+			g_error_free (err);
+			return;
+		}
+		g_error_free (err);
+	}
+
+	if (stop_manager != FALSE) {
+		g_object_unref (server_proxy);
+		server_proxy = NULL;
+		g_object_unref (manager_proxy);
+		manager_proxy = NULL;
+	}
+
+	//FIXME stop all the notifications
+}
+
+void
+obexpush_down (void)
+{
+	obexpush_stop (TRUE);
+}
+
+void
+obexpush_restart (void)
+{
+	obexpush_stop (FALSE);
+	obexpush_up ();
+}
+
+gboolean
+obexpush_init (void)
+{
+	GError *err = NULL;
+
+	connection = dbus_g_bus_get (DBUS_BUS_SESSION, &err);
+	if (connection == NULL) {
+		g_printerr ("Connecting to session bus failed: %s\n",
+			    err->message);
+		g_error_free (err);
+		return FALSE;
+	}
+
+	dbus_g_object_register_marshaller (marshal_VOID__STRING_STRING_UINT64,
+					   G_TYPE_NONE,
+					   G_TYPE_STRING, G_TYPE_STRING, G_TYPE_UINT64, G_TYPE_INVALID);
+
+	if (!notify_init("mate-user-share")) {
+		g_warning("Unable to initialize the notification system\n");
+        }
+
+	dbus_connection_set_exit_on_disconnect (dbus_g_connection_get_connection (connection), FALSE);
+
+	return TRUE;
+}
+
+void
+obexpush_set_accept_files_policy (AcceptSetting setting)
+{
+	accept_setting = setting;
+}
+
+void
+obexpush_set_notify (gboolean enabled)
+{
+	show_notifications = enabled;
+}
+
+
+
+
+ + + diff --git a/2020-12-09-195411-4024-cppcheck@258a71f02483_master/3.html b/2020-12-09-195411-4024-cppcheck@258a71f02483_master/3.html new file mode 100644 index 0000000..55e2139 --- /dev/null +++ b/2020-12-09-195411-4024-cppcheck@258a71f02483_master/3.html @@ -0,0 +1,764 @@ + + + + + + Cppcheck - HTML report - mate-user-share + + + + + + +
+ +
+
  1
+  2
+  3
+  4
+  5
+  6
+  7
+  8
+  9
+ 10
+ 11
+ 12
+ 13
+ 14
+ 15
+ 16
+ 17
+ 18
+ 19
+ 20
+ 21
+ 22
+ 23
+ 24
+ 25
+ 26
+ 27
+ 28
+ 29
+ 30
+ 31
+ 32
+ 33
+ 34
+ 35
+ 36
+ 37
+ 38
+ 39
+ 40
+ 41
+ 42
+ 43
+ 44
+ 45
+ 46
+ 47
+ 48
+ 49
+ 50
+ 51
+ 52
+ 53
+ 54
+ 55
+ 56
+ 57
+ 58
+ 59
+ 60
+ 61
+ 62
+ 63
+ 64
+ 65
+ 66
+ 67
+ 68
+ 69
+ 70
+ 71
+ 72
+ 73
+ 74
+ 75
+ 76
+ 77
+ 78
+ 79
+ 80
+ 81
+ 82
+ 83
+ 84
+ 85
+ 86
+ 87
+ 88
+ 89
+ 90
+ 91
+ 92
+ 93
+ 94
+ 95
+ 96
+ 97
+ 98
+ 99
+100
+101
+102
+103
+104
+105
+106
+107
+108
+109
+110
+111
+112
+113
+114
+115
+116
+117
+118
+119
+120
+121
+122
+123
+124
+125
+126
+127
+128
+129
+130
+131
+132
+133
+134
+135
+136
+137
+138
+139
+140
+141
+142
+143
+144
+145
+146
+147
+148
+149
+150
+151
+152
+153
+154
+155
+156
+157
+158
+159
+160
+161
+162
+163
+164
+165
+166
+167
+168
+169
+170
+171
+172
+173
+174
+175
+176
+177
+178
+179
+180
+181
+182
+183
+184
+185
+186
+187
+188
+189
+190
+191
+192
+193
+194
+195
+196
+197
+198
+199
+200
+201
+202
+203
+204
+205
+206
+207
+208
+209
+210
+211
+212
+213
+214
+215
+216
+217
+218
+219
+220
+221
+222
+223
+224
+225
+226
+227
+228
+229
+230
+231
+232
+233
+234
+235
+236
+237
+238
+239
+240
+241
+242
+243
+244
+245
+246
+247
+248
+249
+250
+251
+252
+253
+254
+255
+256
+257
+258
+259
+260
+261
+262
+263
+264
+265
+266
+267
+268
+269
+270
+271
+272
+273
+274
+275
+276
+277
+278
+279
+280
+281
+282
+283
+284
+285
+286
+287
+288
+289
+290
+291
/* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 8; tab-width: 8 -*-
+ *
+ * Copyright (C) 2003 Novell, Inc.
+ * Copyright (C) 2003-2004 Red Hat, Inc.
+ * Copyright (C) 2005 William Jon McCann <mccann@jhu.edu>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * 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 Foundation, Inc., 51 Franklin St, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ *
+ */
+
+#include "config.h"
+
+#include <stdlib.h>
+#include <string.h>
+#include <glib/gi18n-lib.h>
+#include <gtk/gtk.h>
+#include <libcaja-extension/caja-menu-provider.h>
+#include <libcaja-extension/caja-location-widget-provider.h>
+
+#ifdef HAVE_BLUETOOTH
+#include <bluetooth-client.h>
+#endif
+
+#include "caja-share-bar.h"
+#include "user_share-common.h"
+
+#define CAJA_TYPE_USER_SHARE  (caja_user_share_get_type ())
+#define CAJA_USER_SHARE(o)    (G_TYPE_CHECK_INSTANCE_CAST ((o), CAJA_TYPE_USER_SHARE, CajaUserShare))
+#define CAJA_IS_USER_SHARE(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), CAJA_TYPE_USER_SHARE))
+
+typedef struct
+{
+        GObject              parent_slot;
+} CajaUserShare;
+
+typedef struct
+{
+        GObjectClass parent_slot;
+} CajaUserShareClass;
+
+static GType caja_user_share_get_type      (void);
+static void  caja_user_share_register_type (GTypeModule *module);
+
+static void
+launch_process (char **argv, GtkWindow *parent)
+{
+        GError *error;
+        GtkWidget *dialog;
+
+        error = NULL;
+        if (!g_spawn_async (NULL,
+                            argv, NULL,
+                            0,
+                            NULL, NULL,
+                            NULL,
+                            &error)) {
+
+
+                dialog = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL, GTK_MESSAGE_WARNING,
+						 GTK_BUTTONS_OK, _("Unable to launch the Personal File Sharing preferences"));
+
+                gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog), "%s", error->message);
+
+                gtk_dialog_run (GTK_DIALOG (dialog));
+                gtk_widget_destroy (dialog);
+
+                g_error_free (error);
+        }
+}
+
+static void
+launch_prefs_on_window (GtkWindow *window)
+{
+        char *argv [2];
+
+        argv [0] = g_build_filename (BINDIR, "mate-file-share-properties", NULL);
+        argv [1] = NULL;
+
+        launch_process (argv, window);
+
+        g_free (argv [0]);
+}
+
+static void
+bar_response_cb (CajaShareBar *bar,
+                 gint response,
+                 gpointer         data)
+{
+        if (response == CAJA_SHARE_BAR_RESPONSE_PREFERENCES) {
+                launch_prefs_on_window (GTK_WINDOW (data));
+        }
+}
+
+#ifdef HAVE_BLUETOOTH
+static void
+downloads_bar_set_from_bluetooth_status (GtkWidget *bar)
+{
+	BluetoothClient *client;
+	gboolean bt_powered;
+
+	client = g_object_get_data (G_OBJECT (bar), "bluetooth-client");
+	g_object_get (G_OBJECT (client),
+		      "default-adapter-powered", &bt_powered,
+		      NULL);
+	gtk_widget_set_visible (bar, bt_powered);
+}
+
+static void
+default_adapter_powered_cb (GObject    *gobject,
+			    GParamSpec *pspec,
+			    GtkWidget  *bar)
+{
+	downloads_bar_set_from_bluetooth_status (bar);
+}
+#endif /* HAVE_BLUETOOTH */
+
+static GtkWidget *
+caja_user_share_get_location_widget (CajaLocationWidgetProvider *iface,
+                                         const char                     *uri,
+                                         GtkWidget                      *window)
+{
+	GFile             *file;
+	GtkWidget         *bar;
+	guint              i;
+	gboolean           enable = FALSE;
+	GFile             *home;
+#ifdef HAVE_BLUETOOTH
+	const GUserDirectory special_dirs[] = { G_USER_DIRECTORY_PUBLIC_SHARE, G_USER_DIRECTORY_DOWNLOAD };
+
+	gboolean is_dir[] = { FALSE, FALSE };
+#else
+	const GUserDirectory special_dirs[] = { G_USER_DIRECTORY_PUBLIC_SHARE };
+
+	gboolean is_dir[] = { FALSE };
+#endif /* HAVE_BLUETOOTH */
+	file = g_file_new_for_uri (uri);
+	home = g_file_new_for_path (g_get_home_dir ());
+
+	/* We don't show anything in $HOME */
+	if (g_file_equal (home, file)) {
+		g_object_unref (home);
+		g_object_unref (file);
+		return NULL;
+	}
+
+	g_object_unref (home);
+
+	for (i = 0; i < G_N_ELEMENTS (special_dirs); i++) {
+		GFile *dir;
+		dir = lookup_dir_with_fallback (special_dirs[i]);
+		if (g_file_equal (dir, file)) {
+			enable = TRUE;
+			is_dir[i] = TRUE;
+		}
+		g_object_unref (dir);
+	}
+
+	g_object_unref (file);
+
+	if (enable == FALSE)
+		return NULL;
+
+	if (is_dir[0] != FALSE) {
+#ifdef HAVE_BLUETOOTH
+		if (is_dir[1] != FALSE) {
+			bar = caja_share_bar_new (_("May be used to share or receive files"));
+		} else {
+			bar = caja_share_bar_new (_("May be shared over the network or Bluetooth"));
+		}
+#else
+		bar = caja_share_bar_new (_("May be shared over the network"));
+#endif /* HAVE_BLUETOOTH */
+	} else {
+#ifdef HAVE_BLUETOOTH
+		BluetoothClient *client;
+
+		bar = caja_share_bar_new (_("May be used to receive files over Bluetooth"));
+
+		gtk_widget_set_no_show_all (bar, TRUE);
+		client = bluetooth_client_new ();
+		g_object_set_data_full (G_OBJECT (bar), "bluetooth-client", client, g_object_unref);
+		g_signal_connect (G_OBJECT (client), "notify::default-adapter-powered",
+				  G_CALLBACK (default_adapter_powered_cb), bar);
+		downloads_bar_set_from_bluetooth_status (bar);
+#endif /* HAVE_BLUETOOTH */
+	}
+
+	g_signal_connect (bar, "response",
+			  G_CALLBACK (bar_response_cb),
+			  window);
+
+	gtk_widget_show_all (bar);
+
+	return bar;
+}
+
+static void
+caja_user_share_location_widget_provider_iface_init (CajaLocationWidgetProviderIface *iface)
+{
+        iface->get_widget = caja_user_share_get_location_widget;
+}
+
+static void
+caja_user_share_instance_init (CajaUserShare *share)
+{
+
+}
+
+static void
+caja_user_share_class_init (CajaUserShareClass *klass)
+{
+
+}
+
+static GType share_type = 0;
+
+static GType
+caja_user_share_get_type (void)
+{
+        return share_type;
+}
+
+static void
+caja_user_share_register_type (GTypeModule *module)
+{
+        static const GTypeInfo info = {
+                sizeof (CajaUserShareClass),
+                (GBaseInitFunc) NULL,
+                (GBaseFinalizeFunc) NULL,
+                (GClassInitFunc) caja_user_share_class_init,
+                NULL,
+                NULL,
+                sizeof (CajaUserShare),
+                0,
+                (GInstanceInitFunc) caja_user_share_instance_init,
+        };
+
+        static const GInterfaceInfo location_widget_provider_iface_info = {
+                (GInterfaceInitFunc) caja_user_share_location_widget_provider_iface_init,
+                NULL,
+                NULL
+        };
+
+        share_type = g_type_module_register_type (module,
+                                                 G_TYPE_OBJECT,
+                                                 "CajaUserShare",
+                                                 &info, 0);
+
+        g_type_module_add_interface (module,
+                                     share_type,
+                                     CAJA_TYPE_LOCATION_WIDGET_PROVIDER,
+                                     &location_widget_provider_iface_info);
+}
+
+void
+caja_module_initialize (GTypeModule *module)
+{
+        caja_user_share_register_type (module);
+        bindtextdomain (GETTEXT_PACKAGE, MATELOCALEDIR);
+        bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
+}
+
+void
+caja_module_shutdown (void)
+{
+}
+
+void
+caja_module_list_types (const GType **types,
+                            int          *num_types)
+{
+        static GType type_list [1];
+
+        type_list[0] = CAJA_TYPE_USER_SHARE;
+
+        *types = type_list;
+        *num_types = 1;
+}
+
+
+
+
+ + + diff --git a/2020-12-09-195411-4024-cppcheck@258a71f02483_master/4.html b/2020-12-09-195411-4024-cppcheck@258a71f02483_master/4.html new file mode 100644 index 0000000..0142734 --- /dev/null +++ b/2020-12-09-195411-4024-cppcheck@258a71f02483_master/4.html @@ -0,0 +1,1182 @@ + + + + + + Cppcheck - HTML report - mate-user-share + + + + + + +
+ +
+
  1
+  2
+  3
+  4
+  5
+  6
+  7
+  8
+  9
+ 10
+ 11
+ 12
+ 13
+ 14
+ 15
+ 16
+ 17
+ 18
+ 19
+ 20
+ 21
+ 22
+ 23
+ 24
+ 25
+ 26
+ 27
+ 28
+ 29
+ 30
+ 31
+ 32
+ 33
+ 34
+ 35
+ 36
+ 37
+ 38
+ 39
+ 40
+ 41
+ 42
+ 43
+ 44
+ 45
+ 46
+ 47
+ 48
+ 49
+ 50
+ 51
+ 52
+ 53
+ 54
+ 55
+ 56
+ 57
+ 58
+ 59
+ 60
+ 61
+ 62
+ 63
+ 64
+ 65
+ 66
+ 67
+ 68
+ 69
+ 70
+ 71
+ 72
+ 73
+ 74
+ 75
+ 76
+ 77
+ 78
+ 79
+ 80
+ 81
+ 82
+ 83
+ 84
+ 85
+ 86
+ 87
+ 88
+ 89
+ 90
+ 91
+ 92
+ 93
+ 94
+ 95
+ 96
+ 97
+ 98
+ 99
+100
+101
+102
+103
+104
+105
+106
+107
+108
+109
+110
+111
+112
+113
+114
+115
+116
+117
+118
+119
+120
+121
+122
+123
+124
+125
+126
+127
+128
+129
+130
+131
+132
+133
+134
+135
+136
+137
+138
+139
+140
+141
+142
+143
+144
+145
+146
+147
+148
+149
+150
+151
+152
+153
+154
+155
+156
+157
+158
+159
+160
+161
+162
+163
+164
+165
+166
+167
+168
+169
+170
+171
+172
+173
+174
+175
+176
+177
+178
+179
+180
+181
+182
+183
+184
+185
+186
+187
+188
+189
+190
+191
+192
+193
+194
+195
+196
+197
+198
+199
+200
+201
+202
+203
+204
+205
+206
+207
+208
+209
+210
+211
+212
+213
+214
+215
+216
+217
+218
+219
+220
+221
+222
+223
+224
+225
+226
+227
+228
+229
+230
+231
+232
+233
+234
+235
+236
+237
+238
+239
+240
+241
+242
+243
+244
+245
+246
+247
+248
+249
+250
+251
+252
+253
+254
+255
+256
+257
+258
+259
+260
+261
+262
+263
+264
+265
+266
+267
+268
+269
+270
+271
+272
+273
+274
+275
+276
+277
+278
+279
+280
+281
+282
+283
+284
+285
+286
+287
+288
+289
+290
+291
+292
+293
+294
+295
+296
+297
+298
+299
+300
+301
+302
+303
+304
+305
+306
+307
+308
+309
+310
+311
+312
+313
+314
+315
+316
+317
+318
+319
+320
+321
+322
+323
+324
+325
+326
+327
+328
+329
+330
+331
+332
+333
+334
+335
+336
+337
+338
+339
+340
+341
+342
+343
+344
+345
+346
+347
+348
+349
+350
+351
+352
+353
+354
+355
+356
+357
+358
+359
+360
+361
+362
+363
+364
+365
+366
+367
+368
+369
+370
+371
+372
+373
+374
+375
+376
+377
+378
+379
+380
+381
+382
+383
+384
+385
+386
+387
+388
+389
+390
+391
+392
+393
+394
+395
+396
+397
+398
+399
+400
+401
+402
+403
+404
+405
+406
+407
+408
+409
+410
+411
+412
+413
+414
+415
+416
+417
+418
+419
+420
+421
+422
+423
+424
+425
+426
+427
+428
+429
+430
+431
+432
+433
+434
+435
+436
+437
+438
+439
+440
+441
+442
+443
+444
+445
+446
+447
+448
+449
+450
+451
+452
+453
+454
+455
+456
+457
+458
+459
+460
+461
+462
+463
+464
+465
+466
+467
+468
+469
+470
+471
+472
+473
+474
+475
+476
+477
+478
+479
+480
+481
+482
+483
+484
+485
+486
+487
+488
+489
+490
+491
+492
+493
+494
+495
+496
+497
+498
+499
+500
+501
+502
+503
+504
+505
+506
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
+
+/*
+ *  Copyright (C) 2004-2008 Red Hat, Inc.
+ *
+ *  Caja is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU General Public License as
+ *  published by the Free Software Foundation; either version 2 of the
+ *  License, or (at your option) any later version.
+ *
+ *  Caja is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  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
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ *  Authors: Alexander Larsson <alexl@redhat.com>
+ *
+ */
+
+#include "config.h"
+
+#include <gdk/gdkx.h>
+#include <gtk/gtk.h>
+#include <glib/gi18n.h>
+#include <glib/gstdio.h>
+#include <gio/gio.h>
+#include <X11/Xlib.h>
+
+#include "user_share-private.h"
+#include "user_share-common.h"
+#include "http.h"
+
+#ifdef HAVE_BLUETOOTH
+#include <bluetooth-client.h>
+
+#include "obexftp.h"
+#include "obexpush.h"
+
+#endif /* HAVE_BLUETOOTH */
+
+#include <gio/gio.h>
+
+#include <stdarg.h>
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <signal.h>
+#include <unistd.h>
+
+static guint disabled_timeout_tag = 0;
+static GSettings* settings;<--- Shadowed declaration<--- Shadowed declaration<--- Shadowed declaration
+
+#define GSETTINGS_SCHEMA "org.mate.FileSharing"
+#define GSETTINGS_KEY_FILE_SHARING_ENABLED "enabled"
+#define GSETTINGS_KEY_FILE_SHARING_REQUIRE_PASSWORD "require-password"
+
+#ifdef HAVE_BLUETOOTH
+/* MATE Session */
+#define MATE_SESSION_DBUS_NAME      "org.gnome.SessionManager"
+#define MATE_SESSION_DBUS_OBJECT    "/org/gnome/SessionManager"
+#define MATE_SESSION_DBUS_INTERFACE "org.gnome.SessionManager"
+
+static GDBusProxy *session_proxy = NULL;
+static gboolean has_console = TRUE;
+
+static BluetoothClient *client = NULL;
+static gboolean bluetoothd_enabled = FALSE;
+
+#define OBEX_ENABLED (bluetoothd_enabled && has_console)
+
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_ENABLED "bluetooth-enabled"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_ALLOW_WRITE "bluetooth-allow-write"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_REQUIRE_PAIRING "bluetooth-require-pairing"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED "bluetooth-obexpush-enabled"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_ACCEPT_FILES "bluetooth-accept-files"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_NOTIFY "bluetooth-notify"
+
+
+static void
+obex_services_start (void)
+{
+	GSettings *settings;<--- Shadow variable
+
+	if (bluetoothd_enabled == FALSE ||
+	    has_console == FALSE)
+	    	return;
+
+	settings = g_settings_new(GSETTINGS_SCHEMA);
+
+	if (g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED) == TRUE) {
+	    obexpush_up ();
+	}
+	if (g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_ENABLED) == TRUE) {
+	    obexftp_up ();
+	}
+
+	g_object_unref (client);
+}
+
+static void
+obex_services_shutdown (void)
+{
+	obexpush_down ();
+	obexftp_down ();
+}
+
+static void
+session_properties_changed_cb (GDBusProxy      *session,
+			       GVariant        *changed,
+			       char           **invalidated,
+			       gpointer         user_data)
+{
+	GVariant *v;
+
+	v = g_variant_lookup_value (changed, "SessionIsActive", G_VARIANT_TYPE_BOOLEAN);
+	if (v) {
+		has_console = g_variant_get_boolean (v);
+		g_debug ("Received session is active change: now %s", has_console ? "active" : "inactive");
+
+		if (has_console)
+			obex_services_start ();
+		else
+			obex_services_shutdown ();
+
+		g_variant_unref (v);
+	}
+}
+
+static gboolean
+is_session_active (void)
+{
+	GVariant *variant;
+	gboolean is_session_active = FALSE;
+
+	variant = g_dbus_proxy_get_cached_property (session_proxy,
+						    "SessionIsActive");
+	if (variant) {
+		is_session_active = g_variant_get_boolean (variant);
+		g_variant_unref (variant);
+ 	}
+
+	return is_session_active;
+}
+
+static void
+session_init (void)
+{
+	GError *error = NULL;
+
+	session_proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION,
+						       G_DBUS_PROXY_FLAGS_NONE,
+						       NULL,
+						       MATE_SESSION_DBUS_NAME,
+						       MATE_SESSION_DBUS_OBJECT,
+						       MATE_SESSION_DBUS_INTERFACE,
+						       NULL,
+						       &error);
+	if (session_proxy == NULL) {
+		g_warning ("Failed to get session proxy: %s", error->message);
+		g_error_free (error);
+		return;
+	}
+	g_signal_connect (session_proxy, "g-properties-changed",
+			  G_CALLBACK (session_properties_changed_cb),
+			  NULL);
+	has_console = is_session_active ();
+}
+
+static void
+default_adapter_changed (GObject    *gobject,
+			 GParamSpec *pspec,
+			 gpointer    user_data)
+{
+	char *adapter;
+	gboolean adapter_powered;
+
+	g_object_get (G_OBJECT (client),
+		      "default-adapter", &adapter,
+		      "default-adapter-powered", &adapter_powered,
+		      NULL);
+	if (adapter != NULL && *adapter != '\0') {
+		bluetoothd_enabled = adapter_powered;
+	} else {
+		bluetoothd_enabled = FALSE;
+	}
+
+	/* Were we called as init, or as a callback */
+	if (gobject != NULL) {
+		if (bluetoothd_enabled != FALSE)
+			obex_services_start ();
+		else
+			obex_services_shutdown ();
+	}
+}
+
+static void
+bluez_init (void)
+{
+	client = bluetooth_client_new ();
+	default_adapter_changed (NULL, NULL, NULL);
+	g_signal_connect (G_OBJECT (client), "notify::default-adapter",
+			  G_CALLBACK (default_adapter_changed), NULL);
+	g_signal_connect (G_OBJECT (client), "notify::default-adapter-powered",
+			  G_CALLBACK (default_adapter_changed), NULL);
+}
+#endif /* HAVE_BLUETOOTH */
+
+static gboolean
+file_sharing_enabled (void)
+{
+	gboolean enabled = TRUE;
+	settings = g_settings_new (GSETTINGS_SCHEMA);
+
+#ifdef HAVE_BLUETOOTH
+	if (g_settings_get_boolean (settings, FILE_SHARING_ENABLED) == FALSE &&
+	    g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_ENABLED) == FALSE &&
+	    g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED) == FALSE)
+#else /* HAVE_BLUETOOTH */
+	if (g_settings_get_boolean (settings, FILE_SHARING_ENABLED) == FALSE)
+#endif /* HAVE_BLUETOOTH */
+		enabled = FALSE;
+
+	g_object_unref (settings);
+
+	return enabled;
+}
+
+static void
+migrate_old_configuration (void)
+{
+	const char *old_config_dir;
+	const char *new_config_dir;
+
+	old_config_dir = g_build_filename (g_get_home_dir (), ".mate2", "user-share", NULL);
+	new_config_dir = g_build_filename (g_get_user_config_dir (), "user-share", NULL);
+	if (g_file_test (old_config_dir, G_FILE_TEST_IS_DIR))
+		g_rename (old_config_dir, new_config_dir);
+
+}
+
+static void
+require_password_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	/* Need to restart to get new password setting */
+	if (http_get_pid () != 0) {
+		http_down ();
+		http_up ();
+	}
+}
+
+/* File sharing was disabled for some time, exit now */
+/* If we re-enable it in the ui, this will be restarted anyway */
+static gboolean
+disabled_timeout_callback (gpointer user_data)
+{
+	GSettings *settings = (GSettings *) user_data;<--- Shadow variable
+	http_down ();
+
+#ifdef HAVE_BLUETOOTH
+	if (g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_ENABLED) == FALSE &&
+	    g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED) == FALSE)
+		_exit (0);
+#else /* HAVE_BLUETOOTH */
+	if (g_settings_get_boolean (settings, FILE_SHARING_ENABLED) == FALSE)
+		_exit (0);
+#endif /* HAVE_BLUETOOTH */
+	return FALSE;
+}
+
+static void
+file_sharing_enabled_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	gboolean enabled;
+
+	if (disabled_timeout_tag != 0) {
+		g_source_remove (disabled_timeout_tag);
+		disabled_timeout_tag = 0;
+	}
+
+	enabled = g_settings_get_boolean (settings,
+					 FILE_SHARING_ENABLED);
+	if (enabled) {
+		if (http_get_pid () == 0) {
+			http_up ();
+		}
+	} else {
+		http_down ();
+		disabled_timeout_tag = g_timeout_add_seconds (3,
+							      (GSourceFunc)disabled_timeout_callback,
+							      settings);
+	}
+}
+
+#ifdef HAVE_BLUETOOTH
+static void
+file_sharing_bluetooth_allow_write_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	if (g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_ENABLED) != FALSE)
+		obexftp_restart ();
+}
+
+static void
+file_sharing_bluetooth_require_pairing_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	if (g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_ENABLED) != FALSE) {
+		/* We need to fully reset the session,
+		 * otherwise the new setting isn't taken into account */
+		obexftp_down ();
+		obexftp_up ();
+	}
+}
+
+static void
+file_sharing_bluetooth_enabled_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	if (g_settings_get_boolean (settings,
+				   FILE_SHARING_BLUETOOTH_ENABLED) == FALSE) {
+		obexftp_down ();
+		if (g_settings_get_boolean (settings, FILE_SHARING_ENABLED) == FALSE &&
+		    g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED) == FALSE) {
+			_exit (0);
+		}
+	} else if (OBEX_ENABLED) {
+		obexftp_up ();
+	}
+}
+
+static void
+file_sharing_bluetooth_obexpush_enabled_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	if (g_settings_get_boolean (settings,
+				   FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED) == FALSE) {
+		obexpush_down ();
+		if (g_settings_get_boolean (settings, FILE_SHARING_ENABLED) == FALSE &&
+		    g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_ENABLED) == FALSE) {
+			_exit (0);
+		}
+	} else if (OBEX_ENABLED) {
+		obexpush_up ();
+	}
+}
+
+static void
+file_sharing_bluetooth_obexpush_accept_files_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	AcceptSetting setting;
+	char *str;
+
+	str = g_settings_get_string (settings, FILE_SHARING_BLUETOOTH_OBEXPUSH_ACCEPT_FILES);
+	setting = accept_setting_from_string (str);
+	g_free (str);
+
+	obexpush_set_accept_files_policy (setting);
+}
+
+static void
+file_sharing_bluetooth_obexpush_notify_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	obexpush_set_notify (g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_OBEXPUSH_NOTIFY));
+}
+#endif /* HAVE_BLUETOOTH */
+
+static RETSIGTYPE
+cleanup_handler (int sig)
+{
+	http_down ();
+#ifdef HAVE_BLUETOOTH
+	obexftp_down ();
+	obexpush_down ();
+#endif /* HAVE_BLUETOOTH */
+	_exit (2);
+}
+
+static int
+x_io_error_handler (Display *xdisplay)
+{
+	http_down ();
+#ifdef HAVE_BLUETOOTH
+	obexftp_down ();
+#endif /* HAVE_BLUETOOTH */
+	_exit (2);
+}
+
+int
+main (int argc, char **argv)
+{
+	GSettings *settings;<--- Shadow variable
+	Display *xdisplay;
+	G_GNUC_UNUSED int x_fd;
+	Window selection_owner;
+	Atom xatom;
+
+	bindtextdomain (GETTEXT_PACKAGE, MATELOCALEDIR);
+	bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
+	textdomain (GETTEXT_PACKAGE);
+
+	gtk_init (&argc, &argv);
+
+	if (g_strcmp0 (g_get_real_name (), "root") == 0) {
+		g_warning ("mate-user-share cannot be started as root for security reasons.");
+		return 1;
+	}
+
+	signal (SIGPIPE, SIG_IGN);
+	signal (SIGINT, cleanup_handler);
+	signal (SIGHUP, cleanup_handler);
+	signal (SIGTERM, cleanup_handler);
+
+	xdisplay = GDK_DISPLAY_XDISPLAY (gdk_display_get_default ());
+	if (xdisplay == NULL) {
+		g_warning ("Can't open display");
+		return 1;
+	}
+
+	xatom = XInternAtom (xdisplay, "_MATE_USER_SHARE", FALSE);
+	selection_owner = XGetSelectionOwner (xdisplay, xatom);
+
+	if (selection_owner != None) {
+		/* There is an owner already, quit */
+		return 1;
+	}
+
+	selection_owner = XCreateSimpleWindow (xdisplay,
+					       RootWindow (xdisplay, 0),
+					       0, 0, 1, 1,
+					       0, 0, 0);
+	XSetSelectionOwner (xdisplay, xatom, selection_owner, CurrentTime);
+
+	if (XGetSelectionOwner (xdisplay, xatom) != selection_owner) {
+		/* Didn't get the selection */
+		return 1;
+	}
+
+	migrate_old_configuration ();
+
+	if (!file_sharing_enabled ())
+		return 1;
+
+	settings = g_settings_new (GSETTINGS_SCHEMA);
+
+	x_fd = ConnectionNumber (xdisplay);
+	XSetIOErrorHandler (x_io_error_handler);
+
+	if (http_init () == FALSE)
+		return 1;
+#ifdef HAVE_BLUETOOTH
+	if (obexftp_init () == FALSE)
+		return 1;
+	if (obexpush_init () == FALSE)
+		return 1;
+#endif /* HAVE_BLUETOOTH */
+
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_ENABLED,
+			     G_CALLBACK (file_sharing_enabled_changed), NULL);
+
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_REQUIRE_PASSWORD,
+			     G_CALLBACK (require_password_changed), NULL);
+
+#ifdef HAVE_BLUETOOTH
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_ENABLED,
+			     G_CALLBACK (file_sharing_bluetooth_enabled_changed), NULL);
+
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_ALLOW_WRITE,
+			     G_CALLBACK (file_sharing_bluetooth_allow_write_changed), NULL);
+
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_REQUIRE_PAIRING,
+			     G_CALLBACK (file_sharing_bluetooth_require_pairing_changed), NULL);
+
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED,
+			     G_CALLBACK (file_sharing_bluetooth_obexpush_enabled_changed), NULL);
+
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_ACCEPT_FILES,
+			     G_CALLBACK (file_sharing_bluetooth_obexpush_accept_files_changed), NULL);
+
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_NOTIFY,
+			     G_CALLBACK (file_sharing_bluetooth_obexpush_notify_changed), NULL);
+
+	bluez_init ();
+	session_init ();
+#endif /* HAVE_BLUETOOTH */
+
+	/* Initial setting */
+	file_sharing_enabled_changed (settings, NULL, NULL);
+#ifdef HAVE_BLUETOOTH
+	file_sharing_bluetooth_enabled_changed (settings, NULL, NULL);
+	file_sharing_bluetooth_obexpush_accept_files_changed (settings, NULL, NULL);
+	file_sharing_bluetooth_obexpush_notify_changed (settings, NULL, NULL);
+	file_sharing_bluetooth_obexpush_enabled_changed (settings, NULL, NULL);
+#endif /* HAVE_BLUETOOTH */
+
+	gtk_main ();
+
+	return 0;
+}
+
+
+
+
+ + + diff --git a/2020-12-09-195411-4024-cppcheck@258a71f02483_master/index.html b/2020-12-09-195411-4024-cppcheck@258a71f02483_master/index.html new file mode 100644 index 0000000..71ee45c --- /dev/null +++ b/2020-12-09-195411-4024-cppcheck@258a71f02483_master/index.html @@ -0,0 +1,143 @@ + + + + + + Cppcheck - HTML report - mate-user-share + + + + + + +
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
LineIdCWESeverityMessage
missingIncludeinformationCppcheck cannot find all the include files (use --check-config for details)
src/file-share-properties.c
82variableScope398styleThe scope of the variable 'password' can be reduced.
97shadowVariable398styleLocal variable 'settings' shadows outer variable
105unusedVariable563styleUnused variable: accept_setting
249shadowVariable398styleLocal variable 'settings' shadows outer variable
273shadowVariable398styleLocal variable 'settings' shadows outer variable
294shadowVariable398styleLocal variable 'settings' shadows outer variable
323shadowVariable398styleLocal variable 'settings' shadows outer variable
340shadowVariable398styleLocal variable 'settings' shadows outer variable
357shadowVariable398styleLocal variable 'settings' shadows outer variable
377shadowVariable398styleLocal variable 'settings' shadows outer variable
393shadowVariable398styleLocal variable 'settings' shadows outer variable
457shadowVariable398styleLocal variable 'settings' shadows outer variable
620variableScope398styleThe scope of the variable 'window' can be reduced.
src/http.c
107nullPointerArithmeticRedundantCheck682warningEither the condition 'end!=NULL' is redundant or there is overflow in pointer subtraction.
114variableScope398styleThe scope of the variable 'host_name' can be reduced.
src/obexpush.c
187shadowVariable398styleLocal variable 'connection' shadows outer variable
src/share-extension.c
61variableScope398styleThe scope of the variable 'dialog' can be reduced.
src/user_share.c
86shadowVariable398styleLocal variable 'settings' shadows outer variable
260shadowVariable398styleLocal variable 'settings' shadows outer variable
391shadowVariable398styleLocal variable 'settings' shadows outer variable
+
+
+ + + diff --git a/2020-12-09-195411-4024-cppcheck@258a71f02483_master/stats.html b/2020-12-09-195411-4024-cppcheck@258a71f02483_master/stats.html new file mode 100644 index 0000000..2d39e3f --- /dev/null +++ b/2020-12-09-195411-4024-cppcheck@258a71f02483_master/stats.html @@ -0,0 +1,112 @@ + + + + + + Cppcheck - HTML report - mate-user-share + + + + + + +
+ +
+

Top 10 files for warning severity, total findings: 1
+   1  src/http.c
+

+

Top 10 files for style severity, total findings: 19
+   13  src/file-share-properties.c
+   3   src/user_share.c
+   1   src/share-extension.c
+   1   src/obexpush.c
+   1   src/http.c
+

+ +
+
+ + + diff --git a/2020-12-09-195411-4024-cppcheck@258a71f02483_master/style.css b/2020-12-09-195411-4024-cppcheck@258a71f02483_master/style.css new file mode 100644 index 0000000..07125f4 --- /dev/null +++ b/2020-12-09-195411-4024-cppcheck@258a71f02483_master/style.css @@ -0,0 +1,137 @@ + +body { + font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif; + font-size: 13px; + line-height: 1.5; + margin: 0; + width: auto; +} + +h1 { + margin: 10px; +} + +.header { + border-bottom: thin solid #aaa; +} + +.footer { + border-top: thin solid #aaa; + font-size: 90%; + margin-top: 5px; +} + +.footer ul { + list-style-type: none; + padding-left: 0; +} + +.footer > p { + margin: 4px; +} + +.wrapper { + display: -webkit-box; + display: -ms-flexbox; + display: flex; + -webkit-box-pack: justify; + -ms-flex-pack: justify; + justify-content: space-between; +} + +#menu, +#menu_index { + text-align: left; + width: 350px; + height: 90vh; + min-height: 200px; + overflow: auto; + position: -webkit-sticky; + position: sticky; + top: 0; + padding: 0 15px 15px 15px; +} + +#menu > a { + display: block; + margin-left: 10px; + font-size: 12px; + z-index: 1; +} + +#content, +#content_index { + background-color: #fff; + -webkit-box-sizing: content-box; + -moz-box-sizing: content-box; + box-sizing: content-box; + padding: 0 15px 15px 15px; + width: calc(100% - 350px); + height: 100%; + overflow-x: auto; +} + +#filename { + margin-left: 10px; + font-size: 12px; + z-index: 1; +} + +.error { + background-color: #ffb7b7; +} + +.error2 { + background-color: #faa; + display: inline-block; + margin-left: 4px; +} + +.inconclusive { + background-color: #b6b6b4; +} + +.inconclusive2 { + background-color: #b6b6b4; + display: inline-block; + margin-left: 4px; +} + +.verbose { + display: inline-block; + vertical-align: top; + cursor: help; +} + +.verbose .content { + display: none; + position: absolute; + padding: 10px; + margin: 4px; + max-width: 40%; + white-space: pre-wrap; + border: 1px solid #000; + background-color: #ffffcc; + cursor: auto; +} + +.highlight .hll { + padding: 1px; +} + +.highlighttable { + background-color: #fff; + z-index: 10; + position: relative; + margin: -10px; +} + +.linenos { + border-right: thin solid #aaa; + color: #d3d3d3; + padding-right: 6px; +} + +.d-none { + display: none; +} diff --git a/2021-02-23-075223-9463-cppcheck@8c6c291142e4_master/0.html b/2021-02-23-075223-9463-cppcheck@8c6c291142e4_master/0.html new file mode 100644 index 0000000..74c198b --- /dev/null +++ b/2021-02-23-075223-9463-cppcheck@8c6c291142e4_master/0.html @@ -0,0 +1,1498 @@ + + + + + + Cppcheck - HTML report - mate-user-share + + + + + + +
+ +
+
  1
+  2
+  3
+  4
+  5
+  6
+  7
+  8
+  9
+ 10
+ 11
+ 12
+ 13
+ 14
+ 15
+ 16
+ 17
+ 18
+ 19
+ 20
+ 21
+ 22
+ 23
+ 24
+ 25
+ 26
+ 27
+ 28
+ 29
+ 30
+ 31
+ 32
+ 33
+ 34
+ 35
+ 36
+ 37
+ 38
+ 39
+ 40
+ 41
+ 42
+ 43
+ 44
+ 45
+ 46
+ 47
+ 48
+ 49
+ 50
+ 51
+ 52
+ 53
+ 54
+ 55
+ 56
+ 57
+ 58
+ 59
+ 60
+ 61
+ 62
+ 63
+ 64
+ 65
+ 66
+ 67
+ 68
+ 69
+ 70
+ 71
+ 72
+ 73
+ 74
+ 75
+ 76
+ 77
+ 78
+ 79
+ 80
+ 81
+ 82
+ 83
+ 84
+ 85
+ 86
+ 87
+ 88
+ 89
+ 90
+ 91
+ 92
+ 93
+ 94
+ 95
+ 96
+ 97
+ 98
+ 99
+100
+101
+102
+103
+104
+105
+106
+107
+108
+109
+110
+111
+112
+113
+114
+115
+116
+117
+118
+119
+120
+121
+122
+123
+124
+125
+126
+127
+128
+129
+130
+131
+132
+133
+134
+135
+136
+137
+138
+139
+140
+141
+142
+143
+144
+145
+146
+147
+148
+149
+150
+151
+152
+153
+154
+155
+156
+157
+158
+159
+160
+161
+162
+163
+164
+165
+166
+167
+168
+169
+170
+171
+172
+173
+174
+175
+176
+177
+178
+179
+180
+181
+182
+183
+184
+185
+186
+187
+188
+189
+190
+191
+192
+193
+194
+195
+196
+197
+198
+199
+200
+201
+202
+203
+204
+205
+206
+207
+208
+209
+210
+211
+212
+213
+214
+215
+216
+217
+218
+219
+220
+221
+222
+223
+224
+225
+226
+227
+228
+229
+230
+231
+232
+233
+234
+235
+236
+237
+238
+239
+240
+241
+242
+243
+244
+245
+246
+247
+248
+249
+250
+251
+252
+253
+254
+255
+256
+257
+258
+259
+260
+261
+262
+263
+264
+265
+266
+267
+268
+269
+270
+271
+272
+273
+274
+275
+276
+277
+278
+279
+280
+281
+282
+283
+284
+285
+286
+287
+288
+289
+290
+291
+292
+293
+294
+295
+296
+297
+298
+299
+300
+301
+302
+303
+304
+305
+306
+307
+308
+309
+310
+311
+312
+313
+314
+315
+316
+317
+318
+319
+320
+321
+322
+323
+324
+325
+326
+327
+328
+329
+330
+331
+332
+333
+334
+335
+336
+337
+338
+339
+340
+341
+342
+343
+344
+345
+346
+347
+348
+349
+350
+351
+352
+353
+354
+355
+356
+357
+358
+359
+360
+361
+362
+363
+364
+365
+366
+367
+368
+369
+370
+371
+372
+373
+374
+375
+376
+377
+378
+379
+380
+381
+382
+383
+384
+385
+386
+387
+388
+389
+390
+391
+392
+393
+394
+395
+396
+397
+398
+399
+400
+401
+402
+403
+404
+405
+406
+407
+408
+409
+410
+411
+412
+413
+414
+415
+416
+417
+418
+419
+420
+421
+422
+423
+424
+425
+426
+427
+428
+429
+430
+431
+432
+433
+434
+435
+436
+437
+438
+439
+440
+441
+442
+443
+444
+445
+446
+447
+448
+449
+450
+451
+452
+453
+454
+455
+456
+457
+458
+459
+460
+461
+462
+463
+464
+465
+466
+467
+468
+469
+470
+471
+472
+473
+474
+475
+476
+477
+478
+479
+480
+481
+482
+483
+484
+485
+486
+487
+488
+489
+490
+491
+492
+493
+494
+495
+496
+497
+498
+499
+500
+501
+502
+503
+504
+505
+506
+507
+508
+509
+510
+511
+512
+513
+514
+515
+516
+517
+518
+519
+520
+521
+522
+523
+524
+525
+526
+527
+528
+529
+530
+531
+532
+533
+534
+535
+536
+537
+538
+539
+540
+541
+542
+543
+544
+545
+546
+547
+548
+549
+550
+551
+552
+553
+554
+555
+556
+557
+558
+559
+560
+561
+562
+563
+564
+565
+566
+567
+568
+569
+570
+571
+572
+573
+574
+575
+576
+577
+578
+579
+580
+581
+582
+583
+584
+585
+586
+587
+588
+589
+590
+591
+592
+593
+594
+595
+596
+597
+598
+599
+600
+601
+602
+603
+604
+605
+606
+607
+608
+609
+610
+611
+612
+613
+614
+615
+616
+617
+618
+619
+620
+621
+622
+623
+624
+625
+626
+627
+628
+629
+630
+631
+632
+633
+634
+635
+636
+637
+638
+639
+640
+641
+642
+643
+644
+645
+646
+647
+648
+649
+650
+651
+652
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
+
+/*
+ *  Copyright (C) 2004 Red Hat, Inc.
+ *
+ *  Caja is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU General Public License as
+ *  published by the Free Software Foundation; either version 2 of the
+ *  License, or (at your option) any later version.
+ *
+ *  Caja is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  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
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ *  Authors: Alexander Larsson <alexl@redhat.com>
+ *
+ */
+
+#include "config.h"
+
+#include <string.h>
+#include <stdio.h>
+
+#include <gtk/gtk.h>
+#include <glib/gi18n.h>
+#include <gio/gio.h>
+
+#include "user_share-private.h"
+
+#define REALM "Please log in as the user guest"
+#define USER "guest"
+#define GSETTINGS_SCHEMA "org.mate.FileSharing"
+#define GSETTINGS_KEY_FILE_SHARING_ENABLED "enabled"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_ENABLED "bluetooth-enabled"
+#define GSETTINGS_KEY_FILE_SHARING_REQUIRE_PASSWORD "require-password"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_ALLOW_WRITE "bluetooth-allow-write"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_REQUIRE_PAIRING "bluetooth-require-pairing"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED "bluetooth-obexpush-enabled"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_ACCEPT_FILES "bluetooth-accept-files"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_NOTIFY "bluetooth-notify"
+
+static GtkBuilder* builder;
+static GSettings* settings;<--- Shadowed declaration<--- Shadowed declaration<--- Shadowed declaration<--- Shadowed declaration<--- Shadowed declaration<--- Shadowed declaration<--- Shadowed declaration<--- Shadowed declaration<--- Shadowed declaration<--- Shadowed declaration
+
+
+static void
+write_out_password (const char *password)
+{
+    char *to_hash;
+    char *ascii_digest;
+    char *line;
+    char *filename;
+    FILE *file;
+
+    to_hash = g_strdup_printf ("%s:%s:%s", USER, REALM, password);
+    ascii_digest = g_compute_checksum_for_string (G_CHECKSUM_MD5, to_hash, strlen (to_hash));
+    g_free (to_hash);
+    line = g_strdup_printf ("%s:%s:%s\n", USER, REALM, ascii_digest);
+    g_free (ascii_digest);
+
+    filename = g_build_filename (g_get_user_config_dir (), "user-share", "passwd", NULL);
+
+    file = fopen (filename, "w");
+    if (file != NULL) {
+	fwrite (line, strlen (line), 1, file);
+	fclose (file);
+    }
+
+    g_free (filename);
+    g_free (line);
+}
+
+static void
+flush_password (void)
+{
+    GtkWidget *password_entry;
+    const char *password;
+
+    password_entry = GTK_WIDGET (gtk_builder_get_object (builder, "password_entry"));
+
+    if (g_object_get_data (G_OBJECT( password_entry), "user_edited")) {
+	password = gtk_entry_get_text (GTK_ENTRY (password_entry));
+	if (password != NULL && password[0] != 0)
+	    write_out_password (password);
+    }
+}
+
+
+static void
+update_ui (void)
+{
+    GSettings *settings;<--- Shadow variable
+    gboolean enabled;
+#ifdef HAVE_BLUETOOTH
+    gboolean bluetooth_enabled, bluetooth_write_enabled, require_pairing_enabled;
+    gboolean bluetooth_obexpush_enabled, bluetooth_obexpush_notify;
+#endif /* HAVE_BLUETOOTH */
+    char *str;
+    PasswordSetting password_setting;
+    AcceptSetting accept_setting;<--- Unused variable: accept_setting
+    GtkWidget *check;
+    GtkWidget *password_combo;
+    GtkWidget *password_entry;
+#ifdef HAVE_BLUETOOTH
+    GtkWidget *vbox_share_bluetooth;
+    GtkWidget *vbox_receive_bluetooth;
+    GtkWidget *bluetooth_check;
+    GtkWidget *allow_write_bluetooth_check;
+    GtkWidget *require_pairing_check;
+    GtkWidget *enable_obexpush_check;
+    GtkWidget *accept_obexpush_combo;
+    GtkWidget *notify_received_obexpush_check;
+#endif /* HAVE_BLUETOOTH */
+
+    settings = g_settings_new (GSETTINGS_SCHEMA);
+
+    enabled = g_settings_get_boolean (settings,
+				     FILE_SHARING_ENABLED);
+
+    str = g_settings_get_string (settings, FILE_SHARING_REQUIRE_PASSWORD);
+    password_setting = password_setting_from_string (str);
+    g_free (str);
+
+#ifdef HAVE_BLUETOOTH
+    bluetooth_enabled = g_settings_get_boolean (settings,
+    					       FILE_SHARING_BLUETOOTH_ENABLED);
+    bluetooth_write_enabled = g_settings_get_boolean (settings,
+						     FILE_SHARING_BLUETOOTH_ALLOW_WRITE);
+    require_pairing_enabled = g_settings_get_boolean (settings,
+    						     FILE_SHARING_BLUETOOTH_REQUIRE_PAIRING);
+    bluetooth_obexpush_enabled = g_settings_get_boolean (settings,
+    							FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED);
+    bluetooth_obexpush_notify = g_settings_get_boolean (settings,
+    						       FILE_SHARING_BLUETOOTH_OBEXPUSH_NOTIFY);
+
+    str = g_settings_get_string (settings, FILE_SHARING_BLUETOOTH_OBEXPUSH_ACCEPT_FILES);
+    accept_setting = accept_setting_from_string (str);
+    g_free (str);
+#endif /* HAVE_BLUETOOTH */
+
+    check = GTK_WIDGET (gtk_builder_get_object (builder, "enable_check"));
+    password_combo = GTK_WIDGET (gtk_builder_get_object (builder, "password_combo"));
+    password_entry = GTK_WIDGET (gtk_builder_get_object (builder, "password_entry"));
+#ifdef HAVE_BLUETOOTH
+    vbox_share_bluetooth = GTK_WIDGET (gtk_builder_get_object (builder, "vbox_share_bluetooth"));
+    vbox_receive_bluetooth = GTK_WIDGET (gtk_builder_get_object (builder, "vbox_receive_bluetooth"));
+    bluetooth_check = GTK_WIDGET (gtk_builder_get_object (builder, "enable_bluetooth_check"));
+    allow_write_bluetooth_check = GTK_WIDGET (gtk_builder_get_object (builder, "allow_write_bluetooth_check"));
+    require_pairing_check = GTK_WIDGET (gtk_builder_get_object (builder, "require_pairing_check"));
+    enable_obexpush_check = GTK_WIDGET (gtk_builder_get_object (builder, "enable_obexpush_check"));
+    accept_obexpush_combo = GTK_WIDGET (gtk_builder_get_object (builder, "accept_obexpush_combo"));
+    notify_received_obexpush_check = GTK_WIDGET (gtk_builder_get_object (builder, "notify_received_obexpush_check"));
+#endif /* HAVE_BLUETOOTH */
+
+    /* Network */
+    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (check), enabled);
+    gtk_widget_set_sensitive (password_combo, enabled);
+    gtk_widget_set_sensitive (password_entry, enabled && password_setting != PASSWORD_NEVER);
+
+    gtk_combo_box_set_active (GTK_COMBO_BOX (password_combo),
+			      password_setting);
+
+#ifdef HAVE_BLUETOOTH
+    /* Bluetooth ObexFTP */
+    gtk_widget_set_visible (vbox_share_bluetooth, TRUE);
+    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (bluetooth_check), bluetooth_enabled);
+    gtk_widget_set_sensitive (allow_write_bluetooth_check, bluetooth_enabled);
+    gtk_widget_set_sensitive (require_pairing_check, bluetooth_enabled);
+
+    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (allow_write_bluetooth_check),
+    				  bluetooth_write_enabled);
+    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (require_pairing_check),
+    				  require_pairing_enabled);
+
+    /* Bluetooth ObexPush */
+    gtk_widget_set_visible (vbox_receive_bluetooth, TRUE);
+    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (enable_obexpush_check), bluetooth_obexpush_enabled);
+    gtk_widget_set_sensitive (accept_obexpush_combo, bluetooth_obexpush_enabled);
+    gtk_widget_set_sensitive (notify_received_obexpush_check, bluetooth_obexpush_enabled);
+
+    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (notify_received_obexpush_check),
+    				  bluetooth_obexpush_notify);
+
+    gtk_combo_box_set_active (GTK_COMBO_BOX (accept_obexpush_combo),
+    			      accept_setting);
+#endif /* HAVE_BLUETOOTH */
+
+    g_object_unref (settings);
+}
+
+static void
+file_sharing_enabled_changed (GSettings *settings, gchar *key, gpointer data)
+{
+    update_ui ();
+}
+
+static void
+password_required_changed (GSettings *settings, gchar *key, gpointer data)
+{
+    update_ui ();
+}
+
+#ifdef HAVE_BLUETOOTH
+static void
+file_sharing_bluetooth_enabled_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	update_ui ();
+}
+
+static void
+file_sharing_bluetooth_allow_write_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	update_ui ();
+}
+
+static void
+file_sharing_bluetooth_require_pairing_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	update_ui ();
+}
+
+static void
+file_sharing_bluetooth_obexpush_enabled_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	update_ui ();
+}
+
+static void
+file_sharing_bluetooth_obexpush_accept_files_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	update_ui ();
+}
+
+static void
+file_sharing_bluetooth_obexpush_notify_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	update_ui ();
+}
+#endif /* HAVE_BLUETOOTH */
+
+static void
+password_combo_changed (GtkComboBox *combo_box)
+{
+    GSettings *settings;<--- Shadow variable
+    guint setting;
+
+    setting = gtk_combo_box_get_active (combo_box);
+
+    settings = g_settings_new (GSETTINGS_SCHEMA) ;
+
+    g_settings_set_string (settings,
+			     FILE_SHARING_REQUIRE_PASSWORD,
+			     password_string_from_setting (setting));
+    g_object_unref (settings);
+}
+
+static void
+launch_share (void)
+{
+	if (!g_spawn_command_line_async (USER_SHARE_PROGRAM, NULL))
+		g_warning ("Unable to start mate-user-share program");
+}
+
+#ifdef HAVE_BLUETOOTH
+static void
+enable_bluetooth_check_toggled (GtkWidget *check)
+{
+	GSettings *settings;<--- Shadow variable
+	gboolean enabled;
+
+	enabled = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check));
+
+	settings = g_settings_new (GSETTINGS_SCHEMA) ;
+
+	g_settings_set_boolean (settings,
+			       FILE_SHARING_BLUETOOTH_ENABLED,
+			       enabled);
+
+	g_object_unref (settings);
+
+	if (enabled != FALSE)
+		launch_share ();
+}
+#endif /* HAVE_BLUETOOTH */
+
+static void
+enable_check_toggled (GtkWidget *check)
+{
+	GSettings *settings;<--- Shadow variable
+	gboolean enabled;
+
+	enabled = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check));
+
+	settings = g_settings_new (GSETTINGS_SCHEMA);
+
+	g_settings_set_boolean (settings,
+			       FILE_SHARING_ENABLED,
+			       enabled);
+
+	g_object_unref (settings);
+
+	if (enabled != FALSE)
+		launch_share ();
+}
+
+static void
+password_entry_changed (GtkEditable *editable)
+{
+	g_object_set_data (G_OBJECT (editable),
+			   "user_edited", GINT_TO_POINTER (1));
+	flush_password ();
+}
+
+#ifdef HAVE_BLUETOOTH
+static void
+bluetooth_allow_write_check_toggled (GtkWidget *check)
+{
+	GSettings *settings;<--- Shadow variable
+	gboolean enabled;
+
+	enabled = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check));
+
+	settings = g_settings_new (GSETTINGS_SCHEMA) ;
+
+	g_settings_set_boolean (settings,
+			       FILE_SHARING_BLUETOOTH_ALLOW_WRITE,
+			       enabled);
+
+	g_object_unref (settings);
+}
+
+static void
+bluetooth_require_pairing_check_toggled (GtkWidget *check)
+{
+	GSettings *settings;<--- Shadow variable
+	gboolean enabled;
+
+	enabled = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check));
+
+	settings = g_settings_new (GSETTINGS_SCHEMA) ;
+
+	g_settings_set_boolean (settings,
+			       FILE_SHARING_BLUETOOTH_REQUIRE_PAIRING,
+			       enabled);
+
+	g_object_unref (settings);
+}
+
+static void
+enable_obexpush_check_toggled (GtkWidget *check)
+{
+	GSettings *settings;<--- Shadow variable
+	gboolean enabled;
+
+	enabled = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check));
+
+	settings = g_settings_new (GSETTINGS_SCHEMA) ;
+
+	g_settings_set_boolean (settings,
+			       FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED,
+			       enabled);
+
+	g_object_unref (settings);
+
+	if (enabled != FALSE)
+		launch_share ();
+}
+
+static void
+accept_obexpush_combo_changed (GtkComboBox *combo_box)
+{
+    GSettings *settings;<--- Shadow variable
+    guint setting;
+
+    setting = gtk_combo_box_get_active (combo_box);
+
+    settings = g_settings_new (GSETTINGS_SCHEMA) ;
+
+    g_settings_set_string (settings,
+			     FILE_SHARING_BLUETOOTH_OBEXPUSH_ACCEPT_FILES,
+			     accept_string_from_setting (setting));
+    g_object_unref (settings);
+}
+
+static void
+notify_received_obexpush_check_toggled (GtkWidget *check)
+{
+	GSettings *settings;<--- Shadow variable
+	gboolean enabled;
+
+	enabled = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check));
+
+	settings = g_settings_new (GSETTINGS_SCHEMA) ;
+
+	g_settings_set_boolean (settings,
+			       FILE_SHARING_BLUETOOTH_OBEXPUSH_NOTIFY,
+			       enabled);
+
+	g_object_unref (settings);
+}
+#endif /* HAVE_BLUETOOTH */
+
+static GtkWidget *
+error_dialog (const char *title,
+	      const char *reason,
+	      GtkWindow *parent)
+{
+	GtkWidget *error_dialog;
+
+	if (reason == NULL)
+		reason = _("No reason");
+
+	error_dialog =
+		gtk_message_dialog_new (parent,
+					GTK_DIALOG_MODAL,
+					GTK_MESSAGE_ERROR,
+					GTK_BUTTONS_OK,
+					"%s", title);
+	gtk_message_dialog_format_secondary_text
+		(GTK_MESSAGE_DIALOG (error_dialog), "%s", reason);
+
+	gtk_window_set_title (GTK_WINDOW (error_dialog), ""); /* as per HIG */
+	gtk_container_set_border_width (GTK_CONTAINER (error_dialog), 5);
+	gtk_dialog_set_default_response (GTK_DIALOG (error_dialog),
+					 GTK_RESPONSE_OK);
+	gtk_window_set_modal (GTK_WINDOW (error_dialog), TRUE);
+
+	return error_dialog;
+}
+
+static void
+help_button_clicked (GtkButton *button, GtkWidget *window)
+{
+	GError *error = NULL;
+
+	if (gtk_show_uri_on_window (GTK_WINDOW (window), "help:mate-user-share", gtk_get_current_event_time (), &error) == FALSE) {
+		GtkWidget *dialog;
+
+		dialog = error_dialog (_("Could not display the help contents."), error->message, GTK_WINDOW (window));
+		g_signal_connect (G_OBJECT (dialog), "response", G_CALLBACK
+				  (gtk_widget_destroy), error_dialog);
+		gtk_window_present (GTK_WINDOW (dialog));
+
+		g_error_free (error);
+	}
+}
+
+static GtkWidget *
+create_window (void)
+{
+    GError *error = NULL;
+    GSettings *settings;<--- Shadow variable
+    GtkWidget *check;
+    GtkWidget *password_combo;
+    GtkWidget *password_entry;
+#ifdef HAVE_BLUETOOTH
+    GtkWidget *bluetooth_check;
+    GtkWidget *bluetooth_allow_write_check;
+    GtkWidget *require_pairing_check;
+    GtkWidget *enable_obexpush_check;
+    GtkWidget *accept_obexpush_combo;
+    GtkWidget *notify_received_obexpush_check;
+#endif /* HAVE_BLUETOOTH */
+    GtkWidget *window;
+    GtkListStore *store;
+    GtkCellRenderer *cell;
+    GtkTreeIter iter;
+
+    builder = gtk_builder_new ();
+    gtk_builder_add_from_file (builder, DATADIR"file-share-properties.ui", &error);
+
+    if (error) {
+      GtkWidget *dialog;
+
+      dialog = error_dialog (_("Could not build interface."), error->message, NULL);
+      gtk_dialog_run (GTK_DIALOG (dialog));
+      gtk_widget_destroy (dialog);
+
+      g_error_free (error);
+      return NULL;
+    }
+
+    window = GTK_WIDGET (gtk_builder_get_object (builder, "user_share_dialog"));
+
+    settings = g_settings_new (GSETTINGS_SCHEMA);
+
+    check = GTK_WIDGET (gtk_builder_get_object (builder, "enable_check"));
+    password_combo = GTK_WIDGET (gtk_builder_get_object (builder, "password_combo"));
+    password_entry = GTK_WIDGET (gtk_builder_get_object (builder, "password_entry"));
+#ifdef HAVE_BLUETOOTH
+    bluetooth_check = GTK_WIDGET (gtk_builder_get_object (builder, "enable_bluetooth_check"));
+    bluetooth_allow_write_check = GTK_WIDGET (gtk_builder_get_object (builder, "allow_write_bluetooth_check"));
+    require_pairing_check = GTK_WIDGET (gtk_builder_get_object (builder, "require_pairing_check"));
+    enable_obexpush_check = GTK_WIDGET (gtk_builder_get_object (builder, "enable_obexpush_check"));
+    accept_obexpush_combo = GTK_WIDGET (gtk_builder_get_object (builder, "accept_obexpush_combo"));
+    notify_received_obexpush_check = GTK_WIDGET (gtk_builder_get_object (builder, "notify_received_obexpush_check"));
+#endif /* HAVE_BLUETOOTH */
+
+    store = gtk_list_store_new (1, G_TYPE_STRING);
+    gtk_combo_box_set_model (GTK_COMBO_BOX (password_combo),
+			     GTK_TREE_MODEL (store));
+    cell = gtk_cell_renderer_text_new ();
+    gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (password_combo), cell, TRUE);
+    gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (password_combo), cell,
+				    "text", 0,
+				    NULL);
+
+    /* Keep in same order as enum */
+    gtk_list_store_append (store, &iter);
+    gtk_list_store_set (store, &iter, 0,
+			_("Never"), -1);
+    gtk_list_store_append (store, &iter);
+    gtk_list_store_set (store, &iter, 0,
+			_("When writing files"), -1);
+    gtk_list_store_append (store, &iter);
+    gtk_list_store_set (store, &iter, 0,
+			_("Always"), -1);
+    g_object_unref (store);
+
+    /* We can't read the password from the text, just set it to something */
+    gtk_entry_set_text (GTK_ENTRY (password_entry), "none");
+    g_object_set_data (G_OBJECT (password_entry),
+		       "user_edited", GINT_TO_POINTER (0));
+    g_signal_connect (password_entry,
+		      "changed", G_CALLBACK (password_entry_changed), NULL);
+
+#ifdef HAVE_BLUETOOTH
+    /* Accept files combo */
+    store = gtk_list_store_new (1, G_TYPE_STRING);
+    gtk_combo_box_set_model (GTK_COMBO_BOX (accept_obexpush_combo),
+			     GTK_TREE_MODEL (store));
+    cell = gtk_cell_renderer_text_new ();
+    gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (accept_obexpush_combo), cell, TRUE);
+    gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (accept_obexpush_combo), cell,
+				    "text", 0,
+				    NULL);
+
+    /* Keep in same order as enum */
+    gtk_list_store_append (store, &iter);
+    gtk_list_store_set (store, &iter, 0,
+			_("Always"), -1);
+    gtk_list_store_append (store, &iter);
+    gtk_list_store_set (store, &iter, 0,
+			_("Only for set up devices"), -1);
+    //FIXME implement
+#if 0
+    gtk_list_store_append (store, &iter);
+    gtk_list_store_set (store, &iter, 0,
+    			_("Ask"), -1);
+#endif
+    g_object_unref (store);
+#endif /* HAVE_BLUETOOTH */
+
+    g_signal_connect (check,
+		      "toggled", G_CALLBACK (enable_check_toggled), NULL);
+    g_signal_connect (password_combo,
+		      "changed", G_CALLBACK (password_combo_changed), NULL);
+#ifdef HAVE_BLUETOOTH
+    g_signal_connect (bluetooth_check,
+    		      "toggled", G_CALLBACK (enable_bluetooth_check_toggled), NULL);
+    g_signal_connect (bluetooth_allow_write_check,
+    		      "toggled", G_CALLBACK (bluetooth_allow_write_check_toggled), NULL);
+    g_signal_connect (require_pairing_check,
+    		      "toggled", G_CALLBACK (bluetooth_require_pairing_check_toggled), NULL);
+    g_signal_connect (enable_obexpush_check,
+    		      "toggled", G_CALLBACK (enable_obexpush_check_toggled), NULL);
+    g_signal_connect (accept_obexpush_combo,
+    		      "changed", G_CALLBACK (accept_obexpush_combo_changed), NULL);
+    g_signal_connect (notify_received_obexpush_check,
+    		      "toggled", G_CALLBACK (notify_received_obexpush_check_toggled), NULL);
+#endif /* HAVE_BLUETOOTH */
+
+    g_signal_connect_swapped (GTK_WIDGET (gtk_builder_get_object (builder, "close_button")),
+                              "clicked", G_CALLBACK (gtk_widget_destroy), window);
+    g_signal_connect (GTK_WIDGET (gtk_builder_get_object (builder, "help_button")),
+		      "clicked", G_CALLBACK (help_button_clicked),
+		      gtk_builder_get_object (builder, "user_share_dialog"));
+
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_ENABLED,
+			     G_CALLBACK (file_sharing_enabled_changed), NULL);
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_REQUIRE_PASSWORD,
+			     G_CALLBACK (password_required_changed), NULL);
+#ifdef HAVE_BLUETOOTH
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_ENABLED,
+			     G_CALLBACK (file_sharing_bluetooth_enabled_changed), NULL);
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_ALLOW_WRITE,
+			     G_CALLBACK (file_sharing_bluetooth_allow_write_changed), NULL);
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_REQUIRE_PAIRING,
+			     G_CALLBACK (file_sharing_bluetooth_require_pairing_changed), NULL);
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED,
+			     G_CALLBACK (file_sharing_bluetooth_obexpush_enabled_changed), NULL);
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_ACCEPT_FILES,
+			     G_CALLBACK (file_sharing_bluetooth_obexpush_accept_files_changed), NULL);
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_NOTIFY,
+			     G_CALLBACK (file_sharing_bluetooth_obexpush_notify_changed), NULL);
+#endif /* HAVE_BLUETOOTH */
+
+    update_ui ();
+
+    return window;
+}
+
+static void
+activate (GtkApplication *app)
+{
+    GList *list;
+    GtkWidget *window;
+
+    list = gtk_application_get_windows (app);
+
+    if (list) {
+        gtk_window_present (GTK_WINDOW (list->data));
+    } else {
+        window = create_window ();
+        gtk_window_set_application (GTK_WINDOW (window), app);
+        gtk_widget_show (window);
+    }
+}
+
+int
+main (int argc, char *argv[])
+{
+    GtkApplication *app;
+    gint status;
+
+    bindtextdomain (GETTEXT_PACKAGE, MATELOCALEDIR);
+    bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
+    textdomain (GETTEXT_PACKAGE);
+
+    app = gtk_application_new ("org.mate.user-share.properties",
+                               G_APPLICATION_FLAGS_NONE);
+    g_signal_connect (app, "activate", G_CALLBACK (activate), NULL);
+
+    status = g_application_run (G_APPLICATION (app), argc, argv);
+
+    g_object_unref (app);
+
+    return status;
+}
+
+
+
+
+ + + diff --git a/2021-02-23-075223-9463-cppcheck@8c6c291142e4_master/1.html b/2021-02-23-075223-9463-cppcheck@8c6c291142e4_master/1.html new file mode 100644 index 0000000..cec50f3 --- /dev/null +++ b/2021-02-23-075223-9463-cppcheck@8c6c291142e4_master/1.html @@ -0,0 +1,1054 @@ + + + + + + Cppcheck - HTML report - mate-user-share + + + + + + +
+ +
+
  1
+  2
+  3
+  4
+  5
+  6
+  7
+  8
+  9
+ 10
+ 11
+ 12
+ 13
+ 14
+ 15
+ 16
+ 17
+ 18
+ 19
+ 20
+ 21
+ 22
+ 23
+ 24
+ 25
+ 26
+ 27
+ 28
+ 29
+ 30
+ 31
+ 32
+ 33
+ 34
+ 35
+ 36
+ 37
+ 38
+ 39
+ 40
+ 41
+ 42
+ 43
+ 44
+ 45
+ 46
+ 47
+ 48
+ 49
+ 50
+ 51
+ 52
+ 53
+ 54
+ 55
+ 56
+ 57
+ 58
+ 59
+ 60
+ 61
+ 62
+ 63
+ 64
+ 65
+ 66
+ 67
+ 68
+ 69
+ 70
+ 71
+ 72
+ 73
+ 74
+ 75
+ 76
+ 77
+ 78
+ 79
+ 80
+ 81
+ 82
+ 83
+ 84
+ 85
+ 86
+ 87
+ 88
+ 89
+ 90
+ 91
+ 92
+ 93
+ 94
+ 95
+ 96
+ 97
+ 98
+ 99
+100
+101
+102
+103
+104
+105
+106
+107
+108
+109
+110
+111
+112
+113
+114
+115
+116
+117
+118
+119
+120
+121
+122
+123
+124
+125
+126
+127
+128
+129
+130
+131
+132
+133
+134
+135
+136
+137
+138
+139
+140
+141
+142
+143
+144
+145
+146
+147
+148
+149
+150
+151
+152
+153
+154
+155
+156
+157
+158
+159
+160
+161
+162
+163
+164
+165
+166
+167
+168
+169
+170
+171
+172
+173
+174
+175
+176
+177
+178
+179
+180
+181
+182
+183
+184
+185
+186
+187
+188
+189
+190
+191
+192
+193
+194
+195
+196
+197
+198
+199
+200
+201
+202
+203
+204
+205
+206
+207
+208
+209
+210
+211
+212
+213
+214
+215
+216
+217
+218
+219
+220
+221
+222
+223
+224
+225
+226
+227
+228
+229
+230
+231
+232
+233
+234
+235
+236
+237
+238
+239
+240
+241
+242
+243
+244
+245
+246
+247
+248
+249
+250
+251
+252
+253
+254
+255
+256
+257
+258
+259
+260
+261
+262
+263
+264
+265
+266
+267
+268
+269
+270
+271
+272
+273
+274
+275
+276
+277
+278
+279
+280
+281
+282
+283
+284
+285
+286
+287
+288
+289
+290
+291
+292
+293
+294
+295
+296
+297
+298
+299
+300
+301
+302
+303
+304
+305
+306
+307
+308
+309
+310
+311
+312
+313
+314
+315
+316
+317
+318
+319
+320
+321
+322
+323
+324
+325
+326
+327
+328
+329
+330
+331
+332
+333
+334
+335
+336
+337
+338
+339
+340
+341
+342
+343
+344
+345
+346
+347
+348
+349
+350
+351
+352
+353
+354
+355
+356
+357
+358
+359
+360
+361
+362
+363
+364
+365
+366
+367
+368
+369
+370
+371
+372
+373
+374
+375
+376
+377
+378
+379
+380
+381
+382
+383
+384
+385
+386
+387
+388
+389
+390
+391
+392
+393
+394
+395
+396
+397
+398
+399
+400
+401
+402
+403
+404
+405
+406
+407
+408
+409
+410
+411
+412
+413
+414
+415
+416
+417
+418
+419
+420
+421
+422
+423
+424
+425
+426
+427
+428
+429
+430
+431
+432
+433
+434
+435
+436
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
+
+/*
+ *  Copyright (C) 2004-2008 Red Hat, Inc.
+ *
+ *  Caja is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU General Public License as
+ *  published by the Free Software Foundation; either version 2 of the
+ *  License, or (at your option) any later version.
+ *
+ *  Caja is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  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
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ *  Authors: Alexander Larsson <alexl@redhat.com>
+ *
+ */
+
+#include "config.h"
+
+#include <glib.h>
+#include <glib/gi18n.h>
+#include <X11/Xlib.h>
+
+#include <gio/gio.h>
+
+#include <stdarg.h>
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <signal.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <sys/stat.h>
+
+#ifdef HAVE_SELINUX
+#include <selinux/selinux.h>
+#endif
+
+#include "user_share-common.h"
+#include "user_share-private.h"
+#include "http.h"
+
+/* From avahi-common/domain.h */
+#define AVAHI_LABEL_MAX 64
+
+#define GSETTINGS_SCHEMA "org.mate.FileSharing"
+
+static pid_t httpd_pid = 0;
+
+static int
+get_port (void)
+{
+	int sock;
+	struct sockaddr_in addr;
+	int reuse;
+	socklen_t len;
+
+	sock = socket (PF_INET, SOCK_STREAM, 0);
+	if (sock < 0) {
+		return -1;
+	}
+
+	memset (&addr, 0, sizeof (addr));
+	addr.sin_port = 0;
+	addr.sin_addr.s_addr = INADDR_ANY;
+	addr.sin_family = AF_INET;
+
+	reuse = 1;
+	setsockopt (sock, SOL_SOCKET, SO_REUSEADDR, &reuse, sizeof (reuse));
+	if (bind (sock, (struct sockaddr *)&addr, sizeof (addr)) == -1) {
+		close (sock);
+		return -1;
+	}
+
+	len = sizeof (addr);
+	if (getsockname (sock, (struct sockaddr *)&addr, &len) == -1) {
+		close (sock);
+		return -1;
+	}
+
+#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__APPLE__) || defined(__OpenBSD__)
+	/* XXX This exposes a potential race condition, but without this,
+	 * httpd will not start on the above listed platforms due to the fact
+	 * that SO_REUSEADDR is also needed when Apache binds to the listening
+	 * socket.  At this time, Apache does not support that socket option.
+	 */
+	close (sock);
+#endif
+	return ntohs (addr.sin_port);
+}
+
+static char *
+truncate_name (const char *name)
+{
+	const char *end;
+
+	end = g_utf8_find_prev_char (name, name + 64);
+	g_assert (end != NULL);
+	return g_strndup (name, end - name);
+}
+
+static char *
+get_share_name (void)
+{
+	static char *name = NULL;
+	const char *host_name;
+	char *str;
+
+	if (name == NULL) {
+		host_name = g_get_host_name ();
+		if (strcmp (host_name, "localhost") == 0) {
+			/* Translators: The %s will get filled in with the user name
+			   of the user, to form a genitive. If this is difficult to
+			   translate correctly so that it will work correctly in your
+			   language, you may use something equivalent to
+			   "Public files of %s", or leave out the %s altogether.
+			   In the latter case, please put "%.0s" somewhere in the string,
+			   which will match the user name string passed by the C code,
+			   but not put the user name in the final string. This is to
+			   avoid the warning that msgfmt might otherwise generate. */
+			name = g_strdup_printf (_("%s's public files"), g_get_user_name ());
+		} else {
+			/* Translators: This is similar to the string before, only it
+			   has the hostname in it too. */
+			name = g_strdup_printf (_("%s's public files on %s"),
+						g_get_user_name (),
+						host_name);
+		}
+
+	}
+	/* And truncate */
+	if (strlen (name) < AVAHI_LABEL_MAX)
+		return name;
+
+	str = truncate_name (name);
+	g_free (name);
+	name = str;
+
+	return name;
+}
+
+static void
+ensure_conf_dir (void)
+{
+	char *dirname;
+
+	dirname = g_build_filename (g_get_user_config_dir (), "user-share", NULL);
+	g_mkdir_with_parents (dirname, 0755);
+	g_free (dirname);
+}
+
+static void
+httpd_child_setup (gpointer user_data)
+{
+#ifdef HAVE_SELINUX
+	char *mycon;
+	/* If selinux is enabled, avoid transitioning to the httpd_t context,
+	   as this normally means you can't read the users homedir. */
+	if (is_selinux_enabled()) {
+		if (getcon (&mycon) < 0) {
+			abort ();
+		}
+		if (setexeccon (mycon) < 0)
+			abort ();
+		freecon (mycon);
+	}
+#endif
+}
+
+static const char *known_httpd_locations [] = {
+	HTTPD_PROGRAM,
+	"/usr/sbin/httpd",
+	"/usr/sbin/httpd2",
+	"/usr/sbin/apache2",
+	NULL
+};
+
+static char*
+get_httpd_program (void)
+{
+	int i;
+
+	for (i = 0; known_httpd_locations[i]; i++) {
+		if (known_httpd_locations[i][0] == '\0') {
+			/* empty string as first element, happens when
+			 * configured --with-httpd=auto */
+			continue;
+		}
+		if (g_file_test (known_httpd_locations[i], G_FILE_TEST_IS_EXECUTABLE)
+				&& ! g_file_test (known_httpd_locations[i], G_FILE_TEST_IS_DIR)) {
+			return g_strdup (known_httpd_locations[i]);
+		}
+	}
+	return NULL;
+}
+
+static const char *known_httpd_modules_locations [] = {
+	HTTPD_MODULES_PATH,
+	"/etc/httpd/modules",
+	"/usr/lib/apache2/modules",
+	NULL
+};
+
+static gchar*
+get_httpd_modules_path (void)
+{
+	int i;
+
+	for (i = 0; known_httpd_modules_locations[i]; i++) {
+		if (known_httpd_modules_locations[i][0] == '\0') {
+			/* empty string as first element, happens when
+			 * configured --with-httpd=auto */
+			continue;
+		}
+		if (g_file_test (known_httpd_modules_locations[i], G_FILE_TEST_IS_EXECUTABLE)
+				&& g_file_test (known_httpd_modules_locations[i], G_FILE_TEST_IS_DIR)) {
+			return g_strdup (known_httpd_modules_locations[i]);
+		}
+	}
+	return NULL;
+}
+
+static GRegex *version_regex = NULL;
+
+static char*
+get_httpd_config (const char *httpd_program)
+{
+	gchar *standard_output;
+	gchar *cmd_line;
+	GMatchInfo *match_info;
+	gchar *version_number = NULL;
+	gchar *config;
+
+	cmd_line = g_strdup_printf ("%s -v", httpd_program);
+	if (! g_spawn_command_line_sync (cmd_line, &standard_output, NULL, NULL, NULL)) {
+		g_free (cmd_line);
+		return NULL;
+	}
+	g_free (cmd_line);
+
+	if (version_regex == NULL) {
+		version_regex = g_regex_new ("\\d\\.\\d", 0, 0, NULL);
+	}
+
+	if (g_regex_match (version_regex, standard_output, 0, &match_info)) {
+		while (g_match_info_matches (match_info)) {
+			version_number = g_match_info_fetch (match_info, 0);
+			break;
+		}
+		g_match_info_free (match_info);
+		g_free (standard_output);
+	} else {
+		/* Failed to parse httpd version number */
+		g_warning ("Could not parse '%s' as a version for httpd", standard_output);
+		g_free (standard_output);
+		/* assume it is 2.2 */
+		version_number = g_strdup ("2.2");
+	}
+
+	config = g_strdup_printf (HTTPD_CONFIG_TEMPLATE, version_number);
+	g_free (version_number);
+
+	return config;
+}
+
+static gboolean
+spawn_httpd (int port, pid_t *pid_out)
+{
+	char *free1, *free2, *free3, *free4, *free5, *free6, *free7, *free8, *free9;
+	gboolean res;
+	char *argv[10];
+	char *env[10];
+	int i;
+	gint status;
+	char *pid_filename;
+	char *pidfile;
+	GError *error;
+	gboolean got_pidfile;
+	GSettings *settings;
+	char *str;
+	char *public_dir;
+
+	public_dir = lookup_public_dir ();
+	ensure_conf_dir ();
+
+	i = 0;
+	free1 = argv[i++] = get_httpd_program ();
+	if (argv[0] == NULL) {
+		fprintf (stderr, "error finding httpd server\n");
+		return FALSE;
+	}
+
+	argv[i++] = "-f";
+	free2 = argv[i++] = get_httpd_config (argv[0]);
+	argv[i++] = "-C";
+	free3 = argv[i++] = g_strdup_printf ("Listen %d", port);
+
+	settings = g_settings_new (GSETTINGS_SCHEMA);
+	str = g_settings_get_string (settings,
+				       FILE_SHARING_REQUIRE_PASSWORD);
+
+	if (str && strcmp (str, "never") == 0) {
+		/* Do nothing */
+	} else if (str && strcmp (str, "on_write") == 0){
+		argv[i++] = "-D";
+		argv[i++] = "RequirePasswordOnWrite";
+	} else {
+		/* always, or safe fallback */
+		argv[i++] = "-D";
+		argv[i++] = "RequirePasswordAlways";
+	}
+	g_free (str);
+	g_object_unref (settings);
+
+	argv[i] = NULL;
+
+	i = 0;
+	free4 = env[i++] = g_strdup_printf ("HOME=%s", g_get_home_dir());
+	free5 = env[i++] = g_strdup_printf ("XDG_PUBLICSHARE_DIR=%s", public_dir);
+	free6 = env[i++] = g_strdup_printf ("XDG_CONFIG_HOME=%s", g_get_user_config_dir ());
+	free7 = env[i++] = g_strdup_printf ("GUS_SHARE_NAME=%s", get_share_name ());
+	free8 = env[i++] = g_strdup_printf ("GUS_LOGIN_LABEL=%s", "Please log in as the user guest");
+	free9 = env[i++] = g_strdup_printf ("HTTP_MODULES_PATH=%s",get_httpd_modules_path ());
+	env[i++] = "LANG=C";
+	env[i] = NULL;
+
+	pid_filename = g_build_filename (g_get_user_config_dir (), "user-share", "pid", NULL);
+
+	/* Remove pid file before spawning to avoid races with child and old pidfile */
+	unlink (pid_filename);
+
+	error = NULL;
+	res = g_spawn_sync (g_get_home_dir(),
+			    argv, env, 0,
+			    httpd_child_setup, NULL,
+			    NULL, NULL,
+			    &status,
+			    &error);
+	g_free (free1);
+	g_free (free2);
+	g_free (free3);
+	g_free (free4);
+	g_free (free5);
+	g_free (free6);
+	g_free (free7);
+	g_free (free8);
+	g_free (free9);
+	g_free (public_dir);
+
+	if (!res) {
+		fprintf (stderr, "error spawning httpd: %s\n",
+			 error->message);
+		g_error_free (error);
+		g_free (pid_filename);
+		return FALSE;
+	}
+
+	if (status != 0) {
+		g_free (pid_filename);
+		return FALSE;
+	}
+
+	got_pidfile = FALSE;
+	error = NULL;
+	for (i = 0; i < 5; i++) {
+		if (error != NULL)
+			g_error_free (error);
+		error = NULL;
+		if (g_file_get_contents (pid_filename, &pidfile, NULL, &error)) {
+			got_pidfile = TRUE;
+			*pid_out = atoi (pidfile);
+			g_free (pidfile);
+			break;
+		}
+		sleep (1);
+	}
+
+	g_free (pid_filename);
+
+	if (!got_pidfile) {
+		fprintf (stderr, "error opening httpd pidfile: %s\n", error->message);
+		g_error_free (error);
+		return FALSE;
+	}
+	return TRUE;
+}
+
+static void
+kill_httpd (void)
+{
+	if (httpd_pid != 0) {
+		kill (httpd_pid, SIGTERM);
+
+		/* Allow child time to die, we can't waitpid, because its
+		   not a direct child */
+		sleep (1);
+	}
+	httpd_pid = 0;
+}
+
+void
+http_up (void)
+{
+	guint port;
+
+	port = get_port ();
+	if (!spawn_httpd (port, &httpd_pid)) {
+		fprintf (stderr, "spawning httpd failed\n");
+	}
+}
+
+void
+http_down (void)
+{
+	kill_httpd ();
+}
+
+gboolean
+http_init (void)
+{
+	return TRUE;
+}
+
+pid_t
+http_get_pid (void)
+{
+	return httpd_pid;
+}
+
+
+
+
+ + + diff --git a/2021-02-23-075223-9463-cppcheck@8c6c291142e4_master/2.html b/2021-02-23-075223-9463-cppcheck@8c6c291142e4_master/2.html new file mode 100644 index 0000000..c95a0b0 --- /dev/null +++ b/2021-02-23-075223-9463-cppcheck@8c6c291142e4_master/2.html @@ -0,0 +1,1288 @@ + + + + + + Cppcheck - HTML report - mate-user-share + + + + + + +
+ +
+
  1
+  2
+  3
+  4
+  5
+  6
+  7
+  8
+  9
+ 10
+ 11
+ 12
+ 13
+ 14
+ 15
+ 16
+ 17
+ 18
+ 19
+ 20
+ 21
+ 22
+ 23
+ 24
+ 25
+ 26
+ 27
+ 28
+ 29
+ 30
+ 31
+ 32
+ 33
+ 34
+ 35
+ 36
+ 37
+ 38
+ 39
+ 40
+ 41
+ 42
+ 43
+ 44
+ 45
+ 46
+ 47
+ 48
+ 49
+ 50
+ 51
+ 52
+ 53
+ 54
+ 55
+ 56
+ 57
+ 58
+ 59
+ 60
+ 61
+ 62
+ 63
+ 64
+ 65
+ 66
+ 67
+ 68
+ 69
+ 70
+ 71
+ 72
+ 73
+ 74
+ 75
+ 76
+ 77
+ 78
+ 79
+ 80
+ 81
+ 82
+ 83
+ 84
+ 85
+ 86
+ 87
+ 88
+ 89
+ 90
+ 91
+ 92
+ 93
+ 94
+ 95
+ 96
+ 97
+ 98
+ 99
+100
+101
+102
+103
+104
+105
+106
+107
+108
+109
+110
+111
+112
+113
+114
+115
+116
+117
+118
+119
+120
+121
+122
+123
+124
+125
+126
+127
+128
+129
+130
+131
+132
+133
+134
+135
+136
+137
+138
+139
+140
+141
+142
+143
+144
+145
+146
+147
+148
+149
+150
+151
+152
+153
+154
+155
+156
+157
+158
+159
+160
+161
+162
+163
+164
+165
+166
+167
+168
+169
+170
+171
+172
+173
+174
+175
+176
+177
+178
+179
+180
+181
+182
+183
+184
+185
+186
+187
+188
+189
+190
+191
+192
+193
+194
+195
+196
+197
+198
+199
+200
+201
+202
+203
+204
+205
+206
+207
+208
+209
+210
+211
+212
+213
+214
+215
+216
+217
+218
+219
+220
+221
+222
+223
+224
+225
+226
+227
+228
+229
+230
+231
+232
+233
+234
+235
+236
+237
+238
+239
+240
+241
+242
+243
+244
+245
+246
+247
+248
+249
+250
+251
+252
+253
+254
+255
+256
+257
+258
+259
+260
+261
+262
+263
+264
+265
+266
+267
+268
+269
+270
+271
+272
+273
+274
+275
+276
+277
+278
+279
+280
+281
+282
+283
+284
+285
+286
+287
+288
+289
+290
+291
+292
+293
+294
+295
+296
+297
+298
+299
+300
+301
+302
+303
+304
+305
+306
+307
+308
+309
+310
+311
+312
+313
+314
+315
+316
+317
+318
+319
+320
+321
+322
+323
+324
+325
+326
+327
+328
+329
+330
+331
+332
+333
+334
+335
+336
+337
+338
+339
+340
+341
+342
+343
+344
+345
+346
+347
+348
+349
+350
+351
+352
+353
+354
+355
+356
+357
+358
+359
+360
+361
+362
+363
+364
+365
+366
+367
+368
+369
+370
+371
+372
+373
+374
+375
+376
+377
+378
+379
+380
+381
+382
+383
+384
+385
+386
+387
+388
+389
+390
+391
+392
+393
+394
+395
+396
+397
+398
+399
+400
+401
+402
+403
+404
+405
+406
+407
+408
+409
+410
+411
+412
+413
+414
+415
+416
+417
+418
+419
+420
+421
+422
+423
+424
+425
+426
+427
+428
+429
+430
+431
+432
+433
+434
+435
+436
+437
+438
+439
+440
+441
+442
+443
+444
+445
+446
+447
+448
+449
+450
+451
+452
+453
+454
+455
+456
+457
+458
+459
+460
+461
+462
+463
+464
+465
+466
+467
+468
+469
+470
+471
+472
+473
+474
+475
+476
+477
+478
+479
+480
+481
+482
+483
+484
+485
+486
+487
+488
+489
+490
+491
+492
+493
+494
+495
+496
+497
+498
+499
+500
+501
+502
+503
+504
+505
+506
+507
+508
+509
+510
+511
+512
+513
+514
+515
+516
+517
+518
+519
+520
+521
+522
+523
+524
+525
+526
+527
+528
+529
+530
+531
+532
+533
+534
+535
+536
+537
+538
+539
+540
+541
+542
+543
+544
+545
+546
+547
+548
+549
+550
+551
+552
+553
+554
+555
+556
+557
+558
+559
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
+
+/*
+ *  Copyright (C) 2004-2008 Red Hat, Inc.
+ *
+ *  Caja is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU General Public License as
+ *  published by the Free Software Foundation; either version 2 of the
+ *  License, or (at your option) any later version.
+ *
+ *  Caja is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  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
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ *  Authors: Bastien Nocera <hadess@hadess.net>
+ *
+ */
+
+#include "config.h"
+
+#include <glib.h>
+#include <glib/gi18n.h>
+#include <gio/gio.h>
+#include <gdk/gdk.h>
+#include <gtk/gtk.h>
+#include <libnotify/notify.h>
+#include <dbus/dbus-glib.h>
+#include <dbus/dbus-glib-lowlevel.h>
+#include <canberra-gtk.h>
+
+#include <string.h>
+
+#include "marshal.h"
+#include "obexpush.h"
+#include "user_share-common.h"
+#include "user_share-private.h"
+
+#define DBUS_TYPE_G_STRING_VARIANT_HASHTABLE (dbus_g_type_get_map ("GHashTable", G_TYPE_STRING, G_TYPE_STRING))
+
+#define GSETTINGS_SCHEMA "org.mate.FileSharing"
+
+static DBusGConnection *connection = NULL;<--- Shadowed declaration
+static DBusGProxy *manager_proxy = NULL;
+static DBusGProxy *server_proxy = NULL;
+static AcceptSetting accept_setting = -1;
+static gboolean show_notifications = FALSE;
+
+static GtkStatusIcon *statusicon = NULL;
+static guint num_notifications = 0;
+
+static void
+hide_statusicon (void)
+{
+	num_notifications--;
+	if (num_notifications == 0)
+		gtk_status_icon_set_visible (statusicon, FALSE);
+}
+
+static void
+on_close_notification (NotifyNotification *notification)
+{
+	hide_statusicon ();
+	g_object_unref (notification);
+}
+
+static void
+notification_launch_action_on_file_cb (NotifyNotification *notification,
+				       const char *action,
+				       const char *file_uri)
+{
+	GdkScreen *screen;
+	GAppLaunchContext *ctx;
+	GTimeVal val;
+
+	g_assert (action != NULL);
+
+	g_get_current_time (&val);
+
+	ctx = G_APP_LAUNCH_CONTEXT (gdk_app_launch_context_new ());
+	screen = gdk_screen_get_default ();
+	gdk_app_launch_context_set_screen (GDK_APP_LAUNCH_CONTEXT (ctx), screen);
+	gdk_app_launch_context_set_timestamp (GDK_APP_LAUNCH_CONTEXT (ctx), val.tv_sec);
+
+	/* We launch the file viewer for the file */
+	if (g_str_equal (action, "display") != FALSE) {
+		if (g_app_info_launch_default_for_uri (file_uri, ctx, NULL) == FALSE) {
+			g_warning ("Failed to launch the file viewer\n");
+		}
+	}
+
+	/* we open the Downloads folder */
+	if (g_str_equal (action, "reveal") != FALSE) {
+		GFile *file;
+		GFile *parent;
+		gchar *parent_uri;
+
+		file = g_file_new_for_uri (file_uri);
+		parent = g_file_get_parent (file);
+		parent_uri = g_file_get_uri (parent);
+		g_object_unref (file);
+		g_object_unref (parent);
+
+		if (!g_app_info_launch_default_for_uri (parent_uri, ctx, NULL)) {
+			g_warning ("Failed to launch the file manager\n");
+		}
+
+		g_free (parent_uri);
+	}
+
+	notify_notification_close (notification, NULL);
+	/* No need to call hide_statusicon(), closing the notification
+	 * will call the close callback */
+}
+
+static void
+show_notification (const char *filename)
+{
+	char *file_uri, *notification_text, *display, *mime_type;
+	NotifyNotification *notification;
+	ca_context *ctx;
+	GAppInfo *app;
+
+	file_uri = g_filename_to_uri (filename, NULL, NULL);
+	if (file_uri == NULL) {
+		g_warning ("Could not make a filename from '%s'", filename);
+		return;
+	}
+
+	display = g_filename_display_basename (filename);
+	/* Translators: %s is the name of the filename received */
+	notification_text = g_strdup_printf(_("You received \"%s\" via Bluetooth"), display);
+	g_free (display);
+	notification = notify_notification_new (_("You received a file"),
+								 notification_text,
+								 "dialog-information");
+
+	notify_notification_set_timeout (notification, NOTIFY_EXPIRES_DEFAULT);
+
+	mime_type = g_content_type_guess (filename, NULL, 0, NULL);
+	app = g_app_info_get_default_for_type (mime_type, FALSE);
+	if (app != NULL) {
+		g_object_unref (app);
+		notify_notification_add_action (notification, "display", _("Open File"),
+						(NotifyActionCallback) notification_launch_action_on_file_cb,
+						g_strdup (file_uri), (GFreeFunc) g_free);
+	}
+	notify_notification_add_action (notification, "reveal", _("Reveal File"),
+					(NotifyActionCallback) notification_launch_action_on_file_cb,
+					g_strdup (file_uri), (GFreeFunc) g_free);
+
+	g_free (file_uri);
+
+	g_signal_connect (G_OBJECT (notification), "closed", G_CALLBACK (on_close_notification), notification);
+
+	if (!notify_notification_show (notification, NULL)) {
+		g_warning ("failed to send notification\n");
+	}
+	g_free (notification_text);
+
+	/* Now we do the audio notification */
+	ctx = ca_gtk_context_get ();
+	ca_context_play (ctx, 0,
+			 CA_PROP_EVENT_ID, "complete-download",
+			 CA_PROP_EVENT_DESCRIPTION, _("File reception complete"),
+			 NULL);
+}
+
+static void
+show_icon (void)
+{
+	if (statusicon == NULL) {
+		statusicon = gtk_status_icon_new_from_icon_name ("mate-obex-server");
+	} else {
+		gtk_status_icon_set_visible (statusicon, TRUE);
+	}
+	num_notifications++;
+}
+
+static gboolean
+device_is_authorised (const char *bdaddr)
+{
+	DBusGConnection *connection;<--- Shadow variable
+	DBusGProxy *manager;
+	GError *error = NULL;
+	GPtrArray *adapters;
+	gboolean retval = FALSE;
+	guint i;
+
+	connection = dbus_g_bus_get (DBUS_BUS_SYSTEM, NULL);
+	if (connection == NULL)
+		return FALSE;
+
+	manager = dbus_g_proxy_new_for_name (connection, "org.bluez",
+					     "/", "org.bluez.Manager");
+	if (manager == NULL) {
+		dbus_g_connection_unref (connection);
+		return FALSE;
+	}
+
+	if (dbus_g_proxy_call (manager, "ListAdapters", &error, G_TYPE_INVALID, dbus_g_type_get_collection ("GPtrArray", DBUS_TYPE_G_OBJECT_PATH), &adapters, G_TYPE_INVALID) == FALSE) {
+		g_object_unref (manager);
+		dbus_g_connection_unref (connection);
+		return FALSE;
+	}
+
+	for (i = 0; i < adapters->len; i++) {
+		DBusGProxy *adapter, *device;
+		char *device_path;
+		GHashTable *props;
+
+		g_debug ("checking adapter %s", (gchar *) g_ptr_array_index (adapters, i));
+
+		adapter = dbus_g_proxy_new_for_name (connection, "org.bluez",
+						    g_ptr_array_index (adapters, i), "org.bluez.Adapter");
+
+		if (dbus_g_proxy_call (adapter, "FindDevice", NULL,
+				       G_TYPE_STRING, bdaddr, G_TYPE_INVALID,
+				       DBUS_TYPE_G_OBJECT_PATH, &device_path, G_TYPE_INVALID) == FALSE)
+		{
+			g_object_unref (adapter);
+			continue;
+		}
+
+		device = dbus_g_proxy_new_for_name (connection, "org.bluez", device_path, "org.bluez.Device");
+
+		if (dbus_g_proxy_call (device, "GetProperties", NULL,
+				       G_TYPE_INVALID, dbus_g_type_get_map ("GHashTable", G_TYPE_STRING, G_TYPE_VALUE),
+				       &props, G_TYPE_INVALID) != FALSE)
+		{
+			GValue *value;
+			gboolean bonded;
+
+			value = g_hash_table_lookup (props, "Paired");
+			bonded = g_value_get_boolean (value);
+			g_message ("%s is %s", bdaddr, bonded ? "bonded" : "not bonded");
+
+			if (bonded) {
+				g_hash_table_destroy (props);
+				g_object_unref (device);
+				g_object_unref (adapter);
+				retval = TRUE;
+				break;
+			}
+		}
+		g_object_unref(adapter);
+	}
+
+	g_ptr_array_free (adapters, TRUE);
+
+	g_object_unref(manager);
+	dbus_g_connection_unref(connection);
+
+	return retval;
+}
+
+static void
+transfer_started_cb (DBusGProxy *session,
+		     const char *filename,
+		     const char *local_path,
+		     guint64 size,
+		     gpointer user_data)
+{
+	GHashTable *dict;
+	DBusGProxy *server = (DBusGProxy *) user_data;
+	GError *error = NULL;
+	gboolean authorise;
+
+	g_message ("transfer started on %s", local_path);
+	g_object_set_data_full (G_OBJECT (session), "filename", g_strdup (local_path), (GDestroyNotify) g_free);
+
+	show_icon ();
+
+	/* First transfer of the session */
+	if (g_object_get_data (G_OBJECT (session), "bdaddr") == NULL) {
+		const char *bdaddr;
+
+		if (dbus_g_proxy_call (server, "GetServerSessionInfo", &error,
+				       DBUS_TYPE_G_OBJECT_PATH, dbus_g_proxy_get_path (session), G_TYPE_INVALID,
+				       DBUS_TYPE_G_STRING_VARIANT_HASHTABLE, &dict, G_TYPE_INVALID) == FALSE) {
+			g_printerr ("Getting Server session info failed: %s\n",
+				    error->message);
+			g_error_free (error);
+			return;
+		}
+
+		bdaddr = g_hash_table_lookup (dict, "BluetoothAddress");
+		g_message ("transfer started for device %s", bdaddr);
+
+		g_object_set_data_full (G_OBJECT (session), "bdaddr", g_strdup (bdaddr), (GDestroyNotify) g_free);
+		/* Initial accept method is undefined, we do that lower down */
+		g_object_set_data (G_OBJECT (session), "accept-method", GINT_TO_POINTER (-1));
+		g_hash_table_destroy (dict);
+	}
+
+	/* Accept method changed */
+	if (GPOINTER_TO_INT (g_object_get_data (G_OBJECT (session), "accept-method")) != accept_setting) {
+		const char *bdaddr;
+
+		bdaddr = g_object_get_data (G_OBJECT (session), "bdaddr");
+
+		if (bdaddr == NULL) {
+			g_warning ("Couldn't get the Bluetooth address for the device, rejecting the transfer");
+			authorise = FALSE;
+		} else if (accept_setting == ACCEPT_ALWAYS) {
+			authorise = TRUE;
+		} else if (accept_setting == ACCEPT_BONDED) {
+			authorise = device_is_authorised (bdaddr);
+		} else {
+			//FIXME implement
+			g_warning ("\"Ask\" authorisation method not implemented");
+			authorise = FALSE;
+		}
+		g_object_set_data (G_OBJECT (session), "authorise", GINT_TO_POINTER (authorise));
+	}
+
+	g_message ("accept_setting: %d", accept_setting);
+
+	authorise = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (session), "authorise"));
+	if (authorise != FALSE) {
+		if (dbus_g_proxy_call (session, "Accept", &error, G_TYPE_INVALID, G_TYPE_INVALID) == FALSE) {
+			g_printerr ("Failed to accept file transfer: %s\n", error->message);
+			g_error_free (error);
+			return;
+		}
+		g_message ("authorised transfer");
+	} else {
+		if (dbus_g_proxy_call (session, "Reject", &error, G_TYPE_INVALID, G_TYPE_INVALID) == FALSE) {
+			g_printerr ("Failed to reject file transfer: %s\n", error->message);
+			g_error_free (error);
+			return;
+		}
+		g_message ("rejected transfer");
+		g_object_set_data (G_OBJECT (session), "filename", NULL);
+	}
+}
+
+static void
+transfer_completed_cb (DBusGProxy *session,
+		       gpointer user_data)
+{
+	GSettings *settings;
+	gboolean display_notify;
+	const char *filename;
+
+	filename = (const char *) g_object_get_data (G_OBJECT (session), "filename");
+
+	g_message ("file finish transfer: %s", filename);
+
+	if (filename == NULL)
+		return;
+
+	settings = g_settings_new (GSETTINGS_SCHEMA);
+	display_notify = g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_OBEXPUSH_NOTIFY);
+	g_object_unref (settings);
+
+	if (display_notify) {
+		show_notification (filename);
+	} else {
+		hide_statusicon ();
+	}
+	g_object_set_data (G_OBJECT (session), "filename", NULL);
+}
+
+static void
+cancelled_cb (DBusGProxy *session,
+	      gpointer user_data)
+{
+	//FIXME implement properly, we never actually finished the transfer
+	g_message ("transfered was cancelled by the sender");
+	transfer_completed_cb (session, user_data);
+	hide_statusicon ();
+}
+
+static void
+error_occurred_cb (DBusGProxy *session,
+		   const char *error_name,
+		   const char *error_message,
+		   gpointer user_data)
+{
+	//FIXME implement properly
+	g_message ("transfer error occurred: %s", error_message);
+	transfer_completed_cb (session, user_data);
+}
+
+static void
+session_created_cb (DBusGProxy *server, const char *session_path, gpointer user_data)
+{
+	DBusGProxy *session;
+
+	session = dbus_g_proxy_new_for_name (connection,
+					     "org.openobex",
+					     session_path,
+					     "org.openobex.ServerSession");
+
+	dbus_g_proxy_add_signal (session, "TransferStarted",
+				 G_TYPE_STRING, G_TYPE_STRING, G_TYPE_UINT64, G_TYPE_INVALID);
+	dbus_g_proxy_connect_signal(session, "TransferStarted",
+				    G_CALLBACK (transfer_started_cb), server, NULL);
+	dbus_g_proxy_add_signal (session, "TransferCompleted",
+				 G_TYPE_INVALID, G_TYPE_INVALID);
+	dbus_g_proxy_connect_signal(session, "TransferCompleted",
+				    G_CALLBACK (transfer_completed_cb), server, NULL);
+	dbus_g_proxy_add_signal (session, "Cancelled",
+				 G_TYPE_INVALID, G_TYPE_INVALID);
+	dbus_g_proxy_connect_signal(session, "Cancelled",
+				    G_CALLBACK (cancelled_cb), server, NULL);
+	dbus_g_proxy_add_signal (session, "ErrorOccurred",
+				 G_TYPE_INVALID, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INVALID);
+	dbus_g_proxy_connect_signal(session, "ErrorOccurred",
+				    G_CALLBACK (error_occurred_cb), server, NULL);
+}
+
+void
+obexpush_up (void)
+{
+	GError *err = NULL;
+	char *download_dir, *server;
+
+	server = NULL;
+	if (manager_proxy == NULL) {
+		manager_proxy = dbus_g_proxy_new_for_name (connection,
+							   "org.openobex",
+							   "/org/openobex",
+							   "org.openobex.Manager");
+		if (dbus_g_proxy_call (manager_proxy, "CreateBluetoothServer",
+				       &err, G_TYPE_STRING, "00:00:00:00:00:00", G_TYPE_STRING, "opp", G_TYPE_BOOLEAN, FALSE, G_TYPE_INVALID,
+				       DBUS_TYPE_G_OBJECT_PATH, &server, G_TYPE_INVALID) == FALSE) {
+			g_printerr ("Creating Bluetooth ObexPush server failed: %s\n",
+				    err->message);
+			g_error_free (err);
+			g_object_unref (manager_proxy);
+			manager_proxy = NULL;
+			return;
+		}
+	}
+
+	download_dir = lookup_download_dir ();
+
+	if (server_proxy == NULL) {
+		server_proxy = dbus_g_proxy_new_for_name (connection,
+							   "org.openobex",
+							   server,
+							   "org.openobex.Server");
+		g_free (server);
+
+		dbus_g_proxy_add_signal (server_proxy, "SessionCreated",
+					 DBUS_TYPE_G_OBJECT_PATH, G_TYPE_INVALID);
+		dbus_g_proxy_connect_signal(server_proxy, "SessionCreated",
+					    G_CALLBACK (session_created_cb), NULL, NULL);
+	}
+
+	if (dbus_g_proxy_call (server_proxy, "Start", &err,
+			   G_TYPE_STRING, download_dir, G_TYPE_BOOLEAN, TRUE, G_TYPE_BOOLEAN, FALSE, G_TYPE_INVALID,
+			   G_TYPE_INVALID) == FALSE) {
+		if (g_error_matches (err, DBUS_GERROR, DBUS_GERROR_REMOTE_EXCEPTION) != FALSE &&
+		    dbus_g_error_has_name (err, "org.openobex.Error.Started") != FALSE) {
+		    	g_error_free (err);
+		    	g_message ("already started, ignoring error");
+		    	g_free (download_dir);
+		    	return;
+		}
+		g_printerr ("Starting Bluetooth ObexPush server failed: %s\n",
+			    err->message);
+		g_error_free (err);
+		g_free (download_dir);
+		g_object_unref (server_proxy);
+		server_proxy = NULL;
+		g_object_unref (manager_proxy);
+		manager_proxy = NULL;
+		return;
+	}
+
+	g_free (download_dir);
+}
+
+static void
+obexpush_stop (gboolean stop_manager)
+{
+	GError *err = NULL;
+
+	if (server_proxy == NULL)
+		return;
+
+	if (dbus_g_proxy_call (server_proxy, "Close", &err, G_TYPE_INVALID, G_TYPE_INVALID) == FALSE) {
+		if (g_error_matches (err, DBUS_GERROR, DBUS_GERROR_REMOTE_EXCEPTION) == FALSE ||
+		    dbus_g_error_has_name (err, "org.openobex.Error.NotStarted") == FALSE) {
+			g_printerr ("Stopping Bluetooth ObexPush server failed: %s\n",
+				    err->message);
+			g_error_free (err);
+			return;
+		}
+		g_error_free (err);
+	}
+
+	if (stop_manager != FALSE) {
+		g_object_unref (server_proxy);
+		server_proxy = NULL;
+		g_object_unref (manager_proxy);
+		manager_proxy = NULL;
+	}
+
+	//FIXME stop all the notifications
+}
+
+void
+obexpush_down (void)
+{
+	obexpush_stop (TRUE);
+}
+
+void
+obexpush_restart (void)
+{
+	obexpush_stop (FALSE);
+	obexpush_up ();
+}
+
+gboolean
+obexpush_init (void)
+{
+	GError *err = NULL;
+
+	connection = dbus_g_bus_get (DBUS_BUS_SESSION, &err);
+	if (connection == NULL) {
+		g_printerr ("Connecting to session bus failed: %s\n",
+			    err->message);
+		g_error_free (err);
+		return FALSE;
+	}
+
+	dbus_g_object_register_marshaller (marshal_VOID__STRING_STRING_UINT64,
+					   G_TYPE_NONE,
+					   G_TYPE_STRING, G_TYPE_STRING, G_TYPE_UINT64, G_TYPE_INVALID);
+
+	if (!notify_init("mate-user-share")) {
+		g_warning("Unable to initialize the notification system\n");
+        }
+
+	dbus_connection_set_exit_on_disconnect (dbus_g_connection_get_connection (connection), FALSE);
+
+	return TRUE;
+}
+
+void
+obexpush_set_accept_files_policy (AcceptSetting setting)
+{
+	accept_setting = setting;
+}
+
+void
+obexpush_set_notify (gboolean enabled)
+{
+	show_notifications = enabled;
+}
+
+
+
+
+ + + diff --git a/2021-02-23-075223-9463-cppcheck@8c6c291142e4_master/3.html b/2021-02-23-075223-9463-cppcheck@8c6c291142e4_master/3.html new file mode 100644 index 0000000..f2cda19 --- /dev/null +++ b/2021-02-23-075223-9463-cppcheck@8c6c291142e4_master/3.html @@ -0,0 +1,764 @@ + + + + + + Cppcheck - HTML report - mate-user-share + + + + + + +
+ +
+
  1
+  2
+  3
+  4
+  5
+  6
+  7
+  8
+  9
+ 10
+ 11
+ 12
+ 13
+ 14
+ 15
+ 16
+ 17
+ 18
+ 19
+ 20
+ 21
+ 22
+ 23
+ 24
+ 25
+ 26
+ 27
+ 28
+ 29
+ 30
+ 31
+ 32
+ 33
+ 34
+ 35
+ 36
+ 37
+ 38
+ 39
+ 40
+ 41
+ 42
+ 43
+ 44
+ 45
+ 46
+ 47
+ 48
+ 49
+ 50
+ 51
+ 52
+ 53
+ 54
+ 55
+ 56
+ 57
+ 58
+ 59
+ 60
+ 61
+ 62
+ 63
+ 64
+ 65
+ 66
+ 67
+ 68
+ 69
+ 70
+ 71
+ 72
+ 73
+ 74
+ 75
+ 76
+ 77
+ 78
+ 79
+ 80
+ 81
+ 82
+ 83
+ 84
+ 85
+ 86
+ 87
+ 88
+ 89
+ 90
+ 91
+ 92
+ 93
+ 94
+ 95
+ 96
+ 97
+ 98
+ 99
+100
+101
+102
+103
+104
+105
+106
+107
+108
+109
+110
+111
+112
+113
+114
+115
+116
+117
+118
+119
+120
+121
+122
+123
+124
+125
+126
+127
+128
+129
+130
+131
+132
+133
+134
+135
+136
+137
+138
+139
+140
+141
+142
+143
+144
+145
+146
+147
+148
+149
+150
+151
+152
+153
+154
+155
+156
+157
+158
+159
+160
+161
+162
+163
+164
+165
+166
+167
+168
+169
+170
+171
+172
+173
+174
+175
+176
+177
+178
+179
+180
+181
+182
+183
+184
+185
+186
+187
+188
+189
+190
+191
+192
+193
+194
+195
+196
+197
+198
+199
+200
+201
+202
+203
+204
+205
+206
+207
+208
+209
+210
+211
+212
+213
+214
+215
+216
+217
+218
+219
+220
+221
+222
+223
+224
+225
+226
+227
+228
+229
+230
+231
+232
+233
+234
+235
+236
+237
+238
+239
+240
+241
+242
+243
+244
+245
+246
+247
+248
+249
+250
+251
+252
+253
+254
+255
+256
+257
+258
+259
+260
+261
+262
+263
+264
+265
+266
+267
+268
+269
+270
+271
+272
+273
+274
+275
+276
+277
+278
+279
+280
+281
+282
+283
+284
+285
+286
+287
+288
+289
+290
+291
/* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 8; tab-width: 8 -*-
+ *
+ * Copyright (C) 2003 Novell, Inc.
+ * Copyright (C) 2003-2004 Red Hat, Inc.
+ * Copyright (C) 2005 William Jon McCann <mccann@jhu.edu>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * 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 Foundation, Inc., 51 Franklin St, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ *
+ */
+
+#include "config.h"
+
+#include <stdlib.h>
+#include <string.h>
+#include <glib/gi18n-lib.h>
+#include <gtk/gtk.h>
+#include <libcaja-extension/caja-menu-provider.h>
+#include <libcaja-extension/caja-location-widget-provider.h>
+
+#ifdef HAVE_BLUETOOTH
+#include <bluetooth-client.h>
+#endif
+
+#include "caja-share-bar.h"
+#include "user_share-common.h"
+
+#define CAJA_TYPE_USER_SHARE  (caja_user_share_get_type ())
+#define CAJA_USER_SHARE(o)    (G_TYPE_CHECK_INSTANCE_CAST ((o), CAJA_TYPE_USER_SHARE, CajaUserShare))
+#define CAJA_IS_USER_SHARE(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), CAJA_TYPE_USER_SHARE))
+
+typedef struct
+{
+        GObject              parent_slot;
+} CajaUserShare;
+
+typedef struct
+{
+        GObjectClass parent_slot;
+} CajaUserShareClass;
+
+static GType caja_user_share_get_type      (void);
+static void  caja_user_share_register_type (GTypeModule *module);
+
+static void
+launch_process (char **argv, GtkWindow *parent)
+{
+        GError *error;
+        GtkWidget *dialog;
+
+        error = NULL;
+        if (!g_spawn_async (NULL,
+                            argv, NULL,
+                            0,
+                            NULL, NULL,
+                            NULL,
+                            &error)) {
+
+
+                dialog = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL, GTK_MESSAGE_WARNING,
+						 GTK_BUTTONS_OK, _("Unable to launch the Personal File Sharing preferences"));
+
+                gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog), "%s", error->message);
+
+                gtk_dialog_run (GTK_DIALOG (dialog));
+                gtk_widget_destroy (dialog);
+
+                g_error_free (error);
+        }
+}
+
+static void
+launch_prefs_on_window (GtkWindow *window)
+{
+        char *argv [2];
+
+        argv [0] = g_build_filename (BINDIR, "mate-file-share-properties", NULL);
+        argv [1] = NULL;
+
+        launch_process (argv, window);
+
+        g_free (argv [0]);
+}
+
+static void
+bar_response_cb (CajaShareBar *bar,
+                 gint response,
+                 gpointer         data)
+{
+        if (response == CAJA_SHARE_BAR_RESPONSE_PREFERENCES) {
+                launch_prefs_on_window (GTK_WINDOW (data));
+        }
+}
+
+#ifdef HAVE_BLUETOOTH
+static void
+downloads_bar_set_from_bluetooth_status (GtkWidget *bar)
+{
+	BluetoothClient *client;
+	gboolean bt_powered;
+
+	client = g_object_get_data (G_OBJECT (bar), "bluetooth-client");
+	g_object_get (G_OBJECT (client),
+		      "default-adapter-powered", &bt_powered,
+		      NULL);
+	gtk_widget_set_visible (bar, bt_powered);
+}
+
+static void
+default_adapter_powered_cb (GObject    *gobject,
+			    GParamSpec *pspec,
+			    GtkWidget  *bar)
+{
+	downloads_bar_set_from_bluetooth_status (bar);
+}
+#endif /* HAVE_BLUETOOTH */
+
+static GtkWidget *
+caja_user_share_get_location_widget (CajaLocationWidgetProvider *iface,
+                                         const char                     *uri,
+                                         GtkWidget                      *window)
+{
+	GFile             *file;
+	GtkWidget         *bar;
+	guint              i;
+	gboolean           enable = FALSE;
+	GFile             *home;
+#ifdef HAVE_BLUETOOTH
+	const GUserDirectory special_dirs[] = { G_USER_DIRECTORY_PUBLIC_SHARE, G_USER_DIRECTORY_DOWNLOAD };
+
+	gboolean is_dir[] = { FALSE, FALSE };
+#else
+	const GUserDirectory special_dirs[] = { G_USER_DIRECTORY_PUBLIC_SHARE };
+
+	gboolean is_dir[] = { FALSE };
+#endif /* HAVE_BLUETOOTH */
+	file = g_file_new_for_uri (uri);
+	home = g_file_new_for_path (g_get_home_dir ());
+
+	/* We don't show anything in $HOME */
+	if (g_file_equal (home, file)) {
+		g_object_unref (home);
+		g_object_unref (file);
+		return NULL;
+	}
+
+	g_object_unref (home);
+
+	for (i = 0; i < G_N_ELEMENTS (special_dirs); i++) {
+		GFile *dir;
+		dir = lookup_dir_with_fallback (special_dirs[i]);
+		if (g_file_equal (dir, file)) {
+			enable = TRUE;
+			is_dir[i] = TRUE;
+		}
+		g_object_unref (dir);
+	}
+
+	g_object_unref (file);
+
+	if (enable == FALSE)
+		return NULL;
+
+	if (is_dir[0] != FALSE) {
+#ifdef HAVE_BLUETOOTH
+		if (is_dir[1] != FALSE) {
+			bar = caja_share_bar_new (_("May be used to share or receive files"));
+		} else {
+			bar = caja_share_bar_new (_("May be shared over the network or Bluetooth"));
+		}
+#else
+		bar = caja_share_bar_new (_("May be shared over the network"));
+#endif /* HAVE_BLUETOOTH */
+	} else {
+#ifdef HAVE_BLUETOOTH
+		BluetoothClient *client;
+
+		bar = caja_share_bar_new (_("May be used to receive files over Bluetooth"));
+
+		gtk_widget_set_no_show_all (bar, TRUE);
+		client = bluetooth_client_new ();
+		g_object_set_data_full (G_OBJECT (bar), "bluetooth-client", client, g_object_unref);
+		g_signal_connect (G_OBJECT (client), "notify::default-adapter-powered",
+				  G_CALLBACK (default_adapter_powered_cb), bar);
+		downloads_bar_set_from_bluetooth_status (bar);
+#endif /* HAVE_BLUETOOTH */
+	}
+
+	g_signal_connect (bar, "response",
+			  G_CALLBACK (bar_response_cb),
+			  window);
+
+	gtk_widget_show_all (bar);
+
+	return bar;
+}
+
+static void
+caja_user_share_location_widget_provider_iface_init (CajaLocationWidgetProviderIface *iface)
+{
+        iface->get_widget = caja_user_share_get_location_widget;
+}
+
+static void
+caja_user_share_instance_init (CajaUserShare *share)
+{
+
+}
+
+static void
+caja_user_share_class_init (CajaUserShareClass *klass)
+{
+
+}
+
+static GType share_type = 0;
+
+static GType
+caja_user_share_get_type (void)
+{
+        return share_type;
+}
+
+static void
+caja_user_share_register_type (GTypeModule *module)
+{
+        static const GTypeInfo info = {
+                sizeof (CajaUserShareClass),
+                (GBaseInitFunc) NULL,
+                (GBaseFinalizeFunc) NULL,
+                (GClassInitFunc) caja_user_share_class_init,
+                NULL,
+                NULL,
+                sizeof (CajaUserShare),
+                0,
+                (GInstanceInitFunc) caja_user_share_instance_init,
+        };
+
+        static const GInterfaceInfo location_widget_provider_iface_info = {
+                (GInterfaceInitFunc) caja_user_share_location_widget_provider_iface_init,
+                NULL,
+                NULL
+        };
+
+        share_type = g_type_module_register_type (module,
+                                                 G_TYPE_OBJECT,
+                                                 "CajaUserShare",
+                                                 &info, 0);
+
+        g_type_module_add_interface (module,
+                                     share_type,
+                                     CAJA_TYPE_LOCATION_WIDGET_PROVIDER,
+                                     &location_widget_provider_iface_info);
+}
+
+void
+caja_module_initialize (GTypeModule *module)
+{
+        caja_user_share_register_type (module);
+        bindtextdomain (GETTEXT_PACKAGE, MATELOCALEDIR);
+        bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
+}
+
+void
+caja_module_shutdown (void)
+{
+}
+
+void
+caja_module_list_types (const GType **types,
+                            int          *num_types)
+{
+        static GType type_list [1];
+
+        type_list[0] = CAJA_TYPE_USER_SHARE;
+
+        *types = type_list;
+        *num_types = 1;
+}
+
+
+
+
+ + + diff --git a/2021-02-23-075223-9463-cppcheck@8c6c291142e4_master/4.html b/2021-02-23-075223-9463-cppcheck@8c6c291142e4_master/4.html new file mode 100644 index 0000000..06db2f5 --- /dev/null +++ b/2021-02-23-075223-9463-cppcheck@8c6c291142e4_master/4.html @@ -0,0 +1,1182 @@ + + + + + + Cppcheck - HTML report - mate-user-share + + + + + + +
+ +
+
  1
+  2
+  3
+  4
+  5
+  6
+  7
+  8
+  9
+ 10
+ 11
+ 12
+ 13
+ 14
+ 15
+ 16
+ 17
+ 18
+ 19
+ 20
+ 21
+ 22
+ 23
+ 24
+ 25
+ 26
+ 27
+ 28
+ 29
+ 30
+ 31
+ 32
+ 33
+ 34
+ 35
+ 36
+ 37
+ 38
+ 39
+ 40
+ 41
+ 42
+ 43
+ 44
+ 45
+ 46
+ 47
+ 48
+ 49
+ 50
+ 51
+ 52
+ 53
+ 54
+ 55
+ 56
+ 57
+ 58
+ 59
+ 60
+ 61
+ 62
+ 63
+ 64
+ 65
+ 66
+ 67
+ 68
+ 69
+ 70
+ 71
+ 72
+ 73
+ 74
+ 75
+ 76
+ 77
+ 78
+ 79
+ 80
+ 81
+ 82
+ 83
+ 84
+ 85
+ 86
+ 87
+ 88
+ 89
+ 90
+ 91
+ 92
+ 93
+ 94
+ 95
+ 96
+ 97
+ 98
+ 99
+100
+101
+102
+103
+104
+105
+106
+107
+108
+109
+110
+111
+112
+113
+114
+115
+116
+117
+118
+119
+120
+121
+122
+123
+124
+125
+126
+127
+128
+129
+130
+131
+132
+133
+134
+135
+136
+137
+138
+139
+140
+141
+142
+143
+144
+145
+146
+147
+148
+149
+150
+151
+152
+153
+154
+155
+156
+157
+158
+159
+160
+161
+162
+163
+164
+165
+166
+167
+168
+169
+170
+171
+172
+173
+174
+175
+176
+177
+178
+179
+180
+181
+182
+183
+184
+185
+186
+187
+188
+189
+190
+191
+192
+193
+194
+195
+196
+197
+198
+199
+200
+201
+202
+203
+204
+205
+206
+207
+208
+209
+210
+211
+212
+213
+214
+215
+216
+217
+218
+219
+220
+221
+222
+223
+224
+225
+226
+227
+228
+229
+230
+231
+232
+233
+234
+235
+236
+237
+238
+239
+240
+241
+242
+243
+244
+245
+246
+247
+248
+249
+250
+251
+252
+253
+254
+255
+256
+257
+258
+259
+260
+261
+262
+263
+264
+265
+266
+267
+268
+269
+270
+271
+272
+273
+274
+275
+276
+277
+278
+279
+280
+281
+282
+283
+284
+285
+286
+287
+288
+289
+290
+291
+292
+293
+294
+295
+296
+297
+298
+299
+300
+301
+302
+303
+304
+305
+306
+307
+308
+309
+310
+311
+312
+313
+314
+315
+316
+317
+318
+319
+320
+321
+322
+323
+324
+325
+326
+327
+328
+329
+330
+331
+332
+333
+334
+335
+336
+337
+338
+339
+340
+341
+342
+343
+344
+345
+346
+347
+348
+349
+350
+351
+352
+353
+354
+355
+356
+357
+358
+359
+360
+361
+362
+363
+364
+365
+366
+367
+368
+369
+370
+371
+372
+373
+374
+375
+376
+377
+378
+379
+380
+381
+382
+383
+384
+385
+386
+387
+388
+389
+390
+391
+392
+393
+394
+395
+396
+397
+398
+399
+400
+401
+402
+403
+404
+405
+406
+407
+408
+409
+410
+411
+412
+413
+414
+415
+416
+417
+418
+419
+420
+421
+422
+423
+424
+425
+426
+427
+428
+429
+430
+431
+432
+433
+434
+435
+436
+437
+438
+439
+440
+441
+442
+443
+444
+445
+446
+447
+448
+449
+450
+451
+452
+453
+454
+455
+456
+457
+458
+459
+460
+461
+462
+463
+464
+465
+466
+467
+468
+469
+470
+471
+472
+473
+474
+475
+476
+477
+478
+479
+480
+481
+482
+483
+484
+485
+486
+487
+488
+489
+490
+491
+492
+493
+494
+495
+496
+497
+498
+499
+500
+501
+502
+503
+504
+505
+506
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
+
+/*
+ *  Copyright (C) 2004-2008 Red Hat, Inc.
+ *
+ *  Caja is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU General Public License as
+ *  published by the Free Software Foundation; either version 2 of the
+ *  License, or (at your option) any later version.
+ *
+ *  Caja is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  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
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ *  Authors: Alexander Larsson <alexl@redhat.com>
+ *
+ */
+
+#include "config.h"
+
+#include <gdk/gdkx.h>
+#include <gtk/gtk.h>
+#include <glib/gi18n.h>
+#include <glib/gstdio.h>
+#include <gio/gio.h>
+#include <X11/Xlib.h>
+
+#include "user_share-private.h"
+#include "user_share-common.h"
+#include "http.h"
+
+#ifdef HAVE_BLUETOOTH
+#include <bluetooth-client.h>
+
+#include "obexftp.h"
+#include "obexpush.h"
+
+#endif /* HAVE_BLUETOOTH */
+
+#include <gio/gio.h>
+
+#include <stdarg.h>
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <signal.h>
+#include <unistd.h>
+
+static guint disabled_timeout_tag = 0;
+static GSettings* settings;<--- Shadowed declaration<--- Shadowed declaration<--- Shadowed declaration
+
+#define GSETTINGS_SCHEMA "org.mate.FileSharing"
+#define GSETTINGS_KEY_FILE_SHARING_ENABLED "enabled"
+#define GSETTINGS_KEY_FILE_SHARING_REQUIRE_PASSWORD "require-password"
+
+#ifdef HAVE_BLUETOOTH
+/* MATE Session */
+#define MATE_SESSION_DBUS_NAME      "org.gnome.SessionManager"
+#define MATE_SESSION_DBUS_OBJECT    "/org/gnome/SessionManager"
+#define MATE_SESSION_DBUS_INTERFACE "org.gnome.SessionManager"
+
+static GDBusProxy *session_proxy = NULL;
+static gboolean has_console = TRUE;
+
+static BluetoothClient *client = NULL;
+static gboolean bluetoothd_enabled = FALSE;
+
+#define OBEX_ENABLED (bluetoothd_enabled && has_console)
+
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_ENABLED "bluetooth-enabled"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_ALLOW_WRITE "bluetooth-allow-write"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_REQUIRE_PAIRING "bluetooth-require-pairing"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED "bluetooth-obexpush-enabled"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_ACCEPT_FILES "bluetooth-accept-files"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_NOTIFY "bluetooth-notify"
+
+
+static void
+obex_services_start (void)
+{
+	GSettings *settings;<--- Shadow variable
+
+	if (bluetoothd_enabled == FALSE ||
+	    has_console == FALSE)
+	    	return;
+
+	settings = g_settings_new(GSETTINGS_SCHEMA);
+
+	if (g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED) == TRUE) {
+	    obexpush_up ();
+	}
+	if (g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_ENABLED) == TRUE) {
+	    obexftp_up ();
+	}
+
+	g_object_unref (client);
+}
+
+static void
+obex_services_shutdown (void)
+{
+	obexpush_down ();
+	obexftp_down ();
+}
+
+static void
+session_properties_changed_cb (GDBusProxy      *session,
+			       GVariant        *changed,
+			       char           **invalidated,
+			       gpointer         user_data)
+{
+	GVariant *v;
+
+	v = g_variant_lookup_value (changed, "SessionIsActive", G_VARIANT_TYPE_BOOLEAN);
+	if (v) {
+		has_console = g_variant_get_boolean (v);
+		g_debug ("Received session is active change: now %s", has_console ? "active" : "inactive");
+
+		if (has_console)
+			obex_services_start ();
+		else
+			obex_services_shutdown ();
+
+		g_variant_unref (v);
+	}
+}
+
+static gboolean
+is_session_active (void)
+{
+	GVariant *variant;
+	gboolean is_session_active = FALSE;
+
+	variant = g_dbus_proxy_get_cached_property (session_proxy,
+						    "SessionIsActive");
+	if (variant) {
+		is_session_active = g_variant_get_boolean (variant);
+		g_variant_unref (variant);
+ 	}
+
+	return is_session_active;
+}
+
+static void
+session_init (void)
+{
+	GError *error = NULL;
+
+	session_proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION,
+						       G_DBUS_PROXY_FLAGS_NONE,
+						       NULL,
+						       MATE_SESSION_DBUS_NAME,
+						       MATE_SESSION_DBUS_OBJECT,
+						       MATE_SESSION_DBUS_INTERFACE,
+						       NULL,
+						       &error);
+	if (session_proxy == NULL) {
+		g_warning ("Failed to get session proxy: %s", error->message);
+		g_error_free (error);
+		return;
+	}
+	g_signal_connect (session_proxy, "g-properties-changed",
+			  G_CALLBACK (session_properties_changed_cb),
+			  NULL);
+	has_console = is_session_active ();
+}
+
+static void
+default_adapter_changed (GObject    *gobject,
+			 GParamSpec *pspec,
+			 gpointer    user_data)
+{
+	char *adapter;
+	gboolean adapter_powered;
+
+	g_object_get (G_OBJECT (client),
+		      "default-adapter", &adapter,
+		      "default-adapter-powered", &adapter_powered,
+		      NULL);
+	if (adapter != NULL && *adapter != '\0') {
+		bluetoothd_enabled = adapter_powered;
+	} else {
+		bluetoothd_enabled = FALSE;
+	}
+
+	/* Were we called as init, or as a callback */
+	if (gobject != NULL) {
+		if (bluetoothd_enabled != FALSE)
+			obex_services_start ();
+		else
+			obex_services_shutdown ();
+	}
+}
+
+static void
+bluez_init (void)
+{
+	client = bluetooth_client_new ();
+	default_adapter_changed (NULL, NULL, NULL);
+	g_signal_connect (G_OBJECT (client), "notify::default-adapter",
+			  G_CALLBACK (default_adapter_changed), NULL);
+	g_signal_connect (G_OBJECT (client), "notify::default-adapter-powered",
+			  G_CALLBACK (default_adapter_changed), NULL);
+}
+#endif /* HAVE_BLUETOOTH */
+
+static gboolean
+file_sharing_enabled (void)
+{
+	gboolean enabled = TRUE;
+	settings = g_settings_new (GSETTINGS_SCHEMA);
+
+#ifdef HAVE_BLUETOOTH
+	if (g_settings_get_boolean (settings, FILE_SHARING_ENABLED) == FALSE &&
+	    g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_ENABLED) == FALSE &&
+	    g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED) == FALSE)
+#else /* HAVE_BLUETOOTH */
+	if (g_settings_get_boolean (settings, FILE_SHARING_ENABLED) == FALSE)
+#endif /* HAVE_BLUETOOTH */
+		enabled = FALSE;
+
+	g_object_unref (settings);
+
+	return enabled;
+}
+
+static void
+migrate_old_configuration (void)
+{
+	const char *old_config_dir;
+	const char *new_config_dir;
+
+	old_config_dir = g_build_filename (g_get_home_dir (), ".mate2", "user-share", NULL);
+	new_config_dir = g_build_filename (g_get_user_config_dir (), "user-share", NULL);
+	if (g_file_test (old_config_dir, G_FILE_TEST_IS_DIR))
+		g_rename (old_config_dir, new_config_dir);
+
+}
+
+static void
+require_password_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	/* Need to restart to get new password setting */
+	if (http_get_pid () != 0) {
+		http_down ();
+		http_up ();
+	}
+}
+
+/* File sharing was disabled for some time, exit now */
+/* If we re-enable it in the ui, this will be restarted anyway */
+static gboolean
+disabled_timeout_callback (gpointer user_data)
+{
+	GSettings *settings = (GSettings *) user_data;<--- Shadow variable
+	http_down ();
+
+#ifdef HAVE_BLUETOOTH
+	if (g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_ENABLED) == FALSE &&
+	    g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED) == FALSE)
+		_exit (0);
+#else /* HAVE_BLUETOOTH */
+	if (g_settings_get_boolean (settings, FILE_SHARING_ENABLED) == FALSE)
+		_exit (0);
+#endif /* HAVE_BLUETOOTH */
+	return FALSE;
+}
+
+static void
+file_sharing_enabled_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	gboolean enabled;
+
+	if (disabled_timeout_tag != 0) {
+		g_source_remove (disabled_timeout_tag);
+		disabled_timeout_tag = 0;
+	}
+
+	enabled = g_settings_get_boolean (settings,
+					 FILE_SHARING_ENABLED);
+	if (enabled) {
+		if (http_get_pid () == 0) {
+			http_up ();
+		}
+	} else {
+		http_down ();
+		disabled_timeout_tag = g_timeout_add_seconds (3,
+							      (GSourceFunc)disabled_timeout_callback,
+							      settings);
+	}
+}
+
+#ifdef HAVE_BLUETOOTH
+static void
+file_sharing_bluetooth_allow_write_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	if (g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_ENABLED) != FALSE)
+		obexftp_restart ();
+}
+
+static void
+file_sharing_bluetooth_require_pairing_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	if (g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_ENABLED) != FALSE) {
+		/* We need to fully reset the session,
+		 * otherwise the new setting isn't taken into account */
+		obexftp_down ();
+		obexftp_up ();
+	}
+}
+
+static void
+file_sharing_bluetooth_enabled_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	if (g_settings_get_boolean (settings,
+				   FILE_SHARING_BLUETOOTH_ENABLED) == FALSE) {
+		obexftp_down ();
+		if (g_settings_get_boolean (settings, FILE_SHARING_ENABLED) == FALSE &&
+		    g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED) == FALSE) {
+			_exit (0);
+		}
+	} else if (OBEX_ENABLED) {
+		obexftp_up ();
+	}
+}
+
+static void
+file_sharing_bluetooth_obexpush_enabled_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	if (g_settings_get_boolean (settings,
+				   FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED) == FALSE) {
+		obexpush_down ();
+		if (g_settings_get_boolean (settings, FILE_SHARING_ENABLED) == FALSE &&
+		    g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_ENABLED) == FALSE) {
+			_exit (0);
+		}
+	} else if (OBEX_ENABLED) {
+		obexpush_up ();
+	}
+}
+
+static void
+file_sharing_bluetooth_obexpush_accept_files_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	AcceptSetting setting;
+	char *str;
+
+	str = g_settings_get_string (settings, FILE_SHARING_BLUETOOTH_OBEXPUSH_ACCEPT_FILES);
+	setting = accept_setting_from_string (str);
+	g_free (str);
+
+	obexpush_set_accept_files_policy (setting);
+}
+
+static void
+file_sharing_bluetooth_obexpush_notify_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	obexpush_set_notify (g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_OBEXPUSH_NOTIFY));
+}
+#endif /* HAVE_BLUETOOTH */
+
+static RETSIGTYPE
+cleanup_handler (int sig)
+{
+	http_down ();
+#ifdef HAVE_BLUETOOTH
+	obexftp_down ();
+	obexpush_down ();
+#endif /* HAVE_BLUETOOTH */
+	_exit (2);
+}
+
+static int
+x_io_error_handler (Display *xdisplay)
+{
+	http_down ();
+#ifdef HAVE_BLUETOOTH
+	obexftp_down ();
+#endif /* HAVE_BLUETOOTH */
+	_exit (2);
+}
+
+int
+main (int argc, char **argv)
+{
+	GSettings *settings;<--- Shadow variable
+	Display *xdisplay;
+	G_GNUC_UNUSED int x_fd;
+	Window selection_owner;
+	Atom xatom;
+
+	bindtextdomain (GETTEXT_PACKAGE, MATELOCALEDIR);
+	bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
+	textdomain (GETTEXT_PACKAGE);
+
+	gtk_init (&argc, &argv);
+
+	if (g_strcmp0 (g_get_real_name (), "root") == 0) {
+		g_warning ("mate-user-share cannot be started as root for security reasons.");
+		return 1;
+	}
+
+	signal (SIGPIPE, SIG_IGN);
+	signal (SIGINT, cleanup_handler);
+	signal (SIGHUP, cleanup_handler);
+	signal (SIGTERM, cleanup_handler);
+
+	xdisplay = GDK_DISPLAY_XDISPLAY (gdk_display_get_default ());
+	if (xdisplay == NULL) {
+		g_warning ("Can't open display");
+		return 1;
+	}
+
+	xatom = XInternAtom (xdisplay, "_MATE_USER_SHARE", FALSE);
+	selection_owner = XGetSelectionOwner (xdisplay, xatom);
+
+	if (selection_owner != None) {
+		/* There is an owner already, quit */
+		return 1;
+	}
+
+	selection_owner = XCreateSimpleWindow (xdisplay,
+					       RootWindow (xdisplay, 0),
+					       0, 0, 1, 1,
+					       0, 0, 0);
+	XSetSelectionOwner (xdisplay, xatom, selection_owner, CurrentTime);
+
+	if (XGetSelectionOwner (xdisplay, xatom) != selection_owner) {
+		/* Didn't get the selection */
+		return 1;
+	}
+
+	migrate_old_configuration ();
+
+	if (!file_sharing_enabled ())
+		return 1;
+
+	settings = g_settings_new (GSETTINGS_SCHEMA);
+
+	x_fd = ConnectionNumber (xdisplay);
+	XSetIOErrorHandler (x_io_error_handler);
+
+	if (http_init () == FALSE)
+		return 1;
+#ifdef HAVE_BLUETOOTH
+	if (obexftp_init () == FALSE)
+		return 1;
+	if (obexpush_init () == FALSE)
+		return 1;
+#endif /* HAVE_BLUETOOTH */
+
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_ENABLED,
+			     G_CALLBACK (file_sharing_enabled_changed), NULL);
+
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_REQUIRE_PASSWORD,
+			     G_CALLBACK (require_password_changed), NULL);
+
+#ifdef HAVE_BLUETOOTH
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_ENABLED,
+			     G_CALLBACK (file_sharing_bluetooth_enabled_changed), NULL);
+
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_ALLOW_WRITE,
+			     G_CALLBACK (file_sharing_bluetooth_allow_write_changed), NULL);
+
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_REQUIRE_PAIRING,
+			     G_CALLBACK (file_sharing_bluetooth_require_pairing_changed), NULL);
+
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED,
+			     G_CALLBACK (file_sharing_bluetooth_obexpush_enabled_changed), NULL);
+
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_ACCEPT_FILES,
+			     G_CALLBACK (file_sharing_bluetooth_obexpush_accept_files_changed), NULL);
+
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_NOTIFY,
+			     G_CALLBACK (file_sharing_bluetooth_obexpush_notify_changed), NULL);
+
+	bluez_init ();
+	session_init ();
+#endif /* HAVE_BLUETOOTH */
+
+	/* Initial setting */
+	file_sharing_enabled_changed (settings, NULL, NULL);
+#ifdef HAVE_BLUETOOTH
+	file_sharing_bluetooth_enabled_changed (settings, NULL, NULL);
+	file_sharing_bluetooth_obexpush_accept_files_changed (settings, NULL, NULL);
+	file_sharing_bluetooth_obexpush_notify_changed (settings, NULL, NULL);
+	file_sharing_bluetooth_obexpush_enabled_changed (settings, NULL, NULL);
+#endif /* HAVE_BLUETOOTH */
+
+	gtk_main ();
+
+	return 0;
+}
+
+
+
+
+ + + diff --git a/2021-02-23-075223-9463-cppcheck@8c6c291142e4_master/index.html b/2021-02-23-075223-9463-cppcheck@8c6c291142e4_master/index.html new file mode 100644 index 0000000..bbcd983 --- /dev/null +++ b/2021-02-23-075223-9463-cppcheck@8c6c291142e4_master/index.html @@ -0,0 +1,141 @@ + + + + + + Cppcheck - HTML report - mate-user-share + + + + + + +
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
LineIdCWESeverityMessage
missingIncludeinformationCppcheck cannot find all the include files (use --check-config for details)
src/file-share-properties.c
82variableScope398styleThe scope of the variable 'password' can be reduced.
97shadowVariable398styleLocal variable 'settings' shadows outer variable
105unusedVariable563styleUnused variable: accept_setting
249shadowVariable398styleLocal variable 'settings' shadows outer variable
273shadowVariable398styleLocal variable 'settings' shadows outer variable
294shadowVariable398styleLocal variable 'settings' shadows outer variable
323shadowVariable398styleLocal variable 'settings' shadows outer variable
340shadowVariable398styleLocal variable 'settings' shadows outer variable
357shadowVariable398styleLocal variable 'settings' shadows outer variable
377shadowVariable398styleLocal variable 'settings' shadows outer variable
393shadowVariable398styleLocal variable 'settings' shadows outer variable
457shadowVariable398styleLocal variable 'settings' shadows outer variable
620variableScope398styleThe scope of the variable 'window' can be reduced.
src/http.c
114variableScope398styleThe scope of the variable 'host_name' can be reduced.
src/obexpush.c
187shadowVariable398styleLocal variable 'connection' shadows outer variable
src/share-extension.c
61variableScope398styleThe scope of the variable 'dialog' can be reduced.
src/user_share.c
86shadowVariable398styleLocal variable 'settings' shadows outer variable
260shadowVariable398styleLocal variable 'settings' shadows outer variable
391shadowVariable398styleLocal variable 'settings' shadows outer variable
+
+
+ + + diff --git a/2021-02-23-075223-9463-cppcheck@8c6c291142e4_master/stats.html b/2021-02-23-075223-9463-cppcheck@8c6c291142e4_master/stats.html new file mode 100644 index 0000000..2020977 --- /dev/null +++ b/2021-02-23-075223-9463-cppcheck@8c6c291142e4_master/stats.html @@ -0,0 +1,109 @@ + + + + + + Cppcheck - HTML report - mate-user-share + + + + + + +
+ +
+

Top 10 files for style severity, total findings: 19
+   13  src/file-share-properties.c
+   3   src/user_share.c
+   1   src/share-extension.c
+   1   src/obexpush.c
+   1   src/http.c
+

+ +
+
+ + + diff --git a/2021-02-23-075223-9463-cppcheck@8c6c291142e4_master/style.css b/2021-02-23-075223-9463-cppcheck@8c6c291142e4_master/style.css new file mode 100644 index 0000000..07125f4 --- /dev/null +++ b/2021-02-23-075223-9463-cppcheck@8c6c291142e4_master/style.css @@ -0,0 +1,137 @@ + +body { + font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif; + font-size: 13px; + line-height: 1.5; + margin: 0; + width: auto; +} + +h1 { + margin: 10px; +} + +.header { + border-bottom: thin solid #aaa; +} + +.footer { + border-top: thin solid #aaa; + font-size: 90%; + margin-top: 5px; +} + +.footer ul { + list-style-type: none; + padding-left: 0; +} + +.footer > p { + margin: 4px; +} + +.wrapper { + display: -webkit-box; + display: -ms-flexbox; + display: flex; + -webkit-box-pack: justify; + -ms-flex-pack: justify; + justify-content: space-between; +} + +#menu, +#menu_index { + text-align: left; + width: 350px; + height: 90vh; + min-height: 200px; + overflow: auto; + position: -webkit-sticky; + position: sticky; + top: 0; + padding: 0 15px 15px 15px; +} + +#menu > a { + display: block; + margin-left: 10px; + font-size: 12px; + z-index: 1; +} + +#content, +#content_index { + background-color: #fff; + -webkit-box-sizing: content-box; + -moz-box-sizing: content-box; + box-sizing: content-box; + padding: 0 15px 15px 15px; + width: calc(100% - 350px); + height: 100%; + overflow-x: auto; +} + +#filename { + margin-left: 10px; + font-size: 12px; + z-index: 1; +} + +.error { + background-color: #ffb7b7; +} + +.error2 { + background-color: #faa; + display: inline-block; + margin-left: 4px; +} + +.inconclusive { + background-color: #b6b6b4; +} + +.inconclusive2 { + background-color: #b6b6b4; + display: inline-block; + margin-left: 4px; +} + +.verbose { + display: inline-block; + vertical-align: top; + cursor: help; +} + +.verbose .content { + display: none; + position: absolute; + padding: 10px; + margin: 4px; + max-width: 40%; + white-space: pre-wrap; + border: 1px solid #000; + background-color: #ffffcc; + cursor: auto; +} + +.highlight .hll { + padding: 1px; +} + +.highlighttable { + background-color: #fff; + z-index: 10; + position: relative; + margin: -10px; +} + +.linenos { + border-right: thin solid #aaa; + color: #d3d3d3; + padding-right: 6px; +} + +.d-none { + display: none; +} diff --git a/2021-03-09-235935-8562-cppcheck@52bc759bdcfd_master/0.html b/2021-03-09-235935-8562-cppcheck@52bc759bdcfd_master/0.html new file mode 100644 index 0000000..74c198b --- /dev/null +++ b/2021-03-09-235935-8562-cppcheck@52bc759bdcfd_master/0.html @@ -0,0 +1,1498 @@ + + + + + + Cppcheck - HTML report - mate-user-share + + + + + + +
+ +
+
  1
+  2
+  3
+  4
+  5
+  6
+  7
+  8
+  9
+ 10
+ 11
+ 12
+ 13
+ 14
+ 15
+ 16
+ 17
+ 18
+ 19
+ 20
+ 21
+ 22
+ 23
+ 24
+ 25
+ 26
+ 27
+ 28
+ 29
+ 30
+ 31
+ 32
+ 33
+ 34
+ 35
+ 36
+ 37
+ 38
+ 39
+ 40
+ 41
+ 42
+ 43
+ 44
+ 45
+ 46
+ 47
+ 48
+ 49
+ 50
+ 51
+ 52
+ 53
+ 54
+ 55
+ 56
+ 57
+ 58
+ 59
+ 60
+ 61
+ 62
+ 63
+ 64
+ 65
+ 66
+ 67
+ 68
+ 69
+ 70
+ 71
+ 72
+ 73
+ 74
+ 75
+ 76
+ 77
+ 78
+ 79
+ 80
+ 81
+ 82
+ 83
+ 84
+ 85
+ 86
+ 87
+ 88
+ 89
+ 90
+ 91
+ 92
+ 93
+ 94
+ 95
+ 96
+ 97
+ 98
+ 99
+100
+101
+102
+103
+104
+105
+106
+107
+108
+109
+110
+111
+112
+113
+114
+115
+116
+117
+118
+119
+120
+121
+122
+123
+124
+125
+126
+127
+128
+129
+130
+131
+132
+133
+134
+135
+136
+137
+138
+139
+140
+141
+142
+143
+144
+145
+146
+147
+148
+149
+150
+151
+152
+153
+154
+155
+156
+157
+158
+159
+160
+161
+162
+163
+164
+165
+166
+167
+168
+169
+170
+171
+172
+173
+174
+175
+176
+177
+178
+179
+180
+181
+182
+183
+184
+185
+186
+187
+188
+189
+190
+191
+192
+193
+194
+195
+196
+197
+198
+199
+200
+201
+202
+203
+204
+205
+206
+207
+208
+209
+210
+211
+212
+213
+214
+215
+216
+217
+218
+219
+220
+221
+222
+223
+224
+225
+226
+227
+228
+229
+230
+231
+232
+233
+234
+235
+236
+237
+238
+239
+240
+241
+242
+243
+244
+245
+246
+247
+248
+249
+250
+251
+252
+253
+254
+255
+256
+257
+258
+259
+260
+261
+262
+263
+264
+265
+266
+267
+268
+269
+270
+271
+272
+273
+274
+275
+276
+277
+278
+279
+280
+281
+282
+283
+284
+285
+286
+287
+288
+289
+290
+291
+292
+293
+294
+295
+296
+297
+298
+299
+300
+301
+302
+303
+304
+305
+306
+307
+308
+309
+310
+311
+312
+313
+314
+315
+316
+317
+318
+319
+320
+321
+322
+323
+324
+325
+326
+327
+328
+329
+330
+331
+332
+333
+334
+335
+336
+337
+338
+339
+340
+341
+342
+343
+344
+345
+346
+347
+348
+349
+350
+351
+352
+353
+354
+355
+356
+357
+358
+359
+360
+361
+362
+363
+364
+365
+366
+367
+368
+369
+370
+371
+372
+373
+374
+375
+376
+377
+378
+379
+380
+381
+382
+383
+384
+385
+386
+387
+388
+389
+390
+391
+392
+393
+394
+395
+396
+397
+398
+399
+400
+401
+402
+403
+404
+405
+406
+407
+408
+409
+410
+411
+412
+413
+414
+415
+416
+417
+418
+419
+420
+421
+422
+423
+424
+425
+426
+427
+428
+429
+430
+431
+432
+433
+434
+435
+436
+437
+438
+439
+440
+441
+442
+443
+444
+445
+446
+447
+448
+449
+450
+451
+452
+453
+454
+455
+456
+457
+458
+459
+460
+461
+462
+463
+464
+465
+466
+467
+468
+469
+470
+471
+472
+473
+474
+475
+476
+477
+478
+479
+480
+481
+482
+483
+484
+485
+486
+487
+488
+489
+490
+491
+492
+493
+494
+495
+496
+497
+498
+499
+500
+501
+502
+503
+504
+505
+506
+507
+508
+509
+510
+511
+512
+513
+514
+515
+516
+517
+518
+519
+520
+521
+522
+523
+524
+525
+526
+527
+528
+529
+530
+531
+532
+533
+534
+535
+536
+537
+538
+539
+540
+541
+542
+543
+544
+545
+546
+547
+548
+549
+550
+551
+552
+553
+554
+555
+556
+557
+558
+559
+560
+561
+562
+563
+564
+565
+566
+567
+568
+569
+570
+571
+572
+573
+574
+575
+576
+577
+578
+579
+580
+581
+582
+583
+584
+585
+586
+587
+588
+589
+590
+591
+592
+593
+594
+595
+596
+597
+598
+599
+600
+601
+602
+603
+604
+605
+606
+607
+608
+609
+610
+611
+612
+613
+614
+615
+616
+617
+618
+619
+620
+621
+622
+623
+624
+625
+626
+627
+628
+629
+630
+631
+632
+633
+634
+635
+636
+637
+638
+639
+640
+641
+642
+643
+644
+645
+646
+647
+648
+649
+650
+651
+652
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
+
+/*
+ *  Copyright (C) 2004 Red Hat, Inc.
+ *
+ *  Caja is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU General Public License as
+ *  published by the Free Software Foundation; either version 2 of the
+ *  License, or (at your option) any later version.
+ *
+ *  Caja is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  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
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ *  Authors: Alexander Larsson <alexl@redhat.com>
+ *
+ */
+
+#include "config.h"
+
+#include <string.h>
+#include <stdio.h>
+
+#include <gtk/gtk.h>
+#include <glib/gi18n.h>
+#include <gio/gio.h>
+
+#include "user_share-private.h"
+
+#define REALM "Please log in as the user guest"
+#define USER "guest"
+#define GSETTINGS_SCHEMA "org.mate.FileSharing"
+#define GSETTINGS_KEY_FILE_SHARING_ENABLED "enabled"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_ENABLED "bluetooth-enabled"
+#define GSETTINGS_KEY_FILE_SHARING_REQUIRE_PASSWORD "require-password"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_ALLOW_WRITE "bluetooth-allow-write"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_REQUIRE_PAIRING "bluetooth-require-pairing"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED "bluetooth-obexpush-enabled"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_ACCEPT_FILES "bluetooth-accept-files"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_NOTIFY "bluetooth-notify"
+
+static GtkBuilder* builder;
+static GSettings* settings;<--- Shadowed declaration<--- Shadowed declaration<--- Shadowed declaration<--- Shadowed declaration<--- Shadowed declaration<--- Shadowed declaration<--- Shadowed declaration<--- Shadowed declaration<--- Shadowed declaration<--- Shadowed declaration
+
+
+static void
+write_out_password (const char *password)
+{
+    char *to_hash;
+    char *ascii_digest;
+    char *line;
+    char *filename;
+    FILE *file;
+
+    to_hash = g_strdup_printf ("%s:%s:%s", USER, REALM, password);
+    ascii_digest = g_compute_checksum_for_string (G_CHECKSUM_MD5, to_hash, strlen (to_hash));
+    g_free (to_hash);
+    line = g_strdup_printf ("%s:%s:%s\n", USER, REALM, ascii_digest);
+    g_free (ascii_digest);
+
+    filename = g_build_filename (g_get_user_config_dir (), "user-share", "passwd", NULL);
+
+    file = fopen (filename, "w");
+    if (file != NULL) {
+	fwrite (line, strlen (line), 1, file);
+	fclose (file);
+    }
+
+    g_free (filename);
+    g_free (line);
+}
+
+static void
+flush_password (void)
+{
+    GtkWidget *password_entry;
+    const char *password;
+
+    password_entry = GTK_WIDGET (gtk_builder_get_object (builder, "password_entry"));
+
+    if (g_object_get_data (G_OBJECT( password_entry), "user_edited")) {
+	password = gtk_entry_get_text (GTK_ENTRY (password_entry));
+	if (password != NULL && password[0] != 0)
+	    write_out_password (password);
+    }
+}
+
+
+static void
+update_ui (void)
+{
+    GSettings *settings;<--- Shadow variable
+    gboolean enabled;
+#ifdef HAVE_BLUETOOTH
+    gboolean bluetooth_enabled, bluetooth_write_enabled, require_pairing_enabled;
+    gboolean bluetooth_obexpush_enabled, bluetooth_obexpush_notify;
+#endif /* HAVE_BLUETOOTH */
+    char *str;
+    PasswordSetting password_setting;
+    AcceptSetting accept_setting;<--- Unused variable: accept_setting
+    GtkWidget *check;
+    GtkWidget *password_combo;
+    GtkWidget *password_entry;
+#ifdef HAVE_BLUETOOTH
+    GtkWidget *vbox_share_bluetooth;
+    GtkWidget *vbox_receive_bluetooth;
+    GtkWidget *bluetooth_check;
+    GtkWidget *allow_write_bluetooth_check;
+    GtkWidget *require_pairing_check;
+    GtkWidget *enable_obexpush_check;
+    GtkWidget *accept_obexpush_combo;
+    GtkWidget *notify_received_obexpush_check;
+#endif /* HAVE_BLUETOOTH */
+
+    settings = g_settings_new (GSETTINGS_SCHEMA);
+
+    enabled = g_settings_get_boolean (settings,
+				     FILE_SHARING_ENABLED);
+
+    str = g_settings_get_string (settings, FILE_SHARING_REQUIRE_PASSWORD);
+    password_setting = password_setting_from_string (str);
+    g_free (str);
+
+#ifdef HAVE_BLUETOOTH
+    bluetooth_enabled = g_settings_get_boolean (settings,
+    					       FILE_SHARING_BLUETOOTH_ENABLED);
+    bluetooth_write_enabled = g_settings_get_boolean (settings,
+						     FILE_SHARING_BLUETOOTH_ALLOW_WRITE);
+    require_pairing_enabled = g_settings_get_boolean (settings,
+    						     FILE_SHARING_BLUETOOTH_REQUIRE_PAIRING);
+    bluetooth_obexpush_enabled = g_settings_get_boolean (settings,
+    							FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED);
+    bluetooth_obexpush_notify = g_settings_get_boolean (settings,
+    						       FILE_SHARING_BLUETOOTH_OBEXPUSH_NOTIFY);
+
+    str = g_settings_get_string (settings, FILE_SHARING_BLUETOOTH_OBEXPUSH_ACCEPT_FILES);
+    accept_setting = accept_setting_from_string (str);
+    g_free (str);
+#endif /* HAVE_BLUETOOTH */
+
+    check = GTK_WIDGET (gtk_builder_get_object (builder, "enable_check"));
+    password_combo = GTK_WIDGET (gtk_builder_get_object (builder, "password_combo"));
+    password_entry = GTK_WIDGET (gtk_builder_get_object (builder, "password_entry"));
+#ifdef HAVE_BLUETOOTH
+    vbox_share_bluetooth = GTK_WIDGET (gtk_builder_get_object (builder, "vbox_share_bluetooth"));
+    vbox_receive_bluetooth = GTK_WIDGET (gtk_builder_get_object (builder, "vbox_receive_bluetooth"));
+    bluetooth_check = GTK_WIDGET (gtk_builder_get_object (builder, "enable_bluetooth_check"));
+    allow_write_bluetooth_check = GTK_WIDGET (gtk_builder_get_object (builder, "allow_write_bluetooth_check"));
+    require_pairing_check = GTK_WIDGET (gtk_builder_get_object (builder, "require_pairing_check"));
+    enable_obexpush_check = GTK_WIDGET (gtk_builder_get_object (builder, "enable_obexpush_check"));
+    accept_obexpush_combo = GTK_WIDGET (gtk_builder_get_object (builder, "accept_obexpush_combo"));
+    notify_received_obexpush_check = GTK_WIDGET (gtk_builder_get_object (builder, "notify_received_obexpush_check"));
+#endif /* HAVE_BLUETOOTH */
+
+    /* Network */
+    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (check), enabled);
+    gtk_widget_set_sensitive (password_combo, enabled);
+    gtk_widget_set_sensitive (password_entry, enabled && password_setting != PASSWORD_NEVER);
+
+    gtk_combo_box_set_active (GTK_COMBO_BOX (password_combo),
+			      password_setting);
+
+#ifdef HAVE_BLUETOOTH
+    /* Bluetooth ObexFTP */
+    gtk_widget_set_visible (vbox_share_bluetooth, TRUE);
+    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (bluetooth_check), bluetooth_enabled);
+    gtk_widget_set_sensitive (allow_write_bluetooth_check, bluetooth_enabled);
+    gtk_widget_set_sensitive (require_pairing_check, bluetooth_enabled);
+
+    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (allow_write_bluetooth_check),
+    				  bluetooth_write_enabled);
+    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (require_pairing_check),
+    				  require_pairing_enabled);
+
+    /* Bluetooth ObexPush */
+    gtk_widget_set_visible (vbox_receive_bluetooth, TRUE);
+    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (enable_obexpush_check), bluetooth_obexpush_enabled);
+    gtk_widget_set_sensitive (accept_obexpush_combo, bluetooth_obexpush_enabled);
+    gtk_widget_set_sensitive (notify_received_obexpush_check, bluetooth_obexpush_enabled);
+
+    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (notify_received_obexpush_check),
+    				  bluetooth_obexpush_notify);
+
+    gtk_combo_box_set_active (GTK_COMBO_BOX (accept_obexpush_combo),
+    			      accept_setting);
+#endif /* HAVE_BLUETOOTH */
+
+    g_object_unref (settings);
+}
+
+static void
+file_sharing_enabled_changed (GSettings *settings, gchar *key, gpointer data)
+{
+    update_ui ();
+}
+
+static void
+password_required_changed (GSettings *settings, gchar *key, gpointer data)
+{
+    update_ui ();
+}
+
+#ifdef HAVE_BLUETOOTH
+static void
+file_sharing_bluetooth_enabled_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	update_ui ();
+}
+
+static void
+file_sharing_bluetooth_allow_write_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	update_ui ();
+}
+
+static void
+file_sharing_bluetooth_require_pairing_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	update_ui ();
+}
+
+static void
+file_sharing_bluetooth_obexpush_enabled_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	update_ui ();
+}
+
+static void
+file_sharing_bluetooth_obexpush_accept_files_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	update_ui ();
+}
+
+static void
+file_sharing_bluetooth_obexpush_notify_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	update_ui ();
+}
+#endif /* HAVE_BLUETOOTH */
+
+static void
+password_combo_changed (GtkComboBox *combo_box)
+{
+    GSettings *settings;<--- Shadow variable
+    guint setting;
+
+    setting = gtk_combo_box_get_active (combo_box);
+
+    settings = g_settings_new (GSETTINGS_SCHEMA) ;
+
+    g_settings_set_string (settings,
+			     FILE_SHARING_REQUIRE_PASSWORD,
+			     password_string_from_setting (setting));
+    g_object_unref (settings);
+}
+
+static void
+launch_share (void)
+{
+	if (!g_spawn_command_line_async (USER_SHARE_PROGRAM, NULL))
+		g_warning ("Unable to start mate-user-share program");
+}
+
+#ifdef HAVE_BLUETOOTH
+static void
+enable_bluetooth_check_toggled (GtkWidget *check)
+{
+	GSettings *settings;<--- Shadow variable
+	gboolean enabled;
+
+	enabled = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check));
+
+	settings = g_settings_new (GSETTINGS_SCHEMA) ;
+
+	g_settings_set_boolean (settings,
+			       FILE_SHARING_BLUETOOTH_ENABLED,
+			       enabled);
+
+	g_object_unref (settings);
+
+	if (enabled != FALSE)
+		launch_share ();
+}
+#endif /* HAVE_BLUETOOTH */
+
+static void
+enable_check_toggled (GtkWidget *check)
+{
+	GSettings *settings;<--- Shadow variable
+	gboolean enabled;
+
+	enabled = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check));
+
+	settings = g_settings_new (GSETTINGS_SCHEMA);
+
+	g_settings_set_boolean (settings,
+			       FILE_SHARING_ENABLED,
+			       enabled);
+
+	g_object_unref (settings);
+
+	if (enabled != FALSE)
+		launch_share ();
+}
+
+static void
+password_entry_changed (GtkEditable *editable)
+{
+	g_object_set_data (G_OBJECT (editable),
+			   "user_edited", GINT_TO_POINTER (1));
+	flush_password ();
+}
+
+#ifdef HAVE_BLUETOOTH
+static void
+bluetooth_allow_write_check_toggled (GtkWidget *check)
+{
+	GSettings *settings;<--- Shadow variable
+	gboolean enabled;
+
+	enabled = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check));
+
+	settings = g_settings_new (GSETTINGS_SCHEMA) ;
+
+	g_settings_set_boolean (settings,
+			       FILE_SHARING_BLUETOOTH_ALLOW_WRITE,
+			       enabled);
+
+	g_object_unref (settings);
+}
+
+static void
+bluetooth_require_pairing_check_toggled (GtkWidget *check)
+{
+	GSettings *settings;<--- Shadow variable
+	gboolean enabled;
+
+	enabled = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check));
+
+	settings = g_settings_new (GSETTINGS_SCHEMA) ;
+
+	g_settings_set_boolean (settings,
+			       FILE_SHARING_BLUETOOTH_REQUIRE_PAIRING,
+			       enabled);
+
+	g_object_unref (settings);
+}
+
+static void
+enable_obexpush_check_toggled (GtkWidget *check)
+{
+	GSettings *settings;<--- Shadow variable
+	gboolean enabled;
+
+	enabled = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check));
+
+	settings = g_settings_new (GSETTINGS_SCHEMA) ;
+
+	g_settings_set_boolean (settings,
+			       FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED,
+			       enabled);
+
+	g_object_unref (settings);
+
+	if (enabled != FALSE)
+		launch_share ();
+}
+
+static void
+accept_obexpush_combo_changed (GtkComboBox *combo_box)
+{
+    GSettings *settings;<--- Shadow variable
+    guint setting;
+
+    setting = gtk_combo_box_get_active (combo_box);
+
+    settings = g_settings_new (GSETTINGS_SCHEMA) ;
+
+    g_settings_set_string (settings,
+			     FILE_SHARING_BLUETOOTH_OBEXPUSH_ACCEPT_FILES,
+			     accept_string_from_setting (setting));
+    g_object_unref (settings);
+}
+
+static void
+notify_received_obexpush_check_toggled (GtkWidget *check)
+{
+	GSettings *settings;<--- Shadow variable
+	gboolean enabled;
+
+	enabled = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check));
+
+	settings = g_settings_new (GSETTINGS_SCHEMA) ;
+
+	g_settings_set_boolean (settings,
+			       FILE_SHARING_BLUETOOTH_OBEXPUSH_NOTIFY,
+			       enabled);
+
+	g_object_unref (settings);
+}
+#endif /* HAVE_BLUETOOTH */
+
+static GtkWidget *
+error_dialog (const char *title,
+	      const char *reason,
+	      GtkWindow *parent)
+{
+	GtkWidget *error_dialog;
+
+	if (reason == NULL)
+		reason = _("No reason");
+
+	error_dialog =
+		gtk_message_dialog_new (parent,
+					GTK_DIALOG_MODAL,
+					GTK_MESSAGE_ERROR,
+					GTK_BUTTONS_OK,
+					"%s", title);
+	gtk_message_dialog_format_secondary_text
+		(GTK_MESSAGE_DIALOG (error_dialog), "%s", reason);
+
+	gtk_window_set_title (GTK_WINDOW (error_dialog), ""); /* as per HIG */
+	gtk_container_set_border_width (GTK_CONTAINER (error_dialog), 5);
+	gtk_dialog_set_default_response (GTK_DIALOG (error_dialog),
+					 GTK_RESPONSE_OK);
+	gtk_window_set_modal (GTK_WINDOW (error_dialog), TRUE);
+
+	return error_dialog;
+}
+
+static void
+help_button_clicked (GtkButton *button, GtkWidget *window)
+{
+	GError *error = NULL;
+
+	if (gtk_show_uri_on_window (GTK_WINDOW (window), "help:mate-user-share", gtk_get_current_event_time (), &error) == FALSE) {
+		GtkWidget *dialog;
+
+		dialog = error_dialog (_("Could not display the help contents."), error->message, GTK_WINDOW (window));
+		g_signal_connect (G_OBJECT (dialog), "response", G_CALLBACK
+				  (gtk_widget_destroy), error_dialog);
+		gtk_window_present (GTK_WINDOW (dialog));
+
+		g_error_free (error);
+	}
+}
+
+static GtkWidget *
+create_window (void)
+{
+    GError *error = NULL;
+    GSettings *settings;<--- Shadow variable
+    GtkWidget *check;
+    GtkWidget *password_combo;
+    GtkWidget *password_entry;
+#ifdef HAVE_BLUETOOTH
+    GtkWidget *bluetooth_check;
+    GtkWidget *bluetooth_allow_write_check;
+    GtkWidget *require_pairing_check;
+    GtkWidget *enable_obexpush_check;
+    GtkWidget *accept_obexpush_combo;
+    GtkWidget *notify_received_obexpush_check;
+#endif /* HAVE_BLUETOOTH */
+    GtkWidget *window;
+    GtkListStore *store;
+    GtkCellRenderer *cell;
+    GtkTreeIter iter;
+
+    builder = gtk_builder_new ();
+    gtk_builder_add_from_file (builder, DATADIR"file-share-properties.ui", &error);
+
+    if (error) {
+      GtkWidget *dialog;
+
+      dialog = error_dialog (_("Could not build interface."), error->message, NULL);
+      gtk_dialog_run (GTK_DIALOG (dialog));
+      gtk_widget_destroy (dialog);
+
+      g_error_free (error);
+      return NULL;
+    }
+
+    window = GTK_WIDGET (gtk_builder_get_object (builder, "user_share_dialog"));
+
+    settings = g_settings_new (GSETTINGS_SCHEMA);
+
+    check = GTK_WIDGET (gtk_builder_get_object (builder, "enable_check"));
+    password_combo = GTK_WIDGET (gtk_builder_get_object (builder, "password_combo"));
+    password_entry = GTK_WIDGET (gtk_builder_get_object (builder, "password_entry"));
+#ifdef HAVE_BLUETOOTH
+    bluetooth_check = GTK_WIDGET (gtk_builder_get_object (builder, "enable_bluetooth_check"));
+    bluetooth_allow_write_check = GTK_WIDGET (gtk_builder_get_object (builder, "allow_write_bluetooth_check"));
+    require_pairing_check = GTK_WIDGET (gtk_builder_get_object (builder, "require_pairing_check"));
+    enable_obexpush_check = GTK_WIDGET (gtk_builder_get_object (builder, "enable_obexpush_check"));
+    accept_obexpush_combo = GTK_WIDGET (gtk_builder_get_object (builder, "accept_obexpush_combo"));
+    notify_received_obexpush_check = GTK_WIDGET (gtk_builder_get_object (builder, "notify_received_obexpush_check"));
+#endif /* HAVE_BLUETOOTH */
+
+    store = gtk_list_store_new (1, G_TYPE_STRING);
+    gtk_combo_box_set_model (GTK_COMBO_BOX (password_combo),
+			     GTK_TREE_MODEL (store));
+    cell = gtk_cell_renderer_text_new ();
+    gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (password_combo), cell, TRUE);
+    gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (password_combo), cell,
+				    "text", 0,
+				    NULL);
+
+    /* Keep in same order as enum */
+    gtk_list_store_append (store, &iter);
+    gtk_list_store_set (store, &iter, 0,
+			_("Never"), -1);
+    gtk_list_store_append (store, &iter);
+    gtk_list_store_set (store, &iter, 0,
+			_("When writing files"), -1);
+    gtk_list_store_append (store, &iter);
+    gtk_list_store_set (store, &iter, 0,
+			_("Always"), -1);
+    g_object_unref (store);
+
+    /* We can't read the password from the text, just set it to something */
+    gtk_entry_set_text (GTK_ENTRY (password_entry), "none");
+    g_object_set_data (G_OBJECT (password_entry),
+		       "user_edited", GINT_TO_POINTER (0));
+    g_signal_connect (password_entry,
+		      "changed", G_CALLBACK (password_entry_changed), NULL);
+
+#ifdef HAVE_BLUETOOTH
+    /* Accept files combo */
+    store = gtk_list_store_new (1, G_TYPE_STRING);
+    gtk_combo_box_set_model (GTK_COMBO_BOX (accept_obexpush_combo),
+			     GTK_TREE_MODEL (store));
+    cell = gtk_cell_renderer_text_new ();
+    gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (accept_obexpush_combo), cell, TRUE);
+    gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (accept_obexpush_combo), cell,
+				    "text", 0,
+				    NULL);
+
+    /* Keep in same order as enum */
+    gtk_list_store_append (store, &iter);
+    gtk_list_store_set (store, &iter, 0,
+			_("Always"), -1);
+    gtk_list_store_append (store, &iter);
+    gtk_list_store_set (store, &iter, 0,
+			_("Only for set up devices"), -1);
+    //FIXME implement
+#if 0
+    gtk_list_store_append (store, &iter);
+    gtk_list_store_set (store, &iter, 0,
+    			_("Ask"), -1);
+#endif
+    g_object_unref (store);
+#endif /* HAVE_BLUETOOTH */
+
+    g_signal_connect (check,
+		      "toggled", G_CALLBACK (enable_check_toggled), NULL);
+    g_signal_connect (password_combo,
+		      "changed", G_CALLBACK (password_combo_changed), NULL);
+#ifdef HAVE_BLUETOOTH
+    g_signal_connect (bluetooth_check,
+    		      "toggled", G_CALLBACK (enable_bluetooth_check_toggled), NULL);
+    g_signal_connect (bluetooth_allow_write_check,
+    		      "toggled", G_CALLBACK (bluetooth_allow_write_check_toggled), NULL);
+    g_signal_connect (require_pairing_check,
+    		      "toggled", G_CALLBACK (bluetooth_require_pairing_check_toggled), NULL);
+    g_signal_connect (enable_obexpush_check,
+    		      "toggled", G_CALLBACK (enable_obexpush_check_toggled), NULL);
+    g_signal_connect (accept_obexpush_combo,
+    		      "changed", G_CALLBACK (accept_obexpush_combo_changed), NULL);
+    g_signal_connect (notify_received_obexpush_check,
+    		      "toggled", G_CALLBACK (notify_received_obexpush_check_toggled), NULL);
+#endif /* HAVE_BLUETOOTH */
+
+    g_signal_connect_swapped (GTK_WIDGET (gtk_builder_get_object (builder, "close_button")),
+                              "clicked", G_CALLBACK (gtk_widget_destroy), window);
+    g_signal_connect (GTK_WIDGET (gtk_builder_get_object (builder, "help_button")),
+		      "clicked", G_CALLBACK (help_button_clicked),
+		      gtk_builder_get_object (builder, "user_share_dialog"));
+
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_ENABLED,
+			     G_CALLBACK (file_sharing_enabled_changed), NULL);
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_REQUIRE_PASSWORD,
+			     G_CALLBACK (password_required_changed), NULL);
+#ifdef HAVE_BLUETOOTH
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_ENABLED,
+			     G_CALLBACK (file_sharing_bluetooth_enabled_changed), NULL);
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_ALLOW_WRITE,
+			     G_CALLBACK (file_sharing_bluetooth_allow_write_changed), NULL);
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_REQUIRE_PAIRING,
+			     G_CALLBACK (file_sharing_bluetooth_require_pairing_changed), NULL);
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED,
+			     G_CALLBACK (file_sharing_bluetooth_obexpush_enabled_changed), NULL);
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_ACCEPT_FILES,
+			     G_CALLBACK (file_sharing_bluetooth_obexpush_accept_files_changed), NULL);
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_NOTIFY,
+			     G_CALLBACK (file_sharing_bluetooth_obexpush_notify_changed), NULL);
+#endif /* HAVE_BLUETOOTH */
+
+    update_ui ();
+
+    return window;
+}
+
+static void
+activate (GtkApplication *app)
+{
+    GList *list;
+    GtkWidget *window;
+
+    list = gtk_application_get_windows (app);
+
+    if (list) {
+        gtk_window_present (GTK_WINDOW (list->data));
+    } else {
+        window = create_window ();
+        gtk_window_set_application (GTK_WINDOW (window), app);
+        gtk_widget_show (window);
+    }
+}
+
+int
+main (int argc, char *argv[])
+{
+    GtkApplication *app;
+    gint status;
+
+    bindtextdomain (GETTEXT_PACKAGE, MATELOCALEDIR);
+    bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
+    textdomain (GETTEXT_PACKAGE);
+
+    app = gtk_application_new ("org.mate.user-share.properties",
+                               G_APPLICATION_FLAGS_NONE);
+    g_signal_connect (app, "activate", G_CALLBACK (activate), NULL);
+
+    status = g_application_run (G_APPLICATION (app), argc, argv);
+
+    g_object_unref (app);
+
+    return status;
+}
+
+
+
+
+ + + diff --git a/2021-03-09-235935-8562-cppcheck@52bc759bdcfd_master/1.html b/2021-03-09-235935-8562-cppcheck@52bc759bdcfd_master/1.html new file mode 100644 index 0000000..cec50f3 --- /dev/null +++ b/2021-03-09-235935-8562-cppcheck@52bc759bdcfd_master/1.html @@ -0,0 +1,1054 @@ + + + + + + Cppcheck - HTML report - mate-user-share + + + + + + +
+ +
+
  1
+  2
+  3
+  4
+  5
+  6
+  7
+  8
+  9
+ 10
+ 11
+ 12
+ 13
+ 14
+ 15
+ 16
+ 17
+ 18
+ 19
+ 20
+ 21
+ 22
+ 23
+ 24
+ 25
+ 26
+ 27
+ 28
+ 29
+ 30
+ 31
+ 32
+ 33
+ 34
+ 35
+ 36
+ 37
+ 38
+ 39
+ 40
+ 41
+ 42
+ 43
+ 44
+ 45
+ 46
+ 47
+ 48
+ 49
+ 50
+ 51
+ 52
+ 53
+ 54
+ 55
+ 56
+ 57
+ 58
+ 59
+ 60
+ 61
+ 62
+ 63
+ 64
+ 65
+ 66
+ 67
+ 68
+ 69
+ 70
+ 71
+ 72
+ 73
+ 74
+ 75
+ 76
+ 77
+ 78
+ 79
+ 80
+ 81
+ 82
+ 83
+ 84
+ 85
+ 86
+ 87
+ 88
+ 89
+ 90
+ 91
+ 92
+ 93
+ 94
+ 95
+ 96
+ 97
+ 98
+ 99
+100
+101
+102
+103
+104
+105
+106
+107
+108
+109
+110
+111
+112
+113
+114
+115
+116
+117
+118
+119
+120
+121
+122
+123
+124
+125
+126
+127
+128
+129
+130
+131
+132
+133
+134
+135
+136
+137
+138
+139
+140
+141
+142
+143
+144
+145
+146
+147
+148
+149
+150
+151
+152
+153
+154
+155
+156
+157
+158
+159
+160
+161
+162
+163
+164
+165
+166
+167
+168
+169
+170
+171
+172
+173
+174
+175
+176
+177
+178
+179
+180
+181
+182
+183
+184
+185
+186
+187
+188
+189
+190
+191
+192
+193
+194
+195
+196
+197
+198
+199
+200
+201
+202
+203
+204
+205
+206
+207
+208
+209
+210
+211
+212
+213
+214
+215
+216
+217
+218
+219
+220
+221
+222
+223
+224
+225
+226
+227
+228
+229
+230
+231
+232
+233
+234
+235
+236
+237
+238
+239
+240
+241
+242
+243
+244
+245
+246
+247
+248
+249
+250
+251
+252
+253
+254
+255
+256
+257
+258
+259
+260
+261
+262
+263
+264
+265
+266
+267
+268
+269
+270
+271
+272
+273
+274
+275
+276
+277
+278
+279
+280
+281
+282
+283
+284
+285
+286
+287
+288
+289
+290
+291
+292
+293
+294
+295
+296
+297
+298
+299
+300
+301
+302
+303
+304
+305
+306
+307
+308
+309
+310
+311
+312
+313
+314
+315
+316
+317
+318
+319
+320
+321
+322
+323
+324
+325
+326
+327
+328
+329
+330
+331
+332
+333
+334
+335
+336
+337
+338
+339
+340
+341
+342
+343
+344
+345
+346
+347
+348
+349
+350
+351
+352
+353
+354
+355
+356
+357
+358
+359
+360
+361
+362
+363
+364
+365
+366
+367
+368
+369
+370
+371
+372
+373
+374
+375
+376
+377
+378
+379
+380
+381
+382
+383
+384
+385
+386
+387
+388
+389
+390
+391
+392
+393
+394
+395
+396
+397
+398
+399
+400
+401
+402
+403
+404
+405
+406
+407
+408
+409
+410
+411
+412
+413
+414
+415
+416
+417
+418
+419
+420
+421
+422
+423
+424
+425
+426
+427
+428
+429
+430
+431
+432
+433
+434
+435
+436
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
+
+/*
+ *  Copyright (C) 2004-2008 Red Hat, Inc.
+ *
+ *  Caja is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU General Public License as
+ *  published by the Free Software Foundation; either version 2 of the
+ *  License, or (at your option) any later version.
+ *
+ *  Caja is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  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
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ *  Authors: Alexander Larsson <alexl@redhat.com>
+ *
+ */
+
+#include "config.h"
+
+#include <glib.h>
+#include <glib/gi18n.h>
+#include <X11/Xlib.h>
+
+#include <gio/gio.h>
+
+#include <stdarg.h>
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <signal.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <sys/stat.h>
+
+#ifdef HAVE_SELINUX
+#include <selinux/selinux.h>
+#endif
+
+#include "user_share-common.h"
+#include "user_share-private.h"
+#include "http.h"
+
+/* From avahi-common/domain.h */
+#define AVAHI_LABEL_MAX 64
+
+#define GSETTINGS_SCHEMA "org.mate.FileSharing"
+
+static pid_t httpd_pid = 0;
+
+static int
+get_port (void)
+{
+	int sock;
+	struct sockaddr_in addr;
+	int reuse;
+	socklen_t len;
+
+	sock = socket (PF_INET, SOCK_STREAM, 0);
+	if (sock < 0) {
+		return -1;
+	}
+
+	memset (&addr, 0, sizeof (addr));
+	addr.sin_port = 0;
+	addr.sin_addr.s_addr = INADDR_ANY;
+	addr.sin_family = AF_INET;
+
+	reuse = 1;
+	setsockopt (sock, SOL_SOCKET, SO_REUSEADDR, &reuse, sizeof (reuse));
+	if (bind (sock, (struct sockaddr *)&addr, sizeof (addr)) == -1) {
+		close (sock);
+		return -1;
+	}
+
+	len = sizeof (addr);
+	if (getsockname (sock, (struct sockaddr *)&addr, &len) == -1) {
+		close (sock);
+		return -1;
+	}
+
+#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__APPLE__) || defined(__OpenBSD__)
+	/* XXX This exposes a potential race condition, but without this,
+	 * httpd will not start on the above listed platforms due to the fact
+	 * that SO_REUSEADDR is also needed when Apache binds to the listening
+	 * socket.  At this time, Apache does not support that socket option.
+	 */
+	close (sock);
+#endif
+	return ntohs (addr.sin_port);
+}
+
+static char *
+truncate_name (const char *name)
+{
+	const char *end;
+
+	end = g_utf8_find_prev_char (name, name + 64);
+	g_assert (end != NULL);
+	return g_strndup (name, end - name);
+}
+
+static char *
+get_share_name (void)
+{
+	static char *name = NULL;
+	const char *host_name;
+	char *str;
+
+	if (name == NULL) {
+		host_name = g_get_host_name ();
+		if (strcmp (host_name, "localhost") == 0) {
+			/* Translators: The %s will get filled in with the user name
+			   of the user, to form a genitive. If this is difficult to
+			   translate correctly so that it will work correctly in your
+			   language, you may use something equivalent to
+			   "Public files of %s", or leave out the %s altogether.
+			   In the latter case, please put "%.0s" somewhere in the string,
+			   which will match the user name string passed by the C code,
+			   but not put the user name in the final string. This is to
+			   avoid the warning that msgfmt might otherwise generate. */
+			name = g_strdup_printf (_("%s's public files"), g_get_user_name ());
+		} else {
+			/* Translators: This is similar to the string before, only it
+			   has the hostname in it too. */
+			name = g_strdup_printf (_("%s's public files on %s"),
+						g_get_user_name (),
+						host_name);
+		}
+
+	}
+	/* And truncate */
+	if (strlen (name) < AVAHI_LABEL_MAX)
+		return name;
+
+	str = truncate_name (name);
+	g_free (name);
+	name = str;
+
+	return name;
+}
+
+static void
+ensure_conf_dir (void)
+{
+	char *dirname;
+
+	dirname = g_build_filename (g_get_user_config_dir (), "user-share", NULL);
+	g_mkdir_with_parents (dirname, 0755);
+	g_free (dirname);
+}
+
+static void
+httpd_child_setup (gpointer user_data)
+{
+#ifdef HAVE_SELINUX
+	char *mycon;
+	/* If selinux is enabled, avoid transitioning to the httpd_t context,
+	   as this normally means you can't read the users homedir. */
+	if (is_selinux_enabled()) {
+		if (getcon (&mycon) < 0) {
+			abort ();
+		}
+		if (setexeccon (mycon) < 0)
+			abort ();
+		freecon (mycon);
+	}
+#endif
+}
+
+static const char *known_httpd_locations [] = {
+	HTTPD_PROGRAM,
+	"/usr/sbin/httpd",
+	"/usr/sbin/httpd2",
+	"/usr/sbin/apache2",
+	NULL
+};
+
+static char*
+get_httpd_program (void)
+{
+	int i;
+
+	for (i = 0; known_httpd_locations[i]; i++) {
+		if (known_httpd_locations[i][0] == '\0') {
+			/* empty string as first element, happens when
+			 * configured --with-httpd=auto */
+			continue;
+		}
+		if (g_file_test (known_httpd_locations[i], G_FILE_TEST_IS_EXECUTABLE)
+				&& ! g_file_test (known_httpd_locations[i], G_FILE_TEST_IS_DIR)) {
+			return g_strdup (known_httpd_locations[i]);
+		}
+	}
+	return NULL;
+}
+
+static const char *known_httpd_modules_locations [] = {
+	HTTPD_MODULES_PATH,
+	"/etc/httpd/modules",
+	"/usr/lib/apache2/modules",
+	NULL
+};
+
+static gchar*
+get_httpd_modules_path (void)
+{
+	int i;
+
+	for (i = 0; known_httpd_modules_locations[i]; i++) {
+		if (known_httpd_modules_locations[i][0] == '\0') {
+			/* empty string as first element, happens when
+			 * configured --with-httpd=auto */
+			continue;
+		}
+		if (g_file_test (known_httpd_modules_locations[i], G_FILE_TEST_IS_EXECUTABLE)
+				&& g_file_test (known_httpd_modules_locations[i], G_FILE_TEST_IS_DIR)) {
+			return g_strdup (known_httpd_modules_locations[i]);
+		}
+	}
+	return NULL;
+}
+
+static GRegex *version_regex = NULL;
+
+static char*
+get_httpd_config (const char *httpd_program)
+{
+	gchar *standard_output;
+	gchar *cmd_line;
+	GMatchInfo *match_info;
+	gchar *version_number = NULL;
+	gchar *config;
+
+	cmd_line = g_strdup_printf ("%s -v", httpd_program);
+	if (! g_spawn_command_line_sync (cmd_line, &standard_output, NULL, NULL, NULL)) {
+		g_free (cmd_line);
+		return NULL;
+	}
+	g_free (cmd_line);
+
+	if (version_regex == NULL) {
+		version_regex = g_regex_new ("\\d\\.\\d", 0, 0, NULL);
+	}
+
+	if (g_regex_match (version_regex, standard_output, 0, &match_info)) {
+		while (g_match_info_matches (match_info)) {
+			version_number = g_match_info_fetch (match_info, 0);
+			break;
+		}
+		g_match_info_free (match_info);
+		g_free (standard_output);
+	} else {
+		/* Failed to parse httpd version number */
+		g_warning ("Could not parse '%s' as a version for httpd", standard_output);
+		g_free (standard_output);
+		/* assume it is 2.2 */
+		version_number = g_strdup ("2.2");
+	}
+
+	config = g_strdup_printf (HTTPD_CONFIG_TEMPLATE, version_number);
+	g_free (version_number);
+
+	return config;
+}
+
+static gboolean
+spawn_httpd (int port, pid_t *pid_out)
+{
+	char *free1, *free2, *free3, *free4, *free5, *free6, *free7, *free8, *free9;
+	gboolean res;
+	char *argv[10];
+	char *env[10];
+	int i;
+	gint status;
+	char *pid_filename;
+	char *pidfile;
+	GError *error;
+	gboolean got_pidfile;
+	GSettings *settings;
+	char *str;
+	char *public_dir;
+
+	public_dir = lookup_public_dir ();
+	ensure_conf_dir ();
+
+	i = 0;
+	free1 = argv[i++] = get_httpd_program ();
+	if (argv[0] == NULL) {
+		fprintf (stderr, "error finding httpd server\n");
+		return FALSE;
+	}
+
+	argv[i++] = "-f";
+	free2 = argv[i++] = get_httpd_config (argv[0]);
+	argv[i++] = "-C";
+	free3 = argv[i++] = g_strdup_printf ("Listen %d", port);
+
+	settings = g_settings_new (GSETTINGS_SCHEMA);
+	str = g_settings_get_string (settings,
+				       FILE_SHARING_REQUIRE_PASSWORD);
+
+	if (str && strcmp (str, "never") == 0) {
+		/* Do nothing */
+	} else if (str && strcmp (str, "on_write") == 0){
+		argv[i++] = "-D";
+		argv[i++] = "RequirePasswordOnWrite";
+	} else {
+		/* always, or safe fallback */
+		argv[i++] = "-D";
+		argv[i++] = "RequirePasswordAlways";
+	}
+	g_free (str);
+	g_object_unref (settings);
+
+	argv[i] = NULL;
+
+	i = 0;
+	free4 = env[i++] = g_strdup_printf ("HOME=%s", g_get_home_dir());
+	free5 = env[i++] = g_strdup_printf ("XDG_PUBLICSHARE_DIR=%s", public_dir);
+	free6 = env[i++] = g_strdup_printf ("XDG_CONFIG_HOME=%s", g_get_user_config_dir ());
+	free7 = env[i++] = g_strdup_printf ("GUS_SHARE_NAME=%s", get_share_name ());
+	free8 = env[i++] = g_strdup_printf ("GUS_LOGIN_LABEL=%s", "Please log in as the user guest");
+	free9 = env[i++] = g_strdup_printf ("HTTP_MODULES_PATH=%s",get_httpd_modules_path ());
+	env[i++] = "LANG=C";
+	env[i] = NULL;
+
+	pid_filename = g_build_filename (g_get_user_config_dir (), "user-share", "pid", NULL);
+
+	/* Remove pid file before spawning to avoid races with child and old pidfile */
+	unlink (pid_filename);
+
+	error = NULL;
+	res = g_spawn_sync (g_get_home_dir(),
+			    argv, env, 0,
+			    httpd_child_setup, NULL,
+			    NULL, NULL,
+			    &status,
+			    &error);
+	g_free (free1);
+	g_free (free2);
+	g_free (free3);
+	g_free (free4);
+	g_free (free5);
+	g_free (free6);
+	g_free (free7);
+	g_free (free8);
+	g_free (free9);
+	g_free (public_dir);
+
+	if (!res) {
+		fprintf (stderr, "error spawning httpd: %s\n",
+			 error->message);
+		g_error_free (error);
+		g_free (pid_filename);
+		return FALSE;
+	}
+
+	if (status != 0) {
+		g_free (pid_filename);
+		return FALSE;
+	}
+
+	got_pidfile = FALSE;
+	error = NULL;
+	for (i = 0; i < 5; i++) {
+		if (error != NULL)
+			g_error_free (error);
+		error = NULL;
+		if (g_file_get_contents (pid_filename, &pidfile, NULL, &error)) {
+			got_pidfile = TRUE;
+			*pid_out = atoi (pidfile);
+			g_free (pidfile);
+			break;
+		}
+		sleep (1);
+	}
+
+	g_free (pid_filename);
+
+	if (!got_pidfile) {
+		fprintf (stderr, "error opening httpd pidfile: %s\n", error->message);
+		g_error_free (error);
+		return FALSE;
+	}
+	return TRUE;
+}
+
+static void
+kill_httpd (void)
+{
+	if (httpd_pid != 0) {
+		kill (httpd_pid, SIGTERM);
+
+		/* Allow child time to die, we can't waitpid, because its
+		   not a direct child */
+		sleep (1);
+	}
+	httpd_pid = 0;
+}
+
+void
+http_up (void)
+{
+	guint port;
+
+	port = get_port ();
+	if (!spawn_httpd (port, &httpd_pid)) {
+		fprintf (stderr, "spawning httpd failed\n");
+	}
+}
+
+void
+http_down (void)
+{
+	kill_httpd ();
+}
+
+gboolean
+http_init (void)
+{
+	return TRUE;
+}
+
+pid_t
+http_get_pid (void)
+{
+	return httpd_pid;
+}
+
+
+
+
+ + + diff --git a/2021-03-09-235935-8562-cppcheck@52bc759bdcfd_master/2.html b/2021-03-09-235935-8562-cppcheck@52bc759bdcfd_master/2.html new file mode 100644 index 0000000..c95a0b0 --- /dev/null +++ b/2021-03-09-235935-8562-cppcheck@52bc759bdcfd_master/2.html @@ -0,0 +1,1288 @@ + + + + + + Cppcheck - HTML report - mate-user-share + + + + + + +
+ +
+
  1
+  2
+  3
+  4
+  5
+  6
+  7
+  8
+  9
+ 10
+ 11
+ 12
+ 13
+ 14
+ 15
+ 16
+ 17
+ 18
+ 19
+ 20
+ 21
+ 22
+ 23
+ 24
+ 25
+ 26
+ 27
+ 28
+ 29
+ 30
+ 31
+ 32
+ 33
+ 34
+ 35
+ 36
+ 37
+ 38
+ 39
+ 40
+ 41
+ 42
+ 43
+ 44
+ 45
+ 46
+ 47
+ 48
+ 49
+ 50
+ 51
+ 52
+ 53
+ 54
+ 55
+ 56
+ 57
+ 58
+ 59
+ 60
+ 61
+ 62
+ 63
+ 64
+ 65
+ 66
+ 67
+ 68
+ 69
+ 70
+ 71
+ 72
+ 73
+ 74
+ 75
+ 76
+ 77
+ 78
+ 79
+ 80
+ 81
+ 82
+ 83
+ 84
+ 85
+ 86
+ 87
+ 88
+ 89
+ 90
+ 91
+ 92
+ 93
+ 94
+ 95
+ 96
+ 97
+ 98
+ 99
+100
+101
+102
+103
+104
+105
+106
+107
+108
+109
+110
+111
+112
+113
+114
+115
+116
+117
+118
+119
+120
+121
+122
+123
+124
+125
+126
+127
+128
+129
+130
+131
+132
+133
+134
+135
+136
+137
+138
+139
+140
+141
+142
+143
+144
+145
+146
+147
+148
+149
+150
+151
+152
+153
+154
+155
+156
+157
+158
+159
+160
+161
+162
+163
+164
+165
+166
+167
+168
+169
+170
+171
+172
+173
+174
+175
+176
+177
+178
+179
+180
+181
+182
+183
+184
+185
+186
+187
+188
+189
+190
+191
+192
+193
+194
+195
+196
+197
+198
+199
+200
+201
+202
+203
+204
+205
+206
+207
+208
+209
+210
+211
+212
+213
+214
+215
+216
+217
+218
+219
+220
+221
+222
+223
+224
+225
+226
+227
+228
+229
+230
+231
+232
+233
+234
+235
+236
+237
+238
+239
+240
+241
+242
+243
+244
+245
+246
+247
+248
+249
+250
+251
+252
+253
+254
+255
+256
+257
+258
+259
+260
+261
+262
+263
+264
+265
+266
+267
+268
+269
+270
+271
+272
+273
+274
+275
+276
+277
+278
+279
+280
+281
+282
+283
+284
+285
+286
+287
+288
+289
+290
+291
+292
+293
+294
+295
+296
+297
+298
+299
+300
+301
+302
+303
+304
+305
+306
+307
+308
+309
+310
+311
+312
+313
+314
+315
+316
+317
+318
+319
+320
+321
+322
+323
+324
+325
+326
+327
+328
+329
+330
+331
+332
+333
+334
+335
+336
+337
+338
+339
+340
+341
+342
+343
+344
+345
+346
+347
+348
+349
+350
+351
+352
+353
+354
+355
+356
+357
+358
+359
+360
+361
+362
+363
+364
+365
+366
+367
+368
+369
+370
+371
+372
+373
+374
+375
+376
+377
+378
+379
+380
+381
+382
+383
+384
+385
+386
+387
+388
+389
+390
+391
+392
+393
+394
+395
+396
+397
+398
+399
+400
+401
+402
+403
+404
+405
+406
+407
+408
+409
+410
+411
+412
+413
+414
+415
+416
+417
+418
+419
+420
+421
+422
+423
+424
+425
+426
+427
+428
+429
+430
+431
+432
+433
+434
+435
+436
+437
+438
+439
+440
+441
+442
+443
+444
+445
+446
+447
+448
+449
+450
+451
+452
+453
+454
+455
+456
+457
+458
+459
+460
+461
+462
+463
+464
+465
+466
+467
+468
+469
+470
+471
+472
+473
+474
+475
+476
+477
+478
+479
+480
+481
+482
+483
+484
+485
+486
+487
+488
+489
+490
+491
+492
+493
+494
+495
+496
+497
+498
+499
+500
+501
+502
+503
+504
+505
+506
+507
+508
+509
+510
+511
+512
+513
+514
+515
+516
+517
+518
+519
+520
+521
+522
+523
+524
+525
+526
+527
+528
+529
+530
+531
+532
+533
+534
+535
+536
+537
+538
+539
+540
+541
+542
+543
+544
+545
+546
+547
+548
+549
+550
+551
+552
+553
+554
+555
+556
+557
+558
+559
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
+
+/*
+ *  Copyright (C) 2004-2008 Red Hat, Inc.
+ *
+ *  Caja is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU General Public License as
+ *  published by the Free Software Foundation; either version 2 of the
+ *  License, or (at your option) any later version.
+ *
+ *  Caja is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  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
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ *  Authors: Bastien Nocera <hadess@hadess.net>
+ *
+ */
+
+#include "config.h"
+
+#include <glib.h>
+#include <glib/gi18n.h>
+#include <gio/gio.h>
+#include <gdk/gdk.h>
+#include <gtk/gtk.h>
+#include <libnotify/notify.h>
+#include <dbus/dbus-glib.h>
+#include <dbus/dbus-glib-lowlevel.h>
+#include <canberra-gtk.h>
+
+#include <string.h>
+
+#include "marshal.h"
+#include "obexpush.h"
+#include "user_share-common.h"
+#include "user_share-private.h"
+
+#define DBUS_TYPE_G_STRING_VARIANT_HASHTABLE (dbus_g_type_get_map ("GHashTable", G_TYPE_STRING, G_TYPE_STRING))
+
+#define GSETTINGS_SCHEMA "org.mate.FileSharing"
+
+static DBusGConnection *connection = NULL;<--- Shadowed declaration
+static DBusGProxy *manager_proxy = NULL;
+static DBusGProxy *server_proxy = NULL;
+static AcceptSetting accept_setting = -1;
+static gboolean show_notifications = FALSE;
+
+static GtkStatusIcon *statusicon = NULL;
+static guint num_notifications = 0;
+
+static void
+hide_statusicon (void)
+{
+	num_notifications--;
+	if (num_notifications == 0)
+		gtk_status_icon_set_visible (statusicon, FALSE);
+}
+
+static void
+on_close_notification (NotifyNotification *notification)
+{
+	hide_statusicon ();
+	g_object_unref (notification);
+}
+
+static void
+notification_launch_action_on_file_cb (NotifyNotification *notification,
+				       const char *action,
+				       const char *file_uri)
+{
+	GdkScreen *screen;
+	GAppLaunchContext *ctx;
+	GTimeVal val;
+
+	g_assert (action != NULL);
+
+	g_get_current_time (&val);
+
+	ctx = G_APP_LAUNCH_CONTEXT (gdk_app_launch_context_new ());
+	screen = gdk_screen_get_default ();
+	gdk_app_launch_context_set_screen (GDK_APP_LAUNCH_CONTEXT (ctx), screen);
+	gdk_app_launch_context_set_timestamp (GDK_APP_LAUNCH_CONTEXT (ctx), val.tv_sec);
+
+	/* We launch the file viewer for the file */
+	if (g_str_equal (action, "display") != FALSE) {
+		if (g_app_info_launch_default_for_uri (file_uri, ctx, NULL) == FALSE) {
+			g_warning ("Failed to launch the file viewer\n");
+		}
+	}
+
+	/* we open the Downloads folder */
+	if (g_str_equal (action, "reveal") != FALSE) {
+		GFile *file;
+		GFile *parent;
+		gchar *parent_uri;
+
+		file = g_file_new_for_uri (file_uri);
+		parent = g_file_get_parent (file);
+		parent_uri = g_file_get_uri (parent);
+		g_object_unref (file);
+		g_object_unref (parent);
+
+		if (!g_app_info_launch_default_for_uri (parent_uri, ctx, NULL)) {
+			g_warning ("Failed to launch the file manager\n");
+		}
+
+		g_free (parent_uri);
+	}
+
+	notify_notification_close (notification, NULL);
+	/* No need to call hide_statusicon(), closing the notification
+	 * will call the close callback */
+}
+
+static void
+show_notification (const char *filename)
+{
+	char *file_uri, *notification_text, *display, *mime_type;
+	NotifyNotification *notification;
+	ca_context *ctx;
+	GAppInfo *app;
+
+	file_uri = g_filename_to_uri (filename, NULL, NULL);
+	if (file_uri == NULL) {
+		g_warning ("Could not make a filename from '%s'", filename);
+		return;
+	}
+
+	display = g_filename_display_basename (filename);
+	/* Translators: %s is the name of the filename received */
+	notification_text = g_strdup_printf(_("You received \"%s\" via Bluetooth"), display);
+	g_free (display);
+	notification = notify_notification_new (_("You received a file"),
+								 notification_text,
+								 "dialog-information");
+
+	notify_notification_set_timeout (notification, NOTIFY_EXPIRES_DEFAULT);
+
+	mime_type = g_content_type_guess (filename, NULL, 0, NULL);
+	app = g_app_info_get_default_for_type (mime_type, FALSE);
+	if (app != NULL) {
+		g_object_unref (app);
+		notify_notification_add_action (notification, "display", _("Open File"),
+						(NotifyActionCallback) notification_launch_action_on_file_cb,
+						g_strdup (file_uri), (GFreeFunc) g_free);
+	}
+	notify_notification_add_action (notification, "reveal", _("Reveal File"),
+					(NotifyActionCallback) notification_launch_action_on_file_cb,
+					g_strdup (file_uri), (GFreeFunc) g_free);
+
+	g_free (file_uri);
+
+	g_signal_connect (G_OBJECT (notification), "closed", G_CALLBACK (on_close_notification), notification);
+
+	if (!notify_notification_show (notification, NULL)) {
+		g_warning ("failed to send notification\n");
+	}
+	g_free (notification_text);
+
+	/* Now we do the audio notification */
+	ctx = ca_gtk_context_get ();
+	ca_context_play (ctx, 0,
+			 CA_PROP_EVENT_ID, "complete-download",
+			 CA_PROP_EVENT_DESCRIPTION, _("File reception complete"),
+			 NULL);
+}
+
+static void
+show_icon (void)
+{
+	if (statusicon == NULL) {
+		statusicon = gtk_status_icon_new_from_icon_name ("mate-obex-server");
+	} else {
+		gtk_status_icon_set_visible (statusicon, TRUE);
+	}
+	num_notifications++;
+}
+
+static gboolean
+device_is_authorised (const char *bdaddr)
+{
+	DBusGConnection *connection;<--- Shadow variable
+	DBusGProxy *manager;
+	GError *error = NULL;
+	GPtrArray *adapters;
+	gboolean retval = FALSE;
+	guint i;
+
+	connection = dbus_g_bus_get (DBUS_BUS_SYSTEM, NULL);
+	if (connection == NULL)
+		return FALSE;
+
+	manager = dbus_g_proxy_new_for_name (connection, "org.bluez",
+					     "/", "org.bluez.Manager");
+	if (manager == NULL) {
+		dbus_g_connection_unref (connection);
+		return FALSE;
+	}
+
+	if (dbus_g_proxy_call (manager, "ListAdapters", &error, G_TYPE_INVALID, dbus_g_type_get_collection ("GPtrArray", DBUS_TYPE_G_OBJECT_PATH), &adapters, G_TYPE_INVALID) == FALSE) {
+		g_object_unref (manager);
+		dbus_g_connection_unref (connection);
+		return FALSE;
+	}
+
+	for (i = 0; i < adapters->len; i++) {
+		DBusGProxy *adapter, *device;
+		char *device_path;
+		GHashTable *props;
+
+		g_debug ("checking adapter %s", (gchar *) g_ptr_array_index (adapters, i));
+
+		adapter = dbus_g_proxy_new_for_name (connection, "org.bluez",
+						    g_ptr_array_index (adapters, i), "org.bluez.Adapter");
+
+		if (dbus_g_proxy_call (adapter, "FindDevice", NULL,
+				       G_TYPE_STRING, bdaddr, G_TYPE_INVALID,
+				       DBUS_TYPE_G_OBJECT_PATH, &device_path, G_TYPE_INVALID) == FALSE)
+		{
+			g_object_unref (adapter);
+			continue;
+		}
+
+		device = dbus_g_proxy_new_for_name (connection, "org.bluez", device_path, "org.bluez.Device");
+
+		if (dbus_g_proxy_call (device, "GetProperties", NULL,
+				       G_TYPE_INVALID, dbus_g_type_get_map ("GHashTable", G_TYPE_STRING, G_TYPE_VALUE),
+				       &props, G_TYPE_INVALID) != FALSE)
+		{
+			GValue *value;
+			gboolean bonded;
+
+			value = g_hash_table_lookup (props, "Paired");
+			bonded = g_value_get_boolean (value);
+			g_message ("%s is %s", bdaddr, bonded ? "bonded" : "not bonded");
+
+			if (bonded) {
+				g_hash_table_destroy (props);
+				g_object_unref (device);
+				g_object_unref (adapter);
+				retval = TRUE;
+				break;
+			}
+		}
+		g_object_unref(adapter);
+	}
+
+	g_ptr_array_free (adapters, TRUE);
+
+	g_object_unref(manager);
+	dbus_g_connection_unref(connection);
+
+	return retval;
+}
+
+static void
+transfer_started_cb (DBusGProxy *session,
+		     const char *filename,
+		     const char *local_path,
+		     guint64 size,
+		     gpointer user_data)
+{
+	GHashTable *dict;
+	DBusGProxy *server = (DBusGProxy *) user_data;
+	GError *error = NULL;
+	gboolean authorise;
+
+	g_message ("transfer started on %s", local_path);
+	g_object_set_data_full (G_OBJECT (session), "filename", g_strdup (local_path), (GDestroyNotify) g_free);
+
+	show_icon ();
+
+	/* First transfer of the session */
+	if (g_object_get_data (G_OBJECT (session), "bdaddr") == NULL) {
+		const char *bdaddr;
+
+		if (dbus_g_proxy_call (server, "GetServerSessionInfo", &error,
+				       DBUS_TYPE_G_OBJECT_PATH, dbus_g_proxy_get_path (session), G_TYPE_INVALID,
+				       DBUS_TYPE_G_STRING_VARIANT_HASHTABLE, &dict, G_TYPE_INVALID) == FALSE) {
+			g_printerr ("Getting Server session info failed: %s\n",
+				    error->message);
+			g_error_free (error);
+			return;
+		}
+
+		bdaddr = g_hash_table_lookup (dict, "BluetoothAddress");
+		g_message ("transfer started for device %s", bdaddr);
+
+		g_object_set_data_full (G_OBJECT (session), "bdaddr", g_strdup (bdaddr), (GDestroyNotify) g_free);
+		/* Initial accept method is undefined, we do that lower down */
+		g_object_set_data (G_OBJECT (session), "accept-method", GINT_TO_POINTER (-1));
+		g_hash_table_destroy (dict);
+	}
+
+	/* Accept method changed */
+	if (GPOINTER_TO_INT (g_object_get_data (G_OBJECT (session), "accept-method")) != accept_setting) {
+		const char *bdaddr;
+
+		bdaddr = g_object_get_data (G_OBJECT (session), "bdaddr");
+
+		if (bdaddr == NULL) {
+			g_warning ("Couldn't get the Bluetooth address for the device, rejecting the transfer");
+			authorise = FALSE;
+		} else if (accept_setting == ACCEPT_ALWAYS) {
+			authorise = TRUE;
+		} else if (accept_setting == ACCEPT_BONDED) {
+			authorise = device_is_authorised (bdaddr);
+		} else {
+			//FIXME implement
+			g_warning ("\"Ask\" authorisation method not implemented");
+			authorise = FALSE;
+		}
+		g_object_set_data (G_OBJECT (session), "authorise", GINT_TO_POINTER (authorise));
+	}
+
+	g_message ("accept_setting: %d", accept_setting);
+
+	authorise = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (session), "authorise"));
+	if (authorise != FALSE) {
+		if (dbus_g_proxy_call (session, "Accept", &error, G_TYPE_INVALID, G_TYPE_INVALID) == FALSE) {
+			g_printerr ("Failed to accept file transfer: %s\n", error->message);
+			g_error_free (error);
+			return;
+		}
+		g_message ("authorised transfer");
+	} else {
+		if (dbus_g_proxy_call (session, "Reject", &error, G_TYPE_INVALID, G_TYPE_INVALID) == FALSE) {
+			g_printerr ("Failed to reject file transfer: %s\n", error->message);
+			g_error_free (error);
+			return;
+		}
+		g_message ("rejected transfer");
+		g_object_set_data (G_OBJECT (session), "filename", NULL);
+	}
+}
+
+static void
+transfer_completed_cb (DBusGProxy *session,
+		       gpointer user_data)
+{
+	GSettings *settings;
+	gboolean display_notify;
+	const char *filename;
+
+	filename = (const char *) g_object_get_data (G_OBJECT (session), "filename");
+
+	g_message ("file finish transfer: %s", filename);
+
+	if (filename == NULL)
+		return;
+
+	settings = g_settings_new (GSETTINGS_SCHEMA);
+	display_notify = g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_OBEXPUSH_NOTIFY);
+	g_object_unref (settings);
+
+	if (display_notify) {
+		show_notification (filename);
+	} else {
+		hide_statusicon ();
+	}
+	g_object_set_data (G_OBJECT (session), "filename", NULL);
+}
+
+static void
+cancelled_cb (DBusGProxy *session,
+	      gpointer user_data)
+{
+	//FIXME implement properly, we never actually finished the transfer
+	g_message ("transfered was cancelled by the sender");
+	transfer_completed_cb (session, user_data);
+	hide_statusicon ();
+}
+
+static void
+error_occurred_cb (DBusGProxy *session,
+		   const char *error_name,
+		   const char *error_message,
+		   gpointer user_data)
+{
+	//FIXME implement properly
+	g_message ("transfer error occurred: %s", error_message);
+	transfer_completed_cb (session, user_data);
+}
+
+static void
+session_created_cb (DBusGProxy *server, const char *session_path, gpointer user_data)
+{
+	DBusGProxy *session;
+
+	session = dbus_g_proxy_new_for_name (connection,
+					     "org.openobex",
+					     session_path,
+					     "org.openobex.ServerSession");
+
+	dbus_g_proxy_add_signal (session, "TransferStarted",
+				 G_TYPE_STRING, G_TYPE_STRING, G_TYPE_UINT64, G_TYPE_INVALID);
+	dbus_g_proxy_connect_signal(session, "TransferStarted",
+				    G_CALLBACK (transfer_started_cb), server, NULL);
+	dbus_g_proxy_add_signal (session, "TransferCompleted",
+				 G_TYPE_INVALID, G_TYPE_INVALID);
+	dbus_g_proxy_connect_signal(session, "TransferCompleted",
+				    G_CALLBACK (transfer_completed_cb), server, NULL);
+	dbus_g_proxy_add_signal (session, "Cancelled",
+				 G_TYPE_INVALID, G_TYPE_INVALID);
+	dbus_g_proxy_connect_signal(session, "Cancelled",
+				    G_CALLBACK (cancelled_cb), server, NULL);
+	dbus_g_proxy_add_signal (session, "ErrorOccurred",
+				 G_TYPE_INVALID, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INVALID);
+	dbus_g_proxy_connect_signal(session, "ErrorOccurred",
+				    G_CALLBACK (error_occurred_cb), server, NULL);
+}
+
+void
+obexpush_up (void)
+{
+	GError *err = NULL;
+	char *download_dir, *server;
+
+	server = NULL;
+	if (manager_proxy == NULL) {
+		manager_proxy = dbus_g_proxy_new_for_name (connection,
+							   "org.openobex",
+							   "/org/openobex",
+							   "org.openobex.Manager");
+		if (dbus_g_proxy_call (manager_proxy, "CreateBluetoothServer",
+				       &err, G_TYPE_STRING, "00:00:00:00:00:00", G_TYPE_STRING, "opp", G_TYPE_BOOLEAN, FALSE, G_TYPE_INVALID,
+				       DBUS_TYPE_G_OBJECT_PATH, &server, G_TYPE_INVALID) == FALSE) {
+			g_printerr ("Creating Bluetooth ObexPush server failed: %s\n",
+				    err->message);
+			g_error_free (err);
+			g_object_unref (manager_proxy);
+			manager_proxy = NULL;
+			return;
+		}
+	}
+
+	download_dir = lookup_download_dir ();
+
+	if (server_proxy == NULL) {
+		server_proxy = dbus_g_proxy_new_for_name (connection,
+							   "org.openobex",
+							   server,
+							   "org.openobex.Server");
+		g_free (server);
+
+		dbus_g_proxy_add_signal (server_proxy, "SessionCreated",
+					 DBUS_TYPE_G_OBJECT_PATH, G_TYPE_INVALID);
+		dbus_g_proxy_connect_signal(server_proxy, "SessionCreated",
+					    G_CALLBACK (session_created_cb), NULL, NULL);
+	}
+
+	if (dbus_g_proxy_call (server_proxy, "Start", &err,
+			   G_TYPE_STRING, download_dir, G_TYPE_BOOLEAN, TRUE, G_TYPE_BOOLEAN, FALSE, G_TYPE_INVALID,
+			   G_TYPE_INVALID) == FALSE) {
+		if (g_error_matches (err, DBUS_GERROR, DBUS_GERROR_REMOTE_EXCEPTION) != FALSE &&
+		    dbus_g_error_has_name (err, "org.openobex.Error.Started") != FALSE) {
+		    	g_error_free (err);
+		    	g_message ("already started, ignoring error");
+		    	g_free (download_dir);
+		    	return;
+		}
+		g_printerr ("Starting Bluetooth ObexPush server failed: %s\n",
+			    err->message);
+		g_error_free (err);
+		g_free (download_dir);
+		g_object_unref (server_proxy);
+		server_proxy = NULL;
+		g_object_unref (manager_proxy);
+		manager_proxy = NULL;
+		return;
+	}
+
+	g_free (download_dir);
+}
+
+static void
+obexpush_stop (gboolean stop_manager)
+{
+	GError *err = NULL;
+
+	if (server_proxy == NULL)
+		return;
+
+	if (dbus_g_proxy_call (server_proxy, "Close", &err, G_TYPE_INVALID, G_TYPE_INVALID) == FALSE) {
+		if (g_error_matches (err, DBUS_GERROR, DBUS_GERROR_REMOTE_EXCEPTION) == FALSE ||
+		    dbus_g_error_has_name (err, "org.openobex.Error.NotStarted") == FALSE) {
+			g_printerr ("Stopping Bluetooth ObexPush server failed: %s\n",
+				    err->message);
+			g_error_free (err);
+			return;
+		}
+		g_error_free (err);
+	}
+
+	if (stop_manager != FALSE) {
+		g_object_unref (server_proxy);
+		server_proxy = NULL;
+		g_object_unref (manager_proxy);
+		manager_proxy = NULL;
+	}
+
+	//FIXME stop all the notifications
+}
+
+void
+obexpush_down (void)
+{
+	obexpush_stop (TRUE);
+}
+
+void
+obexpush_restart (void)
+{
+	obexpush_stop (FALSE);
+	obexpush_up ();
+}
+
+gboolean
+obexpush_init (void)
+{
+	GError *err = NULL;
+
+	connection = dbus_g_bus_get (DBUS_BUS_SESSION, &err);
+	if (connection == NULL) {
+		g_printerr ("Connecting to session bus failed: %s\n",
+			    err->message);
+		g_error_free (err);
+		return FALSE;
+	}
+
+	dbus_g_object_register_marshaller (marshal_VOID__STRING_STRING_UINT64,
+					   G_TYPE_NONE,
+					   G_TYPE_STRING, G_TYPE_STRING, G_TYPE_UINT64, G_TYPE_INVALID);
+
+	if (!notify_init("mate-user-share")) {
+		g_warning("Unable to initialize the notification system\n");
+        }
+
+	dbus_connection_set_exit_on_disconnect (dbus_g_connection_get_connection (connection), FALSE);
+
+	return TRUE;
+}
+
+void
+obexpush_set_accept_files_policy (AcceptSetting setting)
+{
+	accept_setting = setting;
+}
+
+void
+obexpush_set_notify (gboolean enabled)
+{
+	show_notifications = enabled;
+}
+
+
+
+
+ + + diff --git a/2021-03-09-235935-8562-cppcheck@52bc759bdcfd_master/3.html b/2021-03-09-235935-8562-cppcheck@52bc759bdcfd_master/3.html new file mode 100644 index 0000000..f2cda19 --- /dev/null +++ b/2021-03-09-235935-8562-cppcheck@52bc759bdcfd_master/3.html @@ -0,0 +1,764 @@ + + + + + + Cppcheck - HTML report - mate-user-share + + + + + + +
+ +
+
  1
+  2
+  3
+  4
+  5
+  6
+  7
+  8
+  9
+ 10
+ 11
+ 12
+ 13
+ 14
+ 15
+ 16
+ 17
+ 18
+ 19
+ 20
+ 21
+ 22
+ 23
+ 24
+ 25
+ 26
+ 27
+ 28
+ 29
+ 30
+ 31
+ 32
+ 33
+ 34
+ 35
+ 36
+ 37
+ 38
+ 39
+ 40
+ 41
+ 42
+ 43
+ 44
+ 45
+ 46
+ 47
+ 48
+ 49
+ 50
+ 51
+ 52
+ 53
+ 54
+ 55
+ 56
+ 57
+ 58
+ 59
+ 60
+ 61
+ 62
+ 63
+ 64
+ 65
+ 66
+ 67
+ 68
+ 69
+ 70
+ 71
+ 72
+ 73
+ 74
+ 75
+ 76
+ 77
+ 78
+ 79
+ 80
+ 81
+ 82
+ 83
+ 84
+ 85
+ 86
+ 87
+ 88
+ 89
+ 90
+ 91
+ 92
+ 93
+ 94
+ 95
+ 96
+ 97
+ 98
+ 99
+100
+101
+102
+103
+104
+105
+106
+107
+108
+109
+110
+111
+112
+113
+114
+115
+116
+117
+118
+119
+120
+121
+122
+123
+124
+125
+126
+127
+128
+129
+130
+131
+132
+133
+134
+135
+136
+137
+138
+139
+140
+141
+142
+143
+144
+145
+146
+147
+148
+149
+150
+151
+152
+153
+154
+155
+156
+157
+158
+159
+160
+161
+162
+163
+164
+165
+166
+167
+168
+169
+170
+171
+172
+173
+174
+175
+176
+177
+178
+179
+180
+181
+182
+183
+184
+185
+186
+187
+188
+189
+190
+191
+192
+193
+194
+195
+196
+197
+198
+199
+200
+201
+202
+203
+204
+205
+206
+207
+208
+209
+210
+211
+212
+213
+214
+215
+216
+217
+218
+219
+220
+221
+222
+223
+224
+225
+226
+227
+228
+229
+230
+231
+232
+233
+234
+235
+236
+237
+238
+239
+240
+241
+242
+243
+244
+245
+246
+247
+248
+249
+250
+251
+252
+253
+254
+255
+256
+257
+258
+259
+260
+261
+262
+263
+264
+265
+266
+267
+268
+269
+270
+271
+272
+273
+274
+275
+276
+277
+278
+279
+280
+281
+282
+283
+284
+285
+286
+287
+288
+289
+290
+291
/* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 8; tab-width: 8 -*-
+ *
+ * Copyright (C) 2003 Novell, Inc.
+ * Copyright (C) 2003-2004 Red Hat, Inc.
+ * Copyright (C) 2005 William Jon McCann <mccann@jhu.edu>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * 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 Foundation, Inc., 51 Franklin St, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ *
+ */
+
+#include "config.h"
+
+#include <stdlib.h>
+#include <string.h>
+#include <glib/gi18n-lib.h>
+#include <gtk/gtk.h>
+#include <libcaja-extension/caja-menu-provider.h>
+#include <libcaja-extension/caja-location-widget-provider.h>
+
+#ifdef HAVE_BLUETOOTH
+#include <bluetooth-client.h>
+#endif
+
+#include "caja-share-bar.h"
+#include "user_share-common.h"
+
+#define CAJA_TYPE_USER_SHARE  (caja_user_share_get_type ())
+#define CAJA_USER_SHARE(o)    (G_TYPE_CHECK_INSTANCE_CAST ((o), CAJA_TYPE_USER_SHARE, CajaUserShare))
+#define CAJA_IS_USER_SHARE(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), CAJA_TYPE_USER_SHARE))
+
+typedef struct
+{
+        GObject              parent_slot;
+} CajaUserShare;
+
+typedef struct
+{
+        GObjectClass parent_slot;
+} CajaUserShareClass;
+
+static GType caja_user_share_get_type      (void);
+static void  caja_user_share_register_type (GTypeModule *module);
+
+static void
+launch_process (char **argv, GtkWindow *parent)
+{
+        GError *error;
+        GtkWidget *dialog;
+
+        error = NULL;
+        if (!g_spawn_async (NULL,
+                            argv, NULL,
+                            0,
+                            NULL, NULL,
+                            NULL,
+                            &error)) {
+
+
+                dialog = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL, GTK_MESSAGE_WARNING,
+						 GTK_BUTTONS_OK, _("Unable to launch the Personal File Sharing preferences"));
+
+                gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog), "%s", error->message);
+
+                gtk_dialog_run (GTK_DIALOG (dialog));
+                gtk_widget_destroy (dialog);
+
+                g_error_free (error);
+        }
+}
+
+static void
+launch_prefs_on_window (GtkWindow *window)
+{
+        char *argv [2];
+
+        argv [0] = g_build_filename (BINDIR, "mate-file-share-properties", NULL);
+        argv [1] = NULL;
+
+        launch_process (argv, window);
+
+        g_free (argv [0]);
+}
+
+static void
+bar_response_cb (CajaShareBar *bar,
+                 gint response,
+                 gpointer         data)
+{
+        if (response == CAJA_SHARE_BAR_RESPONSE_PREFERENCES) {
+                launch_prefs_on_window (GTK_WINDOW (data));
+        }
+}
+
+#ifdef HAVE_BLUETOOTH
+static void
+downloads_bar_set_from_bluetooth_status (GtkWidget *bar)
+{
+	BluetoothClient *client;
+	gboolean bt_powered;
+
+	client = g_object_get_data (G_OBJECT (bar), "bluetooth-client");
+	g_object_get (G_OBJECT (client),
+		      "default-adapter-powered", &bt_powered,
+		      NULL);
+	gtk_widget_set_visible (bar, bt_powered);
+}
+
+static void
+default_adapter_powered_cb (GObject    *gobject,
+			    GParamSpec *pspec,
+			    GtkWidget  *bar)
+{
+	downloads_bar_set_from_bluetooth_status (bar);
+}
+#endif /* HAVE_BLUETOOTH */
+
+static GtkWidget *
+caja_user_share_get_location_widget (CajaLocationWidgetProvider *iface,
+                                         const char                     *uri,
+                                         GtkWidget                      *window)
+{
+	GFile             *file;
+	GtkWidget         *bar;
+	guint              i;
+	gboolean           enable = FALSE;
+	GFile             *home;
+#ifdef HAVE_BLUETOOTH
+	const GUserDirectory special_dirs[] = { G_USER_DIRECTORY_PUBLIC_SHARE, G_USER_DIRECTORY_DOWNLOAD };
+
+	gboolean is_dir[] = { FALSE, FALSE };
+#else
+	const GUserDirectory special_dirs[] = { G_USER_DIRECTORY_PUBLIC_SHARE };
+
+	gboolean is_dir[] = { FALSE };
+#endif /* HAVE_BLUETOOTH */
+	file = g_file_new_for_uri (uri);
+	home = g_file_new_for_path (g_get_home_dir ());
+
+	/* We don't show anything in $HOME */
+	if (g_file_equal (home, file)) {
+		g_object_unref (home);
+		g_object_unref (file);
+		return NULL;
+	}
+
+	g_object_unref (home);
+
+	for (i = 0; i < G_N_ELEMENTS (special_dirs); i++) {
+		GFile *dir;
+		dir = lookup_dir_with_fallback (special_dirs[i]);
+		if (g_file_equal (dir, file)) {
+			enable = TRUE;
+			is_dir[i] = TRUE;
+		}
+		g_object_unref (dir);
+	}
+
+	g_object_unref (file);
+
+	if (enable == FALSE)
+		return NULL;
+
+	if (is_dir[0] != FALSE) {
+#ifdef HAVE_BLUETOOTH
+		if (is_dir[1] != FALSE) {
+			bar = caja_share_bar_new (_("May be used to share or receive files"));
+		} else {
+			bar = caja_share_bar_new (_("May be shared over the network or Bluetooth"));
+		}
+#else
+		bar = caja_share_bar_new (_("May be shared over the network"));
+#endif /* HAVE_BLUETOOTH */
+	} else {
+#ifdef HAVE_BLUETOOTH
+		BluetoothClient *client;
+
+		bar = caja_share_bar_new (_("May be used to receive files over Bluetooth"));
+
+		gtk_widget_set_no_show_all (bar, TRUE);
+		client = bluetooth_client_new ();
+		g_object_set_data_full (G_OBJECT (bar), "bluetooth-client", client, g_object_unref);
+		g_signal_connect (G_OBJECT (client), "notify::default-adapter-powered",
+				  G_CALLBACK (default_adapter_powered_cb), bar);
+		downloads_bar_set_from_bluetooth_status (bar);
+#endif /* HAVE_BLUETOOTH */
+	}
+
+	g_signal_connect (bar, "response",
+			  G_CALLBACK (bar_response_cb),
+			  window);
+
+	gtk_widget_show_all (bar);
+
+	return bar;
+}
+
+static void
+caja_user_share_location_widget_provider_iface_init (CajaLocationWidgetProviderIface *iface)
+{
+        iface->get_widget = caja_user_share_get_location_widget;
+}
+
+static void
+caja_user_share_instance_init (CajaUserShare *share)
+{
+
+}
+
+static void
+caja_user_share_class_init (CajaUserShareClass *klass)
+{
+
+}
+
+static GType share_type = 0;
+
+static GType
+caja_user_share_get_type (void)
+{
+        return share_type;
+}
+
+static void
+caja_user_share_register_type (GTypeModule *module)
+{
+        static const GTypeInfo info = {
+                sizeof (CajaUserShareClass),
+                (GBaseInitFunc) NULL,
+                (GBaseFinalizeFunc) NULL,
+                (GClassInitFunc) caja_user_share_class_init,
+                NULL,
+                NULL,
+                sizeof (CajaUserShare),
+                0,
+                (GInstanceInitFunc) caja_user_share_instance_init,
+        };
+
+        static const GInterfaceInfo location_widget_provider_iface_info = {
+                (GInterfaceInitFunc) caja_user_share_location_widget_provider_iface_init,
+                NULL,
+                NULL
+        };
+
+        share_type = g_type_module_register_type (module,
+                                                 G_TYPE_OBJECT,
+                                                 "CajaUserShare",
+                                                 &info, 0);
+
+        g_type_module_add_interface (module,
+                                     share_type,
+                                     CAJA_TYPE_LOCATION_WIDGET_PROVIDER,
+                                     &location_widget_provider_iface_info);
+}
+
+void
+caja_module_initialize (GTypeModule *module)
+{
+        caja_user_share_register_type (module);
+        bindtextdomain (GETTEXT_PACKAGE, MATELOCALEDIR);
+        bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
+}
+
+void
+caja_module_shutdown (void)
+{
+}
+
+void
+caja_module_list_types (const GType **types,
+                            int          *num_types)
+{
+        static GType type_list [1];
+
+        type_list[0] = CAJA_TYPE_USER_SHARE;
+
+        *types = type_list;
+        *num_types = 1;
+}
+
+
+
+
+ + + diff --git a/2021-03-09-235935-8562-cppcheck@52bc759bdcfd_master/4.html b/2021-03-09-235935-8562-cppcheck@52bc759bdcfd_master/4.html new file mode 100644 index 0000000..06db2f5 --- /dev/null +++ b/2021-03-09-235935-8562-cppcheck@52bc759bdcfd_master/4.html @@ -0,0 +1,1182 @@ + + + + + + Cppcheck - HTML report - mate-user-share + + + + + + +
+ +
+
  1
+  2
+  3
+  4
+  5
+  6
+  7
+  8
+  9
+ 10
+ 11
+ 12
+ 13
+ 14
+ 15
+ 16
+ 17
+ 18
+ 19
+ 20
+ 21
+ 22
+ 23
+ 24
+ 25
+ 26
+ 27
+ 28
+ 29
+ 30
+ 31
+ 32
+ 33
+ 34
+ 35
+ 36
+ 37
+ 38
+ 39
+ 40
+ 41
+ 42
+ 43
+ 44
+ 45
+ 46
+ 47
+ 48
+ 49
+ 50
+ 51
+ 52
+ 53
+ 54
+ 55
+ 56
+ 57
+ 58
+ 59
+ 60
+ 61
+ 62
+ 63
+ 64
+ 65
+ 66
+ 67
+ 68
+ 69
+ 70
+ 71
+ 72
+ 73
+ 74
+ 75
+ 76
+ 77
+ 78
+ 79
+ 80
+ 81
+ 82
+ 83
+ 84
+ 85
+ 86
+ 87
+ 88
+ 89
+ 90
+ 91
+ 92
+ 93
+ 94
+ 95
+ 96
+ 97
+ 98
+ 99
+100
+101
+102
+103
+104
+105
+106
+107
+108
+109
+110
+111
+112
+113
+114
+115
+116
+117
+118
+119
+120
+121
+122
+123
+124
+125
+126
+127
+128
+129
+130
+131
+132
+133
+134
+135
+136
+137
+138
+139
+140
+141
+142
+143
+144
+145
+146
+147
+148
+149
+150
+151
+152
+153
+154
+155
+156
+157
+158
+159
+160
+161
+162
+163
+164
+165
+166
+167
+168
+169
+170
+171
+172
+173
+174
+175
+176
+177
+178
+179
+180
+181
+182
+183
+184
+185
+186
+187
+188
+189
+190
+191
+192
+193
+194
+195
+196
+197
+198
+199
+200
+201
+202
+203
+204
+205
+206
+207
+208
+209
+210
+211
+212
+213
+214
+215
+216
+217
+218
+219
+220
+221
+222
+223
+224
+225
+226
+227
+228
+229
+230
+231
+232
+233
+234
+235
+236
+237
+238
+239
+240
+241
+242
+243
+244
+245
+246
+247
+248
+249
+250
+251
+252
+253
+254
+255
+256
+257
+258
+259
+260
+261
+262
+263
+264
+265
+266
+267
+268
+269
+270
+271
+272
+273
+274
+275
+276
+277
+278
+279
+280
+281
+282
+283
+284
+285
+286
+287
+288
+289
+290
+291
+292
+293
+294
+295
+296
+297
+298
+299
+300
+301
+302
+303
+304
+305
+306
+307
+308
+309
+310
+311
+312
+313
+314
+315
+316
+317
+318
+319
+320
+321
+322
+323
+324
+325
+326
+327
+328
+329
+330
+331
+332
+333
+334
+335
+336
+337
+338
+339
+340
+341
+342
+343
+344
+345
+346
+347
+348
+349
+350
+351
+352
+353
+354
+355
+356
+357
+358
+359
+360
+361
+362
+363
+364
+365
+366
+367
+368
+369
+370
+371
+372
+373
+374
+375
+376
+377
+378
+379
+380
+381
+382
+383
+384
+385
+386
+387
+388
+389
+390
+391
+392
+393
+394
+395
+396
+397
+398
+399
+400
+401
+402
+403
+404
+405
+406
+407
+408
+409
+410
+411
+412
+413
+414
+415
+416
+417
+418
+419
+420
+421
+422
+423
+424
+425
+426
+427
+428
+429
+430
+431
+432
+433
+434
+435
+436
+437
+438
+439
+440
+441
+442
+443
+444
+445
+446
+447
+448
+449
+450
+451
+452
+453
+454
+455
+456
+457
+458
+459
+460
+461
+462
+463
+464
+465
+466
+467
+468
+469
+470
+471
+472
+473
+474
+475
+476
+477
+478
+479
+480
+481
+482
+483
+484
+485
+486
+487
+488
+489
+490
+491
+492
+493
+494
+495
+496
+497
+498
+499
+500
+501
+502
+503
+504
+505
+506
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
+
+/*
+ *  Copyright (C) 2004-2008 Red Hat, Inc.
+ *
+ *  Caja is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU General Public License as
+ *  published by the Free Software Foundation; either version 2 of the
+ *  License, or (at your option) any later version.
+ *
+ *  Caja is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  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
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ *  Authors: Alexander Larsson <alexl@redhat.com>
+ *
+ */
+
+#include "config.h"
+
+#include <gdk/gdkx.h>
+#include <gtk/gtk.h>
+#include <glib/gi18n.h>
+#include <glib/gstdio.h>
+#include <gio/gio.h>
+#include <X11/Xlib.h>
+
+#include "user_share-private.h"
+#include "user_share-common.h"
+#include "http.h"
+
+#ifdef HAVE_BLUETOOTH
+#include <bluetooth-client.h>
+
+#include "obexftp.h"
+#include "obexpush.h"
+
+#endif /* HAVE_BLUETOOTH */
+
+#include <gio/gio.h>
+
+#include <stdarg.h>
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <signal.h>
+#include <unistd.h>
+
+static guint disabled_timeout_tag = 0;
+static GSettings* settings;<--- Shadowed declaration<--- Shadowed declaration<--- Shadowed declaration
+
+#define GSETTINGS_SCHEMA "org.mate.FileSharing"
+#define GSETTINGS_KEY_FILE_SHARING_ENABLED "enabled"
+#define GSETTINGS_KEY_FILE_SHARING_REQUIRE_PASSWORD "require-password"
+
+#ifdef HAVE_BLUETOOTH
+/* MATE Session */
+#define MATE_SESSION_DBUS_NAME      "org.gnome.SessionManager"
+#define MATE_SESSION_DBUS_OBJECT    "/org/gnome/SessionManager"
+#define MATE_SESSION_DBUS_INTERFACE "org.gnome.SessionManager"
+
+static GDBusProxy *session_proxy = NULL;
+static gboolean has_console = TRUE;
+
+static BluetoothClient *client = NULL;
+static gboolean bluetoothd_enabled = FALSE;
+
+#define OBEX_ENABLED (bluetoothd_enabled && has_console)
+
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_ENABLED "bluetooth-enabled"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_ALLOW_WRITE "bluetooth-allow-write"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_REQUIRE_PAIRING "bluetooth-require-pairing"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED "bluetooth-obexpush-enabled"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_ACCEPT_FILES "bluetooth-accept-files"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_NOTIFY "bluetooth-notify"
+
+
+static void
+obex_services_start (void)
+{
+	GSettings *settings;<--- Shadow variable
+
+	if (bluetoothd_enabled == FALSE ||
+	    has_console == FALSE)
+	    	return;
+
+	settings = g_settings_new(GSETTINGS_SCHEMA);
+
+	if (g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED) == TRUE) {
+	    obexpush_up ();
+	}
+	if (g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_ENABLED) == TRUE) {
+	    obexftp_up ();
+	}
+
+	g_object_unref (client);
+}
+
+static void
+obex_services_shutdown (void)
+{
+	obexpush_down ();
+	obexftp_down ();
+}
+
+static void
+session_properties_changed_cb (GDBusProxy      *session,
+			       GVariant        *changed,
+			       char           **invalidated,
+			       gpointer         user_data)
+{
+	GVariant *v;
+
+	v = g_variant_lookup_value (changed, "SessionIsActive", G_VARIANT_TYPE_BOOLEAN);
+	if (v) {
+		has_console = g_variant_get_boolean (v);
+		g_debug ("Received session is active change: now %s", has_console ? "active" : "inactive");
+
+		if (has_console)
+			obex_services_start ();
+		else
+			obex_services_shutdown ();
+
+		g_variant_unref (v);
+	}
+}
+
+static gboolean
+is_session_active (void)
+{
+	GVariant *variant;
+	gboolean is_session_active = FALSE;
+
+	variant = g_dbus_proxy_get_cached_property (session_proxy,
+						    "SessionIsActive");
+	if (variant) {
+		is_session_active = g_variant_get_boolean (variant);
+		g_variant_unref (variant);
+ 	}
+
+	return is_session_active;
+}
+
+static void
+session_init (void)
+{
+	GError *error = NULL;
+
+	session_proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION,
+						       G_DBUS_PROXY_FLAGS_NONE,
+						       NULL,
+						       MATE_SESSION_DBUS_NAME,
+						       MATE_SESSION_DBUS_OBJECT,
+						       MATE_SESSION_DBUS_INTERFACE,
+						       NULL,
+						       &error);
+	if (session_proxy == NULL) {
+		g_warning ("Failed to get session proxy: %s", error->message);
+		g_error_free (error);
+		return;
+	}
+	g_signal_connect (session_proxy, "g-properties-changed",
+			  G_CALLBACK (session_properties_changed_cb),
+			  NULL);
+	has_console = is_session_active ();
+}
+
+static void
+default_adapter_changed (GObject    *gobject,
+			 GParamSpec *pspec,
+			 gpointer    user_data)
+{
+	char *adapter;
+	gboolean adapter_powered;
+
+	g_object_get (G_OBJECT (client),
+		      "default-adapter", &adapter,
+		      "default-adapter-powered", &adapter_powered,
+		      NULL);
+	if (adapter != NULL && *adapter != '\0') {
+		bluetoothd_enabled = adapter_powered;
+	} else {
+		bluetoothd_enabled = FALSE;
+	}
+
+	/* Were we called as init, or as a callback */
+	if (gobject != NULL) {
+		if (bluetoothd_enabled != FALSE)
+			obex_services_start ();
+		else
+			obex_services_shutdown ();
+	}
+}
+
+static void
+bluez_init (void)
+{
+	client = bluetooth_client_new ();
+	default_adapter_changed (NULL, NULL, NULL);
+	g_signal_connect (G_OBJECT (client), "notify::default-adapter",
+			  G_CALLBACK (default_adapter_changed), NULL);
+	g_signal_connect (G_OBJECT (client), "notify::default-adapter-powered",
+			  G_CALLBACK (default_adapter_changed), NULL);
+}
+#endif /* HAVE_BLUETOOTH */
+
+static gboolean
+file_sharing_enabled (void)
+{
+	gboolean enabled = TRUE;
+	settings = g_settings_new (GSETTINGS_SCHEMA);
+
+#ifdef HAVE_BLUETOOTH
+	if (g_settings_get_boolean (settings, FILE_SHARING_ENABLED) == FALSE &&
+	    g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_ENABLED) == FALSE &&
+	    g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED) == FALSE)
+#else /* HAVE_BLUETOOTH */
+	if (g_settings_get_boolean (settings, FILE_SHARING_ENABLED) == FALSE)
+#endif /* HAVE_BLUETOOTH */
+		enabled = FALSE;
+
+	g_object_unref (settings);
+
+	return enabled;
+}
+
+static void
+migrate_old_configuration (void)
+{
+	const char *old_config_dir;
+	const char *new_config_dir;
+
+	old_config_dir = g_build_filename (g_get_home_dir (), ".mate2", "user-share", NULL);
+	new_config_dir = g_build_filename (g_get_user_config_dir (), "user-share", NULL);
+	if (g_file_test (old_config_dir, G_FILE_TEST_IS_DIR))
+		g_rename (old_config_dir, new_config_dir);
+
+}
+
+static void
+require_password_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	/* Need to restart to get new password setting */
+	if (http_get_pid () != 0) {
+		http_down ();
+		http_up ();
+	}
+}
+
+/* File sharing was disabled for some time, exit now */
+/* If we re-enable it in the ui, this will be restarted anyway */
+static gboolean
+disabled_timeout_callback (gpointer user_data)
+{
+	GSettings *settings = (GSettings *) user_data;<--- Shadow variable
+	http_down ();
+
+#ifdef HAVE_BLUETOOTH
+	if (g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_ENABLED) == FALSE &&
+	    g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED) == FALSE)
+		_exit (0);
+#else /* HAVE_BLUETOOTH */
+	if (g_settings_get_boolean (settings, FILE_SHARING_ENABLED) == FALSE)
+		_exit (0);
+#endif /* HAVE_BLUETOOTH */
+	return FALSE;
+}
+
+static void
+file_sharing_enabled_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	gboolean enabled;
+
+	if (disabled_timeout_tag != 0) {
+		g_source_remove (disabled_timeout_tag);
+		disabled_timeout_tag = 0;
+	}
+
+	enabled = g_settings_get_boolean (settings,
+					 FILE_SHARING_ENABLED);
+	if (enabled) {
+		if (http_get_pid () == 0) {
+			http_up ();
+		}
+	} else {
+		http_down ();
+		disabled_timeout_tag = g_timeout_add_seconds (3,
+							      (GSourceFunc)disabled_timeout_callback,
+							      settings);
+	}
+}
+
+#ifdef HAVE_BLUETOOTH
+static void
+file_sharing_bluetooth_allow_write_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	if (g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_ENABLED) != FALSE)
+		obexftp_restart ();
+}
+
+static void
+file_sharing_bluetooth_require_pairing_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	if (g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_ENABLED) != FALSE) {
+		/* We need to fully reset the session,
+		 * otherwise the new setting isn't taken into account */
+		obexftp_down ();
+		obexftp_up ();
+	}
+}
+
+static void
+file_sharing_bluetooth_enabled_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	if (g_settings_get_boolean (settings,
+				   FILE_SHARING_BLUETOOTH_ENABLED) == FALSE) {
+		obexftp_down ();
+		if (g_settings_get_boolean (settings, FILE_SHARING_ENABLED) == FALSE &&
+		    g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED) == FALSE) {
+			_exit (0);
+		}
+	} else if (OBEX_ENABLED) {
+		obexftp_up ();
+	}
+}
+
+static void
+file_sharing_bluetooth_obexpush_enabled_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	if (g_settings_get_boolean (settings,
+				   FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED) == FALSE) {
+		obexpush_down ();
+		if (g_settings_get_boolean (settings, FILE_SHARING_ENABLED) == FALSE &&
+		    g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_ENABLED) == FALSE) {
+			_exit (0);
+		}
+	} else if (OBEX_ENABLED) {
+		obexpush_up ();
+	}
+}
+
+static void
+file_sharing_bluetooth_obexpush_accept_files_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	AcceptSetting setting;
+	char *str;
+
+	str = g_settings_get_string (settings, FILE_SHARING_BLUETOOTH_OBEXPUSH_ACCEPT_FILES);
+	setting = accept_setting_from_string (str);
+	g_free (str);
+
+	obexpush_set_accept_files_policy (setting);
+}
+
+static void
+file_sharing_bluetooth_obexpush_notify_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	obexpush_set_notify (g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_OBEXPUSH_NOTIFY));
+}
+#endif /* HAVE_BLUETOOTH */
+
+static RETSIGTYPE
+cleanup_handler (int sig)
+{
+	http_down ();
+#ifdef HAVE_BLUETOOTH
+	obexftp_down ();
+	obexpush_down ();
+#endif /* HAVE_BLUETOOTH */
+	_exit (2);
+}
+
+static int
+x_io_error_handler (Display *xdisplay)
+{
+	http_down ();
+#ifdef HAVE_BLUETOOTH
+	obexftp_down ();
+#endif /* HAVE_BLUETOOTH */
+	_exit (2);
+}
+
+int
+main (int argc, char **argv)
+{
+	GSettings *settings;<--- Shadow variable
+	Display *xdisplay;
+	G_GNUC_UNUSED int x_fd;
+	Window selection_owner;
+	Atom xatom;
+
+	bindtextdomain (GETTEXT_PACKAGE, MATELOCALEDIR);
+	bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
+	textdomain (GETTEXT_PACKAGE);
+
+	gtk_init (&argc, &argv);
+
+	if (g_strcmp0 (g_get_real_name (), "root") == 0) {
+		g_warning ("mate-user-share cannot be started as root for security reasons.");
+		return 1;
+	}
+
+	signal (SIGPIPE, SIG_IGN);
+	signal (SIGINT, cleanup_handler);
+	signal (SIGHUP, cleanup_handler);
+	signal (SIGTERM, cleanup_handler);
+
+	xdisplay = GDK_DISPLAY_XDISPLAY (gdk_display_get_default ());
+	if (xdisplay == NULL) {
+		g_warning ("Can't open display");
+		return 1;
+	}
+
+	xatom = XInternAtom (xdisplay, "_MATE_USER_SHARE", FALSE);
+	selection_owner = XGetSelectionOwner (xdisplay, xatom);
+
+	if (selection_owner != None) {
+		/* There is an owner already, quit */
+		return 1;
+	}
+
+	selection_owner = XCreateSimpleWindow (xdisplay,
+					       RootWindow (xdisplay, 0),
+					       0, 0, 1, 1,
+					       0, 0, 0);
+	XSetSelectionOwner (xdisplay, xatom, selection_owner, CurrentTime);
+
+	if (XGetSelectionOwner (xdisplay, xatom) != selection_owner) {
+		/* Didn't get the selection */
+		return 1;
+	}
+
+	migrate_old_configuration ();
+
+	if (!file_sharing_enabled ())
+		return 1;
+
+	settings = g_settings_new (GSETTINGS_SCHEMA);
+
+	x_fd = ConnectionNumber (xdisplay);
+	XSetIOErrorHandler (x_io_error_handler);
+
+	if (http_init () == FALSE)
+		return 1;
+#ifdef HAVE_BLUETOOTH
+	if (obexftp_init () == FALSE)
+		return 1;
+	if (obexpush_init () == FALSE)
+		return 1;
+#endif /* HAVE_BLUETOOTH */
+
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_ENABLED,
+			     G_CALLBACK (file_sharing_enabled_changed), NULL);
+
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_REQUIRE_PASSWORD,
+			     G_CALLBACK (require_password_changed), NULL);
+
+#ifdef HAVE_BLUETOOTH
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_ENABLED,
+			     G_CALLBACK (file_sharing_bluetooth_enabled_changed), NULL);
+
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_ALLOW_WRITE,
+			     G_CALLBACK (file_sharing_bluetooth_allow_write_changed), NULL);
+
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_REQUIRE_PAIRING,
+			     G_CALLBACK (file_sharing_bluetooth_require_pairing_changed), NULL);
+
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED,
+			     G_CALLBACK (file_sharing_bluetooth_obexpush_enabled_changed), NULL);
+
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_ACCEPT_FILES,
+			     G_CALLBACK (file_sharing_bluetooth_obexpush_accept_files_changed), NULL);
+
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_NOTIFY,
+			     G_CALLBACK (file_sharing_bluetooth_obexpush_notify_changed), NULL);
+
+	bluez_init ();
+	session_init ();
+#endif /* HAVE_BLUETOOTH */
+
+	/* Initial setting */
+	file_sharing_enabled_changed (settings, NULL, NULL);
+#ifdef HAVE_BLUETOOTH
+	file_sharing_bluetooth_enabled_changed (settings, NULL, NULL);
+	file_sharing_bluetooth_obexpush_accept_files_changed (settings, NULL, NULL);
+	file_sharing_bluetooth_obexpush_notify_changed (settings, NULL, NULL);
+	file_sharing_bluetooth_obexpush_enabled_changed (settings, NULL, NULL);
+#endif /* HAVE_BLUETOOTH */
+
+	gtk_main ();
+
+	return 0;
+}
+
+
+
+
+ + + diff --git a/2021-03-09-235935-8562-cppcheck@52bc759bdcfd_master/index.html b/2021-03-09-235935-8562-cppcheck@52bc759bdcfd_master/index.html new file mode 100644 index 0000000..bbcd983 --- /dev/null +++ b/2021-03-09-235935-8562-cppcheck@52bc759bdcfd_master/index.html @@ -0,0 +1,141 @@ + + + + + + Cppcheck - HTML report - mate-user-share + + + + + + +
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
LineIdCWESeverityMessage
missingIncludeinformationCppcheck cannot find all the include files (use --check-config for details)
src/file-share-properties.c
82variableScope398styleThe scope of the variable 'password' can be reduced.
97shadowVariable398styleLocal variable 'settings' shadows outer variable
105unusedVariable563styleUnused variable: accept_setting
249shadowVariable398styleLocal variable 'settings' shadows outer variable
273shadowVariable398styleLocal variable 'settings' shadows outer variable
294shadowVariable398styleLocal variable 'settings' shadows outer variable
323shadowVariable398styleLocal variable 'settings' shadows outer variable
340shadowVariable398styleLocal variable 'settings' shadows outer variable
357shadowVariable398styleLocal variable 'settings' shadows outer variable
377shadowVariable398styleLocal variable 'settings' shadows outer variable
393shadowVariable398styleLocal variable 'settings' shadows outer variable
457shadowVariable398styleLocal variable 'settings' shadows outer variable
620variableScope398styleThe scope of the variable 'window' can be reduced.
src/http.c
114variableScope398styleThe scope of the variable 'host_name' can be reduced.
src/obexpush.c
187shadowVariable398styleLocal variable 'connection' shadows outer variable
src/share-extension.c
61variableScope398styleThe scope of the variable 'dialog' can be reduced.
src/user_share.c
86shadowVariable398styleLocal variable 'settings' shadows outer variable
260shadowVariable398styleLocal variable 'settings' shadows outer variable
391shadowVariable398styleLocal variable 'settings' shadows outer variable
+
+
+ + + diff --git a/2021-03-09-235935-8562-cppcheck@52bc759bdcfd_master/stats.html b/2021-03-09-235935-8562-cppcheck@52bc759bdcfd_master/stats.html new file mode 100644 index 0000000..2020977 --- /dev/null +++ b/2021-03-09-235935-8562-cppcheck@52bc759bdcfd_master/stats.html @@ -0,0 +1,109 @@ + + + + + + Cppcheck - HTML report - mate-user-share + + + + + + +
+ +
+

Top 10 files for style severity, total findings: 19
+   13  src/file-share-properties.c
+   3   src/user_share.c
+   1   src/share-extension.c
+   1   src/obexpush.c
+   1   src/http.c
+

+ +
+
+ + + diff --git a/2021-03-09-235935-8562-cppcheck@52bc759bdcfd_master/style.css b/2021-03-09-235935-8562-cppcheck@52bc759bdcfd_master/style.css new file mode 100644 index 0000000..07125f4 --- /dev/null +++ b/2021-03-09-235935-8562-cppcheck@52bc759bdcfd_master/style.css @@ -0,0 +1,137 @@ + +body { + font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif; + font-size: 13px; + line-height: 1.5; + margin: 0; + width: auto; +} + +h1 { + margin: 10px; +} + +.header { + border-bottom: thin solid #aaa; +} + +.footer { + border-top: thin solid #aaa; + font-size: 90%; + margin-top: 5px; +} + +.footer ul { + list-style-type: none; + padding-left: 0; +} + +.footer > p { + margin: 4px; +} + +.wrapper { + display: -webkit-box; + display: -ms-flexbox; + display: flex; + -webkit-box-pack: justify; + -ms-flex-pack: justify; + justify-content: space-between; +} + +#menu, +#menu_index { + text-align: left; + width: 350px; + height: 90vh; + min-height: 200px; + overflow: auto; + position: -webkit-sticky; + position: sticky; + top: 0; + padding: 0 15px 15px 15px; +} + +#menu > a { + display: block; + margin-left: 10px; + font-size: 12px; + z-index: 1; +} + +#content, +#content_index { + background-color: #fff; + -webkit-box-sizing: content-box; + -moz-box-sizing: content-box; + box-sizing: content-box; + padding: 0 15px 15px 15px; + width: calc(100% - 350px); + height: 100%; + overflow-x: auto; +} + +#filename { + margin-left: 10px; + font-size: 12px; + z-index: 1; +} + +.error { + background-color: #ffb7b7; +} + +.error2 { + background-color: #faa; + display: inline-block; + margin-left: 4px; +} + +.inconclusive { + background-color: #b6b6b4; +} + +.inconclusive2 { + background-color: #b6b6b4; + display: inline-block; + margin-left: 4px; +} + +.verbose { + display: inline-block; + vertical-align: top; + cursor: help; +} + +.verbose .content { + display: none; + position: absolute; + padding: 10px; + margin: 4px; + max-width: 40%; + white-space: pre-wrap; + border: 1px solid #000; + background-color: #ffffcc; + cursor: auto; +} + +.highlight .hll { + padding: 1px; +} + +.highlighttable { + background-color: #fff; + z-index: 10; + position: relative; + margin: -10px; +} + +.linenos { + border-right: thin solid #aaa; + color: #d3d3d3; + padding-right: 6px; +} + +.d-none { + display: none; +} diff --git a/2021-03-27-160708-9454-cppcheck@bc0bdef34681_master/0.html b/2021-03-27-160708-9454-cppcheck@bc0bdef34681_master/0.html new file mode 100644 index 0000000..74c198b --- /dev/null +++ b/2021-03-27-160708-9454-cppcheck@bc0bdef34681_master/0.html @@ -0,0 +1,1498 @@ + + + + + + Cppcheck - HTML report - mate-user-share + + + + + + +
+ +
+
  1
+  2
+  3
+  4
+  5
+  6
+  7
+  8
+  9
+ 10
+ 11
+ 12
+ 13
+ 14
+ 15
+ 16
+ 17
+ 18
+ 19
+ 20
+ 21
+ 22
+ 23
+ 24
+ 25
+ 26
+ 27
+ 28
+ 29
+ 30
+ 31
+ 32
+ 33
+ 34
+ 35
+ 36
+ 37
+ 38
+ 39
+ 40
+ 41
+ 42
+ 43
+ 44
+ 45
+ 46
+ 47
+ 48
+ 49
+ 50
+ 51
+ 52
+ 53
+ 54
+ 55
+ 56
+ 57
+ 58
+ 59
+ 60
+ 61
+ 62
+ 63
+ 64
+ 65
+ 66
+ 67
+ 68
+ 69
+ 70
+ 71
+ 72
+ 73
+ 74
+ 75
+ 76
+ 77
+ 78
+ 79
+ 80
+ 81
+ 82
+ 83
+ 84
+ 85
+ 86
+ 87
+ 88
+ 89
+ 90
+ 91
+ 92
+ 93
+ 94
+ 95
+ 96
+ 97
+ 98
+ 99
+100
+101
+102
+103
+104
+105
+106
+107
+108
+109
+110
+111
+112
+113
+114
+115
+116
+117
+118
+119
+120
+121
+122
+123
+124
+125
+126
+127
+128
+129
+130
+131
+132
+133
+134
+135
+136
+137
+138
+139
+140
+141
+142
+143
+144
+145
+146
+147
+148
+149
+150
+151
+152
+153
+154
+155
+156
+157
+158
+159
+160
+161
+162
+163
+164
+165
+166
+167
+168
+169
+170
+171
+172
+173
+174
+175
+176
+177
+178
+179
+180
+181
+182
+183
+184
+185
+186
+187
+188
+189
+190
+191
+192
+193
+194
+195
+196
+197
+198
+199
+200
+201
+202
+203
+204
+205
+206
+207
+208
+209
+210
+211
+212
+213
+214
+215
+216
+217
+218
+219
+220
+221
+222
+223
+224
+225
+226
+227
+228
+229
+230
+231
+232
+233
+234
+235
+236
+237
+238
+239
+240
+241
+242
+243
+244
+245
+246
+247
+248
+249
+250
+251
+252
+253
+254
+255
+256
+257
+258
+259
+260
+261
+262
+263
+264
+265
+266
+267
+268
+269
+270
+271
+272
+273
+274
+275
+276
+277
+278
+279
+280
+281
+282
+283
+284
+285
+286
+287
+288
+289
+290
+291
+292
+293
+294
+295
+296
+297
+298
+299
+300
+301
+302
+303
+304
+305
+306
+307
+308
+309
+310
+311
+312
+313
+314
+315
+316
+317
+318
+319
+320
+321
+322
+323
+324
+325
+326
+327
+328
+329
+330
+331
+332
+333
+334
+335
+336
+337
+338
+339
+340
+341
+342
+343
+344
+345
+346
+347
+348
+349
+350
+351
+352
+353
+354
+355
+356
+357
+358
+359
+360
+361
+362
+363
+364
+365
+366
+367
+368
+369
+370
+371
+372
+373
+374
+375
+376
+377
+378
+379
+380
+381
+382
+383
+384
+385
+386
+387
+388
+389
+390
+391
+392
+393
+394
+395
+396
+397
+398
+399
+400
+401
+402
+403
+404
+405
+406
+407
+408
+409
+410
+411
+412
+413
+414
+415
+416
+417
+418
+419
+420
+421
+422
+423
+424
+425
+426
+427
+428
+429
+430
+431
+432
+433
+434
+435
+436
+437
+438
+439
+440
+441
+442
+443
+444
+445
+446
+447
+448
+449
+450
+451
+452
+453
+454
+455
+456
+457
+458
+459
+460
+461
+462
+463
+464
+465
+466
+467
+468
+469
+470
+471
+472
+473
+474
+475
+476
+477
+478
+479
+480
+481
+482
+483
+484
+485
+486
+487
+488
+489
+490
+491
+492
+493
+494
+495
+496
+497
+498
+499
+500
+501
+502
+503
+504
+505
+506
+507
+508
+509
+510
+511
+512
+513
+514
+515
+516
+517
+518
+519
+520
+521
+522
+523
+524
+525
+526
+527
+528
+529
+530
+531
+532
+533
+534
+535
+536
+537
+538
+539
+540
+541
+542
+543
+544
+545
+546
+547
+548
+549
+550
+551
+552
+553
+554
+555
+556
+557
+558
+559
+560
+561
+562
+563
+564
+565
+566
+567
+568
+569
+570
+571
+572
+573
+574
+575
+576
+577
+578
+579
+580
+581
+582
+583
+584
+585
+586
+587
+588
+589
+590
+591
+592
+593
+594
+595
+596
+597
+598
+599
+600
+601
+602
+603
+604
+605
+606
+607
+608
+609
+610
+611
+612
+613
+614
+615
+616
+617
+618
+619
+620
+621
+622
+623
+624
+625
+626
+627
+628
+629
+630
+631
+632
+633
+634
+635
+636
+637
+638
+639
+640
+641
+642
+643
+644
+645
+646
+647
+648
+649
+650
+651
+652
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
+
+/*
+ *  Copyright (C) 2004 Red Hat, Inc.
+ *
+ *  Caja is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU General Public License as
+ *  published by the Free Software Foundation; either version 2 of the
+ *  License, or (at your option) any later version.
+ *
+ *  Caja is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  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
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ *  Authors: Alexander Larsson <alexl@redhat.com>
+ *
+ */
+
+#include "config.h"
+
+#include <string.h>
+#include <stdio.h>
+
+#include <gtk/gtk.h>
+#include <glib/gi18n.h>
+#include <gio/gio.h>
+
+#include "user_share-private.h"
+
+#define REALM "Please log in as the user guest"
+#define USER "guest"
+#define GSETTINGS_SCHEMA "org.mate.FileSharing"
+#define GSETTINGS_KEY_FILE_SHARING_ENABLED "enabled"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_ENABLED "bluetooth-enabled"
+#define GSETTINGS_KEY_FILE_SHARING_REQUIRE_PASSWORD "require-password"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_ALLOW_WRITE "bluetooth-allow-write"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_REQUIRE_PAIRING "bluetooth-require-pairing"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED "bluetooth-obexpush-enabled"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_ACCEPT_FILES "bluetooth-accept-files"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_NOTIFY "bluetooth-notify"
+
+static GtkBuilder* builder;
+static GSettings* settings;<--- Shadowed declaration<--- Shadowed declaration<--- Shadowed declaration<--- Shadowed declaration<--- Shadowed declaration<--- Shadowed declaration<--- Shadowed declaration<--- Shadowed declaration<--- Shadowed declaration<--- Shadowed declaration
+
+
+static void
+write_out_password (const char *password)
+{
+    char *to_hash;
+    char *ascii_digest;
+    char *line;
+    char *filename;
+    FILE *file;
+
+    to_hash = g_strdup_printf ("%s:%s:%s", USER, REALM, password);
+    ascii_digest = g_compute_checksum_for_string (G_CHECKSUM_MD5, to_hash, strlen (to_hash));
+    g_free (to_hash);
+    line = g_strdup_printf ("%s:%s:%s\n", USER, REALM, ascii_digest);
+    g_free (ascii_digest);
+
+    filename = g_build_filename (g_get_user_config_dir (), "user-share", "passwd", NULL);
+
+    file = fopen (filename, "w");
+    if (file != NULL) {
+	fwrite (line, strlen (line), 1, file);
+	fclose (file);
+    }
+
+    g_free (filename);
+    g_free (line);
+}
+
+static void
+flush_password (void)
+{
+    GtkWidget *password_entry;
+    const char *password;
+
+    password_entry = GTK_WIDGET (gtk_builder_get_object (builder, "password_entry"));
+
+    if (g_object_get_data (G_OBJECT( password_entry), "user_edited")) {
+	password = gtk_entry_get_text (GTK_ENTRY (password_entry));
+	if (password != NULL && password[0] != 0)
+	    write_out_password (password);
+    }
+}
+
+
+static void
+update_ui (void)
+{
+    GSettings *settings;<--- Shadow variable
+    gboolean enabled;
+#ifdef HAVE_BLUETOOTH
+    gboolean bluetooth_enabled, bluetooth_write_enabled, require_pairing_enabled;
+    gboolean bluetooth_obexpush_enabled, bluetooth_obexpush_notify;
+#endif /* HAVE_BLUETOOTH */
+    char *str;
+    PasswordSetting password_setting;
+    AcceptSetting accept_setting;<--- Unused variable: accept_setting
+    GtkWidget *check;
+    GtkWidget *password_combo;
+    GtkWidget *password_entry;
+#ifdef HAVE_BLUETOOTH
+    GtkWidget *vbox_share_bluetooth;
+    GtkWidget *vbox_receive_bluetooth;
+    GtkWidget *bluetooth_check;
+    GtkWidget *allow_write_bluetooth_check;
+    GtkWidget *require_pairing_check;
+    GtkWidget *enable_obexpush_check;
+    GtkWidget *accept_obexpush_combo;
+    GtkWidget *notify_received_obexpush_check;
+#endif /* HAVE_BLUETOOTH */
+
+    settings = g_settings_new (GSETTINGS_SCHEMA);
+
+    enabled = g_settings_get_boolean (settings,
+				     FILE_SHARING_ENABLED);
+
+    str = g_settings_get_string (settings, FILE_SHARING_REQUIRE_PASSWORD);
+    password_setting = password_setting_from_string (str);
+    g_free (str);
+
+#ifdef HAVE_BLUETOOTH
+    bluetooth_enabled = g_settings_get_boolean (settings,
+    					       FILE_SHARING_BLUETOOTH_ENABLED);
+    bluetooth_write_enabled = g_settings_get_boolean (settings,
+						     FILE_SHARING_BLUETOOTH_ALLOW_WRITE);
+    require_pairing_enabled = g_settings_get_boolean (settings,
+    						     FILE_SHARING_BLUETOOTH_REQUIRE_PAIRING);
+    bluetooth_obexpush_enabled = g_settings_get_boolean (settings,
+    							FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED);
+    bluetooth_obexpush_notify = g_settings_get_boolean (settings,
+    						       FILE_SHARING_BLUETOOTH_OBEXPUSH_NOTIFY);
+
+    str = g_settings_get_string (settings, FILE_SHARING_BLUETOOTH_OBEXPUSH_ACCEPT_FILES);
+    accept_setting = accept_setting_from_string (str);
+    g_free (str);
+#endif /* HAVE_BLUETOOTH */
+
+    check = GTK_WIDGET (gtk_builder_get_object (builder, "enable_check"));
+    password_combo = GTK_WIDGET (gtk_builder_get_object (builder, "password_combo"));
+    password_entry = GTK_WIDGET (gtk_builder_get_object (builder, "password_entry"));
+#ifdef HAVE_BLUETOOTH
+    vbox_share_bluetooth = GTK_WIDGET (gtk_builder_get_object (builder, "vbox_share_bluetooth"));
+    vbox_receive_bluetooth = GTK_WIDGET (gtk_builder_get_object (builder, "vbox_receive_bluetooth"));
+    bluetooth_check = GTK_WIDGET (gtk_builder_get_object (builder, "enable_bluetooth_check"));
+    allow_write_bluetooth_check = GTK_WIDGET (gtk_builder_get_object (builder, "allow_write_bluetooth_check"));
+    require_pairing_check = GTK_WIDGET (gtk_builder_get_object (builder, "require_pairing_check"));
+    enable_obexpush_check = GTK_WIDGET (gtk_builder_get_object (builder, "enable_obexpush_check"));
+    accept_obexpush_combo = GTK_WIDGET (gtk_builder_get_object (builder, "accept_obexpush_combo"));
+    notify_received_obexpush_check = GTK_WIDGET (gtk_builder_get_object (builder, "notify_received_obexpush_check"));
+#endif /* HAVE_BLUETOOTH */
+
+    /* Network */
+    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (check), enabled);
+    gtk_widget_set_sensitive (password_combo, enabled);
+    gtk_widget_set_sensitive (password_entry, enabled && password_setting != PASSWORD_NEVER);
+
+    gtk_combo_box_set_active (GTK_COMBO_BOX (password_combo),
+			      password_setting);
+
+#ifdef HAVE_BLUETOOTH
+    /* Bluetooth ObexFTP */
+    gtk_widget_set_visible (vbox_share_bluetooth, TRUE);
+    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (bluetooth_check), bluetooth_enabled);
+    gtk_widget_set_sensitive (allow_write_bluetooth_check, bluetooth_enabled);
+    gtk_widget_set_sensitive (require_pairing_check, bluetooth_enabled);
+
+    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (allow_write_bluetooth_check),
+    				  bluetooth_write_enabled);
+    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (require_pairing_check),
+    				  require_pairing_enabled);
+
+    /* Bluetooth ObexPush */
+    gtk_widget_set_visible (vbox_receive_bluetooth, TRUE);
+    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (enable_obexpush_check), bluetooth_obexpush_enabled);
+    gtk_widget_set_sensitive (accept_obexpush_combo, bluetooth_obexpush_enabled);
+    gtk_widget_set_sensitive (notify_received_obexpush_check, bluetooth_obexpush_enabled);
+
+    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (notify_received_obexpush_check),
+    				  bluetooth_obexpush_notify);
+
+    gtk_combo_box_set_active (GTK_COMBO_BOX (accept_obexpush_combo),
+    			      accept_setting);
+#endif /* HAVE_BLUETOOTH */
+
+    g_object_unref (settings);
+}
+
+static void
+file_sharing_enabled_changed (GSettings *settings, gchar *key, gpointer data)
+{
+    update_ui ();
+}
+
+static void
+password_required_changed (GSettings *settings, gchar *key, gpointer data)
+{
+    update_ui ();
+}
+
+#ifdef HAVE_BLUETOOTH
+static void
+file_sharing_bluetooth_enabled_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	update_ui ();
+}
+
+static void
+file_sharing_bluetooth_allow_write_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	update_ui ();
+}
+
+static void
+file_sharing_bluetooth_require_pairing_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	update_ui ();
+}
+
+static void
+file_sharing_bluetooth_obexpush_enabled_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	update_ui ();
+}
+
+static void
+file_sharing_bluetooth_obexpush_accept_files_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	update_ui ();
+}
+
+static void
+file_sharing_bluetooth_obexpush_notify_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	update_ui ();
+}
+#endif /* HAVE_BLUETOOTH */
+
+static void
+password_combo_changed (GtkComboBox *combo_box)
+{
+    GSettings *settings;<--- Shadow variable
+    guint setting;
+
+    setting = gtk_combo_box_get_active (combo_box);
+
+    settings = g_settings_new (GSETTINGS_SCHEMA) ;
+
+    g_settings_set_string (settings,
+			     FILE_SHARING_REQUIRE_PASSWORD,
+			     password_string_from_setting (setting));
+    g_object_unref (settings);
+}
+
+static void
+launch_share (void)
+{
+	if (!g_spawn_command_line_async (USER_SHARE_PROGRAM, NULL))
+		g_warning ("Unable to start mate-user-share program");
+}
+
+#ifdef HAVE_BLUETOOTH
+static void
+enable_bluetooth_check_toggled (GtkWidget *check)
+{
+	GSettings *settings;<--- Shadow variable
+	gboolean enabled;
+
+	enabled = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check));
+
+	settings = g_settings_new (GSETTINGS_SCHEMA) ;
+
+	g_settings_set_boolean (settings,
+			       FILE_SHARING_BLUETOOTH_ENABLED,
+			       enabled);
+
+	g_object_unref (settings);
+
+	if (enabled != FALSE)
+		launch_share ();
+}
+#endif /* HAVE_BLUETOOTH */
+
+static void
+enable_check_toggled (GtkWidget *check)
+{
+	GSettings *settings;<--- Shadow variable
+	gboolean enabled;
+
+	enabled = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check));
+
+	settings = g_settings_new (GSETTINGS_SCHEMA);
+
+	g_settings_set_boolean (settings,
+			       FILE_SHARING_ENABLED,
+			       enabled);
+
+	g_object_unref (settings);
+
+	if (enabled != FALSE)
+		launch_share ();
+}
+
+static void
+password_entry_changed (GtkEditable *editable)
+{
+	g_object_set_data (G_OBJECT (editable),
+			   "user_edited", GINT_TO_POINTER (1));
+	flush_password ();
+}
+
+#ifdef HAVE_BLUETOOTH
+static void
+bluetooth_allow_write_check_toggled (GtkWidget *check)
+{
+	GSettings *settings;<--- Shadow variable
+	gboolean enabled;
+
+	enabled = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check));
+
+	settings = g_settings_new (GSETTINGS_SCHEMA) ;
+
+	g_settings_set_boolean (settings,
+			       FILE_SHARING_BLUETOOTH_ALLOW_WRITE,
+			       enabled);
+
+	g_object_unref (settings);
+}
+
+static void
+bluetooth_require_pairing_check_toggled (GtkWidget *check)
+{
+	GSettings *settings;<--- Shadow variable
+	gboolean enabled;
+
+	enabled = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check));
+
+	settings = g_settings_new (GSETTINGS_SCHEMA) ;
+
+	g_settings_set_boolean (settings,
+			       FILE_SHARING_BLUETOOTH_REQUIRE_PAIRING,
+			       enabled);
+
+	g_object_unref (settings);
+}
+
+static void
+enable_obexpush_check_toggled (GtkWidget *check)
+{
+	GSettings *settings;<--- Shadow variable
+	gboolean enabled;
+
+	enabled = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check));
+
+	settings = g_settings_new (GSETTINGS_SCHEMA) ;
+
+	g_settings_set_boolean (settings,
+			       FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED,
+			       enabled);
+
+	g_object_unref (settings);
+
+	if (enabled != FALSE)
+		launch_share ();
+}
+
+static void
+accept_obexpush_combo_changed (GtkComboBox *combo_box)
+{
+    GSettings *settings;<--- Shadow variable
+    guint setting;
+
+    setting = gtk_combo_box_get_active (combo_box);
+
+    settings = g_settings_new (GSETTINGS_SCHEMA) ;
+
+    g_settings_set_string (settings,
+			     FILE_SHARING_BLUETOOTH_OBEXPUSH_ACCEPT_FILES,
+			     accept_string_from_setting (setting));
+    g_object_unref (settings);
+}
+
+static void
+notify_received_obexpush_check_toggled (GtkWidget *check)
+{
+	GSettings *settings;<--- Shadow variable
+	gboolean enabled;
+
+	enabled = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check));
+
+	settings = g_settings_new (GSETTINGS_SCHEMA) ;
+
+	g_settings_set_boolean (settings,
+			       FILE_SHARING_BLUETOOTH_OBEXPUSH_NOTIFY,
+			       enabled);
+
+	g_object_unref (settings);
+}
+#endif /* HAVE_BLUETOOTH */
+
+static GtkWidget *
+error_dialog (const char *title,
+	      const char *reason,
+	      GtkWindow *parent)
+{
+	GtkWidget *error_dialog;
+
+	if (reason == NULL)
+		reason = _("No reason");
+
+	error_dialog =
+		gtk_message_dialog_new (parent,
+					GTK_DIALOG_MODAL,
+					GTK_MESSAGE_ERROR,
+					GTK_BUTTONS_OK,
+					"%s", title);
+	gtk_message_dialog_format_secondary_text
+		(GTK_MESSAGE_DIALOG (error_dialog), "%s", reason);
+
+	gtk_window_set_title (GTK_WINDOW (error_dialog), ""); /* as per HIG */
+	gtk_container_set_border_width (GTK_CONTAINER (error_dialog), 5);
+	gtk_dialog_set_default_response (GTK_DIALOG (error_dialog),
+					 GTK_RESPONSE_OK);
+	gtk_window_set_modal (GTK_WINDOW (error_dialog), TRUE);
+
+	return error_dialog;
+}
+
+static void
+help_button_clicked (GtkButton *button, GtkWidget *window)
+{
+	GError *error = NULL;
+
+	if (gtk_show_uri_on_window (GTK_WINDOW (window), "help:mate-user-share", gtk_get_current_event_time (), &error) == FALSE) {
+		GtkWidget *dialog;
+
+		dialog = error_dialog (_("Could not display the help contents."), error->message, GTK_WINDOW (window));
+		g_signal_connect (G_OBJECT (dialog), "response", G_CALLBACK
+				  (gtk_widget_destroy), error_dialog);
+		gtk_window_present (GTK_WINDOW (dialog));
+
+		g_error_free (error);
+	}
+}
+
+static GtkWidget *
+create_window (void)
+{
+    GError *error = NULL;
+    GSettings *settings;<--- Shadow variable
+    GtkWidget *check;
+    GtkWidget *password_combo;
+    GtkWidget *password_entry;
+#ifdef HAVE_BLUETOOTH
+    GtkWidget *bluetooth_check;
+    GtkWidget *bluetooth_allow_write_check;
+    GtkWidget *require_pairing_check;
+    GtkWidget *enable_obexpush_check;
+    GtkWidget *accept_obexpush_combo;
+    GtkWidget *notify_received_obexpush_check;
+#endif /* HAVE_BLUETOOTH */
+    GtkWidget *window;
+    GtkListStore *store;
+    GtkCellRenderer *cell;
+    GtkTreeIter iter;
+
+    builder = gtk_builder_new ();
+    gtk_builder_add_from_file (builder, DATADIR"file-share-properties.ui", &error);
+
+    if (error) {
+      GtkWidget *dialog;
+
+      dialog = error_dialog (_("Could not build interface."), error->message, NULL);
+      gtk_dialog_run (GTK_DIALOG (dialog));
+      gtk_widget_destroy (dialog);
+
+      g_error_free (error);
+      return NULL;
+    }
+
+    window = GTK_WIDGET (gtk_builder_get_object (builder, "user_share_dialog"));
+
+    settings = g_settings_new (GSETTINGS_SCHEMA);
+
+    check = GTK_WIDGET (gtk_builder_get_object (builder, "enable_check"));
+    password_combo = GTK_WIDGET (gtk_builder_get_object (builder, "password_combo"));
+    password_entry = GTK_WIDGET (gtk_builder_get_object (builder, "password_entry"));
+#ifdef HAVE_BLUETOOTH
+    bluetooth_check = GTK_WIDGET (gtk_builder_get_object (builder, "enable_bluetooth_check"));
+    bluetooth_allow_write_check = GTK_WIDGET (gtk_builder_get_object (builder, "allow_write_bluetooth_check"));
+    require_pairing_check = GTK_WIDGET (gtk_builder_get_object (builder, "require_pairing_check"));
+    enable_obexpush_check = GTK_WIDGET (gtk_builder_get_object (builder, "enable_obexpush_check"));
+    accept_obexpush_combo = GTK_WIDGET (gtk_builder_get_object (builder, "accept_obexpush_combo"));
+    notify_received_obexpush_check = GTK_WIDGET (gtk_builder_get_object (builder, "notify_received_obexpush_check"));
+#endif /* HAVE_BLUETOOTH */
+
+    store = gtk_list_store_new (1, G_TYPE_STRING);
+    gtk_combo_box_set_model (GTK_COMBO_BOX (password_combo),
+			     GTK_TREE_MODEL (store));
+    cell = gtk_cell_renderer_text_new ();
+    gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (password_combo), cell, TRUE);
+    gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (password_combo), cell,
+				    "text", 0,
+				    NULL);
+
+    /* Keep in same order as enum */
+    gtk_list_store_append (store, &iter);
+    gtk_list_store_set (store, &iter, 0,
+			_("Never"), -1);
+    gtk_list_store_append (store, &iter);
+    gtk_list_store_set (store, &iter, 0,
+			_("When writing files"), -1);
+    gtk_list_store_append (store, &iter);
+    gtk_list_store_set (store, &iter, 0,
+			_("Always"), -1);
+    g_object_unref (store);
+
+    /* We can't read the password from the text, just set it to something */
+    gtk_entry_set_text (GTK_ENTRY (password_entry), "none");
+    g_object_set_data (G_OBJECT (password_entry),
+		       "user_edited", GINT_TO_POINTER (0));
+    g_signal_connect (password_entry,
+		      "changed", G_CALLBACK (password_entry_changed), NULL);
+
+#ifdef HAVE_BLUETOOTH
+    /* Accept files combo */
+    store = gtk_list_store_new (1, G_TYPE_STRING);
+    gtk_combo_box_set_model (GTK_COMBO_BOX (accept_obexpush_combo),
+			     GTK_TREE_MODEL (store));
+    cell = gtk_cell_renderer_text_new ();
+    gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (accept_obexpush_combo), cell, TRUE);
+    gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (accept_obexpush_combo), cell,
+				    "text", 0,
+				    NULL);
+
+    /* Keep in same order as enum */
+    gtk_list_store_append (store, &iter);
+    gtk_list_store_set (store, &iter, 0,
+			_("Always"), -1);
+    gtk_list_store_append (store, &iter);
+    gtk_list_store_set (store, &iter, 0,
+			_("Only for set up devices"), -1);
+    //FIXME implement
+#if 0
+    gtk_list_store_append (store, &iter);
+    gtk_list_store_set (store, &iter, 0,
+    			_("Ask"), -1);
+#endif
+    g_object_unref (store);
+#endif /* HAVE_BLUETOOTH */
+
+    g_signal_connect (check,
+		      "toggled", G_CALLBACK (enable_check_toggled), NULL);
+    g_signal_connect (password_combo,
+		      "changed", G_CALLBACK (password_combo_changed), NULL);
+#ifdef HAVE_BLUETOOTH
+    g_signal_connect (bluetooth_check,
+    		      "toggled", G_CALLBACK (enable_bluetooth_check_toggled), NULL);
+    g_signal_connect (bluetooth_allow_write_check,
+    		      "toggled", G_CALLBACK (bluetooth_allow_write_check_toggled), NULL);
+    g_signal_connect (require_pairing_check,
+    		      "toggled", G_CALLBACK (bluetooth_require_pairing_check_toggled), NULL);
+    g_signal_connect (enable_obexpush_check,
+    		      "toggled", G_CALLBACK (enable_obexpush_check_toggled), NULL);
+    g_signal_connect (accept_obexpush_combo,
+    		      "changed", G_CALLBACK (accept_obexpush_combo_changed), NULL);
+    g_signal_connect (notify_received_obexpush_check,
+    		      "toggled", G_CALLBACK (notify_received_obexpush_check_toggled), NULL);
+#endif /* HAVE_BLUETOOTH */
+
+    g_signal_connect_swapped (GTK_WIDGET (gtk_builder_get_object (builder, "close_button")),
+                              "clicked", G_CALLBACK (gtk_widget_destroy), window);
+    g_signal_connect (GTK_WIDGET (gtk_builder_get_object (builder, "help_button")),
+		      "clicked", G_CALLBACK (help_button_clicked),
+		      gtk_builder_get_object (builder, "user_share_dialog"));
+
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_ENABLED,
+			     G_CALLBACK (file_sharing_enabled_changed), NULL);
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_REQUIRE_PASSWORD,
+			     G_CALLBACK (password_required_changed), NULL);
+#ifdef HAVE_BLUETOOTH
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_ENABLED,
+			     G_CALLBACK (file_sharing_bluetooth_enabled_changed), NULL);
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_ALLOW_WRITE,
+			     G_CALLBACK (file_sharing_bluetooth_allow_write_changed), NULL);
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_REQUIRE_PAIRING,
+			     G_CALLBACK (file_sharing_bluetooth_require_pairing_changed), NULL);
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED,
+			     G_CALLBACK (file_sharing_bluetooth_obexpush_enabled_changed), NULL);
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_ACCEPT_FILES,
+			     G_CALLBACK (file_sharing_bluetooth_obexpush_accept_files_changed), NULL);
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_NOTIFY,
+			     G_CALLBACK (file_sharing_bluetooth_obexpush_notify_changed), NULL);
+#endif /* HAVE_BLUETOOTH */
+
+    update_ui ();
+
+    return window;
+}
+
+static void
+activate (GtkApplication *app)
+{
+    GList *list;
+    GtkWidget *window;
+
+    list = gtk_application_get_windows (app);
+
+    if (list) {
+        gtk_window_present (GTK_WINDOW (list->data));
+    } else {
+        window = create_window ();
+        gtk_window_set_application (GTK_WINDOW (window), app);
+        gtk_widget_show (window);
+    }
+}
+
+int
+main (int argc, char *argv[])
+{
+    GtkApplication *app;
+    gint status;
+
+    bindtextdomain (GETTEXT_PACKAGE, MATELOCALEDIR);
+    bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
+    textdomain (GETTEXT_PACKAGE);
+
+    app = gtk_application_new ("org.mate.user-share.properties",
+                               G_APPLICATION_FLAGS_NONE);
+    g_signal_connect (app, "activate", G_CALLBACK (activate), NULL);
+
+    status = g_application_run (G_APPLICATION (app), argc, argv);
+
+    g_object_unref (app);
+
+    return status;
+}
+
+
+
+
+ + + diff --git a/2021-03-27-160708-9454-cppcheck@bc0bdef34681_master/1.html b/2021-03-27-160708-9454-cppcheck@bc0bdef34681_master/1.html new file mode 100644 index 0000000..cec50f3 --- /dev/null +++ b/2021-03-27-160708-9454-cppcheck@bc0bdef34681_master/1.html @@ -0,0 +1,1054 @@ + + + + + + Cppcheck - HTML report - mate-user-share + + + + + + +
+ +
+
  1
+  2
+  3
+  4
+  5
+  6
+  7
+  8
+  9
+ 10
+ 11
+ 12
+ 13
+ 14
+ 15
+ 16
+ 17
+ 18
+ 19
+ 20
+ 21
+ 22
+ 23
+ 24
+ 25
+ 26
+ 27
+ 28
+ 29
+ 30
+ 31
+ 32
+ 33
+ 34
+ 35
+ 36
+ 37
+ 38
+ 39
+ 40
+ 41
+ 42
+ 43
+ 44
+ 45
+ 46
+ 47
+ 48
+ 49
+ 50
+ 51
+ 52
+ 53
+ 54
+ 55
+ 56
+ 57
+ 58
+ 59
+ 60
+ 61
+ 62
+ 63
+ 64
+ 65
+ 66
+ 67
+ 68
+ 69
+ 70
+ 71
+ 72
+ 73
+ 74
+ 75
+ 76
+ 77
+ 78
+ 79
+ 80
+ 81
+ 82
+ 83
+ 84
+ 85
+ 86
+ 87
+ 88
+ 89
+ 90
+ 91
+ 92
+ 93
+ 94
+ 95
+ 96
+ 97
+ 98
+ 99
+100
+101
+102
+103
+104
+105
+106
+107
+108
+109
+110
+111
+112
+113
+114
+115
+116
+117
+118
+119
+120
+121
+122
+123
+124
+125
+126
+127
+128
+129
+130
+131
+132
+133
+134
+135
+136
+137
+138
+139
+140
+141
+142
+143
+144
+145
+146
+147
+148
+149
+150
+151
+152
+153
+154
+155
+156
+157
+158
+159
+160
+161
+162
+163
+164
+165
+166
+167
+168
+169
+170
+171
+172
+173
+174
+175
+176
+177
+178
+179
+180
+181
+182
+183
+184
+185
+186
+187
+188
+189
+190
+191
+192
+193
+194
+195
+196
+197
+198
+199
+200
+201
+202
+203
+204
+205
+206
+207
+208
+209
+210
+211
+212
+213
+214
+215
+216
+217
+218
+219
+220
+221
+222
+223
+224
+225
+226
+227
+228
+229
+230
+231
+232
+233
+234
+235
+236
+237
+238
+239
+240
+241
+242
+243
+244
+245
+246
+247
+248
+249
+250
+251
+252
+253
+254
+255
+256
+257
+258
+259
+260
+261
+262
+263
+264
+265
+266
+267
+268
+269
+270
+271
+272
+273
+274
+275
+276
+277
+278
+279
+280
+281
+282
+283
+284
+285
+286
+287
+288
+289
+290
+291
+292
+293
+294
+295
+296
+297
+298
+299
+300
+301
+302
+303
+304
+305
+306
+307
+308
+309
+310
+311
+312
+313
+314
+315
+316
+317
+318
+319
+320
+321
+322
+323
+324
+325
+326
+327
+328
+329
+330
+331
+332
+333
+334
+335
+336
+337
+338
+339
+340
+341
+342
+343
+344
+345
+346
+347
+348
+349
+350
+351
+352
+353
+354
+355
+356
+357
+358
+359
+360
+361
+362
+363
+364
+365
+366
+367
+368
+369
+370
+371
+372
+373
+374
+375
+376
+377
+378
+379
+380
+381
+382
+383
+384
+385
+386
+387
+388
+389
+390
+391
+392
+393
+394
+395
+396
+397
+398
+399
+400
+401
+402
+403
+404
+405
+406
+407
+408
+409
+410
+411
+412
+413
+414
+415
+416
+417
+418
+419
+420
+421
+422
+423
+424
+425
+426
+427
+428
+429
+430
+431
+432
+433
+434
+435
+436
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
+
+/*
+ *  Copyright (C) 2004-2008 Red Hat, Inc.
+ *
+ *  Caja is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU General Public License as
+ *  published by the Free Software Foundation; either version 2 of the
+ *  License, or (at your option) any later version.
+ *
+ *  Caja is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  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
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ *  Authors: Alexander Larsson <alexl@redhat.com>
+ *
+ */
+
+#include "config.h"
+
+#include <glib.h>
+#include <glib/gi18n.h>
+#include <X11/Xlib.h>
+
+#include <gio/gio.h>
+
+#include <stdarg.h>
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <signal.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <sys/stat.h>
+
+#ifdef HAVE_SELINUX
+#include <selinux/selinux.h>
+#endif
+
+#include "user_share-common.h"
+#include "user_share-private.h"
+#include "http.h"
+
+/* From avahi-common/domain.h */
+#define AVAHI_LABEL_MAX 64
+
+#define GSETTINGS_SCHEMA "org.mate.FileSharing"
+
+static pid_t httpd_pid = 0;
+
+static int
+get_port (void)
+{
+	int sock;
+	struct sockaddr_in addr;
+	int reuse;
+	socklen_t len;
+
+	sock = socket (PF_INET, SOCK_STREAM, 0);
+	if (sock < 0) {
+		return -1;
+	}
+
+	memset (&addr, 0, sizeof (addr));
+	addr.sin_port = 0;
+	addr.sin_addr.s_addr = INADDR_ANY;
+	addr.sin_family = AF_INET;
+
+	reuse = 1;
+	setsockopt (sock, SOL_SOCKET, SO_REUSEADDR, &reuse, sizeof (reuse));
+	if (bind (sock, (struct sockaddr *)&addr, sizeof (addr)) == -1) {
+		close (sock);
+		return -1;
+	}
+
+	len = sizeof (addr);
+	if (getsockname (sock, (struct sockaddr *)&addr, &len) == -1) {
+		close (sock);
+		return -1;
+	}
+
+#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__APPLE__) || defined(__OpenBSD__)
+	/* XXX This exposes a potential race condition, but without this,
+	 * httpd will not start on the above listed platforms due to the fact
+	 * that SO_REUSEADDR is also needed when Apache binds to the listening
+	 * socket.  At this time, Apache does not support that socket option.
+	 */
+	close (sock);
+#endif
+	return ntohs (addr.sin_port);
+}
+
+static char *
+truncate_name (const char *name)
+{
+	const char *end;
+
+	end = g_utf8_find_prev_char (name, name + 64);
+	g_assert (end != NULL);
+	return g_strndup (name, end - name);
+}
+
+static char *
+get_share_name (void)
+{
+	static char *name = NULL;
+	const char *host_name;
+	char *str;
+
+	if (name == NULL) {
+		host_name = g_get_host_name ();
+		if (strcmp (host_name, "localhost") == 0) {
+			/* Translators: The %s will get filled in with the user name
+			   of the user, to form a genitive. If this is difficult to
+			   translate correctly so that it will work correctly in your
+			   language, you may use something equivalent to
+			   "Public files of %s", or leave out the %s altogether.
+			   In the latter case, please put "%.0s" somewhere in the string,
+			   which will match the user name string passed by the C code,
+			   but not put the user name in the final string. This is to
+			   avoid the warning that msgfmt might otherwise generate. */
+			name = g_strdup_printf (_("%s's public files"), g_get_user_name ());
+		} else {
+			/* Translators: This is similar to the string before, only it
+			   has the hostname in it too. */
+			name = g_strdup_printf (_("%s's public files on %s"),
+						g_get_user_name (),
+						host_name);
+		}
+
+	}
+	/* And truncate */
+	if (strlen (name) < AVAHI_LABEL_MAX)
+		return name;
+
+	str = truncate_name (name);
+	g_free (name);
+	name = str;
+
+	return name;
+}
+
+static void
+ensure_conf_dir (void)
+{
+	char *dirname;
+
+	dirname = g_build_filename (g_get_user_config_dir (), "user-share", NULL);
+	g_mkdir_with_parents (dirname, 0755);
+	g_free (dirname);
+}
+
+static void
+httpd_child_setup (gpointer user_data)
+{
+#ifdef HAVE_SELINUX
+	char *mycon;
+	/* If selinux is enabled, avoid transitioning to the httpd_t context,
+	   as this normally means you can't read the users homedir. */
+	if (is_selinux_enabled()) {
+		if (getcon (&mycon) < 0) {
+			abort ();
+		}
+		if (setexeccon (mycon) < 0)
+			abort ();
+		freecon (mycon);
+	}
+#endif
+}
+
+static const char *known_httpd_locations [] = {
+	HTTPD_PROGRAM,
+	"/usr/sbin/httpd",
+	"/usr/sbin/httpd2",
+	"/usr/sbin/apache2",
+	NULL
+};
+
+static char*
+get_httpd_program (void)
+{
+	int i;
+
+	for (i = 0; known_httpd_locations[i]; i++) {
+		if (known_httpd_locations[i][0] == '\0') {
+			/* empty string as first element, happens when
+			 * configured --with-httpd=auto */
+			continue;
+		}
+		if (g_file_test (known_httpd_locations[i], G_FILE_TEST_IS_EXECUTABLE)
+				&& ! g_file_test (known_httpd_locations[i], G_FILE_TEST_IS_DIR)) {
+			return g_strdup (known_httpd_locations[i]);
+		}
+	}
+	return NULL;
+}
+
+static const char *known_httpd_modules_locations [] = {
+	HTTPD_MODULES_PATH,
+	"/etc/httpd/modules",
+	"/usr/lib/apache2/modules",
+	NULL
+};
+
+static gchar*
+get_httpd_modules_path (void)
+{
+	int i;
+
+	for (i = 0; known_httpd_modules_locations[i]; i++) {
+		if (known_httpd_modules_locations[i][0] == '\0') {
+			/* empty string as first element, happens when
+			 * configured --with-httpd=auto */
+			continue;
+		}
+		if (g_file_test (known_httpd_modules_locations[i], G_FILE_TEST_IS_EXECUTABLE)
+				&& g_file_test (known_httpd_modules_locations[i], G_FILE_TEST_IS_DIR)) {
+			return g_strdup (known_httpd_modules_locations[i]);
+		}
+	}
+	return NULL;
+}
+
+static GRegex *version_regex = NULL;
+
+static char*
+get_httpd_config (const char *httpd_program)
+{
+	gchar *standard_output;
+	gchar *cmd_line;
+	GMatchInfo *match_info;
+	gchar *version_number = NULL;
+	gchar *config;
+
+	cmd_line = g_strdup_printf ("%s -v", httpd_program);
+	if (! g_spawn_command_line_sync (cmd_line, &standard_output, NULL, NULL, NULL)) {
+		g_free (cmd_line);
+		return NULL;
+	}
+	g_free (cmd_line);
+
+	if (version_regex == NULL) {
+		version_regex = g_regex_new ("\\d\\.\\d", 0, 0, NULL);
+	}
+
+	if (g_regex_match (version_regex, standard_output, 0, &match_info)) {
+		while (g_match_info_matches (match_info)) {
+			version_number = g_match_info_fetch (match_info, 0);
+			break;
+		}
+		g_match_info_free (match_info);
+		g_free (standard_output);
+	} else {
+		/* Failed to parse httpd version number */
+		g_warning ("Could not parse '%s' as a version for httpd", standard_output);
+		g_free (standard_output);
+		/* assume it is 2.2 */
+		version_number = g_strdup ("2.2");
+	}
+
+	config = g_strdup_printf (HTTPD_CONFIG_TEMPLATE, version_number);
+	g_free (version_number);
+
+	return config;
+}
+
+static gboolean
+spawn_httpd (int port, pid_t *pid_out)
+{
+	char *free1, *free2, *free3, *free4, *free5, *free6, *free7, *free8, *free9;
+	gboolean res;
+	char *argv[10];
+	char *env[10];
+	int i;
+	gint status;
+	char *pid_filename;
+	char *pidfile;
+	GError *error;
+	gboolean got_pidfile;
+	GSettings *settings;
+	char *str;
+	char *public_dir;
+
+	public_dir = lookup_public_dir ();
+	ensure_conf_dir ();
+
+	i = 0;
+	free1 = argv[i++] = get_httpd_program ();
+	if (argv[0] == NULL) {
+		fprintf (stderr, "error finding httpd server\n");
+		return FALSE;
+	}
+
+	argv[i++] = "-f";
+	free2 = argv[i++] = get_httpd_config (argv[0]);
+	argv[i++] = "-C";
+	free3 = argv[i++] = g_strdup_printf ("Listen %d", port);
+
+	settings = g_settings_new (GSETTINGS_SCHEMA);
+	str = g_settings_get_string (settings,
+				       FILE_SHARING_REQUIRE_PASSWORD);
+
+	if (str && strcmp (str, "never") == 0) {
+		/* Do nothing */
+	} else if (str && strcmp (str, "on_write") == 0){
+		argv[i++] = "-D";
+		argv[i++] = "RequirePasswordOnWrite";
+	} else {
+		/* always, or safe fallback */
+		argv[i++] = "-D";
+		argv[i++] = "RequirePasswordAlways";
+	}
+	g_free (str);
+	g_object_unref (settings);
+
+	argv[i] = NULL;
+
+	i = 0;
+	free4 = env[i++] = g_strdup_printf ("HOME=%s", g_get_home_dir());
+	free5 = env[i++] = g_strdup_printf ("XDG_PUBLICSHARE_DIR=%s", public_dir);
+	free6 = env[i++] = g_strdup_printf ("XDG_CONFIG_HOME=%s", g_get_user_config_dir ());
+	free7 = env[i++] = g_strdup_printf ("GUS_SHARE_NAME=%s", get_share_name ());
+	free8 = env[i++] = g_strdup_printf ("GUS_LOGIN_LABEL=%s", "Please log in as the user guest");
+	free9 = env[i++] = g_strdup_printf ("HTTP_MODULES_PATH=%s",get_httpd_modules_path ());
+	env[i++] = "LANG=C";
+	env[i] = NULL;
+
+	pid_filename = g_build_filename (g_get_user_config_dir (), "user-share", "pid", NULL);
+
+	/* Remove pid file before spawning to avoid races with child and old pidfile */
+	unlink (pid_filename);
+
+	error = NULL;
+	res = g_spawn_sync (g_get_home_dir(),
+			    argv, env, 0,
+			    httpd_child_setup, NULL,
+			    NULL, NULL,
+			    &status,
+			    &error);
+	g_free (free1);
+	g_free (free2);
+	g_free (free3);
+	g_free (free4);
+	g_free (free5);
+	g_free (free6);
+	g_free (free7);
+	g_free (free8);
+	g_free (free9);
+	g_free (public_dir);
+
+	if (!res) {
+		fprintf (stderr, "error spawning httpd: %s\n",
+			 error->message);
+		g_error_free (error);
+		g_free (pid_filename);
+		return FALSE;
+	}
+
+	if (status != 0) {
+		g_free (pid_filename);
+		return FALSE;
+	}
+
+	got_pidfile = FALSE;
+	error = NULL;
+	for (i = 0; i < 5; i++) {
+		if (error != NULL)
+			g_error_free (error);
+		error = NULL;
+		if (g_file_get_contents (pid_filename, &pidfile, NULL, &error)) {
+			got_pidfile = TRUE;
+			*pid_out = atoi (pidfile);
+			g_free (pidfile);
+			break;
+		}
+		sleep (1);
+	}
+
+	g_free (pid_filename);
+
+	if (!got_pidfile) {
+		fprintf (stderr, "error opening httpd pidfile: %s\n", error->message);
+		g_error_free (error);
+		return FALSE;
+	}
+	return TRUE;
+}
+
+static void
+kill_httpd (void)
+{
+	if (httpd_pid != 0) {
+		kill (httpd_pid, SIGTERM);
+
+		/* Allow child time to die, we can't waitpid, because its
+		   not a direct child */
+		sleep (1);
+	}
+	httpd_pid = 0;
+}
+
+void
+http_up (void)
+{
+	guint port;
+
+	port = get_port ();
+	if (!spawn_httpd (port, &httpd_pid)) {
+		fprintf (stderr, "spawning httpd failed\n");
+	}
+}
+
+void
+http_down (void)
+{
+	kill_httpd ();
+}
+
+gboolean
+http_init (void)
+{
+	return TRUE;
+}
+
+pid_t
+http_get_pid (void)
+{
+	return httpd_pid;
+}
+
+
+
+
+ + + diff --git a/2021-03-27-160708-9454-cppcheck@bc0bdef34681_master/2.html b/2021-03-27-160708-9454-cppcheck@bc0bdef34681_master/2.html new file mode 100644 index 0000000..c95a0b0 --- /dev/null +++ b/2021-03-27-160708-9454-cppcheck@bc0bdef34681_master/2.html @@ -0,0 +1,1288 @@ + + + + + + Cppcheck - HTML report - mate-user-share + + + + + + +
+ +
+
  1
+  2
+  3
+  4
+  5
+  6
+  7
+  8
+  9
+ 10
+ 11
+ 12
+ 13
+ 14
+ 15
+ 16
+ 17
+ 18
+ 19
+ 20
+ 21
+ 22
+ 23
+ 24
+ 25
+ 26
+ 27
+ 28
+ 29
+ 30
+ 31
+ 32
+ 33
+ 34
+ 35
+ 36
+ 37
+ 38
+ 39
+ 40
+ 41
+ 42
+ 43
+ 44
+ 45
+ 46
+ 47
+ 48
+ 49
+ 50
+ 51
+ 52
+ 53
+ 54
+ 55
+ 56
+ 57
+ 58
+ 59
+ 60
+ 61
+ 62
+ 63
+ 64
+ 65
+ 66
+ 67
+ 68
+ 69
+ 70
+ 71
+ 72
+ 73
+ 74
+ 75
+ 76
+ 77
+ 78
+ 79
+ 80
+ 81
+ 82
+ 83
+ 84
+ 85
+ 86
+ 87
+ 88
+ 89
+ 90
+ 91
+ 92
+ 93
+ 94
+ 95
+ 96
+ 97
+ 98
+ 99
+100
+101
+102
+103
+104
+105
+106
+107
+108
+109
+110
+111
+112
+113
+114
+115
+116
+117
+118
+119
+120
+121
+122
+123
+124
+125
+126
+127
+128
+129
+130
+131
+132
+133
+134
+135
+136
+137
+138
+139
+140
+141
+142
+143
+144
+145
+146
+147
+148
+149
+150
+151
+152
+153
+154
+155
+156
+157
+158
+159
+160
+161
+162
+163
+164
+165
+166
+167
+168
+169
+170
+171
+172
+173
+174
+175
+176
+177
+178
+179
+180
+181
+182
+183
+184
+185
+186
+187
+188
+189
+190
+191
+192
+193
+194
+195
+196
+197
+198
+199
+200
+201
+202
+203
+204
+205
+206
+207
+208
+209
+210
+211
+212
+213
+214
+215
+216
+217
+218
+219
+220
+221
+222
+223
+224
+225
+226
+227
+228
+229
+230
+231
+232
+233
+234
+235
+236
+237
+238
+239
+240
+241
+242
+243
+244
+245
+246
+247
+248
+249
+250
+251
+252
+253
+254
+255
+256
+257
+258
+259
+260
+261
+262
+263
+264
+265
+266
+267
+268
+269
+270
+271
+272
+273
+274
+275
+276
+277
+278
+279
+280
+281
+282
+283
+284
+285
+286
+287
+288
+289
+290
+291
+292
+293
+294
+295
+296
+297
+298
+299
+300
+301
+302
+303
+304
+305
+306
+307
+308
+309
+310
+311
+312
+313
+314
+315
+316
+317
+318
+319
+320
+321
+322
+323
+324
+325
+326
+327
+328
+329
+330
+331
+332
+333
+334
+335
+336
+337
+338
+339
+340
+341
+342
+343
+344
+345
+346
+347
+348
+349
+350
+351
+352
+353
+354
+355
+356
+357
+358
+359
+360
+361
+362
+363
+364
+365
+366
+367
+368
+369
+370
+371
+372
+373
+374
+375
+376
+377
+378
+379
+380
+381
+382
+383
+384
+385
+386
+387
+388
+389
+390
+391
+392
+393
+394
+395
+396
+397
+398
+399
+400
+401
+402
+403
+404
+405
+406
+407
+408
+409
+410
+411
+412
+413
+414
+415
+416
+417
+418
+419
+420
+421
+422
+423
+424
+425
+426
+427
+428
+429
+430
+431
+432
+433
+434
+435
+436
+437
+438
+439
+440
+441
+442
+443
+444
+445
+446
+447
+448
+449
+450
+451
+452
+453
+454
+455
+456
+457
+458
+459
+460
+461
+462
+463
+464
+465
+466
+467
+468
+469
+470
+471
+472
+473
+474
+475
+476
+477
+478
+479
+480
+481
+482
+483
+484
+485
+486
+487
+488
+489
+490
+491
+492
+493
+494
+495
+496
+497
+498
+499
+500
+501
+502
+503
+504
+505
+506
+507
+508
+509
+510
+511
+512
+513
+514
+515
+516
+517
+518
+519
+520
+521
+522
+523
+524
+525
+526
+527
+528
+529
+530
+531
+532
+533
+534
+535
+536
+537
+538
+539
+540
+541
+542
+543
+544
+545
+546
+547
+548
+549
+550
+551
+552
+553
+554
+555
+556
+557
+558
+559
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
+
+/*
+ *  Copyright (C) 2004-2008 Red Hat, Inc.
+ *
+ *  Caja is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU General Public License as
+ *  published by the Free Software Foundation; either version 2 of the
+ *  License, or (at your option) any later version.
+ *
+ *  Caja is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  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
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ *  Authors: Bastien Nocera <hadess@hadess.net>
+ *
+ */
+
+#include "config.h"
+
+#include <glib.h>
+#include <glib/gi18n.h>
+#include <gio/gio.h>
+#include <gdk/gdk.h>
+#include <gtk/gtk.h>
+#include <libnotify/notify.h>
+#include <dbus/dbus-glib.h>
+#include <dbus/dbus-glib-lowlevel.h>
+#include <canberra-gtk.h>
+
+#include <string.h>
+
+#include "marshal.h"
+#include "obexpush.h"
+#include "user_share-common.h"
+#include "user_share-private.h"
+
+#define DBUS_TYPE_G_STRING_VARIANT_HASHTABLE (dbus_g_type_get_map ("GHashTable", G_TYPE_STRING, G_TYPE_STRING))
+
+#define GSETTINGS_SCHEMA "org.mate.FileSharing"
+
+static DBusGConnection *connection = NULL;<--- Shadowed declaration
+static DBusGProxy *manager_proxy = NULL;
+static DBusGProxy *server_proxy = NULL;
+static AcceptSetting accept_setting = -1;
+static gboolean show_notifications = FALSE;
+
+static GtkStatusIcon *statusicon = NULL;
+static guint num_notifications = 0;
+
+static void
+hide_statusicon (void)
+{
+	num_notifications--;
+	if (num_notifications == 0)
+		gtk_status_icon_set_visible (statusicon, FALSE);
+}
+
+static void
+on_close_notification (NotifyNotification *notification)
+{
+	hide_statusicon ();
+	g_object_unref (notification);
+}
+
+static void
+notification_launch_action_on_file_cb (NotifyNotification *notification,
+				       const char *action,
+				       const char *file_uri)
+{
+	GdkScreen *screen;
+	GAppLaunchContext *ctx;
+	GTimeVal val;
+
+	g_assert (action != NULL);
+
+	g_get_current_time (&val);
+
+	ctx = G_APP_LAUNCH_CONTEXT (gdk_app_launch_context_new ());
+	screen = gdk_screen_get_default ();
+	gdk_app_launch_context_set_screen (GDK_APP_LAUNCH_CONTEXT (ctx), screen);
+	gdk_app_launch_context_set_timestamp (GDK_APP_LAUNCH_CONTEXT (ctx), val.tv_sec);
+
+	/* We launch the file viewer for the file */
+	if (g_str_equal (action, "display") != FALSE) {
+		if (g_app_info_launch_default_for_uri (file_uri, ctx, NULL) == FALSE) {
+			g_warning ("Failed to launch the file viewer\n");
+		}
+	}
+
+	/* we open the Downloads folder */
+	if (g_str_equal (action, "reveal") != FALSE) {
+		GFile *file;
+		GFile *parent;
+		gchar *parent_uri;
+
+		file = g_file_new_for_uri (file_uri);
+		parent = g_file_get_parent (file);
+		parent_uri = g_file_get_uri (parent);
+		g_object_unref (file);
+		g_object_unref (parent);
+
+		if (!g_app_info_launch_default_for_uri (parent_uri, ctx, NULL)) {
+			g_warning ("Failed to launch the file manager\n");
+		}
+
+		g_free (parent_uri);
+	}
+
+	notify_notification_close (notification, NULL);
+	/* No need to call hide_statusicon(), closing the notification
+	 * will call the close callback */
+}
+
+static void
+show_notification (const char *filename)
+{
+	char *file_uri, *notification_text, *display, *mime_type;
+	NotifyNotification *notification;
+	ca_context *ctx;
+	GAppInfo *app;
+
+	file_uri = g_filename_to_uri (filename, NULL, NULL);
+	if (file_uri == NULL) {
+		g_warning ("Could not make a filename from '%s'", filename);
+		return;
+	}
+
+	display = g_filename_display_basename (filename);
+	/* Translators: %s is the name of the filename received */
+	notification_text = g_strdup_printf(_("You received \"%s\" via Bluetooth"), display);
+	g_free (display);
+	notification = notify_notification_new (_("You received a file"),
+								 notification_text,
+								 "dialog-information");
+
+	notify_notification_set_timeout (notification, NOTIFY_EXPIRES_DEFAULT);
+
+	mime_type = g_content_type_guess (filename, NULL, 0, NULL);
+	app = g_app_info_get_default_for_type (mime_type, FALSE);
+	if (app != NULL) {
+		g_object_unref (app);
+		notify_notification_add_action (notification, "display", _("Open File"),
+						(NotifyActionCallback) notification_launch_action_on_file_cb,
+						g_strdup (file_uri), (GFreeFunc) g_free);
+	}
+	notify_notification_add_action (notification, "reveal", _("Reveal File"),
+					(NotifyActionCallback) notification_launch_action_on_file_cb,
+					g_strdup (file_uri), (GFreeFunc) g_free);
+
+	g_free (file_uri);
+
+	g_signal_connect (G_OBJECT (notification), "closed", G_CALLBACK (on_close_notification), notification);
+
+	if (!notify_notification_show (notification, NULL)) {
+		g_warning ("failed to send notification\n");
+	}
+	g_free (notification_text);
+
+	/* Now we do the audio notification */
+	ctx = ca_gtk_context_get ();
+	ca_context_play (ctx, 0,
+			 CA_PROP_EVENT_ID, "complete-download",
+			 CA_PROP_EVENT_DESCRIPTION, _("File reception complete"),
+			 NULL);
+}
+
+static void
+show_icon (void)
+{
+	if (statusicon == NULL) {
+		statusicon = gtk_status_icon_new_from_icon_name ("mate-obex-server");
+	} else {
+		gtk_status_icon_set_visible (statusicon, TRUE);
+	}
+	num_notifications++;
+}
+
+static gboolean
+device_is_authorised (const char *bdaddr)
+{
+	DBusGConnection *connection;<--- Shadow variable
+	DBusGProxy *manager;
+	GError *error = NULL;
+	GPtrArray *adapters;
+	gboolean retval = FALSE;
+	guint i;
+
+	connection = dbus_g_bus_get (DBUS_BUS_SYSTEM, NULL);
+	if (connection == NULL)
+		return FALSE;
+
+	manager = dbus_g_proxy_new_for_name (connection, "org.bluez",
+					     "/", "org.bluez.Manager");
+	if (manager == NULL) {
+		dbus_g_connection_unref (connection);
+		return FALSE;
+	}
+
+	if (dbus_g_proxy_call (manager, "ListAdapters", &error, G_TYPE_INVALID, dbus_g_type_get_collection ("GPtrArray", DBUS_TYPE_G_OBJECT_PATH), &adapters, G_TYPE_INVALID) == FALSE) {
+		g_object_unref (manager);
+		dbus_g_connection_unref (connection);
+		return FALSE;
+	}
+
+	for (i = 0; i < adapters->len; i++) {
+		DBusGProxy *adapter, *device;
+		char *device_path;
+		GHashTable *props;
+
+		g_debug ("checking adapter %s", (gchar *) g_ptr_array_index (adapters, i));
+
+		adapter = dbus_g_proxy_new_for_name (connection, "org.bluez",
+						    g_ptr_array_index (adapters, i), "org.bluez.Adapter");
+
+		if (dbus_g_proxy_call (adapter, "FindDevice", NULL,
+				       G_TYPE_STRING, bdaddr, G_TYPE_INVALID,
+				       DBUS_TYPE_G_OBJECT_PATH, &device_path, G_TYPE_INVALID) == FALSE)
+		{
+			g_object_unref (adapter);
+			continue;
+		}
+
+		device = dbus_g_proxy_new_for_name (connection, "org.bluez", device_path, "org.bluez.Device");
+
+		if (dbus_g_proxy_call (device, "GetProperties", NULL,
+				       G_TYPE_INVALID, dbus_g_type_get_map ("GHashTable", G_TYPE_STRING, G_TYPE_VALUE),
+				       &props, G_TYPE_INVALID) != FALSE)
+		{
+			GValue *value;
+			gboolean bonded;
+
+			value = g_hash_table_lookup (props, "Paired");
+			bonded = g_value_get_boolean (value);
+			g_message ("%s is %s", bdaddr, bonded ? "bonded" : "not bonded");
+
+			if (bonded) {
+				g_hash_table_destroy (props);
+				g_object_unref (device);
+				g_object_unref (adapter);
+				retval = TRUE;
+				break;
+			}
+		}
+		g_object_unref(adapter);
+	}
+
+	g_ptr_array_free (adapters, TRUE);
+
+	g_object_unref(manager);
+	dbus_g_connection_unref(connection);
+
+	return retval;
+}
+
+static void
+transfer_started_cb (DBusGProxy *session,
+		     const char *filename,
+		     const char *local_path,
+		     guint64 size,
+		     gpointer user_data)
+{
+	GHashTable *dict;
+	DBusGProxy *server = (DBusGProxy *) user_data;
+	GError *error = NULL;
+	gboolean authorise;
+
+	g_message ("transfer started on %s", local_path);
+	g_object_set_data_full (G_OBJECT (session), "filename", g_strdup (local_path), (GDestroyNotify) g_free);
+
+	show_icon ();
+
+	/* First transfer of the session */
+	if (g_object_get_data (G_OBJECT (session), "bdaddr") == NULL) {
+		const char *bdaddr;
+
+		if (dbus_g_proxy_call (server, "GetServerSessionInfo", &error,
+				       DBUS_TYPE_G_OBJECT_PATH, dbus_g_proxy_get_path (session), G_TYPE_INVALID,
+				       DBUS_TYPE_G_STRING_VARIANT_HASHTABLE, &dict, G_TYPE_INVALID) == FALSE) {
+			g_printerr ("Getting Server session info failed: %s\n",
+				    error->message);
+			g_error_free (error);
+			return;
+		}
+
+		bdaddr = g_hash_table_lookup (dict, "BluetoothAddress");
+		g_message ("transfer started for device %s", bdaddr);
+
+		g_object_set_data_full (G_OBJECT (session), "bdaddr", g_strdup (bdaddr), (GDestroyNotify) g_free);
+		/* Initial accept method is undefined, we do that lower down */
+		g_object_set_data (G_OBJECT (session), "accept-method", GINT_TO_POINTER (-1));
+		g_hash_table_destroy (dict);
+	}
+
+	/* Accept method changed */
+	if (GPOINTER_TO_INT (g_object_get_data (G_OBJECT (session), "accept-method")) != accept_setting) {
+		const char *bdaddr;
+
+		bdaddr = g_object_get_data (G_OBJECT (session), "bdaddr");
+
+		if (bdaddr == NULL) {
+			g_warning ("Couldn't get the Bluetooth address for the device, rejecting the transfer");
+			authorise = FALSE;
+		} else if (accept_setting == ACCEPT_ALWAYS) {
+			authorise = TRUE;
+		} else if (accept_setting == ACCEPT_BONDED) {
+			authorise = device_is_authorised (bdaddr);
+		} else {
+			//FIXME implement
+			g_warning ("\"Ask\" authorisation method not implemented");
+			authorise = FALSE;
+		}
+		g_object_set_data (G_OBJECT (session), "authorise", GINT_TO_POINTER (authorise));
+	}
+
+	g_message ("accept_setting: %d", accept_setting);
+
+	authorise = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (session), "authorise"));
+	if (authorise != FALSE) {
+		if (dbus_g_proxy_call (session, "Accept", &error, G_TYPE_INVALID, G_TYPE_INVALID) == FALSE) {
+			g_printerr ("Failed to accept file transfer: %s\n", error->message);
+			g_error_free (error);
+			return;
+		}
+		g_message ("authorised transfer");
+	} else {
+		if (dbus_g_proxy_call (session, "Reject", &error, G_TYPE_INVALID, G_TYPE_INVALID) == FALSE) {
+			g_printerr ("Failed to reject file transfer: %s\n", error->message);
+			g_error_free (error);
+			return;
+		}
+		g_message ("rejected transfer");
+		g_object_set_data (G_OBJECT (session), "filename", NULL);
+	}
+}
+
+static void
+transfer_completed_cb (DBusGProxy *session,
+		       gpointer user_data)
+{
+	GSettings *settings;
+	gboolean display_notify;
+	const char *filename;
+
+	filename = (const char *) g_object_get_data (G_OBJECT (session), "filename");
+
+	g_message ("file finish transfer: %s", filename);
+
+	if (filename == NULL)
+		return;
+
+	settings = g_settings_new (GSETTINGS_SCHEMA);
+	display_notify = g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_OBEXPUSH_NOTIFY);
+	g_object_unref (settings);
+
+	if (display_notify) {
+		show_notification (filename);
+	} else {
+		hide_statusicon ();
+	}
+	g_object_set_data (G_OBJECT (session), "filename", NULL);
+}
+
+static void
+cancelled_cb (DBusGProxy *session,
+	      gpointer user_data)
+{
+	//FIXME implement properly, we never actually finished the transfer
+	g_message ("transfered was cancelled by the sender");
+	transfer_completed_cb (session, user_data);
+	hide_statusicon ();
+}
+
+static void
+error_occurred_cb (DBusGProxy *session,
+		   const char *error_name,
+		   const char *error_message,
+		   gpointer user_data)
+{
+	//FIXME implement properly
+	g_message ("transfer error occurred: %s", error_message);
+	transfer_completed_cb (session, user_data);
+}
+
+static void
+session_created_cb (DBusGProxy *server, const char *session_path, gpointer user_data)
+{
+	DBusGProxy *session;
+
+	session = dbus_g_proxy_new_for_name (connection,
+					     "org.openobex",
+					     session_path,
+					     "org.openobex.ServerSession");
+
+	dbus_g_proxy_add_signal (session, "TransferStarted",
+				 G_TYPE_STRING, G_TYPE_STRING, G_TYPE_UINT64, G_TYPE_INVALID);
+	dbus_g_proxy_connect_signal(session, "TransferStarted",
+				    G_CALLBACK (transfer_started_cb), server, NULL);
+	dbus_g_proxy_add_signal (session, "TransferCompleted",
+				 G_TYPE_INVALID, G_TYPE_INVALID);
+	dbus_g_proxy_connect_signal(session, "TransferCompleted",
+				    G_CALLBACK (transfer_completed_cb), server, NULL);
+	dbus_g_proxy_add_signal (session, "Cancelled",
+				 G_TYPE_INVALID, G_TYPE_INVALID);
+	dbus_g_proxy_connect_signal(session, "Cancelled",
+				    G_CALLBACK (cancelled_cb), server, NULL);
+	dbus_g_proxy_add_signal (session, "ErrorOccurred",
+				 G_TYPE_INVALID, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INVALID);
+	dbus_g_proxy_connect_signal(session, "ErrorOccurred",
+				    G_CALLBACK (error_occurred_cb), server, NULL);
+}
+
+void
+obexpush_up (void)
+{
+	GError *err = NULL;
+	char *download_dir, *server;
+
+	server = NULL;
+	if (manager_proxy == NULL) {
+		manager_proxy = dbus_g_proxy_new_for_name (connection,
+							   "org.openobex",
+							   "/org/openobex",
+							   "org.openobex.Manager");
+		if (dbus_g_proxy_call (manager_proxy, "CreateBluetoothServer",
+				       &err, G_TYPE_STRING, "00:00:00:00:00:00", G_TYPE_STRING, "opp", G_TYPE_BOOLEAN, FALSE, G_TYPE_INVALID,
+				       DBUS_TYPE_G_OBJECT_PATH, &server, G_TYPE_INVALID) == FALSE) {
+			g_printerr ("Creating Bluetooth ObexPush server failed: %s\n",
+				    err->message);
+			g_error_free (err);
+			g_object_unref (manager_proxy);
+			manager_proxy = NULL;
+			return;
+		}
+	}
+
+	download_dir = lookup_download_dir ();
+
+	if (server_proxy == NULL) {
+		server_proxy = dbus_g_proxy_new_for_name (connection,
+							   "org.openobex",
+							   server,
+							   "org.openobex.Server");
+		g_free (server);
+
+		dbus_g_proxy_add_signal (server_proxy, "SessionCreated",
+					 DBUS_TYPE_G_OBJECT_PATH, G_TYPE_INVALID);
+		dbus_g_proxy_connect_signal(server_proxy, "SessionCreated",
+					    G_CALLBACK (session_created_cb), NULL, NULL);
+	}
+
+	if (dbus_g_proxy_call (server_proxy, "Start", &err,
+			   G_TYPE_STRING, download_dir, G_TYPE_BOOLEAN, TRUE, G_TYPE_BOOLEAN, FALSE, G_TYPE_INVALID,
+			   G_TYPE_INVALID) == FALSE) {
+		if (g_error_matches (err, DBUS_GERROR, DBUS_GERROR_REMOTE_EXCEPTION) != FALSE &&
+		    dbus_g_error_has_name (err, "org.openobex.Error.Started") != FALSE) {
+		    	g_error_free (err);
+		    	g_message ("already started, ignoring error");
+		    	g_free (download_dir);
+		    	return;
+		}
+		g_printerr ("Starting Bluetooth ObexPush server failed: %s\n",
+			    err->message);
+		g_error_free (err);
+		g_free (download_dir);
+		g_object_unref (server_proxy);
+		server_proxy = NULL;
+		g_object_unref (manager_proxy);
+		manager_proxy = NULL;
+		return;
+	}
+
+	g_free (download_dir);
+}
+
+static void
+obexpush_stop (gboolean stop_manager)
+{
+	GError *err = NULL;
+
+	if (server_proxy == NULL)
+		return;
+
+	if (dbus_g_proxy_call (server_proxy, "Close", &err, G_TYPE_INVALID, G_TYPE_INVALID) == FALSE) {
+		if (g_error_matches (err, DBUS_GERROR, DBUS_GERROR_REMOTE_EXCEPTION) == FALSE ||
+		    dbus_g_error_has_name (err, "org.openobex.Error.NotStarted") == FALSE) {
+			g_printerr ("Stopping Bluetooth ObexPush server failed: %s\n",
+				    err->message);
+			g_error_free (err);
+			return;
+		}
+		g_error_free (err);
+	}
+
+	if (stop_manager != FALSE) {
+		g_object_unref (server_proxy);
+		server_proxy = NULL;
+		g_object_unref (manager_proxy);
+		manager_proxy = NULL;
+	}
+
+	//FIXME stop all the notifications
+}
+
+void
+obexpush_down (void)
+{
+	obexpush_stop (TRUE);
+}
+
+void
+obexpush_restart (void)
+{
+	obexpush_stop (FALSE);
+	obexpush_up ();
+}
+
+gboolean
+obexpush_init (void)
+{
+	GError *err = NULL;
+
+	connection = dbus_g_bus_get (DBUS_BUS_SESSION, &err);
+	if (connection == NULL) {
+		g_printerr ("Connecting to session bus failed: %s\n",
+			    err->message);
+		g_error_free (err);
+		return FALSE;
+	}
+
+	dbus_g_object_register_marshaller (marshal_VOID__STRING_STRING_UINT64,
+					   G_TYPE_NONE,
+					   G_TYPE_STRING, G_TYPE_STRING, G_TYPE_UINT64, G_TYPE_INVALID);
+
+	if (!notify_init("mate-user-share")) {
+		g_warning("Unable to initialize the notification system\n");
+        }
+
+	dbus_connection_set_exit_on_disconnect (dbus_g_connection_get_connection (connection), FALSE);
+
+	return TRUE;
+}
+
+void
+obexpush_set_accept_files_policy (AcceptSetting setting)
+{
+	accept_setting = setting;
+}
+
+void
+obexpush_set_notify (gboolean enabled)
+{
+	show_notifications = enabled;
+}
+
+
+
+
+ + + diff --git a/2021-03-27-160708-9454-cppcheck@bc0bdef34681_master/3.html b/2021-03-27-160708-9454-cppcheck@bc0bdef34681_master/3.html new file mode 100644 index 0000000..f2cda19 --- /dev/null +++ b/2021-03-27-160708-9454-cppcheck@bc0bdef34681_master/3.html @@ -0,0 +1,764 @@ + + + + + + Cppcheck - HTML report - mate-user-share + + + + + + +
+ +
+
  1
+  2
+  3
+  4
+  5
+  6
+  7
+  8
+  9
+ 10
+ 11
+ 12
+ 13
+ 14
+ 15
+ 16
+ 17
+ 18
+ 19
+ 20
+ 21
+ 22
+ 23
+ 24
+ 25
+ 26
+ 27
+ 28
+ 29
+ 30
+ 31
+ 32
+ 33
+ 34
+ 35
+ 36
+ 37
+ 38
+ 39
+ 40
+ 41
+ 42
+ 43
+ 44
+ 45
+ 46
+ 47
+ 48
+ 49
+ 50
+ 51
+ 52
+ 53
+ 54
+ 55
+ 56
+ 57
+ 58
+ 59
+ 60
+ 61
+ 62
+ 63
+ 64
+ 65
+ 66
+ 67
+ 68
+ 69
+ 70
+ 71
+ 72
+ 73
+ 74
+ 75
+ 76
+ 77
+ 78
+ 79
+ 80
+ 81
+ 82
+ 83
+ 84
+ 85
+ 86
+ 87
+ 88
+ 89
+ 90
+ 91
+ 92
+ 93
+ 94
+ 95
+ 96
+ 97
+ 98
+ 99
+100
+101
+102
+103
+104
+105
+106
+107
+108
+109
+110
+111
+112
+113
+114
+115
+116
+117
+118
+119
+120
+121
+122
+123
+124
+125
+126
+127
+128
+129
+130
+131
+132
+133
+134
+135
+136
+137
+138
+139
+140
+141
+142
+143
+144
+145
+146
+147
+148
+149
+150
+151
+152
+153
+154
+155
+156
+157
+158
+159
+160
+161
+162
+163
+164
+165
+166
+167
+168
+169
+170
+171
+172
+173
+174
+175
+176
+177
+178
+179
+180
+181
+182
+183
+184
+185
+186
+187
+188
+189
+190
+191
+192
+193
+194
+195
+196
+197
+198
+199
+200
+201
+202
+203
+204
+205
+206
+207
+208
+209
+210
+211
+212
+213
+214
+215
+216
+217
+218
+219
+220
+221
+222
+223
+224
+225
+226
+227
+228
+229
+230
+231
+232
+233
+234
+235
+236
+237
+238
+239
+240
+241
+242
+243
+244
+245
+246
+247
+248
+249
+250
+251
+252
+253
+254
+255
+256
+257
+258
+259
+260
+261
+262
+263
+264
+265
+266
+267
+268
+269
+270
+271
+272
+273
+274
+275
+276
+277
+278
+279
+280
+281
+282
+283
+284
+285
+286
+287
+288
+289
+290
+291
/* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 8; tab-width: 8 -*-
+ *
+ * Copyright (C) 2003 Novell, Inc.
+ * Copyright (C) 2003-2004 Red Hat, Inc.
+ * Copyright (C) 2005 William Jon McCann <mccann@jhu.edu>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * 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 Foundation, Inc., 51 Franklin St, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ *
+ */
+
+#include "config.h"
+
+#include <stdlib.h>
+#include <string.h>
+#include <glib/gi18n-lib.h>
+#include <gtk/gtk.h>
+#include <libcaja-extension/caja-menu-provider.h>
+#include <libcaja-extension/caja-location-widget-provider.h>
+
+#ifdef HAVE_BLUETOOTH
+#include <bluetooth-client.h>
+#endif
+
+#include "caja-share-bar.h"
+#include "user_share-common.h"
+
+#define CAJA_TYPE_USER_SHARE  (caja_user_share_get_type ())
+#define CAJA_USER_SHARE(o)    (G_TYPE_CHECK_INSTANCE_CAST ((o), CAJA_TYPE_USER_SHARE, CajaUserShare))
+#define CAJA_IS_USER_SHARE(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), CAJA_TYPE_USER_SHARE))
+
+typedef struct
+{
+        GObject              parent_slot;
+} CajaUserShare;
+
+typedef struct
+{
+        GObjectClass parent_slot;
+} CajaUserShareClass;
+
+static GType caja_user_share_get_type      (void);
+static void  caja_user_share_register_type (GTypeModule *module);
+
+static void
+launch_process (char **argv, GtkWindow *parent)
+{
+        GError *error;
+        GtkWidget *dialog;
+
+        error = NULL;
+        if (!g_spawn_async (NULL,
+                            argv, NULL,
+                            0,
+                            NULL, NULL,
+                            NULL,
+                            &error)) {
+
+
+                dialog = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL, GTK_MESSAGE_WARNING,
+						 GTK_BUTTONS_OK, _("Unable to launch the Personal File Sharing preferences"));
+
+                gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog), "%s", error->message);
+
+                gtk_dialog_run (GTK_DIALOG (dialog));
+                gtk_widget_destroy (dialog);
+
+                g_error_free (error);
+        }
+}
+
+static void
+launch_prefs_on_window (GtkWindow *window)
+{
+        char *argv [2];
+
+        argv [0] = g_build_filename (BINDIR, "mate-file-share-properties", NULL);
+        argv [1] = NULL;
+
+        launch_process (argv, window);
+
+        g_free (argv [0]);
+}
+
+static void
+bar_response_cb (CajaShareBar *bar,
+                 gint response,
+                 gpointer         data)
+{
+        if (response == CAJA_SHARE_BAR_RESPONSE_PREFERENCES) {
+                launch_prefs_on_window (GTK_WINDOW (data));
+        }
+}
+
+#ifdef HAVE_BLUETOOTH
+static void
+downloads_bar_set_from_bluetooth_status (GtkWidget *bar)
+{
+	BluetoothClient *client;
+	gboolean bt_powered;
+
+	client = g_object_get_data (G_OBJECT (bar), "bluetooth-client");
+	g_object_get (G_OBJECT (client),
+		      "default-adapter-powered", &bt_powered,
+		      NULL);
+	gtk_widget_set_visible (bar, bt_powered);
+}
+
+static void
+default_adapter_powered_cb (GObject    *gobject,
+			    GParamSpec *pspec,
+			    GtkWidget  *bar)
+{
+	downloads_bar_set_from_bluetooth_status (bar);
+}
+#endif /* HAVE_BLUETOOTH */
+
+static GtkWidget *
+caja_user_share_get_location_widget (CajaLocationWidgetProvider *iface,
+                                         const char                     *uri,
+                                         GtkWidget                      *window)
+{
+	GFile             *file;
+	GtkWidget         *bar;
+	guint              i;
+	gboolean           enable = FALSE;
+	GFile             *home;
+#ifdef HAVE_BLUETOOTH
+	const GUserDirectory special_dirs[] = { G_USER_DIRECTORY_PUBLIC_SHARE, G_USER_DIRECTORY_DOWNLOAD };
+
+	gboolean is_dir[] = { FALSE, FALSE };
+#else
+	const GUserDirectory special_dirs[] = { G_USER_DIRECTORY_PUBLIC_SHARE };
+
+	gboolean is_dir[] = { FALSE };
+#endif /* HAVE_BLUETOOTH */
+	file = g_file_new_for_uri (uri);
+	home = g_file_new_for_path (g_get_home_dir ());
+
+	/* We don't show anything in $HOME */
+	if (g_file_equal (home, file)) {
+		g_object_unref (home);
+		g_object_unref (file);
+		return NULL;
+	}
+
+	g_object_unref (home);
+
+	for (i = 0; i < G_N_ELEMENTS (special_dirs); i++) {
+		GFile *dir;
+		dir = lookup_dir_with_fallback (special_dirs[i]);
+		if (g_file_equal (dir, file)) {
+			enable = TRUE;
+			is_dir[i] = TRUE;
+		}
+		g_object_unref (dir);
+	}
+
+	g_object_unref (file);
+
+	if (enable == FALSE)
+		return NULL;
+
+	if (is_dir[0] != FALSE) {
+#ifdef HAVE_BLUETOOTH
+		if (is_dir[1] != FALSE) {
+			bar = caja_share_bar_new (_("May be used to share or receive files"));
+		} else {
+			bar = caja_share_bar_new (_("May be shared over the network or Bluetooth"));
+		}
+#else
+		bar = caja_share_bar_new (_("May be shared over the network"));
+#endif /* HAVE_BLUETOOTH */
+	} else {
+#ifdef HAVE_BLUETOOTH
+		BluetoothClient *client;
+
+		bar = caja_share_bar_new (_("May be used to receive files over Bluetooth"));
+
+		gtk_widget_set_no_show_all (bar, TRUE);
+		client = bluetooth_client_new ();
+		g_object_set_data_full (G_OBJECT (bar), "bluetooth-client", client, g_object_unref);
+		g_signal_connect (G_OBJECT (client), "notify::default-adapter-powered",
+				  G_CALLBACK (default_adapter_powered_cb), bar);
+		downloads_bar_set_from_bluetooth_status (bar);
+#endif /* HAVE_BLUETOOTH */
+	}
+
+	g_signal_connect (bar, "response",
+			  G_CALLBACK (bar_response_cb),
+			  window);
+
+	gtk_widget_show_all (bar);
+
+	return bar;
+}
+
+static void
+caja_user_share_location_widget_provider_iface_init (CajaLocationWidgetProviderIface *iface)
+{
+        iface->get_widget = caja_user_share_get_location_widget;
+}
+
+static void
+caja_user_share_instance_init (CajaUserShare *share)
+{
+
+}
+
+static void
+caja_user_share_class_init (CajaUserShareClass *klass)
+{
+
+}
+
+static GType share_type = 0;
+
+static GType
+caja_user_share_get_type (void)
+{
+        return share_type;
+}
+
+static void
+caja_user_share_register_type (GTypeModule *module)
+{
+        static const GTypeInfo info = {
+                sizeof (CajaUserShareClass),
+                (GBaseInitFunc) NULL,
+                (GBaseFinalizeFunc) NULL,
+                (GClassInitFunc) caja_user_share_class_init,
+                NULL,
+                NULL,
+                sizeof (CajaUserShare),
+                0,
+                (GInstanceInitFunc) caja_user_share_instance_init,
+        };
+
+        static const GInterfaceInfo location_widget_provider_iface_info = {
+                (GInterfaceInitFunc) caja_user_share_location_widget_provider_iface_init,
+                NULL,
+                NULL
+        };
+
+        share_type = g_type_module_register_type (module,
+                                                 G_TYPE_OBJECT,
+                                                 "CajaUserShare",
+                                                 &info, 0);
+
+        g_type_module_add_interface (module,
+                                     share_type,
+                                     CAJA_TYPE_LOCATION_WIDGET_PROVIDER,
+                                     &location_widget_provider_iface_info);
+}
+
+void
+caja_module_initialize (GTypeModule *module)
+{
+        caja_user_share_register_type (module);
+        bindtextdomain (GETTEXT_PACKAGE, MATELOCALEDIR);
+        bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
+}
+
+void
+caja_module_shutdown (void)
+{
+}
+
+void
+caja_module_list_types (const GType **types,
+                            int          *num_types)
+{
+        static GType type_list [1];
+
+        type_list[0] = CAJA_TYPE_USER_SHARE;
+
+        *types = type_list;
+        *num_types = 1;
+}
+
+
+
+
+ + + diff --git a/2021-03-27-160708-9454-cppcheck@bc0bdef34681_master/4.html b/2021-03-27-160708-9454-cppcheck@bc0bdef34681_master/4.html new file mode 100644 index 0000000..06db2f5 --- /dev/null +++ b/2021-03-27-160708-9454-cppcheck@bc0bdef34681_master/4.html @@ -0,0 +1,1182 @@ + + + + + + Cppcheck - HTML report - mate-user-share + + + + + + +
+ +
+
  1
+  2
+  3
+  4
+  5
+  6
+  7
+  8
+  9
+ 10
+ 11
+ 12
+ 13
+ 14
+ 15
+ 16
+ 17
+ 18
+ 19
+ 20
+ 21
+ 22
+ 23
+ 24
+ 25
+ 26
+ 27
+ 28
+ 29
+ 30
+ 31
+ 32
+ 33
+ 34
+ 35
+ 36
+ 37
+ 38
+ 39
+ 40
+ 41
+ 42
+ 43
+ 44
+ 45
+ 46
+ 47
+ 48
+ 49
+ 50
+ 51
+ 52
+ 53
+ 54
+ 55
+ 56
+ 57
+ 58
+ 59
+ 60
+ 61
+ 62
+ 63
+ 64
+ 65
+ 66
+ 67
+ 68
+ 69
+ 70
+ 71
+ 72
+ 73
+ 74
+ 75
+ 76
+ 77
+ 78
+ 79
+ 80
+ 81
+ 82
+ 83
+ 84
+ 85
+ 86
+ 87
+ 88
+ 89
+ 90
+ 91
+ 92
+ 93
+ 94
+ 95
+ 96
+ 97
+ 98
+ 99
+100
+101
+102
+103
+104
+105
+106
+107
+108
+109
+110
+111
+112
+113
+114
+115
+116
+117
+118
+119
+120
+121
+122
+123
+124
+125
+126
+127
+128
+129
+130
+131
+132
+133
+134
+135
+136
+137
+138
+139
+140
+141
+142
+143
+144
+145
+146
+147
+148
+149
+150
+151
+152
+153
+154
+155
+156
+157
+158
+159
+160
+161
+162
+163
+164
+165
+166
+167
+168
+169
+170
+171
+172
+173
+174
+175
+176
+177
+178
+179
+180
+181
+182
+183
+184
+185
+186
+187
+188
+189
+190
+191
+192
+193
+194
+195
+196
+197
+198
+199
+200
+201
+202
+203
+204
+205
+206
+207
+208
+209
+210
+211
+212
+213
+214
+215
+216
+217
+218
+219
+220
+221
+222
+223
+224
+225
+226
+227
+228
+229
+230
+231
+232
+233
+234
+235
+236
+237
+238
+239
+240
+241
+242
+243
+244
+245
+246
+247
+248
+249
+250
+251
+252
+253
+254
+255
+256
+257
+258
+259
+260
+261
+262
+263
+264
+265
+266
+267
+268
+269
+270
+271
+272
+273
+274
+275
+276
+277
+278
+279
+280
+281
+282
+283
+284
+285
+286
+287
+288
+289
+290
+291
+292
+293
+294
+295
+296
+297
+298
+299
+300
+301
+302
+303
+304
+305
+306
+307
+308
+309
+310
+311
+312
+313
+314
+315
+316
+317
+318
+319
+320
+321
+322
+323
+324
+325
+326
+327
+328
+329
+330
+331
+332
+333
+334
+335
+336
+337
+338
+339
+340
+341
+342
+343
+344
+345
+346
+347
+348
+349
+350
+351
+352
+353
+354
+355
+356
+357
+358
+359
+360
+361
+362
+363
+364
+365
+366
+367
+368
+369
+370
+371
+372
+373
+374
+375
+376
+377
+378
+379
+380
+381
+382
+383
+384
+385
+386
+387
+388
+389
+390
+391
+392
+393
+394
+395
+396
+397
+398
+399
+400
+401
+402
+403
+404
+405
+406
+407
+408
+409
+410
+411
+412
+413
+414
+415
+416
+417
+418
+419
+420
+421
+422
+423
+424
+425
+426
+427
+428
+429
+430
+431
+432
+433
+434
+435
+436
+437
+438
+439
+440
+441
+442
+443
+444
+445
+446
+447
+448
+449
+450
+451
+452
+453
+454
+455
+456
+457
+458
+459
+460
+461
+462
+463
+464
+465
+466
+467
+468
+469
+470
+471
+472
+473
+474
+475
+476
+477
+478
+479
+480
+481
+482
+483
+484
+485
+486
+487
+488
+489
+490
+491
+492
+493
+494
+495
+496
+497
+498
+499
+500
+501
+502
+503
+504
+505
+506
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
+
+/*
+ *  Copyright (C) 2004-2008 Red Hat, Inc.
+ *
+ *  Caja is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU General Public License as
+ *  published by the Free Software Foundation; either version 2 of the
+ *  License, or (at your option) any later version.
+ *
+ *  Caja is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  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
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ *  Authors: Alexander Larsson <alexl@redhat.com>
+ *
+ */
+
+#include "config.h"
+
+#include <gdk/gdkx.h>
+#include <gtk/gtk.h>
+#include <glib/gi18n.h>
+#include <glib/gstdio.h>
+#include <gio/gio.h>
+#include <X11/Xlib.h>
+
+#include "user_share-private.h"
+#include "user_share-common.h"
+#include "http.h"
+
+#ifdef HAVE_BLUETOOTH
+#include <bluetooth-client.h>
+
+#include "obexftp.h"
+#include "obexpush.h"
+
+#endif /* HAVE_BLUETOOTH */
+
+#include <gio/gio.h>
+
+#include <stdarg.h>
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <signal.h>
+#include <unistd.h>
+
+static guint disabled_timeout_tag = 0;
+static GSettings* settings;<--- Shadowed declaration<--- Shadowed declaration<--- Shadowed declaration
+
+#define GSETTINGS_SCHEMA "org.mate.FileSharing"
+#define GSETTINGS_KEY_FILE_SHARING_ENABLED "enabled"
+#define GSETTINGS_KEY_FILE_SHARING_REQUIRE_PASSWORD "require-password"
+
+#ifdef HAVE_BLUETOOTH
+/* MATE Session */
+#define MATE_SESSION_DBUS_NAME      "org.gnome.SessionManager"
+#define MATE_SESSION_DBUS_OBJECT    "/org/gnome/SessionManager"
+#define MATE_SESSION_DBUS_INTERFACE "org.gnome.SessionManager"
+
+static GDBusProxy *session_proxy = NULL;
+static gboolean has_console = TRUE;
+
+static BluetoothClient *client = NULL;
+static gboolean bluetoothd_enabled = FALSE;
+
+#define OBEX_ENABLED (bluetoothd_enabled && has_console)
+
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_ENABLED "bluetooth-enabled"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_ALLOW_WRITE "bluetooth-allow-write"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_REQUIRE_PAIRING "bluetooth-require-pairing"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED "bluetooth-obexpush-enabled"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_ACCEPT_FILES "bluetooth-accept-files"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_NOTIFY "bluetooth-notify"
+
+
+static void
+obex_services_start (void)
+{
+	GSettings *settings;<--- Shadow variable
+
+	if (bluetoothd_enabled == FALSE ||
+	    has_console == FALSE)
+	    	return;
+
+	settings = g_settings_new(GSETTINGS_SCHEMA);
+
+	if (g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED) == TRUE) {
+	    obexpush_up ();
+	}
+	if (g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_ENABLED) == TRUE) {
+	    obexftp_up ();
+	}
+
+	g_object_unref (client);
+}
+
+static void
+obex_services_shutdown (void)
+{
+	obexpush_down ();
+	obexftp_down ();
+}
+
+static void
+session_properties_changed_cb (GDBusProxy      *session,
+			       GVariant        *changed,
+			       char           **invalidated,
+			       gpointer         user_data)
+{
+	GVariant *v;
+
+	v = g_variant_lookup_value (changed, "SessionIsActive", G_VARIANT_TYPE_BOOLEAN);
+	if (v) {
+		has_console = g_variant_get_boolean (v);
+		g_debug ("Received session is active change: now %s", has_console ? "active" : "inactive");
+
+		if (has_console)
+			obex_services_start ();
+		else
+			obex_services_shutdown ();
+
+		g_variant_unref (v);
+	}
+}
+
+static gboolean
+is_session_active (void)
+{
+	GVariant *variant;
+	gboolean is_session_active = FALSE;
+
+	variant = g_dbus_proxy_get_cached_property (session_proxy,
+						    "SessionIsActive");
+	if (variant) {
+		is_session_active = g_variant_get_boolean (variant);
+		g_variant_unref (variant);
+ 	}
+
+	return is_session_active;
+}
+
+static void
+session_init (void)
+{
+	GError *error = NULL;
+
+	session_proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION,
+						       G_DBUS_PROXY_FLAGS_NONE,
+						       NULL,
+						       MATE_SESSION_DBUS_NAME,
+						       MATE_SESSION_DBUS_OBJECT,
+						       MATE_SESSION_DBUS_INTERFACE,
+						       NULL,
+						       &error);
+	if (session_proxy == NULL) {
+		g_warning ("Failed to get session proxy: %s", error->message);
+		g_error_free (error);
+		return;
+	}
+	g_signal_connect (session_proxy, "g-properties-changed",
+			  G_CALLBACK (session_properties_changed_cb),
+			  NULL);
+	has_console = is_session_active ();
+}
+
+static void
+default_adapter_changed (GObject    *gobject,
+			 GParamSpec *pspec,
+			 gpointer    user_data)
+{
+	char *adapter;
+	gboolean adapter_powered;
+
+	g_object_get (G_OBJECT (client),
+		      "default-adapter", &adapter,
+		      "default-adapter-powered", &adapter_powered,
+		      NULL);
+	if (adapter != NULL && *adapter != '\0') {
+		bluetoothd_enabled = adapter_powered;
+	} else {
+		bluetoothd_enabled = FALSE;
+	}
+
+	/* Were we called as init, or as a callback */
+	if (gobject != NULL) {
+		if (bluetoothd_enabled != FALSE)
+			obex_services_start ();
+		else
+			obex_services_shutdown ();
+	}
+}
+
+static void
+bluez_init (void)
+{
+	client = bluetooth_client_new ();
+	default_adapter_changed (NULL, NULL, NULL);
+	g_signal_connect (G_OBJECT (client), "notify::default-adapter",
+			  G_CALLBACK (default_adapter_changed), NULL);
+	g_signal_connect (G_OBJECT (client), "notify::default-adapter-powered",
+			  G_CALLBACK (default_adapter_changed), NULL);
+}
+#endif /* HAVE_BLUETOOTH */
+
+static gboolean
+file_sharing_enabled (void)
+{
+	gboolean enabled = TRUE;
+	settings = g_settings_new (GSETTINGS_SCHEMA);
+
+#ifdef HAVE_BLUETOOTH
+	if (g_settings_get_boolean (settings, FILE_SHARING_ENABLED) == FALSE &&
+	    g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_ENABLED) == FALSE &&
+	    g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED) == FALSE)
+#else /* HAVE_BLUETOOTH */
+	if (g_settings_get_boolean (settings, FILE_SHARING_ENABLED) == FALSE)
+#endif /* HAVE_BLUETOOTH */
+		enabled = FALSE;
+
+	g_object_unref (settings);
+
+	return enabled;
+}
+
+static void
+migrate_old_configuration (void)
+{
+	const char *old_config_dir;
+	const char *new_config_dir;
+
+	old_config_dir = g_build_filename (g_get_home_dir (), ".mate2", "user-share", NULL);
+	new_config_dir = g_build_filename (g_get_user_config_dir (), "user-share", NULL);
+	if (g_file_test (old_config_dir, G_FILE_TEST_IS_DIR))
+		g_rename (old_config_dir, new_config_dir);
+
+}
+
+static void
+require_password_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	/* Need to restart to get new password setting */
+	if (http_get_pid () != 0) {
+		http_down ();
+		http_up ();
+	}
+}
+
+/* File sharing was disabled for some time, exit now */
+/* If we re-enable it in the ui, this will be restarted anyway */
+static gboolean
+disabled_timeout_callback (gpointer user_data)
+{
+	GSettings *settings = (GSettings *) user_data;<--- Shadow variable
+	http_down ();
+
+#ifdef HAVE_BLUETOOTH
+	if (g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_ENABLED) == FALSE &&
+	    g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED) == FALSE)
+		_exit (0);
+#else /* HAVE_BLUETOOTH */
+	if (g_settings_get_boolean (settings, FILE_SHARING_ENABLED) == FALSE)
+		_exit (0);
+#endif /* HAVE_BLUETOOTH */
+	return FALSE;
+}
+
+static void
+file_sharing_enabled_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	gboolean enabled;
+
+	if (disabled_timeout_tag != 0) {
+		g_source_remove (disabled_timeout_tag);
+		disabled_timeout_tag = 0;
+	}
+
+	enabled = g_settings_get_boolean (settings,
+					 FILE_SHARING_ENABLED);
+	if (enabled) {
+		if (http_get_pid () == 0) {
+			http_up ();
+		}
+	} else {
+		http_down ();
+		disabled_timeout_tag = g_timeout_add_seconds (3,
+							      (GSourceFunc)disabled_timeout_callback,
+							      settings);
+	}
+}
+
+#ifdef HAVE_BLUETOOTH
+static void
+file_sharing_bluetooth_allow_write_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	if (g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_ENABLED) != FALSE)
+		obexftp_restart ();
+}
+
+static void
+file_sharing_bluetooth_require_pairing_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	if (g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_ENABLED) != FALSE) {
+		/* We need to fully reset the session,
+		 * otherwise the new setting isn't taken into account */
+		obexftp_down ();
+		obexftp_up ();
+	}
+}
+
+static void
+file_sharing_bluetooth_enabled_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	if (g_settings_get_boolean (settings,
+				   FILE_SHARING_BLUETOOTH_ENABLED) == FALSE) {
+		obexftp_down ();
+		if (g_settings_get_boolean (settings, FILE_SHARING_ENABLED) == FALSE &&
+		    g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED) == FALSE) {
+			_exit (0);
+		}
+	} else if (OBEX_ENABLED) {
+		obexftp_up ();
+	}
+}
+
+static void
+file_sharing_bluetooth_obexpush_enabled_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	if (g_settings_get_boolean (settings,
+				   FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED) == FALSE) {
+		obexpush_down ();
+		if (g_settings_get_boolean (settings, FILE_SHARING_ENABLED) == FALSE &&
+		    g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_ENABLED) == FALSE) {
+			_exit (0);
+		}
+	} else if (OBEX_ENABLED) {
+		obexpush_up ();
+	}
+}
+
+static void
+file_sharing_bluetooth_obexpush_accept_files_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	AcceptSetting setting;
+	char *str;
+
+	str = g_settings_get_string (settings, FILE_SHARING_BLUETOOTH_OBEXPUSH_ACCEPT_FILES);
+	setting = accept_setting_from_string (str);
+	g_free (str);
+
+	obexpush_set_accept_files_policy (setting);
+}
+
+static void
+file_sharing_bluetooth_obexpush_notify_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	obexpush_set_notify (g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_OBEXPUSH_NOTIFY));
+}
+#endif /* HAVE_BLUETOOTH */
+
+static RETSIGTYPE
+cleanup_handler (int sig)
+{
+	http_down ();
+#ifdef HAVE_BLUETOOTH
+	obexftp_down ();
+	obexpush_down ();
+#endif /* HAVE_BLUETOOTH */
+	_exit (2);
+}
+
+static int
+x_io_error_handler (Display *xdisplay)
+{
+	http_down ();
+#ifdef HAVE_BLUETOOTH
+	obexftp_down ();
+#endif /* HAVE_BLUETOOTH */
+	_exit (2);
+}
+
+int
+main (int argc, char **argv)
+{
+	GSettings *settings;<--- Shadow variable
+	Display *xdisplay;
+	G_GNUC_UNUSED int x_fd;
+	Window selection_owner;
+	Atom xatom;
+
+	bindtextdomain (GETTEXT_PACKAGE, MATELOCALEDIR);
+	bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
+	textdomain (GETTEXT_PACKAGE);
+
+	gtk_init (&argc, &argv);
+
+	if (g_strcmp0 (g_get_real_name (), "root") == 0) {
+		g_warning ("mate-user-share cannot be started as root for security reasons.");
+		return 1;
+	}
+
+	signal (SIGPIPE, SIG_IGN);
+	signal (SIGINT, cleanup_handler);
+	signal (SIGHUP, cleanup_handler);
+	signal (SIGTERM, cleanup_handler);
+
+	xdisplay = GDK_DISPLAY_XDISPLAY (gdk_display_get_default ());
+	if (xdisplay == NULL) {
+		g_warning ("Can't open display");
+		return 1;
+	}
+
+	xatom = XInternAtom (xdisplay, "_MATE_USER_SHARE", FALSE);
+	selection_owner = XGetSelectionOwner (xdisplay, xatom);
+
+	if (selection_owner != None) {
+		/* There is an owner already, quit */
+		return 1;
+	}
+
+	selection_owner = XCreateSimpleWindow (xdisplay,
+					       RootWindow (xdisplay, 0),
+					       0, 0, 1, 1,
+					       0, 0, 0);
+	XSetSelectionOwner (xdisplay, xatom, selection_owner, CurrentTime);
+
+	if (XGetSelectionOwner (xdisplay, xatom) != selection_owner) {
+		/* Didn't get the selection */
+		return 1;
+	}
+
+	migrate_old_configuration ();
+
+	if (!file_sharing_enabled ())
+		return 1;
+
+	settings = g_settings_new (GSETTINGS_SCHEMA);
+
+	x_fd = ConnectionNumber (xdisplay);
+	XSetIOErrorHandler (x_io_error_handler);
+
+	if (http_init () == FALSE)
+		return 1;
+#ifdef HAVE_BLUETOOTH
+	if (obexftp_init () == FALSE)
+		return 1;
+	if (obexpush_init () == FALSE)
+		return 1;
+#endif /* HAVE_BLUETOOTH */
+
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_ENABLED,
+			     G_CALLBACK (file_sharing_enabled_changed), NULL);
+
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_REQUIRE_PASSWORD,
+			     G_CALLBACK (require_password_changed), NULL);
+
+#ifdef HAVE_BLUETOOTH
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_ENABLED,
+			     G_CALLBACK (file_sharing_bluetooth_enabled_changed), NULL);
+
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_ALLOW_WRITE,
+			     G_CALLBACK (file_sharing_bluetooth_allow_write_changed), NULL);
+
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_REQUIRE_PAIRING,
+			     G_CALLBACK (file_sharing_bluetooth_require_pairing_changed), NULL);
+
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED,
+			     G_CALLBACK (file_sharing_bluetooth_obexpush_enabled_changed), NULL);
+
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_ACCEPT_FILES,
+			     G_CALLBACK (file_sharing_bluetooth_obexpush_accept_files_changed), NULL);
+
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_NOTIFY,
+			     G_CALLBACK (file_sharing_bluetooth_obexpush_notify_changed), NULL);
+
+	bluez_init ();
+	session_init ();
+#endif /* HAVE_BLUETOOTH */
+
+	/* Initial setting */
+	file_sharing_enabled_changed (settings, NULL, NULL);
+#ifdef HAVE_BLUETOOTH
+	file_sharing_bluetooth_enabled_changed (settings, NULL, NULL);
+	file_sharing_bluetooth_obexpush_accept_files_changed (settings, NULL, NULL);
+	file_sharing_bluetooth_obexpush_notify_changed (settings, NULL, NULL);
+	file_sharing_bluetooth_obexpush_enabled_changed (settings, NULL, NULL);
+#endif /* HAVE_BLUETOOTH */
+
+	gtk_main ();
+
+	return 0;
+}
+
+
+
+
+ + + diff --git a/2021-03-27-160708-9454-cppcheck@bc0bdef34681_master/index.html b/2021-03-27-160708-9454-cppcheck@bc0bdef34681_master/index.html new file mode 100644 index 0000000..bbcd983 --- /dev/null +++ b/2021-03-27-160708-9454-cppcheck@bc0bdef34681_master/index.html @@ -0,0 +1,141 @@ + + + + + + Cppcheck - HTML report - mate-user-share + + + + + + +
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
LineIdCWESeverityMessage
missingIncludeinformationCppcheck cannot find all the include files (use --check-config for details)
src/file-share-properties.c
82variableScope398styleThe scope of the variable 'password' can be reduced.
97shadowVariable398styleLocal variable 'settings' shadows outer variable
105unusedVariable563styleUnused variable: accept_setting
249shadowVariable398styleLocal variable 'settings' shadows outer variable
273shadowVariable398styleLocal variable 'settings' shadows outer variable
294shadowVariable398styleLocal variable 'settings' shadows outer variable
323shadowVariable398styleLocal variable 'settings' shadows outer variable
340shadowVariable398styleLocal variable 'settings' shadows outer variable
357shadowVariable398styleLocal variable 'settings' shadows outer variable
377shadowVariable398styleLocal variable 'settings' shadows outer variable
393shadowVariable398styleLocal variable 'settings' shadows outer variable
457shadowVariable398styleLocal variable 'settings' shadows outer variable
620variableScope398styleThe scope of the variable 'window' can be reduced.
src/http.c
114variableScope398styleThe scope of the variable 'host_name' can be reduced.
src/obexpush.c
187shadowVariable398styleLocal variable 'connection' shadows outer variable
src/share-extension.c
61variableScope398styleThe scope of the variable 'dialog' can be reduced.
src/user_share.c
86shadowVariable398styleLocal variable 'settings' shadows outer variable
260shadowVariable398styleLocal variable 'settings' shadows outer variable
391shadowVariable398styleLocal variable 'settings' shadows outer variable
+
+
+ + + diff --git a/2021-03-27-160708-9454-cppcheck@bc0bdef34681_master/stats.html b/2021-03-27-160708-9454-cppcheck@bc0bdef34681_master/stats.html new file mode 100644 index 0000000..2020977 --- /dev/null +++ b/2021-03-27-160708-9454-cppcheck@bc0bdef34681_master/stats.html @@ -0,0 +1,109 @@ + + + + + + Cppcheck - HTML report - mate-user-share + + + + + + +
+ +
+

Top 10 files for style severity, total findings: 19
+   13  src/file-share-properties.c
+   3   src/user_share.c
+   1   src/share-extension.c
+   1   src/obexpush.c
+   1   src/http.c
+

+ +
+
+ + + diff --git a/2021-03-27-160708-9454-cppcheck@bc0bdef34681_master/style.css b/2021-03-27-160708-9454-cppcheck@bc0bdef34681_master/style.css new file mode 100644 index 0000000..07125f4 --- /dev/null +++ b/2021-03-27-160708-9454-cppcheck@bc0bdef34681_master/style.css @@ -0,0 +1,137 @@ + +body { + font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif; + font-size: 13px; + line-height: 1.5; + margin: 0; + width: auto; +} + +h1 { + margin: 10px; +} + +.header { + border-bottom: thin solid #aaa; +} + +.footer { + border-top: thin solid #aaa; + font-size: 90%; + margin-top: 5px; +} + +.footer ul { + list-style-type: none; + padding-left: 0; +} + +.footer > p { + margin: 4px; +} + +.wrapper { + display: -webkit-box; + display: -ms-flexbox; + display: flex; + -webkit-box-pack: justify; + -ms-flex-pack: justify; + justify-content: space-between; +} + +#menu, +#menu_index { + text-align: left; + width: 350px; + height: 90vh; + min-height: 200px; + overflow: auto; + position: -webkit-sticky; + position: sticky; + top: 0; + padding: 0 15px 15px 15px; +} + +#menu > a { + display: block; + margin-left: 10px; + font-size: 12px; + z-index: 1; +} + +#content, +#content_index { + background-color: #fff; + -webkit-box-sizing: content-box; + -moz-box-sizing: content-box; + box-sizing: content-box; + padding: 0 15px 15px 15px; + width: calc(100% - 350px); + height: 100%; + overflow-x: auto; +} + +#filename { + margin-left: 10px; + font-size: 12px; + z-index: 1; +} + +.error { + background-color: #ffb7b7; +} + +.error2 { + background-color: #faa; + display: inline-block; + margin-left: 4px; +} + +.inconclusive { + background-color: #b6b6b4; +} + +.inconclusive2 { + background-color: #b6b6b4; + display: inline-block; + margin-left: 4px; +} + +.verbose { + display: inline-block; + vertical-align: top; + cursor: help; +} + +.verbose .content { + display: none; + position: absolute; + padding: 10px; + margin: 4px; + max-width: 40%; + white-space: pre-wrap; + border: 1px solid #000; + background-color: #ffffcc; + cursor: auto; +} + +.highlight .hll { + padding: 1px; +} + +.highlighttable { + background-color: #fff; + z-index: 10; + position: relative; + margin: -10px; +} + +.linenos { + border-right: thin solid #aaa; + color: #d3d3d3; + padding-right: 6px; +} + +.d-none { + display: none; +} diff --git a/2021-04-25-143339-9886-cppcheck@cf2a18e177f2_master/0.html b/2021-04-25-143339-9886-cppcheck@cf2a18e177f2_master/0.html new file mode 100644 index 0000000..74c198b --- /dev/null +++ b/2021-04-25-143339-9886-cppcheck@cf2a18e177f2_master/0.html @@ -0,0 +1,1498 @@ + + + + + + Cppcheck - HTML report - mate-user-share + + + + + + +
+ +
+
  1
+  2
+  3
+  4
+  5
+  6
+  7
+  8
+  9
+ 10
+ 11
+ 12
+ 13
+ 14
+ 15
+ 16
+ 17
+ 18
+ 19
+ 20
+ 21
+ 22
+ 23
+ 24
+ 25
+ 26
+ 27
+ 28
+ 29
+ 30
+ 31
+ 32
+ 33
+ 34
+ 35
+ 36
+ 37
+ 38
+ 39
+ 40
+ 41
+ 42
+ 43
+ 44
+ 45
+ 46
+ 47
+ 48
+ 49
+ 50
+ 51
+ 52
+ 53
+ 54
+ 55
+ 56
+ 57
+ 58
+ 59
+ 60
+ 61
+ 62
+ 63
+ 64
+ 65
+ 66
+ 67
+ 68
+ 69
+ 70
+ 71
+ 72
+ 73
+ 74
+ 75
+ 76
+ 77
+ 78
+ 79
+ 80
+ 81
+ 82
+ 83
+ 84
+ 85
+ 86
+ 87
+ 88
+ 89
+ 90
+ 91
+ 92
+ 93
+ 94
+ 95
+ 96
+ 97
+ 98
+ 99
+100
+101
+102
+103
+104
+105
+106
+107
+108
+109
+110
+111
+112
+113
+114
+115
+116
+117
+118
+119
+120
+121
+122
+123
+124
+125
+126
+127
+128
+129
+130
+131
+132
+133
+134
+135
+136
+137
+138
+139
+140
+141
+142
+143
+144
+145
+146
+147
+148
+149
+150
+151
+152
+153
+154
+155
+156
+157
+158
+159
+160
+161
+162
+163
+164
+165
+166
+167
+168
+169
+170
+171
+172
+173
+174
+175
+176
+177
+178
+179
+180
+181
+182
+183
+184
+185
+186
+187
+188
+189
+190
+191
+192
+193
+194
+195
+196
+197
+198
+199
+200
+201
+202
+203
+204
+205
+206
+207
+208
+209
+210
+211
+212
+213
+214
+215
+216
+217
+218
+219
+220
+221
+222
+223
+224
+225
+226
+227
+228
+229
+230
+231
+232
+233
+234
+235
+236
+237
+238
+239
+240
+241
+242
+243
+244
+245
+246
+247
+248
+249
+250
+251
+252
+253
+254
+255
+256
+257
+258
+259
+260
+261
+262
+263
+264
+265
+266
+267
+268
+269
+270
+271
+272
+273
+274
+275
+276
+277
+278
+279
+280
+281
+282
+283
+284
+285
+286
+287
+288
+289
+290
+291
+292
+293
+294
+295
+296
+297
+298
+299
+300
+301
+302
+303
+304
+305
+306
+307
+308
+309
+310
+311
+312
+313
+314
+315
+316
+317
+318
+319
+320
+321
+322
+323
+324
+325
+326
+327
+328
+329
+330
+331
+332
+333
+334
+335
+336
+337
+338
+339
+340
+341
+342
+343
+344
+345
+346
+347
+348
+349
+350
+351
+352
+353
+354
+355
+356
+357
+358
+359
+360
+361
+362
+363
+364
+365
+366
+367
+368
+369
+370
+371
+372
+373
+374
+375
+376
+377
+378
+379
+380
+381
+382
+383
+384
+385
+386
+387
+388
+389
+390
+391
+392
+393
+394
+395
+396
+397
+398
+399
+400
+401
+402
+403
+404
+405
+406
+407
+408
+409
+410
+411
+412
+413
+414
+415
+416
+417
+418
+419
+420
+421
+422
+423
+424
+425
+426
+427
+428
+429
+430
+431
+432
+433
+434
+435
+436
+437
+438
+439
+440
+441
+442
+443
+444
+445
+446
+447
+448
+449
+450
+451
+452
+453
+454
+455
+456
+457
+458
+459
+460
+461
+462
+463
+464
+465
+466
+467
+468
+469
+470
+471
+472
+473
+474
+475
+476
+477
+478
+479
+480
+481
+482
+483
+484
+485
+486
+487
+488
+489
+490
+491
+492
+493
+494
+495
+496
+497
+498
+499
+500
+501
+502
+503
+504
+505
+506
+507
+508
+509
+510
+511
+512
+513
+514
+515
+516
+517
+518
+519
+520
+521
+522
+523
+524
+525
+526
+527
+528
+529
+530
+531
+532
+533
+534
+535
+536
+537
+538
+539
+540
+541
+542
+543
+544
+545
+546
+547
+548
+549
+550
+551
+552
+553
+554
+555
+556
+557
+558
+559
+560
+561
+562
+563
+564
+565
+566
+567
+568
+569
+570
+571
+572
+573
+574
+575
+576
+577
+578
+579
+580
+581
+582
+583
+584
+585
+586
+587
+588
+589
+590
+591
+592
+593
+594
+595
+596
+597
+598
+599
+600
+601
+602
+603
+604
+605
+606
+607
+608
+609
+610
+611
+612
+613
+614
+615
+616
+617
+618
+619
+620
+621
+622
+623
+624
+625
+626
+627
+628
+629
+630
+631
+632
+633
+634
+635
+636
+637
+638
+639
+640
+641
+642
+643
+644
+645
+646
+647
+648
+649
+650
+651
+652
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
+
+/*
+ *  Copyright (C) 2004 Red Hat, Inc.
+ *
+ *  Caja is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU General Public License as
+ *  published by the Free Software Foundation; either version 2 of the
+ *  License, or (at your option) any later version.
+ *
+ *  Caja is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  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
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ *  Authors: Alexander Larsson <alexl@redhat.com>
+ *
+ */
+
+#include "config.h"
+
+#include <string.h>
+#include <stdio.h>
+
+#include <gtk/gtk.h>
+#include <glib/gi18n.h>
+#include <gio/gio.h>
+
+#include "user_share-private.h"
+
+#define REALM "Please log in as the user guest"
+#define USER "guest"
+#define GSETTINGS_SCHEMA "org.mate.FileSharing"
+#define GSETTINGS_KEY_FILE_SHARING_ENABLED "enabled"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_ENABLED "bluetooth-enabled"
+#define GSETTINGS_KEY_FILE_SHARING_REQUIRE_PASSWORD "require-password"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_ALLOW_WRITE "bluetooth-allow-write"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_REQUIRE_PAIRING "bluetooth-require-pairing"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED "bluetooth-obexpush-enabled"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_ACCEPT_FILES "bluetooth-accept-files"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_NOTIFY "bluetooth-notify"
+
+static GtkBuilder* builder;
+static GSettings* settings;<--- Shadowed declaration<--- Shadowed declaration<--- Shadowed declaration<--- Shadowed declaration<--- Shadowed declaration<--- Shadowed declaration<--- Shadowed declaration<--- Shadowed declaration<--- Shadowed declaration<--- Shadowed declaration
+
+
+static void
+write_out_password (const char *password)
+{
+    char *to_hash;
+    char *ascii_digest;
+    char *line;
+    char *filename;
+    FILE *file;
+
+    to_hash = g_strdup_printf ("%s:%s:%s", USER, REALM, password);
+    ascii_digest = g_compute_checksum_for_string (G_CHECKSUM_MD5, to_hash, strlen (to_hash));
+    g_free (to_hash);
+    line = g_strdup_printf ("%s:%s:%s\n", USER, REALM, ascii_digest);
+    g_free (ascii_digest);
+
+    filename = g_build_filename (g_get_user_config_dir (), "user-share", "passwd", NULL);
+
+    file = fopen (filename, "w");
+    if (file != NULL) {
+	fwrite (line, strlen (line), 1, file);
+	fclose (file);
+    }
+
+    g_free (filename);
+    g_free (line);
+}
+
+static void
+flush_password (void)
+{
+    GtkWidget *password_entry;
+    const char *password;
+
+    password_entry = GTK_WIDGET (gtk_builder_get_object (builder, "password_entry"));
+
+    if (g_object_get_data (G_OBJECT( password_entry), "user_edited")) {
+	password = gtk_entry_get_text (GTK_ENTRY (password_entry));
+	if (password != NULL && password[0] != 0)
+	    write_out_password (password);
+    }
+}
+
+
+static void
+update_ui (void)
+{
+    GSettings *settings;<--- Shadow variable
+    gboolean enabled;
+#ifdef HAVE_BLUETOOTH
+    gboolean bluetooth_enabled, bluetooth_write_enabled, require_pairing_enabled;
+    gboolean bluetooth_obexpush_enabled, bluetooth_obexpush_notify;
+#endif /* HAVE_BLUETOOTH */
+    char *str;
+    PasswordSetting password_setting;
+    AcceptSetting accept_setting;<--- Unused variable: accept_setting
+    GtkWidget *check;
+    GtkWidget *password_combo;
+    GtkWidget *password_entry;
+#ifdef HAVE_BLUETOOTH
+    GtkWidget *vbox_share_bluetooth;
+    GtkWidget *vbox_receive_bluetooth;
+    GtkWidget *bluetooth_check;
+    GtkWidget *allow_write_bluetooth_check;
+    GtkWidget *require_pairing_check;
+    GtkWidget *enable_obexpush_check;
+    GtkWidget *accept_obexpush_combo;
+    GtkWidget *notify_received_obexpush_check;
+#endif /* HAVE_BLUETOOTH */
+
+    settings = g_settings_new (GSETTINGS_SCHEMA);
+
+    enabled = g_settings_get_boolean (settings,
+				     FILE_SHARING_ENABLED);
+
+    str = g_settings_get_string (settings, FILE_SHARING_REQUIRE_PASSWORD);
+    password_setting = password_setting_from_string (str);
+    g_free (str);
+
+#ifdef HAVE_BLUETOOTH
+    bluetooth_enabled = g_settings_get_boolean (settings,
+    					       FILE_SHARING_BLUETOOTH_ENABLED);
+    bluetooth_write_enabled = g_settings_get_boolean (settings,
+						     FILE_SHARING_BLUETOOTH_ALLOW_WRITE);
+    require_pairing_enabled = g_settings_get_boolean (settings,
+    						     FILE_SHARING_BLUETOOTH_REQUIRE_PAIRING);
+    bluetooth_obexpush_enabled = g_settings_get_boolean (settings,
+    							FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED);
+    bluetooth_obexpush_notify = g_settings_get_boolean (settings,
+    						       FILE_SHARING_BLUETOOTH_OBEXPUSH_NOTIFY);
+
+    str = g_settings_get_string (settings, FILE_SHARING_BLUETOOTH_OBEXPUSH_ACCEPT_FILES);
+    accept_setting = accept_setting_from_string (str);
+    g_free (str);
+#endif /* HAVE_BLUETOOTH */
+
+    check = GTK_WIDGET (gtk_builder_get_object (builder, "enable_check"));
+    password_combo = GTK_WIDGET (gtk_builder_get_object (builder, "password_combo"));
+    password_entry = GTK_WIDGET (gtk_builder_get_object (builder, "password_entry"));
+#ifdef HAVE_BLUETOOTH
+    vbox_share_bluetooth = GTK_WIDGET (gtk_builder_get_object (builder, "vbox_share_bluetooth"));
+    vbox_receive_bluetooth = GTK_WIDGET (gtk_builder_get_object (builder, "vbox_receive_bluetooth"));
+    bluetooth_check = GTK_WIDGET (gtk_builder_get_object (builder, "enable_bluetooth_check"));
+    allow_write_bluetooth_check = GTK_WIDGET (gtk_builder_get_object (builder, "allow_write_bluetooth_check"));
+    require_pairing_check = GTK_WIDGET (gtk_builder_get_object (builder, "require_pairing_check"));
+    enable_obexpush_check = GTK_WIDGET (gtk_builder_get_object (builder, "enable_obexpush_check"));
+    accept_obexpush_combo = GTK_WIDGET (gtk_builder_get_object (builder, "accept_obexpush_combo"));
+    notify_received_obexpush_check = GTK_WIDGET (gtk_builder_get_object (builder, "notify_received_obexpush_check"));
+#endif /* HAVE_BLUETOOTH */
+
+    /* Network */
+    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (check), enabled);
+    gtk_widget_set_sensitive (password_combo, enabled);
+    gtk_widget_set_sensitive (password_entry, enabled && password_setting != PASSWORD_NEVER);
+
+    gtk_combo_box_set_active (GTK_COMBO_BOX (password_combo),
+			      password_setting);
+
+#ifdef HAVE_BLUETOOTH
+    /* Bluetooth ObexFTP */
+    gtk_widget_set_visible (vbox_share_bluetooth, TRUE);
+    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (bluetooth_check), bluetooth_enabled);
+    gtk_widget_set_sensitive (allow_write_bluetooth_check, bluetooth_enabled);
+    gtk_widget_set_sensitive (require_pairing_check, bluetooth_enabled);
+
+    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (allow_write_bluetooth_check),
+    				  bluetooth_write_enabled);
+    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (require_pairing_check),
+    				  require_pairing_enabled);
+
+    /* Bluetooth ObexPush */
+    gtk_widget_set_visible (vbox_receive_bluetooth, TRUE);
+    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (enable_obexpush_check), bluetooth_obexpush_enabled);
+    gtk_widget_set_sensitive (accept_obexpush_combo, bluetooth_obexpush_enabled);
+    gtk_widget_set_sensitive (notify_received_obexpush_check, bluetooth_obexpush_enabled);
+
+    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (notify_received_obexpush_check),
+    				  bluetooth_obexpush_notify);
+
+    gtk_combo_box_set_active (GTK_COMBO_BOX (accept_obexpush_combo),
+    			      accept_setting);
+#endif /* HAVE_BLUETOOTH */
+
+    g_object_unref (settings);
+}
+
+static void
+file_sharing_enabled_changed (GSettings *settings, gchar *key, gpointer data)
+{
+    update_ui ();
+}
+
+static void
+password_required_changed (GSettings *settings, gchar *key, gpointer data)
+{
+    update_ui ();
+}
+
+#ifdef HAVE_BLUETOOTH
+static void
+file_sharing_bluetooth_enabled_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	update_ui ();
+}
+
+static void
+file_sharing_bluetooth_allow_write_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	update_ui ();
+}
+
+static void
+file_sharing_bluetooth_require_pairing_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	update_ui ();
+}
+
+static void
+file_sharing_bluetooth_obexpush_enabled_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	update_ui ();
+}
+
+static void
+file_sharing_bluetooth_obexpush_accept_files_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	update_ui ();
+}
+
+static void
+file_sharing_bluetooth_obexpush_notify_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	update_ui ();
+}
+#endif /* HAVE_BLUETOOTH */
+
+static void
+password_combo_changed (GtkComboBox *combo_box)
+{
+    GSettings *settings;<--- Shadow variable
+    guint setting;
+
+    setting = gtk_combo_box_get_active (combo_box);
+
+    settings = g_settings_new (GSETTINGS_SCHEMA) ;
+
+    g_settings_set_string (settings,
+			     FILE_SHARING_REQUIRE_PASSWORD,
+			     password_string_from_setting (setting));
+    g_object_unref (settings);
+}
+
+static void
+launch_share (void)
+{
+	if (!g_spawn_command_line_async (USER_SHARE_PROGRAM, NULL))
+		g_warning ("Unable to start mate-user-share program");
+}
+
+#ifdef HAVE_BLUETOOTH
+static void
+enable_bluetooth_check_toggled (GtkWidget *check)
+{
+	GSettings *settings;<--- Shadow variable
+	gboolean enabled;
+
+	enabled = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check));
+
+	settings = g_settings_new (GSETTINGS_SCHEMA) ;
+
+	g_settings_set_boolean (settings,
+			       FILE_SHARING_BLUETOOTH_ENABLED,
+			       enabled);
+
+	g_object_unref (settings);
+
+	if (enabled != FALSE)
+		launch_share ();
+}
+#endif /* HAVE_BLUETOOTH */
+
+static void
+enable_check_toggled (GtkWidget *check)
+{
+	GSettings *settings;<--- Shadow variable
+	gboolean enabled;
+
+	enabled = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check));
+
+	settings = g_settings_new (GSETTINGS_SCHEMA);
+
+	g_settings_set_boolean (settings,
+			       FILE_SHARING_ENABLED,
+			       enabled);
+
+	g_object_unref (settings);
+
+	if (enabled != FALSE)
+		launch_share ();
+}
+
+static void
+password_entry_changed (GtkEditable *editable)
+{
+	g_object_set_data (G_OBJECT (editable),
+			   "user_edited", GINT_TO_POINTER (1));
+	flush_password ();
+}
+
+#ifdef HAVE_BLUETOOTH
+static void
+bluetooth_allow_write_check_toggled (GtkWidget *check)
+{
+	GSettings *settings;<--- Shadow variable
+	gboolean enabled;
+
+	enabled = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check));
+
+	settings = g_settings_new (GSETTINGS_SCHEMA) ;
+
+	g_settings_set_boolean (settings,
+			       FILE_SHARING_BLUETOOTH_ALLOW_WRITE,
+			       enabled);
+
+	g_object_unref (settings);
+}
+
+static void
+bluetooth_require_pairing_check_toggled (GtkWidget *check)
+{
+	GSettings *settings;<--- Shadow variable
+	gboolean enabled;
+
+	enabled = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check));
+
+	settings = g_settings_new (GSETTINGS_SCHEMA) ;
+
+	g_settings_set_boolean (settings,
+			       FILE_SHARING_BLUETOOTH_REQUIRE_PAIRING,
+			       enabled);
+
+	g_object_unref (settings);
+}
+
+static void
+enable_obexpush_check_toggled (GtkWidget *check)
+{
+	GSettings *settings;<--- Shadow variable
+	gboolean enabled;
+
+	enabled = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check));
+
+	settings = g_settings_new (GSETTINGS_SCHEMA) ;
+
+	g_settings_set_boolean (settings,
+			       FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED,
+			       enabled);
+
+	g_object_unref (settings);
+
+	if (enabled != FALSE)
+		launch_share ();
+}
+
+static void
+accept_obexpush_combo_changed (GtkComboBox *combo_box)
+{
+    GSettings *settings;<--- Shadow variable
+    guint setting;
+
+    setting = gtk_combo_box_get_active (combo_box);
+
+    settings = g_settings_new (GSETTINGS_SCHEMA) ;
+
+    g_settings_set_string (settings,
+			     FILE_SHARING_BLUETOOTH_OBEXPUSH_ACCEPT_FILES,
+			     accept_string_from_setting (setting));
+    g_object_unref (settings);
+}
+
+static void
+notify_received_obexpush_check_toggled (GtkWidget *check)
+{
+	GSettings *settings;<--- Shadow variable
+	gboolean enabled;
+
+	enabled = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check));
+
+	settings = g_settings_new (GSETTINGS_SCHEMA) ;
+
+	g_settings_set_boolean (settings,
+			       FILE_SHARING_BLUETOOTH_OBEXPUSH_NOTIFY,
+			       enabled);
+
+	g_object_unref (settings);
+}
+#endif /* HAVE_BLUETOOTH */
+
+static GtkWidget *
+error_dialog (const char *title,
+	      const char *reason,
+	      GtkWindow *parent)
+{
+	GtkWidget *error_dialog;
+
+	if (reason == NULL)
+		reason = _("No reason");
+
+	error_dialog =
+		gtk_message_dialog_new (parent,
+					GTK_DIALOG_MODAL,
+					GTK_MESSAGE_ERROR,
+					GTK_BUTTONS_OK,
+					"%s", title);
+	gtk_message_dialog_format_secondary_text
+		(GTK_MESSAGE_DIALOG (error_dialog), "%s", reason);
+
+	gtk_window_set_title (GTK_WINDOW (error_dialog), ""); /* as per HIG */
+	gtk_container_set_border_width (GTK_CONTAINER (error_dialog), 5);
+	gtk_dialog_set_default_response (GTK_DIALOG (error_dialog),
+					 GTK_RESPONSE_OK);
+	gtk_window_set_modal (GTK_WINDOW (error_dialog), TRUE);
+
+	return error_dialog;
+}
+
+static void
+help_button_clicked (GtkButton *button, GtkWidget *window)
+{
+	GError *error = NULL;
+
+	if (gtk_show_uri_on_window (GTK_WINDOW (window), "help:mate-user-share", gtk_get_current_event_time (), &error) == FALSE) {
+		GtkWidget *dialog;
+
+		dialog = error_dialog (_("Could not display the help contents."), error->message, GTK_WINDOW (window));
+		g_signal_connect (G_OBJECT (dialog), "response", G_CALLBACK
+				  (gtk_widget_destroy), error_dialog);
+		gtk_window_present (GTK_WINDOW (dialog));
+
+		g_error_free (error);
+	}
+}
+
+static GtkWidget *
+create_window (void)
+{
+    GError *error = NULL;
+    GSettings *settings;<--- Shadow variable
+    GtkWidget *check;
+    GtkWidget *password_combo;
+    GtkWidget *password_entry;
+#ifdef HAVE_BLUETOOTH
+    GtkWidget *bluetooth_check;
+    GtkWidget *bluetooth_allow_write_check;
+    GtkWidget *require_pairing_check;
+    GtkWidget *enable_obexpush_check;
+    GtkWidget *accept_obexpush_combo;
+    GtkWidget *notify_received_obexpush_check;
+#endif /* HAVE_BLUETOOTH */
+    GtkWidget *window;
+    GtkListStore *store;
+    GtkCellRenderer *cell;
+    GtkTreeIter iter;
+
+    builder = gtk_builder_new ();
+    gtk_builder_add_from_file (builder, DATADIR"file-share-properties.ui", &error);
+
+    if (error) {
+      GtkWidget *dialog;
+
+      dialog = error_dialog (_("Could not build interface."), error->message, NULL);
+      gtk_dialog_run (GTK_DIALOG (dialog));
+      gtk_widget_destroy (dialog);
+
+      g_error_free (error);
+      return NULL;
+    }
+
+    window = GTK_WIDGET (gtk_builder_get_object (builder, "user_share_dialog"));
+
+    settings = g_settings_new (GSETTINGS_SCHEMA);
+
+    check = GTK_WIDGET (gtk_builder_get_object (builder, "enable_check"));
+    password_combo = GTK_WIDGET (gtk_builder_get_object (builder, "password_combo"));
+    password_entry = GTK_WIDGET (gtk_builder_get_object (builder, "password_entry"));
+#ifdef HAVE_BLUETOOTH
+    bluetooth_check = GTK_WIDGET (gtk_builder_get_object (builder, "enable_bluetooth_check"));
+    bluetooth_allow_write_check = GTK_WIDGET (gtk_builder_get_object (builder, "allow_write_bluetooth_check"));
+    require_pairing_check = GTK_WIDGET (gtk_builder_get_object (builder, "require_pairing_check"));
+    enable_obexpush_check = GTK_WIDGET (gtk_builder_get_object (builder, "enable_obexpush_check"));
+    accept_obexpush_combo = GTK_WIDGET (gtk_builder_get_object (builder, "accept_obexpush_combo"));
+    notify_received_obexpush_check = GTK_WIDGET (gtk_builder_get_object (builder, "notify_received_obexpush_check"));
+#endif /* HAVE_BLUETOOTH */
+
+    store = gtk_list_store_new (1, G_TYPE_STRING);
+    gtk_combo_box_set_model (GTK_COMBO_BOX (password_combo),
+			     GTK_TREE_MODEL (store));
+    cell = gtk_cell_renderer_text_new ();
+    gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (password_combo), cell, TRUE);
+    gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (password_combo), cell,
+				    "text", 0,
+				    NULL);
+
+    /* Keep in same order as enum */
+    gtk_list_store_append (store, &iter);
+    gtk_list_store_set (store, &iter, 0,
+			_("Never"), -1);
+    gtk_list_store_append (store, &iter);
+    gtk_list_store_set (store, &iter, 0,
+			_("When writing files"), -1);
+    gtk_list_store_append (store, &iter);
+    gtk_list_store_set (store, &iter, 0,
+			_("Always"), -1);
+    g_object_unref (store);
+
+    /* We can't read the password from the text, just set it to something */
+    gtk_entry_set_text (GTK_ENTRY (password_entry), "none");
+    g_object_set_data (G_OBJECT (password_entry),
+		       "user_edited", GINT_TO_POINTER (0));
+    g_signal_connect (password_entry,
+		      "changed", G_CALLBACK (password_entry_changed), NULL);
+
+#ifdef HAVE_BLUETOOTH
+    /* Accept files combo */
+    store = gtk_list_store_new (1, G_TYPE_STRING);
+    gtk_combo_box_set_model (GTK_COMBO_BOX (accept_obexpush_combo),
+			     GTK_TREE_MODEL (store));
+    cell = gtk_cell_renderer_text_new ();
+    gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (accept_obexpush_combo), cell, TRUE);
+    gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (accept_obexpush_combo), cell,
+				    "text", 0,
+				    NULL);
+
+    /* Keep in same order as enum */
+    gtk_list_store_append (store, &iter);
+    gtk_list_store_set (store, &iter, 0,
+			_("Always"), -1);
+    gtk_list_store_append (store, &iter);
+    gtk_list_store_set (store, &iter, 0,
+			_("Only for set up devices"), -1);
+    //FIXME implement
+#if 0
+    gtk_list_store_append (store, &iter);
+    gtk_list_store_set (store, &iter, 0,
+    			_("Ask"), -1);
+#endif
+    g_object_unref (store);
+#endif /* HAVE_BLUETOOTH */
+
+    g_signal_connect (check,
+		      "toggled", G_CALLBACK (enable_check_toggled), NULL);
+    g_signal_connect (password_combo,
+		      "changed", G_CALLBACK (password_combo_changed), NULL);
+#ifdef HAVE_BLUETOOTH
+    g_signal_connect (bluetooth_check,
+    		      "toggled", G_CALLBACK (enable_bluetooth_check_toggled), NULL);
+    g_signal_connect (bluetooth_allow_write_check,
+    		      "toggled", G_CALLBACK (bluetooth_allow_write_check_toggled), NULL);
+    g_signal_connect (require_pairing_check,
+    		      "toggled", G_CALLBACK (bluetooth_require_pairing_check_toggled), NULL);
+    g_signal_connect (enable_obexpush_check,
+    		      "toggled", G_CALLBACK (enable_obexpush_check_toggled), NULL);
+    g_signal_connect (accept_obexpush_combo,
+    		      "changed", G_CALLBACK (accept_obexpush_combo_changed), NULL);
+    g_signal_connect (notify_received_obexpush_check,
+    		      "toggled", G_CALLBACK (notify_received_obexpush_check_toggled), NULL);
+#endif /* HAVE_BLUETOOTH */
+
+    g_signal_connect_swapped (GTK_WIDGET (gtk_builder_get_object (builder, "close_button")),
+                              "clicked", G_CALLBACK (gtk_widget_destroy), window);
+    g_signal_connect (GTK_WIDGET (gtk_builder_get_object (builder, "help_button")),
+		      "clicked", G_CALLBACK (help_button_clicked),
+		      gtk_builder_get_object (builder, "user_share_dialog"));
+
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_ENABLED,
+			     G_CALLBACK (file_sharing_enabled_changed), NULL);
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_REQUIRE_PASSWORD,
+			     G_CALLBACK (password_required_changed), NULL);
+#ifdef HAVE_BLUETOOTH
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_ENABLED,
+			     G_CALLBACK (file_sharing_bluetooth_enabled_changed), NULL);
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_ALLOW_WRITE,
+			     G_CALLBACK (file_sharing_bluetooth_allow_write_changed), NULL);
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_REQUIRE_PAIRING,
+			     G_CALLBACK (file_sharing_bluetooth_require_pairing_changed), NULL);
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED,
+			     G_CALLBACK (file_sharing_bluetooth_obexpush_enabled_changed), NULL);
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_ACCEPT_FILES,
+			     G_CALLBACK (file_sharing_bluetooth_obexpush_accept_files_changed), NULL);
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_NOTIFY,
+			     G_CALLBACK (file_sharing_bluetooth_obexpush_notify_changed), NULL);
+#endif /* HAVE_BLUETOOTH */
+
+    update_ui ();
+
+    return window;
+}
+
+static void
+activate (GtkApplication *app)
+{
+    GList *list;
+    GtkWidget *window;
+
+    list = gtk_application_get_windows (app);
+
+    if (list) {
+        gtk_window_present (GTK_WINDOW (list->data));
+    } else {
+        window = create_window ();
+        gtk_window_set_application (GTK_WINDOW (window), app);
+        gtk_widget_show (window);
+    }
+}
+
+int
+main (int argc, char *argv[])
+{
+    GtkApplication *app;
+    gint status;
+
+    bindtextdomain (GETTEXT_PACKAGE, MATELOCALEDIR);
+    bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
+    textdomain (GETTEXT_PACKAGE);
+
+    app = gtk_application_new ("org.mate.user-share.properties",
+                               G_APPLICATION_FLAGS_NONE);
+    g_signal_connect (app, "activate", G_CALLBACK (activate), NULL);
+
+    status = g_application_run (G_APPLICATION (app), argc, argv);
+
+    g_object_unref (app);
+
+    return status;
+}
+
+
+
+
+ + + diff --git a/2021-04-25-143339-9886-cppcheck@cf2a18e177f2_master/1.html b/2021-04-25-143339-9886-cppcheck@cf2a18e177f2_master/1.html new file mode 100644 index 0000000..cec50f3 --- /dev/null +++ b/2021-04-25-143339-9886-cppcheck@cf2a18e177f2_master/1.html @@ -0,0 +1,1054 @@ + + + + + + Cppcheck - HTML report - mate-user-share + + + + + + +
+ +
+
  1
+  2
+  3
+  4
+  5
+  6
+  7
+  8
+  9
+ 10
+ 11
+ 12
+ 13
+ 14
+ 15
+ 16
+ 17
+ 18
+ 19
+ 20
+ 21
+ 22
+ 23
+ 24
+ 25
+ 26
+ 27
+ 28
+ 29
+ 30
+ 31
+ 32
+ 33
+ 34
+ 35
+ 36
+ 37
+ 38
+ 39
+ 40
+ 41
+ 42
+ 43
+ 44
+ 45
+ 46
+ 47
+ 48
+ 49
+ 50
+ 51
+ 52
+ 53
+ 54
+ 55
+ 56
+ 57
+ 58
+ 59
+ 60
+ 61
+ 62
+ 63
+ 64
+ 65
+ 66
+ 67
+ 68
+ 69
+ 70
+ 71
+ 72
+ 73
+ 74
+ 75
+ 76
+ 77
+ 78
+ 79
+ 80
+ 81
+ 82
+ 83
+ 84
+ 85
+ 86
+ 87
+ 88
+ 89
+ 90
+ 91
+ 92
+ 93
+ 94
+ 95
+ 96
+ 97
+ 98
+ 99
+100
+101
+102
+103
+104
+105
+106
+107
+108
+109
+110
+111
+112
+113
+114
+115
+116
+117
+118
+119
+120
+121
+122
+123
+124
+125
+126
+127
+128
+129
+130
+131
+132
+133
+134
+135
+136
+137
+138
+139
+140
+141
+142
+143
+144
+145
+146
+147
+148
+149
+150
+151
+152
+153
+154
+155
+156
+157
+158
+159
+160
+161
+162
+163
+164
+165
+166
+167
+168
+169
+170
+171
+172
+173
+174
+175
+176
+177
+178
+179
+180
+181
+182
+183
+184
+185
+186
+187
+188
+189
+190
+191
+192
+193
+194
+195
+196
+197
+198
+199
+200
+201
+202
+203
+204
+205
+206
+207
+208
+209
+210
+211
+212
+213
+214
+215
+216
+217
+218
+219
+220
+221
+222
+223
+224
+225
+226
+227
+228
+229
+230
+231
+232
+233
+234
+235
+236
+237
+238
+239
+240
+241
+242
+243
+244
+245
+246
+247
+248
+249
+250
+251
+252
+253
+254
+255
+256
+257
+258
+259
+260
+261
+262
+263
+264
+265
+266
+267
+268
+269
+270
+271
+272
+273
+274
+275
+276
+277
+278
+279
+280
+281
+282
+283
+284
+285
+286
+287
+288
+289
+290
+291
+292
+293
+294
+295
+296
+297
+298
+299
+300
+301
+302
+303
+304
+305
+306
+307
+308
+309
+310
+311
+312
+313
+314
+315
+316
+317
+318
+319
+320
+321
+322
+323
+324
+325
+326
+327
+328
+329
+330
+331
+332
+333
+334
+335
+336
+337
+338
+339
+340
+341
+342
+343
+344
+345
+346
+347
+348
+349
+350
+351
+352
+353
+354
+355
+356
+357
+358
+359
+360
+361
+362
+363
+364
+365
+366
+367
+368
+369
+370
+371
+372
+373
+374
+375
+376
+377
+378
+379
+380
+381
+382
+383
+384
+385
+386
+387
+388
+389
+390
+391
+392
+393
+394
+395
+396
+397
+398
+399
+400
+401
+402
+403
+404
+405
+406
+407
+408
+409
+410
+411
+412
+413
+414
+415
+416
+417
+418
+419
+420
+421
+422
+423
+424
+425
+426
+427
+428
+429
+430
+431
+432
+433
+434
+435
+436
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
+
+/*
+ *  Copyright (C) 2004-2008 Red Hat, Inc.
+ *
+ *  Caja is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU General Public License as
+ *  published by the Free Software Foundation; either version 2 of the
+ *  License, or (at your option) any later version.
+ *
+ *  Caja is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  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
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ *  Authors: Alexander Larsson <alexl@redhat.com>
+ *
+ */
+
+#include "config.h"
+
+#include <glib.h>
+#include <glib/gi18n.h>
+#include <X11/Xlib.h>
+
+#include <gio/gio.h>
+
+#include <stdarg.h>
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <signal.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <sys/stat.h>
+
+#ifdef HAVE_SELINUX
+#include <selinux/selinux.h>
+#endif
+
+#include "user_share-common.h"
+#include "user_share-private.h"
+#include "http.h"
+
+/* From avahi-common/domain.h */
+#define AVAHI_LABEL_MAX 64
+
+#define GSETTINGS_SCHEMA "org.mate.FileSharing"
+
+static pid_t httpd_pid = 0;
+
+static int
+get_port (void)
+{
+	int sock;
+	struct sockaddr_in addr;
+	int reuse;
+	socklen_t len;
+
+	sock = socket (PF_INET, SOCK_STREAM, 0);
+	if (sock < 0) {
+		return -1;
+	}
+
+	memset (&addr, 0, sizeof (addr));
+	addr.sin_port = 0;
+	addr.sin_addr.s_addr = INADDR_ANY;
+	addr.sin_family = AF_INET;
+
+	reuse = 1;
+	setsockopt (sock, SOL_SOCKET, SO_REUSEADDR, &reuse, sizeof (reuse));
+	if (bind (sock, (struct sockaddr *)&addr, sizeof (addr)) == -1) {
+		close (sock);
+		return -1;
+	}
+
+	len = sizeof (addr);
+	if (getsockname (sock, (struct sockaddr *)&addr, &len) == -1) {
+		close (sock);
+		return -1;
+	}
+
+#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__APPLE__) || defined(__OpenBSD__)
+	/* XXX This exposes a potential race condition, but without this,
+	 * httpd will not start on the above listed platforms due to the fact
+	 * that SO_REUSEADDR is also needed when Apache binds to the listening
+	 * socket.  At this time, Apache does not support that socket option.
+	 */
+	close (sock);
+#endif
+	return ntohs (addr.sin_port);
+}
+
+static char *
+truncate_name (const char *name)
+{
+	const char *end;
+
+	end = g_utf8_find_prev_char (name, name + 64);
+	g_assert (end != NULL);
+	return g_strndup (name, end - name);
+}
+
+static char *
+get_share_name (void)
+{
+	static char *name = NULL;
+	const char *host_name;
+	char *str;
+
+	if (name == NULL) {
+		host_name = g_get_host_name ();
+		if (strcmp (host_name, "localhost") == 0) {
+			/* Translators: The %s will get filled in with the user name
+			   of the user, to form a genitive. If this is difficult to
+			   translate correctly so that it will work correctly in your
+			   language, you may use something equivalent to
+			   "Public files of %s", or leave out the %s altogether.
+			   In the latter case, please put "%.0s" somewhere in the string,
+			   which will match the user name string passed by the C code,
+			   but not put the user name in the final string. This is to
+			   avoid the warning that msgfmt might otherwise generate. */
+			name = g_strdup_printf (_("%s's public files"), g_get_user_name ());
+		} else {
+			/* Translators: This is similar to the string before, only it
+			   has the hostname in it too. */
+			name = g_strdup_printf (_("%s's public files on %s"),
+						g_get_user_name (),
+						host_name);
+		}
+
+	}
+	/* And truncate */
+	if (strlen (name) < AVAHI_LABEL_MAX)
+		return name;
+
+	str = truncate_name (name);
+	g_free (name);
+	name = str;
+
+	return name;
+}
+
+static void
+ensure_conf_dir (void)
+{
+	char *dirname;
+
+	dirname = g_build_filename (g_get_user_config_dir (), "user-share", NULL);
+	g_mkdir_with_parents (dirname, 0755);
+	g_free (dirname);
+}
+
+static void
+httpd_child_setup (gpointer user_data)
+{
+#ifdef HAVE_SELINUX
+	char *mycon;
+	/* If selinux is enabled, avoid transitioning to the httpd_t context,
+	   as this normally means you can't read the users homedir. */
+	if (is_selinux_enabled()) {
+		if (getcon (&mycon) < 0) {
+			abort ();
+		}
+		if (setexeccon (mycon) < 0)
+			abort ();
+		freecon (mycon);
+	}
+#endif
+}
+
+static const char *known_httpd_locations [] = {
+	HTTPD_PROGRAM,
+	"/usr/sbin/httpd",
+	"/usr/sbin/httpd2",
+	"/usr/sbin/apache2",
+	NULL
+};
+
+static char*
+get_httpd_program (void)
+{
+	int i;
+
+	for (i = 0; known_httpd_locations[i]; i++) {
+		if (known_httpd_locations[i][0] == '\0') {
+			/* empty string as first element, happens when
+			 * configured --with-httpd=auto */
+			continue;
+		}
+		if (g_file_test (known_httpd_locations[i], G_FILE_TEST_IS_EXECUTABLE)
+				&& ! g_file_test (known_httpd_locations[i], G_FILE_TEST_IS_DIR)) {
+			return g_strdup (known_httpd_locations[i]);
+		}
+	}
+	return NULL;
+}
+
+static const char *known_httpd_modules_locations [] = {
+	HTTPD_MODULES_PATH,
+	"/etc/httpd/modules",
+	"/usr/lib/apache2/modules",
+	NULL
+};
+
+static gchar*
+get_httpd_modules_path (void)
+{
+	int i;
+
+	for (i = 0; known_httpd_modules_locations[i]; i++) {
+		if (known_httpd_modules_locations[i][0] == '\0') {
+			/* empty string as first element, happens when
+			 * configured --with-httpd=auto */
+			continue;
+		}
+		if (g_file_test (known_httpd_modules_locations[i], G_FILE_TEST_IS_EXECUTABLE)
+				&& g_file_test (known_httpd_modules_locations[i], G_FILE_TEST_IS_DIR)) {
+			return g_strdup (known_httpd_modules_locations[i]);
+		}
+	}
+	return NULL;
+}
+
+static GRegex *version_regex = NULL;
+
+static char*
+get_httpd_config (const char *httpd_program)
+{
+	gchar *standard_output;
+	gchar *cmd_line;
+	GMatchInfo *match_info;
+	gchar *version_number = NULL;
+	gchar *config;
+
+	cmd_line = g_strdup_printf ("%s -v", httpd_program);
+	if (! g_spawn_command_line_sync (cmd_line, &standard_output, NULL, NULL, NULL)) {
+		g_free (cmd_line);
+		return NULL;
+	}
+	g_free (cmd_line);
+
+	if (version_regex == NULL) {
+		version_regex = g_regex_new ("\\d\\.\\d", 0, 0, NULL);
+	}
+
+	if (g_regex_match (version_regex, standard_output, 0, &match_info)) {
+		while (g_match_info_matches (match_info)) {
+			version_number = g_match_info_fetch (match_info, 0);
+			break;
+		}
+		g_match_info_free (match_info);
+		g_free (standard_output);
+	} else {
+		/* Failed to parse httpd version number */
+		g_warning ("Could not parse '%s' as a version for httpd", standard_output);
+		g_free (standard_output);
+		/* assume it is 2.2 */
+		version_number = g_strdup ("2.2");
+	}
+
+	config = g_strdup_printf (HTTPD_CONFIG_TEMPLATE, version_number);
+	g_free (version_number);
+
+	return config;
+}
+
+static gboolean
+spawn_httpd (int port, pid_t *pid_out)
+{
+	char *free1, *free2, *free3, *free4, *free5, *free6, *free7, *free8, *free9;
+	gboolean res;
+	char *argv[10];
+	char *env[10];
+	int i;
+	gint status;
+	char *pid_filename;
+	char *pidfile;
+	GError *error;
+	gboolean got_pidfile;
+	GSettings *settings;
+	char *str;
+	char *public_dir;
+
+	public_dir = lookup_public_dir ();
+	ensure_conf_dir ();
+
+	i = 0;
+	free1 = argv[i++] = get_httpd_program ();
+	if (argv[0] == NULL) {
+		fprintf (stderr, "error finding httpd server\n");
+		return FALSE;
+	}
+
+	argv[i++] = "-f";
+	free2 = argv[i++] = get_httpd_config (argv[0]);
+	argv[i++] = "-C";
+	free3 = argv[i++] = g_strdup_printf ("Listen %d", port);
+
+	settings = g_settings_new (GSETTINGS_SCHEMA);
+	str = g_settings_get_string (settings,
+				       FILE_SHARING_REQUIRE_PASSWORD);
+
+	if (str && strcmp (str, "never") == 0) {
+		/* Do nothing */
+	} else if (str && strcmp (str, "on_write") == 0){
+		argv[i++] = "-D";
+		argv[i++] = "RequirePasswordOnWrite";
+	} else {
+		/* always, or safe fallback */
+		argv[i++] = "-D";
+		argv[i++] = "RequirePasswordAlways";
+	}
+	g_free (str);
+	g_object_unref (settings);
+
+	argv[i] = NULL;
+
+	i = 0;
+	free4 = env[i++] = g_strdup_printf ("HOME=%s", g_get_home_dir());
+	free5 = env[i++] = g_strdup_printf ("XDG_PUBLICSHARE_DIR=%s", public_dir);
+	free6 = env[i++] = g_strdup_printf ("XDG_CONFIG_HOME=%s", g_get_user_config_dir ());
+	free7 = env[i++] = g_strdup_printf ("GUS_SHARE_NAME=%s", get_share_name ());
+	free8 = env[i++] = g_strdup_printf ("GUS_LOGIN_LABEL=%s", "Please log in as the user guest");
+	free9 = env[i++] = g_strdup_printf ("HTTP_MODULES_PATH=%s",get_httpd_modules_path ());
+	env[i++] = "LANG=C";
+	env[i] = NULL;
+
+	pid_filename = g_build_filename (g_get_user_config_dir (), "user-share", "pid", NULL);
+
+	/* Remove pid file before spawning to avoid races with child and old pidfile */
+	unlink (pid_filename);
+
+	error = NULL;
+	res = g_spawn_sync (g_get_home_dir(),
+			    argv, env, 0,
+			    httpd_child_setup, NULL,
+			    NULL, NULL,
+			    &status,
+			    &error);
+	g_free (free1);
+	g_free (free2);
+	g_free (free3);
+	g_free (free4);
+	g_free (free5);
+	g_free (free6);
+	g_free (free7);
+	g_free (free8);
+	g_free (free9);
+	g_free (public_dir);
+
+	if (!res) {
+		fprintf (stderr, "error spawning httpd: %s\n",
+			 error->message);
+		g_error_free (error);
+		g_free (pid_filename);
+		return FALSE;
+	}
+
+	if (status != 0) {
+		g_free (pid_filename);
+		return FALSE;
+	}
+
+	got_pidfile = FALSE;
+	error = NULL;
+	for (i = 0; i < 5; i++) {
+		if (error != NULL)
+			g_error_free (error);
+		error = NULL;
+		if (g_file_get_contents (pid_filename, &pidfile, NULL, &error)) {
+			got_pidfile = TRUE;
+			*pid_out = atoi (pidfile);
+			g_free (pidfile);
+			break;
+		}
+		sleep (1);
+	}
+
+	g_free (pid_filename);
+
+	if (!got_pidfile) {
+		fprintf (stderr, "error opening httpd pidfile: %s\n", error->message);
+		g_error_free (error);
+		return FALSE;
+	}
+	return TRUE;
+}
+
+static void
+kill_httpd (void)
+{
+	if (httpd_pid != 0) {
+		kill (httpd_pid, SIGTERM);
+
+		/* Allow child time to die, we can't waitpid, because its
+		   not a direct child */
+		sleep (1);
+	}
+	httpd_pid = 0;
+}
+
+void
+http_up (void)
+{
+	guint port;
+
+	port = get_port ();
+	if (!spawn_httpd (port, &httpd_pid)) {
+		fprintf (stderr, "spawning httpd failed\n");
+	}
+}
+
+void
+http_down (void)
+{
+	kill_httpd ();
+}
+
+gboolean
+http_init (void)
+{
+	return TRUE;
+}
+
+pid_t
+http_get_pid (void)
+{
+	return httpd_pid;
+}
+
+
+
+
+ + + diff --git a/2021-04-25-143339-9886-cppcheck@cf2a18e177f2_master/2.html b/2021-04-25-143339-9886-cppcheck@cf2a18e177f2_master/2.html new file mode 100644 index 0000000..c95a0b0 --- /dev/null +++ b/2021-04-25-143339-9886-cppcheck@cf2a18e177f2_master/2.html @@ -0,0 +1,1288 @@ + + + + + + Cppcheck - HTML report - mate-user-share + + + + + + +
+ +
+
  1
+  2
+  3
+  4
+  5
+  6
+  7
+  8
+  9
+ 10
+ 11
+ 12
+ 13
+ 14
+ 15
+ 16
+ 17
+ 18
+ 19
+ 20
+ 21
+ 22
+ 23
+ 24
+ 25
+ 26
+ 27
+ 28
+ 29
+ 30
+ 31
+ 32
+ 33
+ 34
+ 35
+ 36
+ 37
+ 38
+ 39
+ 40
+ 41
+ 42
+ 43
+ 44
+ 45
+ 46
+ 47
+ 48
+ 49
+ 50
+ 51
+ 52
+ 53
+ 54
+ 55
+ 56
+ 57
+ 58
+ 59
+ 60
+ 61
+ 62
+ 63
+ 64
+ 65
+ 66
+ 67
+ 68
+ 69
+ 70
+ 71
+ 72
+ 73
+ 74
+ 75
+ 76
+ 77
+ 78
+ 79
+ 80
+ 81
+ 82
+ 83
+ 84
+ 85
+ 86
+ 87
+ 88
+ 89
+ 90
+ 91
+ 92
+ 93
+ 94
+ 95
+ 96
+ 97
+ 98
+ 99
+100
+101
+102
+103
+104
+105
+106
+107
+108
+109
+110
+111
+112
+113
+114
+115
+116
+117
+118
+119
+120
+121
+122
+123
+124
+125
+126
+127
+128
+129
+130
+131
+132
+133
+134
+135
+136
+137
+138
+139
+140
+141
+142
+143
+144
+145
+146
+147
+148
+149
+150
+151
+152
+153
+154
+155
+156
+157
+158
+159
+160
+161
+162
+163
+164
+165
+166
+167
+168
+169
+170
+171
+172
+173
+174
+175
+176
+177
+178
+179
+180
+181
+182
+183
+184
+185
+186
+187
+188
+189
+190
+191
+192
+193
+194
+195
+196
+197
+198
+199
+200
+201
+202
+203
+204
+205
+206
+207
+208
+209
+210
+211
+212
+213
+214
+215
+216
+217
+218
+219
+220
+221
+222
+223
+224
+225
+226
+227
+228
+229
+230
+231
+232
+233
+234
+235
+236
+237
+238
+239
+240
+241
+242
+243
+244
+245
+246
+247
+248
+249
+250
+251
+252
+253
+254
+255
+256
+257
+258
+259
+260
+261
+262
+263
+264
+265
+266
+267
+268
+269
+270
+271
+272
+273
+274
+275
+276
+277
+278
+279
+280
+281
+282
+283
+284
+285
+286
+287
+288
+289
+290
+291
+292
+293
+294
+295
+296
+297
+298
+299
+300
+301
+302
+303
+304
+305
+306
+307
+308
+309
+310
+311
+312
+313
+314
+315
+316
+317
+318
+319
+320
+321
+322
+323
+324
+325
+326
+327
+328
+329
+330
+331
+332
+333
+334
+335
+336
+337
+338
+339
+340
+341
+342
+343
+344
+345
+346
+347
+348
+349
+350
+351
+352
+353
+354
+355
+356
+357
+358
+359
+360
+361
+362
+363
+364
+365
+366
+367
+368
+369
+370
+371
+372
+373
+374
+375
+376
+377
+378
+379
+380
+381
+382
+383
+384
+385
+386
+387
+388
+389
+390
+391
+392
+393
+394
+395
+396
+397
+398
+399
+400
+401
+402
+403
+404
+405
+406
+407
+408
+409
+410
+411
+412
+413
+414
+415
+416
+417
+418
+419
+420
+421
+422
+423
+424
+425
+426
+427
+428
+429
+430
+431
+432
+433
+434
+435
+436
+437
+438
+439
+440
+441
+442
+443
+444
+445
+446
+447
+448
+449
+450
+451
+452
+453
+454
+455
+456
+457
+458
+459
+460
+461
+462
+463
+464
+465
+466
+467
+468
+469
+470
+471
+472
+473
+474
+475
+476
+477
+478
+479
+480
+481
+482
+483
+484
+485
+486
+487
+488
+489
+490
+491
+492
+493
+494
+495
+496
+497
+498
+499
+500
+501
+502
+503
+504
+505
+506
+507
+508
+509
+510
+511
+512
+513
+514
+515
+516
+517
+518
+519
+520
+521
+522
+523
+524
+525
+526
+527
+528
+529
+530
+531
+532
+533
+534
+535
+536
+537
+538
+539
+540
+541
+542
+543
+544
+545
+546
+547
+548
+549
+550
+551
+552
+553
+554
+555
+556
+557
+558
+559
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
+
+/*
+ *  Copyright (C) 2004-2008 Red Hat, Inc.
+ *
+ *  Caja is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU General Public License as
+ *  published by the Free Software Foundation; either version 2 of the
+ *  License, or (at your option) any later version.
+ *
+ *  Caja is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  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
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ *  Authors: Bastien Nocera <hadess@hadess.net>
+ *
+ */
+
+#include "config.h"
+
+#include <glib.h>
+#include <glib/gi18n.h>
+#include <gio/gio.h>
+#include <gdk/gdk.h>
+#include <gtk/gtk.h>
+#include <libnotify/notify.h>
+#include <dbus/dbus-glib.h>
+#include <dbus/dbus-glib-lowlevel.h>
+#include <canberra-gtk.h>
+
+#include <string.h>
+
+#include "marshal.h"
+#include "obexpush.h"
+#include "user_share-common.h"
+#include "user_share-private.h"
+
+#define DBUS_TYPE_G_STRING_VARIANT_HASHTABLE (dbus_g_type_get_map ("GHashTable", G_TYPE_STRING, G_TYPE_STRING))
+
+#define GSETTINGS_SCHEMA "org.mate.FileSharing"
+
+static DBusGConnection *connection = NULL;<--- Shadowed declaration
+static DBusGProxy *manager_proxy = NULL;
+static DBusGProxy *server_proxy = NULL;
+static AcceptSetting accept_setting = -1;
+static gboolean show_notifications = FALSE;
+
+static GtkStatusIcon *statusicon = NULL;
+static guint num_notifications = 0;
+
+static void
+hide_statusicon (void)
+{
+	num_notifications--;
+	if (num_notifications == 0)
+		gtk_status_icon_set_visible (statusicon, FALSE);
+}
+
+static void
+on_close_notification (NotifyNotification *notification)
+{
+	hide_statusicon ();
+	g_object_unref (notification);
+}
+
+static void
+notification_launch_action_on_file_cb (NotifyNotification *notification,
+				       const char *action,
+				       const char *file_uri)
+{
+	GdkScreen *screen;
+	GAppLaunchContext *ctx;
+	GTimeVal val;
+
+	g_assert (action != NULL);
+
+	g_get_current_time (&val);
+
+	ctx = G_APP_LAUNCH_CONTEXT (gdk_app_launch_context_new ());
+	screen = gdk_screen_get_default ();
+	gdk_app_launch_context_set_screen (GDK_APP_LAUNCH_CONTEXT (ctx), screen);
+	gdk_app_launch_context_set_timestamp (GDK_APP_LAUNCH_CONTEXT (ctx), val.tv_sec);
+
+	/* We launch the file viewer for the file */
+	if (g_str_equal (action, "display") != FALSE) {
+		if (g_app_info_launch_default_for_uri (file_uri, ctx, NULL) == FALSE) {
+			g_warning ("Failed to launch the file viewer\n");
+		}
+	}
+
+	/* we open the Downloads folder */
+	if (g_str_equal (action, "reveal") != FALSE) {
+		GFile *file;
+		GFile *parent;
+		gchar *parent_uri;
+
+		file = g_file_new_for_uri (file_uri);
+		parent = g_file_get_parent (file);
+		parent_uri = g_file_get_uri (parent);
+		g_object_unref (file);
+		g_object_unref (parent);
+
+		if (!g_app_info_launch_default_for_uri (parent_uri, ctx, NULL)) {
+			g_warning ("Failed to launch the file manager\n");
+		}
+
+		g_free (parent_uri);
+	}
+
+	notify_notification_close (notification, NULL);
+	/* No need to call hide_statusicon(), closing the notification
+	 * will call the close callback */
+}
+
+static void
+show_notification (const char *filename)
+{
+	char *file_uri, *notification_text, *display, *mime_type;
+	NotifyNotification *notification;
+	ca_context *ctx;
+	GAppInfo *app;
+
+	file_uri = g_filename_to_uri (filename, NULL, NULL);
+	if (file_uri == NULL) {
+		g_warning ("Could not make a filename from '%s'", filename);
+		return;
+	}
+
+	display = g_filename_display_basename (filename);
+	/* Translators: %s is the name of the filename received */
+	notification_text = g_strdup_printf(_("You received \"%s\" via Bluetooth"), display);
+	g_free (display);
+	notification = notify_notification_new (_("You received a file"),
+								 notification_text,
+								 "dialog-information");
+
+	notify_notification_set_timeout (notification, NOTIFY_EXPIRES_DEFAULT);
+
+	mime_type = g_content_type_guess (filename, NULL, 0, NULL);
+	app = g_app_info_get_default_for_type (mime_type, FALSE);
+	if (app != NULL) {
+		g_object_unref (app);
+		notify_notification_add_action (notification, "display", _("Open File"),
+						(NotifyActionCallback) notification_launch_action_on_file_cb,
+						g_strdup (file_uri), (GFreeFunc) g_free);
+	}
+	notify_notification_add_action (notification, "reveal", _("Reveal File"),
+					(NotifyActionCallback) notification_launch_action_on_file_cb,
+					g_strdup (file_uri), (GFreeFunc) g_free);
+
+	g_free (file_uri);
+
+	g_signal_connect (G_OBJECT (notification), "closed", G_CALLBACK (on_close_notification), notification);
+
+	if (!notify_notification_show (notification, NULL)) {
+		g_warning ("failed to send notification\n");
+	}
+	g_free (notification_text);
+
+	/* Now we do the audio notification */
+	ctx = ca_gtk_context_get ();
+	ca_context_play (ctx, 0,
+			 CA_PROP_EVENT_ID, "complete-download",
+			 CA_PROP_EVENT_DESCRIPTION, _("File reception complete"),
+			 NULL);
+}
+
+static void
+show_icon (void)
+{
+	if (statusicon == NULL) {
+		statusicon = gtk_status_icon_new_from_icon_name ("mate-obex-server");
+	} else {
+		gtk_status_icon_set_visible (statusicon, TRUE);
+	}
+	num_notifications++;
+}
+
+static gboolean
+device_is_authorised (const char *bdaddr)
+{
+	DBusGConnection *connection;<--- Shadow variable
+	DBusGProxy *manager;
+	GError *error = NULL;
+	GPtrArray *adapters;
+	gboolean retval = FALSE;
+	guint i;
+
+	connection = dbus_g_bus_get (DBUS_BUS_SYSTEM, NULL);
+	if (connection == NULL)
+		return FALSE;
+
+	manager = dbus_g_proxy_new_for_name (connection, "org.bluez",
+					     "/", "org.bluez.Manager");
+	if (manager == NULL) {
+		dbus_g_connection_unref (connection);
+		return FALSE;
+	}
+
+	if (dbus_g_proxy_call (manager, "ListAdapters", &error, G_TYPE_INVALID, dbus_g_type_get_collection ("GPtrArray", DBUS_TYPE_G_OBJECT_PATH), &adapters, G_TYPE_INVALID) == FALSE) {
+		g_object_unref (manager);
+		dbus_g_connection_unref (connection);
+		return FALSE;
+	}
+
+	for (i = 0; i < adapters->len; i++) {
+		DBusGProxy *adapter, *device;
+		char *device_path;
+		GHashTable *props;
+
+		g_debug ("checking adapter %s", (gchar *) g_ptr_array_index (adapters, i));
+
+		adapter = dbus_g_proxy_new_for_name (connection, "org.bluez",
+						    g_ptr_array_index (adapters, i), "org.bluez.Adapter");
+
+		if (dbus_g_proxy_call (adapter, "FindDevice", NULL,
+				       G_TYPE_STRING, bdaddr, G_TYPE_INVALID,
+				       DBUS_TYPE_G_OBJECT_PATH, &device_path, G_TYPE_INVALID) == FALSE)
+		{
+			g_object_unref (adapter);
+			continue;
+		}
+
+		device = dbus_g_proxy_new_for_name (connection, "org.bluez", device_path, "org.bluez.Device");
+
+		if (dbus_g_proxy_call (device, "GetProperties", NULL,
+				       G_TYPE_INVALID, dbus_g_type_get_map ("GHashTable", G_TYPE_STRING, G_TYPE_VALUE),
+				       &props, G_TYPE_INVALID) != FALSE)
+		{
+			GValue *value;
+			gboolean bonded;
+
+			value = g_hash_table_lookup (props, "Paired");
+			bonded = g_value_get_boolean (value);
+			g_message ("%s is %s", bdaddr, bonded ? "bonded" : "not bonded");
+
+			if (bonded) {
+				g_hash_table_destroy (props);
+				g_object_unref (device);
+				g_object_unref (adapter);
+				retval = TRUE;
+				break;
+			}
+		}
+		g_object_unref(adapter);
+	}
+
+	g_ptr_array_free (adapters, TRUE);
+
+	g_object_unref(manager);
+	dbus_g_connection_unref(connection);
+
+	return retval;
+}
+
+static void
+transfer_started_cb (DBusGProxy *session,
+		     const char *filename,
+		     const char *local_path,
+		     guint64 size,
+		     gpointer user_data)
+{
+	GHashTable *dict;
+	DBusGProxy *server = (DBusGProxy *) user_data;
+	GError *error = NULL;
+	gboolean authorise;
+
+	g_message ("transfer started on %s", local_path);
+	g_object_set_data_full (G_OBJECT (session), "filename", g_strdup (local_path), (GDestroyNotify) g_free);
+
+	show_icon ();
+
+	/* First transfer of the session */
+	if (g_object_get_data (G_OBJECT (session), "bdaddr") == NULL) {
+		const char *bdaddr;
+
+		if (dbus_g_proxy_call (server, "GetServerSessionInfo", &error,
+				       DBUS_TYPE_G_OBJECT_PATH, dbus_g_proxy_get_path (session), G_TYPE_INVALID,
+				       DBUS_TYPE_G_STRING_VARIANT_HASHTABLE, &dict, G_TYPE_INVALID) == FALSE) {
+			g_printerr ("Getting Server session info failed: %s\n",
+				    error->message);
+			g_error_free (error);
+			return;
+		}
+
+		bdaddr = g_hash_table_lookup (dict, "BluetoothAddress");
+		g_message ("transfer started for device %s", bdaddr);
+
+		g_object_set_data_full (G_OBJECT (session), "bdaddr", g_strdup (bdaddr), (GDestroyNotify) g_free);
+		/* Initial accept method is undefined, we do that lower down */
+		g_object_set_data (G_OBJECT (session), "accept-method", GINT_TO_POINTER (-1));
+		g_hash_table_destroy (dict);
+	}
+
+	/* Accept method changed */
+	if (GPOINTER_TO_INT (g_object_get_data (G_OBJECT (session), "accept-method")) != accept_setting) {
+		const char *bdaddr;
+
+		bdaddr = g_object_get_data (G_OBJECT (session), "bdaddr");
+
+		if (bdaddr == NULL) {
+			g_warning ("Couldn't get the Bluetooth address for the device, rejecting the transfer");
+			authorise = FALSE;
+		} else if (accept_setting == ACCEPT_ALWAYS) {
+			authorise = TRUE;
+		} else if (accept_setting == ACCEPT_BONDED) {
+			authorise = device_is_authorised (bdaddr);
+		} else {
+			//FIXME implement
+			g_warning ("\"Ask\" authorisation method not implemented");
+			authorise = FALSE;
+		}
+		g_object_set_data (G_OBJECT (session), "authorise", GINT_TO_POINTER (authorise));
+	}
+
+	g_message ("accept_setting: %d", accept_setting);
+
+	authorise = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (session), "authorise"));
+	if (authorise != FALSE) {
+		if (dbus_g_proxy_call (session, "Accept", &error, G_TYPE_INVALID, G_TYPE_INVALID) == FALSE) {
+			g_printerr ("Failed to accept file transfer: %s\n", error->message);
+			g_error_free (error);
+			return;
+		}
+		g_message ("authorised transfer");
+	} else {
+		if (dbus_g_proxy_call (session, "Reject", &error, G_TYPE_INVALID, G_TYPE_INVALID) == FALSE) {
+			g_printerr ("Failed to reject file transfer: %s\n", error->message);
+			g_error_free (error);
+			return;
+		}
+		g_message ("rejected transfer");
+		g_object_set_data (G_OBJECT (session), "filename", NULL);
+	}
+}
+
+static void
+transfer_completed_cb (DBusGProxy *session,
+		       gpointer user_data)
+{
+	GSettings *settings;
+	gboolean display_notify;
+	const char *filename;
+
+	filename = (const char *) g_object_get_data (G_OBJECT (session), "filename");
+
+	g_message ("file finish transfer: %s", filename);
+
+	if (filename == NULL)
+		return;
+
+	settings = g_settings_new (GSETTINGS_SCHEMA);
+	display_notify = g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_OBEXPUSH_NOTIFY);
+	g_object_unref (settings);
+
+	if (display_notify) {
+		show_notification (filename);
+	} else {
+		hide_statusicon ();
+	}
+	g_object_set_data (G_OBJECT (session), "filename", NULL);
+}
+
+static void
+cancelled_cb (DBusGProxy *session,
+	      gpointer user_data)
+{
+	//FIXME implement properly, we never actually finished the transfer
+	g_message ("transfered was cancelled by the sender");
+	transfer_completed_cb (session, user_data);
+	hide_statusicon ();
+}
+
+static void
+error_occurred_cb (DBusGProxy *session,
+		   const char *error_name,
+		   const char *error_message,
+		   gpointer user_data)
+{
+	//FIXME implement properly
+	g_message ("transfer error occurred: %s", error_message);
+	transfer_completed_cb (session, user_data);
+}
+
+static void
+session_created_cb (DBusGProxy *server, const char *session_path, gpointer user_data)
+{
+	DBusGProxy *session;
+
+	session = dbus_g_proxy_new_for_name (connection,
+					     "org.openobex",
+					     session_path,
+					     "org.openobex.ServerSession");
+
+	dbus_g_proxy_add_signal (session, "TransferStarted",
+				 G_TYPE_STRING, G_TYPE_STRING, G_TYPE_UINT64, G_TYPE_INVALID);
+	dbus_g_proxy_connect_signal(session, "TransferStarted",
+				    G_CALLBACK (transfer_started_cb), server, NULL);
+	dbus_g_proxy_add_signal (session, "TransferCompleted",
+				 G_TYPE_INVALID, G_TYPE_INVALID);
+	dbus_g_proxy_connect_signal(session, "TransferCompleted",
+				    G_CALLBACK (transfer_completed_cb), server, NULL);
+	dbus_g_proxy_add_signal (session, "Cancelled",
+				 G_TYPE_INVALID, G_TYPE_INVALID);
+	dbus_g_proxy_connect_signal(session, "Cancelled",
+				    G_CALLBACK (cancelled_cb), server, NULL);
+	dbus_g_proxy_add_signal (session, "ErrorOccurred",
+				 G_TYPE_INVALID, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INVALID);
+	dbus_g_proxy_connect_signal(session, "ErrorOccurred",
+				    G_CALLBACK (error_occurred_cb), server, NULL);
+}
+
+void
+obexpush_up (void)
+{
+	GError *err = NULL;
+	char *download_dir, *server;
+
+	server = NULL;
+	if (manager_proxy == NULL) {
+		manager_proxy = dbus_g_proxy_new_for_name (connection,
+							   "org.openobex",
+							   "/org/openobex",
+							   "org.openobex.Manager");
+		if (dbus_g_proxy_call (manager_proxy, "CreateBluetoothServer",
+				       &err, G_TYPE_STRING, "00:00:00:00:00:00", G_TYPE_STRING, "opp", G_TYPE_BOOLEAN, FALSE, G_TYPE_INVALID,
+				       DBUS_TYPE_G_OBJECT_PATH, &server, G_TYPE_INVALID) == FALSE) {
+			g_printerr ("Creating Bluetooth ObexPush server failed: %s\n",
+				    err->message);
+			g_error_free (err);
+			g_object_unref (manager_proxy);
+			manager_proxy = NULL;
+			return;
+		}
+	}
+
+	download_dir = lookup_download_dir ();
+
+	if (server_proxy == NULL) {
+		server_proxy = dbus_g_proxy_new_for_name (connection,
+							   "org.openobex",
+							   server,
+							   "org.openobex.Server");
+		g_free (server);
+
+		dbus_g_proxy_add_signal (server_proxy, "SessionCreated",
+					 DBUS_TYPE_G_OBJECT_PATH, G_TYPE_INVALID);
+		dbus_g_proxy_connect_signal(server_proxy, "SessionCreated",
+					    G_CALLBACK (session_created_cb), NULL, NULL);
+	}
+
+	if (dbus_g_proxy_call (server_proxy, "Start", &err,
+			   G_TYPE_STRING, download_dir, G_TYPE_BOOLEAN, TRUE, G_TYPE_BOOLEAN, FALSE, G_TYPE_INVALID,
+			   G_TYPE_INVALID) == FALSE) {
+		if (g_error_matches (err, DBUS_GERROR, DBUS_GERROR_REMOTE_EXCEPTION) != FALSE &&
+		    dbus_g_error_has_name (err, "org.openobex.Error.Started") != FALSE) {
+		    	g_error_free (err);
+		    	g_message ("already started, ignoring error");
+		    	g_free (download_dir);
+		    	return;
+		}
+		g_printerr ("Starting Bluetooth ObexPush server failed: %s\n",
+			    err->message);
+		g_error_free (err);
+		g_free (download_dir);
+		g_object_unref (server_proxy);
+		server_proxy = NULL;
+		g_object_unref (manager_proxy);
+		manager_proxy = NULL;
+		return;
+	}
+
+	g_free (download_dir);
+}
+
+static void
+obexpush_stop (gboolean stop_manager)
+{
+	GError *err = NULL;
+
+	if (server_proxy == NULL)
+		return;
+
+	if (dbus_g_proxy_call (server_proxy, "Close", &err, G_TYPE_INVALID, G_TYPE_INVALID) == FALSE) {
+		if (g_error_matches (err, DBUS_GERROR, DBUS_GERROR_REMOTE_EXCEPTION) == FALSE ||
+		    dbus_g_error_has_name (err, "org.openobex.Error.NotStarted") == FALSE) {
+			g_printerr ("Stopping Bluetooth ObexPush server failed: %s\n",
+				    err->message);
+			g_error_free (err);
+			return;
+		}
+		g_error_free (err);
+	}
+
+	if (stop_manager != FALSE) {
+		g_object_unref (server_proxy);
+		server_proxy = NULL;
+		g_object_unref (manager_proxy);
+		manager_proxy = NULL;
+	}
+
+	//FIXME stop all the notifications
+}
+
+void
+obexpush_down (void)
+{
+	obexpush_stop (TRUE);
+}
+
+void
+obexpush_restart (void)
+{
+	obexpush_stop (FALSE);
+	obexpush_up ();
+}
+
+gboolean
+obexpush_init (void)
+{
+	GError *err = NULL;
+
+	connection = dbus_g_bus_get (DBUS_BUS_SESSION, &err);
+	if (connection == NULL) {
+		g_printerr ("Connecting to session bus failed: %s\n",
+			    err->message);
+		g_error_free (err);
+		return FALSE;
+	}
+
+	dbus_g_object_register_marshaller (marshal_VOID__STRING_STRING_UINT64,
+					   G_TYPE_NONE,
+					   G_TYPE_STRING, G_TYPE_STRING, G_TYPE_UINT64, G_TYPE_INVALID);
+
+	if (!notify_init("mate-user-share")) {
+		g_warning("Unable to initialize the notification system\n");
+        }
+
+	dbus_connection_set_exit_on_disconnect (dbus_g_connection_get_connection (connection), FALSE);
+
+	return TRUE;
+}
+
+void
+obexpush_set_accept_files_policy (AcceptSetting setting)
+{
+	accept_setting = setting;
+}
+
+void
+obexpush_set_notify (gboolean enabled)
+{
+	show_notifications = enabled;
+}
+
+
+
+
+ + + diff --git a/2021-04-25-143339-9886-cppcheck@cf2a18e177f2_master/3.html b/2021-04-25-143339-9886-cppcheck@cf2a18e177f2_master/3.html new file mode 100644 index 0000000..f2cda19 --- /dev/null +++ b/2021-04-25-143339-9886-cppcheck@cf2a18e177f2_master/3.html @@ -0,0 +1,764 @@ + + + + + + Cppcheck - HTML report - mate-user-share + + + + + + +
+ +
+
  1
+  2
+  3
+  4
+  5
+  6
+  7
+  8
+  9
+ 10
+ 11
+ 12
+ 13
+ 14
+ 15
+ 16
+ 17
+ 18
+ 19
+ 20
+ 21
+ 22
+ 23
+ 24
+ 25
+ 26
+ 27
+ 28
+ 29
+ 30
+ 31
+ 32
+ 33
+ 34
+ 35
+ 36
+ 37
+ 38
+ 39
+ 40
+ 41
+ 42
+ 43
+ 44
+ 45
+ 46
+ 47
+ 48
+ 49
+ 50
+ 51
+ 52
+ 53
+ 54
+ 55
+ 56
+ 57
+ 58
+ 59
+ 60
+ 61
+ 62
+ 63
+ 64
+ 65
+ 66
+ 67
+ 68
+ 69
+ 70
+ 71
+ 72
+ 73
+ 74
+ 75
+ 76
+ 77
+ 78
+ 79
+ 80
+ 81
+ 82
+ 83
+ 84
+ 85
+ 86
+ 87
+ 88
+ 89
+ 90
+ 91
+ 92
+ 93
+ 94
+ 95
+ 96
+ 97
+ 98
+ 99
+100
+101
+102
+103
+104
+105
+106
+107
+108
+109
+110
+111
+112
+113
+114
+115
+116
+117
+118
+119
+120
+121
+122
+123
+124
+125
+126
+127
+128
+129
+130
+131
+132
+133
+134
+135
+136
+137
+138
+139
+140
+141
+142
+143
+144
+145
+146
+147
+148
+149
+150
+151
+152
+153
+154
+155
+156
+157
+158
+159
+160
+161
+162
+163
+164
+165
+166
+167
+168
+169
+170
+171
+172
+173
+174
+175
+176
+177
+178
+179
+180
+181
+182
+183
+184
+185
+186
+187
+188
+189
+190
+191
+192
+193
+194
+195
+196
+197
+198
+199
+200
+201
+202
+203
+204
+205
+206
+207
+208
+209
+210
+211
+212
+213
+214
+215
+216
+217
+218
+219
+220
+221
+222
+223
+224
+225
+226
+227
+228
+229
+230
+231
+232
+233
+234
+235
+236
+237
+238
+239
+240
+241
+242
+243
+244
+245
+246
+247
+248
+249
+250
+251
+252
+253
+254
+255
+256
+257
+258
+259
+260
+261
+262
+263
+264
+265
+266
+267
+268
+269
+270
+271
+272
+273
+274
+275
+276
+277
+278
+279
+280
+281
+282
+283
+284
+285
+286
+287
+288
+289
+290
+291
/* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 8; tab-width: 8 -*-
+ *
+ * Copyright (C) 2003 Novell, Inc.
+ * Copyright (C) 2003-2004 Red Hat, Inc.
+ * Copyright (C) 2005 William Jon McCann <mccann@jhu.edu>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * 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 Foundation, Inc., 51 Franklin St, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ *
+ */
+
+#include "config.h"
+
+#include <stdlib.h>
+#include <string.h>
+#include <glib/gi18n-lib.h>
+#include <gtk/gtk.h>
+#include <libcaja-extension/caja-menu-provider.h>
+#include <libcaja-extension/caja-location-widget-provider.h>
+
+#ifdef HAVE_BLUETOOTH
+#include <bluetooth-client.h>
+#endif
+
+#include "caja-share-bar.h"
+#include "user_share-common.h"
+
+#define CAJA_TYPE_USER_SHARE  (caja_user_share_get_type ())
+#define CAJA_USER_SHARE(o)    (G_TYPE_CHECK_INSTANCE_CAST ((o), CAJA_TYPE_USER_SHARE, CajaUserShare))
+#define CAJA_IS_USER_SHARE(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), CAJA_TYPE_USER_SHARE))
+
+typedef struct
+{
+        GObject              parent_slot;
+} CajaUserShare;
+
+typedef struct
+{
+        GObjectClass parent_slot;
+} CajaUserShareClass;
+
+static GType caja_user_share_get_type      (void);
+static void  caja_user_share_register_type (GTypeModule *module);
+
+static void
+launch_process (char **argv, GtkWindow *parent)
+{
+        GError *error;
+        GtkWidget *dialog;
+
+        error = NULL;
+        if (!g_spawn_async (NULL,
+                            argv, NULL,
+                            0,
+                            NULL, NULL,
+                            NULL,
+                            &error)) {
+
+
+                dialog = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL, GTK_MESSAGE_WARNING,
+						 GTK_BUTTONS_OK, _("Unable to launch the Personal File Sharing preferences"));
+
+                gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog), "%s", error->message);
+
+                gtk_dialog_run (GTK_DIALOG (dialog));
+                gtk_widget_destroy (dialog);
+
+                g_error_free (error);
+        }
+}
+
+static void
+launch_prefs_on_window (GtkWindow *window)
+{
+        char *argv [2];
+
+        argv [0] = g_build_filename (BINDIR, "mate-file-share-properties", NULL);
+        argv [1] = NULL;
+
+        launch_process (argv, window);
+
+        g_free (argv [0]);
+}
+
+static void
+bar_response_cb (CajaShareBar *bar,
+                 gint response,
+                 gpointer         data)
+{
+        if (response == CAJA_SHARE_BAR_RESPONSE_PREFERENCES) {
+                launch_prefs_on_window (GTK_WINDOW (data));
+        }
+}
+
+#ifdef HAVE_BLUETOOTH
+static void
+downloads_bar_set_from_bluetooth_status (GtkWidget *bar)
+{
+	BluetoothClient *client;
+	gboolean bt_powered;
+
+	client = g_object_get_data (G_OBJECT (bar), "bluetooth-client");
+	g_object_get (G_OBJECT (client),
+		      "default-adapter-powered", &bt_powered,
+		      NULL);
+	gtk_widget_set_visible (bar, bt_powered);
+}
+
+static void
+default_adapter_powered_cb (GObject    *gobject,
+			    GParamSpec *pspec,
+			    GtkWidget  *bar)
+{
+	downloads_bar_set_from_bluetooth_status (bar);
+}
+#endif /* HAVE_BLUETOOTH */
+
+static GtkWidget *
+caja_user_share_get_location_widget (CajaLocationWidgetProvider *iface,
+                                         const char                     *uri,
+                                         GtkWidget                      *window)
+{
+	GFile             *file;
+	GtkWidget         *bar;
+	guint              i;
+	gboolean           enable = FALSE;
+	GFile             *home;
+#ifdef HAVE_BLUETOOTH
+	const GUserDirectory special_dirs[] = { G_USER_DIRECTORY_PUBLIC_SHARE, G_USER_DIRECTORY_DOWNLOAD };
+
+	gboolean is_dir[] = { FALSE, FALSE };
+#else
+	const GUserDirectory special_dirs[] = { G_USER_DIRECTORY_PUBLIC_SHARE };
+
+	gboolean is_dir[] = { FALSE };
+#endif /* HAVE_BLUETOOTH */
+	file = g_file_new_for_uri (uri);
+	home = g_file_new_for_path (g_get_home_dir ());
+
+	/* We don't show anything in $HOME */
+	if (g_file_equal (home, file)) {
+		g_object_unref (home);
+		g_object_unref (file);
+		return NULL;
+	}
+
+	g_object_unref (home);
+
+	for (i = 0; i < G_N_ELEMENTS (special_dirs); i++) {
+		GFile *dir;
+		dir = lookup_dir_with_fallback (special_dirs[i]);
+		if (g_file_equal (dir, file)) {
+			enable = TRUE;
+			is_dir[i] = TRUE;
+		}
+		g_object_unref (dir);
+	}
+
+	g_object_unref (file);
+
+	if (enable == FALSE)
+		return NULL;
+
+	if (is_dir[0] != FALSE) {
+#ifdef HAVE_BLUETOOTH
+		if (is_dir[1] != FALSE) {
+			bar = caja_share_bar_new (_("May be used to share or receive files"));
+		} else {
+			bar = caja_share_bar_new (_("May be shared over the network or Bluetooth"));
+		}
+#else
+		bar = caja_share_bar_new (_("May be shared over the network"));
+#endif /* HAVE_BLUETOOTH */
+	} else {
+#ifdef HAVE_BLUETOOTH
+		BluetoothClient *client;
+
+		bar = caja_share_bar_new (_("May be used to receive files over Bluetooth"));
+
+		gtk_widget_set_no_show_all (bar, TRUE);
+		client = bluetooth_client_new ();
+		g_object_set_data_full (G_OBJECT (bar), "bluetooth-client", client, g_object_unref);
+		g_signal_connect (G_OBJECT (client), "notify::default-adapter-powered",
+				  G_CALLBACK (default_adapter_powered_cb), bar);
+		downloads_bar_set_from_bluetooth_status (bar);
+#endif /* HAVE_BLUETOOTH */
+	}
+
+	g_signal_connect (bar, "response",
+			  G_CALLBACK (bar_response_cb),
+			  window);
+
+	gtk_widget_show_all (bar);
+
+	return bar;
+}
+
+static void
+caja_user_share_location_widget_provider_iface_init (CajaLocationWidgetProviderIface *iface)
+{
+        iface->get_widget = caja_user_share_get_location_widget;
+}
+
+static void
+caja_user_share_instance_init (CajaUserShare *share)
+{
+
+}
+
+static void
+caja_user_share_class_init (CajaUserShareClass *klass)
+{
+
+}
+
+static GType share_type = 0;
+
+static GType
+caja_user_share_get_type (void)
+{
+        return share_type;
+}
+
+static void
+caja_user_share_register_type (GTypeModule *module)
+{
+        static const GTypeInfo info = {
+                sizeof (CajaUserShareClass),
+                (GBaseInitFunc) NULL,
+                (GBaseFinalizeFunc) NULL,
+                (GClassInitFunc) caja_user_share_class_init,
+                NULL,
+                NULL,
+                sizeof (CajaUserShare),
+                0,
+                (GInstanceInitFunc) caja_user_share_instance_init,
+        };
+
+        static const GInterfaceInfo location_widget_provider_iface_info = {
+                (GInterfaceInitFunc) caja_user_share_location_widget_provider_iface_init,
+                NULL,
+                NULL
+        };
+
+        share_type = g_type_module_register_type (module,
+                                                 G_TYPE_OBJECT,
+                                                 "CajaUserShare",
+                                                 &info, 0);
+
+        g_type_module_add_interface (module,
+                                     share_type,
+                                     CAJA_TYPE_LOCATION_WIDGET_PROVIDER,
+                                     &location_widget_provider_iface_info);
+}
+
+void
+caja_module_initialize (GTypeModule *module)
+{
+        caja_user_share_register_type (module);
+        bindtextdomain (GETTEXT_PACKAGE, MATELOCALEDIR);
+        bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
+}
+
+void
+caja_module_shutdown (void)
+{
+}
+
+void
+caja_module_list_types (const GType **types,
+                            int          *num_types)
+{
+        static GType type_list [1];
+
+        type_list[0] = CAJA_TYPE_USER_SHARE;
+
+        *types = type_list;
+        *num_types = 1;
+}
+
+
+
+
+ + + diff --git a/2021-04-25-143339-9886-cppcheck@cf2a18e177f2_master/4.html b/2021-04-25-143339-9886-cppcheck@cf2a18e177f2_master/4.html new file mode 100644 index 0000000..06db2f5 --- /dev/null +++ b/2021-04-25-143339-9886-cppcheck@cf2a18e177f2_master/4.html @@ -0,0 +1,1182 @@ + + + + + + Cppcheck - HTML report - mate-user-share + + + + + + +
+ +
+
  1
+  2
+  3
+  4
+  5
+  6
+  7
+  8
+  9
+ 10
+ 11
+ 12
+ 13
+ 14
+ 15
+ 16
+ 17
+ 18
+ 19
+ 20
+ 21
+ 22
+ 23
+ 24
+ 25
+ 26
+ 27
+ 28
+ 29
+ 30
+ 31
+ 32
+ 33
+ 34
+ 35
+ 36
+ 37
+ 38
+ 39
+ 40
+ 41
+ 42
+ 43
+ 44
+ 45
+ 46
+ 47
+ 48
+ 49
+ 50
+ 51
+ 52
+ 53
+ 54
+ 55
+ 56
+ 57
+ 58
+ 59
+ 60
+ 61
+ 62
+ 63
+ 64
+ 65
+ 66
+ 67
+ 68
+ 69
+ 70
+ 71
+ 72
+ 73
+ 74
+ 75
+ 76
+ 77
+ 78
+ 79
+ 80
+ 81
+ 82
+ 83
+ 84
+ 85
+ 86
+ 87
+ 88
+ 89
+ 90
+ 91
+ 92
+ 93
+ 94
+ 95
+ 96
+ 97
+ 98
+ 99
+100
+101
+102
+103
+104
+105
+106
+107
+108
+109
+110
+111
+112
+113
+114
+115
+116
+117
+118
+119
+120
+121
+122
+123
+124
+125
+126
+127
+128
+129
+130
+131
+132
+133
+134
+135
+136
+137
+138
+139
+140
+141
+142
+143
+144
+145
+146
+147
+148
+149
+150
+151
+152
+153
+154
+155
+156
+157
+158
+159
+160
+161
+162
+163
+164
+165
+166
+167
+168
+169
+170
+171
+172
+173
+174
+175
+176
+177
+178
+179
+180
+181
+182
+183
+184
+185
+186
+187
+188
+189
+190
+191
+192
+193
+194
+195
+196
+197
+198
+199
+200
+201
+202
+203
+204
+205
+206
+207
+208
+209
+210
+211
+212
+213
+214
+215
+216
+217
+218
+219
+220
+221
+222
+223
+224
+225
+226
+227
+228
+229
+230
+231
+232
+233
+234
+235
+236
+237
+238
+239
+240
+241
+242
+243
+244
+245
+246
+247
+248
+249
+250
+251
+252
+253
+254
+255
+256
+257
+258
+259
+260
+261
+262
+263
+264
+265
+266
+267
+268
+269
+270
+271
+272
+273
+274
+275
+276
+277
+278
+279
+280
+281
+282
+283
+284
+285
+286
+287
+288
+289
+290
+291
+292
+293
+294
+295
+296
+297
+298
+299
+300
+301
+302
+303
+304
+305
+306
+307
+308
+309
+310
+311
+312
+313
+314
+315
+316
+317
+318
+319
+320
+321
+322
+323
+324
+325
+326
+327
+328
+329
+330
+331
+332
+333
+334
+335
+336
+337
+338
+339
+340
+341
+342
+343
+344
+345
+346
+347
+348
+349
+350
+351
+352
+353
+354
+355
+356
+357
+358
+359
+360
+361
+362
+363
+364
+365
+366
+367
+368
+369
+370
+371
+372
+373
+374
+375
+376
+377
+378
+379
+380
+381
+382
+383
+384
+385
+386
+387
+388
+389
+390
+391
+392
+393
+394
+395
+396
+397
+398
+399
+400
+401
+402
+403
+404
+405
+406
+407
+408
+409
+410
+411
+412
+413
+414
+415
+416
+417
+418
+419
+420
+421
+422
+423
+424
+425
+426
+427
+428
+429
+430
+431
+432
+433
+434
+435
+436
+437
+438
+439
+440
+441
+442
+443
+444
+445
+446
+447
+448
+449
+450
+451
+452
+453
+454
+455
+456
+457
+458
+459
+460
+461
+462
+463
+464
+465
+466
+467
+468
+469
+470
+471
+472
+473
+474
+475
+476
+477
+478
+479
+480
+481
+482
+483
+484
+485
+486
+487
+488
+489
+490
+491
+492
+493
+494
+495
+496
+497
+498
+499
+500
+501
+502
+503
+504
+505
+506
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
+
+/*
+ *  Copyright (C) 2004-2008 Red Hat, Inc.
+ *
+ *  Caja is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU General Public License as
+ *  published by the Free Software Foundation; either version 2 of the
+ *  License, or (at your option) any later version.
+ *
+ *  Caja is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  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
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ *  Authors: Alexander Larsson <alexl@redhat.com>
+ *
+ */
+
+#include "config.h"
+
+#include <gdk/gdkx.h>
+#include <gtk/gtk.h>
+#include <glib/gi18n.h>
+#include <glib/gstdio.h>
+#include <gio/gio.h>
+#include <X11/Xlib.h>
+
+#include "user_share-private.h"
+#include "user_share-common.h"
+#include "http.h"
+
+#ifdef HAVE_BLUETOOTH
+#include <bluetooth-client.h>
+
+#include "obexftp.h"
+#include "obexpush.h"
+
+#endif /* HAVE_BLUETOOTH */
+
+#include <gio/gio.h>
+
+#include <stdarg.h>
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <signal.h>
+#include <unistd.h>
+
+static guint disabled_timeout_tag = 0;
+static GSettings* settings;<--- Shadowed declaration<--- Shadowed declaration<--- Shadowed declaration
+
+#define GSETTINGS_SCHEMA "org.mate.FileSharing"
+#define GSETTINGS_KEY_FILE_SHARING_ENABLED "enabled"
+#define GSETTINGS_KEY_FILE_SHARING_REQUIRE_PASSWORD "require-password"
+
+#ifdef HAVE_BLUETOOTH
+/* MATE Session */
+#define MATE_SESSION_DBUS_NAME      "org.gnome.SessionManager"
+#define MATE_SESSION_DBUS_OBJECT    "/org/gnome/SessionManager"
+#define MATE_SESSION_DBUS_INTERFACE "org.gnome.SessionManager"
+
+static GDBusProxy *session_proxy = NULL;
+static gboolean has_console = TRUE;
+
+static BluetoothClient *client = NULL;
+static gboolean bluetoothd_enabled = FALSE;
+
+#define OBEX_ENABLED (bluetoothd_enabled && has_console)
+
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_ENABLED "bluetooth-enabled"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_ALLOW_WRITE "bluetooth-allow-write"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_REQUIRE_PAIRING "bluetooth-require-pairing"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED "bluetooth-obexpush-enabled"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_ACCEPT_FILES "bluetooth-accept-files"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_NOTIFY "bluetooth-notify"
+
+
+static void
+obex_services_start (void)
+{
+	GSettings *settings;<--- Shadow variable
+
+	if (bluetoothd_enabled == FALSE ||
+	    has_console == FALSE)
+	    	return;
+
+	settings = g_settings_new(GSETTINGS_SCHEMA);
+
+	if (g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED) == TRUE) {
+	    obexpush_up ();
+	}
+	if (g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_ENABLED) == TRUE) {
+	    obexftp_up ();
+	}
+
+	g_object_unref (client);
+}
+
+static void
+obex_services_shutdown (void)
+{
+	obexpush_down ();
+	obexftp_down ();
+}
+
+static void
+session_properties_changed_cb (GDBusProxy      *session,
+			       GVariant        *changed,
+			       char           **invalidated,
+			       gpointer         user_data)
+{
+	GVariant *v;
+
+	v = g_variant_lookup_value (changed, "SessionIsActive", G_VARIANT_TYPE_BOOLEAN);
+	if (v) {
+		has_console = g_variant_get_boolean (v);
+		g_debug ("Received session is active change: now %s", has_console ? "active" : "inactive");
+
+		if (has_console)
+			obex_services_start ();
+		else
+			obex_services_shutdown ();
+
+		g_variant_unref (v);
+	}
+}
+
+static gboolean
+is_session_active (void)
+{
+	GVariant *variant;
+	gboolean is_session_active = FALSE;
+
+	variant = g_dbus_proxy_get_cached_property (session_proxy,
+						    "SessionIsActive");
+	if (variant) {
+		is_session_active = g_variant_get_boolean (variant);
+		g_variant_unref (variant);
+ 	}
+
+	return is_session_active;
+}
+
+static void
+session_init (void)
+{
+	GError *error = NULL;
+
+	session_proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION,
+						       G_DBUS_PROXY_FLAGS_NONE,
+						       NULL,
+						       MATE_SESSION_DBUS_NAME,
+						       MATE_SESSION_DBUS_OBJECT,
+						       MATE_SESSION_DBUS_INTERFACE,
+						       NULL,
+						       &error);
+	if (session_proxy == NULL) {
+		g_warning ("Failed to get session proxy: %s", error->message);
+		g_error_free (error);
+		return;
+	}
+	g_signal_connect (session_proxy, "g-properties-changed",
+			  G_CALLBACK (session_properties_changed_cb),
+			  NULL);
+	has_console = is_session_active ();
+}
+
+static void
+default_adapter_changed (GObject    *gobject,
+			 GParamSpec *pspec,
+			 gpointer    user_data)
+{
+	char *adapter;
+	gboolean adapter_powered;
+
+	g_object_get (G_OBJECT (client),
+		      "default-adapter", &adapter,
+		      "default-adapter-powered", &adapter_powered,
+		      NULL);
+	if (adapter != NULL && *adapter != '\0') {
+		bluetoothd_enabled = adapter_powered;
+	} else {
+		bluetoothd_enabled = FALSE;
+	}
+
+	/* Were we called as init, or as a callback */
+	if (gobject != NULL) {
+		if (bluetoothd_enabled != FALSE)
+			obex_services_start ();
+		else
+			obex_services_shutdown ();
+	}
+}
+
+static void
+bluez_init (void)
+{
+	client = bluetooth_client_new ();
+	default_adapter_changed (NULL, NULL, NULL);
+	g_signal_connect (G_OBJECT (client), "notify::default-adapter",
+			  G_CALLBACK (default_adapter_changed), NULL);
+	g_signal_connect (G_OBJECT (client), "notify::default-adapter-powered",
+			  G_CALLBACK (default_adapter_changed), NULL);
+}
+#endif /* HAVE_BLUETOOTH */
+
+static gboolean
+file_sharing_enabled (void)
+{
+	gboolean enabled = TRUE;
+	settings = g_settings_new (GSETTINGS_SCHEMA);
+
+#ifdef HAVE_BLUETOOTH
+	if (g_settings_get_boolean (settings, FILE_SHARING_ENABLED) == FALSE &&
+	    g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_ENABLED) == FALSE &&
+	    g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED) == FALSE)
+#else /* HAVE_BLUETOOTH */
+	if (g_settings_get_boolean (settings, FILE_SHARING_ENABLED) == FALSE)
+#endif /* HAVE_BLUETOOTH */
+		enabled = FALSE;
+
+	g_object_unref (settings);
+
+	return enabled;
+}
+
+static void
+migrate_old_configuration (void)
+{
+	const char *old_config_dir;
+	const char *new_config_dir;
+
+	old_config_dir = g_build_filename (g_get_home_dir (), ".mate2", "user-share", NULL);
+	new_config_dir = g_build_filename (g_get_user_config_dir (), "user-share", NULL);
+	if (g_file_test (old_config_dir, G_FILE_TEST_IS_DIR))
+		g_rename (old_config_dir, new_config_dir);
+
+}
+
+static void
+require_password_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	/* Need to restart to get new password setting */
+	if (http_get_pid () != 0) {
+		http_down ();
+		http_up ();
+	}
+}
+
+/* File sharing was disabled for some time, exit now */
+/* If we re-enable it in the ui, this will be restarted anyway */
+static gboolean
+disabled_timeout_callback (gpointer user_data)
+{
+	GSettings *settings = (GSettings *) user_data;<--- Shadow variable
+	http_down ();
+
+#ifdef HAVE_BLUETOOTH
+	if (g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_ENABLED) == FALSE &&
+	    g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED) == FALSE)
+		_exit (0);
+#else /* HAVE_BLUETOOTH */
+	if (g_settings_get_boolean (settings, FILE_SHARING_ENABLED) == FALSE)
+		_exit (0);
+#endif /* HAVE_BLUETOOTH */
+	return FALSE;
+}
+
+static void
+file_sharing_enabled_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	gboolean enabled;
+
+	if (disabled_timeout_tag != 0) {
+		g_source_remove (disabled_timeout_tag);
+		disabled_timeout_tag = 0;
+	}
+
+	enabled = g_settings_get_boolean (settings,
+					 FILE_SHARING_ENABLED);
+	if (enabled) {
+		if (http_get_pid () == 0) {
+			http_up ();
+		}
+	} else {
+		http_down ();
+		disabled_timeout_tag = g_timeout_add_seconds (3,
+							      (GSourceFunc)disabled_timeout_callback,
+							      settings);
+	}
+}
+
+#ifdef HAVE_BLUETOOTH
+static void
+file_sharing_bluetooth_allow_write_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	if (g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_ENABLED) != FALSE)
+		obexftp_restart ();
+}
+
+static void
+file_sharing_bluetooth_require_pairing_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	if (g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_ENABLED) != FALSE) {
+		/* We need to fully reset the session,
+		 * otherwise the new setting isn't taken into account */
+		obexftp_down ();
+		obexftp_up ();
+	}
+}
+
+static void
+file_sharing_bluetooth_enabled_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	if (g_settings_get_boolean (settings,
+				   FILE_SHARING_BLUETOOTH_ENABLED) == FALSE) {
+		obexftp_down ();
+		if (g_settings_get_boolean (settings, FILE_SHARING_ENABLED) == FALSE &&
+		    g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED) == FALSE) {
+			_exit (0);
+		}
+	} else if (OBEX_ENABLED) {
+		obexftp_up ();
+	}
+}
+
+static void
+file_sharing_bluetooth_obexpush_enabled_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	if (g_settings_get_boolean (settings,
+				   FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED) == FALSE) {
+		obexpush_down ();
+		if (g_settings_get_boolean (settings, FILE_SHARING_ENABLED) == FALSE &&
+		    g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_ENABLED) == FALSE) {
+			_exit (0);
+		}
+	} else if (OBEX_ENABLED) {
+		obexpush_up ();
+	}
+}
+
+static void
+file_sharing_bluetooth_obexpush_accept_files_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	AcceptSetting setting;
+	char *str;
+
+	str = g_settings_get_string (settings, FILE_SHARING_BLUETOOTH_OBEXPUSH_ACCEPT_FILES);
+	setting = accept_setting_from_string (str);
+	g_free (str);
+
+	obexpush_set_accept_files_policy (setting);
+}
+
+static void
+file_sharing_bluetooth_obexpush_notify_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	obexpush_set_notify (g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_OBEXPUSH_NOTIFY));
+}
+#endif /* HAVE_BLUETOOTH */
+
+static RETSIGTYPE
+cleanup_handler (int sig)
+{
+	http_down ();
+#ifdef HAVE_BLUETOOTH
+	obexftp_down ();
+	obexpush_down ();
+#endif /* HAVE_BLUETOOTH */
+	_exit (2);
+}
+
+static int
+x_io_error_handler (Display *xdisplay)
+{
+	http_down ();
+#ifdef HAVE_BLUETOOTH
+	obexftp_down ();
+#endif /* HAVE_BLUETOOTH */
+	_exit (2);
+}
+
+int
+main (int argc, char **argv)
+{
+	GSettings *settings;<--- Shadow variable
+	Display *xdisplay;
+	G_GNUC_UNUSED int x_fd;
+	Window selection_owner;
+	Atom xatom;
+
+	bindtextdomain (GETTEXT_PACKAGE, MATELOCALEDIR);
+	bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
+	textdomain (GETTEXT_PACKAGE);
+
+	gtk_init (&argc, &argv);
+
+	if (g_strcmp0 (g_get_real_name (), "root") == 0) {
+		g_warning ("mate-user-share cannot be started as root for security reasons.");
+		return 1;
+	}
+
+	signal (SIGPIPE, SIG_IGN);
+	signal (SIGINT, cleanup_handler);
+	signal (SIGHUP, cleanup_handler);
+	signal (SIGTERM, cleanup_handler);
+
+	xdisplay = GDK_DISPLAY_XDISPLAY (gdk_display_get_default ());
+	if (xdisplay == NULL) {
+		g_warning ("Can't open display");
+		return 1;
+	}
+
+	xatom = XInternAtom (xdisplay, "_MATE_USER_SHARE", FALSE);
+	selection_owner = XGetSelectionOwner (xdisplay, xatom);
+
+	if (selection_owner != None) {
+		/* There is an owner already, quit */
+		return 1;
+	}
+
+	selection_owner = XCreateSimpleWindow (xdisplay,
+					       RootWindow (xdisplay, 0),
+					       0, 0, 1, 1,
+					       0, 0, 0);
+	XSetSelectionOwner (xdisplay, xatom, selection_owner, CurrentTime);
+
+	if (XGetSelectionOwner (xdisplay, xatom) != selection_owner) {
+		/* Didn't get the selection */
+		return 1;
+	}
+
+	migrate_old_configuration ();
+
+	if (!file_sharing_enabled ())
+		return 1;
+
+	settings = g_settings_new (GSETTINGS_SCHEMA);
+
+	x_fd = ConnectionNumber (xdisplay);
+	XSetIOErrorHandler (x_io_error_handler);
+
+	if (http_init () == FALSE)
+		return 1;
+#ifdef HAVE_BLUETOOTH
+	if (obexftp_init () == FALSE)
+		return 1;
+	if (obexpush_init () == FALSE)
+		return 1;
+#endif /* HAVE_BLUETOOTH */
+
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_ENABLED,
+			     G_CALLBACK (file_sharing_enabled_changed), NULL);
+
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_REQUIRE_PASSWORD,
+			     G_CALLBACK (require_password_changed), NULL);
+
+#ifdef HAVE_BLUETOOTH
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_ENABLED,
+			     G_CALLBACK (file_sharing_bluetooth_enabled_changed), NULL);
+
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_ALLOW_WRITE,
+			     G_CALLBACK (file_sharing_bluetooth_allow_write_changed), NULL);
+
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_REQUIRE_PAIRING,
+			     G_CALLBACK (file_sharing_bluetooth_require_pairing_changed), NULL);
+
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED,
+			     G_CALLBACK (file_sharing_bluetooth_obexpush_enabled_changed), NULL);
+
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_ACCEPT_FILES,
+			     G_CALLBACK (file_sharing_bluetooth_obexpush_accept_files_changed), NULL);
+
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_NOTIFY,
+			     G_CALLBACK (file_sharing_bluetooth_obexpush_notify_changed), NULL);
+
+	bluez_init ();
+	session_init ();
+#endif /* HAVE_BLUETOOTH */
+
+	/* Initial setting */
+	file_sharing_enabled_changed (settings, NULL, NULL);
+#ifdef HAVE_BLUETOOTH
+	file_sharing_bluetooth_enabled_changed (settings, NULL, NULL);
+	file_sharing_bluetooth_obexpush_accept_files_changed (settings, NULL, NULL);
+	file_sharing_bluetooth_obexpush_notify_changed (settings, NULL, NULL);
+	file_sharing_bluetooth_obexpush_enabled_changed (settings, NULL, NULL);
+#endif /* HAVE_BLUETOOTH */
+
+	gtk_main ();
+
+	return 0;
+}
+
+
+
+
+ + + diff --git a/2021-04-25-143339-9886-cppcheck@cf2a18e177f2_master/index.html b/2021-04-25-143339-9886-cppcheck@cf2a18e177f2_master/index.html new file mode 100644 index 0000000..bbcd983 --- /dev/null +++ b/2021-04-25-143339-9886-cppcheck@cf2a18e177f2_master/index.html @@ -0,0 +1,141 @@ + + + + + + Cppcheck - HTML report - mate-user-share + + + + + + +
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
LineIdCWESeverityMessage
missingIncludeinformationCppcheck cannot find all the include files (use --check-config for details)
src/file-share-properties.c
82variableScope398styleThe scope of the variable 'password' can be reduced.
97shadowVariable398styleLocal variable 'settings' shadows outer variable
105unusedVariable563styleUnused variable: accept_setting
249shadowVariable398styleLocal variable 'settings' shadows outer variable
273shadowVariable398styleLocal variable 'settings' shadows outer variable
294shadowVariable398styleLocal variable 'settings' shadows outer variable
323shadowVariable398styleLocal variable 'settings' shadows outer variable
340shadowVariable398styleLocal variable 'settings' shadows outer variable
357shadowVariable398styleLocal variable 'settings' shadows outer variable
377shadowVariable398styleLocal variable 'settings' shadows outer variable
393shadowVariable398styleLocal variable 'settings' shadows outer variable
457shadowVariable398styleLocal variable 'settings' shadows outer variable
620variableScope398styleThe scope of the variable 'window' can be reduced.
src/http.c
114variableScope398styleThe scope of the variable 'host_name' can be reduced.
src/obexpush.c
187shadowVariable398styleLocal variable 'connection' shadows outer variable
src/share-extension.c
61variableScope398styleThe scope of the variable 'dialog' can be reduced.
src/user_share.c
86shadowVariable398styleLocal variable 'settings' shadows outer variable
260shadowVariable398styleLocal variable 'settings' shadows outer variable
391shadowVariable398styleLocal variable 'settings' shadows outer variable
+
+
+ + + diff --git a/2021-04-25-143339-9886-cppcheck@cf2a18e177f2_master/stats.html b/2021-04-25-143339-9886-cppcheck@cf2a18e177f2_master/stats.html new file mode 100644 index 0000000..2020977 --- /dev/null +++ b/2021-04-25-143339-9886-cppcheck@cf2a18e177f2_master/stats.html @@ -0,0 +1,109 @@ + + + + + + Cppcheck - HTML report - mate-user-share + + + + + + +
+ +
+

Top 10 files for style severity, total findings: 19
+   13  src/file-share-properties.c
+   3   src/user_share.c
+   1   src/share-extension.c
+   1   src/obexpush.c
+   1   src/http.c
+

+ +
+
+ + + diff --git a/2021-04-25-143339-9886-cppcheck@cf2a18e177f2_master/style.css b/2021-04-25-143339-9886-cppcheck@cf2a18e177f2_master/style.css new file mode 100644 index 0000000..07125f4 --- /dev/null +++ b/2021-04-25-143339-9886-cppcheck@cf2a18e177f2_master/style.css @@ -0,0 +1,137 @@ + +body { + font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif; + font-size: 13px; + line-height: 1.5; + margin: 0; + width: auto; +} + +h1 { + margin: 10px; +} + +.header { + border-bottom: thin solid #aaa; +} + +.footer { + border-top: thin solid #aaa; + font-size: 90%; + margin-top: 5px; +} + +.footer ul { + list-style-type: none; + padding-left: 0; +} + +.footer > p { + margin: 4px; +} + +.wrapper { + display: -webkit-box; + display: -ms-flexbox; + display: flex; + -webkit-box-pack: justify; + -ms-flex-pack: justify; + justify-content: space-between; +} + +#menu, +#menu_index { + text-align: left; + width: 350px; + height: 90vh; + min-height: 200px; + overflow: auto; + position: -webkit-sticky; + position: sticky; + top: 0; + padding: 0 15px 15px 15px; +} + +#menu > a { + display: block; + margin-left: 10px; + font-size: 12px; + z-index: 1; +} + +#content, +#content_index { + background-color: #fff; + -webkit-box-sizing: content-box; + -moz-box-sizing: content-box; + box-sizing: content-box; + padding: 0 15px 15px 15px; + width: calc(100% - 350px); + height: 100%; + overflow-x: auto; +} + +#filename { + margin-left: 10px; + font-size: 12px; + z-index: 1; +} + +.error { + background-color: #ffb7b7; +} + +.error2 { + background-color: #faa; + display: inline-block; + margin-left: 4px; +} + +.inconclusive { + background-color: #b6b6b4; +} + +.inconclusive2 { + background-color: #b6b6b4; + display: inline-block; + margin-left: 4px; +} + +.verbose { + display: inline-block; + vertical-align: top; + cursor: help; +} + +.verbose .content { + display: none; + position: absolute; + padding: 10px; + margin: 4px; + max-width: 40%; + white-space: pre-wrap; + border: 1px solid #000; + background-color: #ffffcc; + cursor: auto; +} + +.highlight .hll { + padding: 1px; +} + +.highlighttable { + background-color: #fff; + z-index: 10; + position: relative; + margin: -10px; +} + +.linenos { + border-right: thin solid #aaa; + color: #d3d3d3; + padding-right: 6px; +} + +.d-none { + display: none; +} diff --git a/2021-05-30-164325-0736-cppcheck@58f05a4efe60_master/0.html b/2021-05-30-164325-0736-cppcheck@58f05a4efe60_master/0.html new file mode 100644 index 0000000..afe28ae --- /dev/null +++ b/2021-05-30-164325-0736-cppcheck@58f05a4efe60_master/0.html @@ -0,0 +1,1503 @@ + + + + + + Cppcheck - HTML report - mate-user-share + + + + + + +
+ +
+
  1
+  2
+  3
+  4
+  5
+  6
+  7
+  8
+  9
+ 10
+ 11
+ 12
+ 13
+ 14
+ 15
+ 16
+ 17
+ 18
+ 19
+ 20
+ 21
+ 22
+ 23
+ 24
+ 25
+ 26
+ 27
+ 28
+ 29
+ 30
+ 31
+ 32
+ 33
+ 34
+ 35
+ 36
+ 37
+ 38
+ 39
+ 40
+ 41
+ 42
+ 43
+ 44
+ 45
+ 46
+ 47
+ 48
+ 49
+ 50
+ 51
+ 52
+ 53
+ 54
+ 55
+ 56
+ 57
+ 58
+ 59
+ 60
+ 61
+ 62
+ 63
+ 64
+ 65
+ 66
+ 67
+ 68
+ 69
+ 70
+ 71
+ 72
+ 73
+ 74
+ 75
+ 76
+ 77
+ 78
+ 79
+ 80
+ 81
+ 82
+ 83
+ 84
+ 85
+ 86
+ 87
+ 88
+ 89
+ 90
+ 91
+ 92
+ 93
+ 94
+ 95
+ 96
+ 97
+ 98
+ 99
+100
+101
+102
+103
+104
+105
+106
+107
+108
+109
+110
+111
+112
+113
+114
+115
+116
+117
+118
+119
+120
+121
+122
+123
+124
+125
+126
+127
+128
+129
+130
+131
+132
+133
+134
+135
+136
+137
+138
+139
+140
+141
+142
+143
+144
+145
+146
+147
+148
+149
+150
+151
+152
+153
+154
+155
+156
+157
+158
+159
+160
+161
+162
+163
+164
+165
+166
+167
+168
+169
+170
+171
+172
+173
+174
+175
+176
+177
+178
+179
+180
+181
+182
+183
+184
+185
+186
+187
+188
+189
+190
+191
+192
+193
+194
+195
+196
+197
+198
+199
+200
+201
+202
+203
+204
+205
+206
+207
+208
+209
+210
+211
+212
+213
+214
+215
+216
+217
+218
+219
+220
+221
+222
+223
+224
+225
+226
+227
+228
+229
+230
+231
+232
+233
+234
+235
+236
+237
+238
+239
+240
+241
+242
+243
+244
+245
+246
+247
+248
+249
+250
+251
+252
+253
+254
+255
+256
+257
+258
+259
+260
+261
+262
+263
+264
+265
+266
+267
+268
+269
+270
+271
+272
+273
+274
+275
+276
+277
+278
+279
+280
+281
+282
+283
+284
+285
+286
+287
+288
+289
+290
+291
+292
+293
+294
+295
+296
+297
+298
+299
+300
+301
+302
+303
+304
+305
+306
+307
+308
+309
+310
+311
+312
+313
+314
+315
+316
+317
+318
+319
+320
+321
+322
+323
+324
+325
+326
+327
+328
+329
+330
+331
+332
+333
+334
+335
+336
+337
+338
+339
+340
+341
+342
+343
+344
+345
+346
+347
+348
+349
+350
+351
+352
+353
+354
+355
+356
+357
+358
+359
+360
+361
+362
+363
+364
+365
+366
+367
+368
+369
+370
+371
+372
+373
+374
+375
+376
+377
+378
+379
+380
+381
+382
+383
+384
+385
+386
+387
+388
+389
+390
+391
+392
+393
+394
+395
+396
+397
+398
+399
+400
+401
+402
+403
+404
+405
+406
+407
+408
+409
+410
+411
+412
+413
+414
+415
+416
+417
+418
+419
+420
+421
+422
+423
+424
+425
+426
+427
+428
+429
+430
+431
+432
+433
+434
+435
+436
+437
+438
+439
+440
+441
+442
+443
+444
+445
+446
+447
+448
+449
+450
+451
+452
+453
+454
+455
+456
+457
+458
+459
+460
+461
+462
+463
+464
+465
+466
+467
+468
+469
+470
+471
+472
+473
+474
+475
+476
+477
+478
+479
+480
+481
+482
+483
+484
+485
+486
+487
+488
+489
+490
+491
+492
+493
+494
+495
+496
+497
+498
+499
+500
+501
+502
+503
+504
+505
+506
+507
+508
+509
+510
+511
+512
+513
+514
+515
+516
+517
+518
+519
+520
+521
+522
+523
+524
+525
+526
+527
+528
+529
+530
+531
+532
+533
+534
+535
+536
+537
+538
+539
+540
+541
+542
+543
+544
+545
+546
+547
+548
+549
+550
+551
+552
+553
+554
+555
+556
+557
+558
+559
+560
+561
+562
+563
+564
+565
+566
+567
+568
+569
+570
+571
+572
+573
+574
+575
+576
+577
+578
+579
+580
+581
+582
+583
+584
+585
+586
+587
+588
+589
+590
+591
+592
+593
+594
+595
+596
+597
+598
+599
+600
+601
+602
+603
+604
+605
+606
+607
+608
+609
+610
+611
+612
+613
+614
+615
+616
+617
+618
+619
+620
+621
+622
+623
+624
+625
+626
+627
+628
+629
+630
+631
+632
+633
+634
+635
+636
+637
+638
+639
+640
+641
+642
+643
+644
+645
+646
+647
+648
+649
+650
+651
+652
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
+
+/*
+ *  Copyright (C) 2004 Red Hat, Inc.
+ *
+ *  Caja is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU General Public License as
+ *  published by the Free Software Foundation; either version 2 of the
+ *  License, or (at your option) any later version.
+ *
+ *  Caja is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  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
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ *  Authors: Alexander Larsson <alexl@redhat.com>
+ *
+ */
+
+#include "config.h"
+
+#include <string.h>
+#include <stdio.h>
+
+#include <gtk/gtk.h>
+#include <glib/gi18n.h>
+#include <gio/gio.h>
+
+#include "user_share-private.h"
+
+#define REALM "Please log in as the user guest"
+#define USER "guest"
+#define GSETTINGS_SCHEMA "org.mate.FileSharing"
+#define GSETTINGS_KEY_FILE_SHARING_ENABLED "enabled"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_ENABLED "bluetooth-enabled"
+#define GSETTINGS_KEY_FILE_SHARING_REQUIRE_PASSWORD "require-password"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_ALLOW_WRITE "bluetooth-allow-write"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_REQUIRE_PAIRING "bluetooth-require-pairing"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED "bluetooth-obexpush-enabled"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_ACCEPT_FILES "bluetooth-accept-files"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_NOTIFY "bluetooth-notify"
+
+static GtkBuilder* builder;
+static GSettings* settings;<--- Shadowed declaration<--- Shadowed declaration<--- Shadowed declaration<--- Shadowed declaration<--- Shadowed declaration<--- Shadowed declaration<--- Shadowed declaration<--- Shadowed declaration<--- Shadowed declaration<--- Shadowed declaration
+
+
+static void
+write_out_password (const char *password)
+{
+    char *to_hash;
+    char *ascii_digest;
+    char *line;
+    char *filename;
+    FILE *file;
+
+    to_hash = g_strdup_printf ("%s:%s:%s", USER, REALM, password);
+    ascii_digest = g_compute_checksum_for_string (G_CHECKSUM_MD5, to_hash, strlen (to_hash));
+    g_free (to_hash);
+    line = g_strdup_printf ("%s:%s:%s\n", USER, REALM, ascii_digest);
+    g_free (ascii_digest);
+
+    filename = g_build_filename (g_get_user_config_dir (), "user-share", "passwd", NULL);
+
+    file = fopen (filename, "w");
+    if (file != NULL) {
+	fwrite (line, strlen (line), 1, file);
+	fclose (file);
+    }
+
+    g_free (filename);
+    g_free (line);
+}
+
+static void
+flush_password (void)
+{
+    GtkWidget *password_entry;
+    const char *password;
+
+    password_entry = GTK_WIDGET (gtk_builder_get_object (builder, "password_entry"));
+
+    if (g_object_get_data (G_OBJECT( password_entry), "user_edited")) {
+	password = gtk_entry_get_text (GTK_ENTRY (password_entry));
+	if (password != NULL && password[0] != 0)
+	    write_out_password (password);
+    }
+}
+
+
+static void
+update_ui (void)
+{
+    GSettings *settings;<--- Shadow variable
+    gboolean enabled;
+#ifdef HAVE_BLUETOOTH
+    gboolean bluetooth_enabled, bluetooth_write_enabled, require_pairing_enabled;
+    gboolean bluetooth_obexpush_enabled, bluetooth_obexpush_notify;
+#endif /* HAVE_BLUETOOTH */
+    char *str;
+    PasswordSetting password_setting;
+    AcceptSetting accept_setting;<--- Unused variable: accept_setting
+    GtkWidget *check;
+    GtkWidget *password_combo;
+    GtkWidget *password_entry;
+#ifdef HAVE_BLUETOOTH
+    GtkWidget *vbox_share_bluetooth;
+    GtkWidget *vbox_receive_bluetooth;
+    GtkWidget *bluetooth_check;
+    GtkWidget *allow_write_bluetooth_check;
+    GtkWidget *require_pairing_check;
+    GtkWidget *enable_obexpush_check;
+    GtkWidget *accept_obexpush_combo;
+    GtkWidget *notify_received_obexpush_check;
+#endif /* HAVE_BLUETOOTH */
+
+    settings = g_settings_new (GSETTINGS_SCHEMA);
+
+    enabled = g_settings_get_boolean (settings,
+				     FILE_SHARING_ENABLED);
+
+    str = g_settings_get_string (settings, FILE_SHARING_REQUIRE_PASSWORD);
+    password_setting = password_setting_from_string (str);
+    g_free (str);
+
+#ifdef HAVE_BLUETOOTH
+    bluetooth_enabled = g_settings_get_boolean (settings,
+    					       FILE_SHARING_BLUETOOTH_ENABLED);
+    bluetooth_write_enabled = g_settings_get_boolean (settings,
+						     FILE_SHARING_BLUETOOTH_ALLOW_WRITE);
+    require_pairing_enabled = g_settings_get_boolean (settings,
+    						     FILE_SHARING_BLUETOOTH_REQUIRE_PAIRING);
+    bluetooth_obexpush_enabled = g_settings_get_boolean (settings,
+    							FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED);
+    bluetooth_obexpush_notify = g_settings_get_boolean (settings,
+    						       FILE_SHARING_BLUETOOTH_OBEXPUSH_NOTIFY);
+
+    str = g_settings_get_string (settings, FILE_SHARING_BLUETOOTH_OBEXPUSH_ACCEPT_FILES);
+    accept_setting = accept_setting_from_string (str);
+    g_free (str);
+#endif /* HAVE_BLUETOOTH */
+
+    check = GTK_WIDGET (gtk_builder_get_object (builder, "enable_check"));
+    password_combo = GTK_WIDGET (gtk_builder_get_object (builder, "password_combo"));
+    password_entry = GTK_WIDGET (gtk_builder_get_object (builder, "password_entry"));
+#ifdef HAVE_BLUETOOTH
+    vbox_share_bluetooth = GTK_WIDGET (gtk_builder_get_object (builder, "vbox_share_bluetooth"));
+    vbox_receive_bluetooth = GTK_WIDGET (gtk_builder_get_object (builder, "vbox_receive_bluetooth"));
+    bluetooth_check = GTK_WIDGET (gtk_builder_get_object (builder, "enable_bluetooth_check"));
+    allow_write_bluetooth_check = GTK_WIDGET (gtk_builder_get_object (builder, "allow_write_bluetooth_check"));
+    require_pairing_check = GTK_WIDGET (gtk_builder_get_object (builder, "require_pairing_check"));
+    enable_obexpush_check = GTK_WIDGET (gtk_builder_get_object (builder, "enable_obexpush_check"));
+    accept_obexpush_combo = GTK_WIDGET (gtk_builder_get_object (builder, "accept_obexpush_combo"));
+    notify_received_obexpush_check = GTK_WIDGET (gtk_builder_get_object (builder, "notify_received_obexpush_check"));
+#endif /* HAVE_BLUETOOTH */
+
+    /* Network */
+    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (check), enabled);
+    gtk_widget_set_sensitive (password_combo, enabled);
+    gtk_widget_set_sensitive (password_entry, enabled && password_setting != PASSWORD_NEVER);
+
+    gtk_combo_box_set_active (GTK_COMBO_BOX (password_combo),
+			      password_setting);
+
+#ifdef HAVE_BLUETOOTH
+    /* Bluetooth ObexFTP */
+    gtk_widget_set_visible (vbox_share_bluetooth, TRUE);
+    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (bluetooth_check), bluetooth_enabled);
+    gtk_widget_set_sensitive (allow_write_bluetooth_check, bluetooth_enabled);
+    gtk_widget_set_sensitive (require_pairing_check, bluetooth_enabled);
+
+    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (allow_write_bluetooth_check),
+    				  bluetooth_write_enabled);
+    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (require_pairing_check),
+    				  require_pairing_enabled);
+
+    /* Bluetooth ObexPush */
+    gtk_widget_set_visible (vbox_receive_bluetooth, TRUE);
+    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (enable_obexpush_check), bluetooth_obexpush_enabled);
+    gtk_widget_set_sensitive (accept_obexpush_combo, bluetooth_obexpush_enabled);
+    gtk_widget_set_sensitive (notify_received_obexpush_check, bluetooth_obexpush_enabled);
+
+    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (notify_received_obexpush_check),
+    				  bluetooth_obexpush_notify);
+
+    gtk_combo_box_set_active (GTK_COMBO_BOX (accept_obexpush_combo),
+    			      accept_setting);
+#endif /* HAVE_BLUETOOTH */
+
+    g_object_unref (settings);
+}
+
+static void
+file_sharing_enabled_changed (GSettings *settings, gchar *key, gpointer data)
+{
+    update_ui ();
+}
+
+static void
+password_required_changed (GSettings *settings, gchar *key, gpointer data)
+{
+    update_ui ();
+}
+
+#ifdef HAVE_BLUETOOTH
+static void
+file_sharing_bluetooth_enabled_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	update_ui ();
+}
+
+static void
+file_sharing_bluetooth_allow_write_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	update_ui ();
+}
+
+static void
+file_sharing_bluetooth_require_pairing_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	update_ui ();
+}
+
+static void
+file_sharing_bluetooth_obexpush_enabled_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	update_ui ();
+}
+
+static void
+file_sharing_bluetooth_obexpush_accept_files_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	update_ui ();
+}
+
+static void
+file_sharing_bluetooth_obexpush_notify_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	update_ui ();
+}
+#endif /* HAVE_BLUETOOTH */
+
+static void
+password_combo_changed (GtkComboBox *combo_box)
+{
+    GSettings *settings;<--- Shadow variable
+    guint setting;
+
+    setting = gtk_combo_box_get_active (combo_box);
+
+    settings = g_settings_new (GSETTINGS_SCHEMA) ;
+
+    g_settings_set_string (settings,
+			     FILE_SHARING_REQUIRE_PASSWORD,
+			     password_string_from_setting (setting));
+    g_object_unref (settings);
+}
+
+static void
+launch_share (void)
+{
+	if (!g_spawn_command_line_async (USER_SHARE_PROGRAM, NULL))
+		g_warning ("Unable to start mate-user-share program");
+}
+
+#ifdef HAVE_BLUETOOTH
+static void
+enable_bluetooth_check_toggled (GtkWidget *check)
+{
+	GSettings *settings;<--- Shadow variable
+	gboolean enabled;
+
+	enabled = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check));
+
+	settings = g_settings_new (GSETTINGS_SCHEMA) ;
+
+	g_settings_set_boolean (settings,
+			       FILE_SHARING_BLUETOOTH_ENABLED,
+			       enabled);
+
+	g_object_unref (settings);
+
+	if (enabled != FALSE)
+		launch_share ();
+}
+#endif /* HAVE_BLUETOOTH */
+
+static void
+enable_check_toggled (GtkWidget *check)
+{
+	GSettings *settings;<--- Shadow variable
+	gboolean enabled;
+
+	enabled = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check));
+
+	settings = g_settings_new (GSETTINGS_SCHEMA);
+
+	g_settings_set_boolean (settings,
+			       FILE_SHARING_ENABLED,
+			       enabled);
+
+	g_object_unref (settings);
+
+	if (enabled != FALSE)
+		launch_share ();
+}
+
+static void
+password_entry_changed (GtkEditable *editable)
+{
+	g_object_set_data (G_OBJECT (editable),
+			   "user_edited", GINT_TO_POINTER (1));
+	flush_password ();
+}
+
+#ifdef HAVE_BLUETOOTH
+static void
+bluetooth_allow_write_check_toggled (GtkWidget *check)
+{
+	GSettings *settings;<--- Shadow variable
+	gboolean enabled;
+
+	enabled = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check));
+
+	settings = g_settings_new (GSETTINGS_SCHEMA) ;
+
+	g_settings_set_boolean (settings,
+			       FILE_SHARING_BLUETOOTH_ALLOW_WRITE,
+			       enabled);
+
+	g_object_unref (settings);
+}
+
+static void
+bluetooth_require_pairing_check_toggled (GtkWidget *check)
+{
+	GSettings *settings;<--- Shadow variable
+	gboolean enabled;
+
+	enabled = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check));
+
+	settings = g_settings_new (GSETTINGS_SCHEMA) ;
+
+	g_settings_set_boolean (settings,
+			       FILE_SHARING_BLUETOOTH_REQUIRE_PAIRING,
+			       enabled);
+
+	g_object_unref (settings);
+}
+
+static void
+enable_obexpush_check_toggled (GtkWidget *check)
+{
+	GSettings *settings;<--- Shadow variable
+	gboolean enabled;
+
+	enabled = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check));
+
+	settings = g_settings_new (GSETTINGS_SCHEMA) ;
+
+	g_settings_set_boolean (settings,
+			       FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED,
+			       enabled);
+
+	g_object_unref (settings);
+
+	if (enabled != FALSE)
+		launch_share ();
+}
+
+static void
+accept_obexpush_combo_changed (GtkComboBox *combo_box)
+{
+    GSettings *settings;<--- Shadow variable
+    guint setting;
+
+    setting = gtk_combo_box_get_active (combo_box);
+
+    settings = g_settings_new (GSETTINGS_SCHEMA) ;
+
+    g_settings_set_string (settings,
+			     FILE_SHARING_BLUETOOTH_OBEXPUSH_ACCEPT_FILES,
+			     accept_string_from_setting (setting));
+    g_object_unref (settings);
+}
+
+static void
+notify_received_obexpush_check_toggled (GtkWidget *check)
+{
+	GSettings *settings;<--- Shadow variable
+	gboolean enabled;
+
+	enabled = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check));
+
+	settings = g_settings_new (GSETTINGS_SCHEMA) ;
+
+	g_settings_set_boolean (settings,
+			       FILE_SHARING_BLUETOOTH_OBEXPUSH_NOTIFY,
+			       enabled);
+
+	g_object_unref (settings);
+}
+#endif /* HAVE_BLUETOOTH */
+
+static GtkWidget *
+error_dialog (const char *title,
+	      const char *reason,
+	      GtkWindow *parent)
+{
+	GtkWidget *error_dialog;
+
+	if (reason == NULL)
+		reason = _("No reason");
+
+	error_dialog =
+		gtk_message_dialog_new (parent,
+					GTK_DIALOG_MODAL,
+					GTK_MESSAGE_ERROR,
+					GTK_BUTTONS_OK,
+					"%s", title);
+	gtk_message_dialog_format_secondary_text
+		(GTK_MESSAGE_DIALOG (error_dialog), "%s", reason);
+
+	gtk_window_set_title (GTK_WINDOW (error_dialog), ""); /* as per HIG */
+	gtk_container_set_border_width (GTK_CONTAINER (error_dialog), 5);
+	gtk_dialog_set_default_response (GTK_DIALOG (error_dialog),
+					 GTK_RESPONSE_OK);
+	gtk_window_set_modal (GTK_WINDOW (error_dialog), TRUE);
+
+	return error_dialog;
+}
+
+static void
+help_button_clicked (GtkButton *button, GtkWidget *window)
+{
+	GError *error = NULL;
+
+	if (gtk_show_uri_on_window (GTK_WINDOW (window), "help:mate-user-share", gtk_get_current_event_time (), &error) == FALSE) {
+		GtkWidget *dialog;
+
+		dialog = error_dialog (_("Could not display the help contents."), error->message, GTK_WINDOW (window));
+		g_signal_connect (G_OBJECT (dialog), "response", G_CALLBACK
+				  (gtk_widget_destroy), error_dialog);
+		gtk_window_present (GTK_WINDOW (dialog));
+
+		g_error_free (error);
+	}
+}
+
+static GtkWidget *
+create_window (void)
+{
+    GError *error = NULL;
+    GSettings *settings;<--- Shadow variable
+    GtkWidget *check;
+    GtkWidget *password_combo;
+    GtkWidget *password_entry;
+#ifdef HAVE_BLUETOOTH
+    GtkWidget *bluetooth_check;
+    GtkWidget *bluetooth_allow_write_check;
+    GtkWidget *require_pairing_check;
+    GtkWidget *enable_obexpush_check;
+    GtkWidget *accept_obexpush_combo;
+    GtkWidget *notify_received_obexpush_check;
+#endif /* HAVE_BLUETOOTH */
+    GtkWidget *window;
+    GtkListStore *store;
+    GtkCellRenderer *cell;
+    GtkTreeIter iter;
+
+    builder = gtk_builder_new ();
+    gtk_builder_add_from_file (builder, DATADIR"file-share-properties.ui", &error);
+
+    if (error) {
+      GtkWidget *dialog;
+
+      dialog = error_dialog (_("Could not build interface."), error->message, NULL);
+      gtk_dialog_run (GTK_DIALOG (dialog));
+      gtk_widget_destroy (dialog);
+
+      g_error_free (error);
+      return NULL;
+    }
+
+    window = GTK_WIDGET (gtk_builder_get_object (builder, "user_share_dialog"));
+
+    settings = g_settings_new (GSETTINGS_SCHEMA);
+
+    check = GTK_WIDGET (gtk_builder_get_object (builder, "enable_check"));
+    password_combo = GTK_WIDGET (gtk_builder_get_object (builder, "password_combo"));
+    password_entry = GTK_WIDGET (gtk_builder_get_object (builder, "password_entry"));
+#ifdef HAVE_BLUETOOTH
+    bluetooth_check = GTK_WIDGET (gtk_builder_get_object (builder, "enable_bluetooth_check"));
+    bluetooth_allow_write_check = GTK_WIDGET (gtk_builder_get_object (builder, "allow_write_bluetooth_check"));
+    require_pairing_check = GTK_WIDGET (gtk_builder_get_object (builder, "require_pairing_check"));
+    enable_obexpush_check = GTK_WIDGET (gtk_builder_get_object (builder, "enable_obexpush_check"));
+    accept_obexpush_combo = GTK_WIDGET (gtk_builder_get_object (builder, "accept_obexpush_combo"));
+    notify_received_obexpush_check = GTK_WIDGET (gtk_builder_get_object (builder, "notify_received_obexpush_check"));
+#endif /* HAVE_BLUETOOTH */
+
+    store = gtk_list_store_new (1, G_TYPE_STRING);
+    gtk_combo_box_set_model (GTK_COMBO_BOX (password_combo),
+			     GTK_TREE_MODEL (store));
+    cell = gtk_cell_renderer_text_new ();
+    gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (password_combo), cell, TRUE);
+    gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (password_combo), cell,
+				    "text", 0,
+				    NULL);
+
+    /* Keep in same order as enum */
+    gtk_list_store_append (store, &iter);
+    gtk_list_store_set (store, &iter, 0,
+			_("Never"), -1);
+    gtk_list_store_append (store, &iter);
+    gtk_list_store_set (store, &iter, 0,
+			_("When writing files"), -1);
+    gtk_list_store_append (store, &iter);
+    gtk_list_store_set (store, &iter, 0,
+			_("Always"), -1);
+    g_object_unref (store);
+
+    /* We can't read the password from the text, just set it to something */
+    gtk_entry_set_text (GTK_ENTRY (password_entry), "none");
+    g_object_set_data (G_OBJECT (password_entry),
+		       "user_edited", GINT_TO_POINTER (0));
+    g_signal_connect (password_entry,
+		      "changed", G_CALLBACK (password_entry_changed), NULL);
+
+#ifdef HAVE_BLUETOOTH
+    /* Accept files combo */
+    store = gtk_list_store_new (1, G_TYPE_STRING);
+    gtk_combo_box_set_model (GTK_COMBO_BOX (accept_obexpush_combo),
+			     GTK_TREE_MODEL (store));
+    cell = gtk_cell_renderer_text_new ();
+    gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (accept_obexpush_combo), cell, TRUE);
+    gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (accept_obexpush_combo), cell,
+				    "text", 0,
+				    NULL);
+
+    /* Keep in same order as enum */
+    gtk_list_store_append (store, &iter);
+    gtk_list_store_set (store, &iter, 0,
+			_("Always"), -1);
+    gtk_list_store_append (store, &iter);
+    gtk_list_store_set (store, &iter, 0,
+			_("Only for set up devices"), -1);
+    //FIXME implement
+#if 0
+    gtk_list_store_append (store, &iter);
+    gtk_list_store_set (store, &iter, 0,
+    			_("Ask"), -1);
+#endif
+    g_object_unref (store);
+#endif /* HAVE_BLUETOOTH */
+
+    g_signal_connect (check,
+		      "toggled", G_CALLBACK (enable_check_toggled), NULL);
+    g_signal_connect (password_combo,
+		      "changed", G_CALLBACK (password_combo_changed), NULL);
+#ifdef HAVE_BLUETOOTH
+    g_signal_connect (bluetooth_check,
+    		      "toggled", G_CALLBACK (enable_bluetooth_check_toggled), NULL);
+    g_signal_connect (bluetooth_allow_write_check,
+    		      "toggled", G_CALLBACK (bluetooth_allow_write_check_toggled), NULL);
+    g_signal_connect (require_pairing_check,
+    		      "toggled", G_CALLBACK (bluetooth_require_pairing_check_toggled), NULL);
+    g_signal_connect (enable_obexpush_check,
+    		      "toggled", G_CALLBACK (enable_obexpush_check_toggled), NULL);
+    g_signal_connect (accept_obexpush_combo,
+    		      "changed", G_CALLBACK (accept_obexpush_combo_changed), NULL);
+    g_signal_connect (notify_received_obexpush_check,
+    		      "toggled", G_CALLBACK (notify_received_obexpush_check_toggled), NULL);
+#endif /* HAVE_BLUETOOTH */
+
+    g_signal_connect_swapped (GTK_WIDGET (gtk_builder_get_object (builder, "close_button")),
+                              "clicked", G_CALLBACK (gtk_widget_destroy), window);
+    g_signal_connect (GTK_WIDGET (gtk_builder_get_object (builder, "help_button")),
+		      "clicked", G_CALLBACK (help_button_clicked),
+		      gtk_builder_get_object (builder, "user_share_dialog"));
+
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_ENABLED,
+			     G_CALLBACK (file_sharing_enabled_changed), NULL);
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_REQUIRE_PASSWORD,
+			     G_CALLBACK (password_required_changed), NULL);
+#ifdef HAVE_BLUETOOTH
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_ENABLED,
+			     G_CALLBACK (file_sharing_bluetooth_enabled_changed), NULL);
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_ALLOW_WRITE,
+			     G_CALLBACK (file_sharing_bluetooth_allow_write_changed), NULL);
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_REQUIRE_PAIRING,
+			     G_CALLBACK (file_sharing_bluetooth_require_pairing_changed), NULL);
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED,
+			     G_CALLBACK (file_sharing_bluetooth_obexpush_enabled_changed), NULL);
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_ACCEPT_FILES,
+			     G_CALLBACK (file_sharing_bluetooth_obexpush_accept_files_changed), NULL);
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_NOTIFY,
+			     G_CALLBACK (file_sharing_bluetooth_obexpush_notify_changed), NULL);
+#endif /* HAVE_BLUETOOTH */
+
+    update_ui ();
+
+    return window;
+}
+
+static void
+activate (GtkApplication *app)
+{
+    GList *list;
+    GtkWidget *window;
+
+    list = gtk_application_get_windows (app);
+
+    if (list) {
+        gtk_window_present (GTK_WINDOW (list->data));
+    } else {
+        window = create_window ();
+        gtk_window_set_application (GTK_WINDOW (window), app);
+        gtk_widget_show (window);
+    }
+}
+
+int
+main (int argc, char *argv[])
+{
+    GtkApplication *app;
+    gint status;
+
+    bindtextdomain (GETTEXT_PACKAGE, MATELOCALEDIR);
+    bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
+    textdomain (GETTEXT_PACKAGE);
+
+    app = gtk_application_new ("org.mate.user-share.properties",
+                               G_APPLICATION_FLAGS_NONE);
+    g_signal_connect (app, "activate", G_CALLBACK (activate), NULL);
+
+    status = g_application_run (G_APPLICATION (app), argc, argv);
+
+    g_object_unref (app);
+
+    return status;
+}
+
+
+
+
+ + + diff --git a/2021-05-30-164325-0736-cppcheck@58f05a4efe60_master/1.html b/2021-05-30-164325-0736-cppcheck@58f05a4efe60_master/1.html new file mode 100644 index 0000000..7b20f33 --- /dev/null +++ b/2021-05-30-164325-0736-cppcheck@58f05a4efe60_master/1.html @@ -0,0 +1,1059 @@ + + + + + + Cppcheck - HTML report - mate-user-share + + + + + + +
+ +
+
  1
+  2
+  3
+  4
+  5
+  6
+  7
+  8
+  9
+ 10
+ 11
+ 12
+ 13
+ 14
+ 15
+ 16
+ 17
+ 18
+ 19
+ 20
+ 21
+ 22
+ 23
+ 24
+ 25
+ 26
+ 27
+ 28
+ 29
+ 30
+ 31
+ 32
+ 33
+ 34
+ 35
+ 36
+ 37
+ 38
+ 39
+ 40
+ 41
+ 42
+ 43
+ 44
+ 45
+ 46
+ 47
+ 48
+ 49
+ 50
+ 51
+ 52
+ 53
+ 54
+ 55
+ 56
+ 57
+ 58
+ 59
+ 60
+ 61
+ 62
+ 63
+ 64
+ 65
+ 66
+ 67
+ 68
+ 69
+ 70
+ 71
+ 72
+ 73
+ 74
+ 75
+ 76
+ 77
+ 78
+ 79
+ 80
+ 81
+ 82
+ 83
+ 84
+ 85
+ 86
+ 87
+ 88
+ 89
+ 90
+ 91
+ 92
+ 93
+ 94
+ 95
+ 96
+ 97
+ 98
+ 99
+100
+101
+102
+103
+104
+105
+106
+107
+108
+109
+110
+111
+112
+113
+114
+115
+116
+117
+118
+119
+120
+121
+122
+123
+124
+125
+126
+127
+128
+129
+130
+131
+132
+133
+134
+135
+136
+137
+138
+139
+140
+141
+142
+143
+144
+145
+146
+147
+148
+149
+150
+151
+152
+153
+154
+155
+156
+157
+158
+159
+160
+161
+162
+163
+164
+165
+166
+167
+168
+169
+170
+171
+172
+173
+174
+175
+176
+177
+178
+179
+180
+181
+182
+183
+184
+185
+186
+187
+188
+189
+190
+191
+192
+193
+194
+195
+196
+197
+198
+199
+200
+201
+202
+203
+204
+205
+206
+207
+208
+209
+210
+211
+212
+213
+214
+215
+216
+217
+218
+219
+220
+221
+222
+223
+224
+225
+226
+227
+228
+229
+230
+231
+232
+233
+234
+235
+236
+237
+238
+239
+240
+241
+242
+243
+244
+245
+246
+247
+248
+249
+250
+251
+252
+253
+254
+255
+256
+257
+258
+259
+260
+261
+262
+263
+264
+265
+266
+267
+268
+269
+270
+271
+272
+273
+274
+275
+276
+277
+278
+279
+280
+281
+282
+283
+284
+285
+286
+287
+288
+289
+290
+291
+292
+293
+294
+295
+296
+297
+298
+299
+300
+301
+302
+303
+304
+305
+306
+307
+308
+309
+310
+311
+312
+313
+314
+315
+316
+317
+318
+319
+320
+321
+322
+323
+324
+325
+326
+327
+328
+329
+330
+331
+332
+333
+334
+335
+336
+337
+338
+339
+340
+341
+342
+343
+344
+345
+346
+347
+348
+349
+350
+351
+352
+353
+354
+355
+356
+357
+358
+359
+360
+361
+362
+363
+364
+365
+366
+367
+368
+369
+370
+371
+372
+373
+374
+375
+376
+377
+378
+379
+380
+381
+382
+383
+384
+385
+386
+387
+388
+389
+390
+391
+392
+393
+394
+395
+396
+397
+398
+399
+400
+401
+402
+403
+404
+405
+406
+407
+408
+409
+410
+411
+412
+413
+414
+415
+416
+417
+418
+419
+420
+421
+422
+423
+424
+425
+426
+427
+428
+429
+430
+431
+432
+433
+434
+435
+436
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
+
+/*
+ *  Copyright (C) 2004-2008 Red Hat, Inc.
+ *
+ *  Caja is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU General Public License as
+ *  published by the Free Software Foundation; either version 2 of the
+ *  License, or (at your option) any later version.
+ *
+ *  Caja is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  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
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ *  Authors: Alexander Larsson <alexl@redhat.com>
+ *
+ */
+
+#include "config.h"
+
+#include <glib.h>
+#include <glib/gi18n.h>
+#include <X11/Xlib.h>
+
+#include <gio/gio.h>
+
+#include <stdarg.h>
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <signal.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <sys/stat.h>
+
+#ifdef HAVE_SELINUX
+#include <selinux/selinux.h>
+#endif
+
+#include "user_share-common.h"
+#include "user_share-private.h"
+#include "http.h"
+
+/* From avahi-common/domain.h */
+#define AVAHI_LABEL_MAX 64
+
+#define GSETTINGS_SCHEMA "org.mate.FileSharing"
+
+static pid_t httpd_pid = 0;
+
+static int
+get_port (void)
+{
+	int sock;
+	struct sockaddr_in addr;
+	int reuse;
+	socklen_t len;
+
+	sock = socket (PF_INET, SOCK_STREAM, 0);
+	if (sock < 0) {
+		return -1;
+	}
+
+	memset (&addr, 0, sizeof (addr));
+	addr.sin_port = 0;
+	addr.sin_addr.s_addr = INADDR_ANY;
+	addr.sin_family = AF_INET;
+
+	reuse = 1;
+	setsockopt (sock, SOL_SOCKET, SO_REUSEADDR, &reuse, sizeof (reuse));
+	if (bind (sock, (struct sockaddr *)&addr, sizeof (addr)) == -1) {
+		close (sock);
+		return -1;
+	}
+
+	len = sizeof (addr);
+	if (getsockname (sock, (struct sockaddr *)&addr, &len) == -1) {
+		close (sock);
+		return -1;
+	}
+
+#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__APPLE__) || defined(__OpenBSD__)
+	/* XXX This exposes a potential race condition, but without this,
+	 * httpd will not start on the above listed platforms due to the fact
+	 * that SO_REUSEADDR is also needed when Apache binds to the listening
+	 * socket.  At this time, Apache does not support that socket option.
+	 */
+	close (sock);
+#endif
+	return ntohs (addr.sin_port);
+}
+
+static char *
+truncate_name (const char *name)
+{
+	const char *end;
+
+	end = g_utf8_find_prev_char (name, name + 64);
+	g_assert (end != NULL);
+	return g_strndup (name, end - name);
+}
+
+static char *
+get_share_name (void)
+{
+	static char *name = NULL;
+	const char *host_name;
+	char *str;
+
+	if (name == NULL) {
+		host_name = g_get_host_name ();
+		if (strcmp (host_name, "localhost") == 0) {
+			/* Translators: The %s will get filled in with the user name
+			   of the user, to form a genitive. If this is difficult to
+			   translate correctly so that it will work correctly in your
+			   language, you may use something equivalent to
+			   "Public files of %s", or leave out the %s altogether.
+			   In the latter case, please put "%.0s" somewhere in the string,
+			   which will match the user name string passed by the C code,
+			   but not put the user name in the final string. This is to
+			   avoid the warning that msgfmt might otherwise generate. */
+			name = g_strdup_printf (_("%s's public files"), g_get_user_name ());
+		} else {
+			/* Translators: This is similar to the string before, only it
+			   has the hostname in it too. */
+			name = g_strdup_printf (_("%s's public files on %s"),
+						g_get_user_name (),
+						host_name);
+		}
+
+	}
+	/* And truncate */
+	if (strlen (name) < AVAHI_LABEL_MAX)
+		return name;
+
+	str = truncate_name (name);
+	g_free (name);
+	name = str;
+
+	return name;
+}
+
+static void
+ensure_conf_dir (void)
+{
+	char *dirname;
+
+	dirname = g_build_filename (g_get_user_config_dir (), "user-share", NULL);
+	g_mkdir_with_parents (dirname, 0755);
+	g_free (dirname);
+}
+
+static void
+httpd_child_setup (gpointer user_data)
+{
+#ifdef HAVE_SELINUX
+	char *mycon;
+	/* If selinux is enabled, avoid transitioning to the httpd_t context,
+	   as this normally means you can't read the users homedir. */
+	if (is_selinux_enabled()) {
+		if (getcon (&mycon) < 0) {
+			abort ();
+		}
+		if (setexeccon (mycon) < 0)
+			abort ();
+		freecon (mycon);
+	}
+#endif
+}
+
+static const char *known_httpd_locations [] = {
+	HTTPD_PROGRAM,
+	"/usr/sbin/httpd",
+	"/usr/sbin/httpd2",
+	"/usr/sbin/apache2",
+	NULL
+};
+
+static char*
+get_httpd_program (void)
+{
+	int i;
+
+	for (i = 0; known_httpd_locations[i]; i++) {
+		if (known_httpd_locations[i][0] == '\0') {
+			/* empty string as first element, happens when
+			 * configured --with-httpd=auto */
+			continue;
+		}
+		if (g_file_test (known_httpd_locations[i], G_FILE_TEST_IS_EXECUTABLE)
+				&& ! g_file_test (known_httpd_locations[i], G_FILE_TEST_IS_DIR)) {
+			return g_strdup (known_httpd_locations[i]);
+		}
+	}
+	return NULL;
+}
+
+static const char *known_httpd_modules_locations [] = {
+	HTTPD_MODULES_PATH,
+	"/etc/httpd/modules",
+	"/usr/lib/apache2/modules",
+	NULL
+};
+
+static gchar*
+get_httpd_modules_path (void)
+{
+	int i;
+
+	for (i = 0; known_httpd_modules_locations[i]; i++) {
+		if (known_httpd_modules_locations[i][0] == '\0') {
+			/* empty string as first element, happens when
+			 * configured --with-httpd=auto */
+			continue;
+		}
+		if (g_file_test (known_httpd_modules_locations[i], G_FILE_TEST_IS_EXECUTABLE)
+				&& g_file_test (known_httpd_modules_locations[i], G_FILE_TEST_IS_DIR)) {
+			return g_strdup (known_httpd_modules_locations[i]);
+		}
+	}
+	return NULL;
+}
+
+static GRegex *version_regex = NULL;
+
+static char*
+get_httpd_config (const char *httpd_program)
+{
+	gchar *standard_output;
+	gchar *cmd_line;
+	GMatchInfo *match_info;
+	gchar *version_number = NULL;
+	gchar *config;
+
+	cmd_line = g_strdup_printf ("%s -v", httpd_program);
+	if (! g_spawn_command_line_sync (cmd_line, &standard_output, NULL, NULL, NULL)) {
+		g_free (cmd_line);
+		return NULL;
+	}
+	g_free (cmd_line);
+
+	if (version_regex == NULL) {
+		version_regex = g_regex_new ("\\d\\.\\d", 0, 0, NULL);
+	}
+
+	if (g_regex_match (version_regex, standard_output, 0, &match_info)) {
+		while (g_match_info_matches (match_info)) {
+			version_number = g_match_info_fetch (match_info, 0);
+			break;
+		}
+		g_match_info_free (match_info);
+		g_free (standard_output);
+	} else {
+		/* Failed to parse httpd version number */
+		g_warning ("Could not parse '%s' as a version for httpd", standard_output);
+		g_free (standard_output);
+		/* assume it is 2.2 */
+		version_number = g_strdup ("2.2");
+	}
+
+	config = g_strdup_printf (HTTPD_CONFIG_TEMPLATE, version_number);
+	g_free (version_number);
+
+	return config;
+}
+
+static gboolean
+spawn_httpd (int port, pid_t *pid_out)
+{
+	char *free1, *free2, *free3, *free4, *free5, *free6, *free7, *free8, *free9;
+	gboolean res;
+	char *argv[10];
+	char *env[10];
+	int i;
+	gint status;
+	char *pid_filename;
+	char *pidfile;
+	GError *error;
+	gboolean got_pidfile;
+	GSettings *settings;
+	char *str;
+	char *public_dir;
+
+	public_dir = lookup_public_dir ();
+	ensure_conf_dir ();
+
+	i = 0;
+	free1 = argv[i++] = get_httpd_program ();
+	if (argv[0] == NULL) {
+		fprintf (stderr, "error finding httpd server\n");
+		return FALSE;
+	}
+
+	argv[i++] = "-f";
+	free2 = argv[i++] = get_httpd_config (argv[0]);
+	argv[i++] = "-C";
+	free3 = argv[i++] = g_strdup_printf ("Listen %d", port);
+
+	settings = g_settings_new (GSETTINGS_SCHEMA);
+	str = g_settings_get_string (settings,
+				       FILE_SHARING_REQUIRE_PASSWORD);
+
+	if (str && strcmp (str, "never") == 0) {
+		/* Do nothing */
+	} else if (str && strcmp (str, "on_write") == 0){
+		argv[i++] = "-D";
+		argv[i++] = "RequirePasswordOnWrite";
+	} else {
+		/* always, or safe fallback */
+		argv[i++] = "-D";
+		argv[i++] = "RequirePasswordAlways";
+	}
+	g_free (str);
+	g_object_unref (settings);
+
+	argv[i] = NULL;
+
+	i = 0;
+	free4 = env[i++] = g_strdup_printf ("HOME=%s", g_get_home_dir());
+	free5 = env[i++] = g_strdup_printf ("XDG_PUBLICSHARE_DIR=%s", public_dir);
+	free6 = env[i++] = g_strdup_printf ("XDG_CONFIG_HOME=%s", g_get_user_config_dir ());
+	free7 = env[i++] = g_strdup_printf ("GUS_SHARE_NAME=%s", get_share_name ());
+	free8 = env[i++] = g_strdup_printf ("GUS_LOGIN_LABEL=%s", "Please log in as the user guest");
+	free9 = env[i++] = g_strdup_printf ("HTTP_MODULES_PATH=%s",get_httpd_modules_path ());
+	env[i++] = "LANG=C";
+	env[i] = NULL;
+
+	pid_filename = g_build_filename (g_get_user_config_dir (), "user-share", "pid", NULL);
+
+	/* Remove pid file before spawning to avoid races with child and old pidfile */
+	unlink (pid_filename);
+
+	error = NULL;
+	res = g_spawn_sync (g_get_home_dir(),
+			    argv, env, 0,
+			    httpd_child_setup, NULL,
+			    NULL, NULL,
+			    &status,
+			    &error);
+	g_free (free1);
+	g_free (free2);
+	g_free (free3);
+	g_free (free4);
+	g_free (free5);
+	g_free (free6);
+	g_free (free7);
+	g_free (free8);
+	g_free (free9);
+	g_free (public_dir);
+
+	if (!res) {
+		fprintf (stderr, "error spawning httpd: %s\n",
+			 error->message);
+		g_error_free (error);
+		g_free (pid_filename);
+		return FALSE;
+	}
+
+	if (status != 0) {
+		g_free (pid_filename);
+		return FALSE;
+	}
+
+	got_pidfile = FALSE;
+	error = NULL;
+	for (i = 0; i < 5; i++) {
+		if (error != NULL)
+			g_error_free (error);
+		error = NULL;
+		if (g_file_get_contents (pid_filename, &pidfile, NULL, &error)) {
+			got_pidfile = TRUE;
+			*pid_out = atoi (pidfile);
+			g_free (pidfile);
+			break;
+		}
+		sleep (1);
+	}
+
+	g_free (pid_filename);
+
+	if (!got_pidfile) {
+		fprintf (stderr, "error opening httpd pidfile: %s\n", error->message);
+		g_error_free (error);
+		return FALSE;
+	}
+	return TRUE;
+}
+
+static void
+kill_httpd (void)
+{
+	if (httpd_pid != 0) {
+		kill (httpd_pid, SIGTERM);
+
+		/* Allow child time to die, we can't waitpid, because its
+		   not a direct child */
+		sleep (1);
+	}
+	httpd_pid = 0;
+}
+
+void
+http_up (void)
+{
+	guint port;
+
+	port = get_port ();
+	if (!spawn_httpd (port, &httpd_pid)) {
+		fprintf (stderr, "spawning httpd failed\n");
+	}
+}
+
+void
+http_down (void)
+{
+	kill_httpd ();
+}
+
+gboolean
+http_init (void)
+{
+	return TRUE;
+}
+
+pid_t
+http_get_pid (void)
+{
+	return httpd_pid;
+}
+
+
+
+
+ + + diff --git a/2021-05-30-164325-0736-cppcheck@58f05a4efe60_master/2.html b/2021-05-30-164325-0736-cppcheck@58f05a4efe60_master/2.html new file mode 100644 index 0000000..f8d5c03 --- /dev/null +++ b/2021-05-30-164325-0736-cppcheck@58f05a4efe60_master/2.html @@ -0,0 +1,1293 @@ + + + + + + Cppcheck - HTML report - mate-user-share + + + + + + +
+ +
+
  1
+  2
+  3
+  4
+  5
+  6
+  7
+  8
+  9
+ 10
+ 11
+ 12
+ 13
+ 14
+ 15
+ 16
+ 17
+ 18
+ 19
+ 20
+ 21
+ 22
+ 23
+ 24
+ 25
+ 26
+ 27
+ 28
+ 29
+ 30
+ 31
+ 32
+ 33
+ 34
+ 35
+ 36
+ 37
+ 38
+ 39
+ 40
+ 41
+ 42
+ 43
+ 44
+ 45
+ 46
+ 47
+ 48
+ 49
+ 50
+ 51
+ 52
+ 53
+ 54
+ 55
+ 56
+ 57
+ 58
+ 59
+ 60
+ 61
+ 62
+ 63
+ 64
+ 65
+ 66
+ 67
+ 68
+ 69
+ 70
+ 71
+ 72
+ 73
+ 74
+ 75
+ 76
+ 77
+ 78
+ 79
+ 80
+ 81
+ 82
+ 83
+ 84
+ 85
+ 86
+ 87
+ 88
+ 89
+ 90
+ 91
+ 92
+ 93
+ 94
+ 95
+ 96
+ 97
+ 98
+ 99
+100
+101
+102
+103
+104
+105
+106
+107
+108
+109
+110
+111
+112
+113
+114
+115
+116
+117
+118
+119
+120
+121
+122
+123
+124
+125
+126
+127
+128
+129
+130
+131
+132
+133
+134
+135
+136
+137
+138
+139
+140
+141
+142
+143
+144
+145
+146
+147
+148
+149
+150
+151
+152
+153
+154
+155
+156
+157
+158
+159
+160
+161
+162
+163
+164
+165
+166
+167
+168
+169
+170
+171
+172
+173
+174
+175
+176
+177
+178
+179
+180
+181
+182
+183
+184
+185
+186
+187
+188
+189
+190
+191
+192
+193
+194
+195
+196
+197
+198
+199
+200
+201
+202
+203
+204
+205
+206
+207
+208
+209
+210
+211
+212
+213
+214
+215
+216
+217
+218
+219
+220
+221
+222
+223
+224
+225
+226
+227
+228
+229
+230
+231
+232
+233
+234
+235
+236
+237
+238
+239
+240
+241
+242
+243
+244
+245
+246
+247
+248
+249
+250
+251
+252
+253
+254
+255
+256
+257
+258
+259
+260
+261
+262
+263
+264
+265
+266
+267
+268
+269
+270
+271
+272
+273
+274
+275
+276
+277
+278
+279
+280
+281
+282
+283
+284
+285
+286
+287
+288
+289
+290
+291
+292
+293
+294
+295
+296
+297
+298
+299
+300
+301
+302
+303
+304
+305
+306
+307
+308
+309
+310
+311
+312
+313
+314
+315
+316
+317
+318
+319
+320
+321
+322
+323
+324
+325
+326
+327
+328
+329
+330
+331
+332
+333
+334
+335
+336
+337
+338
+339
+340
+341
+342
+343
+344
+345
+346
+347
+348
+349
+350
+351
+352
+353
+354
+355
+356
+357
+358
+359
+360
+361
+362
+363
+364
+365
+366
+367
+368
+369
+370
+371
+372
+373
+374
+375
+376
+377
+378
+379
+380
+381
+382
+383
+384
+385
+386
+387
+388
+389
+390
+391
+392
+393
+394
+395
+396
+397
+398
+399
+400
+401
+402
+403
+404
+405
+406
+407
+408
+409
+410
+411
+412
+413
+414
+415
+416
+417
+418
+419
+420
+421
+422
+423
+424
+425
+426
+427
+428
+429
+430
+431
+432
+433
+434
+435
+436
+437
+438
+439
+440
+441
+442
+443
+444
+445
+446
+447
+448
+449
+450
+451
+452
+453
+454
+455
+456
+457
+458
+459
+460
+461
+462
+463
+464
+465
+466
+467
+468
+469
+470
+471
+472
+473
+474
+475
+476
+477
+478
+479
+480
+481
+482
+483
+484
+485
+486
+487
+488
+489
+490
+491
+492
+493
+494
+495
+496
+497
+498
+499
+500
+501
+502
+503
+504
+505
+506
+507
+508
+509
+510
+511
+512
+513
+514
+515
+516
+517
+518
+519
+520
+521
+522
+523
+524
+525
+526
+527
+528
+529
+530
+531
+532
+533
+534
+535
+536
+537
+538
+539
+540
+541
+542
+543
+544
+545
+546
+547
+548
+549
+550
+551
+552
+553
+554
+555
+556
+557
+558
+559
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
+
+/*
+ *  Copyright (C) 2004-2008 Red Hat, Inc.
+ *
+ *  Caja is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU General Public License as
+ *  published by the Free Software Foundation; either version 2 of the
+ *  License, or (at your option) any later version.
+ *
+ *  Caja is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  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
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ *  Authors: Bastien Nocera <hadess@hadess.net>
+ *
+ */
+
+#include "config.h"
+
+#include <glib.h>
+#include <glib/gi18n.h>
+#include <gio/gio.h>
+#include <gdk/gdk.h>
+#include <gtk/gtk.h>
+#include <libnotify/notify.h>
+#include <dbus/dbus-glib.h>
+#include <dbus/dbus-glib-lowlevel.h>
+#include <canberra-gtk.h>
+
+#include <string.h>
+
+#include "marshal.h"
+#include "obexpush.h"
+#include "user_share-common.h"
+#include "user_share-private.h"
+
+#define DBUS_TYPE_G_STRING_VARIANT_HASHTABLE (dbus_g_type_get_map ("GHashTable", G_TYPE_STRING, G_TYPE_STRING))
+
+#define GSETTINGS_SCHEMA "org.mate.FileSharing"
+
+static DBusGConnection *connection = NULL;<--- Shadowed declaration
+static DBusGProxy *manager_proxy = NULL;
+static DBusGProxy *server_proxy = NULL;
+static AcceptSetting accept_setting = -1;
+static gboolean show_notifications = FALSE;
+
+static GtkStatusIcon *statusicon = NULL;
+static guint num_notifications = 0;
+
+static void
+hide_statusicon (void)
+{
+	num_notifications--;
+	if (num_notifications == 0)
+		gtk_status_icon_set_visible (statusicon, FALSE);
+}
+
+static void
+on_close_notification (NotifyNotification *notification)
+{
+	hide_statusicon ();
+	g_object_unref (notification);
+}
+
+static void
+notification_launch_action_on_file_cb (NotifyNotification *notification,
+				       const char *action,
+				       const char *file_uri)
+{
+	GdkScreen *screen;
+	GAppLaunchContext *ctx;
+	GTimeVal val;
+
+	g_assert (action != NULL);
+
+	g_get_current_time (&val);
+
+	ctx = G_APP_LAUNCH_CONTEXT (gdk_app_launch_context_new ());
+	screen = gdk_screen_get_default ();
+	gdk_app_launch_context_set_screen (GDK_APP_LAUNCH_CONTEXT (ctx), screen);
+	gdk_app_launch_context_set_timestamp (GDK_APP_LAUNCH_CONTEXT (ctx), val.tv_sec);
+
+	/* We launch the file viewer for the file */
+	if (g_str_equal (action, "display") != FALSE) {
+		if (g_app_info_launch_default_for_uri (file_uri, ctx, NULL) == FALSE) {
+			g_warning ("Failed to launch the file viewer\n");
+		}
+	}
+
+	/* we open the Downloads folder */
+	if (g_str_equal (action, "reveal") != FALSE) {
+		GFile *file;
+		GFile *parent;
+		gchar *parent_uri;
+
+		file = g_file_new_for_uri (file_uri);
+		parent = g_file_get_parent (file);
+		parent_uri = g_file_get_uri (parent);
+		g_object_unref (file);
+		g_object_unref (parent);
+
+		if (!g_app_info_launch_default_for_uri (parent_uri, ctx, NULL)) {
+			g_warning ("Failed to launch the file manager\n");
+		}
+
+		g_free (parent_uri);
+	}
+
+	notify_notification_close (notification, NULL);
+	/* No need to call hide_statusicon(), closing the notification
+	 * will call the close callback */
+}
+
+static void
+show_notification (const char *filename)
+{
+	char *file_uri, *notification_text, *display, *mime_type;
+	NotifyNotification *notification;
+	ca_context *ctx;
+	GAppInfo *app;
+
+	file_uri = g_filename_to_uri (filename, NULL, NULL);
+	if (file_uri == NULL) {
+		g_warning ("Could not make a filename from '%s'", filename);
+		return;
+	}
+
+	display = g_filename_display_basename (filename);
+	/* Translators: %s is the name of the filename received */
+	notification_text = g_strdup_printf(_("You received \"%s\" via Bluetooth"), display);
+	g_free (display);
+	notification = notify_notification_new (_("You received a file"),
+								 notification_text,
+								 "dialog-information");
+
+	notify_notification_set_timeout (notification, NOTIFY_EXPIRES_DEFAULT);
+
+	mime_type = g_content_type_guess (filename, NULL, 0, NULL);
+	app = g_app_info_get_default_for_type (mime_type, FALSE);
+	if (app != NULL) {
+		g_object_unref (app);
+		notify_notification_add_action (notification, "display", _("Open File"),
+						(NotifyActionCallback) notification_launch_action_on_file_cb,
+						g_strdup (file_uri), (GFreeFunc) g_free);
+	}
+	notify_notification_add_action (notification, "reveal", _("Reveal File"),
+					(NotifyActionCallback) notification_launch_action_on_file_cb,
+					g_strdup (file_uri), (GFreeFunc) g_free);
+
+	g_free (file_uri);
+
+	g_signal_connect (G_OBJECT (notification), "closed", G_CALLBACK (on_close_notification), notification);
+
+	if (!notify_notification_show (notification, NULL)) {
+		g_warning ("failed to send notification\n");
+	}
+	g_free (notification_text);
+
+	/* Now we do the audio notification */
+	ctx = ca_gtk_context_get ();
+	ca_context_play (ctx, 0,
+			 CA_PROP_EVENT_ID, "complete-download",
+			 CA_PROP_EVENT_DESCRIPTION, _("File reception complete"),
+			 NULL);
+}
+
+static void
+show_icon (void)
+{
+	if (statusicon == NULL) {
+		statusicon = gtk_status_icon_new_from_icon_name ("mate-obex-server");
+	} else {
+		gtk_status_icon_set_visible (statusicon, TRUE);
+	}
+	num_notifications++;
+}
+
+static gboolean
+device_is_authorised (const char *bdaddr)
+{
+	DBusGConnection *connection;<--- Shadow variable
+	DBusGProxy *manager;
+	GError *error = NULL;
+	GPtrArray *adapters;
+	gboolean retval = FALSE;
+	guint i;
+
+	connection = dbus_g_bus_get (DBUS_BUS_SYSTEM, NULL);
+	if (connection == NULL)
+		return FALSE;
+
+	manager = dbus_g_proxy_new_for_name (connection, "org.bluez",
+					     "/", "org.bluez.Manager");
+	if (manager == NULL) {
+		dbus_g_connection_unref (connection);
+		return FALSE;
+	}
+
+	if (dbus_g_proxy_call (manager, "ListAdapters", &error, G_TYPE_INVALID, dbus_g_type_get_collection ("GPtrArray", DBUS_TYPE_G_OBJECT_PATH), &adapters, G_TYPE_INVALID) == FALSE) {
+		g_object_unref (manager);
+		dbus_g_connection_unref (connection);
+		return FALSE;
+	}
+
+	for (i = 0; i < adapters->len; i++) {
+		DBusGProxy *adapter, *device;
+		char *device_path;
+		GHashTable *props;
+
+		g_debug ("checking adapter %s", (gchar *) g_ptr_array_index (adapters, i));
+
+		adapter = dbus_g_proxy_new_for_name (connection, "org.bluez",
+						    g_ptr_array_index (adapters, i), "org.bluez.Adapter");
+
+		if (dbus_g_proxy_call (adapter, "FindDevice", NULL,
+				       G_TYPE_STRING, bdaddr, G_TYPE_INVALID,
+				       DBUS_TYPE_G_OBJECT_PATH, &device_path, G_TYPE_INVALID) == FALSE)
+		{
+			g_object_unref (adapter);
+			continue;
+		}
+
+		device = dbus_g_proxy_new_for_name (connection, "org.bluez", device_path, "org.bluez.Device");
+
+		if (dbus_g_proxy_call (device, "GetProperties", NULL,
+				       G_TYPE_INVALID, dbus_g_type_get_map ("GHashTable", G_TYPE_STRING, G_TYPE_VALUE),
+				       &props, G_TYPE_INVALID) != FALSE)
+		{
+			GValue *value;
+			gboolean bonded;
+
+			value = g_hash_table_lookup (props, "Paired");
+			bonded = g_value_get_boolean (value);
+			g_message ("%s is %s", bdaddr, bonded ? "bonded" : "not bonded");
+
+			if (bonded) {
+				g_hash_table_destroy (props);
+				g_object_unref (device);
+				g_object_unref (adapter);
+				retval = TRUE;
+				break;
+			}
+		}
+		g_object_unref(adapter);
+	}
+
+	g_ptr_array_free (adapters, TRUE);
+
+	g_object_unref(manager);
+	dbus_g_connection_unref(connection);
+
+	return retval;
+}
+
+static void
+transfer_started_cb (DBusGProxy *session,
+		     const char *filename,
+		     const char *local_path,
+		     guint64 size,
+		     gpointer user_data)
+{
+	GHashTable *dict;
+	DBusGProxy *server = (DBusGProxy *) user_data;
+	GError *error = NULL;
+	gboolean authorise;
+
+	g_message ("transfer started on %s", local_path);
+	g_object_set_data_full (G_OBJECT (session), "filename", g_strdup (local_path), (GDestroyNotify) g_free);
+
+	show_icon ();
+
+	/* First transfer of the session */
+	if (g_object_get_data (G_OBJECT (session), "bdaddr") == NULL) {
+		const char *bdaddr;
+
+		if (dbus_g_proxy_call (server, "GetServerSessionInfo", &error,
+				       DBUS_TYPE_G_OBJECT_PATH, dbus_g_proxy_get_path (session), G_TYPE_INVALID,
+				       DBUS_TYPE_G_STRING_VARIANT_HASHTABLE, &dict, G_TYPE_INVALID) == FALSE) {
+			g_printerr ("Getting Server session info failed: %s\n",
+				    error->message);
+			g_error_free (error);
+			return;
+		}
+
+		bdaddr = g_hash_table_lookup (dict, "BluetoothAddress");
+		g_message ("transfer started for device %s", bdaddr);
+
+		g_object_set_data_full (G_OBJECT (session), "bdaddr", g_strdup (bdaddr), (GDestroyNotify) g_free);
+		/* Initial accept method is undefined, we do that lower down */
+		g_object_set_data (G_OBJECT (session), "accept-method", GINT_TO_POINTER (-1));
+		g_hash_table_destroy (dict);
+	}
+
+	/* Accept method changed */
+	if (GPOINTER_TO_INT (g_object_get_data (G_OBJECT (session), "accept-method")) != accept_setting) {
+		const char *bdaddr;
+
+		bdaddr = g_object_get_data (G_OBJECT (session), "bdaddr");
+
+		if (bdaddr == NULL) {
+			g_warning ("Couldn't get the Bluetooth address for the device, rejecting the transfer");
+			authorise = FALSE;
+		} else if (accept_setting == ACCEPT_ALWAYS) {
+			authorise = TRUE;
+		} else if (accept_setting == ACCEPT_BONDED) {
+			authorise = device_is_authorised (bdaddr);
+		} else {
+			//FIXME implement
+			g_warning ("\"Ask\" authorisation method not implemented");
+			authorise = FALSE;
+		}
+		g_object_set_data (G_OBJECT (session), "authorise", GINT_TO_POINTER (authorise));
+	}
+
+	g_message ("accept_setting: %d", accept_setting);
+
+	authorise = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (session), "authorise"));
+	if (authorise != FALSE) {
+		if (dbus_g_proxy_call (session, "Accept", &error, G_TYPE_INVALID, G_TYPE_INVALID) == FALSE) {
+			g_printerr ("Failed to accept file transfer: %s\n", error->message);
+			g_error_free (error);
+			return;
+		}
+		g_message ("authorised transfer");
+	} else {
+		if (dbus_g_proxy_call (session, "Reject", &error, G_TYPE_INVALID, G_TYPE_INVALID) == FALSE) {
+			g_printerr ("Failed to reject file transfer: %s\n", error->message);
+			g_error_free (error);
+			return;
+		}
+		g_message ("rejected transfer");
+		g_object_set_data (G_OBJECT (session), "filename", NULL);
+	}
+}
+
+static void
+transfer_completed_cb (DBusGProxy *session,
+		       gpointer user_data)
+{
+	GSettings *settings;
+	gboolean display_notify;
+	const char *filename;
+
+	filename = (const char *) g_object_get_data (G_OBJECT (session), "filename");
+
+	g_message ("file finish transfer: %s", filename);
+
+	if (filename == NULL)
+		return;
+
+	settings = g_settings_new (GSETTINGS_SCHEMA);
+	display_notify = g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_OBEXPUSH_NOTIFY);
+	g_object_unref (settings);
+
+	if (display_notify) {
+		show_notification (filename);
+	} else {
+		hide_statusicon ();
+	}
+	g_object_set_data (G_OBJECT (session), "filename", NULL);
+}
+
+static void
+cancelled_cb (DBusGProxy *session,
+	      gpointer user_data)
+{
+	//FIXME implement properly, we never actually finished the transfer
+	g_message ("transfered was cancelled by the sender");
+	transfer_completed_cb (session, user_data);
+	hide_statusicon ();
+}
+
+static void
+error_occurred_cb (DBusGProxy *session,
+		   const char *error_name,
+		   const char *error_message,
+		   gpointer user_data)
+{
+	//FIXME implement properly
+	g_message ("transfer error occurred: %s", error_message);
+	transfer_completed_cb (session, user_data);
+}
+
+static void
+session_created_cb (DBusGProxy *server, const char *session_path, gpointer user_data)
+{
+	DBusGProxy *session;
+
+	session = dbus_g_proxy_new_for_name (connection,
+					     "org.openobex",
+					     session_path,
+					     "org.openobex.ServerSession");
+
+	dbus_g_proxy_add_signal (session, "TransferStarted",
+				 G_TYPE_STRING, G_TYPE_STRING, G_TYPE_UINT64, G_TYPE_INVALID);
+	dbus_g_proxy_connect_signal(session, "TransferStarted",
+				    G_CALLBACK (transfer_started_cb), server, NULL);
+	dbus_g_proxy_add_signal (session, "TransferCompleted",
+				 G_TYPE_INVALID, G_TYPE_INVALID);
+	dbus_g_proxy_connect_signal(session, "TransferCompleted",
+				    G_CALLBACK (transfer_completed_cb), server, NULL);
+	dbus_g_proxy_add_signal (session, "Cancelled",
+				 G_TYPE_INVALID, G_TYPE_INVALID);
+	dbus_g_proxy_connect_signal(session, "Cancelled",
+				    G_CALLBACK (cancelled_cb), server, NULL);
+	dbus_g_proxy_add_signal (session, "ErrorOccurred",
+				 G_TYPE_INVALID, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INVALID);
+	dbus_g_proxy_connect_signal(session, "ErrorOccurred",
+				    G_CALLBACK (error_occurred_cb), server, NULL);
+}
+
+void
+obexpush_up (void)
+{
+	GError *err = NULL;
+	char *download_dir, *server;
+
+	server = NULL;
+	if (manager_proxy == NULL) {
+		manager_proxy = dbus_g_proxy_new_for_name (connection,
+							   "org.openobex",
+							   "/org/openobex",
+							   "org.openobex.Manager");
+		if (dbus_g_proxy_call (manager_proxy, "CreateBluetoothServer",
+				       &err, G_TYPE_STRING, "00:00:00:00:00:00", G_TYPE_STRING, "opp", G_TYPE_BOOLEAN, FALSE, G_TYPE_INVALID,
+				       DBUS_TYPE_G_OBJECT_PATH, &server, G_TYPE_INVALID) == FALSE) {
+			g_printerr ("Creating Bluetooth ObexPush server failed: %s\n",
+				    err->message);
+			g_error_free (err);
+			g_object_unref (manager_proxy);
+			manager_proxy = NULL;
+			return;
+		}
+	}
+
+	download_dir = lookup_download_dir ();
+
+	if (server_proxy == NULL) {
+		server_proxy = dbus_g_proxy_new_for_name (connection,
+							   "org.openobex",
+							   server,
+							   "org.openobex.Server");
+		g_free (server);
+
+		dbus_g_proxy_add_signal (server_proxy, "SessionCreated",
+					 DBUS_TYPE_G_OBJECT_PATH, G_TYPE_INVALID);
+		dbus_g_proxy_connect_signal(server_proxy, "SessionCreated",
+					    G_CALLBACK (session_created_cb), NULL, NULL);
+	}
+
+	if (dbus_g_proxy_call (server_proxy, "Start", &err,
+			   G_TYPE_STRING, download_dir, G_TYPE_BOOLEAN, TRUE, G_TYPE_BOOLEAN, FALSE, G_TYPE_INVALID,
+			   G_TYPE_INVALID) == FALSE) {
+		if (g_error_matches (err, DBUS_GERROR, DBUS_GERROR_REMOTE_EXCEPTION) != FALSE &&
+		    dbus_g_error_has_name (err, "org.openobex.Error.Started") != FALSE) {
+		    	g_error_free (err);
+		    	g_message ("already started, ignoring error");
+		    	g_free (download_dir);
+		    	return;
+		}
+		g_printerr ("Starting Bluetooth ObexPush server failed: %s\n",
+			    err->message);
+		g_error_free (err);
+		g_free (download_dir);
+		g_object_unref (server_proxy);
+		server_proxy = NULL;
+		g_object_unref (manager_proxy);
+		manager_proxy = NULL;
+		return;
+	}
+
+	g_free (download_dir);
+}
+
+static void
+obexpush_stop (gboolean stop_manager)
+{
+	GError *err = NULL;
+
+	if (server_proxy == NULL)
+		return;
+
+	if (dbus_g_proxy_call (server_proxy, "Close", &err, G_TYPE_INVALID, G_TYPE_INVALID) == FALSE) {
+		if (g_error_matches (err, DBUS_GERROR, DBUS_GERROR_REMOTE_EXCEPTION) == FALSE ||
+		    dbus_g_error_has_name (err, "org.openobex.Error.NotStarted") == FALSE) {
+			g_printerr ("Stopping Bluetooth ObexPush server failed: %s\n",
+				    err->message);
+			g_error_free (err);
+			return;
+		}
+		g_error_free (err);
+	}
+
+	if (stop_manager != FALSE) {
+		g_object_unref (server_proxy);
+		server_proxy = NULL;
+		g_object_unref (manager_proxy);
+		manager_proxy = NULL;
+	}
+
+	//FIXME stop all the notifications
+}
+
+void
+obexpush_down (void)
+{
+	obexpush_stop (TRUE);
+}
+
+void
+obexpush_restart (void)
+{
+	obexpush_stop (FALSE);
+	obexpush_up ();
+}
+
+gboolean
+obexpush_init (void)
+{
+	GError *err = NULL;
+
+	connection = dbus_g_bus_get (DBUS_BUS_SESSION, &err);
+	if (connection == NULL) {
+		g_printerr ("Connecting to session bus failed: %s\n",
+			    err->message);
+		g_error_free (err);
+		return FALSE;
+	}
+
+	dbus_g_object_register_marshaller (marshal_VOID__STRING_STRING_UINT64,
+					   G_TYPE_NONE,
+					   G_TYPE_STRING, G_TYPE_STRING, G_TYPE_UINT64, G_TYPE_INVALID);
+
+	if (!notify_init("mate-user-share")) {
+		g_warning("Unable to initialize the notification system\n");
+        }
+
+	dbus_connection_set_exit_on_disconnect (dbus_g_connection_get_connection (connection), FALSE);
+
+	return TRUE;
+}
+
+void
+obexpush_set_accept_files_policy (AcceptSetting setting)
+{
+	accept_setting = setting;
+}
+
+void
+obexpush_set_notify (gboolean enabled)
+{
+	show_notifications = enabled;
+}
+
+
+
+
+ + + diff --git a/2021-05-30-164325-0736-cppcheck@58f05a4efe60_master/3.html b/2021-05-30-164325-0736-cppcheck@58f05a4efe60_master/3.html new file mode 100644 index 0000000..72b3af5 --- /dev/null +++ b/2021-05-30-164325-0736-cppcheck@58f05a4efe60_master/3.html @@ -0,0 +1,769 @@ + + + + + + Cppcheck - HTML report - mate-user-share + + + + + + +
+ +
+
  1
+  2
+  3
+  4
+  5
+  6
+  7
+  8
+  9
+ 10
+ 11
+ 12
+ 13
+ 14
+ 15
+ 16
+ 17
+ 18
+ 19
+ 20
+ 21
+ 22
+ 23
+ 24
+ 25
+ 26
+ 27
+ 28
+ 29
+ 30
+ 31
+ 32
+ 33
+ 34
+ 35
+ 36
+ 37
+ 38
+ 39
+ 40
+ 41
+ 42
+ 43
+ 44
+ 45
+ 46
+ 47
+ 48
+ 49
+ 50
+ 51
+ 52
+ 53
+ 54
+ 55
+ 56
+ 57
+ 58
+ 59
+ 60
+ 61
+ 62
+ 63
+ 64
+ 65
+ 66
+ 67
+ 68
+ 69
+ 70
+ 71
+ 72
+ 73
+ 74
+ 75
+ 76
+ 77
+ 78
+ 79
+ 80
+ 81
+ 82
+ 83
+ 84
+ 85
+ 86
+ 87
+ 88
+ 89
+ 90
+ 91
+ 92
+ 93
+ 94
+ 95
+ 96
+ 97
+ 98
+ 99
+100
+101
+102
+103
+104
+105
+106
+107
+108
+109
+110
+111
+112
+113
+114
+115
+116
+117
+118
+119
+120
+121
+122
+123
+124
+125
+126
+127
+128
+129
+130
+131
+132
+133
+134
+135
+136
+137
+138
+139
+140
+141
+142
+143
+144
+145
+146
+147
+148
+149
+150
+151
+152
+153
+154
+155
+156
+157
+158
+159
+160
+161
+162
+163
+164
+165
+166
+167
+168
+169
+170
+171
+172
+173
+174
+175
+176
+177
+178
+179
+180
+181
+182
+183
+184
+185
+186
+187
+188
+189
+190
+191
+192
+193
+194
+195
+196
+197
+198
+199
+200
+201
+202
+203
+204
+205
+206
+207
+208
+209
+210
+211
+212
+213
+214
+215
+216
+217
+218
+219
+220
+221
+222
+223
+224
+225
+226
+227
+228
+229
+230
+231
+232
+233
+234
+235
+236
+237
+238
+239
+240
+241
+242
+243
+244
+245
+246
+247
+248
+249
+250
+251
+252
+253
+254
+255
+256
+257
+258
+259
+260
+261
+262
+263
+264
+265
+266
+267
+268
+269
+270
+271
+272
+273
+274
+275
+276
+277
+278
+279
+280
+281
+282
+283
+284
+285
+286
+287
+288
+289
+290
+291
/* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 8; tab-width: 8 -*-
+ *
+ * Copyright (C) 2003 Novell, Inc.
+ * Copyright (C) 2003-2004 Red Hat, Inc.
+ * Copyright (C) 2005 William Jon McCann <mccann@jhu.edu>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * 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 Foundation, Inc., 51 Franklin St, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ *
+ */
+
+#include "config.h"
+
+#include <stdlib.h>
+#include <string.h>
+#include <glib/gi18n-lib.h>
+#include <gtk/gtk.h>
+#include <libcaja-extension/caja-menu-provider.h>
+#include <libcaja-extension/caja-location-widget-provider.h>
+
+#ifdef HAVE_BLUETOOTH
+#include <bluetooth-client.h>
+#endif
+
+#include "caja-share-bar.h"
+#include "user_share-common.h"
+
+#define CAJA_TYPE_USER_SHARE  (caja_user_share_get_type ())
+#define CAJA_USER_SHARE(o)    (G_TYPE_CHECK_INSTANCE_CAST ((o), CAJA_TYPE_USER_SHARE, CajaUserShare))
+#define CAJA_IS_USER_SHARE(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), CAJA_TYPE_USER_SHARE))
+
+typedef struct
+{
+        GObject              parent_slot;
+} CajaUserShare;
+
+typedef struct
+{
+        GObjectClass parent_slot;
+} CajaUserShareClass;
+
+static GType caja_user_share_get_type      (void);
+static void  caja_user_share_register_type (GTypeModule *module);
+
+static void
+launch_process (char **argv, GtkWindow *parent)
+{
+        GError *error;
+        GtkWidget *dialog;
+
+        error = NULL;
+        if (!g_spawn_async (NULL,
+                            argv, NULL,
+                            0,
+                            NULL, NULL,
+                            NULL,
+                            &error)) {
+
+
+                dialog = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL, GTK_MESSAGE_WARNING,
+						 GTK_BUTTONS_OK, _("Unable to launch the Personal File Sharing preferences"));
+
+                gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog), "%s", error->message);
+
+                gtk_dialog_run (GTK_DIALOG (dialog));
+                gtk_widget_destroy (dialog);
+
+                g_error_free (error);
+        }
+}
+
+static void
+launch_prefs_on_window (GtkWindow *window)
+{
+        char *argv [2];
+
+        argv [0] = g_build_filename (BINDIR, "mate-file-share-properties", NULL);
+        argv [1] = NULL;
+
+        launch_process (argv, window);
+
+        g_free (argv [0]);
+}
+
+static void
+bar_response_cb (CajaShareBar *bar,
+                 gint response,
+                 gpointer         data)
+{
+        if (response == CAJA_SHARE_BAR_RESPONSE_PREFERENCES) {
+                launch_prefs_on_window (GTK_WINDOW (data));
+        }
+}
+
+#ifdef HAVE_BLUETOOTH
+static void
+downloads_bar_set_from_bluetooth_status (GtkWidget *bar)
+{
+	BluetoothClient *client;
+	gboolean bt_powered;
+
+	client = g_object_get_data (G_OBJECT (bar), "bluetooth-client");
+	g_object_get (G_OBJECT (client),
+		      "default-adapter-powered", &bt_powered,
+		      NULL);
+	gtk_widget_set_visible (bar, bt_powered);
+}
+
+static void
+default_adapter_powered_cb (GObject    *gobject,
+			    GParamSpec *pspec,
+			    GtkWidget  *bar)
+{
+	downloads_bar_set_from_bluetooth_status (bar);
+}
+#endif /* HAVE_BLUETOOTH */
+
+static GtkWidget *
+caja_user_share_get_location_widget (CajaLocationWidgetProvider *iface,
+                                         const char                     *uri,
+                                         GtkWidget                      *window)
+{
+	GFile             *file;
+	GtkWidget         *bar;
+	guint              i;
+	gboolean           enable = FALSE;
+	GFile             *home;
+#ifdef HAVE_BLUETOOTH
+	const GUserDirectory special_dirs[] = { G_USER_DIRECTORY_PUBLIC_SHARE, G_USER_DIRECTORY_DOWNLOAD };
+
+	gboolean is_dir[] = { FALSE, FALSE };
+#else
+	const GUserDirectory special_dirs[] = { G_USER_DIRECTORY_PUBLIC_SHARE };
+
+	gboolean is_dir[] = { FALSE };
+#endif /* HAVE_BLUETOOTH */
+	file = g_file_new_for_uri (uri);
+	home = g_file_new_for_path (g_get_home_dir ());
+
+	/* We don't show anything in $HOME */
+	if (g_file_equal (home, file)) {
+		g_object_unref (home);
+		g_object_unref (file);
+		return NULL;
+	}
+
+	g_object_unref (home);
+
+	for (i = 0; i < G_N_ELEMENTS (special_dirs); i++) {
+		GFile *dir;
+		dir = lookup_dir_with_fallback (special_dirs[i]);
+		if (g_file_equal (dir, file)) {
+			enable = TRUE;
+			is_dir[i] = TRUE;
+		}
+		g_object_unref (dir);
+	}
+
+	g_object_unref (file);
+
+	if (enable == FALSE)
+		return NULL;
+
+	if (is_dir[0] != FALSE) {
+#ifdef HAVE_BLUETOOTH
+		if (is_dir[1] != FALSE) {
+			bar = caja_share_bar_new (_("May be used to share or receive files"));
+		} else {
+			bar = caja_share_bar_new (_("May be shared over the network or Bluetooth"));
+		}
+#else
+		bar = caja_share_bar_new (_("May be shared over the network"));
+#endif /* HAVE_BLUETOOTH */
+	} else {
+#ifdef HAVE_BLUETOOTH
+		BluetoothClient *client;
+
+		bar = caja_share_bar_new (_("May be used to receive files over Bluetooth"));
+
+		gtk_widget_set_no_show_all (bar, TRUE);
+		client = bluetooth_client_new ();
+		g_object_set_data_full (G_OBJECT (bar), "bluetooth-client", client, g_object_unref);
+		g_signal_connect (G_OBJECT (client), "notify::default-adapter-powered",
+				  G_CALLBACK (default_adapter_powered_cb), bar);
+		downloads_bar_set_from_bluetooth_status (bar);
+#endif /* HAVE_BLUETOOTH */
+	}
+
+	g_signal_connect (bar, "response",
+			  G_CALLBACK (bar_response_cb),
+			  window);
+
+	gtk_widget_show_all (bar);
+
+	return bar;
+}
+
+static void
+caja_user_share_location_widget_provider_iface_init (CajaLocationWidgetProviderIface *iface)
+{
+        iface->get_widget = caja_user_share_get_location_widget;
+}
+
+static void
+caja_user_share_instance_init (CajaUserShare *share)
+{
+
+}
+
+static void
+caja_user_share_class_init (CajaUserShareClass *klass)
+{
+
+}
+
+static GType share_type = 0;
+
+static GType
+caja_user_share_get_type (void)
+{
+        return share_type;
+}
+
+static void
+caja_user_share_register_type (GTypeModule *module)
+{
+        static const GTypeInfo info = {
+                sizeof (CajaUserShareClass),
+                (GBaseInitFunc) NULL,
+                (GBaseFinalizeFunc) NULL,
+                (GClassInitFunc) caja_user_share_class_init,
+                NULL,
+                NULL,
+                sizeof (CajaUserShare),
+                0,
+                (GInstanceInitFunc) caja_user_share_instance_init,
+        };
+
+        static const GInterfaceInfo location_widget_provider_iface_info = {
+                (GInterfaceInitFunc) caja_user_share_location_widget_provider_iface_init,
+                NULL,
+                NULL
+        };
+
+        share_type = g_type_module_register_type (module,
+                                                 G_TYPE_OBJECT,
+                                                 "CajaUserShare",
+                                                 &info, 0);
+
+        g_type_module_add_interface (module,
+                                     share_type,
+                                     CAJA_TYPE_LOCATION_WIDGET_PROVIDER,
+                                     &location_widget_provider_iface_info);
+}
+
+void
+caja_module_initialize (GTypeModule *module)
+{
+        caja_user_share_register_type (module);
+        bindtextdomain (GETTEXT_PACKAGE, MATELOCALEDIR);
+        bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
+}
+
+void
+caja_module_shutdown (void)
+{
+}
+
+void
+caja_module_list_types (const GType **types,
+                            int          *num_types)
+{
+        static GType type_list [1];
+
+        type_list[0] = CAJA_TYPE_USER_SHARE;
+
+        *types = type_list;
+        *num_types = 1;
+}
+
+
+
+
+ + + diff --git a/2021-05-30-164325-0736-cppcheck@58f05a4efe60_master/4.html b/2021-05-30-164325-0736-cppcheck@58f05a4efe60_master/4.html new file mode 100644 index 0000000..051582e --- /dev/null +++ b/2021-05-30-164325-0736-cppcheck@58f05a4efe60_master/4.html @@ -0,0 +1,1187 @@ + + + + + + Cppcheck - HTML report - mate-user-share + + + + + + +
+ +
+
  1
+  2
+  3
+  4
+  5
+  6
+  7
+  8
+  9
+ 10
+ 11
+ 12
+ 13
+ 14
+ 15
+ 16
+ 17
+ 18
+ 19
+ 20
+ 21
+ 22
+ 23
+ 24
+ 25
+ 26
+ 27
+ 28
+ 29
+ 30
+ 31
+ 32
+ 33
+ 34
+ 35
+ 36
+ 37
+ 38
+ 39
+ 40
+ 41
+ 42
+ 43
+ 44
+ 45
+ 46
+ 47
+ 48
+ 49
+ 50
+ 51
+ 52
+ 53
+ 54
+ 55
+ 56
+ 57
+ 58
+ 59
+ 60
+ 61
+ 62
+ 63
+ 64
+ 65
+ 66
+ 67
+ 68
+ 69
+ 70
+ 71
+ 72
+ 73
+ 74
+ 75
+ 76
+ 77
+ 78
+ 79
+ 80
+ 81
+ 82
+ 83
+ 84
+ 85
+ 86
+ 87
+ 88
+ 89
+ 90
+ 91
+ 92
+ 93
+ 94
+ 95
+ 96
+ 97
+ 98
+ 99
+100
+101
+102
+103
+104
+105
+106
+107
+108
+109
+110
+111
+112
+113
+114
+115
+116
+117
+118
+119
+120
+121
+122
+123
+124
+125
+126
+127
+128
+129
+130
+131
+132
+133
+134
+135
+136
+137
+138
+139
+140
+141
+142
+143
+144
+145
+146
+147
+148
+149
+150
+151
+152
+153
+154
+155
+156
+157
+158
+159
+160
+161
+162
+163
+164
+165
+166
+167
+168
+169
+170
+171
+172
+173
+174
+175
+176
+177
+178
+179
+180
+181
+182
+183
+184
+185
+186
+187
+188
+189
+190
+191
+192
+193
+194
+195
+196
+197
+198
+199
+200
+201
+202
+203
+204
+205
+206
+207
+208
+209
+210
+211
+212
+213
+214
+215
+216
+217
+218
+219
+220
+221
+222
+223
+224
+225
+226
+227
+228
+229
+230
+231
+232
+233
+234
+235
+236
+237
+238
+239
+240
+241
+242
+243
+244
+245
+246
+247
+248
+249
+250
+251
+252
+253
+254
+255
+256
+257
+258
+259
+260
+261
+262
+263
+264
+265
+266
+267
+268
+269
+270
+271
+272
+273
+274
+275
+276
+277
+278
+279
+280
+281
+282
+283
+284
+285
+286
+287
+288
+289
+290
+291
+292
+293
+294
+295
+296
+297
+298
+299
+300
+301
+302
+303
+304
+305
+306
+307
+308
+309
+310
+311
+312
+313
+314
+315
+316
+317
+318
+319
+320
+321
+322
+323
+324
+325
+326
+327
+328
+329
+330
+331
+332
+333
+334
+335
+336
+337
+338
+339
+340
+341
+342
+343
+344
+345
+346
+347
+348
+349
+350
+351
+352
+353
+354
+355
+356
+357
+358
+359
+360
+361
+362
+363
+364
+365
+366
+367
+368
+369
+370
+371
+372
+373
+374
+375
+376
+377
+378
+379
+380
+381
+382
+383
+384
+385
+386
+387
+388
+389
+390
+391
+392
+393
+394
+395
+396
+397
+398
+399
+400
+401
+402
+403
+404
+405
+406
+407
+408
+409
+410
+411
+412
+413
+414
+415
+416
+417
+418
+419
+420
+421
+422
+423
+424
+425
+426
+427
+428
+429
+430
+431
+432
+433
+434
+435
+436
+437
+438
+439
+440
+441
+442
+443
+444
+445
+446
+447
+448
+449
+450
+451
+452
+453
+454
+455
+456
+457
+458
+459
+460
+461
+462
+463
+464
+465
+466
+467
+468
+469
+470
+471
+472
+473
+474
+475
+476
+477
+478
+479
+480
+481
+482
+483
+484
+485
+486
+487
+488
+489
+490
+491
+492
+493
+494
+495
+496
+497
+498
+499
+500
+501
+502
+503
+504
+505
+506
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
+
+/*
+ *  Copyright (C) 2004-2008 Red Hat, Inc.
+ *
+ *  Caja is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU General Public License as
+ *  published by the Free Software Foundation; either version 2 of the
+ *  License, or (at your option) any later version.
+ *
+ *  Caja is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  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
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ *  Authors: Alexander Larsson <alexl@redhat.com>
+ *
+ */
+
+#include "config.h"
+
+#include <gdk/gdkx.h>
+#include <gtk/gtk.h>
+#include <glib/gi18n.h>
+#include <glib/gstdio.h>
+#include <gio/gio.h>
+#include <X11/Xlib.h>
+
+#include "user_share-private.h"
+#include "user_share-common.h"
+#include "http.h"
+
+#ifdef HAVE_BLUETOOTH
+#include <bluetooth-client.h>
+
+#include "obexftp.h"
+#include "obexpush.h"
+
+#endif /* HAVE_BLUETOOTH */
+
+#include <gio/gio.h>
+
+#include <stdarg.h>
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <signal.h>
+#include <unistd.h>
+
+static guint disabled_timeout_tag = 0;
+static GSettings* settings;<--- Shadowed declaration<--- Shadowed declaration<--- Shadowed declaration
+
+#define GSETTINGS_SCHEMA "org.mate.FileSharing"
+#define GSETTINGS_KEY_FILE_SHARING_ENABLED "enabled"
+#define GSETTINGS_KEY_FILE_SHARING_REQUIRE_PASSWORD "require-password"
+
+#ifdef HAVE_BLUETOOTH
+/* MATE Session */
+#define MATE_SESSION_DBUS_NAME      "org.gnome.SessionManager"
+#define MATE_SESSION_DBUS_OBJECT    "/org/gnome/SessionManager"
+#define MATE_SESSION_DBUS_INTERFACE "org.gnome.SessionManager"
+
+static GDBusProxy *session_proxy = NULL;
+static gboolean has_console = TRUE;
+
+static BluetoothClient *client = NULL;
+static gboolean bluetoothd_enabled = FALSE;
+
+#define OBEX_ENABLED (bluetoothd_enabled && has_console)
+
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_ENABLED "bluetooth-enabled"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_ALLOW_WRITE "bluetooth-allow-write"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_REQUIRE_PAIRING "bluetooth-require-pairing"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED "bluetooth-obexpush-enabled"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_ACCEPT_FILES "bluetooth-accept-files"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_NOTIFY "bluetooth-notify"
+
+
+static void
+obex_services_start (void)
+{
+	GSettings *settings;<--- Shadow variable
+
+	if (bluetoothd_enabled == FALSE ||
+	    has_console == FALSE)
+	    	return;
+
+	settings = g_settings_new(GSETTINGS_SCHEMA);
+
+	if (g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED) == TRUE) {
+	    obexpush_up ();
+	}
+	if (g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_ENABLED) == TRUE) {
+	    obexftp_up ();
+	}
+
+	g_object_unref (client);
+}
+
+static void
+obex_services_shutdown (void)
+{
+	obexpush_down ();
+	obexftp_down ();
+}
+
+static void
+session_properties_changed_cb (GDBusProxy      *session,
+			       GVariant        *changed,
+			       char           **invalidated,
+			       gpointer         user_data)
+{
+	GVariant *v;
+
+	v = g_variant_lookup_value (changed, "SessionIsActive", G_VARIANT_TYPE_BOOLEAN);
+	if (v) {
+		has_console = g_variant_get_boolean (v);
+		g_debug ("Received session is active change: now %s", has_console ? "active" : "inactive");
+
+		if (has_console)
+			obex_services_start ();
+		else
+			obex_services_shutdown ();
+
+		g_variant_unref (v);
+	}
+}
+
+static gboolean
+is_session_active (void)
+{
+	GVariant *variant;
+	gboolean is_session_active = FALSE;
+
+	variant = g_dbus_proxy_get_cached_property (session_proxy,
+						    "SessionIsActive");
+	if (variant) {
+		is_session_active = g_variant_get_boolean (variant);
+		g_variant_unref (variant);
+ 	}
+
+	return is_session_active;
+}
+
+static void
+session_init (void)
+{
+	GError *error = NULL;
+
+	session_proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION,
+						       G_DBUS_PROXY_FLAGS_NONE,
+						       NULL,
+						       MATE_SESSION_DBUS_NAME,
+						       MATE_SESSION_DBUS_OBJECT,
+						       MATE_SESSION_DBUS_INTERFACE,
+						       NULL,
+						       &error);
+	if (session_proxy == NULL) {
+		g_warning ("Failed to get session proxy: %s", error->message);
+		g_error_free (error);
+		return;
+	}
+	g_signal_connect (session_proxy, "g-properties-changed",
+			  G_CALLBACK (session_properties_changed_cb),
+			  NULL);
+	has_console = is_session_active ();
+}
+
+static void
+default_adapter_changed (GObject    *gobject,
+			 GParamSpec *pspec,
+			 gpointer    user_data)
+{
+	char *adapter;
+	gboolean adapter_powered;
+
+	g_object_get (G_OBJECT (client),
+		      "default-adapter", &adapter,
+		      "default-adapter-powered", &adapter_powered,
+		      NULL);
+	if (adapter != NULL && *adapter != '\0') {
+		bluetoothd_enabled = adapter_powered;
+	} else {
+		bluetoothd_enabled = FALSE;
+	}
+
+	/* Were we called as init, or as a callback */
+	if (gobject != NULL) {
+		if (bluetoothd_enabled != FALSE)
+			obex_services_start ();
+		else
+			obex_services_shutdown ();
+	}
+}
+
+static void
+bluez_init (void)
+{
+	client = bluetooth_client_new ();
+	default_adapter_changed (NULL, NULL, NULL);
+	g_signal_connect (G_OBJECT (client), "notify::default-adapter",
+			  G_CALLBACK (default_adapter_changed), NULL);
+	g_signal_connect (G_OBJECT (client), "notify::default-adapter-powered",
+			  G_CALLBACK (default_adapter_changed), NULL);
+}
+#endif /* HAVE_BLUETOOTH */
+
+static gboolean
+file_sharing_enabled (void)
+{
+	gboolean enabled = TRUE;
+	settings = g_settings_new (GSETTINGS_SCHEMA);
+
+#ifdef HAVE_BLUETOOTH
+	if (g_settings_get_boolean (settings, FILE_SHARING_ENABLED) == FALSE &&
+	    g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_ENABLED) == FALSE &&
+	    g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED) == FALSE)
+#else /* HAVE_BLUETOOTH */
+	if (g_settings_get_boolean (settings, FILE_SHARING_ENABLED) == FALSE)
+#endif /* HAVE_BLUETOOTH */
+		enabled = FALSE;
+
+	g_object_unref (settings);
+
+	return enabled;
+}
+
+static void
+migrate_old_configuration (void)
+{
+	const char *old_config_dir;
+	const char *new_config_dir;
+
+	old_config_dir = g_build_filename (g_get_home_dir (), ".mate2", "user-share", NULL);
+	new_config_dir = g_build_filename (g_get_user_config_dir (), "user-share", NULL);
+	if (g_file_test (old_config_dir, G_FILE_TEST_IS_DIR))
+		g_rename (old_config_dir, new_config_dir);
+
+}
+
+static void
+require_password_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	/* Need to restart to get new password setting */
+	if (http_get_pid () != 0) {
+		http_down ();
+		http_up ();
+	}
+}
+
+/* File sharing was disabled for some time, exit now */
+/* If we re-enable it in the ui, this will be restarted anyway */
+static gboolean
+disabled_timeout_callback (gpointer user_data)
+{
+	GSettings *settings = (GSettings *) user_data;<--- Shadow variable
+	http_down ();
+
+#ifdef HAVE_BLUETOOTH
+	if (g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_ENABLED) == FALSE &&
+	    g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED) == FALSE)
+		_exit (0);
+#else /* HAVE_BLUETOOTH */
+	if (g_settings_get_boolean (settings, FILE_SHARING_ENABLED) == FALSE)
+		_exit (0);
+#endif /* HAVE_BLUETOOTH */
+	return FALSE;
+}
+
+static void
+file_sharing_enabled_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	gboolean enabled;
+
+	if (disabled_timeout_tag != 0) {
+		g_source_remove (disabled_timeout_tag);
+		disabled_timeout_tag = 0;
+	}
+
+	enabled = g_settings_get_boolean (settings,
+					 FILE_SHARING_ENABLED);
+	if (enabled) {
+		if (http_get_pid () == 0) {
+			http_up ();
+		}
+	} else {
+		http_down ();
+		disabled_timeout_tag = g_timeout_add_seconds (3,
+							      (GSourceFunc)disabled_timeout_callback,
+							      settings);
+	}
+}
+
+#ifdef HAVE_BLUETOOTH
+static void
+file_sharing_bluetooth_allow_write_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	if (g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_ENABLED) != FALSE)
+		obexftp_restart ();
+}
+
+static void
+file_sharing_bluetooth_require_pairing_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	if (g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_ENABLED) != FALSE) {
+		/* We need to fully reset the session,
+		 * otherwise the new setting isn't taken into account */
+		obexftp_down ();
+		obexftp_up ();
+	}
+}
+
+static void
+file_sharing_bluetooth_enabled_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	if (g_settings_get_boolean (settings,
+				   FILE_SHARING_BLUETOOTH_ENABLED) == FALSE) {
+		obexftp_down ();
+		if (g_settings_get_boolean (settings, FILE_SHARING_ENABLED) == FALSE &&
+		    g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED) == FALSE) {
+			_exit (0);
+		}
+	} else if (OBEX_ENABLED) {
+		obexftp_up ();
+	}
+}
+
+static void
+file_sharing_bluetooth_obexpush_enabled_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	if (g_settings_get_boolean (settings,
+				   FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED) == FALSE) {
+		obexpush_down ();
+		if (g_settings_get_boolean (settings, FILE_SHARING_ENABLED) == FALSE &&
+		    g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_ENABLED) == FALSE) {
+			_exit (0);
+		}
+	} else if (OBEX_ENABLED) {
+		obexpush_up ();
+	}
+}
+
+static void
+file_sharing_bluetooth_obexpush_accept_files_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	AcceptSetting setting;
+	char *str;
+
+	str = g_settings_get_string (settings, FILE_SHARING_BLUETOOTH_OBEXPUSH_ACCEPT_FILES);
+	setting = accept_setting_from_string (str);
+	g_free (str);
+
+	obexpush_set_accept_files_policy (setting);
+}
+
+static void
+file_sharing_bluetooth_obexpush_notify_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	obexpush_set_notify (g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_OBEXPUSH_NOTIFY));
+}
+#endif /* HAVE_BLUETOOTH */
+
+static RETSIGTYPE
+cleanup_handler (int sig)
+{
+	http_down ();
+#ifdef HAVE_BLUETOOTH
+	obexftp_down ();
+	obexpush_down ();
+#endif /* HAVE_BLUETOOTH */
+	_exit (2);
+}
+
+static int
+x_io_error_handler (Display *xdisplay)
+{
+	http_down ();
+#ifdef HAVE_BLUETOOTH
+	obexftp_down ();
+#endif /* HAVE_BLUETOOTH */
+	_exit (2);
+}
+
+int
+main (int argc, char **argv)
+{
+	GSettings *settings;<--- Shadow variable
+	Display *xdisplay;
+	G_GNUC_UNUSED int x_fd;
+	Window selection_owner;
+	Atom xatom;
+
+	bindtextdomain (GETTEXT_PACKAGE, MATELOCALEDIR);
+	bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
+	textdomain (GETTEXT_PACKAGE);
+
+	gtk_init (&argc, &argv);
+
+	if (g_strcmp0 (g_get_real_name (), "root") == 0) {
+		g_warning ("mate-user-share cannot be started as root for security reasons.");
+		return 1;
+	}
+
+	signal (SIGPIPE, SIG_IGN);
+	signal (SIGINT, cleanup_handler);
+	signal (SIGHUP, cleanup_handler);
+	signal (SIGTERM, cleanup_handler);
+
+	xdisplay = GDK_DISPLAY_XDISPLAY (gdk_display_get_default ());
+	if (xdisplay == NULL) {
+		g_warning ("Can't open display");
+		return 1;
+	}
+
+	xatom = XInternAtom (xdisplay, "_MATE_USER_SHARE", FALSE);
+	selection_owner = XGetSelectionOwner (xdisplay, xatom);
+
+	if (selection_owner != None) {
+		/* There is an owner already, quit */
+		return 1;
+	}
+
+	selection_owner = XCreateSimpleWindow (xdisplay,
+					       RootWindow (xdisplay, 0),
+					       0, 0, 1, 1,
+					       0, 0, 0);
+	XSetSelectionOwner (xdisplay, xatom, selection_owner, CurrentTime);
+
+	if (XGetSelectionOwner (xdisplay, xatom) != selection_owner) {
+		/* Didn't get the selection */
+		return 1;
+	}
+
+	migrate_old_configuration ();
+
+	if (!file_sharing_enabled ())
+		return 1;
+
+	settings = g_settings_new (GSETTINGS_SCHEMA);
+
+	x_fd = ConnectionNumber (xdisplay);
+	XSetIOErrorHandler (x_io_error_handler);
+
+	if (http_init () == FALSE)
+		return 1;
+#ifdef HAVE_BLUETOOTH
+	if (obexftp_init () == FALSE)
+		return 1;
+	if (obexpush_init () == FALSE)
+		return 1;
+#endif /* HAVE_BLUETOOTH */
+
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_ENABLED,
+			     G_CALLBACK (file_sharing_enabled_changed), NULL);
+
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_REQUIRE_PASSWORD,
+			     G_CALLBACK (require_password_changed), NULL);
+
+#ifdef HAVE_BLUETOOTH
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_ENABLED,
+			     G_CALLBACK (file_sharing_bluetooth_enabled_changed), NULL);
+
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_ALLOW_WRITE,
+			     G_CALLBACK (file_sharing_bluetooth_allow_write_changed), NULL);
+
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_REQUIRE_PAIRING,
+			     G_CALLBACK (file_sharing_bluetooth_require_pairing_changed), NULL);
+
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED,
+			     G_CALLBACK (file_sharing_bluetooth_obexpush_enabled_changed), NULL);
+
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_ACCEPT_FILES,
+			     G_CALLBACK (file_sharing_bluetooth_obexpush_accept_files_changed), NULL);
+
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_NOTIFY,
+			     G_CALLBACK (file_sharing_bluetooth_obexpush_notify_changed), NULL);
+
+	bluez_init ();
+	session_init ();
+#endif /* HAVE_BLUETOOTH */
+
+	/* Initial setting */
+	file_sharing_enabled_changed (settings, NULL, NULL);
+#ifdef HAVE_BLUETOOTH
+	file_sharing_bluetooth_enabled_changed (settings, NULL, NULL);
+	file_sharing_bluetooth_obexpush_accept_files_changed (settings, NULL, NULL);
+	file_sharing_bluetooth_obexpush_notify_changed (settings, NULL, NULL);
+	file_sharing_bluetooth_obexpush_enabled_changed (settings, NULL, NULL);
+#endif /* HAVE_BLUETOOTH */
+
+	gtk_main ();
+
+	return 0;
+}
+
+
+
+
+ + + diff --git a/2021-05-30-164325-0736-cppcheck@58f05a4efe60_master/index.html b/2021-05-30-164325-0736-cppcheck@58f05a4efe60_master/index.html new file mode 100644 index 0000000..bbcd983 --- /dev/null +++ b/2021-05-30-164325-0736-cppcheck@58f05a4efe60_master/index.html @@ -0,0 +1,141 @@ + + + + + + Cppcheck - HTML report - mate-user-share + + + + + + +
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
LineIdCWESeverityMessage
missingIncludeinformationCppcheck cannot find all the include files (use --check-config for details)
src/file-share-properties.c
82variableScope398styleThe scope of the variable 'password' can be reduced.
97shadowVariable398styleLocal variable 'settings' shadows outer variable
105unusedVariable563styleUnused variable: accept_setting
249shadowVariable398styleLocal variable 'settings' shadows outer variable
273shadowVariable398styleLocal variable 'settings' shadows outer variable
294shadowVariable398styleLocal variable 'settings' shadows outer variable
323shadowVariable398styleLocal variable 'settings' shadows outer variable
340shadowVariable398styleLocal variable 'settings' shadows outer variable
357shadowVariable398styleLocal variable 'settings' shadows outer variable
377shadowVariable398styleLocal variable 'settings' shadows outer variable
393shadowVariable398styleLocal variable 'settings' shadows outer variable
457shadowVariable398styleLocal variable 'settings' shadows outer variable
620variableScope398styleThe scope of the variable 'window' can be reduced.
src/http.c
114variableScope398styleThe scope of the variable 'host_name' can be reduced.
src/obexpush.c
187shadowVariable398styleLocal variable 'connection' shadows outer variable
src/share-extension.c
61variableScope398styleThe scope of the variable 'dialog' can be reduced.
src/user_share.c
86shadowVariable398styleLocal variable 'settings' shadows outer variable
260shadowVariable398styleLocal variable 'settings' shadows outer variable
391shadowVariable398styleLocal variable 'settings' shadows outer variable
+
+
+ + + diff --git a/2021-05-30-164325-0736-cppcheck@58f05a4efe60_master/stats.html b/2021-05-30-164325-0736-cppcheck@58f05a4efe60_master/stats.html new file mode 100644 index 0000000..2020977 --- /dev/null +++ b/2021-05-30-164325-0736-cppcheck@58f05a4efe60_master/stats.html @@ -0,0 +1,109 @@ + + + + + + Cppcheck - HTML report - mate-user-share + + + + + + +
+ +
+

Top 10 files for style severity, total findings: 19
+   13  src/file-share-properties.c
+   3   src/user_share.c
+   1   src/share-extension.c
+   1   src/obexpush.c
+   1   src/http.c
+

+ +
+
+ + + diff --git a/2021-05-30-164325-0736-cppcheck@58f05a4efe60_master/style.css b/2021-05-30-164325-0736-cppcheck@58f05a4efe60_master/style.css new file mode 100644 index 0000000..07125f4 --- /dev/null +++ b/2021-05-30-164325-0736-cppcheck@58f05a4efe60_master/style.css @@ -0,0 +1,137 @@ + +body { + font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif; + font-size: 13px; + line-height: 1.5; + margin: 0; + width: auto; +} + +h1 { + margin: 10px; +} + +.header { + border-bottom: thin solid #aaa; +} + +.footer { + border-top: thin solid #aaa; + font-size: 90%; + margin-top: 5px; +} + +.footer ul { + list-style-type: none; + padding-left: 0; +} + +.footer > p { + margin: 4px; +} + +.wrapper { + display: -webkit-box; + display: -ms-flexbox; + display: flex; + -webkit-box-pack: justify; + -ms-flex-pack: justify; + justify-content: space-between; +} + +#menu, +#menu_index { + text-align: left; + width: 350px; + height: 90vh; + min-height: 200px; + overflow: auto; + position: -webkit-sticky; + position: sticky; + top: 0; + padding: 0 15px 15px 15px; +} + +#menu > a { + display: block; + margin-left: 10px; + font-size: 12px; + z-index: 1; +} + +#content, +#content_index { + background-color: #fff; + -webkit-box-sizing: content-box; + -moz-box-sizing: content-box; + box-sizing: content-box; + padding: 0 15px 15px 15px; + width: calc(100% - 350px); + height: 100%; + overflow-x: auto; +} + +#filename { + margin-left: 10px; + font-size: 12px; + z-index: 1; +} + +.error { + background-color: #ffb7b7; +} + +.error2 { + background-color: #faa; + display: inline-block; + margin-left: 4px; +} + +.inconclusive { + background-color: #b6b6b4; +} + +.inconclusive2 { + background-color: #b6b6b4; + display: inline-block; + margin-left: 4px; +} + +.verbose { + display: inline-block; + vertical-align: top; + cursor: help; +} + +.verbose .content { + display: none; + position: absolute; + padding: 10px; + margin: 4px; + max-width: 40%; + white-space: pre-wrap; + border: 1px solid #000; + background-color: #ffffcc; + cursor: auto; +} + +.highlight .hll { + padding: 1px; +} + +.highlighttable { + background-color: #fff; + z-index: 10; + position: relative; + margin: -10px; +} + +.linenos { + border-right: thin solid #aaa; + color: #d3d3d3; + padding-right: 6px; +} + +.d-none { + display: none; +} diff --git a/2021-06-25-153248-0614-cppcheck@198f334ccf4c_master/0.html b/2021-06-25-153248-0614-cppcheck@198f334ccf4c_master/0.html new file mode 100644 index 0000000..e20d301 --- /dev/null +++ b/2021-06-25-153248-0614-cppcheck@198f334ccf4c_master/0.html @@ -0,0 +1,1505 @@ + + + + + + Cppcheck - HTML report - mate-user-share + + + + + + +
+ +
+
  1
+  2
+  3
+  4
+  5
+  6
+  7
+  8
+  9
+ 10
+ 11
+ 12
+ 13
+ 14
+ 15
+ 16
+ 17
+ 18
+ 19
+ 20
+ 21
+ 22
+ 23
+ 24
+ 25
+ 26
+ 27
+ 28
+ 29
+ 30
+ 31
+ 32
+ 33
+ 34
+ 35
+ 36
+ 37
+ 38
+ 39
+ 40
+ 41
+ 42
+ 43
+ 44
+ 45
+ 46
+ 47
+ 48
+ 49
+ 50
+ 51
+ 52
+ 53
+ 54
+ 55
+ 56
+ 57
+ 58
+ 59
+ 60
+ 61
+ 62
+ 63
+ 64
+ 65
+ 66
+ 67
+ 68
+ 69
+ 70
+ 71
+ 72
+ 73
+ 74
+ 75
+ 76
+ 77
+ 78
+ 79
+ 80
+ 81
+ 82
+ 83
+ 84
+ 85
+ 86
+ 87
+ 88
+ 89
+ 90
+ 91
+ 92
+ 93
+ 94
+ 95
+ 96
+ 97
+ 98
+ 99
+100
+101
+102
+103
+104
+105
+106
+107
+108
+109
+110
+111
+112
+113
+114
+115
+116
+117
+118
+119
+120
+121
+122
+123
+124
+125
+126
+127
+128
+129
+130
+131
+132
+133
+134
+135
+136
+137
+138
+139
+140
+141
+142
+143
+144
+145
+146
+147
+148
+149
+150
+151
+152
+153
+154
+155
+156
+157
+158
+159
+160
+161
+162
+163
+164
+165
+166
+167
+168
+169
+170
+171
+172
+173
+174
+175
+176
+177
+178
+179
+180
+181
+182
+183
+184
+185
+186
+187
+188
+189
+190
+191
+192
+193
+194
+195
+196
+197
+198
+199
+200
+201
+202
+203
+204
+205
+206
+207
+208
+209
+210
+211
+212
+213
+214
+215
+216
+217
+218
+219
+220
+221
+222
+223
+224
+225
+226
+227
+228
+229
+230
+231
+232
+233
+234
+235
+236
+237
+238
+239
+240
+241
+242
+243
+244
+245
+246
+247
+248
+249
+250
+251
+252
+253
+254
+255
+256
+257
+258
+259
+260
+261
+262
+263
+264
+265
+266
+267
+268
+269
+270
+271
+272
+273
+274
+275
+276
+277
+278
+279
+280
+281
+282
+283
+284
+285
+286
+287
+288
+289
+290
+291
+292
+293
+294
+295
+296
+297
+298
+299
+300
+301
+302
+303
+304
+305
+306
+307
+308
+309
+310
+311
+312
+313
+314
+315
+316
+317
+318
+319
+320
+321
+322
+323
+324
+325
+326
+327
+328
+329
+330
+331
+332
+333
+334
+335
+336
+337
+338
+339
+340
+341
+342
+343
+344
+345
+346
+347
+348
+349
+350
+351
+352
+353
+354
+355
+356
+357
+358
+359
+360
+361
+362
+363
+364
+365
+366
+367
+368
+369
+370
+371
+372
+373
+374
+375
+376
+377
+378
+379
+380
+381
+382
+383
+384
+385
+386
+387
+388
+389
+390
+391
+392
+393
+394
+395
+396
+397
+398
+399
+400
+401
+402
+403
+404
+405
+406
+407
+408
+409
+410
+411
+412
+413
+414
+415
+416
+417
+418
+419
+420
+421
+422
+423
+424
+425
+426
+427
+428
+429
+430
+431
+432
+433
+434
+435
+436
+437
+438
+439
+440
+441
+442
+443
+444
+445
+446
+447
+448
+449
+450
+451
+452
+453
+454
+455
+456
+457
+458
+459
+460
+461
+462
+463
+464
+465
+466
+467
+468
+469
+470
+471
+472
+473
+474
+475
+476
+477
+478
+479
+480
+481
+482
+483
+484
+485
+486
+487
+488
+489
+490
+491
+492
+493
+494
+495
+496
+497
+498
+499
+500
+501
+502
+503
+504
+505
+506
+507
+508
+509
+510
+511
+512
+513
+514
+515
+516
+517
+518
+519
+520
+521
+522
+523
+524
+525
+526
+527
+528
+529
+530
+531
+532
+533
+534
+535
+536
+537
+538
+539
+540
+541
+542
+543
+544
+545
+546
+547
+548
+549
+550
+551
+552
+553
+554
+555
+556
+557
+558
+559
+560
+561
+562
+563
+564
+565
+566
+567
+568
+569
+570
+571
+572
+573
+574
+575
+576
+577
+578
+579
+580
+581
+582
+583
+584
+585
+586
+587
+588
+589
+590
+591
+592
+593
+594
+595
+596
+597
+598
+599
+600
+601
+602
+603
+604
+605
+606
+607
+608
+609
+610
+611
+612
+613
+614
+615
+616
+617
+618
+619
+620
+621
+622
+623
+624
+625
+626
+627
+628
+629
+630
+631
+632
+633
+634
+635
+636
+637
+638
+639
+640
+641
+642
+643
+644
+645
+646
+647
+648
+649
+650
+651
+652
+653
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
+
+/*
+ *  Copyright (C) 2004 Red Hat, Inc.
+ * Copyright (C) 2012-2021 MATE Developers
+ *
+ *  Caja is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU General Public License as
+ *  published by the Free Software Foundation; either version 2 of the
+ *  License, or (at your option) any later version.
+ *
+ *  Caja is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  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
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ *  Authors: Alexander Larsson <alexl@redhat.com>
+ *
+ */
+
+#include "config.h"
+
+#include <string.h>
+#include <stdio.h>
+
+#include <gtk/gtk.h>
+#include <glib/gi18n.h>
+#include <gio/gio.h>
+
+#include "user_share-private.h"
+
+#define REALM "Please log in as the user guest"
+#define USER "guest"
+#define GSETTINGS_SCHEMA "org.mate.FileSharing"
+#define GSETTINGS_KEY_FILE_SHARING_ENABLED "enabled"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_ENABLED "bluetooth-enabled"
+#define GSETTINGS_KEY_FILE_SHARING_REQUIRE_PASSWORD "require-password"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_ALLOW_WRITE "bluetooth-allow-write"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_REQUIRE_PAIRING "bluetooth-require-pairing"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED "bluetooth-obexpush-enabled"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_ACCEPT_FILES "bluetooth-accept-files"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_NOTIFY "bluetooth-notify"
+
+static GtkBuilder* builder;
+static GSettings* settings;<--- Shadowed declaration<--- Shadowed declaration<--- Shadowed declaration<--- Shadowed declaration<--- Shadowed declaration<--- Shadowed declaration<--- Shadowed declaration<--- Shadowed declaration<--- Shadowed declaration<--- Shadowed declaration
+
+
+static void
+write_out_password (const char *password)
+{
+    char *to_hash;
+    char *ascii_digest;
+    char *line;
+    char *filename;
+    FILE *file;
+
+    to_hash = g_strdup_printf ("%s:%s:%s", USER, REALM, password);
+    ascii_digest = g_compute_checksum_for_string (G_CHECKSUM_MD5, to_hash, strlen (to_hash));
+    g_free (to_hash);
+    line = g_strdup_printf ("%s:%s:%s\n", USER, REALM, ascii_digest);
+    g_free (ascii_digest);
+
+    filename = g_build_filename (g_get_user_config_dir (), "user-share", "passwd", NULL);
+
+    file = fopen (filename, "w");
+    if (file != NULL) {
+	fwrite (line, strlen (line), 1, file);
+	fclose (file);
+    }
+
+    g_free (filename);
+    g_free (line);
+}
+
+static void
+flush_password (void)
+{
+    GtkWidget *password_entry;
+    const char *password;
+
+    password_entry = GTK_WIDGET (gtk_builder_get_object (builder, "password_entry"));
+
+    if (g_object_get_data (G_OBJECT( password_entry), "user_edited")) {
+	password = gtk_entry_get_text (GTK_ENTRY (password_entry));
+	if (password != NULL && password[0] != 0)
+	    write_out_password (password);
+    }
+}
+
+
+static void
+update_ui (void)
+{
+    GSettings *settings;<--- Shadow variable
+    gboolean enabled;
+#ifdef HAVE_BLUETOOTH
+    gboolean bluetooth_enabled, bluetooth_write_enabled, require_pairing_enabled;
+    gboolean bluetooth_obexpush_enabled, bluetooth_obexpush_notify;
+#endif /* HAVE_BLUETOOTH */
+    char *str;
+    PasswordSetting password_setting;
+    AcceptSetting accept_setting;<--- Unused variable: accept_setting
+    GtkWidget *check;
+    GtkWidget *password_combo;
+    GtkWidget *password_entry;
+#ifdef HAVE_BLUETOOTH
+    GtkWidget *vbox_share_bluetooth;
+    GtkWidget *vbox_receive_bluetooth;
+    GtkWidget *bluetooth_check;
+    GtkWidget *allow_write_bluetooth_check;
+    GtkWidget *require_pairing_check;
+    GtkWidget *enable_obexpush_check;
+    GtkWidget *accept_obexpush_combo;
+    GtkWidget *notify_received_obexpush_check;
+#endif /* HAVE_BLUETOOTH */
+
+    settings = g_settings_new (GSETTINGS_SCHEMA);
+
+    enabled = g_settings_get_boolean (settings,
+				     FILE_SHARING_ENABLED);
+
+    str = g_settings_get_string (settings, FILE_SHARING_REQUIRE_PASSWORD);
+    password_setting = password_setting_from_string (str);
+    g_free (str);
+
+#ifdef HAVE_BLUETOOTH
+    bluetooth_enabled = g_settings_get_boolean (settings,
+    					       FILE_SHARING_BLUETOOTH_ENABLED);
+    bluetooth_write_enabled = g_settings_get_boolean (settings,
+						     FILE_SHARING_BLUETOOTH_ALLOW_WRITE);
+    require_pairing_enabled = g_settings_get_boolean (settings,
+    						     FILE_SHARING_BLUETOOTH_REQUIRE_PAIRING);
+    bluetooth_obexpush_enabled = g_settings_get_boolean (settings,
+    							FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED);
+    bluetooth_obexpush_notify = g_settings_get_boolean (settings,
+    						       FILE_SHARING_BLUETOOTH_OBEXPUSH_NOTIFY);
+
+    str = g_settings_get_string (settings, FILE_SHARING_BLUETOOTH_OBEXPUSH_ACCEPT_FILES);
+    accept_setting = accept_setting_from_string (str);
+    g_free (str);
+#endif /* HAVE_BLUETOOTH */
+
+    check = GTK_WIDGET (gtk_builder_get_object (builder, "enable_check"));
+    password_combo = GTK_WIDGET (gtk_builder_get_object (builder, "password_combo"));
+    password_entry = GTK_WIDGET (gtk_builder_get_object (builder, "password_entry"));
+#ifdef HAVE_BLUETOOTH
+    vbox_share_bluetooth = GTK_WIDGET (gtk_builder_get_object (builder, "vbox_share_bluetooth"));
+    vbox_receive_bluetooth = GTK_WIDGET (gtk_builder_get_object (builder, "vbox_receive_bluetooth"));
+    bluetooth_check = GTK_WIDGET (gtk_builder_get_object (builder, "enable_bluetooth_check"));
+    allow_write_bluetooth_check = GTK_WIDGET (gtk_builder_get_object (builder, "allow_write_bluetooth_check"));
+    require_pairing_check = GTK_WIDGET (gtk_builder_get_object (builder, "require_pairing_check"));
+    enable_obexpush_check = GTK_WIDGET (gtk_builder_get_object (builder, "enable_obexpush_check"));
+    accept_obexpush_combo = GTK_WIDGET (gtk_builder_get_object (builder, "accept_obexpush_combo"));
+    notify_received_obexpush_check = GTK_WIDGET (gtk_builder_get_object (builder, "notify_received_obexpush_check"));
+#endif /* HAVE_BLUETOOTH */
+
+    /* Network */
+    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (check), enabled);
+    gtk_widget_set_sensitive (password_combo, enabled);
+    gtk_widget_set_sensitive (password_entry, enabled && password_setting != PASSWORD_NEVER);
+
+    gtk_combo_box_set_active (GTK_COMBO_BOX (password_combo),
+			      password_setting);
+
+#ifdef HAVE_BLUETOOTH
+    /* Bluetooth ObexFTP */
+    gtk_widget_set_visible (vbox_share_bluetooth, TRUE);
+    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (bluetooth_check), bluetooth_enabled);
+    gtk_widget_set_sensitive (allow_write_bluetooth_check, bluetooth_enabled);
+    gtk_widget_set_sensitive (require_pairing_check, bluetooth_enabled);
+
+    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (allow_write_bluetooth_check),
+    				  bluetooth_write_enabled);
+    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (require_pairing_check),
+    				  require_pairing_enabled);
+
+    /* Bluetooth ObexPush */
+    gtk_widget_set_visible (vbox_receive_bluetooth, TRUE);
+    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (enable_obexpush_check), bluetooth_obexpush_enabled);
+    gtk_widget_set_sensitive (accept_obexpush_combo, bluetooth_obexpush_enabled);
+    gtk_widget_set_sensitive (notify_received_obexpush_check, bluetooth_obexpush_enabled);
+
+    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (notify_received_obexpush_check),
+    				  bluetooth_obexpush_notify);
+
+    gtk_combo_box_set_active (GTK_COMBO_BOX (accept_obexpush_combo),
+    			      accept_setting);
+#endif /* HAVE_BLUETOOTH */
+
+    g_object_unref (settings);
+}
+
+static void
+file_sharing_enabled_changed (GSettings *settings, gchar *key, gpointer data)
+{
+    update_ui ();
+}
+
+static void
+password_required_changed (GSettings *settings, gchar *key, gpointer data)
+{
+    update_ui ();
+}
+
+#ifdef HAVE_BLUETOOTH
+static void
+file_sharing_bluetooth_enabled_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	update_ui ();
+}
+
+static void
+file_sharing_bluetooth_allow_write_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	update_ui ();
+}
+
+static void
+file_sharing_bluetooth_require_pairing_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	update_ui ();
+}
+
+static void
+file_sharing_bluetooth_obexpush_enabled_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	update_ui ();
+}
+
+static void
+file_sharing_bluetooth_obexpush_accept_files_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	update_ui ();
+}
+
+static void
+file_sharing_bluetooth_obexpush_notify_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	update_ui ();
+}
+#endif /* HAVE_BLUETOOTH */
+
+static void
+password_combo_changed (GtkComboBox *combo_box)
+{
+    GSettings *settings;<--- Shadow variable
+    guint setting;
+
+    setting = gtk_combo_box_get_active (combo_box);
+
+    settings = g_settings_new (GSETTINGS_SCHEMA) ;
+
+    g_settings_set_string (settings,
+			     FILE_SHARING_REQUIRE_PASSWORD,
+			     password_string_from_setting (setting));
+    g_object_unref (settings);
+}
+
+static void
+launch_share (void)
+{
+	if (!g_spawn_command_line_async (USER_SHARE_PROGRAM, NULL))
+		g_warning ("Unable to start mate-user-share program");
+}
+
+#ifdef HAVE_BLUETOOTH
+static void
+enable_bluetooth_check_toggled (GtkWidget *check)
+{
+	GSettings *settings;<--- Shadow variable
+	gboolean enabled;
+
+	enabled = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check));
+
+	settings = g_settings_new (GSETTINGS_SCHEMA) ;
+
+	g_settings_set_boolean (settings,
+			       FILE_SHARING_BLUETOOTH_ENABLED,
+			       enabled);
+
+	g_object_unref (settings);
+
+	if (enabled != FALSE)
+		launch_share ();
+}
+#endif /* HAVE_BLUETOOTH */
+
+static void
+enable_check_toggled (GtkWidget *check)
+{
+	GSettings *settings;<--- Shadow variable
+	gboolean enabled;
+
+	enabled = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check));
+
+	settings = g_settings_new (GSETTINGS_SCHEMA);
+
+	g_settings_set_boolean (settings,
+			       FILE_SHARING_ENABLED,
+			       enabled);
+
+	g_object_unref (settings);
+
+	if (enabled != FALSE)
+		launch_share ();
+}
+
+static void
+password_entry_changed (GtkEditable *editable)
+{
+	g_object_set_data (G_OBJECT (editable),
+			   "user_edited", GINT_TO_POINTER (1));
+	flush_password ();
+}
+
+#ifdef HAVE_BLUETOOTH
+static void
+bluetooth_allow_write_check_toggled (GtkWidget *check)
+{
+	GSettings *settings;<--- Shadow variable
+	gboolean enabled;
+
+	enabled = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check));
+
+	settings = g_settings_new (GSETTINGS_SCHEMA) ;
+
+	g_settings_set_boolean (settings,
+			       FILE_SHARING_BLUETOOTH_ALLOW_WRITE,
+			       enabled);
+
+	g_object_unref (settings);
+}
+
+static void
+bluetooth_require_pairing_check_toggled (GtkWidget *check)
+{
+	GSettings *settings;<--- Shadow variable
+	gboolean enabled;
+
+	enabled = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check));
+
+	settings = g_settings_new (GSETTINGS_SCHEMA) ;
+
+	g_settings_set_boolean (settings,
+			       FILE_SHARING_BLUETOOTH_REQUIRE_PAIRING,
+			       enabled);
+
+	g_object_unref (settings);
+}
+
+static void
+enable_obexpush_check_toggled (GtkWidget *check)
+{
+	GSettings *settings;<--- Shadow variable
+	gboolean enabled;
+
+	enabled = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check));
+
+	settings = g_settings_new (GSETTINGS_SCHEMA) ;
+
+	g_settings_set_boolean (settings,
+			       FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED,
+			       enabled);
+
+	g_object_unref (settings);
+
+	if (enabled != FALSE)
+		launch_share ();
+}
+
+static void
+accept_obexpush_combo_changed (GtkComboBox *combo_box)
+{
+    GSettings *settings;<--- Shadow variable
+    guint setting;
+
+    setting = gtk_combo_box_get_active (combo_box);
+
+    settings = g_settings_new (GSETTINGS_SCHEMA) ;
+
+    g_settings_set_string (settings,
+			     FILE_SHARING_BLUETOOTH_OBEXPUSH_ACCEPT_FILES,
+			     accept_string_from_setting (setting));
+    g_object_unref (settings);
+}
+
+static void
+notify_received_obexpush_check_toggled (GtkWidget *check)
+{
+	GSettings *settings;<--- Shadow variable
+	gboolean enabled;
+
+	enabled = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check));
+
+	settings = g_settings_new (GSETTINGS_SCHEMA) ;
+
+	g_settings_set_boolean (settings,
+			       FILE_SHARING_BLUETOOTH_OBEXPUSH_NOTIFY,
+			       enabled);
+
+	g_object_unref (settings);
+}
+#endif /* HAVE_BLUETOOTH */
+
+static GtkWidget *
+error_dialog (const char *title,
+	      const char *reason,
+	      GtkWindow *parent)
+{
+	GtkWidget *error_dialog;
+
+	if (reason == NULL)
+		reason = _("No reason");
+
+	error_dialog =
+		gtk_message_dialog_new (parent,
+					GTK_DIALOG_MODAL,
+					GTK_MESSAGE_ERROR,
+					GTK_BUTTONS_OK,
+					"%s", title);
+	gtk_message_dialog_format_secondary_text
+		(GTK_MESSAGE_DIALOG (error_dialog), "%s", reason);
+
+	gtk_window_set_title (GTK_WINDOW (error_dialog), ""); /* as per HIG */
+	gtk_container_set_border_width (GTK_CONTAINER (error_dialog), 5);
+	gtk_dialog_set_default_response (GTK_DIALOG (error_dialog),
+					 GTK_RESPONSE_OK);
+	gtk_window_set_modal (GTK_WINDOW (error_dialog), TRUE);
+
+	return error_dialog;
+}
+
+static void
+help_button_clicked (GtkButton *button, GtkWidget *window)
+{
+	GError *error = NULL;
+
+	if (gtk_show_uri_on_window (GTK_WINDOW (window), "help:mate-user-share", gtk_get_current_event_time (), &error) == FALSE) {
+		GtkWidget *dialog;
+
+		dialog = error_dialog (_("Could not display the help contents."), error->message, GTK_WINDOW (window));
+		g_signal_connect (G_OBJECT (dialog), "response", G_CALLBACK
+				  (gtk_widget_destroy), error_dialog);
+		gtk_window_present (GTK_WINDOW (dialog));
+
+		g_error_free (error);
+	}
+}
+
+static GtkWidget *
+create_window (void)
+{
+    GError *error = NULL;
+    GSettings *settings;<--- Shadow variable
+    GtkWidget *check;
+    GtkWidget *password_combo;
+    GtkWidget *password_entry;
+#ifdef HAVE_BLUETOOTH
+    GtkWidget *bluetooth_check;
+    GtkWidget *bluetooth_allow_write_check;
+    GtkWidget *require_pairing_check;
+    GtkWidget *enable_obexpush_check;
+    GtkWidget *accept_obexpush_combo;
+    GtkWidget *notify_received_obexpush_check;
+#endif /* HAVE_BLUETOOTH */
+    GtkWidget *window;
+    GtkListStore *store;
+    GtkCellRenderer *cell;
+    GtkTreeIter iter;
+
+    builder = gtk_builder_new ();
+    gtk_builder_add_from_file (builder, DATADIR"file-share-properties.ui", &error);
+
+    if (error) {
+      GtkWidget *dialog;
+
+      dialog = error_dialog (_("Could not build interface."), error->message, NULL);
+      gtk_dialog_run (GTK_DIALOG (dialog));
+      gtk_widget_destroy (dialog);
+
+      g_error_free (error);
+      return NULL;
+    }
+
+    window = GTK_WIDGET (gtk_builder_get_object (builder, "user_share_dialog"));
+
+    settings = g_settings_new (GSETTINGS_SCHEMA);
+
+    check = GTK_WIDGET (gtk_builder_get_object (builder, "enable_check"));
+    password_combo = GTK_WIDGET (gtk_builder_get_object (builder, "password_combo"));
+    password_entry = GTK_WIDGET (gtk_builder_get_object (builder, "password_entry"));
+#ifdef HAVE_BLUETOOTH
+    bluetooth_check = GTK_WIDGET (gtk_builder_get_object (builder, "enable_bluetooth_check"));
+    bluetooth_allow_write_check = GTK_WIDGET (gtk_builder_get_object (builder, "allow_write_bluetooth_check"));
+    require_pairing_check = GTK_WIDGET (gtk_builder_get_object (builder, "require_pairing_check"));
+    enable_obexpush_check = GTK_WIDGET (gtk_builder_get_object (builder, "enable_obexpush_check"));
+    accept_obexpush_combo = GTK_WIDGET (gtk_builder_get_object (builder, "accept_obexpush_combo"));
+    notify_received_obexpush_check = GTK_WIDGET (gtk_builder_get_object (builder, "notify_received_obexpush_check"));
+#endif /* HAVE_BLUETOOTH */
+
+    store = gtk_list_store_new (1, G_TYPE_STRING);
+    gtk_combo_box_set_model (GTK_COMBO_BOX (password_combo),
+			     GTK_TREE_MODEL (store));
+    cell = gtk_cell_renderer_text_new ();
+    gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (password_combo), cell, TRUE);
+    gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (password_combo), cell,
+				    "text", 0,
+				    NULL);
+
+    /* Keep in same order as enum */
+    gtk_list_store_append (store, &iter);
+    gtk_list_store_set (store, &iter, 0,
+			_("Never"), -1);
+    gtk_list_store_append (store, &iter);
+    gtk_list_store_set (store, &iter, 0,
+			_("When writing files"), -1);
+    gtk_list_store_append (store, &iter);
+    gtk_list_store_set (store, &iter, 0,
+			_("Always"), -1);
+    g_object_unref (store);
+
+    /* We can't read the password from the text, just set it to something */
+    gtk_entry_set_text (GTK_ENTRY (password_entry), "none");
+    g_object_set_data (G_OBJECT (password_entry),
+		       "user_edited", GINT_TO_POINTER (0));
+    g_signal_connect (password_entry,
+		      "changed", G_CALLBACK (password_entry_changed), NULL);
+
+#ifdef HAVE_BLUETOOTH
+    /* Accept files combo */
+    store = gtk_list_store_new (1, G_TYPE_STRING);
+    gtk_combo_box_set_model (GTK_COMBO_BOX (accept_obexpush_combo),
+			     GTK_TREE_MODEL (store));
+    cell = gtk_cell_renderer_text_new ();
+    gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (accept_obexpush_combo), cell, TRUE);
+    gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (accept_obexpush_combo), cell,
+				    "text", 0,
+				    NULL);
+
+    /* Keep in same order as enum */
+    gtk_list_store_append (store, &iter);
+    gtk_list_store_set (store, &iter, 0,
+			_("Always"), -1);
+    gtk_list_store_append (store, &iter);
+    gtk_list_store_set (store, &iter, 0,
+			_("Only for set up devices"), -1);
+    //FIXME implement
+#if 0
+    gtk_list_store_append (store, &iter);
+    gtk_list_store_set (store, &iter, 0,
+    			_("Ask"), -1);
+#endif
+    g_object_unref (store);
+#endif /* HAVE_BLUETOOTH */
+
+    g_signal_connect (check,
+		      "toggled", G_CALLBACK (enable_check_toggled), NULL);
+    g_signal_connect (password_combo,
+		      "changed", G_CALLBACK (password_combo_changed), NULL);
+#ifdef HAVE_BLUETOOTH
+    g_signal_connect (bluetooth_check,
+    		      "toggled", G_CALLBACK (enable_bluetooth_check_toggled), NULL);
+    g_signal_connect (bluetooth_allow_write_check,
+    		      "toggled", G_CALLBACK (bluetooth_allow_write_check_toggled), NULL);
+    g_signal_connect (require_pairing_check,
+    		      "toggled", G_CALLBACK (bluetooth_require_pairing_check_toggled), NULL);
+    g_signal_connect (enable_obexpush_check,
+    		      "toggled", G_CALLBACK (enable_obexpush_check_toggled), NULL);
+    g_signal_connect (accept_obexpush_combo,
+    		      "changed", G_CALLBACK (accept_obexpush_combo_changed), NULL);
+    g_signal_connect (notify_received_obexpush_check,
+    		      "toggled", G_CALLBACK (notify_received_obexpush_check_toggled), NULL);
+#endif /* HAVE_BLUETOOTH */
+
+    g_signal_connect_swapped (GTK_WIDGET (gtk_builder_get_object (builder, "close_button")),
+                              "clicked", G_CALLBACK (gtk_widget_destroy), window);
+    g_signal_connect (GTK_WIDGET (gtk_builder_get_object (builder, "help_button")),
+		      "clicked", G_CALLBACK (help_button_clicked),
+		      gtk_builder_get_object (builder, "user_share_dialog"));
+
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_ENABLED,
+			     G_CALLBACK (file_sharing_enabled_changed), NULL);
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_REQUIRE_PASSWORD,
+			     G_CALLBACK (password_required_changed), NULL);
+#ifdef HAVE_BLUETOOTH
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_ENABLED,
+			     G_CALLBACK (file_sharing_bluetooth_enabled_changed), NULL);
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_ALLOW_WRITE,
+			     G_CALLBACK (file_sharing_bluetooth_allow_write_changed), NULL);
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_REQUIRE_PAIRING,
+			     G_CALLBACK (file_sharing_bluetooth_require_pairing_changed), NULL);
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED,
+			     G_CALLBACK (file_sharing_bluetooth_obexpush_enabled_changed), NULL);
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_ACCEPT_FILES,
+			     G_CALLBACK (file_sharing_bluetooth_obexpush_accept_files_changed), NULL);
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_NOTIFY,
+			     G_CALLBACK (file_sharing_bluetooth_obexpush_notify_changed), NULL);
+#endif /* HAVE_BLUETOOTH */
+
+    update_ui ();
+
+    return window;
+}
+
+static void
+activate (GtkApplication *app)
+{
+    GList *list;
+    GtkWidget *window;
+
+    list = gtk_application_get_windows (app);
+
+    if (list) {
+        gtk_window_present (GTK_WINDOW (list->data));
+    } else {
+        window = create_window ();
+        gtk_window_set_application (GTK_WINDOW (window), app);
+        gtk_widget_show (window);
+    }
+}
+
+int
+main (int argc, char *argv[])
+{
+    GtkApplication *app;
+    gint status;
+
+    bindtextdomain (GETTEXT_PACKAGE, MATELOCALEDIR);
+    bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
+    textdomain (GETTEXT_PACKAGE);
+
+    app = gtk_application_new ("org.mate.user-share.properties",
+                               G_APPLICATION_FLAGS_NONE);
+    g_signal_connect (app, "activate", G_CALLBACK (activate), NULL);
+
+    status = g_application_run (G_APPLICATION (app), argc, argv);
+
+    g_object_unref (app);
+
+    return status;
+}
+
+
+
+
+ + + diff --git a/2021-06-25-153248-0614-cppcheck@198f334ccf4c_master/1.html b/2021-06-25-153248-0614-cppcheck@198f334ccf4c_master/1.html new file mode 100644 index 0000000..5897574 --- /dev/null +++ b/2021-06-25-153248-0614-cppcheck@198f334ccf4c_master/1.html @@ -0,0 +1,1061 @@ + + + + + + Cppcheck - HTML report - mate-user-share + + + + + + +
+ +
+
  1
+  2
+  3
+  4
+  5
+  6
+  7
+  8
+  9
+ 10
+ 11
+ 12
+ 13
+ 14
+ 15
+ 16
+ 17
+ 18
+ 19
+ 20
+ 21
+ 22
+ 23
+ 24
+ 25
+ 26
+ 27
+ 28
+ 29
+ 30
+ 31
+ 32
+ 33
+ 34
+ 35
+ 36
+ 37
+ 38
+ 39
+ 40
+ 41
+ 42
+ 43
+ 44
+ 45
+ 46
+ 47
+ 48
+ 49
+ 50
+ 51
+ 52
+ 53
+ 54
+ 55
+ 56
+ 57
+ 58
+ 59
+ 60
+ 61
+ 62
+ 63
+ 64
+ 65
+ 66
+ 67
+ 68
+ 69
+ 70
+ 71
+ 72
+ 73
+ 74
+ 75
+ 76
+ 77
+ 78
+ 79
+ 80
+ 81
+ 82
+ 83
+ 84
+ 85
+ 86
+ 87
+ 88
+ 89
+ 90
+ 91
+ 92
+ 93
+ 94
+ 95
+ 96
+ 97
+ 98
+ 99
+100
+101
+102
+103
+104
+105
+106
+107
+108
+109
+110
+111
+112
+113
+114
+115
+116
+117
+118
+119
+120
+121
+122
+123
+124
+125
+126
+127
+128
+129
+130
+131
+132
+133
+134
+135
+136
+137
+138
+139
+140
+141
+142
+143
+144
+145
+146
+147
+148
+149
+150
+151
+152
+153
+154
+155
+156
+157
+158
+159
+160
+161
+162
+163
+164
+165
+166
+167
+168
+169
+170
+171
+172
+173
+174
+175
+176
+177
+178
+179
+180
+181
+182
+183
+184
+185
+186
+187
+188
+189
+190
+191
+192
+193
+194
+195
+196
+197
+198
+199
+200
+201
+202
+203
+204
+205
+206
+207
+208
+209
+210
+211
+212
+213
+214
+215
+216
+217
+218
+219
+220
+221
+222
+223
+224
+225
+226
+227
+228
+229
+230
+231
+232
+233
+234
+235
+236
+237
+238
+239
+240
+241
+242
+243
+244
+245
+246
+247
+248
+249
+250
+251
+252
+253
+254
+255
+256
+257
+258
+259
+260
+261
+262
+263
+264
+265
+266
+267
+268
+269
+270
+271
+272
+273
+274
+275
+276
+277
+278
+279
+280
+281
+282
+283
+284
+285
+286
+287
+288
+289
+290
+291
+292
+293
+294
+295
+296
+297
+298
+299
+300
+301
+302
+303
+304
+305
+306
+307
+308
+309
+310
+311
+312
+313
+314
+315
+316
+317
+318
+319
+320
+321
+322
+323
+324
+325
+326
+327
+328
+329
+330
+331
+332
+333
+334
+335
+336
+337
+338
+339
+340
+341
+342
+343
+344
+345
+346
+347
+348
+349
+350
+351
+352
+353
+354
+355
+356
+357
+358
+359
+360
+361
+362
+363
+364
+365
+366
+367
+368
+369
+370
+371
+372
+373
+374
+375
+376
+377
+378
+379
+380
+381
+382
+383
+384
+385
+386
+387
+388
+389
+390
+391
+392
+393
+394
+395
+396
+397
+398
+399
+400
+401
+402
+403
+404
+405
+406
+407
+408
+409
+410
+411
+412
+413
+414
+415
+416
+417
+418
+419
+420
+421
+422
+423
+424
+425
+426
+427
+428
+429
+430
+431
+432
+433
+434
+435
+436
+437
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
+
+/*
+ *  Copyright (C) 2004-2008 Red Hat, Inc.
+ * Copyright (C) 2012-2021 MATE Developers
+ *
+ *  Caja is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU General Public License as
+ *  published by the Free Software Foundation; either version 2 of the
+ *  License, or (at your option) any later version.
+ *
+ *  Caja is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  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
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ *  Authors: Alexander Larsson <alexl@redhat.com>
+ *
+ */
+
+#include "config.h"
+
+#include <glib.h>
+#include <glib/gi18n.h>
+#include <X11/Xlib.h>
+
+#include <gio/gio.h>
+
+#include <stdarg.h>
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <signal.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <sys/stat.h>
+
+#ifdef HAVE_SELINUX
+#include <selinux/selinux.h>
+#endif
+
+#include "user_share-common.h"
+#include "user_share-private.h"
+#include "http.h"
+
+/* From avahi-common/domain.h */
+#define AVAHI_LABEL_MAX 64
+
+#define GSETTINGS_SCHEMA "org.mate.FileSharing"
+
+static pid_t httpd_pid = 0;
+
+static int
+get_port (void)
+{
+	int sock;
+	struct sockaddr_in addr;
+	int reuse;
+	socklen_t len;
+
+	sock = socket (PF_INET, SOCK_STREAM, 0);
+	if (sock < 0) {
+		return -1;
+	}
+
+	memset (&addr, 0, sizeof (addr));
+	addr.sin_port = 0;
+	addr.sin_addr.s_addr = INADDR_ANY;
+	addr.sin_family = AF_INET;
+
+	reuse = 1;
+	setsockopt (sock, SOL_SOCKET, SO_REUSEADDR, &reuse, sizeof (reuse));
+	if (bind (sock, (struct sockaddr *)&addr, sizeof (addr)) == -1) {
+		close (sock);
+		return -1;
+	}
+
+	len = sizeof (addr);
+	if (getsockname (sock, (struct sockaddr *)&addr, &len) == -1) {
+		close (sock);
+		return -1;
+	}
+
+#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__APPLE__) || defined(__OpenBSD__)
+	/* XXX This exposes a potential race condition, but without this,
+	 * httpd will not start on the above listed platforms due to the fact
+	 * that SO_REUSEADDR is also needed when Apache binds to the listening
+	 * socket.  At this time, Apache does not support that socket option.
+	 */
+	close (sock);
+#endif
+	return ntohs (addr.sin_port);
+}
+
+static char *
+truncate_name (const char *name)
+{
+	const char *end;
+
+	end = g_utf8_find_prev_char (name, name + 64);
+	g_assert (end != NULL);
+	return g_strndup (name, end - name);
+}
+
+static char *
+get_share_name (void)
+{
+	static char *name = NULL;
+	const char *host_name;
+	char *str;
+
+	if (name == NULL) {
+		host_name = g_get_host_name ();
+		if (strcmp (host_name, "localhost") == 0) {
+			/* Translators: The %s will get filled in with the user name
+			   of the user, to form a genitive. If this is difficult to
+			   translate correctly so that it will work correctly in your
+			   language, you may use something equivalent to
+			   "Public files of %s", or leave out the %s altogether.
+			   In the latter case, please put "%.0s" somewhere in the string,
+			   which will match the user name string passed by the C code,
+			   but not put the user name in the final string. This is to
+			   avoid the warning that msgfmt might otherwise generate. */
+			name = g_strdup_printf (_("%s's public files"), g_get_user_name ());
+		} else {
+			/* Translators: This is similar to the string before, only it
+			   has the hostname in it too. */
+			name = g_strdup_printf (_("%s's public files on %s"),
+						g_get_user_name (),
+						host_name);
+		}
+
+	}
+	/* And truncate */
+	if (strlen (name) < AVAHI_LABEL_MAX)
+		return name;
+
+	str = truncate_name (name);
+	g_free (name);
+	name = str;
+
+	return name;
+}
+
+static void
+ensure_conf_dir (void)
+{
+	char *dirname;
+
+	dirname = g_build_filename (g_get_user_config_dir (), "user-share", NULL);
+	g_mkdir_with_parents (dirname, 0755);
+	g_free (dirname);
+}
+
+static void
+httpd_child_setup (gpointer user_data)
+{
+#ifdef HAVE_SELINUX
+	char *mycon;
+	/* If selinux is enabled, avoid transitioning to the httpd_t context,
+	   as this normally means you can't read the users homedir. */
+	if (is_selinux_enabled()) {
+		if (getcon (&mycon) < 0) {
+			abort ();
+		}
+		if (setexeccon (mycon) < 0)
+			abort ();
+		freecon (mycon);
+	}
+#endif
+}
+
+static const char *known_httpd_locations [] = {
+	HTTPD_PROGRAM,
+	"/usr/sbin/httpd",
+	"/usr/sbin/httpd2",
+	"/usr/sbin/apache2",
+	NULL
+};
+
+static char*
+get_httpd_program (void)
+{
+	int i;
+
+	for (i = 0; known_httpd_locations[i]; i++) {
+		if (known_httpd_locations[i][0] == '\0') {
+			/* empty string as first element, happens when
+			 * configured --with-httpd=auto */
+			continue;
+		}
+		if (g_file_test (known_httpd_locations[i], G_FILE_TEST_IS_EXECUTABLE)
+				&& ! g_file_test (known_httpd_locations[i], G_FILE_TEST_IS_DIR)) {
+			return g_strdup (known_httpd_locations[i]);
+		}
+	}
+	return NULL;
+}
+
+static const char *known_httpd_modules_locations [] = {
+	HTTPD_MODULES_PATH,
+	"/etc/httpd/modules",
+	"/usr/lib/apache2/modules",
+	NULL
+};
+
+static gchar*
+get_httpd_modules_path (void)
+{
+	int i;
+
+	for (i = 0; known_httpd_modules_locations[i]; i++) {
+		if (known_httpd_modules_locations[i][0] == '\0') {
+			/* empty string as first element, happens when
+			 * configured --with-httpd=auto */
+			continue;
+		}
+		if (g_file_test (known_httpd_modules_locations[i], G_FILE_TEST_IS_EXECUTABLE)
+				&& g_file_test (known_httpd_modules_locations[i], G_FILE_TEST_IS_DIR)) {
+			return g_strdup (known_httpd_modules_locations[i]);
+		}
+	}
+	return NULL;
+}
+
+static GRegex *version_regex = NULL;
+
+static char*
+get_httpd_config (const char *httpd_program)
+{
+	gchar *standard_output;
+	gchar *cmd_line;
+	GMatchInfo *match_info;
+	gchar *version_number = NULL;
+	gchar *config;
+
+	cmd_line = g_strdup_printf ("%s -v", httpd_program);
+	if (! g_spawn_command_line_sync (cmd_line, &standard_output, NULL, NULL, NULL)) {
+		g_free (cmd_line);
+		return NULL;
+	}
+	g_free (cmd_line);
+
+	if (version_regex == NULL) {
+		version_regex = g_regex_new ("\\d\\.\\d", 0, 0, NULL);
+	}
+
+	if (g_regex_match (version_regex, standard_output, 0, &match_info)) {
+		while (g_match_info_matches (match_info)) {
+			version_number = g_match_info_fetch (match_info, 0);
+			break;
+		}
+		g_match_info_free (match_info);
+		g_free (standard_output);
+	} else {
+		/* Failed to parse httpd version number */
+		g_warning ("Could not parse '%s' as a version for httpd", standard_output);
+		g_free (standard_output);
+		/* assume it is 2.2 */
+		version_number = g_strdup ("2.2");
+	}
+
+	config = g_strdup_printf (HTTPD_CONFIG_TEMPLATE, version_number);
+	g_free (version_number);
+
+	return config;
+}
+
+static gboolean
+spawn_httpd (int port, pid_t *pid_out)
+{
+	char *free1, *free2, *free3, *free4, *free5, *free6, *free7, *free8, *free9;
+	gboolean res;
+	char *argv[10];
+	char *env[10];
+	int i;
+	gint status;
+	char *pid_filename;
+	char *pidfile;
+	GError *error;
+	gboolean got_pidfile;
+	GSettings *settings;
+	char *str;
+	char *public_dir;
+
+	public_dir = lookup_public_dir ();
+	ensure_conf_dir ();
+
+	i = 0;
+	free1 = argv[i++] = get_httpd_program ();
+	if (argv[0] == NULL) {
+		fprintf (stderr, "error finding httpd server\n");
+		return FALSE;
+	}
+
+	argv[i++] = "-f";
+	free2 = argv[i++] = get_httpd_config (argv[0]);
+	argv[i++] = "-C";
+	free3 = argv[i++] = g_strdup_printf ("Listen %d", port);
+
+	settings = g_settings_new (GSETTINGS_SCHEMA);
+	str = g_settings_get_string (settings,
+				       FILE_SHARING_REQUIRE_PASSWORD);
+
+	if (str && strcmp (str, "never") == 0) {
+		/* Do nothing */
+	} else if (str && strcmp (str, "on_write") == 0){
+		argv[i++] = "-D";
+		argv[i++] = "RequirePasswordOnWrite";
+	} else {
+		/* always, or safe fallback */
+		argv[i++] = "-D";
+		argv[i++] = "RequirePasswordAlways";
+	}
+	g_free (str);
+	g_object_unref (settings);
+
+	argv[i] = NULL;
+
+	i = 0;
+	free4 = env[i++] = g_strdup_printf ("HOME=%s", g_get_home_dir());
+	free5 = env[i++] = g_strdup_printf ("XDG_PUBLICSHARE_DIR=%s", public_dir);
+	free6 = env[i++] = g_strdup_printf ("XDG_CONFIG_HOME=%s", g_get_user_config_dir ());
+	free7 = env[i++] = g_strdup_printf ("GUS_SHARE_NAME=%s", get_share_name ());
+	free8 = env[i++] = g_strdup_printf ("GUS_LOGIN_LABEL=%s", "Please log in as the user guest");
+	free9 = env[i++] = g_strdup_printf ("HTTP_MODULES_PATH=%s",get_httpd_modules_path ());
+	env[i++] = "LANG=C";
+	env[i] = NULL;
+
+	pid_filename = g_build_filename (g_get_user_config_dir (), "user-share", "pid", NULL);
+
+	/* Remove pid file before spawning to avoid races with child and old pidfile */
+	unlink (pid_filename);
+
+	error = NULL;
+	res = g_spawn_sync (g_get_home_dir(),
+			    argv, env, 0,
+			    httpd_child_setup, NULL,
+			    NULL, NULL,
+			    &status,
+			    &error);
+	g_free (free1);
+	g_free (free2);
+	g_free (free3);
+	g_free (free4);
+	g_free (free5);
+	g_free (free6);
+	g_free (free7);
+	g_free (free8);
+	g_free (free9);
+	g_free (public_dir);
+
+	if (!res) {
+		fprintf (stderr, "error spawning httpd: %s\n",
+			 error->message);
+		g_error_free (error);
+		g_free (pid_filename);
+		return FALSE;
+	}
+
+	if (status != 0) {
+		g_free (pid_filename);
+		return FALSE;
+	}
+
+	got_pidfile = FALSE;
+	error = NULL;
+	for (i = 0; i < 5; i++) {
+		if (error != NULL)
+			g_error_free (error);
+		error = NULL;
+		if (g_file_get_contents (pid_filename, &pidfile, NULL, &error)) {
+			got_pidfile = TRUE;
+			*pid_out = atoi (pidfile);
+			g_free (pidfile);
+			break;
+		}
+		sleep (1);
+	}
+
+	g_free (pid_filename);
+
+	if (!got_pidfile) {
+		fprintf (stderr, "error opening httpd pidfile: %s\n", error->message);
+		g_error_free (error);
+		return FALSE;
+	}
+	return TRUE;
+}
+
+static void
+kill_httpd (void)
+{
+	if (httpd_pid != 0) {
+		kill (httpd_pid, SIGTERM);
+
+		/* Allow child time to die, we can't waitpid, because its
+		   not a direct child */
+		sleep (1);
+	}
+	httpd_pid = 0;
+}
+
+void
+http_up (void)
+{
+	guint port;
+
+	port = get_port ();
+	if (!spawn_httpd (port, &httpd_pid)) {
+		fprintf (stderr, "spawning httpd failed\n");
+	}
+}
+
+void
+http_down (void)
+{
+	kill_httpd ();
+}
+
+gboolean
+http_init (void)
+{
+	return TRUE;
+}
+
+pid_t
+http_get_pid (void)
+{
+	return httpd_pid;
+}
+
+
+
+
+ + + diff --git a/2021-06-25-153248-0614-cppcheck@198f334ccf4c_master/2.html b/2021-06-25-153248-0614-cppcheck@198f334ccf4c_master/2.html new file mode 100644 index 0000000..4049036 --- /dev/null +++ b/2021-06-25-153248-0614-cppcheck@198f334ccf4c_master/2.html @@ -0,0 +1,1295 @@ + + + + + + Cppcheck - HTML report - mate-user-share + + + + + + +
+ +
+
  1
+  2
+  3
+  4
+  5
+  6
+  7
+  8
+  9
+ 10
+ 11
+ 12
+ 13
+ 14
+ 15
+ 16
+ 17
+ 18
+ 19
+ 20
+ 21
+ 22
+ 23
+ 24
+ 25
+ 26
+ 27
+ 28
+ 29
+ 30
+ 31
+ 32
+ 33
+ 34
+ 35
+ 36
+ 37
+ 38
+ 39
+ 40
+ 41
+ 42
+ 43
+ 44
+ 45
+ 46
+ 47
+ 48
+ 49
+ 50
+ 51
+ 52
+ 53
+ 54
+ 55
+ 56
+ 57
+ 58
+ 59
+ 60
+ 61
+ 62
+ 63
+ 64
+ 65
+ 66
+ 67
+ 68
+ 69
+ 70
+ 71
+ 72
+ 73
+ 74
+ 75
+ 76
+ 77
+ 78
+ 79
+ 80
+ 81
+ 82
+ 83
+ 84
+ 85
+ 86
+ 87
+ 88
+ 89
+ 90
+ 91
+ 92
+ 93
+ 94
+ 95
+ 96
+ 97
+ 98
+ 99
+100
+101
+102
+103
+104
+105
+106
+107
+108
+109
+110
+111
+112
+113
+114
+115
+116
+117
+118
+119
+120
+121
+122
+123
+124
+125
+126
+127
+128
+129
+130
+131
+132
+133
+134
+135
+136
+137
+138
+139
+140
+141
+142
+143
+144
+145
+146
+147
+148
+149
+150
+151
+152
+153
+154
+155
+156
+157
+158
+159
+160
+161
+162
+163
+164
+165
+166
+167
+168
+169
+170
+171
+172
+173
+174
+175
+176
+177
+178
+179
+180
+181
+182
+183
+184
+185
+186
+187
+188
+189
+190
+191
+192
+193
+194
+195
+196
+197
+198
+199
+200
+201
+202
+203
+204
+205
+206
+207
+208
+209
+210
+211
+212
+213
+214
+215
+216
+217
+218
+219
+220
+221
+222
+223
+224
+225
+226
+227
+228
+229
+230
+231
+232
+233
+234
+235
+236
+237
+238
+239
+240
+241
+242
+243
+244
+245
+246
+247
+248
+249
+250
+251
+252
+253
+254
+255
+256
+257
+258
+259
+260
+261
+262
+263
+264
+265
+266
+267
+268
+269
+270
+271
+272
+273
+274
+275
+276
+277
+278
+279
+280
+281
+282
+283
+284
+285
+286
+287
+288
+289
+290
+291
+292
+293
+294
+295
+296
+297
+298
+299
+300
+301
+302
+303
+304
+305
+306
+307
+308
+309
+310
+311
+312
+313
+314
+315
+316
+317
+318
+319
+320
+321
+322
+323
+324
+325
+326
+327
+328
+329
+330
+331
+332
+333
+334
+335
+336
+337
+338
+339
+340
+341
+342
+343
+344
+345
+346
+347
+348
+349
+350
+351
+352
+353
+354
+355
+356
+357
+358
+359
+360
+361
+362
+363
+364
+365
+366
+367
+368
+369
+370
+371
+372
+373
+374
+375
+376
+377
+378
+379
+380
+381
+382
+383
+384
+385
+386
+387
+388
+389
+390
+391
+392
+393
+394
+395
+396
+397
+398
+399
+400
+401
+402
+403
+404
+405
+406
+407
+408
+409
+410
+411
+412
+413
+414
+415
+416
+417
+418
+419
+420
+421
+422
+423
+424
+425
+426
+427
+428
+429
+430
+431
+432
+433
+434
+435
+436
+437
+438
+439
+440
+441
+442
+443
+444
+445
+446
+447
+448
+449
+450
+451
+452
+453
+454
+455
+456
+457
+458
+459
+460
+461
+462
+463
+464
+465
+466
+467
+468
+469
+470
+471
+472
+473
+474
+475
+476
+477
+478
+479
+480
+481
+482
+483
+484
+485
+486
+487
+488
+489
+490
+491
+492
+493
+494
+495
+496
+497
+498
+499
+500
+501
+502
+503
+504
+505
+506
+507
+508
+509
+510
+511
+512
+513
+514
+515
+516
+517
+518
+519
+520
+521
+522
+523
+524
+525
+526
+527
+528
+529
+530
+531
+532
+533
+534
+535
+536
+537
+538
+539
+540
+541
+542
+543
+544
+545
+546
+547
+548
+549
+550
+551
+552
+553
+554
+555
+556
+557
+558
+559
+560
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
+
+/*
+ *  Copyright (C) 2004-2008 Red Hat, Inc.
+ *  Copyright (C) 2012-2021 MATE Developers
+ *
+ *  Caja is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU General Public License as
+ *  published by the Free Software Foundation; either version 2 of the
+ *  License, or (at your option) any later version.
+ *
+ *  Caja is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  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
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ *  Authors: Bastien Nocera <hadess@hadess.net>
+ *
+ */
+
+#include "config.h"
+
+#include <glib.h>
+#include <glib/gi18n.h>
+#include <gio/gio.h>
+#include <gdk/gdk.h>
+#include <gtk/gtk.h>
+#include <libnotify/notify.h>
+#include <dbus/dbus-glib.h>
+#include <dbus/dbus-glib-lowlevel.h>
+#include <canberra-gtk.h>
+
+#include <string.h>
+
+#include "marshal.h"
+#include "obexpush.h"
+#include "user_share-common.h"
+#include "user_share-private.h"
+
+#define DBUS_TYPE_G_STRING_VARIANT_HASHTABLE (dbus_g_type_get_map ("GHashTable", G_TYPE_STRING, G_TYPE_STRING))
+
+#define GSETTINGS_SCHEMA "org.mate.FileSharing"
+
+static DBusGConnection *connection = NULL;<--- Shadowed declaration
+static DBusGProxy *manager_proxy = NULL;
+static DBusGProxy *server_proxy = NULL;
+static AcceptSetting accept_setting = -1;
+static gboolean show_notifications = FALSE;
+
+static GtkStatusIcon *statusicon = NULL;
+static guint num_notifications = 0;
+
+static void
+hide_statusicon (void)
+{
+	num_notifications--;
+	if (num_notifications == 0)
+		gtk_status_icon_set_visible (statusicon, FALSE);
+}
+
+static void
+on_close_notification (NotifyNotification *notification)
+{
+	hide_statusicon ();
+	g_object_unref (notification);
+}
+
+static void
+notification_launch_action_on_file_cb (NotifyNotification *notification,
+				       const char *action,
+				       const char *file_uri)
+{
+	GdkScreen *screen;
+	GAppLaunchContext *ctx;
+	GTimeVal val;
+
+	g_assert (action != NULL);
+
+	g_get_current_time (&val);
+
+	ctx = G_APP_LAUNCH_CONTEXT (gdk_app_launch_context_new ());
+	screen = gdk_screen_get_default ();
+	gdk_app_launch_context_set_screen (GDK_APP_LAUNCH_CONTEXT (ctx), screen);
+	gdk_app_launch_context_set_timestamp (GDK_APP_LAUNCH_CONTEXT (ctx), val.tv_sec);
+
+	/* We launch the file viewer for the file */
+	if (g_str_equal (action, "display") != FALSE) {
+		if (g_app_info_launch_default_for_uri (file_uri, ctx, NULL) == FALSE) {
+			g_warning ("Failed to launch the file viewer\n");
+		}
+	}
+
+	/* we open the Downloads folder */
+	if (g_str_equal (action, "reveal") != FALSE) {
+		GFile *file;
+		GFile *parent;
+		gchar *parent_uri;
+
+		file = g_file_new_for_uri (file_uri);
+		parent = g_file_get_parent (file);
+		parent_uri = g_file_get_uri (parent);
+		g_object_unref (file);
+		g_object_unref (parent);
+
+		if (!g_app_info_launch_default_for_uri (parent_uri, ctx, NULL)) {
+			g_warning ("Failed to launch the file manager\n");
+		}
+
+		g_free (parent_uri);
+	}
+
+	notify_notification_close (notification, NULL);
+	/* No need to call hide_statusicon(), closing the notification
+	 * will call the close callback */
+}
+
+static void
+show_notification (const char *filename)
+{
+	char *file_uri, *notification_text, *display, *mime_type;
+	NotifyNotification *notification;
+	ca_context *ctx;
+	GAppInfo *app;
+
+	file_uri = g_filename_to_uri (filename, NULL, NULL);
+	if (file_uri == NULL) {
+		g_warning ("Could not make a filename from '%s'", filename);
+		return;
+	}
+
+	display = g_filename_display_basename (filename);
+	/* Translators: %s is the name of the filename received */
+	notification_text = g_strdup_printf(_("You received \"%s\" via Bluetooth"), display);
+	g_free (display);
+	notification = notify_notification_new (_("You received a file"),
+								 notification_text,
+								 "dialog-information");
+
+	notify_notification_set_timeout (notification, NOTIFY_EXPIRES_DEFAULT);
+
+	mime_type = g_content_type_guess (filename, NULL, 0, NULL);
+	app = g_app_info_get_default_for_type (mime_type, FALSE);
+	if (app != NULL) {
+		g_object_unref (app);
+		notify_notification_add_action (notification, "display", _("Open File"),
+						(NotifyActionCallback) notification_launch_action_on_file_cb,
+						g_strdup (file_uri), (GFreeFunc) g_free);
+	}
+	notify_notification_add_action (notification, "reveal", _("Reveal File"),
+					(NotifyActionCallback) notification_launch_action_on_file_cb,
+					g_strdup (file_uri), (GFreeFunc) g_free);
+
+	g_free (file_uri);
+
+	g_signal_connect (G_OBJECT (notification), "closed", G_CALLBACK (on_close_notification), notification);
+
+	if (!notify_notification_show (notification, NULL)) {
+		g_warning ("failed to send notification\n");
+	}
+	g_free (notification_text);
+
+	/* Now we do the audio notification */
+	ctx = ca_gtk_context_get ();
+	ca_context_play (ctx, 0,
+			 CA_PROP_EVENT_ID, "complete-download",
+			 CA_PROP_EVENT_DESCRIPTION, _("File reception complete"),
+			 NULL);
+}
+
+static void
+show_icon (void)
+{
+	if (statusicon == NULL) {
+		statusicon = gtk_status_icon_new_from_icon_name ("mate-obex-server");
+	} else {
+		gtk_status_icon_set_visible (statusicon, TRUE);
+	}
+	num_notifications++;
+}
+
+static gboolean
+device_is_authorised (const char *bdaddr)
+{
+	DBusGConnection *connection;<--- Shadow variable
+	DBusGProxy *manager;
+	GError *error = NULL;
+	GPtrArray *adapters;
+	gboolean retval = FALSE;
+	guint i;
+
+	connection = dbus_g_bus_get (DBUS_BUS_SYSTEM, NULL);
+	if (connection == NULL)
+		return FALSE;
+
+	manager = dbus_g_proxy_new_for_name (connection, "org.bluez",
+					     "/", "org.bluez.Manager");
+	if (manager == NULL) {
+		dbus_g_connection_unref (connection);
+		return FALSE;
+	}
+
+	if (dbus_g_proxy_call (manager, "ListAdapters", &error, G_TYPE_INVALID, dbus_g_type_get_collection ("GPtrArray", DBUS_TYPE_G_OBJECT_PATH), &adapters, G_TYPE_INVALID) == FALSE) {
+		g_object_unref (manager);
+		dbus_g_connection_unref (connection);
+		return FALSE;
+	}
+
+	for (i = 0; i < adapters->len; i++) {
+		DBusGProxy *adapter, *device;
+		char *device_path;
+		GHashTable *props;
+
+		g_debug ("checking adapter %s", (gchar *) g_ptr_array_index (adapters, i));
+
+		adapter = dbus_g_proxy_new_for_name (connection, "org.bluez",
+						    g_ptr_array_index (adapters, i), "org.bluez.Adapter");
+
+		if (dbus_g_proxy_call (adapter, "FindDevice", NULL,
+				       G_TYPE_STRING, bdaddr, G_TYPE_INVALID,
+				       DBUS_TYPE_G_OBJECT_PATH, &device_path, G_TYPE_INVALID) == FALSE)
+		{
+			g_object_unref (adapter);
+			continue;
+		}
+
+		device = dbus_g_proxy_new_for_name (connection, "org.bluez", device_path, "org.bluez.Device");
+
+		if (dbus_g_proxy_call (device, "GetProperties", NULL,
+				       G_TYPE_INVALID, dbus_g_type_get_map ("GHashTable", G_TYPE_STRING, G_TYPE_VALUE),
+				       &props, G_TYPE_INVALID) != FALSE)
+		{
+			GValue *value;
+			gboolean bonded;
+
+			value = g_hash_table_lookup (props, "Paired");
+			bonded = g_value_get_boolean (value);
+			g_message ("%s is %s", bdaddr, bonded ? "bonded" : "not bonded");
+
+			if (bonded) {
+				g_hash_table_destroy (props);
+				g_object_unref (device);
+				g_object_unref (adapter);
+				retval = TRUE;
+				break;
+			}
+		}
+		g_object_unref(adapter);
+	}
+
+	g_ptr_array_free (adapters, TRUE);
+
+	g_object_unref(manager);
+	dbus_g_connection_unref(connection);
+
+	return retval;
+}
+
+static void
+transfer_started_cb (DBusGProxy *session,
+		     const char *filename,
+		     const char *local_path,
+		     guint64 size,
+		     gpointer user_data)
+{
+	GHashTable *dict;
+	DBusGProxy *server = (DBusGProxy *) user_data;
+	GError *error = NULL;
+	gboolean authorise;
+
+	g_message ("transfer started on %s", local_path);
+	g_object_set_data_full (G_OBJECT (session), "filename", g_strdup (local_path), (GDestroyNotify) g_free);
+
+	show_icon ();
+
+	/* First transfer of the session */
+	if (g_object_get_data (G_OBJECT (session), "bdaddr") == NULL) {
+		const char *bdaddr;
+
+		if (dbus_g_proxy_call (server, "GetServerSessionInfo", &error,
+				       DBUS_TYPE_G_OBJECT_PATH, dbus_g_proxy_get_path (session), G_TYPE_INVALID,
+				       DBUS_TYPE_G_STRING_VARIANT_HASHTABLE, &dict, G_TYPE_INVALID) == FALSE) {
+			g_printerr ("Getting Server session info failed: %s\n",
+				    error->message);
+			g_error_free (error);
+			return;
+		}
+
+		bdaddr = g_hash_table_lookup (dict, "BluetoothAddress");
+		g_message ("transfer started for device %s", bdaddr);
+
+		g_object_set_data_full (G_OBJECT (session), "bdaddr", g_strdup (bdaddr), (GDestroyNotify) g_free);
+		/* Initial accept method is undefined, we do that lower down */
+		g_object_set_data (G_OBJECT (session), "accept-method", GINT_TO_POINTER (-1));
+		g_hash_table_destroy (dict);
+	}
+
+	/* Accept method changed */
+	if (GPOINTER_TO_INT (g_object_get_data (G_OBJECT (session), "accept-method")) != accept_setting) {
+		const char *bdaddr;
+
+		bdaddr = g_object_get_data (G_OBJECT (session), "bdaddr");
+
+		if (bdaddr == NULL) {
+			g_warning ("Couldn't get the Bluetooth address for the device, rejecting the transfer");
+			authorise = FALSE;
+		} else if (accept_setting == ACCEPT_ALWAYS) {
+			authorise = TRUE;
+		} else if (accept_setting == ACCEPT_BONDED) {
+			authorise = device_is_authorised (bdaddr);
+		} else {
+			//FIXME implement
+			g_warning ("\"Ask\" authorisation method not implemented");
+			authorise = FALSE;
+		}
+		g_object_set_data (G_OBJECT (session), "authorise", GINT_TO_POINTER (authorise));
+	}
+
+	g_message ("accept_setting: %d", accept_setting);
+
+	authorise = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (session), "authorise"));
+	if (authorise != FALSE) {
+		if (dbus_g_proxy_call (session, "Accept", &error, G_TYPE_INVALID, G_TYPE_INVALID) == FALSE) {
+			g_printerr ("Failed to accept file transfer: %s\n", error->message);
+			g_error_free (error);
+			return;
+		}
+		g_message ("authorised transfer");
+	} else {
+		if (dbus_g_proxy_call (session, "Reject", &error, G_TYPE_INVALID, G_TYPE_INVALID) == FALSE) {
+			g_printerr ("Failed to reject file transfer: %s\n", error->message);
+			g_error_free (error);
+			return;
+		}
+		g_message ("rejected transfer");
+		g_object_set_data (G_OBJECT (session), "filename", NULL);
+	}
+}
+
+static void
+transfer_completed_cb (DBusGProxy *session,
+		       gpointer user_data)
+{
+	GSettings *settings;
+	gboolean display_notify;
+	const char *filename;
+
+	filename = (const char *) g_object_get_data (G_OBJECT (session), "filename");
+
+	g_message ("file finish transfer: %s", filename);
+
+	if (filename == NULL)
+		return;
+
+	settings = g_settings_new (GSETTINGS_SCHEMA);
+	display_notify = g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_OBEXPUSH_NOTIFY);
+	g_object_unref (settings);
+
+	if (display_notify) {
+		show_notification (filename);
+	} else {
+		hide_statusicon ();
+	}
+	g_object_set_data (G_OBJECT (session), "filename", NULL);
+}
+
+static void
+cancelled_cb (DBusGProxy *session,
+	      gpointer user_data)
+{
+	//FIXME implement properly, we never actually finished the transfer
+	g_message ("transfered was cancelled by the sender");
+	transfer_completed_cb (session, user_data);
+	hide_statusicon ();
+}
+
+static void
+error_occurred_cb (DBusGProxy *session,
+		   const char *error_name,
+		   const char *error_message,
+		   gpointer user_data)
+{
+	//FIXME implement properly
+	g_message ("transfer error occurred: %s", error_message);
+	transfer_completed_cb (session, user_data);
+}
+
+static void
+session_created_cb (DBusGProxy *server, const char *session_path, gpointer user_data)
+{
+	DBusGProxy *session;
+
+	session = dbus_g_proxy_new_for_name (connection,
+					     "org.openobex",
+					     session_path,
+					     "org.openobex.ServerSession");
+
+	dbus_g_proxy_add_signal (session, "TransferStarted",
+				 G_TYPE_STRING, G_TYPE_STRING, G_TYPE_UINT64, G_TYPE_INVALID);
+	dbus_g_proxy_connect_signal(session, "TransferStarted",
+				    G_CALLBACK (transfer_started_cb), server, NULL);
+	dbus_g_proxy_add_signal (session, "TransferCompleted",
+				 G_TYPE_INVALID, G_TYPE_INVALID);
+	dbus_g_proxy_connect_signal(session, "TransferCompleted",
+				    G_CALLBACK (transfer_completed_cb), server, NULL);
+	dbus_g_proxy_add_signal (session, "Cancelled",
+				 G_TYPE_INVALID, G_TYPE_INVALID);
+	dbus_g_proxy_connect_signal(session, "Cancelled",
+				    G_CALLBACK (cancelled_cb), server, NULL);
+	dbus_g_proxy_add_signal (session, "ErrorOccurred",
+				 G_TYPE_INVALID, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INVALID);
+	dbus_g_proxy_connect_signal(session, "ErrorOccurred",
+				    G_CALLBACK (error_occurred_cb), server, NULL);
+}
+
+void
+obexpush_up (void)
+{
+	GError *err = NULL;
+	char *download_dir, *server;
+
+	server = NULL;
+	if (manager_proxy == NULL) {
+		manager_proxy = dbus_g_proxy_new_for_name (connection,
+							   "org.openobex",
+							   "/org/openobex",
+							   "org.openobex.Manager");
+		if (dbus_g_proxy_call (manager_proxy, "CreateBluetoothServer",
+				       &err, G_TYPE_STRING, "00:00:00:00:00:00", G_TYPE_STRING, "opp", G_TYPE_BOOLEAN, FALSE, G_TYPE_INVALID,
+				       DBUS_TYPE_G_OBJECT_PATH, &server, G_TYPE_INVALID) == FALSE) {
+			g_printerr ("Creating Bluetooth ObexPush server failed: %s\n",
+				    err->message);
+			g_error_free (err);
+			g_object_unref (manager_proxy);
+			manager_proxy = NULL;
+			return;
+		}
+	}
+
+	download_dir = lookup_download_dir ();
+
+	if (server_proxy == NULL) {
+		server_proxy = dbus_g_proxy_new_for_name (connection,
+							   "org.openobex",
+							   server,
+							   "org.openobex.Server");
+		g_free (server);
+
+		dbus_g_proxy_add_signal (server_proxy, "SessionCreated",
+					 DBUS_TYPE_G_OBJECT_PATH, G_TYPE_INVALID);
+		dbus_g_proxy_connect_signal(server_proxy, "SessionCreated",
+					    G_CALLBACK (session_created_cb), NULL, NULL);
+	}
+
+	if (dbus_g_proxy_call (server_proxy, "Start", &err,
+			   G_TYPE_STRING, download_dir, G_TYPE_BOOLEAN, TRUE, G_TYPE_BOOLEAN, FALSE, G_TYPE_INVALID,
+			   G_TYPE_INVALID) == FALSE) {
+		if (g_error_matches (err, DBUS_GERROR, DBUS_GERROR_REMOTE_EXCEPTION) != FALSE &&
+		    dbus_g_error_has_name (err, "org.openobex.Error.Started") != FALSE) {
+		    	g_error_free (err);
+		    	g_message ("already started, ignoring error");
+		    	g_free (download_dir);
+		    	return;
+		}
+		g_printerr ("Starting Bluetooth ObexPush server failed: %s\n",
+			    err->message);
+		g_error_free (err);
+		g_free (download_dir);
+		g_object_unref (server_proxy);
+		server_proxy = NULL;
+		g_object_unref (manager_proxy);
+		manager_proxy = NULL;
+		return;
+	}
+
+	g_free (download_dir);
+}
+
+static void
+obexpush_stop (gboolean stop_manager)
+{
+	GError *err = NULL;
+
+	if (server_proxy == NULL)
+		return;
+
+	if (dbus_g_proxy_call (server_proxy, "Close", &err, G_TYPE_INVALID, G_TYPE_INVALID) == FALSE) {
+		if (g_error_matches (err, DBUS_GERROR, DBUS_GERROR_REMOTE_EXCEPTION) == FALSE ||
+		    dbus_g_error_has_name (err, "org.openobex.Error.NotStarted") == FALSE) {
+			g_printerr ("Stopping Bluetooth ObexPush server failed: %s\n",
+				    err->message);
+			g_error_free (err);
+			return;
+		}
+		g_error_free (err);
+	}
+
+	if (stop_manager != FALSE) {
+		g_object_unref (server_proxy);
+		server_proxy = NULL;
+		g_object_unref (manager_proxy);
+		manager_proxy = NULL;
+	}
+
+	//FIXME stop all the notifications
+}
+
+void
+obexpush_down (void)
+{
+	obexpush_stop (TRUE);
+}
+
+void
+obexpush_restart (void)
+{
+	obexpush_stop (FALSE);
+	obexpush_up ();
+}
+
+gboolean
+obexpush_init (void)
+{
+	GError *err = NULL;
+
+	connection = dbus_g_bus_get (DBUS_BUS_SESSION, &err);
+	if (connection == NULL) {
+		g_printerr ("Connecting to session bus failed: %s\n",
+			    err->message);
+		g_error_free (err);
+		return FALSE;
+	}
+
+	dbus_g_object_register_marshaller (marshal_VOID__STRING_STRING_UINT64,
+					   G_TYPE_NONE,
+					   G_TYPE_STRING, G_TYPE_STRING, G_TYPE_UINT64, G_TYPE_INVALID);
+
+	if (!notify_init("mate-user-share")) {
+		g_warning("Unable to initialize the notification system\n");
+        }
+
+	dbus_connection_set_exit_on_disconnect (dbus_g_connection_get_connection (connection), FALSE);
+
+	return TRUE;
+}
+
+void
+obexpush_set_accept_files_policy (AcceptSetting setting)
+{
+	accept_setting = setting;
+}
+
+void
+obexpush_set_notify (gboolean enabled)
+{
+	show_notifications = enabled;
+}
+
+
+
+
+ + + diff --git a/2021-06-25-153248-0614-cppcheck@198f334ccf4c_master/3.html b/2021-06-25-153248-0614-cppcheck@198f334ccf4c_master/3.html new file mode 100644 index 0000000..5211d1c --- /dev/null +++ b/2021-06-25-153248-0614-cppcheck@198f334ccf4c_master/3.html @@ -0,0 +1,771 @@ + + + + + + Cppcheck - HTML report - mate-user-share + + + + + + +
+ +
+
  1
+  2
+  3
+  4
+  5
+  6
+  7
+  8
+  9
+ 10
+ 11
+ 12
+ 13
+ 14
+ 15
+ 16
+ 17
+ 18
+ 19
+ 20
+ 21
+ 22
+ 23
+ 24
+ 25
+ 26
+ 27
+ 28
+ 29
+ 30
+ 31
+ 32
+ 33
+ 34
+ 35
+ 36
+ 37
+ 38
+ 39
+ 40
+ 41
+ 42
+ 43
+ 44
+ 45
+ 46
+ 47
+ 48
+ 49
+ 50
+ 51
+ 52
+ 53
+ 54
+ 55
+ 56
+ 57
+ 58
+ 59
+ 60
+ 61
+ 62
+ 63
+ 64
+ 65
+ 66
+ 67
+ 68
+ 69
+ 70
+ 71
+ 72
+ 73
+ 74
+ 75
+ 76
+ 77
+ 78
+ 79
+ 80
+ 81
+ 82
+ 83
+ 84
+ 85
+ 86
+ 87
+ 88
+ 89
+ 90
+ 91
+ 92
+ 93
+ 94
+ 95
+ 96
+ 97
+ 98
+ 99
+100
+101
+102
+103
+104
+105
+106
+107
+108
+109
+110
+111
+112
+113
+114
+115
+116
+117
+118
+119
+120
+121
+122
+123
+124
+125
+126
+127
+128
+129
+130
+131
+132
+133
+134
+135
+136
+137
+138
+139
+140
+141
+142
+143
+144
+145
+146
+147
+148
+149
+150
+151
+152
+153
+154
+155
+156
+157
+158
+159
+160
+161
+162
+163
+164
+165
+166
+167
+168
+169
+170
+171
+172
+173
+174
+175
+176
+177
+178
+179
+180
+181
+182
+183
+184
+185
+186
+187
+188
+189
+190
+191
+192
+193
+194
+195
+196
+197
+198
+199
+200
+201
+202
+203
+204
+205
+206
+207
+208
+209
+210
+211
+212
+213
+214
+215
+216
+217
+218
+219
+220
+221
+222
+223
+224
+225
+226
+227
+228
+229
+230
+231
+232
+233
+234
+235
+236
+237
+238
+239
+240
+241
+242
+243
+244
+245
+246
+247
+248
+249
+250
+251
+252
+253
+254
+255
+256
+257
+258
+259
+260
+261
+262
+263
+264
+265
+266
+267
+268
+269
+270
+271
+272
+273
+274
+275
+276
+277
+278
+279
+280
+281
+282
+283
+284
+285
+286
+287
+288
+289
+290
+291
+292
/* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 8; tab-width: 8 -*-
+ *
+ * Copyright (C) 2003 Novell, Inc.
+ * Copyright (C) 2003-2004 Red Hat, Inc.
+ * Copyright (C) 2005 William Jon McCann <mccann@jhu.edu>
+ * Copyright (C) 2012-2021 MATE Developers
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * 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 Foundation, Inc., 51 Franklin St, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ *
+ */
+
+#include "config.h"
+
+#include <stdlib.h>
+#include <string.h>
+#include <glib/gi18n-lib.h>
+#include <gtk/gtk.h>
+#include <libcaja-extension/caja-menu-provider.h>
+#include <libcaja-extension/caja-location-widget-provider.h>
+
+#ifdef HAVE_BLUETOOTH
+#include <bluetooth-client.h>
+#endif
+
+#include "caja-share-bar.h"
+#include "user_share-common.h"
+
+#define CAJA_TYPE_USER_SHARE  (caja_user_share_get_type ())
+#define CAJA_USER_SHARE(o)    (G_TYPE_CHECK_INSTANCE_CAST ((o), CAJA_TYPE_USER_SHARE, CajaUserShare))
+#define CAJA_IS_USER_SHARE(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), CAJA_TYPE_USER_SHARE))
+
+typedef struct
+{
+        GObject              parent_slot;
+} CajaUserShare;
+
+typedef struct
+{
+        GObjectClass parent_slot;
+} CajaUserShareClass;
+
+static GType caja_user_share_get_type      (void);
+static void  caja_user_share_register_type (GTypeModule *module);
+
+static void
+launch_process (char **argv, GtkWindow *parent)
+{
+        GError *error;
+        GtkWidget *dialog;
+
+        error = NULL;
+        if (!g_spawn_async (NULL,
+                            argv, NULL,
+                            0,
+                            NULL, NULL,
+                            NULL,
+                            &error)) {
+
+
+                dialog = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL, GTK_MESSAGE_WARNING,
+						 GTK_BUTTONS_OK, _("Unable to launch the Personal File Sharing preferences"));
+
+                gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog), "%s", error->message);
+
+                gtk_dialog_run (GTK_DIALOG (dialog));
+                gtk_widget_destroy (dialog);
+
+                g_error_free (error);
+        }
+}
+
+static void
+launch_prefs_on_window (GtkWindow *window)
+{
+        char *argv [2];
+
+        argv [0] = g_build_filename (BINDIR, "mate-file-share-properties", NULL);
+        argv [1] = NULL;
+
+        launch_process (argv, window);
+
+        g_free (argv [0]);
+}
+
+static void
+bar_response_cb (CajaShareBar *bar,
+                 gint response,
+                 gpointer         data)
+{
+        if (response == CAJA_SHARE_BAR_RESPONSE_PREFERENCES) {
+                launch_prefs_on_window (GTK_WINDOW (data));
+        }
+}
+
+#ifdef HAVE_BLUETOOTH
+static void
+downloads_bar_set_from_bluetooth_status (GtkWidget *bar)
+{
+	BluetoothClient *client;
+	gboolean bt_powered;
+
+	client = g_object_get_data (G_OBJECT (bar), "bluetooth-client");
+	g_object_get (G_OBJECT (client),
+		      "default-adapter-powered", &bt_powered,
+		      NULL);
+	gtk_widget_set_visible (bar, bt_powered);
+}
+
+static void
+default_adapter_powered_cb (GObject    *gobject,
+			    GParamSpec *pspec,
+			    GtkWidget  *bar)
+{
+	downloads_bar_set_from_bluetooth_status (bar);
+}
+#endif /* HAVE_BLUETOOTH */
+
+static GtkWidget *
+caja_user_share_get_location_widget (CajaLocationWidgetProvider *iface,
+                                         const char                     *uri,
+                                         GtkWidget                      *window)
+{
+	GFile             *file;
+	GtkWidget         *bar;
+	guint              i;
+	gboolean           enable = FALSE;
+	GFile             *home;
+#ifdef HAVE_BLUETOOTH
+	const GUserDirectory special_dirs[] = { G_USER_DIRECTORY_PUBLIC_SHARE, G_USER_DIRECTORY_DOWNLOAD };
+
+	gboolean is_dir[] = { FALSE, FALSE };
+#else
+	const GUserDirectory special_dirs[] = { G_USER_DIRECTORY_PUBLIC_SHARE };
+
+	gboolean is_dir[] = { FALSE };
+#endif /* HAVE_BLUETOOTH */
+	file = g_file_new_for_uri (uri);
+	home = g_file_new_for_path (g_get_home_dir ());
+
+	/* We don't show anything in $HOME */
+	if (g_file_equal (home, file)) {
+		g_object_unref (home);
+		g_object_unref (file);
+		return NULL;
+	}
+
+	g_object_unref (home);
+
+	for (i = 0; i < G_N_ELEMENTS (special_dirs); i++) {
+		GFile *dir;
+		dir = lookup_dir_with_fallback (special_dirs[i]);
+		if (g_file_equal (dir, file)) {
+			enable = TRUE;
+			is_dir[i] = TRUE;
+		}
+		g_object_unref (dir);
+	}
+
+	g_object_unref (file);
+
+	if (enable == FALSE)
+		return NULL;
+
+	if (is_dir[0] != FALSE) {
+#ifdef HAVE_BLUETOOTH
+		if (is_dir[1] != FALSE) {
+			bar = caja_share_bar_new (_("May be used to share or receive files"));
+		} else {
+			bar = caja_share_bar_new (_("May be shared over the network or Bluetooth"));
+		}
+#else
+		bar = caja_share_bar_new (_("May be shared over the network"));
+#endif /* HAVE_BLUETOOTH */
+	} else {
+#ifdef HAVE_BLUETOOTH
+		BluetoothClient *client;
+
+		bar = caja_share_bar_new (_("May be used to receive files over Bluetooth"));
+
+		gtk_widget_set_no_show_all (bar, TRUE);
+		client = bluetooth_client_new ();
+		g_object_set_data_full (G_OBJECT (bar), "bluetooth-client", client, g_object_unref);
+		g_signal_connect (G_OBJECT (client), "notify::default-adapter-powered",
+				  G_CALLBACK (default_adapter_powered_cb), bar);
+		downloads_bar_set_from_bluetooth_status (bar);
+#endif /* HAVE_BLUETOOTH */
+	}
+
+	g_signal_connect (bar, "response",
+			  G_CALLBACK (bar_response_cb),
+			  window);
+
+	gtk_widget_show_all (bar);
+
+	return bar;
+}
+
+static void
+caja_user_share_location_widget_provider_iface_init (CajaLocationWidgetProviderIface *iface)
+{
+        iface->get_widget = caja_user_share_get_location_widget;
+}
+
+static void
+caja_user_share_instance_init (CajaUserShare *share)
+{
+
+}
+
+static void
+caja_user_share_class_init (CajaUserShareClass *klass)
+{
+
+}
+
+static GType share_type = 0;
+
+static GType
+caja_user_share_get_type (void)
+{
+        return share_type;
+}
+
+static void
+caja_user_share_register_type (GTypeModule *module)
+{
+        static const GTypeInfo info = {
+                sizeof (CajaUserShareClass),
+                (GBaseInitFunc) NULL,
+                (GBaseFinalizeFunc) NULL,
+                (GClassInitFunc) caja_user_share_class_init,
+                NULL,
+                NULL,
+                sizeof (CajaUserShare),
+                0,
+                (GInstanceInitFunc) caja_user_share_instance_init,
+        };
+
+        static const GInterfaceInfo location_widget_provider_iface_info = {
+                (GInterfaceInitFunc) caja_user_share_location_widget_provider_iface_init,
+                NULL,
+                NULL
+        };
+
+        share_type = g_type_module_register_type (module,
+                                                 G_TYPE_OBJECT,
+                                                 "CajaUserShare",
+                                                 &info, 0);
+
+        g_type_module_add_interface (module,
+                                     share_type,
+                                     CAJA_TYPE_LOCATION_WIDGET_PROVIDER,
+                                     &location_widget_provider_iface_info);
+}
+
+void
+caja_module_initialize (GTypeModule *module)
+{
+        caja_user_share_register_type (module);
+        bindtextdomain (GETTEXT_PACKAGE, MATELOCALEDIR);
+        bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
+}
+
+void
+caja_module_shutdown (void)
+{
+}
+
+void
+caja_module_list_types (const GType **types,
+                            int          *num_types)
+{
+        static GType type_list [1];
+
+        type_list[0] = CAJA_TYPE_USER_SHARE;
+
+        *types = type_list;
+        *num_types = 1;
+}
+
+
+
+
+ + + diff --git a/2021-06-25-153248-0614-cppcheck@198f334ccf4c_master/4.html b/2021-06-25-153248-0614-cppcheck@198f334ccf4c_master/4.html new file mode 100644 index 0000000..6886e58 --- /dev/null +++ b/2021-06-25-153248-0614-cppcheck@198f334ccf4c_master/4.html @@ -0,0 +1,1189 @@ + + + + + + Cppcheck - HTML report - mate-user-share + + + + + + +
+ +
+
  1
+  2
+  3
+  4
+  5
+  6
+  7
+  8
+  9
+ 10
+ 11
+ 12
+ 13
+ 14
+ 15
+ 16
+ 17
+ 18
+ 19
+ 20
+ 21
+ 22
+ 23
+ 24
+ 25
+ 26
+ 27
+ 28
+ 29
+ 30
+ 31
+ 32
+ 33
+ 34
+ 35
+ 36
+ 37
+ 38
+ 39
+ 40
+ 41
+ 42
+ 43
+ 44
+ 45
+ 46
+ 47
+ 48
+ 49
+ 50
+ 51
+ 52
+ 53
+ 54
+ 55
+ 56
+ 57
+ 58
+ 59
+ 60
+ 61
+ 62
+ 63
+ 64
+ 65
+ 66
+ 67
+ 68
+ 69
+ 70
+ 71
+ 72
+ 73
+ 74
+ 75
+ 76
+ 77
+ 78
+ 79
+ 80
+ 81
+ 82
+ 83
+ 84
+ 85
+ 86
+ 87
+ 88
+ 89
+ 90
+ 91
+ 92
+ 93
+ 94
+ 95
+ 96
+ 97
+ 98
+ 99
+100
+101
+102
+103
+104
+105
+106
+107
+108
+109
+110
+111
+112
+113
+114
+115
+116
+117
+118
+119
+120
+121
+122
+123
+124
+125
+126
+127
+128
+129
+130
+131
+132
+133
+134
+135
+136
+137
+138
+139
+140
+141
+142
+143
+144
+145
+146
+147
+148
+149
+150
+151
+152
+153
+154
+155
+156
+157
+158
+159
+160
+161
+162
+163
+164
+165
+166
+167
+168
+169
+170
+171
+172
+173
+174
+175
+176
+177
+178
+179
+180
+181
+182
+183
+184
+185
+186
+187
+188
+189
+190
+191
+192
+193
+194
+195
+196
+197
+198
+199
+200
+201
+202
+203
+204
+205
+206
+207
+208
+209
+210
+211
+212
+213
+214
+215
+216
+217
+218
+219
+220
+221
+222
+223
+224
+225
+226
+227
+228
+229
+230
+231
+232
+233
+234
+235
+236
+237
+238
+239
+240
+241
+242
+243
+244
+245
+246
+247
+248
+249
+250
+251
+252
+253
+254
+255
+256
+257
+258
+259
+260
+261
+262
+263
+264
+265
+266
+267
+268
+269
+270
+271
+272
+273
+274
+275
+276
+277
+278
+279
+280
+281
+282
+283
+284
+285
+286
+287
+288
+289
+290
+291
+292
+293
+294
+295
+296
+297
+298
+299
+300
+301
+302
+303
+304
+305
+306
+307
+308
+309
+310
+311
+312
+313
+314
+315
+316
+317
+318
+319
+320
+321
+322
+323
+324
+325
+326
+327
+328
+329
+330
+331
+332
+333
+334
+335
+336
+337
+338
+339
+340
+341
+342
+343
+344
+345
+346
+347
+348
+349
+350
+351
+352
+353
+354
+355
+356
+357
+358
+359
+360
+361
+362
+363
+364
+365
+366
+367
+368
+369
+370
+371
+372
+373
+374
+375
+376
+377
+378
+379
+380
+381
+382
+383
+384
+385
+386
+387
+388
+389
+390
+391
+392
+393
+394
+395
+396
+397
+398
+399
+400
+401
+402
+403
+404
+405
+406
+407
+408
+409
+410
+411
+412
+413
+414
+415
+416
+417
+418
+419
+420
+421
+422
+423
+424
+425
+426
+427
+428
+429
+430
+431
+432
+433
+434
+435
+436
+437
+438
+439
+440
+441
+442
+443
+444
+445
+446
+447
+448
+449
+450
+451
+452
+453
+454
+455
+456
+457
+458
+459
+460
+461
+462
+463
+464
+465
+466
+467
+468
+469
+470
+471
+472
+473
+474
+475
+476
+477
+478
+479
+480
+481
+482
+483
+484
+485
+486
+487
+488
+489
+490
+491
+492
+493
+494
+495
+496
+497
+498
+499
+500
+501
+502
+503
+504
+505
+506
+507
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
+
+/*
+ *  Copyright (C) 2004-2008 Red Hat, Inc.
+ *  Copyright (C) 2012-2021 MATE Developers
+ *
+ *  Caja is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU General Public License as
+ *  published by the Free Software Foundation; either version 2 of the
+ *  License, or (at your option) any later version.
+ *
+ *  Caja is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  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
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ *  Authors: Alexander Larsson <alexl@redhat.com>
+ *
+ */
+
+#include "config.h"
+
+#include <gdk/gdkx.h>
+#include <gtk/gtk.h>
+#include <glib/gi18n.h>
+#include <glib/gstdio.h>
+#include <gio/gio.h>
+#include <X11/Xlib.h>
+
+#include "user_share-private.h"
+#include "user_share-common.h"
+#include "http.h"
+
+#ifdef HAVE_BLUETOOTH
+#include <bluetooth-client.h>
+
+#include "obexftp.h"
+#include "obexpush.h"
+
+#endif /* HAVE_BLUETOOTH */
+
+#include <gio/gio.h>
+
+#include <stdarg.h>
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <signal.h>
+#include <unistd.h>
+
+static guint disabled_timeout_tag = 0;
+static GSettings* settings;<--- Shadowed declaration<--- Shadowed declaration<--- Shadowed declaration
+
+#define GSETTINGS_SCHEMA "org.mate.FileSharing"
+#define GSETTINGS_KEY_FILE_SHARING_ENABLED "enabled"
+#define GSETTINGS_KEY_FILE_SHARING_REQUIRE_PASSWORD "require-password"
+
+#ifdef HAVE_BLUETOOTH
+/* MATE Session */
+#define MATE_SESSION_DBUS_NAME      "org.gnome.SessionManager"
+#define MATE_SESSION_DBUS_OBJECT    "/org/gnome/SessionManager"
+#define MATE_SESSION_DBUS_INTERFACE "org.gnome.SessionManager"
+
+static GDBusProxy *session_proxy = NULL;
+static gboolean has_console = TRUE;
+
+static BluetoothClient *client = NULL;
+static gboolean bluetoothd_enabled = FALSE;
+
+#define OBEX_ENABLED (bluetoothd_enabled && has_console)
+
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_ENABLED "bluetooth-enabled"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_ALLOW_WRITE "bluetooth-allow-write"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_REQUIRE_PAIRING "bluetooth-require-pairing"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED "bluetooth-obexpush-enabled"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_ACCEPT_FILES "bluetooth-accept-files"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_NOTIFY "bluetooth-notify"
+
+
+static void
+obex_services_start (void)
+{
+	GSettings *settings;<--- Shadow variable
+
+	if (bluetoothd_enabled == FALSE ||
+	    has_console == FALSE)
+	    	return;
+
+	settings = g_settings_new(GSETTINGS_SCHEMA);
+
+	if (g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED) == TRUE) {
+	    obexpush_up ();
+	}
+	if (g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_ENABLED) == TRUE) {
+	    obexftp_up ();
+	}
+
+	g_object_unref (client);
+}
+
+static void
+obex_services_shutdown (void)
+{
+	obexpush_down ();
+	obexftp_down ();
+}
+
+static void
+session_properties_changed_cb (GDBusProxy      *session,
+			       GVariant        *changed,
+			       char           **invalidated,
+			       gpointer         user_data)
+{
+	GVariant *v;
+
+	v = g_variant_lookup_value (changed, "SessionIsActive", G_VARIANT_TYPE_BOOLEAN);
+	if (v) {
+		has_console = g_variant_get_boolean (v);
+		g_debug ("Received session is active change: now %s", has_console ? "active" : "inactive");
+
+		if (has_console)
+			obex_services_start ();
+		else
+			obex_services_shutdown ();
+
+		g_variant_unref (v);
+	}
+}
+
+static gboolean
+is_session_active (void)
+{
+	GVariant *variant;
+	gboolean is_session_active = FALSE;
+
+	variant = g_dbus_proxy_get_cached_property (session_proxy,
+						    "SessionIsActive");
+	if (variant) {
+		is_session_active = g_variant_get_boolean (variant);
+		g_variant_unref (variant);
+ 	}
+
+	return is_session_active;
+}
+
+static void
+session_init (void)
+{
+	GError *error = NULL;
+
+	session_proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION,
+						       G_DBUS_PROXY_FLAGS_NONE,
+						       NULL,
+						       MATE_SESSION_DBUS_NAME,
+						       MATE_SESSION_DBUS_OBJECT,
+						       MATE_SESSION_DBUS_INTERFACE,
+						       NULL,
+						       &error);
+	if (session_proxy == NULL) {
+		g_warning ("Failed to get session proxy: %s", error->message);
+		g_error_free (error);
+		return;
+	}
+	g_signal_connect (session_proxy, "g-properties-changed",
+			  G_CALLBACK (session_properties_changed_cb),
+			  NULL);
+	has_console = is_session_active ();
+}
+
+static void
+default_adapter_changed (GObject    *gobject,
+			 GParamSpec *pspec,
+			 gpointer    user_data)
+{
+	char *adapter;
+	gboolean adapter_powered;
+
+	g_object_get (G_OBJECT (client),
+		      "default-adapter", &adapter,
+		      "default-adapter-powered", &adapter_powered,
+		      NULL);
+	if (adapter != NULL && *adapter != '\0') {
+		bluetoothd_enabled = adapter_powered;
+	} else {
+		bluetoothd_enabled = FALSE;
+	}
+
+	/* Were we called as init, or as a callback */
+	if (gobject != NULL) {
+		if (bluetoothd_enabled != FALSE)
+			obex_services_start ();
+		else
+			obex_services_shutdown ();
+	}
+}
+
+static void
+bluez_init (void)
+{
+	client = bluetooth_client_new ();
+	default_adapter_changed (NULL, NULL, NULL);
+	g_signal_connect (G_OBJECT (client), "notify::default-adapter",
+			  G_CALLBACK (default_adapter_changed), NULL);
+	g_signal_connect (G_OBJECT (client), "notify::default-adapter-powered",
+			  G_CALLBACK (default_adapter_changed), NULL);
+}
+#endif /* HAVE_BLUETOOTH */
+
+static gboolean
+file_sharing_enabled (void)
+{
+	gboolean enabled = TRUE;
+	settings = g_settings_new (GSETTINGS_SCHEMA);
+
+#ifdef HAVE_BLUETOOTH
+	if (g_settings_get_boolean (settings, FILE_SHARING_ENABLED) == FALSE &&
+	    g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_ENABLED) == FALSE &&
+	    g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED) == FALSE)
+#else /* HAVE_BLUETOOTH */
+	if (g_settings_get_boolean (settings, FILE_SHARING_ENABLED) == FALSE)
+#endif /* HAVE_BLUETOOTH */
+		enabled = FALSE;
+
+	g_object_unref (settings);
+
+	return enabled;
+}
+
+static void
+migrate_old_configuration (void)
+{
+	const char *old_config_dir;
+	const char *new_config_dir;
+
+	old_config_dir = g_build_filename (g_get_home_dir (), ".mate2", "user-share", NULL);
+	new_config_dir = g_build_filename (g_get_user_config_dir (), "user-share", NULL);
+	if (g_file_test (old_config_dir, G_FILE_TEST_IS_DIR))
+		g_rename (old_config_dir, new_config_dir);
+
+}
+
+static void
+require_password_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	/* Need to restart to get new password setting */
+	if (http_get_pid () != 0) {
+		http_down ();
+		http_up ();
+	}
+}
+
+/* File sharing was disabled for some time, exit now */
+/* If we re-enable it in the ui, this will be restarted anyway */
+static gboolean
+disabled_timeout_callback (gpointer user_data)
+{
+	GSettings *settings = (GSettings *) user_data;<--- Shadow variable
+	http_down ();
+
+#ifdef HAVE_BLUETOOTH
+	if (g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_ENABLED) == FALSE &&
+	    g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED) == FALSE)
+		_exit (0);
+#else /* HAVE_BLUETOOTH */
+	if (g_settings_get_boolean (settings, FILE_SHARING_ENABLED) == FALSE)
+		_exit (0);
+#endif /* HAVE_BLUETOOTH */
+	return FALSE;
+}
+
+static void
+file_sharing_enabled_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	gboolean enabled;
+
+	if (disabled_timeout_tag != 0) {
+		g_source_remove (disabled_timeout_tag);
+		disabled_timeout_tag = 0;
+	}
+
+	enabled = g_settings_get_boolean (settings,
+					 FILE_SHARING_ENABLED);
+	if (enabled) {
+		if (http_get_pid () == 0) {
+			http_up ();
+		}
+	} else {
+		http_down ();
+		disabled_timeout_tag = g_timeout_add_seconds (3,
+							      (GSourceFunc)disabled_timeout_callback,
+							      settings);
+	}
+}
+
+#ifdef HAVE_BLUETOOTH
+static void
+file_sharing_bluetooth_allow_write_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	if (g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_ENABLED) != FALSE)
+		obexftp_restart ();
+}
+
+static void
+file_sharing_bluetooth_require_pairing_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	if (g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_ENABLED) != FALSE) {
+		/* We need to fully reset the session,
+		 * otherwise the new setting isn't taken into account */
+		obexftp_down ();
+		obexftp_up ();
+	}
+}
+
+static void
+file_sharing_bluetooth_enabled_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	if (g_settings_get_boolean (settings,
+				   FILE_SHARING_BLUETOOTH_ENABLED) == FALSE) {
+		obexftp_down ();
+		if (g_settings_get_boolean (settings, FILE_SHARING_ENABLED) == FALSE &&
+		    g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED) == FALSE) {
+			_exit (0);
+		}
+	} else if (OBEX_ENABLED) {
+		obexftp_up ();
+	}
+}
+
+static void
+file_sharing_bluetooth_obexpush_enabled_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	if (g_settings_get_boolean (settings,
+				   FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED) == FALSE) {
+		obexpush_down ();
+		if (g_settings_get_boolean (settings, FILE_SHARING_ENABLED) == FALSE &&
+		    g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_ENABLED) == FALSE) {
+			_exit (0);
+		}
+	} else if (OBEX_ENABLED) {
+		obexpush_up ();
+	}
+}
+
+static void
+file_sharing_bluetooth_obexpush_accept_files_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	AcceptSetting setting;
+	char *str;
+
+	str = g_settings_get_string (settings, FILE_SHARING_BLUETOOTH_OBEXPUSH_ACCEPT_FILES);
+	setting = accept_setting_from_string (str);
+	g_free (str);
+
+	obexpush_set_accept_files_policy (setting);
+}
+
+static void
+file_sharing_bluetooth_obexpush_notify_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	obexpush_set_notify (g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_OBEXPUSH_NOTIFY));
+}
+#endif /* HAVE_BLUETOOTH */
+
+static RETSIGTYPE
+cleanup_handler (int sig)
+{
+	http_down ();
+#ifdef HAVE_BLUETOOTH
+	obexftp_down ();
+	obexpush_down ();
+#endif /* HAVE_BLUETOOTH */
+	_exit (2);
+}
+
+static int
+x_io_error_handler (Display *xdisplay)
+{
+	http_down ();
+#ifdef HAVE_BLUETOOTH
+	obexftp_down ();
+#endif /* HAVE_BLUETOOTH */
+	_exit (2);
+}
+
+int
+main (int argc, char **argv)
+{
+	GSettings *settings;<--- Shadow variable
+	Display *xdisplay;
+	G_GNUC_UNUSED int x_fd;
+	Window selection_owner;
+	Atom xatom;
+
+	bindtextdomain (GETTEXT_PACKAGE, MATELOCALEDIR);
+	bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
+	textdomain (GETTEXT_PACKAGE);
+
+	gtk_init (&argc, &argv);
+
+	if (g_strcmp0 (g_get_real_name (), "root") == 0) {
+		g_warning ("mate-user-share cannot be started as root for security reasons.");
+		return 1;
+	}
+
+	signal (SIGPIPE, SIG_IGN);
+	signal (SIGINT, cleanup_handler);
+	signal (SIGHUP, cleanup_handler);
+	signal (SIGTERM, cleanup_handler);
+
+	xdisplay = GDK_DISPLAY_XDISPLAY (gdk_display_get_default ());
+	if (xdisplay == NULL) {
+		g_warning ("Can't open display");
+		return 1;
+	}
+
+	xatom = XInternAtom (xdisplay, "_MATE_USER_SHARE", FALSE);
+	selection_owner = XGetSelectionOwner (xdisplay, xatom);
+
+	if (selection_owner != None) {
+		/* There is an owner already, quit */
+		return 1;
+	}
+
+	selection_owner = XCreateSimpleWindow (xdisplay,
+					       RootWindow (xdisplay, 0),
+					       0, 0, 1, 1,
+					       0, 0, 0);
+	XSetSelectionOwner (xdisplay, xatom, selection_owner, CurrentTime);
+
+	if (XGetSelectionOwner (xdisplay, xatom) != selection_owner) {
+		/* Didn't get the selection */
+		return 1;
+	}
+
+	migrate_old_configuration ();
+
+	if (!file_sharing_enabled ())
+		return 1;
+
+	settings = g_settings_new (GSETTINGS_SCHEMA);
+
+	x_fd = ConnectionNumber (xdisplay);
+	XSetIOErrorHandler (x_io_error_handler);
+
+	if (http_init () == FALSE)
+		return 1;
+#ifdef HAVE_BLUETOOTH
+	if (obexftp_init () == FALSE)
+		return 1;
+	if (obexpush_init () == FALSE)
+		return 1;
+#endif /* HAVE_BLUETOOTH */
+
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_ENABLED,
+			     G_CALLBACK (file_sharing_enabled_changed), NULL);
+
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_REQUIRE_PASSWORD,
+			     G_CALLBACK (require_password_changed), NULL);
+
+#ifdef HAVE_BLUETOOTH
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_ENABLED,
+			     G_CALLBACK (file_sharing_bluetooth_enabled_changed), NULL);
+
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_ALLOW_WRITE,
+			     G_CALLBACK (file_sharing_bluetooth_allow_write_changed), NULL);
+
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_REQUIRE_PAIRING,
+			     G_CALLBACK (file_sharing_bluetooth_require_pairing_changed), NULL);
+
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED,
+			     G_CALLBACK (file_sharing_bluetooth_obexpush_enabled_changed), NULL);
+
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_ACCEPT_FILES,
+			     G_CALLBACK (file_sharing_bluetooth_obexpush_accept_files_changed), NULL);
+
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_NOTIFY,
+			     G_CALLBACK (file_sharing_bluetooth_obexpush_notify_changed), NULL);
+
+	bluez_init ();
+	session_init ();
+#endif /* HAVE_BLUETOOTH */
+
+	/* Initial setting */
+	file_sharing_enabled_changed (settings, NULL, NULL);
+#ifdef HAVE_BLUETOOTH
+	file_sharing_bluetooth_enabled_changed (settings, NULL, NULL);
+	file_sharing_bluetooth_obexpush_accept_files_changed (settings, NULL, NULL);
+	file_sharing_bluetooth_obexpush_notify_changed (settings, NULL, NULL);
+	file_sharing_bluetooth_obexpush_enabled_changed (settings, NULL, NULL);
+#endif /* HAVE_BLUETOOTH */
+
+	gtk_main ();
+
+	return 0;
+}
+
+
+
+
+ + + diff --git a/2021-06-25-153248-0614-cppcheck@198f334ccf4c_master/index.html b/2021-06-25-153248-0614-cppcheck@198f334ccf4c_master/index.html new file mode 100644 index 0000000..58c64de --- /dev/null +++ b/2021-06-25-153248-0614-cppcheck@198f334ccf4c_master/index.html @@ -0,0 +1,141 @@ + + + + + + Cppcheck - HTML report - mate-user-share + + + + + + +
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
LineIdCWESeverityMessage
missingIncludeinformationCppcheck cannot find all the include files (use --check-config for details)
src/file-share-properties.c
83variableScope398styleThe scope of the variable 'password' can be reduced.
98shadowVariable398styleLocal variable 'settings' shadows outer variable
106unusedVariable563styleUnused variable: accept_setting
250shadowVariable398styleLocal variable 'settings' shadows outer variable
274shadowVariable398styleLocal variable 'settings' shadows outer variable
295shadowVariable398styleLocal variable 'settings' shadows outer variable
324shadowVariable398styleLocal variable 'settings' shadows outer variable
341shadowVariable398styleLocal variable 'settings' shadows outer variable
358shadowVariable398styleLocal variable 'settings' shadows outer variable
378shadowVariable398styleLocal variable 'settings' shadows outer variable
394shadowVariable398styleLocal variable 'settings' shadows outer variable
458shadowVariable398styleLocal variable 'settings' shadows outer variable
621variableScope398styleThe scope of the variable 'window' can be reduced.
src/http.c
115variableScope398styleThe scope of the variable 'host_name' can be reduced.
src/obexpush.c
188shadowVariable398styleLocal variable 'connection' shadows outer variable
src/share-extension.c
62variableScope398styleThe scope of the variable 'dialog' can be reduced.
src/user_share.c
87shadowVariable398styleLocal variable 'settings' shadows outer variable
261shadowVariable398styleLocal variable 'settings' shadows outer variable
392shadowVariable398styleLocal variable 'settings' shadows outer variable
+
+
+ + + diff --git a/2021-06-25-153248-0614-cppcheck@198f334ccf4c_master/stats.html b/2021-06-25-153248-0614-cppcheck@198f334ccf4c_master/stats.html new file mode 100644 index 0000000..2020977 --- /dev/null +++ b/2021-06-25-153248-0614-cppcheck@198f334ccf4c_master/stats.html @@ -0,0 +1,109 @@ + + + + + + Cppcheck - HTML report - mate-user-share + + + + + + +
+ +
+

Top 10 files for style severity, total findings: 19
+   13  src/file-share-properties.c
+   3   src/user_share.c
+   1   src/share-extension.c
+   1   src/obexpush.c
+   1   src/http.c
+

+ +
+
+ + + diff --git a/2021-06-25-153248-0614-cppcheck@198f334ccf4c_master/style.css b/2021-06-25-153248-0614-cppcheck@198f334ccf4c_master/style.css new file mode 100644 index 0000000..07125f4 --- /dev/null +++ b/2021-06-25-153248-0614-cppcheck@198f334ccf4c_master/style.css @@ -0,0 +1,137 @@ + +body { + font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif; + font-size: 13px; + line-height: 1.5; + margin: 0; + width: auto; +} + +h1 { + margin: 10px; +} + +.header { + border-bottom: thin solid #aaa; +} + +.footer { + border-top: thin solid #aaa; + font-size: 90%; + margin-top: 5px; +} + +.footer ul { + list-style-type: none; + padding-left: 0; +} + +.footer > p { + margin: 4px; +} + +.wrapper { + display: -webkit-box; + display: -ms-flexbox; + display: flex; + -webkit-box-pack: justify; + -ms-flex-pack: justify; + justify-content: space-between; +} + +#menu, +#menu_index { + text-align: left; + width: 350px; + height: 90vh; + min-height: 200px; + overflow: auto; + position: -webkit-sticky; + position: sticky; + top: 0; + padding: 0 15px 15px 15px; +} + +#menu > a { + display: block; + margin-left: 10px; + font-size: 12px; + z-index: 1; +} + +#content, +#content_index { + background-color: #fff; + -webkit-box-sizing: content-box; + -moz-box-sizing: content-box; + box-sizing: content-box; + padding: 0 15px 15px 15px; + width: calc(100% - 350px); + height: 100%; + overflow-x: auto; +} + +#filename { + margin-left: 10px; + font-size: 12px; + z-index: 1; +} + +.error { + background-color: #ffb7b7; +} + +.error2 { + background-color: #faa; + display: inline-block; + margin-left: 4px; +} + +.inconclusive { + background-color: #b6b6b4; +} + +.inconclusive2 { + background-color: #b6b6b4; + display: inline-block; + margin-left: 4px; +} + +.verbose { + display: inline-block; + vertical-align: top; + cursor: help; +} + +.verbose .content { + display: none; + position: absolute; + padding: 10px; + margin: 4px; + max-width: 40%; + white-space: pre-wrap; + border: 1px solid #000; + background-color: #ffffcc; + cursor: auto; +} + +.highlight .hll { + padding: 1px; +} + +.highlighttable { + background-color: #fff; + z-index: 10; + position: relative; + margin: -10px; +} + +.linenos { + border-right: thin solid #aaa; + color: #d3d3d3; + padding-right: 6px; +} + +.d-none { + display: none; +} diff --git a/2021-08-05-192303-3702-cppcheck@c6718ce23130_master/0.html b/2021-08-05-192303-3702-cppcheck@c6718ce23130_master/0.html new file mode 100644 index 0000000..3125c1e --- /dev/null +++ b/2021-08-05-192303-3702-cppcheck@c6718ce23130_master/0.html @@ -0,0 +1,1505 @@ + + + + + + Cppcheck - HTML report - mate-user-share + + + + + + +
+ +
+
  1
+  2
+  3
+  4
+  5
+  6
+  7
+  8
+  9
+ 10
+ 11
+ 12
+ 13
+ 14
+ 15
+ 16
+ 17
+ 18
+ 19
+ 20
+ 21
+ 22
+ 23
+ 24
+ 25
+ 26
+ 27
+ 28
+ 29
+ 30
+ 31
+ 32
+ 33
+ 34
+ 35
+ 36
+ 37
+ 38
+ 39
+ 40
+ 41
+ 42
+ 43
+ 44
+ 45
+ 46
+ 47
+ 48
+ 49
+ 50
+ 51
+ 52
+ 53
+ 54
+ 55
+ 56
+ 57
+ 58
+ 59
+ 60
+ 61
+ 62
+ 63
+ 64
+ 65
+ 66
+ 67
+ 68
+ 69
+ 70
+ 71
+ 72
+ 73
+ 74
+ 75
+ 76
+ 77
+ 78
+ 79
+ 80
+ 81
+ 82
+ 83
+ 84
+ 85
+ 86
+ 87
+ 88
+ 89
+ 90
+ 91
+ 92
+ 93
+ 94
+ 95
+ 96
+ 97
+ 98
+ 99
+100
+101
+102
+103
+104
+105
+106
+107
+108
+109
+110
+111
+112
+113
+114
+115
+116
+117
+118
+119
+120
+121
+122
+123
+124
+125
+126
+127
+128
+129
+130
+131
+132
+133
+134
+135
+136
+137
+138
+139
+140
+141
+142
+143
+144
+145
+146
+147
+148
+149
+150
+151
+152
+153
+154
+155
+156
+157
+158
+159
+160
+161
+162
+163
+164
+165
+166
+167
+168
+169
+170
+171
+172
+173
+174
+175
+176
+177
+178
+179
+180
+181
+182
+183
+184
+185
+186
+187
+188
+189
+190
+191
+192
+193
+194
+195
+196
+197
+198
+199
+200
+201
+202
+203
+204
+205
+206
+207
+208
+209
+210
+211
+212
+213
+214
+215
+216
+217
+218
+219
+220
+221
+222
+223
+224
+225
+226
+227
+228
+229
+230
+231
+232
+233
+234
+235
+236
+237
+238
+239
+240
+241
+242
+243
+244
+245
+246
+247
+248
+249
+250
+251
+252
+253
+254
+255
+256
+257
+258
+259
+260
+261
+262
+263
+264
+265
+266
+267
+268
+269
+270
+271
+272
+273
+274
+275
+276
+277
+278
+279
+280
+281
+282
+283
+284
+285
+286
+287
+288
+289
+290
+291
+292
+293
+294
+295
+296
+297
+298
+299
+300
+301
+302
+303
+304
+305
+306
+307
+308
+309
+310
+311
+312
+313
+314
+315
+316
+317
+318
+319
+320
+321
+322
+323
+324
+325
+326
+327
+328
+329
+330
+331
+332
+333
+334
+335
+336
+337
+338
+339
+340
+341
+342
+343
+344
+345
+346
+347
+348
+349
+350
+351
+352
+353
+354
+355
+356
+357
+358
+359
+360
+361
+362
+363
+364
+365
+366
+367
+368
+369
+370
+371
+372
+373
+374
+375
+376
+377
+378
+379
+380
+381
+382
+383
+384
+385
+386
+387
+388
+389
+390
+391
+392
+393
+394
+395
+396
+397
+398
+399
+400
+401
+402
+403
+404
+405
+406
+407
+408
+409
+410
+411
+412
+413
+414
+415
+416
+417
+418
+419
+420
+421
+422
+423
+424
+425
+426
+427
+428
+429
+430
+431
+432
+433
+434
+435
+436
+437
+438
+439
+440
+441
+442
+443
+444
+445
+446
+447
+448
+449
+450
+451
+452
+453
+454
+455
+456
+457
+458
+459
+460
+461
+462
+463
+464
+465
+466
+467
+468
+469
+470
+471
+472
+473
+474
+475
+476
+477
+478
+479
+480
+481
+482
+483
+484
+485
+486
+487
+488
+489
+490
+491
+492
+493
+494
+495
+496
+497
+498
+499
+500
+501
+502
+503
+504
+505
+506
+507
+508
+509
+510
+511
+512
+513
+514
+515
+516
+517
+518
+519
+520
+521
+522
+523
+524
+525
+526
+527
+528
+529
+530
+531
+532
+533
+534
+535
+536
+537
+538
+539
+540
+541
+542
+543
+544
+545
+546
+547
+548
+549
+550
+551
+552
+553
+554
+555
+556
+557
+558
+559
+560
+561
+562
+563
+564
+565
+566
+567
+568
+569
+570
+571
+572
+573
+574
+575
+576
+577
+578
+579
+580
+581
+582
+583
+584
+585
+586
+587
+588
+589
+590
+591
+592
+593
+594
+595
+596
+597
+598
+599
+600
+601
+602
+603
+604
+605
+606
+607
+608
+609
+610
+611
+612
+613
+614
+615
+616
+617
+618
+619
+620
+621
+622
+623
+624
+625
+626
+627
+628
+629
+630
+631
+632
+633
+634
+635
+636
+637
+638
+639
+640
+641
+642
+643
+644
+645
+646
+647
+648
+649
+650
+651
+652
+653
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
+
+/*
+ *  Copyright (C) 2004 Red Hat, Inc.
+ * Copyright (C) 2012-2021 MATE Developers
+ *
+ *  Caja is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU General Public License as
+ *  published by the Free Software Foundation; either version 2 of the
+ *  License, or (at your option) any later version.
+ *
+ *  Caja is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  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
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ *  Authors: Alexander Larsson <alexl@redhat.com>
+ *
+ */
+
+#include "config.h"
+
+#include <string.h>
+#include <stdio.h>
+
+#include <gtk/gtk.h>
+#include <glib/gi18n.h>
+#include <gio/gio.h>
+
+#include "user_share-private.h"
+
+#define REALM "Please log in as the user guest"
+#define USER "guest"
+#define GSETTINGS_SCHEMA "org.mate.FileSharing"
+#define GSETTINGS_KEY_FILE_SHARING_ENABLED "enabled"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_ENABLED "bluetooth-enabled"
+#define GSETTINGS_KEY_FILE_SHARING_REQUIRE_PASSWORD "require-password"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_ALLOW_WRITE "bluetooth-allow-write"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_REQUIRE_PAIRING "bluetooth-require-pairing"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED "bluetooth-obexpush-enabled"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_ACCEPT_FILES "bluetooth-accept-files"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_NOTIFY "bluetooth-notify"
+
+static GtkBuilder* builder;
+static GSettings* settings;<--- Shadowed declaration<--- Shadowed declaration<--- Shadowed declaration<--- Shadowed declaration<--- Shadowed declaration<--- Shadowed declaration<--- Shadowed declaration<--- Shadowed declaration<--- Shadowed declaration<--- Shadowed declaration
+
+
+static void
+write_out_password (const char *password)
+{
+    char *to_hash;
+    char *ascii_digest;
+    char *line;
+    char *filename;
+    FILE *file;
+
+    to_hash = g_strdup_printf ("%s:%s:%s", USER, REALM, password);
+    ascii_digest = g_compute_checksum_for_string (G_CHECKSUM_MD5, to_hash, strlen (to_hash));
+    g_free (to_hash);
+    line = g_strdup_printf ("%s:%s:%s\n", USER, REALM, ascii_digest);
+    g_free (ascii_digest);
+
+    filename = g_build_filename (g_get_user_config_dir (), "user-share", "passwd", NULL);
+
+    file = fopen (filename, "w");
+    if (file != NULL) {
+	fwrite (line, strlen (line), 1, file);
+	fclose (file);
+    }
+
+    g_free (filename);
+    g_free (line);
+}
+
+static void
+flush_password (void)
+{
+    GtkWidget *password_entry;
+    const char *password;
+
+    password_entry = GTK_WIDGET (gtk_builder_get_object (builder, "password_entry"));
+
+    if (g_object_get_data (G_OBJECT( password_entry), "user_edited")) {
+	password = gtk_entry_get_text (GTK_ENTRY (password_entry));
+	if (password != NULL && password[0] != 0)
+	    write_out_password (password);
+    }
+}
+
+
+static void
+update_ui (void)
+{
+    GSettings *settings;<--- Shadow variable
+    gboolean enabled;
+#ifdef HAVE_BLUETOOTH
+    gboolean bluetooth_enabled, bluetooth_write_enabled, require_pairing_enabled;
+    gboolean bluetooth_obexpush_enabled, bluetooth_obexpush_notify;
+#endif /* HAVE_BLUETOOTH */
+    char *str;
+    PasswordSetting password_setting;
+    AcceptSetting accept_setting;<--- Unused variable: accept_setting
+    GtkWidget *check;
+    GtkWidget *password_combo;
+    GtkWidget *password_entry;
+#ifdef HAVE_BLUETOOTH
+    GtkWidget *vbox_share_bluetooth;
+    GtkWidget *vbox_receive_bluetooth;
+    GtkWidget *bluetooth_check;
+    GtkWidget *allow_write_bluetooth_check;
+    GtkWidget *require_pairing_check;
+    GtkWidget *enable_obexpush_check;
+    GtkWidget *accept_obexpush_combo;
+    GtkWidget *notify_received_obexpush_check;
+#endif /* HAVE_BLUETOOTH */
+
+    settings = g_settings_new (GSETTINGS_SCHEMA);
+
+    enabled = g_settings_get_boolean (settings,
+				     FILE_SHARING_ENABLED);
+
+    str = g_settings_get_string (settings, FILE_SHARING_REQUIRE_PASSWORD);
+    password_setting = password_setting_from_string (str);
+    g_free (str);
+
+#ifdef HAVE_BLUETOOTH
+    bluetooth_enabled = g_settings_get_boolean (settings,
+    					       FILE_SHARING_BLUETOOTH_ENABLED);
+    bluetooth_write_enabled = g_settings_get_boolean (settings,
+						     FILE_SHARING_BLUETOOTH_ALLOW_WRITE);
+    require_pairing_enabled = g_settings_get_boolean (settings,
+    						     FILE_SHARING_BLUETOOTH_REQUIRE_PAIRING);
+    bluetooth_obexpush_enabled = g_settings_get_boolean (settings,
+    							FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED);
+    bluetooth_obexpush_notify = g_settings_get_boolean (settings,
+    						       FILE_SHARING_BLUETOOTH_OBEXPUSH_NOTIFY);
+
+    str = g_settings_get_string (settings, FILE_SHARING_BLUETOOTH_OBEXPUSH_ACCEPT_FILES);
+    accept_setting = accept_setting_from_string (str);
+    g_free (str);
+#endif /* HAVE_BLUETOOTH */
+
+    check = GTK_WIDGET (gtk_builder_get_object (builder, "enable_check"));
+    password_combo = GTK_WIDGET (gtk_builder_get_object (builder, "password_combo"));
+    password_entry = GTK_WIDGET (gtk_builder_get_object (builder, "password_entry"));
+#ifdef HAVE_BLUETOOTH
+    vbox_share_bluetooth = GTK_WIDGET (gtk_builder_get_object (builder, "vbox_share_bluetooth"));
+    vbox_receive_bluetooth = GTK_WIDGET (gtk_builder_get_object (builder, "vbox_receive_bluetooth"));
+    bluetooth_check = GTK_WIDGET (gtk_builder_get_object (builder, "enable_bluetooth_check"));
+    allow_write_bluetooth_check = GTK_WIDGET (gtk_builder_get_object (builder, "allow_write_bluetooth_check"));
+    require_pairing_check = GTK_WIDGET (gtk_builder_get_object (builder, "require_pairing_check"));
+    enable_obexpush_check = GTK_WIDGET (gtk_builder_get_object (builder, "enable_obexpush_check"));
+    accept_obexpush_combo = GTK_WIDGET (gtk_builder_get_object (builder, "accept_obexpush_combo"));
+    notify_received_obexpush_check = GTK_WIDGET (gtk_builder_get_object (builder, "notify_received_obexpush_check"));
+#endif /* HAVE_BLUETOOTH */
+
+    /* Network */
+    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (check), enabled);
+    gtk_widget_set_sensitive (password_combo, enabled);
+    gtk_widget_set_sensitive (password_entry, enabled && password_setting != PASSWORD_NEVER);
+
+    gtk_combo_box_set_active (GTK_COMBO_BOX (password_combo),
+			      password_setting);
+
+#ifdef HAVE_BLUETOOTH
+    /* Bluetooth ObexFTP */
+    gtk_widget_set_visible (vbox_share_bluetooth, TRUE);
+    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (bluetooth_check), bluetooth_enabled);
+    gtk_widget_set_sensitive (allow_write_bluetooth_check, bluetooth_enabled);
+    gtk_widget_set_sensitive (require_pairing_check, bluetooth_enabled);
+
+    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (allow_write_bluetooth_check),
+    				  bluetooth_write_enabled);
+    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (require_pairing_check),
+    				  require_pairing_enabled);
+
+    /* Bluetooth ObexPush */
+    gtk_widget_set_visible (vbox_receive_bluetooth, TRUE);
+    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (enable_obexpush_check), bluetooth_obexpush_enabled);
+    gtk_widget_set_sensitive (accept_obexpush_combo, bluetooth_obexpush_enabled);
+    gtk_widget_set_sensitive (notify_received_obexpush_check, bluetooth_obexpush_enabled);
+
+    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (notify_received_obexpush_check),
+    				  bluetooth_obexpush_notify);
+
+    gtk_combo_box_set_active (GTK_COMBO_BOX (accept_obexpush_combo),
+    			      accept_setting);
+#endif /* HAVE_BLUETOOTH */
+
+    g_object_unref (settings);
+}
+
+static void
+file_sharing_enabled_changed (GSettings *settings, gchar *key, gpointer data)
+{
+    update_ui ();
+}
+
+static void
+password_required_changed (GSettings *settings, gchar *key, gpointer data)
+{
+    update_ui ();
+}
+
+#ifdef HAVE_BLUETOOTH
+static void
+file_sharing_bluetooth_enabled_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	update_ui ();
+}
+
+static void
+file_sharing_bluetooth_allow_write_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	update_ui ();
+}
+
+static void
+file_sharing_bluetooth_require_pairing_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	update_ui ();
+}
+
+static void
+file_sharing_bluetooth_obexpush_enabled_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	update_ui ();
+}
+
+static void
+file_sharing_bluetooth_obexpush_accept_files_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	update_ui ();
+}
+
+static void
+file_sharing_bluetooth_obexpush_notify_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	update_ui ();
+}
+#endif /* HAVE_BLUETOOTH */
+
+static void
+password_combo_changed (GtkComboBox *combo_box)
+{
+    GSettings *settings;<--- Shadow variable
+    guint setting;
+
+    setting = gtk_combo_box_get_active (combo_box);
+
+    settings = g_settings_new (GSETTINGS_SCHEMA) ;
+
+    g_settings_set_string (settings,
+			     FILE_SHARING_REQUIRE_PASSWORD,
+			     password_string_from_setting (setting));
+    g_object_unref (settings);
+}
+
+static void
+launch_share (void)
+{
+	if (!g_spawn_command_line_async (USER_SHARE_PROGRAM, NULL))
+		g_warning ("Unable to start mate-user-share program");
+}
+
+#ifdef HAVE_BLUETOOTH
+static void
+enable_bluetooth_check_toggled (GtkWidget *check)
+{
+	GSettings *settings;<--- Shadow variable
+	gboolean enabled;
+
+	enabled = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check));
+
+	settings = g_settings_new (GSETTINGS_SCHEMA) ;
+
+	g_settings_set_boolean (settings,
+			       FILE_SHARING_BLUETOOTH_ENABLED,
+			       enabled);
+
+	g_object_unref (settings);
+
+	if (enabled != FALSE)
+		launch_share ();
+}
+#endif /* HAVE_BLUETOOTH */
+
+static void
+enable_check_toggled (GtkWidget *check)
+{
+	GSettings *settings;<--- Shadow variable
+	gboolean enabled;
+
+	enabled = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check));
+
+	settings = g_settings_new (GSETTINGS_SCHEMA);
+
+	g_settings_set_boolean (settings,
+			       FILE_SHARING_ENABLED,
+			       enabled);
+
+	g_object_unref (settings);
+
+	if (enabled != FALSE)
+		launch_share ();
+}
+
+static void
+password_entry_changed (GtkEditable *editable)
+{
+	g_object_set_data (G_OBJECT (editable),
+			   "user_edited", GINT_TO_POINTER (1));
+	flush_password ();
+}
+
+#ifdef HAVE_BLUETOOTH
+static void
+bluetooth_allow_write_check_toggled (GtkWidget *check)
+{
+	GSettings *settings;<--- Shadow variable
+	gboolean enabled;
+
+	enabled = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check));
+
+	settings = g_settings_new (GSETTINGS_SCHEMA) ;
+
+	g_settings_set_boolean (settings,
+			       FILE_SHARING_BLUETOOTH_ALLOW_WRITE,
+			       enabled);
+
+	g_object_unref (settings);
+}
+
+static void
+bluetooth_require_pairing_check_toggled (GtkWidget *check)
+{
+	GSettings *settings;<--- Shadow variable
+	gboolean enabled;
+
+	enabled = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check));
+
+	settings = g_settings_new (GSETTINGS_SCHEMA) ;
+
+	g_settings_set_boolean (settings,
+			       FILE_SHARING_BLUETOOTH_REQUIRE_PAIRING,
+			       enabled);
+
+	g_object_unref (settings);
+}
+
+static void
+enable_obexpush_check_toggled (GtkWidget *check)
+{
+	GSettings *settings;<--- Shadow variable
+	gboolean enabled;
+
+	enabled = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check));
+
+	settings = g_settings_new (GSETTINGS_SCHEMA) ;
+
+	g_settings_set_boolean (settings,
+			       FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED,
+			       enabled);
+
+	g_object_unref (settings);
+
+	if (enabled != FALSE)
+		launch_share ();
+}
+
+static void
+accept_obexpush_combo_changed (GtkComboBox *combo_box)
+{
+    GSettings *settings;<--- Shadow variable
+    guint setting;
+
+    setting = gtk_combo_box_get_active (combo_box);
+
+    settings = g_settings_new (GSETTINGS_SCHEMA) ;
+
+    g_settings_set_string (settings,
+			     FILE_SHARING_BLUETOOTH_OBEXPUSH_ACCEPT_FILES,
+			     accept_string_from_setting (setting));
+    g_object_unref (settings);
+}
+
+static void
+notify_received_obexpush_check_toggled (GtkWidget *check)
+{
+	GSettings *settings;<--- Shadow variable
+	gboolean enabled;
+
+	enabled = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check));
+
+	settings = g_settings_new (GSETTINGS_SCHEMA) ;
+
+	g_settings_set_boolean (settings,
+			       FILE_SHARING_BLUETOOTH_OBEXPUSH_NOTIFY,
+			       enabled);
+
+	g_object_unref (settings);
+}
+#endif /* HAVE_BLUETOOTH */
+
+static GtkWidget *
+error_dialog (const char *title,
+	      const char *reason,
+	      GtkWindow *parent)
+{
+	GtkWidget *error_dialog;
+
+	if (reason == NULL)
+		reason = _("No reason");
+
+	error_dialog =
+		gtk_message_dialog_new (parent,
+					GTK_DIALOG_MODAL,
+					GTK_MESSAGE_ERROR,
+					GTK_BUTTONS_OK,
+					"%s", title);
+	gtk_message_dialog_format_secondary_text
+		(GTK_MESSAGE_DIALOG (error_dialog), "%s", reason);
+
+	gtk_window_set_title (GTK_WINDOW (error_dialog), ""); /* as per HIG */
+	gtk_container_set_border_width (GTK_CONTAINER (error_dialog), 5);
+	gtk_dialog_set_default_response (GTK_DIALOG (error_dialog),
+					 GTK_RESPONSE_OK);
+	gtk_window_set_modal (GTK_WINDOW (error_dialog), TRUE);
+
+	return error_dialog;
+}
+
+static void
+help_button_clicked (GtkButton *button, GtkWidget *window)
+{
+	GError *error = NULL;
+
+	if (gtk_show_uri_on_window (GTK_WINDOW (window), "help:mate-user-share", gtk_get_current_event_time (), &error) == FALSE) {
+		GtkWidget *dialog;
+
+		dialog = error_dialog (_("Could not display the help contents."), error->message, GTK_WINDOW (window));
+		g_signal_connect (G_OBJECT (dialog), "response", G_CALLBACK
+				  (gtk_widget_destroy), error_dialog);
+		gtk_window_present (GTK_WINDOW (dialog));
+
+		g_error_free (error);
+	}
+}
+
+static GtkWidget *
+create_window (void)
+{
+    GError *error = NULL;
+    GSettings *settings;<--- Shadow variable
+    GtkWidget *check;
+    GtkWidget *password_combo;
+    GtkWidget *password_entry;
+#ifdef HAVE_BLUETOOTH
+    GtkWidget *bluetooth_check;
+    GtkWidget *bluetooth_allow_write_check;
+    GtkWidget *require_pairing_check;
+    GtkWidget *enable_obexpush_check;
+    GtkWidget *accept_obexpush_combo;
+    GtkWidget *notify_received_obexpush_check;
+#endif /* HAVE_BLUETOOTH */
+    GtkWidget *window;
+    GtkListStore *store;
+    GtkCellRenderer *cell;
+    GtkTreeIter iter;
+
+    builder = gtk_builder_new ();
+    gtk_builder_add_from_file (builder, DATADIR"file-share-properties.ui", &error);
+
+    if (error) {
+      GtkWidget *dialog;
+
+      dialog = error_dialog (_("Could not build interface."), error->message, NULL);
+      gtk_dialog_run (GTK_DIALOG (dialog));
+      gtk_widget_destroy (dialog);
+
+      g_error_free (error);
+      return NULL;
+    }
+
+    window = GTK_WIDGET (gtk_builder_get_object (builder, "user_share_dialog"));
+
+    settings = g_settings_new (GSETTINGS_SCHEMA);
+
+    check = GTK_WIDGET (gtk_builder_get_object (builder, "enable_check"));
+    password_combo = GTK_WIDGET (gtk_builder_get_object (builder, "password_combo"));
+    password_entry = GTK_WIDGET (gtk_builder_get_object (builder, "password_entry"));
+#ifdef HAVE_BLUETOOTH
+    bluetooth_check = GTK_WIDGET (gtk_builder_get_object (builder, "enable_bluetooth_check"));
+    bluetooth_allow_write_check = GTK_WIDGET (gtk_builder_get_object (builder, "allow_write_bluetooth_check"));
+    require_pairing_check = GTK_WIDGET (gtk_builder_get_object (builder, "require_pairing_check"));
+    enable_obexpush_check = GTK_WIDGET (gtk_builder_get_object (builder, "enable_obexpush_check"));
+    accept_obexpush_combo = GTK_WIDGET (gtk_builder_get_object (builder, "accept_obexpush_combo"));
+    notify_received_obexpush_check = GTK_WIDGET (gtk_builder_get_object (builder, "notify_received_obexpush_check"));
+#endif /* HAVE_BLUETOOTH */
+
+    store = gtk_list_store_new (1, G_TYPE_STRING);
+    gtk_combo_box_set_model (GTK_COMBO_BOX (password_combo),
+			     GTK_TREE_MODEL (store));
+    cell = gtk_cell_renderer_text_new ();
+    gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (password_combo), cell, TRUE);
+    gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (password_combo), cell,
+				    "text", 0,
+				    NULL);
+
+    /* Keep in same order as enum */
+    gtk_list_store_append (store, &iter);
+    gtk_list_store_set (store, &iter, 0,
+			_("Never"), -1);
+    gtk_list_store_append (store, &iter);
+    gtk_list_store_set (store, &iter, 0,
+			_("When writing files"), -1);
+    gtk_list_store_append (store, &iter);
+    gtk_list_store_set (store, &iter, 0,
+			_("Always"), -1);
+    g_object_unref (store);
+
+    /* We can't read the password from the text, just set it to something */
+    gtk_entry_set_text (GTK_ENTRY (password_entry), "none");
+    g_object_set_data (G_OBJECT (password_entry),
+		       "user_edited", GINT_TO_POINTER (0));
+    g_signal_connect (password_entry,
+		      "changed", G_CALLBACK (password_entry_changed), NULL);
+
+#ifdef HAVE_BLUETOOTH
+    /* Accept files combo */
+    store = gtk_list_store_new (1, G_TYPE_STRING);
+    gtk_combo_box_set_model (GTK_COMBO_BOX (accept_obexpush_combo),
+			     GTK_TREE_MODEL (store));
+    cell = gtk_cell_renderer_text_new ();
+    gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (accept_obexpush_combo), cell, TRUE);
+    gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (accept_obexpush_combo), cell,
+				    "text", 0,
+				    NULL);
+
+    /* Keep in same order as enum */
+    gtk_list_store_append (store, &iter);
+    gtk_list_store_set (store, &iter, 0,
+			_("Always"), -1);
+    gtk_list_store_append (store, &iter);
+    gtk_list_store_set (store, &iter, 0,
+			_("Only for set up devices"), -1);
+    //FIXME implement
+#if 0
+    gtk_list_store_append (store, &iter);
+    gtk_list_store_set (store, &iter, 0,
+    			_("Ask"), -1);
+#endif
+    g_object_unref (store);
+#endif /* HAVE_BLUETOOTH */
+
+    g_signal_connect (check,
+		      "toggled", G_CALLBACK (enable_check_toggled), NULL);
+    g_signal_connect (password_combo,
+		      "changed", G_CALLBACK (password_combo_changed), NULL);
+#ifdef HAVE_BLUETOOTH
+    g_signal_connect (bluetooth_check,
+    		      "toggled", G_CALLBACK (enable_bluetooth_check_toggled), NULL);
+    g_signal_connect (bluetooth_allow_write_check,
+    		      "toggled", G_CALLBACK (bluetooth_allow_write_check_toggled), NULL);
+    g_signal_connect (require_pairing_check,
+    		      "toggled", G_CALLBACK (bluetooth_require_pairing_check_toggled), NULL);
+    g_signal_connect (enable_obexpush_check,
+    		      "toggled", G_CALLBACK (enable_obexpush_check_toggled), NULL);
+    g_signal_connect (accept_obexpush_combo,
+    		      "changed", G_CALLBACK (accept_obexpush_combo_changed), NULL);
+    g_signal_connect (notify_received_obexpush_check,
+    		      "toggled", G_CALLBACK (notify_received_obexpush_check_toggled), NULL);
+#endif /* HAVE_BLUETOOTH */
+
+    g_signal_connect_swapped (GTK_WIDGET (gtk_builder_get_object (builder, "close_button")),
+                              "clicked", G_CALLBACK (gtk_widget_destroy), window);
+    g_signal_connect (GTK_WIDGET (gtk_builder_get_object (builder, "help_button")),
+		      "clicked", G_CALLBACK (help_button_clicked),
+		      gtk_builder_get_object (builder, "user_share_dialog"));
+
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_ENABLED,
+			     G_CALLBACK (file_sharing_enabled_changed), NULL);
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_REQUIRE_PASSWORD,
+			     G_CALLBACK (password_required_changed), NULL);
+#ifdef HAVE_BLUETOOTH
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_ENABLED,
+			     G_CALLBACK (file_sharing_bluetooth_enabled_changed), NULL);
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_ALLOW_WRITE,
+			     G_CALLBACK (file_sharing_bluetooth_allow_write_changed), NULL);
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_REQUIRE_PAIRING,
+			     G_CALLBACK (file_sharing_bluetooth_require_pairing_changed), NULL);
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED,
+			     G_CALLBACK (file_sharing_bluetooth_obexpush_enabled_changed), NULL);
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_ACCEPT_FILES,
+			     G_CALLBACK (file_sharing_bluetooth_obexpush_accept_files_changed), NULL);
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_NOTIFY,
+			     G_CALLBACK (file_sharing_bluetooth_obexpush_notify_changed), NULL);
+#endif /* HAVE_BLUETOOTH */
+
+    update_ui ();
+
+    return window;
+}
+
+static void
+activate (GtkApplication *app)
+{
+    GList *list;
+    GtkWidget *window;
+
+    list = gtk_application_get_windows (app);
+
+    if (list) {
+        gtk_window_present (GTK_WINDOW (list->data));
+    } else {
+        window = create_window ();
+        gtk_window_set_application (GTK_WINDOW (window), app);
+        gtk_widget_show (window);
+    }
+}
+
+int
+main (int argc, char *argv[])
+{
+    GtkApplication *app;
+    gint status;
+
+    bindtextdomain (GETTEXT_PACKAGE, MATELOCALEDIR);
+    bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
+    textdomain (GETTEXT_PACKAGE);
+
+    app = gtk_application_new ("org.mate.user-share.properties",
+                               G_APPLICATION_FLAGS_NONE);
+    g_signal_connect (app, "activate", G_CALLBACK (activate), NULL);
+
+    status = g_application_run (G_APPLICATION (app), argc, argv);
+
+    g_object_unref (app);
+
+    return status;
+}
+
+
+
+
+ + + diff --git a/2021-08-05-192303-3702-cppcheck@c6718ce23130_master/1.html b/2021-08-05-192303-3702-cppcheck@c6718ce23130_master/1.html new file mode 100644 index 0000000..d941d34 --- /dev/null +++ b/2021-08-05-192303-3702-cppcheck@c6718ce23130_master/1.html @@ -0,0 +1,1061 @@ + + + + + + Cppcheck - HTML report - mate-user-share + + + + + + +
+ +
+
  1
+  2
+  3
+  4
+  5
+  6
+  7
+  8
+  9
+ 10
+ 11
+ 12
+ 13
+ 14
+ 15
+ 16
+ 17
+ 18
+ 19
+ 20
+ 21
+ 22
+ 23
+ 24
+ 25
+ 26
+ 27
+ 28
+ 29
+ 30
+ 31
+ 32
+ 33
+ 34
+ 35
+ 36
+ 37
+ 38
+ 39
+ 40
+ 41
+ 42
+ 43
+ 44
+ 45
+ 46
+ 47
+ 48
+ 49
+ 50
+ 51
+ 52
+ 53
+ 54
+ 55
+ 56
+ 57
+ 58
+ 59
+ 60
+ 61
+ 62
+ 63
+ 64
+ 65
+ 66
+ 67
+ 68
+ 69
+ 70
+ 71
+ 72
+ 73
+ 74
+ 75
+ 76
+ 77
+ 78
+ 79
+ 80
+ 81
+ 82
+ 83
+ 84
+ 85
+ 86
+ 87
+ 88
+ 89
+ 90
+ 91
+ 92
+ 93
+ 94
+ 95
+ 96
+ 97
+ 98
+ 99
+100
+101
+102
+103
+104
+105
+106
+107
+108
+109
+110
+111
+112
+113
+114
+115
+116
+117
+118
+119
+120
+121
+122
+123
+124
+125
+126
+127
+128
+129
+130
+131
+132
+133
+134
+135
+136
+137
+138
+139
+140
+141
+142
+143
+144
+145
+146
+147
+148
+149
+150
+151
+152
+153
+154
+155
+156
+157
+158
+159
+160
+161
+162
+163
+164
+165
+166
+167
+168
+169
+170
+171
+172
+173
+174
+175
+176
+177
+178
+179
+180
+181
+182
+183
+184
+185
+186
+187
+188
+189
+190
+191
+192
+193
+194
+195
+196
+197
+198
+199
+200
+201
+202
+203
+204
+205
+206
+207
+208
+209
+210
+211
+212
+213
+214
+215
+216
+217
+218
+219
+220
+221
+222
+223
+224
+225
+226
+227
+228
+229
+230
+231
+232
+233
+234
+235
+236
+237
+238
+239
+240
+241
+242
+243
+244
+245
+246
+247
+248
+249
+250
+251
+252
+253
+254
+255
+256
+257
+258
+259
+260
+261
+262
+263
+264
+265
+266
+267
+268
+269
+270
+271
+272
+273
+274
+275
+276
+277
+278
+279
+280
+281
+282
+283
+284
+285
+286
+287
+288
+289
+290
+291
+292
+293
+294
+295
+296
+297
+298
+299
+300
+301
+302
+303
+304
+305
+306
+307
+308
+309
+310
+311
+312
+313
+314
+315
+316
+317
+318
+319
+320
+321
+322
+323
+324
+325
+326
+327
+328
+329
+330
+331
+332
+333
+334
+335
+336
+337
+338
+339
+340
+341
+342
+343
+344
+345
+346
+347
+348
+349
+350
+351
+352
+353
+354
+355
+356
+357
+358
+359
+360
+361
+362
+363
+364
+365
+366
+367
+368
+369
+370
+371
+372
+373
+374
+375
+376
+377
+378
+379
+380
+381
+382
+383
+384
+385
+386
+387
+388
+389
+390
+391
+392
+393
+394
+395
+396
+397
+398
+399
+400
+401
+402
+403
+404
+405
+406
+407
+408
+409
+410
+411
+412
+413
+414
+415
+416
+417
+418
+419
+420
+421
+422
+423
+424
+425
+426
+427
+428
+429
+430
+431
+432
+433
+434
+435
+436
+437
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
+
+/*
+ *  Copyright (C) 2004-2008 Red Hat, Inc.
+ * Copyright (C) 2012-2021 MATE Developers
+ *
+ *  Caja is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU General Public License as
+ *  published by the Free Software Foundation; either version 2 of the
+ *  License, or (at your option) any later version.
+ *
+ *  Caja is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  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
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ *  Authors: Alexander Larsson <alexl@redhat.com>
+ *
+ */
+
+#include "config.h"
+
+#include <glib.h>
+#include <glib/gi18n.h>
+#include <X11/Xlib.h>
+
+#include <gio/gio.h>
+
+#include <stdarg.h>
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <signal.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <sys/stat.h>
+
+#ifdef HAVE_SELINUX
+#include <selinux/selinux.h>
+#endif
+
+#include "user_share-common.h"
+#include "user_share-private.h"
+#include "http.h"
+
+/* From avahi-common/domain.h */
+#define AVAHI_LABEL_MAX 64
+
+#define GSETTINGS_SCHEMA "org.mate.FileSharing"
+
+static pid_t httpd_pid = 0;
+
+static int
+get_port (void)
+{
+	int sock;
+	struct sockaddr_in addr;
+	int reuse;
+	socklen_t len;
+
+	sock = socket (PF_INET, SOCK_STREAM, 0);
+	if (sock < 0) {
+		return -1;
+	}
+
+	memset (&addr, 0, sizeof (addr));
+	addr.sin_port = 0;
+	addr.sin_addr.s_addr = INADDR_ANY;
+	addr.sin_family = AF_INET;
+
+	reuse = 1;
+	setsockopt (sock, SOL_SOCKET, SO_REUSEADDR, &reuse, sizeof (reuse));
+	if (bind (sock, (struct sockaddr *)&addr, sizeof (addr)) == -1) {
+		close (sock);
+		return -1;
+	}
+
+	len = sizeof (addr);
+	if (getsockname (sock, (struct sockaddr *)&addr, &len) == -1) {
+		close (sock);
+		return -1;
+	}
+
+#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__APPLE__) || defined(__OpenBSD__)
+	/* XXX This exposes a potential race condition, but without this,
+	 * httpd will not start on the above listed platforms due to the fact
+	 * that SO_REUSEADDR is also needed when Apache binds to the listening
+	 * socket.  At this time, Apache does not support that socket option.
+	 */
+	close (sock);
+#endif
+	return ntohs (addr.sin_port);
+}
+
+static char *
+truncate_name (const char *name)
+{
+	const char *end;
+
+	end = g_utf8_find_prev_char (name, name + 64);
+	g_assert (end != NULL);
+	return g_strndup (name, end - name);
+}
+
+static char *
+get_share_name (void)
+{
+	static char *name = NULL;
+	const char *host_name;
+	char *str;
+
+	if (name == NULL) {
+		host_name = g_get_host_name ();
+		if (strcmp (host_name, "localhost") == 0) {
+			/* Translators: The %s will get filled in with the user name
+			   of the user, to form a genitive. If this is difficult to
+			   translate correctly so that it will work correctly in your
+			   language, you may use something equivalent to
+			   "Public files of %s", or leave out the %s altogether.
+			   In the latter case, please put "%.0s" somewhere in the string,
+			   which will match the user name string passed by the C code,
+			   but not put the user name in the final string. This is to
+			   avoid the warning that msgfmt might otherwise generate. */
+			name = g_strdup_printf (_("%s's public files"), g_get_user_name ());
+		} else {
+			/* Translators: This is similar to the string before, only it
+			   has the hostname in it too. */
+			name = g_strdup_printf (_("%s's public files on %s"),
+						g_get_user_name (),
+						host_name);
+		}
+
+	}
+	/* And truncate */
+	if (strlen (name) < AVAHI_LABEL_MAX)
+		return name;
+
+	str = truncate_name (name);
+	g_free (name);
+	name = str;
+
+	return name;
+}
+
+static void
+ensure_conf_dir (void)
+{
+	char *dirname;
+
+	dirname = g_build_filename (g_get_user_config_dir (), "user-share", NULL);
+	g_mkdir_with_parents (dirname, 0755);
+	g_free (dirname);
+}
+
+static void
+httpd_child_setup (gpointer user_data)
+{
+#ifdef HAVE_SELINUX
+	char *mycon;
+	/* If selinux is enabled, avoid transitioning to the httpd_t context,
+	   as this normally means you can't read the users homedir. */
+	if (is_selinux_enabled()) {
+		if (getcon (&mycon) < 0) {
+			abort ();
+		}
+		if (setexeccon (mycon) < 0)
+			abort ();
+		freecon (mycon);
+	}
+#endif
+}
+
+static const char *known_httpd_locations [] = {
+	HTTPD_PROGRAM,
+	"/usr/sbin/httpd",
+	"/usr/sbin/httpd2",
+	"/usr/sbin/apache2",
+	NULL
+};
+
+static char*
+get_httpd_program (void)
+{
+	int i;
+
+	for (i = 0; known_httpd_locations[i]; i++) {
+		if (known_httpd_locations[i][0] == '\0') {
+			/* empty string as first element, happens when
+			 * configured --with-httpd=auto */
+			continue;
+		}
+		if (g_file_test (known_httpd_locations[i], G_FILE_TEST_IS_EXECUTABLE)
+				&& ! g_file_test (known_httpd_locations[i], G_FILE_TEST_IS_DIR)) {
+			return g_strdup (known_httpd_locations[i]);
+		}
+	}
+	return NULL;
+}
+
+static const char *known_httpd_modules_locations [] = {
+	HTTPD_MODULES_PATH,
+	"/etc/httpd/modules",
+	"/usr/lib/apache2/modules",
+	NULL
+};
+
+static gchar*
+get_httpd_modules_path (void)
+{
+	int i;
+
+	for (i = 0; known_httpd_modules_locations[i]; i++) {
+		if (known_httpd_modules_locations[i][0] == '\0') {
+			/* empty string as first element, happens when
+			 * configured --with-httpd=auto */
+			continue;
+		}
+		if (g_file_test (known_httpd_modules_locations[i], G_FILE_TEST_IS_EXECUTABLE)
+				&& g_file_test (known_httpd_modules_locations[i], G_FILE_TEST_IS_DIR)) {
+			return g_strdup (known_httpd_modules_locations[i]);
+		}
+	}
+	return NULL;
+}
+
+static GRegex *version_regex = NULL;
+
+static char*
+get_httpd_config (const char *httpd_program)
+{
+	gchar *standard_output;
+	gchar *cmd_line;
+	GMatchInfo *match_info;
+	gchar *version_number = NULL;
+	gchar *config;
+
+	cmd_line = g_strdup_printf ("%s -v", httpd_program);
+	if (! g_spawn_command_line_sync (cmd_line, &standard_output, NULL, NULL, NULL)) {
+		g_free (cmd_line);
+		return NULL;
+	}
+	g_free (cmd_line);
+
+	if (version_regex == NULL) {
+		version_regex = g_regex_new ("\\d\\.\\d", 0, 0, NULL);
+	}
+
+	if (g_regex_match (version_regex, standard_output, 0, &match_info)) {
+		while (g_match_info_matches (match_info)) {
+			version_number = g_match_info_fetch (match_info, 0);
+			break;
+		}
+		g_match_info_free (match_info);
+		g_free (standard_output);
+	} else {
+		/* Failed to parse httpd version number */
+		g_warning ("Could not parse '%s' as a version for httpd", standard_output);
+		g_free (standard_output);
+		/* assume it is 2.2 */
+		version_number = g_strdup ("2.2");
+	}
+
+	config = g_strdup_printf (HTTPD_CONFIG_TEMPLATE, version_number);
+	g_free (version_number);
+
+	return config;
+}
+
+static gboolean
+spawn_httpd (int port, pid_t *pid_out)
+{
+	char *free1, *free2, *free3, *free4, *free5, *free6, *free7, *free8, *free9;
+	gboolean res;
+	char *argv[10];
+	char *env[10];
+	int i;
+	gint status;
+	char *pid_filename;
+	char *pidfile;
+	GError *error;
+	gboolean got_pidfile;
+	GSettings *settings;
+	char *str;
+	char *public_dir;
+
+	public_dir = lookup_public_dir ();
+	ensure_conf_dir ();
+
+	i = 0;
+	free1 = argv[i++] = get_httpd_program ();
+	if (argv[0] == NULL) {
+		fprintf (stderr, "error finding httpd server\n");
+		return FALSE;
+	}
+
+	argv[i++] = "-f";
+	free2 = argv[i++] = get_httpd_config (argv[0]);
+	argv[i++] = "-C";
+	free3 = argv[i++] = g_strdup_printf ("Listen %d", port);
+
+	settings = g_settings_new (GSETTINGS_SCHEMA);
+	str = g_settings_get_string (settings,
+				       FILE_SHARING_REQUIRE_PASSWORD);
+
+	if (str && strcmp (str, "never") == 0) {
+		/* Do nothing */
+	} else if (str && strcmp (str, "on_write") == 0){
+		argv[i++] = "-D";
+		argv[i++] = "RequirePasswordOnWrite";
+	} else {
+		/* always, or safe fallback */
+		argv[i++] = "-D";
+		argv[i++] = "RequirePasswordAlways";
+	}
+	g_free (str);
+	g_object_unref (settings);
+
+	argv[i] = NULL;
+
+	i = 0;
+	free4 = env[i++] = g_strdup_printf ("HOME=%s", g_get_home_dir());
+	free5 = env[i++] = g_strdup_printf ("XDG_PUBLICSHARE_DIR=%s", public_dir);
+	free6 = env[i++] = g_strdup_printf ("XDG_CONFIG_HOME=%s", g_get_user_config_dir ());
+	free7 = env[i++] = g_strdup_printf ("GUS_SHARE_NAME=%s", get_share_name ());
+	free8 = env[i++] = g_strdup_printf ("GUS_LOGIN_LABEL=%s", "Please log in as the user guest");
+	free9 = env[i++] = g_strdup_printf ("HTTP_MODULES_PATH=%s",get_httpd_modules_path ());
+	env[i++] = "LANG=C";
+	env[i] = NULL;
+
+	pid_filename = g_build_filename (g_get_user_config_dir (), "user-share", "pid", NULL);
+
+	/* Remove pid file before spawning to avoid races with child and old pidfile */
+	unlink (pid_filename);
+
+	error = NULL;
+	res = g_spawn_sync (g_get_home_dir(),
+			    argv, env, 0,
+			    httpd_child_setup, NULL,
+			    NULL, NULL,
+			    &status,
+			    &error);
+	g_free (free1);
+	g_free (free2);
+	g_free (free3);
+	g_free (free4);
+	g_free (free5);
+	g_free (free6);
+	g_free (free7);
+	g_free (free8);
+	g_free (free9);
+	g_free (public_dir);
+
+	if (!res) {
+		fprintf (stderr, "error spawning httpd: %s\n",
+			 error->message);
+		g_error_free (error);
+		g_free (pid_filename);
+		return FALSE;
+	}
+
+	if (status != 0) {
+		g_free (pid_filename);
+		return FALSE;
+	}
+
+	got_pidfile = FALSE;
+	error = NULL;
+	for (i = 0; i < 5; i++) {
+		if (error != NULL)
+			g_error_free (error);
+		error = NULL;
+		if (g_file_get_contents (pid_filename, &pidfile, NULL, &error)) {
+			got_pidfile = TRUE;
+			*pid_out = atoi (pidfile);
+			g_free (pidfile);
+			break;
+		}
+		sleep (1);
+	}
+
+	g_free (pid_filename);
+
+	if (!got_pidfile) {
+		fprintf (stderr, "error opening httpd pidfile: %s\n", error->message);
+		g_error_free (error);
+		return FALSE;
+	}
+	return TRUE;
+}
+
+static void
+kill_httpd (void)
+{
+	if (httpd_pid != 0) {
+		kill (httpd_pid, SIGTERM);
+
+		/* Allow child time to die, we can't waitpid, because its
+		   not a direct child */
+		sleep (1);
+	}
+	httpd_pid = 0;
+}
+
+void
+http_up (void)
+{
+	guint port;
+
+	port = get_port ();
+	if (!spawn_httpd (port, &httpd_pid)) {
+		fprintf (stderr, "spawning httpd failed\n");
+	}
+}
+
+void
+http_down (void)
+{
+	kill_httpd ();
+}
+
+gboolean
+http_init (void)
+{
+	return TRUE;
+}
+
+pid_t
+http_get_pid (void)
+{
+	return httpd_pid;
+}
+
+
+
+
+ + + diff --git a/2021-08-05-192303-3702-cppcheck@c6718ce23130_master/2.html b/2021-08-05-192303-3702-cppcheck@c6718ce23130_master/2.html new file mode 100644 index 0000000..535b792 --- /dev/null +++ b/2021-08-05-192303-3702-cppcheck@c6718ce23130_master/2.html @@ -0,0 +1,1295 @@ + + + + + + Cppcheck - HTML report - mate-user-share + + + + + + +
+ +
+
  1
+  2
+  3
+  4
+  5
+  6
+  7
+  8
+  9
+ 10
+ 11
+ 12
+ 13
+ 14
+ 15
+ 16
+ 17
+ 18
+ 19
+ 20
+ 21
+ 22
+ 23
+ 24
+ 25
+ 26
+ 27
+ 28
+ 29
+ 30
+ 31
+ 32
+ 33
+ 34
+ 35
+ 36
+ 37
+ 38
+ 39
+ 40
+ 41
+ 42
+ 43
+ 44
+ 45
+ 46
+ 47
+ 48
+ 49
+ 50
+ 51
+ 52
+ 53
+ 54
+ 55
+ 56
+ 57
+ 58
+ 59
+ 60
+ 61
+ 62
+ 63
+ 64
+ 65
+ 66
+ 67
+ 68
+ 69
+ 70
+ 71
+ 72
+ 73
+ 74
+ 75
+ 76
+ 77
+ 78
+ 79
+ 80
+ 81
+ 82
+ 83
+ 84
+ 85
+ 86
+ 87
+ 88
+ 89
+ 90
+ 91
+ 92
+ 93
+ 94
+ 95
+ 96
+ 97
+ 98
+ 99
+100
+101
+102
+103
+104
+105
+106
+107
+108
+109
+110
+111
+112
+113
+114
+115
+116
+117
+118
+119
+120
+121
+122
+123
+124
+125
+126
+127
+128
+129
+130
+131
+132
+133
+134
+135
+136
+137
+138
+139
+140
+141
+142
+143
+144
+145
+146
+147
+148
+149
+150
+151
+152
+153
+154
+155
+156
+157
+158
+159
+160
+161
+162
+163
+164
+165
+166
+167
+168
+169
+170
+171
+172
+173
+174
+175
+176
+177
+178
+179
+180
+181
+182
+183
+184
+185
+186
+187
+188
+189
+190
+191
+192
+193
+194
+195
+196
+197
+198
+199
+200
+201
+202
+203
+204
+205
+206
+207
+208
+209
+210
+211
+212
+213
+214
+215
+216
+217
+218
+219
+220
+221
+222
+223
+224
+225
+226
+227
+228
+229
+230
+231
+232
+233
+234
+235
+236
+237
+238
+239
+240
+241
+242
+243
+244
+245
+246
+247
+248
+249
+250
+251
+252
+253
+254
+255
+256
+257
+258
+259
+260
+261
+262
+263
+264
+265
+266
+267
+268
+269
+270
+271
+272
+273
+274
+275
+276
+277
+278
+279
+280
+281
+282
+283
+284
+285
+286
+287
+288
+289
+290
+291
+292
+293
+294
+295
+296
+297
+298
+299
+300
+301
+302
+303
+304
+305
+306
+307
+308
+309
+310
+311
+312
+313
+314
+315
+316
+317
+318
+319
+320
+321
+322
+323
+324
+325
+326
+327
+328
+329
+330
+331
+332
+333
+334
+335
+336
+337
+338
+339
+340
+341
+342
+343
+344
+345
+346
+347
+348
+349
+350
+351
+352
+353
+354
+355
+356
+357
+358
+359
+360
+361
+362
+363
+364
+365
+366
+367
+368
+369
+370
+371
+372
+373
+374
+375
+376
+377
+378
+379
+380
+381
+382
+383
+384
+385
+386
+387
+388
+389
+390
+391
+392
+393
+394
+395
+396
+397
+398
+399
+400
+401
+402
+403
+404
+405
+406
+407
+408
+409
+410
+411
+412
+413
+414
+415
+416
+417
+418
+419
+420
+421
+422
+423
+424
+425
+426
+427
+428
+429
+430
+431
+432
+433
+434
+435
+436
+437
+438
+439
+440
+441
+442
+443
+444
+445
+446
+447
+448
+449
+450
+451
+452
+453
+454
+455
+456
+457
+458
+459
+460
+461
+462
+463
+464
+465
+466
+467
+468
+469
+470
+471
+472
+473
+474
+475
+476
+477
+478
+479
+480
+481
+482
+483
+484
+485
+486
+487
+488
+489
+490
+491
+492
+493
+494
+495
+496
+497
+498
+499
+500
+501
+502
+503
+504
+505
+506
+507
+508
+509
+510
+511
+512
+513
+514
+515
+516
+517
+518
+519
+520
+521
+522
+523
+524
+525
+526
+527
+528
+529
+530
+531
+532
+533
+534
+535
+536
+537
+538
+539
+540
+541
+542
+543
+544
+545
+546
+547
+548
+549
+550
+551
+552
+553
+554
+555
+556
+557
+558
+559
+560
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
+
+/*
+ *  Copyright (C) 2004-2008 Red Hat, Inc.
+ *  Copyright (C) 2012-2021 MATE Developers
+ *
+ *  Caja is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU General Public License as
+ *  published by the Free Software Foundation; either version 2 of the
+ *  License, or (at your option) any later version.
+ *
+ *  Caja is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  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
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ *  Authors: Bastien Nocera <hadess@hadess.net>
+ *
+ */
+
+#include "config.h"
+
+#include <glib.h>
+#include <glib/gi18n.h>
+#include <gio/gio.h>
+#include <gdk/gdk.h>
+#include <gtk/gtk.h>
+#include <libnotify/notify.h>
+#include <dbus/dbus-glib.h>
+#include <dbus/dbus-glib-lowlevel.h>
+#include <canberra-gtk.h>
+
+#include <string.h>
+
+#include "marshal.h"
+#include "obexpush.h"
+#include "user_share-common.h"
+#include "user_share-private.h"
+
+#define DBUS_TYPE_G_STRING_VARIANT_HASHTABLE (dbus_g_type_get_map ("GHashTable", G_TYPE_STRING, G_TYPE_STRING))
+
+#define GSETTINGS_SCHEMA "org.mate.FileSharing"
+
+static DBusGConnection *connection = NULL;<--- Shadowed declaration
+static DBusGProxy *manager_proxy = NULL;
+static DBusGProxy *server_proxy = NULL;
+static AcceptSetting accept_setting = -1;
+static gboolean show_notifications = FALSE;
+
+static GtkStatusIcon *statusicon = NULL;
+static guint num_notifications = 0;
+
+static void
+hide_statusicon (void)
+{
+	num_notifications--;
+	if (num_notifications == 0)
+		gtk_status_icon_set_visible (statusicon, FALSE);
+}
+
+static void
+on_close_notification (NotifyNotification *notification)
+{
+	hide_statusicon ();
+	g_object_unref (notification);
+}
+
+static void
+notification_launch_action_on_file_cb (NotifyNotification *notification,
+				       const char *action,
+				       const char *file_uri)
+{
+	GdkScreen *screen;
+	GAppLaunchContext *ctx;
+	GTimeVal val;
+
+	g_assert (action != NULL);
+
+	g_get_current_time (&val);
+
+	ctx = G_APP_LAUNCH_CONTEXT (gdk_app_launch_context_new ());
+	screen = gdk_screen_get_default ();
+	gdk_app_launch_context_set_screen (GDK_APP_LAUNCH_CONTEXT (ctx), screen);
+	gdk_app_launch_context_set_timestamp (GDK_APP_LAUNCH_CONTEXT (ctx), val.tv_sec);
+
+	/* We launch the file viewer for the file */
+	if (g_str_equal (action, "display") != FALSE) {
+		if (g_app_info_launch_default_for_uri (file_uri, ctx, NULL) == FALSE) {
+			g_warning ("Failed to launch the file viewer\n");
+		}
+	}
+
+	/* we open the Downloads folder */
+	if (g_str_equal (action, "reveal") != FALSE) {
+		GFile *file;
+		GFile *parent;
+		gchar *parent_uri;
+
+		file = g_file_new_for_uri (file_uri);
+		parent = g_file_get_parent (file);
+		parent_uri = g_file_get_uri (parent);
+		g_object_unref (file);
+		g_object_unref (parent);
+
+		if (!g_app_info_launch_default_for_uri (parent_uri, ctx, NULL)) {
+			g_warning ("Failed to launch the file manager\n");
+		}
+
+		g_free (parent_uri);
+	}
+
+	notify_notification_close (notification, NULL);
+	/* No need to call hide_statusicon(), closing the notification
+	 * will call the close callback */
+}
+
+static void
+show_notification (const char *filename)
+{
+	char *file_uri, *notification_text, *display, *mime_type;
+	NotifyNotification *notification;
+	ca_context *ctx;
+	GAppInfo *app;
+
+	file_uri = g_filename_to_uri (filename, NULL, NULL);
+	if (file_uri == NULL) {
+		g_warning ("Could not make a filename from '%s'", filename);
+		return;
+	}
+
+	display = g_filename_display_basename (filename);
+	/* Translators: %s is the name of the filename received */
+	notification_text = g_strdup_printf(_("You received \"%s\" via Bluetooth"), display);
+	g_free (display);
+	notification = notify_notification_new (_("You received a file"),
+								 notification_text,
+								 "dialog-information");
+
+	notify_notification_set_timeout (notification, NOTIFY_EXPIRES_DEFAULT);
+
+	mime_type = g_content_type_guess (filename, NULL, 0, NULL);
+	app = g_app_info_get_default_for_type (mime_type, FALSE);
+	if (app != NULL) {
+		g_object_unref (app);
+		notify_notification_add_action (notification, "display", _("Open File"),
+						(NotifyActionCallback) notification_launch_action_on_file_cb,
+						g_strdup (file_uri), (GFreeFunc) g_free);
+	}
+	notify_notification_add_action (notification, "reveal", _("Reveal File"),
+					(NotifyActionCallback) notification_launch_action_on_file_cb,
+					g_strdup (file_uri), (GFreeFunc) g_free);
+
+	g_free (file_uri);
+
+	g_signal_connect (G_OBJECT (notification), "closed", G_CALLBACK (on_close_notification), notification);
+
+	if (!notify_notification_show (notification, NULL)) {
+		g_warning ("failed to send notification\n");
+	}
+	g_free (notification_text);
+
+	/* Now we do the audio notification */
+	ctx = ca_gtk_context_get ();
+	ca_context_play (ctx, 0,
+			 CA_PROP_EVENT_ID, "complete-download",
+			 CA_PROP_EVENT_DESCRIPTION, _("File reception complete"),
+			 NULL);
+}
+
+static void
+show_icon (void)
+{
+	if (statusicon == NULL) {
+		statusicon = gtk_status_icon_new_from_icon_name ("mate-obex-server");
+	} else {
+		gtk_status_icon_set_visible (statusicon, TRUE);
+	}
+	num_notifications++;
+}
+
+static gboolean
+device_is_authorised (const char *bdaddr)
+{
+	DBusGConnection *connection;<--- Shadow variable
+	DBusGProxy *manager;
+	GError *error = NULL;
+	GPtrArray *adapters;
+	gboolean retval = FALSE;
+	guint i;
+
+	connection = dbus_g_bus_get (DBUS_BUS_SYSTEM, NULL);
+	if (connection == NULL)
+		return FALSE;
+
+	manager = dbus_g_proxy_new_for_name (connection, "org.bluez",
+					     "/", "org.bluez.Manager");
+	if (manager == NULL) {
+		dbus_g_connection_unref (connection);
+		return FALSE;
+	}
+
+	if (dbus_g_proxy_call (manager, "ListAdapters", &error, G_TYPE_INVALID, dbus_g_type_get_collection ("GPtrArray", DBUS_TYPE_G_OBJECT_PATH), &adapters, G_TYPE_INVALID) == FALSE) {
+		g_object_unref (manager);
+		dbus_g_connection_unref (connection);
+		return FALSE;
+	}
+
+	for (i = 0; i < adapters->len; i++) {
+		DBusGProxy *adapter, *device;
+		char *device_path;
+		GHashTable *props;
+
+		g_debug ("checking adapter %s", (gchar *) g_ptr_array_index (adapters, i));
+
+		adapter = dbus_g_proxy_new_for_name (connection, "org.bluez",
+						    g_ptr_array_index (adapters, i), "org.bluez.Adapter");
+
+		if (dbus_g_proxy_call (adapter, "FindDevice", NULL,
+				       G_TYPE_STRING, bdaddr, G_TYPE_INVALID,
+				       DBUS_TYPE_G_OBJECT_PATH, &device_path, G_TYPE_INVALID) == FALSE)
+		{
+			g_object_unref (adapter);
+			continue;
+		}
+
+		device = dbus_g_proxy_new_for_name (connection, "org.bluez", device_path, "org.bluez.Device");
+
+		if (dbus_g_proxy_call (device, "GetProperties", NULL,
+				       G_TYPE_INVALID, dbus_g_type_get_map ("GHashTable", G_TYPE_STRING, G_TYPE_VALUE),
+				       &props, G_TYPE_INVALID) != FALSE)
+		{
+			GValue *value;
+			gboolean bonded;
+
+			value = g_hash_table_lookup (props, "Paired");
+			bonded = g_value_get_boolean (value);
+			g_message ("%s is %s", bdaddr, bonded ? "bonded" : "not bonded");
+
+			if (bonded) {
+				g_hash_table_destroy (props);
+				g_object_unref (device);
+				g_object_unref (adapter);
+				retval = TRUE;
+				break;
+			}
+		}
+		g_object_unref(adapter);
+	}
+
+	g_ptr_array_free (adapters, TRUE);
+
+	g_object_unref(manager);
+	dbus_g_connection_unref(connection);
+
+	return retval;
+}
+
+static void
+transfer_started_cb (DBusGProxy *session,
+		     const char *filename,
+		     const char *local_path,
+		     guint64 size,
+		     gpointer user_data)
+{
+	GHashTable *dict;
+	DBusGProxy *server = (DBusGProxy *) user_data;
+	GError *error = NULL;
+	gboolean authorise;
+
+	g_message ("transfer started on %s", local_path);
+	g_object_set_data_full (G_OBJECT (session), "filename", g_strdup (local_path), (GDestroyNotify) g_free);
+
+	show_icon ();
+
+	/* First transfer of the session */
+	if (g_object_get_data (G_OBJECT (session), "bdaddr") == NULL) {
+		const char *bdaddr;
+
+		if (dbus_g_proxy_call (server, "GetServerSessionInfo", &error,
+				       DBUS_TYPE_G_OBJECT_PATH, dbus_g_proxy_get_path (session), G_TYPE_INVALID,
+				       DBUS_TYPE_G_STRING_VARIANT_HASHTABLE, &dict, G_TYPE_INVALID) == FALSE) {
+			g_printerr ("Getting Server session info failed: %s\n",
+				    error->message);
+			g_error_free (error);
+			return;
+		}
+
+		bdaddr = g_hash_table_lookup (dict, "BluetoothAddress");
+		g_message ("transfer started for device %s", bdaddr);
+
+		g_object_set_data_full (G_OBJECT (session), "bdaddr", g_strdup (bdaddr), (GDestroyNotify) g_free);
+		/* Initial accept method is undefined, we do that lower down */
+		g_object_set_data (G_OBJECT (session), "accept-method", GINT_TO_POINTER (-1));
+		g_hash_table_destroy (dict);
+	}
+
+	/* Accept method changed */
+	if (GPOINTER_TO_INT (g_object_get_data (G_OBJECT (session), "accept-method")) != accept_setting) {
+		const char *bdaddr;
+
+		bdaddr = g_object_get_data (G_OBJECT (session), "bdaddr");
+
+		if (bdaddr == NULL) {
+			g_warning ("Couldn't get the Bluetooth address for the device, rejecting the transfer");
+			authorise = FALSE;
+		} else if (accept_setting == ACCEPT_ALWAYS) {
+			authorise = TRUE;
+		} else if (accept_setting == ACCEPT_BONDED) {
+			authorise = device_is_authorised (bdaddr);
+		} else {
+			//FIXME implement
+			g_warning ("\"Ask\" authorisation method not implemented");
+			authorise = FALSE;
+		}
+		g_object_set_data (G_OBJECT (session), "authorise", GINT_TO_POINTER (authorise));
+	}
+
+	g_message ("accept_setting: %d", accept_setting);
+
+	authorise = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (session), "authorise"));
+	if (authorise != FALSE) {
+		if (dbus_g_proxy_call (session, "Accept", &error, G_TYPE_INVALID, G_TYPE_INVALID) == FALSE) {
+			g_printerr ("Failed to accept file transfer: %s\n", error->message);
+			g_error_free (error);
+			return;
+		}
+		g_message ("authorised transfer");
+	} else {
+		if (dbus_g_proxy_call (session, "Reject", &error, G_TYPE_INVALID, G_TYPE_INVALID) == FALSE) {
+			g_printerr ("Failed to reject file transfer: %s\n", error->message);
+			g_error_free (error);
+			return;
+		}
+		g_message ("rejected transfer");
+		g_object_set_data (G_OBJECT (session), "filename", NULL);
+	}
+}
+
+static void
+transfer_completed_cb (DBusGProxy *session,
+		       gpointer user_data)
+{
+	GSettings *settings;
+	gboolean display_notify;
+	const char *filename;
+
+	filename = (const char *) g_object_get_data (G_OBJECT (session), "filename");
+
+	g_message ("file finish transfer: %s", filename);
+
+	if (filename == NULL)
+		return;
+
+	settings = g_settings_new (GSETTINGS_SCHEMA);
+	display_notify = g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_OBEXPUSH_NOTIFY);
+	g_object_unref (settings);
+
+	if (display_notify) {
+		show_notification (filename);
+	} else {
+		hide_statusicon ();
+	}
+	g_object_set_data (G_OBJECT (session), "filename", NULL);
+}
+
+static void
+cancelled_cb (DBusGProxy *session,
+	      gpointer user_data)
+{
+	//FIXME implement properly, we never actually finished the transfer
+	g_message ("transfered was cancelled by the sender");
+	transfer_completed_cb (session, user_data);
+	hide_statusicon ();
+}
+
+static void
+error_occurred_cb (DBusGProxy *session,
+		   const char *error_name,
+		   const char *error_message,
+		   gpointer user_data)
+{
+	//FIXME implement properly
+	g_message ("transfer error occurred: %s", error_message);
+	transfer_completed_cb (session, user_data);
+}
+
+static void
+session_created_cb (DBusGProxy *server, const char *session_path, gpointer user_data)
+{
+	DBusGProxy *session;
+
+	session = dbus_g_proxy_new_for_name (connection,
+					     "org.openobex",
+					     session_path,
+					     "org.openobex.ServerSession");
+
+	dbus_g_proxy_add_signal (session, "TransferStarted",
+				 G_TYPE_STRING, G_TYPE_STRING, G_TYPE_UINT64, G_TYPE_INVALID);
+	dbus_g_proxy_connect_signal(session, "TransferStarted",
+				    G_CALLBACK (transfer_started_cb), server, NULL);
+	dbus_g_proxy_add_signal (session, "TransferCompleted",
+				 G_TYPE_INVALID, G_TYPE_INVALID);
+	dbus_g_proxy_connect_signal(session, "TransferCompleted",
+				    G_CALLBACK (transfer_completed_cb), server, NULL);
+	dbus_g_proxy_add_signal (session, "Cancelled",
+				 G_TYPE_INVALID, G_TYPE_INVALID);
+	dbus_g_proxy_connect_signal(session, "Cancelled",
+				    G_CALLBACK (cancelled_cb), server, NULL);
+	dbus_g_proxy_add_signal (session, "ErrorOccurred",
+				 G_TYPE_INVALID, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INVALID);
+	dbus_g_proxy_connect_signal(session, "ErrorOccurred",
+				    G_CALLBACK (error_occurred_cb), server, NULL);
+}
+
+void
+obexpush_up (void)
+{
+	GError *err = NULL;
+	char *download_dir, *server;
+
+	server = NULL;
+	if (manager_proxy == NULL) {
+		manager_proxy = dbus_g_proxy_new_for_name (connection,
+							   "org.openobex",
+							   "/org/openobex",
+							   "org.openobex.Manager");
+		if (dbus_g_proxy_call (manager_proxy, "CreateBluetoothServer",
+				       &err, G_TYPE_STRING, "00:00:00:00:00:00", G_TYPE_STRING, "opp", G_TYPE_BOOLEAN, FALSE, G_TYPE_INVALID,
+				       DBUS_TYPE_G_OBJECT_PATH, &server, G_TYPE_INVALID) == FALSE) {
+			g_printerr ("Creating Bluetooth ObexPush server failed: %s\n",
+				    err->message);
+			g_error_free (err);
+			g_object_unref (manager_proxy);
+			manager_proxy = NULL;
+			return;
+		}
+	}
+
+	download_dir = lookup_download_dir ();
+
+	if (server_proxy == NULL) {
+		server_proxy = dbus_g_proxy_new_for_name (connection,
+							   "org.openobex",
+							   server,
+							   "org.openobex.Server");
+		g_free (server);
+
+		dbus_g_proxy_add_signal (server_proxy, "SessionCreated",
+					 DBUS_TYPE_G_OBJECT_PATH, G_TYPE_INVALID);
+		dbus_g_proxy_connect_signal(server_proxy, "SessionCreated",
+					    G_CALLBACK (session_created_cb), NULL, NULL);
+	}
+
+	if (dbus_g_proxy_call (server_proxy, "Start", &err,
+			   G_TYPE_STRING, download_dir, G_TYPE_BOOLEAN, TRUE, G_TYPE_BOOLEAN, FALSE, G_TYPE_INVALID,
+			   G_TYPE_INVALID) == FALSE) {
+		if (g_error_matches (err, DBUS_GERROR, DBUS_GERROR_REMOTE_EXCEPTION) != FALSE &&
+		    dbus_g_error_has_name (err, "org.openobex.Error.Started") != FALSE) {
+		    	g_error_free (err);
+		    	g_message ("already started, ignoring error");
+		    	g_free (download_dir);
+		    	return;
+		}
+		g_printerr ("Starting Bluetooth ObexPush server failed: %s\n",
+			    err->message);
+		g_error_free (err);
+		g_free (download_dir);
+		g_object_unref (server_proxy);
+		server_proxy = NULL;
+		g_object_unref (manager_proxy);
+		manager_proxy = NULL;
+		return;
+	}
+
+	g_free (download_dir);
+}
+
+static void
+obexpush_stop (gboolean stop_manager)
+{
+	GError *err = NULL;
+
+	if (server_proxy == NULL)
+		return;
+
+	if (dbus_g_proxy_call (server_proxy, "Close", &err, G_TYPE_INVALID, G_TYPE_INVALID) == FALSE) {
+		if (g_error_matches (err, DBUS_GERROR, DBUS_GERROR_REMOTE_EXCEPTION) == FALSE ||
+		    dbus_g_error_has_name (err, "org.openobex.Error.NotStarted") == FALSE) {
+			g_printerr ("Stopping Bluetooth ObexPush server failed: %s\n",
+				    err->message);
+			g_error_free (err);
+			return;
+		}
+		g_error_free (err);
+	}
+
+	if (stop_manager != FALSE) {
+		g_object_unref (server_proxy);
+		server_proxy = NULL;
+		g_object_unref (manager_proxy);
+		manager_proxy = NULL;
+	}
+
+	//FIXME stop all the notifications
+}
+
+void
+obexpush_down (void)
+{
+	obexpush_stop (TRUE);
+}
+
+void
+obexpush_restart (void)
+{
+	obexpush_stop (FALSE);
+	obexpush_up ();
+}
+
+gboolean
+obexpush_init (void)
+{
+	GError *err = NULL;
+
+	connection = dbus_g_bus_get (DBUS_BUS_SESSION, &err);
+	if (connection == NULL) {
+		g_printerr ("Connecting to session bus failed: %s\n",
+			    err->message);
+		g_error_free (err);
+		return FALSE;
+	}
+
+	dbus_g_object_register_marshaller (marshal_VOID__STRING_STRING_UINT64,
+					   G_TYPE_NONE,
+					   G_TYPE_STRING, G_TYPE_STRING, G_TYPE_UINT64, G_TYPE_INVALID);
+
+	if (!notify_init("mate-user-share")) {
+		g_warning("Unable to initialize the notification system\n");
+        }
+
+	dbus_connection_set_exit_on_disconnect (dbus_g_connection_get_connection (connection), FALSE);
+
+	return TRUE;
+}
+
+void
+obexpush_set_accept_files_policy (AcceptSetting setting)
+{
+	accept_setting = setting;
+}
+
+void
+obexpush_set_notify (gboolean enabled)
+{
+	show_notifications = enabled;
+}
+
+
+
+
+ + + diff --git a/2021-08-05-192303-3702-cppcheck@c6718ce23130_master/3.html b/2021-08-05-192303-3702-cppcheck@c6718ce23130_master/3.html new file mode 100644 index 0000000..b1b41be --- /dev/null +++ b/2021-08-05-192303-3702-cppcheck@c6718ce23130_master/3.html @@ -0,0 +1,771 @@ + + + + + + Cppcheck - HTML report - mate-user-share + + + + + + +
+ +
+
  1
+  2
+  3
+  4
+  5
+  6
+  7
+  8
+  9
+ 10
+ 11
+ 12
+ 13
+ 14
+ 15
+ 16
+ 17
+ 18
+ 19
+ 20
+ 21
+ 22
+ 23
+ 24
+ 25
+ 26
+ 27
+ 28
+ 29
+ 30
+ 31
+ 32
+ 33
+ 34
+ 35
+ 36
+ 37
+ 38
+ 39
+ 40
+ 41
+ 42
+ 43
+ 44
+ 45
+ 46
+ 47
+ 48
+ 49
+ 50
+ 51
+ 52
+ 53
+ 54
+ 55
+ 56
+ 57
+ 58
+ 59
+ 60
+ 61
+ 62
+ 63
+ 64
+ 65
+ 66
+ 67
+ 68
+ 69
+ 70
+ 71
+ 72
+ 73
+ 74
+ 75
+ 76
+ 77
+ 78
+ 79
+ 80
+ 81
+ 82
+ 83
+ 84
+ 85
+ 86
+ 87
+ 88
+ 89
+ 90
+ 91
+ 92
+ 93
+ 94
+ 95
+ 96
+ 97
+ 98
+ 99
+100
+101
+102
+103
+104
+105
+106
+107
+108
+109
+110
+111
+112
+113
+114
+115
+116
+117
+118
+119
+120
+121
+122
+123
+124
+125
+126
+127
+128
+129
+130
+131
+132
+133
+134
+135
+136
+137
+138
+139
+140
+141
+142
+143
+144
+145
+146
+147
+148
+149
+150
+151
+152
+153
+154
+155
+156
+157
+158
+159
+160
+161
+162
+163
+164
+165
+166
+167
+168
+169
+170
+171
+172
+173
+174
+175
+176
+177
+178
+179
+180
+181
+182
+183
+184
+185
+186
+187
+188
+189
+190
+191
+192
+193
+194
+195
+196
+197
+198
+199
+200
+201
+202
+203
+204
+205
+206
+207
+208
+209
+210
+211
+212
+213
+214
+215
+216
+217
+218
+219
+220
+221
+222
+223
+224
+225
+226
+227
+228
+229
+230
+231
+232
+233
+234
+235
+236
+237
+238
+239
+240
+241
+242
+243
+244
+245
+246
+247
+248
+249
+250
+251
+252
+253
+254
+255
+256
+257
+258
+259
+260
+261
+262
+263
+264
+265
+266
+267
+268
+269
+270
+271
+272
+273
+274
+275
+276
+277
+278
+279
+280
+281
+282
+283
+284
+285
+286
+287
+288
+289
+290
+291
+292
/* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 8; tab-width: 8 -*-
+ *
+ * Copyright (C) 2003 Novell, Inc.
+ * Copyright (C) 2003-2004 Red Hat, Inc.
+ * Copyright (C) 2005 William Jon McCann <mccann@jhu.edu>
+ * Copyright (C) 2012-2021 MATE Developers
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * 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 Foundation, Inc., 51 Franklin St, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ *
+ */
+
+#include "config.h"
+
+#include <stdlib.h>
+#include <string.h>
+#include <glib/gi18n-lib.h>
+#include <gtk/gtk.h>
+#include <libcaja-extension/caja-menu-provider.h>
+#include <libcaja-extension/caja-location-widget-provider.h>
+
+#ifdef HAVE_BLUETOOTH
+#include <bluetooth-client.h>
+#endif
+
+#include "caja-share-bar.h"
+#include "user_share-common.h"
+
+#define CAJA_TYPE_USER_SHARE  (caja_user_share_get_type ())
+#define CAJA_USER_SHARE(o)    (G_TYPE_CHECK_INSTANCE_CAST ((o), CAJA_TYPE_USER_SHARE, CajaUserShare))
+#define CAJA_IS_USER_SHARE(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), CAJA_TYPE_USER_SHARE))
+
+typedef struct
+{
+        GObject              parent_slot;
+} CajaUserShare;
+
+typedef struct
+{
+        GObjectClass parent_slot;
+} CajaUserShareClass;
+
+static GType caja_user_share_get_type      (void);
+static void  caja_user_share_register_type (GTypeModule *module);
+
+static void
+launch_process (char **argv, GtkWindow *parent)
+{
+        GError *error;
+        GtkWidget *dialog;
+
+        error = NULL;
+        if (!g_spawn_async (NULL,
+                            argv, NULL,
+                            0,
+                            NULL, NULL,
+                            NULL,
+                            &error)) {
+
+
+                dialog = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL, GTK_MESSAGE_WARNING,
+						 GTK_BUTTONS_OK, _("Unable to launch the Personal File Sharing preferences"));
+
+                gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog), "%s", error->message);
+
+                gtk_dialog_run (GTK_DIALOG (dialog));
+                gtk_widget_destroy (dialog);
+
+                g_error_free (error);
+        }
+}
+
+static void
+launch_prefs_on_window (GtkWindow *window)
+{
+        char *argv [2];
+
+        argv [0] = g_build_filename (BINDIR, "mate-file-share-properties", NULL);
+        argv [1] = NULL;
+
+        launch_process (argv, window);
+
+        g_free (argv [0]);
+}
+
+static void
+bar_response_cb (CajaShareBar *bar,
+                 gint response,
+                 gpointer         data)
+{
+        if (response == CAJA_SHARE_BAR_RESPONSE_PREFERENCES) {
+                launch_prefs_on_window (GTK_WINDOW (data));
+        }
+}
+
+#ifdef HAVE_BLUETOOTH
+static void
+downloads_bar_set_from_bluetooth_status (GtkWidget *bar)
+{
+	BluetoothClient *client;
+	gboolean bt_powered;
+
+	client = g_object_get_data (G_OBJECT (bar), "bluetooth-client");
+	g_object_get (G_OBJECT (client),
+		      "default-adapter-powered", &bt_powered,
+		      NULL);
+	gtk_widget_set_visible (bar, bt_powered);
+}
+
+static void
+default_adapter_powered_cb (GObject    *gobject,
+			    GParamSpec *pspec,
+			    GtkWidget  *bar)
+{
+	downloads_bar_set_from_bluetooth_status (bar);
+}
+#endif /* HAVE_BLUETOOTH */
+
+static GtkWidget *
+caja_user_share_get_location_widget (CajaLocationWidgetProvider *iface,
+                                         const char                     *uri,
+                                         GtkWidget                      *window)
+{
+	GFile             *file;
+	GtkWidget         *bar;
+	guint              i;
+	gboolean           enable = FALSE;
+	GFile             *home;
+#ifdef HAVE_BLUETOOTH
+	const GUserDirectory special_dirs[] = { G_USER_DIRECTORY_PUBLIC_SHARE, G_USER_DIRECTORY_DOWNLOAD };
+
+	gboolean is_dir[] = { FALSE, FALSE };
+#else
+	const GUserDirectory special_dirs[] = { G_USER_DIRECTORY_PUBLIC_SHARE };
+
+	gboolean is_dir[] = { FALSE };
+#endif /* HAVE_BLUETOOTH */
+	file = g_file_new_for_uri (uri);
+	home = g_file_new_for_path (g_get_home_dir ());
+
+	/* We don't show anything in $HOME */
+	if (g_file_equal (home, file)) {
+		g_object_unref (home);
+		g_object_unref (file);
+		return NULL;
+	}
+
+	g_object_unref (home);
+
+	for (i = 0; i < G_N_ELEMENTS (special_dirs); i++) {
+		GFile *dir;
+		dir = lookup_dir_with_fallback (special_dirs[i]);
+		if (g_file_equal (dir, file)) {
+			enable = TRUE;
+			is_dir[i] = TRUE;
+		}
+		g_object_unref (dir);
+	}
+
+	g_object_unref (file);
+
+	if (enable == FALSE)
+		return NULL;
+
+	if (is_dir[0] != FALSE) {
+#ifdef HAVE_BLUETOOTH
+		if (is_dir[1] != FALSE) {
+			bar = caja_share_bar_new (_("May be used to share or receive files"));
+		} else {
+			bar = caja_share_bar_new (_("May be shared over the network or Bluetooth"));
+		}
+#else
+		bar = caja_share_bar_new (_("May be shared over the network"));
+#endif /* HAVE_BLUETOOTH */
+	} else {
+#ifdef HAVE_BLUETOOTH
+		BluetoothClient *client;
+
+		bar = caja_share_bar_new (_("May be used to receive files over Bluetooth"));
+
+		gtk_widget_set_no_show_all (bar, TRUE);
+		client = bluetooth_client_new ();
+		g_object_set_data_full (G_OBJECT (bar), "bluetooth-client", client, g_object_unref);
+		g_signal_connect (G_OBJECT (client), "notify::default-adapter-powered",
+				  G_CALLBACK (default_adapter_powered_cb), bar);
+		downloads_bar_set_from_bluetooth_status (bar);
+#endif /* HAVE_BLUETOOTH */
+	}
+
+	g_signal_connect (bar, "response",
+			  G_CALLBACK (bar_response_cb),
+			  window);
+
+	gtk_widget_show_all (bar);
+
+	return bar;
+}
+
+static void
+caja_user_share_location_widget_provider_iface_init (CajaLocationWidgetProviderIface *iface)
+{
+        iface->get_widget = caja_user_share_get_location_widget;
+}
+
+static void
+caja_user_share_instance_init (CajaUserShare *share)
+{
+
+}
+
+static void
+caja_user_share_class_init (CajaUserShareClass *klass)
+{
+
+}
+
+static GType share_type = 0;
+
+static GType
+caja_user_share_get_type (void)
+{
+        return share_type;
+}
+
+static void
+caja_user_share_register_type (GTypeModule *module)
+{
+        static const GTypeInfo info = {
+                sizeof (CajaUserShareClass),
+                (GBaseInitFunc) NULL,
+                (GBaseFinalizeFunc) NULL,
+                (GClassInitFunc) caja_user_share_class_init,
+                NULL,
+                NULL,
+                sizeof (CajaUserShare),
+                0,
+                (GInstanceInitFunc) caja_user_share_instance_init,
+        };
+
+        static const GInterfaceInfo location_widget_provider_iface_info = {
+                (GInterfaceInitFunc) caja_user_share_location_widget_provider_iface_init,
+                NULL,
+                NULL
+        };
+
+        share_type = g_type_module_register_type (module,
+                                                 G_TYPE_OBJECT,
+                                                 "CajaUserShare",
+                                                 &info, 0);
+
+        g_type_module_add_interface (module,
+                                     share_type,
+                                     CAJA_TYPE_LOCATION_WIDGET_PROVIDER,
+                                     &location_widget_provider_iface_info);
+}
+
+void
+caja_module_initialize (GTypeModule *module)
+{
+        caja_user_share_register_type (module);
+        bindtextdomain (GETTEXT_PACKAGE, MATELOCALEDIR);
+        bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
+}
+
+void
+caja_module_shutdown (void)
+{
+}
+
+void
+caja_module_list_types (const GType **types,
+                            int          *num_types)
+{
+        static GType type_list [1];
+
+        type_list[0] = CAJA_TYPE_USER_SHARE;
+
+        *types = type_list;
+        *num_types = 1;
+}
+
+
+
+
+ + + diff --git a/2021-08-05-192303-3702-cppcheck@c6718ce23130_master/4.html b/2021-08-05-192303-3702-cppcheck@c6718ce23130_master/4.html new file mode 100644 index 0000000..8b2be4b --- /dev/null +++ b/2021-08-05-192303-3702-cppcheck@c6718ce23130_master/4.html @@ -0,0 +1,1189 @@ + + + + + + Cppcheck - HTML report - mate-user-share + + + + + + +
+ +
+
  1
+  2
+  3
+  4
+  5
+  6
+  7
+  8
+  9
+ 10
+ 11
+ 12
+ 13
+ 14
+ 15
+ 16
+ 17
+ 18
+ 19
+ 20
+ 21
+ 22
+ 23
+ 24
+ 25
+ 26
+ 27
+ 28
+ 29
+ 30
+ 31
+ 32
+ 33
+ 34
+ 35
+ 36
+ 37
+ 38
+ 39
+ 40
+ 41
+ 42
+ 43
+ 44
+ 45
+ 46
+ 47
+ 48
+ 49
+ 50
+ 51
+ 52
+ 53
+ 54
+ 55
+ 56
+ 57
+ 58
+ 59
+ 60
+ 61
+ 62
+ 63
+ 64
+ 65
+ 66
+ 67
+ 68
+ 69
+ 70
+ 71
+ 72
+ 73
+ 74
+ 75
+ 76
+ 77
+ 78
+ 79
+ 80
+ 81
+ 82
+ 83
+ 84
+ 85
+ 86
+ 87
+ 88
+ 89
+ 90
+ 91
+ 92
+ 93
+ 94
+ 95
+ 96
+ 97
+ 98
+ 99
+100
+101
+102
+103
+104
+105
+106
+107
+108
+109
+110
+111
+112
+113
+114
+115
+116
+117
+118
+119
+120
+121
+122
+123
+124
+125
+126
+127
+128
+129
+130
+131
+132
+133
+134
+135
+136
+137
+138
+139
+140
+141
+142
+143
+144
+145
+146
+147
+148
+149
+150
+151
+152
+153
+154
+155
+156
+157
+158
+159
+160
+161
+162
+163
+164
+165
+166
+167
+168
+169
+170
+171
+172
+173
+174
+175
+176
+177
+178
+179
+180
+181
+182
+183
+184
+185
+186
+187
+188
+189
+190
+191
+192
+193
+194
+195
+196
+197
+198
+199
+200
+201
+202
+203
+204
+205
+206
+207
+208
+209
+210
+211
+212
+213
+214
+215
+216
+217
+218
+219
+220
+221
+222
+223
+224
+225
+226
+227
+228
+229
+230
+231
+232
+233
+234
+235
+236
+237
+238
+239
+240
+241
+242
+243
+244
+245
+246
+247
+248
+249
+250
+251
+252
+253
+254
+255
+256
+257
+258
+259
+260
+261
+262
+263
+264
+265
+266
+267
+268
+269
+270
+271
+272
+273
+274
+275
+276
+277
+278
+279
+280
+281
+282
+283
+284
+285
+286
+287
+288
+289
+290
+291
+292
+293
+294
+295
+296
+297
+298
+299
+300
+301
+302
+303
+304
+305
+306
+307
+308
+309
+310
+311
+312
+313
+314
+315
+316
+317
+318
+319
+320
+321
+322
+323
+324
+325
+326
+327
+328
+329
+330
+331
+332
+333
+334
+335
+336
+337
+338
+339
+340
+341
+342
+343
+344
+345
+346
+347
+348
+349
+350
+351
+352
+353
+354
+355
+356
+357
+358
+359
+360
+361
+362
+363
+364
+365
+366
+367
+368
+369
+370
+371
+372
+373
+374
+375
+376
+377
+378
+379
+380
+381
+382
+383
+384
+385
+386
+387
+388
+389
+390
+391
+392
+393
+394
+395
+396
+397
+398
+399
+400
+401
+402
+403
+404
+405
+406
+407
+408
+409
+410
+411
+412
+413
+414
+415
+416
+417
+418
+419
+420
+421
+422
+423
+424
+425
+426
+427
+428
+429
+430
+431
+432
+433
+434
+435
+436
+437
+438
+439
+440
+441
+442
+443
+444
+445
+446
+447
+448
+449
+450
+451
+452
+453
+454
+455
+456
+457
+458
+459
+460
+461
+462
+463
+464
+465
+466
+467
+468
+469
+470
+471
+472
+473
+474
+475
+476
+477
+478
+479
+480
+481
+482
+483
+484
+485
+486
+487
+488
+489
+490
+491
+492
+493
+494
+495
+496
+497
+498
+499
+500
+501
+502
+503
+504
+505
+506
+507
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
+
+/*
+ *  Copyright (C) 2004-2008 Red Hat, Inc.
+ *  Copyright (C) 2012-2021 MATE Developers
+ *
+ *  Caja is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU General Public License as
+ *  published by the Free Software Foundation; either version 2 of the
+ *  License, or (at your option) any later version.
+ *
+ *  Caja is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  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
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ *  Authors: Alexander Larsson <alexl@redhat.com>
+ *
+ */
+
+#include "config.h"
+
+#include <gdk/gdkx.h>
+#include <gtk/gtk.h>
+#include <glib/gi18n.h>
+#include <glib/gstdio.h>
+#include <gio/gio.h>
+#include <X11/Xlib.h>
+
+#include "user_share-private.h"
+#include "user_share-common.h"
+#include "http.h"
+
+#ifdef HAVE_BLUETOOTH
+#include <bluetooth-client.h>
+
+#include "obexftp.h"
+#include "obexpush.h"
+
+#endif /* HAVE_BLUETOOTH */
+
+#include <gio/gio.h>
+
+#include <stdarg.h>
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <signal.h>
+#include <unistd.h>
+
+static guint disabled_timeout_tag = 0;
+static GSettings* settings;<--- Shadowed declaration<--- Shadowed declaration<--- Shadowed declaration
+
+#define GSETTINGS_SCHEMA "org.mate.FileSharing"
+#define GSETTINGS_KEY_FILE_SHARING_ENABLED "enabled"
+#define GSETTINGS_KEY_FILE_SHARING_REQUIRE_PASSWORD "require-password"
+
+#ifdef HAVE_BLUETOOTH
+/* MATE Session */
+#define MATE_SESSION_DBUS_NAME      "org.gnome.SessionManager"
+#define MATE_SESSION_DBUS_OBJECT    "/org/gnome/SessionManager"
+#define MATE_SESSION_DBUS_INTERFACE "org.gnome.SessionManager"
+
+static GDBusProxy *session_proxy = NULL;
+static gboolean has_console = TRUE;
+
+static BluetoothClient *client = NULL;
+static gboolean bluetoothd_enabled = FALSE;
+
+#define OBEX_ENABLED (bluetoothd_enabled && has_console)
+
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_ENABLED "bluetooth-enabled"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_ALLOW_WRITE "bluetooth-allow-write"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_REQUIRE_PAIRING "bluetooth-require-pairing"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED "bluetooth-obexpush-enabled"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_ACCEPT_FILES "bluetooth-accept-files"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_NOTIFY "bluetooth-notify"
+
+
+static void
+obex_services_start (void)
+{
+	GSettings *settings;<--- Shadow variable
+
+	if (bluetoothd_enabled == FALSE ||
+	    has_console == FALSE)
+	    	return;
+
+	settings = g_settings_new(GSETTINGS_SCHEMA);
+
+	if (g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED) == TRUE) {
+	    obexpush_up ();
+	}
+	if (g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_ENABLED) == TRUE) {
+	    obexftp_up ();
+	}
+
+	g_object_unref (client);
+}
+
+static void
+obex_services_shutdown (void)
+{
+	obexpush_down ();
+	obexftp_down ();
+}
+
+static void
+session_properties_changed_cb (GDBusProxy      *session,
+			       GVariant        *changed,
+			       char           **invalidated,
+			       gpointer         user_data)
+{
+	GVariant *v;
+
+	v = g_variant_lookup_value (changed, "SessionIsActive", G_VARIANT_TYPE_BOOLEAN);
+	if (v) {
+		has_console = g_variant_get_boolean (v);
+		g_debug ("Received session is active change: now %s", has_console ? "active" : "inactive");
+
+		if (has_console)
+			obex_services_start ();
+		else
+			obex_services_shutdown ();
+
+		g_variant_unref (v);
+	}
+}
+
+static gboolean
+is_session_active (void)
+{
+	GVariant *variant;
+	gboolean is_session_active = FALSE;
+
+	variant = g_dbus_proxy_get_cached_property (session_proxy,
+						    "SessionIsActive");
+	if (variant) {
+		is_session_active = g_variant_get_boolean (variant);
+		g_variant_unref (variant);
+ 	}
+
+	return is_session_active;
+}
+
+static void
+session_init (void)
+{
+	GError *error = NULL;
+
+	session_proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION,
+						       G_DBUS_PROXY_FLAGS_NONE,
+						       NULL,
+						       MATE_SESSION_DBUS_NAME,
+						       MATE_SESSION_DBUS_OBJECT,
+						       MATE_SESSION_DBUS_INTERFACE,
+						       NULL,
+						       &error);
+	if (session_proxy == NULL) {
+		g_warning ("Failed to get session proxy: %s", error->message);
+		g_error_free (error);
+		return;
+	}
+	g_signal_connect (session_proxy, "g-properties-changed",
+			  G_CALLBACK (session_properties_changed_cb),
+			  NULL);
+	has_console = is_session_active ();
+}
+
+static void
+default_adapter_changed (GObject    *gobject,
+			 GParamSpec *pspec,
+			 gpointer    user_data)
+{
+	char *adapter;
+	gboolean adapter_powered;
+
+	g_object_get (G_OBJECT (client),
+		      "default-adapter", &adapter,
+		      "default-adapter-powered", &adapter_powered,
+		      NULL);
+	if (adapter != NULL && *adapter != '\0') {
+		bluetoothd_enabled = adapter_powered;
+	} else {
+		bluetoothd_enabled = FALSE;
+	}
+
+	/* Were we called as init, or as a callback */
+	if (gobject != NULL) {
+		if (bluetoothd_enabled != FALSE)
+			obex_services_start ();
+		else
+			obex_services_shutdown ();
+	}
+}
+
+static void
+bluez_init (void)
+{
+	client = bluetooth_client_new ();
+	default_adapter_changed (NULL, NULL, NULL);
+	g_signal_connect (G_OBJECT (client), "notify::default-adapter",
+			  G_CALLBACK (default_adapter_changed), NULL);
+	g_signal_connect (G_OBJECT (client), "notify::default-adapter-powered",
+			  G_CALLBACK (default_adapter_changed), NULL);
+}
+#endif /* HAVE_BLUETOOTH */
+
+static gboolean
+file_sharing_enabled (void)
+{
+	gboolean enabled = TRUE;
+	settings = g_settings_new (GSETTINGS_SCHEMA);
+
+#ifdef HAVE_BLUETOOTH
+	if (g_settings_get_boolean (settings, FILE_SHARING_ENABLED) == FALSE &&
+	    g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_ENABLED) == FALSE &&
+	    g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED) == FALSE)
+#else /* HAVE_BLUETOOTH */
+	if (g_settings_get_boolean (settings, FILE_SHARING_ENABLED) == FALSE)
+#endif /* HAVE_BLUETOOTH */
+		enabled = FALSE;
+
+	g_object_unref (settings);
+
+	return enabled;
+}
+
+static void
+migrate_old_configuration (void)
+{
+	const char *old_config_dir;
+	const char *new_config_dir;
+
+	old_config_dir = g_build_filename (g_get_home_dir (), ".mate2", "user-share", NULL);
+	new_config_dir = g_build_filename (g_get_user_config_dir (), "user-share", NULL);
+	if (g_file_test (old_config_dir, G_FILE_TEST_IS_DIR))
+		g_rename (old_config_dir, new_config_dir);
+
+}
+
+static void
+require_password_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	/* Need to restart to get new password setting */
+	if (http_get_pid () != 0) {
+		http_down ();
+		http_up ();
+	}
+}
+
+/* File sharing was disabled for some time, exit now */
+/* If we re-enable it in the ui, this will be restarted anyway */
+static gboolean
+disabled_timeout_callback (gpointer user_data)
+{
+	GSettings *settings = (GSettings *) user_data;<--- Shadow variable
+	http_down ();
+
+#ifdef HAVE_BLUETOOTH
+	if (g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_ENABLED) == FALSE &&
+	    g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED) == FALSE)
+		_exit (0);
+#else /* HAVE_BLUETOOTH */
+	if (g_settings_get_boolean (settings, FILE_SHARING_ENABLED) == FALSE)
+		_exit (0);
+#endif /* HAVE_BLUETOOTH */
+	return FALSE;
+}
+
+static void
+file_sharing_enabled_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	gboolean enabled;
+
+	if (disabled_timeout_tag != 0) {
+		g_source_remove (disabled_timeout_tag);
+		disabled_timeout_tag = 0;
+	}
+
+	enabled = g_settings_get_boolean (settings,
+					 FILE_SHARING_ENABLED);
+	if (enabled) {
+		if (http_get_pid () == 0) {
+			http_up ();
+		}
+	} else {
+		http_down ();
+		disabled_timeout_tag = g_timeout_add_seconds (3,
+							      (GSourceFunc)disabled_timeout_callback,
+							      settings);
+	}
+}
+
+#ifdef HAVE_BLUETOOTH
+static void
+file_sharing_bluetooth_allow_write_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	if (g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_ENABLED) != FALSE)
+		obexftp_restart ();
+}
+
+static void
+file_sharing_bluetooth_require_pairing_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	if (g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_ENABLED) != FALSE) {
+		/* We need to fully reset the session,
+		 * otherwise the new setting isn't taken into account */
+		obexftp_down ();
+		obexftp_up ();
+	}
+}
+
+static void
+file_sharing_bluetooth_enabled_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	if (g_settings_get_boolean (settings,
+				   FILE_SHARING_BLUETOOTH_ENABLED) == FALSE) {
+		obexftp_down ();
+		if (g_settings_get_boolean (settings, FILE_SHARING_ENABLED) == FALSE &&
+		    g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED) == FALSE) {
+			_exit (0);
+		}
+	} else if (OBEX_ENABLED) {
+		obexftp_up ();
+	}
+}
+
+static void
+file_sharing_bluetooth_obexpush_enabled_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	if (g_settings_get_boolean (settings,
+				   FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED) == FALSE) {
+		obexpush_down ();
+		if (g_settings_get_boolean (settings, FILE_SHARING_ENABLED) == FALSE &&
+		    g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_ENABLED) == FALSE) {
+			_exit (0);
+		}
+	} else if (OBEX_ENABLED) {
+		obexpush_up ();
+	}
+}
+
+static void
+file_sharing_bluetooth_obexpush_accept_files_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	AcceptSetting setting;
+	char *str;
+
+	str = g_settings_get_string (settings, FILE_SHARING_BLUETOOTH_OBEXPUSH_ACCEPT_FILES);
+	setting = accept_setting_from_string (str);
+	g_free (str);
+
+	obexpush_set_accept_files_policy (setting);
+}
+
+static void
+file_sharing_bluetooth_obexpush_notify_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	obexpush_set_notify (g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_OBEXPUSH_NOTIFY));
+}
+#endif /* HAVE_BLUETOOTH */
+
+static RETSIGTYPE
+cleanup_handler (int sig)
+{
+	http_down ();
+#ifdef HAVE_BLUETOOTH
+	obexftp_down ();
+	obexpush_down ();
+#endif /* HAVE_BLUETOOTH */
+	_exit (2);
+}
+
+static int
+x_io_error_handler (Display *xdisplay)
+{
+	http_down ();
+#ifdef HAVE_BLUETOOTH
+	obexftp_down ();
+#endif /* HAVE_BLUETOOTH */
+	_exit (2);
+}
+
+int
+main (int argc, char **argv)
+{
+	GSettings *settings;<--- Shadow variable
+	Display *xdisplay;
+	G_GNUC_UNUSED int x_fd;
+	Window selection_owner;
+	Atom xatom;
+
+	bindtextdomain (GETTEXT_PACKAGE, MATELOCALEDIR);
+	bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
+	textdomain (GETTEXT_PACKAGE);
+
+	gtk_init (&argc, &argv);
+
+	if (g_strcmp0 (g_get_real_name (), "root") == 0) {
+		g_warning ("mate-user-share cannot be started as root for security reasons.");
+		return 1;
+	}
+
+	signal (SIGPIPE, SIG_IGN);
+	signal (SIGINT, cleanup_handler);
+	signal (SIGHUP, cleanup_handler);
+	signal (SIGTERM, cleanup_handler);
+
+	xdisplay = GDK_DISPLAY_XDISPLAY (gdk_display_get_default ());
+	if (xdisplay == NULL) {
+		g_warning ("Can't open display");
+		return 1;
+	}
+
+	xatom = XInternAtom (xdisplay, "_MATE_USER_SHARE", FALSE);
+	selection_owner = XGetSelectionOwner (xdisplay, xatom);
+
+	if (selection_owner != None) {
+		/* There is an owner already, quit */
+		return 1;
+	}
+
+	selection_owner = XCreateSimpleWindow (xdisplay,
+					       RootWindow (xdisplay, 0),
+					       0, 0, 1, 1,
+					       0, 0, 0);
+	XSetSelectionOwner (xdisplay, xatom, selection_owner, CurrentTime);
+
+	if (XGetSelectionOwner (xdisplay, xatom) != selection_owner) {
+		/* Didn't get the selection */
+		return 1;
+	}
+
+	migrate_old_configuration ();
+
+	if (!file_sharing_enabled ())
+		return 1;
+
+	settings = g_settings_new (GSETTINGS_SCHEMA);
+
+	x_fd = ConnectionNumber (xdisplay);
+	XSetIOErrorHandler (x_io_error_handler);
+
+	if (http_init () == FALSE)
+		return 1;
+#ifdef HAVE_BLUETOOTH
+	if (obexftp_init () == FALSE)
+		return 1;
+	if (obexpush_init () == FALSE)
+		return 1;
+#endif /* HAVE_BLUETOOTH */
+
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_ENABLED,
+			     G_CALLBACK (file_sharing_enabled_changed), NULL);
+
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_REQUIRE_PASSWORD,
+			     G_CALLBACK (require_password_changed), NULL);
+
+#ifdef HAVE_BLUETOOTH
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_ENABLED,
+			     G_CALLBACK (file_sharing_bluetooth_enabled_changed), NULL);
+
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_ALLOW_WRITE,
+			     G_CALLBACK (file_sharing_bluetooth_allow_write_changed), NULL);
+
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_REQUIRE_PAIRING,
+			     G_CALLBACK (file_sharing_bluetooth_require_pairing_changed), NULL);
+
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED,
+			     G_CALLBACK (file_sharing_bluetooth_obexpush_enabled_changed), NULL);
+
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_ACCEPT_FILES,
+			     G_CALLBACK (file_sharing_bluetooth_obexpush_accept_files_changed), NULL);
+
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_NOTIFY,
+			     G_CALLBACK (file_sharing_bluetooth_obexpush_notify_changed), NULL);
+
+	bluez_init ();
+	session_init ();
+#endif /* HAVE_BLUETOOTH */
+
+	/* Initial setting */
+	file_sharing_enabled_changed (settings, NULL, NULL);
+#ifdef HAVE_BLUETOOTH
+	file_sharing_bluetooth_enabled_changed (settings, NULL, NULL);
+	file_sharing_bluetooth_obexpush_accept_files_changed (settings, NULL, NULL);
+	file_sharing_bluetooth_obexpush_notify_changed (settings, NULL, NULL);
+	file_sharing_bluetooth_obexpush_enabled_changed (settings, NULL, NULL);
+#endif /* HAVE_BLUETOOTH */
+
+	gtk_main ();
+
+	return 0;
+}
+
+
+
+
+ + + diff --git a/2021-08-05-192303-3702-cppcheck@c6718ce23130_master/index.html b/2021-08-05-192303-3702-cppcheck@c6718ce23130_master/index.html new file mode 100644 index 0000000..67287ae --- /dev/null +++ b/2021-08-05-192303-3702-cppcheck@c6718ce23130_master/index.html @@ -0,0 +1,141 @@ + + + + + + Cppcheck - HTML report - mate-user-share + + + + + + +
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
LineIdCWESeverityMessage
missingIncludeinformationCppcheck cannot find all the include files (use --check-config for details)
src/file-share-properties.c
83variableScope398styleThe scope of the variable 'password' can be reduced.
98shadowVariable398styleLocal variable 'settings' shadows outer variable
106unusedVariable563styleUnused variable: accept_setting
250shadowVariable398styleLocal variable 'settings' shadows outer variable
274shadowVariable398styleLocal variable 'settings' shadows outer variable
295shadowVariable398styleLocal variable 'settings' shadows outer variable
324shadowVariable398styleLocal variable 'settings' shadows outer variable
341shadowVariable398styleLocal variable 'settings' shadows outer variable
358shadowVariable398styleLocal variable 'settings' shadows outer variable
378shadowVariable398styleLocal variable 'settings' shadows outer variable
394shadowVariable398styleLocal variable 'settings' shadows outer variable
458shadowVariable398styleLocal variable 'settings' shadows outer variable
621variableScope398styleThe scope of the variable 'window' can be reduced.
src/http.c
115variableScope398styleThe scope of the variable 'host_name' can be reduced.
src/obexpush.c
188shadowVariable398styleLocal variable 'connection' shadows outer variable
src/share-extension.c
62variableScope398styleThe scope of the variable 'dialog' can be reduced.
src/user_share.c
87shadowVariable398styleLocal variable 'settings' shadows outer variable
261shadowVariable398styleLocal variable 'settings' shadows outer variable
392shadowVariable398styleLocal variable 'settings' shadows outer variable
+
+
+ + + diff --git a/2021-08-05-192303-3702-cppcheck@c6718ce23130_master/stats.html b/2021-08-05-192303-3702-cppcheck@c6718ce23130_master/stats.html new file mode 100644 index 0000000..4496b03 --- /dev/null +++ b/2021-08-05-192303-3702-cppcheck@c6718ce23130_master/stats.html @@ -0,0 +1,109 @@ + + + + + + Cppcheck - HTML report - mate-user-share + + + + + + +
+ +
+

Top 10 files for style severity, total findings: 19
+   13  src/file-share-properties.c
+   3   src/user_share.c
+   1   src/share-extension.c
+   1   src/obexpush.c
+   1   src/http.c
+

+ +
+
+ + + diff --git a/2021-08-05-192303-3702-cppcheck@c6718ce23130_master/style.css b/2021-08-05-192303-3702-cppcheck@c6718ce23130_master/style.css new file mode 100644 index 0000000..07125f4 --- /dev/null +++ b/2021-08-05-192303-3702-cppcheck@c6718ce23130_master/style.css @@ -0,0 +1,137 @@ + +body { + font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif; + font-size: 13px; + line-height: 1.5; + margin: 0; + width: auto; +} + +h1 { + margin: 10px; +} + +.header { + border-bottom: thin solid #aaa; +} + +.footer { + border-top: thin solid #aaa; + font-size: 90%; + margin-top: 5px; +} + +.footer ul { + list-style-type: none; + padding-left: 0; +} + +.footer > p { + margin: 4px; +} + +.wrapper { + display: -webkit-box; + display: -ms-flexbox; + display: flex; + -webkit-box-pack: justify; + -ms-flex-pack: justify; + justify-content: space-between; +} + +#menu, +#menu_index { + text-align: left; + width: 350px; + height: 90vh; + min-height: 200px; + overflow: auto; + position: -webkit-sticky; + position: sticky; + top: 0; + padding: 0 15px 15px 15px; +} + +#menu > a { + display: block; + margin-left: 10px; + font-size: 12px; + z-index: 1; +} + +#content, +#content_index { + background-color: #fff; + -webkit-box-sizing: content-box; + -moz-box-sizing: content-box; + box-sizing: content-box; + padding: 0 15px 15px 15px; + width: calc(100% - 350px); + height: 100%; + overflow-x: auto; +} + +#filename { + margin-left: 10px; + font-size: 12px; + z-index: 1; +} + +.error { + background-color: #ffb7b7; +} + +.error2 { + background-color: #faa; + display: inline-block; + margin-left: 4px; +} + +.inconclusive { + background-color: #b6b6b4; +} + +.inconclusive2 { + background-color: #b6b6b4; + display: inline-block; + margin-left: 4px; +} + +.verbose { + display: inline-block; + vertical-align: top; + cursor: help; +} + +.verbose .content { + display: none; + position: absolute; + padding: 10px; + margin: 4px; + max-width: 40%; + white-space: pre-wrap; + border: 1px solid #000; + background-color: #ffffcc; + cursor: auto; +} + +.highlight .hll { + padding: 1px; +} + +.highlighttable { + background-color: #fff; + z-index: 10; + position: relative; + margin: -10px; +} + +.linenos { + border-right: thin solid #aaa; + color: #d3d3d3; + padding-right: 6px; +} + +.d-none { + display: none; +} diff --git a/2022-02-13-194124-4467-cppcheck@b215c4400bb6_master/0.html b/2022-02-13-194124-4467-cppcheck@b215c4400bb6_master/0.html new file mode 100644 index 0000000..c4f7704 --- /dev/null +++ b/2022-02-13-194124-4467-cppcheck@b215c4400bb6_master/0.html @@ -0,0 +1,1505 @@ + + + + + + Cppcheck - HTML report - mate-user-share + + + + + + +
+ +
+
  1
+  2
+  3
+  4
+  5
+  6
+  7
+  8
+  9
+ 10
+ 11
+ 12
+ 13
+ 14
+ 15
+ 16
+ 17
+ 18
+ 19
+ 20
+ 21
+ 22
+ 23
+ 24
+ 25
+ 26
+ 27
+ 28
+ 29
+ 30
+ 31
+ 32
+ 33
+ 34
+ 35
+ 36
+ 37
+ 38
+ 39
+ 40
+ 41
+ 42
+ 43
+ 44
+ 45
+ 46
+ 47
+ 48
+ 49
+ 50
+ 51
+ 52
+ 53
+ 54
+ 55
+ 56
+ 57
+ 58
+ 59
+ 60
+ 61
+ 62
+ 63
+ 64
+ 65
+ 66
+ 67
+ 68
+ 69
+ 70
+ 71
+ 72
+ 73
+ 74
+ 75
+ 76
+ 77
+ 78
+ 79
+ 80
+ 81
+ 82
+ 83
+ 84
+ 85
+ 86
+ 87
+ 88
+ 89
+ 90
+ 91
+ 92
+ 93
+ 94
+ 95
+ 96
+ 97
+ 98
+ 99
+100
+101
+102
+103
+104
+105
+106
+107
+108
+109
+110
+111
+112
+113
+114
+115
+116
+117
+118
+119
+120
+121
+122
+123
+124
+125
+126
+127
+128
+129
+130
+131
+132
+133
+134
+135
+136
+137
+138
+139
+140
+141
+142
+143
+144
+145
+146
+147
+148
+149
+150
+151
+152
+153
+154
+155
+156
+157
+158
+159
+160
+161
+162
+163
+164
+165
+166
+167
+168
+169
+170
+171
+172
+173
+174
+175
+176
+177
+178
+179
+180
+181
+182
+183
+184
+185
+186
+187
+188
+189
+190
+191
+192
+193
+194
+195
+196
+197
+198
+199
+200
+201
+202
+203
+204
+205
+206
+207
+208
+209
+210
+211
+212
+213
+214
+215
+216
+217
+218
+219
+220
+221
+222
+223
+224
+225
+226
+227
+228
+229
+230
+231
+232
+233
+234
+235
+236
+237
+238
+239
+240
+241
+242
+243
+244
+245
+246
+247
+248
+249
+250
+251
+252
+253
+254
+255
+256
+257
+258
+259
+260
+261
+262
+263
+264
+265
+266
+267
+268
+269
+270
+271
+272
+273
+274
+275
+276
+277
+278
+279
+280
+281
+282
+283
+284
+285
+286
+287
+288
+289
+290
+291
+292
+293
+294
+295
+296
+297
+298
+299
+300
+301
+302
+303
+304
+305
+306
+307
+308
+309
+310
+311
+312
+313
+314
+315
+316
+317
+318
+319
+320
+321
+322
+323
+324
+325
+326
+327
+328
+329
+330
+331
+332
+333
+334
+335
+336
+337
+338
+339
+340
+341
+342
+343
+344
+345
+346
+347
+348
+349
+350
+351
+352
+353
+354
+355
+356
+357
+358
+359
+360
+361
+362
+363
+364
+365
+366
+367
+368
+369
+370
+371
+372
+373
+374
+375
+376
+377
+378
+379
+380
+381
+382
+383
+384
+385
+386
+387
+388
+389
+390
+391
+392
+393
+394
+395
+396
+397
+398
+399
+400
+401
+402
+403
+404
+405
+406
+407
+408
+409
+410
+411
+412
+413
+414
+415
+416
+417
+418
+419
+420
+421
+422
+423
+424
+425
+426
+427
+428
+429
+430
+431
+432
+433
+434
+435
+436
+437
+438
+439
+440
+441
+442
+443
+444
+445
+446
+447
+448
+449
+450
+451
+452
+453
+454
+455
+456
+457
+458
+459
+460
+461
+462
+463
+464
+465
+466
+467
+468
+469
+470
+471
+472
+473
+474
+475
+476
+477
+478
+479
+480
+481
+482
+483
+484
+485
+486
+487
+488
+489
+490
+491
+492
+493
+494
+495
+496
+497
+498
+499
+500
+501
+502
+503
+504
+505
+506
+507
+508
+509
+510
+511
+512
+513
+514
+515
+516
+517
+518
+519
+520
+521
+522
+523
+524
+525
+526
+527
+528
+529
+530
+531
+532
+533
+534
+535
+536
+537
+538
+539
+540
+541
+542
+543
+544
+545
+546
+547
+548
+549
+550
+551
+552
+553
+554
+555
+556
+557
+558
+559
+560
+561
+562
+563
+564
+565
+566
+567
+568
+569
+570
+571
+572
+573
+574
+575
+576
+577
+578
+579
+580
+581
+582
+583
+584
+585
+586
+587
+588
+589
+590
+591
+592
+593
+594
+595
+596
+597
+598
+599
+600
+601
+602
+603
+604
+605
+606
+607
+608
+609
+610
+611
+612
+613
+614
+615
+616
+617
+618
+619
+620
+621
+622
+623
+624
+625
+626
+627
+628
+629
+630
+631
+632
+633
+634
+635
+636
+637
+638
+639
+640
+641
+642
+643
+644
+645
+646
+647
+648
+649
+650
+651
+652
+653
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
+
+/*
+ *  Copyright (C) 2004 Red Hat, Inc.
+ * Copyright (C) 2012-2021 MATE Developers
+ *
+ *  Caja is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU General Public License as
+ *  published by the Free Software Foundation; either version 2 of the
+ *  License, or (at your option) any later version.
+ *
+ *  Caja is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  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
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ *  Authors: Alexander Larsson <alexl@redhat.com>
+ *
+ */
+
+#include "config.h"
+
+#include <string.h>
+#include <stdio.h>
+
+#include <gtk/gtk.h>
+#include <glib/gi18n.h>
+#include <gio/gio.h>
+
+#include "user_share-private.h"
+
+#define REALM "Please log in as the user guest"
+#define USER "guest"
+#define GSETTINGS_SCHEMA "org.mate.FileSharing"
+#define GSETTINGS_KEY_FILE_SHARING_ENABLED "enabled"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_ENABLED "bluetooth-enabled"
+#define GSETTINGS_KEY_FILE_SHARING_REQUIRE_PASSWORD "require-password"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_ALLOW_WRITE "bluetooth-allow-write"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_REQUIRE_PAIRING "bluetooth-require-pairing"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED "bluetooth-obexpush-enabled"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_ACCEPT_FILES "bluetooth-accept-files"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_NOTIFY "bluetooth-notify"
+
+static GtkBuilder* builder;
+static GSettings* settings;<--- Shadowed declaration<--- Shadowed declaration<--- Shadowed declaration<--- Shadowed declaration<--- Shadowed declaration<--- Shadowed declaration<--- Shadowed declaration<--- Shadowed declaration<--- Shadowed declaration<--- Shadowed declaration
+
+
+static void
+write_out_password (const char *password)
+{
+    char *to_hash;
+    char *ascii_digest;
+    char *line;
+    char *filename;
+    FILE *file;
+
+    to_hash = g_strdup_printf ("%s:%s:%s", USER, REALM, password);
+    ascii_digest = g_compute_checksum_for_string (G_CHECKSUM_MD5, to_hash, strlen (to_hash));
+    g_free (to_hash);
+    line = g_strdup_printf ("%s:%s:%s\n", USER, REALM, ascii_digest);
+    g_free (ascii_digest);
+
+    filename = g_build_filename (g_get_user_config_dir (), "user-share", "passwd", NULL);
+
+    file = fopen (filename, "w");
+    if (file != NULL) {
+	fwrite (line, strlen (line), 1, file);
+	fclose (file);
+    }
+
+    g_free (filename);
+    g_free (line);
+}
+
+static void
+flush_password (void)
+{
+    GtkWidget *password_entry;
+    const char *password;
+
+    password_entry = GTK_WIDGET (gtk_builder_get_object (builder, "password_entry"));
+
+    if (g_object_get_data (G_OBJECT( password_entry), "user_edited")) {
+	password = gtk_entry_get_text (GTK_ENTRY (password_entry));
+	if (password != NULL && password[0] != 0)
+	    write_out_password (password);
+    }
+}
+
+
+static void
+update_ui (void)
+{
+    GSettings *settings;<--- Shadow variable
+    gboolean enabled;
+#ifdef HAVE_BLUETOOTH
+    gboolean bluetooth_enabled, bluetooth_write_enabled, require_pairing_enabled;
+    gboolean bluetooth_obexpush_enabled, bluetooth_obexpush_notify;
+#endif /* HAVE_BLUETOOTH */
+    char *str;
+    PasswordSetting password_setting;
+    AcceptSetting accept_setting;<--- Unused variable: accept_setting
+    GtkWidget *check;
+    GtkWidget *password_combo;
+    GtkWidget *password_entry;
+#ifdef HAVE_BLUETOOTH
+    GtkWidget *vbox_share_bluetooth;
+    GtkWidget *vbox_receive_bluetooth;
+    GtkWidget *bluetooth_check;
+    GtkWidget *allow_write_bluetooth_check;
+    GtkWidget *require_pairing_check;
+    GtkWidget *enable_obexpush_check;
+    GtkWidget *accept_obexpush_combo;
+    GtkWidget *notify_received_obexpush_check;
+#endif /* HAVE_BLUETOOTH */
+
+    settings = g_settings_new (GSETTINGS_SCHEMA);
+
+    enabled = g_settings_get_boolean (settings,
+				     FILE_SHARING_ENABLED);
+
+    str = g_settings_get_string (settings, FILE_SHARING_REQUIRE_PASSWORD);
+    password_setting = password_setting_from_string (str);
+    g_free (str);
+
+#ifdef HAVE_BLUETOOTH
+    bluetooth_enabled = g_settings_get_boolean (settings,
+    					       FILE_SHARING_BLUETOOTH_ENABLED);
+    bluetooth_write_enabled = g_settings_get_boolean (settings,
+						     FILE_SHARING_BLUETOOTH_ALLOW_WRITE);
+    require_pairing_enabled = g_settings_get_boolean (settings,
+    						     FILE_SHARING_BLUETOOTH_REQUIRE_PAIRING);
+    bluetooth_obexpush_enabled = g_settings_get_boolean (settings,
+    							FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED);
+    bluetooth_obexpush_notify = g_settings_get_boolean (settings,
+    						       FILE_SHARING_BLUETOOTH_OBEXPUSH_NOTIFY);
+
+    str = g_settings_get_string (settings, FILE_SHARING_BLUETOOTH_OBEXPUSH_ACCEPT_FILES);
+    accept_setting = accept_setting_from_string (str);
+    g_free (str);
+#endif /* HAVE_BLUETOOTH */
+
+    check = GTK_WIDGET (gtk_builder_get_object (builder, "enable_check"));
+    password_combo = GTK_WIDGET (gtk_builder_get_object (builder, "password_combo"));
+    password_entry = GTK_WIDGET (gtk_builder_get_object (builder, "password_entry"));
+#ifdef HAVE_BLUETOOTH
+    vbox_share_bluetooth = GTK_WIDGET (gtk_builder_get_object (builder, "vbox_share_bluetooth"));
+    vbox_receive_bluetooth = GTK_WIDGET (gtk_builder_get_object (builder, "vbox_receive_bluetooth"));
+    bluetooth_check = GTK_WIDGET (gtk_builder_get_object (builder, "enable_bluetooth_check"));
+    allow_write_bluetooth_check = GTK_WIDGET (gtk_builder_get_object (builder, "allow_write_bluetooth_check"));
+    require_pairing_check = GTK_WIDGET (gtk_builder_get_object (builder, "require_pairing_check"));
+    enable_obexpush_check = GTK_WIDGET (gtk_builder_get_object (builder, "enable_obexpush_check"));
+    accept_obexpush_combo = GTK_WIDGET (gtk_builder_get_object (builder, "accept_obexpush_combo"));
+    notify_received_obexpush_check = GTK_WIDGET (gtk_builder_get_object (builder, "notify_received_obexpush_check"));
+#endif /* HAVE_BLUETOOTH */
+
+    /* Network */
+    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (check), enabled);
+    gtk_widget_set_sensitive (password_combo, enabled);
+    gtk_widget_set_sensitive (password_entry, enabled && password_setting != PASSWORD_NEVER);
+
+    gtk_combo_box_set_active (GTK_COMBO_BOX (password_combo),
+			      password_setting);
+
+#ifdef HAVE_BLUETOOTH
+    /* Bluetooth ObexFTP */
+    gtk_widget_set_visible (vbox_share_bluetooth, TRUE);
+    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (bluetooth_check), bluetooth_enabled);
+    gtk_widget_set_sensitive (allow_write_bluetooth_check, bluetooth_enabled);
+    gtk_widget_set_sensitive (require_pairing_check, bluetooth_enabled);
+
+    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (allow_write_bluetooth_check),
+    				  bluetooth_write_enabled);
+    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (require_pairing_check),
+    				  require_pairing_enabled);
+
+    /* Bluetooth ObexPush */
+    gtk_widget_set_visible (vbox_receive_bluetooth, TRUE);
+    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (enable_obexpush_check), bluetooth_obexpush_enabled);
+    gtk_widget_set_sensitive (accept_obexpush_combo, bluetooth_obexpush_enabled);
+    gtk_widget_set_sensitive (notify_received_obexpush_check, bluetooth_obexpush_enabled);
+
+    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (notify_received_obexpush_check),
+    				  bluetooth_obexpush_notify);
+
+    gtk_combo_box_set_active (GTK_COMBO_BOX (accept_obexpush_combo),
+    			      accept_setting);
+#endif /* HAVE_BLUETOOTH */
+
+    g_object_unref (settings);
+}
+
+static void
+file_sharing_enabled_changed (GSettings *settings, gchar *key, gpointer data)
+{
+    update_ui ();
+}
+
+static void
+password_required_changed (GSettings *settings, gchar *key, gpointer data)
+{
+    update_ui ();
+}
+
+#ifdef HAVE_BLUETOOTH
+static void
+file_sharing_bluetooth_enabled_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	update_ui ();
+}
+
+static void
+file_sharing_bluetooth_allow_write_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	update_ui ();
+}
+
+static void
+file_sharing_bluetooth_require_pairing_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	update_ui ();
+}
+
+static void
+file_sharing_bluetooth_obexpush_enabled_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	update_ui ();
+}
+
+static void
+file_sharing_bluetooth_obexpush_accept_files_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	update_ui ();
+}
+
+static void
+file_sharing_bluetooth_obexpush_notify_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	update_ui ();
+}
+#endif /* HAVE_BLUETOOTH */
+
+static void
+password_combo_changed (GtkComboBox *combo_box)
+{
+    GSettings *settings;<--- Shadow variable
+    guint setting;
+
+    setting = gtk_combo_box_get_active (combo_box);
+
+    settings = g_settings_new (GSETTINGS_SCHEMA) ;
+
+    g_settings_set_string (settings,
+			     FILE_SHARING_REQUIRE_PASSWORD,
+			     password_string_from_setting (setting));
+    g_object_unref (settings);
+}
+
+static void
+launch_share (void)
+{
+	if (!g_spawn_command_line_async (USER_SHARE_PROGRAM, NULL))
+		g_warning ("Unable to start mate-user-share program");
+}
+
+#ifdef HAVE_BLUETOOTH
+static void
+enable_bluetooth_check_toggled (GtkWidget *check)
+{
+	GSettings *settings;<--- Shadow variable
+	gboolean enabled;
+
+	enabled = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check));
+
+	settings = g_settings_new (GSETTINGS_SCHEMA) ;
+
+	g_settings_set_boolean (settings,
+			       FILE_SHARING_BLUETOOTH_ENABLED,
+			       enabled);
+
+	g_object_unref (settings);
+
+	if (enabled != FALSE)
+		launch_share ();
+}
+#endif /* HAVE_BLUETOOTH */
+
+static void
+enable_check_toggled (GtkWidget *check)
+{
+	GSettings *settings;<--- Shadow variable
+	gboolean enabled;
+
+	enabled = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check));
+
+	settings = g_settings_new (GSETTINGS_SCHEMA);
+
+	g_settings_set_boolean (settings,
+			       FILE_SHARING_ENABLED,
+			       enabled);
+
+	g_object_unref (settings);
+
+	if (enabled != FALSE)
+		launch_share ();
+}
+
+static void
+password_entry_changed (GtkEditable *editable)
+{
+	g_object_set_data (G_OBJECT (editable),
+			   "user_edited", GINT_TO_POINTER (1));
+	flush_password ();
+}
+
+#ifdef HAVE_BLUETOOTH
+static void
+bluetooth_allow_write_check_toggled (GtkWidget *check)
+{
+	GSettings *settings;<--- Shadow variable
+	gboolean enabled;
+
+	enabled = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check));
+
+	settings = g_settings_new (GSETTINGS_SCHEMA) ;
+
+	g_settings_set_boolean (settings,
+			       FILE_SHARING_BLUETOOTH_ALLOW_WRITE,
+			       enabled);
+
+	g_object_unref (settings);
+}
+
+static void
+bluetooth_require_pairing_check_toggled (GtkWidget *check)
+{
+	GSettings *settings;<--- Shadow variable
+	gboolean enabled;
+
+	enabled = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check));
+
+	settings = g_settings_new (GSETTINGS_SCHEMA) ;
+
+	g_settings_set_boolean (settings,
+			       FILE_SHARING_BLUETOOTH_REQUIRE_PAIRING,
+			       enabled);
+
+	g_object_unref (settings);
+}
+
+static void
+enable_obexpush_check_toggled (GtkWidget *check)
+{
+	GSettings *settings;<--- Shadow variable
+	gboolean enabled;
+
+	enabled = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check));
+
+	settings = g_settings_new (GSETTINGS_SCHEMA) ;
+
+	g_settings_set_boolean (settings,
+			       FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED,
+			       enabled);
+
+	g_object_unref (settings);
+
+	if (enabled != FALSE)
+		launch_share ();
+}
+
+static void
+accept_obexpush_combo_changed (GtkComboBox *combo_box)
+{
+    GSettings *settings;<--- Shadow variable
+    guint setting;
+
+    setting = gtk_combo_box_get_active (combo_box);
+
+    settings = g_settings_new (GSETTINGS_SCHEMA) ;
+
+    g_settings_set_string (settings,
+			     FILE_SHARING_BLUETOOTH_OBEXPUSH_ACCEPT_FILES,
+			     accept_string_from_setting (setting));
+    g_object_unref (settings);
+}
+
+static void
+notify_received_obexpush_check_toggled (GtkWidget *check)
+{
+	GSettings *settings;<--- Shadow variable
+	gboolean enabled;
+
+	enabled = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check));
+
+	settings = g_settings_new (GSETTINGS_SCHEMA) ;
+
+	g_settings_set_boolean (settings,
+			       FILE_SHARING_BLUETOOTH_OBEXPUSH_NOTIFY,
+			       enabled);
+
+	g_object_unref (settings);
+}
+#endif /* HAVE_BLUETOOTH */
+
+static GtkWidget *
+error_dialog (const char *title,
+	      const char *reason,
+	      GtkWindow *parent)
+{
+	GtkWidget *error_dialog;
+
+	if (reason == NULL)
+		reason = _("No reason");
+
+	error_dialog =
+		gtk_message_dialog_new (parent,
+					GTK_DIALOG_MODAL,
+					GTK_MESSAGE_ERROR,
+					GTK_BUTTONS_OK,
+					"%s", title);
+	gtk_message_dialog_format_secondary_text
+		(GTK_MESSAGE_DIALOG (error_dialog), "%s", reason);
+
+	gtk_window_set_title (GTK_WINDOW (error_dialog), ""); /* as per HIG */
+	gtk_container_set_border_width (GTK_CONTAINER (error_dialog), 5);
+	gtk_dialog_set_default_response (GTK_DIALOG (error_dialog),
+					 GTK_RESPONSE_OK);
+	gtk_window_set_modal (GTK_WINDOW (error_dialog), TRUE);
+
+	return error_dialog;
+}
+
+static void
+help_button_clicked (GtkButton *button, GtkWidget *window)
+{
+	GError *error = NULL;
+
+	if (gtk_show_uri_on_window (GTK_WINDOW (window), "help:mate-user-share", gtk_get_current_event_time (), &error) == FALSE) {
+		GtkWidget *dialog;
+
+		dialog = error_dialog (_("Could not display the help contents."), error->message, GTK_WINDOW (window));
+		g_signal_connect (G_OBJECT (dialog), "response", G_CALLBACK
+				  (gtk_widget_destroy), error_dialog);
+		gtk_window_present (GTK_WINDOW (dialog));
+
+		g_error_free (error);
+	}
+}
+
+static GtkWidget *
+create_window (void)
+{
+    GError *error = NULL;
+    GSettings *settings;<--- Shadow variable
+    GtkWidget *check;
+    GtkWidget *password_combo;
+    GtkWidget *password_entry;
+#ifdef HAVE_BLUETOOTH
+    GtkWidget *bluetooth_check;
+    GtkWidget *bluetooth_allow_write_check;
+    GtkWidget *require_pairing_check;
+    GtkWidget *enable_obexpush_check;
+    GtkWidget *accept_obexpush_combo;
+    GtkWidget *notify_received_obexpush_check;
+#endif /* HAVE_BLUETOOTH */
+    GtkWidget *window;
+    GtkListStore *store;
+    GtkCellRenderer *cell;
+    GtkTreeIter iter;
+
+    builder = gtk_builder_new ();
+    gtk_builder_add_from_file (builder, DATADIR"file-share-properties.ui", &error);
+
+    if (error) {
+      GtkWidget *dialog;
+
+      dialog = error_dialog (_("Could not build interface."), error->message, NULL);
+      gtk_dialog_run (GTK_DIALOG (dialog));
+      gtk_widget_destroy (dialog);
+
+      g_error_free (error);
+      return NULL;
+    }
+
+    window = GTK_WIDGET (gtk_builder_get_object (builder, "user_share_dialog"));
+
+    settings = g_settings_new (GSETTINGS_SCHEMA);
+
+    check = GTK_WIDGET (gtk_builder_get_object (builder, "enable_check"));
+    password_combo = GTK_WIDGET (gtk_builder_get_object (builder, "password_combo"));
+    password_entry = GTK_WIDGET (gtk_builder_get_object (builder, "password_entry"));
+#ifdef HAVE_BLUETOOTH
+    bluetooth_check = GTK_WIDGET (gtk_builder_get_object (builder, "enable_bluetooth_check"));
+    bluetooth_allow_write_check = GTK_WIDGET (gtk_builder_get_object (builder, "allow_write_bluetooth_check"));
+    require_pairing_check = GTK_WIDGET (gtk_builder_get_object (builder, "require_pairing_check"));
+    enable_obexpush_check = GTK_WIDGET (gtk_builder_get_object (builder, "enable_obexpush_check"));
+    accept_obexpush_combo = GTK_WIDGET (gtk_builder_get_object (builder, "accept_obexpush_combo"));
+    notify_received_obexpush_check = GTK_WIDGET (gtk_builder_get_object (builder, "notify_received_obexpush_check"));
+#endif /* HAVE_BLUETOOTH */
+
+    store = gtk_list_store_new (1, G_TYPE_STRING);
+    gtk_combo_box_set_model (GTK_COMBO_BOX (password_combo),
+			     GTK_TREE_MODEL (store));
+    cell = gtk_cell_renderer_text_new ();
+    gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (password_combo), cell, TRUE);
+    gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (password_combo), cell,
+				    "text", 0,
+				    NULL);
+
+    /* Keep in same order as enum */
+    gtk_list_store_append (store, &iter);
+    gtk_list_store_set (store, &iter, 0,
+			_("Never"), -1);
+    gtk_list_store_append (store, &iter);
+    gtk_list_store_set (store, &iter, 0,
+			_("When writing files"), -1);
+    gtk_list_store_append (store, &iter);
+    gtk_list_store_set (store, &iter, 0,
+			_("Always"), -1);
+    g_object_unref (store);
+
+    /* We can't read the password from the text, just set it to something */
+    gtk_entry_set_text (GTK_ENTRY (password_entry), "none");
+    g_object_set_data (G_OBJECT (password_entry),
+		       "user_edited", GINT_TO_POINTER (0));
+    g_signal_connect (password_entry,
+		      "changed", G_CALLBACK (password_entry_changed), NULL);
+
+#ifdef HAVE_BLUETOOTH
+    /* Accept files combo */
+    store = gtk_list_store_new (1, G_TYPE_STRING);
+    gtk_combo_box_set_model (GTK_COMBO_BOX (accept_obexpush_combo),
+			     GTK_TREE_MODEL (store));
+    cell = gtk_cell_renderer_text_new ();
+    gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (accept_obexpush_combo), cell, TRUE);
+    gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (accept_obexpush_combo), cell,
+				    "text", 0,
+				    NULL);
+
+    /* Keep in same order as enum */
+    gtk_list_store_append (store, &iter);
+    gtk_list_store_set (store, &iter, 0,
+			_("Always"), -1);
+    gtk_list_store_append (store, &iter);
+    gtk_list_store_set (store, &iter, 0,
+			_("Only for set up devices"), -1);
+    //FIXME implement
+#if 0
+    gtk_list_store_append (store, &iter);
+    gtk_list_store_set (store, &iter, 0,
+    			_("Ask"), -1);
+#endif
+    g_object_unref (store);
+#endif /* HAVE_BLUETOOTH */
+
+    g_signal_connect (check,
+		      "toggled", G_CALLBACK (enable_check_toggled), NULL);
+    g_signal_connect (password_combo,
+		      "changed", G_CALLBACK (password_combo_changed), NULL);
+#ifdef HAVE_BLUETOOTH
+    g_signal_connect (bluetooth_check,
+    		      "toggled", G_CALLBACK (enable_bluetooth_check_toggled), NULL);
+    g_signal_connect (bluetooth_allow_write_check,
+    		      "toggled", G_CALLBACK (bluetooth_allow_write_check_toggled), NULL);
+    g_signal_connect (require_pairing_check,
+    		      "toggled", G_CALLBACK (bluetooth_require_pairing_check_toggled), NULL);
+    g_signal_connect (enable_obexpush_check,
+    		      "toggled", G_CALLBACK (enable_obexpush_check_toggled), NULL);
+    g_signal_connect (accept_obexpush_combo,
+    		      "changed", G_CALLBACK (accept_obexpush_combo_changed), NULL);
+    g_signal_connect (notify_received_obexpush_check,
+    		      "toggled", G_CALLBACK (notify_received_obexpush_check_toggled), NULL);
+#endif /* HAVE_BLUETOOTH */
+
+    g_signal_connect_swapped (GTK_WIDGET (gtk_builder_get_object (builder, "close_button")),
+                              "clicked", G_CALLBACK (gtk_widget_destroy), window);
+    g_signal_connect (GTK_WIDGET (gtk_builder_get_object (builder, "help_button")),
+		      "clicked", G_CALLBACK (help_button_clicked),
+		      gtk_builder_get_object (builder, "user_share_dialog"));
+
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_ENABLED,
+			     G_CALLBACK (file_sharing_enabled_changed), NULL);
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_REQUIRE_PASSWORD,
+			     G_CALLBACK (password_required_changed), NULL);
+#ifdef HAVE_BLUETOOTH
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_ENABLED,
+			     G_CALLBACK (file_sharing_bluetooth_enabled_changed), NULL);
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_ALLOW_WRITE,
+			     G_CALLBACK (file_sharing_bluetooth_allow_write_changed), NULL);
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_REQUIRE_PAIRING,
+			     G_CALLBACK (file_sharing_bluetooth_require_pairing_changed), NULL);
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED,
+			     G_CALLBACK (file_sharing_bluetooth_obexpush_enabled_changed), NULL);
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_ACCEPT_FILES,
+			     G_CALLBACK (file_sharing_bluetooth_obexpush_accept_files_changed), NULL);
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_NOTIFY,
+			     G_CALLBACK (file_sharing_bluetooth_obexpush_notify_changed), NULL);
+#endif /* HAVE_BLUETOOTH */
+
+    update_ui ();
+
+    return window;
+}
+
+static void
+activate (GtkApplication *app)
+{
+    GList *list;
+    GtkWidget *window;
+
+    list = gtk_application_get_windows (app);
+
+    if (list) {
+        gtk_window_present (GTK_WINDOW (list->data));
+    } else {
+        window = create_window ();
+        gtk_window_set_application (GTK_WINDOW (window), app);
+        gtk_widget_show (window);
+    }
+}
+
+int
+main (int argc, char *argv[])
+{
+    GtkApplication *app;
+    gint status;
+
+    bindtextdomain (GETTEXT_PACKAGE, MATELOCALEDIR);
+    bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
+    textdomain (GETTEXT_PACKAGE);
+
+    app = gtk_application_new ("org.mate.user-share.properties",
+                               G_APPLICATION_FLAGS_NONE);
+    g_signal_connect (app, "activate", G_CALLBACK (activate), NULL);
+
+    status = g_application_run (G_APPLICATION (app), argc, argv);
+
+    g_object_unref (app);
+
+    return status;
+}
+
+
+
+
+ + + diff --git a/2022-02-13-194124-4467-cppcheck@b215c4400bb6_master/1.html b/2022-02-13-194124-4467-cppcheck@b215c4400bb6_master/1.html new file mode 100644 index 0000000..8e56153 --- /dev/null +++ b/2022-02-13-194124-4467-cppcheck@b215c4400bb6_master/1.html @@ -0,0 +1,1061 @@ + + + + + + Cppcheck - HTML report - mate-user-share + + + + + + +
+ +
+
  1
+  2
+  3
+  4
+  5
+  6
+  7
+  8
+  9
+ 10
+ 11
+ 12
+ 13
+ 14
+ 15
+ 16
+ 17
+ 18
+ 19
+ 20
+ 21
+ 22
+ 23
+ 24
+ 25
+ 26
+ 27
+ 28
+ 29
+ 30
+ 31
+ 32
+ 33
+ 34
+ 35
+ 36
+ 37
+ 38
+ 39
+ 40
+ 41
+ 42
+ 43
+ 44
+ 45
+ 46
+ 47
+ 48
+ 49
+ 50
+ 51
+ 52
+ 53
+ 54
+ 55
+ 56
+ 57
+ 58
+ 59
+ 60
+ 61
+ 62
+ 63
+ 64
+ 65
+ 66
+ 67
+ 68
+ 69
+ 70
+ 71
+ 72
+ 73
+ 74
+ 75
+ 76
+ 77
+ 78
+ 79
+ 80
+ 81
+ 82
+ 83
+ 84
+ 85
+ 86
+ 87
+ 88
+ 89
+ 90
+ 91
+ 92
+ 93
+ 94
+ 95
+ 96
+ 97
+ 98
+ 99
+100
+101
+102
+103
+104
+105
+106
+107
+108
+109
+110
+111
+112
+113
+114
+115
+116
+117
+118
+119
+120
+121
+122
+123
+124
+125
+126
+127
+128
+129
+130
+131
+132
+133
+134
+135
+136
+137
+138
+139
+140
+141
+142
+143
+144
+145
+146
+147
+148
+149
+150
+151
+152
+153
+154
+155
+156
+157
+158
+159
+160
+161
+162
+163
+164
+165
+166
+167
+168
+169
+170
+171
+172
+173
+174
+175
+176
+177
+178
+179
+180
+181
+182
+183
+184
+185
+186
+187
+188
+189
+190
+191
+192
+193
+194
+195
+196
+197
+198
+199
+200
+201
+202
+203
+204
+205
+206
+207
+208
+209
+210
+211
+212
+213
+214
+215
+216
+217
+218
+219
+220
+221
+222
+223
+224
+225
+226
+227
+228
+229
+230
+231
+232
+233
+234
+235
+236
+237
+238
+239
+240
+241
+242
+243
+244
+245
+246
+247
+248
+249
+250
+251
+252
+253
+254
+255
+256
+257
+258
+259
+260
+261
+262
+263
+264
+265
+266
+267
+268
+269
+270
+271
+272
+273
+274
+275
+276
+277
+278
+279
+280
+281
+282
+283
+284
+285
+286
+287
+288
+289
+290
+291
+292
+293
+294
+295
+296
+297
+298
+299
+300
+301
+302
+303
+304
+305
+306
+307
+308
+309
+310
+311
+312
+313
+314
+315
+316
+317
+318
+319
+320
+321
+322
+323
+324
+325
+326
+327
+328
+329
+330
+331
+332
+333
+334
+335
+336
+337
+338
+339
+340
+341
+342
+343
+344
+345
+346
+347
+348
+349
+350
+351
+352
+353
+354
+355
+356
+357
+358
+359
+360
+361
+362
+363
+364
+365
+366
+367
+368
+369
+370
+371
+372
+373
+374
+375
+376
+377
+378
+379
+380
+381
+382
+383
+384
+385
+386
+387
+388
+389
+390
+391
+392
+393
+394
+395
+396
+397
+398
+399
+400
+401
+402
+403
+404
+405
+406
+407
+408
+409
+410
+411
+412
+413
+414
+415
+416
+417
+418
+419
+420
+421
+422
+423
+424
+425
+426
+427
+428
+429
+430
+431
+432
+433
+434
+435
+436
+437
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
+
+/*
+ *  Copyright (C) 2004-2008 Red Hat, Inc.
+ * Copyright (C) 2012-2021 MATE Developers
+ *
+ *  Caja is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU General Public License as
+ *  published by the Free Software Foundation; either version 2 of the
+ *  License, or (at your option) any later version.
+ *
+ *  Caja is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  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
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ *  Authors: Alexander Larsson <alexl@redhat.com>
+ *
+ */
+
+#include "config.h"
+
+#include <glib.h>
+#include <glib/gi18n.h>
+#include <X11/Xlib.h>
+
+#include <gio/gio.h>
+
+#include <stdarg.h>
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <signal.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <sys/stat.h>
+
+#ifdef HAVE_SELINUX
+#include <selinux/selinux.h>
+#endif
+
+#include "user_share-common.h"
+#include "user_share-private.h"
+#include "http.h"
+
+/* From avahi-common/domain.h */
+#define AVAHI_LABEL_MAX 64
+
+#define GSETTINGS_SCHEMA "org.mate.FileSharing"
+
+static pid_t httpd_pid = 0;
+
+static int
+get_port (void)
+{
+	int sock;
+	struct sockaddr_in addr;
+	int reuse;
+	socklen_t len;
+
+	sock = socket (PF_INET, SOCK_STREAM, 0);
+	if (sock < 0) {
+		return -1;
+	}
+
+	memset (&addr, 0, sizeof (addr));
+	addr.sin_port = 0;
+	addr.sin_addr.s_addr = INADDR_ANY;
+	addr.sin_family = AF_INET;
+
+	reuse = 1;
+	setsockopt (sock, SOL_SOCKET, SO_REUSEADDR, &reuse, sizeof (reuse));
+	if (bind (sock, (struct sockaddr *)&addr, sizeof (addr)) == -1) {
+		close (sock);
+		return -1;
+	}
+
+	len = sizeof (addr);
+	if (getsockname (sock, (struct sockaddr *)&addr, &len) == -1) {
+		close (sock);
+		return -1;
+	}
+
+#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__APPLE__) || defined(__OpenBSD__)
+	/* XXX This exposes a potential race condition, but without this,
+	 * httpd will not start on the above listed platforms due to the fact
+	 * that SO_REUSEADDR is also needed when Apache binds to the listening
+	 * socket.  At this time, Apache does not support that socket option.
+	 */
+	close (sock);
+#endif
+	return ntohs (addr.sin_port);
+}
+
+static char *
+truncate_name (const char *name)
+{
+	const char *end;
+
+	end = g_utf8_find_prev_char (name, name + 64);
+	g_assert (end != NULL);
+	return g_strndup (name, end - name);
+}
+
+static char *
+get_share_name (void)
+{
+	static char *name = NULL;
+	const char *host_name;
+	char *str;
+
+	if (name == NULL) {
+		host_name = g_get_host_name ();
+		if (strcmp (host_name, "localhost") == 0) {
+			/* Translators: The %s will get filled in with the user name
+			   of the user, to form a genitive. If this is difficult to
+			   translate correctly so that it will work correctly in your
+			   language, you may use something equivalent to
+			   "Public files of %s", or leave out the %s altogether.
+			   In the latter case, please put "%.0s" somewhere in the string,
+			   which will match the user name string passed by the C code,
+			   but not put the user name in the final string. This is to
+			   avoid the warning that msgfmt might otherwise generate. */
+			name = g_strdup_printf (_("%s's public files"), g_get_user_name ());
+		} else {
+			/* Translators: This is similar to the string before, only it
+			   has the hostname in it too. */
+			name = g_strdup_printf (_("%s's public files on %s"),
+						g_get_user_name (),
+						host_name);
+		}
+
+	}
+	/* And truncate */
+	if (strlen (name) < AVAHI_LABEL_MAX)
+		return name;
+
+	str = truncate_name (name);
+	g_free (name);
+	name = str;
+
+	return name;
+}
+
+static void
+ensure_conf_dir (void)
+{
+	char *dirname;
+
+	dirname = g_build_filename (g_get_user_config_dir (), "user-share", NULL);
+	g_mkdir_with_parents (dirname, 0755);
+	g_free (dirname);
+}
+
+static void
+httpd_child_setup (gpointer user_data)
+{
+#ifdef HAVE_SELINUX
+	char *mycon;
+	/* If selinux is enabled, avoid transitioning to the httpd_t context,
+	   as this normally means you can't read the users homedir. */
+	if (is_selinux_enabled()) {
+		if (getcon (&mycon) < 0) {
+			abort ();
+		}
+		if (setexeccon (mycon) < 0)
+			abort ();
+		freecon (mycon);
+	}
+#endif
+}
+
+static const char *known_httpd_locations [] = {
+	HTTPD_PROGRAM,
+	"/usr/sbin/httpd",
+	"/usr/sbin/httpd2",
+	"/usr/sbin/apache2",
+	NULL
+};
+
+static char*
+get_httpd_program (void)
+{
+	int i;
+
+	for (i = 0; known_httpd_locations[i]; i++) {
+		if (known_httpd_locations[i][0] == '\0') {
+			/* empty string as first element, happens when
+			 * configured --with-httpd=auto */
+			continue;
+		}
+		if (g_file_test (known_httpd_locations[i], G_FILE_TEST_IS_EXECUTABLE)
+				&& ! g_file_test (known_httpd_locations[i], G_FILE_TEST_IS_DIR)) {
+			return g_strdup (known_httpd_locations[i]);
+		}
+	}
+	return NULL;
+}
+
+static const char *known_httpd_modules_locations [] = {
+	HTTPD_MODULES_PATH,
+	"/etc/httpd/modules",
+	"/usr/lib/apache2/modules",
+	NULL
+};
+
+static gchar*
+get_httpd_modules_path (void)
+{
+	int i;
+
+	for (i = 0; known_httpd_modules_locations[i]; i++) {
+		if (known_httpd_modules_locations[i][0] == '\0') {
+			/* empty string as first element, happens when
+			 * configured --with-httpd=auto */
+			continue;
+		}
+		if (g_file_test (known_httpd_modules_locations[i], G_FILE_TEST_IS_EXECUTABLE)
+				&& g_file_test (known_httpd_modules_locations[i], G_FILE_TEST_IS_DIR)) {
+			return g_strdup (known_httpd_modules_locations[i]);
+		}
+	}
+	return NULL;
+}
+
+static GRegex *version_regex = NULL;
+
+static char*
+get_httpd_config (const char *httpd_program)
+{
+	gchar *standard_output;
+	gchar *cmd_line;
+	GMatchInfo *match_info;
+	gchar *version_number = NULL;
+	gchar *config;
+
+	cmd_line = g_strdup_printf ("%s -v", httpd_program);
+	if (! g_spawn_command_line_sync (cmd_line, &standard_output, NULL, NULL, NULL)) {
+		g_free (cmd_line);
+		return NULL;
+	}
+	g_free (cmd_line);
+
+	if (version_regex == NULL) {
+		version_regex = g_regex_new ("\\d\\.\\d", 0, 0, NULL);
+	}
+
+	if (g_regex_match (version_regex, standard_output, 0, &match_info)) {
+		while (g_match_info_matches (match_info)) {
+			version_number = g_match_info_fetch (match_info, 0);
+			break;
+		}
+		g_match_info_free (match_info);
+		g_free (standard_output);
+	} else {
+		/* Failed to parse httpd version number */
+		g_warning ("Could not parse '%s' as a version for httpd", standard_output);
+		g_free (standard_output);
+		/* assume it is 2.2 */
+		version_number = g_strdup ("2.2");
+	}
+
+	config = g_strdup_printf (HTTPD_CONFIG_TEMPLATE, version_number);
+	g_free (version_number);
+
+	return config;
+}
+
+static gboolean
+spawn_httpd (int port, pid_t *pid_out)
+{
+	char *free1, *free2, *free3, *free4, *free5, *free6, *free7, *free8, *free9;
+	gboolean res;
+	char *argv[10];
+	char *env[10];
+	int i;
+	gint status;
+	char *pid_filename;
+	char *pidfile;
+	GError *error;
+	gboolean got_pidfile;
+	GSettings *settings;
+	char *str;
+	char *public_dir;
+
+	public_dir = lookup_public_dir ();
+	ensure_conf_dir ();
+
+	i = 0;
+	free1 = argv[i++] = get_httpd_program ();
+	if (argv[0] == NULL) {
+		fprintf (stderr, "error finding httpd server\n");
+		return FALSE;
+	}
+
+	argv[i++] = "-f";
+	free2 = argv[i++] = get_httpd_config (argv[0]);
+	argv[i++] = "-C";
+	free3 = argv[i++] = g_strdup_printf ("Listen %d", port);
+
+	settings = g_settings_new (GSETTINGS_SCHEMA);
+	str = g_settings_get_string (settings,
+				       FILE_SHARING_REQUIRE_PASSWORD);
+
+	if (str && strcmp (str, "never") == 0) {
+		/* Do nothing */
+	} else if (str && strcmp (str, "on_write") == 0){
+		argv[i++] = "-D";
+		argv[i++] = "RequirePasswordOnWrite";
+	} else {
+		/* always, or safe fallback */
+		argv[i++] = "-D";
+		argv[i++] = "RequirePasswordAlways";
+	}
+	g_free (str);
+	g_object_unref (settings);
+
+	argv[i] = NULL;
+
+	i = 0;
+	free4 = env[i++] = g_strdup_printf ("HOME=%s", g_get_home_dir());
+	free5 = env[i++] = g_strdup_printf ("XDG_PUBLICSHARE_DIR=%s", public_dir);
+	free6 = env[i++] = g_strdup_printf ("XDG_CONFIG_HOME=%s", g_get_user_config_dir ());
+	free7 = env[i++] = g_strdup_printf ("GUS_SHARE_NAME=%s", get_share_name ());
+	free8 = env[i++] = g_strdup_printf ("GUS_LOGIN_LABEL=%s", "Please log in as the user guest");
+	free9 = env[i++] = g_strdup_printf ("HTTP_MODULES_PATH=%s",get_httpd_modules_path ());
+	env[i++] = "LANG=C";
+	env[i] = NULL;
+
+	pid_filename = g_build_filename (g_get_user_config_dir (), "user-share", "pid", NULL);
+
+	/* Remove pid file before spawning to avoid races with child and old pidfile */
+	unlink (pid_filename);
+
+	error = NULL;
+	res = g_spawn_sync (g_get_home_dir(),
+			    argv, env, 0,
+			    httpd_child_setup, NULL,
+			    NULL, NULL,
+			    &status,
+			    &error);
+	g_free (free1);
+	g_free (free2);
+	g_free (free3);
+	g_free (free4);
+	g_free (free5);
+	g_free (free6);
+	g_free (free7);
+	g_free (free8);
+	g_free (free9);
+	g_free (public_dir);
+
+	if (!res) {
+		fprintf (stderr, "error spawning httpd: %s\n",
+			 error->message);
+		g_error_free (error);
+		g_free (pid_filename);
+		return FALSE;
+	}
+
+	if (status != 0) {
+		g_free (pid_filename);
+		return FALSE;
+	}
+
+	got_pidfile = FALSE;
+	error = NULL;
+	for (i = 0; i < 5; i++) {
+		if (error != NULL)
+			g_error_free (error);
+		error = NULL;
+		if (g_file_get_contents (pid_filename, &pidfile, NULL, &error)) {
+			got_pidfile = TRUE;
+			*pid_out = atoi (pidfile);
+			g_free (pidfile);
+			break;
+		}
+		sleep (1);
+	}
+
+	g_free (pid_filename);
+
+	if (!got_pidfile) {
+		fprintf (stderr, "error opening httpd pidfile: %s\n", error->message);
+		g_error_free (error);
+		return FALSE;
+	}
+	return TRUE;
+}
+
+static void
+kill_httpd (void)
+{
+	if (httpd_pid != 0) {
+		kill (httpd_pid, SIGTERM);
+
+		/* Allow child time to die, we can't waitpid, because its
+		   not a direct child */
+		sleep (1);
+	}
+	httpd_pid = 0;
+}
+
+void
+http_up (void)
+{
+	guint port;
+
+	port = get_port ();
+	if (!spawn_httpd (port, &httpd_pid)) {
+		fprintf (stderr, "spawning httpd failed\n");
+	}
+}
+
+void
+http_down (void)
+{
+	kill_httpd ();
+}
+
+gboolean
+http_init (void)
+{
+	return TRUE;
+}
+
+pid_t
+http_get_pid (void)
+{
+	return httpd_pid;
+}
+
+
+
+
+ + + diff --git a/2022-02-13-194124-4467-cppcheck@b215c4400bb6_master/2.html b/2022-02-13-194124-4467-cppcheck@b215c4400bb6_master/2.html new file mode 100644 index 0000000..8d6e921 --- /dev/null +++ b/2022-02-13-194124-4467-cppcheck@b215c4400bb6_master/2.html @@ -0,0 +1,1295 @@ + + + + + + Cppcheck - HTML report - mate-user-share + + + + + + +
+ +
+
  1
+  2
+  3
+  4
+  5
+  6
+  7
+  8
+  9
+ 10
+ 11
+ 12
+ 13
+ 14
+ 15
+ 16
+ 17
+ 18
+ 19
+ 20
+ 21
+ 22
+ 23
+ 24
+ 25
+ 26
+ 27
+ 28
+ 29
+ 30
+ 31
+ 32
+ 33
+ 34
+ 35
+ 36
+ 37
+ 38
+ 39
+ 40
+ 41
+ 42
+ 43
+ 44
+ 45
+ 46
+ 47
+ 48
+ 49
+ 50
+ 51
+ 52
+ 53
+ 54
+ 55
+ 56
+ 57
+ 58
+ 59
+ 60
+ 61
+ 62
+ 63
+ 64
+ 65
+ 66
+ 67
+ 68
+ 69
+ 70
+ 71
+ 72
+ 73
+ 74
+ 75
+ 76
+ 77
+ 78
+ 79
+ 80
+ 81
+ 82
+ 83
+ 84
+ 85
+ 86
+ 87
+ 88
+ 89
+ 90
+ 91
+ 92
+ 93
+ 94
+ 95
+ 96
+ 97
+ 98
+ 99
+100
+101
+102
+103
+104
+105
+106
+107
+108
+109
+110
+111
+112
+113
+114
+115
+116
+117
+118
+119
+120
+121
+122
+123
+124
+125
+126
+127
+128
+129
+130
+131
+132
+133
+134
+135
+136
+137
+138
+139
+140
+141
+142
+143
+144
+145
+146
+147
+148
+149
+150
+151
+152
+153
+154
+155
+156
+157
+158
+159
+160
+161
+162
+163
+164
+165
+166
+167
+168
+169
+170
+171
+172
+173
+174
+175
+176
+177
+178
+179
+180
+181
+182
+183
+184
+185
+186
+187
+188
+189
+190
+191
+192
+193
+194
+195
+196
+197
+198
+199
+200
+201
+202
+203
+204
+205
+206
+207
+208
+209
+210
+211
+212
+213
+214
+215
+216
+217
+218
+219
+220
+221
+222
+223
+224
+225
+226
+227
+228
+229
+230
+231
+232
+233
+234
+235
+236
+237
+238
+239
+240
+241
+242
+243
+244
+245
+246
+247
+248
+249
+250
+251
+252
+253
+254
+255
+256
+257
+258
+259
+260
+261
+262
+263
+264
+265
+266
+267
+268
+269
+270
+271
+272
+273
+274
+275
+276
+277
+278
+279
+280
+281
+282
+283
+284
+285
+286
+287
+288
+289
+290
+291
+292
+293
+294
+295
+296
+297
+298
+299
+300
+301
+302
+303
+304
+305
+306
+307
+308
+309
+310
+311
+312
+313
+314
+315
+316
+317
+318
+319
+320
+321
+322
+323
+324
+325
+326
+327
+328
+329
+330
+331
+332
+333
+334
+335
+336
+337
+338
+339
+340
+341
+342
+343
+344
+345
+346
+347
+348
+349
+350
+351
+352
+353
+354
+355
+356
+357
+358
+359
+360
+361
+362
+363
+364
+365
+366
+367
+368
+369
+370
+371
+372
+373
+374
+375
+376
+377
+378
+379
+380
+381
+382
+383
+384
+385
+386
+387
+388
+389
+390
+391
+392
+393
+394
+395
+396
+397
+398
+399
+400
+401
+402
+403
+404
+405
+406
+407
+408
+409
+410
+411
+412
+413
+414
+415
+416
+417
+418
+419
+420
+421
+422
+423
+424
+425
+426
+427
+428
+429
+430
+431
+432
+433
+434
+435
+436
+437
+438
+439
+440
+441
+442
+443
+444
+445
+446
+447
+448
+449
+450
+451
+452
+453
+454
+455
+456
+457
+458
+459
+460
+461
+462
+463
+464
+465
+466
+467
+468
+469
+470
+471
+472
+473
+474
+475
+476
+477
+478
+479
+480
+481
+482
+483
+484
+485
+486
+487
+488
+489
+490
+491
+492
+493
+494
+495
+496
+497
+498
+499
+500
+501
+502
+503
+504
+505
+506
+507
+508
+509
+510
+511
+512
+513
+514
+515
+516
+517
+518
+519
+520
+521
+522
+523
+524
+525
+526
+527
+528
+529
+530
+531
+532
+533
+534
+535
+536
+537
+538
+539
+540
+541
+542
+543
+544
+545
+546
+547
+548
+549
+550
+551
+552
+553
+554
+555
+556
+557
+558
+559
+560
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
+
+/*
+ *  Copyright (C) 2004-2008 Red Hat, Inc.
+ *  Copyright (C) 2012-2021 MATE Developers
+ *
+ *  Caja is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU General Public License as
+ *  published by the Free Software Foundation; either version 2 of the
+ *  License, or (at your option) any later version.
+ *
+ *  Caja is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  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
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ *  Authors: Bastien Nocera <hadess@hadess.net>
+ *
+ */
+
+#include "config.h"
+
+#include <glib.h>
+#include <glib/gi18n.h>
+#include <gio/gio.h>
+#include <gdk/gdk.h>
+#include <gtk/gtk.h>
+#include <libnotify/notify.h>
+#include <dbus/dbus-glib.h>
+#include <dbus/dbus-glib-lowlevel.h>
+#include <canberra-gtk.h>
+
+#include <string.h>
+
+#include "marshal.h"
+#include "obexpush.h"
+#include "user_share-common.h"
+#include "user_share-private.h"
+
+#define DBUS_TYPE_G_STRING_VARIANT_HASHTABLE (dbus_g_type_get_map ("GHashTable", G_TYPE_STRING, G_TYPE_STRING))
+
+#define GSETTINGS_SCHEMA "org.mate.FileSharing"
+
+static DBusGConnection *connection = NULL;<--- Shadowed declaration
+static DBusGProxy *manager_proxy = NULL;
+static DBusGProxy *server_proxy = NULL;
+static AcceptSetting accept_setting = -1;
+static gboolean show_notifications = FALSE;
+
+static GtkStatusIcon *statusicon = NULL;
+static guint num_notifications = 0;
+
+static void
+hide_statusicon (void)
+{
+	num_notifications--;
+	if (num_notifications == 0)
+		gtk_status_icon_set_visible (statusicon, FALSE);
+}
+
+static void
+on_close_notification (NotifyNotification *notification)
+{
+	hide_statusicon ();
+	g_object_unref (notification);
+}
+
+static void
+notification_launch_action_on_file_cb (NotifyNotification *notification,
+				       const char *action,
+				       const char *file_uri)
+{
+	GdkScreen *screen;
+	GAppLaunchContext *ctx;
+	GTimeVal val;
+
+	g_assert (action != NULL);
+
+	g_get_current_time (&val);
+
+	ctx = G_APP_LAUNCH_CONTEXT (gdk_app_launch_context_new ());
+	screen = gdk_screen_get_default ();
+	gdk_app_launch_context_set_screen (GDK_APP_LAUNCH_CONTEXT (ctx), screen);
+	gdk_app_launch_context_set_timestamp (GDK_APP_LAUNCH_CONTEXT (ctx), val.tv_sec);
+
+	/* We launch the file viewer for the file */
+	if (g_str_equal (action, "display") != FALSE) {
+		if (g_app_info_launch_default_for_uri (file_uri, ctx, NULL) == FALSE) {
+			g_warning ("Failed to launch the file viewer\n");
+		}
+	}
+
+	/* we open the Downloads folder */
+	if (g_str_equal (action, "reveal") != FALSE) {
+		GFile *file;
+		GFile *parent;
+		gchar *parent_uri;
+
+		file = g_file_new_for_uri (file_uri);
+		parent = g_file_get_parent (file);
+		parent_uri = g_file_get_uri (parent);
+		g_object_unref (file);
+		g_object_unref (parent);
+
+		if (!g_app_info_launch_default_for_uri (parent_uri, ctx, NULL)) {
+			g_warning ("Failed to launch the file manager\n");
+		}
+
+		g_free (parent_uri);
+	}
+
+	notify_notification_close (notification, NULL);
+	/* No need to call hide_statusicon(), closing the notification
+	 * will call the close callback */
+}
+
+static void
+show_notification (const char *filename)
+{
+	char *file_uri, *notification_text, *display, *mime_type;
+	NotifyNotification *notification;
+	ca_context *ctx;
+	GAppInfo *app;
+
+	file_uri = g_filename_to_uri (filename, NULL, NULL);
+	if (file_uri == NULL) {
+		g_warning ("Could not make a filename from '%s'", filename);
+		return;
+	}
+
+	display = g_filename_display_basename (filename);
+	/* Translators: %s is the name of the filename received */
+	notification_text = g_strdup_printf(_("You received \"%s\" via Bluetooth"), display);
+	g_free (display);
+	notification = notify_notification_new (_("You received a file"),
+								 notification_text,
+								 "dialog-information");
+
+	notify_notification_set_timeout (notification, NOTIFY_EXPIRES_DEFAULT);
+
+	mime_type = g_content_type_guess (filename, NULL, 0, NULL);
+	app = g_app_info_get_default_for_type (mime_type, FALSE);
+	if (app != NULL) {
+		g_object_unref (app);
+		notify_notification_add_action (notification, "display", _("Open File"),
+						(NotifyActionCallback) notification_launch_action_on_file_cb,
+						g_strdup (file_uri), (GFreeFunc) g_free);
+	}
+	notify_notification_add_action (notification, "reveal", _("Reveal File"),
+					(NotifyActionCallback) notification_launch_action_on_file_cb,
+					g_strdup (file_uri), (GFreeFunc) g_free);
+
+	g_free (file_uri);
+
+	g_signal_connect (G_OBJECT (notification), "closed", G_CALLBACK (on_close_notification), notification);
+
+	if (!notify_notification_show (notification, NULL)) {
+		g_warning ("failed to send notification\n");
+	}
+	g_free (notification_text);
+
+	/* Now we do the audio notification */
+	ctx = ca_gtk_context_get ();
+	ca_context_play (ctx, 0,
+			 CA_PROP_EVENT_ID, "complete-download",
+			 CA_PROP_EVENT_DESCRIPTION, _("File reception complete"),
+			 NULL);
+}
+
+static void
+show_icon (void)
+{
+	if (statusicon == NULL) {
+		statusicon = gtk_status_icon_new_from_icon_name ("mate-obex-server");
+	} else {
+		gtk_status_icon_set_visible (statusicon, TRUE);
+	}
+	num_notifications++;
+}
+
+static gboolean
+device_is_authorised (const char *bdaddr)
+{
+	DBusGConnection *connection;<--- Shadow variable
+	DBusGProxy *manager;
+	GError *error = NULL;
+	GPtrArray *adapters;
+	gboolean retval = FALSE;
+	guint i;
+
+	connection = dbus_g_bus_get (DBUS_BUS_SYSTEM, NULL);
+	if (connection == NULL)
+		return FALSE;
+
+	manager = dbus_g_proxy_new_for_name (connection, "org.bluez",
+					     "/", "org.bluez.Manager");
+	if (manager == NULL) {
+		dbus_g_connection_unref (connection);
+		return FALSE;
+	}
+
+	if (dbus_g_proxy_call (manager, "ListAdapters", &error, G_TYPE_INVALID, dbus_g_type_get_collection ("GPtrArray", DBUS_TYPE_G_OBJECT_PATH), &adapters, G_TYPE_INVALID) == FALSE) {
+		g_object_unref (manager);
+		dbus_g_connection_unref (connection);
+		return FALSE;
+	}
+
+	for (i = 0; i < adapters->len; i++) {
+		DBusGProxy *adapter, *device;
+		char *device_path;
+		GHashTable *props;
+
+		g_debug ("checking adapter %s", (gchar *) g_ptr_array_index (adapters, i));
+
+		adapter = dbus_g_proxy_new_for_name (connection, "org.bluez",
+						    g_ptr_array_index (adapters, i), "org.bluez.Adapter");
+
+		if (dbus_g_proxy_call (adapter, "FindDevice", NULL,
+				       G_TYPE_STRING, bdaddr, G_TYPE_INVALID,
+				       DBUS_TYPE_G_OBJECT_PATH, &device_path, G_TYPE_INVALID) == FALSE)
+		{
+			g_object_unref (adapter);
+			continue;
+		}
+
+		device = dbus_g_proxy_new_for_name (connection, "org.bluez", device_path, "org.bluez.Device");
+
+		if (dbus_g_proxy_call (device, "GetProperties", NULL,
+				       G_TYPE_INVALID, dbus_g_type_get_map ("GHashTable", G_TYPE_STRING, G_TYPE_VALUE),
+				       &props, G_TYPE_INVALID) != FALSE)
+		{
+			GValue *value;
+			gboolean bonded;
+
+			value = g_hash_table_lookup (props, "Paired");
+			bonded = g_value_get_boolean (value);
+			g_message ("%s is %s", bdaddr, bonded ? "bonded" : "not bonded");
+
+			if (bonded) {
+				g_hash_table_destroy (props);
+				g_object_unref (device);
+				g_object_unref (adapter);
+				retval = TRUE;
+				break;
+			}
+		}
+		g_object_unref(adapter);
+	}
+
+	g_ptr_array_free (adapters, TRUE);
+
+	g_object_unref(manager);
+	dbus_g_connection_unref(connection);
+
+	return retval;
+}
+
+static void
+transfer_started_cb (DBusGProxy *session,
+		     const char *filename,
+		     const char *local_path,
+		     guint64 size,
+		     gpointer user_data)
+{
+	GHashTable *dict;
+	DBusGProxy *server = (DBusGProxy *) user_data;
+	GError *error = NULL;
+	gboolean authorise;
+
+	g_message ("transfer started on %s", local_path);
+	g_object_set_data_full (G_OBJECT (session), "filename", g_strdup (local_path), (GDestroyNotify) g_free);
+
+	show_icon ();
+
+	/* First transfer of the session */
+	if (g_object_get_data (G_OBJECT (session), "bdaddr") == NULL) {
+		const char *bdaddr;
+
+		if (dbus_g_proxy_call (server, "GetServerSessionInfo", &error,
+				       DBUS_TYPE_G_OBJECT_PATH, dbus_g_proxy_get_path (session), G_TYPE_INVALID,
+				       DBUS_TYPE_G_STRING_VARIANT_HASHTABLE, &dict, G_TYPE_INVALID) == FALSE) {
+			g_printerr ("Getting Server session info failed: %s\n",
+				    error->message);
+			g_error_free (error);
+			return;
+		}
+
+		bdaddr = g_hash_table_lookup (dict, "BluetoothAddress");
+		g_message ("transfer started for device %s", bdaddr);
+
+		g_object_set_data_full (G_OBJECT (session), "bdaddr", g_strdup (bdaddr), (GDestroyNotify) g_free);
+		/* Initial accept method is undefined, we do that lower down */
+		g_object_set_data (G_OBJECT (session), "accept-method", GINT_TO_POINTER (-1));
+		g_hash_table_destroy (dict);
+	}
+
+	/* Accept method changed */
+	if (GPOINTER_TO_INT (g_object_get_data (G_OBJECT (session), "accept-method")) != accept_setting) {
+		const char *bdaddr;
+
+		bdaddr = g_object_get_data (G_OBJECT (session), "bdaddr");
+
+		if (bdaddr == NULL) {
+			g_warning ("Couldn't get the Bluetooth address for the device, rejecting the transfer");
+			authorise = FALSE;
+		} else if (accept_setting == ACCEPT_ALWAYS) {
+			authorise = TRUE;
+		} else if (accept_setting == ACCEPT_BONDED) {
+			authorise = device_is_authorised (bdaddr);
+		} else {
+			//FIXME implement
+			g_warning ("\"Ask\" authorisation method not implemented");
+			authorise = FALSE;
+		}
+		g_object_set_data (G_OBJECT (session), "authorise", GINT_TO_POINTER (authorise));
+	}
+
+	g_message ("accept_setting: %d", accept_setting);
+
+	authorise = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (session), "authorise"));
+	if (authorise != FALSE) {
+		if (dbus_g_proxy_call (session, "Accept", &error, G_TYPE_INVALID, G_TYPE_INVALID) == FALSE) {
+			g_printerr ("Failed to accept file transfer: %s\n", error->message);
+			g_error_free (error);
+			return;
+		}
+		g_message ("authorised transfer");
+	} else {
+		if (dbus_g_proxy_call (session, "Reject", &error, G_TYPE_INVALID, G_TYPE_INVALID) == FALSE) {
+			g_printerr ("Failed to reject file transfer: %s\n", error->message);
+			g_error_free (error);
+			return;
+		}
+		g_message ("rejected transfer");
+		g_object_set_data (G_OBJECT (session), "filename", NULL);
+	}
+}
+
+static void
+transfer_completed_cb (DBusGProxy *session,
+		       gpointer user_data)
+{
+	GSettings *settings;
+	gboolean display_notify;
+	const char *filename;
+
+	filename = (const char *) g_object_get_data (G_OBJECT (session), "filename");
+
+	g_message ("file finish transfer: %s", filename);
+
+	if (filename == NULL)
+		return;
+
+	settings = g_settings_new (GSETTINGS_SCHEMA);
+	display_notify = g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_OBEXPUSH_NOTIFY);
+	g_object_unref (settings);
+
+	if (display_notify) {
+		show_notification (filename);
+	} else {
+		hide_statusicon ();
+	}
+	g_object_set_data (G_OBJECT (session), "filename", NULL);
+}
+
+static void
+cancelled_cb (DBusGProxy *session,
+	      gpointer user_data)
+{
+	//FIXME implement properly, we never actually finished the transfer
+	g_message ("transfered was cancelled by the sender");
+	transfer_completed_cb (session, user_data);
+	hide_statusicon ();
+}
+
+static void
+error_occurred_cb (DBusGProxy *session,
+		   const char *error_name,
+		   const char *error_message,
+		   gpointer user_data)
+{
+	//FIXME implement properly
+	g_message ("transfer error occurred: %s", error_message);
+	transfer_completed_cb (session, user_data);
+}
+
+static void
+session_created_cb (DBusGProxy *server, const char *session_path, gpointer user_data)
+{
+	DBusGProxy *session;
+
+	session = dbus_g_proxy_new_for_name (connection,
+					     "org.openobex",
+					     session_path,
+					     "org.openobex.ServerSession");
+
+	dbus_g_proxy_add_signal (session, "TransferStarted",
+				 G_TYPE_STRING, G_TYPE_STRING, G_TYPE_UINT64, G_TYPE_INVALID);
+	dbus_g_proxy_connect_signal(session, "TransferStarted",
+				    G_CALLBACK (transfer_started_cb), server, NULL);
+	dbus_g_proxy_add_signal (session, "TransferCompleted",
+				 G_TYPE_INVALID, G_TYPE_INVALID);
+	dbus_g_proxy_connect_signal(session, "TransferCompleted",
+				    G_CALLBACK (transfer_completed_cb), server, NULL);
+	dbus_g_proxy_add_signal (session, "Cancelled",
+				 G_TYPE_INVALID, G_TYPE_INVALID);
+	dbus_g_proxy_connect_signal(session, "Cancelled",
+				    G_CALLBACK (cancelled_cb), server, NULL);
+	dbus_g_proxy_add_signal (session, "ErrorOccurred",
+				 G_TYPE_INVALID, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INVALID);
+	dbus_g_proxy_connect_signal(session, "ErrorOccurred",
+				    G_CALLBACK (error_occurred_cb), server, NULL);
+}
+
+void
+obexpush_up (void)
+{
+	GError *err = NULL;
+	char *download_dir, *server;
+
+	server = NULL;
+	if (manager_proxy == NULL) {
+		manager_proxy = dbus_g_proxy_new_for_name (connection,
+							   "org.openobex",
+							   "/org/openobex",
+							   "org.openobex.Manager");
+		if (dbus_g_proxy_call (manager_proxy, "CreateBluetoothServer",
+				       &err, G_TYPE_STRING, "00:00:00:00:00:00", G_TYPE_STRING, "opp", G_TYPE_BOOLEAN, FALSE, G_TYPE_INVALID,
+				       DBUS_TYPE_G_OBJECT_PATH, &server, G_TYPE_INVALID) == FALSE) {
+			g_printerr ("Creating Bluetooth ObexPush server failed: %s\n",
+				    err->message);
+			g_error_free (err);
+			g_object_unref (manager_proxy);
+			manager_proxy = NULL;
+			return;
+		}
+	}
+
+	download_dir = lookup_download_dir ();
+
+	if (server_proxy == NULL) {
+		server_proxy = dbus_g_proxy_new_for_name (connection,
+							   "org.openobex",
+							   server,
+							   "org.openobex.Server");
+		g_free (server);
+
+		dbus_g_proxy_add_signal (server_proxy, "SessionCreated",
+					 DBUS_TYPE_G_OBJECT_PATH, G_TYPE_INVALID);
+		dbus_g_proxy_connect_signal(server_proxy, "SessionCreated",
+					    G_CALLBACK (session_created_cb), NULL, NULL);
+	}
+
+	if (dbus_g_proxy_call (server_proxy, "Start", &err,
+			   G_TYPE_STRING, download_dir, G_TYPE_BOOLEAN, TRUE, G_TYPE_BOOLEAN, FALSE, G_TYPE_INVALID,
+			   G_TYPE_INVALID) == FALSE) {
+		if (g_error_matches (err, DBUS_GERROR, DBUS_GERROR_REMOTE_EXCEPTION) != FALSE &&
+		    dbus_g_error_has_name (err, "org.openobex.Error.Started") != FALSE) {
+		    	g_error_free (err);
+		    	g_message ("already started, ignoring error");
+		    	g_free (download_dir);
+		    	return;
+		}
+		g_printerr ("Starting Bluetooth ObexPush server failed: %s\n",
+			    err->message);
+		g_error_free (err);
+		g_free (download_dir);
+		g_object_unref (server_proxy);
+		server_proxy = NULL;
+		g_object_unref (manager_proxy);
+		manager_proxy = NULL;
+		return;
+	}
+
+	g_free (download_dir);
+}
+
+static void
+obexpush_stop (gboolean stop_manager)
+{
+	GError *err = NULL;
+
+	if (server_proxy == NULL)
+		return;
+
+	if (dbus_g_proxy_call (server_proxy, "Close", &err, G_TYPE_INVALID, G_TYPE_INVALID) == FALSE) {
+		if (g_error_matches (err, DBUS_GERROR, DBUS_GERROR_REMOTE_EXCEPTION) == FALSE ||
+		    dbus_g_error_has_name (err, "org.openobex.Error.NotStarted") == FALSE) {
+			g_printerr ("Stopping Bluetooth ObexPush server failed: %s\n",
+				    err->message);
+			g_error_free (err);
+			return;
+		}
+		g_error_free (err);
+	}
+
+	if (stop_manager != FALSE) {
+		g_object_unref (server_proxy);
+		server_proxy = NULL;
+		g_object_unref (manager_proxy);
+		manager_proxy = NULL;
+	}
+
+	//FIXME stop all the notifications
+}
+
+void
+obexpush_down (void)
+{
+	obexpush_stop (TRUE);
+}
+
+void
+obexpush_restart (void)
+{
+	obexpush_stop (FALSE);
+	obexpush_up ();
+}
+
+gboolean
+obexpush_init (void)
+{
+	GError *err = NULL;
+
+	connection = dbus_g_bus_get (DBUS_BUS_SESSION, &err);
+	if (connection == NULL) {
+		g_printerr ("Connecting to session bus failed: %s\n",
+			    err->message);
+		g_error_free (err);
+		return FALSE;
+	}
+
+	dbus_g_object_register_marshaller (marshal_VOID__STRING_STRING_UINT64,
+					   G_TYPE_NONE,
+					   G_TYPE_STRING, G_TYPE_STRING, G_TYPE_UINT64, G_TYPE_INVALID);
+
+	if (!notify_init("mate-user-share")) {
+		g_warning("Unable to initialize the notification system\n");
+        }
+
+	dbus_connection_set_exit_on_disconnect (dbus_g_connection_get_connection (connection), FALSE);
+
+	return TRUE;
+}
+
+void
+obexpush_set_accept_files_policy (AcceptSetting setting)
+{
+	accept_setting = setting;
+}
+
+void
+obexpush_set_notify (gboolean enabled)
+{
+	show_notifications = enabled;
+}
+
+
+
+
+ + + diff --git a/2022-02-13-194124-4467-cppcheck@b215c4400bb6_master/3.html b/2022-02-13-194124-4467-cppcheck@b215c4400bb6_master/3.html new file mode 100644 index 0000000..13adc8a --- /dev/null +++ b/2022-02-13-194124-4467-cppcheck@b215c4400bb6_master/3.html @@ -0,0 +1,771 @@ + + + + + + Cppcheck - HTML report - mate-user-share + + + + + + +
+ +
+
  1
+  2
+  3
+  4
+  5
+  6
+  7
+  8
+  9
+ 10
+ 11
+ 12
+ 13
+ 14
+ 15
+ 16
+ 17
+ 18
+ 19
+ 20
+ 21
+ 22
+ 23
+ 24
+ 25
+ 26
+ 27
+ 28
+ 29
+ 30
+ 31
+ 32
+ 33
+ 34
+ 35
+ 36
+ 37
+ 38
+ 39
+ 40
+ 41
+ 42
+ 43
+ 44
+ 45
+ 46
+ 47
+ 48
+ 49
+ 50
+ 51
+ 52
+ 53
+ 54
+ 55
+ 56
+ 57
+ 58
+ 59
+ 60
+ 61
+ 62
+ 63
+ 64
+ 65
+ 66
+ 67
+ 68
+ 69
+ 70
+ 71
+ 72
+ 73
+ 74
+ 75
+ 76
+ 77
+ 78
+ 79
+ 80
+ 81
+ 82
+ 83
+ 84
+ 85
+ 86
+ 87
+ 88
+ 89
+ 90
+ 91
+ 92
+ 93
+ 94
+ 95
+ 96
+ 97
+ 98
+ 99
+100
+101
+102
+103
+104
+105
+106
+107
+108
+109
+110
+111
+112
+113
+114
+115
+116
+117
+118
+119
+120
+121
+122
+123
+124
+125
+126
+127
+128
+129
+130
+131
+132
+133
+134
+135
+136
+137
+138
+139
+140
+141
+142
+143
+144
+145
+146
+147
+148
+149
+150
+151
+152
+153
+154
+155
+156
+157
+158
+159
+160
+161
+162
+163
+164
+165
+166
+167
+168
+169
+170
+171
+172
+173
+174
+175
+176
+177
+178
+179
+180
+181
+182
+183
+184
+185
+186
+187
+188
+189
+190
+191
+192
+193
+194
+195
+196
+197
+198
+199
+200
+201
+202
+203
+204
+205
+206
+207
+208
+209
+210
+211
+212
+213
+214
+215
+216
+217
+218
+219
+220
+221
+222
+223
+224
+225
+226
+227
+228
+229
+230
+231
+232
+233
+234
+235
+236
+237
+238
+239
+240
+241
+242
+243
+244
+245
+246
+247
+248
+249
+250
+251
+252
+253
+254
+255
+256
+257
+258
+259
+260
+261
+262
+263
+264
+265
+266
+267
+268
+269
+270
+271
+272
+273
+274
+275
+276
+277
+278
+279
+280
+281
+282
+283
+284
+285
+286
+287
+288
+289
+290
+291
+292
/* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 8; tab-width: 8 -*-
+ *
+ * Copyright (C) 2003 Novell, Inc.
+ * Copyright (C) 2003-2004 Red Hat, Inc.
+ * Copyright (C) 2005 William Jon McCann <mccann@jhu.edu>
+ * Copyright (C) 2012-2021 MATE Developers
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * 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 Foundation, Inc., 51 Franklin St, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ *
+ */
+
+#include "config.h"
+
+#include <stdlib.h>
+#include <string.h>
+#include <glib/gi18n-lib.h>
+#include <gtk/gtk.h>
+#include <libcaja-extension/caja-menu-provider.h>
+#include <libcaja-extension/caja-location-widget-provider.h>
+
+#ifdef HAVE_BLUETOOTH
+#include <bluetooth-client.h>
+#endif
+
+#include "caja-share-bar.h"
+#include "user_share-common.h"
+
+#define CAJA_TYPE_USER_SHARE  (caja_user_share_get_type ())
+#define CAJA_USER_SHARE(o)    (G_TYPE_CHECK_INSTANCE_CAST ((o), CAJA_TYPE_USER_SHARE, CajaUserShare))
+#define CAJA_IS_USER_SHARE(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), CAJA_TYPE_USER_SHARE))
+
+typedef struct
+{
+        GObject              parent_slot;
+} CajaUserShare;
+
+typedef struct
+{
+        GObjectClass parent_slot;
+} CajaUserShareClass;
+
+static GType caja_user_share_get_type      (void);
+static void  caja_user_share_register_type (GTypeModule *module);
+
+static void
+launch_process (char **argv, GtkWindow *parent)
+{
+        GError *error;
+        GtkWidget *dialog;
+
+        error = NULL;
+        if (!g_spawn_async (NULL,
+                            argv, NULL,
+                            0,
+                            NULL, NULL,
+                            NULL,
+                            &error)) {
+
+
+                dialog = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL, GTK_MESSAGE_WARNING,
+						 GTK_BUTTONS_OK, _("Unable to launch the Personal File Sharing preferences"));
+
+                gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog), "%s", error->message);
+
+                gtk_dialog_run (GTK_DIALOG (dialog));
+                gtk_widget_destroy (dialog);
+
+                g_error_free (error);
+        }
+}
+
+static void
+launch_prefs_on_window (GtkWindow *window)
+{
+        char *argv [2];
+
+        argv [0] = g_build_filename (BINDIR, "mate-file-share-properties", NULL);
+        argv [1] = NULL;
+
+        launch_process (argv, window);
+
+        g_free (argv [0]);
+}
+
+static void
+bar_response_cb (CajaShareBar *bar,
+                 gint response,
+                 gpointer         data)
+{
+        if (response == CAJA_SHARE_BAR_RESPONSE_PREFERENCES) {
+                launch_prefs_on_window (GTK_WINDOW (data));
+        }
+}
+
+#ifdef HAVE_BLUETOOTH
+static void
+downloads_bar_set_from_bluetooth_status (GtkWidget *bar)
+{
+	BluetoothClient *client;
+	gboolean bt_powered;
+
+	client = g_object_get_data (G_OBJECT (bar), "bluetooth-client");
+	g_object_get (G_OBJECT (client),
+		      "default-adapter-powered", &bt_powered,
+		      NULL);
+	gtk_widget_set_visible (bar, bt_powered);
+}
+
+static void
+default_adapter_powered_cb (GObject    *gobject,
+			    GParamSpec *pspec,
+			    GtkWidget  *bar)
+{
+	downloads_bar_set_from_bluetooth_status (bar);
+}
+#endif /* HAVE_BLUETOOTH */
+
+static GtkWidget *
+caja_user_share_get_location_widget (CajaLocationWidgetProvider *iface,
+                                         const char                     *uri,
+                                         GtkWidget                      *window)
+{
+	GFile             *file;
+	GtkWidget         *bar;
+	guint              i;
+	gboolean           enable = FALSE;
+	GFile             *home;
+#ifdef HAVE_BLUETOOTH
+	const GUserDirectory special_dirs[] = { G_USER_DIRECTORY_PUBLIC_SHARE, G_USER_DIRECTORY_DOWNLOAD };
+
+	gboolean is_dir[] = { FALSE, FALSE };
+#else
+	const GUserDirectory special_dirs[] = { G_USER_DIRECTORY_PUBLIC_SHARE };
+
+	gboolean is_dir[] = { FALSE };
+#endif /* HAVE_BLUETOOTH */
+	file = g_file_new_for_uri (uri);
+	home = g_file_new_for_path (g_get_home_dir ());
+
+	/* We don't show anything in $HOME */
+	if (g_file_equal (home, file)) {
+		g_object_unref (home);
+		g_object_unref (file);
+		return NULL;
+	}
+
+	g_object_unref (home);
+
+	for (i = 0; i < G_N_ELEMENTS (special_dirs); i++) {
+		GFile *dir;
+		dir = lookup_dir_with_fallback (special_dirs[i]);
+		if (g_file_equal (dir, file)) {
+			enable = TRUE;
+			is_dir[i] = TRUE;
+		}
+		g_object_unref (dir);
+	}
+
+	g_object_unref (file);
+
+	if (enable == FALSE)
+		return NULL;
+
+	if (is_dir[0] != FALSE) {
+#ifdef HAVE_BLUETOOTH
+		if (is_dir[1] != FALSE) {
+			bar = caja_share_bar_new (_("May be used to share or receive files"));
+		} else {
+			bar = caja_share_bar_new (_("May be shared over the network or Bluetooth"));
+		}
+#else
+		bar = caja_share_bar_new (_("May be shared over the network"));
+#endif /* HAVE_BLUETOOTH */
+	} else {
+#ifdef HAVE_BLUETOOTH
+		BluetoothClient *client;
+
+		bar = caja_share_bar_new (_("May be used to receive files over Bluetooth"));
+
+		gtk_widget_set_no_show_all (bar, TRUE);
+		client = bluetooth_client_new ();
+		g_object_set_data_full (G_OBJECT (bar), "bluetooth-client", client, g_object_unref);
+		g_signal_connect (G_OBJECT (client), "notify::default-adapter-powered",
+				  G_CALLBACK (default_adapter_powered_cb), bar);
+		downloads_bar_set_from_bluetooth_status (bar);
+#endif /* HAVE_BLUETOOTH */
+	}
+
+	g_signal_connect (bar, "response",
+			  G_CALLBACK (bar_response_cb),
+			  window);
+
+	gtk_widget_show_all (bar);
+
+	return bar;
+}
+
+static void
+caja_user_share_location_widget_provider_iface_init (CajaLocationWidgetProviderIface *iface)
+{
+        iface->get_widget = caja_user_share_get_location_widget;
+}
+
+static void
+caja_user_share_instance_init (CajaUserShare *share)
+{
+
+}
+
+static void
+caja_user_share_class_init (CajaUserShareClass *klass)
+{
+
+}
+
+static GType share_type = 0;
+
+static GType
+caja_user_share_get_type (void)
+{
+        return share_type;
+}
+
+static void
+caja_user_share_register_type (GTypeModule *module)
+{
+        static const GTypeInfo info = {
+                sizeof (CajaUserShareClass),
+                (GBaseInitFunc) NULL,
+                (GBaseFinalizeFunc) NULL,
+                (GClassInitFunc) caja_user_share_class_init,
+                NULL,
+                NULL,
+                sizeof (CajaUserShare),
+                0,
+                (GInstanceInitFunc) caja_user_share_instance_init,
+        };
+
+        static const GInterfaceInfo location_widget_provider_iface_info = {
+                (GInterfaceInitFunc) caja_user_share_location_widget_provider_iface_init,
+                NULL,
+                NULL
+        };
+
+        share_type = g_type_module_register_type (module,
+                                                 G_TYPE_OBJECT,
+                                                 "CajaUserShare",
+                                                 &info, 0);
+
+        g_type_module_add_interface (module,
+                                     share_type,
+                                     CAJA_TYPE_LOCATION_WIDGET_PROVIDER,
+                                     &location_widget_provider_iface_info);
+}
+
+void
+caja_module_initialize (GTypeModule *module)
+{
+        caja_user_share_register_type (module);
+        bindtextdomain (GETTEXT_PACKAGE, MATELOCALEDIR);
+        bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
+}
+
+void
+caja_module_shutdown (void)
+{
+}
+
+void
+caja_module_list_types (const GType **types,
+                            int          *num_types)
+{
+        static GType type_list [1];
+
+        type_list[0] = CAJA_TYPE_USER_SHARE;
+
+        *types = type_list;
+        *num_types = 1;
+}
+
+
+
+
+ + + diff --git a/2022-02-13-194124-4467-cppcheck@b215c4400bb6_master/4.html b/2022-02-13-194124-4467-cppcheck@b215c4400bb6_master/4.html new file mode 100644 index 0000000..b89124d --- /dev/null +++ b/2022-02-13-194124-4467-cppcheck@b215c4400bb6_master/4.html @@ -0,0 +1,1189 @@ + + + + + + Cppcheck - HTML report - mate-user-share + + + + + + +
+ +
+
  1
+  2
+  3
+  4
+  5
+  6
+  7
+  8
+  9
+ 10
+ 11
+ 12
+ 13
+ 14
+ 15
+ 16
+ 17
+ 18
+ 19
+ 20
+ 21
+ 22
+ 23
+ 24
+ 25
+ 26
+ 27
+ 28
+ 29
+ 30
+ 31
+ 32
+ 33
+ 34
+ 35
+ 36
+ 37
+ 38
+ 39
+ 40
+ 41
+ 42
+ 43
+ 44
+ 45
+ 46
+ 47
+ 48
+ 49
+ 50
+ 51
+ 52
+ 53
+ 54
+ 55
+ 56
+ 57
+ 58
+ 59
+ 60
+ 61
+ 62
+ 63
+ 64
+ 65
+ 66
+ 67
+ 68
+ 69
+ 70
+ 71
+ 72
+ 73
+ 74
+ 75
+ 76
+ 77
+ 78
+ 79
+ 80
+ 81
+ 82
+ 83
+ 84
+ 85
+ 86
+ 87
+ 88
+ 89
+ 90
+ 91
+ 92
+ 93
+ 94
+ 95
+ 96
+ 97
+ 98
+ 99
+100
+101
+102
+103
+104
+105
+106
+107
+108
+109
+110
+111
+112
+113
+114
+115
+116
+117
+118
+119
+120
+121
+122
+123
+124
+125
+126
+127
+128
+129
+130
+131
+132
+133
+134
+135
+136
+137
+138
+139
+140
+141
+142
+143
+144
+145
+146
+147
+148
+149
+150
+151
+152
+153
+154
+155
+156
+157
+158
+159
+160
+161
+162
+163
+164
+165
+166
+167
+168
+169
+170
+171
+172
+173
+174
+175
+176
+177
+178
+179
+180
+181
+182
+183
+184
+185
+186
+187
+188
+189
+190
+191
+192
+193
+194
+195
+196
+197
+198
+199
+200
+201
+202
+203
+204
+205
+206
+207
+208
+209
+210
+211
+212
+213
+214
+215
+216
+217
+218
+219
+220
+221
+222
+223
+224
+225
+226
+227
+228
+229
+230
+231
+232
+233
+234
+235
+236
+237
+238
+239
+240
+241
+242
+243
+244
+245
+246
+247
+248
+249
+250
+251
+252
+253
+254
+255
+256
+257
+258
+259
+260
+261
+262
+263
+264
+265
+266
+267
+268
+269
+270
+271
+272
+273
+274
+275
+276
+277
+278
+279
+280
+281
+282
+283
+284
+285
+286
+287
+288
+289
+290
+291
+292
+293
+294
+295
+296
+297
+298
+299
+300
+301
+302
+303
+304
+305
+306
+307
+308
+309
+310
+311
+312
+313
+314
+315
+316
+317
+318
+319
+320
+321
+322
+323
+324
+325
+326
+327
+328
+329
+330
+331
+332
+333
+334
+335
+336
+337
+338
+339
+340
+341
+342
+343
+344
+345
+346
+347
+348
+349
+350
+351
+352
+353
+354
+355
+356
+357
+358
+359
+360
+361
+362
+363
+364
+365
+366
+367
+368
+369
+370
+371
+372
+373
+374
+375
+376
+377
+378
+379
+380
+381
+382
+383
+384
+385
+386
+387
+388
+389
+390
+391
+392
+393
+394
+395
+396
+397
+398
+399
+400
+401
+402
+403
+404
+405
+406
+407
+408
+409
+410
+411
+412
+413
+414
+415
+416
+417
+418
+419
+420
+421
+422
+423
+424
+425
+426
+427
+428
+429
+430
+431
+432
+433
+434
+435
+436
+437
+438
+439
+440
+441
+442
+443
+444
+445
+446
+447
+448
+449
+450
+451
+452
+453
+454
+455
+456
+457
+458
+459
+460
+461
+462
+463
+464
+465
+466
+467
+468
+469
+470
+471
+472
+473
+474
+475
+476
+477
+478
+479
+480
+481
+482
+483
+484
+485
+486
+487
+488
+489
+490
+491
+492
+493
+494
+495
+496
+497
+498
+499
+500
+501
+502
+503
+504
+505
+506
+507
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
+
+/*
+ *  Copyright (C) 2004-2008 Red Hat, Inc.
+ *  Copyright (C) 2012-2021 MATE Developers
+ *
+ *  Caja is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU General Public License as
+ *  published by the Free Software Foundation; either version 2 of the
+ *  License, or (at your option) any later version.
+ *
+ *  Caja is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  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
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ *  Authors: Alexander Larsson <alexl@redhat.com>
+ *
+ */
+
+#include "config.h"
+
+#include <gdk/gdkx.h>
+#include <gtk/gtk.h>
+#include <glib/gi18n.h>
+#include <glib/gstdio.h>
+#include <gio/gio.h>
+#include <X11/Xlib.h>
+
+#include "user_share-private.h"
+#include "user_share-common.h"
+#include "http.h"
+
+#ifdef HAVE_BLUETOOTH
+#include <bluetooth-client.h>
+
+#include "obexftp.h"
+#include "obexpush.h"
+
+#endif /* HAVE_BLUETOOTH */
+
+#include <gio/gio.h>
+
+#include <stdarg.h>
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <signal.h>
+#include <unistd.h>
+
+static guint disabled_timeout_tag = 0;
+static GSettings* settings;<--- Shadowed declaration<--- Shadowed declaration<--- Shadowed declaration
+
+#define GSETTINGS_SCHEMA "org.mate.FileSharing"
+#define GSETTINGS_KEY_FILE_SHARING_ENABLED "enabled"
+#define GSETTINGS_KEY_FILE_SHARING_REQUIRE_PASSWORD "require-password"
+
+#ifdef HAVE_BLUETOOTH
+/* MATE Session */
+#define MATE_SESSION_DBUS_NAME      "org.gnome.SessionManager"
+#define MATE_SESSION_DBUS_OBJECT    "/org/gnome/SessionManager"
+#define MATE_SESSION_DBUS_INTERFACE "org.gnome.SessionManager"
+
+static GDBusProxy *session_proxy = NULL;
+static gboolean has_console = TRUE;
+
+static BluetoothClient *client = NULL;
+static gboolean bluetoothd_enabled = FALSE;
+
+#define OBEX_ENABLED (bluetoothd_enabled && has_console)
+
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_ENABLED "bluetooth-enabled"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_ALLOW_WRITE "bluetooth-allow-write"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_REQUIRE_PAIRING "bluetooth-require-pairing"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED "bluetooth-obexpush-enabled"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_ACCEPT_FILES "bluetooth-accept-files"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_NOTIFY "bluetooth-notify"
+
+
+static void
+obex_services_start (void)
+{
+	GSettings *settings;<--- Shadow variable
+
+	if (bluetoothd_enabled == FALSE ||
+	    has_console == FALSE)
+	    	return;
+
+	settings = g_settings_new(GSETTINGS_SCHEMA);
+
+	if (g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED) == TRUE) {
+	    obexpush_up ();
+	}
+	if (g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_ENABLED) == TRUE) {
+	    obexftp_up ();
+	}
+
+	g_object_unref (client);
+}
+
+static void
+obex_services_shutdown (void)
+{
+	obexpush_down ();
+	obexftp_down ();
+}
+
+static void
+session_properties_changed_cb (GDBusProxy      *session,
+			       GVariant        *changed,
+			       char           **invalidated,
+			       gpointer         user_data)
+{
+	GVariant *v;
+
+	v = g_variant_lookup_value (changed, "SessionIsActive", G_VARIANT_TYPE_BOOLEAN);
+	if (v) {
+		has_console = g_variant_get_boolean (v);
+		g_debug ("Received session is active change: now %s", has_console ? "active" : "inactive");
+
+		if (has_console)
+			obex_services_start ();
+		else
+			obex_services_shutdown ();
+
+		g_variant_unref (v);
+	}
+}
+
+static gboolean
+is_session_active (void)
+{
+	GVariant *variant;
+	gboolean is_session_active = FALSE;
+
+	variant = g_dbus_proxy_get_cached_property (session_proxy,
+						    "SessionIsActive");
+	if (variant) {
+		is_session_active = g_variant_get_boolean (variant);
+		g_variant_unref (variant);
+ 	}
+
+	return is_session_active;
+}
+
+static void
+session_init (void)
+{
+	GError *error = NULL;
+
+	session_proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION,
+						       G_DBUS_PROXY_FLAGS_NONE,
+						       NULL,
+						       MATE_SESSION_DBUS_NAME,
+						       MATE_SESSION_DBUS_OBJECT,
+						       MATE_SESSION_DBUS_INTERFACE,
+						       NULL,
+						       &error);
+	if (session_proxy == NULL) {
+		g_warning ("Failed to get session proxy: %s", error->message);
+		g_error_free (error);
+		return;
+	}
+	g_signal_connect (session_proxy, "g-properties-changed",
+			  G_CALLBACK (session_properties_changed_cb),
+			  NULL);
+	has_console = is_session_active ();
+}
+
+static void
+default_adapter_changed (GObject    *gobject,<--- Parameter 'gobject' can be declared with const
+			 GParamSpec *pspec,
+			 gpointer    user_data)
+{
+	char *adapter;
+	gboolean adapter_powered;
+
+	g_object_get (G_OBJECT (client),
+		      "default-adapter", &adapter,
+		      "default-adapter-powered", &adapter_powered,
+		      NULL);
+	if (adapter != NULL && *adapter != '\0') {
+		bluetoothd_enabled = adapter_powered;
+	} else {
+		bluetoothd_enabled = FALSE;
+	}
+
+	/* Were we called as init, or as a callback */
+	if (gobject != NULL) {
+		if (bluetoothd_enabled != FALSE)
+			obex_services_start ();
+		else
+			obex_services_shutdown ();
+	}
+}
+
+static void
+bluez_init (void)
+{
+	client = bluetooth_client_new ();
+	default_adapter_changed (NULL, NULL, NULL);
+	g_signal_connect (G_OBJECT (client), "notify::default-adapter",
+			  G_CALLBACK (default_adapter_changed), NULL);
+	g_signal_connect (G_OBJECT (client), "notify::default-adapter-powered",
+			  G_CALLBACK (default_adapter_changed), NULL);
+}
+#endif /* HAVE_BLUETOOTH */
+
+static gboolean
+file_sharing_enabled (void)
+{
+	gboolean enabled = TRUE;
+	settings = g_settings_new (GSETTINGS_SCHEMA);
+
+#ifdef HAVE_BLUETOOTH
+	if (g_settings_get_boolean (settings, FILE_SHARING_ENABLED) == FALSE &&
+	    g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_ENABLED) == FALSE &&
+	    g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED) == FALSE)
+#else /* HAVE_BLUETOOTH */
+	if (g_settings_get_boolean (settings, FILE_SHARING_ENABLED) == FALSE)
+#endif /* HAVE_BLUETOOTH */
+		enabled = FALSE;
+
+	g_object_unref (settings);
+
+	return enabled;
+}
+
+static void
+migrate_old_configuration (void)
+{
+	const char *old_config_dir;
+	const char *new_config_dir;
+
+	old_config_dir = g_build_filename (g_get_home_dir (), ".mate2", "user-share", NULL);
+	new_config_dir = g_build_filename (g_get_user_config_dir (), "user-share", NULL);
+	if (g_file_test (old_config_dir, G_FILE_TEST_IS_DIR))
+		g_rename (old_config_dir, new_config_dir);
+
+}
+
+static void
+require_password_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	/* Need to restart to get new password setting */
+	if (http_get_pid () != 0) {
+		http_down ();
+		http_up ();
+	}
+}
+
+/* File sharing was disabled for some time, exit now */
+/* If we re-enable it in the ui, this will be restarted anyway */
+static gboolean
+disabled_timeout_callback (gpointer user_data)
+{
+	GSettings *settings = (GSettings *) user_data;<--- Shadow variable
+	http_down ();
+
+#ifdef HAVE_BLUETOOTH
+	if (g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_ENABLED) == FALSE &&
+	    g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED) == FALSE)
+		_exit (0);
+#else /* HAVE_BLUETOOTH */
+	if (g_settings_get_boolean (settings, FILE_SHARING_ENABLED) == FALSE)
+		_exit (0);
+#endif /* HAVE_BLUETOOTH */
+	return FALSE;
+}
+
+static void
+file_sharing_enabled_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	gboolean enabled;
+
+	if (disabled_timeout_tag != 0) {
+		g_source_remove (disabled_timeout_tag);
+		disabled_timeout_tag = 0;
+	}
+
+	enabled = g_settings_get_boolean (settings,
+					 FILE_SHARING_ENABLED);
+	if (enabled) {
+		if (http_get_pid () == 0) {
+			http_up ();
+		}
+	} else {
+		http_down ();
+		disabled_timeout_tag = g_timeout_add_seconds (3,
+							      (GSourceFunc)disabled_timeout_callback,
+							      settings);
+	}
+}
+
+#ifdef HAVE_BLUETOOTH
+static void
+file_sharing_bluetooth_allow_write_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	if (g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_ENABLED) != FALSE)
+		obexftp_restart ();
+}
+
+static void
+file_sharing_bluetooth_require_pairing_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	if (g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_ENABLED) != FALSE) {
+		/* We need to fully reset the session,
+		 * otherwise the new setting isn't taken into account */
+		obexftp_down ();
+		obexftp_up ();
+	}
+}
+
+static void
+file_sharing_bluetooth_enabled_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	if (g_settings_get_boolean (settings,
+				   FILE_SHARING_BLUETOOTH_ENABLED) == FALSE) {
+		obexftp_down ();
+		if (g_settings_get_boolean (settings, FILE_SHARING_ENABLED) == FALSE &&
+		    g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED) == FALSE) {
+			_exit (0);
+		}
+	} else if (OBEX_ENABLED) {
+		obexftp_up ();
+	}
+}
+
+static void
+file_sharing_bluetooth_obexpush_enabled_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	if (g_settings_get_boolean (settings,
+				   FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED) == FALSE) {
+		obexpush_down ();
+		if (g_settings_get_boolean (settings, FILE_SHARING_ENABLED) == FALSE &&
+		    g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_ENABLED) == FALSE) {
+			_exit (0);
+		}
+	} else if (OBEX_ENABLED) {
+		obexpush_up ();
+	}
+}
+
+static void
+file_sharing_bluetooth_obexpush_accept_files_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	AcceptSetting setting;
+	char *str;
+
+	str = g_settings_get_string (settings, FILE_SHARING_BLUETOOTH_OBEXPUSH_ACCEPT_FILES);
+	setting = accept_setting_from_string (str);
+	g_free (str);
+
+	obexpush_set_accept_files_policy (setting);
+}
+
+static void
+file_sharing_bluetooth_obexpush_notify_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	obexpush_set_notify (g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_OBEXPUSH_NOTIFY));
+}
+#endif /* HAVE_BLUETOOTH */
+
+static RETSIGTYPE
+cleanup_handler (int sig)
+{
+	http_down ();
+#ifdef HAVE_BLUETOOTH
+	obexftp_down ();
+	obexpush_down ();
+#endif /* HAVE_BLUETOOTH */
+	_exit (2);
+}
+
+static int
+x_io_error_handler (Display *xdisplay)
+{
+	http_down ();
+#ifdef HAVE_BLUETOOTH
+	obexftp_down ();
+#endif /* HAVE_BLUETOOTH */
+	_exit (2);
+}
+
+int
+main (int argc, char **argv)
+{
+	GSettings *settings;<--- Shadow variable
+	Display *xdisplay;
+	G_GNUC_UNUSED int x_fd;
+	Window selection_owner;
+	Atom xatom;
+
+	bindtextdomain (GETTEXT_PACKAGE, MATELOCALEDIR);
+	bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
+	textdomain (GETTEXT_PACKAGE);
+
+	gtk_init (&argc, &argv);
+
+	if (g_strcmp0 (g_get_real_name (), "root") == 0) {
+		g_warning ("mate-user-share cannot be started as root for security reasons.");
+		return 1;
+	}
+
+	signal (SIGPIPE, SIG_IGN);
+	signal (SIGINT, cleanup_handler);
+	signal (SIGHUP, cleanup_handler);
+	signal (SIGTERM, cleanup_handler);
+
+	xdisplay = GDK_DISPLAY_XDISPLAY (gdk_display_get_default ());
+	if (xdisplay == NULL) {
+		g_warning ("Can't open display");
+		return 1;
+	}
+
+	xatom = XInternAtom (xdisplay, "_MATE_USER_SHARE", FALSE);
+	selection_owner = XGetSelectionOwner (xdisplay, xatom);
+
+	if (selection_owner != None) {
+		/* There is an owner already, quit */
+		return 1;
+	}
+
+	selection_owner = XCreateSimpleWindow (xdisplay,
+					       RootWindow (xdisplay, 0),
+					       0, 0, 1, 1,
+					       0, 0, 0);
+	XSetSelectionOwner (xdisplay, xatom, selection_owner, CurrentTime);
+
+	if (XGetSelectionOwner (xdisplay, xatom) != selection_owner) {
+		/* Didn't get the selection */
+		return 1;
+	}
+
+	migrate_old_configuration ();
+
+	if (!file_sharing_enabled ())
+		return 1;
+
+	settings = g_settings_new (GSETTINGS_SCHEMA);
+
+	x_fd = ConnectionNumber (xdisplay);
+	XSetIOErrorHandler (x_io_error_handler);
+
+	if (http_init () == FALSE)
+		return 1;
+#ifdef HAVE_BLUETOOTH
+	if (obexftp_init () == FALSE)
+		return 1;
+	if (obexpush_init () == FALSE)
+		return 1;
+#endif /* HAVE_BLUETOOTH */
+
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_ENABLED,
+			     G_CALLBACK (file_sharing_enabled_changed), NULL);
+
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_REQUIRE_PASSWORD,
+			     G_CALLBACK (require_password_changed), NULL);
+
+#ifdef HAVE_BLUETOOTH
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_ENABLED,
+			     G_CALLBACK (file_sharing_bluetooth_enabled_changed), NULL);
+
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_ALLOW_WRITE,
+			     G_CALLBACK (file_sharing_bluetooth_allow_write_changed), NULL);
+
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_REQUIRE_PAIRING,
+			     G_CALLBACK (file_sharing_bluetooth_require_pairing_changed), NULL);
+
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED,
+			     G_CALLBACK (file_sharing_bluetooth_obexpush_enabled_changed), NULL);
+
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_ACCEPT_FILES,
+			     G_CALLBACK (file_sharing_bluetooth_obexpush_accept_files_changed), NULL);
+
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_NOTIFY,
+			     G_CALLBACK (file_sharing_bluetooth_obexpush_notify_changed), NULL);
+
+	bluez_init ();
+	session_init ();
+#endif /* HAVE_BLUETOOTH */
+
+	/* Initial setting */
+	file_sharing_enabled_changed (settings, NULL, NULL);
+#ifdef HAVE_BLUETOOTH
+	file_sharing_bluetooth_enabled_changed (settings, NULL, NULL);
+	file_sharing_bluetooth_obexpush_accept_files_changed (settings, NULL, NULL);
+	file_sharing_bluetooth_obexpush_notify_changed (settings, NULL, NULL);
+	file_sharing_bluetooth_obexpush_enabled_changed (settings, NULL, NULL);
+#endif /* HAVE_BLUETOOTH */
+
+	gtk_main ();
+
+	return 0;
+}
+
+
+
+
+ + + diff --git a/2022-02-13-194124-4467-cppcheck@b215c4400bb6_master/index.html b/2022-02-13-194124-4467-cppcheck@b215c4400bb6_master/index.html new file mode 100644 index 0000000..142ce17 --- /dev/null +++ b/2022-02-13-194124-4467-cppcheck@b215c4400bb6_master/index.html @@ -0,0 +1,143 @@ + + + + + + Cppcheck - HTML report - mate-user-share + + + + + + +
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
LineIdCWESeverityMessage
missingIncludeinformationCppcheck cannot find all the include files (use --check-config for details)
src/file-share-properties.c
83variableScope398styleThe scope of the variable 'password' can be reduced.
98shadowVariable398styleLocal variable 'settings' shadows outer variable
106unusedVariable563styleUnused variable: accept_setting
250shadowVariable398styleLocal variable 'settings' shadows outer variable
274shadowVariable398styleLocal variable 'settings' shadows outer variable
295shadowVariable398styleLocal variable 'settings' shadows outer variable
324shadowVariable398styleLocal variable 'settings' shadows outer variable
341shadowVariable398styleLocal variable 'settings' shadows outer variable
358shadowVariable398styleLocal variable 'settings' shadows outer variable
378shadowVariable398styleLocal variable 'settings' shadows outer variable
394shadowVariable398styleLocal variable 'settings' shadows outer variable
458shadowVariable398styleLocal variable 'settings' shadows outer variable
621variableScope398styleThe scope of the variable 'window' can be reduced.
src/http.c
115variableScope398styleThe scope of the variable 'host_name' can be reduced.
src/obexpush.c
188shadowVariable398styleLocal variable 'connection' shadows outer variable
src/share-extension.c
62variableScope398styleThe scope of the variable 'dialog' can be reduced.
src/user_share.c
87shadowVariable398styleLocal variable 'settings' shadows outer variable
175constParameter398styleParameter 'gobject' can be declared with const
261shadowVariable398styleLocal variable 'settings' shadows outer variable
392shadowVariable398styleLocal variable 'settings' shadows outer variable
+
+
+ + + diff --git a/2022-02-13-194124-4467-cppcheck@b215c4400bb6_master/stats.html b/2022-02-13-194124-4467-cppcheck@b215c4400bb6_master/stats.html new file mode 100644 index 0000000..0bf7c20 --- /dev/null +++ b/2022-02-13-194124-4467-cppcheck@b215c4400bb6_master/stats.html @@ -0,0 +1,109 @@ + + + + + + Cppcheck - HTML report - mate-user-share + + + + + + +
+ +
+

Top 10 files for style severity, total findings: 20
+   13  src/file-share-properties.c
+   4   src/user_share.c
+   1   src/share-extension.c
+   1   src/obexpush.c
+   1   src/http.c
+

+ +
+
+ + + diff --git a/2022-02-13-194124-4467-cppcheck@b215c4400bb6_master/style.css b/2022-02-13-194124-4467-cppcheck@b215c4400bb6_master/style.css new file mode 100644 index 0000000..07125f4 --- /dev/null +++ b/2022-02-13-194124-4467-cppcheck@b215c4400bb6_master/style.css @@ -0,0 +1,137 @@ + +body { + font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif; + font-size: 13px; + line-height: 1.5; + margin: 0; + width: auto; +} + +h1 { + margin: 10px; +} + +.header { + border-bottom: thin solid #aaa; +} + +.footer { + border-top: thin solid #aaa; + font-size: 90%; + margin-top: 5px; +} + +.footer ul { + list-style-type: none; + padding-left: 0; +} + +.footer > p { + margin: 4px; +} + +.wrapper { + display: -webkit-box; + display: -ms-flexbox; + display: flex; + -webkit-box-pack: justify; + -ms-flex-pack: justify; + justify-content: space-between; +} + +#menu, +#menu_index { + text-align: left; + width: 350px; + height: 90vh; + min-height: 200px; + overflow: auto; + position: -webkit-sticky; + position: sticky; + top: 0; + padding: 0 15px 15px 15px; +} + +#menu > a { + display: block; + margin-left: 10px; + font-size: 12px; + z-index: 1; +} + +#content, +#content_index { + background-color: #fff; + -webkit-box-sizing: content-box; + -moz-box-sizing: content-box; + box-sizing: content-box; + padding: 0 15px 15px 15px; + width: calc(100% - 350px); + height: 100%; + overflow-x: auto; +} + +#filename { + margin-left: 10px; + font-size: 12px; + z-index: 1; +} + +.error { + background-color: #ffb7b7; +} + +.error2 { + background-color: #faa; + display: inline-block; + margin-left: 4px; +} + +.inconclusive { + background-color: #b6b6b4; +} + +.inconclusive2 { + background-color: #b6b6b4; + display: inline-block; + margin-left: 4px; +} + +.verbose { + display: inline-block; + vertical-align: top; + cursor: help; +} + +.verbose .content { + display: none; + position: absolute; + padding: 10px; + margin: 4px; + max-width: 40%; + white-space: pre-wrap; + border: 1px solid #000; + background-color: #ffffcc; + cursor: auto; +} + +.highlight .hll { + padding: 1px; +} + +.highlighttable { + background-color: #fff; + z-index: 10; + position: relative; + margin: -10px; +} + +.linenos { + border-right: thin solid #aaa; + color: #d3d3d3; + padding-right: 6px; +} + +.d-none { + display: none; +} diff --git a/2022-10-29-134846-0734-cppcheck@fcf648868871_master/0.html b/2022-10-29-134846-0734-cppcheck@fcf648868871_master/0.html new file mode 100644 index 0000000..7a4ab90 --- /dev/null +++ b/2022-10-29-134846-0734-cppcheck@fcf648868871_master/0.html @@ -0,0 +1,1567 @@ + + + + + + Cppcheck - HTML report - mate-user-share + + + + + +
+ + + +
+
  1
+  2
+  3
+  4
+  5
+  6
+  7
+  8
+  9
+ 10
+ 11
+ 12
+ 13
+ 14
+ 15
+ 16
+ 17
+ 18
+ 19
+ 20
+ 21
+ 22
+ 23
+ 24
+ 25
+ 26
+ 27
+ 28
+ 29
+ 30
+ 31
+ 32
+ 33
+ 34
+ 35
+ 36
+ 37
+ 38
+ 39
+ 40
+ 41
+ 42
+ 43
+ 44
+ 45
+ 46
+ 47
+ 48
+ 49
+ 50
+ 51
+ 52
+ 53
+ 54
+ 55
+ 56
+ 57
+ 58
+ 59
+ 60
+ 61
+ 62
+ 63
+ 64
+ 65
+ 66
+ 67
+ 68
+ 69
+ 70
+ 71
+ 72
+ 73
+ 74
+ 75
+ 76
+ 77
+ 78
+ 79
+ 80
+ 81
+ 82
+ 83
+ 84
+ 85
+ 86
+ 87
+ 88
+ 89
+ 90
+ 91
+ 92
+ 93
+ 94
+ 95
+ 96
+ 97
+ 98
+ 99
+100
+101
+102
+103
+104
+105
+106
+107
+108
+109
+110
+111
+112
+113
+114
+115
+116
+117
+118
+119
+120
+121
+122
+123
+124
+125
+126
+127
+128
+129
+130
+131
+132
+133
+134
+135
+136
+137
+138
+139
+140
+141
+142
+143
+144
+145
+146
+147
+148
+149
+150
+151
+152
+153
+154
+155
+156
+157
+158
+159
+160
+161
+162
+163
+164
+165
+166
+167
+168
+169
+170
+171
+172
+173
+174
+175
+176
+177
+178
+179
+180
+181
+182
+183
+184
+185
+186
+187
+188
+189
+190
+191
+192
+193
+194
+195
+196
+197
+198
+199
+200
+201
+202
+203
+204
+205
+206
+207
+208
+209
+210
+211
+212
+213
+214
+215
+216
+217
+218
+219
+220
+221
+222
+223
+224
+225
+226
+227
+228
+229
+230
+231
+232
+233
+234
+235
+236
+237
+238
+239
+240
+241
+242
+243
+244
+245
+246
+247
+248
+249
+250
+251
+252
+253
+254
+255
+256
+257
+258
+259
+260
+261
+262
+263
+264
+265
+266
+267
+268
+269
+270
+271
+272
+273
+274
+275
+276
+277
+278
+279
+280
+281
+282
+283
+284
+285
+286
+287
+288
+289
+290
+291
+292
+293
+294
+295
+296
+297
+298
+299
+300
+301
+302
+303
+304
+305
+306
+307
+308
+309
+310
+311
+312
+313
+314
+315
+316
+317
+318
+319
+320
+321
+322
+323
+324
+325
+326
+327
+328
+329
+330
+331
+332
+333
+334
+335
+336
+337
+338
+339
+340
+341
+342
+343
+344
+345
+346
+347
+348
+349
+350
+351
+352
+353
+354
+355
+356
+357
+358
+359
+360
+361
+362
+363
+364
+365
+366
+367
+368
+369
+370
+371
+372
+373
+374
+375
+376
+377
+378
+379
+380
+381
+382
+383
+384
+385
+386
+387
+388
+389
+390
+391
+392
+393
+394
+395
+396
+397
+398
+399
+400
+401
+402
+403
+404
+405
+406
+407
+408
+409
+410
+411
+412
+413
+414
+415
+416
+417
+418
+419
+420
+421
+422
+423
+424
+425
+426
+427
+428
+429
+430
+431
+432
+433
+434
+435
+436
+437
+438
+439
+440
+441
+442
+443
+444
+445
+446
+447
+448
+449
+450
+451
+452
+453
+454
+455
+456
+457
+458
+459
+460
+461
+462
+463
+464
+465
+466
+467
+468
+469
+470
+471
+472
+473
+474
+475
+476
+477
+478
+479
+480
+481
+482
+483
+484
+485
+486
+487
+488
+489
+490
+491
+492
+493
+494
+495
+496
+497
+498
+499
+500
+501
+502
+503
+504
+505
+506
+507
+508
+509
+510
+511
+512
+513
+514
+515
+516
+517
+518
+519
+520
+521
+522
+523
+524
+525
+526
+527
+528
+529
+530
+531
+532
+533
+534
+535
+536
+537
+538
+539
+540
+541
+542
+543
+544
+545
+546
+547
+548
+549
+550
+551
+552
+553
+554
+555
+556
+557
+558
+559
+560
+561
+562
+563
+564
+565
+566
+567
+568
+569
+570
+571
+572
+573
+574
+575
+576
+577
+578
+579
+580
+581
+582
+583
+584
+585
+586
+587
+588
+589
+590
+591
+592
+593
+594
+595
+596
+597
+598
+599
+600
+601
+602
+603
+604
+605
+606
+607
+608
+609
+610
+611
+612
+613
+614
+615
+616
+617
+618
+619
+620
+621
+622
+623
+624
+625
+626
+627
+628
+629
+630
+631
+632
+633
+634
+635
+636
+637
+638
+639
+640
+641
+642
+643
+644
+645
+646
+647
+648
+649
+650
+651
+652
+653
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
+
+/*
+ *  Copyright (C) 2004 Red Hat, Inc.
+ * Copyright (C) 2012-2021 MATE Developers
+ *
+ *  Caja is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU General Public License as
+ *  published by the Free Software Foundation; either version 2 of the
+ *  License, or (at your option) any later version.
+ *
+ *  Caja is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  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
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ *  Authors: Alexander Larsson <alexl@redhat.com>
+ *
+ */
+
+#include "config.h"
+
+#include <string.h>
+#include <stdio.h>
+
+#include <gtk/gtk.h>
+#include <glib/gi18n.h>
+#include <gio/gio.h>
+
+#include "user_share-private.h"
+
+#define REALM "Please log in as the user guest"
+#define USER "guest"
+#define GSETTINGS_SCHEMA "org.mate.FileSharing"
+#define GSETTINGS_KEY_FILE_SHARING_ENABLED "enabled"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_ENABLED "bluetooth-enabled"
+#define GSETTINGS_KEY_FILE_SHARING_REQUIRE_PASSWORD "require-password"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_ALLOW_WRITE "bluetooth-allow-write"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_REQUIRE_PAIRING "bluetooth-require-pairing"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED "bluetooth-obexpush-enabled"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_ACCEPT_FILES "bluetooth-accept-files"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_NOTIFY "bluetooth-notify"
+
+static GtkBuilder* builder;
+static GSettings* settings;
+
+
+static void
+write_out_password (const char *password)
+{
+    char *to_hash;
+    char *ascii_digest;
+    char *line;
+    char *filename;
+    FILE *file;
+
+    to_hash = g_strdup_printf ("%s:%s:%s", USER, REALM, password);
+    ascii_digest = g_compute_checksum_for_string (G_CHECKSUM_MD5, to_hash, strlen (to_hash));
+    g_free (to_hash);
+    line = g_strdup_printf ("%s:%s:%s\n", USER, REALM, ascii_digest);
+    g_free (ascii_digest);
+
+    filename = g_build_filename (g_get_user_config_dir (), "user-share", "passwd", NULL);
+
+    file = fopen (filename, "w");
+    if (file != NULL) {
+	fwrite (line, strlen (line), 1, file);
+	fclose (file);
+    }
+
+    g_free (filename);
+    g_free (line);
+}
+
+static void
+flush_password (void)
+{
+    GtkWidget *password_entry;
+    const char *password;
+
+    password_entry = GTK_WIDGET (gtk_builder_get_object (builder, "password_entry"));
+
+    if (g_object_get_data (G_OBJECT( password_entry), "user_edited")) {
+	password = gtk_entry_get_text (GTK_ENTRY (password_entry));
+	if (password != NULL && password[0] != 0)
+	    write_out_password (password);
+    }
+}
+
+
+static void
+update_ui (void)
+{
+    GSettings *settings;
+    gboolean enabled;
+#ifdef HAVE_BLUETOOTH
+    gboolean bluetooth_enabled, bluetooth_write_enabled, require_pairing_enabled;
+    gboolean bluetooth_obexpush_enabled, bluetooth_obexpush_notify;
+#endif /* HAVE_BLUETOOTH */
+    char *str;
+    PasswordSetting password_setting;
+    AcceptSetting accept_setting;<--- Unused variable: accept_setting
+    GtkWidget *check;
+    GtkWidget *password_combo;
+    GtkWidget *password_entry;
+#ifdef HAVE_BLUETOOTH
+    GtkWidget *vbox_share_bluetooth;
+    GtkWidget *vbox_receive_bluetooth;
+    GtkWidget *bluetooth_check;
+    GtkWidget *allow_write_bluetooth_check;
+    GtkWidget *require_pairing_check;
+    GtkWidget *enable_obexpush_check;
+    GtkWidget *accept_obexpush_combo;
+    GtkWidget *notify_received_obexpush_check;
+#endif /* HAVE_BLUETOOTH */
+
+    settings = g_settings_new (GSETTINGS_SCHEMA);
+
+    enabled = g_settings_get_boolean (settings,
+				     FILE_SHARING_ENABLED);
+
+    str = g_settings_get_string (settings, FILE_SHARING_REQUIRE_PASSWORD);
+    password_setting = password_setting_from_string (str);
+    g_free (str);
+
+#ifdef HAVE_BLUETOOTH
+    bluetooth_enabled = g_settings_get_boolean (settings,
+    					       FILE_SHARING_BLUETOOTH_ENABLED);
+    bluetooth_write_enabled = g_settings_get_boolean (settings,
+						     FILE_SHARING_BLUETOOTH_ALLOW_WRITE);
+    require_pairing_enabled = g_settings_get_boolean (settings,
+    						     FILE_SHARING_BLUETOOTH_REQUIRE_PAIRING);
+    bluetooth_obexpush_enabled = g_settings_get_boolean (settings,
+    							FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED);
+    bluetooth_obexpush_notify = g_settings_get_boolean (settings,
+    						       FILE_SHARING_BLUETOOTH_OBEXPUSH_NOTIFY);
+
+    str = g_settings_get_string (settings, FILE_SHARING_BLUETOOTH_OBEXPUSH_ACCEPT_FILES);
+    accept_setting = accept_setting_from_string (str);
+    g_free (str);
+#endif /* HAVE_BLUETOOTH */
+
+    check = GTK_WIDGET (gtk_builder_get_object (builder, "enable_check"));
+    password_combo = GTK_WIDGET (gtk_builder_get_object (builder, "password_combo"));
+    password_entry = GTK_WIDGET (gtk_builder_get_object (builder, "password_entry"));
+#ifdef HAVE_BLUETOOTH
+    vbox_share_bluetooth = GTK_WIDGET (gtk_builder_get_object (builder, "vbox_share_bluetooth"));
+    vbox_receive_bluetooth = GTK_WIDGET (gtk_builder_get_object (builder, "vbox_receive_bluetooth"));
+    bluetooth_check = GTK_WIDGET (gtk_builder_get_object (builder, "enable_bluetooth_check"));
+    allow_write_bluetooth_check = GTK_WIDGET (gtk_builder_get_object (builder, "allow_write_bluetooth_check"));
+    require_pairing_check = GTK_WIDGET (gtk_builder_get_object (builder, "require_pairing_check"));
+    enable_obexpush_check = GTK_WIDGET (gtk_builder_get_object (builder, "enable_obexpush_check"));
+    accept_obexpush_combo = GTK_WIDGET (gtk_builder_get_object (builder, "accept_obexpush_combo"));
+    notify_received_obexpush_check = GTK_WIDGET (gtk_builder_get_object (builder, "notify_received_obexpush_check"));
+#endif /* HAVE_BLUETOOTH */
+
+    /* Network */
+    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (check), enabled);
+    gtk_widget_set_sensitive (password_combo, enabled);
+    gtk_widget_set_sensitive (password_entry, enabled && password_setting != PASSWORD_NEVER);
+
+    gtk_combo_box_set_active (GTK_COMBO_BOX (password_combo),
+			      password_setting);
+
+#ifdef HAVE_BLUETOOTH
+    /* Bluetooth ObexFTP */
+    gtk_widget_set_visible (vbox_share_bluetooth, TRUE);
+    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (bluetooth_check), bluetooth_enabled);
+    gtk_widget_set_sensitive (allow_write_bluetooth_check, bluetooth_enabled);
+    gtk_widget_set_sensitive (require_pairing_check, bluetooth_enabled);
+
+    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (allow_write_bluetooth_check),
+    				  bluetooth_write_enabled);
+    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (require_pairing_check),
+    				  require_pairing_enabled);
+
+    /* Bluetooth ObexPush */
+    gtk_widget_set_visible (vbox_receive_bluetooth, TRUE);
+    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (enable_obexpush_check), bluetooth_obexpush_enabled);
+    gtk_widget_set_sensitive (accept_obexpush_combo, bluetooth_obexpush_enabled);
+    gtk_widget_set_sensitive (notify_received_obexpush_check, bluetooth_obexpush_enabled);
+
+    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (notify_received_obexpush_check),
+    				  bluetooth_obexpush_notify);
+
+    gtk_combo_box_set_active (GTK_COMBO_BOX (accept_obexpush_combo),
+    			      accept_setting);
+#endif /* HAVE_BLUETOOTH */
+
+    g_object_unref (settings);
+}
+
+static void
+file_sharing_enabled_changed (GSettings *settings, gchar *key, gpointer data)
+{
+    update_ui ();
+}
+
+static void
+password_required_changed (GSettings *settings, gchar *key, gpointer data)
+{
+    update_ui ();
+}
+
+#ifdef HAVE_BLUETOOTH
+static void
+file_sharing_bluetooth_enabled_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	update_ui ();
+}
+
+static void
+file_sharing_bluetooth_allow_write_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	update_ui ();
+}
+
+static void
+file_sharing_bluetooth_require_pairing_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	update_ui ();
+}
+
+static void
+file_sharing_bluetooth_obexpush_enabled_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	update_ui ();
+}
+
+static void
+file_sharing_bluetooth_obexpush_accept_files_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	update_ui ();
+}
+
+static void
+file_sharing_bluetooth_obexpush_notify_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	update_ui ();
+}
+#endif /* HAVE_BLUETOOTH */
+
+static void
+password_combo_changed (GtkComboBox *combo_box)
+{
+    GSettings *settings;
+    guint setting;
+
+    setting = gtk_combo_box_get_active (combo_box);
+
+    settings = g_settings_new (GSETTINGS_SCHEMA) ;
+
+    g_settings_set_string (settings,
+			     FILE_SHARING_REQUIRE_PASSWORD,
+			     password_string_from_setting (setting));
+    g_object_unref (settings);
+}
+
+static void
+launch_share (void)
+{
+	if (!g_spawn_command_line_async (USER_SHARE_PROGRAM, NULL))
+		g_warning ("Unable to start mate-user-share program");
+}
+
+#ifdef HAVE_BLUETOOTH
+static void
+enable_bluetooth_check_toggled (GtkWidget *check)
+{
+	GSettings *settings;
+	gboolean enabled;
+
+	enabled = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check));
+
+	settings = g_settings_new (GSETTINGS_SCHEMA) ;
+
+	g_settings_set_boolean (settings,
+			       FILE_SHARING_BLUETOOTH_ENABLED,
+			       enabled);
+
+	g_object_unref (settings);
+
+	if (enabled != FALSE)
+		launch_share ();
+}
+#endif /* HAVE_BLUETOOTH */
+
+static void
+enable_check_toggled (GtkWidget *check)
+{
+	GSettings *settings;
+	gboolean enabled;
+
+	enabled = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check));
+
+	settings = g_settings_new (GSETTINGS_SCHEMA);
+
+	g_settings_set_boolean (settings,
+			       FILE_SHARING_ENABLED,
+			       enabled);
+
+	g_object_unref (settings);
+
+	if (enabled != FALSE)
+		launch_share ();
+}
+
+static void
+password_entry_changed (GtkEditable *editable)
+{
+	g_object_set_data (G_OBJECT (editable),
+			   "user_edited", GINT_TO_POINTER (1));
+	flush_password ();
+}
+
+#ifdef HAVE_BLUETOOTH
+static void
+bluetooth_allow_write_check_toggled (GtkWidget *check)
+{
+	GSettings *settings;
+	gboolean enabled;
+
+	enabled = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check));
+
+	settings = g_settings_new (GSETTINGS_SCHEMA) ;
+
+	g_settings_set_boolean (settings,
+			       FILE_SHARING_BLUETOOTH_ALLOW_WRITE,
+			       enabled);
+
+	g_object_unref (settings);
+}
+
+static void
+bluetooth_require_pairing_check_toggled (GtkWidget *check)
+{
+	GSettings *settings;
+	gboolean enabled;
+
+	enabled = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check));
+
+	settings = g_settings_new (GSETTINGS_SCHEMA) ;
+
+	g_settings_set_boolean (settings,
+			       FILE_SHARING_BLUETOOTH_REQUIRE_PAIRING,
+			       enabled);
+
+	g_object_unref (settings);
+}
+
+static void
+enable_obexpush_check_toggled (GtkWidget *check)
+{
+	GSettings *settings;
+	gboolean enabled;
+
+	enabled = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check));
+
+	settings = g_settings_new (GSETTINGS_SCHEMA) ;
+
+	g_settings_set_boolean (settings,
+			       FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED,
+			       enabled);
+
+	g_object_unref (settings);
+
+	if (enabled != FALSE)
+		launch_share ();
+}
+
+static void
+accept_obexpush_combo_changed (GtkComboBox *combo_box)
+{
+    GSettings *settings;
+    guint setting;
+
+    setting = gtk_combo_box_get_active (combo_box);
+
+    settings = g_settings_new (GSETTINGS_SCHEMA) ;
+
+    g_settings_set_string (settings,
+			     FILE_SHARING_BLUETOOTH_OBEXPUSH_ACCEPT_FILES,
+			     accept_string_from_setting (setting));
+    g_object_unref (settings);
+}
+
+static void
+notify_received_obexpush_check_toggled (GtkWidget *check)
+{
+	GSettings *settings;
+	gboolean enabled;
+
+	enabled = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check));
+
+	settings = g_settings_new (GSETTINGS_SCHEMA) ;
+
+	g_settings_set_boolean (settings,
+			       FILE_SHARING_BLUETOOTH_OBEXPUSH_NOTIFY,
+			       enabled);
+
+	g_object_unref (settings);
+}
+#endif /* HAVE_BLUETOOTH */
+
+static GtkWidget *
+error_dialog (const char *title,
+	      const char *reason,
+	      GtkWindow *parent)
+{
+	GtkWidget *error_dialog;
+
+	if (reason == NULL)
+		reason = _("No reason");
+
+	error_dialog =
+		gtk_message_dialog_new (parent,
+					GTK_DIALOG_MODAL,
+					GTK_MESSAGE_ERROR,
+					GTK_BUTTONS_OK,
+					"%s", title);
+	gtk_message_dialog_format_secondary_text
+		(GTK_MESSAGE_DIALOG (error_dialog), "%s", reason);
+
+	gtk_window_set_title (GTK_WINDOW (error_dialog), ""); /* as per HIG */
+	gtk_container_set_border_width (GTK_CONTAINER (error_dialog), 5);
+	gtk_dialog_set_default_response (GTK_DIALOG (error_dialog),
+					 GTK_RESPONSE_OK);
+	gtk_window_set_modal (GTK_WINDOW (error_dialog), TRUE);
+
+	return error_dialog;
+}
+
+static void
+help_button_clicked (GtkButton *button, GtkWidget *window)
+{
+	GError *error = NULL;
+
+	if (gtk_show_uri_on_window (GTK_WINDOW (window), "help:mate-user-share", gtk_get_current_event_time (), &error) == FALSE) {
+		GtkWidget *dialog;
+
+		dialog = error_dialog (_("Could not display the help contents."), error->message, GTK_WINDOW (window));
+		g_signal_connect (G_OBJECT (dialog), "response", G_CALLBACK
+				  (gtk_widget_destroy), error_dialog);
+		gtk_window_present (GTK_WINDOW (dialog));
+
+		g_error_free (error);
+	}
+}
+
+static GtkWidget *
+create_window (void)
+{
+    GError *error = NULL;
+    GSettings *settings;
+    GtkWidget *check;
+    GtkWidget *password_combo;
+    GtkWidget *password_entry;
+#ifdef HAVE_BLUETOOTH
+    GtkWidget *bluetooth_check;
+    GtkWidget *bluetooth_allow_write_check;
+    GtkWidget *require_pairing_check;
+    GtkWidget *enable_obexpush_check;
+    GtkWidget *accept_obexpush_combo;
+    GtkWidget *notify_received_obexpush_check;
+#endif /* HAVE_BLUETOOTH */
+    GtkWidget *window;
+    GtkListStore *store;
+    GtkCellRenderer *cell;
+    GtkTreeIter iter;
+
+    builder = gtk_builder_new ();
+    gtk_builder_add_from_file (builder, DATADIR"file-share-properties.ui", &error);
+
+    if (error) {
+      GtkWidget *dialog;
+
+      dialog = error_dialog (_("Could not build interface."), error->message, NULL);
+      gtk_dialog_run (GTK_DIALOG (dialog));
+      gtk_widget_destroy (dialog);
+
+      g_error_free (error);
+      return NULL;
+    }
+
+    window = GTK_WIDGET (gtk_builder_get_object (builder, "user_share_dialog"));
+
+    settings = g_settings_new (GSETTINGS_SCHEMA);
+
+    check = GTK_WIDGET (gtk_builder_get_object (builder, "enable_check"));
+    password_combo = GTK_WIDGET (gtk_builder_get_object (builder, "password_combo"));
+    password_entry = GTK_WIDGET (gtk_builder_get_object (builder, "password_entry"));
+#ifdef HAVE_BLUETOOTH
+    bluetooth_check = GTK_WIDGET (gtk_builder_get_object (builder, "enable_bluetooth_check"));
+    bluetooth_allow_write_check = GTK_WIDGET (gtk_builder_get_object (builder, "allow_write_bluetooth_check"));
+    require_pairing_check = GTK_WIDGET (gtk_builder_get_object (builder, "require_pairing_check"));
+    enable_obexpush_check = GTK_WIDGET (gtk_builder_get_object (builder, "enable_obexpush_check"));
+    accept_obexpush_combo = GTK_WIDGET (gtk_builder_get_object (builder, "accept_obexpush_combo"));
+    notify_received_obexpush_check = GTK_WIDGET (gtk_builder_get_object (builder, "notify_received_obexpush_check"));
+#endif /* HAVE_BLUETOOTH */
+
+    store = gtk_list_store_new (1, G_TYPE_STRING);
+    gtk_combo_box_set_model (GTK_COMBO_BOX (password_combo),
+			     GTK_TREE_MODEL (store));
+    cell = gtk_cell_renderer_text_new ();
+    gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (password_combo), cell, TRUE);
+    gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (password_combo), cell,
+				    "text", 0,
+				    NULL);
+
+    /* Keep in same order as enum */
+    gtk_list_store_append (store, &iter);
+    gtk_list_store_set (store, &iter, 0,
+			_("Never"), -1);
+    gtk_list_store_append (store, &iter);
+    gtk_list_store_set (store, &iter, 0,
+			_("When writing files"), -1);
+    gtk_list_store_append (store, &iter);
+    gtk_list_store_set (store, &iter, 0,
+			_("Always"), -1);
+    g_object_unref (store);
+
+    /* We can't read the password from the text, just set it to something */
+    gtk_entry_set_text (GTK_ENTRY (password_entry), "none");
+    g_object_set_data (G_OBJECT (password_entry),
+		       "user_edited", GINT_TO_POINTER (0));
+    g_signal_connect (password_entry,
+		      "changed", G_CALLBACK (password_entry_changed), NULL);
+
+#ifdef HAVE_BLUETOOTH
+    /* Accept files combo */
+    store = gtk_list_store_new (1, G_TYPE_STRING);
+    gtk_combo_box_set_model (GTK_COMBO_BOX (accept_obexpush_combo),
+			     GTK_TREE_MODEL (store));
+    cell = gtk_cell_renderer_text_new ();
+    gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (accept_obexpush_combo), cell, TRUE);
+    gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (accept_obexpush_combo), cell,
+				    "text", 0,
+				    NULL);
+
+    /* Keep in same order as enum */
+    gtk_list_store_append (store, &iter);
+    gtk_list_store_set (store, &iter, 0,
+			_("Always"), -1);
+    gtk_list_store_append (store, &iter);
+    gtk_list_store_set (store, &iter, 0,
+			_("Only for set up devices"), -1);
+    //FIXME implement
+#if 0
+    gtk_list_store_append (store, &iter);
+    gtk_list_store_set (store, &iter, 0,
+    			_("Ask"), -1);
+#endif
+    g_object_unref (store);
+#endif /* HAVE_BLUETOOTH */
+
+    g_signal_connect (check,
+		      "toggled", G_CALLBACK (enable_check_toggled), NULL);
+    g_signal_connect (password_combo,
+		      "changed", G_CALLBACK (password_combo_changed), NULL);
+#ifdef HAVE_BLUETOOTH
+    g_signal_connect (bluetooth_check,
+    		      "toggled", G_CALLBACK (enable_bluetooth_check_toggled), NULL);
+    g_signal_connect (bluetooth_allow_write_check,
+    		      "toggled", G_CALLBACK (bluetooth_allow_write_check_toggled), NULL);
+    g_signal_connect (require_pairing_check,
+    		      "toggled", G_CALLBACK (bluetooth_require_pairing_check_toggled), NULL);
+    g_signal_connect (enable_obexpush_check,
+    		      "toggled", G_CALLBACK (enable_obexpush_check_toggled), NULL);
+    g_signal_connect (accept_obexpush_combo,
+    		      "changed", G_CALLBACK (accept_obexpush_combo_changed), NULL);
+    g_signal_connect (notify_received_obexpush_check,
+    		      "toggled", G_CALLBACK (notify_received_obexpush_check_toggled), NULL);
+#endif /* HAVE_BLUETOOTH */
+
+    g_signal_connect_swapped (GTK_WIDGET (gtk_builder_get_object (builder, "close_button")),
+                              "clicked", G_CALLBACK (gtk_widget_destroy), window);
+    g_signal_connect (GTK_WIDGET (gtk_builder_get_object (builder, "help_button")),
+		      "clicked", G_CALLBACK (help_button_clicked),
+		      gtk_builder_get_object (builder, "user_share_dialog"));
+
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_ENABLED,
+			     G_CALLBACK (file_sharing_enabled_changed), NULL);
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_REQUIRE_PASSWORD,
+			     G_CALLBACK (password_required_changed), NULL);
+#ifdef HAVE_BLUETOOTH
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_ENABLED,
+			     G_CALLBACK (file_sharing_bluetooth_enabled_changed), NULL);
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_ALLOW_WRITE,
+			     G_CALLBACK (file_sharing_bluetooth_allow_write_changed), NULL);
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_REQUIRE_PAIRING,
+			     G_CALLBACK (file_sharing_bluetooth_require_pairing_changed), NULL);
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED,
+			     G_CALLBACK (file_sharing_bluetooth_obexpush_enabled_changed), NULL);
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_ACCEPT_FILES,
+			     G_CALLBACK (file_sharing_bluetooth_obexpush_accept_files_changed), NULL);
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_NOTIFY,
+			     G_CALLBACK (file_sharing_bluetooth_obexpush_notify_changed), NULL);
+#endif /* HAVE_BLUETOOTH */
+
+    update_ui ();
+
+    return window;
+}
+
+static void
+activate (GtkApplication *app)
+{
+    GList *list;
+    GtkWidget *window;
+
+    list = gtk_application_get_windows (app);
+
+    if (list) {
+        gtk_window_present (GTK_WINDOW (list->data));
+    } else {
+        window = create_window ();
+        gtk_window_set_application (GTK_WINDOW (window), app);
+        gtk_widget_show (window);
+    }
+}
+
+int
+main (int argc, char *argv[])
+{
+    GtkApplication *app;
+    gint status;
+
+    bindtextdomain (GETTEXT_PACKAGE, MATELOCALEDIR);
+    bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
+    textdomain (GETTEXT_PACKAGE);
+
+    app = gtk_application_new ("org.mate.user-share.properties",
+                               G_APPLICATION_FLAGS_NONE);
+    g_signal_connect (app, "activate", G_CALLBACK (activate), NULL);
+
+    status = g_application_run (G_APPLICATION (app), argc, argv);
+
+    g_object_unref (app);
+
+    return status;
+}
+
+
+
+ +
+ + diff --git a/2022-10-29-134846-0734-cppcheck@fcf648868871_master/1.html b/2022-10-29-134846-0734-cppcheck@fcf648868871_master/1.html new file mode 100644 index 0000000..6ca74fd --- /dev/null +++ b/2022-10-29-134846-0734-cppcheck@fcf648868871_master/1.html @@ -0,0 +1,1123 @@ + + + + + + Cppcheck - HTML report - mate-user-share + + + + + +
+ + + +
+
  1
+  2
+  3
+  4
+  5
+  6
+  7
+  8
+  9
+ 10
+ 11
+ 12
+ 13
+ 14
+ 15
+ 16
+ 17
+ 18
+ 19
+ 20
+ 21
+ 22
+ 23
+ 24
+ 25
+ 26
+ 27
+ 28
+ 29
+ 30
+ 31
+ 32
+ 33
+ 34
+ 35
+ 36
+ 37
+ 38
+ 39
+ 40
+ 41
+ 42
+ 43
+ 44
+ 45
+ 46
+ 47
+ 48
+ 49
+ 50
+ 51
+ 52
+ 53
+ 54
+ 55
+ 56
+ 57
+ 58
+ 59
+ 60
+ 61
+ 62
+ 63
+ 64
+ 65
+ 66
+ 67
+ 68
+ 69
+ 70
+ 71
+ 72
+ 73
+ 74
+ 75
+ 76
+ 77
+ 78
+ 79
+ 80
+ 81
+ 82
+ 83
+ 84
+ 85
+ 86
+ 87
+ 88
+ 89
+ 90
+ 91
+ 92
+ 93
+ 94
+ 95
+ 96
+ 97
+ 98
+ 99
+100
+101
+102
+103
+104
+105
+106
+107
+108
+109
+110
+111
+112
+113
+114
+115
+116
+117
+118
+119
+120
+121
+122
+123
+124
+125
+126
+127
+128
+129
+130
+131
+132
+133
+134
+135
+136
+137
+138
+139
+140
+141
+142
+143
+144
+145
+146
+147
+148
+149
+150
+151
+152
+153
+154
+155
+156
+157
+158
+159
+160
+161
+162
+163
+164
+165
+166
+167
+168
+169
+170
+171
+172
+173
+174
+175
+176
+177
+178
+179
+180
+181
+182
+183
+184
+185
+186
+187
+188
+189
+190
+191
+192
+193
+194
+195
+196
+197
+198
+199
+200
+201
+202
+203
+204
+205
+206
+207
+208
+209
+210
+211
+212
+213
+214
+215
+216
+217
+218
+219
+220
+221
+222
+223
+224
+225
+226
+227
+228
+229
+230
+231
+232
+233
+234
+235
+236
+237
+238
+239
+240
+241
+242
+243
+244
+245
+246
+247
+248
+249
+250
+251
+252
+253
+254
+255
+256
+257
+258
+259
+260
+261
+262
+263
+264
+265
+266
+267
+268
+269
+270
+271
+272
+273
+274
+275
+276
+277
+278
+279
+280
+281
+282
+283
+284
+285
+286
+287
+288
+289
+290
+291
+292
+293
+294
+295
+296
+297
+298
+299
+300
+301
+302
+303
+304
+305
+306
+307
+308
+309
+310
+311
+312
+313
+314
+315
+316
+317
+318
+319
+320
+321
+322
+323
+324
+325
+326
+327
+328
+329
+330
+331
+332
+333
+334
+335
+336
+337
+338
+339
+340
+341
+342
+343
+344
+345
+346
+347
+348
+349
+350
+351
+352
+353
+354
+355
+356
+357
+358
+359
+360
+361
+362
+363
+364
+365
+366
+367
+368
+369
+370
+371
+372
+373
+374
+375
+376
+377
+378
+379
+380
+381
+382
+383
+384
+385
+386
+387
+388
+389
+390
+391
+392
+393
+394
+395
+396
+397
+398
+399
+400
+401
+402
+403
+404
+405
+406
+407
+408
+409
+410
+411
+412
+413
+414
+415
+416
+417
+418
+419
+420
+421
+422
+423
+424
+425
+426
+427
+428
+429
+430
+431
+432
+433
+434
+435
+436
+437
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
+
+/*
+ *  Copyright (C) 2004-2008 Red Hat, Inc.
+ * Copyright (C) 2012-2021 MATE Developers
+ *
+ *  Caja is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU General Public License as
+ *  published by the Free Software Foundation; either version 2 of the
+ *  License, or (at your option) any later version.
+ *
+ *  Caja is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  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
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ *  Authors: Alexander Larsson <alexl@redhat.com>
+ *
+ */
+
+#include "config.h"
+
+#include <glib.h>
+#include <glib/gi18n.h>
+#include <X11/Xlib.h>
+
+#include <gio/gio.h>
+
+#include <stdarg.h>
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <signal.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <sys/stat.h>
+
+#ifdef HAVE_SELINUX
+#include <selinux/selinux.h>
+#endif
+
+#include "user_share-common.h"
+#include "user_share-private.h"
+#include "http.h"
+
+/* From avahi-common/domain.h */
+#define AVAHI_LABEL_MAX 64
+
+#define GSETTINGS_SCHEMA "org.mate.FileSharing"
+
+static pid_t httpd_pid = 0;
+
+static int
+get_port (void)
+{
+	int sock;
+	struct sockaddr_in addr;
+	int reuse;
+	socklen_t len;
+
+	sock = socket (PF_INET, SOCK_STREAM, 0);
+	if (sock < 0) {
+		return -1;
+	}
+
+	memset (&addr, 0, sizeof (addr));
+	addr.sin_port = 0;
+	addr.sin_addr.s_addr = INADDR_ANY;
+	addr.sin_family = AF_INET;
+
+	reuse = 1;
+	setsockopt (sock, SOL_SOCKET, SO_REUSEADDR, &reuse, sizeof (reuse));
+	if (bind (sock, (struct sockaddr *)&addr, sizeof (addr)) == -1) {
+		close (sock);
+		return -1;
+	}
+
+	len = sizeof (addr);
+	if (getsockname (sock, (struct sockaddr *)&addr, &len) == -1) {
+		close (sock);
+		return -1;
+	}
+
+#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__APPLE__) || defined(__OpenBSD__)
+	/* XXX This exposes a potential race condition, but without this,
+	 * httpd will not start on the above listed platforms due to the fact
+	 * that SO_REUSEADDR is also needed when Apache binds to the listening
+	 * socket.  At this time, Apache does not support that socket option.
+	 */
+	close (sock);
+#endif
+	return ntohs (addr.sin_port);
+}
+
+static char *
+truncate_name (const char *name)
+{
+	const char *end;
+
+	end = g_utf8_find_prev_char (name, name + 64);
+	g_assert (end != NULL);
+	return g_strndup (name, end - name);
+}
+
+static char *
+get_share_name (void)
+{
+	static char *name = NULL;
+	const char *host_name;
+	char *str;
+
+	if (name == NULL) {
+		host_name = g_get_host_name ();
+		if (strcmp (host_name, "localhost") == 0) {
+			/* Translators: The %s will get filled in with the user name
+			   of the user, to form a genitive. If this is difficult to
+			   translate correctly so that it will work correctly in your
+			   language, you may use something equivalent to
+			   "Public files of %s", or leave out the %s altogether.
+			   In the latter case, please put "%.0s" somewhere in the string,
+			   which will match the user name string passed by the C code,
+			   but not put the user name in the final string. This is to
+			   avoid the warning that msgfmt might otherwise generate. */
+			name = g_strdup_printf (_("%s's public files"), g_get_user_name ());
+		} else {
+			/* Translators: This is similar to the string before, only it
+			   has the hostname in it too. */
+			name = g_strdup_printf (_("%s's public files on %s"),
+						g_get_user_name (),
+						host_name);
+		}
+
+	}
+	/* And truncate */
+	if (strlen (name) < AVAHI_LABEL_MAX)
+		return name;
+
+	str = truncate_name (name);
+	g_free (name);
+	name = str;
+
+	return name;
+}
+
+static void
+ensure_conf_dir (void)
+{
+	char *dirname;
+
+	dirname = g_build_filename (g_get_user_config_dir (), "user-share", NULL);
+	g_mkdir_with_parents (dirname, 0755);
+	g_free (dirname);
+}
+
+static void
+httpd_child_setup (gpointer user_data)
+{
+#ifdef HAVE_SELINUX
+	char *mycon;
+	/* If selinux is enabled, avoid transitioning to the httpd_t context,
+	   as this normally means you can't read the users homedir. */
+	if (is_selinux_enabled()) {
+		if (getcon (&mycon) < 0) {
+			abort ();
+		}
+		if (setexeccon (mycon) < 0)
+			abort ();
+		freecon (mycon);
+	}
+#endif
+}
+
+static const char *known_httpd_locations [] = {
+	HTTPD_PROGRAM,
+	"/usr/sbin/httpd",
+	"/usr/sbin/httpd2",
+	"/usr/sbin/apache2",
+	NULL
+};
+
+static char*
+get_httpd_program (void)
+{
+	int i;
+
+	for (i = 0; known_httpd_locations[i]; i++) {
+		if (known_httpd_locations[i][0] == '\0') {
+			/* empty string as first element, happens when
+			 * configured --with-httpd=auto */
+			continue;
+		}
+		if (g_file_test (known_httpd_locations[i], G_FILE_TEST_IS_EXECUTABLE)
+				&& ! g_file_test (known_httpd_locations[i], G_FILE_TEST_IS_DIR)) {
+			return g_strdup (known_httpd_locations[i]);
+		}
+	}
+	return NULL;
+}
+
+static const char *known_httpd_modules_locations [] = {
+	HTTPD_MODULES_PATH,
+	"/etc/httpd/modules",
+	"/usr/lib/apache2/modules",
+	NULL
+};
+
+static gchar*
+get_httpd_modules_path (void)
+{
+	int i;
+
+	for (i = 0; known_httpd_modules_locations[i]; i++) {
+		if (known_httpd_modules_locations[i][0] == '\0') {
+			/* empty string as first element, happens when
+			 * configured --with-httpd=auto */
+			continue;
+		}
+		if (g_file_test (known_httpd_modules_locations[i], G_FILE_TEST_IS_EXECUTABLE)
+				&& g_file_test (known_httpd_modules_locations[i], G_FILE_TEST_IS_DIR)) {
+			return g_strdup (known_httpd_modules_locations[i]);
+		}
+	}
+	return NULL;
+}
+
+static GRegex *version_regex = NULL;
+
+static char*
+get_httpd_config (const char *httpd_program)
+{
+	gchar *standard_output;
+	gchar *cmd_line;
+	GMatchInfo *match_info;
+	gchar *version_number = NULL;
+	gchar *config;
+
+	cmd_line = g_strdup_printf ("%s -v", httpd_program);
+	if (! g_spawn_command_line_sync (cmd_line, &standard_output, NULL, NULL, NULL)) {
+		g_free (cmd_line);
+		return NULL;
+	}
+	g_free (cmd_line);
+
+	if (version_regex == NULL) {
+		version_regex = g_regex_new ("\\d\\.\\d", 0, 0, NULL);
+	}
+
+	if (g_regex_match (version_regex, standard_output, 0, &match_info)) {
+		while (g_match_info_matches (match_info)) {
+			version_number = g_match_info_fetch (match_info, 0);
+			break;
+		}
+		g_match_info_free (match_info);
+		g_free (standard_output);
+	} else {
+		/* Failed to parse httpd version number */
+		g_warning ("Could not parse '%s' as a version for httpd", standard_output);
+		g_free (standard_output);
+		/* assume it is 2.2 */
+		version_number = g_strdup ("2.2");
+	}
+
+	config = g_strdup_printf (HTTPD_CONFIG_TEMPLATE, version_number);
+	g_free (version_number);
+
+	return config;
+}
+
+static gboolean
+spawn_httpd (int port, pid_t *pid_out)
+{
+	char *free1, *free2, *free3, *free4, *free5, *free6, *free7, *free8, *free9;
+	gboolean res;
+	char *argv[10];
+	char *env[10];
+	int i;
+	gint status;
+	char *pid_filename;
+	char *pidfile;
+	GError *error;
+	gboolean got_pidfile;
+	GSettings *settings;
+	char *str;
+	char *public_dir;
+
+	public_dir = lookup_public_dir ();
+	ensure_conf_dir ();
+
+	i = 0;
+	free1 = argv[i++] = get_httpd_program ();
+	if (argv[0] == NULL) {
+		fprintf (stderr, "error finding httpd server\n");
+		return FALSE;
+	}
+
+	argv[i++] = "-f";
+	free2 = argv[i++] = get_httpd_config (argv[0]);
+	argv[i++] = "-C";
+	free3 = argv[i++] = g_strdup_printf ("Listen %d", port);
+
+	settings = g_settings_new (GSETTINGS_SCHEMA);
+	str = g_settings_get_string (settings,
+				       FILE_SHARING_REQUIRE_PASSWORD);
+
+	if (str && strcmp (str, "never") == 0) {
+		/* Do nothing */
+	} else if (str && strcmp (str, "on_write") == 0){
+		argv[i++] = "-D";
+		argv[i++] = "RequirePasswordOnWrite";
+	} else {
+		/* always, or safe fallback */
+		argv[i++] = "-D";
+		argv[i++] = "RequirePasswordAlways";
+	}
+	g_free (str);
+	g_object_unref (settings);
+
+	argv[i] = NULL;
+
+	i = 0;
+	free4 = env[i++] = g_strdup_printf ("HOME=%s", g_get_home_dir());
+	free5 = env[i++] = g_strdup_printf ("XDG_PUBLICSHARE_DIR=%s", public_dir);
+	free6 = env[i++] = g_strdup_printf ("XDG_CONFIG_HOME=%s", g_get_user_config_dir ());
+	free7 = env[i++] = g_strdup_printf ("GUS_SHARE_NAME=%s", get_share_name ());
+	free8 = env[i++] = g_strdup_printf ("GUS_LOGIN_LABEL=%s", "Please log in as the user guest");
+	free9 = env[i++] = g_strdup_printf ("HTTP_MODULES_PATH=%s",get_httpd_modules_path ());
+	env[i++] = "LANG=C";
+	env[i] = NULL;
+
+	pid_filename = g_build_filename (g_get_user_config_dir (), "user-share", "pid", NULL);
+
+	/* Remove pid file before spawning to avoid races with child and old pidfile */
+	unlink (pid_filename);
+
+	error = NULL;
+	res = g_spawn_sync (g_get_home_dir(),
+			    argv, env, 0,
+			    httpd_child_setup, NULL,
+			    NULL, NULL,
+			    &status,
+			    &error);
+	g_free (free1);
+	g_free (free2);
+	g_free (free3);
+	g_free (free4);
+	g_free (free5);
+	g_free (free6);
+	g_free (free7);
+	g_free (free8);
+	g_free (free9);
+	g_free (public_dir);
+
+	if (!res) {
+		fprintf (stderr, "error spawning httpd: %s\n",
+			 error->message);
+		g_error_free (error);
+		g_free (pid_filename);
+		return FALSE;
+	}
+
+	if (status != 0) {
+		g_free (pid_filename);
+		return FALSE;
+	}
+
+	got_pidfile = FALSE;
+	error = NULL;
+	for (i = 0; i < 5; i++) {
+		if (error != NULL)
+			g_error_free (error);
+		error = NULL;
+		if (g_file_get_contents (pid_filename, &pidfile, NULL, &error)) {
+			got_pidfile = TRUE;
+			*pid_out = atoi (pidfile);
+			g_free (pidfile);
+			break;
+		}
+		sleep (1);
+	}
+
+	g_free (pid_filename);
+
+	if (!got_pidfile) {
+		fprintf (stderr, "error opening httpd pidfile: %s\n", error->message);
+		g_error_free (error);
+		return FALSE;
+	}
+	return TRUE;
+}
+
+static void
+kill_httpd (void)
+{
+	if (httpd_pid != 0) {
+		kill (httpd_pid, SIGTERM);
+
+		/* Allow child time to die, we can't waitpid, because its
+		   not a direct child */
+		sleep (1);
+	}
+	httpd_pid = 0;
+}
+
+void
+http_up (void)
+{
+	guint port;
+
+	port = get_port ();
+	if (!spawn_httpd (port, &httpd_pid)) {
+		fprintf (stderr, "spawning httpd failed\n");
+	}
+}
+
+void
+http_down (void)
+{
+	kill_httpd ();
+}
+
+gboolean
+http_init (void)
+{
+	return TRUE;
+}
+
+pid_t
+http_get_pid (void)
+{
+	return httpd_pid;
+}
+
+
+
+ +
+ + diff --git a/2022-10-29-134846-0734-cppcheck@fcf648868871_master/2.html b/2022-10-29-134846-0734-cppcheck@fcf648868871_master/2.html new file mode 100644 index 0000000..1682147 --- /dev/null +++ b/2022-10-29-134846-0734-cppcheck@fcf648868871_master/2.html @@ -0,0 +1,833 @@ + + + + + + Cppcheck - HTML report - mate-user-share + + + + + +
+ + + +
+
  1
+  2
+  3
+  4
+  5
+  6
+  7
+  8
+  9
+ 10
+ 11
+ 12
+ 13
+ 14
+ 15
+ 16
+ 17
+ 18
+ 19
+ 20
+ 21
+ 22
+ 23
+ 24
+ 25
+ 26
+ 27
+ 28
+ 29
+ 30
+ 31
+ 32
+ 33
+ 34
+ 35
+ 36
+ 37
+ 38
+ 39
+ 40
+ 41
+ 42
+ 43
+ 44
+ 45
+ 46
+ 47
+ 48
+ 49
+ 50
+ 51
+ 52
+ 53
+ 54
+ 55
+ 56
+ 57
+ 58
+ 59
+ 60
+ 61
+ 62
+ 63
+ 64
+ 65
+ 66
+ 67
+ 68
+ 69
+ 70
+ 71
+ 72
+ 73
+ 74
+ 75
+ 76
+ 77
+ 78
+ 79
+ 80
+ 81
+ 82
+ 83
+ 84
+ 85
+ 86
+ 87
+ 88
+ 89
+ 90
+ 91
+ 92
+ 93
+ 94
+ 95
+ 96
+ 97
+ 98
+ 99
+100
+101
+102
+103
+104
+105
+106
+107
+108
+109
+110
+111
+112
+113
+114
+115
+116
+117
+118
+119
+120
+121
+122
+123
+124
+125
+126
+127
+128
+129
+130
+131
+132
+133
+134
+135
+136
+137
+138
+139
+140
+141
+142
+143
+144
+145
+146
+147
+148
+149
+150
+151
+152
+153
+154
+155
+156
+157
+158
+159
+160
+161
+162
+163
+164
+165
+166
+167
+168
+169
+170
+171
+172
+173
+174
+175
+176
+177
+178
+179
+180
+181
+182
+183
+184
+185
+186
+187
+188
+189
+190
+191
+192
+193
+194
+195
+196
+197
+198
+199
+200
+201
+202
+203
+204
+205
+206
+207
+208
+209
+210
+211
+212
+213
+214
+215
+216
+217
+218
+219
+220
+221
+222
+223
+224
+225
+226
+227
+228
+229
+230
+231
+232
+233
+234
+235
+236
+237
+238
+239
+240
+241
+242
+243
+244
+245
+246
+247
+248
+249
+250
+251
+252
+253
+254
+255
+256
+257
+258
+259
+260
+261
+262
+263
+264
+265
+266
+267
+268
+269
+270
+271
+272
+273
+274
+275
+276
+277
+278
+279
+280
+281
+282
+283
+284
+285
+286
+287
+288
+289
+290
+291
+292
/* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 8; tab-width: 8 -*-
+ *
+ * Copyright (C) 2003 Novell, Inc.
+ * Copyright (C) 2003-2004 Red Hat, Inc.
+ * Copyright (C) 2005 William Jon McCann <mccann@jhu.edu>
+ * Copyright (C) 2012-2021 MATE Developers
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * 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 Foundation, Inc., 51 Franklin St, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ *
+ */
+
+#include "config.h"
+
+#include <stdlib.h>
+#include <string.h>
+#include <glib/gi18n-lib.h>
+#include <gtk/gtk.h>
+#include <libcaja-extension/caja-menu-provider.h>
+#include <libcaja-extension/caja-location-widget-provider.h>
+
+#ifdef HAVE_BLUETOOTH
+#include <bluetooth-client.h>
+#endif
+
+#include "caja-share-bar.h"
+#include "user_share-common.h"
+
+#define CAJA_TYPE_USER_SHARE  (caja_user_share_get_type ())
+#define CAJA_USER_SHARE(o)    (G_TYPE_CHECK_INSTANCE_CAST ((o), CAJA_TYPE_USER_SHARE, CajaUserShare))
+#define CAJA_IS_USER_SHARE(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), CAJA_TYPE_USER_SHARE))
+
+typedef struct
+{
+        GObject              parent_slot;
+} CajaUserShare;
+
+typedef struct
+{
+        GObjectClass parent_slot;
+} CajaUserShareClass;
+
+static GType caja_user_share_get_type      (void);
+static void  caja_user_share_register_type (GTypeModule *module);
+
+static void
+launch_process (char **argv, GtkWindow *parent)
+{
+        GError *error;
+        GtkWidget *dialog;
+
+        error = NULL;
+        if (!g_spawn_async (NULL,
+                            argv, NULL,
+                            0,
+                            NULL, NULL,
+                            NULL,
+                            &error)) {
+
+
+                dialog = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL, GTK_MESSAGE_WARNING,
+						 GTK_BUTTONS_OK, _("Unable to launch the Personal File Sharing preferences"));
+
+                gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog), "%s", error->message);
+
+                gtk_dialog_run (GTK_DIALOG (dialog));
+                gtk_widget_destroy (dialog);
+
+                g_error_free (error);
+        }
+}
+
+static void
+launch_prefs_on_window (GtkWindow *window)
+{
+        char *argv [2];
+
+        argv [0] = g_build_filename (BINDIR, "mate-file-share-properties", NULL);
+        argv [1] = NULL;
+
+        launch_process (argv, window);
+
+        g_free (argv [0]);
+}
+
+static void
+bar_response_cb (CajaShareBar *bar,
+                 gint response,
+                 gpointer         data)
+{
+        if (response == CAJA_SHARE_BAR_RESPONSE_PREFERENCES) {
+                launch_prefs_on_window (GTK_WINDOW (data));
+        }
+}
+
+#ifdef HAVE_BLUETOOTH
+static void
+downloads_bar_set_from_bluetooth_status (GtkWidget *bar)
+{
+	BluetoothClient *client;
+	gboolean bt_powered;
+
+	client = g_object_get_data (G_OBJECT (bar), "bluetooth-client");
+	g_object_get (G_OBJECT (client),
+		      "default-adapter-powered", &bt_powered,
+		      NULL);
+	gtk_widget_set_visible (bar, bt_powered);
+}
+
+static void
+default_adapter_powered_cb (GObject    *gobject,
+			    GParamSpec *pspec,
+			    GtkWidget  *bar)
+{
+	downloads_bar_set_from_bluetooth_status (bar);
+}
+#endif /* HAVE_BLUETOOTH */
+
+static GtkWidget *
+caja_user_share_get_location_widget (CajaLocationWidgetProvider *iface,
+                                         const char                     *uri,
+                                         GtkWidget                      *window)
+{
+	GFile             *file;
+	GtkWidget         *bar;
+	guint              i;
+	gboolean           enable = FALSE;
+	GFile             *home;
+#ifdef HAVE_BLUETOOTH
+	const GUserDirectory special_dirs[] = { G_USER_DIRECTORY_PUBLIC_SHARE, G_USER_DIRECTORY_DOWNLOAD };
+
+	gboolean is_dir[] = { FALSE, FALSE };
+#else
+	const GUserDirectory special_dirs[] = { G_USER_DIRECTORY_PUBLIC_SHARE };
+
+	gboolean is_dir[] = { FALSE };
+#endif /* HAVE_BLUETOOTH */
+	file = g_file_new_for_uri (uri);
+	home = g_file_new_for_path (g_get_home_dir ());
+
+	/* We don't show anything in $HOME */
+	if (g_file_equal (home, file)) {
+		g_object_unref (home);
+		g_object_unref (file);
+		return NULL;
+	}
+
+	g_object_unref (home);
+
+	for (i = 0; i < G_N_ELEMENTS (special_dirs); i++) {
+		GFile *dir;
+		dir = lookup_dir_with_fallback (special_dirs[i]);
+		if (g_file_equal (dir, file)) {
+			enable = TRUE;
+			is_dir[i] = TRUE;
+		}
+		g_object_unref (dir);
+	}
+
+	g_object_unref (file);
+
+	if (enable == FALSE)
+		return NULL;
+
+	if (is_dir[0] != FALSE) {
+#ifdef HAVE_BLUETOOTH
+		if (is_dir[1] != FALSE) {
+			bar = caja_share_bar_new (_("May be used to share or receive files"));
+		} else {
+			bar = caja_share_bar_new (_("May be shared over the network or Bluetooth"));
+		}
+#else
+		bar = caja_share_bar_new (_("May be shared over the network"));
+#endif /* HAVE_BLUETOOTH */
+	} else {
+#ifdef HAVE_BLUETOOTH
+		BluetoothClient *client;
+
+		bar = caja_share_bar_new (_("May be used to receive files over Bluetooth"));
+
+		gtk_widget_set_no_show_all (bar, TRUE);
+		client = bluetooth_client_new ();
+		g_object_set_data_full (G_OBJECT (bar), "bluetooth-client", client, g_object_unref);
+		g_signal_connect (G_OBJECT (client), "notify::default-adapter-powered",
+				  G_CALLBACK (default_adapter_powered_cb), bar);
+		downloads_bar_set_from_bluetooth_status (bar);
+#endif /* HAVE_BLUETOOTH */
+	}
+
+	g_signal_connect (bar, "response",
+			  G_CALLBACK (bar_response_cb),
+			  window);
+
+	gtk_widget_show_all (bar);
+
+	return bar;
+}
+
+static void
+caja_user_share_location_widget_provider_iface_init (CajaLocationWidgetProviderIface *iface)
+{
+        iface->get_widget = caja_user_share_get_location_widget;
+}
+
+static void
+caja_user_share_instance_init (CajaUserShare *share)
+{
+
+}
+
+static void
+caja_user_share_class_init (CajaUserShareClass *klass)
+{
+
+}
+
+static GType share_type = 0;
+
+static GType
+caja_user_share_get_type (void)
+{
+        return share_type;
+}
+
+static void
+caja_user_share_register_type (GTypeModule *module)
+{
+        static const GTypeInfo info = {
+                sizeof (CajaUserShareClass),
+                (GBaseInitFunc) NULL,
+                (GBaseFinalizeFunc) NULL,
+                (GClassInitFunc) caja_user_share_class_init,
+                NULL,
+                NULL,
+                sizeof (CajaUserShare),
+                0,
+                (GInstanceInitFunc) caja_user_share_instance_init,
+        };
+
+        static const GInterfaceInfo location_widget_provider_iface_info = {
+                (GInterfaceInitFunc) caja_user_share_location_widget_provider_iface_init,
+                NULL,
+                NULL
+        };
+
+        share_type = g_type_module_register_type (module,
+                                                 G_TYPE_OBJECT,
+                                                 "CajaUserShare",
+                                                 &info, 0);
+
+        g_type_module_add_interface (module,
+                                     share_type,
+                                     CAJA_TYPE_LOCATION_WIDGET_PROVIDER,
+                                     &location_widget_provider_iface_info);
+}
+
+void
+caja_module_initialize (GTypeModule *module)
+{
+        caja_user_share_register_type (module);
+        bindtextdomain (GETTEXT_PACKAGE, MATELOCALEDIR);
+        bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
+}
+
+void
+caja_module_shutdown (void)
+{
+}
+
+void
+caja_module_list_types (const GType **types,
+                            int          *num_types)
+{
+        static GType type_list [1];
+
+        type_list[0] = CAJA_TYPE_USER_SHARE;
+
+        *types = type_list;
+        *num_types = 1;
+}
+
+
+
+ +
+ + diff --git a/2022-10-29-134846-0734-cppcheck@fcf648868871_master/3.html b/2022-10-29-134846-0734-cppcheck@fcf648868871_master/3.html new file mode 100644 index 0000000..7bdfa00 --- /dev/null +++ b/2022-10-29-134846-0734-cppcheck@fcf648868871_master/3.html @@ -0,0 +1,1251 @@ + + + + + + Cppcheck - HTML report - mate-user-share + + + + + +
+ + + +
+
  1
+  2
+  3
+  4
+  5
+  6
+  7
+  8
+  9
+ 10
+ 11
+ 12
+ 13
+ 14
+ 15
+ 16
+ 17
+ 18
+ 19
+ 20
+ 21
+ 22
+ 23
+ 24
+ 25
+ 26
+ 27
+ 28
+ 29
+ 30
+ 31
+ 32
+ 33
+ 34
+ 35
+ 36
+ 37
+ 38
+ 39
+ 40
+ 41
+ 42
+ 43
+ 44
+ 45
+ 46
+ 47
+ 48
+ 49
+ 50
+ 51
+ 52
+ 53
+ 54
+ 55
+ 56
+ 57
+ 58
+ 59
+ 60
+ 61
+ 62
+ 63
+ 64
+ 65
+ 66
+ 67
+ 68
+ 69
+ 70
+ 71
+ 72
+ 73
+ 74
+ 75
+ 76
+ 77
+ 78
+ 79
+ 80
+ 81
+ 82
+ 83
+ 84
+ 85
+ 86
+ 87
+ 88
+ 89
+ 90
+ 91
+ 92
+ 93
+ 94
+ 95
+ 96
+ 97
+ 98
+ 99
+100
+101
+102
+103
+104
+105
+106
+107
+108
+109
+110
+111
+112
+113
+114
+115
+116
+117
+118
+119
+120
+121
+122
+123
+124
+125
+126
+127
+128
+129
+130
+131
+132
+133
+134
+135
+136
+137
+138
+139
+140
+141
+142
+143
+144
+145
+146
+147
+148
+149
+150
+151
+152
+153
+154
+155
+156
+157
+158
+159
+160
+161
+162
+163
+164
+165
+166
+167
+168
+169
+170
+171
+172
+173
+174
+175
+176
+177
+178
+179
+180
+181
+182
+183
+184
+185
+186
+187
+188
+189
+190
+191
+192
+193
+194
+195
+196
+197
+198
+199
+200
+201
+202
+203
+204
+205
+206
+207
+208
+209
+210
+211
+212
+213
+214
+215
+216
+217
+218
+219
+220
+221
+222
+223
+224
+225
+226
+227
+228
+229
+230
+231
+232
+233
+234
+235
+236
+237
+238
+239
+240
+241
+242
+243
+244
+245
+246
+247
+248
+249
+250
+251
+252
+253
+254
+255
+256
+257
+258
+259
+260
+261
+262
+263
+264
+265
+266
+267
+268
+269
+270
+271
+272
+273
+274
+275
+276
+277
+278
+279
+280
+281
+282
+283
+284
+285
+286
+287
+288
+289
+290
+291
+292
+293
+294
+295
+296
+297
+298
+299
+300
+301
+302
+303
+304
+305
+306
+307
+308
+309
+310
+311
+312
+313
+314
+315
+316
+317
+318
+319
+320
+321
+322
+323
+324
+325
+326
+327
+328
+329
+330
+331
+332
+333
+334
+335
+336
+337
+338
+339
+340
+341
+342
+343
+344
+345
+346
+347
+348
+349
+350
+351
+352
+353
+354
+355
+356
+357
+358
+359
+360
+361
+362
+363
+364
+365
+366
+367
+368
+369
+370
+371
+372
+373
+374
+375
+376
+377
+378
+379
+380
+381
+382
+383
+384
+385
+386
+387
+388
+389
+390
+391
+392
+393
+394
+395
+396
+397
+398
+399
+400
+401
+402
+403
+404
+405
+406
+407
+408
+409
+410
+411
+412
+413
+414
+415
+416
+417
+418
+419
+420
+421
+422
+423
+424
+425
+426
+427
+428
+429
+430
+431
+432
+433
+434
+435
+436
+437
+438
+439
+440
+441
+442
+443
+444
+445
+446
+447
+448
+449
+450
+451
+452
+453
+454
+455
+456
+457
+458
+459
+460
+461
+462
+463
+464
+465
+466
+467
+468
+469
+470
+471
+472
+473
+474
+475
+476
+477
+478
+479
+480
+481
+482
+483
+484
+485
+486
+487
+488
+489
+490
+491
+492
+493
+494
+495
+496
+497
+498
+499
+500
+501
+502
+503
+504
+505
+506
+507
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
+
+/*
+ *  Copyright (C) 2004-2008 Red Hat, Inc.
+ *  Copyright (C) 2012-2021 MATE Developers
+ *
+ *  Caja is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU General Public License as
+ *  published by the Free Software Foundation; either version 2 of the
+ *  License, or (at your option) any later version.
+ *
+ *  Caja is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  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
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ *  Authors: Alexander Larsson <alexl@redhat.com>
+ *
+ */
+
+#include "config.h"
+
+#include <gdk/gdkx.h>
+#include <gtk/gtk.h>
+#include <glib/gi18n.h>
+#include <glib/gstdio.h>
+#include <gio/gio.h>
+#include <X11/Xlib.h>
+
+#include "user_share-private.h"
+#include "user_share-common.h"
+#include "http.h"
+
+#ifdef HAVE_BLUETOOTH
+#include <bluetooth-client.h>
+
+#include "obexftp.h"
+#include "obexpush.h"
+
+#endif /* HAVE_BLUETOOTH */
+
+#include <gio/gio.h>
+
+#include <stdarg.h>
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <signal.h>
+#include <unistd.h>
+
+static guint disabled_timeout_tag = 0;
+static GSettings* settings;<--- Shadowed declaration
+
+#define GSETTINGS_SCHEMA "org.mate.FileSharing"
+#define GSETTINGS_KEY_FILE_SHARING_ENABLED "enabled"
+#define GSETTINGS_KEY_FILE_SHARING_REQUIRE_PASSWORD "require-password"
+
+#ifdef HAVE_BLUETOOTH
+/* MATE Session */
+#define MATE_SESSION_DBUS_NAME      "org.gnome.SessionManager"
+#define MATE_SESSION_DBUS_OBJECT    "/org/gnome/SessionManager"
+#define MATE_SESSION_DBUS_INTERFACE "org.gnome.SessionManager"
+
+static GDBusProxy *session_proxy = NULL;
+static gboolean has_console = TRUE;
+
+static BluetoothClient *client = NULL;
+static gboolean bluetoothd_enabled = FALSE;
+
+#define OBEX_ENABLED (bluetoothd_enabled && has_console)
+
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_ENABLED "bluetooth-enabled"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_ALLOW_WRITE "bluetooth-allow-write"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_REQUIRE_PAIRING "bluetooth-require-pairing"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED "bluetooth-obexpush-enabled"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_ACCEPT_FILES "bluetooth-accept-files"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_NOTIFY "bluetooth-notify"
+
+
+static void
+obex_services_start (void)
+{
+	GSettings *settings;
+
+	if (bluetoothd_enabled == FALSE ||
+	    has_console == FALSE)
+	    	return;
+
+	settings = g_settings_new(GSETTINGS_SCHEMA);
+
+	if (g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED) == TRUE) {
+	    obexpush_up ();
+	}
+	if (g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_ENABLED) == TRUE) {
+	    obexftp_up ();
+	}
+
+	g_object_unref (client);
+}
+
+static void
+obex_services_shutdown (void)
+{
+	obexpush_down ();
+	obexftp_down ();
+}
+
+static void
+session_properties_changed_cb (GDBusProxy      *session,
+			       GVariant        *changed,
+			       char           **invalidated,
+			       gpointer         user_data)
+{
+	GVariant *v;
+
+	v = g_variant_lookup_value (changed, "SessionIsActive", G_VARIANT_TYPE_BOOLEAN);
+	if (v) {
+		has_console = g_variant_get_boolean (v);
+		g_debug ("Received session is active change: now %s", has_console ? "active" : "inactive");
+
+		if (has_console)
+			obex_services_start ();
+		else
+			obex_services_shutdown ();
+
+		g_variant_unref (v);
+	}
+}
+
+static gboolean
+is_session_active (void)
+{
+	GVariant *variant;
+	gboolean is_session_active = FALSE;
+
+	variant = g_dbus_proxy_get_cached_property (session_proxy,
+						    "SessionIsActive");
+	if (variant) {
+		is_session_active = g_variant_get_boolean (variant);
+		g_variant_unref (variant);
+ 	}
+
+	return is_session_active;
+}
+
+static void
+session_init (void)
+{
+	GError *error = NULL;
+
+	session_proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION,
+						       G_DBUS_PROXY_FLAGS_NONE,
+						       NULL,
+						       MATE_SESSION_DBUS_NAME,
+						       MATE_SESSION_DBUS_OBJECT,
+						       MATE_SESSION_DBUS_INTERFACE,
+						       NULL,
+						       &error);
+	if (session_proxy == NULL) {
+		g_warning ("Failed to get session proxy: %s", error->message);
+		g_error_free (error);
+		return;
+	}
+	g_signal_connect (session_proxy, "g-properties-changed",
+			  G_CALLBACK (session_properties_changed_cb),
+			  NULL);
+	has_console = is_session_active ();
+}
+
+static void
+default_adapter_changed (GObject    *gobject,<--- Parameter 'gobject' can be declared with const
+			 GParamSpec *pspec,
+			 gpointer    user_data)
+{
+	char *adapter;
+	gboolean adapter_powered;
+
+	g_object_get (G_OBJECT (client),
+		      "default-adapter", &adapter,
+		      "default-adapter-powered", &adapter_powered,
+		      NULL);
+	if (adapter != NULL && *adapter != '\0') {
+		bluetoothd_enabled = adapter_powered;
+	} else {
+		bluetoothd_enabled = FALSE;
+	}
+
+	/* Were we called as init, or as a callback */
+	if (gobject != NULL) {
+		if (bluetoothd_enabled != FALSE)
+			obex_services_start ();
+		else
+			obex_services_shutdown ();
+	}
+}
+
+static void
+bluez_init (void)
+{
+	client = bluetooth_client_new ();
+	default_adapter_changed (NULL, NULL, NULL);
+	g_signal_connect (G_OBJECT (client), "notify::default-adapter",
+			  G_CALLBACK (default_adapter_changed), NULL);
+	g_signal_connect (G_OBJECT (client), "notify::default-adapter-powered",
+			  G_CALLBACK (default_adapter_changed), NULL);
+}
+#endif /* HAVE_BLUETOOTH */
+
+static gboolean
+file_sharing_enabled (void)
+{
+	gboolean enabled = TRUE;
+	settings = g_settings_new (GSETTINGS_SCHEMA);
+
+#ifdef HAVE_BLUETOOTH
+	if (g_settings_get_boolean (settings, FILE_SHARING_ENABLED) == FALSE &&
+	    g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_ENABLED) == FALSE &&
+	    g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED) == FALSE)
+#else /* HAVE_BLUETOOTH */
+	if (g_settings_get_boolean (settings, FILE_SHARING_ENABLED) == FALSE)
+#endif /* HAVE_BLUETOOTH */
+		enabled = FALSE;
+
+	g_object_unref (settings);
+
+	return enabled;
+}
+
+static void
+migrate_old_configuration (void)
+{
+	const char *old_config_dir;
+	const char *new_config_dir;
+
+	old_config_dir = g_build_filename (g_get_home_dir (), ".mate2", "user-share", NULL);
+	new_config_dir = g_build_filename (g_get_user_config_dir (), "user-share", NULL);
+	if (g_file_test (old_config_dir, G_FILE_TEST_IS_DIR))
+		g_rename (old_config_dir, new_config_dir);
+
+}
+
+static void
+require_password_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	/* Need to restart to get new password setting */
+	if (http_get_pid () != 0) {
+		http_down ();
+		http_up ();
+	}
+}
+
+/* File sharing was disabled for some time, exit now */
+/* If we re-enable it in the ui, this will be restarted anyway */
+static gboolean
+disabled_timeout_callback (gpointer user_data)
+{
+	GSettings *settings = (GSettings *) user_data;
+	http_down ();
+
+#ifdef HAVE_BLUETOOTH
+	if (g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_ENABLED) == FALSE &&
+	    g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED) == FALSE)
+		_exit (0);
+#else /* HAVE_BLUETOOTH */
+	if (g_settings_get_boolean (settings, FILE_SHARING_ENABLED) == FALSE)
+		_exit (0);
+#endif /* HAVE_BLUETOOTH */
+	return FALSE;
+}
+
+static void
+file_sharing_enabled_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	gboolean enabled;
+
+	if (disabled_timeout_tag != 0) {
+		g_source_remove (disabled_timeout_tag);
+		disabled_timeout_tag = 0;
+	}
+
+	enabled = g_settings_get_boolean (settings,
+					 FILE_SHARING_ENABLED);
+	if (enabled) {
+		if (http_get_pid () == 0) {
+			http_up ();
+		}
+	} else {
+		http_down ();
+		disabled_timeout_tag = g_timeout_add_seconds (3,
+							      (GSourceFunc)disabled_timeout_callback,
+							      settings);
+	}
+}
+
+#ifdef HAVE_BLUETOOTH
+static void
+file_sharing_bluetooth_allow_write_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	if (g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_ENABLED) != FALSE)
+		obexftp_restart ();
+}
+
+static void
+file_sharing_bluetooth_require_pairing_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	if (g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_ENABLED) != FALSE) {
+		/* We need to fully reset the session,
+		 * otherwise the new setting isn't taken into account */
+		obexftp_down ();
+		obexftp_up ();
+	}
+}
+
+static void
+file_sharing_bluetooth_enabled_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	if (g_settings_get_boolean (settings,
+				   FILE_SHARING_BLUETOOTH_ENABLED) == FALSE) {
+		obexftp_down ();
+		if (g_settings_get_boolean (settings, FILE_SHARING_ENABLED) == FALSE &&
+		    g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED) == FALSE) {
+			_exit (0);
+		}
+	} else if (OBEX_ENABLED) {
+		obexftp_up ();
+	}
+}
+
+static void
+file_sharing_bluetooth_obexpush_enabled_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	if (g_settings_get_boolean (settings,
+				   FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED) == FALSE) {
+		obexpush_down ();
+		if (g_settings_get_boolean (settings, FILE_SHARING_ENABLED) == FALSE &&
+		    g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_ENABLED) == FALSE) {
+			_exit (0);
+		}
+	} else if (OBEX_ENABLED) {
+		obexpush_up ();
+	}
+}
+
+static void
+file_sharing_bluetooth_obexpush_accept_files_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	AcceptSetting setting;
+	char *str;
+
+	str = g_settings_get_string (settings, FILE_SHARING_BLUETOOTH_OBEXPUSH_ACCEPT_FILES);
+	setting = accept_setting_from_string (str);
+	g_free (str);
+
+	obexpush_set_accept_files_policy (setting);
+}
+
+static void
+file_sharing_bluetooth_obexpush_notify_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	obexpush_set_notify (g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_OBEXPUSH_NOTIFY));
+}
+#endif /* HAVE_BLUETOOTH */
+
+static RETSIGTYPE
+cleanup_handler (int sig)
+{
+	http_down ();
+#ifdef HAVE_BLUETOOTH
+	obexftp_down ();
+	obexpush_down ();
+#endif /* HAVE_BLUETOOTH */
+	_exit (2);
+}
+
+static int
+x_io_error_handler (Display *xdisplay)
+{
+	http_down ();
+#ifdef HAVE_BLUETOOTH
+	obexftp_down ();
+#endif /* HAVE_BLUETOOTH */
+	_exit (2);
+}
+
+int
+main (int argc, char **argv)
+{
+	GSettings *settings;<--- Shadow variable
+	Display *xdisplay;
+	G_GNUC_UNUSED int x_fd;
+	Window selection_owner;
+	Atom xatom;
+
+	bindtextdomain (GETTEXT_PACKAGE, MATELOCALEDIR);
+	bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
+	textdomain (GETTEXT_PACKAGE);
+
+	gtk_init (&argc, &argv);
+
+	if (g_strcmp0 (g_get_real_name (), "root") == 0) {
+		g_warning ("mate-user-share cannot be started as root for security reasons.");
+		return 1;
+	}
+
+	signal (SIGPIPE, SIG_IGN);
+	signal (SIGINT, cleanup_handler);
+	signal (SIGHUP, cleanup_handler);
+	signal (SIGTERM, cleanup_handler);
+
+	xdisplay = GDK_DISPLAY_XDISPLAY (gdk_display_get_default ());
+	if (xdisplay == NULL) {
+		g_warning ("Can't open display");
+		return 1;
+	}
+
+	xatom = XInternAtom (xdisplay, "_MATE_USER_SHARE", FALSE);
+	selection_owner = XGetSelectionOwner (xdisplay, xatom);
+
+	if (selection_owner != None) {
+		/* There is an owner already, quit */
+		return 1;
+	}
+
+	selection_owner = XCreateSimpleWindow (xdisplay,
+					       RootWindow (xdisplay, 0),
+					       0, 0, 1, 1,
+					       0, 0, 0);
+	XSetSelectionOwner (xdisplay, xatom, selection_owner, CurrentTime);
+
+	if (XGetSelectionOwner (xdisplay, xatom) != selection_owner) {
+		/* Didn't get the selection */
+		return 1;
+	}
+
+	migrate_old_configuration ();
+
+	if (!file_sharing_enabled ())
+		return 1;
+
+	settings = g_settings_new (GSETTINGS_SCHEMA);
+
+	x_fd = ConnectionNumber (xdisplay);
+	XSetIOErrorHandler (x_io_error_handler);
+
+	if (http_init () == FALSE)
+		return 1;
+#ifdef HAVE_BLUETOOTH
+	if (obexftp_init () == FALSE)
+		return 1;
+	if (obexpush_init () == FALSE)
+		return 1;
+#endif /* HAVE_BLUETOOTH */
+
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_ENABLED,
+			     G_CALLBACK (file_sharing_enabled_changed), NULL);
+
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_REQUIRE_PASSWORD,
+			     G_CALLBACK (require_password_changed), NULL);
+
+#ifdef HAVE_BLUETOOTH
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_ENABLED,
+			     G_CALLBACK (file_sharing_bluetooth_enabled_changed), NULL);
+
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_ALLOW_WRITE,
+			     G_CALLBACK (file_sharing_bluetooth_allow_write_changed), NULL);
+
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_REQUIRE_PAIRING,
+			     G_CALLBACK (file_sharing_bluetooth_require_pairing_changed), NULL);
+
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED,
+			     G_CALLBACK (file_sharing_bluetooth_obexpush_enabled_changed), NULL);
+
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_ACCEPT_FILES,
+			     G_CALLBACK (file_sharing_bluetooth_obexpush_accept_files_changed), NULL);
+
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_NOTIFY,
+			     G_CALLBACK (file_sharing_bluetooth_obexpush_notify_changed), NULL);
+
+	bluez_init ();
+	session_init ();
+#endif /* HAVE_BLUETOOTH */
+
+	/* Initial setting */
+	file_sharing_enabled_changed (settings, NULL, NULL);
+#ifdef HAVE_BLUETOOTH
+	file_sharing_bluetooth_enabled_changed (settings, NULL, NULL);
+	file_sharing_bluetooth_obexpush_accept_files_changed (settings, NULL, NULL);
+	file_sharing_bluetooth_obexpush_notify_changed (settings, NULL, NULL);
+	file_sharing_bluetooth_obexpush_enabled_changed (settings, NULL, NULL);
+#endif /* HAVE_BLUETOOTH */
+
+	gtk_main ();
+
+	return 0;
+}
+
+
+
+ +
+ + diff --git a/2022-10-29-134846-0734-cppcheck@fcf648868871_master/index.html b/2022-10-29-134846-0734-cppcheck@fcf648868871_master/index.html new file mode 100644 index 0000000..b780b4e --- /dev/null +++ b/2022-10-29-134846-0734-cppcheck@fcf648868871_master/index.html @@ -0,0 +1,212 @@ + + + + + + Cppcheck - HTML report - mate-user-share + + + + + +
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + +
LineIdCWESeverityMessage
missingIncludeinformationCppcheck cannot find all the include files (use --check-config for details)
src/file-share-properties.c
83variableScope398styleThe scope of the variable 'password' can be reduced.
106unusedVariable563styleUnused variable: accept_setting
621variableScope398styleThe scope of the variable 'window' can be reduced.
src/http.c
115variableScope398styleThe scope of the variable 'host_name' can be reduced.
src/share-extension.c
62variableScope398styleThe scope of the variable 'dialog' can be reduced.
src/user_share.c
175constParameter398styleParameter 'gobject' can be declared with const
392shadowVariable398styleLocal variable 'settings' shadows outer variable
+
+ +
+ + diff --git a/2022-10-29-134846-0734-cppcheck@fcf648868871_master/stats.html b/2022-10-29-134846-0734-cppcheck@fcf648868871_master/stats.html new file mode 100644 index 0000000..93d49a4 --- /dev/null +++ b/2022-10-29-134846-0734-cppcheck@fcf648868871_master/stats.html @@ -0,0 +1,170 @@ + + + + + + Cppcheck - HTML report - mate-user-share + + + + + +
+ + + +
+

Top 10 files for style severity, total findings: 7
+   3  src/file-share-properties.c
+   2  src/user_share.c
+   1  src/share-extension.c
+   1  src/http.c
+

+ +
+ +
+ + diff --git a/2022-10-29-134846-0734-cppcheck@fcf648868871_master/style.css b/2022-10-29-134846-0734-cppcheck@fcf648868871_master/style.css new file mode 100644 index 0000000..3897bfa --- /dev/null +++ b/2022-10-29-134846-0734-cppcheck@fcf648868871_master/style.css @@ -0,0 +1,177 @@ + +body { + font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif; + font-size: 13px; + line-height: 1.5; + height: 100%; + margin: 0; +} + +#wrapper { + position: fixed; + height: 100vh; + width: 100vw; + display: grid; + grid-template-rows: fit-content(8rem) auto fit-content(8rem); + grid-template-columns: fit-content(25%) 1fr; + grid-template-areas: + "header header" + "menu content" + "footer footer"; +} + +h1 { + margin: 0 0 8px -2px; + font-size: 175%; +} + +.header { + padding: 0 0 5px 15px; + grid-area: header; + border-bottom: thin solid #aaa; +} + +.footer { + grid-area: footer; + border-top: thin solid #aaa; + font-size: 85%; + +} + +.footer > p { + margin: 4px; +} + +#menu, +#menu_index { + grid-area: menu; + text-align: left; + overflow: auto; + padding: 0 23px 15px 15px; + border-right: thin solid #aaa; + min-width: 200px; +} + +#menu > a { + display: block; + margin-left: 10px; + font-size: 12px; +} + +#content, +#content_index { + grid-area: content; + padding: 0px 5px 15px 15px; + overflow: auto; +} + +label { + white-space: nowrap; +} + +label.checkBtn.disabled { + color: #606060; + background: #e0e0e0; + font-style: italic; +} + +label.checkBtn, input[type="text"] { + border: 1px solid grey; + border-radius: 4px; + box-shadow: 1px 1px inset; + padding: 1px 5px; +} + +label.checkBtn { + white-space: nowrap; + background: #ccddff; +} + +label.unchecked { + background: #eff8ff; + box-shadow: 1px 1px 1px; +} + +label.checkBtn:hover, label.unchecked:hover{ + box-shadow: 0 0 2px; +} + +label.disabled:hover { + box-shadow: 1px 1px inset; +} + +label.checkBtn > input { + display:none; +} + +.summaryTable { + width: 100%; +} + +table.summaryTable td { padding: 0 5px 0 5px; } + +.statHeader, .severityHeader { + font-weight: bold; +} + +.warning { + background-color: #ffffa7; +} + +.error { + background-color: #ffb7b7; +} + +.error2 { + background-color: #faa; + display: inline-block; + margin-left: 4px; +} + +.inconclusive { + background-color: #b6b6b4; +} + +.inconclusive2 { + background-color: #b6b6b4; + display: inline-block; + margin-left: 4px; +} + +.verbose { + display: inline-block; + vertical-align: top; + cursor: help; +} + +.verbose .content { + display: none; + position: absolute; + padding: 10px; + margin: 4px; + max-width: 40%; + white-space: pre-wrap; + border: 1px solid #000; + background-color: #ffffcc; + cursor: auto; +} + +.highlight .hll { + padding: 1px; +} + +.highlighttable { + background-color: #fff; + position: relative; + margin: -10px; +} + +.linenos { + border-right: thin solid #aaa; + color: #d3d3d3; + padding-right: 6px; +} + +.id-filtered, .severity-filtered, .file-filtered, .tool-filtered, .text-filtered { + visibility: collapse; +} diff --git a/2022-10-30-110836-1803-cppcheck@3a4fb1c0ec7f_master/0.html b/2022-10-30-110836-1803-cppcheck@3a4fb1c0ec7f_master/0.html new file mode 100644 index 0000000..7a4ab90 --- /dev/null +++ b/2022-10-30-110836-1803-cppcheck@3a4fb1c0ec7f_master/0.html @@ -0,0 +1,1567 @@ + + + + + + Cppcheck - HTML report - mate-user-share + + + + + +
+ + + +
+
  1
+  2
+  3
+  4
+  5
+  6
+  7
+  8
+  9
+ 10
+ 11
+ 12
+ 13
+ 14
+ 15
+ 16
+ 17
+ 18
+ 19
+ 20
+ 21
+ 22
+ 23
+ 24
+ 25
+ 26
+ 27
+ 28
+ 29
+ 30
+ 31
+ 32
+ 33
+ 34
+ 35
+ 36
+ 37
+ 38
+ 39
+ 40
+ 41
+ 42
+ 43
+ 44
+ 45
+ 46
+ 47
+ 48
+ 49
+ 50
+ 51
+ 52
+ 53
+ 54
+ 55
+ 56
+ 57
+ 58
+ 59
+ 60
+ 61
+ 62
+ 63
+ 64
+ 65
+ 66
+ 67
+ 68
+ 69
+ 70
+ 71
+ 72
+ 73
+ 74
+ 75
+ 76
+ 77
+ 78
+ 79
+ 80
+ 81
+ 82
+ 83
+ 84
+ 85
+ 86
+ 87
+ 88
+ 89
+ 90
+ 91
+ 92
+ 93
+ 94
+ 95
+ 96
+ 97
+ 98
+ 99
+100
+101
+102
+103
+104
+105
+106
+107
+108
+109
+110
+111
+112
+113
+114
+115
+116
+117
+118
+119
+120
+121
+122
+123
+124
+125
+126
+127
+128
+129
+130
+131
+132
+133
+134
+135
+136
+137
+138
+139
+140
+141
+142
+143
+144
+145
+146
+147
+148
+149
+150
+151
+152
+153
+154
+155
+156
+157
+158
+159
+160
+161
+162
+163
+164
+165
+166
+167
+168
+169
+170
+171
+172
+173
+174
+175
+176
+177
+178
+179
+180
+181
+182
+183
+184
+185
+186
+187
+188
+189
+190
+191
+192
+193
+194
+195
+196
+197
+198
+199
+200
+201
+202
+203
+204
+205
+206
+207
+208
+209
+210
+211
+212
+213
+214
+215
+216
+217
+218
+219
+220
+221
+222
+223
+224
+225
+226
+227
+228
+229
+230
+231
+232
+233
+234
+235
+236
+237
+238
+239
+240
+241
+242
+243
+244
+245
+246
+247
+248
+249
+250
+251
+252
+253
+254
+255
+256
+257
+258
+259
+260
+261
+262
+263
+264
+265
+266
+267
+268
+269
+270
+271
+272
+273
+274
+275
+276
+277
+278
+279
+280
+281
+282
+283
+284
+285
+286
+287
+288
+289
+290
+291
+292
+293
+294
+295
+296
+297
+298
+299
+300
+301
+302
+303
+304
+305
+306
+307
+308
+309
+310
+311
+312
+313
+314
+315
+316
+317
+318
+319
+320
+321
+322
+323
+324
+325
+326
+327
+328
+329
+330
+331
+332
+333
+334
+335
+336
+337
+338
+339
+340
+341
+342
+343
+344
+345
+346
+347
+348
+349
+350
+351
+352
+353
+354
+355
+356
+357
+358
+359
+360
+361
+362
+363
+364
+365
+366
+367
+368
+369
+370
+371
+372
+373
+374
+375
+376
+377
+378
+379
+380
+381
+382
+383
+384
+385
+386
+387
+388
+389
+390
+391
+392
+393
+394
+395
+396
+397
+398
+399
+400
+401
+402
+403
+404
+405
+406
+407
+408
+409
+410
+411
+412
+413
+414
+415
+416
+417
+418
+419
+420
+421
+422
+423
+424
+425
+426
+427
+428
+429
+430
+431
+432
+433
+434
+435
+436
+437
+438
+439
+440
+441
+442
+443
+444
+445
+446
+447
+448
+449
+450
+451
+452
+453
+454
+455
+456
+457
+458
+459
+460
+461
+462
+463
+464
+465
+466
+467
+468
+469
+470
+471
+472
+473
+474
+475
+476
+477
+478
+479
+480
+481
+482
+483
+484
+485
+486
+487
+488
+489
+490
+491
+492
+493
+494
+495
+496
+497
+498
+499
+500
+501
+502
+503
+504
+505
+506
+507
+508
+509
+510
+511
+512
+513
+514
+515
+516
+517
+518
+519
+520
+521
+522
+523
+524
+525
+526
+527
+528
+529
+530
+531
+532
+533
+534
+535
+536
+537
+538
+539
+540
+541
+542
+543
+544
+545
+546
+547
+548
+549
+550
+551
+552
+553
+554
+555
+556
+557
+558
+559
+560
+561
+562
+563
+564
+565
+566
+567
+568
+569
+570
+571
+572
+573
+574
+575
+576
+577
+578
+579
+580
+581
+582
+583
+584
+585
+586
+587
+588
+589
+590
+591
+592
+593
+594
+595
+596
+597
+598
+599
+600
+601
+602
+603
+604
+605
+606
+607
+608
+609
+610
+611
+612
+613
+614
+615
+616
+617
+618
+619
+620
+621
+622
+623
+624
+625
+626
+627
+628
+629
+630
+631
+632
+633
+634
+635
+636
+637
+638
+639
+640
+641
+642
+643
+644
+645
+646
+647
+648
+649
+650
+651
+652
+653
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
+
+/*
+ *  Copyright (C) 2004 Red Hat, Inc.
+ * Copyright (C) 2012-2021 MATE Developers
+ *
+ *  Caja is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU General Public License as
+ *  published by the Free Software Foundation; either version 2 of the
+ *  License, or (at your option) any later version.
+ *
+ *  Caja is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  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
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ *  Authors: Alexander Larsson <alexl@redhat.com>
+ *
+ */
+
+#include "config.h"
+
+#include <string.h>
+#include <stdio.h>
+
+#include <gtk/gtk.h>
+#include <glib/gi18n.h>
+#include <gio/gio.h>
+
+#include "user_share-private.h"
+
+#define REALM "Please log in as the user guest"
+#define USER "guest"
+#define GSETTINGS_SCHEMA "org.mate.FileSharing"
+#define GSETTINGS_KEY_FILE_SHARING_ENABLED "enabled"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_ENABLED "bluetooth-enabled"
+#define GSETTINGS_KEY_FILE_SHARING_REQUIRE_PASSWORD "require-password"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_ALLOW_WRITE "bluetooth-allow-write"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_REQUIRE_PAIRING "bluetooth-require-pairing"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED "bluetooth-obexpush-enabled"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_ACCEPT_FILES "bluetooth-accept-files"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_NOTIFY "bluetooth-notify"
+
+static GtkBuilder* builder;
+static GSettings* settings;
+
+
+static void
+write_out_password (const char *password)
+{
+    char *to_hash;
+    char *ascii_digest;
+    char *line;
+    char *filename;
+    FILE *file;
+
+    to_hash = g_strdup_printf ("%s:%s:%s", USER, REALM, password);
+    ascii_digest = g_compute_checksum_for_string (G_CHECKSUM_MD5, to_hash, strlen (to_hash));
+    g_free (to_hash);
+    line = g_strdup_printf ("%s:%s:%s\n", USER, REALM, ascii_digest);
+    g_free (ascii_digest);
+
+    filename = g_build_filename (g_get_user_config_dir (), "user-share", "passwd", NULL);
+
+    file = fopen (filename, "w");
+    if (file != NULL) {
+	fwrite (line, strlen (line), 1, file);
+	fclose (file);
+    }
+
+    g_free (filename);
+    g_free (line);
+}
+
+static void
+flush_password (void)
+{
+    GtkWidget *password_entry;
+    const char *password;
+
+    password_entry = GTK_WIDGET (gtk_builder_get_object (builder, "password_entry"));
+
+    if (g_object_get_data (G_OBJECT( password_entry), "user_edited")) {
+	password = gtk_entry_get_text (GTK_ENTRY (password_entry));
+	if (password != NULL && password[0] != 0)
+	    write_out_password (password);
+    }
+}
+
+
+static void
+update_ui (void)
+{
+    GSettings *settings;
+    gboolean enabled;
+#ifdef HAVE_BLUETOOTH
+    gboolean bluetooth_enabled, bluetooth_write_enabled, require_pairing_enabled;
+    gboolean bluetooth_obexpush_enabled, bluetooth_obexpush_notify;
+#endif /* HAVE_BLUETOOTH */
+    char *str;
+    PasswordSetting password_setting;
+    AcceptSetting accept_setting;<--- Unused variable: accept_setting
+    GtkWidget *check;
+    GtkWidget *password_combo;
+    GtkWidget *password_entry;
+#ifdef HAVE_BLUETOOTH
+    GtkWidget *vbox_share_bluetooth;
+    GtkWidget *vbox_receive_bluetooth;
+    GtkWidget *bluetooth_check;
+    GtkWidget *allow_write_bluetooth_check;
+    GtkWidget *require_pairing_check;
+    GtkWidget *enable_obexpush_check;
+    GtkWidget *accept_obexpush_combo;
+    GtkWidget *notify_received_obexpush_check;
+#endif /* HAVE_BLUETOOTH */
+
+    settings = g_settings_new (GSETTINGS_SCHEMA);
+
+    enabled = g_settings_get_boolean (settings,
+				     FILE_SHARING_ENABLED);
+
+    str = g_settings_get_string (settings, FILE_SHARING_REQUIRE_PASSWORD);
+    password_setting = password_setting_from_string (str);
+    g_free (str);
+
+#ifdef HAVE_BLUETOOTH
+    bluetooth_enabled = g_settings_get_boolean (settings,
+    					       FILE_SHARING_BLUETOOTH_ENABLED);
+    bluetooth_write_enabled = g_settings_get_boolean (settings,
+						     FILE_SHARING_BLUETOOTH_ALLOW_WRITE);
+    require_pairing_enabled = g_settings_get_boolean (settings,
+    						     FILE_SHARING_BLUETOOTH_REQUIRE_PAIRING);
+    bluetooth_obexpush_enabled = g_settings_get_boolean (settings,
+    							FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED);
+    bluetooth_obexpush_notify = g_settings_get_boolean (settings,
+    						       FILE_SHARING_BLUETOOTH_OBEXPUSH_NOTIFY);
+
+    str = g_settings_get_string (settings, FILE_SHARING_BLUETOOTH_OBEXPUSH_ACCEPT_FILES);
+    accept_setting = accept_setting_from_string (str);
+    g_free (str);
+#endif /* HAVE_BLUETOOTH */
+
+    check = GTK_WIDGET (gtk_builder_get_object (builder, "enable_check"));
+    password_combo = GTK_WIDGET (gtk_builder_get_object (builder, "password_combo"));
+    password_entry = GTK_WIDGET (gtk_builder_get_object (builder, "password_entry"));
+#ifdef HAVE_BLUETOOTH
+    vbox_share_bluetooth = GTK_WIDGET (gtk_builder_get_object (builder, "vbox_share_bluetooth"));
+    vbox_receive_bluetooth = GTK_WIDGET (gtk_builder_get_object (builder, "vbox_receive_bluetooth"));
+    bluetooth_check = GTK_WIDGET (gtk_builder_get_object (builder, "enable_bluetooth_check"));
+    allow_write_bluetooth_check = GTK_WIDGET (gtk_builder_get_object (builder, "allow_write_bluetooth_check"));
+    require_pairing_check = GTK_WIDGET (gtk_builder_get_object (builder, "require_pairing_check"));
+    enable_obexpush_check = GTK_WIDGET (gtk_builder_get_object (builder, "enable_obexpush_check"));
+    accept_obexpush_combo = GTK_WIDGET (gtk_builder_get_object (builder, "accept_obexpush_combo"));
+    notify_received_obexpush_check = GTK_WIDGET (gtk_builder_get_object (builder, "notify_received_obexpush_check"));
+#endif /* HAVE_BLUETOOTH */
+
+    /* Network */
+    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (check), enabled);
+    gtk_widget_set_sensitive (password_combo, enabled);
+    gtk_widget_set_sensitive (password_entry, enabled && password_setting != PASSWORD_NEVER);
+
+    gtk_combo_box_set_active (GTK_COMBO_BOX (password_combo),
+			      password_setting);
+
+#ifdef HAVE_BLUETOOTH
+    /* Bluetooth ObexFTP */
+    gtk_widget_set_visible (vbox_share_bluetooth, TRUE);
+    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (bluetooth_check), bluetooth_enabled);
+    gtk_widget_set_sensitive (allow_write_bluetooth_check, bluetooth_enabled);
+    gtk_widget_set_sensitive (require_pairing_check, bluetooth_enabled);
+
+    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (allow_write_bluetooth_check),
+    				  bluetooth_write_enabled);
+    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (require_pairing_check),
+    				  require_pairing_enabled);
+
+    /* Bluetooth ObexPush */
+    gtk_widget_set_visible (vbox_receive_bluetooth, TRUE);
+    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (enable_obexpush_check), bluetooth_obexpush_enabled);
+    gtk_widget_set_sensitive (accept_obexpush_combo, bluetooth_obexpush_enabled);
+    gtk_widget_set_sensitive (notify_received_obexpush_check, bluetooth_obexpush_enabled);
+
+    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (notify_received_obexpush_check),
+    				  bluetooth_obexpush_notify);
+
+    gtk_combo_box_set_active (GTK_COMBO_BOX (accept_obexpush_combo),
+    			      accept_setting);
+#endif /* HAVE_BLUETOOTH */
+
+    g_object_unref (settings);
+}
+
+static void
+file_sharing_enabled_changed (GSettings *settings, gchar *key, gpointer data)
+{
+    update_ui ();
+}
+
+static void
+password_required_changed (GSettings *settings, gchar *key, gpointer data)
+{
+    update_ui ();
+}
+
+#ifdef HAVE_BLUETOOTH
+static void
+file_sharing_bluetooth_enabled_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	update_ui ();
+}
+
+static void
+file_sharing_bluetooth_allow_write_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	update_ui ();
+}
+
+static void
+file_sharing_bluetooth_require_pairing_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	update_ui ();
+}
+
+static void
+file_sharing_bluetooth_obexpush_enabled_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	update_ui ();
+}
+
+static void
+file_sharing_bluetooth_obexpush_accept_files_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	update_ui ();
+}
+
+static void
+file_sharing_bluetooth_obexpush_notify_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	update_ui ();
+}
+#endif /* HAVE_BLUETOOTH */
+
+static void
+password_combo_changed (GtkComboBox *combo_box)
+{
+    GSettings *settings;
+    guint setting;
+
+    setting = gtk_combo_box_get_active (combo_box);
+
+    settings = g_settings_new (GSETTINGS_SCHEMA) ;
+
+    g_settings_set_string (settings,
+			     FILE_SHARING_REQUIRE_PASSWORD,
+			     password_string_from_setting (setting));
+    g_object_unref (settings);
+}
+
+static void
+launch_share (void)
+{
+	if (!g_spawn_command_line_async (USER_SHARE_PROGRAM, NULL))
+		g_warning ("Unable to start mate-user-share program");
+}
+
+#ifdef HAVE_BLUETOOTH
+static void
+enable_bluetooth_check_toggled (GtkWidget *check)
+{
+	GSettings *settings;
+	gboolean enabled;
+
+	enabled = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check));
+
+	settings = g_settings_new (GSETTINGS_SCHEMA) ;
+
+	g_settings_set_boolean (settings,
+			       FILE_SHARING_BLUETOOTH_ENABLED,
+			       enabled);
+
+	g_object_unref (settings);
+
+	if (enabled != FALSE)
+		launch_share ();
+}
+#endif /* HAVE_BLUETOOTH */
+
+static void
+enable_check_toggled (GtkWidget *check)
+{
+	GSettings *settings;
+	gboolean enabled;
+
+	enabled = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check));
+
+	settings = g_settings_new (GSETTINGS_SCHEMA);
+
+	g_settings_set_boolean (settings,
+			       FILE_SHARING_ENABLED,
+			       enabled);
+
+	g_object_unref (settings);
+
+	if (enabled != FALSE)
+		launch_share ();
+}
+
+static void
+password_entry_changed (GtkEditable *editable)
+{
+	g_object_set_data (G_OBJECT (editable),
+			   "user_edited", GINT_TO_POINTER (1));
+	flush_password ();
+}
+
+#ifdef HAVE_BLUETOOTH
+static void
+bluetooth_allow_write_check_toggled (GtkWidget *check)
+{
+	GSettings *settings;
+	gboolean enabled;
+
+	enabled = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check));
+
+	settings = g_settings_new (GSETTINGS_SCHEMA) ;
+
+	g_settings_set_boolean (settings,
+			       FILE_SHARING_BLUETOOTH_ALLOW_WRITE,
+			       enabled);
+
+	g_object_unref (settings);
+}
+
+static void
+bluetooth_require_pairing_check_toggled (GtkWidget *check)
+{
+	GSettings *settings;
+	gboolean enabled;
+
+	enabled = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check));
+
+	settings = g_settings_new (GSETTINGS_SCHEMA) ;
+
+	g_settings_set_boolean (settings,
+			       FILE_SHARING_BLUETOOTH_REQUIRE_PAIRING,
+			       enabled);
+
+	g_object_unref (settings);
+}
+
+static void
+enable_obexpush_check_toggled (GtkWidget *check)
+{
+	GSettings *settings;
+	gboolean enabled;
+
+	enabled = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check));
+
+	settings = g_settings_new (GSETTINGS_SCHEMA) ;
+
+	g_settings_set_boolean (settings,
+			       FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED,
+			       enabled);
+
+	g_object_unref (settings);
+
+	if (enabled != FALSE)
+		launch_share ();
+}
+
+static void
+accept_obexpush_combo_changed (GtkComboBox *combo_box)
+{
+    GSettings *settings;
+    guint setting;
+
+    setting = gtk_combo_box_get_active (combo_box);
+
+    settings = g_settings_new (GSETTINGS_SCHEMA) ;
+
+    g_settings_set_string (settings,
+			     FILE_SHARING_BLUETOOTH_OBEXPUSH_ACCEPT_FILES,
+			     accept_string_from_setting (setting));
+    g_object_unref (settings);
+}
+
+static void
+notify_received_obexpush_check_toggled (GtkWidget *check)
+{
+	GSettings *settings;
+	gboolean enabled;
+
+	enabled = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check));
+
+	settings = g_settings_new (GSETTINGS_SCHEMA) ;
+
+	g_settings_set_boolean (settings,
+			       FILE_SHARING_BLUETOOTH_OBEXPUSH_NOTIFY,
+			       enabled);
+
+	g_object_unref (settings);
+}
+#endif /* HAVE_BLUETOOTH */
+
+static GtkWidget *
+error_dialog (const char *title,
+	      const char *reason,
+	      GtkWindow *parent)
+{
+	GtkWidget *error_dialog;
+
+	if (reason == NULL)
+		reason = _("No reason");
+
+	error_dialog =
+		gtk_message_dialog_new (parent,
+					GTK_DIALOG_MODAL,
+					GTK_MESSAGE_ERROR,
+					GTK_BUTTONS_OK,
+					"%s", title);
+	gtk_message_dialog_format_secondary_text
+		(GTK_MESSAGE_DIALOG (error_dialog), "%s", reason);
+
+	gtk_window_set_title (GTK_WINDOW (error_dialog), ""); /* as per HIG */
+	gtk_container_set_border_width (GTK_CONTAINER (error_dialog), 5);
+	gtk_dialog_set_default_response (GTK_DIALOG (error_dialog),
+					 GTK_RESPONSE_OK);
+	gtk_window_set_modal (GTK_WINDOW (error_dialog), TRUE);
+
+	return error_dialog;
+}
+
+static void
+help_button_clicked (GtkButton *button, GtkWidget *window)
+{
+	GError *error = NULL;
+
+	if (gtk_show_uri_on_window (GTK_WINDOW (window), "help:mate-user-share", gtk_get_current_event_time (), &error) == FALSE) {
+		GtkWidget *dialog;
+
+		dialog = error_dialog (_("Could not display the help contents."), error->message, GTK_WINDOW (window));
+		g_signal_connect (G_OBJECT (dialog), "response", G_CALLBACK
+				  (gtk_widget_destroy), error_dialog);
+		gtk_window_present (GTK_WINDOW (dialog));
+
+		g_error_free (error);
+	}
+}
+
+static GtkWidget *
+create_window (void)
+{
+    GError *error = NULL;
+    GSettings *settings;
+    GtkWidget *check;
+    GtkWidget *password_combo;
+    GtkWidget *password_entry;
+#ifdef HAVE_BLUETOOTH
+    GtkWidget *bluetooth_check;
+    GtkWidget *bluetooth_allow_write_check;
+    GtkWidget *require_pairing_check;
+    GtkWidget *enable_obexpush_check;
+    GtkWidget *accept_obexpush_combo;
+    GtkWidget *notify_received_obexpush_check;
+#endif /* HAVE_BLUETOOTH */
+    GtkWidget *window;
+    GtkListStore *store;
+    GtkCellRenderer *cell;
+    GtkTreeIter iter;
+
+    builder = gtk_builder_new ();
+    gtk_builder_add_from_file (builder, DATADIR"file-share-properties.ui", &error);
+
+    if (error) {
+      GtkWidget *dialog;
+
+      dialog = error_dialog (_("Could not build interface."), error->message, NULL);
+      gtk_dialog_run (GTK_DIALOG (dialog));
+      gtk_widget_destroy (dialog);
+
+      g_error_free (error);
+      return NULL;
+    }
+
+    window = GTK_WIDGET (gtk_builder_get_object (builder, "user_share_dialog"));
+
+    settings = g_settings_new (GSETTINGS_SCHEMA);
+
+    check = GTK_WIDGET (gtk_builder_get_object (builder, "enable_check"));
+    password_combo = GTK_WIDGET (gtk_builder_get_object (builder, "password_combo"));
+    password_entry = GTK_WIDGET (gtk_builder_get_object (builder, "password_entry"));
+#ifdef HAVE_BLUETOOTH
+    bluetooth_check = GTK_WIDGET (gtk_builder_get_object (builder, "enable_bluetooth_check"));
+    bluetooth_allow_write_check = GTK_WIDGET (gtk_builder_get_object (builder, "allow_write_bluetooth_check"));
+    require_pairing_check = GTK_WIDGET (gtk_builder_get_object (builder, "require_pairing_check"));
+    enable_obexpush_check = GTK_WIDGET (gtk_builder_get_object (builder, "enable_obexpush_check"));
+    accept_obexpush_combo = GTK_WIDGET (gtk_builder_get_object (builder, "accept_obexpush_combo"));
+    notify_received_obexpush_check = GTK_WIDGET (gtk_builder_get_object (builder, "notify_received_obexpush_check"));
+#endif /* HAVE_BLUETOOTH */
+
+    store = gtk_list_store_new (1, G_TYPE_STRING);
+    gtk_combo_box_set_model (GTK_COMBO_BOX (password_combo),
+			     GTK_TREE_MODEL (store));
+    cell = gtk_cell_renderer_text_new ();
+    gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (password_combo), cell, TRUE);
+    gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (password_combo), cell,
+				    "text", 0,
+				    NULL);
+
+    /* Keep in same order as enum */
+    gtk_list_store_append (store, &iter);
+    gtk_list_store_set (store, &iter, 0,
+			_("Never"), -1);
+    gtk_list_store_append (store, &iter);
+    gtk_list_store_set (store, &iter, 0,
+			_("When writing files"), -1);
+    gtk_list_store_append (store, &iter);
+    gtk_list_store_set (store, &iter, 0,
+			_("Always"), -1);
+    g_object_unref (store);
+
+    /* We can't read the password from the text, just set it to something */
+    gtk_entry_set_text (GTK_ENTRY (password_entry), "none");
+    g_object_set_data (G_OBJECT (password_entry),
+		       "user_edited", GINT_TO_POINTER (0));
+    g_signal_connect (password_entry,
+		      "changed", G_CALLBACK (password_entry_changed), NULL);
+
+#ifdef HAVE_BLUETOOTH
+    /* Accept files combo */
+    store = gtk_list_store_new (1, G_TYPE_STRING);
+    gtk_combo_box_set_model (GTK_COMBO_BOX (accept_obexpush_combo),
+			     GTK_TREE_MODEL (store));
+    cell = gtk_cell_renderer_text_new ();
+    gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (accept_obexpush_combo), cell, TRUE);
+    gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (accept_obexpush_combo), cell,
+				    "text", 0,
+				    NULL);
+
+    /* Keep in same order as enum */
+    gtk_list_store_append (store, &iter);
+    gtk_list_store_set (store, &iter, 0,
+			_("Always"), -1);
+    gtk_list_store_append (store, &iter);
+    gtk_list_store_set (store, &iter, 0,
+			_("Only for set up devices"), -1);
+    //FIXME implement
+#if 0
+    gtk_list_store_append (store, &iter);
+    gtk_list_store_set (store, &iter, 0,
+    			_("Ask"), -1);
+#endif
+    g_object_unref (store);
+#endif /* HAVE_BLUETOOTH */
+
+    g_signal_connect (check,
+		      "toggled", G_CALLBACK (enable_check_toggled), NULL);
+    g_signal_connect (password_combo,
+		      "changed", G_CALLBACK (password_combo_changed), NULL);
+#ifdef HAVE_BLUETOOTH
+    g_signal_connect (bluetooth_check,
+    		      "toggled", G_CALLBACK (enable_bluetooth_check_toggled), NULL);
+    g_signal_connect (bluetooth_allow_write_check,
+    		      "toggled", G_CALLBACK (bluetooth_allow_write_check_toggled), NULL);
+    g_signal_connect (require_pairing_check,
+    		      "toggled", G_CALLBACK (bluetooth_require_pairing_check_toggled), NULL);
+    g_signal_connect (enable_obexpush_check,
+    		      "toggled", G_CALLBACK (enable_obexpush_check_toggled), NULL);
+    g_signal_connect (accept_obexpush_combo,
+    		      "changed", G_CALLBACK (accept_obexpush_combo_changed), NULL);
+    g_signal_connect (notify_received_obexpush_check,
+    		      "toggled", G_CALLBACK (notify_received_obexpush_check_toggled), NULL);
+#endif /* HAVE_BLUETOOTH */
+
+    g_signal_connect_swapped (GTK_WIDGET (gtk_builder_get_object (builder, "close_button")),
+                              "clicked", G_CALLBACK (gtk_widget_destroy), window);
+    g_signal_connect (GTK_WIDGET (gtk_builder_get_object (builder, "help_button")),
+		      "clicked", G_CALLBACK (help_button_clicked),
+		      gtk_builder_get_object (builder, "user_share_dialog"));
+
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_ENABLED,
+			     G_CALLBACK (file_sharing_enabled_changed), NULL);
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_REQUIRE_PASSWORD,
+			     G_CALLBACK (password_required_changed), NULL);
+#ifdef HAVE_BLUETOOTH
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_ENABLED,
+			     G_CALLBACK (file_sharing_bluetooth_enabled_changed), NULL);
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_ALLOW_WRITE,
+			     G_CALLBACK (file_sharing_bluetooth_allow_write_changed), NULL);
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_REQUIRE_PAIRING,
+			     G_CALLBACK (file_sharing_bluetooth_require_pairing_changed), NULL);
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED,
+			     G_CALLBACK (file_sharing_bluetooth_obexpush_enabled_changed), NULL);
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_ACCEPT_FILES,
+			     G_CALLBACK (file_sharing_bluetooth_obexpush_accept_files_changed), NULL);
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_NOTIFY,
+			     G_CALLBACK (file_sharing_bluetooth_obexpush_notify_changed), NULL);
+#endif /* HAVE_BLUETOOTH */
+
+    update_ui ();
+
+    return window;
+}
+
+static void
+activate (GtkApplication *app)
+{
+    GList *list;
+    GtkWidget *window;
+
+    list = gtk_application_get_windows (app);
+
+    if (list) {
+        gtk_window_present (GTK_WINDOW (list->data));
+    } else {
+        window = create_window ();
+        gtk_window_set_application (GTK_WINDOW (window), app);
+        gtk_widget_show (window);
+    }
+}
+
+int
+main (int argc, char *argv[])
+{
+    GtkApplication *app;
+    gint status;
+
+    bindtextdomain (GETTEXT_PACKAGE, MATELOCALEDIR);
+    bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
+    textdomain (GETTEXT_PACKAGE);
+
+    app = gtk_application_new ("org.mate.user-share.properties",
+                               G_APPLICATION_FLAGS_NONE);
+    g_signal_connect (app, "activate", G_CALLBACK (activate), NULL);
+
+    status = g_application_run (G_APPLICATION (app), argc, argv);
+
+    g_object_unref (app);
+
+    return status;
+}
+
+
+
+ +
+ + diff --git a/2022-10-30-110836-1803-cppcheck@3a4fb1c0ec7f_master/1.html b/2022-10-30-110836-1803-cppcheck@3a4fb1c0ec7f_master/1.html new file mode 100644 index 0000000..6ca74fd --- /dev/null +++ b/2022-10-30-110836-1803-cppcheck@3a4fb1c0ec7f_master/1.html @@ -0,0 +1,1123 @@ + + + + + + Cppcheck - HTML report - mate-user-share + + + + + +
+ + + +
+
  1
+  2
+  3
+  4
+  5
+  6
+  7
+  8
+  9
+ 10
+ 11
+ 12
+ 13
+ 14
+ 15
+ 16
+ 17
+ 18
+ 19
+ 20
+ 21
+ 22
+ 23
+ 24
+ 25
+ 26
+ 27
+ 28
+ 29
+ 30
+ 31
+ 32
+ 33
+ 34
+ 35
+ 36
+ 37
+ 38
+ 39
+ 40
+ 41
+ 42
+ 43
+ 44
+ 45
+ 46
+ 47
+ 48
+ 49
+ 50
+ 51
+ 52
+ 53
+ 54
+ 55
+ 56
+ 57
+ 58
+ 59
+ 60
+ 61
+ 62
+ 63
+ 64
+ 65
+ 66
+ 67
+ 68
+ 69
+ 70
+ 71
+ 72
+ 73
+ 74
+ 75
+ 76
+ 77
+ 78
+ 79
+ 80
+ 81
+ 82
+ 83
+ 84
+ 85
+ 86
+ 87
+ 88
+ 89
+ 90
+ 91
+ 92
+ 93
+ 94
+ 95
+ 96
+ 97
+ 98
+ 99
+100
+101
+102
+103
+104
+105
+106
+107
+108
+109
+110
+111
+112
+113
+114
+115
+116
+117
+118
+119
+120
+121
+122
+123
+124
+125
+126
+127
+128
+129
+130
+131
+132
+133
+134
+135
+136
+137
+138
+139
+140
+141
+142
+143
+144
+145
+146
+147
+148
+149
+150
+151
+152
+153
+154
+155
+156
+157
+158
+159
+160
+161
+162
+163
+164
+165
+166
+167
+168
+169
+170
+171
+172
+173
+174
+175
+176
+177
+178
+179
+180
+181
+182
+183
+184
+185
+186
+187
+188
+189
+190
+191
+192
+193
+194
+195
+196
+197
+198
+199
+200
+201
+202
+203
+204
+205
+206
+207
+208
+209
+210
+211
+212
+213
+214
+215
+216
+217
+218
+219
+220
+221
+222
+223
+224
+225
+226
+227
+228
+229
+230
+231
+232
+233
+234
+235
+236
+237
+238
+239
+240
+241
+242
+243
+244
+245
+246
+247
+248
+249
+250
+251
+252
+253
+254
+255
+256
+257
+258
+259
+260
+261
+262
+263
+264
+265
+266
+267
+268
+269
+270
+271
+272
+273
+274
+275
+276
+277
+278
+279
+280
+281
+282
+283
+284
+285
+286
+287
+288
+289
+290
+291
+292
+293
+294
+295
+296
+297
+298
+299
+300
+301
+302
+303
+304
+305
+306
+307
+308
+309
+310
+311
+312
+313
+314
+315
+316
+317
+318
+319
+320
+321
+322
+323
+324
+325
+326
+327
+328
+329
+330
+331
+332
+333
+334
+335
+336
+337
+338
+339
+340
+341
+342
+343
+344
+345
+346
+347
+348
+349
+350
+351
+352
+353
+354
+355
+356
+357
+358
+359
+360
+361
+362
+363
+364
+365
+366
+367
+368
+369
+370
+371
+372
+373
+374
+375
+376
+377
+378
+379
+380
+381
+382
+383
+384
+385
+386
+387
+388
+389
+390
+391
+392
+393
+394
+395
+396
+397
+398
+399
+400
+401
+402
+403
+404
+405
+406
+407
+408
+409
+410
+411
+412
+413
+414
+415
+416
+417
+418
+419
+420
+421
+422
+423
+424
+425
+426
+427
+428
+429
+430
+431
+432
+433
+434
+435
+436
+437
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
+
+/*
+ *  Copyright (C) 2004-2008 Red Hat, Inc.
+ * Copyright (C) 2012-2021 MATE Developers
+ *
+ *  Caja is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU General Public License as
+ *  published by the Free Software Foundation; either version 2 of the
+ *  License, or (at your option) any later version.
+ *
+ *  Caja is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  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
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ *  Authors: Alexander Larsson <alexl@redhat.com>
+ *
+ */
+
+#include "config.h"
+
+#include <glib.h>
+#include <glib/gi18n.h>
+#include <X11/Xlib.h>
+
+#include <gio/gio.h>
+
+#include <stdarg.h>
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <signal.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <sys/stat.h>
+
+#ifdef HAVE_SELINUX
+#include <selinux/selinux.h>
+#endif
+
+#include "user_share-common.h"
+#include "user_share-private.h"
+#include "http.h"
+
+/* From avahi-common/domain.h */
+#define AVAHI_LABEL_MAX 64
+
+#define GSETTINGS_SCHEMA "org.mate.FileSharing"
+
+static pid_t httpd_pid = 0;
+
+static int
+get_port (void)
+{
+	int sock;
+	struct sockaddr_in addr;
+	int reuse;
+	socklen_t len;
+
+	sock = socket (PF_INET, SOCK_STREAM, 0);
+	if (sock < 0) {
+		return -1;
+	}
+
+	memset (&addr, 0, sizeof (addr));
+	addr.sin_port = 0;
+	addr.sin_addr.s_addr = INADDR_ANY;
+	addr.sin_family = AF_INET;
+
+	reuse = 1;
+	setsockopt (sock, SOL_SOCKET, SO_REUSEADDR, &reuse, sizeof (reuse));
+	if (bind (sock, (struct sockaddr *)&addr, sizeof (addr)) == -1) {
+		close (sock);
+		return -1;
+	}
+
+	len = sizeof (addr);
+	if (getsockname (sock, (struct sockaddr *)&addr, &len) == -1) {
+		close (sock);
+		return -1;
+	}
+
+#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__APPLE__) || defined(__OpenBSD__)
+	/* XXX This exposes a potential race condition, but without this,
+	 * httpd will not start on the above listed platforms due to the fact
+	 * that SO_REUSEADDR is also needed when Apache binds to the listening
+	 * socket.  At this time, Apache does not support that socket option.
+	 */
+	close (sock);
+#endif
+	return ntohs (addr.sin_port);
+}
+
+static char *
+truncate_name (const char *name)
+{
+	const char *end;
+
+	end = g_utf8_find_prev_char (name, name + 64);
+	g_assert (end != NULL);
+	return g_strndup (name, end - name);
+}
+
+static char *
+get_share_name (void)
+{
+	static char *name = NULL;
+	const char *host_name;
+	char *str;
+
+	if (name == NULL) {
+		host_name = g_get_host_name ();
+		if (strcmp (host_name, "localhost") == 0) {
+			/* Translators: The %s will get filled in with the user name
+			   of the user, to form a genitive. If this is difficult to
+			   translate correctly so that it will work correctly in your
+			   language, you may use something equivalent to
+			   "Public files of %s", or leave out the %s altogether.
+			   In the latter case, please put "%.0s" somewhere in the string,
+			   which will match the user name string passed by the C code,
+			   but not put the user name in the final string. This is to
+			   avoid the warning that msgfmt might otherwise generate. */
+			name = g_strdup_printf (_("%s's public files"), g_get_user_name ());
+		} else {
+			/* Translators: This is similar to the string before, only it
+			   has the hostname in it too. */
+			name = g_strdup_printf (_("%s's public files on %s"),
+						g_get_user_name (),
+						host_name);
+		}
+
+	}
+	/* And truncate */
+	if (strlen (name) < AVAHI_LABEL_MAX)
+		return name;
+
+	str = truncate_name (name);
+	g_free (name);
+	name = str;
+
+	return name;
+}
+
+static void
+ensure_conf_dir (void)
+{
+	char *dirname;
+
+	dirname = g_build_filename (g_get_user_config_dir (), "user-share", NULL);
+	g_mkdir_with_parents (dirname, 0755);
+	g_free (dirname);
+}
+
+static void
+httpd_child_setup (gpointer user_data)
+{
+#ifdef HAVE_SELINUX
+	char *mycon;
+	/* If selinux is enabled, avoid transitioning to the httpd_t context,
+	   as this normally means you can't read the users homedir. */
+	if (is_selinux_enabled()) {
+		if (getcon (&mycon) < 0) {
+			abort ();
+		}
+		if (setexeccon (mycon) < 0)
+			abort ();
+		freecon (mycon);
+	}
+#endif
+}
+
+static const char *known_httpd_locations [] = {
+	HTTPD_PROGRAM,
+	"/usr/sbin/httpd",
+	"/usr/sbin/httpd2",
+	"/usr/sbin/apache2",
+	NULL
+};
+
+static char*
+get_httpd_program (void)
+{
+	int i;
+
+	for (i = 0; known_httpd_locations[i]; i++) {
+		if (known_httpd_locations[i][0] == '\0') {
+			/* empty string as first element, happens when
+			 * configured --with-httpd=auto */
+			continue;
+		}
+		if (g_file_test (known_httpd_locations[i], G_FILE_TEST_IS_EXECUTABLE)
+				&& ! g_file_test (known_httpd_locations[i], G_FILE_TEST_IS_DIR)) {
+			return g_strdup (known_httpd_locations[i]);
+		}
+	}
+	return NULL;
+}
+
+static const char *known_httpd_modules_locations [] = {
+	HTTPD_MODULES_PATH,
+	"/etc/httpd/modules",
+	"/usr/lib/apache2/modules",
+	NULL
+};
+
+static gchar*
+get_httpd_modules_path (void)
+{
+	int i;
+
+	for (i = 0; known_httpd_modules_locations[i]; i++) {
+		if (known_httpd_modules_locations[i][0] == '\0') {
+			/* empty string as first element, happens when
+			 * configured --with-httpd=auto */
+			continue;
+		}
+		if (g_file_test (known_httpd_modules_locations[i], G_FILE_TEST_IS_EXECUTABLE)
+				&& g_file_test (known_httpd_modules_locations[i], G_FILE_TEST_IS_DIR)) {
+			return g_strdup (known_httpd_modules_locations[i]);
+		}
+	}
+	return NULL;
+}
+
+static GRegex *version_regex = NULL;
+
+static char*
+get_httpd_config (const char *httpd_program)
+{
+	gchar *standard_output;
+	gchar *cmd_line;
+	GMatchInfo *match_info;
+	gchar *version_number = NULL;
+	gchar *config;
+
+	cmd_line = g_strdup_printf ("%s -v", httpd_program);
+	if (! g_spawn_command_line_sync (cmd_line, &standard_output, NULL, NULL, NULL)) {
+		g_free (cmd_line);
+		return NULL;
+	}
+	g_free (cmd_line);
+
+	if (version_regex == NULL) {
+		version_regex = g_regex_new ("\\d\\.\\d", 0, 0, NULL);
+	}
+
+	if (g_regex_match (version_regex, standard_output, 0, &match_info)) {
+		while (g_match_info_matches (match_info)) {
+			version_number = g_match_info_fetch (match_info, 0);
+			break;
+		}
+		g_match_info_free (match_info);
+		g_free (standard_output);
+	} else {
+		/* Failed to parse httpd version number */
+		g_warning ("Could not parse '%s' as a version for httpd", standard_output);
+		g_free (standard_output);
+		/* assume it is 2.2 */
+		version_number = g_strdup ("2.2");
+	}
+
+	config = g_strdup_printf (HTTPD_CONFIG_TEMPLATE, version_number);
+	g_free (version_number);
+
+	return config;
+}
+
+static gboolean
+spawn_httpd (int port, pid_t *pid_out)
+{
+	char *free1, *free2, *free3, *free4, *free5, *free6, *free7, *free8, *free9;
+	gboolean res;
+	char *argv[10];
+	char *env[10];
+	int i;
+	gint status;
+	char *pid_filename;
+	char *pidfile;
+	GError *error;
+	gboolean got_pidfile;
+	GSettings *settings;
+	char *str;
+	char *public_dir;
+
+	public_dir = lookup_public_dir ();
+	ensure_conf_dir ();
+
+	i = 0;
+	free1 = argv[i++] = get_httpd_program ();
+	if (argv[0] == NULL) {
+		fprintf (stderr, "error finding httpd server\n");
+		return FALSE;
+	}
+
+	argv[i++] = "-f";
+	free2 = argv[i++] = get_httpd_config (argv[0]);
+	argv[i++] = "-C";
+	free3 = argv[i++] = g_strdup_printf ("Listen %d", port);
+
+	settings = g_settings_new (GSETTINGS_SCHEMA);
+	str = g_settings_get_string (settings,
+				       FILE_SHARING_REQUIRE_PASSWORD);
+
+	if (str && strcmp (str, "never") == 0) {
+		/* Do nothing */
+	} else if (str && strcmp (str, "on_write") == 0){
+		argv[i++] = "-D";
+		argv[i++] = "RequirePasswordOnWrite";
+	} else {
+		/* always, or safe fallback */
+		argv[i++] = "-D";
+		argv[i++] = "RequirePasswordAlways";
+	}
+	g_free (str);
+	g_object_unref (settings);
+
+	argv[i] = NULL;
+
+	i = 0;
+	free4 = env[i++] = g_strdup_printf ("HOME=%s", g_get_home_dir());
+	free5 = env[i++] = g_strdup_printf ("XDG_PUBLICSHARE_DIR=%s", public_dir);
+	free6 = env[i++] = g_strdup_printf ("XDG_CONFIG_HOME=%s", g_get_user_config_dir ());
+	free7 = env[i++] = g_strdup_printf ("GUS_SHARE_NAME=%s", get_share_name ());
+	free8 = env[i++] = g_strdup_printf ("GUS_LOGIN_LABEL=%s", "Please log in as the user guest");
+	free9 = env[i++] = g_strdup_printf ("HTTP_MODULES_PATH=%s",get_httpd_modules_path ());
+	env[i++] = "LANG=C";
+	env[i] = NULL;
+
+	pid_filename = g_build_filename (g_get_user_config_dir (), "user-share", "pid", NULL);
+
+	/* Remove pid file before spawning to avoid races with child and old pidfile */
+	unlink (pid_filename);
+
+	error = NULL;
+	res = g_spawn_sync (g_get_home_dir(),
+			    argv, env, 0,
+			    httpd_child_setup, NULL,
+			    NULL, NULL,
+			    &status,
+			    &error);
+	g_free (free1);
+	g_free (free2);
+	g_free (free3);
+	g_free (free4);
+	g_free (free5);
+	g_free (free6);
+	g_free (free7);
+	g_free (free8);
+	g_free (free9);
+	g_free (public_dir);
+
+	if (!res) {
+		fprintf (stderr, "error spawning httpd: %s\n",
+			 error->message);
+		g_error_free (error);
+		g_free (pid_filename);
+		return FALSE;
+	}
+
+	if (status != 0) {
+		g_free (pid_filename);
+		return FALSE;
+	}
+
+	got_pidfile = FALSE;
+	error = NULL;
+	for (i = 0; i < 5; i++) {
+		if (error != NULL)
+			g_error_free (error);
+		error = NULL;
+		if (g_file_get_contents (pid_filename, &pidfile, NULL, &error)) {
+			got_pidfile = TRUE;
+			*pid_out = atoi (pidfile);
+			g_free (pidfile);
+			break;
+		}
+		sleep (1);
+	}
+
+	g_free (pid_filename);
+
+	if (!got_pidfile) {
+		fprintf (stderr, "error opening httpd pidfile: %s\n", error->message);
+		g_error_free (error);
+		return FALSE;
+	}
+	return TRUE;
+}
+
+static void
+kill_httpd (void)
+{
+	if (httpd_pid != 0) {
+		kill (httpd_pid, SIGTERM);
+
+		/* Allow child time to die, we can't waitpid, because its
+		   not a direct child */
+		sleep (1);
+	}
+	httpd_pid = 0;
+}
+
+void
+http_up (void)
+{
+	guint port;
+
+	port = get_port ();
+	if (!spawn_httpd (port, &httpd_pid)) {
+		fprintf (stderr, "spawning httpd failed\n");
+	}
+}
+
+void
+http_down (void)
+{
+	kill_httpd ();
+}
+
+gboolean
+http_init (void)
+{
+	return TRUE;
+}
+
+pid_t
+http_get_pid (void)
+{
+	return httpd_pid;
+}
+
+
+
+ +
+ + diff --git a/2022-10-30-110836-1803-cppcheck@3a4fb1c0ec7f_master/2.html b/2022-10-30-110836-1803-cppcheck@3a4fb1c0ec7f_master/2.html new file mode 100644 index 0000000..1682147 --- /dev/null +++ b/2022-10-30-110836-1803-cppcheck@3a4fb1c0ec7f_master/2.html @@ -0,0 +1,833 @@ + + + + + + Cppcheck - HTML report - mate-user-share + + + + + +
+ + + +
+
  1
+  2
+  3
+  4
+  5
+  6
+  7
+  8
+  9
+ 10
+ 11
+ 12
+ 13
+ 14
+ 15
+ 16
+ 17
+ 18
+ 19
+ 20
+ 21
+ 22
+ 23
+ 24
+ 25
+ 26
+ 27
+ 28
+ 29
+ 30
+ 31
+ 32
+ 33
+ 34
+ 35
+ 36
+ 37
+ 38
+ 39
+ 40
+ 41
+ 42
+ 43
+ 44
+ 45
+ 46
+ 47
+ 48
+ 49
+ 50
+ 51
+ 52
+ 53
+ 54
+ 55
+ 56
+ 57
+ 58
+ 59
+ 60
+ 61
+ 62
+ 63
+ 64
+ 65
+ 66
+ 67
+ 68
+ 69
+ 70
+ 71
+ 72
+ 73
+ 74
+ 75
+ 76
+ 77
+ 78
+ 79
+ 80
+ 81
+ 82
+ 83
+ 84
+ 85
+ 86
+ 87
+ 88
+ 89
+ 90
+ 91
+ 92
+ 93
+ 94
+ 95
+ 96
+ 97
+ 98
+ 99
+100
+101
+102
+103
+104
+105
+106
+107
+108
+109
+110
+111
+112
+113
+114
+115
+116
+117
+118
+119
+120
+121
+122
+123
+124
+125
+126
+127
+128
+129
+130
+131
+132
+133
+134
+135
+136
+137
+138
+139
+140
+141
+142
+143
+144
+145
+146
+147
+148
+149
+150
+151
+152
+153
+154
+155
+156
+157
+158
+159
+160
+161
+162
+163
+164
+165
+166
+167
+168
+169
+170
+171
+172
+173
+174
+175
+176
+177
+178
+179
+180
+181
+182
+183
+184
+185
+186
+187
+188
+189
+190
+191
+192
+193
+194
+195
+196
+197
+198
+199
+200
+201
+202
+203
+204
+205
+206
+207
+208
+209
+210
+211
+212
+213
+214
+215
+216
+217
+218
+219
+220
+221
+222
+223
+224
+225
+226
+227
+228
+229
+230
+231
+232
+233
+234
+235
+236
+237
+238
+239
+240
+241
+242
+243
+244
+245
+246
+247
+248
+249
+250
+251
+252
+253
+254
+255
+256
+257
+258
+259
+260
+261
+262
+263
+264
+265
+266
+267
+268
+269
+270
+271
+272
+273
+274
+275
+276
+277
+278
+279
+280
+281
+282
+283
+284
+285
+286
+287
+288
+289
+290
+291
+292
/* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 8; tab-width: 8 -*-
+ *
+ * Copyright (C) 2003 Novell, Inc.
+ * Copyright (C) 2003-2004 Red Hat, Inc.
+ * Copyright (C) 2005 William Jon McCann <mccann@jhu.edu>
+ * Copyright (C) 2012-2021 MATE Developers
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * 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 Foundation, Inc., 51 Franklin St, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ *
+ */
+
+#include "config.h"
+
+#include <stdlib.h>
+#include <string.h>
+#include <glib/gi18n-lib.h>
+#include <gtk/gtk.h>
+#include <libcaja-extension/caja-menu-provider.h>
+#include <libcaja-extension/caja-location-widget-provider.h>
+
+#ifdef HAVE_BLUETOOTH
+#include <bluetooth-client.h>
+#endif
+
+#include "caja-share-bar.h"
+#include "user_share-common.h"
+
+#define CAJA_TYPE_USER_SHARE  (caja_user_share_get_type ())
+#define CAJA_USER_SHARE(o)    (G_TYPE_CHECK_INSTANCE_CAST ((o), CAJA_TYPE_USER_SHARE, CajaUserShare))
+#define CAJA_IS_USER_SHARE(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), CAJA_TYPE_USER_SHARE))
+
+typedef struct
+{
+        GObject              parent_slot;
+} CajaUserShare;
+
+typedef struct
+{
+        GObjectClass parent_slot;
+} CajaUserShareClass;
+
+static GType caja_user_share_get_type      (void);
+static void  caja_user_share_register_type (GTypeModule *module);
+
+static void
+launch_process (char **argv, GtkWindow *parent)
+{
+        GError *error;
+        GtkWidget *dialog;
+
+        error = NULL;
+        if (!g_spawn_async (NULL,
+                            argv, NULL,
+                            0,
+                            NULL, NULL,
+                            NULL,
+                            &error)) {
+
+
+                dialog = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL, GTK_MESSAGE_WARNING,
+						 GTK_BUTTONS_OK, _("Unable to launch the Personal File Sharing preferences"));
+
+                gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog), "%s", error->message);
+
+                gtk_dialog_run (GTK_DIALOG (dialog));
+                gtk_widget_destroy (dialog);
+
+                g_error_free (error);
+        }
+}
+
+static void
+launch_prefs_on_window (GtkWindow *window)
+{
+        char *argv [2];
+
+        argv [0] = g_build_filename (BINDIR, "mate-file-share-properties", NULL);
+        argv [1] = NULL;
+
+        launch_process (argv, window);
+
+        g_free (argv [0]);
+}
+
+static void
+bar_response_cb (CajaShareBar *bar,
+                 gint response,
+                 gpointer         data)
+{
+        if (response == CAJA_SHARE_BAR_RESPONSE_PREFERENCES) {
+                launch_prefs_on_window (GTK_WINDOW (data));
+        }
+}
+
+#ifdef HAVE_BLUETOOTH
+static void
+downloads_bar_set_from_bluetooth_status (GtkWidget *bar)
+{
+	BluetoothClient *client;
+	gboolean bt_powered;
+
+	client = g_object_get_data (G_OBJECT (bar), "bluetooth-client");
+	g_object_get (G_OBJECT (client),
+		      "default-adapter-powered", &bt_powered,
+		      NULL);
+	gtk_widget_set_visible (bar, bt_powered);
+}
+
+static void
+default_adapter_powered_cb (GObject    *gobject,
+			    GParamSpec *pspec,
+			    GtkWidget  *bar)
+{
+	downloads_bar_set_from_bluetooth_status (bar);
+}
+#endif /* HAVE_BLUETOOTH */
+
+static GtkWidget *
+caja_user_share_get_location_widget (CajaLocationWidgetProvider *iface,
+                                         const char                     *uri,
+                                         GtkWidget                      *window)
+{
+	GFile             *file;
+	GtkWidget         *bar;
+	guint              i;
+	gboolean           enable = FALSE;
+	GFile             *home;
+#ifdef HAVE_BLUETOOTH
+	const GUserDirectory special_dirs[] = { G_USER_DIRECTORY_PUBLIC_SHARE, G_USER_DIRECTORY_DOWNLOAD };
+
+	gboolean is_dir[] = { FALSE, FALSE };
+#else
+	const GUserDirectory special_dirs[] = { G_USER_DIRECTORY_PUBLIC_SHARE };
+
+	gboolean is_dir[] = { FALSE };
+#endif /* HAVE_BLUETOOTH */
+	file = g_file_new_for_uri (uri);
+	home = g_file_new_for_path (g_get_home_dir ());
+
+	/* We don't show anything in $HOME */
+	if (g_file_equal (home, file)) {
+		g_object_unref (home);
+		g_object_unref (file);
+		return NULL;
+	}
+
+	g_object_unref (home);
+
+	for (i = 0; i < G_N_ELEMENTS (special_dirs); i++) {
+		GFile *dir;
+		dir = lookup_dir_with_fallback (special_dirs[i]);
+		if (g_file_equal (dir, file)) {
+			enable = TRUE;
+			is_dir[i] = TRUE;
+		}
+		g_object_unref (dir);
+	}
+
+	g_object_unref (file);
+
+	if (enable == FALSE)
+		return NULL;
+
+	if (is_dir[0] != FALSE) {
+#ifdef HAVE_BLUETOOTH
+		if (is_dir[1] != FALSE) {
+			bar = caja_share_bar_new (_("May be used to share or receive files"));
+		} else {
+			bar = caja_share_bar_new (_("May be shared over the network or Bluetooth"));
+		}
+#else
+		bar = caja_share_bar_new (_("May be shared over the network"));
+#endif /* HAVE_BLUETOOTH */
+	} else {
+#ifdef HAVE_BLUETOOTH
+		BluetoothClient *client;
+
+		bar = caja_share_bar_new (_("May be used to receive files over Bluetooth"));
+
+		gtk_widget_set_no_show_all (bar, TRUE);
+		client = bluetooth_client_new ();
+		g_object_set_data_full (G_OBJECT (bar), "bluetooth-client", client, g_object_unref);
+		g_signal_connect (G_OBJECT (client), "notify::default-adapter-powered",
+				  G_CALLBACK (default_adapter_powered_cb), bar);
+		downloads_bar_set_from_bluetooth_status (bar);
+#endif /* HAVE_BLUETOOTH */
+	}
+
+	g_signal_connect (bar, "response",
+			  G_CALLBACK (bar_response_cb),
+			  window);
+
+	gtk_widget_show_all (bar);
+
+	return bar;
+}
+
+static void
+caja_user_share_location_widget_provider_iface_init (CajaLocationWidgetProviderIface *iface)
+{
+        iface->get_widget = caja_user_share_get_location_widget;
+}
+
+static void
+caja_user_share_instance_init (CajaUserShare *share)
+{
+
+}
+
+static void
+caja_user_share_class_init (CajaUserShareClass *klass)
+{
+
+}
+
+static GType share_type = 0;
+
+static GType
+caja_user_share_get_type (void)
+{
+        return share_type;
+}
+
+static void
+caja_user_share_register_type (GTypeModule *module)
+{
+        static const GTypeInfo info = {
+                sizeof (CajaUserShareClass),
+                (GBaseInitFunc) NULL,
+                (GBaseFinalizeFunc) NULL,
+                (GClassInitFunc) caja_user_share_class_init,
+                NULL,
+                NULL,
+                sizeof (CajaUserShare),
+                0,
+                (GInstanceInitFunc) caja_user_share_instance_init,
+        };
+
+        static const GInterfaceInfo location_widget_provider_iface_info = {
+                (GInterfaceInitFunc) caja_user_share_location_widget_provider_iface_init,
+                NULL,
+                NULL
+        };
+
+        share_type = g_type_module_register_type (module,
+                                                 G_TYPE_OBJECT,
+                                                 "CajaUserShare",
+                                                 &info, 0);
+
+        g_type_module_add_interface (module,
+                                     share_type,
+                                     CAJA_TYPE_LOCATION_WIDGET_PROVIDER,
+                                     &location_widget_provider_iface_info);
+}
+
+void
+caja_module_initialize (GTypeModule *module)
+{
+        caja_user_share_register_type (module);
+        bindtextdomain (GETTEXT_PACKAGE, MATELOCALEDIR);
+        bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
+}
+
+void
+caja_module_shutdown (void)
+{
+}
+
+void
+caja_module_list_types (const GType **types,
+                            int          *num_types)
+{
+        static GType type_list [1];
+
+        type_list[0] = CAJA_TYPE_USER_SHARE;
+
+        *types = type_list;
+        *num_types = 1;
+}
+
+
+
+ +
+ + diff --git a/2022-10-30-110836-1803-cppcheck@3a4fb1c0ec7f_master/3.html b/2022-10-30-110836-1803-cppcheck@3a4fb1c0ec7f_master/3.html new file mode 100644 index 0000000..7bdfa00 --- /dev/null +++ b/2022-10-30-110836-1803-cppcheck@3a4fb1c0ec7f_master/3.html @@ -0,0 +1,1251 @@ + + + + + + Cppcheck - HTML report - mate-user-share + + + + + +
+ + + +
+
  1
+  2
+  3
+  4
+  5
+  6
+  7
+  8
+  9
+ 10
+ 11
+ 12
+ 13
+ 14
+ 15
+ 16
+ 17
+ 18
+ 19
+ 20
+ 21
+ 22
+ 23
+ 24
+ 25
+ 26
+ 27
+ 28
+ 29
+ 30
+ 31
+ 32
+ 33
+ 34
+ 35
+ 36
+ 37
+ 38
+ 39
+ 40
+ 41
+ 42
+ 43
+ 44
+ 45
+ 46
+ 47
+ 48
+ 49
+ 50
+ 51
+ 52
+ 53
+ 54
+ 55
+ 56
+ 57
+ 58
+ 59
+ 60
+ 61
+ 62
+ 63
+ 64
+ 65
+ 66
+ 67
+ 68
+ 69
+ 70
+ 71
+ 72
+ 73
+ 74
+ 75
+ 76
+ 77
+ 78
+ 79
+ 80
+ 81
+ 82
+ 83
+ 84
+ 85
+ 86
+ 87
+ 88
+ 89
+ 90
+ 91
+ 92
+ 93
+ 94
+ 95
+ 96
+ 97
+ 98
+ 99
+100
+101
+102
+103
+104
+105
+106
+107
+108
+109
+110
+111
+112
+113
+114
+115
+116
+117
+118
+119
+120
+121
+122
+123
+124
+125
+126
+127
+128
+129
+130
+131
+132
+133
+134
+135
+136
+137
+138
+139
+140
+141
+142
+143
+144
+145
+146
+147
+148
+149
+150
+151
+152
+153
+154
+155
+156
+157
+158
+159
+160
+161
+162
+163
+164
+165
+166
+167
+168
+169
+170
+171
+172
+173
+174
+175
+176
+177
+178
+179
+180
+181
+182
+183
+184
+185
+186
+187
+188
+189
+190
+191
+192
+193
+194
+195
+196
+197
+198
+199
+200
+201
+202
+203
+204
+205
+206
+207
+208
+209
+210
+211
+212
+213
+214
+215
+216
+217
+218
+219
+220
+221
+222
+223
+224
+225
+226
+227
+228
+229
+230
+231
+232
+233
+234
+235
+236
+237
+238
+239
+240
+241
+242
+243
+244
+245
+246
+247
+248
+249
+250
+251
+252
+253
+254
+255
+256
+257
+258
+259
+260
+261
+262
+263
+264
+265
+266
+267
+268
+269
+270
+271
+272
+273
+274
+275
+276
+277
+278
+279
+280
+281
+282
+283
+284
+285
+286
+287
+288
+289
+290
+291
+292
+293
+294
+295
+296
+297
+298
+299
+300
+301
+302
+303
+304
+305
+306
+307
+308
+309
+310
+311
+312
+313
+314
+315
+316
+317
+318
+319
+320
+321
+322
+323
+324
+325
+326
+327
+328
+329
+330
+331
+332
+333
+334
+335
+336
+337
+338
+339
+340
+341
+342
+343
+344
+345
+346
+347
+348
+349
+350
+351
+352
+353
+354
+355
+356
+357
+358
+359
+360
+361
+362
+363
+364
+365
+366
+367
+368
+369
+370
+371
+372
+373
+374
+375
+376
+377
+378
+379
+380
+381
+382
+383
+384
+385
+386
+387
+388
+389
+390
+391
+392
+393
+394
+395
+396
+397
+398
+399
+400
+401
+402
+403
+404
+405
+406
+407
+408
+409
+410
+411
+412
+413
+414
+415
+416
+417
+418
+419
+420
+421
+422
+423
+424
+425
+426
+427
+428
+429
+430
+431
+432
+433
+434
+435
+436
+437
+438
+439
+440
+441
+442
+443
+444
+445
+446
+447
+448
+449
+450
+451
+452
+453
+454
+455
+456
+457
+458
+459
+460
+461
+462
+463
+464
+465
+466
+467
+468
+469
+470
+471
+472
+473
+474
+475
+476
+477
+478
+479
+480
+481
+482
+483
+484
+485
+486
+487
+488
+489
+490
+491
+492
+493
+494
+495
+496
+497
+498
+499
+500
+501
+502
+503
+504
+505
+506
+507
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
+
+/*
+ *  Copyright (C) 2004-2008 Red Hat, Inc.
+ *  Copyright (C) 2012-2021 MATE Developers
+ *
+ *  Caja is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU General Public License as
+ *  published by the Free Software Foundation; either version 2 of the
+ *  License, or (at your option) any later version.
+ *
+ *  Caja is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  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
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ *  Authors: Alexander Larsson <alexl@redhat.com>
+ *
+ */
+
+#include "config.h"
+
+#include <gdk/gdkx.h>
+#include <gtk/gtk.h>
+#include <glib/gi18n.h>
+#include <glib/gstdio.h>
+#include <gio/gio.h>
+#include <X11/Xlib.h>
+
+#include "user_share-private.h"
+#include "user_share-common.h"
+#include "http.h"
+
+#ifdef HAVE_BLUETOOTH
+#include <bluetooth-client.h>
+
+#include "obexftp.h"
+#include "obexpush.h"
+
+#endif /* HAVE_BLUETOOTH */
+
+#include <gio/gio.h>
+
+#include <stdarg.h>
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <signal.h>
+#include <unistd.h>
+
+static guint disabled_timeout_tag = 0;
+static GSettings* settings;<--- Shadowed declaration
+
+#define GSETTINGS_SCHEMA "org.mate.FileSharing"
+#define GSETTINGS_KEY_FILE_SHARING_ENABLED "enabled"
+#define GSETTINGS_KEY_FILE_SHARING_REQUIRE_PASSWORD "require-password"
+
+#ifdef HAVE_BLUETOOTH
+/* MATE Session */
+#define MATE_SESSION_DBUS_NAME      "org.gnome.SessionManager"
+#define MATE_SESSION_DBUS_OBJECT    "/org/gnome/SessionManager"
+#define MATE_SESSION_DBUS_INTERFACE "org.gnome.SessionManager"
+
+static GDBusProxy *session_proxy = NULL;
+static gboolean has_console = TRUE;
+
+static BluetoothClient *client = NULL;
+static gboolean bluetoothd_enabled = FALSE;
+
+#define OBEX_ENABLED (bluetoothd_enabled && has_console)
+
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_ENABLED "bluetooth-enabled"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_ALLOW_WRITE "bluetooth-allow-write"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_REQUIRE_PAIRING "bluetooth-require-pairing"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED "bluetooth-obexpush-enabled"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_ACCEPT_FILES "bluetooth-accept-files"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_NOTIFY "bluetooth-notify"
+
+
+static void
+obex_services_start (void)
+{
+	GSettings *settings;
+
+	if (bluetoothd_enabled == FALSE ||
+	    has_console == FALSE)
+	    	return;
+
+	settings = g_settings_new(GSETTINGS_SCHEMA);
+
+	if (g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED) == TRUE) {
+	    obexpush_up ();
+	}
+	if (g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_ENABLED) == TRUE) {
+	    obexftp_up ();
+	}
+
+	g_object_unref (client);
+}
+
+static void
+obex_services_shutdown (void)
+{
+	obexpush_down ();
+	obexftp_down ();
+}
+
+static void
+session_properties_changed_cb (GDBusProxy      *session,
+			       GVariant        *changed,
+			       char           **invalidated,
+			       gpointer         user_data)
+{
+	GVariant *v;
+
+	v = g_variant_lookup_value (changed, "SessionIsActive", G_VARIANT_TYPE_BOOLEAN);
+	if (v) {
+		has_console = g_variant_get_boolean (v);
+		g_debug ("Received session is active change: now %s", has_console ? "active" : "inactive");
+
+		if (has_console)
+			obex_services_start ();
+		else
+			obex_services_shutdown ();
+
+		g_variant_unref (v);
+	}
+}
+
+static gboolean
+is_session_active (void)
+{
+	GVariant *variant;
+	gboolean is_session_active = FALSE;
+
+	variant = g_dbus_proxy_get_cached_property (session_proxy,
+						    "SessionIsActive");
+	if (variant) {
+		is_session_active = g_variant_get_boolean (variant);
+		g_variant_unref (variant);
+ 	}
+
+	return is_session_active;
+}
+
+static void
+session_init (void)
+{
+	GError *error = NULL;
+
+	session_proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION,
+						       G_DBUS_PROXY_FLAGS_NONE,
+						       NULL,
+						       MATE_SESSION_DBUS_NAME,
+						       MATE_SESSION_DBUS_OBJECT,
+						       MATE_SESSION_DBUS_INTERFACE,
+						       NULL,
+						       &error);
+	if (session_proxy == NULL) {
+		g_warning ("Failed to get session proxy: %s", error->message);
+		g_error_free (error);
+		return;
+	}
+	g_signal_connect (session_proxy, "g-properties-changed",
+			  G_CALLBACK (session_properties_changed_cb),
+			  NULL);
+	has_console = is_session_active ();
+}
+
+static void
+default_adapter_changed (GObject    *gobject,<--- Parameter 'gobject' can be declared with const
+			 GParamSpec *pspec,
+			 gpointer    user_data)
+{
+	char *adapter;
+	gboolean adapter_powered;
+
+	g_object_get (G_OBJECT (client),
+		      "default-adapter", &adapter,
+		      "default-adapter-powered", &adapter_powered,
+		      NULL);
+	if (adapter != NULL && *adapter != '\0') {
+		bluetoothd_enabled = adapter_powered;
+	} else {
+		bluetoothd_enabled = FALSE;
+	}
+
+	/* Were we called as init, or as a callback */
+	if (gobject != NULL) {
+		if (bluetoothd_enabled != FALSE)
+			obex_services_start ();
+		else
+			obex_services_shutdown ();
+	}
+}
+
+static void
+bluez_init (void)
+{
+	client = bluetooth_client_new ();
+	default_adapter_changed (NULL, NULL, NULL);
+	g_signal_connect (G_OBJECT (client), "notify::default-adapter",
+			  G_CALLBACK (default_adapter_changed), NULL);
+	g_signal_connect (G_OBJECT (client), "notify::default-adapter-powered",
+			  G_CALLBACK (default_adapter_changed), NULL);
+}
+#endif /* HAVE_BLUETOOTH */
+
+static gboolean
+file_sharing_enabled (void)
+{
+	gboolean enabled = TRUE;
+	settings = g_settings_new (GSETTINGS_SCHEMA);
+
+#ifdef HAVE_BLUETOOTH
+	if (g_settings_get_boolean (settings, FILE_SHARING_ENABLED) == FALSE &&
+	    g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_ENABLED) == FALSE &&
+	    g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED) == FALSE)
+#else /* HAVE_BLUETOOTH */
+	if (g_settings_get_boolean (settings, FILE_SHARING_ENABLED) == FALSE)
+#endif /* HAVE_BLUETOOTH */
+		enabled = FALSE;
+
+	g_object_unref (settings);
+
+	return enabled;
+}
+
+static void
+migrate_old_configuration (void)
+{
+	const char *old_config_dir;
+	const char *new_config_dir;
+
+	old_config_dir = g_build_filename (g_get_home_dir (), ".mate2", "user-share", NULL);
+	new_config_dir = g_build_filename (g_get_user_config_dir (), "user-share", NULL);
+	if (g_file_test (old_config_dir, G_FILE_TEST_IS_DIR))
+		g_rename (old_config_dir, new_config_dir);
+
+}
+
+static void
+require_password_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	/* Need to restart to get new password setting */
+	if (http_get_pid () != 0) {
+		http_down ();
+		http_up ();
+	}
+}
+
+/* File sharing was disabled for some time, exit now */
+/* If we re-enable it in the ui, this will be restarted anyway */
+static gboolean
+disabled_timeout_callback (gpointer user_data)
+{
+	GSettings *settings = (GSettings *) user_data;
+	http_down ();
+
+#ifdef HAVE_BLUETOOTH
+	if (g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_ENABLED) == FALSE &&
+	    g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED) == FALSE)
+		_exit (0);
+#else /* HAVE_BLUETOOTH */
+	if (g_settings_get_boolean (settings, FILE_SHARING_ENABLED) == FALSE)
+		_exit (0);
+#endif /* HAVE_BLUETOOTH */
+	return FALSE;
+}
+
+static void
+file_sharing_enabled_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	gboolean enabled;
+
+	if (disabled_timeout_tag != 0) {
+		g_source_remove (disabled_timeout_tag);
+		disabled_timeout_tag = 0;
+	}
+
+	enabled = g_settings_get_boolean (settings,
+					 FILE_SHARING_ENABLED);
+	if (enabled) {
+		if (http_get_pid () == 0) {
+			http_up ();
+		}
+	} else {
+		http_down ();
+		disabled_timeout_tag = g_timeout_add_seconds (3,
+							      (GSourceFunc)disabled_timeout_callback,
+							      settings);
+	}
+}
+
+#ifdef HAVE_BLUETOOTH
+static void
+file_sharing_bluetooth_allow_write_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	if (g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_ENABLED) != FALSE)
+		obexftp_restart ();
+}
+
+static void
+file_sharing_bluetooth_require_pairing_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	if (g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_ENABLED) != FALSE) {
+		/* We need to fully reset the session,
+		 * otherwise the new setting isn't taken into account */
+		obexftp_down ();
+		obexftp_up ();
+	}
+}
+
+static void
+file_sharing_bluetooth_enabled_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	if (g_settings_get_boolean (settings,
+				   FILE_SHARING_BLUETOOTH_ENABLED) == FALSE) {
+		obexftp_down ();
+		if (g_settings_get_boolean (settings, FILE_SHARING_ENABLED) == FALSE &&
+		    g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED) == FALSE) {
+			_exit (0);
+		}
+	} else if (OBEX_ENABLED) {
+		obexftp_up ();
+	}
+}
+
+static void
+file_sharing_bluetooth_obexpush_enabled_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	if (g_settings_get_boolean (settings,
+				   FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED) == FALSE) {
+		obexpush_down ();
+		if (g_settings_get_boolean (settings, FILE_SHARING_ENABLED) == FALSE &&
+		    g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_ENABLED) == FALSE) {
+			_exit (0);
+		}
+	} else if (OBEX_ENABLED) {
+		obexpush_up ();
+	}
+}
+
+static void
+file_sharing_bluetooth_obexpush_accept_files_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	AcceptSetting setting;
+	char *str;
+
+	str = g_settings_get_string (settings, FILE_SHARING_BLUETOOTH_OBEXPUSH_ACCEPT_FILES);
+	setting = accept_setting_from_string (str);
+	g_free (str);
+
+	obexpush_set_accept_files_policy (setting);
+}
+
+static void
+file_sharing_bluetooth_obexpush_notify_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	obexpush_set_notify (g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_OBEXPUSH_NOTIFY));
+}
+#endif /* HAVE_BLUETOOTH */
+
+static RETSIGTYPE
+cleanup_handler (int sig)
+{
+	http_down ();
+#ifdef HAVE_BLUETOOTH
+	obexftp_down ();
+	obexpush_down ();
+#endif /* HAVE_BLUETOOTH */
+	_exit (2);
+}
+
+static int
+x_io_error_handler (Display *xdisplay)
+{
+	http_down ();
+#ifdef HAVE_BLUETOOTH
+	obexftp_down ();
+#endif /* HAVE_BLUETOOTH */
+	_exit (2);
+}
+
+int
+main (int argc, char **argv)
+{
+	GSettings *settings;<--- Shadow variable
+	Display *xdisplay;
+	G_GNUC_UNUSED int x_fd;
+	Window selection_owner;
+	Atom xatom;
+
+	bindtextdomain (GETTEXT_PACKAGE, MATELOCALEDIR);
+	bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
+	textdomain (GETTEXT_PACKAGE);
+
+	gtk_init (&argc, &argv);
+
+	if (g_strcmp0 (g_get_real_name (), "root") == 0) {
+		g_warning ("mate-user-share cannot be started as root for security reasons.");
+		return 1;
+	}
+
+	signal (SIGPIPE, SIG_IGN);
+	signal (SIGINT, cleanup_handler);
+	signal (SIGHUP, cleanup_handler);
+	signal (SIGTERM, cleanup_handler);
+
+	xdisplay = GDK_DISPLAY_XDISPLAY (gdk_display_get_default ());
+	if (xdisplay == NULL) {
+		g_warning ("Can't open display");
+		return 1;
+	}
+
+	xatom = XInternAtom (xdisplay, "_MATE_USER_SHARE", FALSE);
+	selection_owner = XGetSelectionOwner (xdisplay, xatom);
+
+	if (selection_owner != None) {
+		/* There is an owner already, quit */
+		return 1;
+	}
+
+	selection_owner = XCreateSimpleWindow (xdisplay,
+					       RootWindow (xdisplay, 0),
+					       0, 0, 1, 1,
+					       0, 0, 0);
+	XSetSelectionOwner (xdisplay, xatom, selection_owner, CurrentTime);
+
+	if (XGetSelectionOwner (xdisplay, xatom) != selection_owner) {
+		/* Didn't get the selection */
+		return 1;
+	}
+
+	migrate_old_configuration ();
+
+	if (!file_sharing_enabled ())
+		return 1;
+
+	settings = g_settings_new (GSETTINGS_SCHEMA);
+
+	x_fd = ConnectionNumber (xdisplay);
+	XSetIOErrorHandler (x_io_error_handler);
+
+	if (http_init () == FALSE)
+		return 1;
+#ifdef HAVE_BLUETOOTH
+	if (obexftp_init () == FALSE)
+		return 1;
+	if (obexpush_init () == FALSE)
+		return 1;
+#endif /* HAVE_BLUETOOTH */
+
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_ENABLED,
+			     G_CALLBACK (file_sharing_enabled_changed), NULL);
+
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_REQUIRE_PASSWORD,
+			     G_CALLBACK (require_password_changed), NULL);
+
+#ifdef HAVE_BLUETOOTH
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_ENABLED,
+			     G_CALLBACK (file_sharing_bluetooth_enabled_changed), NULL);
+
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_ALLOW_WRITE,
+			     G_CALLBACK (file_sharing_bluetooth_allow_write_changed), NULL);
+
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_REQUIRE_PAIRING,
+			     G_CALLBACK (file_sharing_bluetooth_require_pairing_changed), NULL);
+
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED,
+			     G_CALLBACK (file_sharing_bluetooth_obexpush_enabled_changed), NULL);
+
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_ACCEPT_FILES,
+			     G_CALLBACK (file_sharing_bluetooth_obexpush_accept_files_changed), NULL);
+
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_NOTIFY,
+			     G_CALLBACK (file_sharing_bluetooth_obexpush_notify_changed), NULL);
+
+	bluez_init ();
+	session_init ();
+#endif /* HAVE_BLUETOOTH */
+
+	/* Initial setting */
+	file_sharing_enabled_changed (settings, NULL, NULL);
+#ifdef HAVE_BLUETOOTH
+	file_sharing_bluetooth_enabled_changed (settings, NULL, NULL);
+	file_sharing_bluetooth_obexpush_accept_files_changed (settings, NULL, NULL);
+	file_sharing_bluetooth_obexpush_notify_changed (settings, NULL, NULL);
+	file_sharing_bluetooth_obexpush_enabled_changed (settings, NULL, NULL);
+#endif /* HAVE_BLUETOOTH */
+
+	gtk_main ();
+
+	return 0;
+}
+
+
+
+ +
+ + diff --git a/2022-10-30-110836-1803-cppcheck@3a4fb1c0ec7f_master/index.html b/2022-10-30-110836-1803-cppcheck@3a4fb1c0ec7f_master/index.html new file mode 100644 index 0000000..b780b4e --- /dev/null +++ b/2022-10-30-110836-1803-cppcheck@3a4fb1c0ec7f_master/index.html @@ -0,0 +1,212 @@ + + + + + + Cppcheck - HTML report - mate-user-share + + + + + +
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + +
LineIdCWESeverityMessage
missingIncludeinformationCppcheck cannot find all the include files (use --check-config for details)
src/file-share-properties.c
83variableScope398styleThe scope of the variable 'password' can be reduced.
106unusedVariable563styleUnused variable: accept_setting
621variableScope398styleThe scope of the variable 'window' can be reduced.
src/http.c
115variableScope398styleThe scope of the variable 'host_name' can be reduced.
src/share-extension.c
62variableScope398styleThe scope of the variable 'dialog' can be reduced.
src/user_share.c
175constParameter398styleParameter 'gobject' can be declared with const
392shadowVariable398styleLocal variable 'settings' shadows outer variable
+
+ +
+ + diff --git a/2022-10-30-110836-1803-cppcheck@3a4fb1c0ec7f_master/stats.html b/2022-10-30-110836-1803-cppcheck@3a4fb1c0ec7f_master/stats.html new file mode 100644 index 0000000..93d49a4 --- /dev/null +++ b/2022-10-30-110836-1803-cppcheck@3a4fb1c0ec7f_master/stats.html @@ -0,0 +1,170 @@ + + + + + + Cppcheck - HTML report - mate-user-share + + + + + +
+ + + +
+

Top 10 files for style severity, total findings: 7
+   3  src/file-share-properties.c
+   2  src/user_share.c
+   1  src/share-extension.c
+   1  src/http.c
+

+ +
+ +
+ + diff --git a/2022-10-30-110836-1803-cppcheck@3a4fb1c0ec7f_master/style.css b/2022-10-30-110836-1803-cppcheck@3a4fb1c0ec7f_master/style.css new file mode 100644 index 0000000..3897bfa --- /dev/null +++ b/2022-10-30-110836-1803-cppcheck@3a4fb1c0ec7f_master/style.css @@ -0,0 +1,177 @@ + +body { + font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif; + font-size: 13px; + line-height: 1.5; + height: 100%; + margin: 0; +} + +#wrapper { + position: fixed; + height: 100vh; + width: 100vw; + display: grid; + grid-template-rows: fit-content(8rem) auto fit-content(8rem); + grid-template-columns: fit-content(25%) 1fr; + grid-template-areas: + "header header" + "menu content" + "footer footer"; +} + +h1 { + margin: 0 0 8px -2px; + font-size: 175%; +} + +.header { + padding: 0 0 5px 15px; + grid-area: header; + border-bottom: thin solid #aaa; +} + +.footer { + grid-area: footer; + border-top: thin solid #aaa; + font-size: 85%; + +} + +.footer > p { + margin: 4px; +} + +#menu, +#menu_index { + grid-area: menu; + text-align: left; + overflow: auto; + padding: 0 23px 15px 15px; + border-right: thin solid #aaa; + min-width: 200px; +} + +#menu > a { + display: block; + margin-left: 10px; + font-size: 12px; +} + +#content, +#content_index { + grid-area: content; + padding: 0px 5px 15px 15px; + overflow: auto; +} + +label { + white-space: nowrap; +} + +label.checkBtn.disabled { + color: #606060; + background: #e0e0e0; + font-style: italic; +} + +label.checkBtn, input[type="text"] { + border: 1px solid grey; + border-radius: 4px; + box-shadow: 1px 1px inset; + padding: 1px 5px; +} + +label.checkBtn { + white-space: nowrap; + background: #ccddff; +} + +label.unchecked { + background: #eff8ff; + box-shadow: 1px 1px 1px; +} + +label.checkBtn:hover, label.unchecked:hover{ + box-shadow: 0 0 2px; +} + +label.disabled:hover { + box-shadow: 1px 1px inset; +} + +label.checkBtn > input { + display:none; +} + +.summaryTable { + width: 100%; +} + +table.summaryTable td { padding: 0 5px 0 5px; } + +.statHeader, .severityHeader { + font-weight: bold; +} + +.warning { + background-color: #ffffa7; +} + +.error { + background-color: #ffb7b7; +} + +.error2 { + background-color: #faa; + display: inline-block; + margin-left: 4px; +} + +.inconclusive { + background-color: #b6b6b4; +} + +.inconclusive2 { + background-color: #b6b6b4; + display: inline-block; + margin-left: 4px; +} + +.verbose { + display: inline-block; + vertical-align: top; + cursor: help; +} + +.verbose .content { + display: none; + position: absolute; + padding: 10px; + margin: 4px; + max-width: 40%; + white-space: pre-wrap; + border: 1px solid #000; + background-color: #ffffcc; + cursor: auto; +} + +.highlight .hll { + padding: 1px; +} + +.highlighttable { + background-color: #fff; + position: relative; + margin: -10px; +} + +.linenos { + border-right: thin solid #aaa; + color: #d3d3d3; + padding-right: 6px; +} + +.id-filtered, .severity-filtered, .file-filtered, .tool-filtered, .text-filtered { + visibility: collapse; +} diff --git a/2022-11-11-200849-3937-cppcheck@c9d02a6bbcbb_master/0.html b/2022-11-11-200849-3937-cppcheck@c9d02a6bbcbb_master/0.html new file mode 100644 index 0000000..7a4ab90 --- /dev/null +++ b/2022-11-11-200849-3937-cppcheck@c9d02a6bbcbb_master/0.html @@ -0,0 +1,1567 @@ + + + + + + Cppcheck - HTML report - mate-user-share + + + + + +
+ + + +
+
  1
+  2
+  3
+  4
+  5
+  6
+  7
+  8
+  9
+ 10
+ 11
+ 12
+ 13
+ 14
+ 15
+ 16
+ 17
+ 18
+ 19
+ 20
+ 21
+ 22
+ 23
+ 24
+ 25
+ 26
+ 27
+ 28
+ 29
+ 30
+ 31
+ 32
+ 33
+ 34
+ 35
+ 36
+ 37
+ 38
+ 39
+ 40
+ 41
+ 42
+ 43
+ 44
+ 45
+ 46
+ 47
+ 48
+ 49
+ 50
+ 51
+ 52
+ 53
+ 54
+ 55
+ 56
+ 57
+ 58
+ 59
+ 60
+ 61
+ 62
+ 63
+ 64
+ 65
+ 66
+ 67
+ 68
+ 69
+ 70
+ 71
+ 72
+ 73
+ 74
+ 75
+ 76
+ 77
+ 78
+ 79
+ 80
+ 81
+ 82
+ 83
+ 84
+ 85
+ 86
+ 87
+ 88
+ 89
+ 90
+ 91
+ 92
+ 93
+ 94
+ 95
+ 96
+ 97
+ 98
+ 99
+100
+101
+102
+103
+104
+105
+106
+107
+108
+109
+110
+111
+112
+113
+114
+115
+116
+117
+118
+119
+120
+121
+122
+123
+124
+125
+126
+127
+128
+129
+130
+131
+132
+133
+134
+135
+136
+137
+138
+139
+140
+141
+142
+143
+144
+145
+146
+147
+148
+149
+150
+151
+152
+153
+154
+155
+156
+157
+158
+159
+160
+161
+162
+163
+164
+165
+166
+167
+168
+169
+170
+171
+172
+173
+174
+175
+176
+177
+178
+179
+180
+181
+182
+183
+184
+185
+186
+187
+188
+189
+190
+191
+192
+193
+194
+195
+196
+197
+198
+199
+200
+201
+202
+203
+204
+205
+206
+207
+208
+209
+210
+211
+212
+213
+214
+215
+216
+217
+218
+219
+220
+221
+222
+223
+224
+225
+226
+227
+228
+229
+230
+231
+232
+233
+234
+235
+236
+237
+238
+239
+240
+241
+242
+243
+244
+245
+246
+247
+248
+249
+250
+251
+252
+253
+254
+255
+256
+257
+258
+259
+260
+261
+262
+263
+264
+265
+266
+267
+268
+269
+270
+271
+272
+273
+274
+275
+276
+277
+278
+279
+280
+281
+282
+283
+284
+285
+286
+287
+288
+289
+290
+291
+292
+293
+294
+295
+296
+297
+298
+299
+300
+301
+302
+303
+304
+305
+306
+307
+308
+309
+310
+311
+312
+313
+314
+315
+316
+317
+318
+319
+320
+321
+322
+323
+324
+325
+326
+327
+328
+329
+330
+331
+332
+333
+334
+335
+336
+337
+338
+339
+340
+341
+342
+343
+344
+345
+346
+347
+348
+349
+350
+351
+352
+353
+354
+355
+356
+357
+358
+359
+360
+361
+362
+363
+364
+365
+366
+367
+368
+369
+370
+371
+372
+373
+374
+375
+376
+377
+378
+379
+380
+381
+382
+383
+384
+385
+386
+387
+388
+389
+390
+391
+392
+393
+394
+395
+396
+397
+398
+399
+400
+401
+402
+403
+404
+405
+406
+407
+408
+409
+410
+411
+412
+413
+414
+415
+416
+417
+418
+419
+420
+421
+422
+423
+424
+425
+426
+427
+428
+429
+430
+431
+432
+433
+434
+435
+436
+437
+438
+439
+440
+441
+442
+443
+444
+445
+446
+447
+448
+449
+450
+451
+452
+453
+454
+455
+456
+457
+458
+459
+460
+461
+462
+463
+464
+465
+466
+467
+468
+469
+470
+471
+472
+473
+474
+475
+476
+477
+478
+479
+480
+481
+482
+483
+484
+485
+486
+487
+488
+489
+490
+491
+492
+493
+494
+495
+496
+497
+498
+499
+500
+501
+502
+503
+504
+505
+506
+507
+508
+509
+510
+511
+512
+513
+514
+515
+516
+517
+518
+519
+520
+521
+522
+523
+524
+525
+526
+527
+528
+529
+530
+531
+532
+533
+534
+535
+536
+537
+538
+539
+540
+541
+542
+543
+544
+545
+546
+547
+548
+549
+550
+551
+552
+553
+554
+555
+556
+557
+558
+559
+560
+561
+562
+563
+564
+565
+566
+567
+568
+569
+570
+571
+572
+573
+574
+575
+576
+577
+578
+579
+580
+581
+582
+583
+584
+585
+586
+587
+588
+589
+590
+591
+592
+593
+594
+595
+596
+597
+598
+599
+600
+601
+602
+603
+604
+605
+606
+607
+608
+609
+610
+611
+612
+613
+614
+615
+616
+617
+618
+619
+620
+621
+622
+623
+624
+625
+626
+627
+628
+629
+630
+631
+632
+633
+634
+635
+636
+637
+638
+639
+640
+641
+642
+643
+644
+645
+646
+647
+648
+649
+650
+651
+652
+653
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
+
+/*
+ *  Copyright (C) 2004 Red Hat, Inc.
+ * Copyright (C) 2012-2021 MATE Developers
+ *
+ *  Caja is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU General Public License as
+ *  published by the Free Software Foundation; either version 2 of the
+ *  License, or (at your option) any later version.
+ *
+ *  Caja is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  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
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ *  Authors: Alexander Larsson <alexl@redhat.com>
+ *
+ */
+
+#include "config.h"
+
+#include <string.h>
+#include <stdio.h>
+
+#include <gtk/gtk.h>
+#include <glib/gi18n.h>
+#include <gio/gio.h>
+
+#include "user_share-private.h"
+
+#define REALM "Please log in as the user guest"
+#define USER "guest"
+#define GSETTINGS_SCHEMA "org.mate.FileSharing"
+#define GSETTINGS_KEY_FILE_SHARING_ENABLED "enabled"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_ENABLED "bluetooth-enabled"
+#define GSETTINGS_KEY_FILE_SHARING_REQUIRE_PASSWORD "require-password"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_ALLOW_WRITE "bluetooth-allow-write"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_REQUIRE_PAIRING "bluetooth-require-pairing"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED "bluetooth-obexpush-enabled"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_ACCEPT_FILES "bluetooth-accept-files"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_NOTIFY "bluetooth-notify"
+
+static GtkBuilder* builder;
+static GSettings* settings;
+
+
+static void
+write_out_password (const char *password)
+{
+    char *to_hash;
+    char *ascii_digest;
+    char *line;
+    char *filename;
+    FILE *file;
+
+    to_hash = g_strdup_printf ("%s:%s:%s", USER, REALM, password);
+    ascii_digest = g_compute_checksum_for_string (G_CHECKSUM_MD5, to_hash, strlen (to_hash));
+    g_free (to_hash);
+    line = g_strdup_printf ("%s:%s:%s\n", USER, REALM, ascii_digest);
+    g_free (ascii_digest);
+
+    filename = g_build_filename (g_get_user_config_dir (), "user-share", "passwd", NULL);
+
+    file = fopen (filename, "w");
+    if (file != NULL) {
+	fwrite (line, strlen (line), 1, file);
+	fclose (file);
+    }
+
+    g_free (filename);
+    g_free (line);
+}
+
+static void
+flush_password (void)
+{
+    GtkWidget *password_entry;
+    const char *password;
+
+    password_entry = GTK_WIDGET (gtk_builder_get_object (builder, "password_entry"));
+
+    if (g_object_get_data (G_OBJECT( password_entry), "user_edited")) {
+	password = gtk_entry_get_text (GTK_ENTRY (password_entry));
+	if (password != NULL && password[0] != 0)
+	    write_out_password (password);
+    }
+}
+
+
+static void
+update_ui (void)
+{
+    GSettings *settings;
+    gboolean enabled;
+#ifdef HAVE_BLUETOOTH
+    gboolean bluetooth_enabled, bluetooth_write_enabled, require_pairing_enabled;
+    gboolean bluetooth_obexpush_enabled, bluetooth_obexpush_notify;
+#endif /* HAVE_BLUETOOTH */
+    char *str;
+    PasswordSetting password_setting;
+    AcceptSetting accept_setting;<--- Unused variable: accept_setting
+    GtkWidget *check;
+    GtkWidget *password_combo;
+    GtkWidget *password_entry;
+#ifdef HAVE_BLUETOOTH
+    GtkWidget *vbox_share_bluetooth;
+    GtkWidget *vbox_receive_bluetooth;
+    GtkWidget *bluetooth_check;
+    GtkWidget *allow_write_bluetooth_check;
+    GtkWidget *require_pairing_check;
+    GtkWidget *enable_obexpush_check;
+    GtkWidget *accept_obexpush_combo;
+    GtkWidget *notify_received_obexpush_check;
+#endif /* HAVE_BLUETOOTH */
+
+    settings = g_settings_new (GSETTINGS_SCHEMA);
+
+    enabled = g_settings_get_boolean (settings,
+				     FILE_SHARING_ENABLED);
+
+    str = g_settings_get_string (settings, FILE_SHARING_REQUIRE_PASSWORD);
+    password_setting = password_setting_from_string (str);
+    g_free (str);
+
+#ifdef HAVE_BLUETOOTH
+    bluetooth_enabled = g_settings_get_boolean (settings,
+    					       FILE_SHARING_BLUETOOTH_ENABLED);
+    bluetooth_write_enabled = g_settings_get_boolean (settings,
+						     FILE_SHARING_BLUETOOTH_ALLOW_WRITE);
+    require_pairing_enabled = g_settings_get_boolean (settings,
+    						     FILE_SHARING_BLUETOOTH_REQUIRE_PAIRING);
+    bluetooth_obexpush_enabled = g_settings_get_boolean (settings,
+    							FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED);
+    bluetooth_obexpush_notify = g_settings_get_boolean (settings,
+    						       FILE_SHARING_BLUETOOTH_OBEXPUSH_NOTIFY);
+
+    str = g_settings_get_string (settings, FILE_SHARING_BLUETOOTH_OBEXPUSH_ACCEPT_FILES);
+    accept_setting = accept_setting_from_string (str);
+    g_free (str);
+#endif /* HAVE_BLUETOOTH */
+
+    check = GTK_WIDGET (gtk_builder_get_object (builder, "enable_check"));
+    password_combo = GTK_WIDGET (gtk_builder_get_object (builder, "password_combo"));
+    password_entry = GTK_WIDGET (gtk_builder_get_object (builder, "password_entry"));
+#ifdef HAVE_BLUETOOTH
+    vbox_share_bluetooth = GTK_WIDGET (gtk_builder_get_object (builder, "vbox_share_bluetooth"));
+    vbox_receive_bluetooth = GTK_WIDGET (gtk_builder_get_object (builder, "vbox_receive_bluetooth"));
+    bluetooth_check = GTK_WIDGET (gtk_builder_get_object (builder, "enable_bluetooth_check"));
+    allow_write_bluetooth_check = GTK_WIDGET (gtk_builder_get_object (builder, "allow_write_bluetooth_check"));
+    require_pairing_check = GTK_WIDGET (gtk_builder_get_object (builder, "require_pairing_check"));
+    enable_obexpush_check = GTK_WIDGET (gtk_builder_get_object (builder, "enable_obexpush_check"));
+    accept_obexpush_combo = GTK_WIDGET (gtk_builder_get_object (builder, "accept_obexpush_combo"));
+    notify_received_obexpush_check = GTK_WIDGET (gtk_builder_get_object (builder, "notify_received_obexpush_check"));
+#endif /* HAVE_BLUETOOTH */
+
+    /* Network */
+    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (check), enabled);
+    gtk_widget_set_sensitive (password_combo, enabled);
+    gtk_widget_set_sensitive (password_entry, enabled && password_setting != PASSWORD_NEVER);
+
+    gtk_combo_box_set_active (GTK_COMBO_BOX (password_combo),
+			      password_setting);
+
+#ifdef HAVE_BLUETOOTH
+    /* Bluetooth ObexFTP */
+    gtk_widget_set_visible (vbox_share_bluetooth, TRUE);
+    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (bluetooth_check), bluetooth_enabled);
+    gtk_widget_set_sensitive (allow_write_bluetooth_check, bluetooth_enabled);
+    gtk_widget_set_sensitive (require_pairing_check, bluetooth_enabled);
+
+    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (allow_write_bluetooth_check),
+    				  bluetooth_write_enabled);
+    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (require_pairing_check),
+    				  require_pairing_enabled);
+
+    /* Bluetooth ObexPush */
+    gtk_widget_set_visible (vbox_receive_bluetooth, TRUE);
+    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (enable_obexpush_check), bluetooth_obexpush_enabled);
+    gtk_widget_set_sensitive (accept_obexpush_combo, bluetooth_obexpush_enabled);
+    gtk_widget_set_sensitive (notify_received_obexpush_check, bluetooth_obexpush_enabled);
+
+    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (notify_received_obexpush_check),
+    				  bluetooth_obexpush_notify);
+
+    gtk_combo_box_set_active (GTK_COMBO_BOX (accept_obexpush_combo),
+    			      accept_setting);
+#endif /* HAVE_BLUETOOTH */
+
+    g_object_unref (settings);
+}
+
+static void
+file_sharing_enabled_changed (GSettings *settings, gchar *key, gpointer data)
+{
+    update_ui ();
+}
+
+static void
+password_required_changed (GSettings *settings, gchar *key, gpointer data)
+{
+    update_ui ();
+}
+
+#ifdef HAVE_BLUETOOTH
+static void
+file_sharing_bluetooth_enabled_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	update_ui ();
+}
+
+static void
+file_sharing_bluetooth_allow_write_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	update_ui ();
+}
+
+static void
+file_sharing_bluetooth_require_pairing_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	update_ui ();
+}
+
+static void
+file_sharing_bluetooth_obexpush_enabled_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	update_ui ();
+}
+
+static void
+file_sharing_bluetooth_obexpush_accept_files_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	update_ui ();
+}
+
+static void
+file_sharing_bluetooth_obexpush_notify_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	update_ui ();
+}
+#endif /* HAVE_BLUETOOTH */
+
+static void
+password_combo_changed (GtkComboBox *combo_box)
+{
+    GSettings *settings;
+    guint setting;
+
+    setting = gtk_combo_box_get_active (combo_box);
+
+    settings = g_settings_new (GSETTINGS_SCHEMA) ;
+
+    g_settings_set_string (settings,
+			     FILE_SHARING_REQUIRE_PASSWORD,
+			     password_string_from_setting (setting));
+    g_object_unref (settings);
+}
+
+static void
+launch_share (void)
+{
+	if (!g_spawn_command_line_async (USER_SHARE_PROGRAM, NULL))
+		g_warning ("Unable to start mate-user-share program");
+}
+
+#ifdef HAVE_BLUETOOTH
+static void
+enable_bluetooth_check_toggled (GtkWidget *check)
+{
+	GSettings *settings;
+	gboolean enabled;
+
+	enabled = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check));
+
+	settings = g_settings_new (GSETTINGS_SCHEMA) ;
+
+	g_settings_set_boolean (settings,
+			       FILE_SHARING_BLUETOOTH_ENABLED,
+			       enabled);
+
+	g_object_unref (settings);
+
+	if (enabled != FALSE)
+		launch_share ();
+}
+#endif /* HAVE_BLUETOOTH */
+
+static void
+enable_check_toggled (GtkWidget *check)
+{
+	GSettings *settings;
+	gboolean enabled;
+
+	enabled = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check));
+
+	settings = g_settings_new (GSETTINGS_SCHEMA);
+
+	g_settings_set_boolean (settings,
+			       FILE_SHARING_ENABLED,
+			       enabled);
+
+	g_object_unref (settings);
+
+	if (enabled != FALSE)
+		launch_share ();
+}
+
+static void
+password_entry_changed (GtkEditable *editable)
+{
+	g_object_set_data (G_OBJECT (editable),
+			   "user_edited", GINT_TO_POINTER (1));
+	flush_password ();
+}
+
+#ifdef HAVE_BLUETOOTH
+static void
+bluetooth_allow_write_check_toggled (GtkWidget *check)
+{
+	GSettings *settings;
+	gboolean enabled;
+
+	enabled = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check));
+
+	settings = g_settings_new (GSETTINGS_SCHEMA) ;
+
+	g_settings_set_boolean (settings,
+			       FILE_SHARING_BLUETOOTH_ALLOW_WRITE,
+			       enabled);
+
+	g_object_unref (settings);
+}
+
+static void
+bluetooth_require_pairing_check_toggled (GtkWidget *check)
+{
+	GSettings *settings;
+	gboolean enabled;
+
+	enabled = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check));
+
+	settings = g_settings_new (GSETTINGS_SCHEMA) ;
+
+	g_settings_set_boolean (settings,
+			       FILE_SHARING_BLUETOOTH_REQUIRE_PAIRING,
+			       enabled);
+
+	g_object_unref (settings);
+}
+
+static void
+enable_obexpush_check_toggled (GtkWidget *check)
+{
+	GSettings *settings;
+	gboolean enabled;
+
+	enabled = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check));
+
+	settings = g_settings_new (GSETTINGS_SCHEMA) ;
+
+	g_settings_set_boolean (settings,
+			       FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED,
+			       enabled);
+
+	g_object_unref (settings);
+
+	if (enabled != FALSE)
+		launch_share ();
+}
+
+static void
+accept_obexpush_combo_changed (GtkComboBox *combo_box)
+{
+    GSettings *settings;
+    guint setting;
+
+    setting = gtk_combo_box_get_active (combo_box);
+
+    settings = g_settings_new (GSETTINGS_SCHEMA) ;
+
+    g_settings_set_string (settings,
+			     FILE_SHARING_BLUETOOTH_OBEXPUSH_ACCEPT_FILES,
+			     accept_string_from_setting (setting));
+    g_object_unref (settings);
+}
+
+static void
+notify_received_obexpush_check_toggled (GtkWidget *check)
+{
+	GSettings *settings;
+	gboolean enabled;
+
+	enabled = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check));
+
+	settings = g_settings_new (GSETTINGS_SCHEMA) ;
+
+	g_settings_set_boolean (settings,
+			       FILE_SHARING_BLUETOOTH_OBEXPUSH_NOTIFY,
+			       enabled);
+
+	g_object_unref (settings);
+}
+#endif /* HAVE_BLUETOOTH */
+
+static GtkWidget *
+error_dialog (const char *title,
+	      const char *reason,
+	      GtkWindow *parent)
+{
+	GtkWidget *error_dialog;
+
+	if (reason == NULL)
+		reason = _("No reason");
+
+	error_dialog =
+		gtk_message_dialog_new (parent,
+					GTK_DIALOG_MODAL,
+					GTK_MESSAGE_ERROR,
+					GTK_BUTTONS_OK,
+					"%s", title);
+	gtk_message_dialog_format_secondary_text
+		(GTK_MESSAGE_DIALOG (error_dialog), "%s", reason);
+
+	gtk_window_set_title (GTK_WINDOW (error_dialog), ""); /* as per HIG */
+	gtk_container_set_border_width (GTK_CONTAINER (error_dialog), 5);
+	gtk_dialog_set_default_response (GTK_DIALOG (error_dialog),
+					 GTK_RESPONSE_OK);
+	gtk_window_set_modal (GTK_WINDOW (error_dialog), TRUE);
+
+	return error_dialog;
+}
+
+static void
+help_button_clicked (GtkButton *button, GtkWidget *window)
+{
+	GError *error = NULL;
+
+	if (gtk_show_uri_on_window (GTK_WINDOW (window), "help:mate-user-share", gtk_get_current_event_time (), &error) == FALSE) {
+		GtkWidget *dialog;
+
+		dialog = error_dialog (_("Could not display the help contents."), error->message, GTK_WINDOW (window));
+		g_signal_connect (G_OBJECT (dialog), "response", G_CALLBACK
+				  (gtk_widget_destroy), error_dialog);
+		gtk_window_present (GTK_WINDOW (dialog));
+
+		g_error_free (error);
+	}
+}
+
+static GtkWidget *
+create_window (void)
+{
+    GError *error = NULL;
+    GSettings *settings;
+    GtkWidget *check;
+    GtkWidget *password_combo;
+    GtkWidget *password_entry;
+#ifdef HAVE_BLUETOOTH
+    GtkWidget *bluetooth_check;
+    GtkWidget *bluetooth_allow_write_check;
+    GtkWidget *require_pairing_check;
+    GtkWidget *enable_obexpush_check;
+    GtkWidget *accept_obexpush_combo;
+    GtkWidget *notify_received_obexpush_check;
+#endif /* HAVE_BLUETOOTH */
+    GtkWidget *window;
+    GtkListStore *store;
+    GtkCellRenderer *cell;
+    GtkTreeIter iter;
+
+    builder = gtk_builder_new ();
+    gtk_builder_add_from_file (builder, DATADIR"file-share-properties.ui", &error);
+
+    if (error) {
+      GtkWidget *dialog;
+
+      dialog = error_dialog (_("Could not build interface."), error->message, NULL);
+      gtk_dialog_run (GTK_DIALOG (dialog));
+      gtk_widget_destroy (dialog);
+
+      g_error_free (error);
+      return NULL;
+    }
+
+    window = GTK_WIDGET (gtk_builder_get_object (builder, "user_share_dialog"));
+
+    settings = g_settings_new (GSETTINGS_SCHEMA);
+
+    check = GTK_WIDGET (gtk_builder_get_object (builder, "enable_check"));
+    password_combo = GTK_WIDGET (gtk_builder_get_object (builder, "password_combo"));
+    password_entry = GTK_WIDGET (gtk_builder_get_object (builder, "password_entry"));
+#ifdef HAVE_BLUETOOTH
+    bluetooth_check = GTK_WIDGET (gtk_builder_get_object (builder, "enable_bluetooth_check"));
+    bluetooth_allow_write_check = GTK_WIDGET (gtk_builder_get_object (builder, "allow_write_bluetooth_check"));
+    require_pairing_check = GTK_WIDGET (gtk_builder_get_object (builder, "require_pairing_check"));
+    enable_obexpush_check = GTK_WIDGET (gtk_builder_get_object (builder, "enable_obexpush_check"));
+    accept_obexpush_combo = GTK_WIDGET (gtk_builder_get_object (builder, "accept_obexpush_combo"));
+    notify_received_obexpush_check = GTK_WIDGET (gtk_builder_get_object (builder, "notify_received_obexpush_check"));
+#endif /* HAVE_BLUETOOTH */
+
+    store = gtk_list_store_new (1, G_TYPE_STRING);
+    gtk_combo_box_set_model (GTK_COMBO_BOX (password_combo),
+			     GTK_TREE_MODEL (store));
+    cell = gtk_cell_renderer_text_new ();
+    gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (password_combo), cell, TRUE);
+    gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (password_combo), cell,
+				    "text", 0,
+				    NULL);
+
+    /* Keep in same order as enum */
+    gtk_list_store_append (store, &iter);
+    gtk_list_store_set (store, &iter, 0,
+			_("Never"), -1);
+    gtk_list_store_append (store, &iter);
+    gtk_list_store_set (store, &iter, 0,
+			_("When writing files"), -1);
+    gtk_list_store_append (store, &iter);
+    gtk_list_store_set (store, &iter, 0,
+			_("Always"), -1);
+    g_object_unref (store);
+
+    /* We can't read the password from the text, just set it to something */
+    gtk_entry_set_text (GTK_ENTRY (password_entry), "none");
+    g_object_set_data (G_OBJECT (password_entry),
+		       "user_edited", GINT_TO_POINTER (0));
+    g_signal_connect (password_entry,
+		      "changed", G_CALLBACK (password_entry_changed), NULL);
+
+#ifdef HAVE_BLUETOOTH
+    /* Accept files combo */
+    store = gtk_list_store_new (1, G_TYPE_STRING);
+    gtk_combo_box_set_model (GTK_COMBO_BOX (accept_obexpush_combo),
+			     GTK_TREE_MODEL (store));
+    cell = gtk_cell_renderer_text_new ();
+    gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (accept_obexpush_combo), cell, TRUE);
+    gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (accept_obexpush_combo), cell,
+				    "text", 0,
+				    NULL);
+
+    /* Keep in same order as enum */
+    gtk_list_store_append (store, &iter);
+    gtk_list_store_set (store, &iter, 0,
+			_("Always"), -1);
+    gtk_list_store_append (store, &iter);
+    gtk_list_store_set (store, &iter, 0,
+			_("Only for set up devices"), -1);
+    //FIXME implement
+#if 0
+    gtk_list_store_append (store, &iter);
+    gtk_list_store_set (store, &iter, 0,
+    			_("Ask"), -1);
+#endif
+    g_object_unref (store);
+#endif /* HAVE_BLUETOOTH */
+
+    g_signal_connect (check,
+		      "toggled", G_CALLBACK (enable_check_toggled), NULL);
+    g_signal_connect (password_combo,
+		      "changed", G_CALLBACK (password_combo_changed), NULL);
+#ifdef HAVE_BLUETOOTH
+    g_signal_connect (bluetooth_check,
+    		      "toggled", G_CALLBACK (enable_bluetooth_check_toggled), NULL);
+    g_signal_connect (bluetooth_allow_write_check,
+    		      "toggled", G_CALLBACK (bluetooth_allow_write_check_toggled), NULL);
+    g_signal_connect (require_pairing_check,
+    		      "toggled", G_CALLBACK (bluetooth_require_pairing_check_toggled), NULL);
+    g_signal_connect (enable_obexpush_check,
+    		      "toggled", G_CALLBACK (enable_obexpush_check_toggled), NULL);
+    g_signal_connect (accept_obexpush_combo,
+    		      "changed", G_CALLBACK (accept_obexpush_combo_changed), NULL);
+    g_signal_connect (notify_received_obexpush_check,
+    		      "toggled", G_CALLBACK (notify_received_obexpush_check_toggled), NULL);
+#endif /* HAVE_BLUETOOTH */
+
+    g_signal_connect_swapped (GTK_WIDGET (gtk_builder_get_object (builder, "close_button")),
+                              "clicked", G_CALLBACK (gtk_widget_destroy), window);
+    g_signal_connect (GTK_WIDGET (gtk_builder_get_object (builder, "help_button")),
+		      "clicked", G_CALLBACK (help_button_clicked),
+		      gtk_builder_get_object (builder, "user_share_dialog"));
+
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_ENABLED,
+			     G_CALLBACK (file_sharing_enabled_changed), NULL);
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_REQUIRE_PASSWORD,
+			     G_CALLBACK (password_required_changed), NULL);
+#ifdef HAVE_BLUETOOTH
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_ENABLED,
+			     G_CALLBACK (file_sharing_bluetooth_enabled_changed), NULL);
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_ALLOW_WRITE,
+			     G_CALLBACK (file_sharing_bluetooth_allow_write_changed), NULL);
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_REQUIRE_PAIRING,
+			     G_CALLBACK (file_sharing_bluetooth_require_pairing_changed), NULL);
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED,
+			     G_CALLBACK (file_sharing_bluetooth_obexpush_enabled_changed), NULL);
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_ACCEPT_FILES,
+			     G_CALLBACK (file_sharing_bluetooth_obexpush_accept_files_changed), NULL);
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_NOTIFY,
+			     G_CALLBACK (file_sharing_bluetooth_obexpush_notify_changed), NULL);
+#endif /* HAVE_BLUETOOTH */
+
+    update_ui ();
+
+    return window;
+}
+
+static void
+activate (GtkApplication *app)
+{
+    GList *list;
+    GtkWidget *window;
+
+    list = gtk_application_get_windows (app);
+
+    if (list) {
+        gtk_window_present (GTK_WINDOW (list->data));
+    } else {
+        window = create_window ();
+        gtk_window_set_application (GTK_WINDOW (window), app);
+        gtk_widget_show (window);
+    }
+}
+
+int
+main (int argc, char *argv[])
+{
+    GtkApplication *app;
+    gint status;
+
+    bindtextdomain (GETTEXT_PACKAGE, MATELOCALEDIR);
+    bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
+    textdomain (GETTEXT_PACKAGE);
+
+    app = gtk_application_new ("org.mate.user-share.properties",
+                               G_APPLICATION_FLAGS_NONE);
+    g_signal_connect (app, "activate", G_CALLBACK (activate), NULL);
+
+    status = g_application_run (G_APPLICATION (app), argc, argv);
+
+    g_object_unref (app);
+
+    return status;
+}
+
+
+
+ +
+ + diff --git a/2022-11-11-200849-3937-cppcheck@c9d02a6bbcbb_master/1.html b/2022-11-11-200849-3937-cppcheck@c9d02a6bbcbb_master/1.html new file mode 100644 index 0000000..6ca74fd --- /dev/null +++ b/2022-11-11-200849-3937-cppcheck@c9d02a6bbcbb_master/1.html @@ -0,0 +1,1123 @@ + + + + + + Cppcheck - HTML report - mate-user-share + + + + + +
+ + + +
+
  1
+  2
+  3
+  4
+  5
+  6
+  7
+  8
+  9
+ 10
+ 11
+ 12
+ 13
+ 14
+ 15
+ 16
+ 17
+ 18
+ 19
+ 20
+ 21
+ 22
+ 23
+ 24
+ 25
+ 26
+ 27
+ 28
+ 29
+ 30
+ 31
+ 32
+ 33
+ 34
+ 35
+ 36
+ 37
+ 38
+ 39
+ 40
+ 41
+ 42
+ 43
+ 44
+ 45
+ 46
+ 47
+ 48
+ 49
+ 50
+ 51
+ 52
+ 53
+ 54
+ 55
+ 56
+ 57
+ 58
+ 59
+ 60
+ 61
+ 62
+ 63
+ 64
+ 65
+ 66
+ 67
+ 68
+ 69
+ 70
+ 71
+ 72
+ 73
+ 74
+ 75
+ 76
+ 77
+ 78
+ 79
+ 80
+ 81
+ 82
+ 83
+ 84
+ 85
+ 86
+ 87
+ 88
+ 89
+ 90
+ 91
+ 92
+ 93
+ 94
+ 95
+ 96
+ 97
+ 98
+ 99
+100
+101
+102
+103
+104
+105
+106
+107
+108
+109
+110
+111
+112
+113
+114
+115
+116
+117
+118
+119
+120
+121
+122
+123
+124
+125
+126
+127
+128
+129
+130
+131
+132
+133
+134
+135
+136
+137
+138
+139
+140
+141
+142
+143
+144
+145
+146
+147
+148
+149
+150
+151
+152
+153
+154
+155
+156
+157
+158
+159
+160
+161
+162
+163
+164
+165
+166
+167
+168
+169
+170
+171
+172
+173
+174
+175
+176
+177
+178
+179
+180
+181
+182
+183
+184
+185
+186
+187
+188
+189
+190
+191
+192
+193
+194
+195
+196
+197
+198
+199
+200
+201
+202
+203
+204
+205
+206
+207
+208
+209
+210
+211
+212
+213
+214
+215
+216
+217
+218
+219
+220
+221
+222
+223
+224
+225
+226
+227
+228
+229
+230
+231
+232
+233
+234
+235
+236
+237
+238
+239
+240
+241
+242
+243
+244
+245
+246
+247
+248
+249
+250
+251
+252
+253
+254
+255
+256
+257
+258
+259
+260
+261
+262
+263
+264
+265
+266
+267
+268
+269
+270
+271
+272
+273
+274
+275
+276
+277
+278
+279
+280
+281
+282
+283
+284
+285
+286
+287
+288
+289
+290
+291
+292
+293
+294
+295
+296
+297
+298
+299
+300
+301
+302
+303
+304
+305
+306
+307
+308
+309
+310
+311
+312
+313
+314
+315
+316
+317
+318
+319
+320
+321
+322
+323
+324
+325
+326
+327
+328
+329
+330
+331
+332
+333
+334
+335
+336
+337
+338
+339
+340
+341
+342
+343
+344
+345
+346
+347
+348
+349
+350
+351
+352
+353
+354
+355
+356
+357
+358
+359
+360
+361
+362
+363
+364
+365
+366
+367
+368
+369
+370
+371
+372
+373
+374
+375
+376
+377
+378
+379
+380
+381
+382
+383
+384
+385
+386
+387
+388
+389
+390
+391
+392
+393
+394
+395
+396
+397
+398
+399
+400
+401
+402
+403
+404
+405
+406
+407
+408
+409
+410
+411
+412
+413
+414
+415
+416
+417
+418
+419
+420
+421
+422
+423
+424
+425
+426
+427
+428
+429
+430
+431
+432
+433
+434
+435
+436
+437
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
+
+/*
+ *  Copyright (C) 2004-2008 Red Hat, Inc.
+ * Copyright (C) 2012-2021 MATE Developers
+ *
+ *  Caja is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU General Public License as
+ *  published by the Free Software Foundation; either version 2 of the
+ *  License, or (at your option) any later version.
+ *
+ *  Caja is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  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
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ *  Authors: Alexander Larsson <alexl@redhat.com>
+ *
+ */
+
+#include "config.h"
+
+#include <glib.h>
+#include <glib/gi18n.h>
+#include <X11/Xlib.h>
+
+#include <gio/gio.h>
+
+#include <stdarg.h>
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <signal.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <sys/stat.h>
+
+#ifdef HAVE_SELINUX
+#include <selinux/selinux.h>
+#endif
+
+#include "user_share-common.h"
+#include "user_share-private.h"
+#include "http.h"
+
+/* From avahi-common/domain.h */
+#define AVAHI_LABEL_MAX 64
+
+#define GSETTINGS_SCHEMA "org.mate.FileSharing"
+
+static pid_t httpd_pid = 0;
+
+static int
+get_port (void)
+{
+	int sock;
+	struct sockaddr_in addr;
+	int reuse;
+	socklen_t len;
+
+	sock = socket (PF_INET, SOCK_STREAM, 0);
+	if (sock < 0) {
+		return -1;
+	}
+
+	memset (&addr, 0, sizeof (addr));
+	addr.sin_port = 0;
+	addr.sin_addr.s_addr = INADDR_ANY;
+	addr.sin_family = AF_INET;
+
+	reuse = 1;
+	setsockopt (sock, SOL_SOCKET, SO_REUSEADDR, &reuse, sizeof (reuse));
+	if (bind (sock, (struct sockaddr *)&addr, sizeof (addr)) == -1) {
+		close (sock);
+		return -1;
+	}
+
+	len = sizeof (addr);
+	if (getsockname (sock, (struct sockaddr *)&addr, &len) == -1) {
+		close (sock);
+		return -1;
+	}
+
+#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__APPLE__) || defined(__OpenBSD__)
+	/* XXX This exposes a potential race condition, but without this,
+	 * httpd will not start on the above listed platforms due to the fact
+	 * that SO_REUSEADDR is also needed when Apache binds to the listening
+	 * socket.  At this time, Apache does not support that socket option.
+	 */
+	close (sock);
+#endif
+	return ntohs (addr.sin_port);
+}
+
+static char *
+truncate_name (const char *name)
+{
+	const char *end;
+
+	end = g_utf8_find_prev_char (name, name + 64);
+	g_assert (end != NULL);
+	return g_strndup (name, end - name);
+}
+
+static char *
+get_share_name (void)
+{
+	static char *name = NULL;
+	const char *host_name;
+	char *str;
+
+	if (name == NULL) {
+		host_name = g_get_host_name ();
+		if (strcmp (host_name, "localhost") == 0) {
+			/* Translators: The %s will get filled in with the user name
+			   of the user, to form a genitive. If this is difficult to
+			   translate correctly so that it will work correctly in your
+			   language, you may use something equivalent to
+			   "Public files of %s", or leave out the %s altogether.
+			   In the latter case, please put "%.0s" somewhere in the string,
+			   which will match the user name string passed by the C code,
+			   but not put the user name in the final string. This is to
+			   avoid the warning that msgfmt might otherwise generate. */
+			name = g_strdup_printf (_("%s's public files"), g_get_user_name ());
+		} else {
+			/* Translators: This is similar to the string before, only it
+			   has the hostname in it too. */
+			name = g_strdup_printf (_("%s's public files on %s"),
+						g_get_user_name (),
+						host_name);
+		}
+
+	}
+	/* And truncate */
+	if (strlen (name) < AVAHI_LABEL_MAX)
+		return name;
+
+	str = truncate_name (name);
+	g_free (name);
+	name = str;
+
+	return name;
+}
+
+static void
+ensure_conf_dir (void)
+{
+	char *dirname;
+
+	dirname = g_build_filename (g_get_user_config_dir (), "user-share", NULL);
+	g_mkdir_with_parents (dirname, 0755);
+	g_free (dirname);
+}
+
+static void
+httpd_child_setup (gpointer user_data)
+{
+#ifdef HAVE_SELINUX
+	char *mycon;
+	/* If selinux is enabled, avoid transitioning to the httpd_t context,
+	   as this normally means you can't read the users homedir. */
+	if (is_selinux_enabled()) {
+		if (getcon (&mycon) < 0) {
+			abort ();
+		}
+		if (setexeccon (mycon) < 0)
+			abort ();
+		freecon (mycon);
+	}
+#endif
+}
+
+static const char *known_httpd_locations [] = {
+	HTTPD_PROGRAM,
+	"/usr/sbin/httpd",
+	"/usr/sbin/httpd2",
+	"/usr/sbin/apache2",
+	NULL
+};
+
+static char*
+get_httpd_program (void)
+{
+	int i;
+
+	for (i = 0; known_httpd_locations[i]; i++) {
+		if (known_httpd_locations[i][0] == '\0') {
+			/* empty string as first element, happens when
+			 * configured --with-httpd=auto */
+			continue;
+		}
+		if (g_file_test (known_httpd_locations[i], G_FILE_TEST_IS_EXECUTABLE)
+				&& ! g_file_test (known_httpd_locations[i], G_FILE_TEST_IS_DIR)) {
+			return g_strdup (known_httpd_locations[i]);
+		}
+	}
+	return NULL;
+}
+
+static const char *known_httpd_modules_locations [] = {
+	HTTPD_MODULES_PATH,
+	"/etc/httpd/modules",
+	"/usr/lib/apache2/modules",
+	NULL
+};
+
+static gchar*
+get_httpd_modules_path (void)
+{
+	int i;
+
+	for (i = 0; known_httpd_modules_locations[i]; i++) {
+		if (known_httpd_modules_locations[i][0] == '\0') {
+			/* empty string as first element, happens when
+			 * configured --with-httpd=auto */
+			continue;
+		}
+		if (g_file_test (known_httpd_modules_locations[i], G_FILE_TEST_IS_EXECUTABLE)
+				&& g_file_test (known_httpd_modules_locations[i], G_FILE_TEST_IS_DIR)) {
+			return g_strdup (known_httpd_modules_locations[i]);
+		}
+	}
+	return NULL;
+}
+
+static GRegex *version_regex = NULL;
+
+static char*
+get_httpd_config (const char *httpd_program)
+{
+	gchar *standard_output;
+	gchar *cmd_line;
+	GMatchInfo *match_info;
+	gchar *version_number = NULL;
+	gchar *config;
+
+	cmd_line = g_strdup_printf ("%s -v", httpd_program);
+	if (! g_spawn_command_line_sync (cmd_line, &standard_output, NULL, NULL, NULL)) {
+		g_free (cmd_line);
+		return NULL;
+	}
+	g_free (cmd_line);
+
+	if (version_regex == NULL) {
+		version_regex = g_regex_new ("\\d\\.\\d", 0, 0, NULL);
+	}
+
+	if (g_regex_match (version_regex, standard_output, 0, &match_info)) {
+		while (g_match_info_matches (match_info)) {
+			version_number = g_match_info_fetch (match_info, 0);
+			break;
+		}
+		g_match_info_free (match_info);
+		g_free (standard_output);
+	} else {
+		/* Failed to parse httpd version number */
+		g_warning ("Could not parse '%s' as a version for httpd", standard_output);
+		g_free (standard_output);
+		/* assume it is 2.2 */
+		version_number = g_strdup ("2.2");
+	}
+
+	config = g_strdup_printf (HTTPD_CONFIG_TEMPLATE, version_number);
+	g_free (version_number);
+
+	return config;
+}
+
+static gboolean
+spawn_httpd (int port, pid_t *pid_out)
+{
+	char *free1, *free2, *free3, *free4, *free5, *free6, *free7, *free8, *free9;
+	gboolean res;
+	char *argv[10];
+	char *env[10];
+	int i;
+	gint status;
+	char *pid_filename;
+	char *pidfile;
+	GError *error;
+	gboolean got_pidfile;
+	GSettings *settings;
+	char *str;
+	char *public_dir;
+
+	public_dir = lookup_public_dir ();
+	ensure_conf_dir ();
+
+	i = 0;
+	free1 = argv[i++] = get_httpd_program ();
+	if (argv[0] == NULL) {
+		fprintf (stderr, "error finding httpd server\n");
+		return FALSE;
+	}
+
+	argv[i++] = "-f";
+	free2 = argv[i++] = get_httpd_config (argv[0]);
+	argv[i++] = "-C";
+	free3 = argv[i++] = g_strdup_printf ("Listen %d", port);
+
+	settings = g_settings_new (GSETTINGS_SCHEMA);
+	str = g_settings_get_string (settings,
+				       FILE_SHARING_REQUIRE_PASSWORD);
+
+	if (str && strcmp (str, "never") == 0) {
+		/* Do nothing */
+	} else if (str && strcmp (str, "on_write") == 0){
+		argv[i++] = "-D";
+		argv[i++] = "RequirePasswordOnWrite";
+	} else {
+		/* always, or safe fallback */
+		argv[i++] = "-D";
+		argv[i++] = "RequirePasswordAlways";
+	}
+	g_free (str);
+	g_object_unref (settings);
+
+	argv[i] = NULL;
+
+	i = 0;
+	free4 = env[i++] = g_strdup_printf ("HOME=%s", g_get_home_dir());
+	free5 = env[i++] = g_strdup_printf ("XDG_PUBLICSHARE_DIR=%s", public_dir);
+	free6 = env[i++] = g_strdup_printf ("XDG_CONFIG_HOME=%s", g_get_user_config_dir ());
+	free7 = env[i++] = g_strdup_printf ("GUS_SHARE_NAME=%s", get_share_name ());
+	free8 = env[i++] = g_strdup_printf ("GUS_LOGIN_LABEL=%s", "Please log in as the user guest");
+	free9 = env[i++] = g_strdup_printf ("HTTP_MODULES_PATH=%s",get_httpd_modules_path ());
+	env[i++] = "LANG=C";
+	env[i] = NULL;
+
+	pid_filename = g_build_filename (g_get_user_config_dir (), "user-share", "pid", NULL);
+
+	/* Remove pid file before spawning to avoid races with child and old pidfile */
+	unlink (pid_filename);
+
+	error = NULL;
+	res = g_spawn_sync (g_get_home_dir(),
+			    argv, env, 0,
+			    httpd_child_setup, NULL,
+			    NULL, NULL,
+			    &status,
+			    &error);
+	g_free (free1);
+	g_free (free2);
+	g_free (free3);
+	g_free (free4);
+	g_free (free5);
+	g_free (free6);
+	g_free (free7);
+	g_free (free8);
+	g_free (free9);
+	g_free (public_dir);
+
+	if (!res) {
+		fprintf (stderr, "error spawning httpd: %s\n",
+			 error->message);
+		g_error_free (error);
+		g_free (pid_filename);
+		return FALSE;
+	}
+
+	if (status != 0) {
+		g_free (pid_filename);
+		return FALSE;
+	}
+
+	got_pidfile = FALSE;
+	error = NULL;
+	for (i = 0; i < 5; i++) {
+		if (error != NULL)
+			g_error_free (error);
+		error = NULL;
+		if (g_file_get_contents (pid_filename, &pidfile, NULL, &error)) {
+			got_pidfile = TRUE;
+			*pid_out = atoi (pidfile);
+			g_free (pidfile);
+			break;
+		}
+		sleep (1);
+	}
+
+	g_free (pid_filename);
+
+	if (!got_pidfile) {
+		fprintf (stderr, "error opening httpd pidfile: %s\n", error->message);
+		g_error_free (error);
+		return FALSE;
+	}
+	return TRUE;
+}
+
+static void
+kill_httpd (void)
+{
+	if (httpd_pid != 0) {
+		kill (httpd_pid, SIGTERM);
+
+		/* Allow child time to die, we can't waitpid, because its
+		   not a direct child */
+		sleep (1);
+	}
+	httpd_pid = 0;
+}
+
+void
+http_up (void)
+{
+	guint port;
+
+	port = get_port ();
+	if (!spawn_httpd (port, &httpd_pid)) {
+		fprintf (stderr, "spawning httpd failed\n");
+	}
+}
+
+void
+http_down (void)
+{
+	kill_httpd ();
+}
+
+gboolean
+http_init (void)
+{
+	return TRUE;
+}
+
+pid_t
+http_get_pid (void)
+{
+	return httpd_pid;
+}
+
+
+
+ +
+ + diff --git a/2022-11-11-200849-3937-cppcheck@c9d02a6bbcbb_master/2.html b/2022-11-11-200849-3937-cppcheck@c9d02a6bbcbb_master/2.html new file mode 100644 index 0000000..1682147 --- /dev/null +++ b/2022-11-11-200849-3937-cppcheck@c9d02a6bbcbb_master/2.html @@ -0,0 +1,833 @@ + + + + + + Cppcheck - HTML report - mate-user-share + + + + + +
+ + + +
+
  1
+  2
+  3
+  4
+  5
+  6
+  7
+  8
+  9
+ 10
+ 11
+ 12
+ 13
+ 14
+ 15
+ 16
+ 17
+ 18
+ 19
+ 20
+ 21
+ 22
+ 23
+ 24
+ 25
+ 26
+ 27
+ 28
+ 29
+ 30
+ 31
+ 32
+ 33
+ 34
+ 35
+ 36
+ 37
+ 38
+ 39
+ 40
+ 41
+ 42
+ 43
+ 44
+ 45
+ 46
+ 47
+ 48
+ 49
+ 50
+ 51
+ 52
+ 53
+ 54
+ 55
+ 56
+ 57
+ 58
+ 59
+ 60
+ 61
+ 62
+ 63
+ 64
+ 65
+ 66
+ 67
+ 68
+ 69
+ 70
+ 71
+ 72
+ 73
+ 74
+ 75
+ 76
+ 77
+ 78
+ 79
+ 80
+ 81
+ 82
+ 83
+ 84
+ 85
+ 86
+ 87
+ 88
+ 89
+ 90
+ 91
+ 92
+ 93
+ 94
+ 95
+ 96
+ 97
+ 98
+ 99
+100
+101
+102
+103
+104
+105
+106
+107
+108
+109
+110
+111
+112
+113
+114
+115
+116
+117
+118
+119
+120
+121
+122
+123
+124
+125
+126
+127
+128
+129
+130
+131
+132
+133
+134
+135
+136
+137
+138
+139
+140
+141
+142
+143
+144
+145
+146
+147
+148
+149
+150
+151
+152
+153
+154
+155
+156
+157
+158
+159
+160
+161
+162
+163
+164
+165
+166
+167
+168
+169
+170
+171
+172
+173
+174
+175
+176
+177
+178
+179
+180
+181
+182
+183
+184
+185
+186
+187
+188
+189
+190
+191
+192
+193
+194
+195
+196
+197
+198
+199
+200
+201
+202
+203
+204
+205
+206
+207
+208
+209
+210
+211
+212
+213
+214
+215
+216
+217
+218
+219
+220
+221
+222
+223
+224
+225
+226
+227
+228
+229
+230
+231
+232
+233
+234
+235
+236
+237
+238
+239
+240
+241
+242
+243
+244
+245
+246
+247
+248
+249
+250
+251
+252
+253
+254
+255
+256
+257
+258
+259
+260
+261
+262
+263
+264
+265
+266
+267
+268
+269
+270
+271
+272
+273
+274
+275
+276
+277
+278
+279
+280
+281
+282
+283
+284
+285
+286
+287
+288
+289
+290
+291
+292
/* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 8; tab-width: 8 -*-
+ *
+ * Copyright (C) 2003 Novell, Inc.
+ * Copyright (C) 2003-2004 Red Hat, Inc.
+ * Copyright (C) 2005 William Jon McCann <mccann@jhu.edu>
+ * Copyright (C) 2012-2021 MATE Developers
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * 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 Foundation, Inc., 51 Franklin St, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ *
+ */
+
+#include "config.h"
+
+#include <stdlib.h>
+#include <string.h>
+#include <glib/gi18n-lib.h>
+#include <gtk/gtk.h>
+#include <libcaja-extension/caja-menu-provider.h>
+#include <libcaja-extension/caja-location-widget-provider.h>
+
+#ifdef HAVE_BLUETOOTH
+#include <bluetooth-client.h>
+#endif
+
+#include "caja-share-bar.h"
+#include "user_share-common.h"
+
+#define CAJA_TYPE_USER_SHARE  (caja_user_share_get_type ())
+#define CAJA_USER_SHARE(o)    (G_TYPE_CHECK_INSTANCE_CAST ((o), CAJA_TYPE_USER_SHARE, CajaUserShare))
+#define CAJA_IS_USER_SHARE(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), CAJA_TYPE_USER_SHARE))
+
+typedef struct
+{
+        GObject              parent_slot;
+} CajaUserShare;
+
+typedef struct
+{
+        GObjectClass parent_slot;
+} CajaUserShareClass;
+
+static GType caja_user_share_get_type      (void);
+static void  caja_user_share_register_type (GTypeModule *module);
+
+static void
+launch_process (char **argv, GtkWindow *parent)
+{
+        GError *error;
+        GtkWidget *dialog;
+
+        error = NULL;
+        if (!g_spawn_async (NULL,
+                            argv, NULL,
+                            0,
+                            NULL, NULL,
+                            NULL,
+                            &error)) {
+
+
+                dialog = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL, GTK_MESSAGE_WARNING,
+						 GTK_BUTTONS_OK, _("Unable to launch the Personal File Sharing preferences"));
+
+                gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog), "%s", error->message);
+
+                gtk_dialog_run (GTK_DIALOG (dialog));
+                gtk_widget_destroy (dialog);
+
+                g_error_free (error);
+        }
+}
+
+static void
+launch_prefs_on_window (GtkWindow *window)
+{
+        char *argv [2];
+
+        argv [0] = g_build_filename (BINDIR, "mate-file-share-properties", NULL);
+        argv [1] = NULL;
+
+        launch_process (argv, window);
+
+        g_free (argv [0]);
+}
+
+static void
+bar_response_cb (CajaShareBar *bar,
+                 gint response,
+                 gpointer         data)
+{
+        if (response == CAJA_SHARE_BAR_RESPONSE_PREFERENCES) {
+                launch_prefs_on_window (GTK_WINDOW (data));
+        }
+}
+
+#ifdef HAVE_BLUETOOTH
+static void
+downloads_bar_set_from_bluetooth_status (GtkWidget *bar)
+{
+	BluetoothClient *client;
+	gboolean bt_powered;
+
+	client = g_object_get_data (G_OBJECT (bar), "bluetooth-client");
+	g_object_get (G_OBJECT (client),
+		      "default-adapter-powered", &bt_powered,
+		      NULL);
+	gtk_widget_set_visible (bar, bt_powered);
+}
+
+static void
+default_adapter_powered_cb (GObject    *gobject,
+			    GParamSpec *pspec,
+			    GtkWidget  *bar)
+{
+	downloads_bar_set_from_bluetooth_status (bar);
+}
+#endif /* HAVE_BLUETOOTH */
+
+static GtkWidget *
+caja_user_share_get_location_widget (CajaLocationWidgetProvider *iface,
+                                         const char                     *uri,
+                                         GtkWidget                      *window)
+{
+	GFile             *file;
+	GtkWidget         *bar;
+	guint              i;
+	gboolean           enable = FALSE;
+	GFile             *home;
+#ifdef HAVE_BLUETOOTH
+	const GUserDirectory special_dirs[] = { G_USER_DIRECTORY_PUBLIC_SHARE, G_USER_DIRECTORY_DOWNLOAD };
+
+	gboolean is_dir[] = { FALSE, FALSE };
+#else
+	const GUserDirectory special_dirs[] = { G_USER_DIRECTORY_PUBLIC_SHARE };
+
+	gboolean is_dir[] = { FALSE };
+#endif /* HAVE_BLUETOOTH */
+	file = g_file_new_for_uri (uri);
+	home = g_file_new_for_path (g_get_home_dir ());
+
+	/* We don't show anything in $HOME */
+	if (g_file_equal (home, file)) {
+		g_object_unref (home);
+		g_object_unref (file);
+		return NULL;
+	}
+
+	g_object_unref (home);
+
+	for (i = 0; i < G_N_ELEMENTS (special_dirs); i++) {
+		GFile *dir;
+		dir = lookup_dir_with_fallback (special_dirs[i]);
+		if (g_file_equal (dir, file)) {
+			enable = TRUE;
+			is_dir[i] = TRUE;
+		}
+		g_object_unref (dir);
+	}
+
+	g_object_unref (file);
+
+	if (enable == FALSE)
+		return NULL;
+
+	if (is_dir[0] != FALSE) {
+#ifdef HAVE_BLUETOOTH
+		if (is_dir[1] != FALSE) {
+			bar = caja_share_bar_new (_("May be used to share or receive files"));
+		} else {
+			bar = caja_share_bar_new (_("May be shared over the network or Bluetooth"));
+		}
+#else
+		bar = caja_share_bar_new (_("May be shared over the network"));
+#endif /* HAVE_BLUETOOTH */
+	} else {
+#ifdef HAVE_BLUETOOTH
+		BluetoothClient *client;
+
+		bar = caja_share_bar_new (_("May be used to receive files over Bluetooth"));
+
+		gtk_widget_set_no_show_all (bar, TRUE);
+		client = bluetooth_client_new ();
+		g_object_set_data_full (G_OBJECT (bar), "bluetooth-client", client, g_object_unref);
+		g_signal_connect (G_OBJECT (client), "notify::default-adapter-powered",
+				  G_CALLBACK (default_adapter_powered_cb), bar);
+		downloads_bar_set_from_bluetooth_status (bar);
+#endif /* HAVE_BLUETOOTH */
+	}
+
+	g_signal_connect (bar, "response",
+			  G_CALLBACK (bar_response_cb),
+			  window);
+
+	gtk_widget_show_all (bar);
+
+	return bar;
+}
+
+static void
+caja_user_share_location_widget_provider_iface_init (CajaLocationWidgetProviderIface *iface)
+{
+        iface->get_widget = caja_user_share_get_location_widget;
+}
+
+static void
+caja_user_share_instance_init (CajaUserShare *share)
+{
+
+}
+
+static void
+caja_user_share_class_init (CajaUserShareClass *klass)
+{
+
+}
+
+static GType share_type = 0;
+
+static GType
+caja_user_share_get_type (void)
+{
+        return share_type;
+}
+
+static void
+caja_user_share_register_type (GTypeModule *module)
+{
+        static const GTypeInfo info = {
+                sizeof (CajaUserShareClass),
+                (GBaseInitFunc) NULL,
+                (GBaseFinalizeFunc) NULL,
+                (GClassInitFunc) caja_user_share_class_init,
+                NULL,
+                NULL,
+                sizeof (CajaUserShare),
+                0,
+                (GInstanceInitFunc) caja_user_share_instance_init,
+        };
+
+        static const GInterfaceInfo location_widget_provider_iface_info = {
+                (GInterfaceInitFunc) caja_user_share_location_widget_provider_iface_init,
+                NULL,
+                NULL
+        };
+
+        share_type = g_type_module_register_type (module,
+                                                 G_TYPE_OBJECT,
+                                                 "CajaUserShare",
+                                                 &info, 0);
+
+        g_type_module_add_interface (module,
+                                     share_type,
+                                     CAJA_TYPE_LOCATION_WIDGET_PROVIDER,
+                                     &location_widget_provider_iface_info);
+}
+
+void
+caja_module_initialize (GTypeModule *module)
+{
+        caja_user_share_register_type (module);
+        bindtextdomain (GETTEXT_PACKAGE, MATELOCALEDIR);
+        bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
+}
+
+void
+caja_module_shutdown (void)
+{
+}
+
+void
+caja_module_list_types (const GType **types,
+                            int          *num_types)
+{
+        static GType type_list [1];
+
+        type_list[0] = CAJA_TYPE_USER_SHARE;
+
+        *types = type_list;
+        *num_types = 1;
+}
+
+
+
+ +
+ + diff --git a/2022-11-11-200849-3937-cppcheck@c9d02a6bbcbb_master/3.html b/2022-11-11-200849-3937-cppcheck@c9d02a6bbcbb_master/3.html new file mode 100644 index 0000000..7bdfa00 --- /dev/null +++ b/2022-11-11-200849-3937-cppcheck@c9d02a6bbcbb_master/3.html @@ -0,0 +1,1251 @@ + + + + + + Cppcheck - HTML report - mate-user-share + + + + + +
+ + + +
+
  1
+  2
+  3
+  4
+  5
+  6
+  7
+  8
+  9
+ 10
+ 11
+ 12
+ 13
+ 14
+ 15
+ 16
+ 17
+ 18
+ 19
+ 20
+ 21
+ 22
+ 23
+ 24
+ 25
+ 26
+ 27
+ 28
+ 29
+ 30
+ 31
+ 32
+ 33
+ 34
+ 35
+ 36
+ 37
+ 38
+ 39
+ 40
+ 41
+ 42
+ 43
+ 44
+ 45
+ 46
+ 47
+ 48
+ 49
+ 50
+ 51
+ 52
+ 53
+ 54
+ 55
+ 56
+ 57
+ 58
+ 59
+ 60
+ 61
+ 62
+ 63
+ 64
+ 65
+ 66
+ 67
+ 68
+ 69
+ 70
+ 71
+ 72
+ 73
+ 74
+ 75
+ 76
+ 77
+ 78
+ 79
+ 80
+ 81
+ 82
+ 83
+ 84
+ 85
+ 86
+ 87
+ 88
+ 89
+ 90
+ 91
+ 92
+ 93
+ 94
+ 95
+ 96
+ 97
+ 98
+ 99
+100
+101
+102
+103
+104
+105
+106
+107
+108
+109
+110
+111
+112
+113
+114
+115
+116
+117
+118
+119
+120
+121
+122
+123
+124
+125
+126
+127
+128
+129
+130
+131
+132
+133
+134
+135
+136
+137
+138
+139
+140
+141
+142
+143
+144
+145
+146
+147
+148
+149
+150
+151
+152
+153
+154
+155
+156
+157
+158
+159
+160
+161
+162
+163
+164
+165
+166
+167
+168
+169
+170
+171
+172
+173
+174
+175
+176
+177
+178
+179
+180
+181
+182
+183
+184
+185
+186
+187
+188
+189
+190
+191
+192
+193
+194
+195
+196
+197
+198
+199
+200
+201
+202
+203
+204
+205
+206
+207
+208
+209
+210
+211
+212
+213
+214
+215
+216
+217
+218
+219
+220
+221
+222
+223
+224
+225
+226
+227
+228
+229
+230
+231
+232
+233
+234
+235
+236
+237
+238
+239
+240
+241
+242
+243
+244
+245
+246
+247
+248
+249
+250
+251
+252
+253
+254
+255
+256
+257
+258
+259
+260
+261
+262
+263
+264
+265
+266
+267
+268
+269
+270
+271
+272
+273
+274
+275
+276
+277
+278
+279
+280
+281
+282
+283
+284
+285
+286
+287
+288
+289
+290
+291
+292
+293
+294
+295
+296
+297
+298
+299
+300
+301
+302
+303
+304
+305
+306
+307
+308
+309
+310
+311
+312
+313
+314
+315
+316
+317
+318
+319
+320
+321
+322
+323
+324
+325
+326
+327
+328
+329
+330
+331
+332
+333
+334
+335
+336
+337
+338
+339
+340
+341
+342
+343
+344
+345
+346
+347
+348
+349
+350
+351
+352
+353
+354
+355
+356
+357
+358
+359
+360
+361
+362
+363
+364
+365
+366
+367
+368
+369
+370
+371
+372
+373
+374
+375
+376
+377
+378
+379
+380
+381
+382
+383
+384
+385
+386
+387
+388
+389
+390
+391
+392
+393
+394
+395
+396
+397
+398
+399
+400
+401
+402
+403
+404
+405
+406
+407
+408
+409
+410
+411
+412
+413
+414
+415
+416
+417
+418
+419
+420
+421
+422
+423
+424
+425
+426
+427
+428
+429
+430
+431
+432
+433
+434
+435
+436
+437
+438
+439
+440
+441
+442
+443
+444
+445
+446
+447
+448
+449
+450
+451
+452
+453
+454
+455
+456
+457
+458
+459
+460
+461
+462
+463
+464
+465
+466
+467
+468
+469
+470
+471
+472
+473
+474
+475
+476
+477
+478
+479
+480
+481
+482
+483
+484
+485
+486
+487
+488
+489
+490
+491
+492
+493
+494
+495
+496
+497
+498
+499
+500
+501
+502
+503
+504
+505
+506
+507
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
+
+/*
+ *  Copyright (C) 2004-2008 Red Hat, Inc.
+ *  Copyright (C) 2012-2021 MATE Developers
+ *
+ *  Caja is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU General Public License as
+ *  published by the Free Software Foundation; either version 2 of the
+ *  License, or (at your option) any later version.
+ *
+ *  Caja is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  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
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ *  Authors: Alexander Larsson <alexl@redhat.com>
+ *
+ */
+
+#include "config.h"
+
+#include <gdk/gdkx.h>
+#include <gtk/gtk.h>
+#include <glib/gi18n.h>
+#include <glib/gstdio.h>
+#include <gio/gio.h>
+#include <X11/Xlib.h>
+
+#include "user_share-private.h"
+#include "user_share-common.h"
+#include "http.h"
+
+#ifdef HAVE_BLUETOOTH
+#include <bluetooth-client.h>
+
+#include "obexftp.h"
+#include "obexpush.h"
+
+#endif /* HAVE_BLUETOOTH */
+
+#include <gio/gio.h>
+
+#include <stdarg.h>
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <signal.h>
+#include <unistd.h>
+
+static guint disabled_timeout_tag = 0;
+static GSettings* settings;<--- Shadowed declaration
+
+#define GSETTINGS_SCHEMA "org.mate.FileSharing"
+#define GSETTINGS_KEY_FILE_SHARING_ENABLED "enabled"
+#define GSETTINGS_KEY_FILE_SHARING_REQUIRE_PASSWORD "require-password"
+
+#ifdef HAVE_BLUETOOTH
+/* MATE Session */
+#define MATE_SESSION_DBUS_NAME      "org.gnome.SessionManager"
+#define MATE_SESSION_DBUS_OBJECT    "/org/gnome/SessionManager"
+#define MATE_SESSION_DBUS_INTERFACE "org.gnome.SessionManager"
+
+static GDBusProxy *session_proxy = NULL;
+static gboolean has_console = TRUE;
+
+static BluetoothClient *client = NULL;
+static gboolean bluetoothd_enabled = FALSE;
+
+#define OBEX_ENABLED (bluetoothd_enabled && has_console)
+
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_ENABLED "bluetooth-enabled"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_ALLOW_WRITE "bluetooth-allow-write"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_REQUIRE_PAIRING "bluetooth-require-pairing"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED "bluetooth-obexpush-enabled"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_ACCEPT_FILES "bluetooth-accept-files"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_NOTIFY "bluetooth-notify"
+
+
+static void
+obex_services_start (void)
+{
+	GSettings *settings;
+
+	if (bluetoothd_enabled == FALSE ||
+	    has_console == FALSE)
+	    	return;
+
+	settings = g_settings_new(GSETTINGS_SCHEMA);
+
+	if (g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED) == TRUE) {
+	    obexpush_up ();
+	}
+	if (g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_ENABLED) == TRUE) {
+	    obexftp_up ();
+	}
+
+	g_object_unref (client);
+}
+
+static void
+obex_services_shutdown (void)
+{
+	obexpush_down ();
+	obexftp_down ();
+}
+
+static void
+session_properties_changed_cb (GDBusProxy      *session,
+			       GVariant        *changed,
+			       char           **invalidated,
+			       gpointer         user_data)
+{
+	GVariant *v;
+
+	v = g_variant_lookup_value (changed, "SessionIsActive", G_VARIANT_TYPE_BOOLEAN);
+	if (v) {
+		has_console = g_variant_get_boolean (v);
+		g_debug ("Received session is active change: now %s", has_console ? "active" : "inactive");
+
+		if (has_console)
+			obex_services_start ();
+		else
+			obex_services_shutdown ();
+
+		g_variant_unref (v);
+	}
+}
+
+static gboolean
+is_session_active (void)
+{
+	GVariant *variant;
+	gboolean is_session_active = FALSE;
+
+	variant = g_dbus_proxy_get_cached_property (session_proxy,
+						    "SessionIsActive");
+	if (variant) {
+		is_session_active = g_variant_get_boolean (variant);
+		g_variant_unref (variant);
+ 	}
+
+	return is_session_active;
+}
+
+static void
+session_init (void)
+{
+	GError *error = NULL;
+
+	session_proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION,
+						       G_DBUS_PROXY_FLAGS_NONE,
+						       NULL,
+						       MATE_SESSION_DBUS_NAME,
+						       MATE_SESSION_DBUS_OBJECT,
+						       MATE_SESSION_DBUS_INTERFACE,
+						       NULL,
+						       &error);
+	if (session_proxy == NULL) {
+		g_warning ("Failed to get session proxy: %s", error->message);
+		g_error_free (error);
+		return;
+	}
+	g_signal_connect (session_proxy, "g-properties-changed",
+			  G_CALLBACK (session_properties_changed_cb),
+			  NULL);
+	has_console = is_session_active ();
+}
+
+static void
+default_adapter_changed (GObject    *gobject,<--- Parameter 'gobject' can be declared with const
+			 GParamSpec *pspec,
+			 gpointer    user_data)
+{
+	char *adapter;
+	gboolean adapter_powered;
+
+	g_object_get (G_OBJECT (client),
+		      "default-adapter", &adapter,
+		      "default-adapter-powered", &adapter_powered,
+		      NULL);
+	if (adapter != NULL && *adapter != '\0') {
+		bluetoothd_enabled = adapter_powered;
+	} else {
+		bluetoothd_enabled = FALSE;
+	}
+
+	/* Were we called as init, or as a callback */
+	if (gobject != NULL) {
+		if (bluetoothd_enabled != FALSE)
+			obex_services_start ();
+		else
+			obex_services_shutdown ();
+	}
+}
+
+static void
+bluez_init (void)
+{
+	client = bluetooth_client_new ();
+	default_adapter_changed (NULL, NULL, NULL);
+	g_signal_connect (G_OBJECT (client), "notify::default-adapter",
+			  G_CALLBACK (default_adapter_changed), NULL);
+	g_signal_connect (G_OBJECT (client), "notify::default-adapter-powered",
+			  G_CALLBACK (default_adapter_changed), NULL);
+}
+#endif /* HAVE_BLUETOOTH */
+
+static gboolean
+file_sharing_enabled (void)
+{
+	gboolean enabled = TRUE;
+	settings = g_settings_new (GSETTINGS_SCHEMA);
+
+#ifdef HAVE_BLUETOOTH
+	if (g_settings_get_boolean (settings, FILE_SHARING_ENABLED) == FALSE &&
+	    g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_ENABLED) == FALSE &&
+	    g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED) == FALSE)
+#else /* HAVE_BLUETOOTH */
+	if (g_settings_get_boolean (settings, FILE_SHARING_ENABLED) == FALSE)
+#endif /* HAVE_BLUETOOTH */
+		enabled = FALSE;
+
+	g_object_unref (settings);
+
+	return enabled;
+}
+
+static void
+migrate_old_configuration (void)
+{
+	const char *old_config_dir;
+	const char *new_config_dir;
+
+	old_config_dir = g_build_filename (g_get_home_dir (), ".mate2", "user-share", NULL);
+	new_config_dir = g_build_filename (g_get_user_config_dir (), "user-share", NULL);
+	if (g_file_test (old_config_dir, G_FILE_TEST_IS_DIR))
+		g_rename (old_config_dir, new_config_dir);
+
+}
+
+static void
+require_password_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	/* Need to restart to get new password setting */
+	if (http_get_pid () != 0) {
+		http_down ();
+		http_up ();
+	}
+}
+
+/* File sharing was disabled for some time, exit now */
+/* If we re-enable it in the ui, this will be restarted anyway */
+static gboolean
+disabled_timeout_callback (gpointer user_data)
+{
+	GSettings *settings = (GSettings *) user_data;
+	http_down ();
+
+#ifdef HAVE_BLUETOOTH
+	if (g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_ENABLED) == FALSE &&
+	    g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED) == FALSE)
+		_exit (0);
+#else /* HAVE_BLUETOOTH */
+	if (g_settings_get_boolean (settings, FILE_SHARING_ENABLED) == FALSE)
+		_exit (0);
+#endif /* HAVE_BLUETOOTH */
+	return FALSE;
+}
+
+static void
+file_sharing_enabled_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	gboolean enabled;
+
+	if (disabled_timeout_tag != 0) {
+		g_source_remove (disabled_timeout_tag);
+		disabled_timeout_tag = 0;
+	}
+
+	enabled = g_settings_get_boolean (settings,
+					 FILE_SHARING_ENABLED);
+	if (enabled) {
+		if (http_get_pid () == 0) {
+			http_up ();
+		}
+	} else {
+		http_down ();
+		disabled_timeout_tag = g_timeout_add_seconds (3,
+							      (GSourceFunc)disabled_timeout_callback,
+							      settings);
+	}
+}
+
+#ifdef HAVE_BLUETOOTH
+static void
+file_sharing_bluetooth_allow_write_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	if (g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_ENABLED) != FALSE)
+		obexftp_restart ();
+}
+
+static void
+file_sharing_bluetooth_require_pairing_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	if (g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_ENABLED) != FALSE) {
+		/* We need to fully reset the session,
+		 * otherwise the new setting isn't taken into account */
+		obexftp_down ();
+		obexftp_up ();
+	}
+}
+
+static void
+file_sharing_bluetooth_enabled_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	if (g_settings_get_boolean (settings,
+				   FILE_SHARING_BLUETOOTH_ENABLED) == FALSE) {
+		obexftp_down ();
+		if (g_settings_get_boolean (settings, FILE_SHARING_ENABLED) == FALSE &&
+		    g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED) == FALSE) {
+			_exit (0);
+		}
+	} else if (OBEX_ENABLED) {
+		obexftp_up ();
+	}
+}
+
+static void
+file_sharing_bluetooth_obexpush_enabled_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	if (g_settings_get_boolean (settings,
+				   FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED) == FALSE) {
+		obexpush_down ();
+		if (g_settings_get_boolean (settings, FILE_SHARING_ENABLED) == FALSE &&
+		    g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_ENABLED) == FALSE) {
+			_exit (0);
+		}
+	} else if (OBEX_ENABLED) {
+		obexpush_up ();
+	}
+}
+
+static void
+file_sharing_bluetooth_obexpush_accept_files_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	AcceptSetting setting;
+	char *str;
+
+	str = g_settings_get_string (settings, FILE_SHARING_BLUETOOTH_OBEXPUSH_ACCEPT_FILES);
+	setting = accept_setting_from_string (str);
+	g_free (str);
+
+	obexpush_set_accept_files_policy (setting);
+}
+
+static void
+file_sharing_bluetooth_obexpush_notify_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	obexpush_set_notify (g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_OBEXPUSH_NOTIFY));
+}
+#endif /* HAVE_BLUETOOTH */
+
+static RETSIGTYPE
+cleanup_handler (int sig)
+{
+	http_down ();
+#ifdef HAVE_BLUETOOTH
+	obexftp_down ();
+	obexpush_down ();
+#endif /* HAVE_BLUETOOTH */
+	_exit (2);
+}
+
+static int
+x_io_error_handler (Display *xdisplay)
+{
+	http_down ();
+#ifdef HAVE_BLUETOOTH
+	obexftp_down ();
+#endif /* HAVE_BLUETOOTH */
+	_exit (2);
+}
+
+int
+main (int argc, char **argv)
+{
+	GSettings *settings;<--- Shadow variable
+	Display *xdisplay;
+	G_GNUC_UNUSED int x_fd;
+	Window selection_owner;
+	Atom xatom;
+
+	bindtextdomain (GETTEXT_PACKAGE, MATELOCALEDIR);
+	bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
+	textdomain (GETTEXT_PACKAGE);
+
+	gtk_init (&argc, &argv);
+
+	if (g_strcmp0 (g_get_real_name (), "root") == 0) {
+		g_warning ("mate-user-share cannot be started as root for security reasons.");
+		return 1;
+	}
+
+	signal (SIGPIPE, SIG_IGN);
+	signal (SIGINT, cleanup_handler);
+	signal (SIGHUP, cleanup_handler);
+	signal (SIGTERM, cleanup_handler);
+
+	xdisplay = GDK_DISPLAY_XDISPLAY (gdk_display_get_default ());
+	if (xdisplay == NULL) {
+		g_warning ("Can't open display");
+		return 1;
+	}
+
+	xatom = XInternAtom (xdisplay, "_MATE_USER_SHARE", FALSE);
+	selection_owner = XGetSelectionOwner (xdisplay, xatom);
+
+	if (selection_owner != None) {
+		/* There is an owner already, quit */
+		return 1;
+	}
+
+	selection_owner = XCreateSimpleWindow (xdisplay,
+					       RootWindow (xdisplay, 0),
+					       0, 0, 1, 1,
+					       0, 0, 0);
+	XSetSelectionOwner (xdisplay, xatom, selection_owner, CurrentTime);
+
+	if (XGetSelectionOwner (xdisplay, xatom) != selection_owner) {
+		/* Didn't get the selection */
+		return 1;
+	}
+
+	migrate_old_configuration ();
+
+	if (!file_sharing_enabled ())
+		return 1;
+
+	settings = g_settings_new (GSETTINGS_SCHEMA);
+
+	x_fd = ConnectionNumber (xdisplay);
+	XSetIOErrorHandler (x_io_error_handler);
+
+	if (http_init () == FALSE)
+		return 1;
+#ifdef HAVE_BLUETOOTH
+	if (obexftp_init () == FALSE)
+		return 1;
+	if (obexpush_init () == FALSE)
+		return 1;
+#endif /* HAVE_BLUETOOTH */
+
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_ENABLED,
+			     G_CALLBACK (file_sharing_enabled_changed), NULL);
+
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_REQUIRE_PASSWORD,
+			     G_CALLBACK (require_password_changed), NULL);
+
+#ifdef HAVE_BLUETOOTH
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_ENABLED,
+			     G_CALLBACK (file_sharing_bluetooth_enabled_changed), NULL);
+
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_ALLOW_WRITE,
+			     G_CALLBACK (file_sharing_bluetooth_allow_write_changed), NULL);
+
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_REQUIRE_PAIRING,
+			     G_CALLBACK (file_sharing_bluetooth_require_pairing_changed), NULL);
+
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED,
+			     G_CALLBACK (file_sharing_bluetooth_obexpush_enabled_changed), NULL);
+
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_ACCEPT_FILES,
+			     G_CALLBACK (file_sharing_bluetooth_obexpush_accept_files_changed), NULL);
+
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_NOTIFY,
+			     G_CALLBACK (file_sharing_bluetooth_obexpush_notify_changed), NULL);
+
+	bluez_init ();
+	session_init ();
+#endif /* HAVE_BLUETOOTH */
+
+	/* Initial setting */
+	file_sharing_enabled_changed (settings, NULL, NULL);
+#ifdef HAVE_BLUETOOTH
+	file_sharing_bluetooth_enabled_changed (settings, NULL, NULL);
+	file_sharing_bluetooth_obexpush_accept_files_changed (settings, NULL, NULL);
+	file_sharing_bluetooth_obexpush_notify_changed (settings, NULL, NULL);
+	file_sharing_bluetooth_obexpush_enabled_changed (settings, NULL, NULL);
+#endif /* HAVE_BLUETOOTH */
+
+	gtk_main ();
+
+	return 0;
+}
+
+
+
+ +
+ + diff --git a/2022-11-11-200849-3937-cppcheck@c9d02a6bbcbb_master/index.html b/2022-11-11-200849-3937-cppcheck@c9d02a6bbcbb_master/index.html new file mode 100644 index 0000000..b780b4e --- /dev/null +++ b/2022-11-11-200849-3937-cppcheck@c9d02a6bbcbb_master/index.html @@ -0,0 +1,212 @@ + + + + + + Cppcheck - HTML report - mate-user-share + + + + + +
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + +
LineIdCWESeverityMessage
missingIncludeinformationCppcheck cannot find all the include files (use --check-config for details)
src/file-share-properties.c
83variableScope398styleThe scope of the variable 'password' can be reduced.
106unusedVariable563styleUnused variable: accept_setting
621variableScope398styleThe scope of the variable 'window' can be reduced.
src/http.c
115variableScope398styleThe scope of the variable 'host_name' can be reduced.
src/share-extension.c
62variableScope398styleThe scope of the variable 'dialog' can be reduced.
src/user_share.c
175constParameter398styleParameter 'gobject' can be declared with const
392shadowVariable398styleLocal variable 'settings' shadows outer variable
+
+ +
+ + diff --git a/2022-11-11-200849-3937-cppcheck@c9d02a6bbcbb_master/stats.html b/2022-11-11-200849-3937-cppcheck@c9d02a6bbcbb_master/stats.html new file mode 100644 index 0000000..93d49a4 --- /dev/null +++ b/2022-11-11-200849-3937-cppcheck@c9d02a6bbcbb_master/stats.html @@ -0,0 +1,170 @@ + + + + + + Cppcheck - HTML report - mate-user-share + + + + + +
+ + + +
+

Top 10 files for style severity, total findings: 7
+   3  src/file-share-properties.c
+   2  src/user_share.c
+   1  src/share-extension.c
+   1  src/http.c
+

+ +
+ +
+ + diff --git a/2022-11-11-200849-3937-cppcheck@c9d02a6bbcbb_master/style.css b/2022-11-11-200849-3937-cppcheck@c9d02a6bbcbb_master/style.css new file mode 100644 index 0000000..3897bfa --- /dev/null +++ b/2022-11-11-200849-3937-cppcheck@c9d02a6bbcbb_master/style.css @@ -0,0 +1,177 @@ + +body { + font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif; + font-size: 13px; + line-height: 1.5; + height: 100%; + margin: 0; +} + +#wrapper { + position: fixed; + height: 100vh; + width: 100vw; + display: grid; + grid-template-rows: fit-content(8rem) auto fit-content(8rem); + grid-template-columns: fit-content(25%) 1fr; + grid-template-areas: + "header header" + "menu content" + "footer footer"; +} + +h1 { + margin: 0 0 8px -2px; + font-size: 175%; +} + +.header { + padding: 0 0 5px 15px; + grid-area: header; + border-bottom: thin solid #aaa; +} + +.footer { + grid-area: footer; + border-top: thin solid #aaa; + font-size: 85%; + +} + +.footer > p { + margin: 4px; +} + +#menu, +#menu_index { + grid-area: menu; + text-align: left; + overflow: auto; + padding: 0 23px 15px 15px; + border-right: thin solid #aaa; + min-width: 200px; +} + +#menu > a { + display: block; + margin-left: 10px; + font-size: 12px; +} + +#content, +#content_index { + grid-area: content; + padding: 0px 5px 15px 15px; + overflow: auto; +} + +label { + white-space: nowrap; +} + +label.checkBtn.disabled { + color: #606060; + background: #e0e0e0; + font-style: italic; +} + +label.checkBtn, input[type="text"] { + border: 1px solid grey; + border-radius: 4px; + box-shadow: 1px 1px inset; + padding: 1px 5px; +} + +label.checkBtn { + white-space: nowrap; + background: #ccddff; +} + +label.unchecked { + background: #eff8ff; + box-shadow: 1px 1px 1px; +} + +label.checkBtn:hover, label.unchecked:hover{ + box-shadow: 0 0 2px; +} + +label.disabled:hover { + box-shadow: 1px 1px inset; +} + +label.checkBtn > input { + display:none; +} + +.summaryTable { + width: 100%; +} + +table.summaryTable td { padding: 0 5px 0 5px; } + +.statHeader, .severityHeader { + font-weight: bold; +} + +.warning { + background-color: #ffffa7; +} + +.error { + background-color: #ffb7b7; +} + +.error2 { + background-color: #faa; + display: inline-block; + margin-left: 4px; +} + +.inconclusive { + background-color: #b6b6b4; +} + +.inconclusive2 { + background-color: #b6b6b4; + display: inline-block; + margin-left: 4px; +} + +.verbose { + display: inline-block; + vertical-align: top; + cursor: help; +} + +.verbose .content { + display: none; + position: absolute; + padding: 10px; + margin: 4px; + max-width: 40%; + white-space: pre-wrap; + border: 1px solid #000; + background-color: #ffffcc; + cursor: auto; +} + +.highlight .hll { + padding: 1px; +} + +.highlighttable { + background-color: #fff; + position: relative; + margin: -10px; +} + +.linenos { + border-right: thin solid #aaa; + color: #d3d3d3; + padding-right: 6px; +} + +.id-filtered, .severity-filtered, .file-filtered, .tool-filtered, .text-filtered { + visibility: collapse; +} diff --git a/2022-11-11-201040-0718-cppcheck@c9d02a6bbcbb_v1.27.0/0.html b/2022-11-11-201040-0718-cppcheck@c9d02a6bbcbb_v1.27.0/0.html new file mode 100644 index 0000000..7a4ab90 --- /dev/null +++ b/2022-11-11-201040-0718-cppcheck@c9d02a6bbcbb_v1.27.0/0.html @@ -0,0 +1,1567 @@ + + + + + + Cppcheck - HTML report - mate-user-share + + + + + +
+ + + +
+
  1
+  2
+  3
+  4
+  5
+  6
+  7
+  8
+  9
+ 10
+ 11
+ 12
+ 13
+ 14
+ 15
+ 16
+ 17
+ 18
+ 19
+ 20
+ 21
+ 22
+ 23
+ 24
+ 25
+ 26
+ 27
+ 28
+ 29
+ 30
+ 31
+ 32
+ 33
+ 34
+ 35
+ 36
+ 37
+ 38
+ 39
+ 40
+ 41
+ 42
+ 43
+ 44
+ 45
+ 46
+ 47
+ 48
+ 49
+ 50
+ 51
+ 52
+ 53
+ 54
+ 55
+ 56
+ 57
+ 58
+ 59
+ 60
+ 61
+ 62
+ 63
+ 64
+ 65
+ 66
+ 67
+ 68
+ 69
+ 70
+ 71
+ 72
+ 73
+ 74
+ 75
+ 76
+ 77
+ 78
+ 79
+ 80
+ 81
+ 82
+ 83
+ 84
+ 85
+ 86
+ 87
+ 88
+ 89
+ 90
+ 91
+ 92
+ 93
+ 94
+ 95
+ 96
+ 97
+ 98
+ 99
+100
+101
+102
+103
+104
+105
+106
+107
+108
+109
+110
+111
+112
+113
+114
+115
+116
+117
+118
+119
+120
+121
+122
+123
+124
+125
+126
+127
+128
+129
+130
+131
+132
+133
+134
+135
+136
+137
+138
+139
+140
+141
+142
+143
+144
+145
+146
+147
+148
+149
+150
+151
+152
+153
+154
+155
+156
+157
+158
+159
+160
+161
+162
+163
+164
+165
+166
+167
+168
+169
+170
+171
+172
+173
+174
+175
+176
+177
+178
+179
+180
+181
+182
+183
+184
+185
+186
+187
+188
+189
+190
+191
+192
+193
+194
+195
+196
+197
+198
+199
+200
+201
+202
+203
+204
+205
+206
+207
+208
+209
+210
+211
+212
+213
+214
+215
+216
+217
+218
+219
+220
+221
+222
+223
+224
+225
+226
+227
+228
+229
+230
+231
+232
+233
+234
+235
+236
+237
+238
+239
+240
+241
+242
+243
+244
+245
+246
+247
+248
+249
+250
+251
+252
+253
+254
+255
+256
+257
+258
+259
+260
+261
+262
+263
+264
+265
+266
+267
+268
+269
+270
+271
+272
+273
+274
+275
+276
+277
+278
+279
+280
+281
+282
+283
+284
+285
+286
+287
+288
+289
+290
+291
+292
+293
+294
+295
+296
+297
+298
+299
+300
+301
+302
+303
+304
+305
+306
+307
+308
+309
+310
+311
+312
+313
+314
+315
+316
+317
+318
+319
+320
+321
+322
+323
+324
+325
+326
+327
+328
+329
+330
+331
+332
+333
+334
+335
+336
+337
+338
+339
+340
+341
+342
+343
+344
+345
+346
+347
+348
+349
+350
+351
+352
+353
+354
+355
+356
+357
+358
+359
+360
+361
+362
+363
+364
+365
+366
+367
+368
+369
+370
+371
+372
+373
+374
+375
+376
+377
+378
+379
+380
+381
+382
+383
+384
+385
+386
+387
+388
+389
+390
+391
+392
+393
+394
+395
+396
+397
+398
+399
+400
+401
+402
+403
+404
+405
+406
+407
+408
+409
+410
+411
+412
+413
+414
+415
+416
+417
+418
+419
+420
+421
+422
+423
+424
+425
+426
+427
+428
+429
+430
+431
+432
+433
+434
+435
+436
+437
+438
+439
+440
+441
+442
+443
+444
+445
+446
+447
+448
+449
+450
+451
+452
+453
+454
+455
+456
+457
+458
+459
+460
+461
+462
+463
+464
+465
+466
+467
+468
+469
+470
+471
+472
+473
+474
+475
+476
+477
+478
+479
+480
+481
+482
+483
+484
+485
+486
+487
+488
+489
+490
+491
+492
+493
+494
+495
+496
+497
+498
+499
+500
+501
+502
+503
+504
+505
+506
+507
+508
+509
+510
+511
+512
+513
+514
+515
+516
+517
+518
+519
+520
+521
+522
+523
+524
+525
+526
+527
+528
+529
+530
+531
+532
+533
+534
+535
+536
+537
+538
+539
+540
+541
+542
+543
+544
+545
+546
+547
+548
+549
+550
+551
+552
+553
+554
+555
+556
+557
+558
+559
+560
+561
+562
+563
+564
+565
+566
+567
+568
+569
+570
+571
+572
+573
+574
+575
+576
+577
+578
+579
+580
+581
+582
+583
+584
+585
+586
+587
+588
+589
+590
+591
+592
+593
+594
+595
+596
+597
+598
+599
+600
+601
+602
+603
+604
+605
+606
+607
+608
+609
+610
+611
+612
+613
+614
+615
+616
+617
+618
+619
+620
+621
+622
+623
+624
+625
+626
+627
+628
+629
+630
+631
+632
+633
+634
+635
+636
+637
+638
+639
+640
+641
+642
+643
+644
+645
+646
+647
+648
+649
+650
+651
+652
+653
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
+
+/*
+ *  Copyright (C) 2004 Red Hat, Inc.
+ * Copyright (C) 2012-2021 MATE Developers
+ *
+ *  Caja is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU General Public License as
+ *  published by the Free Software Foundation; either version 2 of the
+ *  License, or (at your option) any later version.
+ *
+ *  Caja is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  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
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ *  Authors: Alexander Larsson <alexl@redhat.com>
+ *
+ */
+
+#include "config.h"
+
+#include <string.h>
+#include <stdio.h>
+
+#include <gtk/gtk.h>
+#include <glib/gi18n.h>
+#include <gio/gio.h>
+
+#include "user_share-private.h"
+
+#define REALM "Please log in as the user guest"
+#define USER "guest"
+#define GSETTINGS_SCHEMA "org.mate.FileSharing"
+#define GSETTINGS_KEY_FILE_SHARING_ENABLED "enabled"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_ENABLED "bluetooth-enabled"
+#define GSETTINGS_KEY_FILE_SHARING_REQUIRE_PASSWORD "require-password"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_ALLOW_WRITE "bluetooth-allow-write"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_REQUIRE_PAIRING "bluetooth-require-pairing"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED "bluetooth-obexpush-enabled"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_ACCEPT_FILES "bluetooth-accept-files"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_NOTIFY "bluetooth-notify"
+
+static GtkBuilder* builder;
+static GSettings* settings;
+
+
+static void
+write_out_password (const char *password)
+{
+    char *to_hash;
+    char *ascii_digest;
+    char *line;
+    char *filename;
+    FILE *file;
+
+    to_hash = g_strdup_printf ("%s:%s:%s", USER, REALM, password);
+    ascii_digest = g_compute_checksum_for_string (G_CHECKSUM_MD5, to_hash, strlen (to_hash));
+    g_free (to_hash);
+    line = g_strdup_printf ("%s:%s:%s\n", USER, REALM, ascii_digest);
+    g_free (ascii_digest);
+
+    filename = g_build_filename (g_get_user_config_dir (), "user-share", "passwd", NULL);
+
+    file = fopen (filename, "w");
+    if (file != NULL) {
+	fwrite (line, strlen (line), 1, file);
+	fclose (file);
+    }
+
+    g_free (filename);
+    g_free (line);
+}
+
+static void
+flush_password (void)
+{
+    GtkWidget *password_entry;
+    const char *password;
+
+    password_entry = GTK_WIDGET (gtk_builder_get_object (builder, "password_entry"));
+
+    if (g_object_get_data (G_OBJECT( password_entry), "user_edited")) {
+	password = gtk_entry_get_text (GTK_ENTRY (password_entry));
+	if (password != NULL && password[0] != 0)
+	    write_out_password (password);
+    }
+}
+
+
+static void
+update_ui (void)
+{
+    GSettings *settings;
+    gboolean enabled;
+#ifdef HAVE_BLUETOOTH
+    gboolean bluetooth_enabled, bluetooth_write_enabled, require_pairing_enabled;
+    gboolean bluetooth_obexpush_enabled, bluetooth_obexpush_notify;
+#endif /* HAVE_BLUETOOTH */
+    char *str;
+    PasswordSetting password_setting;
+    AcceptSetting accept_setting;<--- Unused variable: accept_setting
+    GtkWidget *check;
+    GtkWidget *password_combo;
+    GtkWidget *password_entry;
+#ifdef HAVE_BLUETOOTH
+    GtkWidget *vbox_share_bluetooth;
+    GtkWidget *vbox_receive_bluetooth;
+    GtkWidget *bluetooth_check;
+    GtkWidget *allow_write_bluetooth_check;
+    GtkWidget *require_pairing_check;
+    GtkWidget *enable_obexpush_check;
+    GtkWidget *accept_obexpush_combo;
+    GtkWidget *notify_received_obexpush_check;
+#endif /* HAVE_BLUETOOTH */
+
+    settings = g_settings_new (GSETTINGS_SCHEMA);
+
+    enabled = g_settings_get_boolean (settings,
+				     FILE_SHARING_ENABLED);
+
+    str = g_settings_get_string (settings, FILE_SHARING_REQUIRE_PASSWORD);
+    password_setting = password_setting_from_string (str);
+    g_free (str);
+
+#ifdef HAVE_BLUETOOTH
+    bluetooth_enabled = g_settings_get_boolean (settings,
+    					       FILE_SHARING_BLUETOOTH_ENABLED);
+    bluetooth_write_enabled = g_settings_get_boolean (settings,
+						     FILE_SHARING_BLUETOOTH_ALLOW_WRITE);
+    require_pairing_enabled = g_settings_get_boolean (settings,
+    						     FILE_SHARING_BLUETOOTH_REQUIRE_PAIRING);
+    bluetooth_obexpush_enabled = g_settings_get_boolean (settings,
+    							FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED);
+    bluetooth_obexpush_notify = g_settings_get_boolean (settings,
+    						       FILE_SHARING_BLUETOOTH_OBEXPUSH_NOTIFY);
+
+    str = g_settings_get_string (settings, FILE_SHARING_BLUETOOTH_OBEXPUSH_ACCEPT_FILES);
+    accept_setting = accept_setting_from_string (str);
+    g_free (str);
+#endif /* HAVE_BLUETOOTH */
+
+    check = GTK_WIDGET (gtk_builder_get_object (builder, "enable_check"));
+    password_combo = GTK_WIDGET (gtk_builder_get_object (builder, "password_combo"));
+    password_entry = GTK_WIDGET (gtk_builder_get_object (builder, "password_entry"));
+#ifdef HAVE_BLUETOOTH
+    vbox_share_bluetooth = GTK_WIDGET (gtk_builder_get_object (builder, "vbox_share_bluetooth"));
+    vbox_receive_bluetooth = GTK_WIDGET (gtk_builder_get_object (builder, "vbox_receive_bluetooth"));
+    bluetooth_check = GTK_WIDGET (gtk_builder_get_object (builder, "enable_bluetooth_check"));
+    allow_write_bluetooth_check = GTK_WIDGET (gtk_builder_get_object (builder, "allow_write_bluetooth_check"));
+    require_pairing_check = GTK_WIDGET (gtk_builder_get_object (builder, "require_pairing_check"));
+    enable_obexpush_check = GTK_WIDGET (gtk_builder_get_object (builder, "enable_obexpush_check"));
+    accept_obexpush_combo = GTK_WIDGET (gtk_builder_get_object (builder, "accept_obexpush_combo"));
+    notify_received_obexpush_check = GTK_WIDGET (gtk_builder_get_object (builder, "notify_received_obexpush_check"));
+#endif /* HAVE_BLUETOOTH */
+
+    /* Network */
+    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (check), enabled);
+    gtk_widget_set_sensitive (password_combo, enabled);
+    gtk_widget_set_sensitive (password_entry, enabled && password_setting != PASSWORD_NEVER);
+
+    gtk_combo_box_set_active (GTK_COMBO_BOX (password_combo),
+			      password_setting);
+
+#ifdef HAVE_BLUETOOTH
+    /* Bluetooth ObexFTP */
+    gtk_widget_set_visible (vbox_share_bluetooth, TRUE);
+    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (bluetooth_check), bluetooth_enabled);
+    gtk_widget_set_sensitive (allow_write_bluetooth_check, bluetooth_enabled);
+    gtk_widget_set_sensitive (require_pairing_check, bluetooth_enabled);
+
+    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (allow_write_bluetooth_check),
+    				  bluetooth_write_enabled);
+    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (require_pairing_check),
+    				  require_pairing_enabled);
+
+    /* Bluetooth ObexPush */
+    gtk_widget_set_visible (vbox_receive_bluetooth, TRUE);
+    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (enable_obexpush_check), bluetooth_obexpush_enabled);
+    gtk_widget_set_sensitive (accept_obexpush_combo, bluetooth_obexpush_enabled);
+    gtk_widget_set_sensitive (notify_received_obexpush_check, bluetooth_obexpush_enabled);
+
+    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (notify_received_obexpush_check),
+    				  bluetooth_obexpush_notify);
+
+    gtk_combo_box_set_active (GTK_COMBO_BOX (accept_obexpush_combo),
+    			      accept_setting);
+#endif /* HAVE_BLUETOOTH */
+
+    g_object_unref (settings);
+}
+
+static void
+file_sharing_enabled_changed (GSettings *settings, gchar *key, gpointer data)
+{
+    update_ui ();
+}
+
+static void
+password_required_changed (GSettings *settings, gchar *key, gpointer data)
+{
+    update_ui ();
+}
+
+#ifdef HAVE_BLUETOOTH
+static void
+file_sharing_bluetooth_enabled_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	update_ui ();
+}
+
+static void
+file_sharing_bluetooth_allow_write_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	update_ui ();
+}
+
+static void
+file_sharing_bluetooth_require_pairing_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	update_ui ();
+}
+
+static void
+file_sharing_bluetooth_obexpush_enabled_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	update_ui ();
+}
+
+static void
+file_sharing_bluetooth_obexpush_accept_files_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	update_ui ();
+}
+
+static void
+file_sharing_bluetooth_obexpush_notify_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	update_ui ();
+}
+#endif /* HAVE_BLUETOOTH */
+
+static void
+password_combo_changed (GtkComboBox *combo_box)
+{
+    GSettings *settings;
+    guint setting;
+
+    setting = gtk_combo_box_get_active (combo_box);
+
+    settings = g_settings_new (GSETTINGS_SCHEMA) ;
+
+    g_settings_set_string (settings,
+			     FILE_SHARING_REQUIRE_PASSWORD,
+			     password_string_from_setting (setting));
+    g_object_unref (settings);
+}
+
+static void
+launch_share (void)
+{
+	if (!g_spawn_command_line_async (USER_SHARE_PROGRAM, NULL))
+		g_warning ("Unable to start mate-user-share program");
+}
+
+#ifdef HAVE_BLUETOOTH
+static void
+enable_bluetooth_check_toggled (GtkWidget *check)
+{
+	GSettings *settings;
+	gboolean enabled;
+
+	enabled = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check));
+
+	settings = g_settings_new (GSETTINGS_SCHEMA) ;
+
+	g_settings_set_boolean (settings,
+			       FILE_SHARING_BLUETOOTH_ENABLED,
+			       enabled);
+
+	g_object_unref (settings);
+
+	if (enabled != FALSE)
+		launch_share ();
+}
+#endif /* HAVE_BLUETOOTH */
+
+static void
+enable_check_toggled (GtkWidget *check)
+{
+	GSettings *settings;
+	gboolean enabled;
+
+	enabled = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check));
+
+	settings = g_settings_new (GSETTINGS_SCHEMA);
+
+	g_settings_set_boolean (settings,
+			       FILE_SHARING_ENABLED,
+			       enabled);
+
+	g_object_unref (settings);
+
+	if (enabled != FALSE)
+		launch_share ();
+}
+
+static void
+password_entry_changed (GtkEditable *editable)
+{
+	g_object_set_data (G_OBJECT (editable),
+			   "user_edited", GINT_TO_POINTER (1));
+	flush_password ();
+}
+
+#ifdef HAVE_BLUETOOTH
+static void
+bluetooth_allow_write_check_toggled (GtkWidget *check)
+{
+	GSettings *settings;
+	gboolean enabled;
+
+	enabled = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check));
+
+	settings = g_settings_new (GSETTINGS_SCHEMA) ;
+
+	g_settings_set_boolean (settings,
+			       FILE_SHARING_BLUETOOTH_ALLOW_WRITE,
+			       enabled);
+
+	g_object_unref (settings);
+}
+
+static void
+bluetooth_require_pairing_check_toggled (GtkWidget *check)
+{
+	GSettings *settings;
+	gboolean enabled;
+
+	enabled = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check));
+
+	settings = g_settings_new (GSETTINGS_SCHEMA) ;
+
+	g_settings_set_boolean (settings,
+			       FILE_SHARING_BLUETOOTH_REQUIRE_PAIRING,
+			       enabled);
+
+	g_object_unref (settings);
+}
+
+static void
+enable_obexpush_check_toggled (GtkWidget *check)
+{
+	GSettings *settings;
+	gboolean enabled;
+
+	enabled = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check));
+
+	settings = g_settings_new (GSETTINGS_SCHEMA) ;
+
+	g_settings_set_boolean (settings,
+			       FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED,
+			       enabled);
+
+	g_object_unref (settings);
+
+	if (enabled != FALSE)
+		launch_share ();
+}
+
+static void
+accept_obexpush_combo_changed (GtkComboBox *combo_box)
+{
+    GSettings *settings;
+    guint setting;
+
+    setting = gtk_combo_box_get_active (combo_box);
+
+    settings = g_settings_new (GSETTINGS_SCHEMA) ;
+
+    g_settings_set_string (settings,
+			     FILE_SHARING_BLUETOOTH_OBEXPUSH_ACCEPT_FILES,
+			     accept_string_from_setting (setting));
+    g_object_unref (settings);
+}
+
+static void
+notify_received_obexpush_check_toggled (GtkWidget *check)
+{
+	GSettings *settings;
+	gboolean enabled;
+
+	enabled = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check));
+
+	settings = g_settings_new (GSETTINGS_SCHEMA) ;
+
+	g_settings_set_boolean (settings,
+			       FILE_SHARING_BLUETOOTH_OBEXPUSH_NOTIFY,
+			       enabled);
+
+	g_object_unref (settings);
+}
+#endif /* HAVE_BLUETOOTH */
+
+static GtkWidget *
+error_dialog (const char *title,
+	      const char *reason,
+	      GtkWindow *parent)
+{
+	GtkWidget *error_dialog;
+
+	if (reason == NULL)
+		reason = _("No reason");
+
+	error_dialog =
+		gtk_message_dialog_new (parent,
+					GTK_DIALOG_MODAL,
+					GTK_MESSAGE_ERROR,
+					GTK_BUTTONS_OK,
+					"%s", title);
+	gtk_message_dialog_format_secondary_text
+		(GTK_MESSAGE_DIALOG (error_dialog), "%s", reason);
+
+	gtk_window_set_title (GTK_WINDOW (error_dialog), ""); /* as per HIG */
+	gtk_container_set_border_width (GTK_CONTAINER (error_dialog), 5);
+	gtk_dialog_set_default_response (GTK_DIALOG (error_dialog),
+					 GTK_RESPONSE_OK);
+	gtk_window_set_modal (GTK_WINDOW (error_dialog), TRUE);
+
+	return error_dialog;
+}
+
+static void
+help_button_clicked (GtkButton *button, GtkWidget *window)
+{
+	GError *error = NULL;
+
+	if (gtk_show_uri_on_window (GTK_WINDOW (window), "help:mate-user-share", gtk_get_current_event_time (), &error) == FALSE) {
+		GtkWidget *dialog;
+
+		dialog = error_dialog (_("Could not display the help contents."), error->message, GTK_WINDOW (window));
+		g_signal_connect (G_OBJECT (dialog), "response", G_CALLBACK
+				  (gtk_widget_destroy), error_dialog);
+		gtk_window_present (GTK_WINDOW (dialog));
+
+		g_error_free (error);
+	}
+}
+
+static GtkWidget *
+create_window (void)
+{
+    GError *error = NULL;
+    GSettings *settings;
+    GtkWidget *check;
+    GtkWidget *password_combo;
+    GtkWidget *password_entry;
+#ifdef HAVE_BLUETOOTH
+    GtkWidget *bluetooth_check;
+    GtkWidget *bluetooth_allow_write_check;
+    GtkWidget *require_pairing_check;
+    GtkWidget *enable_obexpush_check;
+    GtkWidget *accept_obexpush_combo;
+    GtkWidget *notify_received_obexpush_check;
+#endif /* HAVE_BLUETOOTH */
+    GtkWidget *window;
+    GtkListStore *store;
+    GtkCellRenderer *cell;
+    GtkTreeIter iter;
+
+    builder = gtk_builder_new ();
+    gtk_builder_add_from_file (builder, DATADIR"file-share-properties.ui", &error);
+
+    if (error) {
+      GtkWidget *dialog;
+
+      dialog = error_dialog (_("Could not build interface."), error->message, NULL);
+      gtk_dialog_run (GTK_DIALOG (dialog));
+      gtk_widget_destroy (dialog);
+
+      g_error_free (error);
+      return NULL;
+    }
+
+    window = GTK_WIDGET (gtk_builder_get_object (builder, "user_share_dialog"));
+
+    settings = g_settings_new (GSETTINGS_SCHEMA);
+
+    check = GTK_WIDGET (gtk_builder_get_object (builder, "enable_check"));
+    password_combo = GTK_WIDGET (gtk_builder_get_object (builder, "password_combo"));
+    password_entry = GTK_WIDGET (gtk_builder_get_object (builder, "password_entry"));
+#ifdef HAVE_BLUETOOTH
+    bluetooth_check = GTK_WIDGET (gtk_builder_get_object (builder, "enable_bluetooth_check"));
+    bluetooth_allow_write_check = GTK_WIDGET (gtk_builder_get_object (builder, "allow_write_bluetooth_check"));
+    require_pairing_check = GTK_WIDGET (gtk_builder_get_object (builder, "require_pairing_check"));
+    enable_obexpush_check = GTK_WIDGET (gtk_builder_get_object (builder, "enable_obexpush_check"));
+    accept_obexpush_combo = GTK_WIDGET (gtk_builder_get_object (builder, "accept_obexpush_combo"));
+    notify_received_obexpush_check = GTK_WIDGET (gtk_builder_get_object (builder, "notify_received_obexpush_check"));
+#endif /* HAVE_BLUETOOTH */
+
+    store = gtk_list_store_new (1, G_TYPE_STRING);
+    gtk_combo_box_set_model (GTK_COMBO_BOX (password_combo),
+			     GTK_TREE_MODEL (store));
+    cell = gtk_cell_renderer_text_new ();
+    gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (password_combo), cell, TRUE);
+    gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (password_combo), cell,
+				    "text", 0,
+				    NULL);
+
+    /* Keep in same order as enum */
+    gtk_list_store_append (store, &iter);
+    gtk_list_store_set (store, &iter, 0,
+			_("Never"), -1);
+    gtk_list_store_append (store, &iter);
+    gtk_list_store_set (store, &iter, 0,
+			_("When writing files"), -1);
+    gtk_list_store_append (store, &iter);
+    gtk_list_store_set (store, &iter, 0,
+			_("Always"), -1);
+    g_object_unref (store);
+
+    /* We can't read the password from the text, just set it to something */
+    gtk_entry_set_text (GTK_ENTRY (password_entry), "none");
+    g_object_set_data (G_OBJECT (password_entry),
+		       "user_edited", GINT_TO_POINTER (0));
+    g_signal_connect (password_entry,
+		      "changed", G_CALLBACK (password_entry_changed), NULL);
+
+#ifdef HAVE_BLUETOOTH
+    /* Accept files combo */
+    store = gtk_list_store_new (1, G_TYPE_STRING);
+    gtk_combo_box_set_model (GTK_COMBO_BOX (accept_obexpush_combo),
+			     GTK_TREE_MODEL (store));
+    cell = gtk_cell_renderer_text_new ();
+    gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (accept_obexpush_combo), cell, TRUE);
+    gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (accept_obexpush_combo), cell,
+				    "text", 0,
+				    NULL);
+
+    /* Keep in same order as enum */
+    gtk_list_store_append (store, &iter);
+    gtk_list_store_set (store, &iter, 0,
+			_("Always"), -1);
+    gtk_list_store_append (store, &iter);
+    gtk_list_store_set (store, &iter, 0,
+			_("Only for set up devices"), -1);
+    //FIXME implement
+#if 0
+    gtk_list_store_append (store, &iter);
+    gtk_list_store_set (store, &iter, 0,
+    			_("Ask"), -1);
+#endif
+    g_object_unref (store);
+#endif /* HAVE_BLUETOOTH */
+
+    g_signal_connect (check,
+		      "toggled", G_CALLBACK (enable_check_toggled), NULL);
+    g_signal_connect (password_combo,
+		      "changed", G_CALLBACK (password_combo_changed), NULL);
+#ifdef HAVE_BLUETOOTH
+    g_signal_connect (bluetooth_check,
+    		      "toggled", G_CALLBACK (enable_bluetooth_check_toggled), NULL);
+    g_signal_connect (bluetooth_allow_write_check,
+    		      "toggled", G_CALLBACK (bluetooth_allow_write_check_toggled), NULL);
+    g_signal_connect (require_pairing_check,
+    		      "toggled", G_CALLBACK (bluetooth_require_pairing_check_toggled), NULL);
+    g_signal_connect (enable_obexpush_check,
+    		      "toggled", G_CALLBACK (enable_obexpush_check_toggled), NULL);
+    g_signal_connect (accept_obexpush_combo,
+    		      "changed", G_CALLBACK (accept_obexpush_combo_changed), NULL);
+    g_signal_connect (notify_received_obexpush_check,
+    		      "toggled", G_CALLBACK (notify_received_obexpush_check_toggled), NULL);
+#endif /* HAVE_BLUETOOTH */
+
+    g_signal_connect_swapped (GTK_WIDGET (gtk_builder_get_object (builder, "close_button")),
+                              "clicked", G_CALLBACK (gtk_widget_destroy), window);
+    g_signal_connect (GTK_WIDGET (gtk_builder_get_object (builder, "help_button")),
+		      "clicked", G_CALLBACK (help_button_clicked),
+		      gtk_builder_get_object (builder, "user_share_dialog"));
+
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_ENABLED,
+			     G_CALLBACK (file_sharing_enabled_changed), NULL);
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_REQUIRE_PASSWORD,
+			     G_CALLBACK (password_required_changed), NULL);
+#ifdef HAVE_BLUETOOTH
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_ENABLED,
+			     G_CALLBACK (file_sharing_bluetooth_enabled_changed), NULL);
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_ALLOW_WRITE,
+			     G_CALLBACK (file_sharing_bluetooth_allow_write_changed), NULL);
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_REQUIRE_PAIRING,
+			     G_CALLBACK (file_sharing_bluetooth_require_pairing_changed), NULL);
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED,
+			     G_CALLBACK (file_sharing_bluetooth_obexpush_enabled_changed), NULL);
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_ACCEPT_FILES,
+			     G_CALLBACK (file_sharing_bluetooth_obexpush_accept_files_changed), NULL);
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_NOTIFY,
+			     G_CALLBACK (file_sharing_bluetooth_obexpush_notify_changed), NULL);
+#endif /* HAVE_BLUETOOTH */
+
+    update_ui ();
+
+    return window;
+}
+
+static void
+activate (GtkApplication *app)
+{
+    GList *list;
+    GtkWidget *window;
+
+    list = gtk_application_get_windows (app);
+
+    if (list) {
+        gtk_window_present (GTK_WINDOW (list->data));
+    } else {
+        window = create_window ();
+        gtk_window_set_application (GTK_WINDOW (window), app);
+        gtk_widget_show (window);
+    }
+}
+
+int
+main (int argc, char *argv[])
+{
+    GtkApplication *app;
+    gint status;
+
+    bindtextdomain (GETTEXT_PACKAGE, MATELOCALEDIR);
+    bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
+    textdomain (GETTEXT_PACKAGE);
+
+    app = gtk_application_new ("org.mate.user-share.properties",
+                               G_APPLICATION_FLAGS_NONE);
+    g_signal_connect (app, "activate", G_CALLBACK (activate), NULL);
+
+    status = g_application_run (G_APPLICATION (app), argc, argv);
+
+    g_object_unref (app);
+
+    return status;
+}
+
+
+
+ +
+ + diff --git a/2022-11-11-201040-0718-cppcheck@c9d02a6bbcbb_v1.27.0/1.html b/2022-11-11-201040-0718-cppcheck@c9d02a6bbcbb_v1.27.0/1.html new file mode 100644 index 0000000..6ca74fd --- /dev/null +++ b/2022-11-11-201040-0718-cppcheck@c9d02a6bbcbb_v1.27.0/1.html @@ -0,0 +1,1123 @@ + + + + + + Cppcheck - HTML report - mate-user-share + + + + + +
+ + + +
+
  1
+  2
+  3
+  4
+  5
+  6
+  7
+  8
+  9
+ 10
+ 11
+ 12
+ 13
+ 14
+ 15
+ 16
+ 17
+ 18
+ 19
+ 20
+ 21
+ 22
+ 23
+ 24
+ 25
+ 26
+ 27
+ 28
+ 29
+ 30
+ 31
+ 32
+ 33
+ 34
+ 35
+ 36
+ 37
+ 38
+ 39
+ 40
+ 41
+ 42
+ 43
+ 44
+ 45
+ 46
+ 47
+ 48
+ 49
+ 50
+ 51
+ 52
+ 53
+ 54
+ 55
+ 56
+ 57
+ 58
+ 59
+ 60
+ 61
+ 62
+ 63
+ 64
+ 65
+ 66
+ 67
+ 68
+ 69
+ 70
+ 71
+ 72
+ 73
+ 74
+ 75
+ 76
+ 77
+ 78
+ 79
+ 80
+ 81
+ 82
+ 83
+ 84
+ 85
+ 86
+ 87
+ 88
+ 89
+ 90
+ 91
+ 92
+ 93
+ 94
+ 95
+ 96
+ 97
+ 98
+ 99
+100
+101
+102
+103
+104
+105
+106
+107
+108
+109
+110
+111
+112
+113
+114
+115
+116
+117
+118
+119
+120
+121
+122
+123
+124
+125
+126
+127
+128
+129
+130
+131
+132
+133
+134
+135
+136
+137
+138
+139
+140
+141
+142
+143
+144
+145
+146
+147
+148
+149
+150
+151
+152
+153
+154
+155
+156
+157
+158
+159
+160
+161
+162
+163
+164
+165
+166
+167
+168
+169
+170
+171
+172
+173
+174
+175
+176
+177
+178
+179
+180
+181
+182
+183
+184
+185
+186
+187
+188
+189
+190
+191
+192
+193
+194
+195
+196
+197
+198
+199
+200
+201
+202
+203
+204
+205
+206
+207
+208
+209
+210
+211
+212
+213
+214
+215
+216
+217
+218
+219
+220
+221
+222
+223
+224
+225
+226
+227
+228
+229
+230
+231
+232
+233
+234
+235
+236
+237
+238
+239
+240
+241
+242
+243
+244
+245
+246
+247
+248
+249
+250
+251
+252
+253
+254
+255
+256
+257
+258
+259
+260
+261
+262
+263
+264
+265
+266
+267
+268
+269
+270
+271
+272
+273
+274
+275
+276
+277
+278
+279
+280
+281
+282
+283
+284
+285
+286
+287
+288
+289
+290
+291
+292
+293
+294
+295
+296
+297
+298
+299
+300
+301
+302
+303
+304
+305
+306
+307
+308
+309
+310
+311
+312
+313
+314
+315
+316
+317
+318
+319
+320
+321
+322
+323
+324
+325
+326
+327
+328
+329
+330
+331
+332
+333
+334
+335
+336
+337
+338
+339
+340
+341
+342
+343
+344
+345
+346
+347
+348
+349
+350
+351
+352
+353
+354
+355
+356
+357
+358
+359
+360
+361
+362
+363
+364
+365
+366
+367
+368
+369
+370
+371
+372
+373
+374
+375
+376
+377
+378
+379
+380
+381
+382
+383
+384
+385
+386
+387
+388
+389
+390
+391
+392
+393
+394
+395
+396
+397
+398
+399
+400
+401
+402
+403
+404
+405
+406
+407
+408
+409
+410
+411
+412
+413
+414
+415
+416
+417
+418
+419
+420
+421
+422
+423
+424
+425
+426
+427
+428
+429
+430
+431
+432
+433
+434
+435
+436
+437
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
+
+/*
+ *  Copyright (C) 2004-2008 Red Hat, Inc.
+ * Copyright (C) 2012-2021 MATE Developers
+ *
+ *  Caja is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU General Public License as
+ *  published by the Free Software Foundation; either version 2 of the
+ *  License, or (at your option) any later version.
+ *
+ *  Caja is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  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
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ *  Authors: Alexander Larsson <alexl@redhat.com>
+ *
+ */
+
+#include "config.h"
+
+#include <glib.h>
+#include <glib/gi18n.h>
+#include <X11/Xlib.h>
+
+#include <gio/gio.h>
+
+#include <stdarg.h>
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <signal.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <sys/stat.h>
+
+#ifdef HAVE_SELINUX
+#include <selinux/selinux.h>
+#endif
+
+#include "user_share-common.h"
+#include "user_share-private.h"
+#include "http.h"
+
+/* From avahi-common/domain.h */
+#define AVAHI_LABEL_MAX 64
+
+#define GSETTINGS_SCHEMA "org.mate.FileSharing"
+
+static pid_t httpd_pid = 0;
+
+static int
+get_port (void)
+{
+	int sock;
+	struct sockaddr_in addr;
+	int reuse;
+	socklen_t len;
+
+	sock = socket (PF_INET, SOCK_STREAM, 0);
+	if (sock < 0) {
+		return -1;
+	}
+
+	memset (&addr, 0, sizeof (addr));
+	addr.sin_port = 0;
+	addr.sin_addr.s_addr = INADDR_ANY;
+	addr.sin_family = AF_INET;
+
+	reuse = 1;
+	setsockopt (sock, SOL_SOCKET, SO_REUSEADDR, &reuse, sizeof (reuse));
+	if (bind (sock, (struct sockaddr *)&addr, sizeof (addr)) == -1) {
+		close (sock);
+		return -1;
+	}
+
+	len = sizeof (addr);
+	if (getsockname (sock, (struct sockaddr *)&addr, &len) == -1) {
+		close (sock);
+		return -1;
+	}
+
+#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__APPLE__) || defined(__OpenBSD__)
+	/* XXX This exposes a potential race condition, but without this,
+	 * httpd will not start on the above listed platforms due to the fact
+	 * that SO_REUSEADDR is also needed when Apache binds to the listening
+	 * socket.  At this time, Apache does not support that socket option.
+	 */
+	close (sock);
+#endif
+	return ntohs (addr.sin_port);
+}
+
+static char *
+truncate_name (const char *name)
+{
+	const char *end;
+
+	end = g_utf8_find_prev_char (name, name + 64);
+	g_assert (end != NULL);
+	return g_strndup (name, end - name);
+}
+
+static char *
+get_share_name (void)
+{
+	static char *name = NULL;
+	const char *host_name;
+	char *str;
+
+	if (name == NULL) {
+		host_name = g_get_host_name ();
+		if (strcmp (host_name, "localhost") == 0) {
+			/* Translators: The %s will get filled in with the user name
+			   of the user, to form a genitive. If this is difficult to
+			   translate correctly so that it will work correctly in your
+			   language, you may use something equivalent to
+			   "Public files of %s", or leave out the %s altogether.
+			   In the latter case, please put "%.0s" somewhere in the string,
+			   which will match the user name string passed by the C code,
+			   but not put the user name in the final string. This is to
+			   avoid the warning that msgfmt might otherwise generate. */
+			name = g_strdup_printf (_("%s's public files"), g_get_user_name ());
+		} else {
+			/* Translators: This is similar to the string before, only it
+			   has the hostname in it too. */
+			name = g_strdup_printf (_("%s's public files on %s"),
+						g_get_user_name (),
+						host_name);
+		}
+
+	}
+	/* And truncate */
+	if (strlen (name) < AVAHI_LABEL_MAX)
+		return name;
+
+	str = truncate_name (name);
+	g_free (name);
+	name = str;
+
+	return name;
+}
+
+static void
+ensure_conf_dir (void)
+{
+	char *dirname;
+
+	dirname = g_build_filename (g_get_user_config_dir (), "user-share", NULL);
+	g_mkdir_with_parents (dirname, 0755);
+	g_free (dirname);
+}
+
+static void
+httpd_child_setup (gpointer user_data)
+{
+#ifdef HAVE_SELINUX
+	char *mycon;
+	/* If selinux is enabled, avoid transitioning to the httpd_t context,
+	   as this normally means you can't read the users homedir. */
+	if (is_selinux_enabled()) {
+		if (getcon (&mycon) < 0) {
+			abort ();
+		}
+		if (setexeccon (mycon) < 0)
+			abort ();
+		freecon (mycon);
+	}
+#endif
+}
+
+static const char *known_httpd_locations [] = {
+	HTTPD_PROGRAM,
+	"/usr/sbin/httpd",
+	"/usr/sbin/httpd2",
+	"/usr/sbin/apache2",
+	NULL
+};
+
+static char*
+get_httpd_program (void)
+{
+	int i;
+
+	for (i = 0; known_httpd_locations[i]; i++) {
+		if (known_httpd_locations[i][0] == '\0') {
+			/* empty string as first element, happens when
+			 * configured --with-httpd=auto */
+			continue;
+		}
+		if (g_file_test (known_httpd_locations[i], G_FILE_TEST_IS_EXECUTABLE)
+				&& ! g_file_test (known_httpd_locations[i], G_FILE_TEST_IS_DIR)) {
+			return g_strdup (known_httpd_locations[i]);
+		}
+	}
+	return NULL;
+}
+
+static const char *known_httpd_modules_locations [] = {
+	HTTPD_MODULES_PATH,
+	"/etc/httpd/modules",
+	"/usr/lib/apache2/modules",
+	NULL
+};
+
+static gchar*
+get_httpd_modules_path (void)
+{
+	int i;
+
+	for (i = 0; known_httpd_modules_locations[i]; i++) {
+		if (known_httpd_modules_locations[i][0] == '\0') {
+			/* empty string as first element, happens when
+			 * configured --with-httpd=auto */
+			continue;
+		}
+		if (g_file_test (known_httpd_modules_locations[i], G_FILE_TEST_IS_EXECUTABLE)
+				&& g_file_test (known_httpd_modules_locations[i], G_FILE_TEST_IS_DIR)) {
+			return g_strdup (known_httpd_modules_locations[i]);
+		}
+	}
+	return NULL;
+}
+
+static GRegex *version_regex = NULL;
+
+static char*
+get_httpd_config (const char *httpd_program)
+{
+	gchar *standard_output;
+	gchar *cmd_line;
+	GMatchInfo *match_info;
+	gchar *version_number = NULL;
+	gchar *config;
+
+	cmd_line = g_strdup_printf ("%s -v", httpd_program);
+	if (! g_spawn_command_line_sync (cmd_line, &standard_output, NULL, NULL, NULL)) {
+		g_free (cmd_line);
+		return NULL;
+	}
+	g_free (cmd_line);
+
+	if (version_regex == NULL) {
+		version_regex = g_regex_new ("\\d\\.\\d", 0, 0, NULL);
+	}
+
+	if (g_regex_match (version_regex, standard_output, 0, &match_info)) {
+		while (g_match_info_matches (match_info)) {
+			version_number = g_match_info_fetch (match_info, 0);
+			break;
+		}
+		g_match_info_free (match_info);
+		g_free (standard_output);
+	} else {
+		/* Failed to parse httpd version number */
+		g_warning ("Could not parse '%s' as a version for httpd", standard_output);
+		g_free (standard_output);
+		/* assume it is 2.2 */
+		version_number = g_strdup ("2.2");
+	}
+
+	config = g_strdup_printf (HTTPD_CONFIG_TEMPLATE, version_number);
+	g_free (version_number);
+
+	return config;
+}
+
+static gboolean
+spawn_httpd (int port, pid_t *pid_out)
+{
+	char *free1, *free2, *free3, *free4, *free5, *free6, *free7, *free8, *free9;
+	gboolean res;
+	char *argv[10];
+	char *env[10];
+	int i;
+	gint status;
+	char *pid_filename;
+	char *pidfile;
+	GError *error;
+	gboolean got_pidfile;
+	GSettings *settings;
+	char *str;
+	char *public_dir;
+
+	public_dir = lookup_public_dir ();
+	ensure_conf_dir ();
+
+	i = 0;
+	free1 = argv[i++] = get_httpd_program ();
+	if (argv[0] == NULL) {
+		fprintf (stderr, "error finding httpd server\n");
+		return FALSE;
+	}
+
+	argv[i++] = "-f";
+	free2 = argv[i++] = get_httpd_config (argv[0]);
+	argv[i++] = "-C";
+	free3 = argv[i++] = g_strdup_printf ("Listen %d", port);
+
+	settings = g_settings_new (GSETTINGS_SCHEMA);
+	str = g_settings_get_string (settings,
+				       FILE_SHARING_REQUIRE_PASSWORD);
+
+	if (str && strcmp (str, "never") == 0) {
+		/* Do nothing */
+	} else if (str && strcmp (str, "on_write") == 0){
+		argv[i++] = "-D";
+		argv[i++] = "RequirePasswordOnWrite";
+	} else {
+		/* always, or safe fallback */
+		argv[i++] = "-D";
+		argv[i++] = "RequirePasswordAlways";
+	}
+	g_free (str);
+	g_object_unref (settings);
+
+	argv[i] = NULL;
+
+	i = 0;
+	free4 = env[i++] = g_strdup_printf ("HOME=%s", g_get_home_dir());
+	free5 = env[i++] = g_strdup_printf ("XDG_PUBLICSHARE_DIR=%s", public_dir);
+	free6 = env[i++] = g_strdup_printf ("XDG_CONFIG_HOME=%s", g_get_user_config_dir ());
+	free7 = env[i++] = g_strdup_printf ("GUS_SHARE_NAME=%s", get_share_name ());
+	free8 = env[i++] = g_strdup_printf ("GUS_LOGIN_LABEL=%s", "Please log in as the user guest");
+	free9 = env[i++] = g_strdup_printf ("HTTP_MODULES_PATH=%s",get_httpd_modules_path ());
+	env[i++] = "LANG=C";
+	env[i] = NULL;
+
+	pid_filename = g_build_filename (g_get_user_config_dir (), "user-share", "pid", NULL);
+
+	/* Remove pid file before spawning to avoid races with child and old pidfile */
+	unlink (pid_filename);
+
+	error = NULL;
+	res = g_spawn_sync (g_get_home_dir(),
+			    argv, env, 0,
+			    httpd_child_setup, NULL,
+			    NULL, NULL,
+			    &status,
+			    &error);
+	g_free (free1);
+	g_free (free2);
+	g_free (free3);
+	g_free (free4);
+	g_free (free5);
+	g_free (free6);
+	g_free (free7);
+	g_free (free8);
+	g_free (free9);
+	g_free (public_dir);
+
+	if (!res) {
+		fprintf (stderr, "error spawning httpd: %s\n",
+			 error->message);
+		g_error_free (error);
+		g_free (pid_filename);
+		return FALSE;
+	}
+
+	if (status != 0) {
+		g_free (pid_filename);
+		return FALSE;
+	}
+
+	got_pidfile = FALSE;
+	error = NULL;
+	for (i = 0; i < 5; i++) {
+		if (error != NULL)
+			g_error_free (error);
+		error = NULL;
+		if (g_file_get_contents (pid_filename, &pidfile, NULL, &error)) {
+			got_pidfile = TRUE;
+			*pid_out = atoi (pidfile);
+			g_free (pidfile);
+			break;
+		}
+		sleep (1);
+	}
+
+	g_free (pid_filename);
+
+	if (!got_pidfile) {
+		fprintf (stderr, "error opening httpd pidfile: %s\n", error->message);
+		g_error_free (error);
+		return FALSE;
+	}
+	return TRUE;
+}
+
+static void
+kill_httpd (void)
+{
+	if (httpd_pid != 0) {
+		kill (httpd_pid, SIGTERM);
+
+		/* Allow child time to die, we can't waitpid, because its
+		   not a direct child */
+		sleep (1);
+	}
+	httpd_pid = 0;
+}
+
+void
+http_up (void)
+{
+	guint port;
+
+	port = get_port ();
+	if (!spawn_httpd (port, &httpd_pid)) {
+		fprintf (stderr, "spawning httpd failed\n");
+	}
+}
+
+void
+http_down (void)
+{
+	kill_httpd ();
+}
+
+gboolean
+http_init (void)
+{
+	return TRUE;
+}
+
+pid_t
+http_get_pid (void)
+{
+	return httpd_pid;
+}
+
+
+
+ +
+ + diff --git a/2022-11-11-201040-0718-cppcheck@c9d02a6bbcbb_v1.27.0/2.html b/2022-11-11-201040-0718-cppcheck@c9d02a6bbcbb_v1.27.0/2.html new file mode 100644 index 0000000..1682147 --- /dev/null +++ b/2022-11-11-201040-0718-cppcheck@c9d02a6bbcbb_v1.27.0/2.html @@ -0,0 +1,833 @@ + + + + + + Cppcheck - HTML report - mate-user-share + + + + + +
+ + + +
+
  1
+  2
+  3
+  4
+  5
+  6
+  7
+  8
+  9
+ 10
+ 11
+ 12
+ 13
+ 14
+ 15
+ 16
+ 17
+ 18
+ 19
+ 20
+ 21
+ 22
+ 23
+ 24
+ 25
+ 26
+ 27
+ 28
+ 29
+ 30
+ 31
+ 32
+ 33
+ 34
+ 35
+ 36
+ 37
+ 38
+ 39
+ 40
+ 41
+ 42
+ 43
+ 44
+ 45
+ 46
+ 47
+ 48
+ 49
+ 50
+ 51
+ 52
+ 53
+ 54
+ 55
+ 56
+ 57
+ 58
+ 59
+ 60
+ 61
+ 62
+ 63
+ 64
+ 65
+ 66
+ 67
+ 68
+ 69
+ 70
+ 71
+ 72
+ 73
+ 74
+ 75
+ 76
+ 77
+ 78
+ 79
+ 80
+ 81
+ 82
+ 83
+ 84
+ 85
+ 86
+ 87
+ 88
+ 89
+ 90
+ 91
+ 92
+ 93
+ 94
+ 95
+ 96
+ 97
+ 98
+ 99
+100
+101
+102
+103
+104
+105
+106
+107
+108
+109
+110
+111
+112
+113
+114
+115
+116
+117
+118
+119
+120
+121
+122
+123
+124
+125
+126
+127
+128
+129
+130
+131
+132
+133
+134
+135
+136
+137
+138
+139
+140
+141
+142
+143
+144
+145
+146
+147
+148
+149
+150
+151
+152
+153
+154
+155
+156
+157
+158
+159
+160
+161
+162
+163
+164
+165
+166
+167
+168
+169
+170
+171
+172
+173
+174
+175
+176
+177
+178
+179
+180
+181
+182
+183
+184
+185
+186
+187
+188
+189
+190
+191
+192
+193
+194
+195
+196
+197
+198
+199
+200
+201
+202
+203
+204
+205
+206
+207
+208
+209
+210
+211
+212
+213
+214
+215
+216
+217
+218
+219
+220
+221
+222
+223
+224
+225
+226
+227
+228
+229
+230
+231
+232
+233
+234
+235
+236
+237
+238
+239
+240
+241
+242
+243
+244
+245
+246
+247
+248
+249
+250
+251
+252
+253
+254
+255
+256
+257
+258
+259
+260
+261
+262
+263
+264
+265
+266
+267
+268
+269
+270
+271
+272
+273
+274
+275
+276
+277
+278
+279
+280
+281
+282
+283
+284
+285
+286
+287
+288
+289
+290
+291
+292
/* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 8; tab-width: 8 -*-
+ *
+ * Copyright (C) 2003 Novell, Inc.
+ * Copyright (C) 2003-2004 Red Hat, Inc.
+ * Copyright (C) 2005 William Jon McCann <mccann@jhu.edu>
+ * Copyright (C) 2012-2021 MATE Developers
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * 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 Foundation, Inc., 51 Franklin St, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ *
+ */
+
+#include "config.h"
+
+#include <stdlib.h>
+#include <string.h>
+#include <glib/gi18n-lib.h>
+#include <gtk/gtk.h>
+#include <libcaja-extension/caja-menu-provider.h>
+#include <libcaja-extension/caja-location-widget-provider.h>
+
+#ifdef HAVE_BLUETOOTH
+#include <bluetooth-client.h>
+#endif
+
+#include "caja-share-bar.h"
+#include "user_share-common.h"
+
+#define CAJA_TYPE_USER_SHARE  (caja_user_share_get_type ())
+#define CAJA_USER_SHARE(o)    (G_TYPE_CHECK_INSTANCE_CAST ((o), CAJA_TYPE_USER_SHARE, CajaUserShare))
+#define CAJA_IS_USER_SHARE(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), CAJA_TYPE_USER_SHARE))
+
+typedef struct
+{
+        GObject              parent_slot;
+} CajaUserShare;
+
+typedef struct
+{
+        GObjectClass parent_slot;
+} CajaUserShareClass;
+
+static GType caja_user_share_get_type      (void);
+static void  caja_user_share_register_type (GTypeModule *module);
+
+static void
+launch_process (char **argv, GtkWindow *parent)
+{
+        GError *error;
+        GtkWidget *dialog;
+
+        error = NULL;
+        if (!g_spawn_async (NULL,
+                            argv, NULL,
+                            0,
+                            NULL, NULL,
+                            NULL,
+                            &error)) {
+
+
+                dialog = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL, GTK_MESSAGE_WARNING,
+						 GTK_BUTTONS_OK, _("Unable to launch the Personal File Sharing preferences"));
+
+                gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog), "%s", error->message);
+
+                gtk_dialog_run (GTK_DIALOG (dialog));
+                gtk_widget_destroy (dialog);
+
+                g_error_free (error);
+        }
+}
+
+static void
+launch_prefs_on_window (GtkWindow *window)
+{
+        char *argv [2];
+
+        argv [0] = g_build_filename (BINDIR, "mate-file-share-properties", NULL);
+        argv [1] = NULL;
+
+        launch_process (argv, window);
+
+        g_free (argv [0]);
+}
+
+static void
+bar_response_cb (CajaShareBar *bar,
+                 gint response,
+                 gpointer         data)
+{
+        if (response == CAJA_SHARE_BAR_RESPONSE_PREFERENCES) {
+                launch_prefs_on_window (GTK_WINDOW (data));
+        }
+}
+
+#ifdef HAVE_BLUETOOTH
+static void
+downloads_bar_set_from_bluetooth_status (GtkWidget *bar)
+{
+	BluetoothClient *client;
+	gboolean bt_powered;
+
+	client = g_object_get_data (G_OBJECT (bar), "bluetooth-client");
+	g_object_get (G_OBJECT (client),
+		      "default-adapter-powered", &bt_powered,
+		      NULL);
+	gtk_widget_set_visible (bar, bt_powered);
+}
+
+static void
+default_adapter_powered_cb (GObject    *gobject,
+			    GParamSpec *pspec,
+			    GtkWidget  *bar)
+{
+	downloads_bar_set_from_bluetooth_status (bar);
+}
+#endif /* HAVE_BLUETOOTH */
+
+static GtkWidget *
+caja_user_share_get_location_widget (CajaLocationWidgetProvider *iface,
+                                         const char                     *uri,
+                                         GtkWidget                      *window)
+{
+	GFile             *file;
+	GtkWidget         *bar;
+	guint              i;
+	gboolean           enable = FALSE;
+	GFile             *home;
+#ifdef HAVE_BLUETOOTH
+	const GUserDirectory special_dirs[] = { G_USER_DIRECTORY_PUBLIC_SHARE, G_USER_DIRECTORY_DOWNLOAD };
+
+	gboolean is_dir[] = { FALSE, FALSE };
+#else
+	const GUserDirectory special_dirs[] = { G_USER_DIRECTORY_PUBLIC_SHARE };
+
+	gboolean is_dir[] = { FALSE };
+#endif /* HAVE_BLUETOOTH */
+	file = g_file_new_for_uri (uri);
+	home = g_file_new_for_path (g_get_home_dir ());
+
+	/* We don't show anything in $HOME */
+	if (g_file_equal (home, file)) {
+		g_object_unref (home);
+		g_object_unref (file);
+		return NULL;
+	}
+
+	g_object_unref (home);
+
+	for (i = 0; i < G_N_ELEMENTS (special_dirs); i++) {
+		GFile *dir;
+		dir = lookup_dir_with_fallback (special_dirs[i]);
+		if (g_file_equal (dir, file)) {
+			enable = TRUE;
+			is_dir[i] = TRUE;
+		}
+		g_object_unref (dir);
+	}
+
+	g_object_unref (file);
+
+	if (enable == FALSE)
+		return NULL;
+
+	if (is_dir[0] != FALSE) {
+#ifdef HAVE_BLUETOOTH
+		if (is_dir[1] != FALSE) {
+			bar = caja_share_bar_new (_("May be used to share or receive files"));
+		} else {
+			bar = caja_share_bar_new (_("May be shared over the network or Bluetooth"));
+		}
+#else
+		bar = caja_share_bar_new (_("May be shared over the network"));
+#endif /* HAVE_BLUETOOTH */
+	} else {
+#ifdef HAVE_BLUETOOTH
+		BluetoothClient *client;
+
+		bar = caja_share_bar_new (_("May be used to receive files over Bluetooth"));
+
+		gtk_widget_set_no_show_all (bar, TRUE);
+		client = bluetooth_client_new ();
+		g_object_set_data_full (G_OBJECT (bar), "bluetooth-client", client, g_object_unref);
+		g_signal_connect (G_OBJECT (client), "notify::default-adapter-powered",
+				  G_CALLBACK (default_adapter_powered_cb), bar);
+		downloads_bar_set_from_bluetooth_status (bar);
+#endif /* HAVE_BLUETOOTH */
+	}
+
+	g_signal_connect (bar, "response",
+			  G_CALLBACK (bar_response_cb),
+			  window);
+
+	gtk_widget_show_all (bar);
+
+	return bar;
+}
+
+static void
+caja_user_share_location_widget_provider_iface_init (CajaLocationWidgetProviderIface *iface)
+{
+        iface->get_widget = caja_user_share_get_location_widget;
+}
+
+static void
+caja_user_share_instance_init (CajaUserShare *share)
+{
+
+}
+
+static void
+caja_user_share_class_init (CajaUserShareClass *klass)
+{
+
+}
+
+static GType share_type = 0;
+
+static GType
+caja_user_share_get_type (void)
+{
+        return share_type;
+}
+
+static void
+caja_user_share_register_type (GTypeModule *module)
+{
+        static const GTypeInfo info = {
+                sizeof (CajaUserShareClass),
+                (GBaseInitFunc) NULL,
+                (GBaseFinalizeFunc) NULL,
+                (GClassInitFunc) caja_user_share_class_init,
+                NULL,
+                NULL,
+                sizeof (CajaUserShare),
+                0,
+                (GInstanceInitFunc) caja_user_share_instance_init,
+        };
+
+        static const GInterfaceInfo location_widget_provider_iface_info = {
+                (GInterfaceInitFunc) caja_user_share_location_widget_provider_iface_init,
+                NULL,
+                NULL
+        };
+
+        share_type = g_type_module_register_type (module,
+                                                 G_TYPE_OBJECT,
+                                                 "CajaUserShare",
+                                                 &info, 0);
+
+        g_type_module_add_interface (module,
+                                     share_type,
+                                     CAJA_TYPE_LOCATION_WIDGET_PROVIDER,
+                                     &location_widget_provider_iface_info);
+}
+
+void
+caja_module_initialize (GTypeModule *module)
+{
+        caja_user_share_register_type (module);
+        bindtextdomain (GETTEXT_PACKAGE, MATELOCALEDIR);
+        bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
+}
+
+void
+caja_module_shutdown (void)
+{
+}
+
+void
+caja_module_list_types (const GType **types,
+                            int          *num_types)
+{
+        static GType type_list [1];
+
+        type_list[0] = CAJA_TYPE_USER_SHARE;
+
+        *types = type_list;
+        *num_types = 1;
+}
+
+
+
+ +
+ + diff --git a/2022-11-11-201040-0718-cppcheck@c9d02a6bbcbb_v1.27.0/3.html b/2022-11-11-201040-0718-cppcheck@c9d02a6bbcbb_v1.27.0/3.html new file mode 100644 index 0000000..7bdfa00 --- /dev/null +++ b/2022-11-11-201040-0718-cppcheck@c9d02a6bbcbb_v1.27.0/3.html @@ -0,0 +1,1251 @@ + + + + + + Cppcheck - HTML report - mate-user-share + + + + + +
+ + + +
+
  1
+  2
+  3
+  4
+  5
+  6
+  7
+  8
+  9
+ 10
+ 11
+ 12
+ 13
+ 14
+ 15
+ 16
+ 17
+ 18
+ 19
+ 20
+ 21
+ 22
+ 23
+ 24
+ 25
+ 26
+ 27
+ 28
+ 29
+ 30
+ 31
+ 32
+ 33
+ 34
+ 35
+ 36
+ 37
+ 38
+ 39
+ 40
+ 41
+ 42
+ 43
+ 44
+ 45
+ 46
+ 47
+ 48
+ 49
+ 50
+ 51
+ 52
+ 53
+ 54
+ 55
+ 56
+ 57
+ 58
+ 59
+ 60
+ 61
+ 62
+ 63
+ 64
+ 65
+ 66
+ 67
+ 68
+ 69
+ 70
+ 71
+ 72
+ 73
+ 74
+ 75
+ 76
+ 77
+ 78
+ 79
+ 80
+ 81
+ 82
+ 83
+ 84
+ 85
+ 86
+ 87
+ 88
+ 89
+ 90
+ 91
+ 92
+ 93
+ 94
+ 95
+ 96
+ 97
+ 98
+ 99
+100
+101
+102
+103
+104
+105
+106
+107
+108
+109
+110
+111
+112
+113
+114
+115
+116
+117
+118
+119
+120
+121
+122
+123
+124
+125
+126
+127
+128
+129
+130
+131
+132
+133
+134
+135
+136
+137
+138
+139
+140
+141
+142
+143
+144
+145
+146
+147
+148
+149
+150
+151
+152
+153
+154
+155
+156
+157
+158
+159
+160
+161
+162
+163
+164
+165
+166
+167
+168
+169
+170
+171
+172
+173
+174
+175
+176
+177
+178
+179
+180
+181
+182
+183
+184
+185
+186
+187
+188
+189
+190
+191
+192
+193
+194
+195
+196
+197
+198
+199
+200
+201
+202
+203
+204
+205
+206
+207
+208
+209
+210
+211
+212
+213
+214
+215
+216
+217
+218
+219
+220
+221
+222
+223
+224
+225
+226
+227
+228
+229
+230
+231
+232
+233
+234
+235
+236
+237
+238
+239
+240
+241
+242
+243
+244
+245
+246
+247
+248
+249
+250
+251
+252
+253
+254
+255
+256
+257
+258
+259
+260
+261
+262
+263
+264
+265
+266
+267
+268
+269
+270
+271
+272
+273
+274
+275
+276
+277
+278
+279
+280
+281
+282
+283
+284
+285
+286
+287
+288
+289
+290
+291
+292
+293
+294
+295
+296
+297
+298
+299
+300
+301
+302
+303
+304
+305
+306
+307
+308
+309
+310
+311
+312
+313
+314
+315
+316
+317
+318
+319
+320
+321
+322
+323
+324
+325
+326
+327
+328
+329
+330
+331
+332
+333
+334
+335
+336
+337
+338
+339
+340
+341
+342
+343
+344
+345
+346
+347
+348
+349
+350
+351
+352
+353
+354
+355
+356
+357
+358
+359
+360
+361
+362
+363
+364
+365
+366
+367
+368
+369
+370
+371
+372
+373
+374
+375
+376
+377
+378
+379
+380
+381
+382
+383
+384
+385
+386
+387
+388
+389
+390
+391
+392
+393
+394
+395
+396
+397
+398
+399
+400
+401
+402
+403
+404
+405
+406
+407
+408
+409
+410
+411
+412
+413
+414
+415
+416
+417
+418
+419
+420
+421
+422
+423
+424
+425
+426
+427
+428
+429
+430
+431
+432
+433
+434
+435
+436
+437
+438
+439
+440
+441
+442
+443
+444
+445
+446
+447
+448
+449
+450
+451
+452
+453
+454
+455
+456
+457
+458
+459
+460
+461
+462
+463
+464
+465
+466
+467
+468
+469
+470
+471
+472
+473
+474
+475
+476
+477
+478
+479
+480
+481
+482
+483
+484
+485
+486
+487
+488
+489
+490
+491
+492
+493
+494
+495
+496
+497
+498
+499
+500
+501
+502
+503
+504
+505
+506
+507
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
+
+/*
+ *  Copyright (C) 2004-2008 Red Hat, Inc.
+ *  Copyright (C) 2012-2021 MATE Developers
+ *
+ *  Caja is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU General Public License as
+ *  published by the Free Software Foundation; either version 2 of the
+ *  License, or (at your option) any later version.
+ *
+ *  Caja is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  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
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ *  Authors: Alexander Larsson <alexl@redhat.com>
+ *
+ */
+
+#include "config.h"
+
+#include <gdk/gdkx.h>
+#include <gtk/gtk.h>
+#include <glib/gi18n.h>
+#include <glib/gstdio.h>
+#include <gio/gio.h>
+#include <X11/Xlib.h>
+
+#include "user_share-private.h"
+#include "user_share-common.h"
+#include "http.h"
+
+#ifdef HAVE_BLUETOOTH
+#include <bluetooth-client.h>
+
+#include "obexftp.h"
+#include "obexpush.h"
+
+#endif /* HAVE_BLUETOOTH */
+
+#include <gio/gio.h>
+
+#include <stdarg.h>
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <signal.h>
+#include <unistd.h>
+
+static guint disabled_timeout_tag = 0;
+static GSettings* settings;<--- Shadowed declaration
+
+#define GSETTINGS_SCHEMA "org.mate.FileSharing"
+#define GSETTINGS_KEY_FILE_SHARING_ENABLED "enabled"
+#define GSETTINGS_KEY_FILE_SHARING_REQUIRE_PASSWORD "require-password"
+
+#ifdef HAVE_BLUETOOTH
+/* MATE Session */
+#define MATE_SESSION_DBUS_NAME      "org.gnome.SessionManager"
+#define MATE_SESSION_DBUS_OBJECT    "/org/gnome/SessionManager"
+#define MATE_SESSION_DBUS_INTERFACE "org.gnome.SessionManager"
+
+static GDBusProxy *session_proxy = NULL;
+static gboolean has_console = TRUE;
+
+static BluetoothClient *client = NULL;
+static gboolean bluetoothd_enabled = FALSE;
+
+#define OBEX_ENABLED (bluetoothd_enabled && has_console)
+
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_ENABLED "bluetooth-enabled"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_ALLOW_WRITE "bluetooth-allow-write"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_REQUIRE_PAIRING "bluetooth-require-pairing"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED "bluetooth-obexpush-enabled"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_ACCEPT_FILES "bluetooth-accept-files"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_NOTIFY "bluetooth-notify"
+
+
+static void
+obex_services_start (void)
+{
+	GSettings *settings;
+
+	if (bluetoothd_enabled == FALSE ||
+	    has_console == FALSE)
+	    	return;
+
+	settings = g_settings_new(GSETTINGS_SCHEMA);
+
+	if (g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED) == TRUE) {
+	    obexpush_up ();
+	}
+	if (g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_ENABLED) == TRUE) {
+	    obexftp_up ();
+	}
+
+	g_object_unref (client);
+}
+
+static void
+obex_services_shutdown (void)
+{
+	obexpush_down ();
+	obexftp_down ();
+}
+
+static void
+session_properties_changed_cb (GDBusProxy      *session,
+			       GVariant        *changed,
+			       char           **invalidated,
+			       gpointer         user_data)
+{
+	GVariant *v;
+
+	v = g_variant_lookup_value (changed, "SessionIsActive", G_VARIANT_TYPE_BOOLEAN);
+	if (v) {
+		has_console = g_variant_get_boolean (v);
+		g_debug ("Received session is active change: now %s", has_console ? "active" : "inactive");
+
+		if (has_console)
+			obex_services_start ();
+		else
+			obex_services_shutdown ();
+
+		g_variant_unref (v);
+	}
+}
+
+static gboolean
+is_session_active (void)
+{
+	GVariant *variant;
+	gboolean is_session_active = FALSE;
+
+	variant = g_dbus_proxy_get_cached_property (session_proxy,
+						    "SessionIsActive");
+	if (variant) {
+		is_session_active = g_variant_get_boolean (variant);
+		g_variant_unref (variant);
+ 	}
+
+	return is_session_active;
+}
+
+static void
+session_init (void)
+{
+	GError *error = NULL;
+
+	session_proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION,
+						       G_DBUS_PROXY_FLAGS_NONE,
+						       NULL,
+						       MATE_SESSION_DBUS_NAME,
+						       MATE_SESSION_DBUS_OBJECT,
+						       MATE_SESSION_DBUS_INTERFACE,
+						       NULL,
+						       &error);
+	if (session_proxy == NULL) {
+		g_warning ("Failed to get session proxy: %s", error->message);
+		g_error_free (error);
+		return;
+	}
+	g_signal_connect (session_proxy, "g-properties-changed",
+			  G_CALLBACK (session_properties_changed_cb),
+			  NULL);
+	has_console = is_session_active ();
+}
+
+static void
+default_adapter_changed (GObject    *gobject,<--- Parameter 'gobject' can be declared with const
+			 GParamSpec *pspec,
+			 gpointer    user_data)
+{
+	char *adapter;
+	gboolean adapter_powered;
+
+	g_object_get (G_OBJECT (client),
+		      "default-adapter", &adapter,
+		      "default-adapter-powered", &adapter_powered,
+		      NULL);
+	if (adapter != NULL && *adapter != '\0') {
+		bluetoothd_enabled = adapter_powered;
+	} else {
+		bluetoothd_enabled = FALSE;
+	}
+
+	/* Were we called as init, or as a callback */
+	if (gobject != NULL) {
+		if (bluetoothd_enabled != FALSE)
+			obex_services_start ();
+		else
+			obex_services_shutdown ();
+	}
+}
+
+static void
+bluez_init (void)
+{
+	client = bluetooth_client_new ();
+	default_adapter_changed (NULL, NULL, NULL);
+	g_signal_connect (G_OBJECT (client), "notify::default-adapter",
+			  G_CALLBACK (default_adapter_changed), NULL);
+	g_signal_connect (G_OBJECT (client), "notify::default-adapter-powered",
+			  G_CALLBACK (default_adapter_changed), NULL);
+}
+#endif /* HAVE_BLUETOOTH */
+
+static gboolean
+file_sharing_enabled (void)
+{
+	gboolean enabled = TRUE;
+	settings = g_settings_new (GSETTINGS_SCHEMA);
+
+#ifdef HAVE_BLUETOOTH
+	if (g_settings_get_boolean (settings, FILE_SHARING_ENABLED) == FALSE &&
+	    g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_ENABLED) == FALSE &&
+	    g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED) == FALSE)
+#else /* HAVE_BLUETOOTH */
+	if (g_settings_get_boolean (settings, FILE_SHARING_ENABLED) == FALSE)
+#endif /* HAVE_BLUETOOTH */
+		enabled = FALSE;
+
+	g_object_unref (settings);
+
+	return enabled;
+}
+
+static void
+migrate_old_configuration (void)
+{
+	const char *old_config_dir;
+	const char *new_config_dir;
+
+	old_config_dir = g_build_filename (g_get_home_dir (), ".mate2", "user-share", NULL);
+	new_config_dir = g_build_filename (g_get_user_config_dir (), "user-share", NULL);
+	if (g_file_test (old_config_dir, G_FILE_TEST_IS_DIR))
+		g_rename (old_config_dir, new_config_dir);
+
+}
+
+static void
+require_password_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	/* Need to restart to get new password setting */
+	if (http_get_pid () != 0) {
+		http_down ();
+		http_up ();
+	}
+}
+
+/* File sharing was disabled for some time, exit now */
+/* If we re-enable it in the ui, this will be restarted anyway */
+static gboolean
+disabled_timeout_callback (gpointer user_data)
+{
+	GSettings *settings = (GSettings *) user_data;
+	http_down ();
+
+#ifdef HAVE_BLUETOOTH
+	if (g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_ENABLED) == FALSE &&
+	    g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED) == FALSE)
+		_exit (0);
+#else /* HAVE_BLUETOOTH */
+	if (g_settings_get_boolean (settings, FILE_SHARING_ENABLED) == FALSE)
+		_exit (0);
+#endif /* HAVE_BLUETOOTH */
+	return FALSE;
+}
+
+static void
+file_sharing_enabled_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	gboolean enabled;
+
+	if (disabled_timeout_tag != 0) {
+		g_source_remove (disabled_timeout_tag);
+		disabled_timeout_tag = 0;
+	}
+
+	enabled = g_settings_get_boolean (settings,
+					 FILE_SHARING_ENABLED);
+	if (enabled) {
+		if (http_get_pid () == 0) {
+			http_up ();
+		}
+	} else {
+		http_down ();
+		disabled_timeout_tag = g_timeout_add_seconds (3,
+							      (GSourceFunc)disabled_timeout_callback,
+							      settings);
+	}
+}
+
+#ifdef HAVE_BLUETOOTH
+static void
+file_sharing_bluetooth_allow_write_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	if (g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_ENABLED) != FALSE)
+		obexftp_restart ();
+}
+
+static void
+file_sharing_bluetooth_require_pairing_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	if (g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_ENABLED) != FALSE) {
+		/* We need to fully reset the session,
+		 * otherwise the new setting isn't taken into account */
+		obexftp_down ();
+		obexftp_up ();
+	}
+}
+
+static void
+file_sharing_bluetooth_enabled_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	if (g_settings_get_boolean (settings,
+				   FILE_SHARING_BLUETOOTH_ENABLED) == FALSE) {
+		obexftp_down ();
+		if (g_settings_get_boolean (settings, FILE_SHARING_ENABLED) == FALSE &&
+		    g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED) == FALSE) {
+			_exit (0);
+		}
+	} else if (OBEX_ENABLED) {
+		obexftp_up ();
+	}
+}
+
+static void
+file_sharing_bluetooth_obexpush_enabled_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	if (g_settings_get_boolean (settings,
+				   FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED) == FALSE) {
+		obexpush_down ();
+		if (g_settings_get_boolean (settings, FILE_SHARING_ENABLED) == FALSE &&
+		    g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_ENABLED) == FALSE) {
+			_exit (0);
+		}
+	} else if (OBEX_ENABLED) {
+		obexpush_up ();
+	}
+}
+
+static void
+file_sharing_bluetooth_obexpush_accept_files_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	AcceptSetting setting;
+	char *str;
+
+	str = g_settings_get_string (settings, FILE_SHARING_BLUETOOTH_OBEXPUSH_ACCEPT_FILES);
+	setting = accept_setting_from_string (str);
+	g_free (str);
+
+	obexpush_set_accept_files_policy (setting);
+}
+
+static void
+file_sharing_bluetooth_obexpush_notify_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	obexpush_set_notify (g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_OBEXPUSH_NOTIFY));
+}
+#endif /* HAVE_BLUETOOTH */
+
+static RETSIGTYPE
+cleanup_handler (int sig)
+{
+	http_down ();
+#ifdef HAVE_BLUETOOTH
+	obexftp_down ();
+	obexpush_down ();
+#endif /* HAVE_BLUETOOTH */
+	_exit (2);
+}
+
+static int
+x_io_error_handler (Display *xdisplay)
+{
+	http_down ();
+#ifdef HAVE_BLUETOOTH
+	obexftp_down ();
+#endif /* HAVE_BLUETOOTH */
+	_exit (2);
+}
+
+int
+main (int argc, char **argv)
+{
+	GSettings *settings;<--- Shadow variable
+	Display *xdisplay;
+	G_GNUC_UNUSED int x_fd;
+	Window selection_owner;
+	Atom xatom;
+
+	bindtextdomain (GETTEXT_PACKAGE, MATELOCALEDIR);
+	bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
+	textdomain (GETTEXT_PACKAGE);
+
+	gtk_init (&argc, &argv);
+
+	if (g_strcmp0 (g_get_real_name (), "root") == 0) {
+		g_warning ("mate-user-share cannot be started as root for security reasons.");
+		return 1;
+	}
+
+	signal (SIGPIPE, SIG_IGN);
+	signal (SIGINT, cleanup_handler);
+	signal (SIGHUP, cleanup_handler);
+	signal (SIGTERM, cleanup_handler);
+
+	xdisplay = GDK_DISPLAY_XDISPLAY (gdk_display_get_default ());
+	if (xdisplay == NULL) {
+		g_warning ("Can't open display");
+		return 1;
+	}
+
+	xatom = XInternAtom (xdisplay, "_MATE_USER_SHARE", FALSE);
+	selection_owner = XGetSelectionOwner (xdisplay, xatom);
+
+	if (selection_owner != None) {
+		/* There is an owner already, quit */
+		return 1;
+	}
+
+	selection_owner = XCreateSimpleWindow (xdisplay,
+					       RootWindow (xdisplay, 0),
+					       0, 0, 1, 1,
+					       0, 0, 0);
+	XSetSelectionOwner (xdisplay, xatom, selection_owner, CurrentTime);
+
+	if (XGetSelectionOwner (xdisplay, xatom) != selection_owner) {
+		/* Didn't get the selection */
+		return 1;
+	}
+
+	migrate_old_configuration ();
+
+	if (!file_sharing_enabled ())
+		return 1;
+
+	settings = g_settings_new (GSETTINGS_SCHEMA);
+
+	x_fd = ConnectionNumber (xdisplay);
+	XSetIOErrorHandler (x_io_error_handler);
+
+	if (http_init () == FALSE)
+		return 1;
+#ifdef HAVE_BLUETOOTH
+	if (obexftp_init () == FALSE)
+		return 1;
+	if (obexpush_init () == FALSE)
+		return 1;
+#endif /* HAVE_BLUETOOTH */
+
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_ENABLED,
+			     G_CALLBACK (file_sharing_enabled_changed), NULL);
+
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_REQUIRE_PASSWORD,
+			     G_CALLBACK (require_password_changed), NULL);
+
+#ifdef HAVE_BLUETOOTH
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_ENABLED,
+			     G_CALLBACK (file_sharing_bluetooth_enabled_changed), NULL);
+
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_ALLOW_WRITE,
+			     G_CALLBACK (file_sharing_bluetooth_allow_write_changed), NULL);
+
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_REQUIRE_PAIRING,
+			     G_CALLBACK (file_sharing_bluetooth_require_pairing_changed), NULL);
+
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED,
+			     G_CALLBACK (file_sharing_bluetooth_obexpush_enabled_changed), NULL);
+
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_ACCEPT_FILES,
+			     G_CALLBACK (file_sharing_bluetooth_obexpush_accept_files_changed), NULL);
+
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_NOTIFY,
+			     G_CALLBACK (file_sharing_bluetooth_obexpush_notify_changed), NULL);
+
+	bluez_init ();
+	session_init ();
+#endif /* HAVE_BLUETOOTH */
+
+	/* Initial setting */
+	file_sharing_enabled_changed (settings, NULL, NULL);
+#ifdef HAVE_BLUETOOTH
+	file_sharing_bluetooth_enabled_changed (settings, NULL, NULL);
+	file_sharing_bluetooth_obexpush_accept_files_changed (settings, NULL, NULL);
+	file_sharing_bluetooth_obexpush_notify_changed (settings, NULL, NULL);
+	file_sharing_bluetooth_obexpush_enabled_changed (settings, NULL, NULL);
+#endif /* HAVE_BLUETOOTH */
+
+	gtk_main ();
+
+	return 0;
+}
+
+
+
+ +
+ + diff --git a/2022-11-11-201040-0718-cppcheck@c9d02a6bbcbb_v1.27.0/index.html b/2022-11-11-201040-0718-cppcheck@c9d02a6bbcbb_v1.27.0/index.html new file mode 100644 index 0000000..b780b4e --- /dev/null +++ b/2022-11-11-201040-0718-cppcheck@c9d02a6bbcbb_v1.27.0/index.html @@ -0,0 +1,212 @@ + + + + + + Cppcheck - HTML report - mate-user-share + + + + + +
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + +
LineIdCWESeverityMessage
missingIncludeinformationCppcheck cannot find all the include files (use --check-config for details)
src/file-share-properties.c
83variableScope398styleThe scope of the variable 'password' can be reduced.
106unusedVariable563styleUnused variable: accept_setting
621variableScope398styleThe scope of the variable 'window' can be reduced.
src/http.c
115variableScope398styleThe scope of the variable 'host_name' can be reduced.
src/share-extension.c
62variableScope398styleThe scope of the variable 'dialog' can be reduced.
src/user_share.c
175constParameter398styleParameter 'gobject' can be declared with const
392shadowVariable398styleLocal variable 'settings' shadows outer variable
+
+ +
+ + diff --git a/2022-11-11-201040-0718-cppcheck@c9d02a6bbcbb_v1.27.0/stats.html b/2022-11-11-201040-0718-cppcheck@c9d02a6bbcbb_v1.27.0/stats.html new file mode 100644 index 0000000..93d49a4 --- /dev/null +++ b/2022-11-11-201040-0718-cppcheck@c9d02a6bbcbb_v1.27.0/stats.html @@ -0,0 +1,170 @@ + + + + + + Cppcheck - HTML report - mate-user-share + + + + + +
+ + + +
+

Top 10 files for style severity, total findings: 7
+   3  src/file-share-properties.c
+   2  src/user_share.c
+   1  src/share-extension.c
+   1  src/http.c
+

+ +
+ +
+ + diff --git a/2022-11-11-201040-0718-cppcheck@c9d02a6bbcbb_v1.27.0/style.css b/2022-11-11-201040-0718-cppcheck@c9d02a6bbcbb_v1.27.0/style.css new file mode 100644 index 0000000..3897bfa --- /dev/null +++ b/2022-11-11-201040-0718-cppcheck@c9d02a6bbcbb_v1.27.0/style.css @@ -0,0 +1,177 @@ + +body { + font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif; + font-size: 13px; + line-height: 1.5; + height: 100%; + margin: 0; +} + +#wrapper { + position: fixed; + height: 100vh; + width: 100vw; + display: grid; + grid-template-rows: fit-content(8rem) auto fit-content(8rem); + grid-template-columns: fit-content(25%) 1fr; + grid-template-areas: + "header header" + "menu content" + "footer footer"; +} + +h1 { + margin: 0 0 8px -2px; + font-size: 175%; +} + +.header { + padding: 0 0 5px 15px; + grid-area: header; + border-bottom: thin solid #aaa; +} + +.footer { + grid-area: footer; + border-top: thin solid #aaa; + font-size: 85%; + +} + +.footer > p { + margin: 4px; +} + +#menu, +#menu_index { + grid-area: menu; + text-align: left; + overflow: auto; + padding: 0 23px 15px 15px; + border-right: thin solid #aaa; + min-width: 200px; +} + +#menu > a { + display: block; + margin-left: 10px; + font-size: 12px; +} + +#content, +#content_index { + grid-area: content; + padding: 0px 5px 15px 15px; + overflow: auto; +} + +label { + white-space: nowrap; +} + +label.checkBtn.disabled { + color: #606060; + background: #e0e0e0; + font-style: italic; +} + +label.checkBtn, input[type="text"] { + border: 1px solid grey; + border-radius: 4px; + box-shadow: 1px 1px inset; + padding: 1px 5px; +} + +label.checkBtn { + white-space: nowrap; + background: #ccddff; +} + +label.unchecked { + background: #eff8ff; + box-shadow: 1px 1px 1px; +} + +label.checkBtn:hover, label.unchecked:hover{ + box-shadow: 0 0 2px; +} + +label.disabled:hover { + box-shadow: 1px 1px inset; +} + +label.checkBtn > input { + display:none; +} + +.summaryTable { + width: 100%; +} + +table.summaryTable td { padding: 0 5px 0 5px; } + +.statHeader, .severityHeader { + font-weight: bold; +} + +.warning { + background-color: #ffffa7; +} + +.error { + background-color: #ffb7b7; +} + +.error2 { + background-color: #faa; + display: inline-block; + margin-left: 4px; +} + +.inconclusive { + background-color: #b6b6b4; +} + +.inconclusive2 { + background-color: #b6b6b4; + display: inline-block; + margin-left: 4px; +} + +.verbose { + display: inline-block; + vertical-align: top; + cursor: help; +} + +.verbose .content { + display: none; + position: absolute; + padding: 10px; + margin: 4px; + max-width: 40%; + white-space: pre-wrap; + border: 1px solid #000; + background-color: #ffffcc; + cursor: auto; +} + +.highlight .hll { + padding: 1px; +} + +.highlighttable { + background-color: #fff; + position: relative; + margin: -10px; +} + +.linenos { + border-right: thin solid #aaa; + color: #d3d3d3; + padding-right: 6px; +} + +.id-filtered, .severity-filtered, .file-filtered, .tool-filtered, .text-filtered { + visibility: collapse; +} diff --git a/2023-09-10-082921-9712-cppcheck@2d4aba56e7bf_master/0.html b/2023-09-10-082921-9712-cppcheck@2d4aba56e7bf_master/0.html new file mode 100644 index 0000000..5d72935 --- /dev/null +++ b/2023-09-10-082921-9712-cppcheck@2d4aba56e7bf_master/0.html @@ -0,0 +1,501 @@ + + + + + + Cppcheck - HTML report - mate-user-share + + + + + +
+ + + +
+
  1
+  2
+  3
+  4
+  5
+  6
+  7
+  8
+  9
+ 10
+ 11
+ 12
+ 13
+ 14
+ 15
+ 16
+ 17
+ 18
+ 19
+ 20
+ 21
+ 22
+ 23
+ 24
+ 25
+ 26
+ 27
+ 28
+ 29
+ 30
+ 31
+ 32
+ 33
+ 34
+ 35
+ 36
+ 37
+ 38
+ 39
+ 40
+ 41
+ 42
+ 43
+ 44
+ 45
+ 46
+ 47
+ 48
+ 49
+ 50
+ 51
+ 52
+ 53
+ 54
+ 55
+ 56
+ 57
+ 58
+ 59
+ 60
+ 61
+ 62
+ 63
+ 64
+ 65
+ 66
+ 67
+ 68
+ 69
+ 70
+ 71
+ 72
+ 73
+ 74
+ 75
+ 76
+ 77
+ 78
+ 79
+ 80
+ 81
+ 82
+ 83
+ 84
+ 85
+ 86
+ 87
+ 88
+ 89
+ 90
+ 91
+ 92
+ 93
+ 94
+ 95
+ 96
+ 97
+ 98
+ 99
+100
+101
+102
+103
+104
+105
+106
+107
+108
+109
+110
+111
+112
+113
+114
+115
+116
+117
+118
+119
+120
+121
+122
+123
+124
+125
+126
+127
+128
+129
+130
+131
+132
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2005 William Jon McCann <mccann@jhu.edu>
+ * Copyright (C) 2012-2021 MATE Developers
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * 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
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Authors: William Jon McCann <mccann@jhu.edu>
+ *
+ */
+
+#include "config.h"
+
+#include <glib/gi18n-lib.h>
+#include <gtk/gtk.h>
+
+#include "caja-share-bar.h"
+
+struct CajaShareBarPrivate
+{
+	GtkWidget   *label;
+};
+
+enum {
+	PROP_0,
+	PROP_LABEL
+};
+
+G_DEFINE_TYPE_WITH_PRIVATE (CajaShareBar, caja_share_bar, GTK_TYPE_INFO_BAR)<--- There is an unknown macro here somewhere. Configuration is required. If G_DEFINE_TYPE_WITH_PRIVATE is a macro then please configure it.
+
+static void
+caja_share_bar_set_property (GObject            *object,
+                                guint               prop_id,
+                                const GValue       *value,
+                                GParamSpec         *pspec)
+{
+        CajaShareBar *self;
+
+        self = CAJA_SHARE_BAR (object);
+
+        switch (prop_id) {
+	case PROP_LABEL: {
+		gtk_label_set_text (GTK_LABEL (self->priv->label),
+				    g_value_get_string (value));
+		break;
+	}
+        default:
+                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+                break;
+        }
+}
+
+static void
+caja_share_bar_class_init (CajaShareBarClass *klass)
+{
+        GObjectClass   *object_class = G_OBJECT_CLASS (klass);
+
+        object_class->set_property = caja_share_bar_set_property;
+
+        g_object_class_install_property (G_OBJECT_CLASS(klass), PROP_LABEL,
+					 g_param_spec_string ("label", "label",
+							      "The widget's main label",
+							      NULL,
+							      G_PARAM_WRITABLE));
+}
+
+static void
+caja_share_bar_init (CajaShareBar *bar)
+{
+	GtkWidget *content_area;
+	GtkWidget *action_area;
+	GtkWidget *label;
+	GtkWidget *vbox;
+	GtkWidget *button;
+	PangoAttrList *attrs;
+
+	bar->priv = caja_share_bar_get_instance_private (bar);
+
+	content_area = gtk_info_bar_get_content_area (GTK_INFO_BAR (bar));
+	action_area = gtk_info_bar_get_action_area (GTK_INFO_BAR (bar));
+	gtk_button_box_set_layout (GTK_BUTTON_BOX (action_area), GTK_BUTTONBOX_CENTER);
+
+	vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 3);
+	gtk_container_add (GTK_CONTAINER (content_area), vbox);
+
+	attrs = pango_attr_list_new ();
+	pango_attr_list_insert (attrs, pango_attr_weight_new (PANGO_WEIGHT_BOLD));
+	label = gtk_label_new (_("Personal File Sharing"));
+	gtk_label_set_attributes (GTK_LABEL (label), attrs);
+	pango_attr_list_unref (attrs);
+
+	gtk_label_set_xalign (GTK_LABEL (label), 0.0);
+	gtk_label_set_yalign (GTK_LABEL (label), 0.5);
+	gtk_widget_show (label);
+	gtk_container_add (GTK_CONTAINER (vbox), label);
+
+	bar->priv->label = gtk_label_new (NULL);
+	gtk_label_set_xalign (GTK_LABEL (bar->priv->label), 0.0);
+	gtk_label_set_yalign (GTK_LABEL (bar->priv->label), 0.5);
+	gtk_widget_show (bar->priv->label);
+	gtk_container_add (GTK_CONTAINER (vbox), bar->priv->label);
+
+	button = gtk_info_bar_add_button (GTK_INFO_BAR (bar),
+					  _("Preferences"),
+					  CAJA_SHARE_BAR_RESPONSE_PREFERENCES);
+
+	gtk_widget_set_tooltip_text (button,
+				     _("Launch Personal File Sharing Preferences"));
+
+	gtk_widget_show_all (vbox);
+}
+
+GtkWidget *
+caja_share_bar_new (const char *label)
+{
+        return g_object_new (CAJA_TYPE_SHARE_BAR,
+                             "message-type", GTK_MESSAGE_QUESTION,
+			     "label", label,
+                             NULL);
+}
+
+ +
+ +
+ + diff --git a/2023-09-10-082921-9712-cppcheck@2d4aba56e7bf_master/1.html b/2023-09-10-082921-9712-cppcheck@2d4aba56e7bf_master/1.html new file mode 100644 index 0000000..3e27e00 --- /dev/null +++ b/2023-09-10-082921-9712-cppcheck@2d4aba56e7bf_master/1.html @@ -0,0 +1,1567 @@ + + + + + + Cppcheck - HTML report - mate-user-share + + + + + +
+ + + +
+
  1
+  2
+  3
+  4
+  5
+  6
+  7
+  8
+  9
+ 10
+ 11
+ 12
+ 13
+ 14
+ 15
+ 16
+ 17
+ 18
+ 19
+ 20
+ 21
+ 22
+ 23
+ 24
+ 25
+ 26
+ 27
+ 28
+ 29
+ 30
+ 31
+ 32
+ 33
+ 34
+ 35
+ 36
+ 37
+ 38
+ 39
+ 40
+ 41
+ 42
+ 43
+ 44
+ 45
+ 46
+ 47
+ 48
+ 49
+ 50
+ 51
+ 52
+ 53
+ 54
+ 55
+ 56
+ 57
+ 58
+ 59
+ 60
+ 61
+ 62
+ 63
+ 64
+ 65
+ 66
+ 67
+ 68
+ 69
+ 70
+ 71
+ 72
+ 73
+ 74
+ 75
+ 76
+ 77
+ 78
+ 79
+ 80
+ 81
+ 82
+ 83
+ 84
+ 85
+ 86
+ 87
+ 88
+ 89
+ 90
+ 91
+ 92
+ 93
+ 94
+ 95
+ 96
+ 97
+ 98
+ 99
+100
+101
+102
+103
+104
+105
+106
+107
+108
+109
+110
+111
+112
+113
+114
+115
+116
+117
+118
+119
+120
+121
+122
+123
+124
+125
+126
+127
+128
+129
+130
+131
+132
+133
+134
+135
+136
+137
+138
+139
+140
+141
+142
+143
+144
+145
+146
+147
+148
+149
+150
+151
+152
+153
+154
+155
+156
+157
+158
+159
+160
+161
+162
+163
+164
+165
+166
+167
+168
+169
+170
+171
+172
+173
+174
+175
+176
+177
+178
+179
+180
+181
+182
+183
+184
+185
+186
+187
+188
+189
+190
+191
+192
+193
+194
+195
+196
+197
+198
+199
+200
+201
+202
+203
+204
+205
+206
+207
+208
+209
+210
+211
+212
+213
+214
+215
+216
+217
+218
+219
+220
+221
+222
+223
+224
+225
+226
+227
+228
+229
+230
+231
+232
+233
+234
+235
+236
+237
+238
+239
+240
+241
+242
+243
+244
+245
+246
+247
+248
+249
+250
+251
+252
+253
+254
+255
+256
+257
+258
+259
+260
+261
+262
+263
+264
+265
+266
+267
+268
+269
+270
+271
+272
+273
+274
+275
+276
+277
+278
+279
+280
+281
+282
+283
+284
+285
+286
+287
+288
+289
+290
+291
+292
+293
+294
+295
+296
+297
+298
+299
+300
+301
+302
+303
+304
+305
+306
+307
+308
+309
+310
+311
+312
+313
+314
+315
+316
+317
+318
+319
+320
+321
+322
+323
+324
+325
+326
+327
+328
+329
+330
+331
+332
+333
+334
+335
+336
+337
+338
+339
+340
+341
+342
+343
+344
+345
+346
+347
+348
+349
+350
+351
+352
+353
+354
+355
+356
+357
+358
+359
+360
+361
+362
+363
+364
+365
+366
+367
+368
+369
+370
+371
+372
+373
+374
+375
+376
+377
+378
+379
+380
+381
+382
+383
+384
+385
+386
+387
+388
+389
+390
+391
+392
+393
+394
+395
+396
+397
+398
+399
+400
+401
+402
+403
+404
+405
+406
+407
+408
+409
+410
+411
+412
+413
+414
+415
+416
+417
+418
+419
+420
+421
+422
+423
+424
+425
+426
+427
+428
+429
+430
+431
+432
+433
+434
+435
+436
+437
+438
+439
+440
+441
+442
+443
+444
+445
+446
+447
+448
+449
+450
+451
+452
+453
+454
+455
+456
+457
+458
+459
+460
+461
+462
+463
+464
+465
+466
+467
+468
+469
+470
+471
+472
+473
+474
+475
+476
+477
+478
+479
+480
+481
+482
+483
+484
+485
+486
+487
+488
+489
+490
+491
+492
+493
+494
+495
+496
+497
+498
+499
+500
+501
+502
+503
+504
+505
+506
+507
+508
+509
+510
+511
+512
+513
+514
+515
+516
+517
+518
+519
+520
+521
+522
+523
+524
+525
+526
+527
+528
+529
+530
+531
+532
+533
+534
+535
+536
+537
+538
+539
+540
+541
+542
+543
+544
+545
+546
+547
+548
+549
+550
+551
+552
+553
+554
+555
+556
+557
+558
+559
+560
+561
+562
+563
+564
+565
+566
+567
+568
+569
+570
+571
+572
+573
+574
+575
+576
+577
+578
+579
+580
+581
+582
+583
+584
+585
+586
+587
+588
+589
+590
+591
+592
+593
+594
+595
+596
+597
+598
+599
+600
+601
+602
+603
+604
+605
+606
+607
+608
+609
+610
+611
+612
+613
+614
+615
+616
+617
+618
+619
+620
+621
+622
+623
+624
+625
+626
+627
+628
+629
+630
+631
+632
+633
+634
+635
+636
+637
+638
+639
+640
+641
+642
+643
+644
+645
+646
+647
+648
+649
+650
+651
+652
+653
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
+
+/*
+ *  Copyright (C) 2004 Red Hat, Inc.
+ * Copyright (C) 2012-2021 MATE Developers
+ *
+ *  Caja is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU General Public License as
+ *  published by the Free Software Foundation; either version 2 of the
+ *  License, or (at your option) any later version.
+ *
+ *  Caja is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  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
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ *  Authors: Alexander Larsson <alexl@redhat.com>
+ *
+ */
+
+#include "config.h"
+
+#include <string.h>
+#include <stdio.h>
+
+#include <gtk/gtk.h>
+#include <glib/gi18n.h>
+#include <gio/gio.h>
+
+#include "user_share-private.h"
+
+#define REALM "Please log in as the user guest"
+#define USER "guest"
+#define GSETTINGS_SCHEMA "org.mate.FileSharing"
+#define GSETTINGS_KEY_FILE_SHARING_ENABLED "enabled"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_ENABLED "bluetooth-enabled"
+#define GSETTINGS_KEY_FILE_SHARING_REQUIRE_PASSWORD "require-password"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_ALLOW_WRITE "bluetooth-allow-write"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_REQUIRE_PAIRING "bluetooth-require-pairing"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED "bluetooth-obexpush-enabled"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_ACCEPT_FILES "bluetooth-accept-files"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_NOTIFY "bluetooth-notify"
+
+static GtkBuilder* builder;
+static GSettings* settings;<--- Shadowed declaration<--- Shadowed declaration<--- Shadowed declaration<--- Shadowed declaration<--- Shadowed declaration<--- Shadowed declaration<--- Shadowed declaration<--- Shadowed declaration<--- Shadowed declaration<--- Shadowed declaration
+
+
+static void
+write_out_password (const char *password)
+{
+    char *to_hash;
+    char *ascii_digest;
+    char *line;
+    char *filename;
+    FILE *file;
+
+    to_hash = g_strdup_printf ("%s:%s:%s", USER, REALM, password);
+    ascii_digest = g_compute_checksum_for_string (G_CHECKSUM_MD5, to_hash, strlen (to_hash));
+    g_free (to_hash);
+    line = g_strdup_printf ("%s:%s:%s\n", USER, REALM, ascii_digest);
+    g_free (ascii_digest);
+
+    filename = g_build_filename (g_get_user_config_dir (), "user-share", "passwd", NULL);
+
+    file = fopen (filename, "w");
+    if (file != NULL) {
+	fwrite (line, strlen (line), 1, file);
+	fclose (file);
+    }
+
+    g_free (filename);
+    g_free (line);
+}
+
+static void
+flush_password (void)
+{
+    GtkWidget *password_entry;
+    const char *password;
+
+    password_entry = GTK_WIDGET (gtk_builder_get_object (builder, "password_entry"));
+
+    if (g_object_get_data (G_OBJECT( password_entry), "user_edited")) {
+	password = gtk_entry_get_text (GTK_ENTRY (password_entry));
+	if (password != NULL && password[0] != 0)
+	    write_out_password (password);
+    }
+}
+
+
+static void
+update_ui (void)
+{
+    GSettings *settings;<--- Shadow variable
+    gboolean enabled;
+#ifdef HAVE_BLUETOOTH
+    gboolean bluetooth_enabled, bluetooth_write_enabled, require_pairing_enabled;
+    gboolean bluetooth_obexpush_enabled, bluetooth_obexpush_notify;
+#endif /* HAVE_BLUETOOTH */
+    char *str;
+    PasswordSetting password_setting;
+    AcceptSetting accept_setting;<--- Unused variable: accept_setting
+    GtkWidget *check;
+    GtkWidget *password_combo;
+    GtkWidget *password_entry;
+#ifdef HAVE_BLUETOOTH
+    GtkWidget *vbox_share_bluetooth;
+    GtkWidget *vbox_receive_bluetooth;
+    GtkWidget *bluetooth_check;
+    GtkWidget *allow_write_bluetooth_check;
+    GtkWidget *require_pairing_check;
+    GtkWidget *enable_obexpush_check;
+    GtkWidget *accept_obexpush_combo;
+    GtkWidget *notify_received_obexpush_check;
+#endif /* HAVE_BLUETOOTH */
+
+    settings = g_settings_new (GSETTINGS_SCHEMA);
+
+    enabled = g_settings_get_boolean (settings,
+				     FILE_SHARING_ENABLED);
+
+    str = g_settings_get_string (settings, FILE_SHARING_REQUIRE_PASSWORD);
+    password_setting = password_setting_from_string (str);
+    g_free (str);
+
+#ifdef HAVE_BLUETOOTH
+    bluetooth_enabled = g_settings_get_boolean (settings,
+    					       FILE_SHARING_BLUETOOTH_ENABLED);
+    bluetooth_write_enabled = g_settings_get_boolean (settings,
+						     FILE_SHARING_BLUETOOTH_ALLOW_WRITE);
+    require_pairing_enabled = g_settings_get_boolean (settings,
+    						     FILE_SHARING_BLUETOOTH_REQUIRE_PAIRING);
+    bluetooth_obexpush_enabled = g_settings_get_boolean (settings,
+    							FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED);
+    bluetooth_obexpush_notify = g_settings_get_boolean (settings,
+    						       FILE_SHARING_BLUETOOTH_OBEXPUSH_NOTIFY);
+
+    str = g_settings_get_string (settings, FILE_SHARING_BLUETOOTH_OBEXPUSH_ACCEPT_FILES);
+    accept_setting = accept_setting_from_string (str);
+    g_free (str);
+#endif /* HAVE_BLUETOOTH */
+
+    check = GTK_WIDGET (gtk_builder_get_object (builder, "enable_check"));
+    password_combo = GTK_WIDGET (gtk_builder_get_object (builder, "password_combo"));
+    password_entry = GTK_WIDGET (gtk_builder_get_object (builder, "password_entry"));
+#ifdef HAVE_BLUETOOTH
+    vbox_share_bluetooth = GTK_WIDGET (gtk_builder_get_object (builder, "vbox_share_bluetooth"));
+    vbox_receive_bluetooth = GTK_WIDGET (gtk_builder_get_object (builder, "vbox_receive_bluetooth"));
+    bluetooth_check = GTK_WIDGET (gtk_builder_get_object (builder, "enable_bluetooth_check"));
+    allow_write_bluetooth_check = GTK_WIDGET (gtk_builder_get_object (builder, "allow_write_bluetooth_check"));
+    require_pairing_check = GTK_WIDGET (gtk_builder_get_object (builder, "require_pairing_check"));
+    enable_obexpush_check = GTK_WIDGET (gtk_builder_get_object (builder, "enable_obexpush_check"));
+    accept_obexpush_combo = GTK_WIDGET (gtk_builder_get_object (builder, "accept_obexpush_combo"));
+    notify_received_obexpush_check = GTK_WIDGET (gtk_builder_get_object (builder, "notify_received_obexpush_check"));
+#endif /* HAVE_BLUETOOTH */
+
+    /* Network */
+    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (check), enabled);
+    gtk_widget_set_sensitive (password_combo, enabled);
+    gtk_widget_set_sensitive (password_entry, enabled && password_setting != PASSWORD_NEVER);
+
+    gtk_combo_box_set_active (GTK_COMBO_BOX (password_combo),
+			      password_setting);
+
+#ifdef HAVE_BLUETOOTH
+    /* Bluetooth ObexFTP */
+    gtk_widget_set_visible (vbox_share_bluetooth, TRUE);
+    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (bluetooth_check), bluetooth_enabled);
+    gtk_widget_set_sensitive (allow_write_bluetooth_check, bluetooth_enabled);
+    gtk_widget_set_sensitive (require_pairing_check, bluetooth_enabled);
+
+    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (allow_write_bluetooth_check),
+    				  bluetooth_write_enabled);
+    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (require_pairing_check),
+    				  require_pairing_enabled);
+
+    /* Bluetooth ObexPush */
+    gtk_widget_set_visible (vbox_receive_bluetooth, TRUE);
+    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (enable_obexpush_check), bluetooth_obexpush_enabled);
+    gtk_widget_set_sensitive (accept_obexpush_combo, bluetooth_obexpush_enabled);
+    gtk_widget_set_sensitive (notify_received_obexpush_check, bluetooth_obexpush_enabled);
+
+    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (notify_received_obexpush_check),
+    				  bluetooth_obexpush_notify);
+
+    gtk_combo_box_set_active (GTK_COMBO_BOX (accept_obexpush_combo),
+    			      accept_setting);
+#endif /* HAVE_BLUETOOTH */
+
+    g_object_unref (settings);
+}
+
+static void
+file_sharing_enabled_changed (GSettings *settings, gchar *key, gpointer data)
+{
+    update_ui ();
+}
+
+static void
+password_required_changed (GSettings *settings, gchar *key, gpointer data)
+{
+    update_ui ();
+}
+
+#ifdef HAVE_BLUETOOTH
+static void
+file_sharing_bluetooth_enabled_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	update_ui ();
+}
+
+static void
+file_sharing_bluetooth_allow_write_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	update_ui ();
+}
+
+static void
+file_sharing_bluetooth_require_pairing_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	update_ui ();
+}
+
+static void
+file_sharing_bluetooth_obexpush_enabled_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	update_ui ();
+}
+
+static void
+file_sharing_bluetooth_obexpush_accept_files_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	update_ui ();
+}
+
+static void
+file_sharing_bluetooth_obexpush_notify_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	update_ui ();
+}
+#endif /* HAVE_BLUETOOTH */
+
+static void
+password_combo_changed (GtkComboBox *combo_box)
+{
+    GSettings *settings;<--- Shadow variable
+    guint setting;
+
+    setting = gtk_combo_box_get_active (combo_box);
+
+    settings = g_settings_new (GSETTINGS_SCHEMA) ;
+
+    g_settings_set_string (settings,
+			     FILE_SHARING_REQUIRE_PASSWORD,
+			     password_string_from_setting (setting));
+    g_object_unref (settings);
+}
+
+static void
+launch_share (void)
+{
+	if (!g_spawn_command_line_async (USER_SHARE_PROGRAM, NULL))
+		g_warning ("Unable to start mate-user-share program");
+}
+
+#ifdef HAVE_BLUETOOTH
+static void
+enable_bluetooth_check_toggled (GtkWidget *check)
+{
+	GSettings *settings;<--- Shadow variable
+	gboolean enabled;
+
+	enabled = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check));
+
+	settings = g_settings_new (GSETTINGS_SCHEMA) ;
+
+	g_settings_set_boolean (settings,
+			       FILE_SHARING_BLUETOOTH_ENABLED,
+			       enabled);
+
+	g_object_unref (settings);
+
+	if (enabled != FALSE)
+		launch_share ();
+}
+#endif /* HAVE_BLUETOOTH */
+
+static void
+enable_check_toggled (GtkWidget *check)
+{
+	GSettings *settings;<--- Shadow variable
+	gboolean enabled;
+
+	enabled = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check));
+
+	settings = g_settings_new (GSETTINGS_SCHEMA);
+
+	g_settings_set_boolean (settings,
+			       FILE_SHARING_ENABLED,
+			       enabled);
+
+	g_object_unref (settings);
+
+	if (enabled != FALSE)
+		launch_share ();
+}
+
+static void
+password_entry_changed (GtkEditable *editable)
+{
+	g_object_set_data (G_OBJECT (editable),
+			   "user_edited", GINT_TO_POINTER (1));
+	flush_password ();
+}
+
+#ifdef HAVE_BLUETOOTH
+static void
+bluetooth_allow_write_check_toggled (GtkWidget *check)
+{
+	GSettings *settings;<--- Shadow variable
+	gboolean enabled;
+
+	enabled = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check));
+
+	settings = g_settings_new (GSETTINGS_SCHEMA) ;
+
+	g_settings_set_boolean (settings,
+			       FILE_SHARING_BLUETOOTH_ALLOW_WRITE,
+			       enabled);
+
+	g_object_unref (settings);
+}
+
+static void
+bluetooth_require_pairing_check_toggled (GtkWidget *check)
+{
+	GSettings *settings;<--- Shadow variable
+	gboolean enabled;
+
+	enabled = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check));
+
+	settings = g_settings_new (GSETTINGS_SCHEMA) ;
+
+	g_settings_set_boolean (settings,
+			       FILE_SHARING_BLUETOOTH_REQUIRE_PAIRING,
+			       enabled);
+
+	g_object_unref (settings);
+}
+
+static void
+enable_obexpush_check_toggled (GtkWidget *check)
+{
+	GSettings *settings;<--- Shadow variable
+	gboolean enabled;
+
+	enabled = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check));
+
+	settings = g_settings_new (GSETTINGS_SCHEMA) ;
+
+	g_settings_set_boolean (settings,
+			       FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED,
+			       enabled);
+
+	g_object_unref (settings);
+
+	if (enabled != FALSE)
+		launch_share ();
+}
+
+static void
+accept_obexpush_combo_changed (GtkComboBox *combo_box)
+{
+    GSettings *settings;<--- Shadow variable
+    guint setting;
+
+    setting = gtk_combo_box_get_active (combo_box);
+
+    settings = g_settings_new (GSETTINGS_SCHEMA) ;
+
+    g_settings_set_string (settings,
+			     FILE_SHARING_BLUETOOTH_OBEXPUSH_ACCEPT_FILES,
+			     accept_string_from_setting (setting));
+    g_object_unref (settings);
+}
+
+static void
+notify_received_obexpush_check_toggled (GtkWidget *check)
+{
+	GSettings *settings;<--- Shadow variable
+	gboolean enabled;
+
+	enabled = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check));
+
+	settings = g_settings_new (GSETTINGS_SCHEMA) ;
+
+	g_settings_set_boolean (settings,
+			       FILE_SHARING_BLUETOOTH_OBEXPUSH_NOTIFY,
+			       enabled);
+
+	g_object_unref (settings);
+}
+#endif /* HAVE_BLUETOOTH */
+
+static GtkWidget *
+error_dialog (const char *title,
+	      const char *reason,
+	      GtkWindow *parent)
+{
+	GtkWidget *error_dialog;
+
+	if (reason == NULL)
+		reason = _("No reason");
+
+	error_dialog =
+		gtk_message_dialog_new (parent,
+					GTK_DIALOG_MODAL,
+					GTK_MESSAGE_ERROR,
+					GTK_BUTTONS_OK,
+					"%s", title);
+	gtk_message_dialog_format_secondary_text
+		(GTK_MESSAGE_DIALOG (error_dialog), "%s", reason);
+
+	gtk_window_set_title (GTK_WINDOW (error_dialog), ""); /* as per HIG */
+	gtk_container_set_border_width (GTK_CONTAINER (error_dialog), 5);
+	gtk_dialog_set_default_response (GTK_DIALOG (error_dialog),
+					 GTK_RESPONSE_OK);
+	gtk_window_set_modal (GTK_WINDOW (error_dialog), TRUE);
+
+	return error_dialog;
+}
+
+static void
+help_button_clicked (GtkButton *button, GtkWidget *window)
+{
+	GError *error = NULL;
+
+	if (gtk_show_uri_on_window (GTK_WINDOW (window), "help:mate-user-share", gtk_get_current_event_time (), &error) == FALSE) {
+		GtkWidget *dialog;
+
+		dialog = error_dialog (_("Could not display the help contents."), error->message, GTK_WINDOW (window));
+		g_signal_connect (G_OBJECT (dialog), "response", G_CALLBACK
+				  (gtk_widget_destroy), error_dialog);
+		gtk_window_present (GTK_WINDOW (dialog));
+
+		g_error_free (error);
+	}
+}
+
+static GtkWidget *
+create_window (void)
+{
+    GError *error = NULL;
+    GSettings *settings;<--- Shadow variable
+    GtkWidget *check;
+    GtkWidget *password_combo;
+    GtkWidget *password_entry;
+#ifdef HAVE_BLUETOOTH
+    GtkWidget *bluetooth_check;
+    GtkWidget *bluetooth_allow_write_check;
+    GtkWidget *require_pairing_check;
+    GtkWidget *enable_obexpush_check;
+    GtkWidget *accept_obexpush_combo;
+    GtkWidget *notify_received_obexpush_check;
+#endif /* HAVE_BLUETOOTH */
+    GtkWidget *window;
+    GtkListStore *store;
+    GtkCellRenderer *cell;
+    GtkTreeIter iter;
+
+    builder = gtk_builder_new ();
+    gtk_builder_add_from_file (builder, DATADIR"file-share-properties.ui", &error);
+
+    if (error) {
+      GtkWidget *dialog;
+
+      dialog = error_dialog (_("Could not build interface."), error->message, NULL);
+      gtk_dialog_run (GTK_DIALOG (dialog));
+      gtk_widget_destroy (dialog);
+
+      g_error_free (error);
+      return NULL;
+    }
+
+    window = GTK_WIDGET (gtk_builder_get_object (builder, "user_share_dialog"));
+
+    settings = g_settings_new (GSETTINGS_SCHEMA);
+
+    check = GTK_WIDGET (gtk_builder_get_object (builder, "enable_check"));
+    password_combo = GTK_WIDGET (gtk_builder_get_object (builder, "password_combo"));
+    password_entry = GTK_WIDGET (gtk_builder_get_object (builder, "password_entry"));
+#ifdef HAVE_BLUETOOTH
+    bluetooth_check = GTK_WIDGET (gtk_builder_get_object (builder, "enable_bluetooth_check"));
+    bluetooth_allow_write_check = GTK_WIDGET (gtk_builder_get_object (builder, "allow_write_bluetooth_check"));
+    require_pairing_check = GTK_WIDGET (gtk_builder_get_object (builder, "require_pairing_check"));
+    enable_obexpush_check = GTK_WIDGET (gtk_builder_get_object (builder, "enable_obexpush_check"));
+    accept_obexpush_combo = GTK_WIDGET (gtk_builder_get_object (builder, "accept_obexpush_combo"));
+    notify_received_obexpush_check = GTK_WIDGET (gtk_builder_get_object (builder, "notify_received_obexpush_check"));
+#endif /* HAVE_BLUETOOTH */
+
+    store = gtk_list_store_new (1, G_TYPE_STRING);
+    gtk_combo_box_set_model (GTK_COMBO_BOX (password_combo),
+			     GTK_TREE_MODEL (store));
+    cell = gtk_cell_renderer_text_new ();
+    gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (password_combo), cell, TRUE);
+    gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (password_combo), cell,
+				    "text", 0,
+				    NULL);
+
+    /* Keep in same order as enum */
+    gtk_list_store_append (store, &iter);
+    gtk_list_store_set (store, &iter, 0,
+			_("Never"), -1);
+    gtk_list_store_append (store, &iter);
+    gtk_list_store_set (store, &iter, 0,
+			_("When writing files"), -1);
+    gtk_list_store_append (store, &iter);
+    gtk_list_store_set (store, &iter, 0,
+			_("Always"), -1);
+    g_object_unref (store);
+
+    /* We can't read the password from the text, just set it to something */
+    gtk_entry_set_text (GTK_ENTRY (password_entry), "none");
+    g_object_set_data (G_OBJECT (password_entry),
+		       "user_edited", GINT_TO_POINTER (0));
+    g_signal_connect (password_entry,
+		      "changed", G_CALLBACK (password_entry_changed), NULL);
+
+#ifdef HAVE_BLUETOOTH
+    /* Accept files combo */
+    store = gtk_list_store_new (1, G_TYPE_STRING);
+    gtk_combo_box_set_model (GTK_COMBO_BOX (accept_obexpush_combo),
+			     GTK_TREE_MODEL (store));
+    cell = gtk_cell_renderer_text_new ();
+    gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (accept_obexpush_combo), cell, TRUE);
+    gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (accept_obexpush_combo), cell,
+				    "text", 0,
+				    NULL);
+
+    /* Keep in same order as enum */
+    gtk_list_store_append (store, &iter);
+    gtk_list_store_set (store, &iter, 0,
+			_("Always"), -1);
+    gtk_list_store_append (store, &iter);
+    gtk_list_store_set (store, &iter, 0,
+			_("Only for set up devices"), -1);
+    //FIXME implement
+#if 0
+    gtk_list_store_append (store, &iter);
+    gtk_list_store_set (store, &iter, 0,
+    			_("Ask"), -1);
+#endif
+    g_object_unref (store);
+#endif /* HAVE_BLUETOOTH */
+
+    g_signal_connect (check,
+		      "toggled", G_CALLBACK (enable_check_toggled), NULL);
+    g_signal_connect (password_combo,
+		      "changed", G_CALLBACK (password_combo_changed), NULL);
+#ifdef HAVE_BLUETOOTH
+    g_signal_connect (bluetooth_check,
+    		      "toggled", G_CALLBACK (enable_bluetooth_check_toggled), NULL);
+    g_signal_connect (bluetooth_allow_write_check,
+    		      "toggled", G_CALLBACK (bluetooth_allow_write_check_toggled), NULL);
+    g_signal_connect (require_pairing_check,
+    		      "toggled", G_CALLBACK (bluetooth_require_pairing_check_toggled), NULL);
+    g_signal_connect (enable_obexpush_check,
+    		      "toggled", G_CALLBACK (enable_obexpush_check_toggled), NULL);
+    g_signal_connect (accept_obexpush_combo,
+    		      "changed", G_CALLBACK (accept_obexpush_combo_changed), NULL);
+    g_signal_connect (notify_received_obexpush_check,
+    		      "toggled", G_CALLBACK (notify_received_obexpush_check_toggled), NULL);
+#endif /* HAVE_BLUETOOTH */
+
+    g_signal_connect_swapped (GTK_WIDGET (gtk_builder_get_object (builder, "close_button")),
+                              "clicked", G_CALLBACK (gtk_widget_destroy), window);
+    g_signal_connect (GTK_WIDGET (gtk_builder_get_object (builder, "help_button")),
+		      "clicked", G_CALLBACK (help_button_clicked),
+		      gtk_builder_get_object (builder, "user_share_dialog"));
+
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_ENABLED,
+			     G_CALLBACK (file_sharing_enabled_changed), NULL);
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_REQUIRE_PASSWORD,
+			     G_CALLBACK (password_required_changed), NULL);
+#ifdef HAVE_BLUETOOTH
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_ENABLED,
+			     G_CALLBACK (file_sharing_bluetooth_enabled_changed), NULL);
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_ALLOW_WRITE,
+			     G_CALLBACK (file_sharing_bluetooth_allow_write_changed), NULL);
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_REQUIRE_PAIRING,
+			     G_CALLBACK (file_sharing_bluetooth_require_pairing_changed), NULL);
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED,
+			     G_CALLBACK (file_sharing_bluetooth_obexpush_enabled_changed), NULL);
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_ACCEPT_FILES,
+			     G_CALLBACK (file_sharing_bluetooth_obexpush_accept_files_changed), NULL);
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_NOTIFY,
+			     G_CALLBACK (file_sharing_bluetooth_obexpush_notify_changed), NULL);
+#endif /* HAVE_BLUETOOTH */
+
+    update_ui ();
+
+    return window;
+}
+
+static void
+activate (GtkApplication *app)
+{
+    GList *list;
+    GtkWidget *window;
+
+    list = gtk_application_get_windows (app);
+
+    if (list) {
+        gtk_window_present (GTK_WINDOW (list->data));
+    } else {
+        window = create_window ();
+        gtk_window_set_application (GTK_WINDOW (window), app);
+        gtk_widget_show (window);
+    }
+}
+
+int
+main (int argc, char *argv[])
+{
+    GtkApplication *app;
+    gint status;
+
+    bindtextdomain (GETTEXT_PACKAGE, MATELOCALEDIR);
+    bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
+    textdomain (GETTEXT_PACKAGE);
+
+    app = gtk_application_new ("org.mate.user-share.properties",
+                               G_APPLICATION_FLAGS_NONE);
+    g_signal_connect (app, "activate", G_CALLBACK (activate), NULL);
+
+    status = g_application_run (G_APPLICATION (app), argc, argv);
+
+    g_object_unref (app);
+
+    return status;
+}
+
+ +
+ +
+ + diff --git a/2023-09-10-082921-9712-cppcheck@2d4aba56e7bf_master/2.html b/2023-09-10-082921-9712-cppcheck@2d4aba56e7bf_master/2.html new file mode 100644 index 0000000..7bbeccd --- /dev/null +++ b/2023-09-10-082921-9712-cppcheck@2d4aba56e7bf_master/2.html @@ -0,0 +1,1123 @@ + + + + + + Cppcheck - HTML report - mate-user-share + + + + + +
+ + + +
+
  1
+  2
+  3
+  4
+  5
+  6
+  7
+  8
+  9
+ 10
+ 11
+ 12
+ 13
+ 14
+ 15
+ 16
+ 17
+ 18
+ 19
+ 20
+ 21
+ 22
+ 23
+ 24
+ 25
+ 26
+ 27
+ 28
+ 29
+ 30
+ 31
+ 32
+ 33
+ 34
+ 35
+ 36
+ 37
+ 38
+ 39
+ 40
+ 41
+ 42
+ 43
+ 44
+ 45
+ 46
+ 47
+ 48
+ 49
+ 50
+ 51
+ 52
+ 53
+ 54
+ 55
+ 56
+ 57
+ 58
+ 59
+ 60
+ 61
+ 62
+ 63
+ 64
+ 65
+ 66
+ 67
+ 68
+ 69
+ 70
+ 71
+ 72
+ 73
+ 74
+ 75
+ 76
+ 77
+ 78
+ 79
+ 80
+ 81
+ 82
+ 83
+ 84
+ 85
+ 86
+ 87
+ 88
+ 89
+ 90
+ 91
+ 92
+ 93
+ 94
+ 95
+ 96
+ 97
+ 98
+ 99
+100
+101
+102
+103
+104
+105
+106
+107
+108
+109
+110
+111
+112
+113
+114
+115
+116
+117
+118
+119
+120
+121
+122
+123
+124
+125
+126
+127
+128
+129
+130
+131
+132
+133
+134
+135
+136
+137
+138
+139
+140
+141
+142
+143
+144
+145
+146
+147
+148
+149
+150
+151
+152
+153
+154
+155
+156
+157
+158
+159
+160
+161
+162
+163
+164
+165
+166
+167
+168
+169
+170
+171
+172
+173
+174
+175
+176
+177
+178
+179
+180
+181
+182
+183
+184
+185
+186
+187
+188
+189
+190
+191
+192
+193
+194
+195
+196
+197
+198
+199
+200
+201
+202
+203
+204
+205
+206
+207
+208
+209
+210
+211
+212
+213
+214
+215
+216
+217
+218
+219
+220
+221
+222
+223
+224
+225
+226
+227
+228
+229
+230
+231
+232
+233
+234
+235
+236
+237
+238
+239
+240
+241
+242
+243
+244
+245
+246
+247
+248
+249
+250
+251
+252
+253
+254
+255
+256
+257
+258
+259
+260
+261
+262
+263
+264
+265
+266
+267
+268
+269
+270
+271
+272
+273
+274
+275
+276
+277
+278
+279
+280
+281
+282
+283
+284
+285
+286
+287
+288
+289
+290
+291
+292
+293
+294
+295
+296
+297
+298
+299
+300
+301
+302
+303
+304
+305
+306
+307
+308
+309
+310
+311
+312
+313
+314
+315
+316
+317
+318
+319
+320
+321
+322
+323
+324
+325
+326
+327
+328
+329
+330
+331
+332
+333
+334
+335
+336
+337
+338
+339
+340
+341
+342
+343
+344
+345
+346
+347
+348
+349
+350
+351
+352
+353
+354
+355
+356
+357
+358
+359
+360
+361
+362
+363
+364
+365
+366
+367
+368
+369
+370
+371
+372
+373
+374
+375
+376
+377
+378
+379
+380
+381
+382
+383
+384
+385
+386
+387
+388
+389
+390
+391
+392
+393
+394
+395
+396
+397
+398
+399
+400
+401
+402
+403
+404
+405
+406
+407
+408
+409
+410
+411
+412
+413
+414
+415
+416
+417
+418
+419
+420
+421
+422
+423
+424
+425
+426
+427
+428
+429
+430
+431
+432
+433
+434
+435
+436
+437
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
+
+/*
+ *  Copyright (C) 2004-2008 Red Hat, Inc.
+ * Copyright (C) 2012-2021 MATE Developers
+ *
+ *  Caja is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU General Public License as
+ *  published by the Free Software Foundation; either version 2 of the
+ *  License, or (at your option) any later version.
+ *
+ *  Caja is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  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
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ *  Authors: Alexander Larsson <alexl@redhat.com>
+ *
+ */
+
+#include "config.h"
+
+#include <glib.h>
+#include <glib/gi18n.h>
+#include <X11/Xlib.h>
+
+#include <gio/gio.h>
+
+#include <stdarg.h>
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <signal.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <sys/stat.h>
+
+#ifdef HAVE_SELINUX
+#include <selinux/selinux.h>
+#endif
+
+#include "user_share-common.h"
+#include "user_share-private.h"
+#include "http.h"
+
+/* From avahi-common/domain.h */
+#define AVAHI_LABEL_MAX 64
+
+#define GSETTINGS_SCHEMA "org.mate.FileSharing"
+
+static pid_t httpd_pid = 0;
+
+static int
+get_port (void)
+{
+	int sock;
+	struct sockaddr_in addr;
+	int reuse;
+	socklen_t len;
+
+	sock = socket (PF_INET, SOCK_STREAM, 0);
+	if (sock < 0) {
+		return -1;
+	}
+
+	memset (&addr, 0, sizeof (addr));
+	addr.sin_port = 0;
+	addr.sin_addr.s_addr = INADDR_ANY;
+	addr.sin_family = AF_INET;
+
+	reuse = 1;
+	setsockopt (sock, SOL_SOCKET, SO_REUSEADDR, &reuse, sizeof (reuse));
+	if (bind (sock, (struct sockaddr *)&addr, sizeof (addr)) == -1) {
+		close (sock);
+		return -1;
+	}
+
+	len = sizeof (addr);
+	if (getsockname (sock, (struct sockaddr *)&addr, &len) == -1) {
+		close (sock);
+		return -1;
+	}
+
+#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__APPLE__) || defined(__OpenBSD__)
+	/* XXX This exposes a potential race condition, but without this,
+	 * httpd will not start on the above listed platforms due to the fact
+	 * that SO_REUSEADDR is also needed when Apache binds to the listening
+	 * socket.  At this time, Apache does not support that socket option.
+	 */
+	close (sock);
+#endif
+	return ntohs (addr.sin_port);
+}
+
+static char *
+truncate_name (const char *name)
+{
+	const char *end;
+
+	end = g_utf8_find_prev_char (name, name + 64);
+	g_assert (end != NULL);
+	return g_strndup (name, end - name);
+}
+
+static char *
+get_share_name (void)
+{
+	static char *name = NULL;
+	const char *host_name;
+	char *str;
+
+	if (name == NULL) {
+		host_name = g_get_host_name ();
+		if (strcmp (host_name, "localhost") == 0) {
+			/* Translators: The %s will get filled in with the user name
+			   of the user, to form a genitive. If this is difficult to
+			   translate correctly so that it will work correctly in your
+			   language, you may use something equivalent to
+			   "Public files of %s", or leave out the %s altogether.
+			   In the latter case, please put "%.0s" somewhere in the string,
+			   which will match the user name string passed by the C code,
+			   but not put the user name in the final string. This is to
+			   avoid the warning that msgfmt might otherwise generate. */
+			name = g_strdup_printf (_("%s's public files"), g_get_user_name ());
+		} else {
+			/* Translators: This is similar to the string before, only it
+			   has the hostname in it too. */
+			name = g_strdup_printf (_("%s's public files on %s"),
+						g_get_user_name (),
+						host_name);
+		}
+
+	}
+	/* And truncate */
+	if (strlen (name) < AVAHI_LABEL_MAX)
+		return name;
+
+	str = truncate_name (name);
+	g_free (name);
+	name = str;
+
+	return name;
+}
+
+static void
+ensure_conf_dir (void)
+{
+	char *dirname;
+
+	dirname = g_build_filename (g_get_user_config_dir (), "user-share", NULL);
+	g_mkdir_with_parents (dirname, 0755);
+	g_free (dirname);
+}
+
+static void
+httpd_child_setup (gpointer user_data)
+{
+#ifdef HAVE_SELINUX
+	char *mycon;
+	/* If selinux is enabled, avoid transitioning to the httpd_t context,
+	   as this normally means you can't read the users homedir. */
+	if (is_selinux_enabled()) {
+		if (getcon (&mycon) < 0) {
+			abort ();
+		}
+		if (setexeccon (mycon) < 0)
+			abort ();
+		freecon (mycon);
+	}
+#endif
+}
+
+static const char *known_httpd_locations [] = {
+	HTTPD_PROGRAM,
+	"/usr/sbin/httpd",
+	"/usr/sbin/httpd2",
+	"/usr/sbin/apache2",
+	NULL
+};
+
+static char*
+get_httpd_program (void)
+{
+	int i;
+
+	for (i = 0; known_httpd_locations[i]; i++) {
+		if (known_httpd_locations[i][0] == '\0') {
+			/* empty string as first element, happens when
+			 * configured --with-httpd=auto */
+			continue;
+		}
+		if (g_file_test (known_httpd_locations[i], G_FILE_TEST_IS_EXECUTABLE)
+				&& ! g_file_test (known_httpd_locations[i], G_FILE_TEST_IS_DIR)) {
+			return g_strdup (known_httpd_locations[i]);
+		}
+	}
+	return NULL;
+}
+
+static const char *known_httpd_modules_locations [] = {
+	HTTPD_MODULES_PATH,
+	"/etc/httpd/modules",
+	"/usr/lib/apache2/modules",
+	NULL
+};
+
+static gchar*
+get_httpd_modules_path (void)
+{
+	int i;
+
+	for (i = 0; known_httpd_modules_locations[i]; i++) {
+		if (known_httpd_modules_locations[i][0] == '\0') {
+			/* empty string as first element, happens when
+			 * configured --with-httpd=auto */
+			continue;
+		}
+		if (g_file_test (known_httpd_modules_locations[i], G_FILE_TEST_IS_EXECUTABLE)
+				&& g_file_test (known_httpd_modules_locations[i], G_FILE_TEST_IS_DIR)) {
+			return g_strdup (known_httpd_modules_locations[i]);
+		}
+	}
+	return NULL;
+}
+
+static GRegex *version_regex = NULL;
+
+static char*
+get_httpd_config (const char *httpd_program)
+{
+	gchar *standard_output;
+	gchar *cmd_line;
+	GMatchInfo *match_info;
+	gchar *version_number = NULL;
+	gchar *config;
+
+	cmd_line = g_strdup_printf ("%s -v", httpd_program);
+	if (! g_spawn_command_line_sync (cmd_line, &standard_output, NULL, NULL, NULL)) {
+		g_free (cmd_line);
+		return NULL;
+	}
+	g_free (cmd_line);
+
+	if (version_regex == NULL) {
+		version_regex = g_regex_new ("\\d\\.\\d", 0, 0, NULL);
+	}
+
+	if (g_regex_match (version_regex, standard_output, 0, &match_info)) {
+		while (g_match_info_matches (match_info)) {
+			version_number = g_match_info_fetch (match_info, 0);
+			break;
+		}
+		g_match_info_free (match_info);
+		g_free (standard_output);
+	} else {
+		/* Failed to parse httpd version number */
+		g_warning ("Could not parse '%s' as a version for httpd", standard_output);
+		g_free (standard_output);
+		/* assume it is 2.2 */
+		version_number = g_strdup ("2.2");
+	}
+
+	config = g_strdup_printf (HTTPD_CONFIG_TEMPLATE, version_number);
+	g_free (version_number);
+
+	return config;
+}
+
+static gboolean
+spawn_httpd (int port, pid_t *pid_out)
+{
+	char *free1, *free2, *free3, *free4, *free5, *free6, *free7, *free8, *free9;
+	gboolean res;
+	char *argv[10];
+	char *env[10];
+	int i;
+	gint status;
+	char *pid_filename;
+	char *pidfile;
+	GError *error;
+	gboolean got_pidfile;
+	GSettings *settings;
+	char *str;
+	char *public_dir;
+
+	public_dir = lookup_public_dir ();
+	ensure_conf_dir ();
+
+	i = 0;
+	free1 = argv[i++] = get_httpd_program ();
+	if (argv[0] == NULL) {
+		fprintf (stderr, "error finding httpd server\n");
+		return FALSE;
+	}
+
+	argv[i++] = "-f";
+	free2 = argv[i++] = get_httpd_config (argv[0]);
+	argv[i++] = "-C";
+	free3 = argv[i++] = g_strdup_printf ("Listen %d", port);
+
+	settings = g_settings_new (GSETTINGS_SCHEMA);
+	str = g_settings_get_string (settings,
+				       FILE_SHARING_REQUIRE_PASSWORD);
+
+	if (str && strcmp (str, "never") == 0) {
+		/* Do nothing */
+	} else if (str && strcmp (str, "on_write") == 0){
+		argv[i++] = "-D";
+		argv[i++] = "RequirePasswordOnWrite";
+	} else {
+		/* always, or safe fallback */
+		argv[i++] = "-D";
+		argv[i++] = "RequirePasswordAlways";
+	}
+	g_free (str);
+	g_object_unref (settings);
+
+	argv[i] = NULL;
+
+	i = 0;
+	free4 = env[i++] = g_strdup_printf ("HOME=%s", g_get_home_dir());
+	free5 = env[i++] = g_strdup_printf ("XDG_PUBLICSHARE_DIR=%s", public_dir);
+	free6 = env[i++] = g_strdup_printf ("XDG_CONFIG_HOME=%s", g_get_user_config_dir ());
+	free7 = env[i++] = g_strdup_printf ("GUS_SHARE_NAME=%s", get_share_name ());
+	free8 = env[i++] = g_strdup_printf ("GUS_LOGIN_LABEL=%s", "Please log in as the user guest");
+	free9 = env[i++] = g_strdup_printf ("HTTP_MODULES_PATH=%s",get_httpd_modules_path ());
+	env[i++] = "LANG=C";
+	env[i] = NULL;
+
+	pid_filename = g_build_filename (g_get_user_config_dir (), "user-share", "pid", NULL);
+
+	/* Remove pid file before spawning to avoid races with child and old pidfile */
+	unlink (pid_filename);
+
+	error = NULL;
+	res = g_spawn_sync (g_get_home_dir(),
+			    argv, env, 0,
+			    httpd_child_setup, NULL,
+			    NULL, NULL,
+			    &status,
+			    &error);
+	g_free (free1);
+	g_free (free2);
+	g_free (free3);
+	g_free (free4);
+	g_free (free5);
+	g_free (free6);
+	g_free (free7);
+	g_free (free8);
+	g_free (free9);
+	g_free (public_dir);
+
+	if (!res) {
+		fprintf (stderr, "error spawning httpd: %s\n",
+			 error->message);
+		g_error_free (error);
+		g_free (pid_filename);
+		return FALSE;
+	}
+
+	if (status != 0) {
+		g_free (pid_filename);
+		return FALSE;
+	}
+
+	got_pidfile = FALSE;
+	error = NULL;
+	for (i = 0; i < 5; i++) {
+		if (error != NULL)
+			g_error_free (error);
+		error = NULL;
+		if (g_file_get_contents (pid_filename, &pidfile, NULL, &error)) {
+			got_pidfile = TRUE;
+			*pid_out = atoi (pidfile);
+			g_free (pidfile);
+			break;
+		}
+		sleep (1);
+	}
+
+	g_free (pid_filename);
+
+	if (!got_pidfile) {
+		fprintf (stderr, "error opening httpd pidfile: %s\n", error->message);
+		g_error_free (error);
+		return FALSE;
+	}
+	return TRUE;
+}
+
+static void
+kill_httpd (void)
+{
+	if (httpd_pid != 0) {
+		kill (httpd_pid, SIGTERM);
+
+		/* Allow child time to die, we can't waitpid, because its
+		   not a direct child */
+		sleep (1);
+	}
+	httpd_pid = 0;
+}
+
+void
+http_up (void)
+{
+	guint port;
+
+	port = get_port ();
+	if (!spawn_httpd (port, &httpd_pid)) {
+		fprintf (stderr, "spawning httpd failed\n");
+	}
+}
+
+void
+http_down (void)
+{
+	kill_httpd ();
+}
+
+gboolean
+http_init (void)
+{
+	return TRUE;
+}
+
+pid_t
+http_get_pid (void)
+{
+	return httpd_pid;
+}
+
+ +
+ +
+ + diff --git a/2023-09-10-082921-9712-cppcheck@2d4aba56e7bf_master/3.html b/2023-09-10-082921-9712-cppcheck@2d4aba56e7bf_master/3.html new file mode 100644 index 0000000..463b556 --- /dev/null +++ b/2023-09-10-082921-9712-cppcheck@2d4aba56e7bf_master/3.html @@ -0,0 +1,1357 @@ + + + + + + Cppcheck - HTML report - mate-user-share + + + + + +
+ + + +
+
  1
+  2
+  3
+  4
+  5
+  6
+  7
+  8
+  9
+ 10
+ 11
+ 12
+ 13
+ 14
+ 15
+ 16
+ 17
+ 18
+ 19
+ 20
+ 21
+ 22
+ 23
+ 24
+ 25
+ 26
+ 27
+ 28
+ 29
+ 30
+ 31
+ 32
+ 33
+ 34
+ 35
+ 36
+ 37
+ 38
+ 39
+ 40
+ 41
+ 42
+ 43
+ 44
+ 45
+ 46
+ 47
+ 48
+ 49
+ 50
+ 51
+ 52
+ 53
+ 54
+ 55
+ 56
+ 57
+ 58
+ 59
+ 60
+ 61
+ 62
+ 63
+ 64
+ 65
+ 66
+ 67
+ 68
+ 69
+ 70
+ 71
+ 72
+ 73
+ 74
+ 75
+ 76
+ 77
+ 78
+ 79
+ 80
+ 81
+ 82
+ 83
+ 84
+ 85
+ 86
+ 87
+ 88
+ 89
+ 90
+ 91
+ 92
+ 93
+ 94
+ 95
+ 96
+ 97
+ 98
+ 99
+100
+101
+102
+103
+104
+105
+106
+107
+108
+109
+110
+111
+112
+113
+114
+115
+116
+117
+118
+119
+120
+121
+122
+123
+124
+125
+126
+127
+128
+129
+130
+131
+132
+133
+134
+135
+136
+137
+138
+139
+140
+141
+142
+143
+144
+145
+146
+147
+148
+149
+150
+151
+152
+153
+154
+155
+156
+157
+158
+159
+160
+161
+162
+163
+164
+165
+166
+167
+168
+169
+170
+171
+172
+173
+174
+175
+176
+177
+178
+179
+180
+181
+182
+183
+184
+185
+186
+187
+188
+189
+190
+191
+192
+193
+194
+195
+196
+197
+198
+199
+200
+201
+202
+203
+204
+205
+206
+207
+208
+209
+210
+211
+212
+213
+214
+215
+216
+217
+218
+219
+220
+221
+222
+223
+224
+225
+226
+227
+228
+229
+230
+231
+232
+233
+234
+235
+236
+237
+238
+239
+240
+241
+242
+243
+244
+245
+246
+247
+248
+249
+250
+251
+252
+253
+254
+255
+256
+257
+258
+259
+260
+261
+262
+263
+264
+265
+266
+267
+268
+269
+270
+271
+272
+273
+274
+275
+276
+277
+278
+279
+280
+281
+282
+283
+284
+285
+286
+287
+288
+289
+290
+291
+292
+293
+294
+295
+296
+297
+298
+299
+300
+301
+302
+303
+304
+305
+306
+307
+308
+309
+310
+311
+312
+313
+314
+315
+316
+317
+318
+319
+320
+321
+322
+323
+324
+325
+326
+327
+328
+329
+330
+331
+332
+333
+334
+335
+336
+337
+338
+339
+340
+341
+342
+343
+344
+345
+346
+347
+348
+349
+350
+351
+352
+353
+354
+355
+356
+357
+358
+359
+360
+361
+362
+363
+364
+365
+366
+367
+368
+369
+370
+371
+372
+373
+374
+375
+376
+377
+378
+379
+380
+381
+382
+383
+384
+385
+386
+387
+388
+389
+390
+391
+392
+393
+394
+395
+396
+397
+398
+399
+400
+401
+402
+403
+404
+405
+406
+407
+408
+409
+410
+411
+412
+413
+414
+415
+416
+417
+418
+419
+420
+421
+422
+423
+424
+425
+426
+427
+428
+429
+430
+431
+432
+433
+434
+435
+436
+437
+438
+439
+440
+441
+442
+443
+444
+445
+446
+447
+448
+449
+450
+451
+452
+453
+454
+455
+456
+457
+458
+459
+460
+461
+462
+463
+464
+465
+466
+467
+468
+469
+470
+471
+472
+473
+474
+475
+476
+477
+478
+479
+480
+481
+482
+483
+484
+485
+486
+487
+488
+489
+490
+491
+492
+493
+494
+495
+496
+497
+498
+499
+500
+501
+502
+503
+504
+505
+506
+507
+508
+509
+510
+511
+512
+513
+514
+515
+516
+517
+518
+519
+520
+521
+522
+523
+524
+525
+526
+527
+528
+529
+530
+531
+532
+533
+534
+535
+536
+537
+538
+539
+540
+541
+542
+543
+544
+545
+546
+547
+548
+549
+550
+551
+552
+553
+554
+555
+556
+557
+558
+559
+560
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
+
+/*
+ *  Copyright (C) 2004-2008 Red Hat, Inc.
+ *  Copyright (C) 2012-2021 MATE Developers
+ *
+ *  Caja is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU General Public License as
+ *  published by the Free Software Foundation; either version 2 of the
+ *  License, or (at your option) any later version.
+ *
+ *  Caja is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  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
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ *  Authors: Bastien Nocera <hadess@hadess.net>
+ *
+ */
+
+#include "config.h"
+
+#include <glib.h>
+#include <glib/gi18n.h>
+#include <gio/gio.h>
+#include <gdk/gdk.h>
+#include <gtk/gtk.h>
+#include <libnotify/notify.h>
+#include <dbus/dbus-glib.h>
+#include <dbus/dbus-glib-lowlevel.h>
+#include <canberra-gtk.h>
+
+#include <string.h>
+
+#include "marshal.h"
+#include "obexpush.h"
+#include "user_share-common.h"
+#include "user_share-private.h"
+
+#define DBUS_TYPE_G_STRING_VARIANT_HASHTABLE (dbus_g_type_get_map ("GHashTable", G_TYPE_STRING, G_TYPE_STRING))
+
+#define GSETTINGS_SCHEMA "org.mate.FileSharing"
+
+static DBusGConnection *connection = NULL;<--- Shadowed declaration
+static DBusGProxy *manager_proxy = NULL;
+static DBusGProxy *server_proxy = NULL;
+static AcceptSetting accept_setting = -1;
+static gboolean show_notifications = FALSE;
+
+static GtkStatusIcon *statusicon = NULL;
+static guint num_notifications = 0;
+
+static void
+hide_statusicon (void)
+{
+	num_notifications--;
+	if (num_notifications == 0)
+		gtk_status_icon_set_visible (statusicon, FALSE);
+}
+
+static void
+on_close_notification (NotifyNotification *notification)
+{
+	hide_statusicon ();
+	g_object_unref (notification);
+}
+
+static void
+notification_launch_action_on_file_cb (NotifyNotification *notification,
+				       const char *action,
+				       const char *file_uri)
+{
+	GdkScreen *screen;
+	GAppLaunchContext *ctx;
+	GTimeVal val;
+
+	g_assert (action != NULL);
+
+	g_get_current_time (&val);
+
+	ctx = G_APP_LAUNCH_CONTEXT (gdk_app_launch_context_new ());
+	screen = gdk_screen_get_default ();
+	gdk_app_launch_context_set_screen (GDK_APP_LAUNCH_CONTEXT (ctx), screen);
+	gdk_app_launch_context_set_timestamp (GDK_APP_LAUNCH_CONTEXT (ctx), val.tv_sec);
+
+	/* We launch the file viewer for the file */
+	if (g_str_equal (action, "display") != FALSE) {
+		if (g_app_info_launch_default_for_uri (file_uri, ctx, NULL) == FALSE) {
+			g_warning ("Failed to launch the file viewer\n");
+		}
+	}
+
+	/* we open the Downloads folder */
+	if (g_str_equal (action, "reveal") != FALSE) {
+		GFile *file;
+		GFile *parent;
+		gchar *parent_uri;
+
+		file = g_file_new_for_uri (file_uri);
+		parent = g_file_get_parent (file);
+		parent_uri = g_file_get_uri (parent);
+		g_object_unref (file);
+		g_object_unref (parent);
+
+		if (!g_app_info_launch_default_for_uri (parent_uri, ctx, NULL)) {
+			g_warning ("Failed to launch the file manager\n");
+		}
+
+		g_free (parent_uri);
+	}
+
+	notify_notification_close (notification, NULL);
+	/* No need to call hide_statusicon(), closing the notification
+	 * will call the close callback */
+}
+
+static void
+show_notification (const char *filename)
+{
+	char *file_uri, *notification_text, *display, *mime_type;
+	NotifyNotification *notification;
+	ca_context *ctx;
+	GAppInfo *app;
+
+	file_uri = g_filename_to_uri (filename, NULL, NULL);
+	if (file_uri == NULL) {
+		g_warning ("Could not make a filename from '%s'", filename);
+		return;
+	}
+
+	display = g_filename_display_basename (filename);
+	/* Translators: %s is the name of the filename received */
+	notification_text = g_strdup_printf(_("You received \"%s\" via Bluetooth"), display);
+	g_free (display);
+	notification = notify_notification_new (_("You received a file"),
+								 notification_text,
+								 "dialog-information");
+
+	notify_notification_set_timeout (notification, NOTIFY_EXPIRES_DEFAULT);
+
+	mime_type = g_content_type_guess (filename, NULL, 0, NULL);
+	app = g_app_info_get_default_for_type (mime_type, FALSE);
+	if (app != NULL) {
+		g_object_unref (app);
+		notify_notification_add_action (notification, "display", _("Open File"),
+						(NotifyActionCallback) notification_launch_action_on_file_cb,
+						g_strdup (file_uri), (GFreeFunc) g_free);
+	}
+	notify_notification_add_action (notification, "reveal", _("Reveal File"),
+					(NotifyActionCallback) notification_launch_action_on_file_cb,
+					g_strdup (file_uri), (GFreeFunc) g_free);
+
+	g_free (file_uri);
+
+	g_signal_connect (G_OBJECT (notification), "closed", G_CALLBACK (on_close_notification), notification);
+
+	if (!notify_notification_show (notification, NULL)) {
+		g_warning ("failed to send notification\n");
+	}
+	g_free (notification_text);
+
+	/* Now we do the audio notification */
+	ctx = ca_gtk_context_get ();
+	ca_context_play (ctx, 0,
+			 CA_PROP_EVENT_ID, "complete-download",
+			 CA_PROP_EVENT_DESCRIPTION, _("File reception complete"),
+			 NULL);
+}
+
+static void
+show_icon (void)
+{
+	if (statusicon == NULL) {
+		statusicon = gtk_status_icon_new_from_icon_name ("mate-obex-server");
+	} else {
+		gtk_status_icon_set_visible (statusicon, TRUE);
+	}
+	num_notifications++;
+}
+
+static gboolean
+device_is_authorised (const char *bdaddr)
+{
+	DBusGConnection *connection;<--- Shadow variable
+	DBusGProxy *manager;
+	GError *error = NULL;
+	GPtrArray *adapters;
+	gboolean retval = FALSE;
+	guint i;
+
+	connection = dbus_g_bus_get (DBUS_BUS_SYSTEM, NULL);
+	if (connection == NULL)
+		return FALSE;
+
+	manager = dbus_g_proxy_new_for_name (connection, "org.bluez",
+					     "/", "org.bluez.Manager");
+	if (manager == NULL) {
+		dbus_g_connection_unref (connection);
+		return FALSE;
+	}
+
+	if (dbus_g_proxy_call (manager, "ListAdapters", &error, G_TYPE_INVALID, dbus_g_type_get_collection ("GPtrArray", DBUS_TYPE_G_OBJECT_PATH), &adapters, G_TYPE_INVALID) == FALSE) {
+		g_object_unref (manager);
+		dbus_g_connection_unref (connection);
+		return FALSE;
+	}
+
+	for (i = 0; i < adapters->len; i++) {
+		DBusGProxy *adapter, *device;
+		char *device_path;
+		GHashTable *props;
+
+		g_debug ("checking adapter %s", (gchar *) g_ptr_array_index (adapters, i));
+
+		adapter = dbus_g_proxy_new_for_name (connection, "org.bluez",
+						    g_ptr_array_index (adapters, i), "org.bluez.Adapter");
+
+		if (dbus_g_proxy_call (adapter, "FindDevice", NULL,
+				       G_TYPE_STRING, bdaddr, G_TYPE_INVALID,
+				       DBUS_TYPE_G_OBJECT_PATH, &device_path, G_TYPE_INVALID) == FALSE)
+		{
+			g_object_unref (adapter);
+			continue;
+		}
+
+		device = dbus_g_proxy_new_for_name (connection, "org.bluez", device_path, "org.bluez.Device");
+
+		if (dbus_g_proxy_call (device, "GetProperties", NULL,
+				       G_TYPE_INVALID, dbus_g_type_get_map ("GHashTable", G_TYPE_STRING, G_TYPE_VALUE),
+				       &props, G_TYPE_INVALID) != FALSE)
+		{
+			GValue *value;
+			gboolean bonded;
+
+			value = g_hash_table_lookup (props, "Paired");
+			bonded = g_value_get_boolean (value);
+			g_message ("%s is %s", bdaddr, bonded ? "bonded" : "not bonded");
+
+			if (bonded) {
+				g_hash_table_destroy (props);
+				g_object_unref (device);
+				g_object_unref (adapter);
+				retval = TRUE;
+				break;
+			}
+		}
+		g_object_unref(adapter);
+	}
+
+	g_ptr_array_free (adapters, TRUE);
+
+	g_object_unref(manager);
+	dbus_g_connection_unref(connection);
+
+	return retval;
+}
+
+static void
+transfer_started_cb (DBusGProxy *session,
+		     const char *filename,
+		     const char *local_path,
+		     guint64 size,
+		     gpointer user_data)
+{
+	GHashTable *dict;
+	DBusGProxy *server = (DBusGProxy *) user_data;
+	GError *error = NULL;
+	gboolean authorise;
+
+	g_message ("transfer started on %s", local_path);
+	g_object_set_data_full (G_OBJECT (session), "filename", g_strdup (local_path), (GDestroyNotify) g_free);
+
+	show_icon ();
+
+	/* First transfer of the session */
+	if (g_object_get_data (G_OBJECT (session), "bdaddr") == NULL) {
+		const char *bdaddr;
+
+		if (dbus_g_proxy_call (server, "GetServerSessionInfo", &error,
+				       DBUS_TYPE_G_OBJECT_PATH, dbus_g_proxy_get_path (session), G_TYPE_INVALID,
+				       DBUS_TYPE_G_STRING_VARIANT_HASHTABLE, &dict, G_TYPE_INVALID) == FALSE) {
+			g_printerr ("Getting Server session info failed: %s\n",
+				    error->message);
+			g_error_free (error);
+			return;
+		}
+
+		bdaddr = g_hash_table_lookup (dict, "BluetoothAddress");
+		g_message ("transfer started for device %s", bdaddr);
+
+		g_object_set_data_full (G_OBJECT (session), "bdaddr", g_strdup (bdaddr), (GDestroyNotify) g_free);
+		/* Initial accept method is undefined, we do that lower down */
+		g_object_set_data (G_OBJECT (session), "accept-method", GINT_TO_POINTER (-1));
+		g_hash_table_destroy (dict);
+	}
+
+	/* Accept method changed */
+	if (GPOINTER_TO_INT (g_object_get_data (G_OBJECT (session), "accept-method")) != accept_setting) {
+		const char *bdaddr;
+
+		bdaddr = g_object_get_data (G_OBJECT (session), "bdaddr");
+
+		if (bdaddr == NULL) {
+			g_warning ("Couldn't get the Bluetooth address for the device, rejecting the transfer");
+			authorise = FALSE;
+		} else if (accept_setting == ACCEPT_ALWAYS) {
+			authorise = TRUE;
+		} else if (accept_setting == ACCEPT_BONDED) {
+			authorise = device_is_authorised (bdaddr);
+		} else {
+			//FIXME implement
+			g_warning ("\"Ask\" authorisation method not implemented");
+			authorise = FALSE;
+		}
+		g_object_set_data (G_OBJECT (session), "authorise", GINT_TO_POINTER (authorise));
+	}
+
+	g_message ("accept_setting: %d", accept_setting);
+
+	authorise = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (session), "authorise"));
+	if (authorise != FALSE) {
+		if (dbus_g_proxy_call (session, "Accept", &error, G_TYPE_INVALID, G_TYPE_INVALID) == FALSE) {
+			g_printerr ("Failed to accept file transfer: %s\n", error->message);
+			g_error_free (error);
+			return;
+		}
+		g_message ("authorised transfer");
+	} else {
+		if (dbus_g_proxy_call (session, "Reject", &error, G_TYPE_INVALID, G_TYPE_INVALID) == FALSE) {
+			g_printerr ("Failed to reject file transfer: %s\n", error->message);
+			g_error_free (error);
+			return;
+		}
+		g_message ("rejected transfer");
+		g_object_set_data (G_OBJECT (session), "filename", NULL);
+	}
+}
+
+static void
+transfer_completed_cb (DBusGProxy *session,
+		       gpointer user_data)
+{
+	GSettings *settings;
+	gboolean display_notify;
+	const char *filename;
+
+	filename = (const char *) g_object_get_data (G_OBJECT (session), "filename");
+
+	g_message ("file finish transfer: %s", filename);
+
+	if (filename == NULL)
+		return;
+
+	settings = g_settings_new (GSETTINGS_SCHEMA);
+	display_notify = g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_OBEXPUSH_NOTIFY);
+	g_object_unref (settings);
+
+	if (display_notify) {
+		show_notification (filename);
+	} else {
+		hide_statusicon ();
+	}
+	g_object_set_data (G_OBJECT (session), "filename", NULL);
+}
+
+static void
+cancelled_cb (DBusGProxy *session,
+	      gpointer user_data)
+{
+	//FIXME implement properly, we never actually finished the transfer
+	g_message ("transfered was cancelled by the sender");
+	transfer_completed_cb (session, user_data);
+	hide_statusicon ();
+}
+
+static void
+error_occurred_cb (DBusGProxy *session,
+		   const char *error_name,
+		   const char *error_message,
+		   gpointer user_data)
+{
+	//FIXME implement properly
+	g_message ("transfer error occurred: %s", error_message);
+	transfer_completed_cb (session, user_data);
+}
+
+static void
+session_created_cb (DBusGProxy *server, const char *session_path, gpointer user_data)
+{
+	DBusGProxy *session;
+
+	session = dbus_g_proxy_new_for_name (connection,
+					     "org.openobex",
+					     session_path,
+					     "org.openobex.ServerSession");
+
+	dbus_g_proxy_add_signal (session, "TransferStarted",
+				 G_TYPE_STRING, G_TYPE_STRING, G_TYPE_UINT64, G_TYPE_INVALID);
+	dbus_g_proxy_connect_signal(session, "TransferStarted",
+				    G_CALLBACK (transfer_started_cb), server, NULL);
+	dbus_g_proxy_add_signal (session, "TransferCompleted",
+				 G_TYPE_INVALID, G_TYPE_INVALID);
+	dbus_g_proxy_connect_signal(session, "TransferCompleted",
+				    G_CALLBACK (transfer_completed_cb), server, NULL);
+	dbus_g_proxy_add_signal (session, "Cancelled",
+				 G_TYPE_INVALID, G_TYPE_INVALID);
+	dbus_g_proxy_connect_signal(session, "Cancelled",
+				    G_CALLBACK (cancelled_cb), server, NULL);
+	dbus_g_proxy_add_signal (session, "ErrorOccurred",
+				 G_TYPE_INVALID, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INVALID);
+	dbus_g_proxy_connect_signal(session, "ErrorOccurred",
+				    G_CALLBACK (error_occurred_cb), server, NULL);
+}
+
+void
+obexpush_up (void)
+{
+	GError *err = NULL;
+	char *download_dir, *server;
+
+	server = NULL;
+	if (manager_proxy == NULL) {
+		manager_proxy = dbus_g_proxy_new_for_name (connection,
+							   "org.openobex",
+							   "/org/openobex",
+							   "org.openobex.Manager");
+		if (dbus_g_proxy_call (manager_proxy, "CreateBluetoothServer",
+				       &err, G_TYPE_STRING, "00:00:00:00:00:00", G_TYPE_STRING, "opp", G_TYPE_BOOLEAN, FALSE, G_TYPE_INVALID,
+				       DBUS_TYPE_G_OBJECT_PATH, &server, G_TYPE_INVALID) == FALSE) {
+			g_printerr ("Creating Bluetooth ObexPush server failed: %s\n",
+				    err->message);
+			g_error_free (err);
+			g_object_unref (manager_proxy);
+			manager_proxy = NULL;
+			return;
+		}
+	}
+
+	download_dir = lookup_download_dir ();
+
+	if (server_proxy == NULL) {
+		server_proxy = dbus_g_proxy_new_for_name (connection,
+							   "org.openobex",
+							   server,
+							   "org.openobex.Server");
+		g_free (server);
+
+		dbus_g_proxy_add_signal (server_proxy, "SessionCreated",
+					 DBUS_TYPE_G_OBJECT_PATH, G_TYPE_INVALID);
+		dbus_g_proxy_connect_signal(server_proxy, "SessionCreated",
+					    G_CALLBACK (session_created_cb), NULL, NULL);
+	}
+
+	if (dbus_g_proxy_call (server_proxy, "Start", &err,
+			   G_TYPE_STRING, download_dir, G_TYPE_BOOLEAN, TRUE, G_TYPE_BOOLEAN, FALSE, G_TYPE_INVALID,
+			   G_TYPE_INVALID) == FALSE) {
+		if (g_error_matches (err, DBUS_GERROR, DBUS_GERROR_REMOTE_EXCEPTION) != FALSE &&
+		    dbus_g_error_has_name (err, "org.openobex.Error.Started") != FALSE) {
+		    	g_error_free (err);
+		    	g_message ("already started, ignoring error");
+		    	g_free (download_dir);
+		    	return;
+		}
+		g_printerr ("Starting Bluetooth ObexPush server failed: %s\n",
+			    err->message);
+		g_error_free (err);
+		g_free (download_dir);
+		g_object_unref (server_proxy);
+		server_proxy = NULL;
+		g_object_unref (manager_proxy);
+		manager_proxy = NULL;
+		return;
+	}
+
+	g_free (download_dir);
+}
+
+static void
+obexpush_stop (gboolean stop_manager)
+{
+	GError *err = NULL;
+
+	if (server_proxy == NULL)
+		return;
+
+	if (dbus_g_proxy_call (server_proxy, "Close", &err, G_TYPE_INVALID, G_TYPE_INVALID) == FALSE) {
+		if (g_error_matches (err, DBUS_GERROR, DBUS_GERROR_REMOTE_EXCEPTION) == FALSE ||
+		    dbus_g_error_has_name (err, "org.openobex.Error.NotStarted") == FALSE) {
+			g_printerr ("Stopping Bluetooth ObexPush server failed: %s\n",
+				    err->message);
+			g_error_free (err);
+			return;
+		}
+		g_error_free (err);
+	}
+
+	if (stop_manager != FALSE) {
+		g_object_unref (server_proxy);
+		server_proxy = NULL;
+		g_object_unref (manager_proxy);
+		manager_proxy = NULL;
+	}
+
+	//FIXME stop all the notifications
+}
+
+void
+obexpush_down (void)
+{
+	obexpush_stop (TRUE);
+}
+
+void
+obexpush_restart (void)
+{
+	obexpush_stop (FALSE);
+	obexpush_up ();
+}
+
+gboolean
+obexpush_init (void)
+{
+	GError *err = NULL;
+
+	connection = dbus_g_bus_get (DBUS_BUS_SESSION, &err);
+	if (connection == NULL) {
+		g_printerr ("Connecting to session bus failed: %s\n",
+			    err->message);
+		g_error_free (err);
+		return FALSE;
+	}
+
+	dbus_g_object_register_marshaller (marshal_VOID__STRING_STRING_UINT64,
+					   G_TYPE_NONE,
+					   G_TYPE_STRING, G_TYPE_STRING, G_TYPE_UINT64, G_TYPE_INVALID);
+
+	if (!notify_init("mate-user-share")) {
+		g_warning("Unable to initialize the notification system\n");
+        }
+
+	dbus_connection_set_exit_on_disconnect (dbus_g_connection_get_connection (connection), FALSE);
+
+	return TRUE;
+}
+
+void
+obexpush_set_accept_files_policy (AcceptSetting setting)
+{
+	accept_setting = setting;
+}
+
+void
+obexpush_set_notify (gboolean enabled)
+{
+	show_notifications = enabled;
+}
+
+ +
+ +
+ + diff --git a/2023-09-10-082921-9712-cppcheck@2d4aba56e7bf_master/4.html b/2023-09-10-082921-9712-cppcheck@2d4aba56e7bf_master/4.html new file mode 100644 index 0000000..7664cf7 --- /dev/null +++ b/2023-09-10-082921-9712-cppcheck@2d4aba56e7bf_master/4.html @@ -0,0 +1,833 @@ + + + + + + Cppcheck - HTML report - mate-user-share + + + + + +
+ + + +
+
  1
+  2
+  3
+  4
+  5
+  6
+  7
+  8
+  9
+ 10
+ 11
+ 12
+ 13
+ 14
+ 15
+ 16
+ 17
+ 18
+ 19
+ 20
+ 21
+ 22
+ 23
+ 24
+ 25
+ 26
+ 27
+ 28
+ 29
+ 30
+ 31
+ 32
+ 33
+ 34
+ 35
+ 36
+ 37
+ 38
+ 39
+ 40
+ 41
+ 42
+ 43
+ 44
+ 45
+ 46
+ 47
+ 48
+ 49
+ 50
+ 51
+ 52
+ 53
+ 54
+ 55
+ 56
+ 57
+ 58
+ 59
+ 60
+ 61
+ 62
+ 63
+ 64
+ 65
+ 66
+ 67
+ 68
+ 69
+ 70
+ 71
+ 72
+ 73
+ 74
+ 75
+ 76
+ 77
+ 78
+ 79
+ 80
+ 81
+ 82
+ 83
+ 84
+ 85
+ 86
+ 87
+ 88
+ 89
+ 90
+ 91
+ 92
+ 93
+ 94
+ 95
+ 96
+ 97
+ 98
+ 99
+100
+101
+102
+103
+104
+105
+106
+107
+108
+109
+110
+111
+112
+113
+114
+115
+116
+117
+118
+119
+120
+121
+122
+123
+124
+125
+126
+127
+128
+129
+130
+131
+132
+133
+134
+135
+136
+137
+138
+139
+140
+141
+142
+143
+144
+145
+146
+147
+148
+149
+150
+151
+152
+153
+154
+155
+156
+157
+158
+159
+160
+161
+162
+163
+164
+165
+166
+167
+168
+169
+170
+171
+172
+173
+174
+175
+176
+177
+178
+179
+180
+181
+182
+183
+184
+185
+186
+187
+188
+189
+190
+191
+192
+193
+194
+195
+196
+197
+198
+199
+200
+201
+202
+203
+204
+205
+206
+207
+208
+209
+210
+211
+212
+213
+214
+215
+216
+217
+218
+219
+220
+221
+222
+223
+224
+225
+226
+227
+228
+229
+230
+231
+232
+233
+234
+235
+236
+237
+238
+239
+240
+241
+242
+243
+244
+245
+246
+247
+248
+249
+250
+251
+252
+253
+254
+255
+256
+257
+258
+259
+260
+261
+262
+263
+264
+265
+266
+267
+268
+269
+270
+271
+272
+273
+274
+275
+276
+277
+278
+279
+280
+281
+282
+283
+284
+285
+286
+287
+288
+289
+290
+291
+292
/* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 8; tab-width: 8 -*-
+ *
+ * Copyright (C) 2003 Novell, Inc.
+ * Copyright (C) 2003-2004 Red Hat, Inc.
+ * Copyright (C) 2005 William Jon McCann <mccann@jhu.edu>
+ * Copyright (C) 2012-2021 MATE Developers
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * 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 Foundation, Inc., 51 Franklin St, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ *
+ */
+
+#include "config.h"
+
+#include <stdlib.h>
+#include <string.h>
+#include <glib/gi18n-lib.h>
+#include <gtk/gtk.h>
+#include <libcaja-extension/caja-menu-provider.h>
+#include <libcaja-extension/caja-location-widget-provider.h>
+
+#ifdef HAVE_BLUETOOTH
+#include <bluetooth-client.h>
+#endif
+
+#include "caja-share-bar.h"
+#include "user_share-common.h"
+
+#define CAJA_TYPE_USER_SHARE  (caja_user_share_get_type ())
+#define CAJA_USER_SHARE(o)    (G_TYPE_CHECK_INSTANCE_CAST ((o), CAJA_TYPE_USER_SHARE, CajaUserShare))
+#define CAJA_IS_USER_SHARE(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), CAJA_TYPE_USER_SHARE))
+
+typedef struct
+{
+        GObject              parent_slot;
+} CajaUserShare;
+
+typedef struct
+{
+        GObjectClass parent_slot;
+} CajaUserShareClass;
+
+static GType caja_user_share_get_type      (void);
+static void  caja_user_share_register_type (GTypeModule *module);
+
+static void
+launch_process (char **argv, GtkWindow *parent)
+{
+        GError *error;
+        GtkWidget *dialog;
+
+        error = NULL;
+        if (!g_spawn_async (NULL,
+                            argv, NULL,
+                            0,
+                            NULL, NULL,
+                            NULL,
+                            &error)) {
+
+
+                dialog = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL, GTK_MESSAGE_WARNING,
+						 GTK_BUTTONS_OK, _("Unable to launch the Personal File Sharing preferences"));
+
+                gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog), "%s", error->message);
+
+                gtk_dialog_run (GTK_DIALOG (dialog));
+                gtk_widget_destroy (dialog);
+
+                g_error_free (error);
+        }
+}
+
+static void
+launch_prefs_on_window (GtkWindow *window)
+{
+        char *argv [2];
+
+        argv [0] = g_build_filename (BINDIR, "mate-file-share-properties", NULL);
+        argv [1] = NULL;
+
+        launch_process (argv, window);
+
+        g_free (argv [0]);
+}
+
+static void
+bar_response_cb (CajaShareBar *bar,
+                 gint response,
+                 gpointer         data)
+{
+        if (response == CAJA_SHARE_BAR_RESPONSE_PREFERENCES) {
+                launch_prefs_on_window (GTK_WINDOW (data));
+        }
+}
+
+#ifdef HAVE_BLUETOOTH
+static void
+downloads_bar_set_from_bluetooth_status (GtkWidget *bar)
+{
+	BluetoothClient *client;
+	gboolean bt_powered;
+
+	client = g_object_get_data (G_OBJECT (bar), "bluetooth-client");
+	g_object_get (G_OBJECT (client),
+		      "default-adapter-powered", &bt_powered,
+		      NULL);
+	gtk_widget_set_visible (bar, bt_powered);
+}
+
+static void
+default_adapter_powered_cb (GObject    *gobject,
+			    GParamSpec *pspec,
+			    GtkWidget  *bar)
+{
+	downloads_bar_set_from_bluetooth_status (bar);
+}
+#endif /* HAVE_BLUETOOTH */
+
+static GtkWidget *
+caja_user_share_get_location_widget (CajaLocationWidgetProvider *iface,
+                                         const char                     *uri,
+                                         GtkWidget                      *window)
+{
+	GFile             *file;
+	GtkWidget         *bar;
+	guint              i;
+	gboolean           enable = FALSE;
+	GFile             *home;
+#ifdef HAVE_BLUETOOTH
+	const GUserDirectory special_dirs[] = { G_USER_DIRECTORY_PUBLIC_SHARE, G_USER_DIRECTORY_DOWNLOAD };
+
+	gboolean is_dir[] = { FALSE, FALSE };
+#else
+	const GUserDirectory special_dirs[] = { G_USER_DIRECTORY_PUBLIC_SHARE };
+
+	gboolean is_dir[] = { FALSE };
+#endif /* HAVE_BLUETOOTH */
+	file = g_file_new_for_uri (uri);
+	home = g_file_new_for_path (g_get_home_dir ());
+
+	/* We don't show anything in $HOME */
+	if (g_file_equal (home, file)) {
+		g_object_unref (home);
+		g_object_unref (file);
+		return NULL;
+	}
+
+	g_object_unref (home);
+
+	for (i = 0; i < G_N_ELEMENTS (special_dirs); i++) {
+		GFile *dir;
+		dir = lookup_dir_with_fallback (special_dirs[i]);
+		if (g_file_equal (dir, file)) {
+			enable = TRUE;
+			is_dir[i] = TRUE;
+		}
+		g_object_unref (dir);
+	}
+
+	g_object_unref (file);
+
+	if (enable == FALSE)
+		return NULL;
+
+	if (is_dir[0] != FALSE) {
+#ifdef HAVE_BLUETOOTH
+		if (is_dir[1] != FALSE) {
+			bar = caja_share_bar_new (_("May be used to share or receive files"));
+		} else {
+			bar = caja_share_bar_new (_("May be shared over the network or Bluetooth"));
+		}
+#else
+		bar = caja_share_bar_new (_("May be shared over the network"));
+#endif /* HAVE_BLUETOOTH */
+	} else {
+#ifdef HAVE_BLUETOOTH
+		BluetoothClient *client;
+
+		bar = caja_share_bar_new (_("May be used to receive files over Bluetooth"));
+
+		gtk_widget_set_no_show_all (bar, TRUE);
+		client = bluetooth_client_new ();
+		g_object_set_data_full (G_OBJECT (bar), "bluetooth-client", client, g_object_unref);
+		g_signal_connect (G_OBJECT (client), "notify::default-adapter-powered",
+				  G_CALLBACK (default_adapter_powered_cb), bar);
+		downloads_bar_set_from_bluetooth_status (bar);
+#endif /* HAVE_BLUETOOTH */
+	}
+
+	g_signal_connect (bar, "response",
+			  G_CALLBACK (bar_response_cb),
+			  window);
+
+	gtk_widget_show_all (bar);
+
+	return bar;
+}
+
+static void
+caja_user_share_location_widget_provider_iface_init (CajaLocationWidgetProviderIface *iface)
+{
+        iface->get_widget = caja_user_share_get_location_widget;
+}
+
+static void
+caja_user_share_instance_init (CajaUserShare *share)
+{
+
+}
+
+static void
+caja_user_share_class_init (CajaUserShareClass *klass)
+{
+
+}
+
+static GType share_type = 0;
+
+static GType
+caja_user_share_get_type (void)
+{
+        return share_type;
+}
+
+static void
+caja_user_share_register_type (GTypeModule *module)
+{
+        static const GTypeInfo info = {
+                sizeof (CajaUserShareClass),
+                (GBaseInitFunc) NULL,
+                (GBaseFinalizeFunc) NULL,
+                (GClassInitFunc) caja_user_share_class_init,
+                NULL,
+                NULL,
+                sizeof (CajaUserShare),
+                0,
+                (GInstanceInitFunc) caja_user_share_instance_init,
+        };
+
+        static const GInterfaceInfo location_widget_provider_iface_info = {
+                (GInterfaceInitFunc) caja_user_share_location_widget_provider_iface_init,
+                NULL,
+                NULL
+        };
+
+        share_type = g_type_module_register_type (module,
+                                                 G_TYPE_OBJECT,
+                                                 "CajaUserShare",
+                                                 &info, 0);
+
+        g_type_module_add_interface (module,
+                                     share_type,
+                                     CAJA_TYPE_LOCATION_WIDGET_PROVIDER,
+                                     &location_widget_provider_iface_info);
+}
+
+void
+caja_module_initialize (GTypeModule *module)
+{
+        caja_user_share_register_type (module);
+        bindtextdomain (GETTEXT_PACKAGE, MATELOCALEDIR);
+        bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
+}
+
+void
+caja_module_shutdown (void)
+{
+}
+
+void
+caja_module_list_types (const GType **types,
+                            int          *num_types)
+{
+        static GType type_list [1];
+
+        type_list[0] = CAJA_TYPE_USER_SHARE;
+
+        *types = type_list;
+        *num_types = 1;
+}
+
+ +
+ +
+ + diff --git a/2023-09-10-082921-9712-cppcheck@2d4aba56e7bf_master/5.html b/2023-09-10-082921-9712-cppcheck@2d4aba56e7bf_master/5.html new file mode 100644 index 0000000..f850c86 --- /dev/null +++ b/2023-09-10-082921-9712-cppcheck@2d4aba56e7bf_master/5.html @@ -0,0 +1,1251 @@ + + + + + + Cppcheck - HTML report - mate-user-share + + + + + +
+ + + +
+
  1
+  2
+  3
+  4
+  5
+  6
+  7
+  8
+  9
+ 10
+ 11
+ 12
+ 13
+ 14
+ 15
+ 16
+ 17
+ 18
+ 19
+ 20
+ 21
+ 22
+ 23
+ 24
+ 25
+ 26
+ 27
+ 28
+ 29
+ 30
+ 31
+ 32
+ 33
+ 34
+ 35
+ 36
+ 37
+ 38
+ 39
+ 40
+ 41
+ 42
+ 43
+ 44
+ 45
+ 46
+ 47
+ 48
+ 49
+ 50
+ 51
+ 52
+ 53
+ 54
+ 55
+ 56
+ 57
+ 58
+ 59
+ 60
+ 61
+ 62
+ 63
+ 64
+ 65
+ 66
+ 67
+ 68
+ 69
+ 70
+ 71
+ 72
+ 73
+ 74
+ 75
+ 76
+ 77
+ 78
+ 79
+ 80
+ 81
+ 82
+ 83
+ 84
+ 85
+ 86
+ 87
+ 88
+ 89
+ 90
+ 91
+ 92
+ 93
+ 94
+ 95
+ 96
+ 97
+ 98
+ 99
+100
+101
+102
+103
+104
+105
+106
+107
+108
+109
+110
+111
+112
+113
+114
+115
+116
+117
+118
+119
+120
+121
+122
+123
+124
+125
+126
+127
+128
+129
+130
+131
+132
+133
+134
+135
+136
+137
+138
+139
+140
+141
+142
+143
+144
+145
+146
+147
+148
+149
+150
+151
+152
+153
+154
+155
+156
+157
+158
+159
+160
+161
+162
+163
+164
+165
+166
+167
+168
+169
+170
+171
+172
+173
+174
+175
+176
+177
+178
+179
+180
+181
+182
+183
+184
+185
+186
+187
+188
+189
+190
+191
+192
+193
+194
+195
+196
+197
+198
+199
+200
+201
+202
+203
+204
+205
+206
+207
+208
+209
+210
+211
+212
+213
+214
+215
+216
+217
+218
+219
+220
+221
+222
+223
+224
+225
+226
+227
+228
+229
+230
+231
+232
+233
+234
+235
+236
+237
+238
+239
+240
+241
+242
+243
+244
+245
+246
+247
+248
+249
+250
+251
+252
+253
+254
+255
+256
+257
+258
+259
+260
+261
+262
+263
+264
+265
+266
+267
+268
+269
+270
+271
+272
+273
+274
+275
+276
+277
+278
+279
+280
+281
+282
+283
+284
+285
+286
+287
+288
+289
+290
+291
+292
+293
+294
+295
+296
+297
+298
+299
+300
+301
+302
+303
+304
+305
+306
+307
+308
+309
+310
+311
+312
+313
+314
+315
+316
+317
+318
+319
+320
+321
+322
+323
+324
+325
+326
+327
+328
+329
+330
+331
+332
+333
+334
+335
+336
+337
+338
+339
+340
+341
+342
+343
+344
+345
+346
+347
+348
+349
+350
+351
+352
+353
+354
+355
+356
+357
+358
+359
+360
+361
+362
+363
+364
+365
+366
+367
+368
+369
+370
+371
+372
+373
+374
+375
+376
+377
+378
+379
+380
+381
+382
+383
+384
+385
+386
+387
+388
+389
+390
+391
+392
+393
+394
+395
+396
+397
+398
+399
+400
+401
+402
+403
+404
+405
+406
+407
+408
+409
+410
+411
+412
+413
+414
+415
+416
+417
+418
+419
+420
+421
+422
+423
+424
+425
+426
+427
+428
+429
+430
+431
+432
+433
+434
+435
+436
+437
+438
+439
+440
+441
+442
+443
+444
+445
+446
+447
+448
+449
+450
+451
+452
+453
+454
+455
+456
+457
+458
+459
+460
+461
+462
+463
+464
+465
+466
+467
+468
+469
+470
+471
+472
+473
+474
+475
+476
+477
+478
+479
+480
+481
+482
+483
+484
+485
+486
+487
+488
+489
+490
+491
+492
+493
+494
+495
+496
+497
+498
+499
+500
+501
+502
+503
+504
+505
+506
+507
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
+
+/*
+ *  Copyright (C) 2004-2008 Red Hat, Inc.
+ *  Copyright (C) 2012-2021 MATE Developers
+ *
+ *  Caja is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU General Public License as
+ *  published by the Free Software Foundation; either version 2 of the
+ *  License, or (at your option) any later version.
+ *
+ *  Caja is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  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
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ *  Authors: Alexander Larsson <alexl@redhat.com>
+ *
+ */
+
+#include "config.h"
+
+#include <gdk/gdkx.h>
+#include <gtk/gtk.h>
+#include <glib/gi18n.h>
+#include <glib/gstdio.h>
+#include <gio/gio.h>
+#include <X11/Xlib.h>
+
+#include "user_share-private.h"
+#include "user_share-common.h"
+#include "http.h"
+
+#ifdef HAVE_BLUETOOTH
+#include <bluetooth-client.h>
+
+#include "obexftp.h"
+#include "obexpush.h"
+
+#endif /* HAVE_BLUETOOTH */
+
+#include <gio/gio.h>
+
+#include <stdarg.h>
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <signal.h>
+#include <unistd.h>
+
+static guint disabled_timeout_tag = 0;
+static GSettings* settings;<--- Shadowed declaration<--- Shadowed declaration<--- Shadowed declaration
+
+#define GSETTINGS_SCHEMA "org.mate.FileSharing"
+#define GSETTINGS_KEY_FILE_SHARING_ENABLED "enabled"
+#define GSETTINGS_KEY_FILE_SHARING_REQUIRE_PASSWORD "require-password"
+
+#ifdef HAVE_BLUETOOTH
+/* MATE Session */
+#define MATE_SESSION_DBUS_NAME      "org.gnome.SessionManager"
+#define MATE_SESSION_DBUS_OBJECT    "/org/gnome/SessionManager"
+#define MATE_SESSION_DBUS_INTERFACE "org.gnome.SessionManager"
+
+static GDBusProxy *session_proxy = NULL;
+static gboolean has_console = TRUE;
+
+static BluetoothClient *client = NULL;
+static gboolean bluetoothd_enabled = FALSE;
+
+#define OBEX_ENABLED (bluetoothd_enabled && has_console)
+
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_ENABLED "bluetooth-enabled"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_ALLOW_WRITE "bluetooth-allow-write"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_REQUIRE_PAIRING "bluetooth-require-pairing"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED "bluetooth-obexpush-enabled"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_ACCEPT_FILES "bluetooth-accept-files"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_NOTIFY "bluetooth-notify"
+
+
+static void
+obex_services_start (void)
+{
+	GSettings *settings;<--- Shadow variable
+
+	if (bluetoothd_enabled == FALSE ||
+	    has_console == FALSE)
+	    	return;
+
+	settings = g_settings_new(GSETTINGS_SCHEMA);
+
+	if (g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED) == TRUE) {
+	    obexpush_up ();
+	}
+	if (g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_ENABLED) == TRUE) {
+	    obexftp_up ();
+	}
+
+	g_object_unref (client);
+}
+
+static void
+obex_services_shutdown (void)
+{
+	obexpush_down ();
+	obexftp_down ();
+}
+
+static void
+session_properties_changed_cb (GDBusProxy      *session,
+			       GVariant        *changed,
+			       char           **invalidated,
+			       gpointer         user_data)
+{
+	GVariant *v;
+
+	v = g_variant_lookup_value (changed, "SessionIsActive", G_VARIANT_TYPE_BOOLEAN);
+	if (v) {
+		has_console = g_variant_get_boolean (v);
+		g_debug ("Received session is active change: now %s", has_console ? "active" : "inactive");
+
+		if (has_console)
+			obex_services_start ();
+		else
+			obex_services_shutdown ();
+
+		g_variant_unref (v);
+	}
+}
+
+static gboolean
+is_session_active (void)
+{
+	GVariant *variant;
+	gboolean is_session_active = FALSE;
+
+	variant = g_dbus_proxy_get_cached_property (session_proxy,
+						    "SessionIsActive");
+	if (variant) {
+		is_session_active = g_variant_get_boolean (variant);
+		g_variant_unref (variant);
+ 	}
+
+	return is_session_active;
+}
+
+static void
+session_init (void)
+{
+	GError *error = NULL;
+
+	session_proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION,
+						       G_DBUS_PROXY_FLAGS_NONE,
+						       NULL,
+						       MATE_SESSION_DBUS_NAME,
+						       MATE_SESSION_DBUS_OBJECT,
+						       MATE_SESSION_DBUS_INTERFACE,
+						       NULL,
+						       &error);
+	if (session_proxy == NULL) {
+		g_warning ("Failed to get session proxy: %s", error->message);
+		g_error_free (error);
+		return;
+	}
+	g_signal_connect (session_proxy, "g-properties-changed",
+			  G_CALLBACK (session_properties_changed_cb),
+			  NULL);
+	has_console = is_session_active ();
+}
+
+static void
+default_adapter_changed (GObject    *gobject,<--- Parameter 'gobject' can be declared as pointer to const
+			 GParamSpec *pspec,
+			 gpointer    user_data)
+{
+	char *adapter;
+	gboolean adapter_powered;
+
+	g_object_get (G_OBJECT (client),
+		      "default-adapter", &adapter,
+		      "default-adapter-powered", &adapter_powered,
+		      NULL);
+	if (adapter != NULL && *adapter != '\0') {
+		bluetoothd_enabled = adapter_powered;
+	} else {
+		bluetoothd_enabled = FALSE;
+	}
+
+	/* Were we called as init, or as a callback */
+	if (gobject != NULL) {
+		if (bluetoothd_enabled != FALSE)
+			obex_services_start ();
+		else
+			obex_services_shutdown ();
+	}
+}
+
+static void
+bluez_init (void)
+{
+	client = bluetooth_client_new ();
+	default_adapter_changed (NULL, NULL, NULL);
+	g_signal_connect (G_OBJECT (client), "notify::default-adapter",
+			  G_CALLBACK (default_adapter_changed), NULL);
+	g_signal_connect (G_OBJECT (client), "notify::default-adapter-powered",
+			  G_CALLBACK (default_adapter_changed), NULL);
+}
+#endif /* HAVE_BLUETOOTH */
+
+static gboolean
+file_sharing_enabled (void)
+{
+	gboolean enabled = TRUE;
+	settings = g_settings_new (GSETTINGS_SCHEMA);
+
+#ifdef HAVE_BLUETOOTH
+	if (g_settings_get_boolean (settings, FILE_SHARING_ENABLED) == FALSE &&
+	    g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_ENABLED) == FALSE &&
+	    g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED) == FALSE)
+#else /* HAVE_BLUETOOTH */
+	if (g_settings_get_boolean (settings, FILE_SHARING_ENABLED) == FALSE)
+#endif /* HAVE_BLUETOOTH */
+		enabled = FALSE;
+
+	g_object_unref (settings);
+
+	return enabled;
+}
+
+static void
+migrate_old_configuration (void)
+{
+	const char *old_config_dir;
+	const char *new_config_dir;
+
+	old_config_dir = g_build_filename (g_get_home_dir (), ".mate2", "user-share", NULL);
+	new_config_dir = g_build_filename (g_get_user_config_dir (), "user-share", NULL);
+	if (g_file_test (old_config_dir, G_FILE_TEST_IS_DIR))
+		g_rename (old_config_dir, new_config_dir);
+
+}
+
+static void
+require_password_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	/* Need to restart to get new password setting */
+	if (http_get_pid () != 0) {
+		http_down ();
+		http_up ();
+	}
+}
+
+/* File sharing was disabled for some time, exit now */
+/* If we re-enable it in the ui, this will be restarted anyway */
+static gboolean
+disabled_timeout_callback (gpointer user_data)
+{
+	GSettings *settings = (GSettings *) user_data;<--- Shadow variable
+	http_down ();
+
+#ifdef HAVE_BLUETOOTH
+	if (g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_ENABLED) == FALSE &&
+	    g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED) == FALSE)
+		_exit (0);
+#else /* HAVE_BLUETOOTH */
+	if (g_settings_get_boolean (settings, FILE_SHARING_ENABLED) == FALSE)
+		_exit (0);
+#endif /* HAVE_BLUETOOTH */
+	return FALSE;
+}
+
+static void
+file_sharing_enabled_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	gboolean enabled;
+
+	if (disabled_timeout_tag != 0) {
+		g_source_remove (disabled_timeout_tag);
+		disabled_timeout_tag = 0;
+	}
+
+	enabled = g_settings_get_boolean (settings,
+					 FILE_SHARING_ENABLED);
+	if (enabled) {
+		if (http_get_pid () == 0) {
+			http_up ();
+		}
+	} else {
+		http_down ();
+		disabled_timeout_tag = g_timeout_add_seconds (3,
+							      (GSourceFunc)disabled_timeout_callback,
+							      settings);
+	}
+}
+
+#ifdef HAVE_BLUETOOTH
+static void
+file_sharing_bluetooth_allow_write_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	if (g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_ENABLED) != FALSE)
+		obexftp_restart ();
+}
+
+static void
+file_sharing_bluetooth_require_pairing_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	if (g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_ENABLED) != FALSE) {
+		/* We need to fully reset the session,
+		 * otherwise the new setting isn't taken into account */
+		obexftp_down ();
+		obexftp_up ();
+	}
+}
+
+static void
+file_sharing_bluetooth_enabled_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	if (g_settings_get_boolean (settings,
+				   FILE_SHARING_BLUETOOTH_ENABLED) == FALSE) {
+		obexftp_down ();
+		if (g_settings_get_boolean (settings, FILE_SHARING_ENABLED) == FALSE &&
+		    g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED) == FALSE) {
+			_exit (0);
+		}
+	} else if (OBEX_ENABLED) {
+		obexftp_up ();
+	}
+}
+
+static void
+file_sharing_bluetooth_obexpush_enabled_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	if (g_settings_get_boolean (settings,
+				   FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED) == FALSE) {
+		obexpush_down ();
+		if (g_settings_get_boolean (settings, FILE_SHARING_ENABLED) == FALSE &&
+		    g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_ENABLED) == FALSE) {
+			_exit (0);
+		}
+	} else if (OBEX_ENABLED) {
+		obexpush_up ();
+	}
+}
+
+static void
+file_sharing_bluetooth_obexpush_accept_files_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	AcceptSetting setting;
+	char *str;
+
+	str = g_settings_get_string (settings, FILE_SHARING_BLUETOOTH_OBEXPUSH_ACCEPT_FILES);
+	setting = accept_setting_from_string (str);
+	g_free (str);
+
+	obexpush_set_accept_files_policy (setting);
+}
+
+static void
+file_sharing_bluetooth_obexpush_notify_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	obexpush_set_notify (g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_OBEXPUSH_NOTIFY));
+}
+#endif /* HAVE_BLUETOOTH */
+
+static RETSIGTYPE
+cleanup_handler (int sig)
+{
+	http_down ();
+#ifdef HAVE_BLUETOOTH
+	obexftp_down ();
+	obexpush_down ();
+#endif /* HAVE_BLUETOOTH */
+	_exit (2);
+}
+
+static int
+x_io_error_handler (Display *xdisplay)
+{
+	http_down ();
+#ifdef HAVE_BLUETOOTH
+	obexftp_down ();
+#endif /* HAVE_BLUETOOTH */
+	_exit (2);
+}
+
+int
+main (int argc, char **argv)
+{
+	GSettings *settings;<--- Shadow variable
+	Display *xdisplay;
+	G_GNUC_UNUSED int x_fd;
+	Window selection_owner;
+	Atom xatom;
+
+	bindtextdomain (GETTEXT_PACKAGE, MATELOCALEDIR);
+	bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
+	textdomain (GETTEXT_PACKAGE);
+
+	gtk_init (&argc, &argv);
+
+	if (g_strcmp0 (g_get_real_name (), "root") == 0) {
+		g_warning ("mate-user-share cannot be started as root for security reasons.");
+		return 1;
+	}
+
+	signal (SIGPIPE, SIG_IGN);
+	signal (SIGINT, cleanup_handler);
+	signal (SIGHUP, cleanup_handler);
+	signal (SIGTERM, cleanup_handler);
+
+	xdisplay = GDK_DISPLAY_XDISPLAY (gdk_display_get_default ());
+	if (xdisplay == NULL) {
+		g_warning ("Can't open display");
+		return 1;
+	}
+
+	xatom = XInternAtom (xdisplay, "_MATE_USER_SHARE", FALSE);
+	selection_owner = XGetSelectionOwner (xdisplay, xatom);
+
+	if (selection_owner != None) {
+		/* There is an owner already, quit */
+		return 1;
+	}
+
+	selection_owner = XCreateSimpleWindow (xdisplay,
+					       RootWindow (xdisplay, 0),
+					       0, 0, 1, 1,
+					       0, 0, 0);
+	XSetSelectionOwner (xdisplay, xatom, selection_owner, CurrentTime);
+
+	if (XGetSelectionOwner (xdisplay, xatom) != selection_owner) {
+		/* Didn't get the selection */
+		return 1;
+	}
+
+	migrate_old_configuration ();
+
+	if (!file_sharing_enabled ())
+		return 1;
+
+	settings = g_settings_new (GSETTINGS_SCHEMA);
+
+	x_fd = ConnectionNumber (xdisplay);
+	XSetIOErrorHandler (x_io_error_handler);
+
+	if (http_init () == FALSE)
+		return 1;
+#ifdef HAVE_BLUETOOTH
+	if (obexftp_init () == FALSE)
+		return 1;
+	if (obexpush_init () == FALSE)
+		return 1;
+#endif /* HAVE_BLUETOOTH */
+
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_ENABLED,
+			     G_CALLBACK (file_sharing_enabled_changed), NULL);
+
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_REQUIRE_PASSWORD,
+			     G_CALLBACK (require_password_changed), NULL);
+
+#ifdef HAVE_BLUETOOTH
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_ENABLED,
+			     G_CALLBACK (file_sharing_bluetooth_enabled_changed), NULL);
+
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_ALLOW_WRITE,
+			     G_CALLBACK (file_sharing_bluetooth_allow_write_changed), NULL);
+
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_REQUIRE_PAIRING,
+			     G_CALLBACK (file_sharing_bluetooth_require_pairing_changed), NULL);
+
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED,
+			     G_CALLBACK (file_sharing_bluetooth_obexpush_enabled_changed), NULL);
+
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_ACCEPT_FILES,
+			     G_CALLBACK (file_sharing_bluetooth_obexpush_accept_files_changed), NULL);
+
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_NOTIFY,
+			     G_CALLBACK (file_sharing_bluetooth_obexpush_notify_changed), NULL);
+
+	bluez_init ();
+	session_init ();
+#endif /* HAVE_BLUETOOTH */
+
+	/* Initial setting */
+	file_sharing_enabled_changed (settings, NULL, NULL);
+#ifdef HAVE_BLUETOOTH
+	file_sharing_bluetooth_enabled_changed (settings, NULL, NULL);
+	file_sharing_bluetooth_obexpush_accept_files_changed (settings, NULL, NULL);
+	file_sharing_bluetooth_obexpush_notify_changed (settings, NULL, NULL);
+	file_sharing_bluetooth_obexpush_enabled_changed (settings, NULL, NULL);
+#endif /* HAVE_BLUETOOTH */
+
+	gtk_main ();
+
+	return 0;
+}
+
+ +
+ +
+ + diff --git a/2023-09-10-082921-9712-cppcheck@2d4aba56e7bf_master/index.html b/2023-09-10-082921-9712-cppcheck@2d4aba56e7bf_master/index.html new file mode 100644 index 0000000..e87e43e --- /dev/null +++ b/2023-09-10-082921-9712-cppcheck@2d4aba56e7bf_master/index.html @@ -0,0 +1,231 @@ + + + + + + Cppcheck - HTML report - mate-user-share + + + + + +
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
LineIdCWESeverityMessage
missingIncludeinformationCppcheck cannot find all the include files (use --check-config for details)
src/caja-share-bar.c
41unknownMacroerrorThere is an unknown macro here somewhere. Configuration is required. If G_DEFINE_TYPE_WITH_PRIVATE is a macro then please configure it.
src/file-share-properties.c
83variableScope398styleThe scope of the variable 'password' can be reduced.
98shadowVariable398styleLocal variable 'settings' shadows outer variable
106unusedVariable563styleUnused variable: accept_setting
250shadowVariable398styleLocal variable 'settings' shadows outer variable
274shadowVariable398styleLocal variable 'settings' shadows outer variable
295shadowVariable398styleLocal variable 'settings' shadows outer variable
324shadowVariable398styleLocal variable 'settings' shadows outer variable
341shadowVariable398styleLocal variable 'settings' shadows outer variable
358shadowVariable398styleLocal variable 'settings' shadows outer variable
378shadowVariable398styleLocal variable 'settings' shadows outer variable
394shadowVariable398styleLocal variable 'settings' shadows outer variable
458shadowVariable398styleLocal variable 'settings' shadows outer variable
621variableScope398styleThe scope of the variable 'window' can be reduced.
src/http.c
115variableScope398styleThe scope of the variable 'host_name' can be reduced.
src/obexpush.c
188shadowVariable398styleLocal variable 'connection' shadows outer variable
src/share-extension.c
62variableScope398styleThe scope of the variable 'dialog' can be reduced.
src/user_share.c
87shadowVariable398styleLocal variable 'settings' shadows outer variable
175constParameter398styleParameter 'gobject' can be declared as pointer to const
261shadowVariable398styleLocal variable 'settings' shadows outer variable
392shadowVariable398styleLocal variable 'settings' shadows outer variable
+
+ +
+ + diff --git a/2023-09-10-082921-9712-cppcheck@2d4aba56e7bf_master/stats.html b/2023-09-10-082921-9712-cppcheck@2d4aba56e7bf_master/stats.html new file mode 100644 index 0000000..9c87915 --- /dev/null +++ b/2023-09-10-082921-9712-cppcheck@2d4aba56e7bf_master/stats.html @@ -0,0 +1,174 @@ + + + + + + Cppcheck - HTML report - mate-user-share + + + + + +
+ + + +
+

Top 10 files for error severity, total findings: 1
+   1  src/caja-share-bar.c
+

+

Top 10 files for style severity, total findings: 20
+   13  src/file-share-properties.c
+   4   src/user_share.c
+   1   src/share-extension.c
+   1   src/obexpush.c
+   1   src/http.c
+

+ +
+ +
+ + diff --git a/2023-09-10-082921-9712-cppcheck@2d4aba56e7bf_master/style.css b/2023-09-10-082921-9712-cppcheck@2d4aba56e7bf_master/style.css new file mode 100644 index 0000000..3897bfa --- /dev/null +++ b/2023-09-10-082921-9712-cppcheck@2d4aba56e7bf_master/style.css @@ -0,0 +1,177 @@ + +body { + font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif; + font-size: 13px; + line-height: 1.5; + height: 100%; + margin: 0; +} + +#wrapper { + position: fixed; + height: 100vh; + width: 100vw; + display: grid; + grid-template-rows: fit-content(8rem) auto fit-content(8rem); + grid-template-columns: fit-content(25%) 1fr; + grid-template-areas: + "header header" + "menu content" + "footer footer"; +} + +h1 { + margin: 0 0 8px -2px; + font-size: 175%; +} + +.header { + padding: 0 0 5px 15px; + grid-area: header; + border-bottom: thin solid #aaa; +} + +.footer { + grid-area: footer; + border-top: thin solid #aaa; + font-size: 85%; + +} + +.footer > p { + margin: 4px; +} + +#menu, +#menu_index { + grid-area: menu; + text-align: left; + overflow: auto; + padding: 0 23px 15px 15px; + border-right: thin solid #aaa; + min-width: 200px; +} + +#menu > a { + display: block; + margin-left: 10px; + font-size: 12px; +} + +#content, +#content_index { + grid-area: content; + padding: 0px 5px 15px 15px; + overflow: auto; +} + +label { + white-space: nowrap; +} + +label.checkBtn.disabled { + color: #606060; + background: #e0e0e0; + font-style: italic; +} + +label.checkBtn, input[type="text"] { + border: 1px solid grey; + border-radius: 4px; + box-shadow: 1px 1px inset; + padding: 1px 5px; +} + +label.checkBtn { + white-space: nowrap; + background: #ccddff; +} + +label.unchecked { + background: #eff8ff; + box-shadow: 1px 1px 1px; +} + +label.checkBtn:hover, label.unchecked:hover{ + box-shadow: 0 0 2px; +} + +label.disabled:hover { + box-shadow: 1px 1px inset; +} + +label.checkBtn > input { + display:none; +} + +.summaryTable { + width: 100%; +} + +table.summaryTable td { padding: 0 5px 0 5px; } + +.statHeader, .severityHeader { + font-weight: bold; +} + +.warning { + background-color: #ffffa7; +} + +.error { + background-color: #ffb7b7; +} + +.error2 { + background-color: #faa; + display: inline-block; + margin-left: 4px; +} + +.inconclusive { + background-color: #b6b6b4; +} + +.inconclusive2 { + background-color: #b6b6b4; + display: inline-block; + margin-left: 4px; +} + +.verbose { + display: inline-block; + vertical-align: top; + cursor: help; +} + +.verbose .content { + display: none; + position: absolute; + padding: 10px; + margin: 4px; + max-width: 40%; + white-space: pre-wrap; + border: 1px solid #000; + background-color: #ffffcc; + cursor: auto; +} + +.highlight .hll { + padding: 1px; +} + +.highlighttable { + background-color: #fff; + position: relative; + margin: -10px; +} + +.linenos { + border-right: thin solid #aaa; + color: #d3d3d3; + padding-right: 6px; +} + +.id-filtered, .severity-filtered, .file-filtered, .tool-filtered, .text-filtered { + visibility: collapse; +} diff --git a/2023-09-19-100425-2309-cppcheck@72f91230a146_master/0.html b/2023-09-19-100425-2309-cppcheck@72f91230a146_master/0.html new file mode 100644 index 0000000..5d72935 --- /dev/null +++ b/2023-09-19-100425-2309-cppcheck@72f91230a146_master/0.html @@ -0,0 +1,501 @@ + + + + + + Cppcheck - HTML report - mate-user-share + + + + + +
+ + + +
+
  1
+  2
+  3
+  4
+  5
+  6
+  7
+  8
+  9
+ 10
+ 11
+ 12
+ 13
+ 14
+ 15
+ 16
+ 17
+ 18
+ 19
+ 20
+ 21
+ 22
+ 23
+ 24
+ 25
+ 26
+ 27
+ 28
+ 29
+ 30
+ 31
+ 32
+ 33
+ 34
+ 35
+ 36
+ 37
+ 38
+ 39
+ 40
+ 41
+ 42
+ 43
+ 44
+ 45
+ 46
+ 47
+ 48
+ 49
+ 50
+ 51
+ 52
+ 53
+ 54
+ 55
+ 56
+ 57
+ 58
+ 59
+ 60
+ 61
+ 62
+ 63
+ 64
+ 65
+ 66
+ 67
+ 68
+ 69
+ 70
+ 71
+ 72
+ 73
+ 74
+ 75
+ 76
+ 77
+ 78
+ 79
+ 80
+ 81
+ 82
+ 83
+ 84
+ 85
+ 86
+ 87
+ 88
+ 89
+ 90
+ 91
+ 92
+ 93
+ 94
+ 95
+ 96
+ 97
+ 98
+ 99
+100
+101
+102
+103
+104
+105
+106
+107
+108
+109
+110
+111
+112
+113
+114
+115
+116
+117
+118
+119
+120
+121
+122
+123
+124
+125
+126
+127
+128
+129
+130
+131
+132
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2005 William Jon McCann <mccann@jhu.edu>
+ * Copyright (C) 2012-2021 MATE Developers
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * 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
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Authors: William Jon McCann <mccann@jhu.edu>
+ *
+ */
+
+#include "config.h"
+
+#include <glib/gi18n-lib.h>
+#include <gtk/gtk.h>
+
+#include "caja-share-bar.h"
+
+struct CajaShareBarPrivate
+{
+	GtkWidget   *label;
+};
+
+enum {
+	PROP_0,
+	PROP_LABEL
+};
+
+G_DEFINE_TYPE_WITH_PRIVATE (CajaShareBar, caja_share_bar, GTK_TYPE_INFO_BAR)<--- There is an unknown macro here somewhere. Configuration is required. If G_DEFINE_TYPE_WITH_PRIVATE is a macro then please configure it.
+
+static void
+caja_share_bar_set_property (GObject            *object,
+                                guint               prop_id,
+                                const GValue       *value,
+                                GParamSpec         *pspec)
+{
+        CajaShareBar *self;
+
+        self = CAJA_SHARE_BAR (object);
+
+        switch (prop_id) {
+	case PROP_LABEL: {
+		gtk_label_set_text (GTK_LABEL (self->priv->label),
+				    g_value_get_string (value));
+		break;
+	}
+        default:
+                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+                break;
+        }
+}
+
+static void
+caja_share_bar_class_init (CajaShareBarClass *klass)
+{
+        GObjectClass   *object_class = G_OBJECT_CLASS (klass);
+
+        object_class->set_property = caja_share_bar_set_property;
+
+        g_object_class_install_property (G_OBJECT_CLASS(klass), PROP_LABEL,
+					 g_param_spec_string ("label", "label",
+							      "The widget's main label",
+							      NULL,
+							      G_PARAM_WRITABLE));
+}
+
+static void
+caja_share_bar_init (CajaShareBar *bar)
+{
+	GtkWidget *content_area;
+	GtkWidget *action_area;
+	GtkWidget *label;
+	GtkWidget *vbox;
+	GtkWidget *button;
+	PangoAttrList *attrs;
+
+	bar->priv = caja_share_bar_get_instance_private (bar);
+
+	content_area = gtk_info_bar_get_content_area (GTK_INFO_BAR (bar));
+	action_area = gtk_info_bar_get_action_area (GTK_INFO_BAR (bar));
+	gtk_button_box_set_layout (GTK_BUTTON_BOX (action_area), GTK_BUTTONBOX_CENTER);
+
+	vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 3);
+	gtk_container_add (GTK_CONTAINER (content_area), vbox);
+
+	attrs = pango_attr_list_new ();
+	pango_attr_list_insert (attrs, pango_attr_weight_new (PANGO_WEIGHT_BOLD));
+	label = gtk_label_new (_("Personal File Sharing"));
+	gtk_label_set_attributes (GTK_LABEL (label), attrs);
+	pango_attr_list_unref (attrs);
+
+	gtk_label_set_xalign (GTK_LABEL (label), 0.0);
+	gtk_label_set_yalign (GTK_LABEL (label), 0.5);
+	gtk_widget_show (label);
+	gtk_container_add (GTK_CONTAINER (vbox), label);
+
+	bar->priv->label = gtk_label_new (NULL);
+	gtk_label_set_xalign (GTK_LABEL (bar->priv->label), 0.0);
+	gtk_label_set_yalign (GTK_LABEL (bar->priv->label), 0.5);
+	gtk_widget_show (bar->priv->label);
+	gtk_container_add (GTK_CONTAINER (vbox), bar->priv->label);
+
+	button = gtk_info_bar_add_button (GTK_INFO_BAR (bar),
+					  _("Preferences"),
+					  CAJA_SHARE_BAR_RESPONSE_PREFERENCES);
+
+	gtk_widget_set_tooltip_text (button,
+				     _("Launch Personal File Sharing Preferences"));
+
+	gtk_widget_show_all (vbox);
+}
+
+GtkWidget *
+caja_share_bar_new (const char *label)
+{
+        return g_object_new (CAJA_TYPE_SHARE_BAR,
+                             "message-type", GTK_MESSAGE_QUESTION,
+			     "label", label,
+                             NULL);
+}
+
+ +
+ +
+ + diff --git a/2023-09-19-100425-2309-cppcheck@72f91230a146_master/1.html b/2023-09-19-100425-2309-cppcheck@72f91230a146_master/1.html new file mode 100644 index 0000000..3e27e00 --- /dev/null +++ b/2023-09-19-100425-2309-cppcheck@72f91230a146_master/1.html @@ -0,0 +1,1567 @@ + + + + + + Cppcheck - HTML report - mate-user-share + + + + + +
+ + + +
+
  1
+  2
+  3
+  4
+  5
+  6
+  7
+  8
+  9
+ 10
+ 11
+ 12
+ 13
+ 14
+ 15
+ 16
+ 17
+ 18
+ 19
+ 20
+ 21
+ 22
+ 23
+ 24
+ 25
+ 26
+ 27
+ 28
+ 29
+ 30
+ 31
+ 32
+ 33
+ 34
+ 35
+ 36
+ 37
+ 38
+ 39
+ 40
+ 41
+ 42
+ 43
+ 44
+ 45
+ 46
+ 47
+ 48
+ 49
+ 50
+ 51
+ 52
+ 53
+ 54
+ 55
+ 56
+ 57
+ 58
+ 59
+ 60
+ 61
+ 62
+ 63
+ 64
+ 65
+ 66
+ 67
+ 68
+ 69
+ 70
+ 71
+ 72
+ 73
+ 74
+ 75
+ 76
+ 77
+ 78
+ 79
+ 80
+ 81
+ 82
+ 83
+ 84
+ 85
+ 86
+ 87
+ 88
+ 89
+ 90
+ 91
+ 92
+ 93
+ 94
+ 95
+ 96
+ 97
+ 98
+ 99
+100
+101
+102
+103
+104
+105
+106
+107
+108
+109
+110
+111
+112
+113
+114
+115
+116
+117
+118
+119
+120
+121
+122
+123
+124
+125
+126
+127
+128
+129
+130
+131
+132
+133
+134
+135
+136
+137
+138
+139
+140
+141
+142
+143
+144
+145
+146
+147
+148
+149
+150
+151
+152
+153
+154
+155
+156
+157
+158
+159
+160
+161
+162
+163
+164
+165
+166
+167
+168
+169
+170
+171
+172
+173
+174
+175
+176
+177
+178
+179
+180
+181
+182
+183
+184
+185
+186
+187
+188
+189
+190
+191
+192
+193
+194
+195
+196
+197
+198
+199
+200
+201
+202
+203
+204
+205
+206
+207
+208
+209
+210
+211
+212
+213
+214
+215
+216
+217
+218
+219
+220
+221
+222
+223
+224
+225
+226
+227
+228
+229
+230
+231
+232
+233
+234
+235
+236
+237
+238
+239
+240
+241
+242
+243
+244
+245
+246
+247
+248
+249
+250
+251
+252
+253
+254
+255
+256
+257
+258
+259
+260
+261
+262
+263
+264
+265
+266
+267
+268
+269
+270
+271
+272
+273
+274
+275
+276
+277
+278
+279
+280
+281
+282
+283
+284
+285
+286
+287
+288
+289
+290
+291
+292
+293
+294
+295
+296
+297
+298
+299
+300
+301
+302
+303
+304
+305
+306
+307
+308
+309
+310
+311
+312
+313
+314
+315
+316
+317
+318
+319
+320
+321
+322
+323
+324
+325
+326
+327
+328
+329
+330
+331
+332
+333
+334
+335
+336
+337
+338
+339
+340
+341
+342
+343
+344
+345
+346
+347
+348
+349
+350
+351
+352
+353
+354
+355
+356
+357
+358
+359
+360
+361
+362
+363
+364
+365
+366
+367
+368
+369
+370
+371
+372
+373
+374
+375
+376
+377
+378
+379
+380
+381
+382
+383
+384
+385
+386
+387
+388
+389
+390
+391
+392
+393
+394
+395
+396
+397
+398
+399
+400
+401
+402
+403
+404
+405
+406
+407
+408
+409
+410
+411
+412
+413
+414
+415
+416
+417
+418
+419
+420
+421
+422
+423
+424
+425
+426
+427
+428
+429
+430
+431
+432
+433
+434
+435
+436
+437
+438
+439
+440
+441
+442
+443
+444
+445
+446
+447
+448
+449
+450
+451
+452
+453
+454
+455
+456
+457
+458
+459
+460
+461
+462
+463
+464
+465
+466
+467
+468
+469
+470
+471
+472
+473
+474
+475
+476
+477
+478
+479
+480
+481
+482
+483
+484
+485
+486
+487
+488
+489
+490
+491
+492
+493
+494
+495
+496
+497
+498
+499
+500
+501
+502
+503
+504
+505
+506
+507
+508
+509
+510
+511
+512
+513
+514
+515
+516
+517
+518
+519
+520
+521
+522
+523
+524
+525
+526
+527
+528
+529
+530
+531
+532
+533
+534
+535
+536
+537
+538
+539
+540
+541
+542
+543
+544
+545
+546
+547
+548
+549
+550
+551
+552
+553
+554
+555
+556
+557
+558
+559
+560
+561
+562
+563
+564
+565
+566
+567
+568
+569
+570
+571
+572
+573
+574
+575
+576
+577
+578
+579
+580
+581
+582
+583
+584
+585
+586
+587
+588
+589
+590
+591
+592
+593
+594
+595
+596
+597
+598
+599
+600
+601
+602
+603
+604
+605
+606
+607
+608
+609
+610
+611
+612
+613
+614
+615
+616
+617
+618
+619
+620
+621
+622
+623
+624
+625
+626
+627
+628
+629
+630
+631
+632
+633
+634
+635
+636
+637
+638
+639
+640
+641
+642
+643
+644
+645
+646
+647
+648
+649
+650
+651
+652
+653
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
+
+/*
+ *  Copyright (C) 2004 Red Hat, Inc.
+ * Copyright (C) 2012-2021 MATE Developers
+ *
+ *  Caja is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU General Public License as
+ *  published by the Free Software Foundation; either version 2 of the
+ *  License, or (at your option) any later version.
+ *
+ *  Caja is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  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
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ *  Authors: Alexander Larsson <alexl@redhat.com>
+ *
+ */
+
+#include "config.h"
+
+#include <string.h>
+#include <stdio.h>
+
+#include <gtk/gtk.h>
+#include <glib/gi18n.h>
+#include <gio/gio.h>
+
+#include "user_share-private.h"
+
+#define REALM "Please log in as the user guest"
+#define USER "guest"
+#define GSETTINGS_SCHEMA "org.mate.FileSharing"
+#define GSETTINGS_KEY_FILE_SHARING_ENABLED "enabled"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_ENABLED "bluetooth-enabled"
+#define GSETTINGS_KEY_FILE_SHARING_REQUIRE_PASSWORD "require-password"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_ALLOW_WRITE "bluetooth-allow-write"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_REQUIRE_PAIRING "bluetooth-require-pairing"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED "bluetooth-obexpush-enabled"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_ACCEPT_FILES "bluetooth-accept-files"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_NOTIFY "bluetooth-notify"
+
+static GtkBuilder* builder;
+static GSettings* settings;<--- Shadowed declaration<--- Shadowed declaration<--- Shadowed declaration<--- Shadowed declaration<--- Shadowed declaration<--- Shadowed declaration<--- Shadowed declaration<--- Shadowed declaration<--- Shadowed declaration<--- Shadowed declaration
+
+
+static void
+write_out_password (const char *password)
+{
+    char *to_hash;
+    char *ascii_digest;
+    char *line;
+    char *filename;
+    FILE *file;
+
+    to_hash = g_strdup_printf ("%s:%s:%s", USER, REALM, password);
+    ascii_digest = g_compute_checksum_for_string (G_CHECKSUM_MD5, to_hash, strlen (to_hash));
+    g_free (to_hash);
+    line = g_strdup_printf ("%s:%s:%s\n", USER, REALM, ascii_digest);
+    g_free (ascii_digest);
+
+    filename = g_build_filename (g_get_user_config_dir (), "user-share", "passwd", NULL);
+
+    file = fopen (filename, "w");
+    if (file != NULL) {
+	fwrite (line, strlen (line), 1, file);
+	fclose (file);
+    }
+
+    g_free (filename);
+    g_free (line);
+}
+
+static void
+flush_password (void)
+{
+    GtkWidget *password_entry;
+    const char *password;
+
+    password_entry = GTK_WIDGET (gtk_builder_get_object (builder, "password_entry"));
+
+    if (g_object_get_data (G_OBJECT( password_entry), "user_edited")) {
+	password = gtk_entry_get_text (GTK_ENTRY (password_entry));
+	if (password != NULL && password[0] != 0)
+	    write_out_password (password);
+    }
+}
+
+
+static void
+update_ui (void)
+{
+    GSettings *settings;<--- Shadow variable
+    gboolean enabled;
+#ifdef HAVE_BLUETOOTH
+    gboolean bluetooth_enabled, bluetooth_write_enabled, require_pairing_enabled;
+    gboolean bluetooth_obexpush_enabled, bluetooth_obexpush_notify;
+#endif /* HAVE_BLUETOOTH */
+    char *str;
+    PasswordSetting password_setting;
+    AcceptSetting accept_setting;<--- Unused variable: accept_setting
+    GtkWidget *check;
+    GtkWidget *password_combo;
+    GtkWidget *password_entry;
+#ifdef HAVE_BLUETOOTH
+    GtkWidget *vbox_share_bluetooth;
+    GtkWidget *vbox_receive_bluetooth;
+    GtkWidget *bluetooth_check;
+    GtkWidget *allow_write_bluetooth_check;
+    GtkWidget *require_pairing_check;
+    GtkWidget *enable_obexpush_check;
+    GtkWidget *accept_obexpush_combo;
+    GtkWidget *notify_received_obexpush_check;
+#endif /* HAVE_BLUETOOTH */
+
+    settings = g_settings_new (GSETTINGS_SCHEMA);
+
+    enabled = g_settings_get_boolean (settings,
+				     FILE_SHARING_ENABLED);
+
+    str = g_settings_get_string (settings, FILE_SHARING_REQUIRE_PASSWORD);
+    password_setting = password_setting_from_string (str);
+    g_free (str);
+
+#ifdef HAVE_BLUETOOTH
+    bluetooth_enabled = g_settings_get_boolean (settings,
+    					       FILE_SHARING_BLUETOOTH_ENABLED);
+    bluetooth_write_enabled = g_settings_get_boolean (settings,
+						     FILE_SHARING_BLUETOOTH_ALLOW_WRITE);
+    require_pairing_enabled = g_settings_get_boolean (settings,
+    						     FILE_SHARING_BLUETOOTH_REQUIRE_PAIRING);
+    bluetooth_obexpush_enabled = g_settings_get_boolean (settings,
+    							FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED);
+    bluetooth_obexpush_notify = g_settings_get_boolean (settings,
+    						       FILE_SHARING_BLUETOOTH_OBEXPUSH_NOTIFY);
+
+    str = g_settings_get_string (settings, FILE_SHARING_BLUETOOTH_OBEXPUSH_ACCEPT_FILES);
+    accept_setting = accept_setting_from_string (str);
+    g_free (str);
+#endif /* HAVE_BLUETOOTH */
+
+    check = GTK_WIDGET (gtk_builder_get_object (builder, "enable_check"));
+    password_combo = GTK_WIDGET (gtk_builder_get_object (builder, "password_combo"));
+    password_entry = GTK_WIDGET (gtk_builder_get_object (builder, "password_entry"));
+#ifdef HAVE_BLUETOOTH
+    vbox_share_bluetooth = GTK_WIDGET (gtk_builder_get_object (builder, "vbox_share_bluetooth"));
+    vbox_receive_bluetooth = GTK_WIDGET (gtk_builder_get_object (builder, "vbox_receive_bluetooth"));
+    bluetooth_check = GTK_WIDGET (gtk_builder_get_object (builder, "enable_bluetooth_check"));
+    allow_write_bluetooth_check = GTK_WIDGET (gtk_builder_get_object (builder, "allow_write_bluetooth_check"));
+    require_pairing_check = GTK_WIDGET (gtk_builder_get_object (builder, "require_pairing_check"));
+    enable_obexpush_check = GTK_WIDGET (gtk_builder_get_object (builder, "enable_obexpush_check"));
+    accept_obexpush_combo = GTK_WIDGET (gtk_builder_get_object (builder, "accept_obexpush_combo"));
+    notify_received_obexpush_check = GTK_WIDGET (gtk_builder_get_object (builder, "notify_received_obexpush_check"));
+#endif /* HAVE_BLUETOOTH */
+
+    /* Network */
+    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (check), enabled);
+    gtk_widget_set_sensitive (password_combo, enabled);
+    gtk_widget_set_sensitive (password_entry, enabled && password_setting != PASSWORD_NEVER);
+
+    gtk_combo_box_set_active (GTK_COMBO_BOX (password_combo),
+			      password_setting);
+
+#ifdef HAVE_BLUETOOTH
+    /* Bluetooth ObexFTP */
+    gtk_widget_set_visible (vbox_share_bluetooth, TRUE);
+    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (bluetooth_check), bluetooth_enabled);
+    gtk_widget_set_sensitive (allow_write_bluetooth_check, bluetooth_enabled);
+    gtk_widget_set_sensitive (require_pairing_check, bluetooth_enabled);
+
+    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (allow_write_bluetooth_check),
+    				  bluetooth_write_enabled);
+    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (require_pairing_check),
+    				  require_pairing_enabled);
+
+    /* Bluetooth ObexPush */
+    gtk_widget_set_visible (vbox_receive_bluetooth, TRUE);
+    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (enable_obexpush_check), bluetooth_obexpush_enabled);
+    gtk_widget_set_sensitive (accept_obexpush_combo, bluetooth_obexpush_enabled);
+    gtk_widget_set_sensitive (notify_received_obexpush_check, bluetooth_obexpush_enabled);
+
+    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (notify_received_obexpush_check),
+    				  bluetooth_obexpush_notify);
+
+    gtk_combo_box_set_active (GTK_COMBO_BOX (accept_obexpush_combo),
+    			      accept_setting);
+#endif /* HAVE_BLUETOOTH */
+
+    g_object_unref (settings);
+}
+
+static void
+file_sharing_enabled_changed (GSettings *settings, gchar *key, gpointer data)
+{
+    update_ui ();
+}
+
+static void
+password_required_changed (GSettings *settings, gchar *key, gpointer data)
+{
+    update_ui ();
+}
+
+#ifdef HAVE_BLUETOOTH
+static void
+file_sharing_bluetooth_enabled_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	update_ui ();
+}
+
+static void
+file_sharing_bluetooth_allow_write_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	update_ui ();
+}
+
+static void
+file_sharing_bluetooth_require_pairing_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	update_ui ();
+}
+
+static void
+file_sharing_bluetooth_obexpush_enabled_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	update_ui ();
+}
+
+static void
+file_sharing_bluetooth_obexpush_accept_files_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	update_ui ();
+}
+
+static void
+file_sharing_bluetooth_obexpush_notify_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	update_ui ();
+}
+#endif /* HAVE_BLUETOOTH */
+
+static void
+password_combo_changed (GtkComboBox *combo_box)
+{
+    GSettings *settings;<--- Shadow variable
+    guint setting;
+
+    setting = gtk_combo_box_get_active (combo_box);
+
+    settings = g_settings_new (GSETTINGS_SCHEMA) ;
+
+    g_settings_set_string (settings,
+			     FILE_SHARING_REQUIRE_PASSWORD,
+			     password_string_from_setting (setting));
+    g_object_unref (settings);
+}
+
+static void
+launch_share (void)
+{
+	if (!g_spawn_command_line_async (USER_SHARE_PROGRAM, NULL))
+		g_warning ("Unable to start mate-user-share program");
+}
+
+#ifdef HAVE_BLUETOOTH
+static void
+enable_bluetooth_check_toggled (GtkWidget *check)
+{
+	GSettings *settings;<--- Shadow variable
+	gboolean enabled;
+
+	enabled = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check));
+
+	settings = g_settings_new (GSETTINGS_SCHEMA) ;
+
+	g_settings_set_boolean (settings,
+			       FILE_SHARING_BLUETOOTH_ENABLED,
+			       enabled);
+
+	g_object_unref (settings);
+
+	if (enabled != FALSE)
+		launch_share ();
+}
+#endif /* HAVE_BLUETOOTH */
+
+static void
+enable_check_toggled (GtkWidget *check)
+{
+	GSettings *settings;<--- Shadow variable
+	gboolean enabled;
+
+	enabled = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check));
+
+	settings = g_settings_new (GSETTINGS_SCHEMA);
+
+	g_settings_set_boolean (settings,
+			       FILE_SHARING_ENABLED,
+			       enabled);
+
+	g_object_unref (settings);
+
+	if (enabled != FALSE)
+		launch_share ();
+}
+
+static void
+password_entry_changed (GtkEditable *editable)
+{
+	g_object_set_data (G_OBJECT (editable),
+			   "user_edited", GINT_TO_POINTER (1));
+	flush_password ();
+}
+
+#ifdef HAVE_BLUETOOTH
+static void
+bluetooth_allow_write_check_toggled (GtkWidget *check)
+{
+	GSettings *settings;<--- Shadow variable
+	gboolean enabled;
+
+	enabled = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check));
+
+	settings = g_settings_new (GSETTINGS_SCHEMA) ;
+
+	g_settings_set_boolean (settings,
+			       FILE_SHARING_BLUETOOTH_ALLOW_WRITE,
+			       enabled);
+
+	g_object_unref (settings);
+}
+
+static void
+bluetooth_require_pairing_check_toggled (GtkWidget *check)
+{
+	GSettings *settings;<--- Shadow variable
+	gboolean enabled;
+
+	enabled = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check));
+
+	settings = g_settings_new (GSETTINGS_SCHEMA) ;
+
+	g_settings_set_boolean (settings,
+			       FILE_SHARING_BLUETOOTH_REQUIRE_PAIRING,
+			       enabled);
+
+	g_object_unref (settings);
+}
+
+static void
+enable_obexpush_check_toggled (GtkWidget *check)
+{
+	GSettings *settings;<--- Shadow variable
+	gboolean enabled;
+
+	enabled = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check));
+
+	settings = g_settings_new (GSETTINGS_SCHEMA) ;
+
+	g_settings_set_boolean (settings,
+			       FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED,
+			       enabled);
+
+	g_object_unref (settings);
+
+	if (enabled != FALSE)
+		launch_share ();
+}
+
+static void
+accept_obexpush_combo_changed (GtkComboBox *combo_box)
+{
+    GSettings *settings;<--- Shadow variable
+    guint setting;
+
+    setting = gtk_combo_box_get_active (combo_box);
+
+    settings = g_settings_new (GSETTINGS_SCHEMA) ;
+
+    g_settings_set_string (settings,
+			     FILE_SHARING_BLUETOOTH_OBEXPUSH_ACCEPT_FILES,
+			     accept_string_from_setting (setting));
+    g_object_unref (settings);
+}
+
+static void
+notify_received_obexpush_check_toggled (GtkWidget *check)
+{
+	GSettings *settings;<--- Shadow variable
+	gboolean enabled;
+
+	enabled = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check));
+
+	settings = g_settings_new (GSETTINGS_SCHEMA) ;
+
+	g_settings_set_boolean (settings,
+			       FILE_SHARING_BLUETOOTH_OBEXPUSH_NOTIFY,
+			       enabled);
+
+	g_object_unref (settings);
+}
+#endif /* HAVE_BLUETOOTH */
+
+static GtkWidget *
+error_dialog (const char *title,
+	      const char *reason,
+	      GtkWindow *parent)
+{
+	GtkWidget *error_dialog;
+
+	if (reason == NULL)
+		reason = _("No reason");
+
+	error_dialog =
+		gtk_message_dialog_new (parent,
+					GTK_DIALOG_MODAL,
+					GTK_MESSAGE_ERROR,
+					GTK_BUTTONS_OK,
+					"%s", title);
+	gtk_message_dialog_format_secondary_text
+		(GTK_MESSAGE_DIALOG (error_dialog), "%s", reason);
+
+	gtk_window_set_title (GTK_WINDOW (error_dialog), ""); /* as per HIG */
+	gtk_container_set_border_width (GTK_CONTAINER (error_dialog), 5);
+	gtk_dialog_set_default_response (GTK_DIALOG (error_dialog),
+					 GTK_RESPONSE_OK);
+	gtk_window_set_modal (GTK_WINDOW (error_dialog), TRUE);
+
+	return error_dialog;
+}
+
+static void
+help_button_clicked (GtkButton *button, GtkWidget *window)
+{
+	GError *error = NULL;
+
+	if (gtk_show_uri_on_window (GTK_WINDOW (window), "help:mate-user-share", gtk_get_current_event_time (), &error) == FALSE) {
+		GtkWidget *dialog;
+
+		dialog = error_dialog (_("Could not display the help contents."), error->message, GTK_WINDOW (window));
+		g_signal_connect (G_OBJECT (dialog), "response", G_CALLBACK
+				  (gtk_widget_destroy), error_dialog);
+		gtk_window_present (GTK_WINDOW (dialog));
+
+		g_error_free (error);
+	}
+}
+
+static GtkWidget *
+create_window (void)
+{
+    GError *error = NULL;
+    GSettings *settings;<--- Shadow variable
+    GtkWidget *check;
+    GtkWidget *password_combo;
+    GtkWidget *password_entry;
+#ifdef HAVE_BLUETOOTH
+    GtkWidget *bluetooth_check;
+    GtkWidget *bluetooth_allow_write_check;
+    GtkWidget *require_pairing_check;
+    GtkWidget *enable_obexpush_check;
+    GtkWidget *accept_obexpush_combo;
+    GtkWidget *notify_received_obexpush_check;
+#endif /* HAVE_BLUETOOTH */
+    GtkWidget *window;
+    GtkListStore *store;
+    GtkCellRenderer *cell;
+    GtkTreeIter iter;
+
+    builder = gtk_builder_new ();
+    gtk_builder_add_from_file (builder, DATADIR"file-share-properties.ui", &error);
+
+    if (error) {
+      GtkWidget *dialog;
+
+      dialog = error_dialog (_("Could not build interface."), error->message, NULL);
+      gtk_dialog_run (GTK_DIALOG (dialog));
+      gtk_widget_destroy (dialog);
+
+      g_error_free (error);
+      return NULL;
+    }
+
+    window = GTK_WIDGET (gtk_builder_get_object (builder, "user_share_dialog"));
+
+    settings = g_settings_new (GSETTINGS_SCHEMA);
+
+    check = GTK_WIDGET (gtk_builder_get_object (builder, "enable_check"));
+    password_combo = GTK_WIDGET (gtk_builder_get_object (builder, "password_combo"));
+    password_entry = GTK_WIDGET (gtk_builder_get_object (builder, "password_entry"));
+#ifdef HAVE_BLUETOOTH
+    bluetooth_check = GTK_WIDGET (gtk_builder_get_object (builder, "enable_bluetooth_check"));
+    bluetooth_allow_write_check = GTK_WIDGET (gtk_builder_get_object (builder, "allow_write_bluetooth_check"));
+    require_pairing_check = GTK_WIDGET (gtk_builder_get_object (builder, "require_pairing_check"));
+    enable_obexpush_check = GTK_WIDGET (gtk_builder_get_object (builder, "enable_obexpush_check"));
+    accept_obexpush_combo = GTK_WIDGET (gtk_builder_get_object (builder, "accept_obexpush_combo"));
+    notify_received_obexpush_check = GTK_WIDGET (gtk_builder_get_object (builder, "notify_received_obexpush_check"));
+#endif /* HAVE_BLUETOOTH */
+
+    store = gtk_list_store_new (1, G_TYPE_STRING);
+    gtk_combo_box_set_model (GTK_COMBO_BOX (password_combo),
+			     GTK_TREE_MODEL (store));
+    cell = gtk_cell_renderer_text_new ();
+    gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (password_combo), cell, TRUE);
+    gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (password_combo), cell,
+				    "text", 0,
+				    NULL);
+
+    /* Keep in same order as enum */
+    gtk_list_store_append (store, &iter);
+    gtk_list_store_set (store, &iter, 0,
+			_("Never"), -1);
+    gtk_list_store_append (store, &iter);
+    gtk_list_store_set (store, &iter, 0,
+			_("When writing files"), -1);
+    gtk_list_store_append (store, &iter);
+    gtk_list_store_set (store, &iter, 0,
+			_("Always"), -1);
+    g_object_unref (store);
+
+    /* We can't read the password from the text, just set it to something */
+    gtk_entry_set_text (GTK_ENTRY (password_entry), "none");
+    g_object_set_data (G_OBJECT (password_entry),
+		       "user_edited", GINT_TO_POINTER (0));
+    g_signal_connect (password_entry,
+		      "changed", G_CALLBACK (password_entry_changed), NULL);
+
+#ifdef HAVE_BLUETOOTH
+    /* Accept files combo */
+    store = gtk_list_store_new (1, G_TYPE_STRING);
+    gtk_combo_box_set_model (GTK_COMBO_BOX (accept_obexpush_combo),
+			     GTK_TREE_MODEL (store));
+    cell = gtk_cell_renderer_text_new ();
+    gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (accept_obexpush_combo), cell, TRUE);
+    gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (accept_obexpush_combo), cell,
+				    "text", 0,
+				    NULL);
+
+    /* Keep in same order as enum */
+    gtk_list_store_append (store, &iter);
+    gtk_list_store_set (store, &iter, 0,
+			_("Always"), -1);
+    gtk_list_store_append (store, &iter);
+    gtk_list_store_set (store, &iter, 0,
+			_("Only for set up devices"), -1);
+    //FIXME implement
+#if 0
+    gtk_list_store_append (store, &iter);
+    gtk_list_store_set (store, &iter, 0,
+    			_("Ask"), -1);
+#endif
+    g_object_unref (store);
+#endif /* HAVE_BLUETOOTH */
+
+    g_signal_connect (check,
+		      "toggled", G_CALLBACK (enable_check_toggled), NULL);
+    g_signal_connect (password_combo,
+		      "changed", G_CALLBACK (password_combo_changed), NULL);
+#ifdef HAVE_BLUETOOTH
+    g_signal_connect (bluetooth_check,
+    		      "toggled", G_CALLBACK (enable_bluetooth_check_toggled), NULL);
+    g_signal_connect (bluetooth_allow_write_check,
+    		      "toggled", G_CALLBACK (bluetooth_allow_write_check_toggled), NULL);
+    g_signal_connect (require_pairing_check,
+    		      "toggled", G_CALLBACK (bluetooth_require_pairing_check_toggled), NULL);
+    g_signal_connect (enable_obexpush_check,
+    		      "toggled", G_CALLBACK (enable_obexpush_check_toggled), NULL);
+    g_signal_connect (accept_obexpush_combo,
+    		      "changed", G_CALLBACK (accept_obexpush_combo_changed), NULL);
+    g_signal_connect (notify_received_obexpush_check,
+    		      "toggled", G_CALLBACK (notify_received_obexpush_check_toggled), NULL);
+#endif /* HAVE_BLUETOOTH */
+
+    g_signal_connect_swapped (GTK_WIDGET (gtk_builder_get_object (builder, "close_button")),
+                              "clicked", G_CALLBACK (gtk_widget_destroy), window);
+    g_signal_connect (GTK_WIDGET (gtk_builder_get_object (builder, "help_button")),
+		      "clicked", G_CALLBACK (help_button_clicked),
+		      gtk_builder_get_object (builder, "user_share_dialog"));
+
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_ENABLED,
+			     G_CALLBACK (file_sharing_enabled_changed), NULL);
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_REQUIRE_PASSWORD,
+			     G_CALLBACK (password_required_changed), NULL);
+#ifdef HAVE_BLUETOOTH
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_ENABLED,
+			     G_CALLBACK (file_sharing_bluetooth_enabled_changed), NULL);
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_ALLOW_WRITE,
+			     G_CALLBACK (file_sharing_bluetooth_allow_write_changed), NULL);
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_REQUIRE_PAIRING,
+			     G_CALLBACK (file_sharing_bluetooth_require_pairing_changed), NULL);
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED,
+			     G_CALLBACK (file_sharing_bluetooth_obexpush_enabled_changed), NULL);
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_ACCEPT_FILES,
+			     G_CALLBACK (file_sharing_bluetooth_obexpush_accept_files_changed), NULL);
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_NOTIFY,
+			     G_CALLBACK (file_sharing_bluetooth_obexpush_notify_changed), NULL);
+#endif /* HAVE_BLUETOOTH */
+
+    update_ui ();
+
+    return window;
+}
+
+static void
+activate (GtkApplication *app)
+{
+    GList *list;
+    GtkWidget *window;
+
+    list = gtk_application_get_windows (app);
+
+    if (list) {
+        gtk_window_present (GTK_WINDOW (list->data));
+    } else {
+        window = create_window ();
+        gtk_window_set_application (GTK_WINDOW (window), app);
+        gtk_widget_show (window);
+    }
+}
+
+int
+main (int argc, char *argv[])
+{
+    GtkApplication *app;
+    gint status;
+
+    bindtextdomain (GETTEXT_PACKAGE, MATELOCALEDIR);
+    bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
+    textdomain (GETTEXT_PACKAGE);
+
+    app = gtk_application_new ("org.mate.user-share.properties",
+                               G_APPLICATION_FLAGS_NONE);
+    g_signal_connect (app, "activate", G_CALLBACK (activate), NULL);
+
+    status = g_application_run (G_APPLICATION (app), argc, argv);
+
+    g_object_unref (app);
+
+    return status;
+}
+
+ +
+ +
+ + diff --git a/2023-09-19-100425-2309-cppcheck@72f91230a146_master/2.html b/2023-09-19-100425-2309-cppcheck@72f91230a146_master/2.html new file mode 100644 index 0000000..7bbeccd --- /dev/null +++ b/2023-09-19-100425-2309-cppcheck@72f91230a146_master/2.html @@ -0,0 +1,1123 @@ + + + + + + Cppcheck - HTML report - mate-user-share + + + + + +
+ + + +
+
  1
+  2
+  3
+  4
+  5
+  6
+  7
+  8
+  9
+ 10
+ 11
+ 12
+ 13
+ 14
+ 15
+ 16
+ 17
+ 18
+ 19
+ 20
+ 21
+ 22
+ 23
+ 24
+ 25
+ 26
+ 27
+ 28
+ 29
+ 30
+ 31
+ 32
+ 33
+ 34
+ 35
+ 36
+ 37
+ 38
+ 39
+ 40
+ 41
+ 42
+ 43
+ 44
+ 45
+ 46
+ 47
+ 48
+ 49
+ 50
+ 51
+ 52
+ 53
+ 54
+ 55
+ 56
+ 57
+ 58
+ 59
+ 60
+ 61
+ 62
+ 63
+ 64
+ 65
+ 66
+ 67
+ 68
+ 69
+ 70
+ 71
+ 72
+ 73
+ 74
+ 75
+ 76
+ 77
+ 78
+ 79
+ 80
+ 81
+ 82
+ 83
+ 84
+ 85
+ 86
+ 87
+ 88
+ 89
+ 90
+ 91
+ 92
+ 93
+ 94
+ 95
+ 96
+ 97
+ 98
+ 99
+100
+101
+102
+103
+104
+105
+106
+107
+108
+109
+110
+111
+112
+113
+114
+115
+116
+117
+118
+119
+120
+121
+122
+123
+124
+125
+126
+127
+128
+129
+130
+131
+132
+133
+134
+135
+136
+137
+138
+139
+140
+141
+142
+143
+144
+145
+146
+147
+148
+149
+150
+151
+152
+153
+154
+155
+156
+157
+158
+159
+160
+161
+162
+163
+164
+165
+166
+167
+168
+169
+170
+171
+172
+173
+174
+175
+176
+177
+178
+179
+180
+181
+182
+183
+184
+185
+186
+187
+188
+189
+190
+191
+192
+193
+194
+195
+196
+197
+198
+199
+200
+201
+202
+203
+204
+205
+206
+207
+208
+209
+210
+211
+212
+213
+214
+215
+216
+217
+218
+219
+220
+221
+222
+223
+224
+225
+226
+227
+228
+229
+230
+231
+232
+233
+234
+235
+236
+237
+238
+239
+240
+241
+242
+243
+244
+245
+246
+247
+248
+249
+250
+251
+252
+253
+254
+255
+256
+257
+258
+259
+260
+261
+262
+263
+264
+265
+266
+267
+268
+269
+270
+271
+272
+273
+274
+275
+276
+277
+278
+279
+280
+281
+282
+283
+284
+285
+286
+287
+288
+289
+290
+291
+292
+293
+294
+295
+296
+297
+298
+299
+300
+301
+302
+303
+304
+305
+306
+307
+308
+309
+310
+311
+312
+313
+314
+315
+316
+317
+318
+319
+320
+321
+322
+323
+324
+325
+326
+327
+328
+329
+330
+331
+332
+333
+334
+335
+336
+337
+338
+339
+340
+341
+342
+343
+344
+345
+346
+347
+348
+349
+350
+351
+352
+353
+354
+355
+356
+357
+358
+359
+360
+361
+362
+363
+364
+365
+366
+367
+368
+369
+370
+371
+372
+373
+374
+375
+376
+377
+378
+379
+380
+381
+382
+383
+384
+385
+386
+387
+388
+389
+390
+391
+392
+393
+394
+395
+396
+397
+398
+399
+400
+401
+402
+403
+404
+405
+406
+407
+408
+409
+410
+411
+412
+413
+414
+415
+416
+417
+418
+419
+420
+421
+422
+423
+424
+425
+426
+427
+428
+429
+430
+431
+432
+433
+434
+435
+436
+437
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
+
+/*
+ *  Copyright (C) 2004-2008 Red Hat, Inc.
+ * Copyright (C) 2012-2021 MATE Developers
+ *
+ *  Caja is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU General Public License as
+ *  published by the Free Software Foundation; either version 2 of the
+ *  License, or (at your option) any later version.
+ *
+ *  Caja is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  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
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ *  Authors: Alexander Larsson <alexl@redhat.com>
+ *
+ */
+
+#include "config.h"
+
+#include <glib.h>
+#include <glib/gi18n.h>
+#include <X11/Xlib.h>
+
+#include <gio/gio.h>
+
+#include <stdarg.h>
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <signal.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <sys/stat.h>
+
+#ifdef HAVE_SELINUX
+#include <selinux/selinux.h>
+#endif
+
+#include "user_share-common.h"
+#include "user_share-private.h"
+#include "http.h"
+
+/* From avahi-common/domain.h */
+#define AVAHI_LABEL_MAX 64
+
+#define GSETTINGS_SCHEMA "org.mate.FileSharing"
+
+static pid_t httpd_pid = 0;
+
+static int
+get_port (void)
+{
+	int sock;
+	struct sockaddr_in addr;
+	int reuse;
+	socklen_t len;
+
+	sock = socket (PF_INET, SOCK_STREAM, 0);
+	if (sock < 0) {
+		return -1;
+	}
+
+	memset (&addr, 0, sizeof (addr));
+	addr.sin_port = 0;
+	addr.sin_addr.s_addr = INADDR_ANY;
+	addr.sin_family = AF_INET;
+
+	reuse = 1;
+	setsockopt (sock, SOL_SOCKET, SO_REUSEADDR, &reuse, sizeof (reuse));
+	if (bind (sock, (struct sockaddr *)&addr, sizeof (addr)) == -1) {
+		close (sock);
+		return -1;
+	}
+
+	len = sizeof (addr);
+	if (getsockname (sock, (struct sockaddr *)&addr, &len) == -1) {
+		close (sock);
+		return -1;
+	}
+
+#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__APPLE__) || defined(__OpenBSD__)
+	/* XXX This exposes a potential race condition, but without this,
+	 * httpd will not start on the above listed platforms due to the fact
+	 * that SO_REUSEADDR is also needed when Apache binds to the listening
+	 * socket.  At this time, Apache does not support that socket option.
+	 */
+	close (sock);
+#endif
+	return ntohs (addr.sin_port);
+}
+
+static char *
+truncate_name (const char *name)
+{
+	const char *end;
+
+	end = g_utf8_find_prev_char (name, name + 64);
+	g_assert (end != NULL);
+	return g_strndup (name, end - name);
+}
+
+static char *
+get_share_name (void)
+{
+	static char *name = NULL;
+	const char *host_name;
+	char *str;
+
+	if (name == NULL) {
+		host_name = g_get_host_name ();
+		if (strcmp (host_name, "localhost") == 0) {
+			/* Translators: The %s will get filled in with the user name
+			   of the user, to form a genitive. If this is difficult to
+			   translate correctly so that it will work correctly in your
+			   language, you may use something equivalent to
+			   "Public files of %s", or leave out the %s altogether.
+			   In the latter case, please put "%.0s" somewhere in the string,
+			   which will match the user name string passed by the C code,
+			   but not put the user name in the final string. This is to
+			   avoid the warning that msgfmt might otherwise generate. */
+			name = g_strdup_printf (_("%s's public files"), g_get_user_name ());
+		} else {
+			/* Translators: This is similar to the string before, only it
+			   has the hostname in it too. */
+			name = g_strdup_printf (_("%s's public files on %s"),
+						g_get_user_name (),
+						host_name);
+		}
+
+	}
+	/* And truncate */
+	if (strlen (name) < AVAHI_LABEL_MAX)
+		return name;
+
+	str = truncate_name (name);
+	g_free (name);
+	name = str;
+
+	return name;
+}
+
+static void
+ensure_conf_dir (void)
+{
+	char *dirname;
+
+	dirname = g_build_filename (g_get_user_config_dir (), "user-share", NULL);
+	g_mkdir_with_parents (dirname, 0755);
+	g_free (dirname);
+}
+
+static void
+httpd_child_setup (gpointer user_data)
+{
+#ifdef HAVE_SELINUX
+	char *mycon;
+	/* If selinux is enabled, avoid transitioning to the httpd_t context,
+	   as this normally means you can't read the users homedir. */
+	if (is_selinux_enabled()) {
+		if (getcon (&mycon) < 0) {
+			abort ();
+		}
+		if (setexeccon (mycon) < 0)
+			abort ();
+		freecon (mycon);
+	}
+#endif
+}
+
+static const char *known_httpd_locations [] = {
+	HTTPD_PROGRAM,
+	"/usr/sbin/httpd",
+	"/usr/sbin/httpd2",
+	"/usr/sbin/apache2",
+	NULL
+};
+
+static char*
+get_httpd_program (void)
+{
+	int i;
+
+	for (i = 0; known_httpd_locations[i]; i++) {
+		if (known_httpd_locations[i][0] == '\0') {
+			/* empty string as first element, happens when
+			 * configured --with-httpd=auto */
+			continue;
+		}
+		if (g_file_test (known_httpd_locations[i], G_FILE_TEST_IS_EXECUTABLE)
+				&& ! g_file_test (known_httpd_locations[i], G_FILE_TEST_IS_DIR)) {
+			return g_strdup (known_httpd_locations[i]);
+		}
+	}
+	return NULL;
+}
+
+static const char *known_httpd_modules_locations [] = {
+	HTTPD_MODULES_PATH,
+	"/etc/httpd/modules",
+	"/usr/lib/apache2/modules",
+	NULL
+};
+
+static gchar*
+get_httpd_modules_path (void)
+{
+	int i;
+
+	for (i = 0; known_httpd_modules_locations[i]; i++) {
+		if (known_httpd_modules_locations[i][0] == '\0') {
+			/* empty string as first element, happens when
+			 * configured --with-httpd=auto */
+			continue;
+		}
+		if (g_file_test (known_httpd_modules_locations[i], G_FILE_TEST_IS_EXECUTABLE)
+				&& g_file_test (known_httpd_modules_locations[i], G_FILE_TEST_IS_DIR)) {
+			return g_strdup (known_httpd_modules_locations[i]);
+		}
+	}
+	return NULL;
+}
+
+static GRegex *version_regex = NULL;
+
+static char*
+get_httpd_config (const char *httpd_program)
+{
+	gchar *standard_output;
+	gchar *cmd_line;
+	GMatchInfo *match_info;
+	gchar *version_number = NULL;
+	gchar *config;
+
+	cmd_line = g_strdup_printf ("%s -v", httpd_program);
+	if (! g_spawn_command_line_sync (cmd_line, &standard_output, NULL, NULL, NULL)) {
+		g_free (cmd_line);
+		return NULL;
+	}
+	g_free (cmd_line);
+
+	if (version_regex == NULL) {
+		version_regex = g_regex_new ("\\d\\.\\d", 0, 0, NULL);
+	}
+
+	if (g_regex_match (version_regex, standard_output, 0, &match_info)) {
+		while (g_match_info_matches (match_info)) {
+			version_number = g_match_info_fetch (match_info, 0);
+			break;
+		}
+		g_match_info_free (match_info);
+		g_free (standard_output);
+	} else {
+		/* Failed to parse httpd version number */
+		g_warning ("Could not parse '%s' as a version for httpd", standard_output);
+		g_free (standard_output);
+		/* assume it is 2.2 */
+		version_number = g_strdup ("2.2");
+	}
+
+	config = g_strdup_printf (HTTPD_CONFIG_TEMPLATE, version_number);
+	g_free (version_number);
+
+	return config;
+}
+
+static gboolean
+spawn_httpd (int port, pid_t *pid_out)
+{
+	char *free1, *free2, *free3, *free4, *free5, *free6, *free7, *free8, *free9;
+	gboolean res;
+	char *argv[10];
+	char *env[10];
+	int i;
+	gint status;
+	char *pid_filename;
+	char *pidfile;
+	GError *error;
+	gboolean got_pidfile;
+	GSettings *settings;
+	char *str;
+	char *public_dir;
+
+	public_dir = lookup_public_dir ();
+	ensure_conf_dir ();
+
+	i = 0;
+	free1 = argv[i++] = get_httpd_program ();
+	if (argv[0] == NULL) {
+		fprintf (stderr, "error finding httpd server\n");
+		return FALSE;
+	}
+
+	argv[i++] = "-f";
+	free2 = argv[i++] = get_httpd_config (argv[0]);
+	argv[i++] = "-C";
+	free3 = argv[i++] = g_strdup_printf ("Listen %d", port);
+
+	settings = g_settings_new (GSETTINGS_SCHEMA);
+	str = g_settings_get_string (settings,
+				       FILE_SHARING_REQUIRE_PASSWORD);
+
+	if (str && strcmp (str, "never") == 0) {
+		/* Do nothing */
+	} else if (str && strcmp (str, "on_write") == 0){
+		argv[i++] = "-D";
+		argv[i++] = "RequirePasswordOnWrite";
+	} else {
+		/* always, or safe fallback */
+		argv[i++] = "-D";
+		argv[i++] = "RequirePasswordAlways";
+	}
+	g_free (str);
+	g_object_unref (settings);
+
+	argv[i] = NULL;
+
+	i = 0;
+	free4 = env[i++] = g_strdup_printf ("HOME=%s", g_get_home_dir());
+	free5 = env[i++] = g_strdup_printf ("XDG_PUBLICSHARE_DIR=%s", public_dir);
+	free6 = env[i++] = g_strdup_printf ("XDG_CONFIG_HOME=%s", g_get_user_config_dir ());
+	free7 = env[i++] = g_strdup_printf ("GUS_SHARE_NAME=%s", get_share_name ());
+	free8 = env[i++] = g_strdup_printf ("GUS_LOGIN_LABEL=%s", "Please log in as the user guest");
+	free9 = env[i++] = g_strdup_printf ("HTTP_MODULES_PATH=%s",get_httpd_modules_path ());
+	env[i++] = "LANG=C";
+	env[i] = NULL;
+
+	pid_filename = g_build_filename (g_get_user_config_dir (), "user-share", "pid", NULL);
+
+	/* Remove pid file before spawning to avoid races with child and old pidfile */
+	unlink (pid_filename);
+
+	error = NULL;
+	res = g_spawn_sync (g_get_home_dir(),
+			    argv, env, 0,
+			    httpd_child_setup, NULL,
+			    NULL, NULL,
+			    &status,
+			    &error);
+	g_free (free1);
+	g_free (free2);
+	g_free (free3);
+	g_free (free4);
+	g_free (free5);
+	g_free (free6);
+	g_free (free7);
+	g_free (free8);
+	g_free (free9);
+	g_free (public_dir);
+
+	if (!res) {
+		fprintf (stderr, "error spawning httpd: %s\n",
+			 error->message);
+		g_error_free (error);
+		g_free (pid_filename);
+		return FALSE;
+	}
+
+	if (status != 0) {
+		g_free (pid_filename);
+		return FALSE;
+	}
+
+	got_pidfile = FALSE;
+	error = NULL;
+	for (i = 0; i < 5; i++) {
+		if (error != NULL)
+			g_error_free (error);
+		error = NULL;
+		if (g_file_get_contents (pid_filename, &pidfile, NULL, &error)) {
+			got_pidfile = TRUE;
+			*pid_out = atoi (pidfile);
+			g_free (pidfile);
+			break;
+		}
+		sleep (1);
+	}
+
+	g_free (pid_filename);
+
+	if (!got_pidfile) {
+		fprintf (stderr, "error opening httpd pidfile: %s\n", error->message);
+		g_error_free (error);
+		return FALSE;
+	}
+	return TRUE;
+}
+
+static void
+kill_httpd (void)
+{
+	if (httpd_pid != 0) {
+		kill (httpd_pid, SIGTERM);
+
+		/* Allow child time to die, we can't waitpid, because its
+		   not a direct child */
+		sleep (1);
+	}
+	httpd_pid = 0;
+}
+
+void
+http_up (void)
+{
+	guint port;
+
+	port = get_port ();
+	if (!spawn_httpd (port, &httpd_pid)) {
+		fprintf (stderr, "spawning httpd failed\n");
+	}
+}
+
+void
+http_down (void)
+{
+	kill_httpd ();
+}
+
+gboolean
+http_init (void)
+{
+	return TRUE;
+}
+
+pid_t
+http_get_pid (void)
+{
+	return httpd_pid;
+}
+
+ +
+ +
+ + diff --git a/2023-09-19-100425-2309-cppcheck@72f91230a146_master/3.html b/2023-09-19-100425-2309-cppcheck@72f91230a146_master/3.html new file mode 100644 index 0000000..463b556 --- /dev/null +++ b/2023-09-19-100425-2309-cppcheck@72f91230a146_master/3.html @@ -0,0 +1,1357 @@ + + + + + + Cppcheck - HTML report - mate-user-share + + + + + +
+ + + +
+
  1
+  2
+  3
+  4
+  5
+  6
+  7
+  8
+  9
+ 10
+ 11
+ 12
+ 13
+ 14
+ 15
+ 16
+ 17
+ 18
+ 19
+ 20
+ 21
+ 22
+ 23
+ 24
+ 25
+ 26
+ 27
+ 28
+ 29
+ 30
+ 31
+ 32
+ 33
+ 34
+ 35
+ 36
+ 37
+ 38
+ 39
+ 40
+ 41
+ 42
+ 43
+ 44
+ 45
+ 46
+ 47
+ 48
+ 49
+ 50
+ 51
+ 52
+ 53
+ 54
+ 55
+ 56
+ 57
+ 58
+ 59
+ 60
+ 61
+ 62
+ 63
+ 64
+ 65
+ 66
+ 67
+ 68
+ 69
+ 70
+ 71
+ 72
+ 73
+ 74
+ 75
+ 76
+ 77
+ 78
+ 79
+ 80
+ 81
+ 82
+ 83
+ 84
+ 85
+ 86
+ 87
+ 88
+ 89
+ 90
+ 91
+ 92
+ 93
+ 94
+ 95
+ 96
+ 97
+ 98
+ 99
+100
+101
+102
+103
+104
+105
+106
+107
+108
+109
+110
+111
+112
+113
+114
+115
+116
+117
+118
+119
+120
+121
+122
+123
+124
+125
+126
+127
+128
+129
+130
+131
+132
+133
+134
+135
+136
+137
+138
+139
+140
+141
+142
+143
+144
+145
+146
+147
+148
+149
+150
+151
+152
+153
+154
+155
+156
+157
+158
+159
+160
+161
+162
+163
+164
+165
+166
+167
+168
+169
+170
+171
+172
+173
+174
+175
+176
+177
+178
+179
+180
+181
+182
+183
+184
+185
+186
+187
+188
+189
+190
+191
+192
+193
+194
+195
+196
+197
+198
+199
+200
+201
+202
+203
+204
+205
+206
+207
+208
+209
+210
+211
+212
+213
+214
+215
+216
+217
+218
+219
+220
+221
+222
+223
+224
+225
+226
+227
+228
+229
+230
+231
+232
+233
+234
+235
+236
+237
+238
+239
+240
+241
+242
+243
+244
+245
+246
+247
+248
+249
+250
+251
+252
+253
+254
+255
+256
+257
+258
+259
+260
+261
+262
+263
+264
+265
+266
+267
+268
+269
+270
+271
+272
+273
+274
+275
+276
+277
+278
+279
+280
+281
+282
+283
+284
+285
+286
+287
+288
+289
+290
+291
+292
+293
+294
+295
+296
+297
+298
+299
+300
+301
+302
+303
+304
+305
+306
+307
+308
+309
+310
+311
+312
+313
+314
+315
+316
+317
+318
+319
+320
+321
+322
+323
+324
+325
+326
+327
+328
+329
+330
+331
+332
+333
+334
+335
+336
+337
+338
+339
+340
+341
+342
+343
+344
+345
+346
+347
+348
+349
+350
+351
+352
+353
+354
+355
+356
+357
+358
+359
+360
+361
+362
+363
+364
+365
+366
+367
+368
+369
+370
+371
+372
+373
+374
+375
+376
+377
+378
+379
+380
+381
+382
+383
+384
+385
+386
+387
+388
+389
+390
+391
+392
+393
+394
+395
+396
+397
+398
+399
+400
+401
+402
+403
+404
+405
+406
+407
+408
+409
+410
+411
+412
+413
+414
+415
+416
+417
+418
+419
+420
+421
+422
+423
+424
+425
+426
+427
+428
+429
+430
+431
+432
+433
+434
+435
+436
+437
+438
+439
+440
+441
+442
+443
+444
+445
+446
+447
+448
+449
+450
+451
+452
+453
+454
+455
+456
+457
+458
+459
+460
+461
+462
+463
+464
+465
+466
+467
+468
+469
+470
+471
+472
+473
+474
+475
+476
+477
+478
+479
+480
+481
+482
+483
+484
+485
+486
+487
+488
+489
+490
+491
+492
+493
+494
+495
+496
+497
+498
+499
+500
+501
+502
+503
+504
+505
+506
+507
+508
+509
+510
+511
+512
+513
+514
+515
+516
+517
+518
+519
+520
+521
+522
+523
+524
+525
+526
+527
+528
+529
+530
+531
+532
+533
+534
+535
+536
+537
+538
+539
+540
+541
+542
+543
+544
+545
+546
+547
+548
+549
+550
+551
+552
+553
+554
+555
+556
+557
+558
+559
+560
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
+
+/*
+ *  Copyright (C) 2004-2008 Red Hat, Inc.
+ *  Copyright (C) 2012-2021 MATE Developers
+ *
+ *  Caja is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU General Public License as
+ *  published by the Free Software Foundation; either version 2 of the
+ *  License, or (at your option) any later version.
+ *
+ *  Caja is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  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
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ *  Authors: Bastien Nocera <hadess@hadess.net>
+ *
+ */
+
+#include "config.h"
+
+#include <glib.h>
+#include <glib/gi18n.h>
+#include <gio/gio.h>
+#include <gdk/gdk.h>
+#include <gtk/gtk.h>
+#include <libnotify/notify.h>
+#include <dbus/dbus-glib.h>
+#include <dbus/dbus-glib-lowlevel.h>
+#include <canberra-gtk.h>
+
+#include <string.h>
+
+#include "marshal.h"
+#include "obexpush.h"
+#include "user_share-common.h"
+#include "user_share-private.h"
+
+#define DBUS_TYPE_G_STRING_VARIANT_HASHTABLE (dbus_g_type_get_map ("GHashTable", G_TYPE_STRING, G_TYPE_STRING))
+
+#define GSETTINGS_SCHEMA "org.mate.FileSharing"
+
+static DBusGConnection *connection = NULL;<--- Shadowed declaration
+static DBusGProxy *manager_proxy = NULL;
+static DBusGProxy *server_proxy = NULL;
+static AcceptSetting accept_setting = -1;
+static gboolean show_notifications = FALSE;
+
+static GtkStatusIcon *statusicon = NULL;
+static guint num_notifications = 0;
+
+static void
+hide_statusicon (void)
+{
+	num_notifications--;
+	if (num_notifications == 0)
+		gtk_status_icon_set_visible (statusicon, FALSE);
+}
+
+static void
+on_close_notification (NotifyNotification *notification)
+{
+	hide_statusicon ();
+	g_object_unref (notification);
+}
+
+static void
+notification_launch_action_on_file_cb (NotifyNotification *notification,
+				       const char *action,
+				       const char *file_uri)
+{
+	GdkScreen *screen;
+	GAppLaunchContext *ctx;
+	GTimeVal val;
+
+	g_assert (action != NULL);
+
+	g_get_current_time (&val);
+
+	ctx = G_APP_LAUNCH_CONTEXT (gdk_app_launch_context_new ());
+	screen = gdk_screen_get_default ();
+	gdk_app_launch_context_set_screen (GDK_APP_LAUNCH_CONTEXT (ctx), screen);
+	gdk_app_launch_context_set_timestamp (GDK_APP_LAUNCH_CONTEXT (ctx), val.tv_sec);
+
+	/* We launch the file viewer for the file */
+	if (g_str_equal (action, "display") != FALSE) {
+		if (g_app_info_launch_default_for_uri (file_uri, ctx, NULL) == FALSE) {
+			g_warning ("Failed to launch the file viewer\n");
+		}
+	}
+
+	/* we open the Downloads folder */
+	if (g_str_equal (action, "reveal") != FALSE) {
+		GFile *file;
+		GFile *parent;
+		gchar *parent_uri;
+
+		file = g_file_new_for_uri (file_uri);
+		parent = g_file_get_parent (file);
+		parent_uri = g_file_get_uri (parent);
+		g_object_unref (file);
+		g_object_unref (parent);
+
+		if (!g_app_info_launch_default_for_uri (parent_uri, ctx, NULL)) {
+			g_warning ("Failed to launch the file manager\n");
+		}
+
+		g_free (parent_uri);
+	}
+
+	notify_notification_close (notification, NULL);
+	/* No need to call hide_statusicon(), closing the notification
+	 * will call the close callback */
+}
+
+static void
+show_notification (const char *filename)
+{
+	char *file_uri, *notification_text, *display, *mime_type;
+	NotifyNotification *notification;
+	ca_context *ctx;
+	GAppInfo *app;
+
+	file_uri = g_filename_to_uri (filename, NULL, NULL);
+	if (file_uri == NULL) {
+		g_warning ("Could not make a filename from '%s'", filename);
+		return;
+	}
+
+	display = g_filename_display_basename (filename);
+	/* Translators: %s is the name of the filename received */
+	notification_text = g_strdup_printf(_("You received \"%s\" via Bluetooth"), display);
+	g_free (display);
+	notification = notify_notification_new (_("You received a file"),
+								 notification_text,
+								 "dialog-information");
+
+	notify_notification_set_timeout (notification, NOTIFY_EXPIRES_DEFAULT);
+
+	mime_type = g_content_type_guess (filename, NULL, 0, NULL);
+	app = g_app_info_get_default_for_type (mime_type, FALSE);
+	if (app != NULL) {
+		g_object_unref (app);
+		notify_notification_add_action (notification, "display", _("Open File"),
+						(NotifyActionCallback) notification_launch_action_on_file_cb,
+						g_strdup (file_uri), (GFreeFunc) g_free);
+	}
+	notify_notification_add_action (notification, "reveal", _("Reveal File"),
+					(NotifyActionCallback) notification_launch_action_on_file_cb,
+					g_strdup (file_uri), (GFreeFunc) g_free);
+
+	g_free (file_uri);
+
+	g_signal_connect (G_OBJECT (notification), "closed", G_CALLBACK (on_close_notification), notification);
+
+	if (!notify_notification_show (notification, NULL)) {
+		g_warning ("failed to send notification\n");
+	}
+	g_free (notification_text);
+
+	/* Now we do the audio notification */
+	ctx = ca_gtk_context_get ();
+	ca_context_play (ctx, 0,
+			 CA_PROP_EVENT_ID, "complete-download",
+			 CA_PROP_EVENT_DESCRIPTION, _("File reception complete"),
+			 NULL);
+}
+
+static void
+show_icon (void)
+{
+	if (statusicon == NULL) {
+		statusicon = gtk_status_icon_new_from_icon_name ("mate-obex-server");
+	} else {
+		gtk_status_icon_set_visible (statusicon, TRUE);
+	}
+	num_notifications++;
+}
+
+static gboolean
+device_is_authorised (const char *bdaddr)
+{
+	DBusGConnection *connection;<--- Shadow variable
+	DBusGProxy *manager;
+	GError *error = NULL;
+	GPtrArray *adapters;
+	gboolean retval = FALSE;
+	guint i;
+
+	connection = dbus_g_bus_get (DBUS_BUS_SYSTEM, NULL);
+	if (connection == NULL)
+		return FALSE;
+
+	manager = dbus_g_proxy_new_for_name (connection, "org.bluez",
+					     "/", "org.bluez.Manager");
+	if (manager == NULL) {
+		dbus_g_connection_unref (connection);
+		return FALSE;
+	}
+
+	if (dbus_g_proxy_call (manager, "ListAdapters", &error, G_TYPE_INVALID, dbus_g_type_get_collection ("GPtrArray", DBUS_TYPE_G_OBJECT_PATH), &adapters, G_TYPE_INVALID) == FALSE) {
+		g_object_unref (manager);
+		dbus_g_connection_unref (connection);
+		return FALSE;
+	}
+
+	for (i = 0; i < adapters->len; i++) {
+		DBusGProxy *adapter, *device;
+		char *device_path;
+		GHashTable *props;
+
+		g_debug ("checking adapter %s", (gchar *) g_ptr_array_index (adapters, i));
+
+		adapter = dbus_g_proxy_new_for_name (connection, "org.bluez",
+						    g_ptr_array_index (adapters, i), "org.bluez.Adapter");
+
+		if (dbus_g_proxy_call (adapter, "FindDevice", NULL,
+				       G_TYPE_STRING, bdaddr, G_TYPE_INVALID,
+				       DBUS_TYPE_G_OBJECT_PATH, &device_path, G_TYPE_INVALID) == FALSE)
+		{
+			g_object_unref (adapter);
+			continue;
+		}
+
+		device = dbus_g_proxy_new_for_name (connection, "org.bluez", device_path, "org.bluez.Device");
+
+		if (dbus_g_proxy_call (device, "GetProperties", NULL,
+				       G_TYPE_INVALID, dbus_g_type_get_map ("GHashTable", G_TYPE_STRING, G_TYPE_VALUE),
+				       &props, G_TYPE_INVALID) != FALSE)
+		{
+			GValue *value;
+			gboolean bonded;
+
+			value = g_hash_table_lookup (props, "Paired");
+			bonded = g_value_get_boolean (value);
+			g_message ("%s is %s", bdaddr, bonded ? "bonded" : "not bonded");
+
+			if (bonded) {
+				g_hash_table_destroy (props);
+				g_object_unref (device);
+				g_object_unref (adapter);
+				retval = TRUE;
+				break;
+			}
+		}
+		g_object_unref(adapter);
+	}
+
+	g_ptr_array_free (adapters, TRUE);
+
+	g_object_unref(manager);
+	dbus_g_connection_unref(connection);
+
+	return retval;
+}
+
+static void
+transfer_started_cb (DBusGProxy *session,
+		     const char *filename,
+		     const char *local_path,
+		     guint64 size,
+		     gpointer user_data)
+{
+	GHashTable *dict;
+	DBusGProxy *server = (DBusGProxy *) user_data;
+	GError *error = NULL;
+	gboolean authorise;
+
+	g_message ("transfer started on %s", local_path);
+	g_object_set_data_full (G_OBJECT (session), "filename", g_strdup (local_path), (GDestroyNotify) g_free);
+
+	show_icon ();
+
+	/* First transfer of the session */
+	if (g_object_get_data (G_OBJECT (session), "bdaddr") == NULL) {
+		const char *bdaddr;
+
+		if (dbus_g_proxy_call (server, "GetServerSessionInfo", &error,
+				       DBUS_TYPE_G_OBJECT_PATH, dbus_g_proxy_get_path (session), G_TYPE_INVALID,
+				       DBUS_TYPE_G_STRING_VARIANT_HASHTABLE, &dict, G_TYPE_INVALID) == FALSE) {
+			g_printerr ("Getting Server session info failed: %s\n",
+				    error->message);
+			g_error_free (error);
+			return;
+		}
+
+		bdaddr = g_hash_table_lookup (dict, "BluetoothAddress");
+		g_message ("transfer started for device %s", bdaddr);
+
+		g_object_set_data_full (G_OBJECT (session), "bdaddr", g_strdup (bdaddr), (GDestroyNotify) g_free);
+		/* Initial accept method is undefined, we do that lower down */
+		g_object_set_data (G_OBJECT (session), "accept-method", GINT_TO_POINTER (-1));
+		g_hash_table_destroy (dict);
+	}
+
+	/* Accept method changed */
+	if (GPOINTER_TO_INT (g_object_get_data (G_OBJECT (session), "accept-method")) != accept_setting) {
+		const char *bdaddr;
+
+		bdaddr = g_object_get_data (G_OBJECT (session), "bdaddr");
+
+		if (bdaddr == NULL) {
+			g_warning ("Couldn't get the Bluetooth address for the device, rejecting the transfer");
+			authorise = FALSE;
+		} else if (accept_setting == ACCEPT_ALWAYS) {
+			authorise = TRUE;
+		} else if (accept_setting == ACCEPT_BONDED) {
+			authorise = device_is_authorised (bdaddr);
+		} else {
+			//FIXME implement
+			g_warning ("\"Ask\" authorisation method not implemented");
+			authorise = FALSE;
+		}
+		g_object_set_data (G_OBJECT (session), "authorise", GINT_TO_POINTER (authorise));
+	}
+
+	g_message ("accept_setting: %d", accept_setting);
+
+	authorise = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (session), "authorise"));
+	if (authorise != FALSE) {
+		if (dbus_g_proxy_call (session, "Accept", &error, G_TYPE_INVALID, G_TYPE_INVALID) == FALSE) {
+			g_printerr ("Failed to accept file transfer: %s\n", error->message);
+			g_error_free (error);
+			return;
+		}
+		g_message ("authorised transfer");
+	} else {
+		if (dbus_g_proxy_call (session, "Reject", &error, G_TYPE_INVALID, G_TYPE_INVALID) == FALSE) {
+			g_printerr ("Failed to reject file transfer: %s\n", error->message);
+			g_error_free (error);
+			return;
+		}
+		g_message ("rejected transfer");
+		g_object_set_data (G_OBJECT (session), "filename", NULL);
+	}
+}
+
+static void
+transfer_completed_cb (DBusGProxy *session,
+		       gpointer user_data)
+{
+	GSettings *settings;
+	gboolean display_notify;
+	const char *filename;
+
+	filename = (const char *) g_object_get_data (G_OBJECT (session), "filename");
+
+	g_message ("file finish transfer: %s", filename);
+
+	if (filename == NULL)
+		return;
+
+	settings = g_settings_new (GSETTINGS_SCHEMA);
+	display_notify = g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_OBEXPUSH_NOTIFY);
+	g_object_unref (settings);
+
+	if (display_notify) {
+		show_notification (filename);
+	} else {
+		hide_statusicon ();
+	}
+	g_object_set_data (G_OBJECT (session), "filename", NULL);
+}
+
+static void
+cancelled_cb (DBusGProxy *session,
+	      gpointer user_data)
+{
+	//FIXME implement properly, we never actually finished the transfer
+	g_message ("transfered was cancelled by the sender");
+	transfer_completed_cb (session, user_data);
+	hide_statusicon ();
+}
+
+static void
+error_occurred_cb (DBusGProxy *session,
+		   const char *error_name,
+		   const char *error_message,
+		   gpointer user_data)
+{
+	//FIXME implement properly
+	g_message ("transfer error occurred: %s", error_message);
+	transfer_completed_cb (session, user_data);
+}
+
+static void
+session_created_cb (DBusGProxy *server, const char *session_path, gpointer user_data)
+{
+	DBusGProxy *session;
+
+	session = dbus_g_proxy_new_for_name (connection,
+					     "org.openobex",
+					     session_path,
+					     "org.openobex.ServerSession");
+
+	dbus_g_proxy_add_signal (session, "TransferStarted",
+				 G_TYPE_STRING, G_TYPE_STRING, G_TYPE_UINT64, G_TYPE_INVALID);
+	dbus_g_proxy_connect_signal(session, "TransferStarted",
+				    G_CALLBACK (transfer_started_cb), server, NULL);
+	dbus_g_proxy_add_signal (session, "TransferCompleted",
+				 G_TYPE_INVALID, G_TYPE_INVALID);
+	dbus_g_proxy_connect_signal(session, "TransferCompleted",
+				    G_CALLBACK (transfer_completed_cb), server, NULL);
+	dbus_g_proxy_add_signal (session, "Cancelled",
+				 G_TYPE_INVALID, G_TYPE_INVALID);
+	dbus_g_proxy_connect_signal(session, "Cancelled",
+				    G_CALLBACK (cancelled_cb), server, NULL);
+	dbus_g_proxy_add_signal (session, "ErrorOccurred",
+				 G_TYPE_INVALID, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INVALID);
+	dbus_g_proxy_connect_signal(session, "ErrorOccurred",
+				    G_CALLBACK (error_occurred_cb), server, NULL);
+}
+
+void
+obexpush_up (void)
+{
+	GError *err = NULL;
+	char *download_dir, *server;
+
+	server = NULL;
+	if (manager_proxy == NULL) {
+		manager_proxy = dbus_g_proxy_new_for_name (connection,
+							   "org.openobex",
+							   "/org/openobex",
+							   "org.openobex.Manager");
+		if (dbus_g_proxy_call (manager_proxy, "CreateBluetoothServer",
+				       &err, G_TYPE_STRING, "00:00:00:00:00:00", G_TYPE_STRING, "opp", G_TYPE_BOOLEAN, FALSE, G_TYPE_INVALID,
+				       DBUS_TYPE_G_OBJECT_PATH, &server, G_TYPE_INVALID) == FALSE) {
+			g_printerr ("Creating Bluetooth ObexPush server failed: %s\n",
+				    err->message);
+			g_error_free (err);
+			g_object_unref (manager_proxy);
+			manager_proxy = NULL;
+			return;
+		}
+	}
+
+	download_dir = lookup_download_dir ();
+
+	if (server_proxy == NULL) {
+		server_proxy = dbus_g_proxy_new_for_name (connection,
+							   "org.openobex",
+							   server,
+							   "org.openobex.Server");
+		g_free (server);
+
+		dbus_g_proxy_add_signal (server_proxy, "SessionCreated",
+					 DBUS_TYPE_G_OBJECT_PATH, G_TYPE_INVALID);
+		dbus_g_proxy_connect_signal(server_proxy, "SessionCreated",
+					    G_CALLBACK (session_created_cb), NULL, NULL);
+	}
+
+	if (dbus_g_proxy_call (server_proxy, "Start", &err,
+			   G_TYPE_STRING, download_dir, G_TYPE_BOOLEAN, TRUE, G_TYPE_BOOLEAN, FALSE, G_TYPE_INVALID,
+			   G_TYPE_INVALID) == FALSE) {
+		if (g_error_matches (err, DBUS_GERROR, DBUS_GERROR_REMOTE_EXCEPTION) != FALSE &&
+		    dbus_g_error_has_name (err, "org.openobex.Error.Started") != FALSE) {
+		    	g_error_free (err);
+		    	g_message ("already started, ignoring error");
+		    	g_free (download_dir);
+		    	return;
+		}
+		g_printerr ("Starting Bluetooth ObexPush server failed: %s\n",
+			    err->message);
+		g_error_free (err);
+		g_free (download_dir);
+		g_object_unref (server_proxy);
+		server_proxy = NULL;
+		g_object_unref (manager_proxy);
+		manager_proxy = NULL;
+		return;
+	}
+
+	g_free (download_dir);
+}
+
+static void
+obexpush_stop (gboolean stop_manager)
+{
+	GError *err = NULL;
+
+	if (server_proxy == NULL)
+		return;
+
+	if (dbus_g_proxy_call (server_proxy, "Close", &err, G_TYPE_INVALID, G_TYPE_INVALID) == FALSE) {
+		if (g_error_matches (err, DBUS_GERROR, DBUS_GERROR_REMOTE_EXCEPTION) == FALSE ||
+		    dbus_g_error_has_name (err, "org.openobex.Error.NotStarted") == FALSE) {
+			g_printerr ("Stopping Bluetooth ObexPush server failed: %s\n",
+				    err->message);
+			g_error_free (err);
+			return;
+		}
+		g_error_free (err);
+	}
+
+	if (stop_manager != FALSE) {
+		g_object_unref (server_proxy);
+		server_proxy = NULL;
+		g_object_unref (manager_proxy);
+		manager_proxy = NULL;
+	}
+
+	//FIXME stop all the notifications
+}
+
+void
+obexpush_down (void)
+{
+	obexpush_stop (TRUE);
+}
+
+void
+obexpush_restart (void)
+{
+	obexpush_stop (FALSE);
+	obexpush_up ();
+}
+
+gboolean
+obexpush_init (void)
+{
+	GError *err = NULL;
+
+	connection = dbus_g_bus_get (DBUS_BUS_SESSION, &err);
+	if (connection == NULL) {
+		g_printerr ("Connecting to session bus failed: %s\n",
+			    err->message);
+		g_error_free (err);
+		return FALSE;
+	}
+
+	dbus_g_object_register_marshaller (marshal_VOID__STRING_STRING_UINT64,
+					   G_TYPE_NONE,
+					   G_TYPE_STRING, G_TYPE_STRING, G_TYPE_UINT64, G_TYPE_INVALID);
+
+	if (!notify_init("mate-user-share")) {
+		g_warning("Unable to initialize the notification system\n");
+        }
+
+	dbus_connection_set_exit_on_disconnect (dbus_g_connection_get_connection (connection), FALSE);
+
+	return TRUE;
+}
+
+void
+obexpush_set_accept_files_policy (AcceptSetting setting)
+{
+	accept_setting = setting;
+}
+
+void
+obexpush_set_notify (gboolean enabled)
+{
+	show_notifications = enabled;
+}
+
+ +
+ +
+ + diff --git a/2023-09-19-100425-2309-cppcheck@72f91230a146_master/4.html b/2023-09-19-100425-2309-cppcheck@72f91230a146_master/4.html new file mode 100644 index 0000000..7664cf7 --- /dev/null +++ b/2023-09-19-100425-2309-cppcheck@72f91230a146_master/4.html @@ -0,0 +1,833 @@ + + + + + + Cppcheck - HTML report - mate-user-share + + + + + +
+ + + +
+
  1
+  2
+  3
+  4
+  5
+  6
+  7
+  8
+  9
+ 10
+ 11
+ 12
+ 13
+ 14
+ 15
+ 16
+ 17
+ 18
+ 19
+ 20
+ 21
+ 22
+ 23
+ 24
+ 25
+ 26
+ 27
+ 28
+ 29
+ 30
+ 31
+ 32
+ 33
+ 34
+ 35
+ 36
+ 37
+ 38
+ 39
+ 40
+ 41
+ 42
+ 43
+ 44
+ 45
+ 46
+ 47
+ 48
+ 49
+ 50
+ 51
+ 52
+ 53
+ 54
+ 55
+ 56
+ 57
+ 58
+ 59
+ 60
+ 61
+ 62
+ 63
+ 64
+ 65
+ 66
+ 67
+ 68
+ 69
+ 70
+ 71
+ 72
+ 73
+ 74
+ 75
+ 76
+ 77
+ 78
+ 79
+ 80
+ 81
+ 82
+ 83
+ 84
+ 85
+ 86
+ 87
+ 88
+ 89
+ 90
+ 91
+ 92
+ 93
+ 94
+ 95
+ 96
+ 97
+ 98
+ 99
+100
+101
+102
+103
+104
+105
+106
+107
+108
+109
+110
+111
+112
+113
+114
+115
+116
+117
+118
+119
+120
+121
+122
+123
+124
+125
+126
+127
+128
+129
+130
+131
+132
+133
+134
+135
+136
+137
+138
+139
+140
+141
+142
+143
+144
+145
+146
+147
+148
+149
+150
+151
+152
+153
+154
+155
+156
+157
+158
+159
+160
+161
+162
+163
+164
+165
+166
+167
+168
+169
+170
+171
+172
+173
+174
+175
+176
+177
+178
+179
+180
+181
+182
+183
+184
+185
+186
+187
+188
+189
+190
+191
+192
+193
+194
+195
+196
+197
+198
+199
+200
+201
+202
+203
+204
+205
+206
+207
+208
+209
+210
+211
+212
+213
+214
+215
+216
+217
+218
+219
+220
+221
+222
+223
+224
+225
+226
+227
+228
+229
+230
+231
+232
+233
+234
+235
+236
+237
+238
+239
+240
+241
+242
+243
+244
+245
+246
+247
+248
+249
+250
+251
+252
+253
+254
+255
+256
+257
+258
+259
+260
+261
+262
+263
+264
+265
+266
+267
+268
+269
+270
+271
+272
+273
+274
+275
+276
+277
+278
+279
+280
+281
+282
+283
+284
+285
+286
+287
+288
+289
+290
+291
+292
/* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 8; tab-width: 8 -*-
+ *
+ * Copyright (C) 2003 Novell, Inc.
+ * Copyright (C) 2003-2004 Red Hat, Inc.
+ * Copyright (C) 2005 William Jon McCann <mccann@jhu.edu>
+ * Copyright (C) 2012-2021 MATE Developers
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * 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 Foundation, Inc., 51 Franklin St, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ *
+ */
+
+#include "config.h"
+
+#include <stdlib.h>
+#include <string.h>
+#include <glib/gi18n-lib.h>
+#include <gtk/gtk.h>
+#include <libcaja-extension/caja-menu-provider.h>
+#include <libcaja-extension/caja-location-widget-provider.h>
+
+#ifdef HAVE_BLUETOOTH
+#include <bluetooth-client.h>
+#endif
+
+#include "caja-share-bar.h"
+#include "user_share-common.h"
+
+#define CAJA_TYPE_USER_SHARE  (caja_user_share_get_type ())
+#define CAJA_USER_SHARE(o)    (G_TYPE_CHECK_INSTANCE_CAST ((o), CAJA_TYPE_USER_SHARE, CajaUserShare))
+#define CAJA_IS_USER_SHARE(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), CAJA_TYPE_USER_SHARE))
+
+typedef struct
+{
+        GObject              parent_slot;
+} CajaUserShare;
+
+typedef struct
+{
+        GObjectClass parent_slot;
+} CajaUserShareClass;
+
+static GType caja_user_share_get_type      (void);
+static void  caja_user_share_register_type (GTypeModule *module);
+
+static void
+launch_process (char **argv, GtkWindow *parent)
+{
+        GError *error;
+        GtkWidget *dialog;
+
+        error = NULL;
+        if (!g_spawn_async (NULL,
+                            argv, NULL,
+                            0,
+                            NULL, NULL,
+                            NULL,
+                            &error)) {
+
+
+                dialog = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL, GTK_MESSAGE_WARNING,
+						 GTK_BUTTONS_OK, _("Unable to launch the Personal File Sharing preferences"));
+
+                gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog), "%s", error->message);
+
+                gtk_dialog_run (GTK_DIALOG (dialog));
+                gtk_widget_destroy (dialog);
+
+                g_error_free (error);
+        }
+}
+
+static void
+launch_prefs_on_window (GtkWindow *window)
+{
+        char *argv [2];
+
+        argv [0] = g_build_filename (BINDIR, "mate-file-share-properties", NULL);
+        argv [1] = NULL;
+
+        launch_process (argv, window);
+
+        g_free (argv [0]);
+}
+
+static void
+bar_response_cb (CajaShareBar *bar,
+                 gint response,
+                 gpointer         data)
+{
+        if (response == CAJA_SHARE_BAR_RESPONSE_PREFERENCES) {
+                launch_prefs_on_window (GTK_WINDOW (data));
+        }
+}
+
+#ifdef HAVE_BLUETOOTH
+static void
+downloads_bar_set_from_bluetooth_status (GtkWidget *bar)
+{
+	BluetoothClient *client;
+	gboolean bt_powered;
+
+	client = g_object_get_data (G_OBJECT (bar), "bluetooth-client");
+	g_object_get (G_OBJECT (client),
+		      "default-adapter-powered", &bt_powered,
+		      NULL);
+	gtk_widget_set_visible (bar, bt_powered);
+}
+
+static void
+default_adapter_powered_cb (GObject    *gobject,
+			    GParamSpec *pspec,
+			    GtkWidget  *bar)
+{
+	downloads_bar_set_from_bluetooth_status (bar);
+}
+#endif /* HAVE_BLUETOOTH */
+
+static GtkWidget *
+caja_user_share_get_location_widget (CajaLocationWidgetProvider *iface,
+                                         const char                     *uri,
+                                         GtkWidget                      *window)
+{
+	GFile             *file;
+	GtkWidget         *bar;
+	guint              i;
+	gboolean           enable = FALSE;
+	GFile             *home;
+#ifdef HAVE_BLUETOOTH
+	const GUserDirectory special_dirs[] = { G_USER_DIRECTORY_PUBLIC_SHARE, G_USER_DIRECTORY_DOWNLOAD };
+
+	gboolean is_dir[] = { FALSE, FALSE };
+#else
+	const GUserDirectory special_dirs[] = { G_USER_DIRECTORY_PUBLIC_SHARE };
+
+	gboolean is_dir[] = { FALSE };
+#endif /* HAVE_BLUETOOTH */
+	file = g_file_new_for_uri (uri);
+	home = g_file_new_for_path (g_get_home_dir ());
+
+	/* We don't show anything in $HOME */
+	if (g_file_equal (home, file)) {
+		g_object_unref (home);
+		g_object_unref (file);
+		return NULL;
+	}
+
+	g_object_unref (home);
+
+	for (i = 0; i < G_N_ELEMENTS (special_dirs); i++) {
+		GFile *dir;
+		dir = lookup_dir_with_fallback (special_dirs[i]);
+		if (g_file_equal (dir, file)) {
+			enable = TRUE;
+			is_dir[i] = TRUE;
+		}
+		g_object_unref (dir);
+	}
+
+	g_object_unref (file);
+
+	if (enable == FALSE)
+		return NULL;
+
+	if (is_dir[0] != FALSE) {
+#ifdef HAVE_BLUETOOTH
+		if (is_dir[1] != FALSE) {
+			bar = caja_share_bar_new (_("May be used to share or receive files"));
+		} else {
+			bar = caja_share_bar_new (_("May be shared over the network or Bluetooth"));
+		}
+#else
+		bar = caja_share_bar_new (_("May be shared over the network"));
+#endif /* HAVE_BLUETOOTH */
+	} else {
+#ifdef HAVE_BLUETOOTH
+		BluetoothClient *client;
+
+		bar = caja_share_bar_new (_("May be used to receive files over Bluetooth"));
+
+		gtk_widget_set_no_show_all (bar, TRUE);
+		client = bluetooth_client_new ();
+		g_object_set_data_full (G_OBJECT (bar), "bluetooth-client", client, g_object_unref);
+		g_signal_connect (G_OBJECT (client), "notify::default-adapter-powered",
+				  G_CALLBACK (default_adapter_powered_cb), bar);
+		downloads_bar_set_from_bluetooth_status (bar);
+#endif /* HAVE_BLUETOOTH */
+	}
+
+	g_signal_connect (bar, "response",
+			  G_CALLBACK (bar_response_cb),
+			  window);
+
+	gtk_widget_show_all (bar);
+
+	return bar;
+}
+
+static void
+caja_user_share_location_widget_provider_iface_init (CajaLocationWidgetProviderIface *iface)
+{
+        iface->get_widget = caja_user_share_get_location_widget;
+}
+
+static void
+caja_user_share_instance_init (CajaUserShare *share)
+{
+
+}
+
+static void
+caja_user_share_class_init (CajaUserShareClass *klass)
+{
+
+}
+
+static GType share_type = 0;
+
+static GType
+caja_user_share_get_type (void)
+{
+        return share_type;
+}
+
+static void
+caja_user_share_register_type (GTypeModule *module)
+{
+        static const GTypeInfo info = {
+                sizeof (CajaUserShareClass),
+                (GBaseInitFunc) NULL,
+                (GBaseFinalizeFunc) NULL,
+                (GClassInitFunc) caja_user_share_class_init,
+                NULL,
+                NULL,
+                sizeof (CajaUserShare),
+                0,
+                (GInstanceInitFunc) caja_user_share_instance_init,
+        };
+
+        static const GInterfaceInfo location_widget_provider_iface_info = {
+                (GInterfaceInitFunc) caja_user_share_location_widget_provider_iface_init,
+                NULL,
+                NULL
+        };
+
+        share_type = g_type_module_register_type (module,
+                                                 G_TYPE_OBJECT,
+                                                 "CajaUserShare",
+                                                 &info, 0);
+
+        g_type_module_add_interface (module,
+                                     share_type,
+                                     CAJA_TYPE_LOCATION_WIDGET_PROVIDER,
+                                     &location_widget_provider_iface_info);
+}
+
+void
+caja_module_initialize (GTypeModule *module)
+{
+        caja_user_share_register_type (module);
+        bindtextdomain (GETTEXT_PACKAGE, MATELOCALEDIR);
+        bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
+}
+
+void
+caja_module_shutdown (void)
+{
+}
+
+void
+caja_module_list_types (const GType **types,
+                            int          *num_types)
+{
+        static GType type_list [1];
+
+        type_list[0] = CAJA_TYPE_USER_SHARE;
+
+        *types = type_list;
+        *num_types = 1;
+}
+
+ +
+ +
+ + diff --git a/2023-09-19-100425-2309-cppcheck@72f91230a146_master/5.html b/2023-09-19-100425-2309-cppcheck@72f91230a146_master/5.html new file mode 100644 index 0000000..f850c86 --- /dev/null +++ b/2023-09-19-100425-2309-cppcheck@72f91230a146_master/5.html @@ -0,0 +1,1251 @@ + + + + + + Cppcheck - HTML report - mate-user-share + + + + + +
+ + + +
+
  1
+  2
+  3
+  4
+  5
+  6
+  7
+  8
+  9
+ 10
+ 11
+ 12
+ 13
+ 14
+ 15
+ 16
+ 17
+ 18
+ 19
+ 20
+ 21
+ 22
+ 23
+ 24
+ 25
+ 26
+ 27
+ 28
+ 29
+ 30
+ 31
+ 32
+ 33
+ 34
+ 35
+ 36
+ 37
+ 38
+ 39
+ 40
+ 41
+ 42
+ 43
+ 44
+ 45
+ 46
+ 47
+ 48
+ 49
+ 50
+ 51
+ 52
+ 53
+ 54
+ 55
+ 56
+ 57
+ 58
+ 59
+ 60
+ 61
+ 62
+ 63
+ 64
+ 65
+ 66
+ 67
+ 68
+ 69
+ 70
+ 71
+ 72
+ 73
+ 74
+ 75
+ 76
+ 77
+ 78
+ 79
+ 80
+ 81
+ 82
+ 83
+ 84
+ 85
+ 86
+ 87
+ 88
+ 89
+ 90
+ 91
+ 92
+ 93
+ 94
+ 95
+ 96
+ 97
+ 98
+ 99
+100
+101
+102
+103
+104
+105
+106
+107
+108
+109
+110
+111
+112
+113
+114
+115
+116
+117
+118
+119
+120
+121
+122
+123
+124
+125
+126
+127
+128
+129
+130
+131
+132
+133
+134
+135
+136
+137
+138
+139
+140
+141
+142
+143
+144
+145
+146
+147
+148
+149
+150
+151
+152
+153
+154
+155
+156
+157
+158
+159
+160
+161
+162
+163
+164
+165
+166
+167
+168
+169
+170
+171
+172
+173
+174
+175
+176
+177
+178
+179
+180
+181
+182
+183
+184
+185
+186
+187
+188
+189
+190
+191
+192
+193
+194
+195
+196
+197
+198
+199
+200
+201
+202
+203
+204
+205
+206
+207
+208
+209
+210
+211
+212
+213
+214
+215
+216
+217
+218
+219
+220
+221
+222
+223
+224
+225
+226
+227
+228
+229
+230
+231
+232
+233
+234
+235
+236
+237
+238
+239
+240
+241
+242
+243
+244
+245
+246
+247
+248
+249
+250
+251
+252
+253
+254
+255
+256
+257
+258
+259
+260
+261
+262
+263
+264
+265
+266
+267
+268
+269
+270
+271
+272
+273
+274
+275
+276
+277
+278
+279
+280
+281
+282
+283
+284
+285
+286
+287
+288
+289
+290
+291
+292
+293
+294
+295
+296
+297
+298
+299
+300
+301
+302
+303
+304
+305
+306
+307
+308
+309
+310
+311
+312
+313
+314
+315
+316
+317
+318
+319
+320
+321
+322
+323
+324
+325
+326
+327
+328
+329
+330
+331
+332
+333
+334
+335
+336
+337
+338
+339
+340
+341
+342
+343
+344
+345
+346
+347
+348
+349
+350
+351
+352
+353
+354
+355
+356
+357
+358
+359
+360
+361
+362
+363
+364
+365
+366
+367
+368
+369
+370
+371
+372
+373
+374
+375
+376
+377
+378
+379
+380
+381
+382
+383
+384
+385
+386
+387
+388
+389
+390
+391
+392
+393
+394
+395
+396
+397
+398
+399
+400
+401
+402
+403
+404
+405
+406
+407
+408
+409
+410
+411
+412
+413
+414
+415
+416
+417
+418
+419
+420
+421
+422
+423
+424
+425
+426
+427
+428
+429
+430
+431
+432
+433
+434
+435
+436
+437
+438
+439
+440
+441
+442
+443
+444
+445
+446
+447
+448
+449
+450
+451
+452
+453
+454
+455
+456
+457
+458
+459
+460
+461
+462
+463
+464
+465
+466
+467
+468
+469
+470
+471
+472
+473
+474
+475
+476
+477
+478
+479
+480
+481
+482
+483
+484
+485
+486
+487
+488
+489
+490
+491
+492
+493
+494
+495
+496
+497
+498
+499
+500
+501
+502
+503
+504
+505
+506
+507
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
+
+/*
+ *  Copyright (C) 2004-2008 Red Hat, Inc.
+ *  Copyright (C) 2012-2021 MATE Developers
+ *
+ *  Caja is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU General Public License as
+ *  published by the Free Software Foundation; either version 2 of the
+ *  License, or (at your option) any later version.
+ *
+ *  Caja is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  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
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ *  Authors: Alexander Larsson <alexl@redhat.com>
+ *
+ */
+
+#include "config.h"
+
+#include <gdk/gdkx.h>
+#include <gtk/gtk.h>
+#include <glib/gi18n.h>
+#include <glib/gstdio.h>
+#include <gio/gio.h>
+#include <X11/Xlib.h>
+
+#include "user_share-private.h"
+#include "user_share-common.h"
+#include "http.h"
+
+#ifdef HAVE_BLUETOOTH
+#include <bluetooth-client.h>
+
+#include "obexftp.h"
+#include "obexpush.h"
+
+#endif /* HAVE_BLUETOOTH */
+
+#include <gio/gio.h>
+
+#include <stdarg.h>
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <signal.h>
+#include <unistd.h>
+
+static guint disabled_timeout_tag = 0;
+static GSettings* settings;<--- Shadowed declaration<--- Shadowed declaration<--- Shadowed declaration
+
+#define GSETTINGS_SCHEMA "org.mate.FileSharing"
+#define GSETTINGS_KEY_FILE_SHARING_ENABLED "enabled"
+#define GSETTINGS_KEY_FILE_SHARING_REQUIRE_PASSWORD "require-password"
+
+#ifdef HAVE_BLUETOOTH
+/* MATE Session */
+#define MATE_SESSION_DBUS_NAME      "org.gnome.SessionManager"
+#define MATE_SESSION_DBUS_OBJECT    "/org/gnome/SessionManager"
+#define MATE_SESSION_DBUS_INTERFACE "org.gnome.SessionManager"
+
+static GDBusProxy *session_proxy = NULL;
+static gboolean has_console = TRUE;
+
+static BluetoothClient *client = NULL;
+static gboolean bluetoothd_enabled = FALSE;
+
+#define OBEX_ENABLED (bluetoothd_enabled && has_console)
+
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_ENABLED "bluetooth-enabled"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_ALLOW_WRITE "bluetooth-allow-write"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_REQUIRE_PAIRING "bluetooth-require-pairing"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED "bluetooth-obexpush-enabled"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_ACCEPT_FILES "bluetooth-accept-files"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_NOTIFY "bluetooth-notify"
+
+
+static void
+obex_services_start (void)
+{
+	GSettings *settings;<--- Shadow variable
+
+	if (bluetoothd_enabled == FALSE ||
+	    has_console == FALSE)
+	    	return;
+
+	settings = g_settings_new(GSETTINGS_SCHEMA);
+
+	if (g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED) == TRUE) {
+	    obexpush_up ();
+	}
+	if (g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_ENABLED) == TRUE) {
+	    obexftp_up ();
+	}
+
+	g_object_unref (client);
+}
+
+static void
+obex_services_shutdown (void)
+{
+	obexpush_down ();
+	obexftp_down ();
+}
+
+static void
+session_properties_changed_cb (GDBusProxy      *session,
+			       GVariant        *changed,
+			       char           **invalidated,
+			       gpointer         user_data)
+{
+	GVariant *v;
+
+	v = g_variant_lookup_value (changed, "SessionIsActive", G_VARIANT_TYPE_BOOLEAN);
+	if (v) {
+		has_console = g_variant_get_boolean (v);
+		g_debug ("Received session is active change: now %s", has_console ? "active" : "inactive");
+
+		if (has_console)
+			obex_services_start ();
+		else
+			obex_services_shutdown ();
+
+		g_variant_unref (v);
+	}
+}
+
+static gboolean
+is_session_active (void)
+{
+	GVariant *variant;
+	gboolean is_session_active = FALSE;
+
+	variant = g_dbus_proxy_get_cached_property (session_proxy,
+						    "SessionIsActive");
+	if (variant) {
+		is_session_active = g_variant_get_boolean (variant);
+		g_variant_unref (variant);
+ 	}
+
+	return is_session_active;
+}
+
+static void
+session_init (void)
+{
+	GError *error = NULL;
+
+	session_proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION,
+						       G_DBUS_PROXY_FLAGS_NONE,
+						       NULL,
+						       MATE_SESSION_DBUS_NAME,
+						       MATE_SESSION_DBUS_OBJECT,
+						       MATE_SESSION_DBUS_INTERFACE,
+						       NULL,
+						       &error);
+	if (session_proxy == NULL) {
+		g_warning ("Failed to get session proxy: %s", error->message);
+		g_error_free (error);
+		return;
+	}
+	g_signal_connect (session_proxy, "g-properties-changed",
+			  G_CALLBACK (session_properties_changed_cb),
+			  NULL);
+	has_console = is_session_active ();
+}
+
+static void
+default_adapter_changed (GObject    *gobject,<--- Parameter 'gobject' can be declared as pointer to const
+			 GParamSpec *pspec,
+			 gpointer    user_data)
+{
+	char *adapter;
+	gboolean adapter_powered;
+
+	g_object_get (G_OBJECT (client),
+		      "default-adapter", &adapter,
+		      "default-adapter-powered", &adapter_powered,
+		      NULL);
+	if (adapter != NULL && *adapter != '\0') {
+		bluetoothd_enabled = adapter_powered;
+	} else {
+		bluetoothd_enabled = FALSE;
+	}
+
+	/* Were we called as init, or as a callback */
+	if (gobject != NULL) {
+		if (bluetoothd_enabled != FALSE)
+			obex_services_start ();
+		else
+			obex_services_shutdown ();
+	}
+}
+
+static void
+bluez_init (void)
+{
+	client = bluetooth_client_new ();
+	default_adapter_changed (NULL, NULL, NULL);
+	g_signal_connect (G_OBJECT (client), "notify::default-adapter",
+			  G_CALLBACK (default_adapter_changed), NULL);
+	g_signal_connect (G_OBJECT (client), "notify::default-adapter-powered",
+			  G_CALLBACK (default_adapter_changed), NULL);
+}
+#endif /* HAVE_BLUETOOTH */
+
+static gboolean
+file_sharing_enabled (void)
+{
+	gboolean enabled = TRUE;
+	settings = g_settings_new (GSETTINGS_SCHEMA);
+
+#ifdef HAVE_BLUETOOTH
+	if (g_settings_get_boolean (settings, FILE_SHARING_ENABLED) == FALSE &&
+	    g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_ENABLED) == FALSE &&
+	    g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED) == FALSE)
+#else /* HAVE_BLUETOOTH */
+	if (g_settings_get_boolean (settings, FILE_SHARING_ENABLED) == FALSE)
+#endif /* HAVE_BLUETOOTH */
+		enabled = FALSE;
+
+	g_object_unref (settings);
+
+	return enabled;
+}
+
+static void
+migrate_old_configuration (void)
+{
+	const char *old_config_dir;
+	const char *new_config_dir;
+
+	old_config_dir = g_build_filename (g_get_home_dir (), ".mate2", "user-share", NULL);
+	new_config_dir = g_build_filename (g_get_user_config_dir (), "user-share", NULL);
+	if (g_file_test (old_config_dir, G_FILE_TEST_IS_DIR))
+		g_rename (old_config_dir, new_config_dir);
+
+}
+
+static void
+require_password_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	/* Need to restart to get new password setting */
+	if (http_get_pid () != 0) {
+		http_down ();
+		http_up ();
+	}
+}
+
+/* File sharing was disabled for some time, exit now */
+/* If we re-enable it in the ui, this will be restarted anyway */
+static gboolean
+disabled_timeout_callback (gpointer user_data)
+{
+	GSettings *settings = (GSettings *) user_data;<--- Shadow variable
+	http_down ();
+
+#ifdef HAVE_BLUETOOTH
+	if (g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_ENABLED) == FALSE &&
+	    g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED) == FALSE)
+		_exit (0);
+#else /* HAVE_BLUETOOTH */
+	if (g_settings_get_boolean (settings, FILE_SHARING_ENABLED) == FALSE)
+		_exit (0);
+#endif /* HAVE_BLUETOOTH */
+	return FALSE;
+}
+
+static void
+file_sharing_enabled_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	gboolean enabled;
+
+	if (disabled_timeout_tag != 0) {
+		g_source_remove (disabled_timeout_tag);
+		disabled_timeout_tag = 0;
+	}
+
+	enabled = g_settings_get_boolean (settings,
+					 FILE_SHARING_ENABLED);
+	if (enabled) {
+		if (http_get_pid () == 0) {
+			http_up ();
+		}
+	} else {
+		http_down ();
+		disabled_timeout_tag = g_timeout_add_seconds (3,
+							      (GSourceFunc)disabled_timeout_callback,
+							      settings);
+	}
+}
+
+#ifdef HAVE_BLUETOOTH
+static void
+file_sharing_bluetooth_allow_write_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	if (g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_ENABLED) != FALSE)
+		obexftp_restart ();
+}
+
+static void
+file_sharing_bluetooth_require_pairing_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	if (g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_ENABLED) != FALSE) {
+		/* We need to fully reset the session,
+		 * otherwise the new setting isn't taken into account */
+		obexftp_down ();
+		obexftp_up ();
+	}
+}
+
+static void
+file_sharing_bluetooth_enabled_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	if (g_settings_get_boolean (settings,
+				   FILE_SHARING_BLUETOOTH_ENABLED) == FALSE) {
+		obexftp_down ();
+		if (g_settings_get_boolean (settings, FILE_SHARING_ENABLED) == FALSE &&
+		    g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED) == FALSE) {
+			_exit (0);
+		}
+	} else if (OBEX_ENABLED) {
+		obexftp_up ();
+	}
+}
+
+static void
+file_sharing_bluetooth_obexpush_enabled_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	if (g_settings_get_boolean (settings,
+				   FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED) == FALSE) {
+		obexpush_down ();
+		if (g_settings_get_boolean (settings, FILE_SHARING_ENABLED) == FALSE &&
+		    g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_ENABLED) == FALSE) {
+			_exit (0);
+		}
+	} else if (OBEX_ENABLED) {
+		obexpush_up ();
+	}
+}
+
+static void
+file_sharing_bluetooth_obexpush_accept_files_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	AcceptSetting setting;
+	char *str;
+
+	str = g_settings_get_string (settings, FILE_SHARING_BLUETOOTH_OBEXPUSH_ACCEPT_FILES);
+	setting = accept_setting_from_string (str);
+	g_free (str);
+
+	obexpush_set_accept_files_policy (setting);
+}
+
+static void
+file_sharing_bluetooth_obexpush_notify_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	obexpush_set_notify (g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_OBEXPUSH_NOTIFY));
+}
+#endif /* HAVE_BLUETOOTH */
+
+static RETSIGTYPE
+cleanup_handler (int sig)
+{
+	http_down ();
+#ifdef HAVE_BLUETOOTH
+	obexftp_down ();
+	obexpush_down ();
+#endif /* HAVE_BLUETOOTH */
+	_exit (2);
+}
+
+static int
+x_io_error_handler (Display *xdisplay)
+{
+	http_down ();
+#ifdef HAVE_BLUETOOTH
+	obexftp_down ();
+#endif /* HAVE_BLUETOOTH */
+	_exit (2);
+}
+
+int
+main (int argc, char **argv)
+{
+	GSettings *settings;<--- Shadow variable
+	Display *xdisplay;
+	G_GNUC_UNUSED int x_fd;
+	Window selection_owner;
+	Atom xatom;
+
+	bindtextdomain (GETTEXT_PACKAGE, MATELOCALEDIR);
+	bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
+	textdomain (GETTEXT_PACKAGE);
+
+	gtk_init (&argc, &argv);
+
+	if (g_strcmp0 (g_get_real_name (), "root") == 0) {
+		g_warning ("mate-user-share cannot be started as root for security reasons.");
+		return 1;
+	}
+
+	signal (SIGPIPE, SIG_IGN);
+	signal (SIGINT, cleanup_handler);
+	signal (SIGHUP, cleanup_handler);
+	signal (SIGTERM, cleanup_handler);
+
+	xdisplay = GDK_DISPLAY_XDISPLAY (gdk_display_get_default ());
+	if (xdisplay == NULL) {
+		g_warning ("Can't open display");
+		return 1;
+	}
+
+	xatom = XInternAtom (xdisplay, "_MATE_USER_SHARE", FALSE);
+	selection_owner = XGetSelectionOwner (xdisplay, xatom);
+
+	if (selection_owner != None) {
+		/* There is an owner already, quit */
+		return 1;
+	}
+
+	selection_owner = XCreateSimpleWindow (xdisplay,
+					       RootWindow (xdisplay, 0),
+					       0, 0, 1, 1,
+					       0, 0, 0);
+	XSetSelectionOwner (xdisplay, xatom, selection_owner, CurrentTime);
+
+	if (XGetSelectionOwner (xdisplay, xatom) != selection_owner) {
+		/* Didn't get the selection */
+		return 1;
+	}
+
+	migrate_old_configuration ();
+
+	if (!file_sharing_enabled ())
+		return 1;
+
+	settings = g_settings_new (GSETTINGS_SCHEMA);
+
+	x_fd = ConnectionNumber (xdisplay);
+	XSetIOErrorHandler (x_io_error_handler);
+
+	if (http_init () == FALSE)
+		return 1;
+#ifdef HAVE_BLUETOOTH
+	if (obexftp_init () == FALSE)
+		return 1;
+	if (obexpush_init () == FALSE)
+		return 1;
+#endif /* HAVE_BLUETOOTH */
+
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_ENABLED,
+			     G_CALLBACK (file_sharing_enabled_changed), NULL);
+
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_REQUIRE_PASSWORD,
+			     G_CALLBACK (require_password_changed), NULL);
+
+#ifdef HAVE_BLUETOOTH
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_ENABLED,
+			     G_CALLBACK (file_sharing_bluetooth_enabled_changed), NULL);
+
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_ALLOW_WRITE,
+			     G_CALLBACK (file_sharing_bluetooth_allow_write_changed), NULL);
+
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_REQUIRE_PAIRING,
+			     G_CALLBACK (file_sharing_bluetooth_require_pairing_changed), NULL);
+
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED,
+			     G_CALLBACK (file_sharing_bluetooth_obexpush_enabled_changed), NULL);
+
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_ACCEPT_FILES,
+			     G_CALLBACK (file_sharing_bluetooth_obexpush_accept_files_changed), NULL);
+
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_NOTIFY,
+			     G_CALLBACK (file_sharing_bluetooth_obexpush_notify_changed), NULL);
+
+	bluez_init ();
+	session_init ();
+#endif /* HAVE_BLUETOOTH */
+
+	/* Initial setting */
+	file_sharing_enabled_changed (settings, NULL, NULL);
+#ifdef HAVE_BLUETOOTH
+	file_sharing_bluetooth_enabled_changed (settings, NULL, NULL);
+	file_sharing_bluetooth_obexpush_accept_files_changed (settings, NULL, NULL);
+	file_sharing_bluetooth_obexpush_notify_changed (settings, NULL, NULL);
+	file_sharing_bluetooth_obexpush_enabled_changed (settings, NULL, NULL);
+#endif /* HAVE_BLUETOOTH */
+
+	gtk_main ();
+
+	return 0;
+}
+
+ +
+ +
+ + diff --git a/2023-09-19-100425-2309-cppcheck@72f91230a146_master/index.html b/2023-09-19-100425-2309-cppcheck@72f91230a146_master/index.html new file mode 100644 index 0000000..e87e43e --- /dev/null +++ b/2023-09-19-100425-2309-cppcheck@72f91230a146_master/index.html @@ -0,0 +1,231 @@ + + + + + + Cppcheck - HTML report - mate-user-share + + + + + +
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
LineIdCWESeverityMessage
missingIncludeinformationCppcheck cannot find all the include files (use --check-config for details)
src/caja-share-bar.c
41unknownMacroerrorThere is an unknown macro here somewhere. Configuration is required. If G_DEFINE_TYPE_WITH_PRIVATE is a macro then please configure it.
src/file-share-properties.c
83variableScope398styleThe scope of the variable 'password' can be reduced.
98shadowVariable398styleLocal variable 'settings' shadows outer variable
106unusedVariable563styleUnused variable: accept_setting
250shadowVariable398styleLocal variable 'settings' shadows outer variable
274shadowVariable398styleLocal variable 'settings' shadows outer variable
295shadowVariable398styleLocal variable 'settings' shadows outer variable
324shadowVariable398styleLocal variable 'settings' shadows outer variable
341shadowVariable398styleLocal variable 'settings' shadows outer variable
358shadowVariable398styleLocal variable 'settings' shadows outer variable
378shadowVariable398styleLocal variable 'settings' shadows outer variable
394shadowVariable398styleLocal variable 'settings' shadows outer variable
458shadowVariable398styleLocal variable 'settings' shadows outer variable
621variableScope398styleThe scope of the variable 'window' can be reduced.
src/http.c
115variableScope398styleThe scope of the variable 'host_name' can be reduced.
src/obexpush.c
188shadowVariable398styleLocal variable 'connection' shadows outer variable
src/share-extension.c
62variableScope398styleThe scope of the variable 'dialog' can be reduced.
src/user_share.c
87shadowVariable398styleLocal variable 'settings' shadows outer variable
175constParameter398styleParameter 'gobject' can be declared as pointer to const
261shadowVariable398styleLocal variable 'settings' shadows outer variable
392shadowVariable398styleLocal variable 'settings' shadows outer variable
+
+ +
+ + diff --git a/2023-09-19-100425-2309-cppcheck@72f91230a146_master/stats.html b/2023-09-19-100425-2309-cppcheck@72f91230a146_master/stats.html new file mode 100644 index 0000000..9c87915 --- /dev/null +++ b/2023-09-19-100425-2309-cppcheck@72f91230a146_master/stats.html @@ -0,0 +1,174 @@ + + + + + + Cppcheck - HTML report - mate-user-share + + + + + +
+ + + +
+

Top 10 files for error severity, total findings: 1
+   1  src/caja-share-bar.c
+

+

Top 10 files for style severity, total findings: 20
+   13  src/file-share-properties.c
+   4   src/user_share.c
+   1   src/share-extension.c
+   1   src/obexpush.c
+   1   src/http.c
+

+ +
+ +
+ + diff --git a/2023-09-19-100425-2309-cppcheck@72f91230a146_master/style.css b/2023-09-19-100425-2309-cppcheck@72f91230a146_master/style.css new file mode 100644 index 0000000..3897bfa --- /dev/null +++ b/2023-09-19-100425-2309-cppcheck@72f91230a146_master/style.css @@ -0,0 +1,177 @@ + +body { + font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif; + font-size: 13px; + line-height: 1.5; + height: 100%; + margin: 0; +} + +#wrapper { + position: fixed; + height: 100vh; + width: 100vw; + display: grid; + grid-template-rows: fit-content(8rem) auto fit-content(8rem); + grid-template-columns: fit-content(25%) 1fr; + grid-template-areas: + "header header" + "menu content" + "footer footer"; +} + +h1 { + margin: 0 0 8px -2px; + font-size: 175%; +} + +.header { + padding: 0 0 5px 15px; + grid-area: header; + border-bottom: thin solid #aaa; +} + +.footer { + grid-area: footer; + border-top: thin solid #aaa; + font-size: 85%; + +} + +.footer > p { + margin: 4px; +} + +#menu, +#menu_index { + grid-area: menu; + text-align: left; + overflow: auto; + padding: 0 23px 15px 15px; + border-right: thin solid #aaa; + min-width: 200px; +} + +#menu > a { + display: block; + margin-left: 10px; + font-size: 12px; +} + +#content, +#content_index { + grid-area: content; + padding: 0px 5px 15px 15px; + overflow: auto; +} + +label { + white-space: nowrap; +} + +label.checkBtn.disabled { + color: #606060; + background: #e0e0e0; + font-style: italic; +} + +label.checkBtn, input[type="text"] { + border: 1px solid grey; + border-radius: 4px; + box-shadow: 1px 1px inset; + padding: 1px 5px; +} + +label.checkBtn { + white-space: nowrap; + background: #ccddff; +} + +label.unchecked { + background: #eff8ff; + box-shadow: 1px 1px 1px; +} + +label.checkBtn:hover, label.unchecked:hover{ + box-shadow: 0 0 2px; +} + +label.disabled:hover { + box-shadow: 1px 1px inset; +} + +label.checkBtn > input { + display:none; +} + +.summaryTable { + width: 100%; +} + +table.summaryTable td { padding: 0 5px 0 5px; } + +.statHeader, .severityHeader { + font-weight: bold; +} + +.warning { + background-color: #ffffa7; +} + +.error { + background-color: #ffb7b7; +} + +.error2 { + background-color: #faa; + display: inline-block; + margin-left: 4px; +} + +.inconclusive { + background-color: #b6b6b4; +} + +.inconclusive2 { + background-color: #b6b6b4; + display: inline-block; + margin-left: 4px; +} + +.verbose { + display: inline-block; + vertical-align: top; + cursor: help; +} + +.verbose .content { + display: none; + position: absolute; + padding: 10px; + margin: 4px; + max-width: 40%; + white-space: pre-wrap; + border: 1px solid #000; + background-color: #ffffcc; + cursor: auto; +} + +.highlight .hll { + padding: 1px; +} + +.highlighttable { + background-color: #fff; + position: relative; + margin: -10px; +} + +.linenos { + border-right: thin solid #aaa; + color: #d3d3d3; + padding-right: 6px; +} + +.id-filtered, .severity-filtered, .file-filtered, .tool-filtered, .text-filtered { + visibility: collapse; +} diff --git a/2024-02-22-185755-8058-cppcheck@00d9a360c0cc_v1.28.0/0.html b/2024-02-22-185755-8058-cppcheck@00d9a360c0cc_v1.28.0/0.html new file mode 100644 index 0000000..777b6aa --- /dev/null +++ b/2024-02-22-185755-8058-cppcheck@00d9a360c0cc_v1.28.0/0.html @@ -0,0 +1,501 @@ + + + + + + Cppcheck - HTML report - mate-user-share + + + + + +
+ + + +
+
  1
+  2
+  3
+  4
+  5
+  6
+  7
+  8
+  9
+ 10
+ 11
+ 12
+ 13
+ 14
+ 15
+ 16
+ 17
+ 18
+ 19
+ 20
+ 21
+ 22
+ 23
+ 24
+ 25
+ 26
+ 27
+ 28
+ 29
+ 30
+ 31
+ 32
+ 33
+ 34
+ 35
+ 36
+ 37
+ 38
+ 39
+ 40
+ 41
+ 42
+ 43
+ 44
+ 45
+ 46
+ 47
+ 48
+ 49
+ 50
+ 51
+ 52
+ 53
+ 54
+ 55
+ 56
+ 57
+ 58
+ 59
+ 60
+ 61
+ 62
+ 63
+ 64
+ 65
+ 66
+ 67
+ 68
+ 69
+ 70
+ 71
+ 72
+ 73
+ 74
+ 75
+ 76
+ 77
+ 78
+ 79
+ 80
+ 81
+ 82
+ 83
+ 84
+ 85
+ 86
+ 87
+ 88
+ 89
+ 90
+ 91
+ 92
+ 93
+ 94
+ 95
+ 96
+ 97
+ 98
+ 99
+100
+101
+102
+103
+104
+105
+106
+107
+108
+109
+110
+111
+112
+113
+114
+115
+116
+117
+118
+119
+120
+121
+122
+123
+124
+125
+126
+127
+128
+129
+130
+131
+132
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2005 William Jon McCann <mccann@jhu.edu>
+ * Copyright (C) 2012-2021 MATE Developers
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * 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
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Authors: William Jon McCann <mccann@jhu.edu>
+ *
+ */
+
+#include "config.h"<--- Include file: "config.h" not found.
+
+#include <glib/gi18n-lib.h><--- Include file:  not found. Please note: Cppcheck does not need standard library headers to get proper results.
+#include <gtk/gtk.h><--- Include file:  not found. Please note: Cppcheck does not need standard library headers to get proper results.
+
+#include "caja-share-bar.h"
+
+struct CajaShareBarPrivate
+{
+	GtkWidget   *label;
+};
+
+enum {
+	PROP_0,
+	PROP_LABEL
+};
+
+G_DEFINE_TYPE_WITH_PRIVATE (CajaShareBar, caja_share_bar, GTK_TYPE_INFO_BAR)<--- There is an unknown macro here somewhere. Configuration is required. If G_DEFINE_TYPE_WITH_PRIVATE is a macro then please configure it.
+
+static void
+caja_share_bar_set_property (GObject            *object,
+                                guint               prop_id,
+                                const GValue       *value,
+                                GParamSpec         *pspec)
+{
+        CajaShareBar *self;
+
+        self = CAJA_SHARE_BAR (object);
+
+        switch (prop_id) {
+	case PROP_LABEL: {
+		gtk_label_set_text (GTK_LABEL (self->priv->label),
+				    g_value_get_string (value));
+		break;
+	}
+        default:
+                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+                break;
+        }
+}
+
+static void
+caja_share_bar_class_init (CajaShareBarClass *klass)
+{
+        GObjectClass   *object_class = G_OBJECT_CLASS (klass);
+
+        object_class->set_property = caja_share_bar_set_property;
+
+        g_object_class_install_property (G_OBJECT_CLASS(klass), PROP_LABEL,
+					 g_param_spec_string ("label", "label",
+							      "The widget's main label",
+							      NULL,
+							      G_PARAM_WRITABLE));
+}
+
+static void
+caja_share_bar_init (CajaShareBar *bar)
+{
+	GtkWidget *content_area;
+	GtkWidget *action_area;
+	GtkWidget *label;
+	GtkWidget *vbox;
+	GtkWidget *button;
+	PangoAttrList *attrs;
+
+	bar->priv = caja_share_bar_get_instance_private (bar);
+
+	content_area = gtk_info_bar_get_content_area (GTK_INFO_BAR (bar));
+	action_area = gtk_info_bar_get_action_area (GTK_INFO_BAR (bar));
+	gtk_button_box_set_layout (GTK_BUTTON_BOX (action_area), GTK_BUTTONBOX_CENTER);
+
+	vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 3);
+	gtk_container_add (GTK_CONTAINER (content_area), vbox);
+
+	attrs = pango_attr_list_new ();
+	pango_attr_list_insert (attrs, pango_attr_weight_new (PANGO_WEIGHT_BOLD));
+	label = gtk_label_new (_("Personal File Sharing"));
+	gtk_label_set_attributes (GTK_LABEL (label), attrs);
+	pango_attr_list_unref (attrs);
+
+	gtk_label_set_xalign (GTK_LABEL (label), 0.0);
+	gtk_label_set_yalign (GTK_LABEL (label), 0.5);
+	gtk_widget_show (label);
+	gtk_container_add (GTK_CONTAINER (vbox), label);
+
+	bar->priv->label = gtk_label_new (NULL);
+	gtk_label_set_xalign (GTK_LABEL (bar->priv->label), 0.0);
+	gtk_label_set_yalign (GTK_LABEL (bar->priv->label), 0.5);
+	gtk_widget_show (bar->priv->label);
+	gtk_container_add (GTK_CONTAINER (vbox), bar->priv->label);
+
+	button = gtk_info_bar_add_button (GTK_INFO_BAR (bar),
+					  _("Preferences"),
+					  CAJA_SHARE_BAR_RESPONSE_PREFERENCES);
+
+	gtk_widget_set_tooltip_text (button,
+				     _("Launch Personal File Sharing Preferences"));
+
+	gtk_widget_show_all (vbox);
+}
+
+GtkWidget *
+caja_share_bar_new (const char *label)
+{
+        return g_object_new (CAJA_TYPE_SHARE_BAR,
+                             "message-type", GTK_MESSAGE_QUESTION,
+			     "label", label,
+                             NULL);
+}
+
+ +
+ +
+ + diff --git a/2024-02-22-185755-8058-cppcheck@00d9a360c0cc_v1.28.0/1.html b/2024-02-22-185755-8058-cppcheck@00d9a360c0cc_v1.28.0/1.html new file mode 100644 index 0000000..dc4aac8 --- /dev/null +++ b/2024-02-22-185755-8058-cppcheck@00d9a360c0cc_v1.28.0/1.html @@ -0,0 +1,365 @@ + + + + + + Cppcheck - HTML report - mate-user-share + + + + + +
+ + + +
+
 1
+ 2
+ 3
+ 4
+ 5
+ 6
+ 7
+ 8
+ 9
+10
+11
+12
+13
+14
+15
+16
+17
+18
+19
+20
+21
+22
+23
+24
+25
+26
+27
+28
+29
+30
+31
+32
+33
+34
+35
+36
+37
+38
+39
+40
+41
+42
+43
+44
+45
+46
+47
+48
+49
+50
+51
+52
+53
+54
+55
+56
+57
+58
+59
+60
+61
+62
+63
+64
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2005 William Jon McCann <mccann@jhu.edu>
+ * Copyright (C) 2012-2021 MATE Developers
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * 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
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Authors: William Jon McCann <mccann@jhu.edu>
+ *
+ */
+
+#ifndef __CAJA_SHARE_BAR_H
+#define __CAJA_SHARE_BAR_H
+
+#include <gtk/gtk.h><--- Include file:  not found. Please note: Cppcheck does not need standard library headers to get proper results.
+
+G_BEGIN_DECLS
+
+#define CAJA_TYPE_SHARE_BAR         (caja_share_bar_get_type ())
+#define CAJA_SHARE_BAR(o)           (G_TYPE_CHECK_INSTANCE_CAST ((o), CAJA_TYPE_SHARE_BAR, CajaShareBar))
+#define CAJA_SHARE_BAR_CLASS(k)     (G_TYPE_CHECK_CLASS_CAST((k), CAJA_TYPE_SHARE_BAR, CajaShareBarClass))
+#define CAJA_IS_SHARE_BAR(o)        (G_TYPE_CHECK_INSTANCE_TYPE ((o), CAJA_TYPE_SHARE_BAR))
+#define CAJA_IS_SHARE_BAR_CLASS(k)  (G_TYPE_CHECK_CLASS_TYPE ((k), CAJA_TYPE_SHARE_BAR))
+#define CAJA_SHARE_BAR_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), CAJA_TYPE_SHARE_BAR, CajaShareBarClass))
+
+#define CAJA_SHARE_BAR_RESPONSE_PREFERENCES 1
+
+typedef struct CajaShareBarPrivate CajaShareBarPrivate;
+
+typedef struct
+{
+        GtkInfoBar parent;
+
+        CajaShareBarPrivate *priv;
+} CajaShareBar;
+
+typedef struct
+{
+        GtkInfoBarClass  parent_class;
+
+	void (* activate) (CajaShareBar *bar);
+
+} CajaShareBarClass;
+
+GType       caja_share_bar_get_type          (void);
+GtkWidget  *caja_share_bar_new               (const char *label);
+
+GtkWidget  *caja_share_bar_get_button        (CajaShareBar *bar);
+
+G_END_DECLS
+
+#endif /* __GS_SHARE_BAR_H */
+
+ +
+ +
+ + diff --git a/2024-02-22-185755-8058-cppcheck@00d9a360c0cc_v1.28.0/10.html b/2024-02-22-185755-8058-cppcheck@00d9a360c0cc_v1.28.0/10.html new file mode 100644 index 0000000..6ff1e2c --- /dev/null +++ b/2024-02-22-185755-8058-cppcheck@00d9a360c0cc_v1.28.0/10.html @@ -0,0 +1,303 @@ + + + + + + Cppcheck - HTML report - mate-user-share + + + + + +
+ + + +
+
 1
+ 2
+ 3
+ 4
+ 5
+ 6
+ 7
+ 8
+ 9
+10
+11
+12
+13
+14
+15
+16
+17
+18
+19
+20
+21
+22
+23
+24
+25
+26
+27
+28
+29
+30
+31
+32
+33
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
+
+/*
+ *  Copyright (C) 2004-2008 Red Hat, Inc.
+ *  Copyright (C) 2012-2021 MATE Developers
+ *
+ *  Caja is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU General Public License as
+ *  published by the Free Software Foundation; either version 2 of the
+ *  License, or (at your option) any later version.
+ *
+ *  Caja is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  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
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ *  Authors: Bastien Nocera <hadess@hadess.net>
+ *
+ */
+
+#include <glib.h><--- Include file:  not found. Please note: Cppcheck does not need standard library headers to get proper results.
+#include "user_share-private.h"
+
+void obexpush_up (void);
+void obexpush_down (void);
+void obexpush_restart (void);
+gboolean obexpush_init (void);
+void obexpush_set_accept_files_policy (AcceptSetting accept_setting);
+void obexpush_set_notify (gboolean enabled);
+
+ +
+ +
+ + diff --git a/2024-02-22-185755-8058-cppcheck@00d9a360c0cc_v1.28.0/11.html b/2024-02-22-185755-8058-cppcheck@00d9a360c0cc_v1.28.0/11.html new file mode 100644 index 0000000..12c2638 --- /dev/null +++ b/2024-02-22-185755-8058-cppcheck@00d9a360c0cc_v1.28.0/11.html @@ -0,0 +1,833 @@ + + + + + + Cppcheck - HTML report - mate-user-share + + + + + +
+ + + +
+
  1
+  2
+  3
+  4
+  5
+  6
+  7
+  8
+  9
+ 10
+ 11
+ 12
+ 13
+ 14
+ 15
+ 16
+ 17
+ 18
+ 19
+ 20
+ 21
+ 22
+ 23
+ 24
+ 25
+ 26
+ 27
+ 28
+ 29
+ 30
+ 31
+ 32
+ 33
+ 34
+ 35
+ 36
+ 37
+ 38
+ 39
+ 40
+ 41
+ 42
+ 43
+ 44
+ 45
+ 46
+ 47
+ 48
+ 49
+ 50
+ 51
+ 52
+ 53
+ 54
+ 55
+ 56
+ 57
+ 58
+ 59
+ 60
+ 61
+ 62
+ 63
+ 64
+ 65
+ 66
+ 67
+ 68
+ 69
+ 70
+ 71
+ 72
+ 73
+ 74
+ 75
+ 76
+ 77
+ 78
+ 79
+ 80
+ 81
+ 82
+ 83
+ 84
+ 85
+ 86
+ 87
+ 88
+ 89
+ 90
+ 91
+ 92
+ 93
+ 94
+ 95
+ 96
+ 97
+ 98
+ 99
+100
+101
+102
+103
+104
+105
+106
+107
+108
+109
+110
+111
+112
+113
+114
+115
+116
+117
+118
+119
+120
+121
+122
+123
+124
+125
+126
+127
+128
+129
+130
+131
+132
+133
+134
+135
+136
+137
+138
+139
+140
+141
+142
+143
+144
+145
+146
+147
+148
+149
+150
+151
+152
+153
+154
+155
+156
+157
+158
+159
+160
+161
+162
+163
+164
+165
+166
+167
+168
+169
+170
+171
+172
+173
+174
+175
+176
+177
+178
+179
+180
+181
+182
+183
+184
+185
+186
+187
+188
+189
+190
+191
+192
+193
+194
+195
+196
+197
+198
+199
+200
+201
+202
+203
+204
+205
+206
+207
+208
+209
+210
+211
+212
+213
+214
+215
+216
+217
+218
+219
+220
+221
+222
+223
+224
+225
+226
+227
+228
+229
+230
+231
+232
+233
+234
+235
+236
+237
+238
+239
+240
+241
+242
+243
+244
+245
+246
+247
+248
+249
+250
+251
+252
+253
+254
+255
+256
+257
+258
+259
+260
+261
+262
+263
+264
+265
+266
+267
+268
+269
+270
+271
+272
+273
+274
+275
+276
+277
+278
+279
+280
+281
+282
+283
+284
+285
+286
+287
+288
+289
+290
+291
+292
/* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 8; tab-width: 8 -*-
+ *
+ * Copyright (C) 2003 Novell, Inc.
+ * Copyright (C) 2003-2004 Red Hat, Inc.
+ * Copyright (C) 2005 William Jon McCann <mccann@jhu.edu>
+ * Copyright (C) 2012-2021 MATE Developers
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * 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 Foundation, Inc., 51 Franklin St, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ *
+ */
+
+#include "config.h"<--- Include file: "config.h" not found.
+
+#include <stdlib.h><--- Include file:  not found. Please note: Cppcheck does not need standard library headers to get proper results.
+#include <string.h><--- Include file:  not found. Please note: Cppcheck does not need standard library headers to get proper results.
+#include <glib/gi18n-lib.h><--- Include file:  not found. Please note: Cppcheck does not need standard library headers to get proper results.
+#include <gtk/gtk.h><--- Include file:  not found. Please note: Cppcheck does not need standard library headers to get proper results.
+#include <libcaja-extension/caja-menu-provider.h><--- Include file:  not found. Please note: Cppcheck does not need standard library headers to get proper results.
+#include <libcaja-extension/caja-location-widget-provider.h><--- Include file:  not found. Please note: Cppcheck does not need standard library headers to get proper results.
+
+#ifdef HAVE_BLUETOOTH
+#include <bluetooth-client.h><--- Include file:  not found. Please note: Cppcheck does not need standard library headers to get proper results.
+#endif
+
+#include "caja-share-bar.h"
+#include "user_share-common.h"
+
+#define CAJA_TYPE_USER_SHARE  (caja_user_share_get_type ())
+#define CAJA_USER_SHARE(o)    (G_TYPE_CHECK_INSTANCE_CAST ((o), CAJA_TYPE_USER_SHARE, CajaUserShare))
+#define CAJA_IS_USER_SHARE(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), CAJA_TYPE_USER_SHARE))
+
+typedef struct
+{
+        GObject              parent_slot;
+} CajaUserShare;
+
+typedef struct
+{
+        GObjectClass parent_slot;
+} CajaUserShareClass;
+
+static GType caja_user_share_get_type      (void);
+static void  caja_user_share_register_type (GTypeModule *module);
+
+static void
+launch_process (char **argv, GtkWindow *parent)
+{
+        GError *error;
+        GtkWidget *dialog;
+
+        error = NULL;
+        if (!g_spawn_async (NULL,
+                            argv, NULL,
+                            0,
+                            NULL, NULL,
+                            NULL,
+                            &error)) {
+
+
+                dialog = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL, GTK_MESSAGE_WARNING,
+						 GTK_BUTTONS_OK, _("Unable to launch the Personal File Sharing preferences"));
+
+                gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog), "%s", error->message);
+
+                gtk_dialog_run (GTK_DIALOG (dialog));
+                gtk_widget_destroy (dialog);
+
+                g_error_free (error);
+        }
+}
+
+static void
+launch_prefs_on_window (GtkWindow *window)
+{
+        char *argv [2];
+
+        argv [0] = g_build_filename (BINDIR, "mate-file-share-properties", NULL);
+        argv [1] = NULL;
+
+        launch_process (argv, window);
+
+        g_free (argv [0]);
+}
+
+static void
+bar_response_cb (CajaShareBar *bar,
+                 gint response,
+                 gpointer         data)
+{
+        if (response == CAJA_SHARE_BAR_RESPONSE_PREFERENCES) {
+                launch_prefs_on_window (GTK_WINDOW (data));
+        }
+}
+
+#ifdef HAVE_BLUETOOTH
+static void
+downloads_bar_set_from_bluetooth_status (GtkWidget *bar)
+{
+	BluetoothClient *client;
+	gboolean bt_powered;
+
+	client = g_object_get_data (G_OBJECT (bar), "bluetooth-client");
+	g_object_get (G_OBJECT (client),
+		      "default-adapter-powered", &bt_powered,
+		      NULL);
+	gtk_widget_set_visible (bar, bt_powered);
+}
+
+static void
+default_adapter_powered_cb (GObject    *gobject,
+			    GParamSpec *pspec,
+			    GtkWidget  *bar)
+{
+	downloads_bar_set_from_bluetooth_status (bar);
+}
+#endif /* HAVE_BLUETOOTH */
+
+static GtkWidget *
+caja_user_share_get_location_widget (CajaLocationWidgetProvider *iface,
+                                         const char                     *uri,
+                                         GtkWidget                      *window)
+{
+	GFile             *file;
+	GtkWidget         *bar;
+	guint              i;
+	gboolean           enable = FALSE;
+	GFile             *home;
+#ifdef HAVE_BLUETOOTH
+	const GUserDirectory special_dirs[] = { G_USER_DIRECTORY_PUBLIC_SHARE, G_USER_DIRECTORY_DOWNLOAD };
+
+	gboolean is_dir[] = { FALSE, FALSE };
+#else
+	const GUserDirectory special_dirs[] = { G_USER_DIRECTORY_PUBLIC_SHARE };
+
+	gboolean is_dir[] = { FALSE };
+#endif /* HAVE_BLUETOOTH */
+	file = g_file_new_for_uri (uri);
+	home = g_file_new_for_path (g_get_home_dir ());
+
+	/* We don't show anything in $HOME */
+	if (g_file_equal (home, file)) {
+		g_object_unref (home);
+		g_object_unref (file);
+		return NULL;
+	}
+
+	g_object_unref (home);
+
+	for (i = 0; i < G_N_ELEMENTS (special_dirs); i++) {
+		GFile *dir;
+		dir = lookup_dir_with_fallback (special_dirs[i]);
+		if (g_file_equal (dir, file)) {
+			enable = TRUE;
+			is_dir[i] = TRUE;
+		}
+		g_object_unref (dir);
+	}
+
+	g_object_unref (file);
+
+	if (enable == FALSE)
+		return NULL;
+
+	if (is_dir[0] != FALSE) {
+#ifdef HAVE_BLUETOOTH
+		if (is_dir[1] != FALSE) {
+			bar = caja_share_bar_new (_("May be used to share or receive files"));
+		} else {
+			bar = caja_share_bar_new (_("May be shared over the network or Bluetooth"));
+		}
+#else
+		bar = caja_share_bar_new (_("May be shared over the network"));
+#endif /* HAVE_BLUETOOTH */
+	} else {
+#ifdef HAVE_BLUETOOTH
+		BluetoothClient *client;
+
+		bar = caja_share_bar_new (_("May be used to receive files over Bluetooth"));
+
+		gtk_widget_set_no_show_all (bar, TRUE);
+		client = bluetooth_client_new ();
+		g_object_set_data_full (G_OBJECT (bar), "bluetooth-client", client, g_object_unref);
+		g_signal_connect (G_OBJECT (client), "notify::default-adapter-powered",
+				  G_CALLBACK (default_adapter_powered_cb), bar);
+		downloads_bar_set_from_bluetooth_status (bar);
+#endif /* HAVE_BLUETOOTH */
+	}
+
+	g_signal_connect (bar, "response",
+			  G_CALLBACK (bar_response_cb),
+			  window);
+
+	gtk_widget_show_all (bar);
+
+	return bar;
+}
+
+static void
+caja_user_share_location_widget_provider_iface_init (CajaLocationWidgetProviderIface *iface)
+{
+        iface->get_widget = caja_user_share_get_location_widget;
+}
+
+static void
+caja_user_share_instance_init (CajaUserShare *share)
+{
+
+}
+
+static void
+caja_user_share_class_init (CajaUserShareClass *klass)
+{
+
+}
+
+static GType share_type = 0;
+
+static GType
+caja_user_share_get_type (void)
+{
+        return share_type;
+}
+
+static void
+caja_user_share_register_type (GTypeModule *module)
+{
+        static const GTypeInfo info = {
+                sizeof (CajaUserShareClass),
+                (GBaseInitFunc) NULL,
+                (GBaseFinalizeFunc) NULL,
+                (GClassInitFunc) caja_user_share_class_init,
+                NULL,
+                NULL,
+                sizeof (CajaUserShare),
+                0,
+                (GInstanceInitFunc) caja_user_share_instance_init,
+        };
+
+        static const GInterfaceInfo location_widget_provider_iface_info = {
+                (GInterfaceInitFunc) caja_user_share_location_widget_provider_iface_init,
+                NULL,
+                NULL
+        };
+
+        share_type = g_type_module_register_type (module,
+                                                 G_TYPE_OBJECT,
+                                                 "CajaUserShare",
+                                                 &info, 0);
+
+        g_type_module_add_interface (module,
+                                     share_type,
+                                     CAJA_TYPE_LOCATION_WIDGET_PROVIDER,
+                                     &location_widget_provider_iface_info);
+}
+
+void
+caja_module_initialize (GTypeModule *module)
+{
+        caja_user_share_register_type (module);
+        bindtextdomain (GETTEXT_PACKAGE, MATELOCALEDIR);
+        bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
+}
+
+void
+caja_module_shutdown (void)
+{
+}
+
+void
+caja_module_list_types (const GType **types,
+                            int          *num_types)
+{
+        static GType type_list [1];
+
+        type_list[0] = CAJA_TYPE_USER_SHARE;
+
+        *types = type_list;
+        *num_types = 1;
+}
+
+ +
+ +
+ + diff --git a/2024-02-22-185755-8058-cppcheck@00d9a360c0cc_v1.28.0/12.html b/2024-02-22-185755-8058-cppcheck@00d9a360c0cc_v1.28.0/12.html new file mode 100644 index 0000000..2e1611c --- /dev/null +++ b/2024-02-22-185755-8058-cppcheck@00d9a360c0cc_v1.28.0/12.html @@ -0,0 +1,421 @@ + + + + + + Cppcheck - HTML report - mate-user-share + + + + + +
+ + + +
+
 1
+ 2
+ 3
+ 4
+ 5
+ 6
+ 7
+ 8
+ 9
+10
+11
+12
+13
+14
+15
+16
+17
+18
+19
+20
+21
+22
+23
+24
+25
+26
+27
+28
+29
+30
+31
+32
+33
+34
+35
+36
+37
+38
+39
+40
+41
+42
+43
+44
+45
+46
+47
+48
+49
+50
+51
+52
+53
+54
+55
+56
+57
+58
+59
+60
+61
+62
+63
+64
+65
+66
+67
+68
+69
+70
+71
+72
+73
+74
+75
+76
+77
+78
+79
+80
+81
+82
+83
+84
+85
+86
+87
+88
+89
+90
+91
+92
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
+
+/*
+ *  Copyright (C) 2004-2009 Red Hat, Inc.
+ *  Copyright (C) 2012-2021 MATE Developers
+ *
+ *  Caja is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU General Public License as
+ *  published by the Free Software Foundation; either version 2 of the
+ *  License, or (at your option) any later version.
+ *
+ *  Caja is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  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
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ *  Authors: Alexander Larsson <alexl@redhat.com>
+ *  Bastien Nocera <hadess@hadess.net>
+ *
+ */
+
+#include <string.h><--- Include file:  not found. Please note: Cppcheck does not need standard library headers to get proper results.
+
+#include "user_share-common.h"
+
+static char *
+lookup_special_dir (GUserDirectory directory,
+		    const char *name,
+		    gboolean create_dir)
+{
+	const char *special_dir;
+	char *dir;
+
+	special_dir = g_get_user_special_dir (directory);
+	if (special_dir != NULL && strcmp (special_dir, g_get_home_dir ()) != 0) {
+		if (create_dir != FALSE)
+			g_mkdir_with_parents (special_dir, 0755);
+		return g_strdup (special_dir);
+	}
+
+	dir = g_build_filename (g_get_home_dir (), name, NULL);
+	if (create_dir != FALSE)
+		g_mkdir_with_parents (dir, 0755);
+	return dir;
+}
+
+char *
+lookup_public_dir (void)
+{
+	return lookup_special_dir (G_USER_DIRECTORY_PUBLIC_SHARE,
+				   "Public",
+				   TRUE);
+}
+
+char *
+lookup_download_dir (void)
+{
+	return lookup_special_dir (G_USER_DIRECTORY_DOWNLOAD,
+				   "Downloads",
+				   TRUE);
+}
+
+GFile *
+lookup_dir_with_fallback (GUserDirectory directory)
+{
+	GFile *file;
+	char *path;
+	const char *name;
+
+	if (directory == G_USER_DIRECTORY_PUBLIC_SHARE)
+		name = "Public";
+	else if (directory == G_USER_DIRECTORY_DOWNLOAD)
+		name = "Downloads";
+	else
+		g_assert_not_reached ();
+
+	path = lookup_special_dir (directory,
+				   name,
+				   FALSE);
+
+	if (path == NULL)
+		return NULL;
+
+	file = g_file_new_for_path (path);
+	g_free (path);
+
+	return file;
+}
+
+ +
+ +
+ + diff --git a/2024-02-22-185755-8058-cppcheck@00d9a360c0cc_v1.28.0/13.html b/2024-02-22-185755-8058-cppcheck@00d9a360c0cc_v1.28.0/13.html new file mode 100644 index 0000000..35b2ce8 --- /dev/null +++ b/2024-02-22-185755-8058-cppcheck@00d9a360c0cc_v1.28.0/13.html @@ -0,0 +1,443 @@ + + + + + + Cppcheck - HTML report - mate-user-share + + + + + +
+ + + +
+
  1
+  2
+  3
+  4
+  5
+  6
+  7
+  8
+  9
+ 10
+ 11
+ 12
+ 13
+ 14
+ 15
+ 16
+ 17
+ 18
+ 19
+ 20
+ 21
+ 22
+ 23
+ 24
+ 25
+ 26
+ 27
+ 28
+ 29
+ 30
+ 31
+ 32
+ 33
+ 34
+ 35
+ 36
+ 37
+ 38
+ 39
+ 40
+ 41
+ 42
+ 43
+ 44
+ 45
+ 46
+ 47
+ 48
+ 49
+ 50
+ 51
+ 52
+ 53
+ 54
+ 55
+ 56
+ 57
+ 58
+ 59
+ 60
+ 61
+ 62
+ 63
+ 64
+ 65
+ 66
+ 67
+ 68
+ 69
+ 70
+ 71
+ 72
+ 73
+ 74
+ 75
+ 76
+ 77
+ 78
+ 79
+ 80
+ 81
+ 82
+ 83
+ 84
+ 85
+ 86
+ 87
+ 88
+ 89
+ 90
+ 91
+ 92
+ 93
+ 94
+ 95
+ 96
+ 97
+ 98
+ 99
+100
+101
+102
+103
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
+
+/*
+ *  Copyright (C) 2004-2008 Red Hat, Inc.
+ *  Copyright (C) 2012-2021 MATE Developers
+ *
+ *  Caja is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU General Public License as
+ *  published by the Free Software Foundation; either version 2 of the
+ *  License, or (at your option) any later version.
+ *
+ *  Caja is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  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
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ *  Authors: Alexander Larsson <alexl@redhat.com>
+ *  Bastien Nocera <hadess@hadess.net>
+ *
+ */
+
+#include "config.h"<--- Include file: "config.h" not found.
+
+#include <string.h><--- Include file:  not found. Please note: Cppcheck does not need standard library headers to get proper results.
+
+#include "user_share-private.h"
+
+static char *password_setting_strings[] = {
+    "never",
+    "on_write",
+    "always"
+};
+
+static char *accept_file_strings[] = {
+    "always",
+    "bonded",
+    "ask"
+};
+
+const char *
+password_string_from_setting (PasswordSetting setting)
+{
+
+    if (setting >= 0 && setting <= PASSWORD_ALWAYS)
+	return password_setting_strings[setting];
+
+    /* Fallback on secure pref */
+    return password_setting_strings[PASSWORD_ALWAYS];
+}
+
+PasswordSetting
+password_setting_from_string (const char *str)
+{
+    if (str != NULL) {
+	if (strcmp (str, "never") == 0) {
+	    return PASSWORD_NEVER;
+	}
+	if (strcmp (str, "always") == 0) {
+	    return PASSWORD_ALWAYS;
+	}
+	if (strcmp (str, "on_write") == 0) {
+	    return PASSWORD_ON_WRITE;
+	}
+    }
+
+    /* Fallback on secure pref */
+    return PASSWORD_ALWAYS;
+}
+
+const char *
+accept_string_from_setting (AcceptSetting setting)
+{
+
+    if (setting >= 0 && setting <= ACCEPT_ASK)
+	return accept_file_strings[setting];
+
+    /* Fallback on secure pref */
+    return accept_file_strings[ACCEPT_BONDED];
+}
+
+AcceptSetting
+accept_setting_from_string (const char *str)
+{
+    if (str != NULL) {
+	if (strcmp (str, "always") == 0) {
+	    return ACCEPT_ALWAYS;
+	}
+	if (strcmp (str, "bonded") == 0 ||
+	    strcmp (str, "bonded_and_trusted") == 0) {
+	    return ACCEPT_BONDED;
+	}
+	if (strcmp (str, "ask") == 0) {
+	    return ACCEPT_ASK;
+	}
+    }
+
+    /* Fallback on secure pref */
+    return ACCEPT_BONDED;
+}
+
+ +
+ +
+ + diff --git a/2024-02-22-185755-8058-cppcheck@00d9a360c0cc_v1.28.0/14.html b/2024-02-22-185755-8058-cppcheck@00d9a360c0cc_v1.28.0/14.html new file mode 100644 index 0000000..0ff0fee --- /dev/null +++ b/2024-02-22-185755-8058-cppcheck@00d9a360c0cc_v1.28.0/14.html @@ -0,0 +1,1251 @@ + + + + + + Cppcheck - HTML report - mate-user-share + + + + + +
+ + + +
+
  1
+  2
+  3
+  4
+  5
+  6
+  7
+  8
+  9
+ 10
+ 11
+ 12
+ 13
+ 14
+ 15
+ 16
+ 17
+ 18
+ 19
+ 20
+ 21
+ 22
+ 23
+ 24
+ 25
+ 26
+ 27
+ 28
+ 29
+ 30
+ 31
+ 32
+ 33
+ 34
+ 35
+ 36
+ 37
+ 38
+ 39
+ 40
+ 41
+ 42
+ 43
+ 44
+ 45
+ 46
+ 47
+ 48
+ 49
+ 50
+ 51
+ 52
+ 53
+ 54
+ 55
+ 56
+ 57
+ 58
+ 59
+ 60
+ 61
+ 62
+ 63
+ 64
+ 65
+ 66
+ 67
+ 68
+ 69
+ 70
+ 71
+ 72
+ 73
+ 74
+ 75
+ 76
+ 77
+ 78
+ 79
+ 80
+ 81
+ 82
+ 83
+ 84
+ 85
+ 86
+ 87
+ 88
+ 89
+ 90
+ 91
+ 92
+ 93
+ 94
+ 95
+ 96
+ 97
+ 98
+ 99
+100
+101
+102
+103
+104
+105
+106
+107
+108
+109
+110
+111
+112
+113
+114
+115
+116
+117
+118
+119
+120
+121
+122
+123
+124
+125
+126
+127
+128
+129
+130
+131
+132
+133
+134
+135
+136
+137
+138
+139
+140
+141
+142
+143
+144
+145
+146
+147
+148
+149
+150
+151
+152
+153
+154
+155
+156
+157
+158
+159
+160
+161
+162
+163
+164
+165
+166
+167
+168
+169
+170
+171
+172
+173
+174
+175
+176
+177
+178
+179
+180
+181
+182
+183
+184
+185
+186
+187
+188
+189
+190
+191
+192
+193
+194
+195
+196
+197
+198
+199
+200
+201
+202
+203
+204
+205
+206
+207
+208
+209
+210
+211
+212
+213
+214
+215
+216
+217
+218
+219
+220
+221
+222
+223
+224
+225
+226
+227
+228
+229
+230
+231
+232
+233
+234
+235
+236
+237
+238
+239
+240
+241
+242
+243
+244
+245
+246
+247
+248
+249
+250
+251
+252
+253
+254
+255
+256
+257
+258
+259
+260
+261
+262
+263
+264
+265
+266
+267
+268
+269
+270
+271
+272
+273
+274
+275
+276
+277
+278
+279
+280
+281
+282
+283
+284
+285
+286
+287
+288
+289
+290
+291
+292
+293
+294
+295
+296
+297
+298
+299
+300
+301
+302
+303
+304
+305
+306
+307
+308
+309
+310
+311
+312
+313
+314
+315
+316
+317
+318
+319
+320
+321
+322
+323
+324
+325
+326
+327
+328
+329
+330
+331
+332
+333
+334
+335
+336
+337
+338
+339
+340
+341
+342
+343
+344
+345
+346
+347
+348
+349
+350
+351
+352
+353
+354
+355
+356
+357
+358
+359
+360
+361
+362
+363
+364
+365
+366
+367
+368
+369
+370
+371
+372
+373
+374
+375
+376
+377
+378
+379
+380
+381
+382
+383
+384
+385
+386
+387
+388
+389
+390
+391
+392
+393
+394
+395
+396
+397
+398
+399
+400
+401
+402
+403
+404
+405
+406
+407
+408
+409
+410
+411
+412
+413
+414
+415
+416
+417
+418
+419
+420
+421
+422
+423
+424
+425
+426
+427
+428
+429
+430
+431
+432
+433
+434
+435
+436
+437
+438
+439
+440
+441
+442
+443
+444
+445
+446
+447
+448
+449
+450
+451
+452
+453
+454
+455
+456
+457
+458
+459
+460
+461
+462
+463
+464
+465
+466
+467
+468
+469
+470
+471
+472
+473
+474
+475
+476
+477
+478
+479
+480
+481
+482
+483
+484
+485
+486
+487
+488
+489
+490
+491
+492
+493
+494
+495
+496
+497
+498
+499
+500
+501
+502
+503
+504
+505
+506
+507
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
+
+/*
+ *  Copyright (C) 2004-2008 Red Hat, Inc.
+ *  Copyright (C) 2012-2021 MATE Developers
+ *
+ *  Caja is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU General Public License as
+ *  published by the Free Software Foundation; either version 2 of the
+ *  License, or (at your option) any later version.
+ *
+ *  Caja is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  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
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ *  Authors: Alexander Larsson <alexl@redhat.com>
+ *
+ */
+
+#include "config.h"<--- Include file: "config.h" not found.
+
+#include <gdk/gdkx.h><--- Include file:  not found. Please note: Cppcheck does not need standard library headers to get proper results.
+#include <gtk/gtk.h><--- Include file:  not found. Please note: Cppcheck does not need standard library headers to get proper results.
+#include <glib/gi18n.h><--- Include file:  not found. Please note: Cppcheck does not need standard library headers to get proper results.
+#include <glib/gstdio.h><--- Include file:  not found. Please note: Cppcheck does not need standard library headers to get proper results.
+#include <gio/gio.h><--- Include file:  not found. Please note: Cppcheck does not need standard library headers to get proper results.
+#include <X11/Xlib.h><--- Include file:  not found. Please note: Cppcheck does not need standard library headers to get proper results.
+
+#include "user_share-private.h"
+#include "user_share-common.h"
+#include "http.h"
+
+#ifdef HAVE_BLUETOOTH
+#include <bluetooth-client.h><--- Include file:  not found. Please note: Cppcheck does not need standard library headers to get proper results.
+
+#include "obexftp.h"
+#include "obexpush.h"
+
+#endif /* HAVE_BLUETOOTH */
+
+#include <gio/gio.h><--- Include file:  not found. Please note: Cppcheck does not need standard library headers to get proper results.
+
+#include <stdarg.h><--- Include file:  not found. Please note: Cppcheck does not need standard library headers to get proper results.
+#include <string.h><--- Include file:  not found. Please note: Cppcheck does not need standard library headers to get proper results.
+#include <stdio.h><--- Include file:  not found. Please note: Cppcheck does not need standard library headers to get proper results.
+#include <stdlib.h><--- Include file:  not found. Please note: Cppcheck does not need standard library headers to get proper results.
+#include <signal.h><--- Include file:  not found. Please note: Cppcheck does not need standard library headers to get proper results.
+#include <unistd.h><--- Include file:  not found. Please note: Cppcheck does not need standard library headers to get proper results.
+
+static guint disabled_timeout_tag = 0;
+static GSettings* settings;<--- Shadowed declaration<--- Shadowed declaration<--- Shadowed declaration
+
+#define GSETTINGS_SCHEMA "org.mate.FileSharing"
+#define GSETTINGS_KEY_FILE_SHARING_ENABLED "enabled"
+#define GSETTINGS_KEY_FILE_SHARING_REQUIRE_PASSWORD "require-password"
+
+#ifdef HAVE_BLUETOOTH
+/* MATE Session */
+#define MATE_SESSION_DBUS_NAME      "org.gnome.SessionManager"
+#define MATE_SESSION_DBUS_OBJECT    "/org/gnome/SessionManager"
+#define MATE_SESSION_DBUS_INTERFACE "org.gnome.SessionManager"
+
+static GDBusProxy *session_proxy = NULL;
+static gboolean has_console = TRUE;
+
+static BluetoothClient *client = NULL;
+static gboolean bluetoothd_enabled = FALSE;
+
+#define OBEX_ENABLED (bluetoothd_enabled && has_console)
+
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_ENABLED "bluetooth-enabled"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_ALLOW_WRITE "bluetooth-allow-write"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_REQUIRE_PAIRING "bluetooth-require-pairing"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED "bluetooth-obexpush-enabled"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_ACCEPT_FILES "bluetooth-accept-files"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_NOTIFY "bluetooth-notify"
+
+
+static void
+obex_services_start (void)
+{
+	GSettings *settings;<--- Shadow variable
+
+	if (bluetoothd_enabled == FALSE ||
+	    has_console == FALSE)
+	    	return;
+
+	settings = g_settings_new(GSETTINGS_SCHEMA);
+
+	if (g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED) == TRUE) {
+	    obexpush_up ();
+	}
+	if (g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_ENABLED) == TRUE) {
+	    obexftp_up ();
+	}
+
+	g_object_unref (client);
+}
+
+static void
+obex_services_shutdown (void)
+{
+	obexpush_down ();
+	obexftp_down ();
+}
+
+static void
+session_properties_changed_cb (GDBusProxy      *session,
+			       GVariant        *changed,
+			       char           **invalidated,
+			       gpointer         user_data)
+{
+	GVariant *v;
+
+	v = g_variant_lookup_value (changed, "SessionIsActive", G_VARIANT_TYPE_BOOLEAN);
+	if (v) {
+		has_console = g_variant_get_boolean (v);
+		g_debug ("Received session is active change: now %s", has_console ? "active" : "inactive");
+
+		if (has_console)
+			obex_services_start ();
+		else
+			obex_services_shutdown ();
+
+		g_variant_unref (v);
+	}
+}
+
+static gboolean
+is_session_active (void)
+{
+	GVariant *variant;
+	gboolean is_session_active = FALSE;
+
+	variant = g_dbus_proxy_get_cached_property (session_proxy,
+						    "SessionIsActive");
+	if (variant) {
+		is_session_active = g_variant_get_boolean (variant);
+		g_variant_unref (variant);
+ 	}
+
+	return is_session_active;
+}
+
+static void
+session_init (void)
+{
+	GError *error = NULL;
+
+	session_proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION,
+						       G_DBUS_PROXY_FLAGS_NONE,
+						       NULL,
+						       MATE_SESSION_DBUS_NAME,
+						       MATE_SESSION_DBUS_OBJECT,
+						       MATE_SESSION_DBUS_INTERFACE,
+						       NULL,
+						       &error);
+	if (session_proxy == NULL) {
+		g_warning ("Failed to get session proxy: %s", error->message);
+		g_error_free (error);
+		return;
+	}
+	g_signal_connect (session_proxy, "g-properties-changed",
+			  G_CALLBACK (session_properties_changed_cb),
+			  NULL);
+	has_console = is_session_active ();
+}
+
+static void
+default_adapter_changed (GObject    *gobject,<--- Parameter 'gobject' can be declared as pointer to const
+			 GParamSpec *pspec,
+			 gpointer    user_data)
+{
+	char *adapter;
+	gboolean adapter_powered;
+
+	g_object_get (G_OBJECT (client),
+		      "default-adapter", &adapter,
+		      "default-adapter-powered", &adapter_powered,
+		      NULL);
+	if (adapter != NULL && *adapter != '\0') {
+		bluetoothd_enabled = adapter_powered;
+	} else {
+		bluetoothd_enabled = FALSE;
+	}
+
+	/* Were we called as init, or as a callback */
+	if (gobject != NULL) {
+		if (bluetoothd_enabled != FALSE)
+			obex_services_start ();
+		else
+			obex_services_shutdown ();
+	}
+}
+
+static void
+bluez_init (void)
+{
+	client = bluetooth_client_new ();
+	default_adapter_changed (NULL, NULL, NULL);
+	g_signal_connect (G_OBJECT (client), "notify::default-adapter",
+			  G_CALLBACK (default_adapter_changed), NULL);
+	g_signal_connect (G_OBJECT (client), "notify::default-adapter-powered",
+			  G_CALLBACK (default_adapter_changed), NULL);<--- You might need to cast the function pointer here
+}
+#endif /* HAVE_BLUETOOTH */
+
+static gboolean
+file_sharing_enabled (void)
+{
+	gboolean enabled = TRUE;
+	settings = g_settings_new (GSETTINGS_SCHEMA);
+
+#ifdef HAVE_BLUETOOTH
+	if (g_settings_get_boolean (settings, FILE_SHARING_ENABLED) == FALSE &&
+	    g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_ENABLED) == FALSE &&
+	    g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED) == FALSE)
+#else /* HAVE_BLUETOOTH */
+	if (g_settings_get_boolean (settings, FILE_SHARING_ENABLED) == FALSE)
+#endif /* HAVE_BLUETOOTH */
+		enabled = FALSE;
+
+	g_object_unref (settings);
+
+	return enabled;
+}
+
+static void
+migrate_old_configuration (void)
+{
+	const char *old_config_dir;
+	const char *new_config_dir;
+
+	old_config_dir = g_build_filename (g_get_home_dir (), ".mate2", "user-share", NULL);
+	new_config_dir = g_build_filename (g_get_user_config_dir (), "user-share", NULL);
+	if (g_file_test (old_config_dir, G_FILE_TEST_IS_DIR))
+		g_rename (old_config_dir, new_config_dir);
+
+}
+
+static void
+require_password_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	/* Need to restart to get new password setting */
+	if (http_get_pid () != 0) {
+		http_down ();
+		http_up ();
+	}
+}
+
+/* File sharing was disabled for some time, exit now */
+/* If we re-enable it in the ui, this will be restarted anyway */
+static gboolean
+disabled_timeout_callback (gpointer user_data)
+{
+	GSettings *settings = (GSettings *) user_data;<--- Shadow variable
+	http_down ();
+
+#ifdef HAVE_BLUETOOTH
+	if (g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_ENABLED) == FALSE &&
+	    g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED) == FALSE)
+		_exit (0);
+#else /* HAVE_BLUETOOTH */
+	if (g_settings_get_boolean (settings, FILE_SHARING_ENABLED) == FALSE)
+		_exit (0);
+#endif /* HAVE_BLUETOOTH */
+	return FALSE;
+}
+
+static void
+file_sharing_enabled_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	gboolean enabled;
+
+	if (disabled_timeout_tag != 0) {
+		g_source_remove (disabled_timeout_tag);
+		disabled_timeout_tag = 0;
+	}
+
+	enabled = g_settings_get_boolean (settings,
+					 FILE_SHARING_ENABLED);
+	if (enabled) {
+		if (http_get_pid () == 0) {
+			http_up ();
+		}
+	} else {
+		http_down ();
+		disabled_timeout_tag = g_timeout_add_seconds (3,
+							      (GSourceFunc)disabled_timeout_callback,
+							      settings);
+	}
+}
+
+#ifdef HAVE_BLUETOOTH
+static void
+file_sharing_bluetooth_allow_write_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	if (g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_ENABLED) != FALSE)
+		obexftp_restart ();
+}
+
+static void
+file_sharing_bluetooth_require_pairing_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	if (g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_ENABLED) != FALSE) {
+		/* We need to fully reset the session,
+		 * otherwise the new setting isn't taken into account */
+		obexftp_down ();
+		obexftp_up ();
+	}
+}
+
+static void
+file_sharing_bluetooth_enabled_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	if (g_settings_get_boolean (settings,
+				   FILE_SHARING_BLUETOOTH_ENABLED) == FALSE) {
+		obexftp_down ();
+		if (g_settings_get_boolean (settings, FILE_SHARING_ENABLED) == FALSE &&
+		    g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED) == FALSE) {
+			_exit (0);
+		}
+	} else if (OBEX_ENABLED) {
+		obexftp_up ();
+	}
+}
+
+static void
+file_sharing_bluetooth_obexpush_enabled_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	if (g_settings_get_boolean (settings,
+				   FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED) == FALSE) {
+		obexpush_down ();
+		if (g_settings_get_boolean (settings, FILE_SHARING_ENABLED) == FALSE &&
+		    g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_ENABLED) == FALSE) {
+			_exit (0);
+		}
+	} else if (OBEX_ENABLED) {
+		obexpush_up ();
+	}
+}
+
+static void
+file_sharing_bluetooth_obexpush_accept_files_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	AcceptSetting setting;
+	char *str;
+
+	str = g_settings_get_string (settings, FILE_SHARING_BLUETOOTH_OBEXPUSH_ACCEPT_FILES);
+	setting = accept_setting_from_string (str);
+	g_free (str);
+
+	obexpush_set_accept_files_policy (setting);
+}
+
+static void
+file_sharing_bluetooth_obexpush_notify_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	obexpush_set_notify (g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_OBEXPUSH_NOTIFY));
+}
+#endif /* HAVE_BLUETOOTH */
+
+static RETSIGTYPE
+cleanup_handler (int sig)
+{
+	http_down ();
+#ifdef HAVE_BLUETOOTH
+	obexftp_down ();
+	obexpush_down ();
+#endif /* HAVE_BLUETOOTH */
+	_exit (2);
+}
+
+static int
+x_io_error_handler (Display *xdisplay)
+{
+	http_down ();
+#ifdef HAVE_BLUETOOTH
+	obexftp_down ();
+#endif /* HAVE_BLUETOOTH */
+	_exit (2);
+}
+
+int
+main (int argc, char **argv)
+{
+	GSettings *settings;<--- Shadow variable
+	Display *xdisplay;
+	G_GNUC_UNUSED int x_fd;
+	Window selection_owner;
+	Atom xatom;
+
+	bindtextdomain (GETTEXT_PACKAGE, MATELOCALEDIR);
+	bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
+	textdomain (GETTEXT_PACKAGE);
+
+	gtk_init (&argc, &argv);
+
+	if (g_strcmp0 (g_get_real_name (), "root") == 0) {
+		g_warning ("mate-user-share cannot be started as root for security reasons.");
+		return 1;
+	}
+
+	signal (SIGPIPE, SIG_IGN);
+	signal (SIGINT, cleanup_handler);
+	signal (SIGHUP, cleanup_handler);
+	signal (SIGTERM, cleanup_handler);
+
+	xdisplay = GDK_DISPLAY_XDISPLAY (gdk_display_get_default ());
+	if (xdisplay == NULL) {
+		g_warning ("Can't open display");
+		return 1;
+	}
+
+	xatom = XInternAtom (xdisplay, "_MATE_USER_SHARE", FALSE);
+	selection_owner = XGetSelectionOwner (xdisplay, xatom);
+
+	if (selection_owner != None) {
+		/* There is an owner already, quit */
+		return 1;
+	}
+
+	selection_owner = XCreateSimpleWindow (xdisplay,
+					       RootWindow (xdisplay, 0),
+					       0, 0, 1, 1,
+					       0, 0, 0);
+	XSetSelectionOwner (xdisplay, xatom, selection_owner, CurrentTime);
+
+	if (XGetSelectionOwner (xdisplay, xatom) != selection_owner) {
+		/* Didn't get the selection */
+		return 1;
+	}
+
+	migrate_old_configuration ();
+
+	if (!file_sharing_enabled ())
+		return 1;
+
+	settings = g_settings_new (GSETTINGS_SCHEMA);
+
+	x_fd = ConnectionNumber (xdisplay);
+	XSetIOErrorHandler (x_io_error_handler);
+
+	if (http_init () == FALSE)
+		return 1;
+#ifdef HAVE_BLUETOOTH
+	if (obexftp_init () == FALSE)
+		return 1;
+	if (obexpush_init () == FALSE)
+		return 1;
+#endif /* HAVE_BLUETOOTH */
+
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_ENABLED,
+			     G_CALLBACK (file_sharing_enabled_changed), NULL);
+
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_REQUIRE_PASSWORD,
+			     G_CALLBACK (require_password_changed), NULL);
+
+#ifdef HAVE_BLUETOOTH
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_ENABLED,
+			     G_CALLBACK (file_sharing_bluetooth_enabled_changed), NULL);
+
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_ALLOW_WRITE,
+			     G_CALLBACK (file_sharing_bluetooth_allow_write_changed), NULL);
+
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_REQUIRE_PAIRING,
+			     G_CALLBACK (file_sharing_bluetooth_require_pairing_changed), NULL);
+
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED,
+			     G_CALLBACK (file_sharing_bluetooth_obexpush_enabled_changed), NULL);
+
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_ACCEPT_FILES,
+			     G_CALLBACK (file_sharing_bluetooth_obexpush_accept_files_changed), NULL);
+
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_NOTIFY,
+			     G_CALLBACK (file_sharing_bluetooth_obexpush_notify_changed), NULL);
+
+	bluez_init ();
+	session_init ();
+#endif /* HAVE_BLUETOOTH */
+
+	/* Initial setting */
+	file_sharing_enabled_changed (settings, NULL, NULL);
+#ifdef HAVE_BLUETOOTH
+	file_sharing_bluetooth_enabled_changed (settings, NULL, NULL);
+	file_sharing_bluetooth_obexpush_accept_files_changed (settings, NULL, NULL);
+	file_sharing_bluetooth_obexpush_notify_changed (settings, NULL, NULL);
+	file_sharing_bluetooth_obexpush_enabled_changed (settings, NULL, NULL);
+#endif /* HAVE_BLUETOOTH */
+
+	gtk_main ();
+
+	return 0;
+}
+
+ +
+ +
+ + diff --git a/2024-02-22-185755-8058-cppcheck@00d9a360c0cc_v1.28.0/2.html b/2024-02-22-185755-8058-cppcheck@00d9a360c0cc_v1.28.0/2.html new file mode 100644 index 0000000..9ed3248 --- /dev/null +++ b/2024-02-22-185755-8058-cppcheck@00d9a360c0cc_v1.28.0/2.html @@ -0,0 +1,1567 @@ + + + + + + Cppcheck - HTML report - mate-user-share + + + + + +
+ + + +
+
  1
+  2
+  3
+  4
+  5
+  6
+  7
+  8
+  9
+ 10
+ 11
+ 12
+ 13
+ 14
+ 15
+ 16
+ 17
+ 18
+ 19
+ 20
+ 21
+ 22
+ 23
+ 24
+ 25
+ 26
+ 27
+ 28
+ 29
+ 30
+ 31
+ 32
+ 33
+ 34
+ 35
+ 36
+ 37
+ 38
+ 39
+ 40
+ 41
+ 42
+ 43
+ 44
+ 45
+ 46
+ 47
+ 48
+ 49
+ 50
+ 51
+ 52
+ 53
+ 54
+ 55
+ 56
+ 57
+ 58
+ 59
+ 60
+ 61
+ 62
+ 63
+ 64
+ 65
+ 66
+ 67
+ 68
+ 69
+ 70
+ 71
+ 72
+ 73
+ 74
+ 75
+ 76
+ 77
+ 78
+ 79
+ 80
+ 81
+ 82
+ 83
+ 84
+ 85
+ 86
+ 87
+ 88
+ 89
+ 90
+ 91
+ 92
+ 93
+ 94
+ 95
+ 96
+ 97
+ 98
+ 99
+100
+101
+102
+103
+104
+105
+106
+107
+108
+109
+110
+111
+112
+113
+114
+115
+116
+117
+118
+119
+120
+121
+122
+123
+124
+125
+126
+127
+128
+129
+130
+131
+132
+133
+134
+135
+136
+137
+138
+139
+140
+141
+142
+143
+144
+145
+146
+147
+148
+149
+150
+151
+152
+153
+154
+155
+156
+157
+158
+159
+160
+161
+162
+163
+164
+165
+166
+167
+168
+169
+170
+171
+172
+173
+174
+175
+176
+177
+178
+179
+180
+181
+182
+183
+184
+185
+186
+187
+188
+189
+190
+191
+192
+193
+194
+195
+196
+197
+198
+199
+200
+201
+202
+203
+204
+205
+206
+207
+208
+209
+210
+211
+212
+213
+214
+215
+216
+217
+218
+219
+220
+221
+222
+223
+224
+225
+226
+227
+228
+229
+230
+231
+232
+233
+234
+235
+236
+237
+238
+239
+240
+241
+242
+243
+244
+245
+246
+247
+248
+249
+250
+251
+252
+253
+254
+255
+256
+257
+258
+259
+260
+261
+262
+263
+264
+265
+266
+267
+268
+269
+270
+271
+272
+273
+274
+275
+276
+277
+278
+279
+280
+281
+282
+283
+284
+285
+286
+287
+288
+289
+290
+291
+292
+293
+294
+295
+296
+297
+298
+299
+300
+301
+302
+303
+304
+305
+306
+307
+308
+309
+310
+311
+312
+313
+314
+315
+316
+317
+318
+319
+320
+321
+322
+323
+324
+325
+326
+327
+328
+329
+330
+331
+332
+333
+334
+335
+336
+337
+338
+339
+340
+341
+342
+343
+344
+345
+346
+347
+348
+349
+350
+351
+352
+353
+354
+355
+356
+357
+358
+359
+360
+361
+362
+363
+364
+365
+366
+367
+368
+369
+370
+371
+372
+373
+374
+375
+376
+377
+378
+379
+380
+381
+382
+383
+384
+385
+386
+387
+388
+389
+390
+391
+392
+393
+394
+395
+396
+397
+398
+399
+400
+401
+402
+403
+404
+405
+406
+407
+408
+409
+410
+411
+412
+413
+414
+415
+416
+417
+418
+419
+420
+421
+422
+423
+424
+425
+426
+427
+428
+429
+430
+431
+432
+433
+434
+435
+436
+437
+438
+439
+440
+441
+442
+443
+444
+445
+446
+447
+448
+449
+450
+451
+452
+453
+454
+455
+456
+457
+458
+459
+460
+461
+462
+463
+464
+465
+466
+467
+468
+469
+470
+471
+472
+473
+474
+475
+476
+477
+478
+479
+480
+481
+482
+483
+484
+485
+486
+487
+488
+489
+490
+491
+492
+493
+494
+495
+496
+497
+498
+499
+500
+501
+502
+503
+504
+505
+506
+507
+508
+509
+510
+511
+512
+513
+514
+515
+516
+517
+518
+519
+520
+521
+522
+523
+524
+525
+526
+527
+528
+529
+530
+531
+532
+533
+534
+535
+536
+537
+538
+539
+540
+541
+542
+543
+544
+545
+546
+547
+548
+549
+550
+551
+552
+553
+554
+555
+556
+557
+558
+559
+560
+561
+562
+563
+564
+565
+566
+567
+568
+569
+570
+571
+572
+573
+574
+575
+576
+577
+578
+579
+580
+581
+582
+583
+584
+585
+586
+587
+588
+589
+590
+591
+592
+593
+594
+595
+596
+597
+598
+599
+600
+601
+602
+603
+604
+605
+606
+607
+608
+609
+610
+611
+612
+613
+614
+615
+616
+617
+618
+619
+620
+621
+622
+623
+624
+625
+626
+627
+628
+629
+630
+631
+632
+633
+634
+635
+636
+637
+638
+639
+640
+641
+642
+643
+644
+645
+646
+647
+648
+649
+650
+651
+652
+653
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
+
+/*
+ *  Copyright (C) 2004 Red Hat, Inc.
+ * Copyright (C) 2012-2021 MATE Developers
+ *
+ *  Caja is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU General Public License as
+ *  published by the Free Software Foundation; either version 2 of the
+ *  License, or (at your option) any later version.
+ *
+ *  Caja is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  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
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ *  Authors: Alexander Larsson <alexl@redhat.com>
+ *
+ */
+
+#include "config.h"<--- Include file: "config.h" not found.
+
+#include <string.h><--- Include file:  not found. Please note: Cppcheck does not need standard library headers to get proper results.
+#include <stdio.h><--- Include file:  not found. Please note: Cppcheck does not need standard library headers to get proper results.
+
+#include <gtk/gtk.h><--- Include file:  not found. Please note: Cppcheck does not need standard library headers to get proper results.
+#include <glib/gi18n.h><--- Include file:  not found. Please note: Cppcheck does not need standard library headers to get proper results.
+#include <gio/gio.h><--- Include file:  not found. Please note: Cppcheck does not need standard library headers to get proper results.
+
+#include "user_share-private.h"
+
+#define REALM "Please log in as the user guest"
+#define USER "guest"
+#define GSETTINGS_SCHEMA "org.mate.FileSharing"
+#define GSETTINGS_KEY_FILE_SHARING_ENABLED "enabled"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_ENABLED "bluetooth-enabled"
+#define GSETTINGS_KEY_FILE_SHARING_REQUIRE_PASSWORD "require-password"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_ALLOW_WRITE "bluetooth-allow-write"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_REQUIRE_PAIRING "bluetooth-require-pairing"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED "bluetooth-obexpush-enabled"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_ACCEPT_FILES "bluetooth-accept-files"
+#define GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_NOTIFY "bluetooth-notify"
+
+static GtkBuilder* builder;
+static GSettings* settings;<--- Shadowed declaration<--- Shadowed declaration<--- Shadowed declaration<--- Shadowed declaration<--- Shadowed declaration<--- Shadowed declaration<--- Shadowed declaration<--- Shadowed declaration<--- Shadowed declaration<--- Shadowed declaration
+
+
+static void
+write_out_password (const char *password)
+{
+    char *to_hash;
+    char *ascii_digest;
+    char *line;
+    char *filename;
+    FILE *file;
+
+    to_hash = g_strdup_printf ("%s:%s:%s", USER, REALM, password);
+    ascii_digest = g_compute_checksum_for_string (G_CHECKSUM_MD5, to_hash, strlen (to_hash));
+    g_free (to_hash);
+    line = g_strdup_printf ("%s:%s:%s\n", USER, REALM, ascii_digest);
+    g_free (ascii_digest);
+
+    filename = g_build_filename (g_get_user_config_dir (), "user-share", "passwd", NULL);
+
+    file = fopen (filename, "w");
+    if (file != NULL) {
+	fwrite (line, strlen (line), 1, file);
+	fclose (file);
+    }
+
+    g_free (filename);
+    g_free (line);
+}
+
+static void
+flush_password (void)
+{
+    GtkWidget *password_entry;
+    const char *password;
+
+    password_entry = GTK_WIDGET (gtk_builder_get_object (builder, "password_entry"));
+
+    if (g_object_get_data (G_OBJECT( password_entry), "user_edited")) {
+	password = gtk_entry_get_text (GTK_ENTRY (password_entry));
+	if (password != NULL && password[0] != 0)
+	    write_out_password (password);
+    }
+}
+
+
+static void
+update_ui (void)
+{
+    GSettings *settings;<--- Shadow variable
+    gboolean enabled;
+#ifdef HAVE_BLUETOOTH
+    gboolean bluetooth_enabled, bluetooth_write_enabled, require_pairing_enabled;
+    gboolean bluetooth_obexpush_enabled, bluetooth_obexpush_notify;
+#endif /* HAVE_BLUETOOTH */
+    char *str;
+    PasswordSetting password_setting;
+    AcceptSetting accept_setting;<--- Unused variable: accept_setting
+    GtkWidget *check;
+    GtkWidget *password_combo;
+    GtkWidget *password_entry;
+#ifdef HAVE_BLUETOOTH
+    GtkWidget *vbox_share_bluetooth;
+    GtkWidget *vbox_receive_bluetooth;
+    GtkWidget *bluetooth_check;
+    GtkWidget *allow_write_bluetooth_check;
+    GtkWidget *require_pairing_check;
+    GtkWidget *enable_obexpush_check;
+    GtkWidget *accept_obexpush_combo;
+    GtkWidget *notify_received_obexpush_check;
+#endif /* HAVE_BLUETOOTH */
+
+    settings = g_settings_new (GSETTINGS_SCHEMA);
+
+    enabled = g_settings_get_boolean (settings,
+				     FILE_SHARING_ENABLED);
+
+    str = g_settings_get_string (settings, FILE_SHARING_REQUIRE_PASSWORD);
+    password_setting = password_setting_from_string (str);
+    g_free (str);
+
+#ifdef HAVE_BLUETOOTH
+    bluetooth_enabled = g_settings_get_boolean (settings,
+    					       FILE_SHARING_BLUETOOTH_ENABLED);
+    bluetooth_write_enabled = g_settings_get_boolean (settings,
+						     FILE_SHARING_BLUETOOTH_ALLOW_WRITE);
+    require_pairing_enabled = g_settings_get_boolean (settings,
+    						     FILE_SHARING_BLUETOOTH_REQUIRE_PAIRING);
+    bluetooth_obexpush_enabled = g_settings_get_boolean (settings,
+    							FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED);
+    bluetooth_obexpush_notify = g_settings_get_boolean (settings,
+    						       FILE_SHARING_BLUETOOTH_OBEXPUSH_NOTIFY);
+
+    str = g_settings_get_string (settings, FILE_SHARING_BLUETOOTH_OBEXPUSH_ACCEPT_FILES);
+    accept_setting = accept_setting_from_string (str);
+    g_free (str);
+#endif /* HAVE_BLUETOOTH */
+
+    check = GTK_WIDGET (gtk_builder_get_object (builder, "enable_check"));
+    password_combo = GTK_WIDGET (gtk_builder_get_object (builder, "password_combo"));
+    password_entry = GTK_WIDGET (gtk_builder_get_object (builder, "password_entry"));
+#ifdef HAVE_BLUETOOTH
+    vbox_share_bluetooth = GTK_WIDGET (gtk_builder_get_object (builder, "vbox_share_bluetooth"));
+    vbox_receive_bluetooth = GTK_WIDGET (gtk_builder_get_object (builder, "vbox_receive_bluetooth"));
+    bluetooth_check = GTK_WIDGET (gtk_builder_get_object (builder, "enable_bluetooth_check"));
+    allow_write_bluetooth_check = GTK_WIDGET (gtk_builder_get_object (builder, "allow_write_bluetooth_check"));
+    require_pairing_check = GTK_WIDGET (gtk_builder_get_object (builder, "require_pairing_check"));
+    enable_obexpush_check = GTK_WIDGET (gtk_builder_get_object (builder, "enable_obexpush_check"));
+    accept_obexpush_combo = GTK_WIDGET (gtk_builder_get_object (builder, "accept_obexpush_combo"));
+    notify_received_obexpush_check = GTK_WIDGET (gtk_builder_get_object (builder, "notify_received_obexpush_check"));
+#endif /* HAVE_BLUETOOTH */
+
+    /* Network */
+    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (check), enabled);
+    gtk_widget_set_sensitive (password_combo, enabled);
+    gtk_widget_set_sensitive (password_entry, enabled && password_setting != PASSWORD_NEVER);
+
+    gtk_combo_box_set_active (GTK_COMBO_BOX (password_combo),
+			      password_setting);
+
+#ifdef HAVE_BLUETOOTH
+    /* Bluetooth ObexFTP */
+    gtk_widget_set_visible (vbox_share_bluetooth, TRUE);
+    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (bluetooth_check), bluetooth_enabled);
+    gtk_widget_set_sensitive (allow_write_bluetooth_check, bluetooth_enabled);
+    gtk_widget_set_sensitive (require_pairing_check, bluetooth_enabled);
+
+    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (allow_write_bluetooth_check),
+    				  bluetooth_write_enabled);
+    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (require_pairing_check),
+    				  require_pairing_enabled);
+
+    /* Bluetooth ObexPush */
+    gtk_widget_set_visible (vbox_receive_bluetooth, TRUE);
+    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (enable_obexpush_check), bluetooth_obexpush_enabled);
+    gtk_widget_set_sensitive (accept_obexpush_combo, bluetooth_obexpush_enabled);
+    gtk_widget_set_sensitive (notify_received_obexpush_check, bluetooth_obexpush_enabled);
+
+    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (notify_received_obexpush_check),
+    				  bluetooth_obexpush_notify);
+
+    gtk_combo_box_set_active (GTK_COMBO_BOX (accept_obexpush_combo),
+    			      accept_setting);
+#endif /* HAVE_BLUETOOTH */
+
+    g_object_unref (settings);
+}
+
+static void
+file_sharing_enabled_changed (GSettings *settings, gchar *key, gpointer data)
+{
+    update_ui ();
+}
+
+static void
+password_required_changed (GSettings *settings, gchar *key, gpointer data)
+{
+    update_ui ();
+}
+
+#ifdef HAVE_BLUETOOTH
+static void
+file_sharing_bluetooth_enabled_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	update_ui ();
+}
+
+static void
+file_sharing_bluetooth_allow_write_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	update_ui ();
+}
+
+static void
+file_sharing_bluetooth_require_pairing_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	update_ui ();
+}
+
+static void
+file_sharing_bluetooth_obexpush_enabled_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	update_ui ();
+}
+
+static void
+file_sharing_bluetooth_obexpush_accept_files_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	update_ui ();
+}
+
+static void
+file_sharing_bluetooth_obexpush_notify_changed (GSettings *settings, gchar *key, gpointer data)
+{
+	update_ui ();
+}
+#endif /* HAVE_BLUETOOTH */
+
+static void
+password_combo_changed (GtkComboBox *combo_box)
+{
+    GSettings *settings;<--- Shadow variable
+    guint setting;
+
+    setting = gtk_combo_box_get_active (combo_box);
+
+    settings = g_settings_new (GSETTINGS_SCHEMA) ;
+
+    g_settings_set_string (settings,
+			     FILE_SHARING_REQUIRE_PASSWORD,
+			     password_string_from_setting (setting));
+    g_object_unref (settings);
+}
+
+static void
+launch_share (void)
+{
+	if (!g_spawn_command_line_async (USER_SHARE_PROGRAM, NULL))
+		g_warning ("Unable to start mate-user-share program");
+}
+
+#ifdef HAVE_BLUETOOTH
+static void
+enable_bluetooth_check_toggled (GtkWidget *check)
+{
+	GSettings *settings;<--- Shadow variable
+	gboolean enabled;
+
+	enabled = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check));
+
+	settings = g_settings_new (GSETTINGS_SCHEMA) ;
+
+	g_settings_set_boolean (settings,
+			       FILE_SHARING_BLUETOOTH_ENABLED,
+			       enabled);
+
+	g_object_unref (settings);
+
+	if (enabled != FALSE)
+		launch_share ();
+}
+#endif /* HAVE_BLUETOOTH */
+
+static void
+enable_check_toggled (GtkWidget *check)
+{
+	GSettings *settings;<--- Shadow variable
+	gboolean enabled;
+
+	enabled = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check));
+
+	settings = g_settings_new (GSETTINGS_SCHEMA);
+
+	g_settings_set_boolean (settings,
+			       FILE_SHARING_ENABLED,
+			       enabled);
+
+	g_object_unref (settings);
+
+	if (enabled != FALSE)
+		launch_share ();
+}
+
+static void
+password_entry_changed (GtkEditable *editable)
+{
+	g_object_set_data (G_OBJECT (editable),
+			   "user_edited", GINT_TO_POINTER (1));
+	flush_password ();
+}
+
+#ifdef HAVE_BLUETOOTH
+static void
+bluetooth_allow_write_check_toggled (GtkWidget *check)
+{
+	GSettings *settings;<--- Shadow variable
+	gboolean enabled;
+
+	enabled = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check));
+
+	settings = g_settings_new (GSETTINGS_SCHEMA) ;
+
+	g_settings_set_boolean (settings,
+			       FILE_SHARING_BLUETOOTH_ALLOW_WRITE,
+			       enabled);
+
+	g_object_unref (settings);
+}
+
+static void
+bluetooth_require_pairing_check_toggled (GtkWidget *check)
+{
+	GSettings *settings;<--- Shadow variable
+	gboolean enabled;
+
+	enabled = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check));
+
+	settings = g_settings_new (GSETTINGS_SCHEMA) ;
+
+	g_settings_set_boolean (settings,
+			       FILE_SHARING_BLUETOOTH_REQUIRE_PAIRING,
+			       enabled);
+
+	g_object_unref (settings);
+}
+
+static void
+enable_obexpush_check_toggled (GtkWidget *check)
+{
+	GSettings *settings;<--- Shadow variable
+	gboolean enabled;
+
+	enabled = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check));
+
+	settings = g_settings_new (GSETTINGS_SCHEMA) ;
+
+	g_settings_set_boolean (settings,
+			       FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED,
+			       enabled);
+
+	g_object_unref (settings);
+
+	if (enabled != FALSE)
+		launch_share ();
+}
+
+static void
+accept_obexpush_combo_changed (GtkComboBox *combo_box)
+{
+    GSettings *settings;<--- Shadow variable
+    guint setting;
+
+    setting = gtk_combo_box_get_active (combo_box);
+
+    settings = g_settings_new (GSETTINGS_SCHEMA) ;
+
+    g_settings_set_string (settings,
+			     FILE_SHARING_BLUETOOTH_OBEXPUSH_ACCEPT_FILES,
+			     accept_string_from_setting (setting));
+    g_object_unref (settings);
+}
+
+static void
+notify_received_obexpush_check_toggled (GtkWidget *check)
+{
+	GSettings *settings;<--- Shadow variable
+	gboolean enabled;
+
+	enabled = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check));
+
+	settings = g_settings_new (GSETTINGS_SCHEMA) ;
+
+	g_settings_set_boolean (settings,
+			       FILE_SHARING_BLUETOOTH_OBEXPUSH_NOTIFY,
+			       enabled);
+
+	g_object_unref (settings);
+}
+#endif /* HAVE_BLUETOOTH */
+
+static GtkWidget *
+error_dialog (const char *title,
+	      const char *reason,
+	      GtkWindow *parent)
+{
+	GtkWidget *error_dialog;
+
+	if (reason == NULL)
+		reason = _("No reason");
+
+	error_dialog =
+		gtk_message_dialog_new (parent,
+					GTK_DIALOG_MODAL,
+					GTK_MESSAGE_ERROR,
+					GTK_BUTTONS_OK,
+					"%s", title);
+	gtk_message_dialog_format_secondary_text
+		(GTK_MESSAGE_DIALOG (error_dialog), "%s", reason);
+
+	gtk_window_set_title (GTK_WINDOW (error_dialog), ""); /* as per HIG */
+	gtk_container_set_border_width (GTK_CONTAINER (error_dialog), 5);
+	gtk_dialog_set_default_response (GTK_DIALOG (error_dialog),
+					 GTK_RESPONSE_OK);
+	gtk_window_set_modal (GTK_WINDOW (error_dialog), TRUE);
+
+	return error_dialog;
+}
+
+static void
+help_button_clicked (GtkButton *button, GtkWidget *window)
+{
+	GError *error = NULL;
+
+	if (gtk_show_uri_on_window (GTK_WINDOW (window), "help:mate-user-share", gtk_get_current_event_time (), &error) == FALSE) {
+		GtkWidget *dialog;
+
+		dialog = error_dialog (_("Could not display the help contents."), error->message, GTK_WINDOW (window));
+		g_signal_connect (G_OBJECT (dialog), "response", G_CALLBACK
+				  (gtk_widget_destroy), error_dialog);
+		gtk_window_present (GTK_WINDOW (dialog));
+
+		g_error_free (error);
+	}
+}
+
+static GtkWidget *
+create_window (void)
+{
+    GError *error = NULL;
+    GSettings *settings;<--- Shadow variable
+    GtkWidget *check;
+    GtkWidget *password_combo;
+    GtkWidget *password_entry;
+#ifdef HAVE_BLUETOOTH
+    GtkWidget *bluetooth_check;
+    GtkWidget *bluetooth_allow_write_check;
+    GtkWidget *require_pairing_check;
+    GtkWidget *enable_obexpush_check;
+    GtkWidget *accept_obexpush_combo;
+    GtkWidget *notify_received_obexpush_check;
+#endif /* HAVE_BLUETOOTH */
+    GtkWidget *window;
+    GtkListStore *store;
+    GtkCellRenderer *cell;
+    GtkTreeIter iter;
+
+    builder = gtk_builder_new ();
+    gtk_builder_add_from_file (builder, DATADIR"file-share-properties.ui", &error);
+
+    if (error) {
+      GtkWidget *dialog;
+
+      dialog = error_dialog (_("Could not build interface."), error->message, NULL);
+      gtk_dialog_run (GTK_DIALOG (dialog));
+      gtk_widget_destroy (dialog);
+
+      g_error_free (error);
+      return NULL;
+    }
+
+    window = GTK_WIDGET (gtk_builder_get_object (builder, "user_share_dialog"));
+
+    settings = g_settings_new (GSETTINGS_SCHEMA);
+
+    check = GTK_WIDGET (gtk_builder_get_object (builder, "enable_check"));
+    password_combo = GTK_WIDGET (gtk_builder_get_object (builder, "password_combo"));
+    password_entry = GTK_WIDGET (gtk_builder_get_object (builder, "password_entry"));
+#ifdef HAVE_BLUETOOTH
+    bluetooth_check = GTK_WIDGET (gtk_builder_get_object (builder, "enable_bluetooth_check"));
+    bluetooth_allow_write_check = GTK_WIDGET (gtk_builder_get_object (builder, "allow_write_bluetooth_check"));
+    require_pairing_check = GTK_WIDGET (gtk_builder_get_object (builder, "require_pairing_check"));
+    enable_obexpush_check = GTK_WIDGET (gtk_builder_get_object (builder, "enable_obexpush_check"));
+    accept_obexpush_combo = GTK_WIDGET (gtk_builder_get_object (builder, "accept_obexpush_combo"));
+    notify_received_obexpush_check = GTK_WIDGET (gtk_builder_get_object (builder, "notify_received_obexpush_check"));
+#endif /* HAVE_BLUETOOTH */
+
+    store = gtk_list_store_new (1, G_TYPE_STRING);
+    gtk_combo_box_set_model (GTK_COMBO_BOX (password_combo),
+			     GTK_TREE_MODEL (store));
+    cell = gtk_cell_renderer_text_new ();
+    gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (password_combo), cell, TRUE);
+    gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (password_combo), cell,
+				    "text", 0,
+				    NULL);
+
+    /* Keep in same order as enum */
+    gtk_list_store_append (store, &iter);
+    gtk_list_store_set (store, &iter, 0,
+			_("Never"), -1);
+    gtk_list_store_append (store, &iter);
+    gtk_list_store_set (store, &iter, 0,
+			_("When writing files"), -1);
+    gtk_list_store_append (store, &iter);
+    gtk_list_store_set (store, &iter, 0,
+			_("Always"), -1);
+    g_object_unref (store);
+
+    /* We can't read the password from the text, just set it to something */
+    gtk_entry_set_text (GTK_ENTRY (password_entry), "none");
+    g_object_set_data (G_OBJECT (password_entry),
+		       "user_edited", GINT_TO_POINTER (0));
+    g_signal_connect (password_entry,
+		      "changed", G_CALLBACK (password_entry_changed), NULL);
+
+#ifdef HAVE_BLUETOOTH
+    /* Accept files combo */
+    store = gtk_list_store_new (1, G_TYPE_STRING);
+    gtk_combo_box_set_model (GTK_COMBO_BOX (accept_obexpush_combo),
+			     GTK_TREE_MODEL (store));
+    cell = gtk_cell_renderer_text_new ();
+    gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (accept_obexpush_combo), cell, TRUE);
+    gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (accept_obexpush_combo), cell,
+				    "text", 0,
+				    NULL);
+
+    /* Keep in same order as enum */
+    gtk_list_store_append (store, &iter);
+    gtk_list_store_set (store, &iter, 0,
+			_("Always"), -1);
+    gtk_list_store_append (store, &iter);
+    gtk_list_store_set (store, &iter, 0,
+			_("Only for set up devices"), -1);
+    //FIXME implement
+#if 0
+    gtk_list_store_append (store, &iter);
+    gtk_list_store_set (store, &iter, 0,
+    			_("Ask"), -1);
+#endif
+    g_object_unref (store);
+#endif /* HAVE_BLUETOOTH */
+
+    g_signal_connect (check,
+		      "toggled", G_CALLBACK (enable_check_toggled), NULL);
+    g_signal_connect (password_combo,
+		      "changed", G_CALLBACK (password_combo_changed), NULL);
+#ifdef HAVE_BLUETOOTH
+    g_signal_connect (bluetooth_check,
+    		      "toggled", G_CALLBACK (enable_bluetooth_check_toggled), NULL);
+    g_signal_connect (bluetooth_allow_write_check,
+    		      "toggled", G_CALLBACK (bluetooth_allow_write_check_toggled), NULL);
+    g_signal_connect (require_pairing_check,
+    		      "toggled", G_CALLBACK (bluetooth_require_pairing_check_toggled), NULL);
+    g_signal_connect (enable_obexpush_check,
+    		      "toggled", G_CALLBACK (enable_obexpush_check_toggled), NULL);
+    g_signal_connect (accept_obexpush_combo,
+    		      "changed", G_CALLBACK (accept_obexpush_combo_changed), NULL);
+    g_signal_connect (notify_received_obexpush_check,
+    		      "toggled", G_CALLBACK (notify_received_obexpush_check_toggled), NULL);
+#endif /* HAVE_BLUETOOTH */
+
+    g_signal_connect_swapped (GTK_WIDGET (gtk_builder_get_object (builder, "close_button")),
+                              "clicked", G_CALLBACK (gtk_widget_destroy), window);
+    g_signal_connect (GTK_WIDGET (gtk_builder_get_object (builder, "help_button")),
+		      "clicked", G_CALLBACK (help_button_clicked),
+		      gtk_builder_get_object (builder, "user_share_dialog"));
+
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_ENABLED,
+			     G_CALLBACK (file_sharing_enabled_changed), NULL);
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_REQUIRE_PASSWORD,
+			     G_CALLBACK (password_required_changed), NULL);
+#ifdef HAVE_BLUETOOTH
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_ENABLED,
+			     G_CALLBACK (file_sharing_bluetooth_enabled_changed), NULL);
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_ALLOW_WRITE,
+			     G_CALLBACK (file_sharing_bluetooth_allow_write_changed), NULL);
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_REQUIRE_PAIRING,
+			     G_CALLBACK (file_sharing_bluetooth_require_pairing_changed), NULL);
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_ENABLED,
+			     G_CALLBACK (file_sharing_bluetooth_obexpush_enabled_changed), NULL);
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_ACCEPT_FILES,
+			     G_CALLBACK (file_sharing_bluetooth_obexpush_accept_files_changed), NULL);
+    g_signal_connect (settings,
+			     "changed::" GSETTINGS_KEY_FILE_SHARING_BLUETOOTH_OBEXPUSH_NOTIFY,
+			     G_CALLBACK (file_sharing_bluetooth_obexpush_notify_changed), NULL);
+#endif /* HAVE_BLUETOOTH */
+
+    update_ui ();
+
+    return window;
+}
+
+static void
+activate (GtkApplication *app)
+{
+    GList *list;
+    GtkWidget *window;
+
+    list = gtk_application_get_windows (app);
+
+    if (list) {
+        gtk_window_present (GTK_WINDOW (list->data));
+    } else {
+        window = create_window ();
+        gtk_window_set_application (GTK_WINDOW (window), app);
+        gtk_widget_show (window);
+    }
+}
+
+int
+main (int argc, char *argv[])
+{
+    GtkApplication *app;
+    gint status;
+
+    bindtextdomain (GETTEXT_PACKAGE, MATELOCALEDIR);
+    bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
+    textdomain (GETTEXT_PACKAGE);
+
+    app = gtk_application_new ("org.mate.user-share.properties",
+                               G_APPLICATION_FLAGS_NONE);
+    g_signal_connect (app, "activate", G_CALLBACK (activate), NULL);
+
+    status = g_application_run (G_APPLICATION (app), argc, argv);
+
+    g_object_unref (app);
+
+    return status;
+}
+
+ +
+ +
+ + diff --git a/2024-02-22-185755-8058-cppcheck@00d9a360c0cc_v1.28.0/3.html b/2024-02-22-185755-8058-cppcheck@00d9a360c0cc_v1.28.0/3.html new file mode 100644 index 0000000..327930b --- /dev/null +++ b/2024-02-22-185755-8058-cppcheck@00d9a360c0cc_v1.28.0/3.html @@ -0,0 +1,1123 @@ + + + + + + Cppcheck - HTML report - mate-user-share + + + + + +
+ + + +
+
  1
+  2
+  3
+  4
+  5
+  6
+  7
+  8
+  9
+ 10
+ 11
+ 12
+ 13
+ 14
+ 15
+ 16
+ 17
+ 18
+ 19
+ 20
+ 21
+ 22
+ 23
+ 24
+ 25
+ 26
+ 27
+ 28
+ 29
+ 30
+ 31
+ 32
+ 33
+ 34
+ 35
+ 36
+ 37
+ 38
+ 39
+ 40
+ 41
+ 42
+ 43
+ 44
+ 45
+ 46
+ 47
+ 48
+ 49
+ 50
+ 51
+ 52
+ 53
+ 54
+ 55
+ 56
+ 57
+ 58
+ 59
+ 60
+ 61
+ 62
+ 63
+ 64
+ 65
+ 66
+ 67
+ 68
+ 69
+ 70
+ 71
+ 72
+ 73
+ 74
+ 75
+ 76
+ 77
+ 78
+ 79
+ 80
+ 81
+ 82
+ 83
+ 84
+ 85
+ 86
+ 87
+ 88
+ 89
+ 90
+ 91
+ 92
+ 93
+ 94
+ 95
+ 96
+ 97
+ 98
+ 99
+100
+101
+102
+103
+104
+105
+106
+107
+108
+109
+110
+111
+112
+113
+114
+115
+116
+117
+118
+119
+120
+121
+122
+123
+124
+125
+126
+127
+128
+129
+130
+131
+132
+133
+134
+135
+136
+137
+138
+139
+140
+141
+142
+143
+144
+145
+146
+147
+148
+149
+150
+151
+152
+153
+154
+155
+156
+157
+158
+159
+160
+161
+162
+163
+164
+165
+166
+167
+168
+169
+170
+171
+172
+173
+174
+175
+176
+177
+178
+179
+180
+181
+182
+183
+184
+185
+186
+187
+188
+189
+190
+191
+192
+193
+194
+195
+196
+197
+198
+199
+200
+201
+202
+203
+204
+205
+206
+207
+208
+209
+210
+211
+212
+213
+214
+215
+216
+217
+218
+219
+220
+221
+222
+223
+224
+225
+226
+227
+228
+229
+230
+231
+232
+233
+234
+235
+236
+237
+238
+239
+240
+241
+242
+243
+244
+245
+246
+247
+248
+249
+250
+251
+252
+253
+254
+255
+256
+257
+258
+259
+260
+261
+262
+263
+264
+265
+266
+267
+268
+269
+270
+271
+272
+273
+274
+275
+276
+277
+278
+279
+280
+281
+282
+283
+284
+285
+286
+287
+288
+289
+290
+291
+292
+293
+294
+295
+296
+297
+298
+299
+300
+301
+302
+303
+304
+305
+306
+307
+308
+309
+310
+311
+312
+313
+314
+315
+316
+317
+318
+319
+320
+321
+322
+323
+324
+325
+326
+327
+328
+329
+330
+331
+332
+333
+334
+335
+336
+337
+338
+339
+340
+341
+342
+343
+344
+345
+346
+347
+348
+349
+350
+351
+352
+353
+354
+355
+356
+357
+358
+359
+360
+361
+362
+363
+364
+365
+366
+367
+368
+369
+370
+371
+372
+373
+374
+375
+376
+377
+378
+379
+380
+381
+382
+383
+384
+385
+386
+387
+388
+389
+390
+391
+392
+393
+394
+395
+396
+397
+398
+399
+400
+401
+402
+403
+404
+405
+406
+407
+408
+409
+410
+411
+412
+413
+414
+415
+416
+417
+418
+419
+420
+421
+422
+423
+424
+425
+426
+427
+428
+429
+430
+431
+432
+433
+434
+435
+436
+437
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
+
+/*
+ *  Copyright (C) 2004-2008 Red Hat, Inc.
+ * Copyright (C) 2012-2021 MATE Developers
+ *
+ *  Caja is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU General Public License as
+ *  published by the Free Software Foundation; either version 2 of the
+ *  License, or (at your option) any later version.
+ *
+ *  Caja is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  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
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ *  Authors: Alexander Larsson <alexl@redhat.com>
+ *
+ */
+
+#include "config.h"<--- Include file: "config.h" not found.
+
+#include <glib.h><--- Include file:  not found. Please note: Cppcheck does not need standard library headers to get proper results.
+#include <glib/gi18n.h><--- Include file:  not found. Please note: Cppcheck does not need standard library headers to get proper results.
+#include <X11/Xlib.h><--- Include file:  not found. Please note: Cppcheck does not need standard library headers to get proper results.
+
+#include <gio/gio.h><--- Include file:  not found. Please note: Cppcheck does not need standard library headers to get proper results.
+
+#include <stdarg.h><--- Include file:  not found. Please note: Cppcheck does not need standard library headers to get proper results.
+#include <string.h><--- Include file:  not found. Please note: Cppcheck does not need standard library headers to get proper results.
+#include <stdio.h><--- Include file:  not found. Please note: Cppcheck does not need standard library headers to get proper results.
+#include <stdlib.h><--- Include file:  not found. Please note: Cppcheck does not need standard library headers to get proper results.
+#include <signal.h><--- Include file:  not found. Please note: Cppcheck does not need standard library headers to get proper results.
+#include <unistd.h><--- Include file:  not found. Please note: Cppcheck does not need standard library headers to get proper results.
+#include <sys/types.h><--- Include file:  not found. Please note: Cppcheck does not need standard library headers to get proper results.
+#include <sys/socket.h><--- Include file:  not found. Please note: Cppcheck does not need standard library headers to get proper results.
+#include <netinet/in.h><--- Include file:  not found. Please note: Cppcheck does not need standard library headers to get proper results.
+#include <sys/stat.h><--- Include file:  not found. Please note: Cppcheck does not need standard library headers to get proper results.
+
+#ifdef HAVE_SELINUX
+#include <selinux/selinux.h><--- Include file:  not found. Please note: Cppcheck does not need standard library headers to get proper results.
+#endif
+
+#include "user_share-common.h"
+#include "user_share-private.h"
+#include "http.h"
+
+/* From avahi-common/domain.h */
+#define AVAHI_LABEL_MAX 64
+
+#define GSETTINGS_SCHEMA "org.mate.FileSharing"
+
+static pid_t httpd_pid = 0;
+
+static int
+get_port (void)
+{
+	int sock;
+	struct sockaddr_in addr;
+	int reuse;
+	socklen_t len;
+
+	sock = socket (PF_INET, SOCK_STREAM, 0);
+	if (sock < 0) {
+		return -1;
+	}
+
+	memset (&addr, 0, sizeof (addr));
+	addr.sin_port = 0;
+	addr.sin_addr.s_addr = INADDR_ANY;
+	addr.sin_family = AF_INET;
+
+	reuse = 1;
+	setsockopt (sock, SOL_SOCKET, SO_REUSEADDR, &reuse, sizeof (reuse));
+	if (bind (sock, (struct sockaddr *)&addr, sizeof (addr)) == -1) {
+		close (sock);
+		return -1;
+	}
+
+	len = sizeof (addr);
+	if (getsockname (sock, (struct sockaddr *)&addr, &len) == -1) {
+		close (sock);
+		return -1;
+	}
+
+#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__APPLE__) || defined(__OpenBSD__)
+	/* XXX This exposes a potential race condition, but without this,
+	 * httpd will not start on the above listed platforms due to the fact
+	 * that SO_REUSEADDR is also needed when Apache binds to the listening
+	 * socket.  At this time, Apache does not support that socket option.
+	 */
+	close (sock);
+#endif
+	return ntohs (addr.sin_port);
+}
+
+static char *
+truncate_name (const char *name)
+{
+	const char *end;
+
+	end = g_utf8_find_prev_char (name, name + 64);
+	g_assert (end != NULL);
+	return g_strndup (name, end - name);
+}
+
+static char *
+get_share_name (void)
+{
+	static char *name = NULL;
+	const char *host_name;
+	char *str;
+
+	if (name == NULL) {
+		host_name = g_get_host_name ();
+		if (strcmp (host_name, "localhost") == 0) {
+			/* Translators: The %s will get filled in with the user name
+			   of the user, to form a genitive. If this is difficult to
+			   translate correctly so that it will work correctly in your
+			   language, you may use something equivalent to
+			   "Public files of %s", or leave out the %s altogether.
+			   In the latter case, please put "%.0s" somewhere in the string,
+			   which will match the user name string passed by the C code,
+			   but not put the user name in the final string. This is to
+			   avoid the warning that msgfmt might otherwise generate. */
+			name = g_strdup_printf (_("%s's public files"), g_get_user_name ());
+		} else {
+			/* Translators: This is similar to the string before, only it
+			   has the hostname in it too. */
+			name = g_strdup_printf (_("%s's public files on %s"),
+						g_get_user_name (),
+						host_name);
+		}
+
+	}
+	/* And truncate */
+	if (strlen (name) < AVAHI_LABEL_MAX)
+		return name;
+
+	str = truncate_name (name);
+	g_free (name);
+	name = str;
+
+	return name;
+}
+
+static void
+ensure_conf_dir (void)
+{
+	char *dirname;
+
+	dirname = g_build_filename (g_get_user_config_dir (), "user-share", NULL);
+	g_mkdir_with_parents (dirname, 0755);
+	g_free (dirname);
+}
+
+static void
+httpd_child_setup (gpointer user_data)
+{
+#ifdef HAVE_SELINUX
+	char *mycon;
+	/* If selinux is enabled, avoid transitioning to the httpd_t context,
+	   as this normally means you can't read the users homedir. */
+	if (is_selinux_enabled()) {
+		if (getcon (&mycon) < 0) {
+			abort ();
+		}
+		if (setexeccon (mycon) < 0)
+			abort ();
+		freecon (mycon);
+	}
+#endif
+}
+
+static const char *known_httpd_locations [] = {
+	HTTPD_PROGRAM,
+	"/usr/sbin/httpd",
+	"/usr/sbin/httpd2",
+	"/usr/sbin/apache2",
+	NULL
+};
+
+static char*
+get_httpd_program (void)
+{
+	int i;
+
+	for (i = 0; known_httpd_locations[i]; i++) {
+		if (known_httpd_locations[i][0] == '\0') {
+			/* empty string as first element, happens when
+			 * configured --with-httpd=auto */
+			continue;
+		}
+		if (g_file_test (known_httpd_locations[i], G_FILE_TEST_IS_EXECUTABLE)
+				&& ! g_file_test (known_httpd_locations[i], G_FILE_TEST_IS_DIR)) {
+			return g_strdup (known_httpd_locations[i]);
+		}
+	}
+	return NULL;
+}
+
+static const char *known_httpd_modules_locations [] = {
+	HTTPD_MODULES_PATH,
+	"/etc/httpd/modules",
+	"/usr/lib/apache2/modules",
+	NULL
+};
+
+static gchar*
+get_httpd_modules_path (void)
+{
+	int i;
+
+	for (i = 0; known_httpd_modules_locations[i]; i++) {
+		if (known_httpd_modules_locations[i][0] == '\0') {
+			/* empty string as first element, happens when
+			 * configured --with-httpd=auto */
+			continue;
+		}
+		if (g_file_test (known_httpd_modules_locations[i], G_FILE_TEST_IS_EXECUTABLE)
+				&& g_file_test (known_httpd_modules_locations[i], G_FILE_TEST_IS_DIR)) {
+			return g_strdup (known_httpd_modules_locations[i]);
+		}
+	}
+	return NULL;
+}
+
+static GRegex *version_regex = NULL;
+
+static char*
+get_httpd_config (const char *httpd_program)
+{
+	gchar *standard_output;
+	gchar *cmd_line;
+	GMatchInfo *match_info;
+	gchar *version_number = NULL;
+	gchar *config;
+
+	cmd_line = g_strdup_printf ("%s -v", httpd_program);
+	if (! g_spawn_command_line_sync (cmd_line, &standard_output, NULL, NULL, NULL)) {
+		g_free (cmd_line);
+		return NULL;
+	}
+	g_free (cmd_line);
+
+	if (version_regex == NULL) {
+		version_regex = g_regex_new ("\\d\\.\\d", 0, 0, NULL);
+	}
+
+	if (g_regex_match (version_regex, standard_output, 0, &match_info)) {
+		while (g_match_info_matches (match_info)) {
+			version_number = g_match_info_fetch (match_info, 0);
+			break;
+		}
+		g_match_info_free (match_info);
+		g_free (standard_output);
+	} else {
+		/* Failed to parse httpd version number */
+		g_warning ("Could not parse '%s' as a version for httpd", standard_output);
+		g_free (standard_output);
+		/* assume it is 2.2 */
+		version_number = g_strdup ("2.2");
+	}
+
+	config = g_strdup_printf (HTTPD_CONFIG_TEMPLATE, version_number);
+	g_free (version_number);
+
+	return config;
+}
+
+static gboolean
+spawn_httpd (int port, pid_t *pid_out)
+{
+	char *free1, *free2, *free3, *free4, *free5, *free6, *free7, *free8, *free9;
+	gboolean res;
+	char *argv[10];
+	char *env[10];
+	int i;
+	gint status;
+	char *pid_filename;
+	char *pidfile;
+	GError *error;
+	gboolean got_pidfile;
+	GSettings *settings;
+	char *str;
+	char *public_dir;
+
+	public_dir = lookup_public_dir ();
+	ensure_conf_dir ();
+
+	i = 0;
+	free1 = argv[i++] = get_httpd_program ();
+	if (argv[0] == NULL) {
+		fprintf (stderr, "error finding httpd server\n");
+		return FALSE;
+	}
+
+	argv[i++] = "-f";
+	free2 = argv[i++] = get_httpd_config (argv[0]);
+	argv[i++] = "-C";
+	free3 = argv[i++] = g_strdup_printf ("Listen %d", port);
+
+	settings = g_settings_new (GSETTINGS_SCHEMA);
+	str = g_settings_get_string (settings,
+				       FILE_SHARING_REQUIRE_PASSWORD);
+
+	if (str && strcmp (str, "never") == 0) {
+		/* Do nothing */
+	} else if (str && strcmp (str, "on_write") == 0){
+		argv[i++] = "-D";
+		argv[i++] = "RequirePasswordOnWrite";
+	} else {
+		/* always, or safe fallback */
+		argv[i++] = "-D";
+		argv[i++] = "RequirePasswordAlways";
+	}
+	g_free (str);
+	g_object_unref (settings);
+
+	argv[i] = NULL;
+
+	i = 0;
+	free4 = env[i++] = g_strdup_printf ("HOME=%s", g_get_home_dir());
+	free5 = env[i++] = g_strdup_printf ("XDG_PUBLICSHARE_DIR=%s", public_dir);
+	free6 = env[i++] = g_strdup_printf ("XDG_CONFIG_HOME=%s", g_get_user_config_dir ());
+	free7 = env[i++] = g_strdup_printf ("GUS_SHARE_NAME=%s", get_share_name ());
+	free8 = env[i++] = g_strdup_printf ("GUS_LOGIN_LABEL=%s", "Please log in as the user guest");
+	free9 = env[i++] = g_strdup_printf ("HTTP_MODULES_PATH=%s",get_httpd_modules_path ());
+	env[i++] = "LANG=C";
+	env[i] = NULL;
+
+	pid_filename = g_build_filename (g_get_user_config_dir (), "user-share", "pid", NULL);
+
+	/* Remove pid file before spawning to avoid races with child and old pidfile */
+	unlink (pid_filename);
+
+	error = NULL;
+	res = g_spawn_sync (g_get_home_dir(),
+			    argv, env, 0,
+			    httpd_child_setup, NULL,
+			    NULL, NULL,
+			    &status,
+			    &error);
+	g_free (free1);
+	g_free (free2);
+	g_free (free3);
+	g_free (free4);
+	g_free (free5);
+	g_free (free6);
+	g_free (free7);
+	g_free (free8);
+	g_free (free9);
+	g_free (public_dir);
+
+	if (!res) {
+		fprintf (stderr, "error spawning httpd: %s\n",
+			 error->message);
+		g_error_free (error);
+		g_free (pid_filename);
+		return FALSE;
+	}
+
+	if (status != 0) {
+		g_free (pid_filename);
+		return FALSE;
+	}
+
+	got_pidfile = FALSE;
+	error = NULL;
+	for (i = 0; i < 5; i++) {
+		if (error != NULL)
+			g_error_free (error);
+		error = NULL;
+		if (g_file_get_contents (pid_filename, &pidfile, NULL, &error)) {
+			got_pidfile = TRUE;
+			*pid_out = atoi (pidfile);
+			g_free (pidfile);
+			break;
+		}
+		sleep (1);
+	}
+
+	g_free (pid_filename);
+
+	if (!got_pidfile) {
+		fprintf (stderr, "error opening httpd pidfile: %s\n", error->message);
+		g_error_free (error);
+		return FALSE;
+	}
+	return TRUE;
+}
+
+static void
+kill_httpd (void)
+{
+	if (httpd_pid != 0) {
+		kill (httpd_pid, SIGTERM);
+
+		/* Allow child time to die, we can't waitpid, because its
+		   not a direct child */
+		sleep (1);
+	}
+	httpd_pid = 0;
+}
+
+void
+http_up (void)
+{
+	guint port;
+
+	port = get_port ();
+	if (!spawn_httpd (port, &httpd_pid)) {
+		fprintf (stderr, "spawning httpd failed\n");
+	}
+}
+
+void
+http_down (void)
+{
+	kill_httpd ();
+}
+
+gboolean
+http_init (void)
+{
+	return TRUE;
+}
+
+pid_t
+http_get_pid (void)
+{
+	return httpd_pid;
+}
+
+ +
+ +
+ + diff --git a/2024-02-22-185755-8058-cppcheck@00d9a360c0cc_v1.28.0/4.html b/2024-02-22-185755-8058-cppcheck@00d9a360c0cc_v1.28.0/4.html new file mode 100644 index 0000000..40b4557 --- /dev/null +++ b/2024-02-22-185755-8058-cppcheck@00d9a360c0cc_v1.28.0/4.html @@ -0,0 +1,299 @@ + + + + + + Cppcheck - HTML report - mate-user-share + + + + + +
+ + + +
+
 1
+ 2
+ 3
+ 4
+ 5
+ 6
+ 7
+ 8
+ 9
+10
+11
+12
+13
+14
+15
+16
+17
+18
+19
+20
+21
+22
+23
+24
+25
+26
+27
+28
+29
+30
+31
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
+
+/*
+ *  Copyright (C) 2004-2009 Red Hat, Inc.
+ *  Copyright (C) 2012-2021 MATE Developers
+ *
+ *  Caja is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU General Public License as
+ *  published by the Free Software Foundation; either version 2 of the
+ *  License, or (at your option) any later version.
+ *
+ *  Caja is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  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
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ *  Authors: Alexander Larsson <alexl@redhat.com>
+ *  Bastien Nocera <hadess@hadess.net>
+ *
+ */
+
+#include <glib.h><--- Include file:  not found. Please note: Cppcheck does not need standard library headers to get proper results.
+#include <gio/gio.h><--- Include file:  not found. Please note: Cppcheck does not need standard library headers to get proper results.
+
+char *lookup_public_dir (void);
+char *lookup_download_dir (void);
+GFile *lookup_dir_with_fallback (GUserDirectory directory);
+
+ +
+ +
+ + diff --git a/2024-02-22-185755-8058-cppcheck@00d9a360c0cc_v1.28.0/5.html b/2024-02-22-185755-8058-cppcheck@00d9a360c0cc_v1.28.0/5.html new file mode 100644 index 0000000..a3a1517 --- /dev/null +++ b/2024-02-22-185755-8058-cppcheck@00d9a360c0cc_v1.28.0/5.html @@ -0,0 +1,413 @@ + + + + + + Cppcheck - HTML report - mate-user-share + + + + + +
+ + + +
+
 1
+ 2
+ 3
+ 4
+ 5
+ 6
+ 7
+ 8
+ 9
+10
+11
+12
+13
+14
+15
+16
+17
+18
+19
+20
+21
+22
+23
+24
+25
+26
+27
+28
+29
+30
+31
+32
+33
+34
+35
+36
+37
+38
+39
+40
+41
+42
+43
+44
+45
+46
+47
+48
+49
+50
+51
+52
+53
+54
+55
+56
+57
+58
+59
+60
+61
+62
+63
+64
+65
+66
+67
+68
+69
+70
+71
+72
+73
+74
+75
+76
+77
+78
+79
+80
+81
+82
+83
+84
+85
+86
+87
+88
/* This file is generated by glib-genmarshal, do not modify it. This code is licensed under the same license as the containing project. Note that it links to GLib, so must comply with the LGPL linking clauses. */
+#include <glib-object.h><--- Include file:  not found. Please note: Cppcheck does not need standard library headers to get proper results.
+
+#ifdef G_ENABLE_DEBUG
+#define g_marshal_value_peek_boolean(v)  g_value_get_boolean (v)
+#define g_marshal_value_peek_char(v)     g_value_get_schar (v)
+#define g_marshal_value_peek_uchar(v)    g_value_get_uchar (v)
+#define g_marshal_value_peek_int(v)      g_value_get_int (v)
+#define g_marshal_value_peek_uint(v)     g_value_get_uint (v)
+#define g_marshal_value_peek_long(v)     g_value_get_long (v)
+#define g_marshal_value_peek_ulong(v)    g_value_get_ulong (v)
+#define g_marshal_value_peek_int64(v)    g_value_get_int64 (v)
+#define g_marshal_value_peek_uint64(v)   g_value_get_uint64 (v)
+#define g_marshal_value_peek_enum(v)     g_value_get_enum (v)
+#define g_marshal_value_peek_flags(v)    g_value_get_flags (v)
+#define g_marshal_value_peek_float(v)    g_value_get_float (v)
+#define g_marshal_value_peek_double(v)   g_value_get_double (v)
+#define g_marshal_value_peek_string(v)   (char*) g_value_get_string (v)
+#define g_marshal_value_peek_param(v)    g_value_get_param (v)
+#define g_marshal_value_peek_boxed(v)    g_value_get_boxed (v)
+#define g_marshal_value_peek_pointer(v)  g_value_get_pointer (v)
+#define g_marshal_value_peek_object(v)   g_value_get_object (v)
+#define g_marshal_value_peek_variant(v)  g_value_get_variant (v)
+#else /* !G_ENABLE_DEBUG */
+/* WARNING: This code accesses GValues directly, which is UNSUPPORTED API.
+ *          Do not access GValues directly in your code. Instead, use the
+ *          g_value_get_*() functions
+ */
+#define g_marshal_value_peek_boolean(v)  (v)->data[0].v_int
+#define g_marshal_value_peek_char(v)     (v)->data[0].v_int
+#define g_marshal_value_peek_uchar(v)    (v)->data[0].v_uint
+#define g_marshal_value_peek_int(v)      (v)->data[0].v_int
+#define g_marshal_value_peek_uint(v)     (v)->data[0].v_uint
+#define g_marshal_value_peek_long(v)     (v)->data[0].v_long
+#define g_marshal_value_peek_ulong(v)    (v)->data[0].v_ulong
+#define g_marshal_value_peek_int64(v)    (v)->data[0].v_int64
+#define g_marshal_value_peek_uint64(v)   (v)->data[0].v_uint64
+#define g_marshal_value_peek_enum(v)     (v)->data[0].v_long
+#define g_marshal_value_peek_flags(v)    (v)->data[0].v_ulong
+#define g_marshal_value_peek_float(v)    (v)->data[0].v_float
+#define g_marshal_value_peek_double(v)   (v)->data[0].v_double
+#define g_marshal_value_peek_string(v)   (v)->data[0].v_pointer
+#define g_marshal_value_peek_param(v)    (v)->data[0].v_pointer
+#define g_marshal_value_peek_boxed(v)    (v)->data[0].v_pointer
+#define g_marshal_value_peek_pointer(v)  (v)->data[0].v_pointer
+#define g_marshal_value_peek_object(v)   (v)->data[0].v_pointer
+#define g_marshal_value_peek_variant(v)  (v)->data[0].v_pointer
+#endif /* !G_ENABLE_DEBUG */
+
+/* VOID:STRING,STRING,UINT64 (./marshal.list:1) */
+void
+marshal_VOID__STRING_STRING_UINT64 (GClosure     *closure,
+                                    GValue       *return_value G_GNUC_UNUSED,
+                                    guint         n_param_values,
+                                    const GValue *param_values,
+                                    gpointer      invocation_hint G_GNUC_UNUSED,
+                                    gpointer      marshal_data)
+{
+  typedef void (*GMarshalFunc_VOID__STRING_STRING_UINT64) (gpointer data1,
+                                                           gpointer arg1,
+                                                           gpointer arg2,
+                                                           guint64 arg3,
+                                                           gpointer data2);
+  GCClosure *cc = (GCClosure *) closure;
+  gpointer data1, data2;
+  GMarshalFunc_VOID__STRING_STRING_UINT64 callback;
+
+  g_return_if_fail (n_param_values == 4);
+
+  if (G_CCLOSURE_SWAP_DATA (closure))
+    {
+      data1 = closure->data;
+      data2 = g_value_peek_pointer (param_values + 0);
+    }
+  else
+    {
+      data1 = g_value_peek_pointer (param_values + 0);
+      data2 = closure->data;
+    }
+  callback = (GMarshalFunc_VOID__STRING_STRING_UINT64) (marshal_data ? marshal_data : cc->callback);
+
+  callback (data1,
+            g_marshal_value_peek_string (param_values + 1),
+            g_marshal_value_peek_string (param_values + 2),
+            g_marshal_value_peek_uint64 (param_values + 3),
+            data2);
+}
+
+
+ +
+ +
+ + diff --git a/2024-02-22-185755-8058-cppcheck@00d9a360c0cc_v1.28.0/6.html b/2024-02-22-185755-8058-cppcheck@00d9a360c0cc_v1.28.0/6.html new file mode 100644 index 0000000..4a954d3 --- /dev/null +++ b/2024-02-22-185755-8058-cppcheck@00d9a360c0cc_v1.28.0/6.html @@ -0,0 +1,567 @@ + + + + + + Cppcheck - HTML report - mate-user-share + + + + + +
+ + + +
+
  1
+  2
+  3
+  4
+  5
+  6
+  7
+  8
+  9
+ 10
+ 11
+ 12
+ 13
+ 14
+ 15
+ 16
+ 17
+ 18
+ 19
+ 20
+ 21
+ 22
+ 23
+ 24
+ 25
+ 26
+ 27
+ 28
+ 29
+ 30
+ 31
+ 32
+ 33
+ 34
+ 35
+ 36
+ 37
+ 38
+ 39
+ 40
+ 41
+ 42
+ 43
+ 44
+ 45
+ 46
+ 47
+ 48
+ 49
+ 50
+ 51
+ 52
+ 53
+ 54
+ 55
+ 56
+ 57
+ 58
+ 59
+ 60
+ 61
+ 62
+ 63
+ 64
+ 65
+ 66
+ 67
+ 68
+ 69
+ 70
+ 71
+ 72
+ 73
+ 74
+ 75
+ 76
+ 77
+ 78
+ 79
+ 80
+ 81
+ 82
+ 83
+ 84
+ 85
+ 86
+ 87
+ 88
+ 89
+ 90
+ 91
+ 92
+ 93
+ 94
+ 95
+ 96
+ 97
+ 98
+ 99
+100
+101
+102
+103
+104
+105
+106
+107
+108
+109
+110
+111
+112
+113
+114
+115
+116
+117
+118
+119
+120
+121
+122
+123
+124
+125
+126
+127
+128
+129
+130
+131
+132
+133
+134
+135
+136
+137
+138
+139
+140
+141
+142
+143
+144
+145
+146
+147
+148
+149
+150
+151
+152
+153
+154
+155
+156
+157
+158
+159
+160
+161
+162
+163
+164
+165
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
+
+/*
+ *  Copyright (C) 2004-2008 Red Hat, Inc.
+ * Copyright (C) 2012-2021 MATE Developers
+ *
+ *  Caja is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU General Public License as
+ *  published by the Free Software Foundation; either version 2 of the
+ *  License, or (at your option) any later version.
+ *
+ *  Caja is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  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
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ *  Authors: Bastien Nocera <hadess@hadess.net>
+ *
+ */
+
+#include "config.h"<--- Include file: "config.h" not found.
+
+#include <dbus/dbus-glib.h><--- Include file:  not found. Please note: Cppcheck does not need standard library headers to get proper results.
+#include <dbus/dbus-glib-lowlevel.h><--- Include file:  not found. Please note: Cppcheck does not need standard library headers to get proper results.
+#include <gio/gio.h><--- Include file:  not found. Please note: Cppcheck does not need standard library headers to get proper results.
+
+#include <string.h><--- Include file:  not found. Please note: Cppcheck does not need standard library headers to get proper results.
+
+#include "obexftp.h"
+#include "user_share-common.h"
+#include "user_share-private.h"
+
+#define GSETTINGS_SCHEMA "org.mate.FileSharing"
+
+static DBusGConnection *connection = NULL;
+static DBusGProxy *manager_proxy = NULL;
+static DBusGProxy *server_proxy = NULL;
+
+void
+obexftp_up (void)
+{
+	GError *err = NULL;
+	GSettings *settings;
+	char *public_dir, *server;
+	gboolean allow_write, require_pairing;
+
+	settings = g_settings_new (GSETTINGS_SCHEMA);
+	require_pairing = g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_REQUIRE_PAIRING);
+
+	server = NULL;
+	if (manager_proxy == NULL) {
+		manager_proxy = dbus_g_proxy_new_for_name (connection,
+							   "org.openobex",
+							   "/org/openobex",
+							   "org.openobex.Manager");
+		if (dbus_g_proxy_call (manager_proxy, "CreateBluetoothServer",
+				       &err, G_TYPE_STRING, "00:00:00:00:00:00", G_TYPE_STRING, "ftp", G_TYPE_BOOLEAN, require_pairing, G_TYPE_INVALID,
+				       DBUS_TYPE_G_OBJECT_PATH, &server, G_TYPE_INVALID) == FALSE) {
+			g_printerr ("Creating Bluetooth ObexFTP server failed: %s\n",
+				    err->message);
+			g_error_free (err);
+			g_object_unref (manager_proxy);
+			manager_proxy = NULL;
+			return;
+		}
+	}
+
+	public_dir = lookup_public_dir ();
+	allow_write = g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_ALLOW_WRITE);
+	g_object_unref (settings);
+
+	if (server_proxy == NULL) {
+		server_proxy = dbus_g_proxy_new_for_name (connection,
+							   "org.openobex",
+							   server,
+							   "org.openobex.Server");
+		g_free (server);
+	}
+	if (dbus_g_proxy_call (server_proxy, "Start", &err,
+			   G_TYPE_STRING, public_dir, G_TYPE_BOOLEAN, allow_write, G_TYPE_BOOLEAN, TRUE, G_TYPE_INVALID,
+			   G_TYPE_INVALID) == FALSE) {
+		if (g_error_matches (err, DBUS_GERROR, DBUS_GERROR_REMOTE_EXCEPTION) != FALSE &&
+		    dbus_g_error_has_name (err, "org.openobex.Error.Started") != FALSE) {
+		    	g_error_free (err);
+		    	g_message ("already started, ignoring error");
+		    	g_free (public_dir);
+		    	return;
+		}
+		g_printerr ("Starting Bluetooth ObexFTP server failed: %s\n",
+			    err->message);
+		g_error_free (err);
+		g_free (public_dir);
+		g_object_unref (server_proxy);
+		server_proxy = NULL;
+		g_object_unref (manager_proxy);
+		manager_proxy = NULL;
+		return;
+	}
+
+	g_free (public_dir);
+}
+
+static void
+obexftp_stop (gboolean stop_manager)
+{
+	GError *err = NULL;
+
+	if (server_proxy == NULL)
+		return;
+
+	if (dbus_g_proxy_call (server_proxy, "Close", &err, G_TYPE_INVALID, G_TYPE_INVALID) == FALSE) {
+		if (err == NULL ||
+		    g_error_matches (err, DBUS_GERROR, DBUS_GERROR_REMOTE_EXCEPTION) == FALSE ||
+		    dbus_g_error_has_name (err, "org.openobex.Error.NotStarted") == FALSE) {
+			if (err != NULL) {
+				g_printerr ("Stopping Bluetooth ObexFTP server failed: %s\n",
+					    err->message);
+				g_error_free (err);
+			}
+			return;
+		}
+		g_error_free (err);
+	}
+
+	if (stop_manager != FALSE) {
+		g_object_unref (server_proxy);
+		server_proxy = NULL;
+		g_object_unref (manager_proxy);
+		manager_proxy = NULL;
+	}
+}
+
+void
+obexftp_down (void)
+{
+	obexftp_stop (TRUE);
+}
+
+void
+obexftp_restart (void)
+{
+	obexftp_stop (FALSE);
+	obexftp_up ();
+}
+
+gboolean
+obexftp_init (void)
+{
+	GError *err = NULL;
+
+	connection = dbus_g_bus_get (DBUS_BUS_SESSION, &err);
+	if (connection == NULL) {
+		g_printerr ("Connecting to session bus failed: %s\n",
+			    err->message);
+		g_error_free (err);
+		return FALSE;
+	}
+
+	dbus_connection_set_exit_on_disconnect (dbus_g_connection_get_connection (connection), FALSE);
+	return TRUE;
+}
+
+ +
+ +
+ + diff --git a/2024-02-22-185755-8058-cppcheck@00d9a360c0cc_v1.28.0/7.html b/2024-02-22-185755-8058-cppcheck@00d9a360c0cc_v1.28.0/7.html new file mode 100644 index 0000000..78177bd --- /dev/null +++ b/2024-02-22-185755-8058-cppcheck@00d9a360c0cc_v1.28.0/7.html @@ -0,0 +1,297 @@ + + + + + + Cppcheck - HTML report - mate-user-share + + + + + +
+ + + +
+
 1
+ 2
+ 3
+ 4
+ 5
+ 6
+ 7
+ 8
+ 9
+10
+11
+12
+13
+14
+15
+16
+17
+18
+19
+20
+21
+22
+23
+24
+25
+26
+27
+28
+29
+30
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
+
+/*
+ *  Copyright (C) 2004-2008 Red Hat, Inc.
+ * Copyright (C) 2012-2021 MATE Developers
+ *
+ *  Caja is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU General Public License as
+ *  published by the Free Software Foundation; either version 2 of the
+ *  License, or (at your option) any later version.
+ *
+ *  Caja is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  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
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ *  Authors: Bastien Nocera <hadess@hadess.net>
+ *
+ */
+
+#include <glib.h><--- Include file:  not found. Please note: Cppcheck does not need standard library headers to get proper results.
+
+void obexftp_up (void);
+void obexftp_down (void);
+void obexftp_restart (void);
+gboolean obexftp_init (void);
+
+ +
+ +
+ + diff --git a/2024-02-22-185755-8058-cppcheck@00d9a360c0cc_v1.28.0/8.html b/2024-02-22-185755-8058-cppcheck@00d9a360c0cc_v1.28.0/8.html new file mode 100644 index 0000000..676cdb1 --- /dev/null +++ b/2024-02-22-185755-8058-cppcheck@00d9a360c0cc_v1.28.0/8.html @@ -0,0 +1,1357 @@ + + + + + + Cppcheck - HTML report - mate-user-share + + + + + +
+ + + +
+
  1
+  2
+  3
+  4
+  5
+  6
+  7
+  8
+  9
+ 10
+ 11
+ 12
+ 13
+ 14
+ 15
+ 16
+ 17
+ 18
+ 19
+ 20
+ 21
+ 22
+ 23
+ 24
+ 25
+ 26
+ 27
+ 28
+ 29
+ 30
+ 31
+ 32
+ 33
+ 34
+ 35
+ 36
+ 37
+ 38
+ 39
+ 40
+ 41
+ 42
+ 43
+ 44
+ 45
+ 46
+ 47
+ 48
+ 49
+ 50
+ 51
+ 52
+ 53
+ 54
+ 55
+ 56
+ 57
+ 58
+ 59
+ 60
+ 61
+ 62
+ 63
+ 64
+ 65
+ 66
+ 67
+ 68
+ 69
+ 70
+ 71
+ 72
+ 73
+ 74
+ 75
+ 76
+ 77
+ 78
+ 79
+ 80
+ 81
+ 82
+ 83
+ 84
+ 85
+ 86
+ 87
+ 88
+ 89
+ 90
+ 91
+ 92
+ 93
+ 94
+ 95
+ 96
+ 97
+ 98
+ 99
+100
+101
+102
+103
+104
+105
+106
+107
+108
+109
+110
+111
+112
+113
+114
+115
+116
+117
+118
+119
+120
+121
+122
+123
+124
+125
+126
+127
+128
+129
+130
+131
+132
+133
+134
+135
+136
+137
+138
+139
+140
+141
+142
+143
+144
+145
+146
+147
+148
+149
+150
+151
+152
+153
+154
+155
+156
+157
+158
+159
+160
+161
+162
+163
+164
+165
+166
+167
+168
+169
+170
+171
+172
+173
+174
+175
+176
+177
+178
+179
+180
+181
+182
+183
+184
+185
+186
+187
+188
+189
+190
+191
+192
+193
+194
+195
+196
+197
+198
+199
+200
+201
+202
+203
+204
+205
+206
+207
+208
+209
+210
+211
+212
+213
+214
+215
+216
+217
+218
+219
+220
+221
+222
+223
+224
+225
+226
+227
+228
+229
+230
+231
+232
+233
+234
+235
+236
+237
+238
+239
+240
+241
+242
+243
+244
+245
+246
+247
+248
+249
+250
+251
+252
+253
+254
+255
+256
+257
+258
+259
+260
+261
+262
+263
+264
+265
+266
+267
+268
+269
+270
+271
+272
+273
+274
+275
+276
+277
+278
+279
+280
+281
+282
+283
+284
+285
+286
+287
+288
+289
+290
+291
+292
+293
+294
+295
+296
+297
+298
+299
+300
+301
+302
+303
+304
+305
+306
+307
+308
+309
+310
+311
+312
+313
+314
+315
+316
+317
+318
+319
+320
+321
+322
+323
+324
+325
+326
+327
+328
+329
+330
+331
+332
+333
+334
+335
+336
+337
+338
+339
+340
+341
+342
+343
+344
+345
+346
+347
+348
+349
+350
+351
+352
+353
+354
+355
+356
+357
+358
+359
+360
+361
+362
+363
+364
+365
+366
+367
+368
+369
+370
+371
+372
+373
+374
+375
+376
+377
+378
+379
+380
+381
+382
+383
+384
+385
+386
+387
+388
+389
+390
+391
+392
+393
+394
+395
+396
+397
+398
+399
+400
+401
+402
+403
+404
+405
+406
+407
+408
+409
+410
+411
+412
+413
+414
+415
+416
+417
+418
+419
+420
+421
+422
+423
+424
+425
+426
+427
+428
+429
+430
+431
+432
+433
+434
+435
+436
+437
+438
+439
+440
+441
+442
+443
+444
+445
+446
+447
+448
+449
+450
+451
+452
+453
+454
+455
+456
+457
+458
+459
+460
+461
+462
+463
+464
+465
+466
+467
+468
+469
+470
+471
+472
+473
+474
+475
+476
+477
+478
+479
+480
+481
+482
+483
+484
+485
+486
+487
+488
+489
+490
+491
+492
+493
+494
+495
+496
+497
+498
+499
+500
+501
+502
+503
+504
+505
+506
+507
+508
+509
+510
+511
+512
+513
+514
+515
+516
+517
+518
+519
+520
+521
+522
+523
+524
+525
+526
+527
+528
+529
+530
+531
+532
+533
+534
+535
+536
+537
+538
+539
+540
+541
+542
+543
+544
+545
+546
+547
+548
+549
+550
+551
+552
+553
+554
+555
+556
+557
+558
+559
+560
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
+
+/*
+ *  Copyright (C) 2004-2008 Red Hat, Inc.
+ *  Copyright (C) 2012-2021 MATE Developers
+ *
+ *  Caja is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU General Public License as
+ *  published by the Free Software Foundation; either version 2 of the
+ *  License, or (at your option) any later version.
+ *
+ *  Caja is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  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
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ *  Authors: Bastien Nocera <hadess@hadess.net>
+ *
+ */
+
+#include "config.h"<--- Include file: "config.h" not found.
+
+#include <glib.h><--- Include file:  not found. Please note: Cppcheck does not need standard library headers to get proper results.
+#include <glib/gi18n.h><--- Include file:  not found. Please note: Cppcheck does not need standard library headers to get proper results.
+#include <gio/gio.h><--- Include file:  not found. Please note: Cppcheck does not need standard library headers to get proper results.
+#include <gdk/gdk.h><--- Include file:  not found. Please note: Cppcheck does not need standard library headers to get proper results.
+#include <gtk/gtk.h><--- Include file:  not found. Please note: Cppcheck does not need standard library headers to get proper results.
+#include <libnotify/notify.h><--- Include file:  not found. Please note: Cppcheck does not need standard library headers to get proper results.
+#include <dbus/dbus-glib.h><--- Include file:  not found. Please note: Cppcheck does not need standard library headers to get proper results.
+#include <dbus/dbus-glib-lowlevel.h><--- Include file:  not found. Please note: Cppcheck does not need standard library headers to get proper results.
+#include <canberra-gtk.h><--- Include file:  not found. Please note: Cppcheck does not need standard library headers to get proper results.
+
+#include <string.h><--- Include file:  not found. Please note: Cppcheck does not need standard library headers to get proper results.
+
+#include "marshal.h"
+#include "obexpush.h"
+#include "user_share-common.h"
+#include "user_share-private.h"
+
+#define DBUS_TYPE_G_STRING_VARIANT_HASHTABLE (dbus_g_type_get_map ("GHashTable", G_TYPE_STRING, G_TYPE_STRING))
+
+#define GSETTINGS_SCHEMA "org.mate.FileSharing"
+
+static DBusGConnection *connection = NULL;<--- Shadowed declaration
+static DBusGProxy *manager_proxy = NULL;
+static DBusGProxy *server_proxy = NULL;
+static AcceptSetting accept_setting = -1;
+static gboolean show_notifications = FALSE;
+
+static GtkStatusIcon *statusicon = NULL;
+static guint num_notifications = 0;
+
+static void
+hide_statusicon (void)
+{
+	num_notifications--;
+	if (num_notifications == 0)
+		gtk_status_icon_set_visible (statusicon, FALSE);
+}
+
+static void
+on_close_notification (NotifyNotification *notification)
+{
+	hide_statusicon ();
+	g_object_unref (notification);
+}
+
+static void
+notification_launch_action_on_file_cb (NotifyNotification *notification,
+				       const char *action,
+				       const char *file_uri)
+{
+	GdkScreen *screen;
+	GAppLaunchContext *ctx;
+	GTimeVal val;
+
+	g_assert (action != NULL);
+
+	g_get_current_time (&val);
+
+	ctx = G_APP_LAUNCH_CONTEXT (gdk_app_launch_context_new ());
+	screen = gdk_screen_get_default ();
+	gdk_app_launch_context_set_screen (GDK_APP_LAUNCH_CONTEXT (ctx), screen);
+	gdk_app_launch_context_set_timestamp (GDK_APP_LAUNCH_CONTEXT (ctx), val.tv_sec);
+
+	/* We launch the file viewer for the file */
+	if (g_str_equal (action, "display") != FALSE) {
+		if (g_app_info_launch_default_for_uri (file_uri, ctx, NULL) == FALSE) {
+			g_warning ("Failed to launch the file viewer\n");
+		}
+	}
+
+	/* we open the Downloads folder */
+	if (g_str_equal (action, "reveal") != FALSE) {
+		GFile *file;
+		GFile *parent;
+		gchar *parent_uri;
+
+		file = g_file_new_for_uri (file_uri);
+		parent = g_file_get_parent (file);
+		parent_uri = g_file_get_uri (parent);
+		g_object_unref (file);
+		g_object_unref (parent);
+
+		if (!g_app_info_launch_default_for_uri (parent_uri, ctx, NULL)) {
+			g_warning ("Failed to launch the file manager\n");
+		}
+
+		g_free (parent_uri);
+	}
+
+	notify_notification_close (notification, NULL);
+	/* No need to call hide_statusicon(), closing the notification
+	 * will call the close callback */
+}
+
+static void
+show_notification (const char *filename)
+{
+	char *file_uri, *notification_text, *display, *mime_type;
+	NotifyNotification *notification;
+	ca_context *ctx;
+	GAppInfo *app;
+
+	file_uri = g_filename_to_uri (filename, NULL, NULL);
+	if (file_uri == NULL) {
+		g_warning ("Could not make a filename from '%s'", filename);
+		return;
+	}
+
+	display = g_filename_display_basename (filename);
+	/* Translators: %s is the name of the filename received */
+	notification_text = g_strdup_printf(_("You received \"%s\" via Bluetooth"), display);
+	g_free (display);
+	notification = notify_notification_new (_("You received a file"),
+								 notification_text,
+								 "dialog-information");
+
+	notify_notification_set_timeout (notification, NOTIFY_EXPIRES_DEFAULT);
+
+	mime_type = g_content_type_guess (filename, NULL, 0, NULL);
+	app = g_app_info_get_default_for_type (mime_type, FALSE);
+	if (app != NULL) {
+		g_object_unref (app);
+		notify_notification_add_action (notification, "display", _("Open File"),
+						(NotifyActionCallback) notification_launch_action_on_file_cb,
+						g_strdup (file_uri), (GFreeFunc) g_free);
+	}
+	notify_notification_add_action (notification, "reveal", _("Reveal File"),
+					(NotifyActionCallback) notification_launch_action_on_file_cb,
+					g_strdup (file_uri), (GFreeFunc) g_free);
+
+	g_free (file_uri);
+
+	g_signal_connect (G_OBJECT (notification), "closed", G_CALLBACK (on_close_notification), notification);
+
+	if (!notify_notification_show (notification, NULL)) {
+		g_warning ("failed to send notification\n");
+	}
+	g_free (notification_text);
+
+	/* Now we do the audio notification */
+	ctx = ca_gtk_context_get ();
+	ca_context_play (ctx, 0,
+			 CA_PROP_EVENT_ID, "complete-download",
+			 CA_PROP_EVENT_DESCRIPTION, _("File reception complete"),
+			 NULL);
+}
+
+static void
+show_icon (void)
+{
+	if (statusicon == NULL) {
+		statusicon = gtk_status_icon_new_from_icon_name ("mate-obex-server");
+	} else {
+		gtk_status_icon_set_visible (statusicon, TRUE);
+	}
+	num_notifications++;
+}
+
+static gboolean
+device_is_authorised (const char *bdaddr)
+{
+	DBusGConnection *connection;<--- Shadow variable
+	DBusGProxy *manager;
+	GError *error = NULL;
+	GPtrArray *adapters;
+	gboolean retval = FALSE;
+	guint i;
+
+	connection = dbus_g_bus_get (DBUS_BUS_SYSTEM, NULL);
+	if (connection == NULL)
+		return FALSE;
+
+	manager = dbus_g_proxy_new_for_name (connection, "org.bluez",
+					     "/", "org.bluez.Manager");
+	if (manager == NULL) {
+		dbus_g_connection_unref (connection);
+		return FALSE;
+	}
+
+	if (dbus_g_proxy_call (manager, "ListAdapters", &error, G_TYPE_INVALID, dbus_g_type_get_collection ("GPtrArray", DBUS_TYPE_G_OBJECT_PATH), &adapters, G_TYPE_INVALID) == FALSE) {
+		g_object_unref (manager);
+		dbus_g_connection_unref (connection);
+		return FALSE;
+	}
+
+	for (i = 0; i < adapters->len; i++) {
+		DBusGProxy *adapter, *device;
+		char *device_path;
+		GHashTable *props;
+
+		g_debug ("checking adapter %s", (gchar *) g_ptr_array_index (adapters, i));
+
+		adapter = dbus_g_proxy_new_for_name (connection, "org.bluez",
+						    g_ptr_array_index (adapters, i), "org.bluez.Adapter");
+
+		if (dbus_g_proxy_call (adapter, "FindDevice", NULL,
+				       G_TYPE_STRING, bdaddr, G_TYPE_INVALID,
+				       DBUS_TYPE_G_OBJECT_PATH, &device_path, G_TYPE_INVALID) == FALSE)
+		{
+			g_object_unref (adapter);
+			continue;
+		}
+
+		device = dbus_g_proxy_new_for_name (connection, "org.bluez", device_path, "org.bluez.Device");
+
+		if (dbus_g_proxy_call (device, "GetProperties", NULL,
+				       G_TYPE_INVALID, dbus_g_type_get_map ("GHashTable", G_TYPE_STRING, G_TYPE_VALUE),
+				       &props, G_TYPE_INVALID) != FALSE)
+		{
+			GValue *value;
+			gboolean bonded;
+
+			value = g_hash_table_lookup (props, "Paired");
+			bonded = g_value_get_boolean (value);
+			g_message ("%s is %s", bdaddr, bonded ? "bonded" : "not bonded");
+
+			if (bonded) {
+				g_hash_table_destroy (props);
+				g_object_unref (device);
+				g_object_unref (adapter);
+				retval = TRUE;
+				break;
+			}
+		}
+		g_object_unref(adapter);
+	}
+
+	g_ptr_array_free (adapters, TRUE);
+
+	g_object_unref(manager);
+	dbus_g_connection_unref(connection);
+
+	return retval;
+}
+
+static void
+transfer_started_cb (DBusGProxy *session,
+		     const char *filename,
+		     const char *local_path,
+		     guint64 size,
+		     gpointer user_data)
+{
+	GHashTable *dict;
+	DBusGProxy *server = (DBusGProxy *) user_data;
+	GError *error = NULL;
+	gboolean authorise;
+
+	g_message ("transfer started on %s", local_path);
+	g_object_set_data_full (G_OBJECT (session), "filename", g_strdup (local_path), (GDestroyNotify) g_free);
+
+	show_icon ();
+
+	/* First transfer of the session */
+	if (g_object_get_data (G_OBJECT (session), "bdaddr") == NULL) {
+		const char *bdaddr;
+
+		if (dbus_g_proxy_call (server, "GetServerSessionInfo", &error,
+				       DBUS_TYPE_G_OBJECT_PATH, dbus_g_proxy_get_path (session), G_TYPE_INVALID,
+				       DBUS_TYPE_G_STRING_VARIANT_HASHTABLE, &dict, G_TYPE_INVALID) == FALSE) {
+			g_printerr ("Getting Server session info failed: %s\n",
+				    error->message);
+			g_error_free (error);
+			return;
+		}
+
+		bdaddr = g_hash_table_lookup (dict, "BluetoothAddress");
+		g_message ("transfer started for device %s", bdaddr);
+
+		g_object_set_data_full (G_OBJECT (session), "bdaddr", g_strdup (bdaddr), (GDestroyNotify) g_free);
+		/* Initial accept method is undefined, we do that lower down */
+		g_object_set_data (G_OBJECT (session), "accept-method", GINT_TO_POINTER (-1));
+		g_hash_table_destroy (dict);
+	}
+
+	/* Accept method changed */
+	if (GPOINTER_TO_INT (g_object_get_data (G_OBJECT (session), "accept-method")) != accept_setting) {
+		const char *bdaddr;
+
+		bdaddr = g_object_get_data (G_OBJECT (session), "bdaddr");
+
+		if (bdaddr == NULL) {
+			g_warning ("Couldn't get the Bluetooth address for the device, rejecting the transfer");
+			authorise = FALSE;
+		} else if (accept_setting == ACCEPT_ALWAYS) {
+			authorise = TRUE;
+		} else if (accept_setting == ACCEPT_BONDED) {
+			authorise = device_is_authorised (bdaddr);
+		} else {
+			//FIXME implement
+			g_warning ("\"Ask\" authorisation method not implemented");
+			authorise = FALSE;
+		}
+		g_object_set_data (G_OBJECT (session), "authorise", GINT_TO_POINTER (authorise));
+	}
+
+	g_message ("accept_setting: %d", accept_setting);
+
+	authorise = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (session), "authorise"));
+	if (authorise != FALSE) {
+		if (dbus_g_proxy_call (session, "Accept", &error, G_TYPE_INVALID, G_TYPE_INVALID) == FALSE) {
+			g_printerr ("Failed to accept file transfer: %s\n", error->message);
+			g_error_free (error);
+			return;
+		}
+		g_message ("authorised transfer");
+	} else {
+		if (dbus_g_proxy_call (session, "Reject", &error, G_TYPE_INVALID, G_TYPE_INVALID) == FALSE) {
+			g_printerr ("Failed to reject file transfer: %s\n", error->message);
+			g_error_free (error);
+			return;
+		}
+		g_message ("rejected transfer");
+		g_object_set_data (G_OBJECT (session), "filename", NULL);
+	}
+}
+
+static void
+transfer_completed_cb (DBusGProxy *session,
+		       gpointer user_data)
+{
+	GSettings *settings;
+	gboolean display_notify;
+	const char *filename;
+
+	filename = (const char *) g_object_get_data (G_OBJECT (session), "filename");
+
+	g_message ("file finish transfer: %s", filename);
+
+	if (filename == NULL)
+		return;
+
+	settings = g_settings_new (GSETTINGS_SCHEMA);
+	display_notify = g_settings_get_boolean (settings, FILE_SHARING_BLUETOOTH_OBEXPUSH_NOTIFY);
+	g_object_unref (settings);
+
+	if (display_notify) {
+		show_notification (filename);
+	} else {
+		hide_statusicon ();
+	}
+	g_object_set_data (G_OBJECT (session), "filename", NULL);
+}
+
+static void
+cancelled_cb (DBusGProxy *session,
+	      gpointer user_data)
+{
+	//FIXME implement properly, we never actually finished the transfer
+	g_message ("transfered was cancelled by the sender");
+	transfer_completed_cb (session, user_data);
+	hide_statusicon ();
+}
+
+static void
+error_occurred_cb (DBusGProxy *session,
+		   const char *error_name,
+		   const char *error_message,
+		   gpointer user_data)
+{
+	//FIXME implement properly
+	g_message ("transfer error occurred: %s", error_message);
+	transfer_completed_cb (session, user_data);
+}
+
+static void
+session_created_cb (DBusGProxy *server, const char *session_path, gpointer user_data)
+{
+	DBusGProxy *session;
+
+	session = dbus_g_proxy_new_for_name (connection,
+					     "org.openobex",
+					     session_path,
+					     "org.openobex.ServerSession");
+
+	dbus_g_proxy_add_signal (session, "TransferStarted",
+				 G_TYPE_STRING, G_TYPE_STRING, G_TYPE_UINT64, G_TYPE_INVALID);
+	dbus_g_proxy_connect_signal(session, "TransferStarted",
+				    G_CALLBACK (transfer_started_cb), server, NULL);
+	dbus_g_proxy_add_signal (session, "TransferCompleted",
+				 G_TYPE_INVALID, G_TYPE_INVALID);
+	dbus_g_proxy_connect_signal(session, "TransferCompleted",
+				    G_CALLBACK (transfer_completed_cb), server, NULL);
+	dbus_g_proxy_add_signal (session, "Cancelled",
+				 G_TYPE_INVALID, G_TYPE_INVALID);
+	dbus_g_proxy_connect_signal(session, "Cancelled",
+				    G_CALLBACK (cancelled_cb), server, NULL);
+	dbus_g_proxy_add_signal (session, "ErrorOccurred",
+				 G_TYPE_INVALID, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INVALID);
+	dbus_g_proxy_connect_signal(session, "ErrorOccurred",
+				    G_CALLBACK (error_occurred_cb), server, NULL);
+}
+
+void
+obexpush_up (void)
+{
+	GError *err = NULL;
+	char *download_dir, *server;
+
+	server = NULL;
+	if (manager_proxy == NULL) {
+		manager_proxy = dbus_g_proxy_new_for_name (connection,
+							   "org.openobex",
+							   "/org/openobex",
+							   "org.openobex.Manager");
+		if (dbus_g_proxy_call (manager_proxy, "CreateBluetoothServer",
+				       &err, G_TYPE_STRING, "00:00:00:00:00:00", G_TYPE_STRING, "opp", G_TYPE_BOOLEAN, FALSE, G_TYPE_INVALID,
+				       DBUS_TYPE_G_OBJECT_PATH, &server, G_TYPE_INVALID) == FALSE) {
+			g_printerr ("Creating Bluetooth ObexPush server failed: %s\n",
+				    err->message);
+			g_error_free (err);
+			g_object_unref (manager_proxy);
+			manager_proxy = NULL;
+			return;
+		}
+	}
+
+	download_dir = lookup_download_dir ();
+
+	if (server_proxy == NULL) {
+		server_proxy = dbus_g_proxy_new_for_name (connection,
+							   "org.openobex",
+							   server,
+							   "org.openobex.Server");
+		g_free (server);
+
+		dbus_g_proxy_add_signal (server_proxy, "SessionCreated",
+					 DBUS_TYPE_G_OBJECT_PATH, G_TYPE_INVALID);
+		dbus_g_proxy_connect_signal(server_proxy, "SessionCreated",
+					    G_CALLBACK (session_created_cb), NULL, NULL);
+	}
+
+	if (dbus_g_proxy_call (server_proxy, "Start", &err,
+			   G_TYPE_STRING, download_dir, G_TYPE_BOOLEAN, TRUE, G_TYPE_BOOLEAN, FALSE, G_TYPE_INVALID,
+			   G_TYPE_INVALID) == FALSE) {
+		if (g_error_matches (err, DBUS_GERROR, DBUS_GERROR_REMOTE_EXCEPTION) != FALSE &&
+		    dbus_g_error_has_name (err, "org.openobex.Error.Started") != FALSE) {
+		    	g_error_free (err);
+		    	g_message ("already started, ignoring error");
+		    	g_free (download_dir);
+		    	return;
+		}
+		g_printerr ("Starting Bluetooth ObexPush server failed: %s\n",
+			    err->message);
+		g_error_free (err);
+		g_free (download_dir);
+		g_object_unref (server_proxy);
+		server_proxy = NULL;
+		g_object_unref (manager_proxy);
+		manager_proxy = NULL;
+		return;
+	}
+
+	g_free (download_dir);
+}
+
+static void
+obexpush_stop (gboolean stop_manager)
+{
+	GError *err = NULL;
+
+	if (server_proxy == NULL)
+		return;
+
+	if (dbus_g_proxy_call (server_proxy, "Close", &err, G_TYPE_INVALID, G_TYPE_INVALID) == FALSE) {
+		if (g_error_matches (err, DBUS_GERROR, DBUS_GERROR_REMOTE_EXCEPTION) == FALSE ||
+		    dbus_g_error_has_name (err, "org.openobex.Error.NotStarted") == FALSE) {
+			g_printerr ("Stopping Bluetooth ObexPush server failed: %s\n",
+				    err->message);
+			g_error_free (err);
+			return;
+		}
+		g_error_free (err);
+	}
+
+	if (stop_manager != FALSE) {
+		g_object_unref (server_proxy);
+		server_proxy = NULL;
+		g_object_unref (manager_proxy);
+		manager_proxy = NULL;
+	}
+
+	//FIXME stop all the notifications
+}
+
+void
+obexpush_down (void)
+{
+	obexpush_stop (TRUE);
+}
+
+void
+obexpush_restart (void)
+{
+	obexpush_stop (FALSE);
+	obexpush_up ();
+}
+
+gboolean
+obexpush_init (void)
+{
+	GError *err = NULL;
+
+	connection = dbus_g_bus_get (DBUS_BUS_SESSION, &err);
+	if (connection == NULL) {
+		g_printerr ("Connecting to session bus failed: %s\n",
+			    err->message);
+		g_error_free (err);
+		return FALSE;
+	}
+
+	dbus_g_object_register_marshaller (marshal_VOID__STRING_STRING_UINT64,
+					   G_TYPE_NONE,
+					   G_TYPE_STRING, G_TYPE_STRING, G_TYPE_UINT64, G_TYPE_INVALID);
+
+	if (!notify_init("mate-user-share")) {
+		g_warning("Unable to initialize the notification system\n");
+        }
+
+	dbus_connection_set_exit_on_disconnect (dbus_g_connection_get_connection (connection), FALSE);
+
+	return TRUE;
+}
+
+void
+obexpush_set_accept_files_policy (AcceptSetting setting)
+{
+	accept_setting = setting;
+}
+
+void
+obexpush_set_notify (gboolean enabled)
+{
+	show_notifications = enabled;
+}
+
+ +
+ +
+ + diff --git a/2024-02-22-185755-8058-cppcheck@00d9a360c0cc_v1.28.0/9.html b/2024-02-22-185755-8058-cppcheck@00d9a360c0cc_v1.28.0/9.html new file mode 100644 index 0000000..af8fc5f --- /dev/null +++ b/2024-02-22-185755-8058-cppcheck@00d9a360c0cc_v1.28.0/9.html @@ -0,0 +1,279 @@ + + + + + + Cppcheck - HTML report - mate-user-share + + + + + +
+ + + +
+
 1
+ 2
+ 3
+ 4
+ 5
+ 6
+ 7
+ 8
+ 9
+10
+11
+12
+13
+14
+15
+16
+17
+18
+19
+20
+21
/* This file is generated by glib-genmarshal, do not modify it. This code is licensed under the same license as the containing project. Note that it links to GLib, so must comply with the LGPL linking clauses. */
+#ifndef __MARSHAL_MARSHAL_H__
+#define __MARSHAL_MARSHAL_H__
+
+#include <glib-object.h><--- Include file:  not found. Please note: Cppcheck does not need standard library headers to get proper results.
+
+G_BEGIN_DECLS
+
+/* VOID:STRING,STRING,UINT64 (./marshal.list:1) */
+extern
+void marshal_VOID__STRING_STRING_UINT64 (GClosure     *closure,
+                                         GValue       *return_value,
+                                         guint         n_param_values,
+                                         const GValue *param_values,
+                                         gpointer      invocation_hint,
+                                         gpointer      marshal_data);
+
+
+G_END_DECLS
+
+#endif /* __MARSHAL_MARSHAL_H__ */
+
+ +
+ +
+ + diff --git a/2024-02-22-185755-8058-cppcheck@00d9a360c0cc_v1.28.0/index.html b/2024-02-22-185755-8058-cppcheck@00d9a360c0cc_v1.28.0/index.html new file mode 100644 index 0000000..d1a6c49 --- /dev/null +++ b/2024-02-22-185755-8058-cppcheck@00d9a360c0cc_v1.28.0/index.html @@ -0,0 +1,325 @@ + + + + + + Cppcheck - HTML report - mate-user-share + + + + + +
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
LineIdCWESeverityMessage
checkersReportinformationActive checkers: There was critical errors (use --checkers-report=<filename> to see details)
src/caja-share-bar.c
24missingIncludeinformationInclude file: "config.h" not found.
26missingIncludeSysteminformationInclude file: <glib/gi18n-lib.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.
27missingIncludeSysteminformationInclude file: <gtk/gtk.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.
41unknownMacroerrorThere is an unknown macro here somewhere. Configuration is required. If G_DEFINE_TYPE_WITH_PRIVATE is a macro then please configure it.
src/caja-share-bar.h
27missingIncludeSysteminformationInclude file: <gtk/gtk.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.
src/file-share-properties.c
25missingIncludeinformationInclude file: "config.h" not found.
27missingIncludeSysteminformationInclude file: <string.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.
28missingIncludeSysteminformationInclude file: <stdio.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.
30missingIncludeSysteminformationInclude file: <gtk/gtk.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.
31missingIncludeSysteminformationInclude file: <glib/gi18n.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.
32missingIncludeSysteminformationInclude file: <gio/gio.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.
83variableScope398styleThe scope of the variable 'password' can be reduced.
98shadowVariable398styleLocal variable 'settings' shadows outer variable
106unusedVariable563styleUnused variable: accept_setting
250shadowVariable398styleLocal variable 'settings' shadows outer variable
274shadowVariable398styleLocal variable 'settings' shadows outer variable
295shadowVariable398styleLocal variable 'settings' shadows outer variable
324shadowVariable398styleLocal variable 'settings' shadows outer variable
341shadowVariable398styleLocal variable 'settings' shadows outer variable
358shadowVariable398styleLocal variable 'settings' shadows outer variable
378shadowVariable398styleLocal variable 'settings' shadows outer variable
394shadowVariable398styleLocal variable 'settings' shadows outer variable
458shadowVariable398styleLocal variable 'settings' shadows outer variable
621variableScope398styleThe scope of the variable 'window' can be reduced.
src/http.c
25missingIncludeinformationInclude file: "config.h" not found.
27missingIncludeSysteminformationInclude file: <glib.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.
28missingIncludeSysteminformationInclude file: <glib/gi18n.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.
29missingIncludeSysteminformationInclude file: <X11/Xlib.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.
31missingIncludeSysteminformationInclude file: <gio/gio.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.
33missingIncludeSysteminformationInclude file: <stdarg.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.
34missingIncludeSysteminformationInclude file: <string.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.
35missingIncludeSysteminformationInclude file: <stdio.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.
36missingIncludeSysteminformationInclude file: <stdlib.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.
37missingIncludeSysteminformationInclude file: <signal.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.
38missingIncludeSysteminformationInclude file: <unistd.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.
39missingIncludeSysteminformationInclude file: <sys/types.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.
40missingIncludeSysteminformationInclude file: <sys/socket.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.
41missingIncludeSysteminformationInclude file: <netinet/in.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.
42missingIncludeSysteminformationInclude file: <sys/stat.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.
45missingIncludeSysteminformationInclude file: <selinux/selinux.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.
115variableScope398styleThe scope of the variable 'host_name' can be reduced.
src/marshal.c
2missingIncludeSysteminformationInclude file: <glib-object.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.
src/marshal.h
5missingIncludeSysteminformationInclude file: <glib-object.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.
src/obexftp.c
25missingIncludeinformationInclude file: "config.h" not found.
27missingIncludeSysteminformationInclude file: <dbus/dbus-glib.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.
28missingIncludeSysteminformationInclude file: <dbus/dbus-glib-lowlevel.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.
29missingIncludeSysteminformationInclude file: <gio/gio.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.
31missingIncludeSysteminformationInclude file: <string.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.
src/obexftp.h
25missingIncludeSysteminformationInclude file: <glib.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.
src/obexpush.c
25missingIncludeinformationInclude file: "config.h" not found.
27missingIncludeSysteminformationInclude file: <glib.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.
28missingIncludeSysteminformationInclude file: <glib/gi18n.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.
29missingIncludeSysteminformationInclude file: <gio/gio.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.
30missingIncludeSysteminformationInclude file: <gdk/gdk.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.
31missingIncludeSysteminformationInclude file: <gtk/gtk.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.
32missingIncludeSysteminformationInclude file: <libnotify/notify.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.
33missingIncludeSysteminformationInclude file: <dbus/dbus-glib.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.
34missingIncludeSysteminformationInclude file: <dbus/dbus-glib-lowlevel.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.
35missingIncludeSysteminformationInclude file: <canberra-gtk.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.
37missingIncludeSysteminformationInclude file: <string.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.
188shadowVariable398styleLocal variable 'connection' shadows outer variable
src/obexpush.h
25missingIncludeSysteminformationInclude file: <glib.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.
src/share-extension.c
25missingIncludeinformationInclude file: "config.h" not found.
27missingIncludeSysteminformationInclude file: <stdlib.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.
28missingIncludeSysteminformationInclude file: <string.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.
29missingIncludeSysteminformationInclude file: <glib/gi18n-lib.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.
30missingIncludeSysteminformationInclude file: <gtk/gtk.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.
31missingIncludeSysteminformationInclude file: <libcaja-extension/caja-menu-provider.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.
32missingIncludeSysteminformationInclude file: <libcaja-extension/caja-location-widget-provider.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.
35missingIncludeSysteminformationInclude file: <bluetooth-client.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.
62variableScope398styleThe scope of the variable 'dialog' can be reduced.
src/user_share-common.c
26missingIncludeSysteminformationInclude file: <string.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.
src/user_share-common.h
26missingIncludeSysteminformationInclude file: <glib.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.
27missingIncludeSysteminformationInclude file: <gio/gio.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.
src/user_share-private.c
26missingIncludeinformationInclude file: "config.h" not found.
28missingIncludeSysteminformationInclude file: <string.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.
src/user_share.c
25missingIncludeinformationInclude file: "config.h" not found.
27missingIncludeSysteminformationInclude file: <gdk/gdkx.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.
28missingIncludeSysteminformationInclude file: <gtk/gtk.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.
29missingIncludeSysteminformationInclude file: <glib/gi18n.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.
30missingIncludeSysteminformationInclude file: <glib/gstdio.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.
31missingIncludeSysteminformationInclude file: <gio/gio.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.
32missingIncludeSysteminformationInclude file: <X11/Xlib.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.
39missingIncludeSysteminformationInclude file: <bluetooth-client.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.
46missingIncludeSysteminformationInclude file: <gio/gio.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.
48missingIncludeSysteminformationInclude file: <stdarg.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.
49missingIncludeSysteminformationInclude file: <string.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.
50missingIncludeSysteminformationInclude file: <stdio.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.
51missingIncludeSysteminformationInclude file: <stdlib.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.
52missingIncludeSysteminformationInclude file: <signal.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.
53missingIncludeSysteminformationInclude file: <unistd.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.
87shadowVariable398styleLocal variable 'settings' shadows outer variable
175constParameterCallback398styleParameter 'gobject' can be declared as pointer to const. However it seems that 'default_adapter_changed' is a callback function, if 'gobject' is declared with const you might also need to cast function pointer(s).
261shadowVariable398styleLocal variable 'settings' shadows outer variable
392shadowVariable398styleLocal variable 'settings' shadows outer variable
+
+ +
+ + diff --git a/2024-02-22-185755-8058-cppcheck@00d9a360c0cc_v1.28.0/stats.html b/2024-02-22-185755-8058-cppcheck@00d9a360c0cc_v1.28.0/stats.html new file mode 100644 index 0000000..9fda872 --- /dev/null +++ b/2024-02-22-185755-8058-cppcheck@00d9a360c0cc_v1.28.0/stats.html @@ -0,0 +1,186 @@ + + + + + + Cppcheck - HTML report - mate-user-share + + + + + +
+ + + +
+

Top 10 files for error severity, total findings: 1
+   1  src/caja-share-bar.c
+

+

Top 10 files for style severity, total findings: 20
+   13  src/file-share-properties.c
+   4   src/user_share.c
+   1   src/share-extension.c
+   1   src/obexpush.c
+   1   src/http.c
+

+

Top 10 files for information severity, total findings: 74
+   16  src/http.c
+   15  src/user_share.c
+   11  src/obexpush.c
+   8   src/share-extension.c
+   6   src/file-share-properties.c
+   5   src/obexftp.c
+   3   src/caja-share-bar.c
+   2   src/user_share-private.c
+   2   src/user_share-common.h
+   1   src/user_share-common.c
+

+ +
+ +
+ + diff --git a/2024-02-22-185755-8058-cppcheck@00d9a360c0cc_v1.28.0/style.css b/2024-02-22-185755-8058-cppcheck@00d9a360c0cc_v1.28.0/style.css new file mode 100644 index 0000000..3897bfa --- /dev/null +++ b/2024-02-22-185755-8058-cppcheck@00d9a360c0cc_v1.28.0/style.css @@ -0,0 +1,177 @@ + +body { + font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif; + font-size: 13px; + line-height: 1.5; + height: 100%; + margin: 0; +} + +#wrapper { + position: fixed; + height: 100vh; + width: 100vw; + display: grid; + grid-template-rows: fit-content(8rem) auto fit-content(8rem); + grid-template-columns: fit-content(25%) 1fr; + grid-template-areas: + "header header" + "menu content" + "footer footer"; +} + +h1 { + margin: 0 0 8px -2px; + font-size: 175%; +} + +.header { + padding: 0 0 5px 15px; + grid-area: header; + border-bottom: thin solid #aaa; +} + +.footer { + grid-area: footer; + border-top: thin solid #aaa; + font-size: 85%; + +} + +.footer > p { + margin: 4px; +} + +#menu, +#menu_index { + grid-area: menu; + text-align: left; + overflow: auto; + padding: 0 23px 15px 15px; + border-right: thin solid #aaa; + min-width: 200px; +} + +#menu > a { + display: block; + margin-left: 10px; + font-size: 12px; +} + +#content, +#content_index { + grid-area: content; + padding: 0px 5px 15px 15px; + overflow: auto; +} + +label { + white-space: nowrap; +} + +label.checkBtn.disabled { + color: #606060; + background: #e0e0e0; + font-style: italic; +} + +label.checkBtn, input[type="text"] { + border: 1px solid grey; + border-radius: 4px; + box-shadow: 1px 1px inset; + padding: 1px 5px; +} + +label.checkBtn { + white-space: nowrap; + background: #ccddff; +} + +label.unchecked { + background: #eff8ff; + box-shadow: 1px 1px 1px; +} + +label.checkBtn:hover, label.unchecked:hover{ + box-shadow: 0 0 2px; +} + +label.disabled:hover { + box-shadow: 1px 1px inset; +} + +label.checkBtn > input { + display:none; +} + +.summaryTable { + width: 100%; +} + +table.summaryTable td { padding: 0 5px 0 5px; } + +.statHeader, .severityHeader { + font-weight: bold; +} + +.warning { + background-color: #ffffa7; +} + +.error { + background-color: #ffb7b7; +} + +.error2 { + background-color: #faa; + display: inline-block; + margin-left: 4px; +} + +.inconclusive { + background-color: #b6b6b4; +} + +.inconclusive2 { + background-color: #b6b6b4; + display: inline-block; + margin-left: 4px; +} + +.verbose { + display: inline-block; + vertical-align: top; + cursor: help; +} + +.verbose .content { + display: none; + position: absolute; + padding: 10px; + margin: 4px; + max-width: 40%; + white-space: pre-wrap; + border: 1px solid #000; + background-color: #ffffcc; + cursor: auto; +} + +.highlight .hll { + padding: 1px; +} + +.highlighttable { + background-color: #fff; + position: relative; + margin: -10px; +} + +.linenos { + border-right: thin solid #aaa; + color: #d3d3d3; + padding-right: 6px; +} + +.id-filtered, .severity-filtered, .file-filtered, .tool-filtered, .text-filtered { + visibility: collapse; +} diff --git a/CNAME b/CNAME new file mode 100644 index 0000000..114a25a --- /dev/null +++ b/CNAME @@ -0,0 +1 @@ +mate-user-share.mate-desktop.dev diff --git a/index.html b/index.html new file mode 100644 index 0000000..6c766e7 --- /dev/null +++ b/index.html @@ -0,0 +1,47 @@ + + + + + + mate-user-share Code Analyzer results + + +

+ mate-desktop/mate-user-share Static analyzer results +

+ GitHub + Build Status +
+Commit: 00d9a360c0cc7b695f88ea69edd98f31db6d28ab
+Compare:
+Branch: v1.28.0
+Time: 2024-02-22 18:57:55+00:00
+Messages:
+
+ci: use ubuntu jammy as docker
+
+
+ + + -- cgit v1.2.1