text stringlengths 0 357 |
|---|
/* build a more or less unique string based on the timestamp and one receiver - |
for our purposes, this seems "good enough" for the moment, esp. as clients normally set Message-ID on sent. */ |
return dc_mprintf("%lu-%lu-%lu@stub", (unsigned long)message_timestamp, (unsigned long)contact_id_from, (unsigned long)largest_id_to); |
} |
char* dc_extract_grpid_from_rfc724_mid(const char* mid) |
{ |
/* extract our group ID from Message-IDs as `Gr.12345678901.morerandom@domain.de`; "12345678901" is the wanted ID in this example. */ |
int success = 0; |
char* grpid = NULL; |
char* p1 = NULL; |
int grpid_len = 0; |
if (mid==NULL || strlen(mid)<8 || mid[0]!='G' || mid[1]!='r' || mid[2]!='.') { |
goto cleanup; |
} |
grpid = dc_strdup(&mid[3]); |
p1 = strchr(grpid, '.'); |
if (p1==NULL) { |
goto cleanup; |
} |
*p1 = 0; |
#define DC_ALSO_VALID_ID_LEN 16 /* length returned by create_adhoc_grp_id() */ |
grpid_len = strlen(grpid); |
if (grpid_len!=DC_CREATE_ID_LEN && grpid_len!=DC_ALSO_VALID_ID_LEN) { /* strict length comparison, the 'Gr.' magic is weak enough */ |
goto cleanup; |
} |
success = 1; |
cleanup: |
if (success==0) { free(grpid); grpid = NULL; } |
return success? grpid : NULL; |
} |
char* dc_extract_grpid_from_rfc724_mid_list(const clist* list) |
{ |
if (list) { |
for (clistiter* cur = clist_begin(list); cur!=NULL ; cur=clist_next(cur)) { |
const char* mid = clist_content(cur); |
char* grpid = dc_extract_grpid_from_rfc724_mid(mid); |
if (grpid) { |
return grpid; |
} |
} |
} |
return NULL; |
} |
/******************************************************************************* |
* file tools |
******************************************************************************/ |
/* |
* removes trailing slash from given path. |
*/ |
void dc_ensure_no_slash(char* pathNfilename) |
{ |
int path_len = strlen(pathNfilename); |
if (path_len > 0) { |
if (pathNfilename[path_len-1]=='/' |
|| pathNfilename[path_len-1]=='\\') { |
pathNfilename[path_len-1] = 0; |
} |
} |
} |
void dc_validate_filename(char* filename) |
{ |
/* function modifies the given buffer and replaces all characters not valid in filenames by a "-" */ |
char* p1 = filename; |
while (*p1) { |
if (*p1=='/' || *p1=='\\' || *p1==':') { |
*p1 = '-'; |
} |
p1++; |
} |
} |
char* dc_get_filename(const char* pathNfilename) |
{ |
const char* p = strrchr(pathNfilename, '/'); |
if (p==NULL) { |
p = strrchr(pathNfilename, '\\'); |
} |
if (p) { |
p++; |
return dc_strdup(p); |
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.