├── .gitignore ├── AUTHORS ├── COPYING ├── ChangeLog ├── Makefile.am ├── NEWS ├── README ├── README.md ├── build └── Makefile.am ├── configure.ac ├── m4 └── .dummy ├── nsis ├── tox-prpl.nsi.in └── tox.ico ├── pixmaps ├── Makefile.am └── protocols │ ├── 16 │ └── tox.png │ ├── 22 │ └── tox.png │ ├── 32 │ └── tox.png │ └── 48 │ └── tox.png └── src └── toxprpl.c /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | 3 | Makefile 4 | *~ 5 | *.in 6 | !nsis/tox-prpl.nsi.in 7 | *.nsi 8 | 9 | # Vim 10 | *.swp 11 | 12 | # Ctags 13 | tags 14 | 15 | # Object files 16 | *.o 17 | *.lo 18 | *.a 19 | 20 | # Executables 21 | *.exe 22 | *.out 23 | *.app 24 | *.swp 25 | *.la 26 | 27 | m4/*.m4 28 | configure 29 | configure_aux 30 | Makefile.in 31 | aclocal.m4 32 | config.h* 33 | autoconfig.h* 34 | config.log 35 | config.status 36 | stamp-h1 37 | autom4te.cache 38 | libtoxcore.pc 39 | libtool 40 | 41 | .deps 42 | .libs 43 | .dirstamp 44 | 45 | compile 46 | config.sub 47 | config.guess 48 | install-sh 49 | missing 50 | depcomp 51 | ltmain.sh 52 | 53 | ar-lib 54 | 55 | INSTALL 56 | 57 | tox-prpl-*.tar.gz 58 | -------------------------------------------------------------------------------- /AUTHORS: -------------------------------------------------------------------------------- 1 | Sergey 'Jin' Bostandzhyan 2 | 3 | Tom the Dragon (TomDataworks) 4 | 5 | Felix Mauch 6 | 7 | Tox logo was taken from https://rbt.asia/boards/g/img/0352/79/1373823047559.png 8 | 9 | File transfer feature was contributed by naxuroqa: 10 | https://github.com/jin-eld/tox-prpl/pull/21 11 | -------------------------------------------------------------------------------- /COPYING: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /ChangeLog: -------------------------------------------------------------------------------- 1 | Tox Protocol Plugin For Pidgin / libpurple 2 | 3 | v0.5.1 27.11.2016 4 | * fixed compilre warnings 5 | * fixed ignoring of avatar transfers 6 | * updated configure and makefiles to get rid of the subdir objects warning 7 | 8 | v0.5.0 08.09.2016 9 | * updated to latest tox core API 10 | * fixed file transfers for the time being 11 | * auto-cancel avatar file transfers 12 | * using save file now ~/.purple/tox//tox_save.tox 13 | * buddy requests use the standard purple interface 14 | 15 | v0.4.2 29.09.2014 16 | * synted with latest tox core API 17 | * fixed NSIS installer script 18 | 19 | v0.4.1 13.07.2014 20 | * synted with latest tox core API 21 | 22 | v0.4.0 21.04.2014 23 | * fixed crash on new account creation 24 | * added typing status support, #23 25 | * sync with latest tox core API 26 | 27 | v0.3.0 20.12.2013 28 | * added support for file transfer, #21 / contribution by naxuroqa 29 | * fixed setting of username as tox nickname upon creation of new accounts 30 | * made sure account settings are not lost if Pidgin is not shut down 31 | cleanly 32 | 33 | v0.2.0 05.09.2013 34 | * fixed importing of saved accounts unter Win32, #8 35 | * sync Tox friend list with libpurple buddy list after account import, #9 36 | * implemented /nick and /myid commands, #7 37 | 38 | v0.1.0 03.09.2013 39 | * first release, more or less feature complete, covers functionality 40 | that is provided by Tox core rev 36ac8e461e9f65d99ed5da12a9c631448d24f897 41 | -------------------------------------------------------------------------------- /Makefile.am: -------------------------------------------------------------------------------- 1 | SUBDIRS=build pixmaps 2 | 3 | ACLOCAL_AMFLAGS = -I m4 4 | 5 | BUILT_SOURCES = $(top_builddir)/nsis/tox-prpl.nsi 6 | CLEANFILES = $(top_builddir)/nsis/tox-prpl.nsi 7 | EXTRA_DIST = nsis/tox.ico README 8 | 9 | if HAVE_NSIS 10 | nsis-installer: $(BUILT_SOURCES) autoconfig.h 11 | $(MAKE) $(AM_MAKEFLAGS) all-recursive 12 | $(MAKE) $(AM_MAKEFLAGS) install-recursive 13 | $(MAKENSIS) $(top_builddir)/nsis/tox-prpl.nsi 14 | else 15 | nsis-installer: 16 | @echo "makensis is not available, can't generate installer" 17 | endif 18 | 19 | clean-local: clean-nsis-installer 20 | 21 | clean-nsis-installer: 22 | -rm -f $(top_builddir)/build/tox-prpl-pidgin-$(VERSION)$(EXEEXT) 23 | 24 | .PHONY: nsis-installer clean-nsis-installer 25 | -------------------------------------------------------------------------------- /NEWS: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jin-eld/tox-prpl/d8de76a92ea3a9d2ee4d5332236b806a88bda03f/NEWS -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | tox-prpl - Tox Pidgin Protocol Plugin 2 | 3 | http://tox.dhs.org/ 4 | 5 | Dependencies 6 | 7 | * glib: should be available in the repositories of your distribution) 8 | * ncurses: should be in your repo 9 | * libpurple: https://developer.pidgin.im/) should be in your repo as well 10 | * libsodium: http://download.libsodium.org/libsodium/releases/ 11 | * Tox: https://github.com/jin-eld/ProjectTox-Core shared lib branch 12 | 13 | Additionally you will need gcc, autoconf, automake, libtool and maybe 14 | a few other things for actually compiling the code. 15 | 16 | 17 | I assume that you can install the development packages for libpurple and 18 | glib using your favorite package manager, same goes for development tools, 19 | so I'll only walk you through the steps for libsodium and Tox. 20 | 21 | Usually I prefer not to install software system wide which does not come as 22 | a distribution package (i.e. if there is no .rpm, .deb, etc.). 23 | 24 | In the example below, replace "youruser" with your actual user name. If you 25 | do not provide the prefix, the installation will go to /usr/local/ which will 26 | require root priveleges for the _make install_ step. 27 | 28 | 29 | libsodium 30 | 31 | If you cloned libsodium from git you will have to run ./autogen.sh to generate 32 | the configure script, if you downloaded a release tarball then configure will 33 | already be there. 34 | 35 | ./configure --prefix=/home/youruser/Tox/sysroot 36 | make 37 | make install 38 | 39 | This will install libsodium headers in /home/youruser/Tox/sysroot/include 40 | and the library in /home/youruser/Tox/sysroot/lib. 41 | 42 | Remember the /home/youruser/Tox/sysroot/ path, we will need it later on. 43 | 44 | 45 | Tox core 46 | 47 | Clone the repo if you did not do so already: 48 | 49 | git clone https://github.com/jin-eld/ProjectTox-Core.git 50 | cd ProjectTox-Core 51 | 52 | Generate the configure script: 53 | 54 | autoreconf -i 55 | 56 | Tell configure where to find dependencies and where to install the library, 57 | compile and install: 58 | 59 | ./configure --with-dependency-search=/home/youruser/Tox/sysroot/ --prefix=/home/youruser/Tox/sysroot/ 60 | make 61 | make install 62 | 63 | 64 | tox-prpl 65 | 66 | Clone the repo if you did not do so already: 67 | 68 | git clone https://github.com/jin-eld/tox-prpl.git 69 | cd tox-prpl 70 | 71 | Generate the configure script: 72 | 73 | autoreconf -i 74 | 75 | Tell configure where to find dependencies and where to install the plugin, 76 | compile and install: 77 | 78 | ./configure --with-dependency-search=/home/youruser/Tox/sysroot/ --prefix=/home/youruser/Tox/sysroot/ 79 | make 80 | make install 81 | 82 | Unless you also compiled pidgin and installed it in your above "sysroot", the 83 | plugin will not be found, so as a last step you need to: 84 | 85 | mkdir ~/.purple/plugins/ 86 | cp /home/youruser/Tox/sysroot/lib/purple-2/libtox.so ~/.purple/plugins/ 87 | 88 | If you used a non standard installation location for the library, as above, 89 | then you have to add it to your environment before running pidgin. 90 | 91 | In the terminal where you start pidgin (assuming bash): 92 | 93 | export LD_LIBRARY_PATH=/home/youruser/Tox/sysroot/lib 94 | 95 | Now you are ready to start pidgin and to test the plugin. 96 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ### Tox Protocol Plugin For Pidgin / libpurple - discontinued 2 | 3 | Sorry everyone, but I will not continue this project any further. I am using 4 | one of the available Tox clients with audio and video support and since I 5 | do not need the Pidgin tox plugin myself I won't spend any time on it. 6 | 7 | I'll leave this repo around in case someone wants to fork and continue, but I 8 | disabled issues and basically I won't be taking care of this code any more. 9 | -------------------------------------------------------------------------------- /build/Makefile.am: -------------------------------------------------------------------------------- 1 | TOXSOURCES = ../src/toxprpl.c 2 | 3 | libtox_la_LDFLAGS = $(EXTRA_LT_LDFLAGS) 4 | 5 | # todo: check and pass value from configure 6 | PURPLE_MAJOR_VERSION = "2" 7 | 8 | pkgdir = $(libdir)/purple-$(PURPLE_MAJOR_VERSION) 9 | 10 | pkg_LTLIBRARIES = libtox.la 11 | libtox_la_SOURCES = $(TOXSOURCES) 12 | libtox_la_CFLAGS = -I.. \ 13 | -I../src \ 14 | $(GLIB_CFLAGS) \ 15 | $(PURPLE_CFLAGS) \ 16 | $(LIBTOXCORE_CFLAGS) 17 | 18 | libtox_la_LIBADD = $(GLIB_LIBS) \ 19 | $(PURPLE_LIBS) \ 20 | $(LIBTOXCORE_LIBS) 21 | 22 | -------------------------------------------------------------------------------- /configure.ac: -------------------------------------------------------------------------------- 1 | # -*- Autoconf -*- 2 | # Process this file with autoconf to produce a configure script. 3 | 4 | AC_PREREQ([2.66]) 5 | AC_INIT([tox-prpl], [0.5.1], [jin@mediatomb.cc],[], [http://tox.dhs.org/]) 6 | AC_CONFIG_SRCDIR([src/toxprpl.c]) 7 | AC_CONFIG_HEADERS([autoconfig.h]) 8 | AM_INIT_AUTOMAKE([1.10 -Wall subdir-objects]) 9 | m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])]) 10 | AC_CONFIG_MACRO_DIR([m4]) 11 | 12 | if test "x${prefix}" = "xNONE"; then 13 | prefix="${ac_default_prefix}" 14 | fi 15 | 16 | DEPSEARCH= 17 | AC_ARG_WITH(dependency-search, 18 | AC_HELP_STRING([--with-dependency-search=DIR], 19 | [search for dependencies in DIR, i.e. look for libraries in 20 | DIR/lib and for headers in DIR/include]), 21 | [ 22 | DEPSEARCH="$withval" 23 | ] 24 | ) 25 | 26 | if test -n "$DEPSEARCH"; then 27 | CFLAGS="$CFLAGS -I$DEPSEARCH/include" 28 | CPPFLAGS="$CPPFLAGS -I$DEPSEARCH/include" 29 | LDFLAGS="$LDFLAGS -L$DEPSEARCH/lib" 30 | export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:$DEPSEARCH/lib/pkgconfig 31 | fi 32 | 33 | AC_ARG_WITH(libtoxcore-headers, 34 | AC_HELP_STRING([--with-libtoxcore-headers=DIR], 35 | [search for libtoxcore header files in DIR]), 36 | [ 37 | LIBTOXCORE_SEARCH_HEADERS="$withval" 38 | AC_MSG_NOTICE([Will search for libtoxcore header files in $withval]) 39 | ] 40 | ) 41 | 42 | AC_ARG_WITH(libtoxcore-libs, 43 | AC_HELP_STRING([--with-libtoxcore-libs=DIR], 44 | [search for libtoxcore libraries in DIR]), 45 | [ 46 | LIBTOXCORE_SEARCH_LIBS="$withval" 47 | AC_MSG_NOTICE([Will search for libtoxcore libraries in $withval]) 48 | ] 49 | ) 50 | 51 | # Checks for programs. 52 | AC_PROG_CC 53 | m4_ifdef([AM_PROG_AR], [AM_PROG_AR]) 54 | AC_PROG_INSTALL 55 | AC_PROG_LIBTOOL 56 | 57 | # Checks for libraries. 58 | AC_STRUCT_TM 59 | AC_CHECK_SIZEOF(time_t, [],[ 60 | #include 61 | #include ]) 62 | 63 | # Checks for header files. 64 | AC_CHECK_HEADERS([arpa/inet.h string.h]) 65 | 66 | # Checks for typedefs, structures, and compiler characteristics. 67 | AC_TYPE_SIZE_T 68 | AC_TYPE_UINT8_T 69 | AC_TYPE_UINT16_T 70 | AC_TYPE_UINT32_T 71 | 72 | # pkg-config checks 73 | 74 | PKG_PROG_PKG_CONFIG 75 | 76 | PKG_CHECK_MODULES(PURPLE, [purple >= 2.7.0]) 77 | 78 | PKG_CHECK_MODULES(GLIB, [glib-2.0]) 79 | 80 | PKG_CHECK_MODULES(LIBTOXCORE, [libtoxcore]) 81 | 82 | 83 | EXTRA_LT_LDFLAGS="-avoid-version" 84 | 85 | OS_PATH_SEPARATOR="/" 86 | 87 | DEPS_PATH="$prefix" 88 | 89 | WIN32="no" 90 | AC_CANONICAL_HOST 91 | case $host_os in 92 | *mingw*) 93 | WIN32="yes" 94 | EXTRA_LT_LDFLAGS="$EXTRA_LT_LDFLAGS -module -no-undefined" 95 | OS_PATH_SEPARATOR="\\" 96 | ;; 97 | *darwin* | *rhapsody* | *macosx*) 98 | ;; 99 | *) 100 | EXTRA_LT_LDFLAGS="$EXTRA_LT_LDFLAGS -module" 101 | ;; 102 | esac 103 | 104 | if test "x$WIN32" = "xyes"; then 105 | here=`pwd` 106 | $(MKDIR_P) $prefix 107 | cd $prefix 108 | DEPS_PATH=`pwd -W | $SED 's/\//\\\/g'` 109 | cd $here 110 | fi 111 | 112 | AC_SUBST(DEPS_PATH) 113 | AC_SUBST(OS_PATH_SEPARATOR) 114 | AC_SUBST(EXTRA_LT_LDFLAGS) 115 | 116 | if test "x$WIN32" = "xyes"; then 117 | AC_CHECK_LIB(ws2_32, main, 118 | [ 119 | WINSOCK2_LIBS="-lws2_32" 120 | AC_SUBST(WINSOCK2_LIBS) 121 | ], 122 | [ 123 | AC_MSG_ERROR([required library was not found on the system, please c 124 | heck your MinGW installation]) 125 | ]) 126 | 127 | AC_CHECK_HEADERS([winsock2.h ws2tcpip.h], 128 | [], 129 | [ 130 | AC_MSG_ERROR([required header was not found on the system, please check your MinGW installation]) 131 | ]) 132 | AC_DEFINE([_WIN32_WINNT], [0x501], 133 | [enable getaddrinfo/freeaddrinfo for XP and higher]) 134 | fi 135 | 136 | AC_PATH_PROG([MAKENSIS], [makensis${EXEEXT}], [no]) 137 | AM_CONDITIONAL(HAVE_NSIS, test "x$MAKENSIS" != "xno") 138 | 139 | AC_CONFIG_FILES([Makefile 140 | build/Makefile 141 | pixmaps/Makefile 142 | nsis/tox-prpl.nsi 143 | ]) 144 | AC_OUTPUT 145 | -------------------------------------------------------------------------------- /m4/.dummy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jin-eld/tox-prpl/d8de76a92ea3a9d2ee4d5332236b806a88bda03f/m4/.dummy -------------------------------------------------------------------------------- /nsis/tox-prpl.nsi.in: -------------------------------------------------------------------------------- 1 | ; The original nsi script was imported from: 2 | ; Classic Battle.net Plugin for Pidgin, GPLv3 3 | ; https://github.com/nmbook/pidgin-libbnet.git 4 | 5 | ;Include Modern UI 6 | !include "MUI2.nsh" 7 | 8 | ;---------------------------------------------------------------------------- 9 | ; Title : Go to a NSIS page 10 | ; Short Name : RelGotoPage 11 | ; Last Changed : 22/Feb/2005 12 | ; Code Type : Function 13 | ; Code Sub-Type : Special Restricted Call, One-way StrCpy Input 14 | ;---------------------------------------------------------------------------- 15 | ; Description : Makes NSIS to go to a specified page relatively from 16 | ; the current page. See this below for more information: 17 | ; "http://nsis.sf.net/wiki/Go to a NSIS page" 18 | ;---------------------------------------------------------------------------- 19 | ; Function Call : StrCpy $R9 "(number|X)" 20 | ; 21 | ; - If a number > 0: Goes foward that number of 22 | ; pages. Code of that page will be executed, not 23 | ; returning to this point. If it excess the number of 24 | ; pages that are after that page, it simulates a 25 | ; "Cancel" click. 26 | ; 27 | ; - If a number < 0: Goes back that number of pages. 28 | ; Code of that page will be executed, not returning to 29 | ; this point. If it excess the number of pages that 30 | ; are before that page, it simulates a "Cancel" click. 31 | ; 32 | ; - If X: Simulates a "Cancel" click. Code will go to 33 | ; callback functions, not returning to this point. 34 | ; 35 | ; - If 0: Continues on the same page. Code will still 36 | ; be running after the call. 37 | ; 38 | ; Call RelGotoPage 39 | ;---------------------------------------------------------------------------- 40 | ; Author : Diego Pedroso 41 | ; Author Reg. Name : deguix 42 | ;---------------------------------------------------------------------------- 43 | 44 | Function RelGotoPage 45 | IntCmp $R9 0 0 Move Move 46 | StrCmp $R9 "X" 0 Move 47 | StrCpy $R9 "120" 48 | 49 | Move: 50 | SendMessage $HWNDPARENT "0x408" "$R9" "" 51 | FunctionEnd 52 | 53 | ;General 54 | Name "Tox Protocol Plugin For Pidgin" 55 | OutFile "@top_builddir@\build\tox-prpl-pidgin-installer-@VERSION@.exe" 56 | 57 | ShowInstDetails show 58 | ShowUninstDetails show 59 | 60 | InstallDir "" 61 | 62 | Function .onInit 63 | ReadRegStr $0 HKLM "Software\Pidgin" "" 64 | IfErrors 0 NoError 65 | StrCpy $InstDir "$PROGRAMFILES\Pidgin" 66 | Goto Pass 67 | NoError: 68 | StrCpy $InstDir "$0" 69 | Pass: 70 | FunctionEnd 71 | 72 | InstallDirRegKey HKLM "SOFTWARE\pidgin\tox-prpl" "Install_Dir" 73 | 74 | ;Request application privileges for Windows Vista 75 | RequestExecutionLevel admin 76 | 77 | BrandingText "tox-prpl-pidgin @VERSION@" 78 | 79 | ;Interface Settings 80 | !define MUI_ICON @top_srcdir@@OS_PATH_SEPARATOR@nsis@OS_PATH_SEPARATOR@tox.ico 81 | 82 | !define MUI_HEADERIMAGE 83 | ;!define MUI_HEADERIMAGE_BITMAP @top_srcdir@\pixmaps\hdr.bmp 84 | ;!define MUI_WELCOMEFINISHPAGE_BITMAP @top_srcdir@\pixmaps\welcome.bmp 85 | 86 | !define MUI_FINISHPAGE_NOAUTOCLOSE 87 | !define MUI_UNFINISHPAGE_NOAUTOCLOSE 88 | 89 | !define MUI_ABORTWARNING 90 | 91 | ;Page Settings 92 | !define MUI_DIRECTORYPAGE_TEXT_TOP "The setup program will install Tox Protocol Plugin For Pidgin in the following directory. This must be the location where Pidgin is installed. If Pidgin is installed in a different directory, click the [Browse] button and locate it. Click [Install] to start the installation.$\r$\n$\r$\nWARNING: Tox core library is currently in pre-alpha state! It is possible that there are still bugs and security issues. Use for testing only!" 93 | 94 | !define MUI_DIRECTORYPAGE_TEXT_DESTINATION "Pidgin Install Directory" 95 | 96 | !define MUI_FINISHPAGE_TEXT "The Tox Protocol Plugin For Pidgin has been installed.$\r$\n$\r$\nIf Pidgin is running, you must restart it, so that the plugin gets recognized." 97 | 98 | !define MUI_FINISHPAGE_NOREBOOTSUPPORT 99 | 100 | ;Pages 101 | !insertmacro MUI_PAGE_WELCOME 102 | !insertmacro MUI_PAGE_LICENSE @top_srcdir@\COPYING 103 | !insertmacro MUI_PAGE_DIRECTORY 104 | !insertmacro MUI_PAGE_INSTFILES 105 | !insertmacro MUI_PAGE_FINISH 106 | 107 | !insertmacro MUI_UNPAGE_WELCOME 108 | !insertmacro MUI_UNPAGE_CONFIRM 109 | !insertmacro MUI_UNPAGE_INSTFILES 110 | !insertmacro MUI_UNPAGE_FINISH 111 | 112 | ;Languages 113 | !insertmacro MUI_LANGUAGE "English" 114 | 115 | ;Installer Section 116 | Section "tox-prpl" 117 | 118 | SetOutPath "$INSTDIR" 119 | 120 | IfFileExists "$INSTDIR\pidgin.exe" PidginInstalled AbortNotInstalled 121 | 122 | AbortNotInstalled: 123 | MessageBox MB_ICONSTOP "Pidgin could not be found in $\"$INSTDIR$\". Install Pidgin or select the correct location where it is installed, then try again." 124 | 125 | DetailPrint "Pidgin could not be found in $\"$INSTDIR$\"." 126 | DetailPrint "Install Pidgin or select the correct location where it is installed, then try again." 127 | StrCpy $R9 -1 128 | Call RelGotoPage 129 | Goto Exit 130 | 131 | PidginInstalled: 132 | 133 | CheckPidginOpen: 134 | Delete "plugins\libtox.dll" 135 | Delete "libtoxcore-0.dll" 136 | Delete "libsodium-4.dll" 137 | 138 | IfErrors PidginOpen 139 | Goto CreateAndContinue 140 | 141 | PidginOpen: 142 | MessageBox MB_RETRYCANCEL "The installer cannot update the plugin because Pidgin is currently running. Close Pidgin and press Retry." IDRETRY CheckPidginOpen IDCANCEL AbortCurrentlyOpen 143 | 144 | AbortCurrentlyOpen: 145 | DetailPrint "The installer cannot update the plugin because Pidgin is currently running." 146 | DetailPrint "You cancelled the operation." 147 | DetailPrint "The installer will exit." 148 | Quit 149 | 150 | CreateAndContinue: 151 | 152 | ;Store installation folder 153 | WriteRegStr HKLM "SOFTWARE\Pidgin\tox-prpl" "Install_Dir" "$INSTDIR" 154 | 155 | File "/oname=plugins\libtox.dll" @DEPS_PATH@@OS_PATH_SEPARATOR@lib@OS_PATH_SEPARATOR@purple-2@OS_PATH_SEPARATOR@libtox.dll 156 | File "/oname=libtoxcore-0.dll" @DEPS_PATH@@OS_PATH_SEPARATOR@bin@OS_PATH_SEPARATOR@libtoxcore-0.dll 157 | File "/oname=libtoxdns-0.dll" @DEPS_PATH@@OS_PATH_SEPARATOR@bin@OS_PATH_SEPARATOR@libtoxdns-0.dll 158 | File "/oname=libsodium-4.dll" @DEPS_PATH@@OS_PATH_SEPARATOR@bin@OS_PATH_SEPARATOR@libsodium-4.dll 159 | 160 | File "/oname=pixmaps\pidgin\protocols\16\tox.png" @top_srcdir@@OS_PATH_SEPARATOR@pixmaps@OS_PATH_SEPARATOR@protocols@OS_PATH_SEPARATOR@16@OS_PATH_SEPARATOR@tox.png 161 | File "/oname=pixmaps\pidgin\protocols\22\tox.png" @top_srcdir@@OS_PATH_SEPARATOR@pixmaps@OS_PATH_SEPARATOR@protocols@OS_PATH_SEPARATOR@22@OS_PATH_SEPARATOR@tox.png 162 | File "/oname=pixmaps\pidgin\protocols\48\tox.png" @top_srcdir@@OS_PATH_SEPARATOR@pixmaps@OS_PATH_SEPARATOR@protocols@OS_PATH_SEPARATOR@48@OS_PATH_SEPARATOR@tox.png 163 | 164 | ; Write the uninstall keys for Winblows 165 | WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\tox-prpl" "DisplayName" "Tox Protocol Plugin For Pidgin" 166 | WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\tox-prpl" "UninstallString" '"$INSTDIR\uninstall-tox-prpl.exe"' 167 | WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\tox-prpl" "NoModify" 1 168 | WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\tox-prpl" "NoRepair" 1 169 | WriteUninstaller "uninstall-tox-prpl.exe" 170 | Exit: 171 | SectionEnd 172 | 173 | ;Uninstaller Section 174 | Section "Uninstall" 175 | 176 | DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\tox-prpl" 177 | DeleteRegKey HKLM SOFTWARE\Pidgin\tox-prpl 178 | Delete "$INSTDIR\plugins\libtox.dll" 179 | 180 | Delete "$INSTDIR\libtoxcore-0.dll" 181 | Delete "$INSTDIR\libtoxdns-0.dll" 182 | Delete "$INSTDIR\libsodium-4.dll" 183 | 184 | Delete "$INSTDIR\pixmaps\pidgin\protocols\16\tox.png" 185 | Delete "$INSTDIR\pixmaps\pidgin\protocols\22\tox.png" 186 | Delete "$INSTDIR\pixmaps\pidgin\protocols\48\tox.png" 187 | 188 | Delete "$INSTDIR\uninstall-tox-prpl.exe" 189 | 190 | SectionEnd 191 | -------------------------------------------------------------------------------- /nsis/tox.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jin-eld/tox-prpl/d8de76a92ea3a9d2ee4d5332236b806a88bda03f/nsis/tox.ico -------------------------------------------------------------------------------- /pixmaps/Makefile.am: -------------------------------------------------------------------------------- 1 | toxprplpixmapdir = $(datadir)/pixmaps/pidgin 2 | nobase_dist_toxprplpixmap_DATA = \ 3 | protocols/16/tox.png \ 4 | protocols/22/tox.png \ 5 | protocols/32/tox.png \ 6 | protocols/48/tox.png 7 | 8 | -------------------------------------------------------------------------------- /pixmaps/protocols/16/tox.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jin-eld/tox-prpl/d8de76a92ea3a9d2ee4d5332236b806a88bda03f/pixmaps/protocols/16/tox.png -------------------------------------------------------------------------------- /pixmaps/protocols/22/tox.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jin-eld/tox-prpl/d8de76a92ea3a9d2ee4d5332236b806a88bda03f/pixmaps/protocols/22/tox.png -------------------------------------------------------------------------------- /pixmaps/protocols/32/tox.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jin-eld/tox-prpl/d8de76a92ea3a9d2ee4d5332236b806a88bda03f/pixmaps/protocols/32/tox.png -------------------------------------------------------------------------------- /pixmaps/protocols/48/tox.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jin-eld/tox-prpl/d8de76a92ea3a9d2ee4d5332236b806a88bda03f/pixmaps/protocols/48/tox.png -------------------------------------------------------------------------------- /src/toxprpl.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013 Sergey 'Jin' Bostandzhyan 3 | * 4 | * tox-prlp - libpurple protocol plugin or Tox (see http://tox.im) 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | * This plugin is based on the Nullprpl mockup from Pidgin / Finch / libpurple 20 | * which is disributed under GPL v2 or later. See http://pidgin.im/ 21 | */ 22 | 23 | #ifdef HAVE_CONFIG_H 24 | #include "autoconfig.h" 25 | #endif 26 | 27 | #include 28 | #include 29 | #include 30 | 31 | #include 32 | #include 33 | #ifdef __WIN32__ 34 | #include 35 | #include 36 | #else 37 | #include 38 | #include 39 | #include 40 | #endif 41 | 42 | #ifndef O_BINARY 43 | #ifdef _O_BINARY 44 | #define O_BINARY _O_BINARY 45 | #else 46 | #define O_BINARY 0 47 | #endif 48 | #endif 49 | 50 | #include 51 | #include 52 | 53 | #include 54 | #include 55 | 56 | #include 57 | #include 58 | 59 | #define PURPLE_PLUGINS 60 | 61 | #include 62 | #include 63 | #include 64 | #include 65 | #include 66 | #include 67 | #include 68 | #include 69 | #include 70 | #include 71 | #include 72 | #include 73 | #include 74 | #include 75 | #include 76 | 77 | #define _(msg) msg /* might add gettext later */ 78 | 79 | #define TOX_ID_SIZE 64 80 | #define TOXPRPL_ID "prpl-jin_eld-tox" 81 | #define DEFAULT_SERVER_KEY "A09162D68618E742FFBCA1C2C70385E6679604B2D80EA6E84AD0996A1AC8A074" 82 | #define DEFAULT_SERVER_PORT 33445 83 | #define DEFAULT_SERVER_IP "tox.zodiaclabs.org" 84 | #define DEFAULT_ACCOUNT_PATH "toxedpidgin" 85 | 86 | #define DEFAULT_REQUEST_MESSAGE _("Please allow me to add you as a friend!") 87 | 88 | #define MAX_ACCOUNT_DATA_SIZE 1*1024*1024 89 | 90 | #define DEFAULT_NICKNAME "ToxedPidgin" 91 | 92 | #define toxprpl_return_val_if_fail(expr,val) \ 93 | if (!(expr)) \ 94 | { \ 95 | return (val); \ 96 | } 97 | 98 | #define toxprpl_return_if_fail(expr) \ 99 | if (!(expr)) \ 100 | { \ 101 | return; \ 102 | } 103 | 104 | static const char *g_HEX_CHARS = "0123456789abcdef"; 105 | 106 | typedef struct 107 | { 108 | PurpleStatusPrimitive primitive; 109 | uint8_t tox_status; 110 | gchar *id; 111 | gchar *title; 112 | } toxprpl_status; 113 | 114 | typedef struct 115 | { 116 | int tox_friendlist_number; 117 | } toxprpl_buddy_data; 118 | 119 | typedef struct 120 | { 121 | PurpleConnection *gc; 122 | char *buddy_key; 123 | } toxprpl_accept_friend_data; 124 | 125 | typedef struct 126 | { 127 | Tox *tox; 128 | guint tox_timer; 129 | guint connection_timer; 130 | guint connected; 131 | PurpleCmdId myid_command_id; 132 | PurpleCmdId nick_command_id; 133 | } toxprpl_plugin_data; 134 | 135 | typedef struct 136 | { 137 | PurpleXfer *xfer; 138 | uint8_t *buffer; 139 | uint8_t *offset; 140 | gboolean running; 141 | } toxprpl_idle_write_data; 142 | 143 | typedef struct 144 | { 145 | Tox *tox; 146 | uint32_t friendnumber; 147 | uint32_t filenumber; 148 | toxprpl_idle_write_data *idle_write_data; 149 | uint8_t *file_id; 150 | } toxprpl_xfer_data; 151 | 152 | typedef struct 153 | { 154 | bool exists; 155 | gsize size; 156 | guchar* account_data; 157 | } toxprpl_profile_data; 158 | 159 | #define TOXPRPL_MAX_STATUS 4 160 | #define TOXPRPL_STATUS_ONLINE 0 161 | #define TOXPRPL_STATUS_AWAY 1 162 | #define TOXPRPL_STATUS_BUSY 2 163 | #define TOXPRPL_STATUS_OFFLINE 3 164 | 165 | static toxprpl_status toxprpl_statuses[] = 166 | { 167 | { 168 | PURPLE_STATUS_AVAILABLE, TOXPRPL_STATUS_ONLINE, 169 | "tox_online", _("Online") 170 | }, 171 | { 172 | PURPLE_STATUS_AWAY, TOXPRPL_STATUS_AWAY, 173 | "tox_away", _("Away") 174 | }, 175 | { 176 | PURPLE_STATUS_UNAVAILABLE, TOXPRPL_STATUS_BUSY, 177 | "tox_busy", _("Busy") 178 | }, 179 | { 180 | PURPLE_STATUS_OFFLINE, TOXPRPL_STATUS_OFFLINE, 181 | "tox_offline", _("Offline") 182 | } 183 | }; 184 | 185 | /* 186 | * stores offline messages that haven't been delivered yet. maps username 187 | * (char *) to GList * of GOfflineMessages. initialized in toxprpl_init. 188 | */ 189 | GHashTable* goffline_messages = NULL; 190 | 191 | typedef struct 192 | { 193 | char *from; 194 | char *message; 195 | time_t mtime; 196 | PurpleMessageFlags flags; 197 | } GOfflineMessage; 198 | 199 | static void toxprpl_login(PurpleAccount *acct); 200 | static void toxprpl_query_buddy_info(gpointer data, gpointer user_data); 201 | static void toxprpl_set_status(PurpleAccount *account, PurpleStatus *status); 202 | static PurpleXfer *toxprpl_new_xfer_receive(PurpleConnection *gc, 203 | const char *who, 204 | uint32_t friendnumber, 205 | uint32_t filenumber, 206 | const goffset filesize, 207 | const char *filename); 208 | static void toxprpl_user_export(PurpleConnection *gc, const char *filename); 209 | static void toxprpl_user_import(PurpleAccount *acct, const char *filename, 210 | toxprpl_profile_data* profile); 211 | 212 | // utilitis 213 | #define PATH_MAX_STRING_SIZE 256 214 | 215 | void toxprpl_err_friend_add(TOX_ERR_FRIEND_ADD err, PurpleConnection *gc) 216 | { 217 | const char* msg; 218 | switch (err) 219 | { 220 | case TOX_ERR_FRIEND_ADD_NULL: 221 | msg = "One of the arguments to the function was NULL when it was " 222 | "not expected."; 223 | break; 224 | case TOX_ERR_FRIEND_ADD_TOO_LONG: 225 | msg = "The length of the friend request message exceededs maximum " 226 | "allowed size."; 227 | break; 228 | case TOX_ERR_FRIEND_ADD_NO_MESSAGE: 229 | msg = "The friend request message was empty."; 230 | break; 231 | case TOX_ERR_FRIEND_ADD_OWN_KEY: 232 | msg = "The friend address belongs to the sending client."; 233 | break; 234 | case TOX_ERR_FRIEND_ADD_ALREADY_SENT: 235 | msg = "A friend request has already been sent, or you already have " 236 | "this account on your friends list."; 237 | break; 238 | case TOX_ERR_FRIEND_ADD_BAD_CHECKSUM: 239 | msg = "The friend address checksum failed."; 240 | break; 241 | case TOX_ERR_FRIEND_ADD_SET_NEW_NOSPAM: 242 | msg = "The friend was already there, but the nospam value was " 243 | "different."; 244 | break; 245 | case TOX_ERR_FRIEND_ADD_MALLOC: 246 | msg = "A memory allocation failed when trying to increase the " 247 | "friends list size."; 248 | break; 249 | default: 250 | break; 251 | } 252 | 253 | if (err != TOX_ERR_FRIEND_ADD_OK) 254 | { 255 | purple_notify_error(gc, _("Error"), msg, NULL); 256 | } 257 | } 258 | 259 | void toxprpl_err_file_control(TOX_ERR_FILE_CONTROL err, PurpleConnection* gc) 260 | { 261 | const char* msg; 262 | switch (err) 263 | { 264 | case TOX_ERR_FILE_CONTROL_FRIEND_NOT_FOUND: 265 | msg = "File transfer failed: Friend not found."; 266 | break; 267 | case TOX_ERR_FILE_CONTROL_FRIEND_NOT_CONNECTED: 268 | msg = "File transfer failed: Friend is not online."; 269 | break; 270 | case TOX_ERR_FILE_CONTROL_NOT_FOUND: 271 | msg = "File transfer failed: Invalid filenumber."; 272 | break; 273 | case TOX_ERR_FILE_CONTROL_SENDQ: 274 | msg = "File transfer failed: Connection error."; 275 | break; 276 | default: 277 | msg = "File transfer failed: Other error."; 278 | break; 279 | } 280 | 281 | purple_notify_error(gc, _("Error"), msg, NULL); 282 | } 283 | 284 | // returned buffer must be freed by the caller 285 | static char *toxprpl_data_to_hex_string(const unsigned char *data, 286 | const size_t len) 287 | { 288 | unsigned char *chars; 289 | unsigned char hi, lo; 290 | size_t i; 291 | char *buf = malloc((len * 2) + 1); 292 | char *p = buf; 293 | chars = (unsigned char *)data; 294 | chars = (unsigned char *)data; 295 | for (i = 0; i < len; i++) 296 | { 297 | unsigned char c = chars[i]; 298 | hi = c >> 4; 299 | lo = c & 0xF; 300 | *p = g_HEX_CHARS[hi]; 301 | p++; 302 | *p = g_HEX_CHARS[lo]; 303 | p++; 304 | } 305 | buf[len*2] = '\0'; 306 | return buf; 307 | } 308 | 309 | unsigned char *toxprpl_hex_string_to_data(const char *s) 310 | { 311 | size_t len = strlen(s); 312 | unsigned char *buf = malloc(len / 2); 313 | unsigned char *p = buf; 314 | 315 | size_t i; 316 | for (i = 0; i < len; i += 2) 317 | { 318 | const char *chi = strchr(g_HEX_CHARS, g_ascii_tolower(s[i])); 319 | const char *clo = strchr(g_HEX_CHARS, g_ascii_tolower(s[i + 1])); 320 | int hi, lo; 321 | if (chi) 322 | { 323 | hi = chi - g_HEX_CHARS; 324 | } 325 | else 326 | { 327 | hi = 0; 328 | } 329 | 330 | if (clo) 331 | { 332 | lo = clo - g_HEX_CHARS; 333 | } 334 | else 335 | { 336 | lo = 0; 337 | } 338 | 339 | unsigned char ch = (unsigned char)(hi << 4 | lo); 340 | *p = ch; 341 | p++; 342 | } 343 | return buf; 344 | } 345 | 346 | // stay independent from the lib 347 | static int toxprpl_get_status_index(Tox *tox, int fnum, TOX_USER_STATUS status) 348 | { 349 | switch (status) 350 | { 351 | case TOX_USER_STATUS_AWAY: 352 | return TOXPRPL_STATUS_AWAY; 353 | case TOX_USER_STATUS_BUSY: 354 | return TOXPRPL_STATUS_BUSY; 355 | case TOX_USER_STATUS_NONE: 356 | default: 357 | if (fnum != -1) 358 | { 359 | TOX_ERR_FRIEND_QUERY err_bak; 360 | if (tox_friend_get_connection_status(tox, fnum, &err_bak) 361 | != TOX_CONNECTION_NONE) 362 | { 363 | return TOXPRPL_STATUS_ONLINE; 364 | } 365 | } 366 | } 367 | return TOXPRPL_STATUS_OFFLINE; 368 | } 369 | 370 | static bool toxprpl_get_tox_status_from_id(const char *status_id, 371 | TOX_USER_STATUS *status_out) 372 | { 373 | int i; 374 | for (i = 0; i < TOXPRPL_MAX_STATUS; i++) 375 | { 376 | if (strcmp(toxprpl_statuses[i].id, status_id) == 0) 377 | { 378 | *status_out = toxprpl_statuses[i].tox_status; 379 | return true; 380 | } 381 | } 382 | return false; 383 | } 384 | 385 | /* tox helpers */ 386 | static gchar *toxprpl_tox_bin_id_to_string(const uint8_t *bin_id) 387 | { 388 | return toxprpl_data_to_hex_string(bin_id, TOX_PUBLIC_KEY_SIZE); 389 | } 390 | 391 | static gchar *toxprpl_tox_friend_id_to_string(uint8_t *bin_id) 392 | { 393 | return toxprpl_data_to_hex_string(bin_id, TOX_ADDRESS_SIZE); 394 | } 395 | 396 | /* tox specific stuff */ 397 | static void on_connectionstatus(Tox *tox, uint32_t fnum, TOX_CONNECTION status, 398 | void *user_data) 399 | { 400 | PurpleConnection *gc = (PurpleConnection *)user_data; 401 | int tox_status = TOXPRPL_STATUS_OFFLINE; 402 | if (status != TOX_CONNECTION_NONE) 403 | { 404 | tox_status = TOXPRPL_STATUS_ONLINE; 405 | } 406 | 407 | purple_debug_info("toxprpl", "Friend status change: %d\n", status); 408 | uint8_t public_key[TOX_PUBLIC_KEY_SIZE]; 409 | TOX_ERR_FRIEND_GET_PUBLIC_KEY err_back; 410 | // ToDo: Hanndle err_back 411 | if (tox_friend_get_public_key(tox, fnum, public_key, &err_back) != true) 412 | { 413 | purple_debug_info("toxprpl", "Could not get id of friend #%d\n", 414 | fnum); 415 | return; 416 | } 417 | 418 | gchar *buddy_key = toxprpl_tox_bin_id_to_string(public_key); 419 | PurpleAccount *account = purple_connection_get_account(gc); 420 | purple_prpl_got_user_status(account, buddy_key, 421 | toxprpl_statuses[tox_status].id, NULL); 422 | g_free(buddy_key); 423 | } 424 | 425 | static void on_request(struct Tox *tox, const uint8_t *public_key, 426 | const uint8_t *data, size_t length, void *user_data) 427 | { 428 | purple_debug_info("toxprpl", "incoming friend request!\n"); 429 | PurpleConnection *gc = (PurpleConnection *)user_data; 430 | 431 | gchar *buddy_key = toxprpl_tox_bin_id_to_string(public_key); 432 | purple_debug_info("toxprpl", "Buddy request from %s: %s\n", 433 | buddy_key, data); 434 | 435 | PurpleAccount *account = purple_connection_get_account(gc); 436 | PurpleBuddy *buddy = purple_find_buddy(account, buddy_key); 437 | if (buddy != NULL) 438 | { 439 | purple_debug_info("toxprpl", "Buddy %s already in buddy list!\n", 440 | buddy_key); 441 | g_free(buddy_key); 442 | return; 443 | } 444 | 445 | gchar *request_msg = NULL; 446 | if (length > 0) 447 | { 448 | request_msg = g_strndup((const gchar *)data, length); 449 | } 450 | 451 | purple_account_request_authorization(account, buddy_key, NULL, NULL, NULL, 452 | 0, NULL, NULL, NULL); 453 | g_free(request_msg); 454 | } 455 | 456 | static void on_incoming_message(Tox *tox, uint32_t friendnum, 457 | TOX_MESSAGE_TYPE type, 458 | const uint8_t *string, 459 | size_t length, void *user_data) 460 | { 461 | /* TODO: Review if/else for overlapping content */ 462 | 463 | if (type == TOX_MESSAGE_TYPE_NORMAL) 464 | { 465 | purple_debug_info("toxprpl", "Message received!\n"); 466 | PurpleConnection *gc = (PurpleConnection *)user_data; 467 | 468 | uint8_t public_key[TOX_PUBLIC_KEY_SIZE]; 469 | TOX_ERR_FRIEND_GET_PUBLIC_KEY err_back; 470 | /* TODO: Hanndle err_back */ 471 | if (tox_friend_get_public_key(tox, friendnum, public_key, 472 | &err_back) != true) 473 | { 474 | purple_debug_info("toxprpl", "Could not get id of friend %d\n", 475 | friendnum); 476 | return; 477 | } 478 | 479 | gchar *buddy_key = toxprpl_tox_bin_id_to_string(public_key); 480 | gchar *safemsg = g_strndup((const char *)string, length); 481 | serv_got_im(gc, buddy_key, safemsg, PURPLE_MESSAGE_RECV, time(NULL)); 482 | g_free(buddy_key); 483 | g_free(safemsg); 484 | } 485 | else if (type == TOX_MESSAGE_TYPE_ACTION) 486 | { 487 | purple_debug_info("toxprpl", "action received\n"); 488 | PurpleConnection *gc = (PurpleConnection *)user_data; 489 | 490 | uint8_t public_key[TOX_PUBLIC_KEY_SIZE]; 491 | TOX_ERR_FRIEND_GET_PUBLIC_KEY err_back; 492 | /*TODO: Handle err_back */ 493 | if (tox_friend_get_public_key(tox, friendnum, public_key, 494 | &err_back) != true ) 495 | { 496 | purple_debug_info("toxprpl", "Could not get id of friend %d\n", 497 | friendnum); 498 | return; 499 | } 500 | 501 | gchar *buddy_key = toxprpl_tox_bin_id_to_string(public_key); 502 | gchar *safemsg = g_strndup((const char *)string, length); 503 | gchar *message = g_strdup_printf("/me %s", safemsg); 504 | g_free(safemsg); 505 | 506 | serv_got_im(gc, buddy_key, message, PURPLE_MESSAGE_RECV, time(NULL)); 507 | g_free(buddy_key); 508 | g_free(message); 509 | } 510 | } 511 | 512 | static void on_nick_change(Tox *tox, uint32_t friendnum, const uint8_t *data, 513 | size_t length, void *user_data) 514 | { 515 | purple_debug_info("toxprpl", "Nick change!\n"); 516 | 517 | PurpleConnection *gc = (PurpleConnection *)user_data; 518 | 519 | uint8_t public_key[TOX_PUBLIC_KEY_SIZE]; 520 | TOX_ERR_FRIEND_GET_PUBLIC_KEY err_back; 521 | // ToDo: Hanndle err_back 522 | if (tox_friend_get_public_key(tox, friendnum, public_key, 523 | &err_back) != true) 524 | { 525 | purple_debug_info("toxprpl", "Could not get id of friend %d\n", 526 | friendnum); 527 | return; 528 | } 529 | 530 | gchar *buddy_key = toxprpl_tox_bin_id_to_string(public_key); 531 | PurpleAccount *account = purple_connection_get_account(gc); 532 | PurpleBuddy *buddy = purple_find_buddy(account, buddy_key); 533 | if (buddy == NULL) 534 | { 535 | purple_debug_info("toxprpl", "Ignoring nick change because buddy %s " 536 | "was not found\n", buddy_key); 537 | g_free(buddy_key); 538 | return; 539 | } 540 | 541 | g_free(buddy_key); 542 | gchar *safedata = g_strndup((const char *)data, length); 543 | purple_blist_alias_buddy(buddy, safedata); 544 | g_free(safedata); 545 | } 546 | 547 | static void on_status_change(struct Tox *tox, uint32_t friendnum, 548 | TOX_USER_STATUS userstatus, 549 | void *user_data) 550 | { 551 | purple_debug_info("toxprpl", "Status change: %d\n", userstatus); 552 | uint8_t public_key[TOX_PUBLIC_KEY_SIZE]; 553 | TOX_ERR_FRIEND_GET_PUBLIC_KEY err_back; 554 | // ToDo: Hanndle err_back 555 | if (tox_friend_get_public_key(tox, friendnum, public_key, 556 | &err_back) != true) 557 | { 558 | purple_debug_info("toxprpl", "Could not get id of friend %d\n", 559 | friendnum); 560 | return; 561 | } 562 | 563 | gchar *buddy_key = toxprpl_tox_bin_id_to_string(public_key); 564 | 565 | PurpleConnection *gc = (PurpleConnection *)user_data; 566 | PurpleAccount *account = purple_connection_get_account(gc); 567 | 568 | char* status = toxprpl_statuses[ 569 | toxprpl_get_status_index(tox, friendnum, userstatus)].id; 570 | purple_debug_info("toxprpl", "Setting user status for user %s to %s\n", 571 | buddy_key, status); 572 | purple_prpl_got_user_status(account, buddy_key, status, NULL); 573 | g_free(buddy_key); 574 | } 575 | 576 | /* TODO: create an inverted table to speed this up */ 577 | static PurpleXfer *toxprpl_find_xfer(PurpleConnection *gc, 578 | uint32_t friendnumber, uint32_t filenumber) 579 | { 580 | PurpleAccount *account = purple_connection_get_account(gc); 581 | toxprpl_return_val_if_fail(account != NULL, NULL); 582 | GList *xfers = purple_xfers_get_all(); 583 | toxprpl_return_val_if_fail(xfers != NULL, NULL); 584 | 585 | while (xfers != NULL && xfers->data != NULL) 586 | { 587 | PurpleXfer *xfer = xfers->data; 588 | toxprpl_xfer_data *xfer_data = xfer->data; 589 | if (xfer_data != NULL && 590 | xfer_data->friendnumber == friendnumber && 591 | xfer_data->filenumber == filenumber) 592 | { 593 | return xfer; 594 | } 595 | xfers = g_list_next(xfers); 596 | } 597 | return NULL; 598 | } 599 | 600 | void on_file_chunk_request(Tox *m, uint32_t friendnum, uint32_t filenum, 601 | uint64_t position, size_t length, void *userdata) 602 | { 603 | //purple_debug_info("toxprpl", "on_file_chunk_request\n"); 604 | PurpleConnection *gc = userdata; 605 | toxprpl_return_if_fail(gc != NULL); 606 | 607 | PurpleXfer* xfer = toxprpl_find_xfer(gc, friendnum, filenum); 608 | if (length == 0) 609 | { 610 | purple_debug_info("toxprpl", "file successfully sent.\n"); 611 | purple_xfer_set_completed(xfer, TRUE); 612 | purple_xfer_end(xfer); 613 | return; 614 | } 615 | 616 | FILE* fp = fopen(xfer->local_filename, "r"); 617 | if (fp == NULL) 618 | { 619 | purple_debug_info("toxprpl", "file could not be opened.\n"); 620 | return; 621 | } 622 | 623 | if (ftello(fp) != position) 624 | { 625 | while (fseeko(fp, position, SEEK_SET) == -1) 626 | { 627 | if (errno != EAGAIN) 628 | { 629 | perror("toxprpl: file"); 630 | return; 631 | } 632 | } 633 | } 634 | xfer->bytes_sent = position; 635 | 636 | uint8_t send_data[length]; 637 | size_t send_length = fread(send_data, 1, sizeof(send_data), fp); 638 | if (send_length != length) 639 | { 640 | purple_debug_info("toxprpl", "file read fail\n"); 641 | fclose(fp); 642 | return; 643 | } 644 | fclose(fp); 645 | 646 | TOX_ERR_FILE_SEND_CHUNK err; 647 | tox_file_send_chunk(m, friendnum, filenum, position, send_data, 648 | send_length, &err); 649 | if (err != TOX_ERR_FILE_SEND_CHUNK_OK) 650 | { 651 | purple_debug_info("toxprpl", "file chunk send fail\n"); 652 | } 653 | xfer->bytes_sent += send_length; 654 | purple_xfer_update_progress(xfer); 655 | } 656 | 657 | void on_file_recv_chunk(Tox *m, uint32_t friendnum, uint32_t filenum, 658 | uint64_t position, const uint8_t* data, 659 | size_t length, void *userdata) 660 | { 661 | /* purple_debug_info("toxprpl", "on_file_recv_chunk\n"); */ 662 | PurpleConnection *gc = userdata; 663 | toxprpl_return_if_fail(gc != NULL); 664 | 665 | PurpleXfer* xfer = toxprpl_find_xfer(gc, friendnum, filenum); 666 | if (length == 0) 667 | { 668 | purple_debug_info("toxprpl", "file successfully received.\n"); 669 | purple_xfer_set_completed(xfer, TRUE); 670 | purple_xfer_end(xfer); 671 | return; 672 | } 673 | 674 | FILE* fp = fopen(xfer->local_filename, "a"); 675 | if (fp == NULL) 676 | { 677 | purple_debug_info("toxprpl", "file could not be opened for writing.\n"); 678 | return; 679 | } 680 | 681 | while (fwrite(data, length, 1, fp) == -1) 682 | { 683 | if (errno != EAGAIN) 684 | { 685 | perror("toxprpl: file"); 686 | fclose(fp); 687 | return; 688 | } 689 | } 690 | fclose(fp); 691 | 692 | xfer->bytes_sent += length; 693 | purple_xfer_update_progress(xfer); 694 | } 695 | 696 | static void on_file_control(Tox *tox, uint32_t friendnumber, 697 | uint32_t filenumber, TOX_FILE_CONTROL control_type, 698 | void *userdata) 699 | { 700 | PurpleConnection *gc = userdata; 701 | toxprpl_return_if_fail(gc != NULL); 702 | 703 | PurpleXfer* xfer = toxprpl_find_xfer(gc, friendnumber, filenumber); 704 | toxprpl_return_if_fail(xfer != NULL); 705 | 706 | switch(control_type) 707 | { 708 | case TOX_FILE_CONTROL_CANCEL: 709 | purple_xfer_cancel_remote(xfer); 710 | break; 711 | default: 712 | /* TODO: handle TOX_FILE_CONTROL_RESUME / TOX_FILE_CONTROL_PAUSE */ 713 | break; 714 | } 715 | } 716 | 717 | static void on_file_recv(Tox *tox, uint32_t friendnumber, 718 | uint32_t filenumber, uint32_t kind, 719 | uint64_t filesize, const uint8_t *filename, 720 | size_t filename_length, void *userdata) 721 | { 722 | purple_debug_info("toxprpl", "file_send_request: %i %i\n", friendnumber, 723 | filenumber); 724 | 725 | PurpleConnection *gc = userdata; 726 | 727 | /* TCS: Avatar 2.3.2 */ 728 | /* As we do not support avatars, we cancel the file as soon as possible. */ 729 | if (kind == TOX_FILE_KIND_AVATAR) 730 | { 731 | TOX_ERR_FILE_CONTROL err_back; 732 | tox_file_control(tox, friendnumber, filenumber, TOX_FILE_CONTROL_CANCEL, 733 | &err_back); 734 | // we really don't care about the return code from tox_file_control 735 | // since we wanted to cancel the transfer anyway 736 | return; 737 | } 738 | 739 | toxprpl_return_if_fail(gc != NULL); 740 | toxprpl_return_if_fail(filename != NULL); 741 | toxprpl_return_if_fail(tox != NULL); 742 | 743 | uint8_t public_key[TOX_PUBLIC_KEY_SIZE]; 744 | TOX_ERR_FRIEND_GET_PUBLIC_KEY err_back; 745 | /* ToDo: Hanndle err_back */ 746 | if (tox_friend_get_public_key(tox, friendnumber, public_key, 747 | &err_back) != true) 748 | { 749 | purple_debug_info("toxprpl", "Could not get id of friend %d\n", 750 | friendnumber); 751 | return; 752 | } 753 | gchar *buddy_key = toxprpl_tox_bin_id_to_string(public_key); 754 | 755 | PurpleXfer *xfer = toxprpl_new_xfer_receive(gc, buddy_key, friendnumber, 756 | filenumber, filesize, 757 | (const char*) filename); 758 | if (xfer == NULL) 759 | { 760 | purple_debug_warning("toxprpl", "could not create xfer\n"); 761 | g_free(buddy_key); 762 | return; 763 | } 764 | toxprpl_return_if_fail(xfer != NULL); 765 | toxprpl_xfer_data *xfer_data = xfer->data; 766 | purple_debug_warning("toxprpl", "xfer fn/fn: %d %d %d %d\n", 767 | xfer_data->friendnumber, xfer_data->filenumber, 768 | friendnumber, filenumber); 769 | purple_xfer_request(xfer); 770 | g_free(buddy_key); 771 | } 772 | 773 | static void on_typing_change(Tox *tox, uint32_t friendnum, bool is_typing, 774 | void *userdata) 775 | { 776 | purple_debug_info("toxprpl", "Friend typing status change: %d", friendnum); 777 | 778 | PurpleConnection *gc = userdata; 779 | toxprpl_return_if_fail(gc != NULL); 780 | 781 | uint8_t public_key[TOX_PUBLIC_KEY_SIZE]; 782 | TOX_ERR_FRIEND_GET_PUBLIC_KEY err_back; 783 | /* ToDo: Hanndle err_back */ 784 | if (tox_friend_get_public_key(tox, friendnum, public_key, 785 | &err_back) != true) 786 | { 787 | purple_debug_info("toxprpl", "Could not get id of friend %d\n", 788 | friendnum); 789 | return; 790 | } 791 | 792 | gchar *buddy_key = toxprpl_tox_bin_id_to_string(public_key); 793 | PurpleAccount *account = purple_connection_get_account(gc); 794 | PurpleBuddy *buddy = purple_find_buddy(account, buddy_key); 795 | if (buddy == NULL) 796 | { 797 | purple_debug_info("toxprpl", "Ignoring typing change because buddy %s " 798 | "was not found\n", buddy_key); 799 | g_free(buddy_key); 800 | return; 801 | } 802 | g_free(buddy_key); 803 | 804 | if (is_typing) 805 | { 806 | serv_got_typing(gc, buddy->name, 5, PURPLE_TYPING); 807 | /* ^ timeout for typing status 808 | * (0 = disabled) */ 809 | } 810 | else 811 | { 812 | serv_got_typing_stopped(gc, buddy->name); 813 | } 814 | } 815 | 816 | static gboolean tox_messenger_loop(gpointer data) 817 | { 818 | PurpleConnection *gc = (PurpleConnection *)data; 819 | toxprpl_plugin_data *plugin = purple_connection_get_protocol_data(gc); 820 | if ((plugin != NULL) && (plugin->tox != NULL)) 821 | { 822 | tox_iterate(plugin->tox); 823 | } 824 | return TRUE; 825 | } 826 | 827 | static void toxprpl_set_nick_action(PurpleConnection *gc, const char *nickname) 828 | { 829 | PurpleAccount *account = purple_connection_get_account(gc); 830 | toxprpl_plugin_data *plugin = purple_connection_get_protocol_data(gc); 831 | if (nickname != NULL) 832 | { 833 | purple_connection_set_display_name(gc, nickname); 834 | TOX_ERR_SET_INFO err_back; 835 | /* TODO: Handle err_back */ 836 | tox_self_set_name(plugin->tox, (uint8_t *)nickname, 837 | strlen(nickname) + 1, &err_back); 838 | purple_account_set_string(account, "nickname", nickname); 839 | } 840 | } 841 | 842 | static gboolean tox_connection_check(gpointer gc) 843 | { 844 | toxprpl_plugin_data *plugin = purple_connection_get_protocol_data(gc); 845 | 846 | if ((plugin->connected == 0) && tox_self_get_connection_status(plugin->tox)) 847 | { 848 | plugin->connected = 1; 849 | purple_connection_update_progress(gc, _("Connected"), 850 | 1, /* which connection step this is */ 851 | 2); /* total number of steps */ 852 | purple_connection_set_state(gc, PURPLE_CONNECTED); 853 | purple_debug_info("toxprpl", "DHT connected!\n"); 854 | 855 | /* query status of all buddies */ 856 | PurpleAccount *account = purple_connection_get_account(gc); 857 | GSList *buddy_list = purple_find_buddies(account, NULL); 858 | g_slist_foreach(buddy_list, toxprpl_query_buddy_info, gc); 859 | g_slist_free(buddy_list); 860 | 861 | uint8_t our_name[TOX_MAX_NAME_LENGTH + 1]; 862 | tox_self_get_name(plugin->tox, our_name); 863 | size_t name_len = tox_self_get_name_size(plugin->tox); 864 | /* bug in the library? */ 865 | if (name_len == 0) 866 | { 867 | our_name[0] = '\0'; 868 | } 869 | our_name[TOX_MAX_NAME_LENGTH] = '\0'; 870 | 871 | purple_debug_info("toxprpl", "checking for nickname\n"); 872 | 873 | const char *nick = purple_account_get_string(account, "nickname", NULL); 874 | if (strlen(nick) == 0) 875 | { 876 | if (strlen((const char *)our_name) > 0) 877 | { 878 | purple_connection_set_display_name(gc, (const char *)our_name); 879 | purple_account_set_string(account, "nickname", 880 | (const char *)our_name); 881 | } 882 | } 883 | else 884 | { 885 | toxprpl_set_nick_action(gc, nick); 886 | } 887 | 888 | PurpleStatus* status = purple_account_get_active_status(account); 889 | if (status != NULL) 890 | { 891 | purple_debug_info("toxprpl", "(re)setting status\n"); 892 | toxprpl_set_status(account, status); 893 | } 894 | } 895 | else if ((plugin->connected == 1) && !tox_self_get_connection_status(plugin->tox)) 896 | { 897 | plugin->connected = 0; 898 | purple_debug_info("toxprpl", "DHT disconnected!\n"); 899 | purple_connection_notice(gc, 900 | _("Connection to DHT server lost, attempging to reconnect...")); 901 | purple_connection_update_progress(gc, _("Reconnecting..."), 902 | 0, /* which connection step this is */ 903 | 2); /* total number of steps */ 904 | } 905 | return TRUE; 906 | } 907 | 908 | static void toxprpl_set_status(PurpleAccount *account, PurpleStatus *status) 909 | { 910 | const char* status_id = purple_status_get_id(status); 911 | const char *message = purple_status_get_attr_string(status, "message"); 912 | 913 | PurpleConnection *gc = purple_account_get_connection(account); 914 | toxprpl_plugin_data *plugin = purple_connection_get_protocol_data(gc); 915 | 916 | purple_debug_info("toxprpl", "setting status %s\n", status_id); 917 | 918 | TOX_USER_STATUS tox_status; 919 | if (!toxprpl_get_tox_status_from_id(status_id, &tox_status)) 920 | { 921 | purple_debug_info("toxprpl", "status %s is invalid\n", status_id); 922 | return; 923 | } 924 | 925 | tox_self_set_status(plugin->tox, tox_status); 926 | if ((message != NULL) && (strlen(message) > 0)) 927 | { 928 | TOX_ERR_SET_INFO err_back; 929 | /* TODO: Handle err_back */ 930 | tox_self_set_status_message(plugin->tox, (uint8_t *)message, 931 | strlen(message) + 1, &err_back); 932 | } 933 | } 934 | 935 | /* query buddy status */ 936 | static void toxprpl_query_buddy_info(gpointer data, gpointer user_data) 937 | { 938 | purple_debug_info("toxprpl", "toxprpl_query_buddy_info\n"); 939 | PurpleBuddy *buddy = (PurpleBuddy *)data; 940 | PurpleConnection *gc = (PurpleConnection *)user_data; 941 | toxprpl_plugin_data *plugin = purple_connection_get_protocol_data(gc); 942 | 943 | toxprpl_buddy_data *buddy_data = purple_buddy_get_protocol_data(buddy); 944 | if (buddy_data == NULL) 945 | { 946 | unsigned char *bin_key = toxprpl_hex_string_to_data(buddy->name); 947 | TOX_ERR_FRIEND_BY_PUBLIC_KEY err_back; 948 | /* TODO: Handle err_back */ 949 | uint32_t fnum = tox_friend_by_public_key(plugin->tox, bin_key, 950 | &err_back); 951 | buddy_data = g_new0(toxprpl_buddy_data, 1); 952 | buddy_data->tox_friendlist_number = fnum; 953 | purple_buddy_set_protocol_data(buddy, buddy_data); 954 | g_free(bin_key); 955 | } 956 | 957 | PurpleAccount *account = purple_connection_get_account(gc); 958 | TOX_ERR_FRIEND_QUERY err_back_status; 959 | purple_debug_info("toxprpl", "Setting user status for user %s to %s\n", 960 | buddy->name, toxprpl_statuses[toxprpl_get_status_index(plugin->tox, 961 | buddy_data->tox_friendlist_number, 962 | tox_friend_get_status(plugin->tox, buddy_data->tox_friendlist_number, &err_back_status))].id); 963 | purple_prpl_got_user_status(account, buddy->name, 964 | toxprpl_statuses[toxprpl_get_status_index(plugin->tox, 965 | buddy_data->tox_friendlist_number, 966 | tox_friend_get_status(plugin->tox, buddy_data->tox_friendlist_number, &err_back_status))].id, 967 | NULL); 968 | 969 | purple_debug_info("toxprpl", "ERR_FRIEND_QUERY: %d\n", err_back_status); 970 | 971 | uint8_t alias[TOX_MAX_NAME_LENGTH + 1]; 972 | TOX_ERR_FRIEND_QUERY err_back; 973 | /* TODO: handle err_back */ 974 | if (tox_friend_get_name(plugin->tox, buddy_data->tox_friendlist_number, 975 | alias, &err_back) == 0) 976 | { 977 | alias[TOX_MAX_NAME_LENGTH] = '\0'; 978 | purple_blist_alias_buddy(buddy, (const char*)alias); 979 | } 980 | } 981 | 982 | static const char *toxprpl_list_icon(PurpleAccount *acct, PurpleBuddy *buddy) 983 | { 984 | return "tox"; 985 | } 986 | 987 | static GList *toxprpl_status_types(PurpleAccount *acct) 988 | { 989 | GList *types = NULL; 990 | PurpleStatusType *type; 991 | int i; 992 | 993 | purple_debug_info("toxprpl", "setting up status types\n"); 994 | 995 | for (i = 0; i < TOXPRPL_MAX_STATUS; i++) 996 | { 997 | type = purple_status_type_new_with_attrs(toxprpl_statuses[i].primitive, 998 | toxprpl_statuses[i].id, toxprpl_statuses[i].title, TRUE, TRUE, 999 | FALSE, 1000 | "message", _("Message"), purple_value_new(PURPLE_TYPE_STRING), 1001 | NULL); 1002 | types = g_list_append(types, type); 1003 | } 1004 | 1005 | return types; 1006 | } 1007 | 1008 | static PurpleCmdRet toxprpl_myid_cmd_cb(PurpleConversation *conv, 1009 | const gchar *cmd, gchar **args, 1010 | gchar **error, void *data) 1011 | { 1012 | purple_debug_info("toxprpl", "/myid command detected\n"); 1013 | PurpleConnection *gc = (PurpleConnection *)data; 1014 | toxprpl_plugin_data *plugin = purple_connection_get_protocol_data(gc); 1015 | 1016 | uint8_t bin_id[TOX_ADDRESS_SIZE]; 1017 | tox_self_get_address(plugin->tox, bin_id); 1018 | gchar *id = toxprpl_tox_friend_id_to_string(bin_id); 1019 | 1020 | gchar *message = g_strdup_printf(_("If someone wants to add you, give them " 1021 | "this id: %s"), id); 1022 | 1023 | purple_conversation_write(conv, NULL, message, PURPLE_MESSAGE_SYSTEM, 1024 | time(NULL)); 1025 | g_free(id); 1026 | g_free(message); 1027 | return PURPLE_CMD_RET_OK; 1028 | } 1029 | 1030 | static PurpleCmdRet toxprpl_nick_cmd_cb(PurpleConversation *conv, 1031 | const gchar *cmd, gchar **args, 1032 | gchar **error, void *data) 1033 | { 1034 | purple_debug_info("toxprpl", "/nick %s command detected\n", args[0]); 1035 | PurpleConnection *gc = (PurpleConnection *)data; 1036 | toxprpl_set_nick_action(gc, args[0]); 1037 | return PURPLE_CMD_RET_OK; 1038 | } 1039 | 1040 | static void toxprpl_sync_add_buddy(PurpleAccount *account, Tox *tox, 1041 | int friend_number) 1042 | { 1043 | uint8_t alias[TOX_MAX_NAME_LENGTH + 1]; 1044 | uint8_t public_key[TOX_PUBLIC_KEY_SIZE]; 1045 | TOX_ERR_FRIEND_GET_PUBLIC_KEY err_back_key; 1046 | /* TODO: Hanndle err_back */ 1047 | if (tox_friend_get_public_key(tox, friend_number, public_key, 1048 | &err_back_key) != true) 1049 | { 1050 | purple_debug_info("toxprpl", "Could not get id of friend #%d\n", 1051 | friend_number); 1052 | return; 1053 | } 1054 | 1055 | gchar *buddy_key = toxprpl_tox_bin_id_to_string(public_key); 1056 | 1057 | PurpleBuddy *buddy; 1058 | TOX_ERR_FRIEND_QUERY err_back_name; 1059 | /* TODO: Handle err_back_name */ 1060 | int ret = tox_friend_get_name(tox, friend_number, alias, &err_back_name); 1061 | alias[TOX_MAX_NAME_LENGTH] = '\0'; 1062 | if ((ret == 0) && (strlen((const char *)alias) > 0)) 1063 | { 1064 | purple_debug_info("toxprpl", "Got friend alias %s\n", alias); 1065 | buddy = purple_buddy_new(account, buddy_key, (const char*)alias); 1066 | } 1067 | else 1068 | { 1069 | purple_debug_info("toxprpl", "Adding [%s]\n", buddy_key); 1070 | buddy = purple_buddy_new(account, buddy_key, NULL); 1071 | } 1072 | 1073 | toxprpl_buddy_data *buddy_data = g_new0(toxprpl_buddy_data, 1); 1074 | buddy_data->tox_friendlist_number = friend_number; 1075 | purple_buddy_set_protocol_data(buddy, buddy_data); 1076 | purple_blist_add_buddy(buddy, NULL, NULL, NULL); 1077 | TOX_ERR_FRIEND_QUERY err_back_status; 1078 | /* TODO: Handle err_back_status */ 1079 | TOX_USER_STATUS userstatus = tox_friend_get_status(tox, friend_number, 1080 | &err_back_status); 1081 | purple_debug_info("toxprpl", "Friend %s has status %d\n", buddy_key, 1082 | userstatus); 1083 | purple_prpl_got_user_status(account, buddy_key, 1084 | toxprpl_statuses[ 1085 | toxprpl_get_status_index(tox,friend_number,userstatus)].id, 1086 | NULL); 1087 | g_free(buddy_key); 1088 | } 1089 | 1090 | static void toxprpl_sync_friends(PurpleAccount *acct, Tox *tox) 1091 | { 1092 | uint32_t i; 1093 | 1094 | uint32_t fl_len = tox_self_get_friend_list_size(tox); 1095 | uint32_t *friendlist = g_malloc0(fl_len * sizeof(uint32_t)); 1096 | 1097 | if (fl_len != 0) 1098 | { 1099 | tox_self_get_friend_list(tox, friendlist); 1100 | purple_debug_info("toxprpl", "got %u friends\n", fl_len); 1101 | GSList *buddies = purple_find_buddies(acct, NULL); 1102 | GSList *iterator; 1103 | for (i = 0; i < fl_len; i++) 1104 | { 1105 | iterator = buddies; 1106 | uint32_t fnum = friendlist[i]; 1107 | uint8_t bin_id[TOX_PUBLIC_KEY_SIZE]; 1108 | TOX_ERR_FRIEND_GET_PUBLIC_KEY err_back; 1109 | /* TODO: Hanndle err_back */ 1110 | if (tox_friend_get_public_key(tox, fnum, bin_id, &err_back) == 0) 1111 | { 1112 | gchar *str_id = toxprpl_tox_bin_id_to_string(bin_id); 1113 | while (iterator != NULL) 1114 | { 1115 | PurpleBuddy *buddy = iterator->data; 1116 | if (strcmp(buddy->name, str_id) == 0) 1117 | { 1118 | toxprpl_buddy_data *buddy_data = 1119 | g_new0(toxprpl_buddy_data, 1); 1120 | buddy_data->tox_friendlist_number = fnum; 1121 | purple_buddy_set_protocol_data(buddy, buddy_data); 1122 | friendlist[i] = -1; 1123 | } 1124 | iterator = iterator->next; 1125 | } 1126 | g_free(str_id); 1127 | } 1128 | } 1129 | 1130 | iterator = buddies; 1131 | /* all left without buddy_data were not present in Tox and must be */ 1132 | /* removed */ 1133 | while (iterator != NULL) 1134 | { 1135 | PurpleBuddy *buddy = iterator->data; 1136 | toxprpl_buddy_data *buddy_data = 1137 | purple_buddy_get_protocol_data(buddy); 1138 | if (buddy_data == NULL) 1139 | { 1140 | purple_blist_remove_buddy(buddy); 1141 | } 1142 | iterator = iterator->next; 1143 | } 1144 | 1145 | g_slist_free(buddies); 1146 | } 1147 | 1148 | /* all left in friendlist that were not reset are not yet in blist */ 1149 | for (i = 0; i < fl_len; i++) 1150 | { 1151 | if (friendlist[i] != -1) 1152 | { 1153 | toxprpl_sync_add_buddy(acct, tox, friendlist[i]); 1154 | } 1155 | } 1156 | 1157 | g_free(friendlist); 1158 | } 1159 | 1160 | static gboolean toxprpl_save_account(PurpleAccount *account, Tox* tox) 1161 | { 1162 | PurpleConnection *gc = purple_account_get_connection(account); 1163 | const char *key = purple_account_get_string(account, "account_path", 1164 | DEFAULT_ACCOUNT_PATH); 1165 | gchar* filename = g_build_filename(purple_user_dir(), "tox", key, 1166 | "tox_save.tox", NULL); 1167 | gchar* dirname = g_path_get_dirname(filename); 1168 | g_mkdir_with_parents(dirname, 0777); 1169 | toxprpl_user_export(gc, filename); 1170 | 1171 | return TRUE; 1172 | } 1173 | 1174 | static void toxprpl_login_after_setup(PurpleAccount *acct, 1175 | toxprpl_profile_data profile) 1176 | { 1177 | purple_debug_info("toxprpl", "logging in...\n"); 1178 | 1179 | PurpleConnection *gc = purple_account_get_connection(acct); 1180 | 1181 | gc->flags |= PURPLE_CONNECTION_NO_FONTSIZE | PURPLE_CONNECTION_NO_URLDESC; 1182 | gc->flags |= PURPLE_CONNECTION_NO_IMAGES | PURPLE_CONNECTION_NO_NEWLINES; 1183 | 1184 | TOX_ERR_NEW new_err; /* TODO parse the error code? */ 1185 | Tox *tox = tox_new(0, &new_err); 1186 | 1187 | purple_debug_info("toxprpl", "logging in %s\n", acct->username); 1188 | if (profile.exists) 1189 | { 1190 | purple_debug_info("toxprpl", "found existing account data\n"); 1191 | gsize out_len = profile.size; 1192 | guchar *msg_data = profile.account_data; 1193 | TOX_ERR_OPTIONS_NEW err_back; 1194 | /* TODO: Handle err_back */ 1195 | struct Tox_Options *options = tox_options_new(&err_back); 1196 | 1197 | if (err_back == TOX_ERR_OPTIONS_NEW_MALLOC) 1198 | { 1199 | purple_debug_error("toxprpl", "Fatal error, could not allocate " 1200 | "memory for options struct!\n"); 1201 | } 1202 | 1203 | options->savedata_type = TOX_SAVEDATA_TYPE_TOX_SAVE; 1204 | options->savedata_length = (uint32_t)out_len; 1205 | options->savedata_data = (uint8_t *)msg_data; 1206 | 1207 | if (msg_data && (out_len > 0)) 1208 | { 1209 | TOX_ERR_NEW err_back_new; 1210 | /* TODO: Handle err_back */ 1211 | tox = tox_new(options, &err_back_new); 1212 | if (tox == NULL) 1213 | { 1214 | purple_debug_error("toxprpl", "Fatal error, could not allocate " 1215 | "memory for messenger!\n"); 1216 | return; 1217 | } 1218 | g_free(msg_data); 1219 | } 1220 | } 1221 | else /* write account into pidgin */ 1222 | { 1223 | toxprpl_save_account(acct, tox); 1224 | } 1225 | tox_callback_friend_message(tox, on_incoming_message, gc); 1226 | tox_callback_friend_name(tox, on_nick_change, gc); 1227 | tox_callback_friend_status(tox, on_status_change, gc); 1228 | tox_callback_friend_request(tox, on_request, gc); 1229 | tox_callback_friend_connection_status(tox, on_connectionstatus, gc); 1230 | tox_callback_friend_typing(tox, on_typing_change, gc); 1231 | 1232 | 1233 | tox_callback_file_recv(tox, on_file_recv, gc); 1234 | tox_callback_file_chunk_request(tox, on_file_chunk_request, gc); 1235 | tox_callback_file_recv_control(tox, on_file_control, gc); 1236 | tox_callback_file_recv_chunk(tox, on_file_recv_chunk, gc); 1237 | 1238 | purple_debug_info("toxprpl", "initialized tox callbacks\n"); 1239 | 1240 | 1241 | 1242 | purple_connection_update_progress(gc, _("Connecting"), 1243 | 0, /* which connection step this is */ 1244 | 2); /* total number of steps */ 1245 | 1246 | 1247 | const char *key = purple_account_get_string(acct, "dht_server_key", 1248 | DEFAULT_SERVER_KEY); 1249 | /* \todo add limits check to make sure the user did not enter something 1250 | invalid */ 1251 | uint16_t port = (uint16_t)purple_account_get_int(acct, "dht_server_port", 1252 | DEFAULT_SERVER_PORT); 1253 | 1254 | const char* ip = purple_account_get_string(acct, "dht_server", 1255 | DEFAULT_SERVER_IP); 1256 | 1257 | unsigned char *bin_str = toxprpl_hex_string_to_data(key); 1258 | 1259 | purple_debug_info("toxprpl", "Will connect to %s:%d (%s)\n" , 1260 | ip, port, key); 1261 | 1262 | TOX_ERR_BOOTSTRAP err_back_bootstr; 1263 | if (tox_bootstrap(tox, ip, port, bin_str, &err_back_bootstr) == 0) 1264 | { 1265 | purple_connection_error_reason(gc, 1266 | PURPLE_CONNECTION_ERROR_NETWORK_ERROR, 1267 | _("server invalid or not found")); 1268 | g_free(bin_str); 1269 | tox_kill(tox); 1270 | return; 1271 | } 1272 | g_free(bin_str); 1273 | 1274 | toxprpl_sync_friends(acct, tox); 1275 | 1276 | toxprpl_plugin_data *plugin = g_new0(toxprpl_plugin_data, 1); 1277 | 1278 | plugin->tox = tox; 1279 | plugin->tox_timer = purple_timeout_add(80, tox_messenger_loop, gc); 1280 | purple_debug_info("toxprpl", "added messenger timer as %d\n", 1281 | plugin->tox_timer); 1282 | plugin->connection_timer = purple_timeout_add_seconds(2, 1283 | tox_connection_check, 1284 | gc); 1285 | purple_debug_info("toxprpl", "added connection timer as %d\n", 1286 | plugin->connection_timer); 1287 | 1288 | 1289 | gchar *myid_help = "myid print your tox id which you can give to " 1290 | "your friends"; 1291 | gchar *nick_help = "nick <nickname> set your nickname"; 1292 | 1293 | plugin->myid_command_id = purple_cmd_register("myid", "", 1294 | PURPLE_CMD_P_DEFAULT, PURPLE_CMD_FLAG_IM | PURPLE_CMD_FLAG_CHAT, 1295 | TOXPRPL_ID, toxprpl_myid_cmd_cb, myid_help, gc); 1296 | 1297 | plugin->nick_command_id = purple_cmd_register("nick", "s", 1298 | PURPLE_CMD_P_DEFAULT, PURPLE_CMD_FLAG_IM | PURPLE_CMD_FLAG_CHAT, 1299 | TOXPRPL_ID, toxprpl_nick_cmd_cb, nick_help, gc); 1300 | 1301 | const char *nick = purple_account_get_string(acct, "nickname", NULL); 1302 | if (!nick || (strlen(nick) == 0)) 1303 | { 1304 | nick = purple_account_get_username(acct); 1305 | if (strlen(nick) == 0) 1306 | { 1307 | nick = purple_account_get_alias(acct); 1308 | } 1309 | 1310 | if (strlen(nick) == 0) 1311 | { 1312 | nick = DEFAULT_NICKNAME; 1313 | } 1314 | } 1315 | 1316 | purple_connection_set_protocol_data(gc, plugin); 1317 | toxprpl_set_nick_action(gc, nick); 1318 | } 1319 | 1320 | static void toxprpl_user_import(PurpleAccount *acct, const char *filename, toxprpl_profile_data* profile) 1321 | { 1322 | purple_debug_info("toxprpl", "import user account: %s\n", filename); 1323 | profile->exists = 0; 1324 | 1325 | PurpleConnection *gc = purple_account_get_connection(acct); 1326 | 1327 | /* We return invalid profile if the file can't be accessed */ 1328 | GStatBuf sb; 1329 | if (g_stat(filename, &sb) != 0) 1330 | { 1331 | return; 1332 | } 1333 | 1334 | /* We return error message if the size is wrong */ 1335 | if ((sb.st_size == 0) || (sb.st_size > MAX_ACCOUNT_DATA_SIZE)) 1336 | { 1337 | purple_notify_message(gc, 1338 | PURPLE_NOTIFY_MSG_ERROR, 1339 | _("Error"), 1340 | _("Account data file seems to be invalid"), 1341 | NULL, 1342 | (PurpleNotifyCloseCallback)toxprpl_login, 1343 | acct); 1344 | return; 1345 | } 1346 | 1347 | /* We return invalid profile if the file can't be found */ 1348 | int fd = open(filename, O_RDONLY | O_BINARY); 1349 | if (fd == -1) 1350 | { 1351 | return; 1352 | } 1353 | 1354 | guchar *account_data = g_malloc0(sb.st_size); 1355 | guchar *p = account_data; 1356 | size_t remaining = sb.st_size; 1357 | while (remaining > 0) 1358 | { 1359 | /* We return error message if file exists and can't be read */ 1360 | ssize_t rb = read(fd, p, remaining); 1361 | if (rb < 0) 1362 | { 1363 | purple_notify_message(gc, 1364 | PURPLE_NOTIFY_MSG_ERROR, 1365 | _("Error"), 1366 | _("Could not read account data file:"), 1367 | strerror(errno), 1368 | (PurpleNotifyCloseCallback)toxprpl_login, 1369 | acct); 1370 | g_free(account_data); 1371 | close(fd); 1372 | return; 1373 | } 1374 | remaining = remaining - rb; 1375 | p = p + rb; 1376 | } 1377 | 1378 | close(fd); 1379 | 1380 | /* File was read successfully */ 1381 | profile->size = sb.st_size; 1382 | profile->account_data = account_data; 1383 | profile->exists = 1; 1384 | } 1385 | 1386 | static void toxprpl_login(PurpleAccount *acct) 1387 | { 1388 | PurpleConnection *gc = purple_account_get_connection(acct); 1389 | const char *key = purple_account_get_string(acct, "account_path", 1390 | DEFAULT_ACCOUNT_PATH); 1391 | gchar* filename = g_build_filename(purple_user_dir(), "tox", key, "tox_save.tox", NULL); 1392 | toxprpl_profile_data profile; 1393 | toxprpl_user_import(acct, filename, &profile); 1394 | 1395 | /* check if we need to run first time setup */ 1396 | if (!profile.exists) 1397 | { 1398 | purple_request_action(gc, 1399 | _("Setup Tox account"), 1400 | _("This appears to be your first login to the Tox network, " 1401 | "would you like to start with a new Tox user ID or would you " 1402 | "like to import an existing one?"), 1403 | _("Note: you can export / backup your account via the account " 1404 | "actions menu."), 1405 | PURPLE_DEFAULT_ACTION_NONE, 1406 | acct, NULL, NULL, 1407 | acct, /* user data */ 1408 | 1, /* 1 choice */ 1409 | _("Create new Tox account"), 1410 | G_CALLBACK(toxprpl_login_after_setup)); 1411 | } 1412 | else 1413 | { 1414 | toxprpl_login_after_setup(acct, profile); 1415 | } 1416 | } 1417 | 1418 | 1419 | static void toxprpl_close(PurpleConnection *gc) 1420 | { 1421 | /* notify other toxprpl accounts */ 1422 | purple_debug_info("toxprpl", "Closing!\n"); 1423 | 1424 | PurpleAccount *account = purple_connection_get_account(gc); 1425 | toxprpl_plugin_data *plugin = purple_connection_get_protocol_data(gc); 1426 | if (plugin == NULL) 1427 | { 1428 | return; 1429 | } 1430 | 1431 | if (plugin->tox == NULL) 1432 | { 1433 | g_free(plugin); 1434 | purple_connection_set_protocol_data(gc, NULL); 1435 | return; 1436 | } 1437 | 1438 | purple_debug_info("toxprpl", "removing timers %d and %d\n", 1439 | plugin->tox_timer, plugin->connection_timer); 1440 | purple_timeout_remove(plugin->tox_timer); 1441 | purple_timeout_remove(plugin->connection_timer); 1442 | 1443 | purple_cmd_unregister(plugin->myid_command_id); 1444 | purple_cmd_unregister(plugin->nick_command_id); 1445 | 1446 | toxprpl_save_account(account, plugin->tox); 1447 | 1448 | purple_debug_info("toxprpl", "shutting down\n"); 1449 | purple_connection_set_protocol_data(gc, NULL); 1450 | tox_kill(plugin->tox); 1451 | g_free(plugin); 1452 | } 1453 | 1454 | /** 1455 | * This PRPL function should return a positive value on success. 1456 | * If the message is too big to be sent, return -E2BIG. If 1457 | * the account is not connected, return -ENOTCONN. If the 1458 | * PRPL is unable to send the message for another reason, return 1459 | * some other negative value. You can use one of the valid 1460 | * errno values, or just big something. If the message should 1461 | * not be echoed to the conversation window, return 0. 1462 | */ 1463 | static int toxprpl_send_im(PurpleConnection *gc, const char *who, 1464 | const char *message, PurpleMessageFlags flags) 1465 | { 1466 | const char *from_username = gc->account->username; 1467 | 1468 | purple_debug_info("toxprpl", "sending message from %s to %s\n", 1469 | from_username, who); 1470 | 1471 | int message_sent = -999; 1472 | 1473 | PurpleAccount *account = purple_connection_get_account(gc); 1474 | PurpleBuddy *buddy = purple_find_buddy(account, who); 1475 | if (buddy == NULL) 1476 | { 1477 | purple_debug_info("toxprpl", "Can't send message because buddy %s was " 1478 | "not found\n", who); 1479 | return message_sent; 1480 | } 1481 | toxprpl_buddy_data *buddy_data = purple_buddy_get_protocol_data(buddy); 1482 | if (buddy_data == NULL) 1483 | { 1484 | purple_debug_info("toxprpl", "Can't send message because tox friend " 1485 | "number is unknown\n"); 1486 | return message_sent; 1487 | } 1488 | toxprpl_plugin_data *plugin = purple_connection_get_protocol_data(gc); 1489 | char *no_html = purple_markup_strip_html(message); 1490 | 1491 | TOX_MESSAGE_TYPE msg_type; 1492 | if (purple_message_meify(no_html, -1)) 1493 | { 1494 | msg_type = TOX_MESSAGE_TYPE_ACTION; 1495 | } 1496 | else 1497 | { 1498 | msg_type = TOX_MESSAGE_TYPE_NORMAL; 1499 | } 1500 | 1501 | TOX_ERR_FRIEND_SEND_MESSAGE err_back; 1502 | /* ToDo: Handle err_back */ 1503 | if (tox_friend_send_message(plugin->tox, buddy_data->tox_friendlist_number, 1504 | msg_type, (uint8_t *)no_html, strlen(no_html), 1505 | &err_back) != 0) 1506 | { 1507 | message_sent = 1; 1508 | } 1509 | if (no_html) 1510 | { 1511 | free(no_html); 1512 | } 1513 | return message_sent; 1514 | } 1515 | 1516 | static int toxprpl_tox_add_friend(Tox *tox, PurpleConnection *gc, 1517 | const char *buddy_key, 1518 | gboolean sendrequest, 1519 | const char *message) 1520 | { 1521 | unsigned char *bin_key = toxprpl_hex_string_to_data(buddy_key); 1522 | int ret; 1523 | 1524 | if (sendrequest == TRUE) 1525 | { 1526 | if ((message == NULL) || (strlen(message) == 0)) 1527 | { 1528 | message = DEFAULT_REQUEST_MESSAGE; 1529 | } 1530 | TOX_ERR_FRIEND_ADD err_back_add; 1531 | ret = tox_friend_add(tox, bin_key, (uint8_t *)message, 1532 | (uint16_t)strlen(message) + 1, &err_back_add); 1533 | } 1534 | else 1535 | { 1536 | TOX_ERR_FRIEND_ADD err_back_add; 1537 | ret = tox_friend_add_norequest(tox, bin_key, &err_back_add); 1538 | } 1539 | 1540 | g_free(bin_key); 1541 | 1542 | if (ret != TOX_ERR_FRIEND_ADD_OK) 1543 | { 1544 | toxprpl_err_friend_add(ret, gc); 1545 | } 1546 | else 1547 | { 1548 | purple_debug_info("toxprpl", "Friend %s added as %d\n", buddy_key, ret); 1549 | /* save account so buddy is not lost in case pidgin does not exit */ 1550 | /* cleanly */ 1551 | PurpleAccount *account = purple_connection_get_account(gc); 1552 | toxprpl_save_account(account, tox); 1553 | } 1554 | 1555 | return ret; 1556 | } 1557 | 1558 | static void toxprpl_add_buddy(PurpleConnection *gc, PurpleBuddy *buddy, 1559 | PurpleGroup *group, const char *msg) 1560 | { 1561 | purple_debug_info("toxprpl", "adding %s to buddy list with length %zu\n", 1562 | buddy->name, strlen(buddy->name)); 1563 | toxprpl_plugin_data *plugin = purple_connection_get_protocol_data(gc); 1564 | 1565 | buddy->name = g_strstrip(buddy->name); 1566 | if (strlen(buddy->name) == TOX_ID_SIZE) 1567 | { 1568 | purple_debug_info("toxprpl", "adding as a response to a buddy " 1569 | "request\n"); 1570 | int ret = toxprpl_tox_add_friend(plugin->tox, gc, buddy->name, FALSE, 1571 | NULL); 1572 | if (ret < 0) 1573 | { 1574 | purple_debug_info("toxprpl", "adding buddy %s failed (%d)\n", 1575 | buddy->name, ret); 1576 | purple_blist_remove_buddy(buddy); 1577 | return; 1578 | } 1579 | } 1580 | else 1581 | { 1582 | if (strlen(buddy->name) != (TOX_ADDRESS_SIZE * 2)) 1583 | { 1584 | purple_notify_error(gc, _("Error"), 1585 | _("Invalid Tox ID given (must be 76 characters " 1586 | "long)"), NULL); 1587 | purple_blist_remove_buddy(buddy); 1588 | return; 1589 | } 1590 | int ret = toxprpl_tox_add_friend(plugin->tox, gc, buddy->name, TRUE, 1591 | msg); 1592 | if (ret < 0) 1593 | { 1594 | purple_debug_info("toxprpl", "adding buddy %s failed (%d)\n", 1595 | buddy->name, ret); 1596 | purple_blist_remove_buddy(buddy); 1597 | return; 1598 | } 1599 | } 1600 | 1601 | /* save account so buddy is not lost in case pidgin does not exit cleanly */ 1602 | PurpleAccount *account = purple_connection_get_account(gc); 1603 | toxprpl_save_account(account, plugin->tox); 1604 | 1605 | gchar *cut = g_ascii_strdown(buddy->name, TOX_PUBLIC_KEY_SIZE * 2 + 1); 1606 | cut[TOX_PUBLIC_KEY_SIZE * 2] = '\0'; 1607 | purple_debug_info("toxprpl", "converted %s to %s\n", buddy->name, cut); 1608 | purple_blist_rename_buddy(buddy, cut); 1609 | g_free(cut); 1610 | /* buddy data will be added by the query_buddy_info function */ 1611 | toxprpl_query_buddy_info((gpointer)buddy, (gpointer)gc); 1612 | } 1613 | 1614 | static void toxprpl_remove_buddy(PurpleConnection *gc, PurpleBuddy *buddy, 1615 | PurpleGroup *group) 1616 | { 1617 | purple_debug_info("toxprpl", "removing buddy %s\n", buddy->name); 1618 | toxprpl_plugin_data *plugin = purple_connection_get_protocol_data(gc); 1619 | toxprpl_buddy_data *buddy_data = purple_buddy_get_protocol_data(buddy); 1620 | if (buddy_data != NULL) 1621 | { 1622 | purple_debug_info("toxprpl", "removing tox friend #%d\n", 1623 | buddy_data->tox_friendlist_number); 1624 | TOX_ERR_FRIEND_DELETE err_back_del; 1625 | tox_friend_delete(plugin->tox, buddy_data->tox_friendlist_number, 1626 | &err_back_del); 1627 | 1628 | /* save account to make sure buddy stays deleted in case pidgin does */ 1629 | /* not exit cleanly */ 1630 | PurpleAccount *account = purple_connection_get_account(gc); 1631 | toxprpl_save_account(account, plugin->tox); 1632 | } 1633 | } 1634 | 1635 | static void toxprpl_show_id_dialog_closed(gchar *id) 1636 | { 1637 | g_free(id); 1638 | } 1639 | 1640 | static void toxprpl_action_show_id_dialog(PurplePluginAction *action) 1641 | { 1642 | PurpleConnection *gc = (PurpleConnection*)action->context; 1643 | 1644 | toxprpl_plugin_data *plugin = purple_connection_get_protocol_data(gc); 1645 | 1646 | uint8_t bin_id[TOX_ADDRESS_SIZE]; 1647 | tox_self_get_address(plugin->tox, bin_id); 1648 | gchar *id = toxprpl_tox_friend_id_to_string(bin_id); 1649 | 1650 | purple_notify_message(gc, 1651 | PURPLE_NOTIFY_MSG_INFO, 1652 | _("Account ID"), 1653 | _("If someone wants to add you, give them this Tox ID:"), 1654 | id, 1655 | (PurpleNotifyCloseCallback)toxprpl_show_id_dialog_closed, 1656 | id); 1657 | } 1658 | 1659 | static void toxprpl_action_set_nick_dialog(PurplePluginAction *action) 1660 | { 1661 | PurpleConnection *gc = (PurpleConnection*)action->context; 1662 | PurpleAccount *account = purple_connection_get_account(gc); 1663 | 1664 | purple_request_input(gc, _("Set nickname"), 1665 | _("New nickname:"), 1666 | NULL, 1667 | purple_account_get_string(account, "nickname", ""), 1668 | FALSE, FALSE, NULL, 1669 | _("_Set"), G_CALLBACK(toxprpl_set_nick_action), 1670 | _("_Cancel"), NULL, 1671 | account, account->username, NULL, 1672 | gc); 1673 | } 1674 | 1675 | 1676 | static void toxprpl_user_export(PurpleConnection *gc, const char *filename) 1677 | { 1678 | purple_debug_info("toxprpl", "export account to %s\n", filename); 1679 | 1680 | toxprpl_plugin_data *plugin = purple_connection_get_protocol_data(gc); 1681 | if (plugin == NULL || plugin->tox == NULL) 1682 | { 1683 | return; 1684 | } 1685 | 1686 | PurpleAccount *account = purple_connection_get_account(gc); 1687 | 1688 | uint32_t msg_size = tox_get_savedata_size(plugin->tox); 1689 | if (msg_size > 0) 1690 | { 1691 | uint8_t *account_data = g_malloc0(msg_size); 1692 | tox_get_savedata(plugin->tox, account_data); 1693 | guchar *p = account_data; 1694 | 1695 | int fd = open(filename, O_RDWR | O_CREAT | O_BINARY, S_IRUSR | S_IWUSR); 1696 | if (fd == -1) 1697 | { 1698 | g_free(account_data); 1699 | purple_notify_message(gc, 1700 | PURPLE_NOTIFY_MSG_ERROR, 1701 | _("Error"), 1702 | _("Could not save account data file:"), 1703 | strerror(errno), 1704 | NULL, NULL); 1705 | return; 1706 | } 1707 | 1708 | size_t remaining = (size_t)msg_size; 1709 | while (remaining > 0) 1710 | { 1711 | ssize_t wb = write(fd, p, remaining); 1712 | if (wb < 0) 1713 | { 1714 | purple_notify_message(gc, 1715 | PURPLE_NOTIFY_MSG_ERROR, 1716 | _("Error"), 1717 | _("Could not save account data file:"), 1718 | strerror(errno), 1719 | (PurpleNotifyCloseCallback)toxprpl_login, 1720 | account); 1721 | g_free(account_data); 1722 | close(fd); 1723 | return; 1724 | } 1725 | remaining = remaining - wb; 1726 | p = p + wb; 1727 | } 1728 | 1729 | g_free(account_data); 1730 | close(fd); 1731 | } 1732 | } 1733 | 1734 | static void toxprpl_export_account_dialog(PurplePluginAction *action) 1735 | { 1736 | purple_debug_info("toxprpl", "ask to export account\n"); 1737 | 1738 | PurpleConnection *gc = (PurpleConnection*)action->context; 1739 | PurpleAccount *account = purple_connection_get_account(gc); 1740 | toxprpl_plugin_data *plugin = purple_connection_get_protocol_data(gc); 1741 | if (plugin == NULL) 1742 | { 1743 | return; 1744 | } 1745 | 1746 | if (plugin->tox == NULL) 1747 | { 1748 | return; 1749 | } 1750 | 1751 | uint8_t bin_id[TOX_ADDRESS_SIZE]; 1752 | tox_self_get_address(plugin->tox, bin_id); 1753 | gchar *id = toxprpl_tox_friend_id_to_string(bin_id); 1754 | strcpy(id+TOX_PUBLIC_KEY_SIZE, ".tox\0"); // insert extension instead of nospam 1755 | 1756 | purple_request_file(gc, 1757 | _("Export existing Tox account data"), 1758 | id, 1759 | TRUE, 1760 | G_CALLBACK(toxprpl_user_export), 1761 | NULL, 1762 | account, 1763 | NULL, 1764 | NULL, 1765 | gc); 1766 | g_free(id); 1767 | } 1768 | 1769 | static GList *toxprpl_account_actions(PurplePlugin *plugin, gpointer context) 1770 | { 1771 | purple_debug_info("toxprpl", "setting up account actions\n"); 1772 | 1773 | GList *actions = NULL; 1774 | PurplePluginAction *action; 1775 | 1776 | action = purple_plugin_action_new(_("Show my id..."), 1777 | toxprpl_action_show_id_dialog); 1778 | actions = g_list_append(actions, action); 1779 | 1780 | action = purple_plugin_action_new(_("Set nickname..."), 1781 | toxprpl_action_set_nick_dialog); 1782 | actions = g_list_append(actions, action); 1783 | 1784 | action = purple_plugin_action_new(_("Export account data..."), 1785 | toxprpl_export_account_dialog); 1786 | actions = g_list_append(actions, action); 1787 | return actions; 1788 | } 1789 | 1790 | static void toxprpl_free_buddy(PurpleBuddy *buddy) 1791 | { 1792 | if (buddy->proto_data) 1793 | { 1794 | toxprpl_buddy_data *buddy_data = buddy->proto_data; 1795 | g_free(buddy_data); 1796 | } 1797 | } 1798 | 1799 | static gboolean toxprpl_offline_message(const PurpleBuddy *buddy) 1800 | { 1801 | return FALSE; 1802 | } 1803 | 1804 | static gboolean toxprpl_can_receive_file(PurpleConnection *gc, const char *who) 1805 | { 1806 | purple_debug_info("toxprpl", "can_receive_file\n"); 1807 | 1808 | toxprpl_return_val_if_fail(gc != NULL, FALSE); 1809 | toxprpl_return_val_if_fail(who != NULL, FALSE); 1810 | 1811 | toxprpl_plugin_data *plugin = purple_connection_get_protocol_data(gc); 1812 | toxprpl_return_val_if_fail(plugin != NULL && plugin->tox != NULL, FALSE); 1813 | 1814 | PurpleAccount *account = purple_connection_get_account(gc); 1815 | toxprpl_return_val_if_fail(account != NULL, FALSE); 1816 | 1817 | PurpleBuddy *buddy = purple_find_buddy(account, who); 1818 | toxprpl_return_val_if_fail(buddy != NULL, FALSE); 1819 | 1820 | toxprpl_buddy_data *buddy_data = purple_buddy_get_protocol_data(buddy); 1821 | toxprpl_return_val_if_fail(buddy_data != NULL, FALSE); 1822 | 1823 | TOX_ERR_FRIEND_QUERY err_back; 1824 | int status = tox_friend_get_connection_status(plugin->tox, 1825 | buddy_data->tox_friendlist_number, &err_back); 1826 | 1827 | purple_debug_info("toxprpl", "can_receive_file_info %d with status %d\n", buddy_data->tox_friendlist_number, status); 1828 | 1829 | return status != TOX_CONNECTION_NONE; 1830 | } 1831 | 1832 | static void toxprpl_xfer_init(PurpleXfer *xfer) 1833 | { 1834 | TOX_ERR_FILE_CONTROL err_back; 1835 | purple_debug_info("toxprpl", "xfer_init\n"); 1836 | toxprpl_return_if_fail(xfer != NULL); 1837 | 1838 | toxprpl_xfer_data *xfer_data = xfer->data; 1839 | toxprpl_return_if_fail(xfer_data != NULL); 1840 | 1841 | if (purple_xfer_get_type(xfer) == PURPLE_XFER_SEND) 1842 | { 1843 | PurpleAccount *account = purple_xfer_get_account(xfer); 1844 | toxprpl_return_if_fail(account != NULL); 1845 | 1846 | PurpleConnection *gc = purple_account_get_connection(account); 1847 | toxprpl_return_if_fail(gc != NULL); 1848 | 1849 | toxprpl_plugin_data *plugin = purple_connection_get_protocol_data(gc); 1850 | toxprpl_return_if_fail(plugin != NULL && plugin->tox != NULL); 1851 | 1852 | const char *who = purple_xfer_get_remote_user(xfer); 1853 | toxprpl_return_if_fail(who != NULL); 1854 | 1855 | PurpleBuddy *buddy = purple_find_buddy(account, who); 1856 | toxprpl_return_if_fail(buddy != NULL); 1857 | 1858 | toxprpl_buddy_data *buddy_data = purple_buddy_get_protocol_data(buddy); 1859 | toxprpl_return_if_fail(buddy_data != NULL); 1860 | 1861 | int friendnumber = buddy_data->tox_friendlist_number; 1862 | size_t filesize = purple_xfer_get_size(xfer); 1863 | const char *filename = purple_xfer_get_filename(xfer); 1864 | 1865 | purple_debug_info("toxprpl", "sending xfer request for file '%s'.\n", 1866 | filename); 1867 | TOX_ERR_FILE_SEND err_back; 1868 | /* TODO: maybe parsing the file kind before is necessary */ 1869 | int filenumber = tox_file_send(plugin->tox, friendnumber, 1870 | TOX_FILE_KIND_DATA, filesize, NULL, 1871 | (const uint8_t *)filename, 1872 | strlen(filename) + 1, &err_back); 1873 | /* TODO: Handle err_back */ 1874 | toxprpl_return_if_fail(filenumber >= 0); 1875 | 1876 | xfer_data->tox = plugin->tox; 1877 | xfer_data->friendnumber = buddy_data->tox_friendlist_number; 1878 | xfer_data->filenumber = filenumber; 1879 | 1880 | TOX_ERR_FILE_GET err_file_get; 1881 | /* TODO: Return type is bool */ 1882 | tox_file_get_file_id(plugin->tox, friendnumber, filenumber, 1883 | xfer_data->file_id, &err_file_get); 1884 | /* TODO: Handle err_file_get */ 1885 | } 1886 | else if (purple_xfer_get_type(xfer) == PURPLE_XFER_RECEIVE) 1887 | { 1888 | const char *filename = purple_xfer_get_filename(xfer); 1889 | purple_debug_info("toxprpl", "sending recv control for file \'%s\' " 1890 | "%d %d.\n", filename, xfer_data->friendnumber, 1891 | xfer_data->filenumber); 1892 | 1893 | PurpleAccount *account = purple_xfer_get_account(xfer); 1894 | toxprpl_return_if_fail(account != NULL); 1895 | 1896 | PurpleConnection *gc = purple_account_get_connection(account); 1897 | toxprpl_return_if_fail(gc != NULL); 1898 | 1899 | tox_file_control(xfer_data->tox, xfer_data->friendnumber, 1900 | xfer_data->filenumber, TOX_FILE_CONTROL_RESUME, &err_back); 1901 | if (err_back != TOX_ERR_FILE_CONTROL_OK) 1902 | { 1903 | toxprpl_err_file_control(err_back, gc); 1904 | return; 1905 | } 1906 | 1907 | purple_xfer_start(xfer, -1, NULL, 0); 1908 | } 1909 | } 1910 | 1911 | static void toxprpl_xfer_free(PurpleXfer *xfer) 1912 | { 1913 | purple_debug_info("toxprpl", "xfer_free\n"); 1914 | toxprpl_return_if_fail(xfer != NULL); 1915 | toxprpl_return_if_fail(xfer->data != NULL); 1916 | 1917 | toxprpl_xfer_data *xfer_data = xfer->data; 1918 | 1919 | if (xfer_data->idle_write_data != NULL) 1920 | { 1921 | toxprpl_idle_write_data *idle_write_data = xfer_data->idle_write_data; 1922 | idle_write_data->running = FALSE; 1923 | xfer_data->idle_write_data = NULL; 1924 | } 1925 | g_free(xfer_data); 1926 | xfer->data = NULL; 1927 | } 1928 | 1929 | static void toxprpl_xfer_cancel_send(PurpleXfer *xfer) 1930 | { 1931 | purple_debug_info("toxprpl", "xfer_cancel_send\n"); 1932 | toxprpl_return_if_fail(xfer != NULL); 1933 | toxprpl_return_if_fail(xfer->data != NULL); 1934 | 1935 | toxprpl_xfer_data *xfer_data = xfer->data; 1936 | 1937 | PurpleAccount *account = purple_xfer_get_account(xfer); 1938 | toxprpl_return_if_fail(account != NULL); 1939 | 1940 | PurpleConnection *gc = purple_account_get_connection(account); 1941 | toxprpl_return_if_fail(gc != NULL); 1942 | 1943 | if (xfer_data->tox != NULL) 1944 | { 1945 | TOX_ERR_FILE_CONTROL err_back; 1946 | tox_file_control(xfer_data->tox, xfer_data->friendnumber, 1947 | xfer_data->filenumber, TOX_FILE_CONTROL_CANCEL, 1948 | &err_back); 1949 | if(err_back != TOX_ERR_FILE_CONTROL_OK) { 1950 | toxprpl_err_file_control(err_back, gc); 1951 | } 1952 | } 1953 | toxprpl_xfer_free(xfer); 1954 | } 1955 | 1956 | static void toxprpl_xfer_cancel_recv(PurpleXfer *xfer) 1957 | { 1958 | purple_debug_info("toxprpl", "xfer_cancel_recv\n"); 1959 | toxprpl_return_if_fail(xfer != NULL); 1960 | toxprpl_xfer_data *xfer_data = xfer->data; 1961 | 1962 | PurpleAccount *account = purple_xfer_get_account(xfer); 1963 | toxprpl_return_if_fail(account != NULL); 1964 | 1965 | PurpleConnection *gc = purple_account_get_connection(account); 1966 | toxprpl_return_if_fail(gc != NULL); 1967 | 1968 | if (xfer_data->tox != NULL) 1969 | { 1970 | TOX_ERR_FILE_CONTROL err_back; 1971 | tox_file_control(xfer_data->tox, xfer_data->friendnumber, 1972 | xfer_data->filenumber, TOX_FILE_CONTROL_CANCEL, 1973 | &err_back); 1974 | if (err_back != TOX_ERR_FILE_CONTROL_OK) 1975 | { 1976 | toxprpl_err_file_control(err_back, gc); 1977 | } 1978 | } 1979 | toxprpl_xfer_free(xfer); 1980 | } 1981 | 1982 | static void toxprpl_xfer_request_denied(PurpleXfer *xfer) 1983 | { 1984 | purple_debug_info("toxprpl", "xfer_request_denied\n"); 1985 | toxprpl_return_if_fail(xfer != NULL); 1986 | toxprpl_return_if_fail(xfer->data != NULL); 1987 | 1988 | PurpleAccount *account = purple_xfer_get_account(xfer); 1989 | toxprpl_return_if_fail(account != NULL); 1990 | 1991 | PurpleConnection *gc = purple_account_get_connection(account); 1992 | toxprpl_return_if_fail(gc != NULL); 1993 | 1994 | toxprpl_xfer_data *xfer_data = xfer->data; 1995 | if (xfer_data->tox != NULL) 1996 | { 1997 | TOX_ERR_FILE_CONTROL err_back; 1998 | tox_file_control(xfer_data->tox, xfer_data->friendnumber, 1999 | xfer_data->filenumber, TOX_FILE_CONTROL_CANCEL, 2000 | &err_back); 2001 | if (err_back != TOX_ERR_FILE_CONTROL_OK) 2002 | { 2003 | toxprpl_err_file_control(err_back, gc); 2004 | } 2005 | } 2006 | toxprpl_xfer_free(xfer); 2007 | } 2008 | 2009 | static void toxprpl_xfer_end(PurpleXfer *xfer) 2010 | { 2011 | purple_debug_info("toxprpl", "xfer_end\n"); 2012 | toxprpl_return_if_fail(xfer != NULL); 2013 | toxprpl_xfer_free(xfer); 2014 | } 2015 | 2016 | static PurpleXfer *toxprpl_new_xfer(PurpleConnection *gc, const gchar *who) 2017 | { 2018 | purple_debug_info("toxprpl", "new_xfer\n"); 2019 | 2020 | toxprpl_return_val_if_fail(gc != NULL, NULL); 2021 | toxprpl_return_val_if_fail(who != NULL, NULL); 2022 | 2023 | PurpleAccount *account = purple_connection_get_account(gc); 2024 | toxprpl_return_val_if_fail(account != NULL, NULL); 2025 | 2026 | PurpleXfer *xfer = purple_xfer_new(account, PURPLE_XFER_SEND, who); 2027 | toxprpl_return_val_if_fail(xfer != NULL, NULL); 2028 | 2029 | toxprpl_xfer_data *xfer_data = g_new0(toxprpl_xfer_data, 1); 2030 | toxprpl_return_val_if_fail(xfer_data != NULL, NULL); 2031 | 2032 | xfer->data = xfer_data; 2033 | 2034 | purple_xfer_set_init_fnc(xfer, toxprpl_xfer_init); 2035 | purple_xfer_set_cancel_send_fnc(xfer, toxprpl_xfer_cancel_send); 2036 | purple_xfer_set_end_fnc(xfer, toxprpl_xfer_end); 2037 | 2038 | return xfer; 2039 | } 2040 | 2041 | static PurpleXfer* toxprpl_new_xfer_receive(PurpleConnection *gc, 2042 | const char *who, 2043 | uint32_t friendnumber, 2044 | uint32_t filenumber, 2045 | const goffset filesize, 2046 | const char *filename) 2047 | { 2048 | purple_debug_info("toxprpl", "new_xfer_receive\n"); 2049 | toxprpl_return_val_if_fail(gc != NULL, NULL); 2050 | toxprpl_return_val_if_fail(who != NULL, NULL); 2051 | 2052 | PurpleAccount *account = purple_connection_get_account(gc); 2053 | toxprpl_return_val_if_fail(account != NULL, NULL); 2054 | 2055 | PurpleXfer *xfer = purple_xfer_new(account, PURPLE_XFER_RECEIVE, who); 2056 | toxprpl_return_val_if_fail(xfer != NULL, NULL); 2057 | 2058 | toxprpl_xfer_data *xfer_data = g_new0(toxprpl_xfer_data, 1); 2059 | toxprpl_return_val_if_fail(xfer_data != NULL, NULL); 2060 | 2061 | toxprpl_plugin_data *plugin_data = purple_connection_get_protocol_data(gc); 2062 | toxprpl_return_val_if_fail(plugin_data != NULL, NULL); 2063 | 2064 | xfer_data->tox = plugin_data->tox; 2065 | xfer_data->friendnumber = friendnumber; 2066 | xfer_data->filenumber = filenumber; 2067 | xfer->data = xfer_data; 2068 | 2069 | purple_xfer_set_filename(xfer, filename); 2070 | purple_xfer_set_size(xfer, filesize); 2071 | 2072 | purple_xfer_set_init_fnc(xfer, toxprpl_xfer_init); 2073 | purple_xfer_set_request_denied_fnc(xfer, toxprpl_xfer_request_denied); 2074 | purple_xfer_set_cancel_recv_fnc(xfer, toxprpl_xfer_cancel_recv); 2075 | purple_xfer_set_end_fnc(xfer, toxprpl_xfer_end); 2076 | 2077 | return xfer; 2078 | } 2079 | 2080 | static void toxprpl_send_file(PurpleConnection *gc, const char *who, 2081 | const char *filename) 2082 | { 2083 | purple_debug_info("toxprpl", "send_file\n"); 2084 | 2085 | toxprpl_return_if_fail(gc != NULL); 2086 | toxprpl_return_if_fail(who != NULL); 2087 | 2088 | PurpleXfer *xfer = toxprpl_new_xfer(gc, who); 2089 | toxprpl_return_if_fail(xfer != NULL); 2090 | 2091 | if (filename != NULL) 2092 | { 2093 | purple_debug_info("toxprpl", "filename != NULL\n"); 2094 | purple_xfer_request_accepted(xfer, filename); 2095 | } 2096 | else 2097 | { 2098 | purple_debug_info("toxprpl", "filename == NULL\n"); 2099 | purple_xfer_request(xfer); 2100 | } 2101 | } 2102 | 2103 | static unsigned int toxprpl_send_typing(PurpleConnection *gc, const char *who, 2104 | PurpleTypingState state) 2105 | { 2106 | purple_debug_info("toxprpl", "send_typing\n"); 2107 | 2108 | toxprpl_return_val_if_fail(gc != NULL, 0); 2109 | toxprpl_return_val_if_fail(who != NULL, 0); 2110 | 2111 | toxprpl_plugin_data *plugin = purple_connection_get_protocol_data(gc); 2112 | toxprpl_return_val_if_fail(plugin != NULL && plugin->tox != NULL, 0); 2113 | 2114 | PurpleAccount *account = purple_connection_get_account(gc); 2115 | toxprpl_return_val_if_fail(account != NULL, 0); 2116 | 2117 | PurpleBuddy *buddy = purple_find_buddy(account, who); 2118 | toxprpl_return_val_if_fail(buddy != NULL, 0); 2119 | 2120 | toxprpl_buddy_data *buddy_data = purple_buddy_get_protocol_data(buddy); 2121 | toxprpl_return_val_if_fail(buddy_data != NULL, 0); 2122 | 2123 | TOX_ERR_SET_TYPING err_back_typing; 2124 | switch(state) 2125 | { 2126 | case PURPLE_TYPING: 2127 | purple_debug_info("toxprpl", "Send typing state: TYPING\n"); 2128 | tox_self_set_typing(plugin->tox, buddy_data->tox_friendlist_number, TRUE, &err_back_typing); 2129 | break; 2130 | case PURPLE_TYPED: 2131 | /* typing pause */ 2132 | purple_debug_info("toxprpl", "Send typing state: TYPED\n"); 2133 | tox_self_set_typing(plugin->tox, buddy_data->tox_friendlist_number, FALSE, &err_back_typing); 2134 | break; 2135 | default: 2136 | purple_debug_info("toxprpl", "Send typing state: NOT_TYPING\n"); 2137 | tox_self_set_typing(plugin->tox, buddy_data->tox_friendlist_number, FALSE, &err_back_typing); 2138 | break; 2139 | } 2140 | 2141 | return 0; 2142 | } 2143 | 2144 | static PurplePluginProtocolInfo prpl_info = 2145 | { 2146 | OPT_PROTO_NO_PASSWORD | OPT_PROTO_REGISTER_NOSCREENNAME | OPT_PROTO_INVITE_MESSAGE, /* options */ 2147 | NULL, /* user_splits, initialized in toxprpl_init() */ 2148 | NULL, /* protocol_options, initialized in toxprpl_init() */ 2149 | NO_BUDDY_ICONS, /* icon spec */ 2150 | toxprpl_list_icon, /* list_icon */ 2151 | NULL, /* list_emblem */ 2152 | NULL, /* status_text */ 2153 | NULL, /* tooltip_text */ 2154 | toxprpl_status_types, /* status_types */ 2155 | NULL, /* blist_node_menu */ 2156 | NULL, /* chat_info */ 2157 | NULL, /* chat_info_defaults */ 2158 | toxprpl_login, /* login */ 2159 | toxprpl_close, /* close */ 2160 | toxprpl_send_im, /* send_im */ 2161 | NULL, /* set_info */ 2162 | toxprpl_send_typing, /* send_typing */ 2163 | NULL, /* get_info */ 2164 | toxprpl_set_status, /* set_status */ 2165 | NULL, /* set_idle */ 2166 | NULL, /* change_passwd */ 2167 | NULL, /* add_buddy */ 2168 | NULL, /* add_buddies */ 2169 | toxprpl_remove_buddy, /* remove_buddy */ 2170 | NULL, /* remove_buddies */ 2171 | NULL, /* add_permit */ 2172 | NULL, /* add_deny */ 2173 | NULL, /* rem_permit */ 2174 | NULL, /* rem_deny */ 2175 | NULL, /* set_permit_deny */ 2176 | NULL, /* join_chat */ 2177 | NULL, /* reject_chat */ 2178 | NULL, /* get_chat_name */ 2179 | NULL, /* chat_invite */ 2180 | NULL, /* chat_leave */ 2181 | NULL, /* chat_whisper */ 2182 | NULL, /* chat_send */ 2183 | NULL, /* keepalive */ 2184 | NULL, /* register_user */ 2185 | NULL, /* get_cb_info */ 2186 | NULL, /* get_cb_away */ 2187 | NULL, /* alias_buddy */ 2188 | NULL, /* group_buddy */ 2189 | NULL, /* rename_group */ 2190 | toxprpl_free_buddy, /* buddy_free */ 2191 | NULL, /* convo_closed */ 2192 | NULL, /* normalize */ 2193 | NULL, /* set_buddy_icon */ 2194 | NULL, /* remove_group */ 2195 | NULL, /* get_cb_real_name */ 2196 | NULL, /* set_chat_topic */ 2197 | NULL, /* find_blist_chat */ 2198 | NULL, /* roomlist_get_list */ 2199 | NULL, /* roomlist_cancel */ 2200 | NULL, /* roomlist_expand_category */ 2201 | toxprpl_can_receive_file, /* can_receive_file */ 2202 | toxprpl_send_file, /* send_file */ 2203 | toxprpl_new_xfer, /* new_xfer */ 2204 | toxprpl_offline_message, /* offline_message */ 2205 | NULL, /* whiteboard_prpl_ops */ 2206 | NULL, /* send_raw */ 2207 | NULL, /* roomlist_room_serialize */ 2208 | NULL, /* unregister_user */ 2209 | NULL, /* send_attention */ 2210 | NULL, /* get_attention_types */ 2211 | sizeof(PurplePluginProtocolInfo), /* struct_size */ 2212 | NULL, /* get_account_text_table */ 2213 | NULL, /* initiate_media */ 2214 | NULL, /* get_media_caps */ 2215 | NULL, /* get_moods */ 2216 | NULL, /* set_public_alias */ 2217 | NULL, /* get_public_alias */ 2218 | toxprpl_add_buddy, /* add_buddy_with_invite */ 2219 | NULL /* add_buddies_with_invite */ 2220 | }; 2221 | 2222 | static void toxprpl_init(PurplePlugin *plugin) 2223 | { 2224 | purple_debug_info("toxprpl", "starting up\n"); 2225 | 2226 | PurpleAccountOption *option = purple_account_option_string_new( 2227 | _("Nickname"), "nickname", ""); 2228 | prpl_info.protocol_options = g_list_append(NULL, option); 2229 | 2230 | option = purple_account_option_string_new( 2231 | _("Server"), "dht_server", DEFAULT_SERVER_IP); 2232 | prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, 2233 | option); 2234 | 2235 | option = purple_account_option_int_new(_("Port"), "dht_server_port", 2236 | DEFAULT_SERVER_PORT); 2237 | prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, 2238 | option); 2239 | 2240 | option = purple_account_option_string_new(_("Server key"), 2241 | "dht_server_key", DEFAULT_SERVER_KEY); 2242 | prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, 2243 | option); 2244 | purple_debug_info("toxprpl", "initialization complete\n"); 2245 | 2246 | option = purple_account_option_string_new(_("Account path"), 2247 | "account_path", DEFAULT_ACCOUNT_PATH); 2248 | prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, 2249 | option); 2250 | } 2251 | 2252 | static PurplePluginInfo info = 2253 | { 2254 | PURPLE_PLUGIN_MAGIC, /* magic */ 2255 | PURPLE_MAJOR_VERSION, /* major_version */ 2256 | PURPLE_MINOR_VERSION, /* minor_version */ 2257 | PURPLE_PLUGIN_PROTOCOL, /* type */ 2258 | NULL, /* ui_requirement */ 2259 | 0, /* flags */ 2260 | NULL, /* dependencies */ 2261 | PURPLE_PRIORITY_DEFAULT, /* priority */ 2262 | TOXPRPL_ID, /* id */ 2263 | "Tox", /* name */ 2264 | VERSION, /* version */ 2265 | "Tox Protocol Plugin", /* summary */ 2266 | "Tox Protocol Plugin http://tox.im/", /* description */ 2267 | "Sergey 'Jin' Bostandzhyan", /* author */ 2268 | PACKAGE_URL, /* homepage */ 2269 | NULL, /* load */ 2270 | NULL, /* unload */ 2271 | NULL, /* destroy */ 2272 | NULL, /* ui_info */ 2273 | &prpl_info, /* extra_info */ 2274 | NULL, /* prefs_info */ 2275 | toxprpl_account_actions, /* actions */ 2276 | NULL, /* padding... */ 2277 | NULL, 2278 | NULL, 2279 | NULL, 2280 | }; 2281 | 2282 | PURPLE_INIT_PLUGIN(tox, toxprpl_init, info); 2283 | --------------------------------------------------------------------------------