/* * @brief: service command to novacomd * @ret * -1 invalid command * 0 placed in queue * 1 command complete * url parsed command (when ret==0) */ int novacom_service_command(SOCKET cmdsocket, const char *cmd, novacom_command_url_t **_url) { int i=0; int rc=-1; /* error by default */ bool handled = false; struct novacom_command_url *url = NULL; /* check */ if (!_url) { goto done; /* return error */ } // parse the command if (parse_command(cmd, strlen(cmd), &url) < 0) { rc = -1; goto done; } PTRACEF(TRACE_COMMANDS, "command verb '%s', scheme '%s'\n", url->verb, url->scheme); // check command handlers i = 0; while (iohandlers[i].verb != NULL) { if ((strcasecmp(url->verb, iohandlers[i].verb) == 0) && strcasecmp(url->scheme, iohandlers[i].scheme) == 0) { handled = true; break; } i++; } if(!handled) { goto done; } /* some processing involved? */ if(!iohandlers[i].remote) { rc = iohandlers[i].spawn(cmdsocket, 0, url, NULL, NULL); if (!rc) rc = 1; /*done with command */ PTRACEF(TRACE_COMMANDS, "host command: done...\n"); } else { /* register command with device commands queue */ rc = 0; *_url = url; PTRACEF(TRACE_COMMANDS, "device specific command: postponed...\n"); } done: /* free _url only when we have error/completed cmd */ if (rc && url) { free_url(url); } PTRACEF(TRACE_COMMANDS, "return rc(%d)\n", rc); return rc; }
/* * usbrecords_update * @param[elapsed] elapsed time * @ret 0 - success, -1 error */ int usbrecords_update(int elapsed) { recovery_entry_t *item; recovery_entry_t *tmp_item; LTRACEF("Update records\n"); platform_mutex_lock(&recovery_lock); /* check all entries */ for (item = TAILQ_FIRST(&t_recovery_queue); item != NULL; item = tmp_item) { tmp_item = TAILQ_NEXT(item, entries); /* update remaining recovery time */ item->timeout -= elapsed; PTRACEF(USB_RECOVERY, "Check entry(%p): timeout %d\n", item, item->timeout); /* expired? */ if(item->timeout < 0) { TRACEF("expired timeout::destroy record\n"); /* destroy handle */ novacom_usbll_destroy((novacom_usbll_handle_t)item->t_token->user_data); /* Remove the item from queue. */ TAILQ_REMOVE(&t_recovery_queue, item, entries); /* Free the item as we don't need it anymore. */ platform_free(item->t_token); platform_free(item); } } platform_mutex_unlock(&recovery_lock); return 0; }
/* * @brief: service url * @ret * -1 invalid command * 0 placed in queue * 1 command complete */ int novacom_service_url(device_handle_t dev, const char *ssid, SOCKET cmdsocket, uint32_t channel, novacom_command_url_t *url) { bool handled=false; int i=0; int rc=-1; while (iohandlers[i].verb != NULL) { if ((strcasecmp(url->verb, iohandlers[i].verb) == 0) && strcasecmp(url->scheme, iohandlers[i].scheme) == 0) { handled = true; break; } i++; } if (handled) { PTRACEF(TRACE_COMMANDS, "command %s\n", url->verb); rc = iohandlers[i].spawn(cmdsocket, channel, url, dev, ssid); } return rc; }