From a2d742ec911291bdc3878aafd00c19d27327cb3f Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Fri, 14 Aug 2015 00:40:36 +0200 Subject: [PATCH 1/2] For unique values we should use our guid function - not the random function --- include/items.php | 2 +- include/text.php | 10 ++++++++-- mod/item.php | 2 +- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/include/items.php b/include/items.php index 848c21df3..eaa056546 100644 --- a/include/items.php +++ b/include/items.php @@ -2968,7 +2968,7 @@ function item_is_remote_self($contact, &$datarray) { if ($contact['network'] != NETWORK_FEED) { $datarray["guid"] = get_guid(32); unset($datarray["plink"]); - $datarray["uri"] = item_new_uri($a->get_hostname(),$contact['uid']); + $datarray["uri"] = item_new_uri($a->get_hostname(),$contact['uid'], $datarray["guid"]); $datarray["parent-uri"] = $datarray["uri"]; $datarray["extid"] = $contact['network']; $urlpart = parse_url($datarray2['author-link']); diff --git a/include/text.php b/include/text.php index 18ce232f1..285c674d7 100644 --- a/include/text.php +++ b/include/text.php @@ -470,11 +470,17 @@ if(! function_exists('item_new_uri')) { * @param int $uid * @return string */ -function item_new_uri($hostname,$uid) { +function item_new_uri($hostname,$uid, $guid = "") { do { $dups = false; - $hash = random_string(); + + if ($guid == "") + $hash = get_guid(32); + else { + $hash = $guid; + $guid = ""; + } $uri = "urn:X-dfrn:" . $hostname . ':' . $uid . ':' . $hash; diff --git a/mod/item.php b/mod/item.php index a5f483b35..d203ce64d 100644 --- a/mod/item.php +++ b/mod/item.php @@ -674,7 +674,7 @@ function item_post(&$a) { $notify_type = (($parent) ? 'comment-new' : 'wall-new' ); - $uri = (($message_id) ? $message_id : item_new_uri($a->get_hostname(),$profile_uid)); + $uri = (($message_id) ? $message_id : item_new_uri($a->get_hostname(),$profile_uid, $guid)); // Fallback so that we alway have a thr-parent if(!$thr_parent) From bacd71e1c69e7a6e12fc569c9fc809ca78dab137 Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Fri, 14 Aug 2015 07:48:28 +0200 Subject: [PATCH 2/2] Replace random strings with guids where appropriate. --- include/Contact.php | 2 +- include/follow.php | 2 +- include/items.php | 4 ++-- include/message.php | 26 +++++++++++++------------- mod/wall_attach.php | 4 ++-- 5 files changed, 19 insertions(+), 19 deletions(-) diff --git a/include/Contact.php b/include/Contact.php index 1215f40e7..920ec3c2b 100644 --- a/include/Contact.php +++ b/include/Contact.php @@ -113,7 +113,7 @@ function terminate_friendship($user,$self,$contact) { '$photo' => $self['photo'], '$thumb' => $self['thumb'], '$published' => datetime_convert('UTC','UTC', 'now', ATOM_TIME), - '$item_id' => 'urn:X-dfrn:' . $a->get_hostname() . ':unfollow:' . random_string(), + '$item_id' => 'urn:X-dfrn:' . $a->get_hostname() . ':unfollow:' . get_guid(32), '$title' => '', '$type' => 'text', '$content' => t('stopped following'), diff --git a/include/follow.php b/include/follow.php index 6c998e178..10ce4f667 100644 --- a/include/follow.php +++ b/include/follow.php @@ -296,7 +296,7 @@ function new_contact($uid,$url,$interactive = false) { '$photo' => $a->contact['photo'], '$thumb' => $a->contact['thumb'], '$published' => datetime_convert('UTC','UTC', 'now', ATOM_TIME), - '$item_id' => 'urn:X-dfrn:' . $a->get_hostname() . ':follow:' . random_string(), + '$item_id' => 'urn:X-dfrn:' . $a->get_hostname() . ':follow:' . get_guid(32), '$title' => '', '$type' => 'text', '$content' => t('following'), diff --git a/include/items.php b/include/items.php index eaa056546..a2b2a0197 100644 --- a/include/items.php +++ b/include/items.php @@ -1210,7 +1210,8 @@ function item_store($arr,$force_parent = false, $notify = false, $dontcache = fa } $arr['wall'] = ((x($arr,'wall')) ? intval($arr['wall']) : 0); - $arr['uri'] = ((x($arr,'uri')) ? notags(trim($arr['uri'])) : random_string()); + $arr['guid'] = ((x($arr,'guid')) ? notags(trim($arr['guid'])) : get_guid(32, $arr['network'])); + $arr['uri'] = ((x($arr,'uri')) ? notags(trim($arr['uri'])) : $arr['guid']); $arr['extid'] = ((x($arr,'extid')) ? notags(trim($arr['extid'])) : ''); $arr['author-name'] = ((x($arr,'author-name')) ? notags(trim($arr['author-name'])) : ''); $arr['author-link'] = ((x($arr,'author-link')) ? notags(trim($arr['author-link'])) : ''); @@ -1248,7 +1249,6 @@ function item_store($arr,$force_parent = false, $notify = false, $dontcache = fa $arr['app'] = ((x($arr,'app')) ? notags(trim($arr['app'])) : ''); $arr['origin'] = ((x($arr,'origin')) ? intval($arr['origin']) : 0 ); $arr['network'] = ((x($arr,'network')) ? trim($arr['network']) : ''); - $arr['guid'] = ((x($arr,'guid')) ? notags(trim($arr['guid'])) : get_guid(32, $arr['network'])); $arr['postopts'] = ((x($arr,'postopts')) ? trim($arr['postopts']) : ''); $arr['resource-id'] = ((x($arr,'resource-id')) ? trim($arr['resource-id']) : ''); $arr['event-id'] = ((x($arr,'event-id')) ? intval($arr['event-id']) : 0 ); diff --git a/include/message.php b/include/message.php index ac1457172..0f4b53c62 100644 --- a/include/message.php +++ b/include/message.php @@ -26,6 +26,9 @@ function send_message($recipient=0, $body='', $subject='', $replyto=''){ return -2; } + $guid = get_guid(32); + $uri = 'urn:X-dfrn:' . $a->get_baseurl() . ':' . local_user() . ':' . $guid; + $convid = 0; $reply = false; @@ -42,19 +45,16 @@ function send_message($recipient=0, $body='', $subject='', $replyto=''){ $convid = $r[0]['convid']; } - $recip_host = substr($contact[0]['url'],strpos($contact[0]['url'],'://')+3); - $recip_host = substr($recip_host,0,strpos($recip_host,'/')); - - $recip_handle = (($contact[0]['addr']) ? $contact[0]['addr'] : $contact[0]['nick'] . '@' . $recip_host); - $sender_handle = $a->user['nickname'] . '@' . substr($a->get_baseurl(), strpos($a->get_baseurl(),'://') + 3); - - $msg_guid = get_guid(32); - $uri = $recip_handle.':'.$msg_guid; - if(! $convid) { // create a new conversation + $recip_host = substr($contact[0]['url'],strpos($contact[0]['url'],'://')+3); + $recip_host = substr($recip_host,0,strpos($recip_host,'/')); + + $recip_handle = (($contact[0]['addr']) ? $contact[0]['addr'] : $contact[0]['nick'] . '@' . $recip_host); + $sender_handle = $a->user['nickname'] . '@' . substr($a->get_baseurl(), strpos($a->get_baseurl(),'://') + 3); + $conv_guid = get_guid(32); $convuri = $recip_handle.':'.$conv_guid; @@ -92,7 +92,7 @@ function send_message($recipient=0, $body='', $subject='', $replyto=''){ `contact-id`, `title`, `body`, `seen`, `reply`, `replied`, `uri`, `parent-uri`, `created`) VALUES ( %d, '%s', %d, '%s', '%s', '%s', %d, '%s', '%s', %d, %d, %d, '%s', '%s', '%s' )", intval(local_user()), - dbesc($msg_guid), + dbesc($guid), intval($convid), dbesc($me[0]['name']), dbesc($me[0]['thumb']), @@ -172,8 +172,8 @@ function send_wallmessage($recipient='', $body='', $subject='', $replyto=''){ if(! strlen($subject)) $subject = t('[no subject]'); - $hash = random_string(); - $uri = 'urn:X-dfrn:' . $a->get_baseurl() . ':' . local_user() . ':' . $hash ; + $guid = get_guid(32); + $uri = 'urn:X-dfrn:' . $a->get_baseurl() . ':' . local_user() . ':' . $guid; $convid = 0; $reply = false; @@ -222,7 +222,7 @@ function send_wallmessage($recipient='', $body='', $subject='', $replyto=''){ `contact-id`, `title`, `body`, `seen`, `reply`, `replied`, `uri`, `parent-uri`, `created`, `unknown`) VALUES ( %d, '%s', %d, '%s', '%s', '%s', %d, '%s', '%s', %d, %d, %d, '%s', '%s', '%s', %d )", intval($recipient['uid']), - dbesc(get_guid(32)), + dbesc($guid), intval($convid), dbesc($me['name']), dbesc($me['photo']), diff --git a/mod/wall_attach.php b/mod/wall_attach.php index 80b679012..1e63a904c 100644 --- a/mod/wall_attach.php +++ b/mod/wall_attach.php @@ -98,7 +98,7 @@ function wall_attach_post(&$a) { $filedata = @file_get_contents($src); $mimetype = z_mime_content_type($filename); - $hash = random_string(); + $hash = get_guid(64); $created = datetime_convert(); $r = q("INSERT INTO `attach` ( `uid`, `hash`, `filename`, `filetype`, `filesize`, `data`, `created`, `edited`, `allow_cid`, `allow_gid`,`deny_cid`, `deny_gid` ) VALUES ( %d, '%s', '%s', '%s', %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s' ) ", @@ -114,7 +114,7 @@ function wall_attach_post(&$a) { dbesc(''), dbesc(''), dbesc('') - ); + ); @unlink($src);