Skip to content

Commit

Permalink
set default date.
Browse files Browse the repository at this point in the history
  • Loading branch information
jfdelnero committed Nov 7, 2023
1 parent 543f9a9 commit edc98cb
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
2 changes: 2 additions & 0 deletions inc/mtp_datasets.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,6 @@ int build_storageinfo_dataset(mtp_ctx * ctx,void * buffer, int maxsize,uint32_t
int build_objectinfo_dataset(mtp_ctx * ctx, void * buffer, int maxsize,fs_entry * entry);
int build_event_dataset(mtp_ctx * ctx, void * buffer, int maxsize, uint32_t event, uint32_t session, uint32_t transaction, int nbparams, uint32_t * parameters);

void set_default_date(struct tm * date);

#endif
9 changes: 9 additions & 0 deletions src/mtp_datasets.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include <sys/statvfs.h>
#include <time.h>
#include <stdio.h>
#include <string.h>

#include "mtp.h"
#include "mtp_helpers.h"
Expand All @@ -45,6 +46,12 @@
#include "fs_handles_db.h"
#include "logs_out.h"

void set_default_date(struct tm * date)
{
memset(date, 0, sizeof(struct tm));
date->tm_year = 110;
}

int build_deviceinfo_dataset(mtp_ctx * ctx, void * buffer, int maxsize)
{
int ofs,i,elements_cnt;
Expand Down Expand Up @@ -221,12 +228,14 @@ int build_objectinfo_dataset(mtp_ctx * ctx, void * buffer, int maxsize,fs_entry
ofs = poke_string(buffer, ofs, maxsize, entry->name); // Filename

// Date Created (NR) "YYYYMMDDThhmmss.s"
set_default_date(&lt);
t = entrystat.st_mtime;
localtime_r(&t, &lt);
snprintf(timestr,sizeof(timestr),"%.4d%.2d%.2dT%.2d%.2d%.2d",1900 + lt.tm_year, lt.tm_mon + 1, lt.tm_mday, lt.tm_hour, lt.tm_min, lt.tm_sec);
ofs = poke_string(buffer, ofs, maxsize, timestr);

// Date Modified (NR) "YYYYMMDDThhmmss.s"
set_default_date(&lt);
t = entrystat.st_mtime;
localtime_r(&t, &lt);
snprintf(timestr,sizeof(timestr),"%.4d%.2d%.2dT%.2d%.2d%.2d",1900 + lt.tm_year, lt.tm_mon + 1, lt.tm_mday, lt.tm_hour, lt.tm_min, lt.tm_sec);
Expand Down
3 changes: 3 additions & 0 deletions src/mtp_properties.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include "mtp_helpers.h"
#include "mtp_constant.h"
#include "mtp_constant_strings.h"
#include "mtp_datasets.h"
#include "mtp_properties.h"

#include "fs_handles_db.h"
Expand Down Expand Up @@ -788,12 +789,14 @@ int build_objectproplist_dataset(mtp_ctx * ctx, void * buffer, int maxsize,fs_en
numberofelements += objectproplist_element(ctx, buffer, &ofs, maxsize, MTP_PROPERTY_DISPLAY_NAME, handle, 0,prop_code);

// Date Created (NR) "YYYYMMDDThhmmss.s"
set_default_date(&lt);
t = entrystat.st_mtime;
localtime_r(&t, &lt);
snprintf(timestr,sizeof(timestr),"%.4d%.2d%.2dT%.2d%.2d%.2d",1900 + lt.tm_year, lt.tm_mon + 1, lt.tm_mday, lt.tm_hour, lt.tm_min, lt.tm_sec);
numberofelements += objectproplist_element(ctx, buffer, &ofs, maxsize, MTP_PROPERTY_DATE_CREATED, handle, &timestr,prop_code);

// Date Modified (NR) "YYYYMMDDThhmmss.s"
set_default_date(&lt);
t = entrystat.st_mtime;
localtime_r(&t, &lt);
snprintf(timestr,sizeof(timestr),"%.4d%.2d%.2dT%.2d%.2d%.2d",1900 + lt.tm_year, lt.tm_mon + 1, lt.tm_mday, lt.tm_hour, lt.tm_min, lt.tm_sec);
Expand Down

0 comments on commit edc98cb

Please sign in to comment.