Beispiel #1
0
int createfile(AFPObj *obj, uint16_t vid, cnid_t did, const char *name)
{
    const int bufsize = 256;
    char buf[bufsize];
    char *p = buf;
    int len = 0;

    PUSHVAL(p, uint16_t, htons(128), len); /* hard create */
    PUSHVAL(p, uint16_t, vid, len);
    PUSHVAL(p, cnid_t, did, len);
    len += push_path(&p, name);

    return afp_createfile(obj, buf, len, rbuf, &rbuflen);
}
int createdir(AFPObj *obj, uint16_t vid, cnid_t did, const char *name)
{
    const int bufsize = 256;
    char buf[bufsize];
    char *p = buf;
    int len = 0;

    ADD(p, len , 2);

    PUSHVAL(p, uint16_t, vid, len);
    PUSHVAL(p, cnid_t, did, len);
    len += push_path(&p, name);

    return afp_createdir(obj, buf, len, rbuf, &rbuflen);
}
int getfiledirparms(AFPObj *obj, uint16_t vid, cnid_t did, const char *name)
{
    const int bufsize = 256;
    char buf[bufsize];
    char *p = buf;
    int len = 0;

    ADD(p, len , 2);

    PUSHVAL(p, uint16_t, vid, len);
    PUSHVAL(p, cnid_t, did, len);
    PUSHVAL(p, uint16_t, htons(FILPBIT_FNUM | FILPBIT_PDINFO), len);
    PUSHVAL(p, uint16_t, htons(DIRPBIT_DID | DIRPBIT_PDINFO), len);

    len += push_path(&p, name);

    return afp_getfildirparams(obj, buf, len, rbuf, &rbuflen);
}
static int push_path(char **bufp, const char *name)
{
    int len = 0;
    int slen = strlen(name);
    char *p = *bufp;

    PUSHVAL(p, uint8_t, 3, len); /* path type */
    PUSHVAL(p, uint32_t, kTextEncodingUTF8, len); /* text encoding hint */
    PUSHVAL(p, uint16_t, htons(slen), len);
    if (slen) {
        for (int i = 0; i < slen; i++) {
            if (name[i] == '/')
                p[i] = 0;
            else
                p[i] = name[i];
        }
        len += slen;
    }

    *bufp += len;
    return len;
}