-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathchangeset.php
More file actions
executable file
·767 lines (611 loc) · 21.8 KB
/
Copy pathchangeset.php
File metadata and controls
executable file
·767 lines (611 loc) · 21.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
<?php
require_once("config.php");
require_once("querymap.php");
require_once("osmtypes.php");
require_once("system.php");
function GetNewObjectId($type)
{
if(strcmp($type,"node")==0)
return ReadAndIncrementFileNum("nextnodeid.txt");
if(strcmp($type,"way")==0)
return ReadAndIncrementFileNum("nextwayid.txt");
if(strcmp($type,"relation")==0)
return ReadAndIncrementFileNum("nextrelationid.txt");
return null;
}
function ChangesetOpenBackend($userInfo,$putData)
{
$displayName = $userInfo['displayName'];
$userId = $userInfo['userId'];
$lock=GetWriteDatabaseLock();
$data = ParseOsmXmlChangeset($putData);
if(is_null($data)) return array(0,Null,"bad-input");
$cid = ReadAndIncrementFileNum("nextchangesetid.txt");
$data->attr['id'] = $cid;
if(CallFuncByMessage(Message::CHANGESET_IS_OPEN, $cid) !== -1)
return array(0,Null,"changeset-already-exists");
return array(1,array("Content-Type:text/plain"), CallFuncByMessage(Message::OPEN_CHANGESET,
array($cid,$data,$displayName,$userId,time())));
}
function ChangesetUpdateBackend($userInfo, $args)
{
$displayName = $userInfo['displayName'];
$userId = $userInfo['userId'];
list($urlExp, $putData) = $args;
$cid = (int)$urlExp[3];
$lock=GetWriteDatabaseLock();
$data = ParseOsmXmlChangeset($putData);
if(is_null($data)) return array(0,Null,"bad-input");
//Check user is correct
$xmlcid = $data->attr['id'];
$cUser = CallFuncByMessage(Message::GET_CHANGESET_UID, $cid);
if(is_null($cUser)) return array(0,Null,"not-found");
if($userId != $cUser) return array(0,Null,"user-mismatch",$userId,$cUser);
if($cid != $xmlcid) return array(0,Null,"conflict");
if(CallFuncByMessage(Message::CHANGESET_IS_OPEN, $cid)!=1)
return array(0,Null,"conflict");
$ret = CallFuncByMessage(Message::UPDATE_CHANGESET, array($cid,$data,$displayName,$userId));
return GetChangesetMetadataLowLevel($cid);
}
function ChangesetCloseBackend($userInfo,$argExp)
{
$displayName = $userInfo['displayName'];
$userId = $userInfo['userId'];
$cid = (int)$argExp[3];
$lock=GetWriteDatabaseLock();
//Validate user has rights
$cUser = CallFuncByMessage(Message::GET_CHANGESET_UID, $cid);
if(is_null($cUser)) return array(0,Null,"not-found");
if($userId != $cUser) return array(0,Null,"conflict");
if(CallFuncByMessage(Message::CHANGESET_IS_OPEN, $cid)!=1)
return array(0,Null,"already-closed", $cid);
//Do close
CallFuncByMessage(Message::CLOSE_CHANGESET, $cid);
return array(1,array("Content-Type:text/plain"),"");
}
//**************************************
//Process User Uploaded Map Data
//**************************************
//<osmChange version='0.6' generator='JOSM'><delete><way id='171' action='delete' timestamp='2010-10-14T08:41:57Z' uid='6809' user='TimSC' visible='true' version='1' changeset='209'/> <node id='681' action='delete' timestamp='2010-10-14T08:41:57Z' uid='6809' user='TimSC' visible='true' version='1' changeset='209' lat='51.26718186473299' lon='-0.5552857742301459'/></delete></osmChange>
function CheckChildrenExist(&$children, &$createdEls)
{
foreach($children as $child)
{
$childType = $child[0];
$id = $child[1];
if($id>0)
{
//Check the element exists (in a non deleted state)
$exists = CallFuncByMessage(Message::CHECK_ELEMENT_EXISTS,array($childType,$id));
if($exists!=true) return 0;
}
if($id<0 and !isset($createdEls[$childType.$id]))
{
echo $childType.$id;
return 0;
}
}
return 1;
}
function CheckElementInList(&$li, $type, $id)
{
return isset($li[$type.$id]);
}
function CheckCitationsIfDeleted($type, $el, &$deletedEls, &$recentlyChanged)
{
$id = $el->attr['id'];
$type = $el->GetType();
//Check ways would be ok
if(strcmp($type,"node")==0)
{
$citingWays = CallFuncByMessage(Message::GET_WAY_IDS_FOR_NODE,(int)$id);
//All citing ways must already be on the "to delete list"
foreach($citingWays as $wayId)
{
//If this object has appeared in this changeset, skip here
//and consider it separately
if(CheckElementInList($recentlyChanged,"way",$wayId)) continue;
//Ignore if this object have already been deleted
if(CheckElementInList($deletedEls,"way",$wayId)) continue;
//Found a way that would be broken if this node is deleted
return "deleting-would-break,".$id.",way,".$wayId;
}
//Check if it is used by a recently changed element
foreach($recentlyChanged as $el)
{
if(strcmp($el->GetType(),"way")!=0) continue;
$match = 0;
//Check if this node is used
foreach($el->members as $n)
{
if($n[0] == "node" and (int)$n[1]==(int)$id) {$match = $n[1];break;}
}
//Conflict found
if($match!=0) return "deleting-would-break,".$id.",way,".$match;
}
}
//Check relations would be ok
$citingRels = CallFuncByMessage(Message::GET_RELATIONS_FOR_ELEMENT,array($type,$id));
//All citing relations must already be on the "to delete list"
foreach($citingRels as $relId)
{
//If this object has appeared in this changeset, skip here
//and consider it separately
if(CheckElementInList($recentlyChanged,"relation",$relId)) continue;
//Ignore if this object have already been deleted
if(CheckElementInList($deletedEls,"relation",$relId)) continue;
//Found a relation that would be broken if this node is deleted
return "deleting-would-break,".$id.",way,".$relId;
}
//Check if it is used by a recently changed element
foreach($recentlyChanged as $el)
{
if(strcmp($el->GetType(),"relation")!=0) continue;
$match = 0;
//Check if this element is used
foreach($el->members as $n)
{
if($n[0] == $type and (int)$n[1]==(int)$id) {$match = $n[1];break;}
}
//Conflict found
if($match!=0) return "deleting-would-break,".$id.",relation,".$match;
}
return 1;
}
$requiredAttributes = array('id','changeset');
function ValidateOsmChange($osmchange,$cid,$displayName,$userId)
{
$createdEls = array();
$deletedEls = array();
$recentlyChanged = array();
//Check API version
$ver = $osmchange->version;
//if(strcmp($ver,"0.6")!=0) throw new Exception("OsmChange has wrong version"); //Merkaartor doesn't like that!
//For each action,
foreach($osmchange->data as $i => $data)
{
$action = $data[0];
$els = $data[1];
//Has at least one action?
//Actions have at least one element?
//Actions can only be create, modify, delete
if(!(strcmp($action,"create")==0 or strcmp($action,"modify")==0
or strcmp($action,"delete")==0))
throw new Exception("Action ".$action." not supported");
foreach($els as $i2 => $el)
{
$type = $el->GetType();
$id = $el->attr['id'];
$ver = null;
if(isset($el->attr['version'])) $ver = $el->attr['version'];
//Check the mandatory attributes are set
global $requiredAttributes;
foreach($requiredAttributes as $at)
{
if(!isset($el->attr[$at])) throw new Exception("Require attribute ".$at." not set");
}
//Check node has lat lon
if(strcmp($type,"node")==0)
{
if(!isset($el->attr['lat']) or !isset($el->attr['lon']))
throw new Exception("Require attribute not set");
}
//Action is create or version number is set
if(strcmp($action,"create")!=0 and !isset($el->attr['version']))
{
throw new Exception("Version number of element must be specified");
}
//Check if changeset is open
$cid = $el->attr['changeset'];
if(!CallFuncByMessage(Message::CHANGESET_IS_OPEN, $cid)) throw new Exception("Changeset is not open");
//Check if user has permission to add to this changeset
$ciduser = CallFuncByMessage(Message::GET_CHANGESET_UID, $cid);
if($ciduser != $userId)
throw new Exception("Changeset belongs to a different user ".$ciduser.", not ".$userId);
//Check we don't exceed number of max elements
$cidsize = CallFuncByMessage(Message::GET_CHANGESET_SIZE, $cid);
if(is_null($cidsize)) throw new Exception("Changeset size could not be determined ".$cid);
if($cidsize + 1 > MAX_CHANGESET_SIZE)
throw new Exception("Max changeset size exceeded");
//Check if method is consistent
//TODO work out what action really does?? JOSM specific?
if(isset($el->attr['action']))
{
$objaction = $el->attr['action'];
//if(strcmp($action,$objaction)!=0)
// throw new Exception("Action specified in object not consistent ".$action." vs. ".$objaction);
}
//Visibile attribute seems to be a "rails port" specific tag
/*$visible = $el->attr['visible'];
if(!(strcmp($visible,"true")==0 or strcmp($visible,"false")==0))
throw new Exception("Visible attribute must be true or false");
if(strcmp($action,"create")==0 or strcmp($action,"modify")==0)
if(strcmp($visible,"false")==0) throw new Exception("Visiblity must be true for create or modify");
*/
//if(strcmp($action,"delete")==0)
// if(strcmp($visible,"true")==0) throw new Exception("Visiblity must be false for delete");
//Object id zero not allowed?
if($id == 0) throw new Exception("Object ID zero not allowed");
//Object versions
if($id >= 0)
{
$currentVer = CallFuncByMessage(Message::GET_CURRENT_ELEMENT_VER,array($type,$id));
if($currentVer===-1)
return array(0,null,"not-found",$type,$id);
if($currentVer===-2)
return array(0,null,"gone",$type,$id);
if($ver != $currentVer and VERSION_VALIDATION)
{
return array(0,null,"version-mismatch",(int)$ver,$currentVer,$type,$id);
}
}
//Store created objects
if(strcmp($action,"create")==0)
{
$createdEls[$type.$id] = 1;
$recentlyChanged[$type.$id] = $el;
//Created objects must have a negative ID
if($id >= 0) throw new Exception("Created objects must have negative ID");
}
if(strcmp($action,"modify")==0)
$recentlyChanged[$type.$id] = $el;
//Store deleted objects
if(strcmp($action,"delete")==0)
$deletedEls[$type.$id] = 1;
//Check if referenced elements actual exist
$ret = CheckChildrenExist($el->members, $createdEls);
if($ret==0) return array(0,null,"object-not-found",$type,$id);
//Check if deleting stuff will break ways
if(strcmp($action,"delete")==0)
{
$ret = CheckCitationsIfDeleted($type, $el, $deletedEls, $recentlyChanged);
if($ret!=1) return $ret;
}
//Check if deleting stuff will break relations
//Enforce max nodes in way and relations, etc
if (count($el->members)>MAX_WAY_NODES)
return array(0,null,"too-large");
}
}
return 1;
}
function AssignIdsToOsmChange(&$osmchange,$displayName,$userId)
{
$idmapping = array();
$changes = array();
foreach($osmchange->data as $i => &$eldata)
{
$action = $eldata[0];
$els = &$eldata[1];
//Set timestamp of object
foreach($els as $i2 => $el)
{
$el->attr['timestamp'] = date('c'); //Set timestamp at creation
//Visibility is a database model specific concept and doesn't belong here
//if(strcmp($action,"delete")==0) $el->attr['visible'] ="false";
//else $el->attr['visible'] ="true";
}
//Set username and UID for any changed elements
foreach($els as $i2 => $el)
{
$el->attr['user']=(string)$displayName;
$el->attr['uid']=(int)$userId;
unset($el->attr['action']);
}
//Process create actions
if(strcmp($action,"create")==0)
{
foreach($els as $i2 => $el)
{
$type = $el->GetType();
//Initialise version
$el->attr['version'] = 1;
$newver = $el->attr['version'];
$el->attr['visibility'] = "true";
//Initilise element ID
$oldid = (int)$el->attr['id'];
if($oldid >= 0) throw new Exception("Created element has non-negative ID ".$oldid);
$newid = GetNewObjectId($type);
$el->attr['id'] = $newid;
$idmapping[$type.",".$oldid] = array($newid,$el->attr['version']);
//Store changes to return to editor
array_push($changes,array($type,$oldid,$newid,$newver,$newver));
}
}
//Process modify actions
if(strcmp($action,"modify")==0)
{
foreach($els as $i2 => $el)
{
$type = $el->GetType();
$oldid = (int)$el->attr['id'];
$newid = $oldid;
//Increment version
$oldver = $el->attr['version'];
$el->attr['version'] = $el->attr['version'] + 1;
$newver = $el->attr['version'];
$el->attr['visibility'] = "true";
//Store changes to return to editor
array_push($changes,array($type,$oldid,$newid,$newver,$newver));
}
}
//Process delete actions
if(strcmp($action,"delete")==0)
{
foreach($els as $i2 => $el)
{
$type = $el->GetType();
$oldid = (int)$el->attr['id'];
//Increment version
$oldver = $el->attr['version'];
$el->attr['version'] = $el->attr['version'] + 1;
$newver = $el->attr['version'];
$el->attr['visibility'] = "false";
//Store changes to return to editor
array_push($changes,array($type,$oldid,null,null,$newver));
}
}
//Renumber members, for each element
foreach($els as $i2 => $el)
{
//Renumber child members
foreach($el->members as $i3 => $nd)
{
$oldid = $nd[1];
if($oldid >= 0) continue;
$type = $nd[0];
if(!isset($idmapping[$type.",".$oldid]))
throw new Exception("ID not found in mapping ".$type.",".$oldid);
$newid = $idmapping[$type.",".$oldid][0];
$el->members[$i3][1] = $newid;
}
}
}
return $changes;
}
function GetBboxOfReferencedElements($osmchange)
{
//For each element
$bbox= null;
foreach($osmchange->data as $data)
{
list($method, $els) = $data;
//if(strcmp($method,"create")==0)
foreach($els as $el)
{
//echo $method." ".$el->GetType()." ".$el->attr['id']."\n";
$elBbox = CallFuncByMessage(Message::GET_ELEMENT_BBOX,array($el->GetType(),(int)$el->attr['id']));
//print_r($elBbox);
UpdateBbox($bbox, $elBbox);
}
}
return $bbox;
}
function ExpandChangesetBbox($cid,$bbox)
{
if(!is_array($bbox)) return 0;
if($cid === Null) throw new Exception("Null changeset id");
//print_r($bbox);
CallFuncByMessage(Message::EXPAND_BBOX, array($cid,$bbox));
return 1;
}
function ApplyChangeToDatabase(&$osmchange)
{
//For each element
foreach($osmchange->data as $data)
{
list($method, $els) = $data;
if(strcmp($method,"create")==0)
foreach($els as $el)
{
$type = $el->GetType();
$el->attr['visible'] = "true";
//Create in main db
CallFuncByMessage(Message::CREATE_ELEMENT,array($type,$el->attr['id'],$el));
//Also store in changeset
CallFuncByMessage(Message::CHANGESET_APPEND_ELEMENT,array($el->attr['changeset'], $method, $el));
}
if(strcmp($method,"modify")==0)
foreach($els as $el)
{
$type = $el->GetType();
$el->attr['visible'] = "true";
//Modify element in main db
CallFuncByMessage(Message::MODIFY_ELEMENT,array($type,$el->attr['id'],$el));
//Also store in changeset
CallFuncByMessage(Message::CHANGESET_APPEND_ELEMENT,array($el->attr['changeset'], $method, $el));
}
if(strcmp($method,"delete")==0)
foreach($els as $el)
{
$type = $el->GetType();
$value = simplexml_load_string($el->ToXmlString());
$el->attr['visible'] = "false";
//Delete object in main db
CallFuncByMessage(Message::DELETE_ELEMENT,array($type,$el->attr['id'],$el));
//Also store in changeset
CallFuncByMessage(Message::CHANGESET_APPEND_ELEMENT,array($el->attr['changeset'], $method, $el));
}
}
}
function ProcessOsmChange($cid,$osmchange,$displayName,$userId)
{
//Lock the database for writing
$lock=GetWriteDatabaseLock();
//Load database
//Validate change
try
{
$valret = ValidateOsmChange($osmchange,$cid,$displayName,$userId);
if($valret != 1)
return $valret;
}
catch (Exception $e)
{
return array(0,null,"bad-request",$e);
}
//Assign IDs to created objects
$changes = AssignIdsToOsmChange($osmchange,$displayName,$userId);
//Bbox for elements before change is applied
//TODO relations should be handled differently
$bbox = GetBboxOfReferencedElements($osmchange);
ExpandChangesetBbox($cid,$bbox);
//Apply changes to database
ApplyChangeToDatabase($osmchange);
//Bbox for elements after change is applied
$bbox = GetBboxOfReferencedElements($osmchange);
if($cid !== Null) //A Null cid can be used for importing data
ExpandChangesetBbox($cid,$bbox);
return array(1,$changes);
}
function ProcessSingleObjectBackend($userInfo, $args)
{
list($urlExp,$data,$method) = $args;
$displayName = $userInfo['displayName'];
$userId = $userInfo['userId'];
//$cid = 204;
//$data = "<osm version='0.6' generator='JOSM'> <node id='-7801' visible='true' changeset='220' lat='51.26493956255727' lon='-0.5636603245748466' /></osm>";
//Construct an OsmChange from the single object
$osmchange = new OsmChange();
$osmchange->version = 0.6;
$singleObj = SingleObjectFromXml($data);
array_push($osmchange->data,array($method,array($singleObj)));
$cid = null;
//Process OsmChange
$ret = ProcessOsmChange($cid,$osmchange,$displayName,$userId);
if($ret[0]===0) return $ret;
$changes = $ret[1];
//Return version or new ID as appropriate
$newobjid = $changes[0][2];
$newversion = $changes[0][4];
if(strcmp($method,"create")==0)
return array(1,array("Content-Type:text/plain"),$newobjid);
return array(1,array("Content-Type:text/xml"),$newversion);
}
function ChangesetUploadBackend($userInfo, $args)
{
$displayName = $userInfo['displayName'];
$userId = $userInfo['userId'];
$cid = (int)$args[0][3];
$putDataStr = $args[1];
// $cid=204;
// $data="<osmChange version=\"0.6\" generator=\"PythonTest\">\n<modify>\n<way id='595' action='modify' timestamp='2009-03-01T14:21:58Z' uid='6809' user='TimSC' visible='true' version='1' changeset='204' lat='51.285184946434256' lon='-0.5986675534296598'><tag k='name' v='Belvidere'/><nd ref='555'/></way>\n</modify>\n</osmChange>\n";
//$data="<osmChange version='0.6' generator='JOSM'><delete><way id='171' action='delete' timestamp='2010-10-14T08:41:57Z' uid='6809' user='TimSC' visible='true' version='1' changeset='209'/> <node id='681' action='delete' timestamp='2010-10-14T08:41:57Z' uid='6809' user='TimSC' visible='true' version='1' changeset='209' lat='51.26718186473299' lon='-0.5552857742301459'/></delete></osmChange>";
//Convert XML upload to native data
$osmchange = new OsmChange();
$osmchange->FromXmlString($putDataStr);
//Process OsmChange
$ret = ProcessOsmChange($cid,$osmchange,$displayName,$userId);
if($ret[0]===0) return $ret;
$changes = $ret[1];
//echo gettype($changes);
if(is_array($changes))
{
//Return difference info
$diff = '<diffResult generator="'.SERVER_NAME.'" version="0.6">'."\n";
foreach($changes as $ch)
{
list($type,$oldid,$newid,$newvertoeditor,$newver) = $ch;
$diff = $diff.' <'.$type.' old_id="'.$oldid.'"';
if(!is_null($newid)) $diff = $diff.' new_id="'.$newid.'"';
if(!is_null($newvertoeditor)) $diff = $diff.' new_version="'.$newvertoeditor.'"';
$diff = $diff."/>\n";
}
$diff = $diff."</diffResult>\n";
return array(1,array("Content-Type:text/xml"),$diff);
}
return array(0,Null,$changes);
}
function ChangesetExpandBboxBackend($userInfo, $args)
{
$displayName = $userInfo['displayName'];
$userId = $userInfo['userId'];
$cid = (int)$args[0][3];
$putDataStr = $args[1];
//Open database
$lock = GetWriteDatabaseLock();
//Validate
if($userId != CallFuncByMessage(Message::GET_CHANGESET_UID, $cid))
return array(0,null,"forbidden");
$xml = ParseOsmXml($putDataStr);
//Expand Bbox
$bbox = null;
foreach($xml as $el)
{
if($el->GetType() != "node") continue; //Ignore everything but nodes
UpdateBbox($bbox,array($el->attr['lon'],$el->attr['lat'],
$el->attr['lon'],$el->attr['lat']));
}
if(is_array($bbox)) CallFuncByMessage(Message::EXPAND_BBOX, array($cid,$bbox));
//Return changeset
return GetChangesetMetadataLowLevel($cid);
}
function GetChangesets($userInfo,$query)
{
$lock=GetReadDatabaseLock();
$user = null;
if(isset($query['user'])) $user = (int)$query['user'];
$open = null;
if(isset($query['open'])) $open = (strcmp($query['open'],"true")==0);
$timerange = null; //TODO implement this and other arguments
$csids = CallFuncByMessage(Message::CHANGESET_QUERY, array($user,$open,$timerange));
$out = '<?xml version="1.0" encoding="UTF-8"?>'."\n";
$out = $out.'<osm version="0.6" generator="'.SERVER_NAME.'">'."\n";
foreach($csids as $cid)
{
if(isset($query['user']) and $query['user'] != CallFuncByMessage(Message::GET_CHANGESET_UID, $cid)) continue;
#$out = $out.ChangesetToXml($cid);
$out = $out.CallFuncByMessage(Message::GET_CHANGESET_METADATA, $cid)->ToXmlString();
}
$out = $out.'</osm>'."\n";
return array(1,array("Content-Type:text/xml"),$out);
}
function GetChangesetMetadataLowLevel($cid)
{
$data = CallFuncByMessage(Message::GET_CHANGESET_METADATA, $cid);
if(is_null($data)) return array(0,Null,"not-found");
return array(1,array("Content-Type:text/xml"),
'<osm version="0.6" generator="'.SERVER_NAME.'">'.$data->ToXmlString().'</osm>');
}
function GetChangesetMetadata($userInfo, $urlExp)
{
$cid = (int)$urlExp[3];
$lock=GetReadDatabaseLock();
return GetChangesetMetadataLowLevel($cid);
}
function GetChangesetUid($cid)
{
$lock=GetReadDatabaseLock();
return CallFuncByMessage(Message::GET_CHANGESET_UID, $cid);
}
function GetChangesetContentsBackend($userInfo, $urlExp) //Download changeset URL
{
$cid = (int)$urlExp[3];
$lock=GetReadDatabaseLock();
$changeset = CallFuncByMessage(Message::GET_CHANGESET_CONTENT, $cid);
if(is_null($changeset)) return array(0,Null,"not-found");
return array(1,array("Content-Type:text/xml"),$changeset->ToXmlString());
}
function GetChangesetClosedTime($cid)
{
$lock=GetReadDatabaseLock();
return CallFuncByMessage(Message::GET_CHANGESET_CLOSE_TIME, $cid);
}
function ChangesetEventHandler($eventType, $content, $listenVars)
{
if($eventType == Message::API_CHANGESET_OPEN)
return ChangesetOpenBackend($content[0], $content[1]);
if($eventType == Message::API_CHANGESET_UPDATE)
return ChangesetUpdateBackend($content[0], $content[1]);
if($eventType == Message::API_CHANGESET_CLOSE)
return ChangesetCloseBackend($content[0], $content[1]);
if($eventType == Message::API_CHANGESET_UPLOAD)
return ChangesetUploadBackend($content[0], $content[1]);
if($eventType == Message::API_GET_CHANGESET_CONTENTS)
return GetChangesetContentsBackend($content[0], $content[1]);
if($eventType == Message::API_PROCESS_SINGLE_OBJECT)
return ProcessSingleObjectBackend($content[0], $content[1]);
if($eventType == Message::API_CHANGESET_EXPAND)
return ChangesetExpandBboxBackend($content[0], $content[1]);
}
?>