| 1 | package be.nikiroo.fanfix.library; |
| 2 | |
| 3 | import java.io.File; |
| 4 | import java.io.IOException; |
| 5 | import java.net.URL; |
| 6 | import java.net.UnknownHostException; |
| 7 | import java.util.ArrayList; |
| 8 | import java.util.List; |
| 9 | |
| 10 | import javax.net.ssl.SSLException; |
| 11 | |
| 12 | import be.nikiroo.fanfix.Instance; |
| 13 | import be.nikiroo.fanfix.data.MetaData; |
| 14 | import be.nikiroo.fanfix.data.Story; |
| 15 | import be.nikiroo.utils.Image; |
| 16 | import be.nikiroo.utils.Progress; |
| 17 | import be.nikiroo.utils.Version; |
| 18 | import be.nikiroo.utils.serial.server.ConnectActionClientObject; |
| 19 | |
| 20 | /** |
| 21 | * This {@link BasicLibrary} will access a remote server to list the available |
| 22 | * stories, and download the ones you try to load to the local directory |
| 23 | * specified in the configuration. |
| 24 | * |
| 25 | * @author niki |
| 26 | */ |
| 27 | public class RemoteLibrary extends BasicLibrary { |
| 28 | private String host; |
| 29 | private int port; |
| 30 | private final String key; |
| 31 | private final String subkey; |
| 32 | |
| 33 | // informative only (server will make the actual checks) |
| 34 | private boolean rw; |
| 35 | |
| 36 | // TODO: error handling is not up to par! |
| 37 | |
| 38 | /** |
| 39 | * Create a {@link RemoteLibrary} linked to the given server. |
| 40 | * <p> |
| 41 | * Note that the key is structured: |
| 42 | * <tt><b><i>xxx</i></b>(|<b><i>yyy</i></b>|<b>wl</b>)(|<b>rw</b>)</tt> |
| 43 | * <p> |
| 44 | * Note that anything before the first pipe (<tt>|</tt>) character is |
| 45 | * considered to be the encryption key, anything after that character is |
| 46 | * called the subkey (including the other pipe characters and flags!). |
| 47 | * <p> |
| 48 | * This is important because the subkey (including the pipe characters and |
| 49 | * flags) must be present as-is in the server configuration file to be |
| 50 | * allowed. |
| 51 | * <ul> |
| 52 | * <li><b><i>xxx</i></b>: the encryption key used to communicate with the |
| 53 | * server</li> |
| 54 | * <li><b><i>yyy</i></b>: the secondary key</li> |
| 55 | * <li><b>rw</b>: flag to allow read and write access if it is not the |
| 56 | * default on this server</li> |
| 57 | * <li><b>wl</b>: flag to allow access to all the stories (bypassing the |
| 58 | * whitelist if it exists)</li> |
| 59 | * </ul> |
| 60 | * |
| 61 | * Some examples: |
| 62 | * <ul> |
| 63 | * <li><b>my_key</b>: normal connection, will take the default server |
| 64 | * options</li> |
| 65 | * <li><b>my_key|agzyzz|wl</b>: will ask to bypass the white list (if it |
| 66 | * exists)</li> |
| 67 | * <li><b>my_key|agzyzz|rw</b>: will ask read-write access (if the default |
| 68 | * is read-only)</li> |
| 69 | * <li><b>my_key|agzyzz|wl|rw</b>: will ask both read-write access and white |
| 70 | * list bypass</li> |
| 71 | * </ul> |
| 72 | * |
| 73 | * @param key |
| 74 | * the key that will allow us to exchange information with the |
| 75 | * server |
| 76 | * @param host |
| 77 | * the host to contact or NULL for localhost |
| 78 | * @param port |
| 79 | * the port to contact it on |
| 80 | */ |
| 81 | public RemoteLibrary(String key, String host, int port) { |
| 82 | int index = -1; |
| 83 | if (key != null) { |
| 84 | index = key.indexOf('|'); |
| 85 | } |
| 86 | |
| 87 | if (index >= 0) { |
| 88 | this.key = key.substring(0, index); |
| 89 | this.subkey = key.substring(index + 1); |
| 90 | } else { |
| 91 | this.key = key; |
| 92 | this.subkey = ""; |
| 93 | } |
| 94 | |
| 95 | this.host = host; |
| 96 | this.port = port; |
| 97 | } |
| 98 | |
| 99 | @Override |
| 100 | public String getLibraryName() { |
| 101 | return host + ":" + port; |
| 102 | } |
| 103 | |
| 104 | @Override |
| 105 | public Status getStatus() { |
| 106 | Instance.getTraceHandler().trace("Getting remote lib status..."); |
| 107 | Status status = getStatusDo(); |
| 108 | Instance.getTraceHandler().trace("Remote lib status: " + status); |
| 109 | return status; |
| 110 | } |
| 111 | |
| 112 | private boolean check() { |
| 113 | Status status = getStatusDo(); |
| 114 | if (status != Status.READY) { |
| 115 | Instance.getTraceHandler().error("Remote lib not ready: " + status); |
| 116 | return false; |
| 117 | } |
| 118 | |
| 119 | return true; |
| 120 | } |
| 121 | |
| 122 | private Status getStatusDo() { |
| 123 | final Status[] result = new Status[1]; |
| 124 | |
| 125 | result[0] = Status.INVALID; |
| 126 | |
| 127 | try { |
| 128 | new ConnectActionClientObject(host, port, key) { |
| 129 | @Override |
| 130 | public void action(Version serverVersion) throws Exception { |
| 131 | Object rep = send(new Object[] { subkey, "PING" }); |
| 132 | |
| 133 | if ("r/w".equals(rep)) { |
| 134 | rw = true; |
| 135 | result[0] = Status.READY; |
| 136 | } else if ("r/o".equals(rep)) { |
| 137 | rw = false; |
| 138 | result[0] = Status.READY; |
| 139 | } else { |
| 140 | result[0] = Status.UNAUTHORIZED; |
| 141 | } |
| 142 | } |
| 143 | |
| 144 | @Override |
| 145 | protected void onError(Exception e) { |
| 146 | if (e instanceof SSLException) { |
| 147 | result[0] = Status.UNAUTHORIZED; |
| 148 | } else { |
| 149 | result[0] = Status.UNAVAILABLE; |
| 150 | } |
| 151 | } |
| 152 | }.connect(); |
| 153 | } catch (UnknownHostException e) { |
| 154 | result[0] = Status.INVALID; |
| 155 | } catch (IllegalArgumentException e) { |
| 156 | result[0] = Status.INVALID; |
| 157 | } catch (Exception e) { |
| 158 | result[0] = Status.UNAVAILABLE; |
| 159 | } |
| 160 | |
| 161 | return result[0]; |
| 162 | } |
| 163 | |
| 164 | @Override |
| 165 | public Image getCover(final String luid) { |
| 166 | if (!check()) { |
| 167 | return null; |
| 168 | } |
| 169 | |
| 170 | final Image[] result = new Image[1]; |
| 171 | |
| 172 | try { |
| 173 | new ConnectActionClientObject(host, port, key) { |
| 174 | @Override |
| 175 | public void action(Version serverVersion) throws Exception { |
| 176 | Object rep = send(new Object[] { subkey, "GET_COVER", luid }); |
| 177 | result[0] = (Image) rep; |
| 178 | } |
| 179 | |
| 180 | @Override |
| 181 | protected void onError(Exception e) { |
| 182 | if (e instanceof SSLException) { |
| 183 | Instance.getTraceHandler().error( |
| 184 | "Connection refused (bad key)"); |
| 185 | } else { |
| 186 | Instance.getTraceHandler().error(e); |
| 187 | } |
| 188 | } |
| 189 | }.connect(); |
| 190 | } catch (Exception e) { |
| 191 | Instance.getTraceHandler().error(e); |
| 192 | } |
| 193 | |
| 194 | return result[0]; |
| 195 | } |
| 196 | |
| 197 | @Override |
| 198 | public Image getCustomSourceCover(final String source) { |
| 199 | if (!check()) { |
| 200 | return null; |
| 201 | } |
| 202 | |
| 203 | return getCustomCover(source, "SOURCE"); |
| 204 | } |
| 205 | |
| 206 | @Override |
| 207 | public Image getCustomAuthorCover(final String author) { |
| 208 | if (!check()) { |
| 209 | return null; |
| 210 | } |
| 211 | |
| 212 | return getCustomCover(author, "AUTHOR"); |
| 213 | } |
| 214 | |
| 215 | // type: "SOURCE" or "AUTHOR" |
| 216 | private Image getCustomCover(final String source, final String type) { |
| 217 | if (!check()) { |
| 218 | return null; |
| 219 | } |
| 220 | |
| 221 | final Image[] result = new Image[1]; |
| 222 | |
| 223 | try { |
| 224 | new ConnectActionClientObject(host, port, key) { |
| 225 | @Override |
| 226 | public void action(Version serverVersion) throws Exception { |
| 227 | Object rep = send(new Object[] { subkey, |
| 228 | "GET_CUSTOM_COVER", type, source }); |
| 229 | result[0] = (Image) rep; |
| 230 | } |
| 231 | |
| 232 | @Override |
| 233 | protected void onError(Exception e) { |
| 234 | if (e instanceof SSLException) { |
| 235 | Instance.getTraceHandler().error( |
| 236 | "Connection refused (bad key)"); |
| 237 | } else { |
| 238 | Instance.getTraceHandler().error(e); |
| 239 | } |
| 240 | } |
| 241 | }.connect(); |
| 242 | } catch (Exception e) { |
| 243 | Instance.getTraceHandler().error(e); |
| 244 | } |
| 245 | |
| 246 | return result[0]; |
| 247 | } |
| 248 | |
| 249 | @Override |
| 250 | public synchronized Story getStory(final String luid, Progress pg) { |
| 251 | if (!check()) { |
| 252 | return null; |
| 253 | } |
| 254 | |
| 255 | final Progress pgF = pg; |
| 256 | final Story[] result = new Story[1]; |
| 257 | |
| 258 | try { |
| 259 | new ConnectActionClientObject(host, port, key) { |
| 260 | @Override |
| 261 | public void action(Version serverVersion) throws Exception { |
| 262 | Progress pg = pgF; |
| 263 | if (pg == null) { |
| 264 | pg = new Progress(); |
| 265 | } |
| 266 | |
| 267 | Object rep = send(new Object[] { subkey, "GET_STORY", luid }); |
| 268 | |
| 269 | MetaData meta = null; |
| 270 | if (rep instanceof MetaData) { |
| 271 | meta = (MetaData) rep; |
| 272 | if (meta.getWords() <= Integer.MAX_VALUE) { |
| 273 | pg.setMinMax(0, (int) meta.getWords()); |
| 274 | } |
| 275 | } |
| 276 | |
| 277 | List<Object> list = new ArrayList<Object>(); |
| 278 | for (Object obj = send(null); obj != null; obj = send(null)) { |
| 279 | list.add(obj); |
| 280 | pg.add(1); |
| 281 | } |
| 282 | |
| 283 | result[0] = RemoteLibraryServer.rebuildStory(list); |
| 284 | pg.done(); |
| 285 | } |
| 286 | |
| 287 | @Override |
| 288 | protected void onError(Exception e) { |
| 289 | if (e instanceof SSLException) { |
| 290 | Instance.getTraceHandler().error( |
| 291 | "Connection refused (bad key)"); |
| 292 | } else { |
| 293 | Instance.getTraceHandler().error(e); |
| 294 | } |
| 295 | } |
| 296 | }.connect(); |
| 297 | } catch (Exception e) { |
| 298 | Instance.getTraceHandler().error(e); |
| 299 | } |
| 300 | |
| 301 | return result[0]; |
| 302 | } |
| 303 | |
| 304 | @Override |
| 305 | public synchronized Story save(final Story story, final String luid, |
| 306 | Progress pg) throws IOException { |
| 307 | if (!check()) { |
| 308 | return null; |
| 309 | } |
| 310 | |
| 311 | final String[] luidSaved = new String[1]; |
| 312 | Progress pgSave = new Progress(); |
| 313 | Progress pgRefresh = new Progress(); |
| 314 | if (pg == null) { |
| 315 | pg = new Progress(); |
| 316 | } |
| 317 | |
| 318 | pg.setMinMax(0, 10); |
| 319 | pg.addProgress(pgSave, 9); |
| 320 | pg.addProgress(pgRefresh, 1); |
| 321 | |
| 322 | final Progress pgF = pgSave; |
| 323 | |
| 324 | new ConnectActionClientObject(host, port, key) { |
| 325 | @Override |
| 326 | public void action(Version serverVersion) throws Exception { |
| 327 | Progress pg = pgF; |
| 328 | if (story.getMeta().getWords() <= Integer.MAX_VALUE) { |
| 329 | pg.setMinMax(0, (int) story.getMeta().getWords()); |
| 330 | } |
| 331 | |
| 332 | send(new Object[] { subkey, "SAVE_STORY", luid }); |
| 333 | |
| 334 | List<Object> list = RemoteLibraryServer.breakStory(story); |
| 335 | for (Object obj : list) { |
| 336 | send(obj); |
| 337 | pg.add(1); |
| 338 | } |
| 339 | |
| 340 | luidSaved[0] = (String) send(null); |
| 341 | |
| 342 | pg.done(); |
| 343 | } |
| 344 | |
| 345 | @Override |
| 346 | protected void onError(Exception e) { |
| 347 | if (e instanceof SSLException) { |
| 348 | Instance.getTraceHandler().error( |
| 349 | "Connection refused (bad key)"); |
| 350 | } else { |
| 351 | Instance.getTraceHandler().error(e); |
| 352 | } |
| 353 | } |
| 354 | }.connect(); |
| 355 | |
| 356 | // because the meta changed: |
| 357 | MetaData meta = getInfo(luidSaved[0]); |
| 358 | if (story.getMeta().getClass() != null) { |
| 359 | // If already available locally: |
| 360 | meta.setCover(story.getMeta().getCover()); |
| 361 | } else { |
| 362 | // If required: |
| 363 | meta.setCover(getCover(meta.getLuid())); |
| 364 | } |
| 365 | story.setMeta(meta); |
| 366 | |
| 367 | pg.done(); |
| 368 | |
| 369 | return story; |
| 370 | } |
| 371 | |
| 372 | @Override |
| 373 | public synchronized void delete(final String luid) throws IOException { |
| 374 | if (!check()) { |
| 375 | throw new IOException("Library not ready"); |
| 376 | } |
| 377 | |
| 378 | new ConnectActionClientObject(host, port, key) { |
| 379 | @Override |
| 380 | public void action(Version serverVersion) throws Exception { |
| 381 | send(new Object[] { subkey, "DELETE_STORY", luid }); |
| 382 | } |
| 383 | |
| 384 | @Override |
| 385 | protected void onError(Exception e) { |
| 386 | if (e instanceof SSLException) { |
| 387 | Instance.getTraceHandler().error( |
| 388 | "Connection refused (bad key)"); |
| 389 | } else { |
| 390 | Instance.getTraceHandler().error(e); |
| 391 | } |
| 392 | } |
| 393 | }.connect(); |
| 394 | } |
| 395 | |
| 396 | @Override |
| 397 | public void setSourceCover(final String source, final String luid) { |
| 398 | if (!check()) { |
| 399 | return; |
| 400 | } |
| 401 | |
| 402 | setCover(source, luid, "SOURCE"); |
| 403 | } |
| 404 | |
| 405 | @Override |
| 406 | public void setAuthorCover(final String author, final String luid) { |
| 407 | if (!check()) { |
| 408 | return; |
| 409 | } |
| 410 | |
| 411 | setCover(author, luid, "AUTHOR"); |
| 412 | } |
| 413 | |
| 414 | // type = "SOURCE" | "AUTHOR" |
| 415 | private void setCover(final String value, final String luid, |
| 416 | final String type) { |
| 417 | if (!check()) { |
| 418 | return; |
| 419 | } |
| 420 | |
| 421 | try { |
| 422 | new ConnectActionClientObject(host, port, key) { |
| 423 | @Override |
| 424 | public void action(Version serverVersion) throws Exception { |
| 425 | send(new Object[] { subkey, "SET_COVER", type, value, luid }); |
| 426 | } |
| 427 | |
| 428 | @Override |
| 429 | protected void onError(Exception e) { |
| 430 | if (e instanceof SSLException) { |
| 431 | Instance.getTraceHandler().error( |
| 432 | "Connection refused (bad key)"); |
| 433 | } else { |
| 434 | Instance.getTraceHandler().error(e); |
| 435 | } |
| 436 | } |
| 437 | }.connect(); |
| 438 | } catch (IOException e) { |
| 439 | Instance.getTraceHandler().error(e); |
| 440 | } |
| 441 | } |
| 442 | |
| 443 | @Override |
| 444 | // Could work (more slowly) without it |
| 445 | public Story imprt(final URL url, Progress pg) throws IOException { |
| 446 | if (!check()) { |
| 447 | return null; |
| 448 | } |
| 449 | |
| 450 | // Import the file locally if it is actually a file |
| 451 | if (url == null || url.getProtocol().equalsIgnoreCase("file")) { |
| 452 | return super.imprt(url, pg); |
| 453 | } |
| 454 | |
| 455 | // Import it remotely if it is an URL |
| 456 | |
| 457 | if (pg == null) { |
| 458 | pg = new Progress(); |
| 459 | } |
| 460 | |
| 461 | pg.setMinMax(0, 2); |
| 462 | Progress pgImprt = new Progress(); |
| 463 | Progress pgGet = new Progress(); |
| 464 | pg.addProgress(pgImprt, 1); |
| 465 | pg.addProgress(pgGet, 1); |
| 466 | |
| 467 | final Progress pgF = pgImprt; |
| 468 | final String[] luid = new String[1]; |
| 469 | |
| 470 | try { |
| 471 | new ConnectActionClientObject(host, port, key) { |
| 472 | @Override |
| 473 | public void action(Version serverVersion) throws Exception { |
| 474 | Progress pg = pgF; |
| 475 | |
| 476 | Object rep = send(new Object[] { subkey, "IMPORT", |
| 477 | url.toString() }); |
| 478 | |
| 479 | while (true) { |
| 480 | if (!RemoteLibraryServer.updateProgress(pg, rep)) { |
| 481 | break; |
| 482 | } |
| 483 | |
| 484 | rep = send(null); |
| 485 | } |
| 486 | |
| 487 | pg.done(); |
| 488 | luid[0] = (String) rep; |
| 489 | } |
| 490 | |
| 491 | @Override |
| 492 | protected void onError(Exception e) { |
| 493 | if (e instanceof SSLException) { |
| 494 | Instance.getTraceHandler().error( |
| 495 | "Connection refused (bad key)"); |
| 496 | } else { |
| 497 | Instance.getTraceHandler().error(e); |
| 498 | } |
| 499 | } |
| 500 | }.connect(); |
| 501 | } catch (IOException e) { |
| 502 | Instance.getTraceHandler().error(e); |
| 503 | } |
| 504 | |
| 505 | if (luid[0] == null) { |
| 506 | throw new IOException("Remote failure"); |
| 507 | } |
| 508 | |
| 509 | Story story = getStory(luid[0], pgGet); |
| 510 | pgGet.done(); |
| 511 | |
| 512 | pg.done(); |
| 513 | return story; |
| 514 | } |
| 515 | |
| 516 | @Override |
| 517 | // Could work (more slowly) without it |
| 518 | protected synchronized void changeSTA(final String luid, |
| 519 | final String newSource, final String newTitle, |
| 520 | final String newAuthor, Progress pg) throws IOException { |
| 521 | if (!check()) { |
| 522 | return; |
| 523 | } |
| 524 | |
| 525 | final Progress pgF = pg == null ? new Progress() : pg; |
| 526 | |
| 527 | try { |
| 528 | new ConnectActionClientObject(host, port, key) { |
| 529 | @Override |
| 530 | public void action(Version serverVersion) throws Exception { |
| 531 | Progress pg = pgF; |
| 532 | |
| 533 | Object rep = send(new Object[] { subkey, "CHANGE_STA", |
| 534 | luid, newSource, newTitle, newAuthor }); |
| 535 | while (true) { |
| 536 | if (!RemoteLibraryServer.updateProgress(pg, rep)) { |
| 537 | break; |
| 538 | } |
| 539 | |
| 540 | rep = send(null); |
| 541 | } |
| 542 | } |
| 543 | |
| 544 | @Override |
| 545 | protected void onError(Exception e) { |
| 546 | if (e instanceof SSLException) { |
| 547 | Instance.getTraceHandler().error( |
| 548 | "Connection refused (bad key)"); |
| 549 | } else { |
| 550 | Instance.getTraceHandler().error(e); |
| 551 | } |
| 552 | } |
| 553 | }.connect(); |
| 554 | } catch (IOException e) { |
| 555 | Instance.getTraceHandler().error(e); |
| 556 | } |
| 557 | } |
| 558 | |
| 559 | @Override |
| 560 | public synchronized File getFile(final String luid, Progress pg) { |
| 561 | throw new java.lang.InternalError( |
| 562 | "Operation not supportorted on remote Libraries"); |
| 563 | } |
| 564 | |
| 565 | /** |
| 566 | * Stop the server. |
| 567 | */ |
| 568 | public void exit() { |
| 569 | if (!check()) { |
| 570 | return; |
| 571 | } |
| 572 | |
| 573 | try { |
| 574 | new ConnectActionClientObject(host, port, key) { |
| 575 | @Override |
| 576 | public void action(Version serverVersion) throws Exception { |
| 577 | send(new Object[] { subkey, "EXIT" }); |
| 578 | } |
| 579 | |
| 580 | @Override |
| 581 | protected void onError(Exception e) { |
| 582 | if (e instanceof SSLException) { |
| 583 | Instance.getTraceHandler().error( |
| 584 | "Connection refused (bad key)"); |
| 585 | } else { |
| 586 | Instance.getTraceHandler().error(e); |
| 587 | } |
| 588 | } |
| 589 | }.connect(); |
| 590 | } catch (IOException e) { |
| 591 | Instance.getTraceHandler().error(e); |
| 592 | } |
| 593 | } |
| 594 | |
| 595 | @Override |
| 596 | public synchronized MetaData getInfo(String luid) { |
| 597 | if (!check()) { |
| 598 | return null; |
| 599 | } |
| 600 | |
| 601 | List<MetaData> metas = getMetasList(luid, null); |
| 602 | if (!metas.isEmpty()) { |
| 603 | return metas.get(0); |
| 604 | } |
| 605 | |
| 606 | return null; |
| 607 | } |
| 608 | |
| 609 | @Override |
| 610 | protected List<MetaData> getMetas(Progress pg) { |
| 611 | return getMetasList("*", pg); |
| 612 | } |
| 613 | |
| 614 | @Override |
| 615 | protected void updateInfo(MetaData meta) { |
| 616 | // Will be taken care of directly server side |
| 617 | } |
| 618 | |
| 619 | @Override |
| 620 | protected void invalidateInfo(String luid) { |
| 621 | // Will be taken care of directly server side |
| 622 | } |
| 623 | |
| 624 | // The following methods are only used by Save and Delete in BasicLibrary: |
| 625 | |
| 626 | @Override |
| 627 | protected int getNextId() { |
| 628 | throw new java.lang.InternalError("Should not have been called"); |
| 629 | } |
| 630 | |
| 631 | @Override |
| 632 | protected void doDelete(String luid) throws IOException { |
| 633 | throw new java.lang.InternalError("Should not have been called"); |
| 634 | } |
| 635 | |
| 636 | @Override |
| 637 | protected Story doSave(Story story, Progress pg) throws IOException { |
| 638 | throw new java.lang.InternalError("Should not have been called"); |
| 639 | } |
| 640 | |
| 641 | // |
| 642 | |
| 643 | /** |
| 644 | * Return the meta of the given story or a list of all known metas if the |
| 645 | * luid is "*". |
| 646 | * <p> |
| 647 | * Will not get the covers. |
| 648 | * |
| 649 | * @param luid |
| 650 | * the luid of the story or * |
| 651 | * @param pg |
| 652 | * the optional progress |
| 653 | * |
| 654 | * |
| 655 | * @return the metas |
| 656 | */ |
| 657 | private List<MetaData> getMetasList(final String luid, Progress pg) { |
| 658 | if (!check()) { |
| 659 | return null; |
| 660 | } |
| 661 | |
| 662 | final Progress pgF = pg; |
| 663 | final List<MetaData> metas = new ArrayList<MetaData>(); |
| 664 | |
| 665 | try { |
| 666 | new ConnectActionClientObject(host, port, key) { |
| 667 | @Override |
| 668 | public void action(Version serverVersion) throws Exception { |
| 669 | Progress pg = pgF; |
| 670 | if (pg == null) { |
| 671 | pg = new Progress(); |
| 672 | } |
| 673 | |
| 674 | Object rep = send(new Object[] { subkey, "GET_METADATA", |
| 675 | luid }); |
| 676 | |
| 677 | while (true) { |
| 678 | if (!RemoteLibraryServer.updateProgress(pg, rep)) { |
| 679 | break; |
| 680 | } |
| 681 | |
| 682 | rep = send(null); |
| 683 | } |
| 684 | |
| 685 | if (rep instanceof MetaData[]) { |
| 686 | for (MetaData meta : (MetaData[]) rep) { |
| 687 | metas.add(meta); |
| 688 | } |
| 689 | } else if (rep != null) { |
| 690 | metas.add((MetaData) rep); |
| 691 | } |
| 692 | } |
| 693 | |
| 694 | @Override |
| 695 | protected void onError(Exception e) { |
| 696 | if (e instanceof SSLException) { |
| 697 | Instance.getTraceHandler().error( |
| 698 | "Connection refused (bad key)"); |
| 699 | } else { |
| 700 | Instance.getTraceHandler().error(e); |
| 701 | } |
| 702 | } |
| 703 | }.connect(); |
| 704 | } catch (Exception e) { |
| 705 | Instance.getTraceHandler().error(e); |
| 706 | } |
| 707 | |
| 708 | return metas; |
| 709 | } |
| 710 | } |