Line | Branch | Exec | Source |
---|---|---|---|
1 | /* Copyright 2024 Jan-Michael Brummer <jan-michael.brummer1@volkswagen.de> | ||
2 | * | ||
3 | * This program is free software: you can redistribute it and/or modify | ||
4 | * it under the terms of the GNU Lesser General Public License as published by | ||
5 | * the Free Software Foundation, either version 3 of the License, or | ||
6 | * (at your option) any later version. | ||
7 | * | ||
8 | * This program is distributed in the hope that it will be useful, | ||
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
11 | * GNU Lesser General Public License for more details. | ||
12 | * | ||
13 | * You should have received a copy of the GNU Lesser General Public License | ||
14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
15 | */ | ||
16 | |||
17 | #include "user/msg-user.h" | ||
18 | #include "msg-error.h" | ||
19 | #include "msg-json-utils.h" | ||
20 | |||
21 | /** | ||
22 | * MsgUser: | ||
23 | * | ||
24 | * Handling of user specific functions. | ||
25 | */ | ||
26 | |||
27 | struct _MsgUser { | ||
28 | GObject parent_instance; | ||
29 | |||
30 | char *id; | ||
31 | |||
32 | GList *business_phones; | ||
33 | char *display_name; | ||
34 | char *given_name; | ||
35 | char *mail; | ||
36 | char *mobile_phone; | ||
37 | char *office_location; | ||
38 | char *surname; | ||
39 | char *company_name; | ||
40 | char *department; | ||
41 | }; | ||
42 | |||
43 |
5/6✓ Branch 0 taken 2 times.
✓ Branch 1 taken 9 times.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✓ Branch 5 taken 7 times.
|
13 | G_DEFINE_TYPE (MsgUser, msg_user, G_TYPE_OBJECT); |
44 | |||
45 | static void | ||
46 | 4 | msg_user_dispose (GObject *object) | |
47 | { | ||
48 | 4 | MsgUser *self = MSG_USER (object); | |
49 | |||
50 |
2/2✓ Branch 0 taken 3 times.
✓ Branch 1 taken 1 times.
|
4 | g_clear_pointer (&self->mail, g_free); |
51 |
2/2✓ Branch 0 taken 3 times.
✓ Branch 1 taken 1 times.
|
4 | g_clear_pointer (&self->display_name, g_free); |
52 |
2/2✓ Branch 0 taken 3 times.
✓ Branch 1 taken 1 times.
|
4 | g_clear_pointer (&self->given_name, g_free); |
53 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 3 times.
|
4 | g_clear_pointer (&self->mobile_phone, g_free); |
54 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
|
4 | g_clear_pointer (&self->office_location, g_free); |
55 |
2/2✓ Branch 0 taken 3 times.
✓ Branch 1 taken 1 times.
|
4 | g_clear_pointer (&self->surname, g_free); |
56 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 3 times.
|
4 | g_clear_pointer (&self->company_name, g_free); |
57 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
|
4 | g_clear_pointer (&self->department, g_free); |
58 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
4 | g_clear_list (&self->business_phones, g_free); |
59 | |||
60 | 4 | G_OBJECT_CLASS (msg_user_parent_class)->dispose (object); | |
61 | 4 | } | |
62 | |||
63 | static void | ||
64 | 4 | msg_user_init (__attribute__ ((unused)) MsgUser *self) | |
65 | { | ||
66 | 4 | } | |
67 | |||
68 | static void | ||
69 | 2 | msg_user_class_init (MsgUserClass *class) | |
70 | { | ||
71 | 2 | GObjectClass *object_class = G_OBJECT_CLASS (class); | |
72 | |||
73 | 2 | object_class->dispose = msg_user_dispose; | |
74 | 2 | } | |
75 | |||
76 | /** | ||
77 | * msg_user_new: | ||
78 | * | ||
79 | * Creates a new `MsgUser`. | ||
80 | * | ||
81 | * Returns: the newly created `MsgUser` | ||
82 | */ | ||
83 | MsgUser * | ||
84 | 4 | msg_user_new (void) | |
85 | { | ||
86 | 4 | return g_object_new (MSG_TYPE_USER, NULL); | |
87 | } | ||
88 | |||
89 | /** | ||
90 | * msg_user_new_from_json: | ||
91 | * @json_object: The json object to parse | ||
92 | * @error: a #GError | ||
93 | * | ||
94 | * Creates a new `MsgUser` from json response object. | ||
95 | * | ||
96 | * Returns: the newly created `MsgUser` | ||
97 | */ | ||
98 | MsgUser * | ||
99 | 3 | msg_user_new_from_json (JsonObject *json_object, | |
100 | __attribute__ ((unused)) GError **error) | ||
101 | { | ||
102 | MsgUser *self; | ||
103 | |||
104 | 3 | self = msg_user_new (); | |
105 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 2 times.
|
3 | if (json_object_has_member (json_object, "emailAddresses")) { |
106 | 1 | JsonArray *email_addresses = json_object_get_array_member (json_object, "emailAddresses"); | |
107 | 1 | JsonObject *email_address = json_array_get_object_element (email_addresses, 0); | |
108 | |||
109 | 1 | self->mail = g_utf8_strdown (msg_json_object_get_string (email_address, "address"), -1); | |
110 | } else { | ||
111 | 4 | self->mail = g_strdup (msg_json_object_get_string (json_object, "mail")); | |
112 | } | ||
113 | 3 | self->display_name = g_strdup (msg_json_object_get_string (json_object, "displayName")); | |
114 | 3 | self->mobile_phone = g_strdup (msg_json_object_get_string (json_object, "mobilePhone")); | |
115 | 3 | self->office_location = g_strdup (msg_json_object_get_string (json_object, "officeLocation")); | |
116 | 3 | self->surname = g_strdup (msg_json_object_get_string (json_object, "surname")); | |
117 | 3 | self->given_name = g_strdup (msg_json_object_get_string (json_object, "givenName")); | |
118 | 3 | self->company_name = g_strdup (msg_json_object_get_string (json_object, "companyName")); | |
119 | 3 | self->department = g_strdup (msg_json_object_get_string (json_object, "department")); | |
120 | |||
121 | 3 | return self; | |
122 | } | ||
123 | |||
124 | /** | ||
125 | * msg_user_get_mail: | ||
126 | * @self: a user | ||
127 | * | ||
128 | * Returns: (transfer none): mail of user or %NULL if not existing | ||
129 | */ | ||
130 | const char * | ||
131 | 3 | msg_user_get_mail (MsgUser *self) | |
132 | { | ||
133 | 3 | return self->mail; | |
134 | } | ||
135 | |||
136 | /** | ||
137 | * msg_user_get_display_name: | ||
138 | * @self: a user | ||
139 | * | ||
140 | * Returns: (transfer none): display name of user or %NULL if not existing | ||
141 | */ | ||
142 | const char * | ||
143 | 1 | msg_user_get_display_name (MsgUser *self) | |
144 | { | ||
145 | 1 | return self->display_name; | |
146 | } | ||
147 | |||
148 | /** | ||
149 | * msg_user_get_mobile_phone: | ||
150 | * @self: a user | ||
151 | * | ||
152 | * Returns: (transfer none): mobile phone of user or %NULL if not existing | ||
153 | */ | ||
154 | const char * | ||
155 | 1 | msg_user_get_mobile_phone (MsgUser *self) | |
156 | { | ||
157 | 1 | return self->mobile_phone; | |
158 | } | ||
159 | |||
160 | /** | ||
161 | * msg_user_get_office_location: | ||
162 | * @self: a user | ||
163 | * | ||
164 | * Returns: (transfer none): office location of user or %NULL if not existing | ||
165 | */ | ||
166 | const char * | ||
167 | 1 | msg_user_get_office_location (MsgUser *self) | |
168 | { | ||
169 | 1 | return self->office_location; | |
170 | } | ||
171 | |||
172 | /** | ||
173 | * msg_user_get_surname: | ||
174 | * @self: a user | ||
175 | * | ||
176 | * Returns: (transfer none): surname of user or %NULL if not existing | ||
177 | */ | ||
178 | const char * | ||
179 | 1 | msg_user_get_surname (MsgUser *self) | |
180 | { | ||
181 | 1 | return self->surname; | |
182 | } | ||
183 | |||
184 | /** | ||
185 | * msg_user_get_given_name: | ||
186 | * @self: a user | ||
187 | * | ||
188 | * Returns: (transfer none): given name of user or %NULL if not existing | ||
189 | */ | ||
190 | const char * | ||
191 | 1 | msg_user_get_given_name (MsgUser *self) | |
192 | { | ||
193 | 1 | return self->given_name; | |
194 | } | ||
195 | |||
196 | /** | ||
197 | * msg_user_get_company_name: | ||
198 | * @self: a user | ||
199 | * | ||
200 | * Returns: (transfer none): company name of user or %NULL if not existing | ||
201 | */ | ||
202 | const char * | ||
203 | 1 | msg_user_get_company_name (MsgUser *self) | |
204 | { | ||
205 | 1 | return self->company_name; | |
206 | } | ||
207 | |||
208 | /** | ||
209 | * msg_user_get_department: | ||
210 | * @self: a user | ||
211 | * | ||
212 | * Returns: (transfer none): department of user or %NULL if not existing | ||
213 | */ | ||
214 | const char * | ||
215 | 1 | msg_user_get_department (MsgUser *self) | |
216 | { | ||
217 | 1 | return self->department; | |
218 | } | ||
219 |