From 8b6fdaddd2157901ca33e0ed69d2b43d783e6d47 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?C=C3=B4me=20Chilliet?= <come.chilliet@fusiondirectory.org>
Date: Tue, 17 Dec 2019 14:23:42 +0100
Subject: [PATCH] :sparkles: feat(objects) Add b64 option to get base64 encoded
 values of attributes

This will be useful to get binary values through the webservices.

issue #6060
---
 include/class_objects.inc | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/include/class_objects.inc b/include/class_objects.inc
index 9692f425c..55d8c6d81 100644
--- a/include/class_objects.inc
+++ b/include/class_objects.inc
@@ -32,9 +32,9 @@ class objects
    * \param array   $types the objectTypes to list
    * \param mixed   $attrs The attributes to fetch.
    * If this is a single value, the resulting associative array will have for each dn the value of this attribute.
-   * If this is an array, the keys must be the wanted attributes, and the values can be either 1, '*' or 'raw'
+   * If this is an array, the keys must be the wanted attributes, and the values can be either 1, '*', 'b64' or 'raw'
    *  depending if you want a single value or an array of values. 'raw' means untouched LDAP value and is only useful for dns.
-   *  Other values are considered to be 1.
+   *  Other values are considered to be 1. 'b64' means an array of base64 encoded values and is mainly useful through webservice for binary attributes.
    * \param string  $ou the LDAP branch to search in, base will be used if it is NULL
    * \param string  $filter an additional filter to use in the LDAP search.
    * \param boolean $checkAcl should ACL be ignored or checked? Defaults to FALSE.
@@ -144,6 +144,10 @@ class objects
               case 'raw':
                 $result[$key][$attr] = $fetched_attrs[$attr];
                 break;
+              case 'b64':
+                unset($fetched_attrs[$attr]['count']);
+                $result[$key][$attr] = array_map('base64_encode', $fetched_attrs[$attr]);
+                break;
               case 1:
               default:
                 $result[$key][$attr] = $fetched_attrs[$attr][0];
-- 
GitLab