// // Do OBEX SetPath // static int ircp_setpath(ircp_client_t *cli, char *name, int up) { obex_object_t *object; obex_headerdata_t hdd; uint8_t setpath_nohdr_data[2] = {0,}; uint8_t *ucname; int ucname_len; int ret; DEBUG(4, "%s\n", name); object = OBEX_ObjectNew(cli->obexhandle, OBEX_CMD_SETPATH); if(up) { setpath_nohdr_data[0] = 1; } else { ucname_len = strlen(name)*2 + 2; ucname = malloc(ucname_len); if(ucname == NULL) { OBEX_ObjectDelete(cli->obexhandle, object); return -1; } ucname_len = OBEX_CharToUnicode(ucname, (uint8_t *) name, ucname_len); hdd.bs = ucname; OBEX_ObjectAddHeader(cli->obexhandle, object, OBEX_HDR_NAME, hdd, ucname_len, 0); free(ucname); } OBEX_ObjectSetNonHdrData(object, setpath_nohdr_data, 2); ret = cli_sync_request(cli, object); return ret; }
int obex_setpath(int od, const char *path, uint8_t flags) { unsigned char taildata[2] = { 0x00, 0x00 }; obex_t *handle = obex_handles[0]; struct obex_context *context; char unicode[200]; int err, size; obex_object_t *object; obex_headerdata_t hd; if (!(context = OBEX_GetUserData(handle))) return -1; if (context->state != OBEX_CONNECTED) return -1; if (context->mode != OBEX_IDLE) return -1; context->mode = OBEX_REQUEST; if (!(object = OBEX_ObjectNew(handle, OBEX_CMD_SETPATH))) return -1; if (context->cid > 0) { hd.bq4 = context->cid; OBEX_ObjectAddHeader(handle, object, OBEX_HDR_CONNECTION, hd, 4, OBEX_FL_FIT_ONE_PACKET); } if (path) { size = OBEX_CharToUnicode((uint8_t *) unicode, (uint8_t *) path, sizeof(unicode)); hd.bs = (uint8_t *) unicode; OBEX_ObjectAddHeader(handle, object, OBEX_HDR_NAME, hd, size, OBEX_FL_FIT_ONE_PACKET); } taildata[0] = flags; OBEX_ObjectSetNonHdrData(object, taildata, sizeof(taildata)); if ((err = OBEX_Request(handle, object)) < 0) return err; while (1) { OBEX_HandleInput(handle, OBEX_TIMEOUT); if (context->mode == OBEX_ERROR) { err = -EIO; break; } if (context->mode == OBEX_DONE) break; } context->mode = OBEX_IDLE; return err; }
int obex_setpath(obex_t *handle, const char *path, int create) { obex_context_t *context = OBEX_GetUserData(handle); obex_object_t *object; obex_headerdata_t hd; obex_setpath_hdr_t sphdr; int ret; g_return_val_if_fail(context != NULL, -1); if (context->state != OBEX_CONNECTED) return -ENOTCONN; object = OBEX_ObjectNew(handle, OBEX_CMD_SETPATH); if (!object) return -ENOMEM; if (context->cid != CID_INVALID) { hd.bq4 = context->cid; OBEX_ObjectAddHeader(handle, object, OBEX_HDR_CONNECTION, hd, 4, 0); } memset(&sphdr, 0, sizeof(obex_setpath_hdr_t)); if (strcmp(path, "..") == 0) { /* Can't create parent dir */ if (create) return -EINVAL; sphdr.flags = 0x03; } else { int len, ulen = (strlen(path) + 1) * 2; uint8_t *unicode = malloc(ulen); if (!create) sphdr.flags = 0x02; if (!unicode) { OBEX_ObjectDelete(handle, object); return -ENOMEM; } len = OBEX_CharToUnicode(unicode, (uint8_t *) path, ulen); hd.bs = unicode; ret = OBEX_ObjectAddHeader(handle, object, OBEX_HDR_NAME, hd, len, 0); if (ret < 0) { OBEX_ObjectDelete(handle, object); free(unicode); return ret; } free(unicode); } OBEX_ObjectSetNonHdrData(object, (uint8_t *) &sphdr, 2); ret = obex_send_or_queue(handle, object); if (ret < 0) OBEX_ObjectDelete(handle, object); return ret; }