a580e12000-09-27Fredrik Hübinette (Hubbe) #pike __REAL_VERSION__
a20af62000-09-26Fredrik Hübinette (Hubbe) 
19643a1999-06-13Mirar (Pontus Hagland) import "."; Connection con;
205f842001-04-23Henrik Grubbström (Grubba) //! This variable contains the //! @[Protocols.LysKOM.Session.Person] //! that is logged in.
3c58a22000-08-03Johan Sundström object user; // logged in as this Person
19643a1999-06-13Mirar (Pontus Hagland)  string server;
87bc7d1999-07-19Mirar (Pontus Hagland) int protlevel; // protocol level
19643a1999-06-13Mirar (Pontus Hagland)  mapping(int:object) _text=([]); mapping(int:object) _person=([]); mapping(int:object) _conference=([]);
205f842001-04-23Henrik Grubbström (Grubba) //! @decl void create(string server) //! @decl void create(string server, mapping options)
19643a1999-06-13Mirar (Pontus Hagland) //! Initializes the session object, and opens //! a connection to that server.
3c58a22000-08-03Johan Sundström //!
205f842001-04-23Henrik Grubbström (Grubba) //! @[options] is a mapping of options: //! @mapping //! @member int|string "login" //! login as this person number (get number from name). //! @member string "create" //! create a new person and login with it. //! @member string "password" //! send this login password. //! @member int(0..1) "invisible" //! if set, login invisible. //! @member int(0..65535) "port" //! server port (default is 4894). //! @member string "whoami" //! present as this user (default is from uid/getpwent and hostname). //! @endmapping
19643a1999-06-13Mirar (Pontus Hagland) //!
205f842001-04-23Henrik Grubbström (Grubba) //! @seealso //! @[Connection]
19643a1999-06-13Mirar (Pontus Hagland) void create(object|string _server,void|mapping options) { if (objectp(_server)) // clone { con = _server->con; server = _server->server;
41ed0d1999-07-01Mirar (Pontus Hagland)  protlevel = _server->protlevel;
19643a1999-06-13Mirar (Pontus Hagland)  user = _server->user; _person = _server->_person; _conference= _server->_conference; _text = _server->_text; return; } server=_server; con=Connection(_server,options); user=(options && options->login)?person(options->login):0;
41ed0d1999-07-01Mirar (Pontus Hagland)  protlevel=con->protocol_level;
87bc7d1999-07-19Mirar (Pontus Hagland)  /* setup async stuff */ con->con->add_async_callback("async-new-name",async_new_name); con->con->add_async_callback("async-leave-conf",async_leave_conf); if (protlevel>=10) { con->con->add_async_callback("async-deleted-text",async_deleted_text); con->con->add_async_callback("async-new-text",async_new_text); con->con->add_async_callback("async-new-recipient",async_new_recipient); con->con->add_async_callback("async-sub-recipient",async_sub_recipient); con->con->add_async_callback("async-new-membership", async_new_membership); } else { con->con->add_async_callback("async-new-text-old",async_new_text_old); } con->accept_async(con->con->active_asyncs()); /* create person if wanted */ if (options->create) create_person(options->create,options->password);
19643a1999-06-13Mirar (Pontus Hagland) }
87bc7d1999-07-19Mirar (Pontus Hagland) /** async callbacks from raw session **/ void async_new_name() { } void async_leave_conf() { } void async_deleted_text() { } void async_new_text() { } void async_new_recipient(int textno,int confno,array misc) { if (_text[textno]) _text[textno]->update_misc(MiscInfo(misc)); // if (_conference[confno]) _conference[confno]->new_texts(); } void async_sub_recipient(int textno,int confno,array misc) { if (_text[textno]) _text[textno]->update_misc(MiscInfo(misc)); // if (_conference[confno]) _conference[confno]->sub_text(textno); } void async_new_membership() { } void async_new_text_old() { } /** classes *********************/
19643a1999-06-13Mirar (Pontus Hagland)  class MiscInfo {
ce3fd32002-11-29Martin Nilsson  string _sprintf(int t)
be5a792000-08-05Johan Sundström  {
ce3fd32002-11-29Martin Nilsson  if(t!='O') return 0;
be5a792000-08-05Johan Sundström  array(string) to = ({}); if(sizeof(recpt)) to += ({ "To: " + String.implode_nicely(recpt->conf->no) }); if(sizeof(ccrecpt)) to += ({ "Cc: " + String.implode_nicely(ccrecpt->conf->no) }); if(sizeof(bccrecpt)) to += ({ "Bcc: " + String.implode_nicely(bccrecpt->conf->no) });
ce3fd32002-11-29Martin Nilsson  return sprintf("%O(%s)", this_program, sizeof(to) ? to * "; " : "No recipients");
be5a792000-08-05Johan Sundström  } class Recpt { object conf; int local_no; object received_at; object sent_by; object sent_at;
ce3fd32002-11-29Martin Nilsson  string _sprintf(int t)
be5a792000-08-05Johan Sundström  {
ce3fd32002-11-29Martin Nilsson  return t=='O' && sprintf("%O(conf %d: text %d)", this_program, conf && conf->no, local_no);
be5a792000-08-05Johan Sundström  } }
3c58a22000-08-03Johan Sundström 
19643a1999-06-13Mirar (Pontus Hagland)  array(Recpt) recpt=({}); array(Recpt) ccrecpt=({}); array(Recpt) bccrecpt=({}); array(object) comm_to=({}); array(object) comm_in=({}); array(object) foot_to=({}); array(object) foot_in=({});
41ed0d1999-07-01Mirar (Pontus Hagland)  void create(void|mapping|array(int) a)
19643a1999-06-13Mirar (Pontus Hagland)  { int i; object r;
41ed0d1999-07-01Mirar (Pontus Hagland)  if (mappingp(a)) { if (!a->recpt) a->recpt=a->recipient; foreach (arrayp(a->recpt)?a->recpt: a->recpt?({a->recpt}):({}),object o) r=Recpt(),r->conf=o,recpt+=({r}); foreach (arrayp(a->cc)?a->cc: a->cc?({a->cc}):({}),object o) r=Recpt(),r->conf=o,ccrecpt+=({r}); foreach (arrayp(a->bcc)?a->bcc: a->bcc?({a->bcc}):({}),object o) r=Recpt(),r->conf=o,bccrecpt+=({r}); if (a->comm_to) comm_to=(arrayp(a->comm_to)?a->comm_to:({a->comm_to})); if (a->foot_to) foot_to=(arrayp(a->foot_to)?a->foot_to:({a->foot_to})); /* if (a->comm_in) comm_in=(arrayp(a->comm_in)?a->comm_in:({a->comm_in})); if (a->foot_in) foot_in=(arrayp(a->foot_in)?a->foot_in:({a->foot_in})); */ } else if (arrayp(a)) for (i=0; i<sizeof(a);)
19643a1999-06-13Mirar (Pontus Hagland)  { switch (a[i++]) { case 0: recpt+=({r=Recpt()}); r->conf=conference(a[i++]); break;
3c58a22000-08-03Johan Sundström  case 1: ccrecpt+=({r=Recpt()});
19643a1999-06-13Mirar (Pontus Hagland)  r->conf=conference(a[i++]); break;
3c58a22000-08-03Johan Sundström  case 15: bccrecpt+=({r=Recpt()});
19643a1999-06-13Mirar (Pontus Hagland)  r->conf=conference(a[i++]); break; case 2: comm_to+=({text(a[i++])}); break; case 3: comm_in+=({text(a[i++])}); break; case 4: foot_to+=({text(a[i++])}); break; case 5: foot_in+=({text(a[i++])}); break;
3c58a22000-08-03Johan Sundström 
19643a1999-06-13Mirar (Pontus Hagland)  case 6: r->local_no=a[i++]; break;
3c58a22000-08-03Johan Sundström  case 7: r->received_at=ProtocolTypes.LysKOMTime(@a[i..i+8]);
19643a1999-06-13Mirar (Pontus Hagland)  i+=9; break; case 8: r->sent_by=person(a[i++]); break;
3c58a22000-08-03Johan Sundström  case 9: r->sent_at=ProtocolTypes.LysKOMTime(@a[i..i+8]);
19643a1999-06-13Mirar (Pontus Hagland)  i+=9; break; default: error("unexpected selection in misc_info: %d\n",a[i-1]); } } }
41ed0d1999-07-01Mirar (Pontus Hagland)  array(string) encode() { array res=({}); foreach (recpt,object r) res+=({"0 "+r->conf->no}); foreach (ccrecpt,object r) res+=({"1 "+r->conf->no}); foreach (bccrecpt,object r) res+=({"15 "+r->conf->no}); foreach (comm_to,object t) res+=({"2 "+t->no}); foreach (foot_to,object t) res+=({"4 "+t->no}); /* *** this generates illegal-misc *** foreach (comm_in,object t) res+=({"3 "+t->no}); foreach (foot_in,object t) res+=({"5 "+t->no}); */ return res; }
19643a1999-06-13Mirar (Pontus Hagland) } #define FETCHERC(WHAT,TYPE,VAR,CALL,ARGS,CONV) \
4a2c301999-10-11Johan Schön  TYPE VAR; \
19643a1999-06-13Mirar (Pontus Hagland)  private object fetch_##WHAT; \ private array(function) fetch_##WHAT##_callbacks=({}); \ \ void prefetch_##WHAT##(void|function callback) \ { \ if (VAR) \ { \
563bd72004-01-11Martin Nilsson  if (callback) callback(this); \
19643a1999-06-13Mirar (Pontus Hagland)  return; \ } \ if (callback) fetch_##WHAT##_callbacks+=({callback}); \ if (!fetch_##WHAT) \ fetch_##WHAT= \ con->async_cb_##CALL(lambda(mixed res) \ { \ if (objectp(res) && res->iserror) \ err=res; \ else \ VAR=CONV; \ fetch_##WHAT=0; \ array m=fetch_##WHAT##_callbacks; \ fetch_##WHAT##_callbacks=0; \
563bd72004-01-11Martin Nilsson  m(this); \
19643a1999-06-13Mirar (Pontus Hagland)  },ARGS); \ } \ \ inline void need_##WHAT() \ { \ if (VAR) return; \ if (!fetch_##WHAT) prefetch_##WHAT(); \ if (fetch_##WHAT) fetch_##WHAT(); \
4a2c301999-10-11Johan Schön  } \ \ inline void waitfor_##WHAT() \ { \ mixed res; \ if (VAR) return; \ res=con->##CALL(ARGS); \ if(objectp(res) && res->iserror) err=res; else VAR=CONV; \
19643a1999-06-13Mirar (Pontus Hagland)  }
4a2c301999-10-11Johan Schön 
19643a1999-06-13Mirar (Pontus Hagland) #define FETCHER(WHAT,TYPE,VAR,CALL,ARGS) \ FETCHERC(WHAT,TYPE,VAR,CALL,ARGS,res) #define FETCHER2(WHAT,TYPE1,VAR1,TYPE2,VAR2,CALL1,CALL2,ARGS) \ TYPE1 VAR1; \ TYPE2 VAR2; \ private object fetch_##WHAT; \ private array(function) fetch_##WHAT##_callbacks=({}); \ \ private void _got_##WHAT##1(mixed res) \ { \ if (objectp(res) && res->iserror) \ err=res; \ else \ VAR1=res; \ array m=fetch_##WHAT##_callbacks; \ fetch_##WHAT##_callbacks=({}); \
563bd72004-01-11Martin Nilsson  m(this); \
19643a1999-06-13Mirar (Pontus Hagland)  } \ \ private void _got_##WHAT##2(mixed res) \ { \ if (objectp(res) && res->iserror) err=res; else VAR2=res; \ array m=fetch_##WHAT##_callbacks; \ fetch_##WHAT##_callbacks=({}); \
563bd72004-01-11Martin Nilsson  m(this); \
19643a1999-06-13Mirar (Pontus Hagland)  } \ \
563bd72004-01-11Martin Nilsson  this_program prefetch_##WHAT##(void|function callback) \
19643a1999-06-13Mirar (Pontus Hagland)  { \ if (VAR1 || VAR2) \ { \
563bd72004-01-11Martin Nilsson  if (callback) callback(this); \ return this; \
19643a1999-06-13Mirar (Pontus Hagland)  } \ if (callback) fetch_##WHAT##_callbacks+=({callback}); \ if (!fetch_##WHAT) \
41ed0d1999-07-01Mirar (Pontus Hagland)  if (protlevel<10) \
19643a1999-06-13Mirar (Pontus Hagland)  fetch_##WHAT=con->async_cb_##CALL2(_got_##WHAT##2,ARGS); \ else \ fetch_##WHAT=con->async_cb_##CALL1(_got_##WHAT##1,ARGS); \
563bd72004-01-11Martin Nilsson  return this; \
19643a1999-06-13Mirar (Pontus Hagland)  } \ \ inline void need_##WHAT() \ { \ if (VAR1 || VAR2) return; \ if (!fetch_##WHAT) prefetch_##WHAT(); \ if (fetch_##WHAT) fetch_##WHAT(); \ if (fetch_##WHAT) fetch_##WHAT(); \
4a2c301999-10-11Johan Schön  } \ \ inline void waitfor_##WHAT() \ { \ mixed res; \ if(VAR1||VAR2) return; \ if(protlevel<10) \ { \ res=con->##CALL2(ARGS); \ if(objectp(res) && res->iserror) err=res; else VAR2=res; \ } \ else \ { \ res=con->##CALL1(ARGS); \ if(objectp(res) && res->iserror) err=res; else VAR1=res; \ } \
19643a1999-06-13Mirar (Pontus Hagland)  }
4a2c301999-10-11Johan Schön #define FETCHERC2b(WHAT,TYPE,VAR,CALL,ARGS,CONV) \
19643a1999-06-13Mirar (Pontus Hagland)  TYPE VAR; \ private object fetch_##WHAT; \ private array(function) fetch_##WHAT##_callbacks=({}); \ \ private void _got_##WHAT##1(mixed res) \ { \ if (objectp(res) && res->iserror) \ { \ err=res; \ } \ else \ VAR=CONV; \ array m=fetch_##WHAT##_callbacks; \ fetch_##WHAT##_callbacks=({}); \
563bd72004-01-11Martin Nilsson  m(this); \
19643a1999-06-13Mirar (Pontus Hagland)  } \ \ private void _got_##WHAT##2(mixed res) \ { \
4a2c301999-10-11Johan Schön  if (objectp(res) && res->iserror) err=res; \ else VAR=CONV; \
19643a1999-06-13Mirar (Pontus Hagland)  array m=fetch_##WHAT##_callbacks; \ fetch_##WHAT##_callbacks=({}); \
563bd72004-01-11Martin Nilsson  m(this); \
19643a1999-06-13Mirar (Pontus Hagland)  } \ \
563bd72004-01-11Martin Nilsson  this_program prefetch_##WHAT##(void|function callback) \
19643a1999-06-13Mirar (Pontus Hagland)  { \
4a2c301999-10-11Johan Schön  if (VAR) \
19643a1999-06-13Mirar (Pontus Hagland)  { \
563bd72004-01-11Martin Nilsson  if (callback) callback(this); \ return this; \
19643a1999-06-13Mirar (Pontus Hagland)  } \ if (callback) fetch_##WHAT##_callbacks+=({callback}); \ if (!fetch_##WHAT) \
41ed0d1999-07-01Mirar (Pontus Hagland)  if (protlevel<10) \
19643a1999-06-13Mirar (Pontus Hagland)  fetch_##WHAT=con->async_cb_##CALL##_old(_got_##WHAT##2,ARGS); \ else \ fetch_##WHAT=con->async_cb_##CALL(_got_##WHAT##1,ARGS); \
563bd72004-01-11Martin Nilsson  return this; \
19643a1999-06-13Mirar (Pontus Hagland)  } \ \ inline void need_##WHAT() \ { \
4a2c301999-10-11Johan Schön  if (VAR) return; \
19643a1999-06-13Mirar (Pontus Hagland)  if (!fetch_##WHAT) prefetch_##WHAT(); \ if (fetch_##WHAT) fetch_##WHAT(); \ if (fetch_##WHAT) fetch_##WHAT(); \
4a2c301999-10-11Johan Schön  } \ \ inline void waitfor_##WHAT() \ { \ mixed res; \ if(VAR) return; \ if(protlevel<10) \ res=con->##CALL_old(ARGS); \ else \ res=con->##CALL(ARGS); \ if(objectp(res) && res->iserror) err=res; else VAR=CONV; \
19643a1999-06-13Mirar (Pontus Hagland)  }
e2dc7f2000-11-11Johan Sundström constant itemname_to_tag = ([ "content-type": 1, "fast-reply": 2, "cross-reference": 3, "no-comments": 4, "personal-comment": 5, "request-confirmation": 6, "read-confirm": 7, "redirect": 8, "x-face": 9, "alternate-name": 10, "pgp-signature": 11, "pgp-public-key": 12, "e-mail-address": 13, "faq-text": 14, "creating-software": 15, "mx-author": 16, "mx-from": 17, "mx-reply-to": 18, "mx-to": 19, "mx-cc": 20, "mx-date": 21, "mx-message-id": 22, "mx-in-reply-to": 23, "mx-misc": 24, "mx-allow-filter": 25, "mx-reject-forward": 26, "notify-comments": 27, "faq-for-conf": 28, "recommended-conf": 29, "mx-mime-belongs-to": 10100, "mx-mime-part-in": 10101, "mx-mime-misc": 10102, "mx-envelope-sender": 10103, "mx-mime-file-name": 10104, ]);
3fa68a2002-01-17Martin Nilsson //! @fixme //! Undocumented
e2dc7f2000-11-11Johan Sundström class AuxItemInput { inherit ProtocolTypes.AuxItemInput; void create(string|int tag_type, multiset _flags, int _inherit_limit, string _data) { if(intp(tag_type)) tag = tag_type; else tag = itemname_to_tag[replace(tag_type, "_", "-")]; flags = _flags; inherit_limit = _inherit_limit; data = _data; }
ce3fd32002-11-29Martin Nilsson  string _sprintf(int t)
e2dc7f2000-11-11Johan Sundström  {
ce3fd32002-11-29Martin Nilsson  return t=='O' && sprintf("%O(%s)", this_program, search(itemname_to_tag, tag));
e2dc7f2000-11-11Johan Sundström  } }
bbdb9d2000-03-08Johan Schön 
3fa68a2002-01-17Martin Nilsson //! @fixme //! Undocumented
bbdb9d2000-03-08Johan Schön class AuxItems {
ce3fd32002-11-29Martin Nilsson  string _sprintf(int t)
3c58a22000-08-03Johan Sundström  {
ce3fd32002-11-29Martin Nilsson  if(t!='O') return 0;
be5a792000-08-05Johan Sundström  array desc = ({}); foreach((array)tag_to_items, [int tag, mixed item])
e2dc7f2000-11-11Johan Sundström  desc += ({ search(itemname_to_tag, tag) });
ce3fd32002-11-29Martin Nilsson  return sprintf("%O(%s)", this_program, sizeof(desc) ? String.implode_nicely(desc) : "none present");
3c58a22000-08-03Johan Sundström  }
e2dc7f2000-11-11Johan Sundström  mapping(int:array(ProtocolTypes.AuxItem)) tag_to_items = ([]);
bbdb9d2000-03-08Johan Schön  array(ProtocolTypes.AuxItem) aux_items;
3c58a22000-08-03Johan Sundström 
bbdb9d2000-03-08Johan Schön  void create(array(ProtocolTypes.AuxItem) _aux_items) { aux_items=_aux_items; foreach(aux_items, ProtocolTypes.AuxItem item) { if(tag_to_items[item->tag]) tag_to_items[item->tag] += ({ item }); else tag_to_items[item->tag] = ({ item }); } } mixed `[](string what) { switch (what) { case "create": return create; default:
e2dc7f2000-11-11Johan Sundström  return tag_to_items[itemname_to_tag[replace(what,"_","-")]] || ({ });
bbdb9d2000-03-08Johan Schön  } }
3c58a22000-08-03Johan Sundström 
be5a792000-08-05Johan Sundström  array(string) _indices() {
e2dc7f2000-11-11Johan Sundström  return ({ "create" }) + indices(itemname_to_tag);
be5a792000-08-05Johan Sundström  }
3c58a22000-08-03Johan Sundström 
be5a792000-08-05Johan Sundström  mixed `->(string what) { return `[](what); }
bbdb9d2000-03-08Johan Schön }
3fa68a2002-01-17Martin Nilsson //! All variables in this class is read only.
553c3e2002-01-16Martin Nilsson //! @fixme //! Undocumented
19643a1999-06-13Mirar (Pontus Hagland) class Text {
553c3e2002-01-16Martin Nilsson  //! The text number, as spicified to @[create]. int no; MiscInfo _misc;
b3b1d92000-04-10Johan Schön  AuxItems _aux_items;
19643a1999-06-13Mirar (Pontus Hagland) 
553c3e2002-01-16Martin Nilsson  //! Undocumented object err;
19643a1999-06-13Mirar (Pontus Hagland)  object _author;
43b5e92002-01-15Peter Bortas  //! @decl void create(string textnumber) //! Initializes a Text object.
19643a1999-06-13Mirar (Pontus Hagland)  void create(int _no) { no=_no; }
205f842001-04-23Henrik Grubbström (Grubba)  //! @ignore
19643a1999-06-13Mirar (Pontus Hagland)  FETCHERC(text,array(string),_text,get_text,@({no,0,0x7fffffff}),
205f842001-04-23Henrik Grubbström (Grubba)  array_sscanf(res,"%s\n%s"));
19643a1999-06-13Mirar (Pontus Hagland)  FETCHERC2b(stat,object,_stat,get_text_stat,@({no}),
205f842001-04-23Henrik Grubbström (Grubba)  (_misc=MiscInfo(res->misc_info),res)); //! @endignore
19643a1999-06-13Mirar (Pontus Hagland) 
87bc7d1999-07-19Mirar (Pontus Hagland)  void update_misc(MiscInfo m) { _misc=m; }
553c3e2002-01-16Martin Nilsson  //! @fixme //! Undocumented.
ea37871999-10-10Johan Schön  void mark_as_read() {
4a2c301999-10-11Johan Schön  waitfor_stat();
ea37871999-10-10Johan Schön  foreach( ({ @_misc->recpt, @_misc->ccrecpt, @_misc->bccrecpt }), object rcpt)
4a2c301999-10-11Johan Schön  catch(con->async_cb_mark_as_read(0, rcpt->conf->no, ({ rcpt->local_no })));
ea37871999-10-10Johan Schön  /* FIXME: Can't set read text in conferences the user isn't a member of -> error */ }
ce3fd32002-11-29Martin Nilsson  string _sprintf(int t)
3c58a22000-08-03Johan Sundström  {
ce3fd32002-11-29Martin Nilsson  return t=='O' && sprintf("%O(%d)", this_program, no);
3c58a22000-08-03Johan Sundström  }
553c3e2002-01-16Martin Nilsson  //! @decl mixed prefetch_text //! @decl mixed prefetch_stat //! @decl mixed lines //! @decl mixed characters //! @decl mixed clear_stat //! @decl mixed aux_items //! @fixme //! Undocumented //! @decl string text //! The actual text (or body if you wish). //! @decl string subject //! The message subject. //! @decl string author //! The author of the text. //! @decl mixed misc //! Misc info, including what conferences the message is posted to. //! @fixme //! Needs a more complete description. //! @decl int marks //! The number of marks on this text. //! @decl mixed creation_time //! The time the text was created on the server.
19643a1999-06-13Mirar (Pontus Hagland)  mixed `[](string what) { switch (what) { case "create": return create; case "prefetch_text":
5c3ad31999-10-05Johan Schön  werror("prefetch_text(%d",no);
19643a1999-06-13Mirar (Pontus Hagland)  return prefetch_text; case "prefetch_stat": return prefetch_stat; case "no": return no; case "error": return err;
3c58a22000-08-03Johan Sundström  case "text":
4a2c301999-10-11Johan Schön  waitfor_text();
19643a1999-06-13Mirar (Pontus Hagland)  return _text[1];
3c58a22000-08-03Johan Sundström  case "subject":
4a2c301999-10-11Johan Schön  waitfor_text();
19643a1999-06-13Mirar (Pontus Hagland)  return _text[0]; case "author":
4a2c301999-10-11Johan Schön  waitfor_stat();
3c58a22000-08-03Johan Sundström  return _author
19643a1999-06-13Mirar (Pontus Hagland)  || (_author=person(_stat->author)); case "misc":
4a2c301999-10-11Johan Schön  waitfor_stat();
19643a1999-06-13Mirar (Pontus Hagland)  return _misc; case "lines":
4a2c301999-10-11Johan Schön  waitfor_stat(); return _stat->no_of_lines;
19643a1999-06-13Mirar (Pontus Hagland)  case "characters":
4a2c301999-10-11Johan Schön  waitfor_stat(); return _stat->no_of_chars; case "marks": waitfor_stat(); return _stat->no_of_marks; case "creation_time": waitfor_stat(); return _stat->creation_time;
dbb0a11999-10-18Johan Schön  case "clear_stat": _stat=0; return 0;
bbdb9d2000-03-08Johan Schön  case "aux_items": waitfor_stat();
b3b1d92000-04-10Johan Schön  return _aux_items||(_aux_items=AuxItems(_stat->aux_items));
bbdb9d2000-03-08Johan Schön 
ea37871999-10-10Johan Schön  case "mark_as_read": return mark_as_read;
19643a1999-06-13Mirar (Pontus Hagland)  } } mixed `->(string what) { return `[](what); }
be5a792000-08-05Johan Sundström  array(string) _indices() { return ({ "create", "prefetch_text", "misc", "no", "prefetch_stat", "marks", "error", "characters", "lines", "text", "clear_stat", "subject", "author", "creation_time", "aux_items", "mark_as_read" }); }
19643a1999-06-13Mirar (Pontus Hagland) }
3fa68a2002-01-17Martin Nilsson //! Returns the text @[no]. Text text(int no)
19643a1999-06-13Mirar (Pontus Hagland) {
9c07f02001-09-25Johan Schön  if(_text[no]) return _text[no]; if(sizeof(_text)>1000) _text = ([]);
3524712015-05-26Martin Nilsson 
9c07f02001-09-25Johan Schön  return (_text[no]=Text(no));
19643a1999-06-13Mirar (Pontus Hagland) }
3fa68a2002-01-17Martin Nilsson //! All variables in this class is read only.
19643a1999-06-13Mirar (Pontus Hagland) class Membership {
07cfaa1999-09-28Johan Schön  int person; int newtype;
3fa68a2002-01-17Martin Nilsson  //!
3c58a22000-08-03Johan Sundström  object last_time_read;
3fa68a2002-01-17Martin Nilsson  //!
3c58a22000-08-03Johan Sundström  int(0..255) priority;
3fa68a2002-01-17Martin Nilsson  //!
3c58a22000-08-03Johan Sundström  int last_text_read;
3fa68a2002-01-17Martin Nilsson  //!
3c58a22000-08-03Johan Sundström  array(int) read_texts;
3fa68a2002-01-17Martin Nilsson 
07cfaa1999-09-28Johan Schön  int(0..65535) added_by; // new
3fa68a2002-01-17Martin Nilsson  //!
07cfaa1999-09-28Johan Schön  object added_at; // new
3fa68a2002-01-17Martin Nilsson  //!
07cfaa1999-09-28Johan Schön  multiset(string) type; // new
3fa68a2002-01-17Martin Nilsson  //!
d92afd1999-10-17Johan Schön  int position; // new
07cfaa1999-09-28Johan Schön 
3fa68a2002-01-17Martin Nilsson  //!
07cfaa1999-09-28Johan Schön  object conf;
3c58a22000-08-03Johan Sundström 
07cfaa1999-09-28Johan Schön  object err;
d92afd1999-10-17Johan Schön  void setup(object mb)
07cfaa1999-09-28Johan Schön  { last_time_read=mb->last_time_read; read_texts=mb->read_texts; last_text_read=mb->last_text_read; priority=mb->priority;
d92afd1999-10-17Johan Schön  conf=Conference(mb->conf_no);
3c58a22000-08-03Johan Sundström 
07cfaa1999-09-28Johan Schön  if (mb->type) { added_at=mb->added_at; position=mb->position; added_by=mb->added_by; type=mb->type; newtype=1; } }
d92afd1999-10-17Johan Schön  void create(object mb,int pers) { person=pers; setup(mb); }
07cfaa1999-09-28Johan Schön  // FETCHER(unread,ProtocolTypes.TextMapping,_unread,local_to_global,@({conf->no,1,255}))
3fa68a2002-01-17Martin Nilsson  //!
07cfaa1999-09-28Johan Schön  int number_unread()
3c58a22000-08-03Johan Sundström  {
07cfaa1999-09-28Johan Schön  return (conf->no_of_texts+conf->first_local_no-1) -last_text_read -sizeof(read_texts); }
3fa68a2002-01-17Martin Nilsson  //!
d92afd1999-10-17Johan Schön  void query_read_texts() { // werror("query_read_texts()\n"); // werror("read_texts: %O\n",read_texts); setup(con->query_read_texts(person,conf->no)); // werror("read_texts: %O\n",read_texts); }
3c58a22000-08-03Johan Sundström 
3fa68a2002-01-17Martin Nilsson  //! @decl array(object) unread_texts()
07cfaa1999-09-28Johan Schön  array(object) get_unread_texts_blocking() {
bbdb9d2000-03-08Johan Schön #ifdef LYSKOM_DEBUG
5c3ad31999-10-05Johan Schön  werror("get_unread_texts_blocking()\n");
3c58a22000-08-03Johan Sundström #endif
07cfaa1999-09-28Johan Schön  int i=last_text_read+1; mapping(int:int) local_to_global = ([]);
bbdb9d2000-03-08Johan Schön #ifdef LYSKOM_DEBUG
5c3ad31999-10-05Johan Schön  werror("i: %d last_text_read: %d\n",i,last_text_read);
ea37871999-10-10Johan Schön  werror("conf: %d conf->no_of_texts: %d\n",conf->no, conf->no_of_texts);
3c58a22000-08-03Johan Sundström #endif
ea37871999-10-10Johan Schön  if(i > con->get_uconf_stat(conf->no)->highest_local_no)
d92afd1999-10-17Johan Schön  return ({ }) ;
07cfaa1999-09-28Johan Schön  /* Get all the global numbers after last-text-read */ while(1) { ProtocolTypes.TextMapping textmapping=con->local_to_global(conf->no,i,255); ProtocolTypes.LocalToGlobalBlock block=textmapping->block; if(block->densep) /* Use TextList */
19643a1999-06-13Mirar (Pontus Hagland)  {
07cfaa1999-09-28Johan Schön  ProtocolTypes.TextList textlist=block->dense; int j=textmapping->range_begin;
19643a1999-06-13Mirar (Pontus Hagland) 
27ade32002-05-05Martin Stjernholm  foreach(textlist->texts, int global_text) local_to_global[j++]=global_text;
07cfaa1999-09-28Johan Schön  } else /* Use array(TextNumberPair) */
19643a1999-06-13Mirar (Pontus Hagland)  {
07cfaa1999-09-28Johan Schön  foreach(block->sparse, ProtocolTypes.TextNumberPair pair) local_to_global[pair->local_number]=pair->global_number;
19643a1999-06-13Mirar (Pontus Hagland)  }
3c58a22000-08-03Johan Sundström 
07cfaa1999-09-28Johan Schön  if(!textmapping->later_texts_exists) break; i=textmapping->range_end; } mapping unread_numbers = local_to_global - mkmapping(read_texts,allocate(sizeof(read_texts)));
d92afd1999-10-17Johan Schön  return map( sort(values(unread_numbers)), text );
07cfaa1999-09-28Johan Schön  } mixed `[](string what) { switch (what) { case "unread_texts":
d92afd1999-10-17Johan Schön  return get_unread_texts_blocking();
07cfaa1999-09-28Johan Schön  case "last_time_read": case "read_texts": case "last_text_read": case "priority": case "conf": case "added_at": case "position": case "type": case "number_unread":
d92afd1999-10-17Johan Schön  case "query_read_texts":
07cfaa1999-09-28Johan Schön  return ::`[](what); } } mixed `->(string what) { return `[](what); }
ce3fd32002-11-29Martin Nilsson  string _sprintf(int t)
3c58a22000-08-03Johan Sundström  {
ce3fd32002-11-29Martin Nilsson  return t=='O' && sprintf("%O(%d)", this_program, conf->no);
3c58a22000-08-03Johan Sundström  } array(string) _indices() { return ({ "unread_texts", "last_time_read", "read_texts", "last_text_read", "priority", "conf", "added_at", "position", "type", "number_unread", "query_read_texts" }); }
19643a1999-06-13Mirar (Pontus Hagland) }
3fa68a2002-01-17Martin Nilsson //!
19643a1999-06-13Mirar (Pontus Hagland) class Person {
3fa68a2002-01-17Martin Nilsson  //! int no;
3c58a22000-08-03Johan Sundström 
19643a1999-06-13Mirar (Pontus Hagland)  object conf; object err;
205f842001-04-23Henrik Grubbström (Grubba)  //! @ignore
19643a1999-06-13Mirar (Pontus Hagland)  FETCHER(stat,ProtocolTypes.Person,_person,get_person_stat,no); FETCHERC(unread,array(object),_unread,get_unread_confs,no, Array.map(res,conference)); FETCHERC2b(membership,array(object),_membership,get_membership, @({no,0,65535,1}), Array.map(res,Membership,no));
205f842001-04-23Henrik Grubbström (Grubba)  //! @endignore
3fa68a2002-01-17Martin Nilsson  //! @decl void create(int no)
19643a1999-06-13Mirar (Pontus Hagland)  void create(int _no) { no=_no; conf=conference(no); }
3fa68a2002-01-17Martin Nilsson  //! @decl mixed prefetch_stat //! @decl mixed prefetch_conf //! @decl mixed prefetch_membership //! @fixme //! Undocumented //! @decl object error //! @decl Text user_area //! @decl mixed username //! @decl mixed privileges //! @decl mixed flags //! @decl mixed last_login //! @decl mixed total_time_present //! @decl mixed sessions //! @decl mixed created_lines //! @decl mixed created_bytes //! @decl mixed read_texts //! @decl mixed no_of_text_fetches //! @decl mixed created_persons //! @decl mixed created_confs //! @decl mixed first_created_local_no //! @decl mixed no_of_created_texts //! @decl mixed no_of_marks //! @decl mixed no_of_confs //! @decl mixed unread //! @decl int(0..0) clear_membership //! @decl mixed membership //! @fixme //! Undocumented
19643a1999-06-13Mirar (Pontus Hagland)  mixed `[](string what) { switch (what) { case "create": return create; case "prefetch_stat": return prefetch_stat; case "prefetch_conf": return conf->prefetch_stat; case "prefetch_membership": return prefetch_membership; case "no": return no; case "error": return err; case "user_area":
4a2c301999-10-11Johan Schön  waitfor_stat();
19643a1999-06-13Mirar (Pontus Hagland)  return text(_person->user_area);
3fa68a2002-01-17Martin Nilsson  case "username":
19643a1999-06-13Mirar (Pontus Hagland)  case "privileges": case "flags": case "last_login": case "total_time_present": case "sessions": case "created_lines": case "created_bytes": case "read_texts": case "no_of_text_fetches": case "created_persons": case "created_confs": case "first_created_local_no": case "no_of_created_texts": case "no_of_marks": case "no_of_confs":
4a2c301999-10-11Johan Schön  waitfor_stat();
19643a1999-06-13Mirar (Pontus Hagland)  return _person[what]; case "unread":
4a2c301999-10-11Johan Schön  waitfor_unread();
19643a1999-06-13Mirar (Pontus Hagland)  return _unread;
dbb0a11999-10-18Johan Schön  case "clear_membership": _membership=0; return 0;
19643a1999-06-13Mirar (Pontus Hagland)  case "membership":
4a2c301999-10-11Johan Schön  waitfor_membership();
19643a1999-06-13Mirar (Pontus Hagland)  return _membership; } return conf[what]; } mixed `->(string what) { return `[](what); }
3c58a22000-08-03Johan Sundström 
ce3fd32002-11-29Martin Nilsson  string _sprintf(int t)
3c58a22000-08-03Johan Sundström  {
ce3fd32002-11-29Martin Nilsson  return t=='O' && sprintf("%O(%d)", this_program, no);
3c58a22000-08-03Johan Sundström  } array(string) _indices() { return ({ "prefetch_stat", "create", "prefetch_conf", "no", "prefetch_membership", "error", "user_area", "privileges", "username", "flags", "last_login", "total_time_present", "created_lines", "sessions", "created_bytes", "read_texts", "created_persons", "no_of_text_fetches", "created_confs", "first_created_local_no", "no_of_created_texts", "unread", "no_of_marks", "membership" "no_of_confs", "clear_membership", }) | indices(conf); }
19643a1999-06-13Mirar (Pontus Hagland) }
9eda4a2004-05-15Martin Nilsson //! Returns the @[Person] @[no].
3fa68a2002-01-17Martin Nilsson Person person(int no)
19643a1999-06-13Mirar (Pontus Hagland) { return _person[no] || (_person[no]=Person(no)); }
3fa68a2002-01-17Martin Nilsson //!
19643a1999-06-13Mirar (Pontus Hagland) class Conference {
b3b1d92000-04-10Johan Schön  int no; AuxItems _aux_items;
3c58a22000-08-03Johan Sundström 
b3b1d92000-04-10Johan Schön  private object err;
3c58a22000-08-03Johan Sundström 
205f842001-04-23Henrik Grubbström (Grubba)  //! @ignore
b3b1d92000-04-10Johan Schön  FETCHER2(stat,ProtocolTypes.Conference,_conf, ProtocolTypes.ConferenceOld,_confold, get_conf_stat,get_conf_stat_old,no)
3c58a22000-08-03Johan Sundström 
205f842001-04-23Henrik Grubbström (Grubba)  //! @endignore
3fa68a2002-01-17Martin Nilsson  //! @decl void create(int no)
b3b1d92000-04-10Johan Schön  void create(int _no) { no=_no; }
3c58a22000-08-03Johan Sundström 
9eda4a2004-05-15Martin Nilsson  //! @decl mixed prefetch_stat //! @decl int no //! @decl object error //! @decl Text msg_of_day //! @decl Conference supervisor //! @decl Conference permitted_submitters //! @decl Conference super_conf //! @decl Person creator //! @decl mixed aux_items //! @decl mixed name //! @decl mixed type //! @decl mixed creation_time //! @decl mixed last_written //! @decl mixed nice //! @decl mixed no_of_members //! @decl mixed first_local_no //! @decl mixed no_of_texts //! @decl mixed presentation //! @fixme //! Undocumented
b3b1d92000-04-10Johan Schön  mixed `[](string what) { switch (what) { case "create": return create; case "prefetch_stat": return prefetch_stat;
3c58a22000-08-03Johan Sundström 
b3b1d92000-04-10Johan Schön  case "no": return no; case "error": return err;
3c58a22000-08-03Johan Sundström 
b3b1d92000-04-10Johan Schön  // case "presentation": case "msg_of_day": waitfor_stat(); return text( (_conf||_confold)[what] ); case "supervisor": case "permitted_submitters": case "super_conf": waitfor_stat(); return conference( (_conf||_confold)[what] ); case "creator": waitfor_stat(); return person( (_conf||_confold)[what] ); case "aux_items": waitfor_stat(); return _aux_items||(_aux_items=AuxItems(_conf->aux_items)); case "name": case "type": case "creation_time": case "last_written": case "nice": case "no_of_members": case "first_local_no": case "no_of_texts": case "presentation": waitfor_stat(); return (_conf||_confold)[what];
19643a1999-06-13Mirar (Pontus Hagland)  } } mixed `->(string what) { return `[](what); }
3c58a22000-08-03Johan Sundström  array(string) _indices() { return ({ "create", "aux_items", "prefetch_stat", "no", "super_conf", "no_of_members", "error", "supervisor", "first_local_no", "name", "msg_of_day", //"presentation", "type", "no_of_texts", "creator","last_written", "nice", "creation_time", "permitted_submitters", }); }
ce3fd32002-11-29Martin Nilsson  string _sprintf(int t)
3c58a22000-08-03Johan Sundström  {
ce3fd32002-11-29Martin Nilsson  return t=='O' && sprintf("%O(%d)", this_program, no);
3c58a22000-08-03Johan Sundström  }
19643a1999-06-13Mirar (Pontus Hagland) }
3fa68a2002-01-17Martin Nilsson //! Returns conference number @[no]. Conference conference(int no)
19643a1999-06-13Mirar (Pontus Hagland) { return _conference[no] || (_conference[no]=Conference(no)); }
3fa68a2002-01-17Martin Nilsson //! Runs a LysKOM completion on the given string, //! returning an array of confzinfos of the match.
19643a1999-06-13Mirar (Pontus Hagland) array(ProtocolTypes.ConfZInfo) try_complete_person(string orig) { return con->lookup_z_name(orig,1,0); }
205f842001-04-23Henrik Grubbström (Grubba) //! @decl object login(int user_no,string password) //! @decl object login(int user_no,string password,int invisible)
e781222001-11-03Johan Sundström //! Performs a login. Throws a lyskom error if unsuccessful. //! @returns //! The session object logged in.
563bd72004-01-11Martin Nilsson this_program login(int user_no,string password, void|int invisible)
19643a1999-06-13Mirar (Pontus Hagland) { con->login(user_no,password,invisible); user=person(user_no);
563bd72004-01-11Martin Nilsson  return this;
87bc7d1999-07-19Mirar (Pontus Hagland) }
3fa68a2002-01-17Martin Nilsson //! Create a person, which will be logged in.
87bc7d1999-07-19Mirar (Pontus Hagland) //! returns the new person object object create_person(string name,string password) { if (!stringp(name)||!stringp(password)) error("bad types to create_person call\n"); return user=person(con->create_person_old(name,password));
19643a1999-06-13Mirar (Pontus Hagland) }
3fa68a2002-01-17Martin Nilsson //! Logouts from the server.
87bc7d1999-07-19Mirar (Pontus Hagland) //! returns the called object
563bd72004-01-11Martin Nilsson this_program logout()
19643a1999-06-13Mirar (Pontus Hagland) {
3c58a22000-08-03Johan Sundström  if (con)
19643a1999-06-13Mirar (Pontus Hagland)  con->logout();
563bd72004-01-11Martin Nilsson  return this;
19643a1999-06-13Mirar (Pontus Hagland) }
205f842001-04-23Henrik Grubbström (Grubba) //! @decl object create_text(string subject, string body, mapping options) //! @decl object create_text(string subject, string body, mapping options, @ //! function callback, mixed ...extra)
3c58a22000-08-03Johan Sundström //! Creates a new text.
2066191999-06-14Mirar (Pontus Hagland) //!
205f842001-04-23Henrik Grubbström (Grubba) //! if @[callback] is given, the function will be called when the text //! has been created, with the text as first argument.
41ed0d1999-07-01Mirar (Pontus Hagland) //! Otherwise, the new text is returned. //!
205f842001-04-23Henrik Grubbström (Grubba) //! @[options] is a mapping that may contain: //! @mapping //! @member Conference|array(Conference) "recpt" //! recipient conferences. //! @member Conference|array(Conference) "cc" //! cc-recipient conferences. //! @member Conference|array(Conference) "bcc" //! bcc-recipient conferences*. //! @member Text|array(Text) "comm_to" //! The text(s) to be commented. //! @member Text|array(Text) "foot_to" //! The text(s) to be footnoted. //! @member int(0..1) "anonymous" //! send text anonymously. //! @member array(AuxItemInput) "aux_items" //! AuxItems you want to set for the text*. //! @endmapping
3c58a22000-08-03Johan Sundström //!
205f842001-04-23Henrik Grubbström (Grubba) //! @note //! The items above marked with '*' are only available on protocol 10 //! servers. A LysKOM error will be thrown if the call fails.
41ed0d1999-07-01Mirar (Pontus Hagland) //!
205f842001-04-23Henrik Grubbström (Grubba) //! @seealso //! @[Conference.create_text()], @[Text.comment()], @[Text.footnote()]
41ed0d1999-07-01Mirar (Pontus Hagland) object|void create_text(string subject,string body, void|mapping options, void|function callback, void|mixed ...extra)
2066191999-06-14Mirar (Pontus Hagland) {
41ed0d1999-07-01Mirar (Pontus Hagland)  string text=replace(subject,"\n"," ")+"\n"+body; MiscInfo misc=MiscInfo(options); if (!options) options=([]);
3c58a22000-08-03Johan Sundström 
41ed0d1999-07-01Mirar (Pontus Hagland)  return _create_text(text,misc,
a41b172000-11-11Johan Sundström  options->aux_items,
41ed0d1999-07-01Mirar (Pontus Hagland)  options->anonymous, callback,@extra); } object|void _create_text(string textstring, MiscInfo misc,
e2dc7f2000-11-11Johan Sundström  void|array(AuxItemInput) aux_items,
41ed0d1999-07-01Mirar (Pontus Hagland)  int anonymous, void|function callback, void|mixed ...extra) { int|object res; string call;
3c58a22000-08-03Johan Sundström  if (anonymous)
41ed0d1999-07-01Mirar (Pontus Hagland)  call="create_anonymous_text";
3c58a22000-08-03Johan Sundström  else
41ed0d1999-07-01Mirar (Pontus Hagland)  call="create_text";
a41b172000-11-11Johan Sundström  array args = ({ textstring, misc->encode() }); if(protlevel<10) call += "_old"; else args += ({ aux_items || ({}) });
41ed0d1999-07-01Mirar (Pontus Hagland)  if (callback) { con["async_cb_"+call] (lambda(int|object res) {
a41b172000-11-11Johan Sundström  if(objectp(res)) return res;
41ed0d1999-07-01Mirar (Pontus Hagland)  callback(text(res),@extra);
a41b172000-11-11Johan Sundström  }, @args);
41ed0d1999-07-01Mirar (Pontus Hagland)  return; }
a41b172000-11-11Johan Sundström  res = con[call](@args);
41ed0d1999-07-01Mirar (Pontus Hagland)  if (objectp(res)) return res; return text(res);
2066191999-06-14Mirar (Pontus Hagland) }
19643a1999-06-13Mirar (Pontus Hagland) 
efcdbf1999-11-08Marcus Wellhardh //! Sends a message. //!
205f842001-04-23Henrik Grubbström (Grubba) //! @[options] is a mapping that may contain: //! @mapping //! @member Conference "recpt" //! recipient conference. //! @endmapping
efcdbf1999-11-08Marcus Wellhardh object|void send_message(string textstring, mapping options) { int|object res;
3c58a22000-08-03Johan Sundström 
efcdbf1999-11-08Marcus Wellhardh  if(!options) options = ([]);
3c58a22000-08-03Johan Sundström 
efcdbf1999-11-08Marcus Wellhardh  if(!options->recpt)
531b842000-11-26Martin Nilsson  res = con["async_broadcast"](textstring);
efcdbf1999-11-08Marcus Wellhardh  else
531b842000-11-26Martin Nilsson  res = con["async_send_message"](options->recpt->no, textstring);
3c58a22000-08-03Johan Sundström 
efcdbf1999-11-08Marcus Wellhardh  if (objectp(res)) return res; return text(res); }
a1574a1999-11-27Johan Schön 
3fa68a2002-01-17Martin Nilsson //!
a1574a1999-11-27Johan Schön void register_async_message_callback(function(int,int,string:void) cb) {
4fce9b1999-11-27Johan Schön  con->con->add_async_callback("async-send-message", cb);
a1574a1999-11-27Johan Schön }
3c58a22000-08-03Johan Sundström 
ce3fd32002-11-29Martin Nilsson string _sprintf(int t)
3c58a22000-08-03Johan Sundström {
6c54ac2008-05-23Henrik Grubbström (Grubba)  return t=='O' && sprintf("%O(%s)", this_program, server||"");
3c58a22000-08-03Johan Sundström }