Enlightenment CVS committal
Author : rbdpngn
Project : misc
Module : erss
Dir : misc/erss/src
Modified Files:
erss.c parse.c parse.h
Log Message:
Slight re-organization of some global options into the rc file rather than
each individual config file. Also checks the BROWSER env variable if your
config file does not specify it. Fixed some segvs along the way too.
===================================================================
RCS file: /cvsroot/enlightenment/misc/erss/src/erss.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -3 -r1.8 -r1.9
--- erss.c 26 Dec 2003 12:48:09 -0000 1.8
+++ erss.c 9 Jan 2004 23:00:08 -0000 1.9
@@ -16,7 +16,7 @@
char *main_buffer;
char *last_time;
-int bufsize = 0;
+int main_bufsize = 0;
int waiting_for_reply = FALSE;
int total_connects = 0;
@@ -25,7 +25,7 @@
{
if (waiting_for_reply) {
- fprintf (stderr, "%s warning: client has not recived all information
",
+ fprintf (stderr, "%s warning: client has not received all information
",
PACKAGE);
fprintf (stderr, "from the last connection attempt yet! \n");
return TRUE;
@@ -38,25 +38,25 @@
else
printf ("%s info: connecting to '%s' ...\n", PACKAGE, cfg->url);
- if (cfg->proxy) {
- if (!strcasecmp (cfg->proxy, "")) {
+ if (rc->proxy) {
+ if (!strcasecmp (rc->proxy, "")) {
server = ecore_con_server_connect (ECORE_CON_REMOTE_SYSTEM,
cfg->hostname, 80, NULL);
} else {
- if (!cfg->proxy_port)
+ if (!rc->proxy_port)
{
fprintf (stderr,
"%s error: You need to define a proxy
port!\n", PACKAGE);
exit (-1);
}
server = ecore_con_server_connect (ECORE_CON_REMOTE_SYSTEM,
-
cfg->proxy, cfg->proxy_port, NULL);
+
rc->proxy, rc->proxy_port, NULL);
}
} else {
server = ecore_con_server_connect (ECORE_CON_REMOTE_SYSTEM,
cfg->hostname, 80, NULL);
}
-
+
if (!server) {
fprintf (stderr, "%s error: Could not connect to server ..\n",
PACKAGE);
exit (-1);
@@ -207,15 +207,15 @@
Ecore_Con_Event_Server_Data *e = event;
if (total_connects == 1)
- printf ("%s info: reciving data ...\n", PACKAGE);
+ printf ("%s info: receiving data ...\n", PACKAGE);
/*
- * Read everything we recive into one big buffer, and handle
+ * Read everything we receive into one big buffer, and handle
* that buffer when the server disconnects.
*/
- main_buffer = realloc (main_buffer, bufsize + e->size);
- memcpy (main_buffer + bufsize, e->data, e->size);
- bufsize += e->size;
+ main_buffer = realloc (main_buffer, main_bufsize + e->size);
+ memcpy (main_buffer + main_bufsize, e->data, e->size);
+ main_bufsize += e->size;
return 1;
}
@@ -223,31 +223,31 @@
int handler_server_del (void *data, int type, void *event)
{
Ecore_Con_Event_Server_Del *e = event;
+ char *buf = main_buffer;
char *leader;
if (total_connects == 1)
printf ("%s info: disconnecting ...\n", PACKAGE);
/*
- * Now split our main buffer in each newline and then parse
- * the line.
+ * Now split our buffer in each newline and then parse the line.
*/
- while (main_buffer != NULL)
+ while (buf != NULL)
{
char temp;
- leader = strchr (main_buffer, '\n');
+ leader = strchr (buf, '\n');
if (leader)
{
temp = *leader;
*leader = '\0';
- parse_data (main_buffer);
+ parse_data (buf);
*leader = temp;
- main_buffer = leader + 1;
+ buf = leader + 1;
} else
{
- main_buffer = leader;
+ buf = leader;
}
}
@@ -256,11 +256,10 @@
if (ewd_list_is_empty (list)) {
printf ("\n%s error: parsing data\n", PACKAGE);
- if (main_buffer)
+ if (buf)
printf ("%s\n", main_buffer);
else
printf ("%s error: could not connect to '%s'\n", PACKAGE,
cfg->url);
-
exit (-1);
}
@@ -269,7 +268,7 @@
main_buffer = NULL;
}
- bufsize = 0;
+ main_bufsize = 0;
waiting_for_reply = FALSE;
if (total_connects == 1)
@@ -319,12 +318,12 @@
Article *item = data;
char c[1024];
- if (!cfg->browser) {
+ if (!rc->browser) {
fprintf (stderr, "%s error: you have not defined any browser in your
config file setting /usr/bin/mozilla as default\n", PACKAGE);
- cfg->browser = strdup ("/usr/bin/mozilla");
+ rc->browser = strdup ("mozilla");
}
- snprintf (c, sizeof (c), "%s %s", cfg->browser, item->url);
+ snprintf (c, sizeof (c), "%s %s", rc->browser, item->url);
ecore_exe_run (c, NULL);
}
@@ -363,8 +362,7 @@
config_files = ewd_list_new ();
str = malloc (PATH_MAX);
- snprintf (str, PATH_MAX, "%s/.%s/config",
- getenv("HOME"), PACKAGE);
+ snprintf (str, PATH_MAX, "%s/.%s/config", getenv("HOME"), PACKAGE);
ewd_list_append (paths, str);
str = malloc (PATH_MAX);
@@ -372,13 +370,7 @@
ewd_list_append (paths, str);
str = malloc (PATH_MAX);
- snprintf (str, PATH_MAX, "/usr/local/share/%s/config",
- PACKAGE);
- ewd_list_append (paths, str);
-
- str = malloc (PATH_MAX);
- snprintf (str, PATH_MAX, "/usr/share/%s/config",
- PACKAGE);
+ snprintf (str, PATH_MAX, "%s/config", PACKAGE_DATA_DIR);
ewd_list_append (paths, str);
if (output)
@@ -526,14 +518,15 @@
parse_config_file (config_file);
}
- if (!got_theme_file)
+ if (!got_theme_file) {
if (!got_rc_file)
cfg->theme = strdup (PACKAGE_DATA_DIR"/default.eet");
else
cfg->theme = strdup (rc->theme);
+ }
else
cfg->theme = strdup (theme_file);
-
+
stat (cfg->theme, &statbuf);
if (!S_ISREG(statbuf.st_mode)) {
printf ("%s error: themefile '%s' does not exist!\n", PACKAGE,
cfg->theme);
===================================================================
RCS file: /cvsroot/enlightenment/misc/erss/src/parse.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -3 -r1.4 -r1.5
--- parse.c 25 Dec 2003 22:06:27 -0000 1.4
+++ parse.c 9 Jan 2004 23:00:08 -0000 1.5
@@ -43,7 +43,7 @@
if (!ret_val)
goto err_clean_c;
- *buffer = end_tmp + size - 1;
+ /* *buffer = end_tmp + size - 1; */
err_clean_c:
free (c);
@@ -126,6 +126,9 @@
"]]>"
};
+ if (!buf || !*buf)
+ return;
+
/*
printf ("data: %s\n", buf);
*/
@@ -138,7 +141,7 @@
/*
* We have a new story, allocate an item for it
*/
- item = malloc (sizeof (Article *));
+ item = malloc (sizeof (Article));
item->description = NULL;
item->url = NULL;
@@ -171,13 +174,11 @@
c = ecore_txt_convert ("iso-8859-1", "utf8", c);
- text = malloc (1024);
+ i = strlen(c) + 3 + strlen(cfg->prefix);
- if (cfg->prefix)
- snprintf (text, strlen (c) + strlen (cfg->prefix), " %s %s",
- cfg->prefix, c);
- else
- snprintf (text, strlen (c) + 5, " . %s", c);
+ text = malloc (i);
+
+ snprintf (text, i, " %s %s", cfg->prefix, c);
item->obj = edje_object_add (evas);
edje_object_file_set (item->obj,
@@ -239,20 +240,21 @@
if (feof (fp))
return NULL;
+ buf[index++] = temp;
+
+ /* Check size after incrimenting to eliminate extra check
+ * outside of loop */
if (index == bufsize)
{
bufsize += 512;
buf = realloc (buf, bufsize);
}
-
- buf[index++] = temp;
}
- if (index == bufsize)
- buf = realloc (buf, bufsize);
-
buf[index] = '\0';
- buf = realloc (buf, strlen (buf) ? strlen (buf) : 1);
+ index = strlen(buf) + 1;
+ if (bufsize > index)
+ buf = realloc (buf, index);
return buf;
}
@@ -265,14 +267,16 @@
char file[PATH_MAX];
snprintf (file, PATH_MAX, "%s/.erssrc", getenv ("HOME"));
-
- fp = fopen (file, "r");
- if (!fp)
- return FALSE;
rc = malloc (sizeof (Rc_Config));
+ if (!rc)
+ return FALSE;
- while ((line = get_next_line (fp)) != NULL)
+ memset(rc, 0, sizeof(Rc_Config));
+
+ fp = fopen (file, "r");
+
+ while (fp && (line = get_next_line (fp)) != NULL)
{
if ((c = get_element (&line, "config")) != NULL)
{
@@ -285,20 +289,44 @@
rc->theme = strdup (c);
continue;
}
-
- }
-
- free (line);
- fclose (fp);
- if (rc->theme && rc->config)
- return TRUE;
- else {
- fprintf (stderr,
- "Erss error: you are missing something in your rc
file!\n\n");
+ if ((c = get_element (&line, "browser")) != NULL)
+ {
+ rc->browser = strdup (c);
+ continue;
+ }
+
+ if ((c = get_element (&line, "proxy")) != NULL)
+ {
+ rc->proxy = strdup (c);
+ continue;
+ }
+
+ if ((c = get_element (&line, "proxy_port")) != NULL)
+ {
+ rc->proxy_port = atoi (c);
+ }
+
+ free(line);
}
-
- return FALSE;
+
+ if (fp)
+ fclose (fp);
+
+ /*
+ * Set sane defaults for unspecified config options.
+ */
+ if (!rc->theme)
+ rc->theme = strdup(PACKAGE_DATA_DIR "/default.eet");
+ if (!rc->config)
+ rc->config = strdup(PACKAGE_DATA_DIR "/config/slashdot.cfg");
+
+ if (!rc->browser && getenv("BROWSER"))
+ rc->browser = strdup(getenv("BROWSER"));
+ if (!rc->browser)
+ rc->browser = strdup("mozilla");
+
+ return TRUE;
}
void parse_config_file (char *file)
@@ -309,11 +337,12 @@
if ((fp = fopen (file, "r")) == NULL)
{
- fprintf (stderr, "Erss error: Can't open config file\n");
+ fprintf (stderr, "Erss error: Can't open config file %s\n", file);
exit (-1);
}
cfg = malloc (sizeof (Config));
+ memset(cfg, 0, sizeof(Config));
while ((line = get_next_line (fp)) != NULL)
{
@@ -398,12 +427,6 @@
continue;
}
- if ((c = get_element (&line, "browser")) != NULL)
- {
- cfg->browser = strdup (c);
- continue;
- }
-
if ((c = get_element (&line, "borderless")) != NULL)
{
cfg->borderless = atoi (c);
@@ -429,20 +452,12 @@
continue;
}
- if ((c = get_element (&line, "proxy")) != NULL)
- {
- cfg->proxy = strdup (c);
- continue;
- }
-
- if ((c = get_element (&line, "proxy_port")) != NULL)
- {
- cfg->proxy_port = atoi (c);
- }
+ free (line);
}
- free (line);
-
fclose (fp);
+
+ if (!cfg->prefix)
+ cfg->prefix = strdup(" . ");
}
===================================================================
RCS file: /cvsroot/enlightenment/misc/erss/src/parse.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -3 -r1.3 -r1.4
--- parse.h 25 Dec 2003 22:06:27 -0000 1.3
+++ parse.h 9 Jan 2004 23:00:08 -0000 1.4
@@ -24,9 +24,6 @@
int borderless;
- char *proxy;
- int proxy_port;
- char *browser;
char *prefix;
char *theme;
@@ -36,6 +33,9 @@
typedef struct _rc_config {
char *config;
char *theme;
+ char *browser;
+ char *proxy;
+ int proxy_port;
} Rc_Config;
int parse_rc_file ();
-------------------------------------------------------
This SF.net email is sponsored by: Perforce Software.
Perforce is the Fast Software Configuration Management System offering
advanced branching capabilities and atomic changes on 50+ platforms.
Free Eval! http://www.perforce.com/perforce/loadprog.html
_______________________________________________
enlightenment-cvs mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs