From b544c35e84395e2ab86dc2261c88575c8ff68ab3 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Ture=20P=C3=A5lsson?= <ture@lysator.liu.se>
Date: Fri, 5 Dec 2014 09:03:47 +0100
Subject: [PATCH] Streamline callback interface

Send "borrowed" references in some cases, omit username and
timestamp.
---
 src/osm_objects.c | 26 +++++++-------------------
 src/protobuf.c    | 12 ++++++------
 2 files changed, 13 insertions(+), 25 deletions(-)

diff --git a/src/osm_objects.c b/src/osm_objects.c
index 1176901..1112eaf 100644
--- a/src/osm_objects.c
+++ b/src/osm_objects.c
@@ -623,19 +623,9 @@ call_node_callback (readosm_node_callback node_callback,
     exp_node.longitude = node->longitude;
     exp_node.version = node->version;
     exp_node.changeset = node->changeset;
-    if (node->user != NULL)
-      {
-	  len = strlen (node->user);
-	  exp_node.user = malloc (len + 1);
-	  strcpy (exp_node.user, node->user);
-      }
+    exp_node.user = node->user;
     exp_node.uid = node->uid;
-    if (node->timestamp != NULL)
-      {
-	  len = strlen (node->timestamp);
-	  exp_node.timestamp = malloc (len + 1);
-	  strcpy (exp_node.timestamp, node->timestamp);
-      }
+    exp_node.timestamp = node->timestamp;
 
 /* setting up the NODE-TAGs array */
     tag_blk = &(node->first_tag);
@@ -665,15 +655,11 @@ call_node_callback (readosm_node_callback node_callback,
 		      p_tag = exp_node.tags + i;
 		      if (tag->key != NULL)
 			{
-			    len = strlen (tag->key);
-			    p_tag->key = malloc (len + 1);
-			    strcpy (p_tag->key, tag->key);
+                            p_tag->key = strdup (tag->key);
 			}
 		      if (tag->value != NULL)
 			{
-			    len = strlen (tag->value);
-			    p_tag->value = malloc (len + 1);
-			    strcpy (p_tag->value, tag->value);
+			    p_tag->value = strdup (tag->value);
 			}
 		      i++;
 		  }
@@ -684,7 +670,9 @@ call_node_callback (readosm_node_callback node_callback,
 /* calling the user-defined NODE handling callback function */
     ret = (*node_callback) (user_data, readonly_node);
 
-/* resetting the export WAY object */
+    exp_node.user = exp_node.timestamp = 0;
+
+/* resetting the export NODE object */
     reset_export_node (&exp_node);
     return ret;
 }
diff --git a/src/protobuf.c b/src/protobuf.c
index 5bb3729..1b96659 100644
--- a/src/protobuf.c
+++ b/src/protobuf.c
@@ -1505,7 +1505,7 @@ parse_pbf_nodes (readosm_string_table * strings,
 		      nd->version = *(packed_infos.versions + base + i);
 		      xtime = *(packed_infos.timestamps + base + i);
 		      times = gmtime (&xtime);
-		      if (times)
+		      if (0 && times)
 			{
 			    /* formatting Timestamps */
 			    char buf[64];
@@ -1524,7 +1524,7 @@ parse_pbf_nodes (readosm_string_table * strings,
 		      if (*(packed_infos.uids + base + i) >= 0)
 			  nd->uid = *(packed_infos.uids + base + i);
 		      s_id = *(packed_infos.users + base + i);
-		      if (s_id > 0)
+		      if (0 && s_id > 0)
 			{
 			    /* retrieving user-names as strings (by index) */
 			    readosm_string *s_ptr = *(strings->strings + s_id);
@@ -1669,7 +1669,7 @@ parse_pbf_way_info (readosm_internal_way * way, readosm_string_table * strings,
 		/* timestamp */
 		const time_t xtime = variant.value.int32_value;
 		struct tm *times = gmtime (&xtime);
-		if (times)
+		if (0 && times)
 		  {
 		      char buf[64];
 		      int len;
@@ -1702,7 +1702,7 @@ parse_pbf_way_info (readosm_internal_way * way, readosm_string_table * strings,
 		    free (way->user);
 		way->user = NULL;
 		userid = variant.value.int32_value;
-		if (userid > 0 && userid < strings->count)
+		if (0 && userid > 0 && userid < strings->count)
 		  {
 		      readosm_string *string = *(strings->strings + userid);
 		      int len = strlen (string->string);
@@ -1894,7 +1894,7 @@ parse_pbf_relation_info (readosm_internal_relation * relation,
 		/* timestamp */
 		const time_t xtime = variant.value.int32_value;
 		struct tm *times = gmtime (&xtime);
-		if (times)
+		if (0 && times)
 		  {
 		      char buf[64];
 		      int len;
@@ -1927,7 +1927,7 @@ parse_pbf_relation_info (readosm_internal_relation * relation,
 		    free (relation->user);
 		relation->user = NULL;
 		userid = variant.value.int32_value;
-		if (userid > 0 && userid < strings->count)
+		if (0 && userid > 0 && userid < strings->count)
 		  {
 		      readosm_string *string = *(strings->strings + userid);
 		      int len = strlen (string->string);
-- 
GitLab