X-Git-Url: http://dolda2000.com/gitweb/?a=blobdiff_plain;f=daemon%2Fui.c;h=09a6dcff409f4cdfdb98005bf227d867ae0bd118;hb=ba86d49ad5c856e4a56ec092ca554d81bee9ab67;hp=0302fa1a3af5ff0dac76281bd3df35cd7ebe40d1;hpb=d3372da97568d5e1f35fa19787c8ec8af93a0435;p=doldaconnect.git diff --git a/daemon/ui.c b/daemon/ui.c index 0302fa1..09a6dcf 100644 --- a/daemon/ui.c +++ b/daemon/ui.c @@ -123,6 +123,7 @@ struct uidata { int fnact:1; int fnchat:1; + int fnpeer:1; int tract:1; int trprog:1; int srch:1; @@ -739,7 +740,14 @@ static void cmd_download(struct socket *sk, struct uidata *data, int argc, wchar if(argc > 5) { for(i = 5; i < argc; i += 2) - transferaddarg(transfer, argv[i], argv[i + 1]); + { + if(!wcscmp(argv[i], L"hash")) + { + transfersethash(transfer, parsehash(argv[i + 1])); + } else { + transferaddarg(transfer, argv[i], argv[i + 1]); + } + } } sq(sk, 0, L"200", L"%%i", transfer->id, L"Download queued", NULL); transfersetactivity(transfer, L"create"); @@ -761,6 +769,7 @@ static void cmd_lstrans(struct socket *sk, struct uidata *data, int argc, wchar_ (pt->peernick == NULL)?L"":(pt->peernick), (pt->path == NULL)?L"":(pt->path), L"%%i", pt->size, L"%%i", pt->curpos, + (pt->hash == NULL)?L"":unparsehash(pt->hash), NULL); pt = transfer; } @@ -773,6 +782,7 @@ static void cmd_lstrans(struct socket *sk, struct uidata *data, int argc, wchar_ (pt->peernick == NULL)?L"":(pt->peernick), (pt->path == NULL)?L"":(pt->path), L"%%i", pt->size, L"%%i", pt->curpos, + (pt->hash == NULL)?L"":unparsehash(pt->hash), NULL); } @@ -826,6 +836,8 @@ static void cmd_notify(struct socket *sk, struct uidata *data, int argc, wchar_t data->notify.b.fnchat = val; } else if(!wcscasecmp(argv[i], L"fn:act")) { data->notify.b.fnact = val; + } else if(!wcscasecmp(argv[i], L"fn:peer")) { + data->notify.b.fnpeer = val; } else if(!wcscasecmp(argv[i], L"trans:act")) { data->notify.b.tract = val; } else if(!wcscasecmp(argv[i], L"trans:prog")) { @@ -987,7 +999,7 @@ static void cmd_lssr(struct socket *sk, struct uidata *data, int argc, wchar_t * for(sr = srch->results; sr != NULL; sr = sr->next) { swprintf(buf, 64, L"%f", sr->time); - sq(sk, (sr->next != NULL)?1:0, L"200", L"%%ls", sr->filename, sr->fnet->name, L"%%ls", sr->peerid, L"%%i", sr->size, L"%%i", sr->slots, L"%%i", (sr->fn == NULL)?-1:(sr->fn->id), buf, NULL); + sq(sk, (sr->next != NULL)?1:0, L"200", L"%%ls", sr->filename, sr->fnet->name, L"%%ls", sr->peerid, L"%%i", sr->size, L"%%i", sr->slots, L"%%i", (sr->fn == NULL)?-1:(sr->fn->id), buf, L"%%ls", (sr->hash == NULL)?L"":unparsehash(sr->hash), NULL); } } } @@ -1258,18 +1270,10 @@ static struct qcommand *unlinkqcmd(struct uidata *data) return(qcmd); } -static struct notif *newnotif(struct uidata *data, int code, ...) +static void notifappendv(struct notif *notif, va_list args) { - struct notif *notif; - va_list args; int dt, ca; - notif = smalloc(sizeof(*notif)); - memset(notif, 0, sizeof(*notif)); - notif->rlimit = 0.0; - notif->ui = data; - notif->code = code; - va_start(args, code); while((dt = va_arg(args, int)) != NOTIF_END) { ca = notif->argc; @@ -1289,6 +1293,29 @@ static struct notif *newnotif(struct uidata *data, int code, ...) break; } } +} + +static void notifappend(struct notif *notif, ...) +{ + va_list args; + + va_start(args, notif); + notifappendv(notif, args); + va_end(args); +} + +static struct notif *newnotif(struct uidata *data, int code, ...) +{ + struct notif *notif; + va_list args; + + notif = smalloc(sizeof(*notif)); + memset(notif, 0, sizeof(*notif)); + notif->rlimit = 0.0; + notif->ui = data; + notif->code = code; + va_start(args, code); + notifappendv(notif, args); va_end(args); notif->next = NULL; notif->prev = data->lnotif; @@ -1663,7 +1690,10 @@ static int srchres(struct search *srch, struct srchres *sr, void *uudata) for(data = actives; data != NULL; data = data->next) { if(haspriv(data, PERM_SRCH) && data->notify.b.srch && !wcscmp(srch->owner, data->username)) - newnotif(data, 622, NOTIF_ID, srch->id, NOTIF_STR, sr->filename, NOTIF_STR, sr->fnet->name, NOTIF_STR, sr->peerid, NOTIF_INT, sr->size, NOTIF_INT, sr->slots, NOTIF_INT, (sr->fn == NULL)?-1:(sr->fn->id), NOTIF_FLOAT, sr->time, NOTIF_END); + { + newnotif(data, 622, NOTIF_ID, srch->id, NOTIF_STR, sr->filename, NOTIF_STR, sr->fnet->name, NOTIF_STR, sr->peerid, NOTIF_INT, sr->size, + NOTIF_INT, sr->slots, NOTIF_INT, (sr->fn == NULL)?-1:(sr->fn->id), NOTIF_FLOAT, sr->time, NOTIF_STR, (sr->hash == NULL)?L"":unparsehash(sr->hash), NOTIF_END); + } } return(0); } @@ -1706,7 +1736,7 @@ static int fnactive(struct fnetnode *fn, wchar_t *attrib, void *uudata) if((notif = findnotif(data->fnotif, 1, NOTIF_PEND, 605, fn->id)) != NULL) notif->argv[1].d.n = fn->numpeers; else - newnotif(data, 605, NOTIF_ID, fn->id, NOTIF_INT, fn->numpeers, NOTIF_END); + newnotif(data, 605, NOTIF_ID, fn->id, NOTIF_INT, fn->numpeers, NOTIF_END)->rlimit = 0.5; } } } @@ -1725,6 +1755,66 @@ static int fnunlink(struct fnetnode *fn, void *uudata) return(0); } +static int peernew(struct fnetnode *fn, struct fnetpeer *peer, void *uudata) +{ + struct uidata *data; + + for(data = actives; data != NULL; data = data->next) + { + if(data->notify.b.fnpeer) + newnotif(data, 630, NOTIF_INT, fn->id, NOTIF_STR, peer->id, NOTIF_STR, peer->nick, NOTIF_END); + } + return(0); +} + +static int peerdel(struct fnetnode *fn, struct fnetpeer *peer, void *uudata) +{ + struct uidata *data; + + for(data = actives; data != NULL; data = data->next) + { + if(data->notify.b.fnpeer) + newnotif(data, 631, NOTIF_INT, fn->id, NOTIF_STR, peer->id, NOTIF_END); + } + return(0); +} + +static int peerchange(struct fnetnode *fn, struct fnetpeer *peer, struct fnetpeerdi *di, void *uudata) +{ + struct uidata *data; + struct notif *notif; + wchar_t buf[32]; + + for(data = actives; data != NULL; data = data->next) + { + if(data->notify.b.fnpeer) + { + for(notif = data->fnotif; notif != NULL; notif = notif->next) + { + if((notif->code == 632) && (notif->state == NOTIF_PEND) && (notif->argv[0].d.n == fn->id) && !wcscmp(notif->argv[1].d.s, peer->id)) + break; + } + if(notif == NULL) + notif = newnotif(data, 632, NOTIF_INT, fn->id, NOTIF_STR, peer->id, NOTIF_STR, peer->nick, NOTIF_END); + notifappend(notif, NOTIF_STR, di->datum->id, NOTIF_INT, di->datum->datatype, NOTIF_END); + switch(di->datum->datatype) + { + case FNPD_INT: + notifappend(notif, NOTIF_INT, di->data.num, NOTIF_END); + break; + case FNPD_STR: + notifappend(notif, NOTIF_STR, di->data.str, NOTIF_END); + break; + case FNPD_LL: + swprintf(buf, sizeof(buf) / sizeof(*buf), L"%lli", di->data.lnum); + notifappend(notif, NOTIF_STR, buf, NOTIF_END); + break; + } + } + } + return(0); +} + static int newfnetnode(struct fnetnode *fn, void *uudata) { struct uidata *data; @@ -1737,6 +1827,9 @@ static int newfnetnode(struct fnetnode *fn, void *uudata) CBREG(fn, fnetnode_ac, fnactive, NULL, NULL); CBREG(fn, fnetnode_chat, recvchat, NULL, NULL); CBREG(fn, fnetnode_unlink, fnunlink, NULL, NULL); + CBREG(fn, fnetpeer_new, peernew, NULL, NULL); + CBREG(fn, fnetpeer_del, peerdel, NULL, NULL); + CBREG(fn, fnetpeer_chdi, peerchange, NULL, NULL); return(0); } @@ -1775,6 +1868,12 @@ static int transferchattr(struct transfer *transfer, wchar_t *attrib, void *uuda if(haspriv(data, PERM_TRANS) && data->notify.b.tract && ((transfer->owner == 0) || (transfer->owner == data->uid))) newnotif(data, 616, NOTIF_ID, transfer->id, NOTIF_STR, transfer->path, NOTIF_END); } + } else if(!wcscmp(attrib, L"hash")) { + for(data = actives; data != NULL; data = data->next) + { + if(haspriv(data, PERM_TRANS) && data->notify.b.tract && ((transfer->owner == 0) || (transfer->owner == data->uid))) + newnotif(data, 618, NOTIF_ID, transfer->id, NOTIF_STR, (transfer->hash == NULL)?L"":unparsehash(transfer->hash), NOTIF_END); + } } return(0); }