Skip to content

Commit 6845cfd

Browse files
committed
Fix C API time signature access
1 parent 41ff458 commit 6845cfd

4 files changed

Lines changed: 43 additions & 14 deletions

File tree

README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,27 @@ lintian --info --pedantic --display-info ../nmbs_*_amd64.changes
108108
sudo apt install ./nmbs_*_amd64.deb ./libnmbs1_*_amd64.deb
109109
nautilus -q
110110

111+
# Check d/watch is working
112+
uscan -v --no-download
113+
114+
```
115+
116+
## Nautilus Development
117+
118+
It is quite easy to develop for Nautilus. Quite simply, symlink the debug .so to the nautilus extensions folder.
119+
Important to know is that Nautilus runs with a daemon in the background. You must sometimes kill this or the module
120+
will not reload.
121+
122+
Check the run configurations of NMBS-Nautilus to see how to Debug. In CLion this is stored in git, so just debug
123+
the target to start Nautilus with gdb.
124+
```shell
125+
nautilus -q
126+
```
127+
```shell
128+
sudo ln -s $PWD/build/debug/targets/NMBS-Nautilus/libnmbs-nautilusd.so /usr/lib/x86_64-linux-gnu/nautilus/extensions-4/libnmbs-nautilus.so
129+
```
130+
```shell
131+
sudo rm /usr/lib/x86_64-linux-gnu/nautilus/extensions-4/libnmbs-nautilus.so
111132
```
112133

113134
# Runtime Environment Variables

targets/NMBS-Library/include/public/nmbs/nmbs_c.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -187,11 +187,13 @@ void nmbs_confidentiality_labels_read_labels_with_known_binding(nmbs_confidentia
187187
/// @return Pointer to the underlying data. Do not free or delete this!
188188
[[nodiscard]] const char* nmbs_confidentiality_label_get_classification(nmbs_confidentiality_label_ptr label) NMBS_NOEXCEPT;
189189

190-
/// @brief Opaque Accessor
190+
/// @brief Opaque Generator
191191
/// @ingroup c_confidentiality_labels
192192
/// @param label
193-
/// @return
194-
[[nodiscard]] const char* nmbs_confidentiality_label_get_creation_date_time(nmbs_confidentiality_label_ptr label) NMBS_NOEXCEPT;
193+
/// @param out_buffer
194+
/// @param out_buffer_size
195+
unsigned int nmbs_confidentiality_label_get_creation_date_time(nmbs_confidentiality_label_ptr label, char* out_buffer,
196+
unsigned int out_buffer_size) NMBS_NOEXCEPT;
195197

196198
/// @brief Opaque Accessor
197199
/// @ingroup c_confidentiality_labels

targets/NMBS-Library/src/nmbs_c.cpp

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030
#include <iostream>
3131
#include <sstream>
32+
#include <string.h>
3233
#include <string>
3334

3435
#include "nmbs/exit_code.h"
@@ -258,25 +259,29 @@ const char* nmbs_confidentiality_label_get_classification(nmbs_confidentiality_l
258259
}
259260
}
260261

261-
const char* nmbs_confidentiality_label_get_creation_date_time(nmbs_confidentiality_label_ptr label) noexcept
262+
unsigned int nmbs_confidentiality_label_get_creation_date_time(nmbs_confidentiality_label_ptr label, char* out_buffer,
263+
const unsigned int out_buffer_size) noexcept
262264
{
263265
try
264266
{
265-
auto cpp_label = to_cpp_label(label);
267+
auto const cpp_label = to_cpp_label(label);
266268
if (cpp_label == nullptr)
267269
{
268-
return nullptr;
270+
return 0;
271+
}
272+
auto const timepoint = cpp_label->creation_date_time;auto timepoint_string = std::format(std::locale(""), "{:L%c}", timepoint);
273+
274+
if (out_buffer_size > timepoint_string.size())
275+
{
276+
strcpy(out_buffer, timepoint_string.c_str());
277+
return timepoint_string.size();
269278
}
270-
auto timepoint = cpp_label->creation_date_time;
271-
// TODO: This is slightly dangerous. I think in reality it is fine for this use case, but academically
272-
// speaking its possible to get failures caused here.
273-
thread_local auto timepoint_string = std::format(std::locale(""), "{:L%c}", timepoint);
274-
return timepoint_string.c_str();
279+
return 0;
275280
}
276281
catch (...)
277282
{
278283
std::cerr << "C++ Exception caught in nmbs_confidentiality_label_get_creation_date_time" << std::endl;
279-
return nullptr;
284+
return 0;
280285
}
281286
}
282287

targets/NMBS-Nautilus/src/nmbs-nautilus.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,10 +120,11 @@ static NautilusOperationResult nmbs_properties_update_file_info(
120120
auto const label_policy = nmbs_confidentiality_label_get_policy(label);
121121
auto const label_classification = nmbs_confidentiality_label_get_classification(label);
122122
auto const label_originator = nmbs_confidentiality_label_get_originator_id(label);
123-
auto const label_time = nmbs_confidentiality_label_get_creation_date_time(label);
123+
char label_time[100];
124+
auto const label_time_size = nmbs_confidentiality_label_get_creation_date_time(label, label_time, sizeof(label_time));
124125

125126
// These are mandatory fields for a label.
126-
if (!label || !label_policy || !label_classification || !label_time)
127+
if (!label || !label_policy || !label_classification || label_time_size == 0)
127128
{
128129
continue;
129130
}

0 commit comments

Comments
 (0)