From 41ed0d5ed505e1a444d487afc4d002203344cf9b Mon Sep 17 00:00:00 2001
From: "Mirar (Pontus Hagland)" <pike@sort.mirar.org>
Date: Thu, 1 Jul 1999 14:57:26 +0200
Subject: [PATCH] docfix

Rev: lib/modules/Protocols.pmod/LysKOM.pmod/Session.pike:1.4
Rev: src/modules/Parser/html.c:1.23
---
 .../Protocols.pmod/LysKOM.pmod/Session.pike   | 192 ++++++++++++------
 src/modules/Parser/html.c                     | 138 ++++++++++---
 2 files changed, 235 insertions(+), 95 deletions(-)

diff --git a/lib/modules/Protocols.pmod/LysKOM.pmod/Session.pike b/lib/modules/Protocols.pmod/LysKOM.pmod/Session.pike
index b0c7cada40..62e0627668 100644
--- a/lib/modules/Protocols.pmod/LysKOM.pmod/Session.pike
+++ b/lib/modules/Protocols.pmod/LysKOM.pmod/Session.pike
@@ -1,4 +1,4 @@
-//  $Id: Session.pike,v 1.3 1999/06/14 13:11:23 mirar Exp $
+//  $Id: Session.pike,v 1.4 1999/07/01 12:57:26 mirar Exp $
 //! module Protocols
 //! submodule LysKOM
 //! class Session
@@ -16,7 +16,7 @@ object user; // logged in as this Person
 
 string server;
 
-int oldlevel; // level <10 protocol
+int protlevel; // level <10 protocol
 
 mapping(int:object) _text=([]);
 mapping(int:object) _person=([]);
@@ -45,7 +45,7 @@ void create(object|string _server,void|mapping options)
    {
       con        = _server->con;
       server     = _server->server;
-      oldlevel   = _server->oldlevel;
+      protlevel  = _server->protlevel;
       user       = _server->user;
       _person    = _server->_person;
       _conference= _server->_conference;
@@ -55,6 +55,8 @@ void create(object|string _server,void|mapping options)
    server=_server;
    con=Connection(_server,options);
    user=(options && options->login)?person(options->login):0;
+   protlevel=con->protocol_level;
+   werror("protocol_level is %d\n",protlevel);
 }
 
 
@@ -77,11 +79,35 @@ class MiscInfo
    array(object) foot_to=({});
    array(object) foot_in=({});
 
-   void create(array(int) a)
+   void create(void|mapping|array(int) a)
    {
       int i;
       object r;
-      for (i=0; i<sizeof(a);)
+      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);)
       {
 	 switch (a[i++])
 	 {
@@ -107,6 +133,30 @@ class MiscInfo
 	 }
       }
    }
+
+   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;
+   }
 }
 
 #define FETCHERC(WHAT,TYPE,VAR,CALL,ARGS,CONV)				\
