/* See if a cached location is accurate -- called with "Known Bus" set */ INDEX_OR_ERROR ReCheckPresence(struct parsedname *pn) { INDEX_OR_ERROR bus_nr; if (NotRealDir(pn)) { return INDEX_DEFAULT; } if ((pn->selected_device == DeviceSimultaneous) || (pn->selected_device == DeviceThermostat)) { return INDEX_DEFAULT; } if (KnownBus(pn)) { if ( INDEX_VALID( CheckThisConnection(pn->known_bus->index,pn) ) ) { return pn->known_bus->index ; } } if ( GOOD( Cache_Get_Device(&bus_nr, pn)) ) { LEVEL_DEBUG("Found device on bus %d",bus_nr); if ( INDEX_VALID( CheckThisConnection(bus_nr,pn) ) ) { SetKnownBus(bus_nr, pn); return bus_nr ; } } UnsetKnownBus(pn); Cache_Del_Device(pn) ; return CheckPresence(pn); }
/* Misnamed. Actually all directory */ void ShowDir(FILE * out, struct parsedname * pn) { int b = Backup(pn->path); // length of string to get to higher level if (pn->state & ePS_text) { ShowDirText(out, pn); return; } else if (pn->state & ePS_json) { ShowDirJson(out, pn); return; } HTTPstart(out, "200 OK", ct_html); HTTPtitle(out, "Directory"); if (NotRealDir(pn)) { /* return whole path since tree structure could be much deeper now */ /* first / is stripped off */ HTTPheader(out, &pn->path[1]); } else if (pn->state) { /* return whole path since tree structure could be much deeper now */ /* first / is stripped off */ HTTPheader(out, &pn->path[1]); } else { HTTPheader(out, "directory"); } fprintf(out, "<TABLE BGCOLOR=\"#DDDDDD\" BORDER=1>"); if (b != 1) { char * escaped_path = httpescape( pn->path ) ; fprintf(out, "<TR><TD><A HREF='%.*s'><CODE><B><BIG>up</BIG></B></CODE></A></TD><TD>higher level</TD><TD>directory</TD></TR>", b, escaped_path==NULL ? pn->path : escaped_path ); if ( escaped_path ) { owfree( escaped_path ) ; } } else { fprintf(out, "<TR><TD><A HREF='/'><CODE><B><BIG>top</BIG></B></CODE></A></TD><TD>highest level</TD><TD>directory</TD></TR>"); } FS_dir(ShowDirCallback, out, pn); fprintf(out, "</TABLE>"); HTTPfoot(out); }
ZERO_OR_ERROR FS_present(struct one_wire_query *owq) { struct parsedname *pn = PN(owq); if (NotRealDir(pn) || pn->selected_device == DeviceSimultaneous || pn->selected_device == DeviceThermostat) { OWQ_Y(owq) = 1; } else if ( pn->selected_connection->iroutines.flags & ADAP_FLAG_presence_from_dirblob ) { OWQ_Y(owq) = GOOD( PresenceFromDirblob(pn) ) ; } else if ( pn->selected_connection->iroutines.flags & ADAP_FLAG_sham ) { OWQ_Y(owq) = 0 ; } else { struct transaction_log t[] = { TRXN_NVERIFY, TRXN_END, }; OWQ_Y(owq) = BAD(BUS_transaction(t, pn)) ? 0 : 1; } return 0; }
/* Check if device exists -- >=0 yes, -1 no */ INDEX_OR_ERROR CheckPresence(struct parsedname *pn) { INDEX_OR_ERROR bus_nr; if (NotRealDir(pn)) { return INDEX_DEFAULT; } if ((pn->selected_device == DeviceSimultaneous) || (pn->selected_device == DeviceThermostat)) { return INDEX_DEFAULT; } /* If set, already found bus. */ /* Use UnsetKnownBus to clear and allow a new search */ if (KnownBus(pn)) { return pn->known_bus->index; } if ( GOOD( Cache_Get_Device(&bus_nr, pn)) ) { LEVEL_DEBUG("Found device on bus %d",bus_nr); SetKnownBus(bus_nr, pn); return bus_nr; } LEVEL_DETAIL("Checking presence of %s", SAFESTRING(pn->path)); bus_nr = CheckPresence_low(pn); // check only allocated inbound connections if ( INDEX_VALID(bus_nr) ) { SetKnownBus(bus_nr, pn); Cache_Add_Device( bus_nr, pn->sn ) ; return bus_nr; } UnsetKnownBus(pn); return INDEX_BAD; }