viewgit/index.php:465 Only variables should be passed by reference [2048]

viewgit/index.php:466 Non-static method GeSHi::get_language_name_from_extension() should not be called statically [2048]

  1.  
  2. using System;
  3. using System.Collections;
  4. using System.Threading;
  5. using System.Text.RegularExpressions;
  6. using System.IO;
  7. using Tamir.SharpSsh;
  8. using Dizzy;
  9.  
  10. namespace Dizzy
  11. {
  12.  
  13.  
  14. public class ProtocolException : ApplicationException
  15. {
  16. public ProtocolException () {}
  17. public ProtocolException (string Message) {}
  18. }
  19.  
  20. public class Protocol
  21. {
  22.  
  23. // I dati del nostro povero utente.
  24. string user, password;
  25.  
  26. // I transfer attivi
  27. ArrayList transfers = new ArrayList ();
  28.  
  29. public delegate void Del (string src, string dest,
  30. int transferredBytes, int totalBytes, string message);
  31.  
  32.  
  33. ArrayList threads = new ArrayList ();
  34.  
  35. Thread finder;
  36. SFTPConnection sftpUpdater;
  37.  
  38. public Protocol (ref GlobalConfig config)
  39. {
  40. this.user = config.GetValue("user");
  41. this.password = config.password;
  42.  
  43. try
  44. {
  45. this.sftpUpdater = new SFTPConnection(this.user, this.password);
  46. this.sftpUpdater.Connect ();
  47. }
  48. catch(Exception e)
  49. {
  50. throw new ProtocolException("Impossibile connettersi a poisson.phc.unipi.it %% " + e.Message);
  51. }
  52.  
  53.  
  54. }
  55.  
  56. public void Search(string keyword, ref FileTreeView f)
  57. {
  58. if(this.finder != null && this.finder.IsAlive)
  59. {
  60. Console.WriteLine("Ricerca in corso, tento di interromperla.");
  61. this.finder.Abort ();
  62. }
  63.  
  64. FileSearch fs = new FileSearch (this.user, this.password, keyword, ref f);
  65. this.finder = new Thread (new ThreadStart (fs.DoSearch));
  66. this.finder.Start ();
  67. }
  68.  
  69.  
  70. public void Disconnect ()
  71. {
  72. foreach(FileTransfer t in this.transfers)
  73. {
  74. t.Stop ();
  75. }
  76. foreach(Thread t in this.threads)
  77. {
  78. if(t.IsAlive)
  79. t.Abort ();
  80. }
  81.  
  82. if (this.finder.IsAlive)
  83. {
  84. this.finder.Abort ();
  85. }
  86. }
  87.  
  88.  
  89. public void Download(File f, ref TaskTreeView tasks, string downloadFolder)
  90. {
  91. // Preparo gli argomento da passare alla funzione.
  92. ArrayList args = new ArrayList ();
  93. args.Add (f);
  94. args.Add (tasks);
  95. args.Add (downloadFolder);
  96. Thread t = new Thread (new ParameterizedThreadStart(_Download));
  97. t.Start (args);
  98. this.threads.Add (t);
  99. }
  100.  
  101. protected void _Download(object args)
  102. {
  103. // Questi cast sono piuttosto brutali ma posso passare
  104. // solo un oggetto a Download e quindi è il meglio che
  105. // mi riesce di fare.
  106. File f = (File) ((ArrayList) args)[0];
  107. TaskTreeView tasks = (TaskTreeView) ((ArrayList) args)[1];
  108. string downloadFolder = (string) ((ArrayList) args)[2];
  109. Console.WriteLine (" => Download starting");
  110. FileTransfer transfer = new FileTransfer (f, ref tasks, this.user, this.password, downloadFolder);
  111. this.transfers.Add (transfer);
  112. }
  113.  
  114. }
  115.  
  116. public class SFTPConnection
  117. {
  118.  
  119. public Sftp sftp;
  120. public delegate void SFTPEvent (string src, string dest, int transferredBytes,
  121. int totalBytes, string message);
  122.  
  123. public event SFTPEvent TransferStarted;
  124. public event SFTPEvent TransferProgress;
  125. public event SFTPEvent TransferStopped;
  126.  
  127. public delegate void Del (string src, string dest,
  128. int transferredBytes, int totalBytes, string message);
  129.  
  130. public SFTPConnection (string user, string password)
  131. {
  132.  
  133. // Inizializziamo il protocollo
  134. this.sftp = new Sftp ("poisson.phc.unipi.it", user);
  135. this.sftp.Password = password;
  136.  
  137. this.sftp.OnTransferStart += new FileTransferEvent(this.TransferStartedHandler);
  138. this.sftp.OnTransferProgress += new FileTransferEvent(this.TransferProgressHandler);
  139. this.sftp.OnTransferEnd += new FileTransferEvent(this.TransferStoppedHandler);
  140.  
  141. }
  142.  
  143. private void TransferStartedHandler(string src, string dest, int transferredBytes,
  144. int totalBytes, string message)
  145. {
  146. Console.WriteLine (" => TransferStarted");
  147. TransferStarted(src, dest, transferredBytes, totalBytes, message);
  148. }
  149.  
  150. private void TransferProgressHandler(string src, string dest, int transferredBytes,
  151. int totalBytes, string message)
  152. {
  153. TransferProgress(src, dest, transferredBytes, totalBytes, message);
  154. }
  155.  
  156. private void TransferStoppedHandler(string src, string dest, int transferredBytes,
  157. int totalBytes, string message)
  158. {
  159. TransferStopped(src, dest, transferredBytes, totalBytes, message);
  160. }
  161.  
  162. public void Connect()
  163. {
  164. sftp.Connect (22);
  165. }
  166.  
  167. public ArrayList SearchFiles()
  168. {
  169. ArrayList matches = new ArrayList ();
  170. Console.WriteLine(" => Scan della nobackup");
  171. // ArrayList users = sftp.GetFileList ("/nobackup/");
  172. ArrayList users = new ArrayList();
  173. users.Add("robol");
  174. users.Add("bianchi");
  175. foreach(string folder in users)
  176. {
  177. if (folder == ".")
  178. continue;
  179. else if (folder == "..")
  180. continue;
  181. Console.WriteLine(" => Scan di {0}", folder);
  182. try { matches.AddRange (GetFolderContent(folder)); }
  183. catch(Exception e) { Console.WriteLine (e.Message); }
  184. }
  185. Console.WriteLine(" => Scan terminato");
  186. return matches;
  187. }
  188.  
  189. protected ArrayList GetFolderContent(string folder)
  190. {
  191. ArrayList matches, files;
  192. File f;
  193. string user;
  194. files = sftp.GetFileList("/nobackup/" + folder + "/");
  195. matches = new ArrayList ();
  196. foreach(string entry in files)
  197. {
  198. // Controllo che non sia una cartella. Evidentemente
  199. // questo metodo non è affidabile, ma per ora è il meglio
  200. // che SFTP ci permetta di fare.
  201. if(entry.IndexOf(".") == -1)
  202. matches.AddRange(GetFolderContent(folder + "/" + entry));
  203. else if(!entry.StartsWith("."))
  204. {
  205. user = folder;
  206. if(user.Contains("/"))
  207. user = user.Substring(0, user.IndexOf("/"));
  208. f = new File("/nobackup/" + folder + "/" + entry, user );
  209. matches.Add(f);
  210. }
  211. }
  212. return matches;
  213. }
  214.  
  215. public void Download(File f, string downloadFolder)
  216. {
  217. Console.WriteLine (" => Getting {0}", f.name);
  218. // try
  219. // {
  220. Console.WriteLine (f.path);
  221. this.sftp.Get (f.path, downloadFolder + Path.DirectorySeparatorChar + f.name);
  222. // }
  223. /* catch()
  224. {
  225. Console.WriteLine("Error in Get... ");
  226. Console.WriteLine(e.Message);
  227. } */
  228. }
  229.  
  230. public void Disconnect ()
  231. {
  232. sftp.Close ();
  233. }
  234. }
  235.  
  236. public class FileTransfer
  237. {
  238.  
  239. TaskTreeView tasks;
  240. File file;
  241. Gtk.TreeIter iter;
  242.  
  243. SFTPConnection sftp;
  244.  
  245. public delegate void Handler(string src, string dest, int transferredBytes,
  246. int totalBytes, string message);
  247.  
  248. public FileTransfer (File f, ref TaskTreeView tasks, string user, string password, string downloadFolder)
  249. {
  250. // Connessione al server
  251. this.sftp = new SFTPConnection (user, password);
  252. this.sftp.Connect ();
  253.  
  254. this.tasks = tasks;
  255. this.file = f;
  256.  
  257. sftp.TransferStarted += new SFTPConnection.SFTPEvent(OnTransferStarted);
  258. sftp.TransferProgress += new SFTPConnection.SFTPEvent(OnTransferProgress);
  259. sftp.TransferStopped += new SFTPConnection.SFTPEvent(OnTransferStopped);
  260.  
  261. Console.WriteLine(" => Starting sftp command");
  262. sftp.Download (this.file, downloadFolder);
  263. sftp.Disconnect ();
  264. }
  265.  
  266. public void Stop ()
  267. {
  268. this.sftp.Disconnect ();
  269. }
  270.  
  271. public void OnTransferStarted (string src, string dest, int transferredBytes,
  272. int totalBytes, string message)
  273. {
  274. Console.WriteLine(" => TransferStarted received");
  275. this.iter = this.tasks.AddTask(file.name, 0);
  276. }
  277.  
  278. public void OnTransferProgress(string src, string dest, int transferredBytes,
  279. int totalBytes, string message)
  280. {
  281. // if(message != "")
  282. // Console.WriteLine(message);
  283. int perc = transferredBytes / (totalBytes / 100);
  284. this.tasks.SetProgress(this.iter, perc);
  285. }
  286.  
  287. public void OnTransferStopped (string src, string dest, int transferredBytes,
  288. int totalBytes, string message)
  289. {
  290. this.tasks.DeleteRow (this.iter);
  291. }
  292. }
  293.  
  294.  
  295. class FileSearch
  296. {
  297. SshExec sshexec;
  298. string username, password, keywords;
  299. FileTreeView f;
  300.  
  301. public FileSearch (string username, string password, string keywords, ref FileTreeView f)
  302. {
  303. this.username = username;
  304. this.password = password;
  305. this.keywords = keywords;
  306. this.f = f;
  307. }
  308.  
  309. public void DoSearch ()
  310. {
  311. sshexec = new SshExec("poisson.phc.unipi.it", this.username, this.password);
  312. sshexec.Connect ();
  313.  
  314. string command = "locate -i -e --regex /nobackup/.+" + this.keywords;
  315. string output = sshexec.RunCommand (command);
  316. f.Clear ();
  317. foreach(string line in Regex.Split(output, "\n"))
  318. {
  319. if (line.StartsWith("/nobackup/") && Regex.Match(line,".*[.].*").Success)
  320. this.f.AddFile (new File(line, ""));
  321. }
  322. sshexec.Close ();
  323. }
  324.  
  325. }
  326.  
  327. }