@@ -52,8 +52,7 @@ extern char **uxDropFileNames;
5252extern SQFile * fileValueOf (sqInt objectPointer );
5353#else
5454/* Return a pointer to the first byte of of the SQFile data structure file
55- record within
56- anSQFileRecord, which is expected to be a ByteArray of size
55+ record within anSQFileRecord, which is expected to be a ByteArray of size
5756 self>>fileRecordSize.
5857 */
5958
@@ -68,17 +67,53 @@ fileValueOf(sqInt anSQFileRecord)
6867sqInt dropInit (void ) { return 1 ; }
6968sqInt dropShutdown (void ) { return 1 ; }
7069
71- char * dropRequestFileName (sqInt dropIndex ) // in st coordinates
70+ /* We now set USE_FILE_URIs to 1 in platforms/unix//vm-display-X11/sqUnixXdnd.c
71+ * hence dropRequestFileName skips the URI prefix and dropRequestURI includes it
72+ */
73+ char *
74+ dropRequestFileName (sqInt dropIndex ) // in st coordinates
7275{
73- if ((dropIndex > 0 ) && (dropIndex <= uxDropFileCount )) {
74- assert (uxDropFileNames );
75- dndReceived (uxDropFileNames [dropIndex - 1 ]);
76- return uxDropFileNames [dropIndex - 1 ];
77- }
78- return 0 ;
76+ char * fileURIPrefix = "file:///" ;
77+ int prefixLength = 0 ;
78+ char * dropFileName ;
79+
80+ if (dropIndex <= 0 || dropIndex > uxDropFileCount )
81+ return 0 ;
82+
83+ assert (uxDropFileNames );
84+ dndReceived (uxDropFileNames [dropIndex - 1 ]);
85+
86+ // The three valid schemes are
87+ // file://host/path (prefix length 7)
88+ // file:///path (prefix length 8)
89+ // file:/path (prefix length 6)
90+ // see https://en.wikipedia.org/wiki/File_URI_scheme
91+
92+ // Compute the length of the prefix...
93+ if (!(dropFileName = uxDropFileNames [dropIndex - 1 ]))
94+ return 0 ;
95+ while (* fileURIPrefix && * fileURIPrefix ++ == * dropFileName ++ )
96+ ++ prefixLength ;
97+
98+ // file:///path & file:/path => path; anything else answered verbatim
99+ return prefixLength == 8 || prefixLength == 6
100+ ? uxDropFileNames [dropIndex - 1 ] + fileURILength
101+ : uxDropFileNames [dropIndex - 1 ];
79102}
80103
81- sqInt dropRequestFileHandle (sqInt dropIndex )
104+ char *
105+ dropRequestURI (sqInt dropIndex ) // in st coordinates
106+ {
107+ if (dropIndex <= 0 || dropIndex > uxDropFileCount )
108+ return 0 ;
109+
110+ assert (uxDropFileNames );
111+ dndReceived (uxDropFileNames [dropIndex - 1 ]);
112+ return uxDropFileNames [dropIndex - 1 ];
113+ }
114+
115+ sqInt
116+ dropRequestFileHandle (sqInt dropIndex )
82117{
83118 char * path = dropRequestFileName (dropIndex );
84119 if (path ) {
@@ -89,7 +124,3 @@ sqInt dropRequestFileHandle(sqInt dropIndex)
89124 }
90125 return interpreterProxy -> nilObject ();
91126}
92-
93- sqInt sqSecFileAccessCallback (void * callback ) { return 0 ; }
94- void sqSetNumberOfDropFiles (sqInt numberOfFiles ) { }
95- void sqSetFileInformation (sqInt dropIndex , void * dropFile ) { }
0 commit comments