@@ -155,14 +205,7 @@ class MiscInfo
    private void _got_##WHAT##1(mixed res)				\
    {									\
       if (objectp(res) && res->iserror)					\
-      {									\
-	 if (res->no==2)						\
-	 {								\
-	    oldlevel=1;							\
-	    fetch_##WHAT=con->async_cb_##CALL2(_got_##WHAT##2,ARGS);	\
-	 }								\
 	 err=res;							\
-      }									\
       else 								\
 	 VAR1=res;							\
       array m=fetch_##WHAT##_callbacks;					\
@@ -187,7 +230,7 @@ class MiscInfo
       }									\
       if (callback) fetch_##WHAT##_callbacks+=({callback});		\
       if (!fetch_##WHAT)						\
-	 if (oldlevel)							\
+	 if (protlevel<10)						\
 	    fetch_##WHAT=con->async_cb_##CALL2(_got_##WHAT##2,ARGS);	\
 	 else								\
 	    fetch_##WHAT=con->async_cb_##CALL1(_got_##WHAT##1,ARGS);	\
@@ -211,12 +254,6 @@ class MiscInfo
    {									\
       if (objectp(res) && res->iserror)					\
       {									\
-	 if (res->no==2)						\
-	 {								\
-	    oldlevel=1;							\
-	    fetch_##WHAT= \
-                 con->async_cb_##CALL##_old(_got_##WHAT##2,ARGS);	\
-	 }								\
 	 err=res;							\
       }									\
       else 								\
@@ -244,7 +281,7 @@ class MiscInfo
       }									\
       if (callback) fetch_##WHAT##_callbacks+=({callback});		\
       if (!fetch_##WHAT)						\
-	 if (oldlevel)							\
+	 if (protlevel<10)						\
 	    fetch_##WHAT=con->async_cb_##CALL##_old(_got_##WHAT##2,ARGS); \
 	 else								\
 	    fetch_##WHAT=con->async_cb_##CALL(_got_##WHAT##1,ARGS);	\
@@ -563,52 +600,81 @@ int(1..1) logout()
    return 1;
 }
 
-//! method object new_text(string subject,string body)
-//! method object new_text(string subject,string body,object|array(object) mottagare,object|array(object) comment_to,object|array(object) footnote_to,multiset flags)
-//! method void new_text(string subject,string body,object|array(object) mottagare,object|array(object) comment_to,object|array(object) footnote_to,multiset flags,function callback,mixed ...extra)
+//! method object create_text(string subject,string body,mapping options)
+//! method object create_text(string subject,string body,mapping options,function callback,mixed ...extra)
 //! 	Creates a new text. 
 //!
 //! 	if "callback" are given, this function will be called when the text 
-//! 	is created.
-
-object|void new_text(string subject,string body,
-		     object|array(object) mottagare,
-		     object|array(object) comment_to,
-		     object|array(object) footnote_to,
-		     multiset flags,
-		     function callback,
-		     mixed ...extra)
+//! 	is created, with the text as first argument. 
+//!	Otherwise, the new text is returned.
+//!
+//!	options is a mapping that may contain:
+//!	<data_description type=mapping>
+//!	<elem name=recpt type="Conference|array(Conference)">recipient conferences</elem>
+//!	<elem name=cc type="Conference|array(Conference)">cc-recipient conferences</elem>
+//!	<elem name=bcc type="Conference|array(Conference)">bcc-recipient conferences *</elem>
+//!	<elem></elem>
+//!	<elem name=comm_to type="Text|array(Text)">what text(s) is commented</elem>
+//!	<elem name=foot_to type="Text|array(Text)">what text(s) is footnoted</elem>
+//!	<elem></elem>
+//!	<elem name=anonymous type="int(0..1)">send text anonymously</elem>
+//!	</data-description>
+//!		
+//! note:
+//!	The above marked with a '*' is only available on a protocol 10
+//!	server. A LysKOM error will be thrown if the call fails.
+//!
+//! see also: Conference.create_text, Text.comment, Text.footnote
+
+object|void create_text(string subject,string body,
+			void|mapping options,
+			void|function callback,
+			void|mixed ...extra)
 {
+   string text=replace(subject,"\n"," ")+"\n"+body;
+   MiscInfo misc=MiscInfo(options);
+
+   if (!options) options=([]);
+   
+   return _create_text(text,misc,
+		       options->aux_info,
+		       options->anonymous,
+		       callback,@extra);
+}
+
+object|void _create_text(string textstring,
+			 MiscInfo misc,
+			 void|object aux_info,
+			 int anonymous,
+			 void|function callback,
+			 void|mixed ...extra)
+{
+   int|object res;
+   string call;
+   if (anonymous) 
+      call="create_anonymous_text";
+   else 
+      call="create_text";
+
+   if (aux_info)
+      error("unimplemented\n");
+
+   if (protlevel<10) call+="_old";
+
+   if (callback)
+   {
+      con["async_cb_"+call]
+	 (lambda(int|object res)
+	  {
+	     if (objectp(res)) return res;
+	     callback(text(res),@extra);
+	  },textstring,misc->encode());
+      return;
+   }
+
+   res=con[call](textstring,misc->encode());
+
+   if (objectp(res)) return res;
+   return text(res);
 }
 
-/*
-
-session->new_text(string subject,
-                  string message,
-                  void|object|array(object) mottagare,
-                  void|object|array(object) comment_to,
-                  void|object|array(object) footnote_to,
-                  void|multiset flags);
-
-(conf)->new_text(string subject,
-                 string message,
-                 void|object|array(object) mottagare,
-                 void|object|array(object) comment_to,
-                 void|object|array(object) footnote_to,
-                 void|multiset flags);
-
-(text)->comment(string subject,
-                string message,
-                void|object|array(object) mottagare,
-                void|object|array(object) comment_to,
-                void|object|array(object) footnote_to,
-                void|multiset flags);
-
-(text)->footnote(string subject,
-                 string message,
-                 void|object|array(object) mottagare,
-                 void|object|array(object) comment_to,
-                 void|object|array(object) footnote_to,
-                 void|multiset flags);
-
-*/
diff --git a/src/modules/Parser/html.c b/src/modules/Parser/html.c
index e6e72d1e09..bc1e55b242 100644
--- a/src/modules/Parser/html.c
+++ b/src/modules/Parser/html.c
@@ -465,21 +465,38 @@ static void html__set_entity_callback(INT32 args)
 **!
 **!	<tt>to_do</tt> can be:
 **!	<ul>
-**!	<li>a function to be called. The function is on the form
+**!	<li><b>a function</b> to be called. The function is on the form
 **!	<pre>
 **!     mixed tag_callback(object parser,mapping args,mixed ...extra)
 **!	mixed container_callback(object parser,mapping args,string cont,mixed ...extra)
 **!	mixed entity_callback(object parser,mixed ...extra)
 **!	</pre>
 **!	depending on what realm the function is called by.
-**!	<li>a string. This tag/container/entity is then replaced
+**!	<li><b>a string</b>. This tag/container/entity is then replaced
 **!	by the string.
-**!	<li>an array of functions (as above).
-**!	The functions are called with each others result from element
-**!	0 to the last element. Note that the _data_ will change,
-**!	but the argument mapping will still be the same.
-**!	(Ie, do destructive editing of the args mapping if you 
-**!	want the next callback to read it - don't just return a new tag.)
+**	<li><b>an array</b> of functions (as above).
+**	The functions are called with each others result from element
+**	0 to the last element. Note that the _data_ will change,
+**	but the argument mapping will still be the same.
+**	(Ie, do destructive editing of the args mapping if you 
+**	want the next callback to read it - don't just return a new tag.)
+**!	</ul>
+**!
+**!     The callback function can return:
+**!	<ul>
+**!	<li><b>a string</b>; this string will be pushed on the parser
+**!	stack and be parsed. Be careful not to return anything
+**!	in this way that could lead to a infinite recursion.
+**!	<li><b>an array of string(s)</b>; the element(s) of the array
+**!	is the result of the function. This will not be parsed.
+**!	This is useful for avoiding infinite recursion.
+**!	The array can be of any size, this means the empty array
+**!	is the most effective to return if you don't care about 
+**!	the result, and you don't have to concatenate any strings
+**!	yourself, if you have them in an array anyway.
+**!	<li><b>zero</b>; this means "don't do anything", ie the
+**!	item that generated the callback is left as it is, and
+**!	the parser continues.*
 **!	</ul>
 **!
 **! see also: tags, containers, entities
@@ -1866,6 +1883,49 @@ static void try_feed(int finished)
 
 /****** feed ****************************************/
 
+
+static void low_feed(struct pike_string *ps)
+{
+   f=malloc(sizeof(struct piece));
+   if (!f)
+      error("feed: out of memory\n");
+   copy_shared_string(f->s,ps);
+
+   f->next=NULL;
+
+   if (THIS->feed_end==NULL)
+   {
+      DEBUG((stderr,"  (new feed)\n"));
+      THIS->feed=THIS->feed_end=f;
+   }
+   else
+   {
+      DEBUG((stderr,"  (attached to feed end)\n"));
+      THIS->feed_end->next=f;
+      THIS->feed_end=f;
+   }
+}
+
+/*
+**! method object feed()
+**! method object feed(string s)
+**! method object feed(string s,int do_parse)
+**!	Feed new data to the <ref>Parser.HTML</ref>
+**!	object. This will start a scan and may result in
+**!	callbacks. Note that it's possible that all 
+**!	data feeded isn't processed - to do that, call
+**!	<ref>finish</ref>().
+**!
+**!	If the function is called without arguments,
+**!	no data is feeded, but the parser is run.
+**!
+**!	If the string argument is followed by a 0,
+**!	<tt>->feed(s,1);</tt>, the string is feeded,
+**!	but the parser isn't run.
+**! returns the called object
+**! see also: finish, read, feed_insert
+*/
+
 static void html_feed(INT32 args)
 {
    struct piece *f;
@@ -1877,26 +1937,8 @@ static void html_feed(INT32 args)
    if (args)
    {
       if (sp[-args].type!=T_STRING)
-	 error("feed: illegal arguments\n");
-
-      f=malloc(sizeof(struct piece));
-      if (!f)
-	 error("feed: out of memory\n");
-      copy_shared_string(f->s,sp[-args].u.string);
-
-      f->next=NULL;
-
-      if (THIS->feed_end==NULL)
-      {
-	 DEBUG((stderr,"  (new feed)\n"));
-	 THIS->feed=THIS->feed_end=f;
-      }
-      else
-      {
-	 DEBUG((stderr,"  (attached to feed end)\n"));
-	 THIS->feed_end->next=f;
-	 THIS->feed_end=f;
-      }
+	 SIMPLE_BAD_ARG_ERROR("feed",1,"string");
+      low_feed(sp[-args].u.string);
    }
 
    if (args<2 || sp[1-args].type!=T_INT || sp[1-args].u.integer)
@@ -1910,13 +1952,22 @@ static void html_feed(INT32 args)
    ref_push_object(THISOBJ);
 }
 
+/*
+**! method object feed_insert(string s)
+**!	This pushes a string on the parser stack.
+**!	(I'll write more about this mechanism later.)
+**! note: don't use
+*/
+
 static void html_feed_insert(INT32 args)
 {
    struct feed_stack *st2;
 
-   if (!args ||
-       sp[-args].type!=T_STRING)
-      error("feed_insert: illegal arguments\n");
+   if (!args)
+      SIMPLE_TOO_FEW_ARGS_ERROR("feed_insert",1);
+
+   if (!sp[-args].type!=T_STRING)
+      SIMPLE_BAD_ARG_ERROR("finish",1,"string");
 
    DEBUG((stderr,"html_feed_insert: "
 	  "pushing string (len=%d) on feedstack\n",
@@ -1952,13 +2003,36 @@ static void html_feed_insert(INT32 args)
    ref_push_object(THISOBJ);
 }
 
+/*
+**! method object finish()
+**! method object finish(string s)
+**!	Finish a parser pass. 
+**!
+**!	A string may be sent here, similar to feed().
+**!
+**! returns the called object
+*/
+
 static void html_finish(INT32 args)
 {
-   pop_n_elems(args);
+   if (args)
+   {
+      if (sp[-args].type!=T_STRING)
+	 SIMPLE_BAD_ARG_ERROR("finish",1,"string");
+      low_feed(sp[-args].u.string);
+   }
    if (THIS->feed || THIS->stack->prev) try_feed(1);
    ref_push_object(THISOBJ);
 }
 
+/*
+**! method string read()
+**! method string read(int chars)
+**!	Read parsed data from the parser object. 
+**!
+**! returns a string of parsed data
+*/
+
 static void html_read(INT32 args)
 {
    int n;
-- 
GitLab