mirror of
https://github.com/arduino/Arduino.git
synced 2025-03-21 12:29:23 +01:00
httpuploader now uses new lua uploader
https disabled due to some strange bug with uhttpd
This commit is contained in:
parent
765a975414
commit
c174737584
@ -1677,7 +1677,7 @@ public class Sketch {
|
||||
return false;
|
||||
}
|
||||
|
||||
Preferences.set(uploader.getAuthorizationKey(), DigestUtils.sha512Hex(dialog.getPassword()));
|
||||
Preferences.set(uploader.getAuthorizationKey(), DigestUtils.sha256Hex(dialog.getPassword()));
|
||||
}
|
||||
|
||||
success = uploader.uploadUsingPreferences(buildPath, suggestedClassName, usingProgrammer);
|
||||
|
@ -1,32 +1,32 @@
|
||||
package processing.app.debug;
|
||||
|
||||
import org.apache.commons.codec.binary.Base64;
|
||||
import org.apache.commons.httpclient.HttpClient;
|
||||
import org.apache.commons.httpclient.HttpStatus;
|
||||
import org.apache.commons.httpclient.NameValuePair;
|
||||
import org.apache.commons.httpclient.methods.GetMethod;
|
||||
import org.apache.commons.httpclient.methods.PostMethod;
|
||||
import org.apache.commons.httpclient.methods.multipart.FilePart;
|
||||
import org.apache.commons.httpclient.methods.multipart.MultipartRequestEntity;
|
||||
import org.apache.commons.httpclient.methods.multipart.Part;
|
||||
import org.apache.commons.httpclient.methods.multipart.StringPart;
|
||||
import org.apache.commons.httpclient.protocol.Protocol;
|
||||
import processing.app.Base;
|
||||
import processing.app.Preferences;
|
||||
import processing.app.SerialException;
|
||||
import processing.app.helpers.PreferencesMap;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.*;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.Socket;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class HttpUploader extends Uploader {
|
||||
|
||||
private static final Pattern IPV4_ADDRESS = Pattern.compile("(\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3})");
|
||||
private static final String PROTOCOL = "http://";
|
||||
|
||||
/*
|
||||
static {
|
||||
Protocol.registerProtocol("https", new Protocol("https", new EasySSLProtocolSocketFactory(), 443));
|
||||
}
|
||||
*/
|
||||
|
||||
private final HttpClient client;
|
||||
private final String ipAddress;
|
||||
@ -39,7 +39,7 @@ public class HttpUploader extends Uploader {
|
||||
throw new IllegalArgumentException(port);
|
||||
}
|
||||
this.ipAddress = matcher.group(1);
|
||||
this.baseUrl = "https://" + ipAddress;
|
||||
this.baseUrl = PROTOCOL + ipAddress + "/cgi-bin/luci/arduino";
|
||||
}
|
||||
|
||||
public boolean requiresAuthorization() {
|
||||
@ -58,9 +58,10 @@ public class HttpUploader extends Uploader {
|
||||
}
|
||||
|
||||
this.client.getHttpConnectionManager().getParams().setConnectionTimeout(5000);
|
||||
String auth = Base64.encodeBase64String(("root:" + Preferences.get(getAuthorizationKey())).getBytes());
|
||||
|
||||
int sleptTimes = 1;
|
||||
while (boardNotReady()) {
|
||||
while (boardNotReady(auth)) {
|
||||
try {
|
||||
Thread.sleep(100);
|
||||
} catch (InterruptedException e) {
|
||||
@ -72,11 +73,36 @@ public class HttpUploader extends Uploader {
|
||||
sleptTimes += 1;
|
||||
}
|
||||
|
||||
FilePart sketch;
|
||||
StringBuilder uploadRequest = new StringBuilder();
|
||||
|
||||
uploadRequest.append(String.format("PWD%1$04d", Preferences.get(getAuthorizationKey()).length())).append(Preferences.get(getAuthorizationKey())).append("\n");
|
||||
uploadRequest.append("SKETCH\n");
|
||||
readSketchFile(buildPath, className, uploadRequest);
|
||||
uploadRequest.append("SKETCH_END\n");
|
||||
uploadRequest.append("EOF\n");
|
||||
|
||||
Socket socket = null;
|
||||
try {
|
||||
sketch = new FilePart("sketch", new File(buildPath, className + ".hex"));
|
||||
} catch (FileNotFoundException e) {
|
||||
socket = new Socket();
|
||||
socket.connect(new InetSocketAddress(ipAddress, 9876), 5000);
|
||||
OutputStreamWriter osw = new OutputStreamWriter(socket.getOutputStream());
|
||||
osw.write(uploadRequest.toString());
|
||||
osw.flush();
|
||||
BufferedReader isr = new BufferedReader(new InputStreamReader(socket.getInputStream()));
|
||||
String ok = isr.readLine();
|
||||
if (!"OK".equals(ok)) {
|
||||
throw new RunnerException("Problem uploading sketch");
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new RunnerException(e);
|
||||
} finally {
|
||||
if (socket != null) {
|
||||
try {
|
||||
socket.close();
|
||||
} catch (IOException e) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TargetPlatform targetPlatform = Base.getTargetPlatform();
|
||||
@ -85,12 +111,12 @@ public class HttpUploader extends Uploader {
|
||||
prefs.putAll(targetPlatform.getTool(prefs.get("upload.tool")));
|
||||
boolean verbose = prefs.containsKey("upload.verbose") && Boolean.parseBoolean(prefs.get("upload.verbose"));
|
||||
|
||||
StringPart params = new StringPart("params", verbose ? prefs.get("upload.params.verbose") : prefs.get("upload.params.quiet"));
|
||||
|
||||
Part[] parts = {sketch, params};
|
||||
PostMethod post = newPostMethod();
|
||||
post.setRequestHeader("Cookie", "pwd=" + Preferences.get(getAuthorizationKey()));
|
||||
post.setRequestEntity(new MultipartRequestEntity(parts, post.getParams()));
|
||||
PostMethod post = new PostMethod(baseUrl + "/flash");
|
||||
post.setRequestHeader("Authorization", "Basic " + auth);
|
||||
NameValuePair[] data = {
|
||||
new NameValuePair("params", verbose ? prefs.get("upload.params.verbose") : prefs.get("upload.params.quiet"))
|
||||
};
|
||||
post.setRequestBody(data);
|
||||
|
||||
int statusCode;
|
||||
try {
|
||||
@ -105,17 +131,40 @@ public class HttpUploader extends Uploader {
|
||||
}
|
||||
}
|
||||
|
||||
protected boolean boardNotReady() {
|
||||
GetMethod get = new GetMethod(baseUrl + "/ready");
|
||||
private void readSketchFile(String buildPath, String className, StringBuilder uploadRequest) throws RunnerException {
|
||||
BufferedReader sketchReader = null;
|
||||
try {
|
||||
return client.executeMethod(get) != HttpStatus.SC_OK;
|
||||
sketchReader = new BufferedReader(new InputStreamReader(new FileInputStream(new File(buildPath, className + ".hex"))));
|
||||
String line;
|
||||
while ((line = sketchReader.readLine()) != null) {
|
||||
line = line.trim();
|
||||
if (line.length() > 0) {
|
||||
uploadRequest.append(line).append("\n");
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
return true;
|
||||
throw new RunnerException(e);
|
||||
} finally {
|
||||
if (sketchReader != null) {
|
||||
try {
|
||||
sketchReader.close();
|
||||
} catch (IOException e) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected PostMethod newPostMethod() {
|
||||
return new PostMethod(baseUrl + "/upload");
|
||||
protected boolean boardNotReady(String auth) {
|
||||
GetMethod get = new GetMethod(baseUrl + "/ready");
|
||||
get.setRequestHeader("Authorization", "Basic " + auth);
|
||||
try {
|
||||
int httpStatus = client.executeMethod(get);
|
||||
return httpStatus != HttpStatus.SC_OK;
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
x
Reference in New Issue
Block a user