Welcome to mirror list, hosted at ThFree Co, Russian Federation.

monodoc.asmx « webdoc - github.com/mono/mono-tools.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: eefa4cc48d4b557770af601e15d6d1720dce64d1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
<%@ WebService language="C#" class="Editing" %>

// MonoDoc Editing WebService
//
// (C) 2003 by Johannes Roith
// Author: Johannes Roith

// Client API:
//
// Editing edit = new Editing();
// Response response = edit.Submit("Johannes Roith", "johannes@jroith.de",
//                      "This is a change through monodoc editing.", xml);

// response contains:
// a server status message (response.Message)
// a statuscode (response.Status)

// Statuscodes:
//
// 1 - everything went right
// 2 - the xml is not well-formed.
// 3 - some data is missing (email, name, etc.).
// 4 - the data was already posted
// 5 - Some internal Server error


using System;
using System.Web.Services;
using System.Xml.Serialization;
using System.Xml;
using System.Text;
using System.Security.Cryptography;

[WebService(Namespace="http://www.go-mono.org/monodoc")]
public class Editing {

    [WebMethod]
    public Response Submit(string author, string email, string personalmessage, string xmldata) {

        Response response;
        string newsum = GetMd5Sum(xmldata);
        XmlElement dataroot;
        XmlDocument oldposts;
        string today = Convert.ToString(DateTime.Now.DayOfYear);

        try {


        oldposts = new XmlDocument();
        oldposts.Load("oldposts.xml");

        dataroot = oldposts.DocumentElement;

        // Eventually only block in certain time frame?
        // XmlNodeList datanodes = dataroot.SelectNodes("/oldposts/post[@date='" + today + "']");

        XmlNodeList datanodes = dataroot.SelectNodes("/oldposts/post");

        foreach(XmlNode datanode in datanodes) {
            if (datanode.Attributes["md5"].Value == newsum) {

                response = new Response();
                response.Status = 4;
                response.Message = "This was already posted.";

                return response;
            }
        }

        if (xmldata == "")
        {

            response = new Response();
            response.Status = 2;
            response.Message = "Xml not well-formed. No data was posted.";

            return response;
        }

        XmlDocument doc = new XmlDocument();
        doc.LoadXml(xmldata);

        XmlElement root = doc.DocumentElement;
        XmlNodeList nodes = root.SelectNodes("/GlobalChangeset/DocSetChangeset");

        // IMO it's best to generate different Mails for
        // different DocSets, so the correct people can get their hands on it.
        // e.g one mail for Gtk#, one for ecma docs.

        foreach (XmlNode node in nodes) {

            string datastring = "";

            XmlNodeList filenodes = node.SelectNodes("FileChangeset");


           foreach (XmlNode filenode in filenodes) {
            datastring += RenderFileSet(filenode);
           }

            string target = node.Attributes["DocSet"].Value;

            string header = "---------------------\n"
                        + "MonoDoc Change\n"
                        + "---------------------\n\n"
                        + "This mail was generated by monodoc.\n\n"
                        + "--------------------------------------------------\n"
                        + "Author: " + author + "\n"
                        + "EMail: "  + email  + "\n"
                        + "personal Message: " + personalmessage + "\n\n"
                        + "--------------------------------------------------\n\n"
                        + "Changes are listed below:\n\n"
                        + "*************************************\n\n";

            string footer = "\n\n---------------------------------------\n"
                          + "Monodoc Editing WebService";

            SendMail("Monodoc: " + target, header + datastring + footer);
        }

        }

        catch {

            response = new Response();
            response.Status = 5;
            response.Message = "An unknown error occured.";

            return response;

        }


        XmlNode rootnode = dataroot.SelectSingleNode("/oldposts");

        XmlElement newentry = oldposts.CreateElement("post");
        newentry.SetAttribute("md5", newsum);
        newentry.SetAttribute("date", today);
        rootnode.AppendChild(newentry);
        oldposts.Save("oldposts.xml");

        response = new Response();
        response.Status = 1;
        response.Message = "Your changes were sent to Mono Docs List.\n"
                        + "They will be reviewed as soon as possible.";

        return response;

    }

    string RenderFileSet(XmlNode filenode) {

    // Rendering should be improved eventually,
    // so no xml remains.

       return "FILE: " + filenode.Attributes["RealFile"] + "\n\n"
                  + filenode.InnerXml
                  + "\n\n*************************************\n\n";
    }

    public class Response {

        public int Status;
        public string Message;
    }

    public void SendMail(string subject, string body) {

        System.Web.Mail.MailMessage mailMessage = new System.Web.Mail.MailMessage();

        // NOTE: I have made this "groith@tcrz.net", 
        //       so it won't be blocked.
        //       Should be changed later.

        mailMessage.From = "groith@tcrz.net";
        mailMessage.To = "mono-docs-list@ximian.com";
        mailMessage.Subject = subject;
        mailMessage.Body = body;
        mailMessage.BodyFormat = System.Web.Mail.MailFormat.Text;

        System.Web.Mail.SmtpMail.SmtpServer = "post.tcrz.net";
        System.Web.Mail.SmtpMail.Send(mailMessage);


    }

    // from http://weblog.stevex.org/radio/stories/2002/12/08/
    //      cCodeSnippetCreatingAnMd5HashString.html

    public string GetMd5Sum(string str)
    {
        Encoder enc = System.Text.Encoding.Unicode.GetEncoder();

        byte[] unicodeText = new byte[str.Length * 2];
        enc.GetBytes(str.ToCharArray(), 0, str.Length, unicodeText, 0, true);

        MD5 md5 = new MD5CryptoServiceProvider();
        byte[] result = md5.ComputeHash(unicodeText);

        StringBuilder sb = new StringBuilder();
        for (int i=0;i<result.Length;i++)
        {
            sb.Append(result[i].ToString("X2"));
        }

        return sb.ToString();
}


}