#include <ctype.h>
#include <errno.h>
#include <sys/param.h>
-#ifndef G_OS_WIN32
-#include <sys/socket.h>
+#ifdef G_OS_WIN32
+# include <ws2tcpip.h>
+#else
+# include <sys/socket.h>
#endif
#if (HAVE_WCTYPE_H && HAVE_WCHAR_H)
gchar *to_human_readable(goffset size)
{
static gchar str[14];
- static gchar *b_format = NULL, *kb_format = NULL,
+ static gchar *b_format = NULL, *kb_format = NULL,
*mb_format = NULL, *gb_format = NULL;
register int t = 0, r = 0;
if (b_format == NULL) {
mb_format = _("%d.%02dMB");
gb_format = _("%.2fGB");
}
-
+
if (size < (goffset)1024) {
g_snprintf(str, sizeof(str), b_format, (gint)size);
return str;
#endif
if (!loc_dir)
loc_dir = LOCALEDIR;
-
+
return loc_dir;
}
rc_dir_alt = TRUE;
claws_rc_dir = canonical_dir;
-
+
len = strlen(claws_rc_dir);
if (claws_rc_dir[len - 1] == G_DIR_SEPARATOR)
claws_rc_dir[len - 1] = '\0';
-
+
debug_print("set rc_dir to %s\n", claws_rc_dir);
if (!is_dir_exist(claws_rc_dir)) {
if (make_dir_hier(claws_rc_dir) != 0) {
cert_file = g_strconcat(w32_get_module_dir(),
"\\share\\claws-mail\\",
"ca-certificates.crt",
- NULL);
+ NULL);
return cert_file;
}
#endif
else {
static gchar *plugin_dir = NULL;
if (!plugin_dir)
- plugin_dir = g_strconcat(get_rc_dir(),
- G_DIR_SEPARATOR_S, "plugins",
+ plugin_dir = g_strconcat(get_rc_dir(),
+ G_DIR_SEPARATOR_S, "plugins",
G_DIR_SEPARATOR_S, NULL);
- return plugin_dir;
+ return plugin_dir;
}
#endif
}
#endif
}
+/* Tells whether the given host address string is a valid representation of a
+ * numerical IP (v4 or, if supported, v6) address.
+ */
+gboolean is_numeric_host_address(const gchar *hostaddress)
+{
+ struct addrinfo hints, *res;
+ int err;
+
+ /* See what getaddrinfo makes of the string when told that it is a
+ * numeric IP address representation. */
+ memset(&hints, 0, sizeof(struct addrinfo));
+ hints.ai_family = AF_UNSPEC;
+ hints.ai_socktype = 0;
+ hints.ai_flags = AI_NUMERICHOST;
+ hints.ai_protocol = 0;
+
+ err = getaddrinfo(hostaddress, NULL, &hints, &res);
+ if (err == 0)
+ freeaddrinfo(res);
+
+ return (err == 0);
+}
+
off_t get_file_size(const gchar *file)
{
#ifdef G_OS_WIN32
*cs = '\0';
- return buf;
+ return buf;
}
static gint execute_async(gchar *const argv[], const gchar *working_directory)
#ifdef G_OS_WIN32
if (now && *now < 0)
return 0;
-#endif
+#endif
gmt = *gmtime_r(now, &buf1);
lt = localtime_r(now, &buf2);
start++;
*bp = start;
-
+
/* check if there are quotes (to skip , in them) */
if (*start == '"') {
start_quote = start;
start_quote = NULL;
end_quote = NULL;
}
-
+
/* skip anything between quotes */
if (start_quote && end_quote) {
start = end_quote;
-
- }
+
+ }
/* find end (either , or ; or end of line) */
if (strstr(start, ",") && strstr(start, ";"))
testcmd[strlen(testcmd)-1] = '\0';
while (testcmd[strlen(testcmd)-1] == ' ' || testcmd[strlen(testcmd)-1] == '\t')
testcmd[strlen(testcmd)-1] = '\0';
-
+
if (strstr(testcmd, "%s")) {
gchar *tmp = g_strdup_printf(testcmd, file_to_open);
gint res = system(tmp);
g_free(tmp);
g_free(orig_testcmd);
-
+
if (res != 0) {
g_strfreev(parts);
continue;
} else {
gint res = system(testcmd);
g_free(orig_testcmd);
-
+
if (res != 0) {
g_strfreev(parts);
continue;
}
}
}
-
+
trimmed = parts[1];
while (trimmed[0] == ' ' || trimmed[0] == '\t')
trimmed++;
if (claws_safe_fclose(outfp) == EOF)
err = TRUE;
-
+
if (!err)
g_rename(outpath, path);
}
const gchar *daynames[] = {NULL, NULL, NULL, NULL, NULL, NULL, NULL};
-const gchar *monthnames[] = {NULL, NULL, NULL, NULL, NULL, NULL,
+const gchar *monthnames[] = {NULL, NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL, NULL};
const gchar *s_daynames[] = {NULL, NULL, NULL, NULL, NULL, NULL, NULL};
-const gchar *s_monthnames[] = {NULL, NULL, NULL, NULL, NULL, NULL,
+const gchar *s_monthnames[] = {NULL, NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL, NULL};
gint daynames_len[] = {0,0,0,0,0,0,0};
s_daynames[4] = C_("Abbr. day name for use by strftime", "Thu");
s_daynames[5] = C_("Abbr. day name for use by strftime", "Fri");
s_daynames[6] = C_("Abbr. day name for use by strftime", "Sat");
-
+
s_monthnames[0] = C_("Abbr. month name for use by strftime", "Jan");
s_monthnames[1] = C_("Abbr. month name for use by strftime", "Feb");
s_monthnames[2] = C_("Abbr. month name for use by strftime", "Mar");
s_pm_up = C_("For use by strftime (afternoon)", "PM");
s_am_low = C_("For use by strftime (morning, lowercase)", "am");
s_pm_low = C_("For use by strftime (afternoon, lowercase)", "pm");
-
+
s_am_up_len = strlen(s_am_up);
s_pm_up_len = strlen(s_pm_up);
s_am_low_len = strlen(s_am_low);
gint total_done = 0;
gchar subbuf[64], subfmt[64];
static time_t last_tzset = (time_t)0;
-
+
if (!time_names_init_done)
init_time_names();
-
+
if (format == NULL || lt == NULL)
return 0;
-
+
if (last_tzset != time(NULL)) {
tzset();
last_tzset = time(NULL);
break;
case 'F':
len = 10; CHECK_SIZE();
- snprintf(curpos, buflen - total_done, "%4d-%02d-%02d",
+ snprintf(curpos, buflen - total_done, "%4d-%02d-%02d",
lt->tm_year + 1900, lt->tm_mon +1, lt->tm_mday);
break;
case 'H':
}
break;
case 'r':
+#ifdef G_OS_WIN32
+ strftime(subbuf, 64, "%I:%M:%S %p", lt);
+#else
strftime(subbuf, 64, "%r", lt);
+#endif
len = strlen(subbuf); CHECK_SIZE();
strncpy2(curpos, subbuf, buflen - total_done);
break;
format++;
} else {
int len = 1; CHECK_SIZE();
- *curpos++ = *format++;
+ *curpos++ = *format++;
}
}
*curpos = '\0';
return NULL;
}
else /* Remove the last inserted element */
- canonical_parts =
+ canonical_parts =
g_slist_delete_link(canonical_parts,
canonical_parts);
} else {
if (!g_path_is_absolute(target)) {
/* remove the last inserted element */
- canonical_parts =
+ canonical_parts =
g_slist_delete_link(canonical_parts,
canonical_parts);
/* add the target */
gchar *cur = g_get_current_dir();
gchar *absolute_filename = g_strconcat(cur, G_DIR_SEPARATOR_S,
filename, NULL);
-
+
canonical_parts = cm_split_path(absolute_filename, 0);
g_free(absolute_filename);
g_free(cur);
g_free(tmp);
if (strlen(out) != *out_len) {
- g_warning ("strlen(out) %zd != *out_len %" G_GSIZE_FORMAT, strlen(out), *out_len);
+ g_warning ("strlen(out) %"G_GSIZE_FORMAT" != *out_len %"G_GSIZE_FORMAT, strlen(out), *out_len);
}
return out;
/* Read data from the source into buf. */
#if defined G_OS_WIN32
if (!CryptGenRandom(rnd, count, buf)) {
- debug_print("Could not read %zd random bytes.\n", count);
+ debug_print("Could not read %"G_GSIZE_FORMAT" random bytes.\n", count);
CryptReleaseContext(rnd, 0);
return FALSE;
}
return TRUE;
}
+
+/* returns FALSE if parsing failed, otherwise returns TRUE and sets *server, *port
+ and eventually *fp from filename (if not NULL, they must be free'd by caller after
+ user.
+ filenames we expect: 'host.name.port.cert' or 'host.name.port.f:i:n:g:e:r:p:r:i:n:t.cert' */
+gboolean get_serverportfp_from_filename(const gchar *str, gchar **server, gchar **port, gchar **fp)
+{
+ const gchar *pos, *dotport_pos = NULL, *dotcert_pos = NULL, *dotfp_pos = NULL;
+
+ g_return_val_if_fail(str != NULL, FALSE);
+
+ pos = str + strlen(str) - 1;
+ while ((pos > str) && !dotport_pos) {
+ if (*pos == '.') {
+ if (!dotcert_pos) {
+ /* match the .cert suffix */
+ if (strcmp(pos, ".cert") == 0) {
+ dotcert_pos = pos;
+ }
+ } else {
+ if (!dotfp_pos) {
+ /* match an eventual fingerprint */
+ /* or the port number */
+ if (strncmp(pos + 3, ":", 1) == 0) {
+ dotfp_pos = pos;
+ } else {
+ dotport_pos = pos;
+ }
+ } else {
+ /* match the port number */
+ dotport_pos = pos;
+ }
+ }
+ }
+ pos--;
+ }
+ if (!dotport_pos || !dotcert_pos) {
+ g_warning("could not parse filename %s", str);
+ return FALSE;
+ }
+
+ if (server != NULL)
+ *server = g_strndup(str, dotport_pos - str);
+ if (dotfp_pos) {
+ if (port != NULL)
+ *port = g_strndup(dotport_pos + 1, dotfp_pos - dotport_pos - 1);
+ if (fp != NULL)
+ *fp = g_strndup(dotfp_pos + 1, dotcert_pos - dotfp_pos - 1);
+ } else {
+ if (port != NULL)
+ *port = g_strndup(dotport_pos + 1, dotcert_pos - dotport_pos - 1);
+ if (fp != NULL)
+ *fp = NULL;
+ }
+
+ debug_print("filename='%s' => server='%s' port='%s' fp='%s'\n",
+ str,
+ (server ? *server : "(n/a)"),
+ (port ? *port : "(n/a)"),
+ (fp ? *fp : "(n/a)"));
+
+ if (!(server && *server) || !(port && *port))
+ return FALSE;
+ else
+ return TRUE;
+}
+